aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/DocBook/Makefile3
-rw-r--r--Documentation/DocBook/alsa-driver-api.tmpl (renamed from Documentation/sound/alsa/DocBook/alsa-driver-api.tmpl)17
-rw-r--r--Documentation/DocBook/uio-howto.tmpl29
-rw-r--r--Documentation/DocBook/writing-an-alsa-driver.tmpl (renamed from Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl)52
-rw-r--r--Documentation/cpu-freq/governors.txt26
-rw-r--r--Documentation/cpu-freq/user-guide.txt12
-rw-r--r--Documentation/dynamic-debug-howto.txt240
-rw-r--r--Documentation/kernel-parameters.txt5
-rw-r--r--Documentation/sound/alsa/ALSA-Configuration.txt87
-rw-r--r--Documentation/sound/alsa/HD-Audio-Models.txt21
-rw-r--r--Documentation/sound/alsa/HD-Audio.txt47
-rw-r--r--Documentation/sound/alsa/soc/dapm.txt3
-rw-r--r--Documentation/sound/oss/CS423223
-rw-r--r--Documentation/sound/oss/Introduction2
-rw-r--r--Documentation/usb/usbmon.txt27
-rw-r--r--MAINTAINERS6
-rw-r--r--arch/arm/mach-pxa/e740.c5
-rw-r--r--arch/arm/mach-pxa/e750.c5
-rw-r--r--arch/arm/mach-pxa/h5000.c7
-rw-r--r--arch/arm/mach-pxa/include/mach/eseries-gpio.h15
-rw-r--r--arch/arm/mach-pxa/include/mach/regs-ssp.h7
-rw-r--r--arch/arm/mach-pxa/spitz.c6
-rw-r--r--arch/arm/mach-s3c2410/dma.c2
-rw-r--r--arch/arm/mach-s3c2410/usb-simtec.c3
-rw-r--r--arch/arm/mach-s3c2412/dma.c4
-rw-r--r--arch/arm/mach-s3c2440/dma.c2
-rw-r--r--arch/arm/mach-s3c2443/dma.c2
-rw-r--r--arch/arm/plat-s3c/include/plat/audio.h (renamed from arch/arm/mach-s3c2410/include/mach/audio.h)0
-rw-r--r--arch/arm/plat-s3c/include/plat/regs-s3c2412-iis.h (renamed from include/asm-arm/plat-s3c24xx/regs-s3c2412-iis.h)7
-rw-r--r--arch/arm/plat-s3c/include/plat/usb-control.h (renamed from arch/arm/mach-s3c2410/include/mach/usb-control.h)6
-rw-r--r--arch/arm/plat-s3c24xx/include/plat/regs-iis.h (renamed from include/asm-arm/plat-s3c24xx/regs-iis.h)0
-rw-r--r--arch/avr32/boards/hammerhead/flash.c1
-rw-r--r--arch/avr32/include/asm/uaccess.h8
-rw-r--r--arch/avr32/kernel/entry-avr32b.S60
-rw-r--r--arch/avr32/kernel/syscall-stubs.S14
-rw-r--r--arch/avr32/lib/strnlen_user.S2
-rw-r--r--arch/mips/basler/excite/excite_iodev.c27
-rw-r--r--arch/mips/include/asm/mipsregs.h22
-rw-r--r--arch/mips/kernel/linux32.c1
-rw-r--r--arch/mips/kernel/traps.c12
-rw-r--r--arch/mips/mm/c-r4k.c2
-rw-r--r--arch/mips/mm/dma-default.c2
-rw-r--r--arch/powerpc/boot/dts/canyonlands.dts7
-rw-r--r--arch/powerpc/boot/dts/kilauea.dts7
-rw-r--r--arch/powerpc/platforms/ps3/system-bus.c4
-rw-r--r--arch/s390/crypto/sha.h6
-rw-r--r--arch/s390/crypto/sha1_s390.c40
-rw-r--r--arch/s390/crypto/sha256_s390.c40
-rw-r--r--arch/s390/crypto/sha512_s390.c81
-rw-r--r--arch/s390/crypto/sha_common.c20
-rw-r--r--arch/sh/Kconfig63
-rw-r--r--arch/sh/Kconfig.cpu3
-rw-r--r--arch/sh/Makefile1
-rw-r--r--arch/sh/boards/Kconfig27
-rw-r--r--arch/sh/boards/Makefile3
-rw-r--r--arch/sh/boards/board-ap325rxa.c11
-rw-r--r--arch/sh/boards/board-espt.c102
-rw-r--r--arch/sh/boards/board-polaris.c149
-rw-r--r--arch/sh/boards/board-sh7785lcr.c13
-rw-r--r--arch/sh/boards/board-urquell.c162
-rw-r--r--arch/sh/boards/mach-highlander/Kconfig2
-rw-r--r--arch/sh/boards/mach-hp6xx/pm_wakeup.S31
-rw-r--r--arch/sh/boards/mach-hp6xx/setup.c1
-rw-r--r--arch/sh/boards/mach-migor/setup.c9
-rw-r--r--arch/sh/boards/mach-rsk/Kconfig2
-rw-r--r--arch/sh/boards/mach-sh7763rdp/setup.c10
-rw-r--r--arch/sh/boot/Makefile20
-rw-r--r--arch/sh/cchips/hd6446x/hd64461.c30
-rw-r--r--arch/sh/configs/espt_defconfig1190
-rw-r--r--arch/sh/configs/polaris_defconfig969
-rw-r--r--arch/sh/configs/sh7785lcr_32bit_defconfig1553
-rw-r--r--arch/sh/configs/urquell_defconfig1332
-rw-r--r--arch/sh/drivers/dma/Kconfig40
-rw-r--r--arch/sh/drivers/dma/Makefile3
-rw-r--r--arch/sh/drivers/dma/dma-sh.c169
-rw-r--r--arch/sh/drivers/dma/dma-sh.h75
-rw-r--r--arch/sh/drivers/pci/pci-sh7780.c4
-rw-r--r--arch/sh/include/asm/addrspace.h4
-rw-r--r--arch/sh/include/asm/atomic-irq.h16
-rw-r--r--arch/sh/include/asm/bitops-llsc.h72
-rw-r--r--arch/sh/include/asm/clock.h1
-rw-r--r--arch/sh/include/asm/cmpxchg-llsc.h38
-rw-r--r--arch/sh/include/asm/cpu-features.h1
-rw-r--r--arch/sh/include/asm/dma-sh.h118
-rw-r--r--arch/sh/include/asm/dma.h4
-rw-r--r--arch/sh/include/asm/entry-macros.S5
-rw-r--r--arch/sh/include/asm/gpio.h70
-rw-r--r--arch/sh/include/asm/hd64461.h1
-rw-r--r--arch/sh/include/asm/io.h4
-rw-r--r--arch/sh/include/asm/kprobes.h2
-rw-r--r--arch/sh/include/asm/mmu_context.h15
-rw-r--r--arch/sh/include/asm/mmu_context_32.h12
-rw-r--r--arch/sh/include/asm/page.h7
-rw-r--r--arch/sh/include/asm/processor.h2
-rw-r--r--arch/sh/include/asm/processor_32.h15
-rw-r--r--arch/sh/include/asm/processor_64.h14
-rw-r--r--arch/sh/include/asm/ptrace.h8
-rw-r--r--arch/sh/include/asm/sections.h1
-rw-r--r--arch/sh/include/asm/suspend.h22
-rw-r--r--arch/sh/include/asm/timer.h4
-rw-r--r--arch/sh/include/asm/tlb.h100
-rw-r--r--arch/sh/include/cpu-sh3/cpu/dma.h17
-rw-r--r--arch/sh/include/cpu-sh4/cpu/dma-sh4a.h94
-rw-r--r--arch/sh/include/cpu-sh4/cpu/dma-sh7780.h39
-rw-r--r--arch/sh/include/cpu-sh4/cpu/dma.h30
-rw-r--r--arch/sh/include/cpu-sh4/cpu/freq.h4
-rw-r--r--arch/sh/include/cpu-sh4/cpu/mmu_context.h35
-rw-r--r--arch/sh/include/cpu-sh4/cpu/sh7786.h192
-rw-r--r--arch/sh/include/mach-common/mach/urquell.h68
-rw-r--r--arch/sh/kernel/Makefile_321
-rw-r--r--arch/sh/kernel/asm-offsets.c8
-rw-r--r--arch/sh/kernel/cpu/Makefile1
-rw-r--r--arch/sh/kernel/cpu/clock.c95
-rw-r--r--arch/sh/kernel/cpu/sh2/setup-sh7619.c34
-rw-r--r--arch/sh/kernel/cpu/sh2a/setup-mxg.c65
-rw-r--r--arch/sh/kernel/cpu/sh2a/setup-sh7201.c224
-rw-r--r--arch/sh/kernel/cpu/sh2a/setup-sh7203.c236
-rw-r--r--arch/sh/kernel/cpu/sh2a/setup-sh7206.c154
-rw-r--r--arch/sh/kernel/cpu/sh3/Makefile2
-rw-r--r--arch/sh/kernel/cpu/sh3/entry.S357
-rw-r--r--arch/sh/kernel/cpu/sh3/setup-sh7705.c61
-rw-r--r--arch/sh/kernel/cpu/sh3/setup-sh770x.c68
-rw-r--r--arch/sh/kernel/cpu/sh3/setup-sh7710.c69
-rw-r--r--arch/sh/kernel/cpu/sh3/setup-sh7720.c68
-rw-r--r--arch/sh/kernel/cpu/sh3/swsusp.S147
-rw-r--r--arch/sh/kernel/cpu/sh4/Makefile1
-rw-r--r--arch/sh/kernel/cpu/sh4/probe.c7
-rw-r--r--arch/sh/kernel/cpu/sh4/setup-sh7750.c87
-rw-r--r--arch/sh/kernel/cpu/sh4a/Makefile3
-rw-r--r--arch/sh/kernel/cpu/sh4a/clock-sh7786.c148
-rw-r--r--arch/sh/kernel/cpu/sh4a/pinmux-sh7786.c950
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7343.c34
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7366.c34
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7722.c34
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7723.c34
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7763.c114
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7780.c97
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7785.c95
-rw-r--r--arch/sh/kernel/cpu/sh4a/setup-sh7786.c490
-rw-r--r--arch/sh/kernel/cpu/shmobile/Makefile6
-rw-r--r--arch/sh/kernel/cpu/shmobile/pm.c92
-rw-r--r--arch/sh/kernel/cpu/shmobile/sleep.S125
-rw-r--r--arch/sh/kernel/gpio.c338
-rw-r--r--arch/sh/kernel/irq.c2
-rw-r--r--arch/sh/kernel/machine_kexec.c74
-rw-r--r--arch/sh/kernel/relocate_kernel.S203
-rw-r--r--arch/sh/kernel/setup.c3
-rw-r--r--arch/sh/kernel/swsusp.c38
-rw-r--r--arch/sh/kernel/time_32.c71
-rw-r--r--arch/sh/kernel/timers/timer-mtu2.c3
-rw-r--r--arch/sh/kernel/timers/timer-tmu.c21
-rw-r--r--arch/sh/kernel/vmlinux_32.lds.S5
-rw-r--r--arch/sh/mm/Kconfig29
-rw-r--r--arch/sh/mm/Makefile_327
-rw-r--r--arch/sh/mm/asids-debugfs.c4
-rw-r--r--arch/sh/mm/ioremap_32.c8
-rw-r--r--arch/sh/mm/pmb-fixed.c45
-rw-r--r--arch/sh/mm/pmb.c38
-rw-r--r--arch/sh/mm/tlb-pteaex.c96
-rw-r--r--arch/sh/oprofile/common.c1
-rw-r--r--arch/sh/tools/mach-types3
-rw-r--r--arch/x86/crypto/Makefile3
-rw-r--r--arch/x86/crypto/aes-i586-asm_32.S18
-rw-r--r--arch/x86/crypto/aes-x86_64-asm_64.S6
-rw-r--r--arch/x86/crypto/aes_glue.c20
-rw-r--r--arch/x86/crypto/aesni-intel_asm.S896
-rw-r--r--arch/x86/crypto/aesni-intel_glue.c461
-rw-r--r--arch/x86/include/asm/aes.h11
-rw-r--r--arch/x86/include/asm/cpufeature.h1
-rw-r--r--arch/x86/include/asm/timer.h2
-rw-r--r--arch/x86/kernel/cpu/cpufreq/Kconfig19
-rw-r--r--arch/x86/kernel/cpu/cpufreq/Makefile8
-rw-r--r--arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c36
-rw-r--r--arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c54
-rw-r--r--arch/x86/kernel/cpu/cpufreq/e_powersaver.c21
-rw-r--r--arch/x86/kernel/cpu/cpufreq/elanfreq.c6
-rw-r--r--arch/x86/kernel/cpu/cpufreq/gx-suspmod.c105
-rw-r--r--arch/x86/kernel/cpu/cpufreq/longhaul.c193
-rw-r--r--arch/x86/kernel/cpu/cpufreq/longhaul.h12
-rw-r--r--arch/x86/kernel/cpu/cpufreq/longrun.c25
-rw-r--r--arch/x86/kernel/cpu/cpufreq/p4-clockmod.c72
-rw-r--r--arch/x86/kernel/cpu/cpufreq/powernow-k6.c44
-rw-r--r--arch/x86/kernel/cpu/cpufreq/powernow-k7.c239
-rw-r--r--arch/x86/kernel/cpu/cpufreq/powernow-k8.c386
-rw-r--r--arch/x86/kernel/cpu/cpufreq/powernow-k8.h5
-rw-r--r--arch/x86/kernel/cpu/cpufreq/sc520_freq.c30
-rw-r--r--arch/x86/kernel/cpu/cpufreq/speedstep-ich.c70
-rw-r--r--arch/x86/kernel/cpu/cpufreq/speedstep-lib.c163
-rw-r--r--arch/x86/kernel/cpu/cpufreq/speedstep-lib.h18
-rw-r--r--arch/x86/kernel/cpu/cpufreq/speedstep-smi.c166
-rw-r--r--arch/x86/kernel/tsc.c3
-rw-r--r--crypto/Kconfig44
-rw-r--r--crypto/Makefile5
-rw-r--r--crypto/ablkcipher.c19
-rw-r--r--crypto/aead.c16
-rw-r--r--crypto/algboss.c20
-rw-r--r--crypto/ansi_cprng.c17
-rw-r--r--crypto/api.c17
-rw-r--r--crypto/blkcipher.c2
-rw-r--r--crypto/chainiv.c3
-rw-r--r--crypto/cryptd.c237
-rw-r--r--crypto/crypto_wq.c38
-rw-r--r--crypto/gf128mul.c2
-rw-r--r--crypto/internal.h6
-rw-r--r--crypto/pcompress.c97
-rw-r--r--crypto/sha256_generic.c2
-rw-r--r--crypto/shash.c20
-rw-r--r--crypto/tcrypt.c6
-rw-r--r--crypto/testmgr.c198
-rw-r--r--crypto/testmgr.h147
-rw-r--r--crypto/zlib.c378
-rw-r--r--drivers/acpi/dock.c2
-rw-r--r--drivers/amba/bus.c4
-rw-r--r--drivers/ata/ahci.c31
-rw-r--r--drivers/ata/ata_generic.c4
-rw-r--r--drivers/ata/ata_piix.c60
-rw-r--r--drivers/ata/libata-core.c14
-rw-r--r--drivers/ata/libata-eh.c19
-rw-r--r--drivers/ata/libata-sff.c91
-rw-r--r--drivers/ata/libata.h2
-rw-r--r--drivers/ata/pata_acpi.c6
-rw-r--r--drivers/ata/pata_ali.c28
-rw-r--r--drivers/ata/pata_amd.c70
-rw-r--r--drivers/ata/pata_artop.c49
-rw-r--r--drivers/ata/pata_at32.c4
-rw-r--r--drivers/ata/pata_atiixp.c6
-rw-r--r--drivers/ata/pata_bf54x.c2
-rw-r--r--drivers/ata/pata_cmd640.c2
-rw-r--r--drivers/ata/pata_cmd64x.c24
-rw-r--r--drivers/ata/pata_cs5520.c2
-rw-r--r--drivers/ata/pata_cs5530.c8
-rw-r--r--drivers/ata/pata_cs5535.c4
-rw-r--r--drivers/ata/pata_cs5536.c4
-rw-r--r--drivers/ata/pata_cypress.c4
-rw-r--r--drivers/ata/pata_efar.c6
-rw-r--r--drivers/ata/pata_hpt366.c4
-rw-r--r--drivers/ata/pata_hpt37x.c28
-rw-r--r--drivers/ata/pata_hpt3x2n.c4
-rw-r--r--drivers/ata/pata_hpt3x3.c6
-rw-r--r--drivers/ata/pata_icside.c4
-rw-r--r--drivers/ata/pata_isapnp.c14
-rw-r--r--drivers/ata/pata_it8213.c4
-rw-r--r--drivers/ata/pata_it821x.c16
-rw-r--r--drivers/ata/pata_ixp4xx_cf.c2
-rw-r--r--drivers/ata/pata_jmicron.c4
-rw-r--r--drivers/ata/pata_legacy.c2
-rw-r--r--drivers/ata/pata_marvell.c8
-rw-r--r--drivers/ata/pata_mpc52xx.c4
-rw-r--r--drivers/ata/pata_mpiix.c2
-rw-r--r--drivers/ata/pata_netcell.c4
-rw-r--r--drivers/ata/pata_ninja32.c2
-rw-r--r--drivers/ata/pata_ns87410.c2
-rw-r--r--drivers/ata/pata_ns87415.c8
-rw-r--r--drivers/ata/pata_octeon_cf.c4
-rw-r--r--drivers/ata/pata_oldpiix.c4
-rw-r--r--drivers/ata/pata_opti.c2
-rw-r--r--drivers/ata/pata_optidma.c10
-rw-r--r--drivers/ata/pata_pcmcia.c36
-rw-r--r--drivers/ata/pata_pdc2027x.c12
-rw-r--r--drivers/ata/pata_pdc202xx_old.c12
-rw-r--r--drivers/ata/pata_qdi.c4
-rw-r--r--drivers/ata/pata_radisys.c6
-rw-r--r--drivers/ata/pata_rb532_cf.c64
-rw-r--r--drivers/ata/pata_rz1000.c2
-rw-r--r--drivers/ata/pata_sc1200.c35
-rw-r--r--drivers/ata/pata_scc.c4
-rw-r--r--drivers/ata/pata_sch.c6
-rw-r--r--drivers/ata/pata_serverworks.c20
-rw-r--r--drivers/ata/pata_sil680.c8
-rw-r--r--drivers/ata/pata_sis.c32
-rw-r--r--drivers/ata/pata_sl82c105.c6
-rw-r--r--drivers/ata/pata_triflex.c4
-rw-r--r--drivers/ata/pata_via.c24
-rw-r--r--drivers/ata/pata_winbond.c2
-rw-r--r--drivers/ata/pdc_adma.c4
-rw-r--r--drivers/ata/sata_fsl.c4
-rw-r--r--drivers/ata/sata_inic162x.c4
-rw-r--r--drivers/ata/sata_mv.c868
-rw-r--r--drivers/ata/sata_nv.c7
-rw-r--r--drivers/ata/sata_promise.c30
-rw-r--r--drivers/ata/sata_qstor.c3
-rw-r--r--drivers/ata/sata_sil.c16
-rw-r--r--drivers/ata/sata_sil24.c18
-rw-r--r--drivers/ata/sata_sis.c4
-rw-r--r--drivers/ata/sata_svw.c16
-rw-r--r--drivers/ata/sata_sx4.c4
-rw-r--r--drivers/ata/sata_uli.c2
-rw-r--r--drivers/ata/sata_via.c16
-rw-r--r--drivers/ata/sata_vsc.c7
-rw-r--r--drivers/base/base.h31
-rw-r--r--drivers/base/bus.c44
-rw-r--r--drivers/base/core.c108
-rw-r--r--drivers/base/dd.c40
-rw-r--r--drivers/base/driver.c15
-rw-r--r--drivers/base/firmware_class.c4
-rw-r--r--drivers/base/platform.c60
-rw-r--r--drivers/base/power/main.c44
-rw-r--r--drivers/base/power/power.h8
-rw-r--r--drivers/base/sys.c54
-rw-r--r--drivers/block/floppy.c3
-rw-r--r--drivers/block/ub.c11
-rw-r--r--drivers/char/hw_random/Kconfig14
-rw-r--r--drivers/char/hw_random/Makefile1
-rw-r--r--drivers/char/hw_random/timeriomem-rng.c151
-rw-r--r--drivers/char/tpm/tpm_atmel.c28
-rw-r--r--drivers/char/tpm/tpm_tis.c28
-rw-r--r--drivers/char/vc_screen.c16
-rw-r--r--drivers/char/vt.c5
-rw-r--r--drivers/clocksource/Makefile1
-rw-r--r--drivers/clocksource/sh_cmt.c615
-rw-r--r--drivers/cpufreq/cpufreq.c55
-rw-r--r--drivers/cpufreq/cpufreq_conservative.c404
-rw-r--r--drivers/cpufreq/cpufreq_ondemand.c74
-rw-r--r--drivers/cpufreq/cpufreq_stats.c74
-rw-r--r--drivers/cpufreq/cpufreq_userspace.c27
-rw-r--r--drivers/cpufreq/freq_table.c18
-rw-r--r--drivers/crypto/Kconfig15
-rw-r--r--drivers/crypto/Makefile1
-rw-r--r--drivers/crypto/amcc/Makefile2
-rw-r--r--drivers/crypto/amcc/crypto4xx_alg.c293
-rw-r--r--drivers/crypto/amcc/crypto4xx_core.c1310
-rw-r--r--drivers/crypto/amcc/crypto4xx_core.h177
-rw-r--r--drivers/crypto/amcc/crypto4xx_reg_def.h284
-rw-r--r--drivers/crypto/amcc/crypto4xx_sa.c108
-rw-r--r--drivers/crypto/amcc/crypto4xx_sa.h243
-rw-r--r--drivers/dio/dio.c4
-rw-r--r--drivers/dma/dw_dmac.c2
-rw-r--r--drivers/edac/cell_edac.c2
-rw-r--r--drivers/edac/mpc85xx_edac.c2
-rw-r--r--drivers/edac/mv64x60_edac.c8
-rw-r--r--drivers/eisa/eisa-bus.c4
-rw-r--r--drivers/gpio/bt8xxgpio.c2
-rw-r--r--drivers/gpu/drm/drm_sysfs.c4
-rw-r--r--drivers/i2c/i2c-core.c2
-rw-r--r--drivers/ide/Kconfig8
-rw-r--r--drivers/ide/Makefile4
-rw-r--r--drivers/ide/aec62xx.c4
-rw-r--r--drivers/ide/alim15x3.c2
-rw-r--r--drivers/ide/amd74xx.c14
-rw-r--r--drivers/ide/atiixp.c3
-rw-r--r--drivers/ide/au1xxx-ide.c36
-rw-r--r--drivers/ide/cmd64x.c2
-rw-r--r--drivers/ide/cs5520.c3
-rw-r--r--drivers/ide/cs5530.c2
-rw-r--r--drivers/ide/delkin_cb.c2
-rw-r--r--drivers/ide/hpt366.c4
-rw-r--r--drivers/ide/ide-acpi.c214
-rw-r--r--drivers/ide/ide-atapi.c41
-rw-r--r--drivers/ide/ide-cd.c4
-rw-r--r--drivers/ide/ide-devsets.c190
-rw-r--r--drivers/ide/ide-dma.c57
-rw-r--r--drivers/ide/ide-eh.c428
-rw-r--r--drivers/ide/ide-io-std.c316
-rw-r--r--drivers/ide/ide-io.c320
-rw-r--r--drivers/ide/ide-iops.c742
-rw-r--r--drivers/ide/ide-lib.c240
-rw-r--r--drivers/ide/ide-park.c25
-rw-r--r--drivers/ide/ide-pci-generic.c4
-rw-r--r--drivers/ide/ide-probe.c257
-rw-r--r--drivers/ide/ide-proc.c2
-rw-r--r--drivers/ide/ide-xfer-mode.c246
-rw-r--r--drivers/ide/ide.c156
-rw-r--r--drivers/ide/it821x.c2
-rw-r--r--drivers/ide/ns87415.c4
-rw-r--r--drivers/ide/pdc202xx_new.c4
-rw-r--r--drivers/ide/pdc202xx_old.c4
-rw-r--r--drivers/ide/piix.c13
-rw-r--r--drivers/ide/serverworks.c13
-rw-r--r--drivers/ide/setup-pci.c27
-rw-r--r--drivers/ide/siimage.c2
-rw-r--r--drivers/ide/sis5513.c4
-rw-r--r--drivers/ide/sl82c105.c4
-rw-r--r--drivers/ide/slc90e66.c1
-rw-r--r--drivers/ide/trm290.c3
-rw-r--r--drivers/ide/via82cxxx.c12
-rw-r--r--drivers/input/joystick/maplecontrol.c4
-rw-r--r--drivers/input/keyboard/maple_keyb.c37
-rw-r--r--drivers/input/keyboard/sh_keysc.c26
-rw-r--r--drivers/isdn/gigaset/ser-gigaset.c3
-rw-r--r--drivers/mca/mca-bus.c4
-rw-r--r--drivers/media/radio/radio-tea5764.c3
-rw-r--r--drivers/media/video/cx88/cx88-alsa.c7
-rw-r--r--drivers/media/video/em28xx/em28xx-audio.c7
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c8
-rw-r--r--drivers/media/video/v4l2-device.c2
-rw-r--r--drivers/mfd/mcp-core.c2
-rw-r--r--drivers/mfd/ucb1x00-core.c2
-rw-r--r--drivers/mmc/host/atmel-mci.c2
-rw-r--r--drivers/mmc/host/of_mmc_spi.c2
-rw-r--r--drivers/mtd/maps/Kconfig12
-rw-r--r--drivers/mtd/maps/Makefile1
-rw-r--r--drivers/mtd/maps/pxa2xx-flash.c37
-rw-r--r--drivers/mtd/maps/vmu-flash.c832
-rw-r--r--drivers/mtd/nand/excite_nandflash.c25
-rw-r--r--drivers/mtd/nand/ndfc.c2
-rw-r--r--drivers/mtd/onenand/generic.c26
-rw-r--r--drivers/net/arm/ks8695net.c2
-rw-r--r--drivers/net/au1000_eth.c8
-rw-r--r--drivers/net/bfin_mac.c12
-rw-r--r--drivers/net/bmac.c2
-rw-r--r--drivers/net/cpmac.c2
-rw-r--r--drivers/net/declance.c6
-rw-r--r--drivers/net/depca.c6
-rw-r--r--drivers/net/ehea/ehea_main.c2
-rw-r--r--drivers/net/jazzsonic.c6
-rw-r--r--drivers/net/macb.c10
-rw-r--r--drivers/net/macsonic.c15
-rw-r--r--drivers/net/mipsnet.c26
-rw-r--r--drivers/net/mv643xx_eth.c2
-rw-r--r--drivers/net/sb1250-mac.c10
-rw-r--r--drivers/net/smc911x.c2
-rw-r--r--drivers/net/smc91x.c2
-rw-r--r--drivers/net/smsc911x.c7
-rw-r--r--drivers/net/smsc9420.c4
-rw-r--r--drivers/net/tc35815.c4
-rw-r--r--drivers/net/wimax/i2400m/driver.c2
-rw-r--r--drivers/net/wimax/i2400m/usb-notif.c2
-rw-r--r--drivers/net/xtsonic.c2
-rw-r--r--drivers/pci/hotplug/cpqphp_sysfs.c3
-rw-r--r--drivers/pcmcia/au1000_generic.c37
-rw-r--r--drivers/pcmcia/i82365.c28
-rw-r--r--drivers/pcmcia/m32r_cfc.c30
-rw-r--r--drivers/pcmcia/m32r_pcc.c30
-rw-r--r--drivers/pcmcia/rsrc_mgr.c2
-rw-r--r--drivers/pcmcia/sa1100_generic.c38
-rw-r--r--drivers/pcmcia/tcic.c30
-rw-r--r--drivers/pcmcia/vrc4171_card.c34
-rw-r--r--drivers/rapidio/rio-driver.c2
-rw-r--r--drivers/rtc/rtc-at91sam9.c4
-rw-r--r--drivers/rtc/rtc-omap.c4
-rw-r--r--drivers/rtc/rtc-sh.c246
-rw-r--r--drivers/rtc/rtc-twl4030.c2
-rw-r--r--drivers/s390/cio/ccwgroup.c5
-rw-r--r--drivers/s390/cio/chsc_sch.c4
-rw-r--r--drivers/s390/cio/css.c4
-rw-r--r--drivers/s390/cio/device.c13
-rw-r--r--drivers/s390/net/qeth_l3_main.c2
-rw-r--r--drivers/scsi/a4000t.c29
-rw-r--r--drivers/scsi/bvme6000_scsi.c29
-rw-r--r--drivers/scsi/mvme16x_scsi.c29
-rw-r--r--drivers/serial/sh-sci.c12
-rw-r--r--drivers/serial/sh-sci.h15
-rw-r--r--drivers/serial/sunzilog.c4
-rw-r--r--drivers/sh/intc.c47
-rw-r--r--drivers/sh/maple/maple.c471
-rw-r--r--drivers/sh/superhyway/superhyway.c4
-rw-r--r--drivers/spi/atmel_spi.c8
-rw-r--r--drivers/spi/mpc52xx_psc_spi.c2
-rw-r--r--drivers/spi/omap2_mcspi.c2
-rw-r--r--drivers/spi/omap_uwire.c12
-rw-r--r--drivers/spi/orion_spi.c2
-rw-r--r--drivers/spi/pxa2xx_spi.c4
-rw-r--r--drivers/spi/spi_bfin5xx.c4
-rw-r--r--drivers/spi/spi_gpio.c2
-rw-r--r--drivers/spi/spi_imx.c5
-rw-r--r--drivers/spi/spi_mpc83xx.c4
-rw-r--r--drivers/spi/spi_txx9.c3
-rw-r--r--drivers/staging/go7007/snd-go7007.c7
-rw-r--r--drivers/tc/tc.c8
-rw-r--r--drivers/uio/Kconfig18
-rw-r--r--drivers/uio/Makefile1
-rw-r--r--drivers/uio/uio.c25
-rw-r--r--drivers/uio/uio_aec.c175
-rw-r--r--drivers/usb/Kconfig1
-rw-r--r--drivers/usb/Makefile1
-rw-r--r--drivers/usb/class/usblp.c11
-rw-r--r--drivers/usb/core/devices.c2
-rw-r--r--drivers/usb/core/devio.c21
-rw-r--r--drivers/usb/core/endpoint.c9
-rw-r--r--drivers/usb/core/hcd.c33
-rw-r--r--drivers/usb/core/hub.c34
-rw-r--r--drivers/usb/core/message.c11
-rw-r--r--drivers/usb/core/quirks.c4
-rw-r--r--drivers/usb/core/sysfs.c4
-rw-r--r--drivers/usb/core/urb.c4
-rw-r--r--drivers/usb/gadget/Kconfig1
-rw-r--r--drivers/usb/gadget/amd5536udc.c2
-rw-r--r--drivers/usb/gadget/atmel_usba_udc.c20
-rw-r--r--drivers/usb/gadget/cdc2.c8
-rw-r--r--drivers/usb/gadget/ci13xxx_udc.c3
-rw-r--r--drivers/usb/gadget/composite.c13
-rw-r--r--drivers/usb/gadget/dummy_hcd.c4
-rw-r--r--drivers/usb/gadget/epautoconf.c2
-rw-r--r--drivers/usb/gadget/ether.c8
-rw-r--r--drivers/usb/gadget/f_acm.c10
-rw-r--r--drivers/usb/gadget/f_ecm.c16
-rw-r--r--drivers/usb/gadget/f_loopback.c10
-rw-r--r--drivers/usb/gadget/f_obex.c8
-rw-r--r--drivers/usb/gadget/f_phonet.c8
-rw-r--r--drivers/usb/gadget/f_rndis.c12
-rw-r--r--drivers/usb/gadget/f_serial.c4
-rw-r--r--drivers/usb/gadget/f_sourcesink.c56
-rw-r--r--drivers/usb/gadget/f_subset.c14
-rw-r--r--drivers/usb/gadget/file_storage.c22
-rw-r--r--drivers/usb/gadget/fsl_usb2_udc.c8
-rw-r--r--drivers/usb/gadget/g_zero.h4
-rw-r--r--drivers/usb/gadget/gmidi.c23
-rw-r--r--drivers/usb/gadget/goku_udc.c8
-rw-r--r--drivers/usb/gadget/imx_udc.c248
-rw-r--r--drivers/usb/gadget/imx_udc.h49
-rw-r--r--drivers/usb/gadget/inode.c4
-rw-r--r--drivers/usb/gadget/lh7a40x_udc.c16
-rw-r--r--drivers/usb/gadget/net2280.c16
-rw-r--r--drivers/usb/gadget/printer.c18
-rw-r--r--drivers/usb/gadget/pxa27x_udc.c272
-rw-r--r--drivers/usb/gadget/pxa27x_udc.h10
-rw-r--r--drivers/usb/gadget/serial.c12
-rw-r--r--drivers/usb/gadget/u_serial.c2
-rw-r--r--drivers/usb/gadget/zero.c78
-rw-r--r--drivers/usb/host/Kconfig7
-rw-r--r--drivers/usb/host/ehci-hcd.c36
-rw-r--r--drivers/usb/host/ehci-q.c32
-rw-r--r--drivers/usb/host/ehci-sched.c2
-rw-r--r--drivers/usb/host/ehci.h39
-rw-r--r--drivers/usb/host/fhci-dbg.c2
-rw-r--r--drivers/usb/host/fhci-hcd.c4
-rw-r--r--drivers/usb/host/hwa-hc.c3
-rw-r--r--drivers/usb/host/isp116x-hcd.c2
-rw-r--r--drivers/usb/host/isp116x.h8
-rw-r--r--drivers/usb/host/isp1760-hcd.c25
-rw-r--r--drivers/usb/host/isp1760-hcd.h7
-rw-r--r--drivers/usb/host/isp1760-if.c95
-rw-r--r--drivers/usb/host/ohci-hcd.c5
-rw-r--r--drivers/usb/host/ohci-s3c2410.c6
-rw-r--r--drivers/usb/host/oxu210hp-hcd.c24
-rw-r--r--drivers/usb/host/oxu210hp.h8
-rw-r--r--drivers/usb/host/pci-quirks.c2
-rw-r--r--drivers/usb/host/r8a66597-hcd.c118
-rw-r--r--drivers/usb/host/r8a66597.h2
-rw-r--r--drivers/usb/host/sl811-hcd.c4
-rw-r--r--drivers/usb/host/uhci-debug.c4
-rw-r--r--drivers/usb/host/uhci-hcd.h10
-rw-r--r--drivers/usb/host/uhci-q.c21
-rw-r--r--drivers/usb/image/mdc800.c8
-rw-r--r--drivers/usb/misc/Kconfig39
-rw-r--r--drivers/usb/misc/Makefile4
-rw-r--r--drivers/usb/misc/ftdi-elan.c6
-rw-r--r--drivers/usb/misc/phidget.c43
-rw-r--r--drivers/usb/misc/phidget.h12
-rw-r--r--drivers/usb/misc/phidgetkit.c740
-rw-r--r--drivers/usb/misc/phidgetmotorcontrol.c465
-rw-r--r--drivers/usb/misc/phidgetservo.c375
-rw-r--r--drivers/usb/mon/mon_bin.c142
-rw-r--r--drivers/usb/musb/Kconfig6
-rw-r--r--drivers/usb/musb/davinci.c63
-rw-r--r--drivers/usb/musb/davinci.h23
-rw-r--r--drivers/usb/musb/musb_core.c2
-rw-r--r--drivers/usb/musb/musb_core.h5
-rw-r--r--drivers/usb/musb/musb_host.c140
-rw-r--r--drivers/usb/musb/musb_virthub.c2
-rw-r--r--drivers/usb/otg/Kconfig10
-rw-r--r--drivers/usb/otg/Makefile1
-rw-r--r--drivers/usb/otg/gpio_vbus.c42
-rw-r--r--drivers/usb/otg/nop-usb-xceiv.c180
-rw-r--r--drivers/usb/otg/twl4030-usb.c73
-rw-r--r--drivers/usb/serial/Kconfig28
-rw-r--r--drivers/usb/serial/Makefile4
-rw-r--r--drivers/usb/serial/ch341.c396
-rw-r--r--drivers/usb/serial/cp210x.c (renamed from drivers/usb/serial/cp2101.c)161
-rw-r--r--drivers/usb/serial/ftdi_sio.c29
-rw-r--r--drivers/usb/serial/generic.c9
-rw-r--r--drivers/usb/serial/ipaq.c43
-rw-r--r--drivers/usb/serial/keyspan.c2
-rw-r--r--drivers/usb/serial/opticon.c215
-rw-r--r--drivers/usb/serial/option.c86
-rw-r--r--drivers/usb/serial/qcserial.c147
-rw-r--r--drivers/usb/serial/symbolserial.c399
-rw-r--r--drivers/usb/serial/usb-serial.c20
-rw-r--r--drivers/usb/storage/Kconfig48
-rw-r--r--drivers/usb/storage/Makefile41
-rw-r--r--drivers/usb/storage/alauda.c192
-rw-r--r--drivers/usb/storage/alauda.h100
-rw-r--r--drivers/usb/storage/cypress_atacb.c106
-rw-r--r--drivers/usb/storage/datafab.c104
-rw-r--r--drivers/usb/storage/datafab.h40
-rw-r--r--drivers/usb/storage/freecom.c99
-rw-r--r--drivers/usb/storage/isd200.c97
-rw-r--r--drivers/usb/storage/jumpshot.c103
-rw-r--r--drivers/usb/storage/jumpshot.h39
-rw-r--r--drivers/usb/storage/karma.c100
-rw-r--r--drivers/usb/storage/karma.h7
-rw-r--r--drivers/usb/storage/libusual.c33
-rw-r--r--drivers/usb/storage/onetouch.c94
-rw-r--r--drivers/usb/storage/onetouch.h9
-rw-r--r--drivers/usb/storage/protocol.c3
-rw-r--r--drivers/usb/storage/scsiglue.c8
-rw-r--r--drivers/usb/storage/sddr09.c147
-rw-r--r--drivers/usb/storage/sddr09.h38
-rw-r--r--drivers/usb/storage/sddr55.c99
-rw-r--r--drivers/usb/storage/shuttle_usbat.c202
-rw-r--r--drivers/usb/storage/shuttle_usbat.h123
-rw-r--r--drivers/usb/storage/transport.c10
-rw-r--r--drivers/usb/storage/unusual_alauda.h (renamed from drivers/usb/storage/freecom.h)29
-rw-r--r--drivers/usb/storage/unusual_cypress.h34
-rw-r--r--drivers/usb/storage/unusual_datafab.h98
-rw-r--r--drivers/usb/storage/unusual_devs.h307
-rw-r--r--drivers/usb/storage/unusual_freecom.h (renamed from drivers/usb/storage/cypress_atacb.h)19
-rw-r--r--drivers/usb/storage/unusual_isd200.h57
-rw-r--r--drivers/usb/storage/unusual_jumpshot.h (renamed from drivers/usb/storage/sddr55.h)23
-rw-r--r--drivers/usb/storage/unusual_karma.h (renamed from drivers/usb/storage/isd200.h)21
-rw-r--r--drivers/usb/storage/unusual_onetouch.h36
-rw-r--r--drivers/usb/storage/unusual_sddr09.h56
-rw-r--r--drivers/usb/storage/unusual_sddr55.h44
-rw-r--r--drivers/usb/storage/unusual_usbat.h43
-rw-r--r--drivers/usb/storage/usb.c344
-rw-r--r--drivers/usb/storage/usb.h21
-rw-r--r--drivers/usb/storage/usual-tables.c116
-rw-r--r--drivers/usb/usb-skeleton.c6
-rw-r--r--drivers/usb/wusbcore/cbaf.c3
-rw-r--r--drivers/usb/wusbcore/devconnect.c2
-rw-r--r--drivers/usb/wusbcore/security.c2
-rw-r--r--drivers/video/au1100fb.c31
-rw-r--r--drivers/video/au1200fb.c25
-rw-r--r--drivers/video/pmag-ba-fb.c17
-rw-r--r--drivers/video/pmagb-b-fb.c17
-rw-r--r--drivers/video/ps3fb.c2
-rw-r--r--drivers/video/pvr2fb.c16
-rw-r--r--drivers/video/sh_mobile_lcdcfb.c68
-rw-r--r--drivers/video/tmiofb.c2
-rw-r--r--drivers/watchdog/rm9k_wdt.c27
-rw-r--r--drivers/zorro/zorro.c4
-rw-r--r--fs/gfs2/Kconfig17
-rw-r--r--fs/gfs2/Makefile4
-rw-r--r--fs/gfs2/acl.c1
-rw-r--r--fs/gfs2/bmap.c1
-rw-r--r--fs/gfs2/dir.c1
-rw-r--r--fs/gfs2/eaops.c1
-rw-r--r--fs/gfs2/eattr.c1
-rw-r--r--fs/gfs2/glock.c268
-rw-r--r--fs/gfs2/glock.h127
-rw-r--r--fs/gfs2/glops.c160
-rw-r--r--fs/gfs2/glops.h1
-rw-r--r--fs/gfs2/incore.h71
-rw-r--r--fs/gfs2/inode.c13
-rw-r--r--fs/gfs2/inode.h22
-rw-r--r--fs/gfs2/lock_dlm.c241
-rw-r--r--fs/gfs2/locking.c232
-rw-r--r--fs/gfs2/locking/dlm/Makefile3
-rw-r--r--fs/gfs2/locking/dlm/lock.c708
-rw-r--r--fs/gfs2/locking/dlm/lock_dlm.h166
-rw-r--r--fs/gfs2/locking/dlm/main.c48
-rw-r--r--fs/gfs2/locking/dlm/mount.c276
-rw-r--r--fs/gfs2/locking/dlm/sysfs.c226
-rw-r--r--fs/gfs2/locking/dlm/thread.c68
-rw-r--r--fs/gfs2/log.c1
-rw-r--r--fs/gfs2/lops.c1
-rw-r--r--fs/gfs2/main.c13
-rw-r--r--fs/gfs2/meta_io.c22
-rw-r--r--fs/gfs2/meta_io.h1
-rw-r--r--fs/gfs2/mount.c128
-rw-r--r--fs/gfs2/mount.h17
-rw-r--r--fs/gfs2/ops_address.c5
-rw-r--r--fs/gfs2/ops_dentry.c1
-rw-r--r--fs/gfs2/ops_export.c1
-rw-r--r--fs/gfs2/ops_file.c76
-rw-r--r--fs/gfs2/ops_fstype.c156
-rw-r--r--fs/gfs2/ops_inode.c1
-rw-r--r--fs/gfs2/ops_super.c44
-rw-r--r--fs/gfs2/quota.c203
-rw-r--r--fs/gfs2/quota.h2
-rw-r--r--fs/gfs2/recovery.c28
-rw-r--r--fs/gfs2/rgrp.c189
-rw-r--r--fs/gfs2/super.c3
-rw-r--r--fs/gfs2/super.h26
-rw-r--r--fs/gfs2/sys.c236
-rw-r--r--fs/gfs2/trans.c19
-rw-r--r--fs/gfs2/util.c11
-rw-r--r--fs/inode.c47
-rw-r--r--fs/namespace.c11
-rw-r--r--fs/partitions/check.c10
-rw-r--r--fs/sysfs/bin.c253
-rw-r--r--fs/sysfs/dir.c33
-rw-r--r--fs/sysfs/file.c26
-rw-r--r--fs/sysfs/inode.c17
-rw-r--r--fs/sysfs/mount.c6
-rw-r--r--fs/sysfs/sysfs.h3
-rw-r--r--include/asm-frv/ide.h24
-rw-r--r--include/asm-generic/vmlinux.lds.h15
-rw-r--r--include/asm-mn10300/ide.h39
-rw-r--r--include/asm-mn10300/pci.h5
-rw-r--r--include/crypto/aes.h6
-rw-r--r--include/crypto/compress.h145
-rw-r--r--include/crypto/cryptd.h27
-rw-r--r--include/crypto/crypto_wq.h7
-rw-r--r--include/crypto/hash.h5
-rw-r--r--include/crypto/internal/compress.h28
-rw-r--r--include/linux/ata.h8
-rw-r--r--include/linux/console.h4
-rw-r--r--include/linux/crypto.h4
-rw-r--r--include/linux/device.h38
-rw-r--r--include/linux/dynamic_debug.h88
-rw-r--r--include/linux/dynamic_printk.h93
-rw-r--r--include/linux/fs.h1
-rw-r--r--include/linux/ide.h78
-rw-r--r--include/linux/input.h1
-rw-r--r--include/linux/kernel.h7
-rw-r--r--include/linux/kobject.h3
-rw-r--r--include/linux/libata.h8
-rw-r--r--include/linux/lm_interface.h277
-rw-r--r--include/linux/maple.h62
-rw-r--r--include/linux/mfd/wm8350/audio.h1
-rw-r--r--include/linux/mfd/wm8400-audio.h1
-rw-r--r--include/linux/mod_devicetable.h9
-rw-r--r--include/linux/mount.h1
-rw-r--r--include/linux/pci_ids.h2
-rw-r--r--include/linux/platform_device.h7
-rw-r--r--include/linux/pm.h11
-rw-r--r--include/linux/sh_cmt.h13
-rw-r--r--include/linux/sh_intc.h1
-rw-r--r--include/linux/timeriomem-rng.h21
-rw-r--r--include/linux/uio_driver.h4
-rw-r--r--include/linux/usb.h184
-rw-r--r--include/linux/usb/ch9.h183
-rw-r--r--include/linux/usb/composite.h8
-rw-r--r--include/linux/usb/gadget.h6
-rw-r--r--include/linux/usb/otg.h8
-rw-r--r--include/linux/usb/quirks.h3
-rw-r--r--include/linux/usb/serial.h3
-rw-r--r--include/linux/usb_usual.h21
-rw-r--r--include/linux/wimax/debug.h2
-rw-r--r--include/sound/ad1816a.h2
-rw-r--r--include/sound/asound.h185
-rw-r--r--include/sound/atmel-abdac.h23
-rw-r--r--include/sound/atmel-ac97c.h40
-rw-r--r--include/sound/control.h52
-rw-r--r--include/sound/core.h36
-rw-r--r--include/sound/hwdep.h38
-rw-r--r--include/sound/jack.h5
-rw-r--r--include/sound/pcm.h3
-rw-r--r--include/sound/pxa2xx-lib.h15
-rw-r--r--include/sound/rawmidi.h1
-rw-r--r--include/sound/sb.h4
-rw-r--r--include/sound/sfnt_info.h14
-rw-r--r--include/sound/soc-dai.h2
-rw-r--r--include/sound/soc-dapm.h31
-rw-r--r--include/sound/soc.h69
-rw-r--r--include/sound/uda1341.h126
-rw-r--r--include/sound/version.h2
-rw-r--r--include/sound/wss.h1
-rw-r--r--kernel/module.c25
-rw-r--r--lib/Kconfig6
-rw-r--r--lib/Kconfig.debug74
-rw-r--r--lib/Makefile4
-rw-r--r--lib/dynamic_debug.c769
-rw-r--r--lib/dynamic_printk.c414
-rw-r--r--lib/kobject.c2
-rw-r--r--lib/kobject_uevent.c9
-rw-r--r--lib/nlattr.c (renamed from net/netlink/attr.c)20
-rw-r--r--mm/page-writeback.c4
-rw-r--r--net/Kconfig1
-rw-r--r--net/bluetooth/hci_sysfs.c2
-rw-r--r--net/bluetooth/rfcomm/tty.c5
-rw-r--r--net/netfilter/nf_conntrack_pptp.c2
-rw-r--r--net/netlink/Makefile2
-rw-r--r--scripts/Makefile.lib2
-rw-r--r--scripts/mod/file2alias.c12
-rw-r--r--sound/Kconfig2
-rw-r--r--sound/Makefile2
-rw-r--r--sound/aoa/aoa-gpio.h2
-rw-r--r--sound/aoa/core/alsa.c7
-rw-r--r--sound/aoa/core/gpio-feature.c17
-rw-r--r--sound/aoa/fabrics/layout.c81
-rw-r--r--sound/aoa/soundbus/i2sbus/core.c22
-rw-r--r--sound/arm/Kconfig11
-rw-r--r--sound/arm/Makefile3
-rw-r--r--sound/arm/aaci.c7
-rw-r--r--sound/arm/pxa2xx-ac97-lib.c71
-rw-r--r--sound/arm/pxa2xx-ac97.c7
-rw-r--r--sound/arm/sa11xx-uda1341.c983
-rw-r--r--sound/atmel/Kconfig19
-rw-r--r--sound/atmel/Makefile5
-rw-r--r--sound/atmel/abdac.c602
-rw-r--r--sound/atmel/ac97c.c932
-rw-r--r--sound/atmel/ac97c.h71
-rw-r--r--sound/core/hwdep.c9
-rw-r--r--sound/core/init.c89
-rw-r--r--sound/core/jack.c45
-rw-r--r--sound/core/misc.c10
-rw-r--r--sound/core/oss/pcm_oss.c49
-rw-r--r--sound/core/oss/pcm_plugin.h4
-rw-r--r--sound/core/pcm.c3
-rw-r--r--sound/core/pcm_lib.c155
-rw-r--r--sound/core/pcm_native.c6
-rw-r--r--sound/core/pcm_timer.c6
-rw-r--r--sound/core/rawmidi.c379
-rw-r--r--sound/core/seq/oss/seq_oss_device.h2
-rw-r--r--sound/core/seq/seq_prioq.c3
-rw-r--r--sound/core/vmaster.c62
-rw-r--r--sound/drivers/dummy.c8
-rw-r--r--sound/drivers/ml403-ac97cr.c6
-rw-r--r--sound/drivers/mpu401/mpu401.c6
-rw-r--r--sound/drivers/mtpav.c18
-rw-r--r--sound/drivers/mts64.c8
-rw-r--r--sound/drivers/opl3/opl3_lib.c2
-rw-r--r--sound/drivers/opl3/opl3_midi.c30
-rw-r--r--sound/drivers/opl3/opl3_oss.c8
-rw-r--r--sound/drivers/opl3/opl3_synth.c2
-rw-r--r--sound/drivers/pcsp/pcsp.c8
-rw-r--r--sound/drivers/portman2x4.c6
-rw-r--r--sound/drivers/serial-u16550.c24
-rw-r--r--sound/drivers/virmidi.c12
-rw-r--r--sound/drivers/vx/vx_core.c3
-rw-r--r--sound/drivers/vx/vx_hwdep.c12
-rw-r--r--sound/drivers/vx/vx_uer.c2
-rw-r--r--sound/i2c/Makefile2
-rw-r--r--sound/i2c/l3/Makefile8
-rw-r--r--sound/i2c/l3/uda1341.c935
-rw-r--r--sound/isa/Kconfig63
-rw-r--r--sound/isa/Makefile2
-rw-r--r--sound/isa/ad1816a/ad1816a.c21
-rw-r--r--sound/isa/ad1816a/ad1816a_lib.c11
-rw-r--r--sound/isa/ad1848/ad1848.c6
-rw-r--r--sound/isa/adlib.c6
-rw-r--r--sound/isa/als100.c7
-rw-r--r--sound/isa/azt2320.c7
-rw-r--r--sound/isa/cmi8330.c94
-rw-r--r--sound/isa/cs423x/Makefile8
-rw-r--r--sound/isa/cs423x/cs4231.c6
-rw-r--r--sound/isa/cs423x/cs4232.c2
-rw-r--r--sound/isa/cs423x/cs4236.c185
-rw-r--r--sound/isa/cs423x/cs4236_lib.c45
-rw-r--r--sound/isa/dt019x.c7
-rw-r--r--sound/isa/es1688/es1688.c29
-rw-r--r--sound/isa/es1688/es1688_lib.c23
-rw-r--r--sound/isa/es18xx.c24
-rw-r--r--sound/isa/gus/gus_dma.c27
-rw-r--r--sound/isa/gus/gus_irq.c6
-rw-r--r--sound/isa/gus/gus_pcm.c26
-rw-r--r--sound/isa/gus/gus_uart.c10
-rw-r--r--sound/isa/gus/gusclassic.c6
-rw-r--r--sound/isa/gus/gusextreme.c6
-rw-r--r--sound/isa/gus/gusmax.c8
-rw-r--r--sound/isa/gus/interwave.c42
-rw-r--r--sound/isa/msnd/Makefile9
-rw-r--r--sound/isa/msnd/msnd.c705
-rw-r--r--sound/isa/msnd/msnd.h308
-rw-r--r--sound/isa/msnd/msnd_classic.c3
-rw-r--r--sound/isa/msnd/msnd_classic.h129
-rw-r--r--sound/isa/msnd/msnd_midi.c180
-rw-r--r--sound/isa/msnd/msnd_pinnacle.c1238
-rw-r--r--sound/isa/msnd/msnd_pinnacle.h181
-rw-r--r--sound/isa/msnd/msnd_pinnacle_mixer.c343
-rw-r--r--sound/isa/opl3sa2.c45
-rw-r--r--sound/isa/opti9xx/miro.c7
-rw-r--r--sound/isa/opti9xx/opti92x-ad1848.c65
-rw-r--r--sound/isa/sb/es968.c7
-rw-r--r--sound/isa/sb/sb16.c28
-rw-r--r--sound/isa/sb/sb8.c8
-rw-r--r--sound/isa/sb/sb_mixer.c156
-rw-r--r--sound/isa/sc6000.c10
-rw-r--r--sound/isa/sgalaxy.c6
-rw-r--r--sound/isa/sscape.c205
-rw-r--r--sound/isa/wavefront/wavefront.c30
-rw-r--r--sound/isa/wavefront/wavefront_synth.c2
-rw-r--r--sound/isa/wss/wss_lib.c160
-rw-r--r--sound/mips/au1x00.c9
-rw-r--r--sound/mips/hal2.c6
-rw-r--r--sound/mips/sgio2audio.c6
-rw-r--r--sound/oss/ad1848.c4
-rw-r--r--sound/oss/dmabuf.c2
-rw-r--r--sound/oss/pas2_card.c4
-rw-r--r--sound/oss/pss.c12
-rw-r--r--sound/oss/sequencer.c3
-rw-r--r--sound/parisc/harmony.c6
-rw-r--r--sound/pci/Kconfig23
-rw-r--r--sound/pci/ac97/ac97_codec.c8
-rw-r--r--sound/pci/ac97/ac97_proc.c2
-rw-r--r--sound/pci/ad1889.c6
-rw-r--r--sound/pci/ak4531_codec.c3
-rw-r--r--sound/pci/ali5451/ali5451.c10
-rw-r--r--sound/pci/als300.c8
-rw-r--r--sound/pci/als4000.c9
-rw-r--r--sound/pci/atiixp.c6
-rw-r--r--sound/pci/atiixp_modem.c6
-rw-r--r--sound/pci/au88x0/au88x0.c6
-rw-r--r--sound/pci/au88x0/au88x0_a3d.c7
-rw-r--r--sound/pci/au88x0/au88x0_core.c21
-rw-r--r--sound/pci/au88x0/au88x0_synth.c39
-rw-r--r--sound/pci/aw2/aw2-alsa.c6
-rw-r--r--sound/pci/azt3328.c14
-rw-r--r--sound/pci/bt87x.c6
-rw-r--r--sound/pci/ca0106/ca0106_main.c105
-rw-r--r--sound/pci/cmipci.c6
-rw-r--r--sound/pci/cs4281.c12
-rw-r--r--sound/pci/cs46xx/cs46xx.c6
-rw-r--r--sound/pci/cs46xx/cs46xx_lib.c6
-rw-r--r--sound/pci/cs46xx/cs46xx_lib.h6
-rw-r--r--sound/pci/cs5530.c6
-rw-r--r--sound/pci/cs5535audio/cs5535audio.c8
-rw-r--r--sound/pci/echoaudio/Makefile4
-rw-r--r--sound/pci/echoaudio/echo3g_dsp.c2
-rw-r--r--sound/pci/echoaudio/echoaudio.c23
-rw-r--r--sound/pci/echoaudio/echoaudio.h3
-rw-r--r--sound/pci/echoaudio/echoaudio_3g.c3
-rw-r--r--sound/pci/echoaudio/echoaudio_dsp.c6
-rw-r--r--sound/pci/echoaudio/echoaudio_dsp.h9
-rw-r--r--sound/pci/echoaudio/gina20_dsp.c4
-rw-r--r--sound/pci/echoaudio/indigo_dsp.c12
-rw-r--r--sound/pci/echoaudio/indigo_express_dsp.c119
-rw-r--r--sound/pci/echoaudio/indigodj_dsp.c12
-rw-r--r--sound/pci/echoaudio/indigodjx.c107
-rw-r--r--sound/pci/echoaudio/indigodjx_dsp.c68
-rw-r--r--sound/pci/echoaudio/indigoio_dsp.c12
-rw-r--r--sound/pci/echoaudio/indigoiox.c109
-rw-r--r--sound/pci/echoaudio/indigoiox_dsp.c68
-rw-r--r--sound/pci/echoaudio/layla20_dsp.c4
-rw-r--r--sound/pci/echoaudio/mia_dsp.c16
-rw-r--r--sound/pci/echoaudio/midi.c4
-rw-r--r--sound/pci/emu10k1/emu10k1.c6
-rw-r--r--sound/pci/emu10k1/emu10k1_callback.c7
-rw-r--r--sound/pci/emu10k1/emu10k1_main.c11
-rw-r--r--sound/pci/emu10k1/emu10k1x.c6
-rw-r--r--sound/pci/emu10k1/emufx.c11
-rw-r--r--sound/pci/emu10k1/emupcm.c37
-rw-r--r--sound/pci/emu10k1/io.c4
-rw-r--r--sound/pci/emu10k1/p16v.c100
-rw-r--r--sound/pci/emu10k1/voice.c12
-rw-r--r--sound/pci/ens1370.c9
-rw-r--r--sound/pci/es1938.c29
-rw-r--r--sound/pci/es1968.c6
-rw-r--r--sound/pci/fm801.c6
-rw-r--r--sound/pci/hda/hda_beep.c1
-rw-r--r--sound/pci/hda/hda_beep.h2
-rw-r--r--sound/pci/hda/hda_codec.c427
-rw-r--r--sound/pci/hda/hda_codec.h19
-rw-r--r--sound/pci/hda/hda_generic.c4
-rw-r--r--sound/pci/hda/hda_hwdep.c240
-rw-r--r--sound/pci/hda/hda_intel.c121
-rw-r--r--sound/pci/hda/hda_local.h33
-rw-r--r--sound/pci/hda/hda_proc.c21
-rw-r--r--sound/pci/hda/patch_analog.c195
-rw-r--r--sound/pci/hda/patch_cmedia.c12
-rw-r--r--sound/pci/hda/patch_conexant.c368
-rw-r--r--sound/pci/hda/patch_realtek.c1194
-rw-r--r--sound/pci/hda/patch_sigmatel.c1342
-rw-r--r--sound/pci/hda/patch_via.c17
-rw-r--r--sound/pci/ice1712/ice1712.c8
-rw-r--r--sound/pci/ice1712/ice1724.c66
-rw-r--r--sound/pci/ice1712/juli.c5
-rw-r--r--sound/pci/ice1712/prodigy192.c13
-rw-r--r--sound/pci/intel8x0.c85
-rw-r--r--sound/pci/intel8x0m.c20
-rw-r--r--sound/pci/korg1212/korg1212.c6
-rw-r--r--sound/pci/maestro3.c6
-rw-r--r--sound/pci/mixart/mixart.c6
-rw-r--r--sound/pci/mixart/mixart_hwdep.c58
-rw-r--r--sound/pci/nm256/nm256.c6
-rw-r--r--sound/pci/oxygen/hifier.c12
-rw-r--r--sound/pci/oxygen/oxygen.c114
-rw-r--r--sound/pci/oxygen/oxygen.h22
-rw-r--r--sound/pci/oxygen/oxygen_io.c31
-rw-r--r--sound/pci/oxygen/oxygen_lib.c104
-rw-r--r--sound/pci/oxygen/virtuoso.c339
-rw-r--r--sound/pci/pcxhr/pcxhr.c47
-rw-r--r--sound/pci/pcxhr/pcxhr.h5
-rw-r--r--sound/pci/pcxhr/pcxhr_core.h2
-rw-r--r--sound/pci/pcxhr/pcxhr_hwdep.c12
-rw-r--r--sound/pci/pcxhr/pcxhr_mix22.c40
-rw-r--r--sound/pci/pcxhr/pcxhr_mix22.h3
-rw-r--r--sound/pci/pcxhr/pcxhr_mixer.c8
-rw-r--r--sound/pci/riptide/riptide.c6
-rw-r--r--sound/pci/rme32.c7
-rw-r--r--sound/pci/rme96.c7
-rw-r--r--sound/pci/rme9652/hdsp.c521
-rw-r--r--sound/pci/rme9652/hdspm.c17
-rw-r--r--sound/pci/rme9652/rme9652.c8
-rw-r--r--sound/pci/sis7019.c5
-rw-r--r--sound/pci/sonicvibes.c115
-rw-r--r--sound/pci/trident/trident.c6
-rw-r--r--sound/pci/trident/trident_main.c57
-rw-r--r--sound/pci/via82xx.c29
-rw-r--r--sound/pci/via82xx_modem.c11
-rw-r--r--sound/pci/vx222/vx222.c6
-rw-r--r--sound/pci/vx222/vx222_ops.c8
-rw-r--r--sound/pci/ymfpci/ymfpci.c6
-rw-r--r--sound/pci/ymfpci/ymfpci_main.c14
-rw-r--r--sound/pcmcia/pdaudiocf/pdaudiocf.c19
-rw-r--r--sound/pcmcia/pdaudiocf/pdaudiocf_core.c23
-rw-r--r--sound/pcmcia/pdaudiocf/pdaudiocf_irq.c4
-rw-r--r--sound/pcmcia/vx/vxpocket.c32
-rw-r--r--sound/ppc/Kconfig1
-rw-r--r--sound/ppc/awacs.c88
-rw-r--r--sound/ppc/burgundy.c2
-rw-r--r--sound/ppc/daca.c2
-rw-r--r--sound/ppc/pmac.c11
-rw-r--r--sound/ppc/powermac.c8
-rw-r--r--sound/ppc/snd_ps3.c6
-rw-r--r--sound/ppc/tumbler.c13
-rw-r--r--sound/sh/Kconfig1
-rw-r--r--sound/sh/aica.c8
-rw-r--r--sound/soc/Kconfig1
-rw-r--r--sound/soc/Makefile2
-rw-r--r--sound/soc/atmel/atmel-pcm.c2
-rw-r--r--sound/soc/atmel/atmel_ssc_dai.c33
-rw-r--r--sound/soc/atmel/playpaq_wm8510.c24
-rw-r--r--sound/soc/atmel/sam9g20_wm8731.c124
-rw-r--r--sound/soc/au1x/dbdma2.c2
-rw-r--r--sound/soc/au1x/psc-ac97.c10
-rw-r--r--sound/soc/au1x/psc-i2s.c12
-rw-r--r--sound/soc/blackfin/bf5xx-ac97-pcm.c2
-rw-r--r--sound/soc/blackfin/bf5xx-ac97.c94
-rw-r--r--sound/soc/blackfin/bf5xx-ad73311.c4
-rw-r--r--sound/soc/blackfin/bf5xx-i2s-pcm.c2
-rw-r--r--sound/soc/blackfin/bf5xx-i2s.c14
-rw-r--r--sound/soc/blackfin/bf5xx-sport.c104
-rw-r--r--sound/soc/codecs/Kconfig23
-rw-r--r--sound/soc/codecs/Makefile7
-rw-r--r--sound/soc/codecs/ac97.c29
-rw-r--r--sound/soc/codecs/ad1980.c33
-rw-r--r--sound/soc/codecs/ad73311.c8
-rw-r--r--sound/soc/codecs/ad73311.h2
-rw-r--r--sound/soc/codecs/ak4104.c365
-rw-r--r--sound/soc/codecs/ak4104.h7
-rw-r--r--sound/soc/codecs/ak4535.c46
-rw-r--r--sound/soc/codecs/cs4270.c667
-rw-r--r--sound/soc/codecs/pcm3008.c12
-rw-r--r--sound/soc/codecs/ssm2602.c58
-rw-r--r--sound/soc/codecs/tlv320aic23.c57
-rw-r--r--sound/soc/codecs/tlv320aic26.c29
-rw-r--r--sound/soc/codecs/tlv320aic3x.c161
-rw-r--r--sound/soc/codecs/twl4030.c524
-rw-r--r--sound/soc/codecs/twl4030.h15
-rw-r--r--sound/soc/codecs/uda134x.c84
-rw-r--r--sound/soc/codecs/uda1380.c241
-rw-r--r--sound/soc/codecs/wm8350.c166
-rw-r--r--sound/soc/codecs/wm8350.h8
-rw-r--r--sound/soc/codecs/wm8400.c1582
-rw-r--r--sound/soc/codecs/wm8400.h62
-rw-r--r--sound/soc/codecs/wm8510.c55
-rw-r--r--sound/soc/codecs/wm8580.c381
-rw-r--r--sound/soc/codecs/wm8580.h5
-rw-r--r--sound/soc/codecs/wm8728.c50
-rw-r--r--sound/soc/codecs/wm8731.c432
-rw-r--r--sound/soc/codecs/wm8731.h6
-rw-r--r--sound/soc/codecs/wm8750.c48
-rw-r--r--sound/soc/codecs/wm8753.c542
-rw-r--r--sound/soc/codecs/wm8753.h6
-rw-r--r--sound/soc/codecs/wm8900.c51
-rw-r--r--sound/soc/codecs/wm8903.c60
-rw-r--r--sound/soc/codecs/wm8971.c46
-rw-r--r--sound/soc/codecs/wm8990.c54
-rw-r--r--sound/soc/codecs/wm9705.c415
-rw-r--r--sound/soc/codecs/wm9705.h14
-rw-r--r--sound/soc/codecs/wm9712.c57
-rw-r--r--sound/soc/codecs/wm9713.c96
-rw-r--r--sound/soc/davinci/Kconfig2
-rw-r--r--sound/soc/davinci/davinci-evm.c3
-rw-r--r--sound/soc/davinci/davinci-i2s.c14
-rw-r--r--sound/soc/davinci/davinci-pcm.c2
-rw-r--r--sound/soc/davinci/davinci-sffsdr.c43
-rw-r--r--sound/soc/fsl/Kconfig17
-rw-r--r--sound/soc/fsl/Makefile7
-rw-r--r--sound/soc/fsl/fsl_dma.c181
-rw-r--r--sound/soc/fsl/fsl_ssi.c98
-rw-r--r--sound/soc/fsl/fsl_ssi.h2
-rw-r--r--sound/soc/fsl/mpc5200_psc_i2s.c20
-rw-r--r--sound/soc/fsl/mpc8610_hpcd.c5
-rw-r--r--sound/soc/omap/Kconfig14
-rw-r--r--sound/soc/omap/Makefile2
-rw-r--r--sound/soc/omap/n810.c47
-rw-r--r--sound/soc/omap/omap-mcbsp.c20
-rw-r--r--sound/soc/omap/omap-pcm.c2
-rw-r--r--sound/soc/omap/omap3pandora.c49
-rw-r--r--sound/soc/omap/osk5912.c12
-rw-r--r--sound/soc/omap/sdp3430.c115
-rw-r--r--sound/soc/pxa/Kconfig27
-rw-r--r--sound/soc/pxa/Makefile6
-rw-r--r--sound/soc/pxa/corgi.c58
-rw-r--r--sound/soc/pxa/e740_wm9705.c211
-rw-r--r--sound/soc/pxa/e750_wm9705.c187
-rw-r--r--sound/soc/pxa/e800_wm9712.c115
-rw-r--r--sound/soc/pxa/mioa701_wm9713.c250
-rw-r--r--sound/soc/pxa/palm27x.c15
-rw-r--r--sound/soc/pxa/poodle.c56
-rw-r--r--sound/soc/pxa/pxa-ssp.c150
-rw-r--r--sound/soc/pxa/pxa2xx-ac97.c59
-rw-r--r--sound/soc/pxa/pxa2xx-i2s.c54
-rw-r--r--sound/soc/pxa/spitz.c14
-rw-r--r--sound/soc/pxa/tosa.c14
-rw-r--r--sound/soc/pxa/zylonite.c132
-rw-r--r--sound/soc/s3c24xx/Kconfig29
-rw-r--r--sound/soc/s3c24xx/Makefile6
-rw-r--r--sound/soc/s3c24xx/jive_wm8750.c201
-rw-r--r--sound/soc/s3c24xx/neo1973_wm8753.c67
-rw-r--r--sound/soc/s3c24xx/s3c-i2s-v2.c638
-rw-r--r--sound/soc/s3c24xx/s3c-i2s-v2.h90
-rw-r--r--sound/soc/s3c24xx/s3c2412-i2s.c622
-rw-r--r--sound/soc/s3c24xx/s3c2412-i2s.h17
-rw-r--r--sound/soc/s3c24xx/s3c2443-ac97.c20
-rw-r--r--sound/soc/s3c24xx/s3c24xx-i2s.c71
-rw-r--r--sound/soc/s3c24xx/s3c24xx-pcm.c49
-rw-r--r--sound/soc/s3c24xx/s3c24xx_uda134x.c2
-rw-r--r--sound/soc/s3c24xx/s3c64xx-i2s.c222
-rw-r--r--sound/soc/s3c24xx/s3c64xx-i2s.h31
-rw-r--r--sound/soc/sh/hac.c12
-rw-r--r--sound/soc/sh/ssi.c30
-rw-r--r--sound/soc/soc-core.c181
-rw-r--r--sound/soc/soc-dapm.c390
-rw-r--r--sound/soc/soc-jack.c267
-rw-r--r--sound/sparc/amd7930.c12
-rw-r--r--sound/sparc/cs4231.c9
-rw-r--r--sound/sparc/dbri.c8
-rw-r--r--sound/spi/at73c213.c7
-rw-r--r--sound/synth/emux/emux_hwdep.c21
-rw-r--r--sound/synth/emux/emux_oss.c2
-rw-r--r--sound/synth/emux/emux_seq.c16
-rw-r--r--sound/synth/emux/emux_synth.c6
-rw-r--r--sound/synth/emux/soundfont.c28
-rw-r--r--sound/usb/Kconfig3
-rw-r--r--sound/usb/caiaq/caiaq-audio.c15
-rw-r--r--sound/usb/caiaq/caiaq-control.c42
-rw-r--r--sound/usb/caiaq/caiaq-device.c46
-rw-r--r--sound/usb/caiaq/caiaq-device.h6
-rw-r--r--sound/usb/usbaudio.c85
-rw-r--r--sound/usb/usbmixer.c164
-rw-r--r--sound/usb/usbmixer_maps.c26
-rw-r--r--sound/usb/usbquirks.h10
-rw-r--r--sound/usb/usx2y/us122l.c59
-rw-r--r--sound/usb/usx2y/usX2Yhwdep.c15
-rw-r--r--sound/usb/usx2y/usb_stream.c2
-rw-r--r--sound/usb/usx2y/usbusx2y.c56
-rw-r--r--sound/usb/usx2y/usx2yhwdeppcm.h2
1122 files changed, 51791 insertions, 23412 deletions
diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
index 1462ed86d40a..a3a83d38f96f 100644
--- a/Documentation/DocBook/Makefile
+++ b/Documentation/DocBook/Makefile
@@ -12,7 +12,8 @@ DOCBOOKS := z8530book.xml mcabook.xml device-drivers.xml \
12 kernel-api.xml filesystems.xml lsm.xml usb.xml kgdb.xml \ 12 kernel-api.xml filesystems.xml lsm.xml usb.xml kgdb.xml \
13 gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml \ 13 gadget.xml libata.xml mtdnand.xml librs.xml rapidio.xml \
14 genericirq.xml s390-drivers.xml uio-howto.xml scsi.xml \ 14 genericirq.xml s390-drivers.xml uio-howto.xml scsi.xml \
15 mac80211.xml debugobjects.xml sh.xml regulator.xml 15 mac80211.xml debugobjects.xml sh.xml regulator.xml \
16 alsa-driver-api.xml writing-an-alsa-driver.xml
16 17
17### 18###
18# The build process is as follows (targets): 19# The build process is as follows (targets):
diff --git a/Documentation/sound/alsa/DocBook/alsa-driver-api.tmpl b/Documentation/DocBook/alsa-driver-api.tmpl
index 9d644f7e241e..0230a96f0564 100644
--- a/Documentation/sound/alsa/DocBook/alsa-driver-api.tmpl
+++ b/Documentation/DocBook/alsa-driver-api.tmpl
@@ -1,11 +1,11 @@
1<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.1//EN"> 1<?xml version="1.0" encoding="UTF-8"?>
2 2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3<book> 3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
4<?dbhtml filename="index.html">
5 4
6<!-- ****************************************************** --> 5<!-- ****************************************************** -->
7<!-- Header --> 6<!-- Header -->
8<!-- ****************************************************** --> 7<!-- ****************************************************** -->
8<book id="ALSA-Driver-API">
9 <bookinfo> 9 <bookinfo>
10 <title>The ALSA Driver API</title> 10 <title>The ALSA Driver API</title>
11 11
@@ -35,6 +35,8 @@
35 35
36 </bookinfo> 36 </bookinfo>
37 37
38<toc></toc>
39
38 <chapter><title>Management of Cards and Devices</title> 40 <chapter><title>Management of Cards and Devices</title>
39 <sect1><title>Card Management</title> 41 <sect1><title>Card Management</title>
40!Esound/core/init.c 42!Esound/core/init.c
@@ -71,6 +73,10 @@
71!Esound/pci/ac97/ac97_codec.c 73!Esound/pci/ac97/ac97_codec.c
72!Esound/pci/ac97/ac97_pcm.c 74!Esound/pci/ac97/ac97_pcm.c
73 </sect1> 75 </sect1>
76 <sect1><title>Virtual Master Control API</title>
77!Esound/core/vmaster.c
78!Iinclude/sound/control.h
79 </sect1>
74 </chapter> 80 </chapter>
75 <chapter><title>MIDI API</title> 81 <chapter><title>MIDI API</title>
76 <sect1><title>Raw MIDI API</title> 82 <sect1><title>Raw MIDI API</title>
@@ -89,6 +95,9 @@
89 <sect1><title>Hardware-Dependent Devices API</title> 95 <sect1><title>Hardware-Dependent Devices API</title>
90!Esound/core/hwdep.c 96!Esound/core/hwdep.c
91 </sect1> 97 </sect1>
98 <sect1><title>Jack Abstraction Layer API</title>
99!Esound/core/jack.c
100 </sect1>
92 <sect1><title>ISA DMA Helpers</title> 101 <sect1><title>ISA DMA Helpers</title>
93!Esound/core/isadma.c 102!Esound/core/isadma.c
94 </sect1> 103 </sect1>
diff --git a/Documentation/DocBook/uio-howto.tmpl b/Documentation/DocBook/uio-howto.tmpl
index 52e1b79ce0e6..8f6e3b2403c7 100644
--- a/Documentation/DocBook/uio-howto.tmpl
+++ b/Documentation/DocBook/uio-howto.tmpl
@@ -42,6 +42,13 @@ GPL version 2.
42 42
43<revhistory> 43<revhistory>
44 <revision> 44 <revision>
45 <revnumber>0.8</revnumber>
46 <date>2008-12-24</date>
47 <authorinitials>hjk</authorinitials>
48 <revremark>Added name attributes in mem and portio sysfs directories.
49 </revremark>
50 </revision>
51 <revision>
45 <revnumber>0.7</revnumber> 52 <revnumber>0.7</revnumber>
46 <date>2008-12-23</date> 53 <date>2008-12-23</date>
47 <authorinitials>hjk</authorinitials> 54 <authorinitials>hjk</authorinitials>
@@ -303,12 +310,19 @@ interested in translating it, please email me
303 appear if the size of the mapping is not 0. 310 appear if the size of the mapping is not 0.
304</para> 311</para>
305<para> 312<para>
306 Each <filename>mapX/</filename> directory contains two read-only files 313 Each <filename>mapX/</filename> directory contains four read-only files
307 that show start address and size of the memory: 314 that show attributes of the memory:
308</para> 315</para>
309<itemizedlist> 316<itemizedlist>
310<listitem> 317<listitem>
311 <para> 318 <para>
319 <filename>name</filename>: A string identifier for this mapping. This
320 is optional, the string can be empty. Drivers can set this to make it
321 easier for userspace to find the correct mapping.
322 </para>
323</listitem>
324<listitem>
325 <para>
312 <filename>addr</filename>: The address of memory that can be mapped. 326 <filename>addr</filename>: The address of memory that can be mapped.
313 </para> 327 </para>
314</listitem> 328</listitem>
@@ -366,12 +380,19 @@ offset = N * getpagesize();
366 <filename>/sys/class/uio/uioX/portio/</filename>. 380 <filename>/sys/class/uio/uioX/portio/</filename>.
367</para> 381</para>
368<para> 382<para>
369 Each <filename>portX/</filename> directory contains three read-only 383 Each <filename>portX/</filename> directory contains four read-only
370 files that show start, size, and type of the port region: 384 files that show name, start, size, and type of the port region:
371</para> 385</para>
372<itemizedlist> 386<itemizedlist>
373<listitem> 387<listitem>
374 <para> 388 <para>
389 <filename>name</filename>: A string identifier for this port region.
390 The string is optional and can be empty. Drivers can set it to make it
391 easier for userspace to find a certain port region.
392 </para>
393</listitem>
394<listitem>
395 <para>
375 <filename>start</filename>: The first port of this region. 396 <filename>start</filename>: The first port of this region.
376 </para> 397 </para>
377</listitem> 398</listitem>
diff --git a/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl b/Documentation/DocBook/writing-an-alsa-driver.tmpl
index 87a7c07ab658..46b08fef3744 100644
--- a/Documentation/sound/alsa/DocBook/writing-an-alsa-driver.tmpl
+++ b/Documentation/DocBook/writing-an-alsa-driver.tmpl
@@ -1,11 +1,11 @@
1<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook V4.1//EN"> 1<?xml version="1.0" encoding="UTF-8"?>
2 2<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3<book> 3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
4<?dbhtml filename="index.html">
5 4
6<!-- ****************************************************** --> 5<!-- ****************************************************** -->
7<!-- Header --> 6<!-- Header -->
8<!-- ****************************************************** --> 7<!-- ****************************************************** -->
8<book id="Writing-an-ALSA-Driver">
9 <bookinfo> 9 <bookinfo>
10 <title>Writing an ALSA Driver</title> 10 <title>Writing an ALSA Driver</title>
11 <author> 11 <author>
@@ -492,9 +492,9 @@
492 } 492 }
493 493
494 /* (2) */ 494 /* (2) */
495 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 495 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
496 if (card == NULL) 496 if (err < 0)
497 return -ENOMEM; 497 return err;
498 498
499 /* (3) */ 499 /* (3) */
500 err = snd_mychip_create(card, pci, &chip); 500 err = snd_mychip_create(card, pci, &chip);
@@ -590,8 +590,9 @@
590 <programlisting> 590 <programlisting>
591<![CDATA[ 591<![CDATA[
592 struct snd_card *card; 592 struct snd_card *card;
593 int err;
593 .... 594 ....
594 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 595 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
595]]> 596]]>
596 </programlisting> 597 </programlisting>
597 </informalexample> 598 </informalexample>
@@ -809,26 +810,28 @@
809 810
810 <para> 811 <para>
811 As mentioned above, to create a card instance, call 812 As mentioned above, to create a card instance, call
812 <function>snd_card_new()</function>. 813 <function>snd_card_create()</function>.
813 814
814 <informalexample> 815 <informalexample>
815 <programlisting> 816 <programlisting>
816<![CDATA[ 817<![CDATA[
817 struct snd_card *card; 818 struct snd_card *card;
818 card = snd_card_new(index, id, module, extra_size); 819 int err;
820 err = snd_card_create(index, id, module, extra_size, &card);
819]]> 821]]>
820 </programlisting> 822 </programlisting>
821 </informalexample> 823 </informalexample>
822 </para> 824 </para>
823 825
824 <para> 826 <para>
825 The function takes four arguments, the card-index number, the 827 The function takes five arguments, the card-index number, the
826 id string, the module pointer (usually 828 id string, the module pointer (usually
827 <constant>THIS_MODULE</constant>), 829 <constant>THIS_MODULE</constant>),
828 and the size of extra-data space. The last argument is used to 830 the size of extra-data space, and the pointer to return the
831 card instance. The extra_size argument is used to
829 allocate card-&gt;private_data for the 832 allocate card-&gt;private_data for the
830 chip-specific data. Note that these data 833 chip-specific data. Note that these data
831 are allocated by <function>snd_card_new()</function>. 834 are allocated by <function>snd_card_create()</function>.
832 </para> 835 </para>
833 </section> 836 </section>
834 837
@@ -915,15 +918,16 @@
915 </para> 918 </para>
916 919
917 <section id="card-management-chip-specific-snd-card-new"> 920 <section id="card-management-chip-specific-snd-card-new">
918 <title>1. Allocating via <function>snd_card_new()</function>.</title> 921 <title>1. Allocating via <function>snd_card_create()</function>.</title>
919 <para> 922 <para>
920 As mentioned above, you can pass the extra-data-length 923 As mentioned above, you can pass the extra-data-length
921 to the 4th argument of <function>snd_card_new()</function>, i.e. 924 to the 4th argument of <function>snd_card_create()</function>, i.e.
922 925
923 <informalexample> 926 <informalexample>
924 <programlisting> 927 <programlisting>
925<![CDATA[ 928<![CDATA[
926 card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct mychip)); 929 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
930 sizeof(struct mychip), &card);
927]]> 931]]>
928 </programlisting> 932 </programlisting>
929 </informalexample> 933 </informalexample>
@@ -952,8 +956,8 @@
952 956
953 <para> 957 <para>
954 After allocating a card instance via 958 After allocating a card instance via
955 <function>snd_card_new()</function> (with 959 <function>snd_card_create()</function> (with
956 <constant>NULL</constant> on the 4th arg), call 960 <constant>0</constant> on the 4th arg), call
957 <function>kzalloc()</function>. 961 <function>kzalloc()</function>.
958 962
959 <informalexample> 963 <informalexample>
@@ -961,7 +965,7 @@
961<![CDATA[ 965<![CDATA[
962 struct snd_card *card; 966 struct snd_card *card;
963 struct mychip *chip; 967 struct mychip *chip;
964 card = snd_card_new(index[dev], id[dev], THIS_MODULE, NULL); 968 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
965 ..... 969 .....
966 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 970 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
967]]> 971]]>
@@ -5750,8 +5754,9 @@ struct _snd_pcm_runtime {
5750 .... 5754 ....
5751 struct snd_card *card; 5755 struct snd_card *card;
5752 struct mychip *chip; 5756 struct mychip *chip;
5757 int err;
5753 .... 5758 ....
5754 card = snd_card_new(index[dev], id[dev], THIS_MODULE, NULL); 5759 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
5755 .... 5760 ....
5756 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 5761 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
5757 .... 5762 ....
@@ -5763,7 +5768,7 @@ struct _snd_pcm_runtime {
5763 </informalexample> 5768 </informalexample>
5764 5769
5765 When you created the chip data with 5770 When you created the chip data with
5766 <function>snd_card_new()</function>, it's anyway accessible 5771 <function>snd_card_create()</function>, it's anyway accessible
5767 via <structfield>private_data</structfield> field. 5772 via <structfield>private_data</structfield> field.
5768 5773
5769 <informalexample> 5774 <informalexample>
@@ -5775,9 +5780,10 @@ struct _snd_pcm_runtime {
5775 .... 5780 ....
5776 struct snd_card *card; 5781 struct snd_card *card;
5777 struct mychip *chip; 5782 struct mychip *chip;
5783 int err;
5778 .... 5784 ....
5779 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 5785 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
5780 sizeof(struct mychip)); 5786 sizeof(struct mychip), &card);
5781 .... 5787 ....
5782 chip = card->private_data; 5788 chip = card->private_data;
5783 .... 5789 ....
diff --git a/Documentation/cpu-freq/governors.txt b/Documentation/cpu-freq/governors.txt
index 5b0cfa67aff9..ce73f3eb5ddb 100644
--- a/Documentation/cpu-freq/governors.txt
+++ b/Documentation/cpu-freq/governors.txt
@@ -117,10 +117,28 @@ accessible parameters:
117sampling_rate: measured in uS (10^-6 seconds), this is how often you 117sampling_rate: measured in uS (10^-6 seconds), this is how often you
118want the kernel to look at the CPU usage and to make decisions on 118want the kernel to look at the CPU usage and to make decisions on
119what to do about the frequency. Typically this is set to values of 119what to do about the frequency. Typically this is set to values of
120around '10000' or more. 120around '10000' or more. It's default value is (cmp. with users-guide.txt):
121 121transition_latency * 1000
122show_sampling_rate_(min|max): the minimum and maximum sampling rates 122The lowest value you can set is:
123available that you may set 'sampling_rate' to. 123transition_latency * 100 or it may get restricted to a value where it
124makes not sense for the kernel anymore to poll that often which depends
125on your HZ config variable (HZ=1000: max=20000us, HZ=250: max=5000).
126Be aware that transition latency is in ns and sampling_rate is in us, so you
127get the same sysfs value by default.
128Sampling rate should always get adjusted considering the transition latency
129To set the sampling rate 750 times as high as the transition latency
130in the bash (as said, 1000 is default), do:
131echo `$(($(cat cpuinfo_transition_latency) * 750 / 1000)) \
132 >ondemand/sampling_rate
133
134show_sampling_rate_(min|max): THIS INTERFACE IS DEPRECATED, DON'T USE IT.
135You can use wider ranges now and the general
136cpuinfo_transition_latency variable (cmp. with user-guide.txt) can be
137used to obtain exactly the same info:
138show_sampling_rate_min = transtition_latency * 500 / 1000
139show_sampling_rate_max = transtition_latency * 500000 / 1000
140(divided by 1000 is to illustrate that sampling rate is in us and
141transition latency is exported ns).
124 142
125up_threshold: defines what the average CPU usage between the samplings 143up_threshold: defines what the average CPU usage between the samplings
126of 'sampling_rate' needs to be for the kernel to make a decision on 144of 'sampling_rate' needs to be for the kernel to make a decision on
diff --git a/Documentation/cpu-freq/user-guide.txt b/Documentation/cpu-freq/user-guide.txt
index 917918f84fc7..75f41193f3e1 100644
--- a/Documentation/cpu-freq/user-guide.txt
+++ b/Documentation/cpu-freq/user-guide.txt
@@ -152,6 +152,18 @@ cpuinfo_min_freq : this file shows the minimum operating
152 frequency the processor can run at(in kHz) 152 frequency the processor can run at(in kHz)
153cpuinfo_max_freq : this file shows the maximum operating 153cpuinfo_max_freq : this file shows the maximum operating
154 frequency the processor can run at(in kHz) 154 frequency the processor can run at(in kHz)
155cpuinfo_transition_latency The time it takes on this CPU to
156 switch between two frequencies in nano
157 seconds. If unknown or known to be
158 that high that the driver does not
159 work with the ondemand governor, -1
160 (CPUFREQ_ETERNAL) will be returned.
161 Using this information can be useful
162 to choose an appropriate polling
163 frequency for a kernel governor or
164 userspace daemon. Make sure to not
165 switch the frequency too often
166 resulting in performance loss.
155scaling_driver : this file shows what cpufreq driver is 167scaling_driver : this file shows what cpufreq driver is
156 used to set the frequency on this CPU 168 used to set the frequency on this CPU
157 169
diff --git a/Documentation/dynamic-debug-howto.txt b/Documentation/dynamic-debug-howto.txt
new file mode 100644
index 000000000000..674c5663d346
--- /dev/null
+++ b/Documentation/dynamic-debug-howto.txt
@@ -0,0 +1,240 @@
1
2Introduction
3============
4
5This document describes how to use the dynamic debug (ddebug) feature.
6
7Dynamic debug is designed to allow you to dynamically enable/disable kernel
8code to obtain additional kernel information. Currently, if
9CONFIG_DYNAMIC_DEBUG is set, then all pr_debug()/dev_debug() calls can be
10dynamically enabled per-callsite.
11
12Dynamic debug has even more useful features:
13
14 * Simple query language allows turning on and off debugging statements by
15 matching any combination of:
16
17 - source filename
18 - function name
19 - line number (including ranges of line numbers)
20 - module name
21 - format string
22
23 * Provides a debugfs control file: <debugfs>/dynamic_debug/control which can be
24 read to display the complete list of known debug statements, to help guide you
25
26Controlling dynamic debug Behaviour
27===============================
28
29The behaviour of pr_debug()/dev_debug()s are controlled via writing to a
30control file in the 'debugfs' filesystem. Thus, you must first mount the debugfs
31filesystem, in order to make use of this feature. Subsequently, we refer to the
32control file as: <debugfs>/dynamic_debug/control. For example, if you want to
33enable printing from source file 'svcsock.c', line 1603 you simply do:
34
35nullarbor:~ # echo 'file svcsock.c line 1603 +p' >
36 <debugfs>/dynamic_debug/control
37
38If you make a mistake with the syntax, the write will fail thus:
39
40nullarbor:~ # echo 'file svcsock.c wtf 1 +p' >
41 <debugfs>/dynamic_debug/control
42-bash: echo: write error: Invalid argument
43
44Viewing Dynamic Debug Behaviour
45===========================
46
47You can view the currently configured behaviour of all the debug statements
48via:
49
50nullarbor:~ # cat <debugfs>/dynamic_debug/control
51# filename:lineno [module]function flags format
52/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:323 [svcxprt_rdma]svc_rdma_cleanup - "SVCRDMA Module Removed, deregister RPC RDMA transport\012"
53/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:341 [svcxprt_rdma]svc_rdma_init - "\011max_inline : %d\012"
54/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:340 [svcxprt_rdma]svc_rdma_init - "\011sq_depth : %d\012"
55/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svc_rdma.c:338 [svcxprt_rdma]svc_rdma_init - "\011max_requests : %d\012"
56...
57
58
59You can also apply standard Unix text manipulation filters to this
60data, e.g.
61
62nullarbor:~ # grep -i rdma <debugfs>/dynamic_debug/control | wc -l
6362
64
65nullarbor:~ # grep -i tcp <debugfs>/dynamic_debug/control | wc -l
6642
67
68Note in particular that the third column shows the enabled behaviour
69flags for each debug statement callsite (see below for definitions of the
70flags). The default value, no extra behaviour enabled, is "-". So
71you can view all the debug statement callsites with any non-default flags:
72
73nullarbor:~ # awk '$3 != "-"' <debugfs>/dynamic_debug/control
74# filename:lineno [module]function flags format
75/usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svcsock.c:1603 [sunrpc]svc_send p "svc_process: st_sendto returned %d\012"
76
77
78Command Language Reference
79==========================
80
81At the lexical level, a command comprises a sequence of words separated
82by whitespace characters. Note that newlines are treated as word
83separators and do *not* end a command or allow multiple commands to
84be done together. So these are all equivalent:
85
86nullarbor:~ # echo -c 'file svcsock.c line 1603 +p' >
87 <debugfs>/dynamic_debug/control
88nullarbor:~ # echo -c ' file svcsock.c line 1603 +p ' >
89 <debugfs>/dynamic_debug/control
90nullarbor:~ # echo -c 'file svcsock.c\nline 1603 +p' >
91 <debugfs>/dynamic_debug/control
92nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' >
93 <debugfs>/dynamic_debug/control
94
95Commands are bounded by a write() system call. If you want to do
96multiple commands you need to do a separate "echo" for each, like:
97
98nullarbor:~ # echo 'file svcsock.c line 1603 +p' > /proc/dprintk ;\
99> echo 'file svcsock.c line 1563 +p' > /proc/dprintk
100
101or even like:
102
103nullarbor:~ # (
104> echo 'file svcsock.c line 1603 +p' ;\
105> echo 'file svcsock.c line 1563 +p' ;\
106> ) > /proc/dprintk
107
108At the syntactical level, a command comprises a sequence of match
109specifications, followed by a flags change specification.
110
111command ::= match-spec* flags-spec
112
113The match-spec's are used to choose a subset of the known dprintk()
114callsites to which to apply the flags-spec. Think of them as a query
115with implicit ANDs between each pair. Note that an empty list of
116match-specs is possible, but is not very useful because it will not
117match any debug statement callsites.
118
119A match specification comprises a keyword, which controls the attribute
120of the callsite to be compared, and a value to compare against. Possible
121keywords are:
122
123match-spec ::= 'func' string |
124 'file' string |
125 'module' string |
126 'format' string |
127 'line' line-range
128
129line-range ::= lineno |
130 '-'lineno |
131 lineno'-' |
132 lineno'-'lineno
133// Note: line-range cannot contain space, e.g.
134// "1-30" is valid range but "1 - 30" is not.
135
136lineno ::= unsigned-int
137
138The meanings of each keyword are:
139
140func
141 The given string is compared against the function name
142 of each callsite. Example:
143
144 func svc_tcp_accept
145
146file
147 The given string is compared against either the full
148 pathname or the basename of the source file of each
149 callsite. Examples:
150
151 file svcsock.c
152 file /usr/src/packages/BUILD/sgi-enhancednfs-1.4/default/net/sunrpc/svcsock.c
153
154module
155 The given string is compared against the module name
156 of each callsite. The module name is the string as
157 seen in "lsmod", i.e. without the directory or the .ko
158 suffix and with '-' changed to '_'. Examples:
159
160 module sunrpc
161 module nfsd
162
163format
164 The given string is searched for in the dynamic debug format
165 string. Note that the string does not need to match the
166 entire format, only some part. Whitespace and other
167 special characters can be escaped using C octal character
168 escape \ooo notation, e.g. the space character is \040.
169 Alternatively, the string can be enclosed in double quote
170 characters (") or single quote characters (').
171 Examples:
172
173 format svcrdma: // many of the NFS/RDMA server dprintks
174 format readahead // some dprintks in the readahead cache
175 format nfsd:\040SETATTR // one way to match a format with whitespace
176 format "nfsd: SETATTR" // a neater way to match a format with whitespace
177 format 'nfsd: SETATTR' // yet another way to match a format with whitespace
178
179line
180 The given line number or range of line numbers is compared
181 against the line number of each dprintk() callsite. A single
182 line number matches the callsite line number exactly. A
183 range of line numbers matches any callsite between the first
184 and last line number inclusive. An empty first number means
185 the first line in the file, an empty line number means the
186 last number in the file. Examples:
187
188 line 1603 // exactly line 1603
189 line 1600-1605 // the six lines from line 1600 to line 1605
190 line -1605 // the 1605 lines from line 1 to line 1605
191 line 1600- // all lines from line 1600 to the end of the file
192
193The flags specification comprises a change operation followed
194by one or more flag characters. The change operation is one
195of the characters:
196
197-
198 remove the given flags
199
200+
201 add the given flags
202
203=
204 set the flags to the given flags
205
206The flags are:
207
208p
209 Causes a printk() message to be emitted to dmesg
210
211Note the regexp ^[-+=][scp]+$ matches a flags specification.
212Note also that there is no convenient syntax to remove all
213the flags at once, you need to use "-psc".
214
215Examples
216========
217
218// enable the message at line 1603 of file svcsock.c
219nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' >
220 <debugfs>/dynamic_debug/control
221
222// enable all the messages in file svcsock.c
223nullarbor:~ # echo -n 'file svcsock.c +p' >
224 <debugfs>/dynamic_debug/control
225
226// enable all the messages in the NFS server module
227nullarbor:~ # echo -n 'module nfsd +p' >
228 <debugfs>/dynamic_debug/control
229
230// enable all 12 messages in the function svc_process()
231nullarbor:~ # echo -n 'func svc_process +p' >
232 <debugfs>/dynamic_debug/control
233
234// disable all 12 messages in the function svc_process()
235nullarbor:~ # echo -n 'func svc_process -p' >
236 <debugfs>/dynamic_debug/control
237
238// enable messages for NFS calls READ, READLINK, READDIR and READDIR+.
239nullarbor:~ # echo -n 'format "nfsd: READ" +p' >
240 <debugfs>/dynamic_debug/control
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 224263e7711f..1a29ff3df3c5 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -1826,11 +1826,6 @@ and is between 256 and 4096 characters. It is defined in the file
1826 autoconfiguration. 1826 autoconfiguration.
1827 Ranges are in pairs (memory base and size). 1827 Ranges are in pairs (memory base and size).
1828 1828
1829 dynamic_printk Enables pr_debug()/dev_dbg() calls if
1830 CONFIG_DYNAMIC_PRINTK_DEBUG has been enabled.
1831 These can also be switched on/off via
1832 <debugfs>/dynamic_printk/modules
1833
1834 print-fatal-signals= 1829 print-fatal-signals=
1835 [KNL] debug: print fatal signals 1830 [KNL] debug: print fatal signals
1836 print-fatal-signals=1: print segfault info to 1831 print-fatal-signals=1: print segfault info to
diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt
index 841a9365d5fd..012858d2b119 100644
--- a/Documentation/sound/alsa/ALSA-Configuration.txt
+++ b/Documentation/sound/alsa/ALSA-Configuration.txt
@@ -346,6 +346,9 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
346 sbirq - IRQ # for CMI8330 chip (SB16) 346 sbirq - IRQ # for CMI8330 chip (SB16)
347 sbdma8 - 8bit DMA # for CMI8330 chip (SB16) 347 sbdma8 - 8bit DMA # for CMI8330 chip (SB16)
348 sbdma16 - 16bit DMA # for CMI8330 chip (SB16) 348 sbdma16 - 16bit DMA # for CMI8330 chip (SB16)
349 fmport - (optional) OPL3 I/O port
350 mpuport - (optional) MPU401 I/O port
351 mpuirq - (optional) MPU401 irq #
349 352
350 This module supports multiple cards and autoprobe. 353 This module supports multiple cards and autoprobe.
351 354
@@ -388,34 +391,11 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
388 391
389 The power-management is supported. 392 The power-management is supported.
390 393
391 Module snd-cs4232
392 -----------------
393
394 Module for sound cards based on CS4232/CS4232A ISA chips.
395
396 isapnp - ISA PnP detection - 0 = disable, 1 = enable (default)
397
398 with isapnp=0, the following options are available:
399
400 port - port # for CS4232 chip (PnP setup - 0x534)
401 cport - control port # for CS4232 chip (PnP setup - 0x120,0x210,0xf00)
402 mpu_port - port # for MPU-401 UART (PnP setup - 0x300), -1 = disable
403 fm_port - FM port # for CS4232 chip (PnP setup - 0x388), -1 = disable
404 irq - IRQ # for CS4232 chip (5,7,9,11,12,15)
405 mpu_irq - IRQ # for MPU-401 UART (9,11,12,15)
406 dma1 - first DMA # for CS4232 chip (0,1,3)
407 dma2 - second DMA # for Yamaha CS4232 chip (0,1,3), -1 = disable
408
409 This module supports multiple cards. This module does not support autoprobe
410 (if ISA PnP is not used) thus main port must be specified!!! Other ports are
411 optional.
412
413 The power-management is supported.
414
415 Module snd-cs4236 394 Module snd-cs4236
416 ----------------- 395 -----------------
417 396
418 Module for sound cards based on CS4235/CS4236/CS4236B/CS4237B/ 397 Module for sound cards based on CS4232/CS4232A,
398 CS4235/CS4236/CS4236B/CS4237B/
419 CS4238B/CS4239 ISA chips. 399 CS4238B/CS4239 ISA chips.
420 400
421 isapnp - ISA PnP detection - 0 = disable, 1 = enable (default) 401 isapnp - ISA PnP detection - 0 = disable, 1 = enable (default)
@@ -437,6 +417,9 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
437 417
438 The power-management is supported. 418 The power-management is supported.
439 419
420 This module is aliased as snd-cs4232 since it provides the old
421 snd-cs4232 functionality, too.
422
440 Module snd-cs4281 423 Module snd-cs4281
441 ----------------- 424 -----------------
442 425
@@ -606,6 +589,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
606 Module for ESS AudioDrive ES-1688 and ES-688 sound cards. 589 Module for ESS AudioDrive ES-1688 and ES-688 sound cards.
607 590
608 port - port # for ES-1688 chip (0x220,0x240,0x260) 591 port - port # for ES-1688 chip (0x220,0x240,0x260)
592 fm_port - port # for OPL3 (option; share the same port as default)
609 mpu_port - port # for MPU-401 port (0x300,0x310,0x320,0x330), -1 = disable (default) 593 mpu_port - port # for MPU-401 port (0x300,0x310,0x320,0x330), -1 = disable (default)
610 irq - IRQ # for ES-1688 chip (5,7,9,10) 594 irq - IRQ # for ES-1688 chip (5,7,9,10)
611 mpu_irq - IRQ # for MPU-401 port (5,7,9,10) 595 mpu_irq - IRQ # for MPU-401 port (5,7,9,10)
@@ -757,6 +741,9 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
757 model - force the model name 741 model - force the model name
758 position_fix - Fix DMA pointer (0 = auto, 1 = use LPIB, 2 = POSBUF) 742 position_fix - Fix DMA pointer (0 = auto, 1 = use LPIB, 2 = POSBUF)
759 probe_mask - Bitmask to probe codecs (default = -1, meaning all slots) 743 probe_mask - Bitmask to probe codecs (default = -1, meaning all slots)
744 When the bit 8 (0x100) is set, the lower 8 bits are used
745 as the "fixed" codec slots; i.e. the driver probes the
746 slots regardless what hardware reports back
760 probe_only - Only probing and no codec initialization (default=off); 747 probe_only - Only probing and no codec initialization (default=off);
761 Useful to check the initial codec status for debugging 748 Useful to check the initial codec status for debugging
762 bdl_pos_adj - Specifies the DMA IRQ timing delay in samples. 749 bdl_pos_adj - Specifies the DMA IRQ timing delay in samples.
@@ -1185,6 +1172,54 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
1185 1172
1186 This module supports multiple devices and PnP. 1173 This module supports multiple devices and PnP.
1187 1174
1175 Module snd-msnd-classic
1176 -----------------------
1177
1178 Module for Turtle Beach MultiSound Classic, Tahiti or Monterey
1179 soundcards.
1180
1181 io - Port # for msnd-classic card
1182 irq - IRQ # for msnd-classic card
1183 mem - Memory address (0xb0000, 0xc8000, 0xd0000, 0xd8000,
1184 0xe0000 or 0xe8000)
1185 write_ndelay - enable write ndelay (default = 1)
1186 calibrate_signal - calibrate signal (default = 0)
1187 isapnp - ISA PnP detection - 0 = disable, 1 = enable (default)
1188 digital - Digital daughterboard present (default = 0)
1189 cfg - Config port (0x250, 0x260 or 0x270) default = PnP
1190 reset - Reset all devices
1191 mpu_io - MPU401 I/O port
1192 mpu_irq - MPU401 irq#
1193 ide_io0 - IDE port #0
1194 ide_io1 - IDE port #1
1195 ide_irq - IDE irq#
1196 joystick_io - Joystick I/O port
1197
1198 The driver requires firmware files "turtlebeach/msndinit.bin" and
1199 "turtlebeach/msndperm.bin" in the proper firmware directory.
1200
1201 See Documentation/sound/oss/MultiSound for important information
1202 about this driver. Note that it has been discontinued, but the
1203 Voyetra Turtle Beach knowledge base entry for it is still available
1204 at
1205 http://www.turtlebeach.com/site/kb_ftp/790.asp
1206
1207 Module snd-msnd-pinnacle
1208 ------------------------
1209
1210 Module for Turtle Beach MultiSound Pinnacle/Fiji soundcards.
1211
1212 io - Port # for pinnacle/fiji card
1213 irq - IRQ # for pinnalce/fiji card
1214 mem - Memory address (0xb0000, 0xc8000, 0xd0000, 0xd8000,
1215 0xe0000 or 0xe8000)
1216 write_ndelay - enable write ndelay (default = 1)
1217 calibrate_signal - calibrate signal (default = 0)
1218 isapnp - ISA PnP detection - 0 = disable, 1 = enable (default)
1219
1220 The driver requires firmware files "turtlebeach/pndspini.bin" and
1221 "turtlebeach/pndsperm.bin" in the proper firmware directory.
1222
1188 Module snd-mtpav 1223 Module snd-mtpav
1189 ---------------- 1224 ----------------
1190 1225
@@ -1824,7 +1859,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
1824 ------------------- 1859 -------------------
1825 1860
1826 Module for sound cards based on the Asus AV100/AV200 chips, 1861 Module for sound cards based on the Asus AV100/AV200 chips,
1827 i.e., Xonar D1, DX, D2, D2X and HDAV1.3 (Deluxe). 1862 i.e., Xonar D1, DX, D2, D2X, HDAV1.3 (Deluxe), and Essence STX.
1828 1863
1829 This module supports autoprobe and multiple cards. 1864 This module supports autoprobe and multiple cards.
1830 1865
diff --git a/Documentation/sound/alsa/HD-Audio-Models.txt b/Documentation/sound/alsa/HD-Audio-Models.txt
index 0f5d26bea80f..8eec05bc079e 100644
--- a/Documentation/sound/alsa/HD-Audio-Models.txt
+++ b/Documentation/sound/alsa/HD-Audio-Models.txt
@@ -56,6 +56,7 @@ ALC262
56 sony-assamd Sony ASSAMD 56 sony-assamd Sony ASSAMD
57 toshiba-s06 Toshiba S06 57 toshiba-s06 Toshiba S06
58 toshiba-rx1 Toshiba RX1 58 toshiba-rx1 Toshiba RX1
59 tyan Tyan Thunder n6650W (S2915-E)
59 ultra Samsung Q1 Ultra Vista model 60 ultra Samsung Q1 Ultra Vista model
60 lenovo-3000 Lenovo 3000 y410 61 lenovo-3000 Lenovo 3000 y410
61 nec NEC Versa S9100 62 nec NEC Versa S9100
@@ -261,6 +262,8 @@ Conexant 5051
261============= 262=============
262 laptop Basic Laptop config (default) 263 laptop Basic Laptop config (default)
263 hp HP Spartan laptop 264 hp HP Spartan laptop
265 hp-dv6736 HP dv6736
266 lenovo-x200 Lenovo X200 laptop
264 267
265STAC9200 268STAC9200
266======== 269========
@@ -278,6 +281,7 @@ STAC9200
278 gateway-m4 Gateway laptops with EAPD control 281 gateway-m4 Gateway laptops with EAPD control
279 gateway-m4-2 Gateway laptops with EAPD control 282 gateway-m4-2 Gateway laptops with EAPD control
280 panasonic Panasonic CF-74 283 panasonic Panasonic CF-74
284 auto BIOS setup (default)
281 285
282STAC9205/9254 286STAC9205/9254
283============= 287=============
@@ -285,6 +289,8 @@ STAC9205/9254
285 dell-m42 Dell (unknown) 289 dell-m42 Dell (unknown)
286 dell-m43 Dell Precision 290 dell-m43 Dell Precision
287 dell-m44 Dell Inspiron 291 dell-m44 Dell Inspiron
292 eapd Keep EAPD on (e.g. Gateway T1616)
293 auto BIOS setup (default)
288 294
289STAC9220/9221 295STAC9220/9221
290============= 296=============
@@ -308,6 +314,7 @@ STAC9220/9221
308 dell-d82 Dell (unknown) 314 dell-d82 Dell (unknown)
309 dell-m81 Dell (unknown) 315 dell-m81 Dell (unknown)
310 dell-m82 Dell XPS M1210 316 dell-m82 Dell XPS M1210
317 auto BIOS setup (default)
311 318
312STAC9202/9250/9251 319STAC9202/9250/9251
313================== 320==================
@@ -319,6 +326,7 @@ STAC9202/9250/9251
319 m3 Some Gateway MX series laptops 326 m3 Some Gateway MX series laptops
320 m5 Some Gateway MX series laptops (MP6954) 327 m5 Some Gateway MX series laptops (MP6954)
321 m6 Some Gateway NX series laptops 328 m6 Some Gateway NX series laptops
329 auto BIOS setup (default)
322 330
323STAC9227/9228/9229/927x 331STAC9227/9228/9229/927x
324======================= 332=======================
@@ -328,6 +336,7 @@ STAC9227/9228/9229/927x
328 5stack D965 5stack + SPDIF 336 5stack D965 5stack + SPDIF
329 dell-3stack Dell Dimension E520 337 dell-3stack Dell Dimension E520
330 dell-bios Fixes with Dell BIOS setup 338 dell-bios Fixes with Dell BIOS setup
339 auto BIOS setup (default)
331 340
332STAC92HD71B* 341STAC92HD71B*
333============ 342============
@@ -335,7 +344,10 @@ STAC92HD71B*
335 dell-m4-1 Dell desktops 344 dell-m4-1 Dell desktops
336 dell-m4-2 Dell desktops 345 dell-m4-2 Dell desktops
337 dell-m4-3 Dell desktops 346 dell-m4-3 Dell desktops
338 hp-m4 HP dv laptops 347 hp-m4 HP mini 1000
348 hp-dv5 HP dv series
349 hp-hdx HP HDX series
350 auto BIOS setup (default)
339 351
340STAC92HD73* 352STAC92HD73*
341=========== 353===========
@@ -345,13 +357,16 @@ STAC92HD73*
345 dell-m6-dmic Dell desktops/laptops with digital mics 357 dell-m6-dmic Dell desktops/laptops with digital mics
346 dell-m6 Dell desktops/laptops with both type of mics 358 dell-m6 Dell desktops/laptops with both type of mics
347 dell-eq Dell desktops/laptops 359 dell-eq Dell desktops/laptops
360 auto BIOS setup (default)
348 361
349STAC92HD83* 362STAC92HD83*
350=========== 363===========
351 ref Reference board 364 ref Reference board
352 mic-ref Reference board with power managment for ports 365 mic-ref Reference board with power managment for ports
366 dell-s14 Dell laptop
367 auto BIOS setup (default)
353 368
354STAC9872 369STAC9872
355======== 370========
356 vaio Setup for VAIO FE550G/SZ110 371 vaio VAIO laptop without SPDIF
357 vaio-ar Setup for VAIO AR 372 auto BIOS setup (default)
diff --git a/Documentation/sound/alsa/HD-Audio.txt b/Documentation/sound/alsa/HD-Audio.txt
index 8d68fff71839..c5948f2f9a25 100644
--- a/Documentation/sound/alsa/HD-Audio.txt
+++ b/Documentation/sound/alsa/HD-Audio.txt
@@ -109,6 +109,13 @@ slot, pass `probe_mask=1`. For the first and the third slots, pass
109Since 2.6.29 kernel, the driver has a more robust probing method, so 109Since 2.6.29 kernel, the driver has a more robust probing method, so
110this error might happen rarely, though. 110this error might happen rarely, though.
111 111
112On a machine with a broken BIOS, sometimes you need to force the
113driver to probe the codec slots the hardware doesn't report for use.
114In such a case, turn the bit 8 (0x100) of `probe_mask` option on.
115Then the rest 8 bits are passed as the codec slots to probe
116unconditionally. For example, `probe_mask=0x103` will force to probe
117the codec slots 0 and 1 no matter what the hardware reports.
118
112 119
113Interrupt Handling 120Interrupt Handling
114~~~~~~~~~~~~~~~~~~ 121~~~~~~~~~~~~~~~~~~
@@ -358,10 +365,26 @@ modelname::
358 to this file. 365 to this file.
359init_verbs:: 366init_verbs::
360 The extra verbs to execute at initialization. You can add a verb by 367 The extra verbs to execute at initialization. You can add a verb by
361 writing to this file. Pass tree numbers, nid, verb and parameter. 368 writing to this file. Pass three numbers: nid, verb and parameter
369 (separated with a space).
362hints:: 370hints::
363 Shows hint strings for codec parsers for any use. Right now it's 371 Shows / stores hint strings for codec parsers for any use.
364 not used. 372 Its format is `key = value`. For example, passing `hp_detect = yes`
373 to IDT/STAC codec parser will result in the disablement of the
374 headphone detection.
375init_pin_configs::
376 Shows the initial pin default config values set by BIOS.
377driver_pin_configs::
378 Shows the pin default values set by the codec parser explicitly.
379 This doesn't show all pin values but only the changed values by
380 the parser. That is, if the parser doesn't change the pin default
381 config values by itself, this will contain nothing.
382user_pin_configs::
383 Shows the pin default config values to override the BIOS setup.
384 Writing this (with two numbers, NID and value) appends the new
385 value. The given will be used instead of the initial BIOS value at
386 the next reconfiguration time. Note that this config will override
387 even the driver pin configs, too.
365reconfig:: 388reconfig::
366 Triggers the codec re-configuration. When any value is written to 389 Triggers the codec re-configuration. When any value is written to
367 this file, the driver re-initialize and parses the codec tree 390 this file, the driver re-initialize and parses the codec tree
@@ -371,6 +394,14 @@ clear::
371 Resets the codec, removes the mixer elements and PCM stuff of the 394 Resets the codec, removes the mixer elements and PCM stuff of the
372 specified codec, and clear all init verbs and hints. 395 specified codec, and clear all init verbs and hints.
373 396
397For example, when you want to change the pin default configuration
398value of the pin widget 0x14 to 0x9993013f, and let the driver
399re-configure based on that state, run like below:
400------------------------------------------------------------------------
401 # echo 0x14 0x9993013f > /sys/class/sound/hwC0D0/user_pin_configs
402 # echo 1 > /sys/class/sound/hwC0D0/reconfig
403------------------------------------------------------------------------
404
374 405
375Power-Saving 406Power-Saving
376~~~~~~~~~~~~ 407~~~~~~~~~~~~
@@ -461,6 +492,16 @@ run with `--no-upload` option, and attach the generated file.
461There are some other useful options. See `--help` option output for 492There are some other useful options. See `--help` option output for
462details. 493details.
463 494
495When a probe error occurs or when the driver obviously assigns a
496mismatched model, it'd be helpful to load the driver with
497`probe_only=1` option (at best after the cold reboot) and run
498alsa-info at this state. With this option, the driver won't configure
499the mixer and PCM but just tries to probe the codec slot. After
500probing, the proc file is available, so you can get the raw codec
501information before modified by the driver. Of course, the driver
502isn't usable with `probe_only=1`. But you can continue the
503configuration via hwdep sysfs file if hda-reconfig option is enabled.
504
464 505
465hda-verb 506hda-verb
466~~~~~~~~ 507~~~~~~~~
diff --git a/Documentation/sound/alsa/soc/dapm.txt b/Documentation/sound/alsa/soc/dapm.txt
index 46f9684d0b29..9e6763264a2e 100644
--- a/Documentation/sound/alsa/soc/dapm.txt
+++ b/Documentation/sound/alsa/soc/dapm.txt
@@ -116,6 +116,9 @@ SOC_DAPM_SINGLE("HiFi Playback Switch", WM8731_APANA, 4, 1, 0),
116SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1, wm8731_output_mixer_controls, 116SND_SOC_DAPM_MIXER("Output Mixer", WM8731_PWR, 4, 1, wm8731_output_mixer_controls,
117 ARRAY_SIZE(wm8731_output_mixer_controls)), 117 ARRAY_SIZE(wm8731_output_mixer_controls)),
118 118
119If you dont want the mixer elements prefixed with the name of the mixer widget,
120you can use SND_SOC_DAPM_MIXER_NAMED_CTL instead. the parameters are the same
121as for SND_SOC_DAPM_MIXER.
119 122
1202.3 Platform/Machine domain Widgets 1232.3 Platform/Machine domain Widgets
121----------------------------------- 124-----------------------------------
diff --git a/Documentation/sound/oss/CS4232 b/Documentation/sound/oss/CS4232
deleted file mode 100644
index 7d6af7a5c1c2..000000000000
--- a/Documentation/sound/oss/CS4232
+++ /dev/null
@@ -1,23 +0,0 @@
1To configure the Crystal CS423x sound chip and activate its DSP functions,
2modules may be loaded in this order:
3
4 modprobe sound
5 insmod ad1848
6 insmod uart401
7 insmod cs4232 io=* irq=* dma=* dma2=*
8
9This is the meaning of the parameters:
10
11 io--I/O address of the Windows Sound System (normally 0x534)
12 irq--IRQ of this device
13 dma and dma2--DMA channels (DMA2 may be 0)
14
15On some cards, the board attempts to do non-PnP setup, and fails. If you
16have problems, use Linux' PnP facilities.
17
18To get MIDI facilities add
19
20 insmod opl3 io=*
21
22where "io" is the I/O address of the OPL3 synthesizer. This will be shown
23in /proc/sys/pnp and is normally 0x388.
diff --git a/Documentation/sound/oss/Introduction b/Documentation/sound/oss/Introduction
index f04ba6bb7395..75d967ff9266 100644
--- a/Documentation/sound/oss/Introduction
+++ b/Documentation/sound/oss/Introduction
@@ -80,7 +80,7 @@ Notes:
80 additional features. 80 additional features.
81 81
822. The commercial OSS driver may be obtained from the site: 822. The commercial OSS driver may be obtained from the site:
83 http://www/opensound.com. This may be used for cards that 83 http://www.opensound.com. This may be used for cards that
84 are unsupported by the kernel driver, or may be used 84 are unsupported by the kernel driver, or may be used
85 by other operating systems. 85 by other operating systems.
86 86
diff --git a/Documentation/usb/usbmon.txt b/Documentation/usb/usbmon.txt
index 270481906dc8..6c3c625b7f30 100644
--- a/Documentation/usb/usbmon.txt
+++ b/Documentation/usb/usbmon.txt
@@ -229,16 +229,26 @@ struct usbmon_packet {
229 int status; /* 28: */ 229 int status; /* 28: */
230 unsigned int length; /* 32: Length of data (submitted or actual) */ 230 unsigned int length; /* 32: Length of data (submitted or actual) */
231 unsigned int len_cap; /* 36: Delivered length */ 231 unsigned int len_cap; /* 36: Delivered length */
232 unsigned char setup[8]; /* 40: Only for Control 'S' */ 232 union { /* 40: */
233}; /* 48 bytes total */ 233 unsigned char setup[SETUP_LEN]; /* Only for Control S-type */
234 struct iso_rec { /* Only for ISO */
235 int error_count;
236 int numdesc;
237 } iso;
238 } s;
239 int interval; /* 48: Only for Interrupt and ISO */
240 int start_frame; /* 52: For ISO */
241 unsigned int xfer_flags; /* 56: copy of URB's transfer_flags */
242 unsigned int ndesc; /* 60: Actual number of ISO descriptors */
243}; /* 64 total length */
234 244
235These events can be received from a character device by reading with read(2), 245These events can be received from a character device by reading with read(2),
236with an ioctl(2), or by accessing the buffer with mmap. 246with an ioctl(2), or by accessing the buffer with mmap. However, read(2)
247only returns first 48 bytes for compatibility reasons.
237 248
238The character device is usually called /dev/usbmonN, where N is the USB bus 249The character device is usually called /dev/usbmonN, where N is the USB bus
239number. Number zero (/dev/usbmon0) is special and means "all buses". 250number. Number zero (/dev/usbmon0) is special and means "all buses".
240However, this feature is not implemented yet. Note that specific naming 251Note that specific naming policy is set by your Linux distribution.
241policy is set by your Linux distribution.
242 252
243If you create /dev/usbmon0 by hand, make sure that it is owned by root 253If you create /dev/usbmon0 by hand, make sure that it is owned by root
244and has mode 0600. Otherwise, unpriviledged users will be able to snoop 254and has mode 0600. Otherwise, unpriviledged users will be able to snoop
@@ -279,9 +289,10 @@ size is out of [unspecified] bounds for this kernel, the call fails with
279This call returns the current size of the buffer in bytes. 289This call returns the current size of the buffer in bytes.
280 290
281 MON_IOCX_GET, defined as _IOW(MON_IOC_MAGIC, 6, struct mon_get_arg) 291 MON_IOCX_GET, defined as _IOW(MON_IOC_MAGIC, 6, struct mon_get_arg)
292 MON_IOCX_GETX, defined as _IOW(MON_IOC_MAGIC, 10, struct mon_get_arg)
282 293
283This call waits for events to arrive if none were in the kernel buffer, 294These calls wait for events to arrive if none were in the kernel buffer,
284then returns the first event. Its argument is a pointer to the following 295then return the first event. The argument is a pointer to the following
285structure: 296structure:
286 297
287struct mon_get_arg { 298struct mon_get_arg {
@@ -294,6 +305,8 @@ Before the call, hdr, data, and alloc should be filled. Upon return, the area
294pointed by hdr contains the next event structure, and the data buffer contains 305pointed by hdr contains the next event structure, and the data buffer contains
295the data, if any. The event is removed from the kernel buffer. 306the data, if any. The event is removed from the kernel buffer.
296 307
308The MON_IOCX_GET copies 48 bytes, MON_IOCX_GETX copies 64 bytes.
309
297 MON_IOCX_MFETCH, defined as _IOWR(MON_IOC_MAGIC, 7, struct mon_mfetch_arg) 310 MON_IOCX_MFETCH, defined as _IOWR(MON_IOC_MAGIC, 7, struct mon_mfetch_arg)
298 311
299This ioctl is primarily used when the application accesses the buffer 312This ioctl is primarily used when the application accesses the buffer
diff --git a/MAINTAINERS b/MAINTAINERS
index e92ed4a79fa7..1978fb205bf7 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1269,6 +1269,12 @@ L: linux-crypto@vger.kernel.org
1269T: git kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6.git 1269T: git kernel.org:/pub/scm/linux/kernel/git/herbert/crypto-2.6.git
1270S: Maintained 1270S: Maintained
1271 1271
1272CRYPTOGRAPHIC RANDOM NUMBER GENERATOR
1273P: Neil Horman
1274M: nhorman@tuxdriver.com
1275L: linux-crypto@vger.kernel.org
1276S: Maintained
1277
1272CS5535 Audio ALSA driver 1278CS5535 Audio ALSA driver
1273P: Jaya Kumar 1279P: Jaya Kumar
1274M: jayakumar.alsa@gmail.com 1280M: jayakumar.alsa@gmail.com
diff --git a/arch/arm/mach-pxa/e740.c b/arch/arm/mach-pxa/e740.c
index 6d48e00f4f0b..a6fff782e7a8 100644
--- a/arch/arm/mach-pxa/e740.c
+++ b/arch/arm/mach-pxa/e740.c
@@ -135,6 +135,11 @@ static unsigned long e740_pin_config[] __initdata = {
135 /* IrDA */ 135 /* IrDA */
136 GPIO38_GPIO | MFP_LPM_DRIVE_HIGH, 136 GPIO38_GPIO | MFP_LPM_DRIVE_HIGH,
137 137
138 /* Audio power control */
139 GPIO16_GPIO, /* AC97 codec AVDD2 supply (analogue power) */
140 GPIO40_GPIO, /* Mic amp power */
141 GPIO41_GPIO, /* Headphone amp power */
142
138 /* PC Card */ 143 /* PC Card */
139 GPIO8_GPIO, /* CD0 */ 144 GPIO8_GPIO, /* CD0 */
140 GPIO44_GPIO, /* CD1 */ 145 GPIO44_GPIO, /* CD1 */
diff --git a/arch/arm/mach-pxa/e750.c b/arch/arm/mach-pxa/e750.c
index be1ab8edb973..665066fd280e 100644
--- a/arch/arm/mach-pxa/e750.c
+++ b/arch/arm/mach-pxa/e750.c
@@ -133,6 +133,11 @@ static unsigned long e750_pin_config[] __initdata = {
133 /* IrDA */ 133 /* IrDA */
134 GPIO38_GPIO | MFP_LPM_DRIVE_HIGH, 134 GPIO38_GPIO | MFP_LPM_DRIVE_HIGH,
135 135
136 /* Audio power control */
137 GPIO4_GPIO, /* Headphone amp power */
138 GPIO7_GPIO, /* Speaker amp power */
139 GPIO37_GPIO, /* Headphone detect */
140
136 /* PC Card */ 141 /* PC Card */
137 GPIO8_GPIO, /* CD0 */ 142 GPIO8_GPIO, /* CD0 */
138 GPIO44_GPIO, /* CD1 */ 143 GPIO44_GPIO, /* CD1 */
diff --git a/arch/arm/mach-pxa/h5000.c b/arch/arm/mach-pxa/h5000.c
index da6e4422c0f3..295ec413d804 100644
--- a/arch/arm/mach-pxa/h5000.c
+++ b/arch/arm/mach-pxa/h5000.c
@@ -153,6 +153,13 @@ static unsigned long h5000_pin_config[] __initdata = {
153 GPIO23_SSP1_SCLK, 153 GPIO23_SSP1_SCLK,
154 GPIO25_SSP1_TXD, 154 GPIO25_SSP1_TXD,
155 GPIO26_SSP1_RXD, 155 GPIO26_SSP1_RXD,
156
157 /* I2S */
158 GPIO28_I2S_BITCLK_OUT,
159 GPIO29_I2S_SDATA_IN,
160 GPIO30_I2S_SDATA_OUT,
161 GPIO31_I2S_SYNC,
162 GPIO32_I2S_SYSCLK,
156}; 163};
157 164
158/* 165/*
diff --git a/arch/arm/mach-pxa/include/mach/eseries-gpio.h b/arch/arm/mach-pxa/include/mach/eseries-gpio.h
index efbd2aa9ecec..f3e5509820d7 100644
--- a/arch/arm/mach-pxa/include/mach/eseries-gpio.h
+++ b/arch/arm/mach-pxa/include/mach/eseries-gpio.h
@@ -45,6 +45,21 @@
45/* e7xx IrDA power control */ 45/* e7xx IrDA power control */
46#define GPIO_E7XX_IR_OFF 38 46#define GPIO_E7XX_IR_OFF 38
47 47
48/* e740 audio control GPIOs */
49#define GPIO_E740_WM9705_nAVDD2 16
50#define GPIO_E740_MIC_ON 40
51#define GPIO_E740_AMP_ON 41
52
53/* e750 audio control GPIOs */
54#define GPIO_E750_HP_AMP_OFF 4
55#define GPIO_E750_SPK_AMP_OFF 7
56#define GPIO_E750_HP_DETECT 37
57
58/* e800 audio control GPIOs */
59#define GPIO_E800_HP_DETECT 81
60#define GPIO_E800_HP_AMP_OFF 82
61#define GPIO_E800_SPK_AMP_ON 83
62
48/* ASIC related GPIOs */ 63/* ASIC related GPIOs */
49#define GPIO_ESERIES_TMIO_IRQ 5 64#define GPIO_ESERIES_TMIO_IRQ 5
50#define GPIO_ESERIES_TMIO_PCLR 19 65#define GPIO_ESERIES_TMIO_PCLR 19
diff --git a/arch/arm/mach-pxa/include/mach/regs-ssp.h b/arch/arm/mach-pxa/include/mach/regs-ssp.h
index cf31986f6f05..018f6d65b57b 100644
--- a/arch/arm/mach-pxa/include/mach/regs-ssp.h
+++ b/arch/arm/mach-pxa/include/mach/regs-ssp.h
@@ -50,7 +50,7 @@
50#define SSCR0_TUM (1 << 23) /* Transmit FIFO underrun interrupt mask */ 50#define SSCR0_TUM (1 << 23) /* Transmit FIFO underrun interrupt mask */
51#define SSCR0_FRDC (0x07000000) /* Frame rate divider control (mask) */ 51#define SSCR0_FRDC (0x07000000) /* Frame rate divider control (mask) */
52#define SSCR0_SlotsPerFrm(x) (((x) - 1) << 24) /* Time slots per frame [1..8] */ 52#define SSCR0_SlotsPerFrm(x) (((x) - 1) << 24) /* Time slots per frame [1..8] */
53#define SSCR0_ADC (1 << 30) /* Audio clock select */ 53#define SSCR0_ACS (1 << 30) /* Audio clock select */
54#define SSCR0_MOD (1 << 31) /* Mode (normal or network) */ 54#define SSCR0_MOD (1 << 31) /* Mode (normal or network) */
55#endif 55#endif
56 56
@@ -109,6 +109,11 @@
109#define SSSR_TINT (1 << 19) /* Receiver Time-out Interrupt */ 109#define SSSR_TINT (1 << 19) /* Receiver Time-out Interrupt */
110#define SSSR_PINT (1 << 18) /* Peripheral Trailing Byte Interrupt */ 110#define SSSR_PINT (1 << 18) /* Peripheral Trailing Byte Interrupt */
111 111
112#if defined(CONFIG_PXA3xx)
113#define SSPSP_EDMYSTOP(x) ((x) << 28) /* Extended Dummy Stop */
114#define SSPSP_EDMYSTRT(x) ((x) << 26) /* Extended Dummy Start */
115#endif
116
112#define SSPSP_FSRT (1 << 25) /* Frame Sync Relative Timing */ 117#define SSPSP_FSRT (1 << 25) /* Frame Sync Relative Timing */
113#define SSPSP_DMYSTOP(x) ((x) << 23) /* Dummy Stop */ 118#define SSPSP_DMYSTOP(x) ((x) << 23) /* Dummy Stop */
114#define SSPSP_SFRMWDTH(x) ((x) << 16) /* Serial Frame Width */ 119#define SSPSP_SFRMWDTH(x) ((x) << 16) /* Serial Frame Width */
diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c
index 6d447c9ce8ab..0d62d311d41a 100644
--- a/arch/arm/mach-pxa/spitz.c
+++ b/arch/arm/mach-pxa/spitz.c
@@ -105,6 +105,12 @@ static unsigned long spitz_pin_config[] __initdata = {
105 GPIO57_nIOIS16, 105 GPIO57_nIOIS16,
106 GPIO104_PSKTSEL, 106 GPIO104_PSKTSEL,
107 107
108 /* I2S */
109 GPIO28_I2S_BITCLK_OUT,
110 GPIO29_I2S_SDATA_IN,
111 GPIO30_I2S_SDATA_OUT,
112 GPIO31_I2S_SYNC,
113
108 /* MMC */ 114 /* MMC */
109 GPIO32_MMC_CLK, 115 GPIO32_MMC_CLK,
110 GPIO112_MMC_CMD, 116 GPIO112_MMC_CMD,
diff --git a/arch/arm/mach-s3c2410/dma.c b/arch/arm/mach-s3c2410/dma.c
index 552b4c778fdc..440c014e24b3 100644
--- a/arch/arm/mach-s3c2410/dma.c
+++ b/arch/arm/mach-s3c2410/dma.c
@@ -28,7 +28,7 @@
28#include <mach/regs-mem.h> 28#include <mach/regs-mem.h>
29#include <mach/regs-lcd.h> 29#include <mach/regs-lcd.h>
30#include <mach/regs-sdi.h> 30#include <mach/regs-sdi.h>
31#include <asm/plat-s3c24xx/regs-iis.h> 31#include <plat/regs-iis.h>
32#include <plat/regs-spi.h> 32#include <plat/regs-spi.h>
33 33
34static struct s3c24xx_dma_map __initdata s3c2410_dma_mappings[] = { 34static struct s3c24xx_dma_map __initdata s3c2410_dma_mappings[] = {
diff --git a/arch/arm/mach-s3c2410/usb-simtec.c b/arch/arm/mach-s3c2410/usb-simtec.c
index 6078f09b7df5..8331e8d97e20 100644
--- a/arch/arm/mach-s3c2410/usb-simtec.c
+++ b/arch/arm/mach-s3c2410/usb-simtec.c
@@ -29,13 +29,14 @@
29 29
30#include <mach/bast-map.h> 30#include <mach/bast-map.h>
31#include <mach/bast-irq.h> 31#include <mach/bast-irq.h>
32#include <mach/usb-control.h>
33#include <mach/regs-gpio.h> 32#include <mach/regs-gpio.h>
34 33
35#include <mach/hardware.h> 34#include <mach/hardware.h>
36#include <asm/irq.h> 35#include <asm/irq.h>
37 36
37#include <plat/usb-control.h>
38#include <plat/devs.h> 38#include <plat/devs.h>
39
39#include "usb-simtec.h" 40#include "usb-simtec.h"
40 41
41/* control power and monitor over-current events on various Simtec 42/* control power and monitor over-current events on various Simtec
diff --git a/arch/arm/mach-s3c2412/dma.c b/arch/arm/mach-s3c2412/dma.c
index 919856c9433f..9e3478506c6f 100644
--- a/arch/arm/mach-s3c2412/dma.c
+++ b/arch/arm/mach-s3c2412/dma.c
@@ -29,8 +29,8 @@
29#include <mach/regs-mem.h> 29#include <mach/regs-mem.h>
30#include <mach/regs-lcd.h> 30#include <mach/regs-lcd.h>
31#include <mach/regs-sdi.h> 31#include <mach/regs-sdi.h>
32#include <asm/plat-s3c24xx/regs-s3c2412-iis.h> 32#include <plat/regs-s3c2412-iis.h>
33#include <asm/plat-s3c24xx/regs-iis.h> 33#include <plat/regs-iis.h>
34#include <plat/regs-spi.h> 34#include <plat/regs-spi.h>
35 35
36#define MAP(x) { (x)| DMA_CH_VALID, (x)| DMA_CH_VALID, (x)| DMA_CH_VALID, (x)| DMA_CH_VALID } 36#define MAP(x) { (x)| DMA_CH_VALID, (x)| DMA_CH_VALID, (x)| DMA_CH_VALID, (x)| DMA_CH_VALID }
diff --git a/arch/arm/mach-s3c2440/dma.c b/arch/arm/mach-s3c2440/dma.c
index 5b5ee0b8f4e0..69b6cf34df47 100644
--- a/arch/arm/mach-s3c2440/dma.c
+++ b/arch/arm/mach-s3c2440/dma.c
@@ -28,7 +28,7 @@
28#include <mach/regs-mem.h> 28#include <mach/regs-mem.h>
29#include <mach/regs-lcd.h> 29#include <mach/regs-lcd.h>
30#include <mach/regs-sdi.h> 30#include <mach/regs-sdi.h>
31#include <asm/plat-s3c24xx/regs-iis.h> 31#include <plat/regs-iis.h>
32#include <plat/regs-spi.h> 32#include <plat/regs-spi.h>
33 33
34static struct s3c24xx_dma_map __initdata s3c2440_dma_mappings[] = { 34static struct s3c24xx_dma_map __initdata s3c2440_dma_mappings[] = {
diff --git a/arch/arm/mach-s3c2443/dma.c b/arch/arm/mach-s3c2443/dma.c
index 2a58a4d5aa5a..8430e5829186 100644
--- a/arch/arm/mach-s3c2443/dma.c
+++ b/arch/arm/mach-s3c2443/dma.c
@@ -29,7 +29,7 @@
29#include <mach/regs-mem.h> 29#include <mach/regs-mem.h>
30#include <mach/regs-lcd.h> 30#include <mach/regs-lcd.h>
31#include <mach/regs-sdi.h> 31#include <mach/regs-sdi.h>
32#include <asm/plat-s3c24xx/regs-iis.h> 32#include <plat/regs-iis.h>
33#include <plat/regs-spi.h> 33#include <plat/regs-spi.h>
34 34
35#define MAP(x) { \ 35#define MAP(x) { \
diff --git a/arch/arm/mach-s3c2410/include/mach/audio.h b/arch/arm/plat-s3c/include/plat/audio.h
index de0e8da48bc3..de0e8da48bc3 100644
--- a/arch/arm/mach-s3c2410/include/mach/audio.h
+++ b/arch/arm/plat-s3c/include/plat/audio.h
diff --git a/include/asm-arm/plat-s3c24xx/regs-s3c2412-iis.h b/arch/arm/plat-s3c/include/plat/regs-s3c2412-iis.h
index 25d4058bcfed..0fad7571030e 100644
--- a/include/asm-arm/plat-s3c24xx/regs-s3c2412-iis.h
+++ b/arch/arm/plat-s3c/include/plat/regs-s3c2412-iis.h
@@ -33,6 +33,9 @@
33#define S3C2412_IISCON_RXDMA_ACTIVE (1 << 1) 33#define S3C2412_IISCON_RXDMA_ACTIVE (1 << 1)
34#define S3C2412_IISCON_IIS_ACTIVE (1 << 0) 34#define S3C2412_IISCON_IIS_ACTIVE (1 << 0)
35 35
36#define S3C64XX_IISMOD_IMS_PCLK (0 << 10)
37#define S3C64XX_IISMOD_IMS_SYSMUX (1 << 10)
38
36#define S3C2412_IISMOD_MASTER_INTERNAL (0 << 10) 39#define S3C2412_IISMOD_MASTER_INTERNAL (0 << 10)
37#define S3C2412_IISMOD_MASTER_EXTERNAL (1 << 10) 40#define S3C2412_IISMOD_MASTER_EXTERNAL (1 << 10)
38#define S3C2412_IISMOD_SLAVE (2 << 10) 41#define S3C2412_IISMOD_SLAVE (2 << 10)
@@ -44,8 +47,8 @@
44#define S3C2412_IISMOD_LR_LLOW (0 << 7) 47#define S3C2412_IISMOD_LR_LLOW (0 << 7)
45#define S3C2412_IISMOD_LR_RLOW (1 << 7) 48#define S3C2412_IISMOD_LR_RLOW (1 << 7)
46#define S3C2412_IISMOD_SDF_IIS (0 << 5) 49#define S3C2412_IISMOD_SDF_IIS (0 << 5)
47#define S3C2412_IISMOD_SDF_MSB (0 << 5) 50#define S3C2412_IISMOD_SDF_MSB (1 << 5)
48#define S3C2412_IISMOD_SDF_LSB (0 << 5) 51#define S3C2412_IISMOD_SDF_LSB (2 << 5)
49#define S3C2412_IISMOD_SDF_MASK (3 << 5) 52#define S3C2412_IISMOD_SDF_MASK (3 << 5)
50#define S3C2412_IISMOD_RCLK_256FS (0 << 3) 53#define S3C2412_IISMOD_RCLK_256FS (0 << 3)
51#define S3C2412_IISMOD_RCLK_512FS (1 << 3) 54#define S3C2412_IISMOD_RCLK_512FS (1 << 3)
diff --git a/arch/arm/mach-s3c2410/include/mach/usb-control.h b/arch/arm/plat-s3c/include/plat/usb-control.h
index cd91d1591f31..822c87fe948e 100644
--- a/arch/arm/mach-s3c2410/include/mach/usb-control.h
+++ b/arch/arm/plat-s3c/include/plat/usb-control.h
@@ -1,9 +1,9 @@
1/* arch/arm/mach-s3c2410/include/mach/usb-control.h 1/* arch/arm/plat-s3c/include/plat/usb-control.h
2 * 2 *
3 * Copyright (c) 2004 Simtec Electronics 3 * Copyright (c) 2004 Simtec Electronics
4 * Ben Dooks <ben@simtec.co.uk> 4 * Ben Dooks <ben@simtec.co.uk>
5 * 5 *
6 * S3C2410 - usb port information 6 * S3C - USB host port information
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as 9 * it under the terms of the GNU General Public License version 2 as
@@ -11,7 +11,7 @@
11*/ 11*/
12 12
13#ifndef __ASM_ARCH_USBCONTROL_H 13#ifndef __ASM_ARCH_USBCONTROL_H
14#define __ASM_ARCH_USBCONTROL_H "arch/arm/mach-s3c2410/include/mach/usb-control.h" 14#define __ASM_ARCH_USBCONTROL_H
15 15
16#define S3C_HCDFLG_USED (1) 16#define S3C_HCDFLG_USED (1)
17 17
diff --git a/include/asm-arm/plat-s3c24xx/regs-iis.h b/arch/arm/plat-s3c24xx/include/plat/regs-iis.h
index a6f1d5df13b4..a6f1d5df13b4 100644
--- a/include/asm-arm/plat-s3c24xx/regs-iis.h
+++ b/arch/arm/plat-s3c24xx/include/plat/regs-iis.h
diff --git a/arch/avr32/boards/hammerhead/flash.c b/arch/avr32/boards/hammerhead/flash.c
index a98c6dd3a028..559bbcb03f9b 100644
--- a/arch/avr32/boards/hammerhead/flash.c
+++ b/arch/avr32/boards/hammerhead/flash.c
@@ -15,7 +15,6 @@
15#include <linux/mtd/physmap.h> 15#include <linux/mtd/physmap.h>
16#include <linux/usb/isp116x.h> 16#include <linux/usb/isp116x.h>
17#include <linux/dma-mapping.h> 17#include <linux/dma-mapping.h>
18#include <linux/platform_device.h>
19#include <linux/delay.h> 18#include <linux/delay.h>
20 19
21#include <mach/portmux.h> 20#include <mach/portmux.h>
diff --git a/arch/avr32/include/asm/uaccess.h b/arch/avr32/include/asm/uaccess.h
index ed092395215e..245b2ee213c9 100644
--- a/arch/avr32/include/asm/uaccess.h
+++ b/arch/avr32/include/asm/uaccess.h
@@ -230,10 +230,10 @@ extern int __put_user_bad(void);
230 asm volatile( \ 230 asm volatile( \
231 "1: ld." suffix " %1, %3 \n" \ 231 "1: ld." suffix " %1, %3 \n" \
232 "2: \n" \ 232 "2: \n" \
233 " .section .fixup, \"ax\" \n" \ 233 " .subsection 1 \n" \
234 "3: mov %0, %4 \n" \ 234 "3: mov %0, %4 \n" \
235 " rjmp 2b \n" \ 235 " rjmp 2b \n" \
236 " .previous \n" \ 236 " .subsection 0 \n" \
237 " .section __ex_table, \"a\" \n" \ 237 " .section __ex_table, \"a\" \n" \
238 " .long 1b, 3b \n" \ 238 " .long 1b, 3b \n" \
239 " .previous \n" \ 239 " .previous \n" \
@@ -295,10 +295,10 @@ extern int __put_user_bad(void);
295 asm volatile( \ 295 asm volatile( \
296 "1: st." suffix " %1, %3 \n" \ 296 "1: st." suffix " %1, %3 \n" \
297 "2: \n" \ 297 "2: \n" \
298 " .section .fixup, \"ax\" \n" \ 298 " .subsection 1 \n" \
299 "3: mov %0, %4 \n" \ 299 "3: mov %0, %4 \n" \
300 " rjmp 2b \n" \ 300 " rjmp 2b \n" \
301 " .previous \n" \ 301 " .subsection 0 \n" \
302 " .section __ex_table, \"a\" \n" \ 302 " .section __ex_table, \"a\" \n" \
303 " .long 1b, 3b \n" \ 303 " .long 1b, 3b \n" \
304 " .previous \n" \ 304 " .previous \n" \
diff --git a/arch/avr32/kernel/entry-avr32b.S b/arch/avr32/kernel/entry-avr32b.S
index 33d49377b8be..009a80155d67 100644
--- a/arch/avr32/kernel/entry-avr32b.S
+++ b/arch/avr32/kernel/entry-avr32b.S
@@ -150,10 +150,10 @@ page_not_present:
150 tlbmiss_restore 150 tlbmiss_restore
151 sub sp, 4 151 sub sp, 4
152 stmts --sp, r0-lr 152 stmts --sp, r0-lr
153 rcall save_full_context_ex 153 call save_full_context_ex
154 mfsr r12, SYSREG_ECR 154 mfsr r12, SYSREG_ECR
155 mov r11, sp 155 mov r11, sp
156 rcall do_page_fault 156 call do_page_fault
157 rjmp ret_from_exception 157 rjmp ret_from_exception
158 158
159 .align 2 159 .align 2
@@ -250,7 +250,7 @@ syscall_badsys:
250 250
251 .global ret_from_fork 251 .global ret_from_fork
252ret_from_fork: 252ret_from_fork:
253 rcall schedule_tail 253 call schedule_tail
254 254
255 /* check for syscall tracing */ 255 /* check for syscall tracing */
256 get_thread_info r0 256 get_thread_info r0
@@ -261,7 +261,7 @@ ret_from_fork:
261 261
262syscall_trace_enter: 262syscall_trace_enter:
263 pushm r8-r12 263 pushm r8-r12
264 rcall syscall_trace 264 call syscall_trace
265 popm r8-r12 265 popm r8-r12
266 rjmp syscall_trace_cont 266 rjmp syscall_trace_cont
267 267
@@ -269,14 +269,14 @@ syscall_exit_work:
269 bld r1, TIF_SYSCALL_TRACE 269 bld r1, TIF_SYSCALL_TRACE
270 brcc 1f 270 brcc 1f
271 unmask_interrupts 271 unmask_interrupts
272 rcall syscall_trace 272 call syscall_trace
273 mask_interrupts 273 mask_interrupts
274 ld.w r1, r0[TI_flags] 274 ld.w r1, r0[TI_flags]
275 275
2761: bld r1, TIF_NEED_RESCHED 2761: bld r1, TIF_NEED_RESCHED
277 brcc 2f 277 brcc 2f
278 unmask_interrupts 278 unmask_interrupts
279 rcall schedule 279 call schedule
280 mask_interrupts 280 mask_interrupts
281 ld.w r1, r0[TI_flags] 281 ld.w r1, r0[TI_flags]
282 rjmp 1b 282 rjmp 1b
@@ -287,7 +287,7 @@ syscall_exit_work:
287 unmask_interrupts 287 unmask_interrupts
288 mov r12, sp 288 mov r12, sp
289 mov r11, r0 289 mov r11, r0
290 rcall do_notify_resume 290 call do_notify_resume
291 mask_interrupts 291 mask_interrupts
292 ld.w r1, r0[TI_flags] 292 ld.w r1, r0[TI_flags]
293 rjmp 1b 293 rjmp 1b
@@ -394,7 +394,7 @@ handle_critical:
394 394
395 mfsr r12, SYSREG_ECR 395 mfsr r12, SYSREG_ECR
396 mov r11, sp 396 mov r11, sp
397 rcall do_critical_exception 397 call do_critical_exception
398 398
399 /* We should never get here... */ 399 /* We should never get here... */
400bad_return: 400bad_return:
@@ -407,18 +407,18 @@ bad_return:
407do_bus_error_write: 407do_bus_error_write:
408 sub sp, 4 408 sub sp, 4
409 stmts --sp, r0-lr 409 stmts --sp, r0-lr
410 rcall save_full_context_ex 410 call save_full_context_ex
411 mov r11, 1 411 mov r11, 1
412 rjmp 1f 412 rjmp 1f
413 413
414do_bus_error_read: 414do_bus_error_read:
415 sub sp, 4 415 sub sp, 4
416 stmts --sp, r0-lr 416 stmts --sp, r0-lr
417 rcall save_full_context_ex 417 call save_full_context_ex
418 mov r11, 0 418 mov r11, 0
4191: mfsr r12, SYSREG_BEAR 4191: mfsr r12, SYSREG_BEAR
420 mov r10, sp 420 mov r10, sp
421 rcall do_bus_error 421 call do_bus_error
422 rjmp ret_from_exception 422 rjmp ret_from_exception
423 423
424 .align 1 424 .align 1
@@ -433,7 +433,7 @@ do_nmi_ll:
4331: pushm r8, r9 /* PC and SR */ 4331: pushm r8, r9 /* PC and SR */
434 mfsr r12, SYSREG_ECR 434 mfsr r12, SYSREG_ECR
435 mov r11, sp 435 mov r11, sp
436 rcall do_nmi 436 call do_nmi
437 popm r8-r9 437 popm r8-r9
438 mtsr SYSREG_RAR_NMI, r8 438 mtsr SYSREG_RAR_NMI, r8
439 tst r0, r0 439 tst r0, r0
@@ -457,29 +457,29 @@ do_nmi_ll:
457handle_address_fault: 457handle_address_fault:
458 sub sp, 4 458 sub sp, 4
459 stmts --sp, r0-lr 459 stmts --sp, r0-lr
460 rcall save_full_context_ex 460 call save_full_context_ex
461 mfsr r12, SYSREG_ECR 461 mfsr r12, SYSREG_ECR
462 mov r11, sp 462 mov r11, sp
463 rcall do_address_exception 463 call do_address_exception
464 rjmp ret_from_exception 464 rjmp ret_from_exception
465 465
466handle_protection_fault: 466handle_protection_fault:
467 sub sp, 4 467 sub sp, 4
468 stmts --sp, r0-lr 468 stmts --sp, r0-lr
469 rcall save_full_context_ex 469 call save_full_context_ex
470 mfsr r12, SYSREG_ECR 470 mfsr r12, SYSREG_ECR
471 mov r11, sp 471 mov r11, sp
472 rcall do_page_fault 472 call do_page_fault
473 rjmp ret_from_exception 473 rjmp ret_from_exception
474 474
475 .align 1 475 .align 1
476do_illegal_opcode_ll: 476do_illegal_opcode_ll:
477 sub sp, 4 477 sub sp, 4
478 stmts --sp, r0-lr 478 stmts --sp, r0-lr
479 rcall save_full_context_ex 479 call save_full_context_ex
480 mfsr r12, SYSREG_ECR 480 mfsr r12, SYSREG_ECR
481 mov r11, sp 481 mov r11, sp
482 rcall do_illegal_opcode 482 call do_illegal_opcode
483 rjmp ret_from_exception 483 rjmp ret_from_exception
484 484
485do_dtlb_modified: 485do_dtlb_modified:
@@ -513,11 +513,11 @@ do_dtlb_modified:
513do_fpe_ll: 513do_fpe_ll:
514 sub sp, 4 514 sub sp, 4
515 stmts --sp, r0-lr 515 stmts --sp, r0-lr
516 rcall save_full_context_ex 516 call save_full_context_ex
517 unmask_interrupts 517 unmask_interrupts
518 mov r12, 26 518 mov r12, 26
519 mov r11, sp 519 mov r11, sp
520 rcall do_fpe 520 call do_fpe
521 rjmp ret_from_exception 521 rjmp ret_from_exception
522 522
523ret_from_exception: 523ret_from_exception:
@@ -553,7 +553,7 @@ fault_resume_kernel:
553 lddsp r4, sp[REG_SR] 553 lddsp r4, sp[REG_SR]
554 bld r4, SYSREG_GM_OFFSET 554 bld r4, SYSREG_GM_OFFSET
555 brcs 1f 555 brcs 1f
556 rcall preempt_schedule_irq 556 call preempt_schedule_irq
5571: 5571:
558#endif 558#endif
559 559
@@ -582,7 +582,7 @@ fault_exit_work:
582 bld r1, TIF_NEED_RESCHED 582 bld r1, TIF_NEED_RESCHED
583 brcc 1f 583 brcc 1f
584 unmask_interrupts 584 unmask_interrupts
585 rcall schedule 585 call schedule
586 mask_interrupts 586 mask_interrupts
587 ld.w r1, r0[TI_flags] 587 ld.w r1, r0[TI_flags]
588 rjmp fault_exit_work 588 rjmp fault_exit_work
@@ -593,7 +593,7 @@ fault_exit_work:
593 unmask_interrupts 593 unmask_interrupts
594 mov r12, sp 594 mov r12, sp
595 mov r11, r0 595 mov r11, r0
596 rcall do_notify_resume 596 call do_notify_resume
597 mask_interrupts 597 mask_interrupts
598 ld.w r1, r0[TI_flags] 598 ld.w r1, r0[TI_flags]
599 rjmp fault_exit_work 599 rjmp fault_exit_work
@@ -616,10 +616,10 @@ handle_debug:
616 616
617.Ldebug_fixup_cont: 617.Ldebug_fixup_cont:
618#ifdef CONFIG_TRACE_IRQFLAGS 618#ifdef CONFIG_TRACE_IRQFLAGS
619 rcall trace_hardirqs_off 619 call trace_hardirqs_off
620#endif 620#endif
621 mov r12, sp 621 mov r12, sp
622 rcall do_debug 622 call do_debug
623 mov sp, r12 623 mov sp, r12
624 624
625 lddsp r2, sp[REG_SR] 625 lddsp r2, sp[REG_SR]
@@ -643,7 +643,7 @@ handle_debug:
643 mtsr SYSREG_RSR_DBG, r11 643 mtsr SYSREG_RSR_DBG, r11
644 mtsr SYSREG_RAR_DBG, r10 644 mtsr SYSREG_RAR_DBG, r10
645#ifdef CONFIG_TRACE_IRQFLAGS 645#ifdef CONFIG_TRACE_IRQFLAGS
646 rcall trace_hardirqs_on 646 call trace_hardirqs_on
6471: 6471:
648#endif 648#endif
649 ldmts sp++, r0-lr 649 ldmts sp++, r0-lr
@@ -676,7 +676,7 @@ debug_resume_kernel:
676#ifdef CONFIG_TRACE_IRQFLAGS 676#ifdef CONFIG_TRACE_IRQFLAGS
677 bld r11, SYSREG_GM_OFFSET 677 bld r11, SYSREG_GM_OFFSET
678 brcc 1f 678 brcc 1f
679 rcall trace_hardirqs_on 679 call trace_hardirqs_on
6801: 6801:
681#endif 681#endif
682 mfsr r2, SYSREG_SR 682 mfsr r2, SYSREG_SR
@@ -747,7 +747,7 @@ irq_level\level:
747 mov r11, sp 747 mov r11, sp
748 mov r12, \level 748 mov r12, \level
749 749
750 rcall do_IRQ 750 call do_IRQ
751 751
752 lddsp r4, sp[REG_SR] 752 lddsp r4, sp[REG_SR]
753 bfextu r4, r4, SYSREG_M0_OFFSET, 3 753 bfextu r4, r4, SYSREG_M0_OFFSET, 3
@@ -767,7 +767,7 @@ irq_level\level:
767 767
7681: 7681:
769#ifdef CONFIG_TRACE_IRQFLAGS 769#ifdef CONFIG_TRACE_IRQFLAGS
770 rcall trace_hardirqs_on 770 call trace_hardirqs_on
771#endif 771#endif
772 popm r8-r9 772 popm r8-r9
773 mtsr rar_int\level, r8 773 mtsr rar_int\level, r8
@@ -807,7 +807,7 @@ irq_level\level:
807 lddsp r4, sp[REG_SR] 807 lddsp r4, sp[REG_SR]
808 bld r4, SYSREG_GM_OFFSET 808 bld r4, SYSREG_GM_OFFSET
809 brcs 1b 809 brcs 1b
810 rcall preempt_schedule_irq 810 call preempt_schedule_irq
811#endif 811#endif
812 rjmp 1b 812 rjmp 1b
813 .endm 813 .endm
diff --git a/arch/avr32/kernel/syscall-stubs.S b/arch/avr32/kernel/syscall-stubs.S
index 673178e235f3..f7244cd02fbb 100644
--- a/arch/avr32/kernel/syscall-stubs.S
+++ b/arch/avr32/kernel/syscall-stubs.S
@@ -61,7 +61,7 @@ __sys_execve:
61__sys_mmap2: 61__sys_mmap2:
62 pushm lr 62 pushm lr
63 st.w --sp, ARG6 63 st.w --sp, ARG6
64 rcall sys_mmap2 64 call sys_mmap2
65 sub sp, -4 65 sub sp, -4
66 popm pc 66 popm pc
67 67
@@ -70,7 +70,7 @@ __sys_mmap2:
70__sys_sendto: 70__sys_sendto:
71 pushm lr 71 pushm lr
72 st.w --sp, ARG6 72 st.w --sp, ARG6
73 rcall sys_sendto 73 call sys_sendto
74 sub sp, -4 74 sub sp, -4
75 popm pc 75 popm pc
76 76
@@ -79,7 +79,7 @@ __sys_sendto:
79__sys_recvfrom: 79__sys_recvfrom:
80 pushm lr 80 pushm lr
81 st.w --sp, ARG6 81 st.w --sp, ARG6
82 rcall sys_recvfrom 82 call sys_recvfrom
83 sub sp, -4 83 sub sp, -4
84 popm pc 84 popm pc
85 85
@@ -88,7 +88,7 @@ __sys_recvfrom:
88__sys_pselect6: 88__sys_pselect6:
89 pushm lr 89 pushm lr
90 st.w --sp, ARG6 90 st.w --sp, ARG6
91 rcall sys_pselect6 91 call sys_pselect6
92 sub sp, -4 92 sub sp, -4
93 popm pc 93 popm pc
94 94
@@ -97,7 +97,7 @@ __sys_pselect6:
97__sys_splice: 97__sys_splice:
98 pushm lr 98 pushm lr
99 st.w --sp, ARG6 99 st.w --sp, ARG6
100 rcall sys_splice 100 call sys_splice
101 sub sp, -4 101 sub sp, -4
102 popm pc 102 popm pc
103 103
@@ -106,7 +106,7 @@ __sys_splice:
106__sys_epoll_pwait: 106__sys_epoll_pwait:
107 pushm lr 107 pushm lr
108 st.w --sp, ARG6 108 st.w --sp, ARG6
109 rcall sys_epoll_pwait 109 call sys_epoll_pwait
110 sub sp, -4 110 sub sp, -4
111 popm pc 111 popm pc
112 112
@@ -115,6 +115,6 @@ __sys_epoll_pwait:
115__sys_sync_file_range: 115__sys_sync_file_range:
116 pushm lr 116 pushm lr
117 st.w --sp, ARG6 117 st.w --sp, ARG6
118 rcall sys_sync_file_range 118 call sys_sync_file_range
119 sub sp, -4 119 sub sp, -4
120 popm pc 120 popm pc
diff --git a/arch/avr32/lib/strnlen_user.S b/arch/avr32/lib/strnlen_user.S
index 65ce11afa66a..e46f4724962b 100644
--- a/arch/avr32/lib/strnlen_user.S
+++ b/arch/avr32/lib/strnlen_user.S
@@ -48,7 +48,7 @@ adjust_length:
48 lddpc lr, _task_size 48 lddpc lr, _task_size
49 sub r11, lr, r12 49 sub r11, lr, r12
50 mov r9, r11 50 mov r9, r11
51 rcall __strnlen_user 51 call __strnlen_user
52 cp.w r12, r9 52 cp.w r12, r9
53 brgt 1f 53 brgt 1f
54 popm pc 54 popm pc
diff --git a/arch/mips/basler/excite/excite_iodev.c b/arch/mips/basler/excite/excite_iodev.c
index a1e3526b4a94..dfbfd7e2ac08 100644
--- a/arch/mips/basler/excite/excite_iodev.c
+++ b/arch/mips/basler/excite/excite_iodev.c
@@ -33,8 +33,8 @@
33 33
34 34
35static const struct resource *iodev_get_resource(struct platform_device *, const char *, unsigned int); 35static const struct resource *iodev_get_resource(struct platform_device *, const char *, unsigned int);
36static int __init iodev_probe(struct device *); 36static int __init iodev_probe(struct platform_device *);
37static int __exit iodev_remove(struct device *); 37static int __exit iodev_remove(struct platform_device *);
38static int iodev_open(struct inode *, struct file *); 38static int iodev_open(struct inode *, struct file *);
39static int iodev_release(struct inode *, struct file *); 39static int iodev_release(struct inode *, struct file *);
40static ssize_t iodev_read(struct file *, char __user *, size_t s, loff_t *); 40static ssize_t iodev_read(struct file *, char __user *, size_t s, loff_t *);
@@ -65,13 +65,13 @@ static struct miscdevice miscdev =
65 .fops = &fops 65 .fops = &fops
66}; 66};
67 67
68static struct device_driver iodev_driver = 68static struct platform_driver iodev_driver = {
69{ 69 .driver = {
70 .name = (char *) iodev_name, 70 .name = iodev_name,
71 .bus = &platform_bus_type, 71 .owner = THIS_MODULE,
72 .owner = THIS_MODULE, 72 },
73 .probe = iodev_probe, 73 .probe = iodev_probe,
74 .remove = __exit_p(iodev_remove) 74 .remove = __devexit_p(iodev_remove),
75}; 75};
76 76
77 77
@@ -89,11 +89,10 @@ iodev_get_resource(struct platform_device *pdv, const char *name,
89 89
90 90
91/* No hotplugging on the platform bus - use __init */ 91/* No hotplugging on the platform bus - use __init */
92static int __init iodev_probe(struct device *dev) 92static int __init iodev_probe(struct platform_device *dev)
93{ 93{
94 struct platform_device * const pdv = to_platform_device(dev);
95 const struct resource * const ri = 94 const struct resource * const ri =
96 iodev_get_resource(pdv, IODEV_RESOURCE_IRQ, IORESOURCE_IRQ); 95 iodev_get_resource(dev, IODEV_RESOURCE_IRQ, IORESOURCE_IRQ);
97 96
98 if (unlikely(!ri)) 97 if (unlikely(!ri))
99 return -ENXIO; 98 return -ENXIO;
@@ -104,7 +103,7 @@ static int __init iodev_probe(struct device *dev)
104 103
105 104
106 105
107static int __exit iodev_remove(struct device *dev) 106static int __exit iodev_remove(struct platform_device *dev)
108{ 107{
109 return misc_deregister(&miscdev); 108 return misc_deregister(&miscdev);
110} 109}
@@ -160,14 +159,14 @@ static irqreturn_t iodev_irqhdl(int irq, void *ctxt)
160 159
161static int __init iodev_init_module(void) 160static int __init iodev_init_module(void)
162{ 161{
163 return driver_register(&iodev_driver); 162 return platform_driver_register(&iodev_driver);
164} 163}
165 164
166 165
167 166
168static void __exit iodev_cleanup_module(void) 167static void __exit iodev_cleanup_module(void)
169{ 168{
170 driver_unregister(&iodev_driver); 169 platform_driver_unregister(&iodev_driver);
171} 170}
172 171
173module_init(iodev_init_module); 172module_init(iodev_init_module);
diff --git a/arch/mips/include/asm/mipsregs.h b/arch/mips/include/asm/mipsregs.h
index 0417516503f6..526f327475ce 100644
--- a/arch/mips/include/asm/mipsregs.h
+++ b/arch/mips/include/asm/mipsregs.h
@@ -1391,11 +1391,11 @@ static inline void tlb_write_random(void)
1391static inline unsigned int \ 1391static inline unsigned int \
1392set_c0_##name(unsigned int set) \ 1392set_c0_##name(unsigned int set) \
1393{ \ 1393{ \
1394 unsigned int res; \ 1394 unsigned int res, new; \
1395 \ 1395 \
1396 res = read_c0_##name(); \ 1396 res = read_c0_##name(); \
1397 res |= set; \ 1397 new = res | set; \
1398 write_c0_##name(res); \ 1398 write_c0_##name(new); \
1399 \ 1399 \
1400 return res; \ 1400 return res; \
1401} \ 1401} \
@@ -1403,24 +1403,24 @@ set_c0_##name(unsigned int set) \
1403static inline unsigned int \ 1403static inline unsigned int \
1404clear_c0_##name(unsigned int clear) \ 1404clear_c0_##name(unsigned int clear) \
1405{ \ 1405{ \
1406 unsigned int res; \ 1406 unsigned int res, new; \
1407 \ 1407 \
1408 res = read_c0_##name(); \ 1408 res = read_c0_##name(); \
1409 res &= ~clear; \ 1409 new = res & ~clear; \
1410 write_c0_##name(res); \ 1410 write_c0_##name(new); \
1411 \ 1411 \
1412 return res; \ 1412 return res; \
1413} \ 1413} \
1414 \ 1414 \
1415static inline unsigned int \ 1415static inline unsigned int \
1416change_c0_##name(unsigned int change, unsigned int new) \ 1416change_c0_##name(unsigned int change, unsigned int val) \
1417{ \ 1417{ \
1418 unsigned int res; \ 1418 unsigned int res, new; \
1419 \ 1419 \
1420 res = read_c0_##name(); \ 1420 res = read_c0_##name(); \
1421 res &= ~change; \ 1421 new = res & ~change; \
1422 res |= (new & change); \ 1422 new |= (val & change); \
1423 write_c0_##name(res); \ 1423 write_c0_##name(new); \
1424 \ 1424 \
1425 return res; \ 1425 return res; \
1426} 1426}
diff --git a/arch/mips/kernel/linux32.c b/arch/mips/kernel/linux32.c
index 1a86f84fa947..49aac6e17df9 100644
--- a/arch/mips/kernel/linux32.c
+++ b/arch/mips/kernel/linux32.c
@@ -32,7 +32,6 @@
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/binfmts.h> 33#include <linux/binfmts.h>
34#include <linux/security.h> 34#include <linux/security.h>
35#include <linux/syscalls.h>
36#include <linux/compat.h> 35#include <linux/compat.h>
37#include <linux/vfs.h> 36#include <linux/vfs.h>
38#include <linux/ipc.h> 37#include <linux/ipc.h>
diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
index b2d7041341b8..29fadaccecdd 100644
--- a/arch/mips/kernel/traps.c
+++ b/arch/mips/kernel/traps.c
@@ -1520,7 +1520,9 @@ void __cpuinit per_cpu_trap_init(void)
1520#endif /* CONFIG_MIPS_MT_SMTC */ 1520#endif /* CONFIG_MIPS_MT_SMTC */
1521 1521
1522 if (cpu_has_veic || cpu_has_vint) { 1522 if (cpu_has_veic || cpu_has_vint) {
1523 unsigned long sr = set_c0_status(ST0_BEV);
1523 write_c0_ebase(ebase); 1524 write_c0_ebase(ebase);
1525 write_c0_status(sr);
1524 /* Setting vector spacing enables EI/VI mode */ 1526 /* Setting vector spacing enables EI/VI mode */
1525 change_c0_intctl(0x3e0, VECTORSPACING); 1527 change_c0_intctl(0x3e0, VECTORSPACING);
1526 } 1528 }
@@ -1602,8 +1604,6 @@ void __cpuinit set_uncached_handler(unsigned long offset, void *addr,
1602#ifdef CONFIG_64BIT 1604#ifdef CONFIG_64BIT
1603 unsigned long uncached_ebase = TO_UNCAC(ebase); 1605 unsigned long uncached_ebase = TO_UNCAC(ebase);
1604#endif 1606#endif
1605 if (cpu_has_mips_r2)
1606 uncached_ebase += (read_c0_ebase() & 0x3ffff000);
1607 1607
1608 if (!addr) 1608 if (!addr)
1609 panic(panic_null_cerr); 1609 panic(panic_null_cerr);
@@ -1635,9 +1635,11 @@ void __init trap_init(void)
1635 return; /* Already done */ 1635 return; /* Already done */
1636#endif 1636#endif
1637 1637
1638 if (cpu_has_veic || cpu_has_vint) 1638 if (cpu_has_veic || cpu_has_vint) {
1639 ebase = (unsigned long) alloc_bootmem_low_pages(0x200 + VECTORSPACING*64); 1639 unsigned long size = 0x200 + VECTORSPACING*64;
1640 else { 1640 ebase = (unsigned long)
1641 __alloc_bootmem(size, 1 << fls(size), 0);
1642 } else {
1641 ebase = CAC_BASE; 1643 ebase = CAC_BASE;
1642 if (cpu_has_mips_r2) 1644 if (cpu_has_mips_r2)
1643 ebase += (read_c0_ebase() & 0x3ffff000); 1645 ebase += (read_c0_ebase() & 0x3ffff000);
diff --git a/arch/mips/mm/c-r4k.c b/arch/mips/mm/c-r4k.c
index c43f4b26a690..871e828bc62a 100644
--- a/arch/mips/mm/c-r4k.c
+++ b/arch/mips/mm/c-r4k.c
@@ -780,7 +780,7 @@ static void __cpuinit probe_pcache(void)
780 c->dcache.ways = 2; 780 c->dcache.ways = 2;
781 c->dcache.waybit = 0; 781 c->dcache.waybit = 0;
782 782
783 c->options |= MIPS_CPU_CACHE_CDEX_P; 783 c->options |= MIPS_CPU_CACHE_CDEX_P | MIPS_CPU_PREFETCH;
784 break; 784 break;
785 785
786 case CPU_TX49XX: 786 case CPU_TX49XX:
diff --git a/arch/mips/mm/dma-default.c b/arch/mips/mm/dma-default.c
index 546e6977d4ff..bed56f1ac837 100644
--- a/arch/mips/mm/dma-default.c
+++ b/arch/mips/mm/dma-default.c
@@ -225,7 +225,7 @@ void dma_unmap_page(struct device *dev, dma_addr_t dma_address, size_t size,
225 if (!plat_device_is_coherent(dev) && direction != DMA_TO_DEVICE) { 225 if (!plat_device_is_coherent(dev) && direction != DMA_TO_DEVICE) {
226 unsigned long addr; 226 unsigned long addr;
227 227
228 addr = plat_dma_addr_to_phys(dma_address); 228 addr = dma_addr_to_virt(dma_address);
229 dma_cache_wback_inv(addr, size); 229 dma_cache_wback_inv(addr, size);
230 } 230 }
231 231
diff --git a/arch/powerpc/boot/dts/canyonlands.dts b/arch/powerpc/boot/dts/canyonlands.dts
index 8b5ba8261a36..4447def69dc5 100644
--- a/arch/powerpc/boot/dts/canyonlands.dts
+++ b/arch/powerpc/boot/dts/canyonlands.dts
@@ -127,6 +127,13 @@
127 dcr-reg = <0x010 0x002>; 127 dcr-reg = <0x010 0x002>;
128 }; 128 };
129 129
130 CRYPTO: crypto@180000 {
131 compatible = "amcc,ppc460ex-crypto", "amcc,ppc4xx-crypto";
132 reg = <4 0x00180000 0x80400>;
133 interrupt-parent = <&UIC0>;
134 interrupts = <0x1d 0x4>;
135 };
136
130 MAL0: mcmal { 137 MAL0: mcmal {
131 compatible = "ibm,mcmal-460ex", "ibm,mcmal2"; 138 compatible = "ibm,mcmal-460ex", "ibm,mcmal2";
132 dcr-reg = <0x180 0x062>; 139 dcr-reg = <0x180 0x062>;
diff --git a/arch/powerpc/boot/dts/kilauea.dts b/arch/powerpc/boot/dts/kilauea.dts
index 2804444812e5..5e6b08ff6f67 100644
--- a/arch/powerpc/boot/dts/kilauea.dts
+++ b/arch/powerpc/boot/dts/kilauea.dts
@@ -97,6 +97,13 @@
97 0x6 0x4>; /* ECC SEC Error */ 97 0x6 0x4>; /* ECC SEC Error */
98 }; 98 };
99 99
100 CRYPTO: crypto@ef700000 {
101 compatible = "amcc,ppc405ex-crypto", "amcc,ppc4xx-crypto";
102 reg = <0xef700000 0x80400>;
103 interrupt-parent = <&UIC0>;
104 interrupts = <0x17 0x2>;
105 };
106
100 MAL0: mcmal { 107 MAL0: mcmal {
101 compatible = "ibm,mcmal-405ex", "ibm,mcmal2"; 108 compatible = "ibm,mcmal-405ex", "ibm,mcmal2";
102 dcr-reg = <0x180 0x062>; 109 dcr-reg = <0x180 0x062>;
diff --git a/arch/powerpc/platforms/ps3/system-bus.c b/arch/powerpc/platforms/ps3/system-bus.c
index 58311a867851..a705fffbb498 100644
--- a/arch/powerpc/platforms/ps3/system-bus.c
+++ b/arch/powerpc/platforms/ps3/system-bus.c
@@ -376,7 +376,7 @@ static int ps3_system_bus_probe(struct device *_dev)
376 struct ps3_system_bus_driver *drv; 376 struct ps3_system_bus_driver *drv;
377 377
378 BUG_ON(!dev); 378 BUG_ON(!dev);
379 pr_debug(" -> %s:%d: %s\n", __func__, __LINE__, _dev->bus_id); 379 dev_dbg(_dev, "%s:%d\n", __func__, __LINE__);
380 380
381 drv = ps3_system_bus_dev_to_system_bus_drv(dev); 381 drv = ps3_system_bus_dev_to_system_bus_drv(dev);
382 BUG_ON(!drv); 382 BUG_ON(!drv);
@@ -398,7 +398,7 @@ static int ps3_system_bus_remove(struct device *_dev)
398 struct ps3_system_bus_driver *drv; 398 struct ps3_system_bus_driver *drv;
399 399
400 BUG_ON(!dev); 400 BUG_ON(!dev);
401 pr_debug(" -> %s:%d: %s\n", __func__, __LINE__, _dev->bus_id); 401 dev_dbg(_dev, "%s:%d\n", __func__, __LINE__);
402 402
403 drv = ps3_system_bus_dev_to_system_bus_drv(dev); 403 drv = ps3_system_bus_dev_to_system_bus_drv(dev);
404 BUG_ON(!drv); 404 BUG_ON(!drv);
diff --git a/arch/s390/crypto/sha.h b/arch/s390/crypto/sha.h
index 1ceafa571eab..f4e9dc71675f 100644
--- a/arch/s390/crypto/sha.h
+++ b/arch/s390/crypto/sha.h
@@ -29,7 +29,9 @@ struct s390_sha_ctx {
29 int func; /* KIMD function to use */ 29 int func; /* KIMD function to use */
30}; 30};
31 31
32void s390_sha_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len); 32struct shash_desc;
33void s390_sha_final(struct crypto_tfm *tfm, u8 *out); 33
34int s390_sha_update(struct shash_desc *desc, const u8 *data, unsigned int len);
35int s390_sha_final(struct shash_desc *desc, u8 *out);
34 36
35#endif 37#endif
diff --git a/arch/s390/crypto/sha1_s390.c b/arch/s390/crypto/sha1_s390.c
index b3cb5a89b00d..e85ba348722a 100644
--- a/arch/s390/crypto/sha1_s390.c
+++ b/arch/s390/crypto/sha1_s390.c
@@ -23,17 +23,17 @@
23 * any later version. 23 * any later version.
24 * 24 *
25 */ 25 */
26#include <crypto/internal/hash.h>
26#include <linux/init.h> 27#include <linux/init.h>
27#include <linux/module.h> 28#include <linux/module.h>
28#include <linux/crypto.h>
29#include <crypto/sha.h> 29#include <crypto/sha.h>
30 30
31#include "crypt_s390.h" 31#include "crypt_s390.h"
32#include "sha.h" 32#include "sha.h"
33 33
34static void sha1_init(struct crypto_tfm *tfm) 34static int sha1_init(struct shash_desc *desc)
35{ 35{
36 struct s390_sha_ctx *sctx = crypto_tfm_ctx(tfm); 36 struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
37 37
38 sctx->state[0] = SHA1_H0; 38 sctx->state[0] = SHA1_H0;
39 sctx->state[1] = SHA1_H1; 39 sctx->state[1] = SHA1_H1;
@@ -42,34 +42,36 @@ static void sha1_init(struct crypto_tfm *tfm)
42 sctx->state[4] = SHA1_H4; 42 sctx->state[4] = SHA1_H4;
43 sctx->count = 0; 43 sctx->count = 0;
44 sctx->func = KIMD_SHA_1; 44 sctx->func = KIMD_SHA_1;
45
46 return 0;
45} 47}
46 48
47static struct crypto_alg alg = { 49static struct shash_alg alg = {
48 .cra_name = "sha1", 50 .digestsize = SHA1_DIGEST_SIZE,
49 .cra_driver_name= "sha1-s390", 51 .init = sha1_init,
50 .cra_priority = CRYPT_S390_PRIORITY, 52 .update = s390_sha_update,
51 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 53 .final = s390_sha_final,
52 .cra_blocksize = SHA1_BLOCK_SIZE, 54 .descsize = sizeof(struct s390_sha_ctx),
53 .cra_ctxsize = sizeof(struct s390_sha_ctx), 55 .base = {
54 .cra_module = THIS_MODULE, 56 .cra_name = "sha1",
55 .cra_list = LIST_HEAD_INIT(alg.cra_list), 57 .cra_driver_name= "sha1-s390",
56 .cra_u = { .digest = { 58 .cra_priority = CRYPT_S390_PRIORITY,
57 .dia_digestsize = SHA1_DIGEST_SIZE, 59 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
58 .dia_init = sha1_init, 60 .cra_blocksize = SHA1_BLOCK_SIZE,
59 .dia_update = s390_sha_update, 61 .cra_module = THIS_MODULE,
60 .dia_final = s390_sha_final } } 62 }
61}; 63};
62 64
63static int __init sha1_s390_init(void) 65static int __init sha1_s390_init(void)
64{ 66{
65 if (!crypt_s390_func_available(KIMD_SHA_1)) 67 if (!crypt_s390_func_available(KIMD_SHA_1))
66 return -EOPNOTSUPP; 68 return -EOPNOTSUPP;
67 return crypto_register_alg(&alg); 69 return crypto_register_shash(&alg);
68} 70}
69 71
70static void __exit sha1_s390_fini(void) 72static void __exit sha1_s390_fini(void)
71{ 73{
72 crypto_unregister_alg(&alg); 74 crypto_unregister_shash(&alg);
73} 75}
74 76
75module_init(sha1_s390_init); 77module_init(sha1_s390_init);
diff --git a/arch/s390/crypto/sha256_s390.c b/arch/s390/crypto/sha256_s390.c
index 19c03fb6ba7e..f9fefc569632 100644
--- a/arch/s390/crypto/sha256_s390.c
+++ b/arch/s390/crypto/sha256_s390.c
@@ -16,17 +16,17 @@
16 * any later version. 16 * any later version.
17 * 17 *
18 */ 18 */
19#include <crypto/internal/hash.h>
19#include <linux/init.h> 20#include <linux/init.h>
20#include <linux/module.h> 21#include <linux/module.h>
21#include <linux/crypto.h>
22#include <crypto/sha.h> 22#include <crypto/sha.h>
23 23
24#include "crypt_s390.h" 24#include "crypt_s390.h"
25#include "sha.h" 25#include "sha.h"
26 26
27static void sha256_init(struct crypto_tfm *tfm) 27static int sha256_init(struct shash_desc *desc)
28{ 28{
29 struct s390_sha_ctx *sctx = crypto_tfm_ctx(tfm); 29 struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
30 30
31 sctx->state[0] = SHA256_H0; 31 sctx->state[0] = SHA256_H0;
32 sctx->state[1] = SHA256_H1; 32 sctx->state[1] = SHA256_H1;
@@ -38,22 +38,24 @@ static void sha256_init(struct crypto_tfm *tfm)
38 sctx->state[7] = SHA256_H7; 38 sctx->state[7] = SHA256_H7;
39 sctx->count = 0; 39 sctx->count = 0;
40 sctx->func = KIMD_SHA_256; 40 sctx->func = KIMD_SHA_256;
41
42 return 0;
41} 43}
42 44
43static struct crypto_alg alg = { 45static struct shash_alg alg = {
44 .cra_name = "sha256", 46 .digestsize = SHA256_DIGEST_SIZE,
45 .cra_driver_name = "sha256-s390", 47 .init = sha256_init,
46 .cra_priority = CRYPT_S390_PRIORITY, 48 .update = s390_sha_update,
47 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 49 .final = s390_sha_final,
48 .cra_blocksize = SHA256_BLOCK_SIZE, 50 .descsize = sizeof(struct s390_sha_ctx),
49 .cra_ctxsize = sizeof(struct s390_sha_ctx), 51 .base = {
50 .cra_module = THIS_MODULE, 52 .cra_name = "sha256",
51 .cra_list = LIST_HEAD_INIT(alg.cra_list), 53 .cra_driver_name= "sha256-s390",
52 .cra_u = { .digest = { 54 .cra_priority = CRYPT_S390_PRIORITY,
53 .dia_digestsize = SHA256_DIGEST_SIZE, 55 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
54 .dia_init = sha256_init, 56 .cra_blocksize = SHA256_BLOCK_SIZE,
55 .dia_update = s390_sha_update, 57 .cra_module = THIS_MODULE,
56 .dia_final = s390_sha_final } } 58 }
57}; 59};
58 60
59static int sha256_s390_init(void) 61static int sha256_s390_init(void)
@@ -61,12 +63,12 @@ static int sha256_s390_init(void)
61 if (!crypt_s390_func_available(KIMD_SHA_256)) 63 if (!crypt_s390_func_available(KIMD_SHA_256))
62 return -EOPNOTSUPP; 64 return -EOPNOTSUPP;
63 65
64 return crypto_register_alg(&alg); 66 return crypto_register_shash(&alg);
65} 67}
66 68
67static void __exit sha256_s390_fini(void) 69static void __exit sha256_s390_fini(void)
68{ 70{
69 crypto_unregister_alg(&alg); 71 crypto_unregister_shash(&alg);
70} 72}
71 73
72module_init(sha256_s390_init); 74module_init(sha256_s390_init);
diff --git a/arch/s390/crypto/sha512_s390.c b/arch/s390/crypto/sha512_s390.c
index 23c7861f6aeb..83192bfc8048 100644
--- a/arch/s390/crypto/sha512_s390.c
+++ b/arch/s390/crypto/sha512_s390.c
@@ -12,16 +12,16 @@
12 * any later version. 12 * any later version.
13 * 13 *
14 */ 14 */
15#include <crypto/internal/hash.h>
15#include <linux/init.h> 16#include <linux/init.h>
16#include <linux/module.h> 17#include <linux/module.h>
17#include <linux/crypto.h>
18 18
19#include "sha.h" 19#include "sha.h"
20#include "crypt_s390.h" 20#include "crypt_s390.h"
21 21
22static void sha512_init(struct crypto_tfm *tfm) 22static int sha512_init(struct shash_desc *desc)
23{ 23{
24 struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); 24 struct s390_sha_ctx *ctx = shash_desc_ctx(desc);
25 25
26 *(__u64 *)&ctx->state[0] = 0x6a09e667f3bcc908ULL; 26 *(__u64 *)&ctx->state[0] = 0x6a09e667f3bcc908ULL;
27 *(__u64 *)&ctx->state[2] = 0xbb67ae8584caa73bULL; 27 *(__u64 *)&ctx->state[2] = 0xbb67ae8584caa73bULL;
@@ -33,29 +33,31 @@ static void sha512_init(struct crypto_tfm *tfm)
33 *(__u64 *)&ctx->state[14] = 0x5be0cd19137e2179ULL; 33 *(__u64 *)&ctx->state[14] = 0x5be0cd19137e2179ULL;
34 ctx->count = 0; 34 ctx->count = 0;
35 ctx->func = KIMD_SHA_512; 35 ctx->func = KIMD_SHA_512;
36
37 return 0;
36} 38}
37 39
38static struct crypto_alg sha512_alg = { 40static struct shash_alg sha512_alg = {
39 .cra_name = "sha512", 41 .digestsize = SHA512_DIGEST_SIZE,
40 .cra_driver_name = "sha512-s390", 42 .init = sha512_init,
41 .cra_priority = CRYPT_S390_PRIORITY, 43 .update = s390_sha_update,
42 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 44 .final = s390_sha_final,
43 .cra_blocksize = SHA512_BLOCK_SIZE, 45 .descsize = sizeof(struct s390_sha_ctx),
44 .cra_ctxsize = sizeof(struct s390_sha_ctx), 46 .base = {
45 .cra_module = THIS_MODULE, 47 .cra_name = "sha512",
46 .cra_list = LIST_HEAD_INIT(sha512_alg.cra_list), 48 .cra_driver_name= "sha512-s390",
47 .cra_u = { .digest = { 49 .cra_priority = CRYPT_S390_PRIORITY,
48 .dia_digestsize = SHA512_DIGEST_SIZE, 50 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
49 .dia_init = sha512_init, 51 .cra_blocksize = SHA512_BLOCK_SIZE,
50 .dia_update = s390_sha_update, 52 .cra_module = THIS_MODULE,
51 .dia_final = s390_sha_final } } 53 }
52}; 54};
53 55
54MODULE_ALIAS("sha512"); 56MODULE_ALIAS("sha512");
55 57
56static void sha384_init(struct crypto_tfm *tfm) 58static int sha384_init(struct shash_desc *desc)
57{ 59{
58 struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); 60 struct s390_sha_ctx *ctx = shash_desc_ctx(desc);
59 61
60 *(__u64 *)&ctx->state[0] = 0xcbbb9d5dc1059ed8ULL; 62 *(__u64 *)&ctx->state[0] = 0xcbbb9d5dc1059ed8ULL;
61 *(__u64 *)&ctx->state[2] = 0x629a292a367cd507ULL; 63 *(__u64 *)&ctx->state[2] = 0x629a292a367cd507ULL;
@@ -67,22 +69,25 @@ static void sha384_init(struct crypto_tfm *tfm)
67 *(__u64 *)&ctx->state[14] = 0x47b5481dbefa4fa4ULL; 69 *(__u64 *)&ctx->state[14] = 0x47b5481dbefa4fa4ULL;
68 ctx->count = 0; 70 ctx->count = 0;
69 ctx->func = KIMD_SHA_512; 71 ctx->func = KIMD_SHA_512;
72
73 return 0;
70} 74}
71 75
72static struct crypto_alg sha384_alg = { 76static struct shash_alg sha384_alg = {
73 .cra_name = "sha384", 77 .digestsize = SHA384_DIGEST_SIZE,
74 .cra_driver_name = "sha384-s390", 78 .init = sha384_init,
75 .cra_priority = CRYPT_S390_PRIORITY, 79 .update = s390_sha_update,
76 .cra_flags = CRYPTO_ALG_TYPE_DIGEST, 80 .final = s390_sha_final,
77 .cra_blocksize = SHA384_BLOCK_SIZE, 81 .descsize = sizeof(struct s390_sha_ctx),
78 .cra_ctxsize = sizeof(struct s390_sha_ctx), 82 .base = {
79 .cra_module = THIS_MODULE, 83 .cra_name = "sha384",
80 .cra_list = LIST_HEAD_INIT(sha384_alg.cra_list), 84 .cra_driver_name= "sha384-s390",
81 .cra_u = { .digest = { 85 .cra_priority = CRYPT_S390_PRIORITY,
82 .dia_digestsize = SHA384_DIGEST_SIZE, 86 .cra_flags = CRYPTO_ALG_TYPE_SHASH,
83 .dia_init = sha384_init, 87 .cra_blocksize = SHA384_BLOCK_SIZE,
84 .dia_update = s390_sha_update, 88 .cra_ctxsize = sizeof(struct s390_sha_ctx),
85 .dia_final = s390_sha_final } } 89 .cra_module = THIS_MODULE,
90 }
86}; 91};
87 92
88MODULE_ALIAS("sha384"); 93MODULE_ALIAS("sha384");
@@ -93,18 +98,18 @@ static int __init init(void)
93 98
94 if (!crypt_s390_func_available(KIMD_SHA_512)) 99 if (!crypt_s390_func_available(KIMD_SHA_512))
95 return -EOPNOTSUPP; 100 return -EOPNOTSUPP;
96 if ((ret = crypto_register_alg(&sha512_alg)) < 0) 101 if ((ret = crypto_register_shash(&sha512_alg)) < 0)
97 goto out; 102 goto out;
98 if ((ret = crypto_register_alg(&sha384_alg)) < 0) 103 if ((ret = crypto_register_shash(&sha384_alg)) < 0)
99 crypto_unregister_alg(&sha512_alg); 104 crypto_unregister_shash(&sha512_alg);
100out: 105out:
101 return ret; 106 return ret;
102} 107}
103 108
104static void __exit fini(void) 109static void __exit fini(void)
105{ 110{
106 crypto_unregister_alg(&sha512_alg); 111 crypto_unregister_shash(&sha512_alg);
107 crypto_unregister_alg(&sha384_alg); 112 crypto_unregister_shash(&sha384_alg);
108} 113}
109 114
110module_init(init); 115module_init(init);
diff --git a/arch/s390/crypto/sha_common.c b/arch/s390/crypto/sha_common.c
index 9d6eb8c3d37e..7903ec47e6b9 100644
--- a/arch/s390/crypto/sha_common.c
+++ b/arch/s390/crypto/sha_common.c
@@ -13,14 +13,14 @@
13 * 13 *
14 */ 14 */
15 15
16#include <linux/crypto.h> 16#include <crypto/internal/hash.h>
17#include "sha.h" 17#include "sha.h"
18#include "crypt_s390.h" 18#include "crypt_s390.h"
19 19
20void s390_sha_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len) 20int s390_sha_update(struct shash_desc *desc, const u8 *data, unsigned int len)
21{ 21{
22 struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); 22 struct s390_sha_ctx *ctx = shash_desc_ctx(desc);
23 unsigned int bsize = crypto_tfm_alg_blocksize(tfm); 23 unsigned int bsize = crypto_shash_blocksize(desc->tfm);
24 unsigned int index; 24 unsigned int index;
25 int ret; 25 int ret;
26 26
@@ -51,13 +51,15 @@ void s390_sha_update(struct crypto_tfm *tfm, const u8 *data, unsigned int len)
51store: 51store:
52 if (len) 52 if (len)
53 memcpy(ctx->buf + index , data, len); 53 memcpy(ctx->buf + index , data, len);
54
55 return 0;
54} 56}
55EXPORT_SYMBOL_GPL(s390_sha_update); 57EXPORT_SYMBOL_GPL(s390_sha_update);
56 58
57void s390_sha_final(struct crypto_tfm *tfm, u8 *out) 59int s390_sha_final(struct shash_desc *desc, u8 *out)
58{ 60{
59 struct s390_sha_ctx *ctx = crypto_tfm_ctx(tfm); 61 struct s390_sha_ctx *ctx = shash_desc_ctx(desc);
60 unsigned int bsize = crypto_tfm_alg_blocksize(tfm); 62 unsigned int bsize = crypto_shash_blocksize(desc->tfm);
61 u64 bits; 63 u64 bits;
62 unsigned int index, end, plen; 64 unsigned int index, end, plen;
63 int ret; 65 int ret;
@@ -87,9 +89,11 @@ void s390_sha_final(struct crypto_tfm *tfm, u8 *out)
87 BUG_ON(ret != end); 89 BUG_ON(ret != end);
88 90
89 /* copy digest to out */ 91 /* copy digest to out */
90 memcpy(out, ctx->state, crypto_hash_digestsize(crypto_hash_cast(tfm))); 92 memcpy(out, ctx->state, crypto_shash_digestsize(desc->tfm));
91 /* wipe context */ 93 /* wipe context */
92 memset(ctx, 0, sizeof *ctx); 94 memset(ctx, 0, sizeof *ctx);
95
96 return 0;
93} 97}
94EXPORT_SYMBOL_GPL(s390_sha_final); 98EXPORT_SYMBOL_GPL(s390_sha_final);
95 99
diff --git a/arch/sh/Kconfig b/arch/sh/Kconfig
index ebabe518e729..8d50d527c595 100644
--- a/arch/sh/Kconfig
+++ b/arch/sh/Kconfig
@@ -107,6 +107,9 @@ config SYS_SUPPORTS_NUMA
107config SYS_SUPPORTS_PCI 107config SYS_SUPPORTS_PCI
108 bool 108 bool
109 109
110config SYS_SUPPORTS_CMT
111 bool
112
110config STACKTRACE_SUPPORT 113config STACKTRACE_SUPPORT
111 def_bool y 114 def_bool y
112 115
@@ -176,6 +179,10 @@ config CPU_SHX2
176config CPU_SHX3 179config CPU_SHX3
177 bool 180 bool
178 181
182config ARCH_SHMOBILE
183 bool
184 select ARCH_SUSPEND_POSSIBLE
185
179choice 186choice
180 prompt "Processor sub-type selection" 187 prompt "Processor sub-type selection"
181 188
@@ -188,6 +195,7 @@ choice
188config CPU_SUBTYPE_SH7619 195config CPU_SUBTYPE_SH7619
189 bool "Support SH7619 processor" 196 bool "Support SH7619 processor"
190 select CPU_SH2 197 select CPU_SH2
198 select SYS_SUPPORTS_CMT
191 199
192# SH-2A Processor Support 200# SH-2A Processor Support
193 201
@@ -200,15 +208,18 @@ config CPU_SUBTYPE_SH7203
200 bool "Support SH7203 processor" 208 bool "Support SH7203 processor"
201 select CPU_SH2A 209 select CPU_SH2A
202 select CPU_HAS_FPU 210 select CPU_HAS_FPU
211 select SYS_SUPPORTS_CMT
203 212
204config CPU_SUBTYPE_SH7206 213config CPU_SUBTYPE_SH7206
205 bool "Support SH7206 processor" 214 bool "Support SH7206 processor"
206 select CPU_SH2A 215 select CPU_SH2A
216 select SYS_SUPPORTS_CMT
207 217
208config CPU_SUBTYPE_SH7263 218config CPU_SUBTYPE_SH7263
209 bool "Support SH7263 processor" 219 bool "Support SH7263 processor"
210 select CPU_SH2A 220 select CPU_SH2A
211 select CPU_HAS_FPU 221 select CPU_HAS_FPU
222 select SYS_SUPPORTS_CMT
212 223
213config CPU_SUBTYPE_MXG 224config CPU_SUBTYPE_MXG
214 bool "Support MX-G processor" 225 bool "Support MX-G processor"
@@ -323,7 +334,9 @@ config CPU_SUBTYPE_SH7723
323 bool "Support SH7723 processor" 334 bool "Support SH7723 processor"
324 select CPU_SH4A 335 select CPU_SH4A
325 select CPU_SHX2 336 select CPU_SHX2
337 select ARCH_SHMOBILE
326 select ARCH_SPARSEMEM_ENABLE 338 select ARCH_SPARSEMEM_ENABLE
339 select SYS_SUPPORTS_CMT
327 help 340 help
328 Select SH7723 if you have an SH-MobileR2 CPU. 341 Select SH7723 if you have an SH-MobileR2 CPU.
329 342
@@ -348,6 +361,14 @@ config CPU_SUBTYPE_SH7785
348 select ARCH_SPARSEMEM_ENABLE 361 select ARCH_SPARSEMEM_ENABLE
349 select SYS_SUPPORTS_NUMA 362 select SYS_SUPPORTS_NUMA
350 363
364config CPU_SUBTYPE_SH7786
365 bool "Support SH7786 processor"
366 select CPU_SH4A
367 select CPU_SHX3
368 select CPU_HAS_PTEAEX
369 select ARCH_SPARSEMEM_ENABLE
370 select SYS_SUPPORTS_NUMA
371
351config CPU_SUBTYPE_SHX3 372config CPU_SUBTYPE_SHX3
352 bool "Support SH-X3 processor" 373 bool "Support SH-X3 processor"
353 select CPU_SH4A 374 select CPU_SH4A
@@ -362,20 +383,26 @@ config CPU_SUBTYPE_SHX3
362config CPU_SUBTYPE_SH7343 383config CPU_SUBTYPE_SH7343
363 bool "Support SH7343 processor" 384 bool "Support SH7343 processor"
364 select CPU_SH4AL_DSP 385 select CPU_SH4AL_DSP
386 select ARCH_SHMOBILE
387 select SYS_SUPPORTS_CMT
365 388
366config CPU_SUBTYPE_SH7722 389config CPU_SUBTYPE_SH7722
367 bool "Support SH7722 processor" 390 bool "Support SH7722 processor"
368 select CPU_SH4AL_DSP 391 select CPU_SH4AL_DSP
369 select CPU_SHX2 392 select CPU_SHX2
393 select ARCH_SHMOBILE
370 select ARCH_SPARSEMEM_ENABLE 394 select ARCH_SPARSEMEM_ENABLE
371 select SYS_SUPPORTS_NUMA 395 select SYS_SUPPORTS_NUMA
396 select SYS_SUPPORTS_CMT
372 397
373config CPU_SUBTYPE_SH7366 398config CPU_SUBTYPE_SH7366
374 bool "Support SH7366 processor" 399 bool "Support SH7366 processor"
375 select CPU_SH4AL_DSP 400 select CPU_SH4AL_DSP
376 select CPU_SHX2 401 select CPU_SHX2
402 select ARCH_SHMOBILE
377 select ARCH_SPARSEMEM_ENABLE 403 select ARCH_SPARSEMEM_ENABLE
378 select SYS_SUPPORTS_NUMA 404 select SYS_SUPPORTS_NUMA
405 select SYS_SUPPORTS_CMT
379 406
380# SH-5 Processor Support 407# SH-5 Processor Support
381 408
@@ -398,25 +425,34 @@ source "arch/sh/boards/Kconfig"
398menu "Timer and clock configuration" 425menu "Timer and clock configuration"
399 426
400config SH_TMU 427config SH_TMU
401 def_bool y 428 bool "TMU timer support"
402 prompt "TMU timer support"
403 depends on CPU_SH3 || CPU_SH4 429 depends on CPU_SH3 || CPU_SH4
430 default y
404 select GENERIC_TIME 431 select GENERIC_TIME
405 select GENERIC_CLOCKEVENTS 432 select GENERIC_CLOCKEVENTS
406 help 433 help
407 This enables the use of the TMU as the system timer. 434 This enables the use of the TMU as the system timer.
408 435
409config SH_CMT 436config SH_CMT
410 def_bool y 437 bool "CMT timer support"
411 prompt "CMT timer support" 438 depends on SYS_SUPPORTS_CMT && CPU_SH2
412 depends on CPU_SH2 && !CPU_SUBTYPE_MXG 439 default y
413 help 440 help
414 This enables the use of the CMT as the system timer. 441 This enables the use of the CMT as the system timer.
415 442
443#
444# Support for the new-style CMT driver. This will replace SH_CMT
445# once its other dependencies are merged.
446#
447config SH_TIMER_CMT
448 bool "CMT clockevents driver"
449 depends on SYS_SUPPORTS_CMT && !SH_CMT
450 select GENERIC_CLOCKEVENTS
451
416config SH_MTU2 452config SH_MTU2
417 def_bool n 453 bool "MTU2 timer support"
418 prompt "MTU2 timer support"
419 depends on CPU_SH2A 454 depends on CPU_SH2A
455 default y
420 help 456 help
421 This enables the use of the MTU2 as the system timer. 457 This enables the use of the MTU2 as the system timer.
422 458
@@ -426,7 +462,8 @@ config SH_TIMER_IRQ
426 CPU_SUBTYPE_SH7763 462 CPU_SUBTYPE_SH7763
427 default "86" if CPU_SUBTYPE_SH7619 463 default "86" if CPU_SUBTYPE_SH7619
428 default "140" if CPU_SUBTYPE_SH7206 464 default "140" if CPU_SUBTYPE_SH7206
429 default "142" if CPU_SUBTYPE_SH7203 465 default "142" if CPU_SUBTYPE_SH7203 && SH_CMT
466 default "153" if CPU_SUBTYPE_SH7203 && SH_MTU2
430 default "238" if CPU_SUBTYPE_MXG 467 default "238" if CPU_SUBTYPE_MXG
431 default "16" 468 default "16"
432 469
@@ -438,7 +475,8 @@ config SH_PCLK_FREQ
438 default "33333333" if CPU_SUBTYPE_SH7770 || CPU_SUBTYPE_SH7723 || \ 475 default "33333333" if CPU_SUBTYPE_SH7770 || CPU_SUBTYPE_SH7723 || \
439 CPU_SUBTYPE_SH7760 || CPU_SUBTYPE_SH7705 || \ 476 CPU_SUBTYPE_SH7760 || CPU_SUBTYPE_SH7705 || \
440 CPU_SUBTYPE_SH7203 || CPU_SUBTYPE_SH7206 || \ 477 CPU_SUBTYPE_SH7203 || CPU_SUBTYPE_SH7206 || \
441 CPU_SUBTYPE_SH7263 || CPU_SUBTYPE_MXG 478 CPU_SUBTYPE_SH7263 || CPU_SUBTYPE_MXG || \
479 CPU_SUBTYPE_SH7786
442 default "60000000" if CPU_SUBTYPE_SH7751 || CPU_SUBTYPE_SH7751R 480 default "60000000" if CPU_SUBTYPE_SH7751 || CPU_SUBTYPE_SH7751R
443 default "66000000" if CPU_SUBTYPE_SH4_202 481 default "66000000" if CPU_SUBTYPE_SH4_202
444 default "50000000" 482 default "50000000"
@@ -521,6 +559,13 @@ config CRASH_DUMP
521 559
522 For more details see Documentation/kdump/kdump.txt 560 For more details see Documentation/kdump/kdump.txt
523 561
562config KEXEC_JUMP
563 bool "kexec jump (EXPERIMENTAL)"
564 depends on SUPERH32 && KEXEC && HIBERNATION && EXPERIMENTAL
565 help
566 Jump between original kernel and kexeced kernel and invoke
567 code via KEXEC
568
524config SECCOMP 569config SECCOMP
525 bool "Enable seccomp to safely compute untrusted bytecode" 570 bool "Enable seccomp to safely compute untrusted bytecode"
526 depends on PROC_FS 571 depends on PROC_FS
diff --git a/arch/sh/Kconfig.cpu b/arch/sh/Kconfig.cpu
index 0e27fe3b182b..c7d704381a6d 100644
--- a/arch/sh/Kconfig.cpu
+++ b/arch/sh/Kconfig.cpu
@@ -104,6 +104,9 @@ config CPU_HAS_SR_RB
104config CPU_HAS_PTEA 104config CPU_HAS_PTEA
105 bool 105 bool
106 106
107config CPU_HAS_PTEAEX
108 bool
109
107config CPU_HAS_DSP 110config CPU_HAS_DSP
108 bool 111 bool
109 112
diff --git a/arch/sh/Makefile b/arch/sh/Makefile
index 4067b0d9287b..bece1f7535f2 100644
--- a/arch/sh/Makefile
+++ b/arch/sh/Makefile
@@ -80,6 +80,7 @@ OBJCOPYFLAGS := -O binary -R .note -R .note.gnu.build-id -R .comment \
80defaultimage-$(CONFIG_SUPERH32) := zImage 80defaultimage-$(CONFIG_SUPERH32) := zImage
81defaultimage-$(CONFIG_SH_SH7785LCR) := uImage 81defaultimage-$(CONFIG_SH_SH7785LCR) := uImage
82defaultimage-$(CONFIG_SH_RSK) := uImage 82defaultimage-$(CONFIG_SH_RSK) := uImage
83defaultimage-$(CONFIG_SH_URQUELL) := uImage
83defaultimage-$(CONFIG_SH_7206_SOLUTION_ENGINE) := vmlinux 84defaultimage-$(CONFIG_SH_7206_SOLUTION_ENGINE) := vmlinux
84defaultimage-$(CONFIG_SH_7619_SOLUTION_ENGINE) := vmlinux 85defaultimage-$(CONFIG_SH_7619_SOLUTION_ENGINE) := vmlinux
85 86
diff --git a/arch/sh/boards/Kconfig b/arch/sh/boards/Kconfig
index 861914747e4e..dcc1af8a2cfe 100644
--- a/arch/sh/boards/Kconfig
+++ b/arch/sh/boards/Kconfig
@@ -155,17 +155,22 @@ config SH_SH7785LCR
155 155
156config SH_SH7785LCR_29BIT_PHYSMAPS 156config SH_SH7785LCR_29BIT_PHYSMAPS
157 bool "SH7785LCR 29bit physmaps" 157 bool "SH7785LCR 29bit physmaps"
158 depends on SH_SH7785LCR 158 depends on SH_SH7785LCR && 29BIT
159 default y 159 default y
160 help 160 help
161 This board has 2 physical memory maps. It can be changed with 161 This board has 2 physical memory maps. It can be changed with
162 DIP switch(S2-5). If you set the DIP switch for S2-5 = ON, 162 DIP switch(S2-5). If you set the DIP switch for S2-5 = ON,
163 you can access all on-board device in 29bit address mode. 163 you can access all on-board device in 29bit address mode.
164 164
165config SH_URQUELL
166 bool "Urquell"
167 depends on CPU_SUBTYPE_SH7786
168 select ARCH_REQUIRE_GPIOLIB
169
165config SH_MIGOR 170config SH_MIGOR
166 bool "Migo-R" 171 bool "Migo-R"
167 depends on CPU_SUBTYPE_SH7722 172 depends on CPU_SUBTYPE_SH7722
168 select GENERIC_GPIO 173 select ARCH_REQUIRE_GPIOLIB
169 help 174 help
170 Select Migo-R if configuring for the SH7722 Migo-R platform 175 Select Migo-R if configuring for the SH7722 Migo-R platform
171 by Renesas System Solutions Asia Pte. Ltd. 176 by Renesas System Solutions Asia Pte. Ltd.
@@ -173,7 +178,7 @@ config SH_MIGOR
173config SH_AP325RXA 178config SH_AP325RXA
174 bool "AP-325RXA" 179 bool "AP-325RXA"
175 depends on CPU_SUBTYPE_SH7723 180 depends on CPU_SUBTYPE_SH7723
176 select GENERIC_GPIO 181 select ARCH_REQUIRE_GPIOLIB
177 help 182 help
178 Renesas "AP-325RXA" support. 183 Renesas "AP-325RXA" support.
179 Compatible with ALGO SYSTEM CO.,LTD. "AP-320A" 184 Compatible with ALGO SYSTEM CO.,LTD. "AP-320A"
@@ -185,6 +190,13 @@ config SH_SH7763RDP
185 Select SH7763RDP if configuring for a Renesas SH7763 190 Select SH7763RDP if configuring for a Renesas SH7763
186 evaluation board. 191 evaluation board.
187 192
193config SH_ESPT
194 bool "ESPT"
195 depends on CPU_SUBTYPE_SH7763
196 help
197 Select ESPT if configuring for a Renesas SH7763
198 with gigabit ether evaluation board.
199
188config SH_EDOSK7705 200config SH_EDOSK7705
189 bool "EDOSK7705" 201 bool "EDOSK7705"
190 depends on CPU_SUBTYPE_SH7705 202 depends on CPU_SUBTYPE_SH7705
@@ -240,7 +252,7 @@ config SH_X3PROTO
240config SH_MAGIC_PANEL_R2 252config SH_MAGIC_PANEL_R2
241 bool "Magic Panel R2" 253 bool "Magic Panel R2"
242 depends on CPU_SUBTYPE_SH7720 254 depends on CPU_SUBTYPE_SH7720
243 select GENERIC_GPIO 255 select ARCH_REQUIRE_GPIOLIB
244 help 256 help
245 Select Magic Panel R2 if configuring for Magic Panel R2. 257 Select Magic Panel R2 if configuring for Magic Panel R2.
246 258
@@ -249,6 +261,13 @@ config SH_CAYMAN
249 depends on CPU_SUBTYPE_SH5_101 || CPU_SUBTYPE_SH5_103 261 depends on CPU_SUBTYPE_SH5_101 || CPU_SUBTYPE_SH5_103
250 select SYS_SUPPORTS_PCI 262 select SYS_SUPPORTS_PCI
251 263
264config SH_POLARIS
265 bool "SMSC Polaris"
266 select CPU_HAS_IPR_IRQ
267 depends on CPU_SUBTYPE_SH7709
268 help
269 Select if configuring for an SMSC Polaris development board
270
252endmenu 271endmenu
253 272
254source "arch/sh/boards/mach-r2d/Kconfig" 273source "arch/sh/boards/mach-r2d/Kconfig"
diff --git a/arch/sh/boards/Makefile b/arch/sh/boards/Makefile
index 269ae2be49ef..7baa21090231 100644
--- a/arch/sh/boards/Makefile
+++ b/arch/sh/boards/Makefile
@@ -4,5 +4,8 @@
4obj-$(CONFIG_SH_AP325RXA) += board-ap325rxa.o 4obj-$(CONFIG_SH_AP325RXA) += board-ap325rxa.o
5obj-$(CONFIG_SH_MAGIC_PANEL_R2) += board-magicpanelr2.o 5obj-$(CONFIG_SH_MAGIC_PANEL_R2) += board-magicpanelr2.o
6obj-$(CONFIG_SH_SH7785LCR) += board-sh7785lcr.o 6obj-$(CONFIG_SH_SH7785LCR) += board-sh7785lcr.o
7obj-$(CONFIG_SH_URQUELL) += board-urquell.o
7obj-$(CONFIG_SH_SHMIN) += board-shmin.o 8obj-$(CONFIG_SH_SHMIN) += board-shmin.o
8obj-$(CONFIG_SH_EDOSK7760) += board-edosk7760.o 9obj-$(CONFIG_SH_EDOSK7760) += board-edosk7760.o
10obj-$(CONFIG_SH_ESPT) += board-espt.o
11obj-$(CONFIG_SH_POLARIS) += board-polaris.o
diff --git a/arch/sh/boards/board-ap325rxa.c b/arch/sh/boards/board-ap325rxa.c
index 15b6d450fbf0..a64e38841c49 100644
--- a/arch/sh/boards/board-ap325rxa.c
+++ b/arch/sh/boards/board-ap325rxa.c
@@ -166,6 +166,16 @@ static void ap320_wvga_power_on(void *board_data)
166 ctrl_outw(0x100, FPGA_BKLREG); 166 ctrl_outw(0x100, FPGA_BKLREG);
167} 167}
168 168
169static void ap320_wvga_power_off(void *board_data)
170{
171 /* backlight */
172 ctrl_outw(0, FPGA_BKLREG);
173 gpio_set_value(GPIO_PTS3, 1);
174
175 /* ASD AP-320/325 LCD OFF */
176 ctrl_outw(0, FPGA_LCDREG);
177}
178
169static struct sh_mobile_lcdc_info lcdc_info = { 179static struct sh_mobile_lcdc_info lcdc_info = {
170 .clock_source = LCDC_CLK_EXTERNAL, 180 .clock_source = LCDC_CLK_EXTERNAL,
171 .ch[0] = { 181 .ch[0] = {
@@ -191,6 +201,7 @@ static struct sh_mobile_lcdc_info lcdc_info = {
191 }, 201 },
192 .board_cfg = { 202 .board_cfg = {
193 .display_on = ap320_wvga_power_on, 203 .display_on = ap320_wvga_power_on,
204 .display_off = ap320_wvga_power_off,
194 }, 205 },
195 } 206 }
196}; 207};
diff --git a/arch/sh/boards/board-espt.c b/arch/sh/boards/board-espt.c
new file mode 100644
index 000000000000..d5ce5e18eb37
--- /dev/null
+++ b/arch/sh/boards/board-espt.c
@@ -0,0 +1,102 @@
1/*
2 * Data Technology Inc. ESPT-GIGA board suport
3 *
4 * Copyright (C) 2008, 2009 Renesas Solutions Corp.
5 * Copyright (C) 2008, 2009 Nobuhiro Iwamatsu <iwamatsu.nobuhiro@renesas.com>
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11#include <linux/init.h>
12#include <linux/platform_device.h>
13#include <linux/interrupt.h>
14#include <linux/mtd/physmap.h>
15#include <linux/io.h>
16#include <asm/machvec.h>
17#include <asm/sizes.h>
18#include <asm/sh_eth.h>
19
20/* NOR Flash */
21static struct mtd_partition espt_nor_flash_partitions[] = {
22 {
23 .name = "U-Boot",
24 .offset = 0,
25 .size = (2 * SZ_128K),
26 .mask_flags = MTD_WRITEABLE, /* Read-only */
27 }, {
28 .name = "Linux-Kernel",
29 .offset = MTDPART_OFS_APPEND,
30 .size = (20 * SZ_128K),
31 }, {
32 .name = "Root Filesystem",
33 .offset = MTDPART_OFS_APPEND,
34 .size = MTDPART_SIZ_FULL,
35 },
36};
37
38static struct physmap_flash_data espt_nor_flash_data = {
39 .width = 2,
40 .parts = espt_nor_flash_partitions,
41 .nr_parts = ARRAY_SIZE(espt_nor_flash_partitions),
42};
43
44static struct resource espt_nor_flash_resources[] = {
45 [0] = {
46 .name = "NOR Flash",
47 .start = 0,
48 .end = SZ_8M - 1,
49 .flags = IORESOURCE_MEM,
50 },
51};
52
53static struct platform_device espt_nor_flash_device = {
54 .name = "physmap-flash",
55 .resource = espt_nor_flash_resources,
56 .num_resources = ARRAY_SIZE(espt_nor_flash_resources),
57 .dev = {
58 .platform_data = &espt_nor_flash_data,
59 },
60};
61
62/* SH-Ether */
63static struct resource sh_eth_resources[] = {
64 {
65 .start = 0xFEE00800, /* use eth1 */
66 .end = 0xFEE00F7C - 1,
67 .flags = IORESOURCE_MEM,
68 }, {
69 .start = 57, /* irq number */
70 .flags = IORESOURCE_IRQ,
71 },
72};
73
74static struct sh_eth_plat_data sh7763_eth_pdata = {
75 .phy = 0,
76 .edmac_endian = EDMAC_LITTLE_ENDIAN,
77};
78
79static struct platform_device espt_eth_device = {
80 .name = "sh-eth",
81 .resource = sh_eth_resources,
82 .num_resources = ARRAY_SIZE(sh_eth_resources),
83 .dev = {
84 .platform_data = &sh7763_eth_pdata,
85 },
86};
87
88static struct platform_device *espt_devices[] __initdata = {
89 &espt_nor_flash_device,
90 &espt_eth_device,
91};
92
93static int __init espt_devices_setup(void)
94{
95 return platform_add_devices(espt_devices,
96 ARRAY_SIZE(espt_devices));
97}
98device_initcall(espt_devices_setup);
99
100static struct sh_machine_vector mv_espt __initmv = {
101 .mv_name = "ESPT-GIGA",
102};
diff --git a/arch/sh/boards/board-polaris.c b/arch/sh/boards/board-polaris.c
new file mode 100644
index 000000000000..62607eb51004
--- /dev/null
+++ b/arch/sh/boards/board-polaris.c
@@ -0,0 +1,149 @@
1/*
2 * June 2006 steve.glendinning@smsc.com
3 *
4 * Polaris-specific resource declaration
5 *
6 */
7
8#include <linux/init.h>
9#include <linux/interrupt.h>
10#include <linux/irq.h>
11#include <linux/platform_device.h>
12#include <linux/smsc911x.h>
13#include <linux/io.h>
14#include <asm/irq.h>
15#include <asm/machvec.h>
16#include <asm/heartbeat.h>
17#include <cpu/gpio.h>
18#include <mach-se/mach/se.h>
19
20#define BCR2 (0xFFFFFF62)
21#define WCR2 (0xFFFFFF66)
22#define AREA5_WAIT_CTRL (0x1C00)
23#define WAIT_STATES_10 (0x7)
24
25static struct resource smsc911x_resources[] = {
26 [0] = {
27 .name = "smsc911x-memory",
28 .start = PA_EXT5,
29 .end = PA_EXT5 + 0x1fff,
30 .flags = IORESOURCE_MEM,
31 },
32 [1] = {
33 .name = "smsc911x-irq",
34 .start = IRQ0_IRQ,
35 .end = IRQ0_IRQ,
36 .flags = IORESOURCE_IRQ,
37 },
38};
39
40static struct smsc911x_platform_config smsc911x_config = {
41 .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
42 .irq_type = SMSC911X_IRQ_TYPE_OPEN_DRAIN,
43 .flags = SMSC911X_USE_32BIT,
44 .phy_interface = PHY_INTERFACE_MODE_MII,
45};
46
47static struct platform_device smsc911x_device = {
48 .name = "smsc911x",
49 .id = 0,
50 .num_resources = ARRAY_SIZE(smsc911x_resources),
51 .resource = smsc911x_resources,
52 .dev = {
53 .platform_data = &smsc911x_config,
54 },
55};
56
57static unsigned char heartbeat_bit_pos[] = { 0, 1, 2, 3 };
58
59static struct heartbeat_data heartbeat_data = {
60 .bit_pos = heartbeat_bit_pos,
61 .nr_bits = ARRAY_SIZE(heartbeat_bit_pos),
62 .regsize = 8,
63};
64
65static struct resource heartbeat_resources[] = {
66 [0] = {
67 .start = PORT_PCDR,
68 .end = PORT_PCDR,
69 .flags = IORESOURCE_MEM,
70 },
71};
72
73static struct platform_device heartbeat_device = {
74 .name = "heartbeat",
75 .id = -1,
76 .dev = {
77 .platform_data = &heartbeat_data,
78 },
79 .num_resources = ARRAY_SIZE(heartbeat_resources),
80 .resource = heartbeat_resources,
81};
82
83static struct platform_device *polaris_devices[] __initdata = {
84 &smsc911x_device,
85 &heartbeat_device,
86};
87
88static int __init polaris_initialise(void)
89{
90 u16 wcr, bcr_mask;
91
92 printk(KERN_INFO "Configuring Polaris external bus\n");
93
94 /* Configure area 5 with 2 wait states */
95 wcr = ctrl_inw(WCR2);
96 wcr &= (~AREA5_WAIT_CTRL);
97 wcr |= (WAIT_STATES_10 << 10);
98 ctrl_outw(wcr, WCR2);
99
100 /* Configure area 5 for 32-bit access */
101 bcr_mask = ctrl_inw(BCR2);
102 bcr_mask |= 1 << 10;
103 ctrl_outw(bcr_mask, BCR2);
104
105 return platform_add_devices(polaris_devices,
106 ARRAY_SIZE(polaris_devices));
107}
108arch_initcall(polaris_initialise);
109
110static struct ipr_data ipr_irq_table[] = {
111 /* External IRQs */
112 { IRQ0_IRQ, 0, 0, 1, }, /* IRQ0 */
113 { IRQ1_IRQ, 0, 4, 1, }, /* IRQ1 */
114};
115
116static unsigned long ipr_offsets[] = {
117 INTC_IPRC
118};
119
120static struct ipr_desc ipr_irq_desc = {
121 .ipr_offsets = ipr_offsets,
122 .nr_offsets = ARRAY_SIZE(ipr_offsets),
123
124 .ipr_data = ipr_irq_table,
125 .nr_irqs = ARRAY_SIZE(ipr_irq_table),
126 .chip = {
127 .name = "sh7709-ext",
128 },
129};
130
131static void __init init_polaris_irq(void)
132{
133 /* Disable all interrupts */
134 ctrl_outw(0, BCR_ILCRA);
135 ctrl_outw(0, BCR_ILCRB);
136 ctrl_outw(0, BCR_ILCRC);
137 ctrl_outw(0, BCR_ILCRD);
138 ctrl_outw(0, BCR_ILCRE);
139 ctrl_outw(0, BCR_ILCRF);
140 ctrl_outw(0, BCR_ILCRG);
141
142 register_ipr_controller(&ipr_irq_desc);
143}
144
145static struct sh_machine_vector mv_polaris __initmv = {
146 .mv_name = "Polaris",
147 .mv_nr_irqs = 61,
148 .mv_init_irq = init_polaris_irq,
149};
diff --git a/arch/sh/boards/board-sh7785lcr.c b/arch/sh/boards/board-sh7785lcr.c
index 38a64968d7bf..94c0296bc35d 100644
--- a/arch/sh/boards/board-sh7785lcr.c
+++ b/arch/sh/boards/board-sh7785lcr.c
@@ -275,7 +275,18 @@ void __init init_sh7785lcr_IRQ(void)
275 275
276static void sh7785lcr_power_off(void) 276static void sh7785lcr_power_off(void)
277{ 277{
278 ctrl_outb(0x01, P2SEGADDR(PLD_POFCR)); 278 unsigned char *p;
279
280 p = ioremap(PLD_POFCR, PLD_POFCR + 1);
281 if (!p) {
282 printk(KERN_ERR "%s: ioremap error.\n", __func__);
283 return;
284 }
285 *p = 0x01;
286 iounmap(p);
287 set_bl_bit();
288 while (1)
289 cpu_relax();
279} 290}
280 291
281/* Initialize the board */ 292/* Initialize the board */
diff --git a/arch/sh/boards/board-urquell.c b/arch/sh/boards/board-urquell.c
new file mode 100644
index 000000000000..17036ce20086
--- /dev/null
+++ b/arch/sh/boards/board-urquell.c
@@ -0,0 +1,162 @@
1/*
2 * Renesas Technology Corp. SH7786 Urquell Support.
3 *
4 * Copyright (C) 2008 Kuninori Morimoto <morimoto.kuninori@renesas.com>
5 * Copyright (C) 2008 Yoshihiro Shimoda
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11#include <linux/init.h>
12#include <linux/platform_device.h>
13#include <linux/fb.h>
14#include <linux/smc91x.h>
15#include <linux/mtd/physmap.h>
16#include <linux/delay.h>
17#include <linux/gpio.h>
18#include <linux/irq.h>
19#include <mach/urquell.h>
20#include <cpu/sh7786.h>
21#include <asm/heartbeat.h>
22#include <asm/sizes.h>
23
24static struct resource heartbeat_resources[] = {
25 [0] = {
26 .start = BOARDREG(SLEDR),
27 .end = BOARDREG(SLEDR),
28 .flags = IORESOURCE_MEM,
29 },
30};
31
32static struct heartbeat_data heartbeat_data = {
33 .regsize = 16,
34};
35
36static struct platform_device heartbeat_device = {
37 .name = "heartbeat",
38 .id = -1,
39 .dev = {
40 .platform_data = &heartbeat_data,
41 },
42 .num_resources = ARRAY_SIZE(heartbeat_resources),
43 .resource = heartbeat_resources,
44};
45
46static struct smc91x_platdata smc91x_info = {
47 .flags = SMC91X_USE_16BIT | SMC91X_NOWAIT,
48};
49
50static struct resource smc91x_eth_resources[] = {
51 [0] = {
52 .name = "SMC91C111" ,
53 .start = 0x05800300,
54 .end = 0x0580030f,
55 .flags = IORESOURCE_MEM,
56 },
57 [1] = {
58 .start = 11,
59 .flags = IORESOURCE_IRQ,
60 },
61};
62
63static struct platform_device smc91x_eth_device = {
64 .name = "smc91x",
65 .num_resources = ARRAY_SIZE(smc91x_eth_resources),
66 .resource = smc91x_eth_resources,
67 .dev = {
68 .platform_data = &smc91x_info,
69 },
70};
71
72static struct mtd_partition nor_flash_partitions[] = {
73 {
74 .name = "loader",
75 .offset = 0x00000000,
76 .size = SZ_512K,
77 .mask_flags = MTD_WRITEABLE, /* Read-only */
78 },
79 {
80 .name = "bootenv",
81 .offset = MTDPART_OFS_APPEND,
82 .size = SZ_512K,
83 .mask_flags = MTD_WRITEABLE, /* Read-only */
84 },
85 {
86 .name = "kernel",
87 .offset = MTDPART_OFS_APPEND,
88 .size = SZ_4M,
89 },
90 {
91 .name = "data",
92 .offset = MTDPART_OFS_APPEND,
93 .size = MTDPART_SIZ_FULL,
94 },
95};
96
97static struct physmap_flash_data nor_flash_data = {
98 .width = 2,
99 .parts = nor_flash_partitions,
100 .nr_parts = ARRAY_SIZE(nor_flash_partitions),
101};
102
103static struct resource nor_flash_resources[] = {
104 [0] = {
105 .start = NOR_FLASH_ADDR,
106 .end = NOR_FLASH_ADDR + NOR_FLASH_SIZE - 1,
107 .flags = IORESOURCE_MEM,
108 }
109};
110
111static struct platform_device nor_flash_device = {
112 .name = "physmap-flash",
113 .dev = {
114 .platform_data = &nor_flash_data,
115 },
116 .num_resources = ARRAY_SIZE(nor_flash_resources),
117 .resource = nor_flash_resources,
118};
119
120static struct platform_device *urquell_devices[] __initdata = {
121 &heartbeat_device,
122 &smc91x_eth_device,
123 &nor_flash_device,
124};
125
126static int __init urquell_devices_setup(void)
127{
128 /* USB */
129 gpio_request(GPIO_FN_USB_OVC0, NULL);
130 gpio_request(GPIO_FN_USB_PENC0, NULL);
131
132 return platform_add_devices(urquell_devices,
133 ARRAY_SIZE(urquell_devices));
134}
135device_initcall(urquell_devices_setup);
136
137static void urquell_power_off(void)
138{
139 __raw_writew(0xa5a5, UBOARDREG(SRSTR));
140}
141
142static void __init urquell_init_irq(void)
143{
144 plat_irq_setup_pins(IRQ_MODE_IRL3210_MASK);
145}
146
147/* Initialize the board */
148static void __init urquell_setup(char **cmdline_p)
149{
150 printk(KERN_INFO "Renesas Technology Corp. Urquell support.\n");
151
152 pm_power_off = urquell_power_off;
153}
154
155/*
156 * The Machine Vector
157 */
158static struct sh_machine_vector mv_urquell __initmv = {
159 .mv_name = "Urquell",
160 .mv_setup = urquell_setup,
161 .mv_init_irq = urquell_init_irq,
162};
diff --git a/arch/sh/boards/mach-highlander/Kconfig b/arch/sh/boards/mach-highlander/Kconfig
index 08057f62687b..def49cc0a7b9 100644
--- a/arch/sh/boards/mach-highlander/Kconfig
+++ b/arch/sh/boards/mach-highlander/Kconfig
@@ -18,7 +18,7 @@ config SH_R7780MP
18config SH_R7785RP 18config SH_R7785RP
19 bool "R7785RP board support" 19 bool "R7785RP board support"
20 depends on CPU_SUBTYPE_SH7785 20 depends on CPU_SUBTYPE_SH7785
21 select GENERIC_GPIO 21 select ARCH_REQUIRE_GPIOLIB
22 22
23endchoice 23endchoice
24 24
diff --git a/arch/sh/boards/mach-hp6xx/pm_wakeup.S b/arch/sh/boards/mach-hp6xx/pm_wakeup.S
index 44b648cf6f23..4f18d44e0541 100644
--- a/arch/sh/boards/mach-hp6xx/pm_wakeup.S
+++ b/arch/sh/boards/mach-hp6xx/pm_wakeup.S
@@ -10,47 +10,32 @@
10#include <linux/linkage.h> 10#include <linux/linkage.h>
11#include <cpu/mmu_context.h> 11#include <cpu/mmu_context.h>
12 12
13#define k0 r0
14#define k1 r1
15#define k2 r2
16#define k3 r3
17#define k4 r4
18
19/* 13/*
20 * Kernel mode register usage: 14 * Kernel mode register usage:
21 * k0 scratch 15 * k0 scratch
22 * k1 scratch 16 * k1 scratch
23 * k2 scratch (Exception code) 17 * For more details, please have a look at entry.S
24 * k3 scratch (Return address)
25 * k4 scratch
26 * k5 reserved
27 * k6 Global Interrupt Mask (0--15 << 4)
28 * k7 CURRENT_THREAD_INFO (pointer to current thread info)
29 */ 18 */
30 19
20#define k0 r0
21#define k1 r1
22
31ENTRY(wakeup_start) 23ENTRY(wakeup_start)
32! clear STBY bit 24! clear STBY bit
33 mov #-126, k2 25 mov #-126, k1
34 and #127, k0 26 and #127, k0
35 mov.b k0, @k2 27 mov.b k0, @k1
36! enable refresh 28! enable refresh
37 mov.l 5f, k1 29 mov.l 5f, k1
38 mov.w 6f, k0 30 mov.w 6f, k0
39 mov.w k0, @k1 31 mov.w k0, @k1
40! jump to handler 32! jump to handler
41 mov.l 2f, k2
42 mov.l 3f, k3
43 mov.l @k2, k2
44
45 mov.l 4f, k1 33 mov.l 4f, k1
46 jmp @k1 34 jmp @k1
47 nop 35 nop
48 36
49 .align 2 37 .align 2
501: .long EXPEVT 384: .long handle_interrupt
512: .long INTEVT
523: .long ret_from_irq
534: .long handle_exception
545: .long 0xffffff68 395: .long 0xffffff68
556: .word 0x0524 406: .word 0x0524
56 41
diff --git a/arch/sh/boards/mach-hp6xx/setup.c b/arch/sh/boards/mach-hp6xx/setup.c
index 746742bdc014..8f305b36358b 100644
--- a/arch/sh/boards/mach-hp6xx/setup.c
+++ b/arch/sh/boards/mach-hp6xx/setup.c
@@ -115,7 +115,6 @@ static struct sh_machine_vector mv_hp6xx __initmv = {
115 .mv_setup = hp6xx_setup, 115 .mv_setup = hp6xx_setup,
116 /* IRQ's : CPU(64) + CCHIP(16) + FREE_TO_USE(6) */ 116 /* IRQ's : CPU(64) + CCHIP(16) + FREE_TO_USE(6) */
117 .mv_nr_irqs = HD64461_IRQBASE + HD64461_IRQ_NUM + 6, 117 .mv_nr_irqs = HD64461_IRQBASE + HD64461_IRQ_NUM + 6,
118 .mv_irq_demux = hd64461_irq_demux,
119 /* Enable IRQ0 -> IRQ3 in IRQ_MODE */ 118 /* Enable IRQ0 -> IRQ3 in IRQ_MODE */
120 .mv_init_irq = hp6xx_init_irq, 119 .mv_init_irq = hp6xx_init_irq,
121}; 120};
diff --git a/arch/sh/boards/mach-migor/setup.c b/arch/sh/boards/mach-migor/setup.c
index 28e56c5809a2..bc35b4cae6b3 100644
--- a/arch/sh/boards/mach-migor/setup.c
+++ b/arch/sh/boards/mach-migor/setup.c
@@ -450,6 +450,14 @@ static struct spi_board_info migor_spi_devices[] = {
450 450
451static int __init migor_devices_setup(void) 451static int __init migor_devices_setup(void)
452{ 452{
453
454#ifdef CONFIG_PM
455 /* Let D11 LED show STATUS0 */
456 gpio_request(GPIO_FN_STATUS0, NULL);
457
458 /* Lit D12 LED show PDSTATUS */
459 gpio_request(GPIO_FN_PDSTATUS, NULL);
460#else
453 /* Lit D11 LED */ 461 /* Lit D11 LED */
454 gpio_request(GPIO_PTJ7, NULL); 462 gpio_request(GPIO_PTJ7, NULL);
455 gpio_direction_output(GPIO_PTJ7, 1); 463 gpio_direction_output(GPIO_PTJ7, 1);
@@ -459,6 +467,7 @@ static int __init migor_devices_setup(void)
459 gpio_request(GPIO_PTJ5, NULL); 467 gpio_request(GPIO_PTJ5, NULL);
460 gpio_direction_output(GPIO_PTJ5, 1); 468 gpio_direction_output(GPIO_PTJ5, 1);
461 gpio_export(GPIO_PTJ5, 0); 469 gpio_export(GPIO_PTJ5, 0);
470#endif
462 471
463 /* SMC91C111 - Enable IRQ0, Setup CS4 for 16-bit fast access */ 472 /* SMC91C111 - Enable IRQ0, Setup CS4 for 16-bit fast access */
464 gpio_request(GPIO_FN_IRQ0, NULL); 473 gpio_request(GPIO_FN_IRQ0, NULL);
diff --git a/arch/sh/boards/mach-rsk/Kconfig b/arch/sh/boards/mach-rsk/Kconfig
index bff095dffc02..aeff3b042205 100644
--- a/arch/sh/boards/mach-rsk/Kconfig
+++ b/arch/sh/boards/mach-rsk/Kconfig
@@ -10,7 +10,7 @@ config SH_RSK7201
10 10
11config SH_RSK7203 11config SH_RSK7203
12 bool "RSK7203" 12 bool "RSK7203"
13 select GENERIC_GPIO 13 select ARCH_REQUIRE_GPIOLIB
14 depends on CPU_SUBTYPE_SH7203 14 depends on CPU_SUBTYPE_SH7203
15 15
16endchoice 16endchoice
diff --git a/arch/sh/boards/mach-sh7763rdp/setup.c b/arch/sh/boards/mach-sh7763rdp/setup.c
index 6f926fd2162b..390534a0b35c 100644
--- a/arch/sh/boards/mach-sh7763rdp/setup.c
+++ b/arch/sh/boards/mach-sh7763rdp/setup.c
@@ -63,15 +63,19 @@ static struct platform_device sh7763rdp_nor_flash_device = {
63 }, 63 },
64}; 64};
65 65
66/* SH-Ether */ 66/*
67 * SH-Ether
68 *
69 * SH Ether of SH7763 has multi IRQ handling.
70 * (57,58,59 -> 57)
71 */
67static struct resource sh_eth_resources[] = { 72static struct resource sh_eth_resources[] = {
68 { 73 {
69 .start = 0xFEE00800, /* use eth1 */ 74 .start = 0xFEE00800, /* use eth1 */
70 .end = 0xFEE00F7C - 1, 75 .end = 0xFEE00F7C - 1,
71 .flags = IORESOURCE_MEM, 76 .flags = IORESOURCE_MEM,
72 }, { 77 }, {
73 .start = 58, /* irq number */ 78 .start = 57, /* irq number */
74 .end = 58,
75 .flags = IORESOURCE_IRQ, 79 .flags = IORESOURCE_IRQ,
76 }, 80 },
77}; 81};
diff --git a/arch/sh/boot/Makefile b/arch/sh/boot/Makefile
index c16ccd4bfa16..95483d161258 100644
--- a/arch/sh/boot/Makefile
+++ b/arch/sh/boot/Makefile
@@ -33,20 +33,24 @@ $(obj)/zImage: $(obj)/compressed/vmlinux FORCE
33$(obj)/compressed/vmlinux: FORCE 33$(obj)/compressed/vmlinux: FORCE
34 $(Q)$(MAKE) $(build)=$(obj)/compressed $@ 34 $(Q)$(MAKE) $(build)=$(obj)/compressed $@
35 35
36ifeq ($(CONFIG_32BIT),y) 36KERNEL_MEMORY := 0x00000000
37KERNEL_LOAD := $(shell /bin/bash -c 'printf "0x%08x" \ 37ifeq ($(CONFIG_PMB_FIXED),y)
38 $$[$(CONFIG_PAGE_OFFSET) + \ 38KERNEL_MEMORY := $(shell /bin/bash -c 'printf "0x%08x" \
39 $(CONFIG_ZERO_PAGE_OFFSET)]') 39 $$[$(CONFIG_MEMORY_START) & 0x1fffffff]')
40else 40endif
41ifeq ($(CONFIG_29BIT),y)
42KERNEL_MEMORY := $(shell /bin/bash -c 'printf "0x%08x" \
43 $$[$(CONFIG_MEMORY_START)]')
44endif
45
41KERNEL_LOAD := $(shell /bin/bash -c 'printf "0x%08x" \ 46KERNEL_LOAD := $(shell /bin/bash -c 'printf "0x%08x" \
42 $$[$(CONFIG_PAGE_OFFSET) + \ 47 $$[$(CONFIG_PAGE_OFFSET) + \
43 $(CONFIG_MEMORY_START) + \ 48 $(KERNEL_MEMORY) + \
44 $(CONFIG_ZERO_PAGE_OFFSET)]') 49 $(CONFIG_ZERO_PAGE_OFFSET)]')
45endif
46 50
47KERNEL_ENTRY := $(shell /bin/bash -c 'printf "0x%08x" \ 51KERNEL_ENTRY := $(shell /bin/bash -c 'printf "0x%08x" \
48 $$[$(CONFIG_PAGE_OFFSET) + \ 52 $$[$(CONFIG_PAGE_OFFSET) + \
49 $(CONFIG_MEMORY_START) + \ 53 $(KERNEL_MEMORY) + \
50 $(CONFIG_ZERO_PAGE_OFFSET) + $(CONFIG_ENTRY_OFFSET)]') 54 $(CONFIG_ZERO_PAGE_OFFSET) + $(CONFIG_ENTRY_OFFSET)]')
51 55
52quiet_cmd_uimage = UIMAGE $@ 56quiet_cmd_uimage = UIMAGE $@
diff --git a/arch/sh/cchips/hd6446x/hd64461.c b/arch/sh/cchips/hd6446x/hd64461.c
index 27ceeb948bb1..25ef91061521 100644
--- a/arch/sh/cchips/hd6446x/hd64461.c
+++ b/arch/sh/cchips/hd6446x/hd64461.c
@@ -53,21 +53,22 @@ static struct irq_chip hd64461_irq_chip = {
53 .unmask = hd64461_unmask_irq, 53 .unmask = hd64461_unmask_irq,
54}; 54};
55 55
56int hd64461_irq_demux(int irq) 56static void hd64461_irq_demux(unsigned int irq, struct irq_desc *desc)
57{ 57{
58 if (irq == CONFIG_HD64461_IRQ) { 58 unsigned short intv = ctrl_inw(HD64461_NIRR);
59 unsigned short bit; 59 struct irq_desc *ext_desc;
60 unsigned short nirr = inw(HD64461_NIRR); 60 unsigned int ext_irq = HD64461_IRQBASE;
61 unsigned short nimr = inw(HD64461_NIMR); 61
62 int i; 62 intv &= (1 << HD64461_IRQ_NUM) - 1;
63 63
64 nirr &= ~nimr; 64 while (intv) {
65 for (bit = 1, i = 0; i < 16; bit <<= 1, i++) 65 if (intv & 1) {
66 if (nirr & bit) 66 ext_desc = irq_desc + ext_irq;
67 break; 67 handle_level_irq(ext_irq, ext_desc);
68 irq = HD64461_IRQBASE + i; 68 }
69 intv >>= 1;
70 ext_irq++;
69 } 71 }
70 return irq;
71} 72}
72 73
73int __init setup_hd64461(void) 74int __init setup_hd64461(void)
@@ -93,6 +94,9 @@ int __init setup_hd64461(void)
93 set_irq_chip_and_handler(i, &hd64461_irq_chip, 94 set_irq_chip_and_handler(i, &hd64461_irq_chip,
94 handle_level_irq); 95 handle_level_irq);
95 96
97 set_irq_chained_handler(CONFIG_HD64461_IRQ, hd64461_irq_demux);
98 set_irq_type(CONFIG_HD64461_IRQ, IRQ_TYPE_LEVEL_LOW);
99
96#ifdef CONFIG_HD64461_ENABLER 100#ifdef CONFIG_HD64461_ENABLER
97 printk(KERN_INFO "HD64461: enabling PCMCIA devices\n"); 101 printk(KERN_INFO "HD64461: enabling PCMCIA devices\n");
98 __raw_writeb(0x4c, HD64461_PCC1CSCIER); 102 __raw_writeb(0x4c, HD64461_PCC1CSCIER);
diff --git a/arch/sh/configs/espt_defconfig b/arch/sh/configs/espt_defconfig
new file mode 100644
index 000000000000..873ec42c6e69
--- /dev/null
+++ b/arch/sh/configs/espt_defconfig
@@ -0,0 +1,1190 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29-rc7
4# Tue Mar 17 13:25:58 2009
5#
6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y
11CONFIG_GENERIC_FIND_NEXT_BIT=y
12CONFIG_GENERIC_HWEIGHT=y
13CONFIG_GENERIC_HARDIRQS=y
14CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
15CONFIG_GENERIC_IRQ_PROBE=y
16# CONFIG_GENERIC_GPIO is not set
17CONFIG_GENERIC_TIME=y
18CONFIG_GENERIC_CLOCKEVENTS=y
19# CONFIG_ARCH_SUSPEND_POSSIBLE is not set
20# CONFIG_ARCH_HIBERNATION_POSSIBLE is not set
21CONFIG_STACKTRACE_SUPPORT=y
22CONFIG_LOCKDEP_SUPPORT=y
23CONFIG_HAVE_LATENCYTOP_SUPPORT=y
24# CONFIG_ARCH_HAS_ILOG2_U32 is not set
25# CONFIG_ARCH_HAS_ILOG2_U64 is not set
26CONFIG_ARCH_NO_VIRT_TO_BUS=y
27CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
28
29#
30# General setup
31#
32CONFIG_EXPERIMENTAL=y
33CONFIG_BROKEN_ON_SMP=y
34CONFIG_INIT_ENV_ARG_LIMIT=32
35CONFIG_LOCALVERSION=""
36CONFIG_LOCALVERSION_AUTO=y
37CONFIG_SWAP=y
38CONFIG_SYSVIPC=y
39CONFIG_SYSVIPC_SYSCTL=y
40# CONFIG_POSIX_MQUEUE is not set
41# CONFIG_BSD_PROCESS_ACCT is not set
42# CONFIG_TASKSTATS is not set
43# CONFIG_AUDIT is not set
44
45#
46# RCU Subsystem
47#
48CONFIG_CLASSIC_RCU=y
49# CONFIG_TREE_RCU is not set
50# CONFIG_PREEMPT_RCU is not set
51# CONFIG_TREE_RCU_TRACE is not set
52# CONFIG_PREEMPT_RCU_TRACE is not set
53CONFIG_IKCONFIG=y
54CONFIG_IKCONFIG_PROC=y
55CONFIG_LOG_BUF_SHIFT=14
56CONFIG_GROUP_SCHED=y
57CONFIG_FAIR_GROUP_SCHED=y
58# CONFIG_RT_GROUP_SCHED is not set
59CONFIG_USER_SCHED=y
60# CONFIG_CGROUP_SCHED is not set
61# CONFIG_CGROUPS is not set
62CONFIG_SYSFS_DEPRECATED=y
63CONFIG_SYSFS_DEPRECATED_V2=y
64# CONFIG_RELAY is not set
65CONFIG_NAMESPACES=y
66CONFIG_UTS_NS=y
67CONFIG_IPC_NS=y
68# CONFIG_USER_NS is not set
69# CONFIG_PID_NS is not set
70# CONFIG_NET_NS is not set
71# CONFIG_BLK_DEV_INITRD is not set
72CONFIG_CC_OPTIMIZE_FOR_SIZE=y
73CONFIG_SYSCTL=y
74CONFIG_EMBEDDED=y
75CONFIG_UID16=y
76# CONFIG_SYSCTL_SYSCALL is not set
77CONFIG_KALLSYMS=y
78# CONFIG_KALLSYMS_EXTRA_PASS is not set
79CONFIG_HOTPLUG=y
80CONFIG_PRINTK=y
81CONFIG_BUG=y
82CONFIG_ELF_CORE=y
83CONFIG_COMPAT_BRK=y
84CONFIG_BASE_FULL=y
85CONFIG_FUTEX=y
86CONFIG_ANON_INODES=y
87CONFIG_EPOLL=y
88CONFIG_SIGNALFD=y
89CONFIG_TIMERFD=y
90CONFIG_EVENTFD=y
91CONFIG_SHMEM=y
92CONFIG_AIO=y
93CONFIG_VM_EVENT_COUNTERS=y
94CONFIG_SLAB=y
95# CONFIG_SLUB is not set
96# CONFIG_SLOB is not set
97CONFIG_PROFILING=y
98CONFIG_TRACEPOINTS=y
99# CONFIG_MARKERS is not set
100CONFIG_OPROFILE=y
101CONFIG_HAVE_OPROFILE=y
102# CONFIG_KPROBES is not set
103CONFIG_HAVE_IOREMAP_PROT=y
104CONFIG_HAVE_KPROBES=y
105CONFIG_HAVE_KRETPROBES=y
106CONFIG_HAVE_ARCH_TRACEHOOK=y
107CONFIG_HAVE_CLK=y
108CONFIG_HAVE_GENERIC_DMA_COHERENT=y
109CONFIG_SLABINFO=y
110CONFIG_RT_MUTEXES=y
111CONFIG_BASE_SMALL=0
112CONFIG_MODULES=y
113# CONFIG_MODULE_FORCE_LOAD is not set
114# CONFIG_MODULE_UNLOAD is not set
115# CONFIG_MODVERSIONS is not set
116# CONFIG_MODULE_SRCVERSION_ALL is not set
117CONFIG_BLOCK=y
118# CONFIG_LBD is not set
119# CONFIG_BLK_DEV_IO_TRACE is not set
120# CONFIG_BLK_DEV_BSG is not set
121# CONFIG_BLK_DEV_INTEGRITY is not set
122
123#
124# IO Schedulers
125#
126CONFIG_IOSCHED_NOOP=y
127CONFIG_IOSCHED_AS=y
128CONFIG_IOSCHED_DEADLINE=y
129CONFIG_IOSCHED_CFQ=y
130CONFIG_DEFAULT_AS=y
131# CONFIG_DEFAULT_DEADLINE is not set
132# CONFIG_DEFAULT_CFQ is not set
133# CONFIG_DEFAULT_NOOP is not set
134CONFIG_DEFAULT_IOSCHED="anticipatory"
135# CONFIG_FREEZER is not set
136
137#
138# System type
139#
140CONFIG_CPU_SH4=y
141CONFIG_CPU_SH4A=y
142# CONFIG_CPU_SUBTYPE_SH7619 is not set
143# CONFIG_CPU_SUBTYPE_SH7201 is not set
144# CONFIG_CPU_SUBTYPE_SH7203 is not set
145# CONFIG_CPU_SUBTYPE_SH7206 is not set
146# CONFIG_CPU_SUBTYPE_SH7263 is not set
147# CONFIG_CPU_SUBTYPE_MXG is not set
148# CONFIG_CPU_SUBTYPE_SH7705 is not set
149# CONFIG_CPU_SUBTYPE_SH7706 is not set
150# CONFIG_CPU_SUBTYPE_SH7707 is not set
151# CONFIG_CPU_SUBTYPE_SH7708 is not set
152# CONFIG_CPU_SUBTYPE_SH7709 is not set
153# CONFIG_CPU_SUBTYPE_SH7710 is not set
154# CONFIG_CPU_SUBTYPE_SH7712 is not set
155# CONFIG_CPU_SUBTYPE_SH7720 is not set
156# CONFIG_CPU_SUBTYPE_SH7721 is not set
157# CONFIG_CPU_SUBTYPE_SH7750 is not set
158# CONFIG_CPU_SUBTYPE_SH7091 is not set
159# CONFIG_CPU_SUBTYPE_SH7750R is not set
160# CONFIG_CPU_SUBTYPE_SH7750S is not set
161# CONFIG_CPU_SUBTYPE_SH7751 is not set
162# CONFIG_CPU_SUBTYPE_SH7751R is not set
163# CONFIG_CPU_SUBTYPE_SH7760 is not set
164# CONFIG_CPU_SUBTYPE_SH4_202 is not set
165# CONFIG_CPU_SUBTYPE_SH7723 is not set
166CONFIG_CPU_SUBTYPE_SH7763=y
167# CONFIG_CPU_SUBTYPE_SH7770 is not set
168# CONFIG_CPU_SUBTYPE_SH7780 is not set
169# CONFIG_CPU_SUBTYPE_SH7785 is not set
170# CONFIG_CPU_SUBTYPE_SH7786 is not set
171# CONFIG_CPU_SUBTYPE_SHX3 is not set
172# CONFIG_CPU_SUBTYPE_SH7343 is not set
173# CONFIG_CPU_SUBTYPE_SH7722 is not set
174# CONFIG_CPU_SUBTYPE_SH7366 is not set
175# CONFIG_CPU_SUBTYPE_SH5_101 is not set
176# CONFIG_CPU_SUBTYPE_SH5_103 is not set
177
178#
179# Memory management options
180#
181CONFIG_QUICKLIST=y
182CONFIG_MMU=y
183CONFIG_PAGE_OFFSET=0x80000000
184CONFIG_MEMORY_START=0x0c000000
185CONFIG_MEMORY_SIZE=0x04000000
186CONFIG_29BIT=y
187CONFIG_VSYSCALL=y
188CONFIG_ARCH_FLATMEM_ENABLE=y
189CONFIG_ARCH_SPARSEMEM_ENABLE=y
190CONFIG_ARCH_SPARSEMEM_DEFAULT=y
191CONFIG_MAX_ACTIVE_REGIONS=1
192CONFIG_ARCH_POPULATES_NODE_MAP=y
193CONFIG_ARCH_SELECT_MEMORY_MODEL=y
194CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
195CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
196CONFIG_PAGE_SIZE_4KB=y
197# CONFIG_PAGE_SIZE_8KB is not set
198# CONFIG_PAGE_SIZE_16KB is not set
199# CONFIG_PAGE_SIZE_64KB is not set
200CONFIG_ENTRY_OFFSET=0x00001000
201CONFIG_SELECT_MEMORY_MODEL=y
202# CONFIG_FLATMEM_MANUAL is not set
203# CONFIG_DISCONTIGMEM_MANUAL is not set
204CONFIG_SPARSEMEM_MANUAL=y
205CONFIG_SPARSEMEM=y
206CONFIG_HAVE_MEMORY_PRESENT=y
207CONFIG_SPARSEMEM_STATIC=y
208# CONFIG_MEMORY_HOTPLUG is not set
209CONFIG_PAGEFLAGS_EXTENDED=y
210CONFIG_SPLIT_PTLOCK_CPUS=4
211CONFIG_MIGRATION=y
212# CONFIG_PHYS_ADDR_T_64BIT is not set
213CONFIG_ZONE_DMA_FLAG=0
214CONFIG_NR_QUICK=2
215CONFIG_UNEVICTABLE_LRU=y
216
217#
218# Cache configuration
219#
220# CONFIG_SH_DIRECT_MAPPED is not set
221CONFIG_CACHE_WRITEBACK=y
222# CONFIG_CACHE_WRITETHROUGH is not set
223# CONFIG_CACHE_OFF is not set
224
225#
226# Processor features
227#
228CONFIG_CPU_LITTLE_ENDIAN=y
229# CONFIG_CPU_BIG_ENDIAN is not set
230CONFIG_SH_FPU=y
231# CONFIG_SH_STORE_QUEUES is not set
232CONFIG_CPU_HAS_INTEVT=y
233CONFIG_CPU_HAS_SR_RB=y
234CONFIG_CPU_HAS_FPU=y
235
236#
237# Board support
238#
239# CONFIG_SH_SH7763RDP is not set
240CONFIG_SH_ESPT=y
241
242#
243# Timer and clock configuration
244#
245CONFIG_SH_TMU=y
246CONFIG_SH_TIMER_IRQ=28
247CONFIG_SH_PCLK_FREQ=66666666
248# CONFIG_NO_HZ is not set
249# CONFIG_HIGH_RES_TIMERS is not set
250CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
251
252#
253# CPU Frequency scaling
254#
255# CONFIG_CPU_FREQ is not set
256
257#
258# DMA support
259#
260# CONFIG_SH_DMA is not set
261
262#
263# Companion Chips
264#
265
266#
267# Additional SuperH Device Drivers
268#
269# CONFIG_HEARTBEAT is not set
270# CONFIG_PUSH_SWITCH is not set
271
272#
273# Kernel features
274#
275# CONFIG_HZ_100 is not set
276CONFIG_HZ_250=y
277# CONFIG_HZ_300 is not set
278# CONFIG_HZ_1000 is not set
279CONFIG_HZ=250
280# CONFIG_SCHED_HRTICK is not set
281# CONFIG_KEXEC is not set
282# CONFIG_CRASH_DUMP is not set
283CONFIG_SECCOMP=y
284CONFIG_PREEMPT_NONE=y
285# CONFIG_PREEMPT_VOLUNTARY is not set
286# CONFIG_PREEMPT is not set
287CONFIG_GUSA=y
288
289#
290# Boot options
291#
292CONFIG_ZERO_PAGE_OFFSET=0x00001000
293CONFIG_BOOT_LINK_OFFSET=0x00800000
294CONFIG_CMDLINE_BOOL=y
295CONFIG_CMDLINE="console=ttySC0,115200 root=/dev/nfs ip=bootp"
296
297#
298# Bus options
299#
300# CONFIG_ARCH_SUPPORTS_MSI is not set
301# CONFIG_PCCARD is not set
302
303#
304# Executable file formats
305#
306CONFIG_BINFMT_ELF=y
307# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
308# CONFIG_HAVE_AOUT is not set
309# CONFIG_BINFMT_MISC is not set
310
311#
312# Power management options (EXPERIMENTAL)
313#
314# CONFIG_PM is not set
315# CONFIG_CPU_IDLE is not set
316CONFIG_NET=y
317
318#
319# Networking options
320#
321CONFIG_COMPAT_NET_DEV_OPS=y
322CONFIG_PACKET=y
323# CONFIG_PACKET_MMAP is not set
324CONFIG_UNIX=y
325CONFIG_XFRM=y
326# CONFIG_XFRM_USER is not set
327# CONFIG_XFRM_SUB_POLICY is not set
328# CONFIG_XFRM_MIGRATE is not set
329# CONFIG_XFRM_STATISTICS is not set
330# CONFIG_NET_KEY is not set
331CONFIG_INET=y
332# CONFIG_IP_MULTICAST is not set
333# CONFIG_IP_ADVANCED_ROUTER is not set
334CONFIG_IP_FIB_HASH=y
335CONFIG_IP_PNP=y
336CONFIG_IP_PNP_DHCP=y
337CONFIG_IP_PNP_BOOTP=y
338# CONFIG_IP_PNP_RARP is not set
339# CONFIG_NET_IPIP is not set
340# CONFIG_NET_IPGRE is not set
341# CONFIG_ARPD is not set
342# CONFIG_SYN_COOKIES is not set
343# CONFIG_INET_AH is not set
344# CONFIG_INET_ESP is not set
345# CONFIG_INET_IPCOMP is not set
346# CONFIG_INET_XFRM_TUNNEL is not set
347# CONFIG_INET_TUNNEL is not set
348CONFIG_INET_XFRM_MODE_TRANSPORT=y
349CONFIG_INET_XFRM_MODE_TUNNEL=y
350CONFIG_INET_XFRM_MODE_BEET=y
351# CONFIG_INET_LRO is not set
352CONFIG_INET_DIAG=y
353CONFIG_INET_TCP_DIAG=y
354# CONFIG_TCP_CONG_ADVANCED is not set
355CONFIG_TCP_CONG_CUBIC=y
356CONFIG_DEFAULT_TCP_CONG="cubic"
357# CONFIG_TCP_MD5SIG is not set
358# CONFIG_IPV6 is not set
359# CONFIG_NETWORK_SECMARK is not set
360# CONFIG_NETFILTER is not set
361# CONFIG_IP_DCCP is not set
362# CONFIG_IP_SCTP is not set
363# CONFIG_TIPC is not set
364# CONFIG_ATM is not set
365# CONFIG_BRIDGE is not set
366# CONFIG_NET_DSA is not set
367# CONFIG_VLAN_8021Q is not set
368# CONFIG_DECNET is not set
369# CONFIG_LLC2 is not set
370# CONFIG_IPX is not set
371# CONFIG_ATALK is not set
372# CONFIG_X25 is not set
373# CONFIG_LAPB is not set
374# CONFIG_ECONET is not set
375# CONFIG_WAN_ROUTER is not set
376# CONFIG_NET_SCHED is not set
377# CONFIG_DCB is not set
378
379#
380# Network testing
381#
382# CONFIG_NET_PKTGEN is not set
383# CONFIG_HAMRADIO is not set
384# CONFIG_CAN is not set
385# CONFIG_IRDA is not set
386# CONFIG_BT is not set
387# CONFIG_AF_RXRPC is not set
388# CONFIG_PHONET is not set
389# CONFIG_WIRELESS is not set
390# CONFIG_WIMAX is not set
391# CONFIG_RFKILL is not set
392# CONFIG_NET_9P is not set
393
394#
395# Device Drivers
396#
397
398#
399# Generic Driver Options
400#
401CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
402CONFIG_STANDALONE=y
403CONFIG_PREVENT_FIRMWARE_BUILD=y
404CONFIG_FW_LOADER=y
405CONFIG_FIRMWARE_IN_KERNEL=y
406CONFIG_EXTRA_FIRMWARE=""
407# CONFIG_SYS_HYPERVISOR is not set
408# CONFIG_CONNECTOR is not set
409CONFIG_MTD=y
410# CONFIG_MTD_DEBUG is not set
411# CONFIG_MTD_CONCAT is not set
412CONFIG_MTD_PARTITIONS=y
413# CONFIG_MTD_TESTS is not set
414# CONFIG_MTD_REDBOOT_PARTS is not set
415CONFIG_MTD_CMDLINE_PARTS=y
416# CONFIG_MTD_AR7_PARTS is not set
417
418#
419# User Modules And Translation Layers
420#
421CONFIG_MTD_CHAR=y
422CONFIG_MTD_BLKDEVS=y
423CONFIG_MTD_BLOCK=y
424# CONFIG_FTL is not set
425# CONFIG_NFTL is not set
426# CONFIG_INFTL is not set
427# CONFIG_RFD_FTL is not set
428# CONFIG_SSFDC is not set
429# CONFIG_MTD_OOPS is not set
430
431#
432# RAM/ROM/Flash chip drivers
433#
434CONFIG_MTD_CFI=y
435CONFIG_MTD_JEDECPROBE=y
436CONFIG_MTD_GEN_PROBE=y
437CONFIG_MTD_CFI_ADV_OPTIONS=y
438CONFIG_MTD_CFI_NOSWAP=y
439# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
440# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
441CONFIG_MTD_CFI_GEOMETRY=y
442# CONFIG_MTD_MAP_BANK_WIDTH_1 is not set
443CONFIG_MTD_MAP_BANK_WIDTH_2=y
444# CONFIG_MTD_MAP_BANK_WIDTH_4 is not set
445# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
446# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
447# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
448CONFIG_MTD_CFI_I1=y
449CONFIG_MTD_CFI_I2=y
450# CONFIG_MTD_CFI_I4 is not set
451# CONFIG_MTD_CFI_I8 is not set
452# CONFIG_MTD_OTP is not set
453# CONFIG_MTD_CFI_INTELEXT is not set
454CONFIG_MTD_CFI_AMDSTD=y
455# CONFIG_MTD_CFI_STAA is not set
456CONFIG_MTD_CFI_UTIL=y
457# CONFIG_MTD_RAM is not set
458# CONFIG_MTD_ROM is not set
459# CONFIG_MTD_ABSENT is not set
460
461#
462# Mapping drivers for chip access
463#
464CONFIG_MTD_COMPLEX_MAPPINGS=y
465CONFIG_MTD_PHYSMAP=y
466# CONFIG_MTD_PHYSMAP_COMPAT is not set
467# CONFIG_MTD_PLATRAM is not set
468
469#
470# Self-contained MTD device drivers
471#
472# CONFIG_MTD_SLRAM is not set
473# CONFIG_MTD_PHRAM is not set
474# CONFIG_MTD_MTDRAM is not set
475# CONFIG_MTD_BLOCK2MTD is not set
476
477#
478# Disk-On-Chip Device Drivers
479#
480# CONFIG_MTD_DOC2000 is not set
481# CONFIG_MTD_DOC2001 is not set
482# CONFIG_MTD_DOC2001PLUS is not set
483# CONFIG_MTD_NAND is not set
484# CONFIG_MTD_ONENAND is not set
485
486#
487# LPDDR flash memory drivers
488#
489# CONFIG_MTD_LPDDR is not set
490
491#
492# UBI - Unsorted block images
493#
494# CONFIG_MTD_UBI is not set
495# CONFIG_PARPORT is not set
496CONFIG_BLK_DEV=y
497# CONFIG_BLK_DEV_COW_COMMON is not set
498# CONFIG_BLK_DEV_LOOP is not set
499# CONFIG_BLK_DEV_NBD is not set
500# CONFIG_BLK_DEV_UB is not set
501# CONFIG_BLK_DEV_RAM is not set
502# CONFIG_CDROM_PKTCDVD is not set
503# CONFIG_ATA_OVER_ETH is not set
504# CONFIG_BLK_DEV_HD is not set
505# CONFIG_MISC_DEVICES is not set
506CONFIG_HAVE_IDE=y
507# CONFIG_IDE is not set
508
509#
510# SCSI device support
511#
512# CONFIG_RAID_ATTRS is not set
513CONFIG_SCSI=y
514CONFIG_SCSI_DMA=y
515# CONFIG_SCSI_TGT is not set
516# CONFIG_SCSI_NETLINK is not set
517CONFIG_SCSI_PROC_FS=y
518
519#
520# SCSI support type (disk, tape, CD-ROM)
521#
522CONFIG_BLK_DEV_SD=y
523# CONFIG_CHR_DEV_ST is not set
524# CONFIG_CHR_DEV_OSST is not set
525# CONFIG_BLK_DEV_SR is not set
526# CONFIG_CHR_DEV_SG is not set
527# CONFIG_CHR_DEV_SCH is not set
528
529#
530# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
531#
532# CONFIG_SCSI_MULTI_LUN is not set
533# CONFIG_SCSI_CONSTANTS is not set
534# CONFIG_SCSI_LOGGING is not set
535# CONFIG_SCSI_SCAN_ASYNC is not set
536CONFIG_SCSI_WAIT_SCAN=m
537
538#
539# SCSI Transports
540#
541# CONFIG_SCSI_SPI_ATTRS is not set
542# CONFIG_SCSI_FC_ATTRS is not set
543# CONFIG_SCSI_ISCSI_ATTRS is not set
544# CONFIG_SCSI_SAS_LIBSAS is not set
545# CONFIG_SCSI_SRP_ATTRS is not set
546CONFIG_SCSI_LOWLEVEL=y
547# CONFIG_ISCSI_TCP is not set
548# CONFIG_LIBFC is not set
549# CONFIG_SCSI_DEBUG is not set
550# CONFIG_SCSI_DH is not set
551# CONFIG_ATA is not set
552# CONFIG_MD is not set
553CONFIG_NETDEVICES=y
554# CONFIG_DUMMY is not set
555# CONFIG_BONDING is not set
556# CONFIG_MACVLAN is not set
557# CONFIG_EQUALIZER is not set
558# CONFIG_TUN is not set
559# CONFIG_VETH is not set
560CONFIG_PHYLIB=y
561
562#
563# MII PHY device drivers
564#
565# CONFIG_MARVELL_PHY is not set
566# CONFIG_DAVICOM_PHY is not set
567# CONFIG_QSEMI_PHY is not set
568# CONFIG_LXT_PHY is not set
569# CONFIG_CICADA_PHY is not set
570# CONFIG_VITESSE_PHY is not set
571# CONFIG_SMSC_PHY is not set
572# CONFIG_BROADCOM_PHY is not set
573# CONFIG_ICPLUS_PHY is not set
574# CONFIG_REALTEK_PHY is not set
575# CONFIG_NATIONAL_PHY is not set
576# CONFIG_STE10XP is not set
577# CONFIG_LSI_ET1011C_PHY is not set
578# CONFIG_FIXED_PHY is not set
579CONFIG_MDIO_BITBANG=y
580CONFIG_NET_ETHERNET=y
581CONFIG_MII=y
582# CONFIG_AX88796 is not set
583# CONFIG_STNIC is not set
584CONFIG_SH_ETH=y
585# CONFIG_SMC91X is not set
586# CONFIG_SMC911X is not set
587# CONFIG_SMSC911X is not set
588# CONFIG_IBM_NEW_EMAC_ZMII is not set
589# CONFIG_IBM_NEW_EMAC_RGMII is not set
590# CONFIG_IBM_NEW_EMAC_TAH is not set
591# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
592# CONFIG_IBM_NEW_EMAC_NO_FLOW_CTRL is not set
593# CONFIG_IBM_NEW_EMAC_MAL_CLR_ICINTSTAT is not set
594# CONFIG_IBM_NEW_EMAC_MAL_COMMON_ERR is not set
595# CONFIG_B44 is not set
596# CONFIG_NETDEV_1000 is not set
597# CONFIG_NETDEV_10000 is not set
598
599#
600# Wireless LAN
601#
602# CONFIG_WLAN_PRE80211 is not set
603# CONFIG_WLAN_80211 is not set
604# CONFIG_IWLWIFI_LEDS is not set
605
606#
607# Enable WiMAX (Networking options) to see the WiMAX drivers
608#
609
610#
611# USB Network Adapters
612#
613# CONFIG_USB_CATC is not set
614# CONFIG_USB_KAWETH is not set
615# CONFIG_USB_PEGASUS is not set
616# CONFIG_USB_RTL8150 is not set
617# CONFIG_USB_USBNET is not set
618# CONFIG_WAN is not set
619# CONFIG_PPP is not set
620# CONFIG_SLIP is not set
621# CONFIG_NETCONSOLE is not set
622# CONFIG_NETPOLL is not set
623# CONFIG_NET_POLL_CONTROLLER is not set
624# CONFIG_ISDN is not set
625# CONFIG_PHONE is not set
626
627#
628# Input device support
629#
630CONFIG_INPUT=y
631# CONFIG_INPUT_FF_MEMLESS is not set
632# CONFIG_INPUT_POLLDEV is not set
633
634#
635# Userland interfaces
636#
637# CONFIG_INPUT_MOUSEDEV is not set
638# CONFIG_INPUT_JOYDEV is not set
639# CONFIG_INPUT_EVDEV is not set
640# CONFIG_INPUT_EVBUG is not set
641
642#
643# Input Device Drivers
644#
645# CONFIG_INPUT_KEYBOARD is not set
646# CONFIG_INPUT_MOUSE is not set
647# CONFIG_INPUT_JOYSTICK is not set
648# CONFIG_INPUT_TABLET is not set
649# CONFIG_INPUT_TOUCHSCREEN is not set
650# CONFIG_INPUT_MISC is not set
651
652#
653# Hardware I/O ports
654#
655# CONFIG_SERIO is not set
656# CONFIG_GAMEPORT is not set
657
658#
659# Character devices
660#
661CONFIG_VT=y
662CONFIG_CONSOLE_TRANSLATIONS=y
663CONFIG_VT_CONSOLE=y
664CONFIG_HW_CONSOLE=y
665# CONFIG_VT_HW_CONSOLE_BINDING is not set
666CONFIG_DEVKMEM=y
667# CONFIG_SERIAL_NONSTANDARD is not set
668
669#
670# Serial drivers
671#
672# CONFIG_SERIAL_8250 is not set
673
674#
675# Non-8250 serial port support
676#
677CONFIG_SERIAL_SH_SCI=y
678CONFIG_SERIAL_SH_SCI_NR_UARTS=3
679CONFIG_SERIAL_SH_SCI_CONSOLE=y
680CONFIG_SERIAL_CORE=y
681CONFIG_SERIAL_CORE_CONSOLE=y
682CONFIG_UNIX98_PTYS=y
683# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
684CONFIG_LEGACY_PTYS=y
685CONFIG_LEGACY_PTY_COUNT=256
686# CONFIG_IPMI_HANDLER is not set
687CONFIG_HW_RANDOM=y
688# CONFIG_R3964 is not set
689# CONFIG_RAW_DRIVER is not set
690# CONFIG_TCG_TPM is not set
691# CONFIG_I2C is not set
692# CONFIG_SPI is not set
693# CONFIG_W1 is not set
694# CONFIG_POWER_SUPPLY is not set
695# CONFIG_HWMON is not set
696# CONFIG_THERMAL is not set
697# CONFIG_THERMAL_HWMON is not set
698# CONFIG_WATCHDOG is not set
699CONFIG_SSB_POSSIBLE=y
700
701#
702# Sonics Silicon Backplane
703#
704# CONFIG_SSB is not set
705
706#
707# Multifunction device drivers
708#
709# CONFIG_MFD_CORE is not set
710# CONFIG_MFD_SM501 is not set
711# CONFIG_HTC_PASIC3 is not set
712# CONFIG_MFD_TMIO is not set
713# CONFIG_REGULATOR is not set
714
715#
716# Multimedia devices
717#
718
719#
720# Multimedia core support
721#
722# CONFIG_VIDEO_DEV is not set
723# CONFIG_DVB_CORE is not set
724# CONFIG_VIDEO_MEDIA is not set
725
726#
727# Multimedia drivers
728#
729# CONFIG_DAB is not set
730
731#
732# Graphics support
733#
734# CONFIG_VGASTATE is not set
735# CONFIG_VIDEO_OUTPUT_CONTROL is not set
736CONFIG_FB=y
737# CONFIG_FIRMWARE_EDID is not set
738# CONFIG_FB_DDC is not set
739# CONFIG_FB_BOOT_VESA_SUPPORT is not set
740CONFIG_FB_CFB_FILLRECT=y
741CONFIG_FB_CFB_COPYAREA=y
742CONFIG_FB_CFB_IMAGEBLIT=y
743# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
744# CONFIG_FB_SYS_FILLRECT is not set
745# CONFIG_FB_SYS_COPYAREA is not set
746# CONFIG_FB_SYS_IMAGEBLIT is not set
747CONFIG_FB_FOREIGN_ENDIAN=y
748CONFIG_FB_BOTH_ENDIAN=y
749# CONFIG_FB_BIG_ENDIAN is not set
750# CONFIG_FB_LITTLE_ENDIAN is not set
751# CONFIG_FB_SYS_FOPS is not set
752# CONFIG_FB_SVGALIB is not set
753# CONFIG_FB_MACMODES is not set
754# CONFIG_FB_BACKLIGHT is not set
755# CONFIG_FB_MODE_HELPERS is not set
756# CONFIG_FB_TILEBLITTING is not set
757
758#
759# Frame buffer hardware drivers
760#
761# CONFIG_FB_S1D13XXX is not set
762# CONFIG_FB_SH_MOBILE_LCDC is not set
763CONFIG_FB_SH7760=y
764# CONFIG_FB_VIRTUAL is not set
765# CONFIG_FB_METRONOME is not set
766# CONFIG_FB_MB862XX is not set
767# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
768
769#
770# Display device support
771#
772# CONFIG_DISPLAY_SUPPORT is not set
773
774#
775# Console display driver support
776#
777CONFIG_DUMMY_CONSOLE=y
778CONFIG_FRAMEBUFFER_CONSOLE=y
779# CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY is not set
780# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
781# CONFIG_FONTS is not set
782CONFIG_FONT_8x8=y
783CONFIG_FONT_8x16=y
784CONFIG_LOGO=y
785CONFIG_LOGO_LINUX_MONO=y
786CONFIG_LOGO_LINUX_VGA16=y
787CONFIG_LOGO_LINUX_CLUT224=y
788CONFIG_LOGO_SUPERH_MONO=y
789CONFIG_LOGO_SUPERH_VGA16=y
790CONFIG_LOGO_SUPERH_CLUT224=y
791# CONFIG_SOUND is not set
792# CONFIG_HID_SUPPORT is not set
793CONFIG_USB_SUPPORT=y
794CONFIG_USB_ARCH_HAS_HCD=y
795CONFIG_USB_ARCH_HAS_OHCI=y
796# CONFIG_USB_ARCH_HAS_EHCI is not set
797CONFIG_USB=y
798# CONFIG_USB_DEBUG is not set
799# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
800
801#
802# Miscellaneous USB options
803#
804# CONFIG_USB_DEVICEFS is not set
805CONFIG_USB_DEVICE_CLASS=y
806# CONFIG_USB_DYNAMIC_MINORS is not set
807# CONFIG_USB_OTG is not set
808# CONFIG_USB_OTG_WHITELIST is not set
809# CONFIG_USB_OTG_BLACKLIST_HUB is not set
810CONFIG_USB_MON=y
811# CONFIG_USB_WUSB is not set
812# CONFIG_USB_WUSB_CBAF is not set
813
814#
815# USB Host Controller Drivers
816#
817# CONFIG_USB_C67X00_HCD is not set
818# CONFIG_USB_OXU210HP_HCD is not set
819# CONFIG_USB_ISP116X_HCD is not set
820CONFIG_USB_OHCI_HCD=y
821# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
822# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
823CONFIG_USB_OHCI_LITTLE_ENDIAN=y
824# CONFIG_USB_SL811_HCD is not set
825# CONFIG_USB_R8A66597_HCD is not set
826# CONFIG_USB_HWA_HCD is not set
827
828#
829# USB Device Class drivers
830#
831# CONFIG_USB_ACM is not set
832# CONFIG_USB_PRINTER is not set
833# CONFIG_USB_WDM is not set
834# CONFIG_USB_TMC is not set
835
836#
837# NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may also be needed;
838#
839
840#
841# see USB_STORAGE Help for more information
842#
843CONFIG_USB_STORAGE=y
844# CONFIG_USB_STORAGE_DEBUG is not set
845# CONFIG_USB_STORAGE_DATAFAB is not set
846# CONFIG_USB_STORAGE_FREECOM is not set
847# CONFIG_USB_STORAGE_ISD200 is not set
848# CONFIG_USB_STORAGE_USBAT is not set
849# CONFIG_USB_STORAGE_SDDR09 is not set
850# CONFIG_USB_STORAGE_SDDR55 is not set
851# CONFIG_USB_STORAGE_JUMPSHOT is not set
852# CONFIG_USB_STORAGE_ALAUDA is not set
853# CONFIG_USB_STORAGE_ONETOUCH is not set
854# CONFIG_USB_STORAGE_KARMA is not set
855# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
856# CONFIG_USB_LIBUSUAL is not set
857
858#
859# USB Imaging devices
860#
861# CONFIG_USB_MDC800 is not set
862# CONFIG_USB_MICROTEK is not set
863
864#
865# USB port drivers
866#
867# CONFIG_USB_SERIAL is not set
868
869#
870# USB Miscellaneous drivers
871#
872# CONFIG_USB_EMI62 is not set
873# CONFIG_USB_EMI26 is not set
874# CONFIG_USB_ADUTUX is not set
875# CONFIG_USB_SEVSEG is not set
876# CONFIG_USB_RIO500 is not set
877# CONFIG_USB_LEGOTOWER is not set
878# CONFIG_USB_LCD is not set
879# CONFIG_USB_BERRY_CHARGE is not set
880# CONFIG_USB_LED is not set
881# CONFIG_USB_CYPRESS_CY7C63 is not set
882# CONFIG_USB_CYTHERM is not set
883# CONFIG_USB_PHIDGET is not set
884# CONFIG_USB_IDMOUSE is not set
885# CONFIG_USB_FTDI_ELAN is not set
886# CONFIG_USB_APPLEDISPLAY is not set
887# CONFIG_USB_LD is not set
888# CONFIG_USB_TRANCEVIBRATOR is not set
889# CONFIG_USB_IOWARRIOR is not set
890# CONFIG_USB_ISIGHTFW is not set
891# CONFIG_USB_VST is not set
892# CONFIG_USB_GADGET is not set
893
894#
895# OTG and related infrastructure
896#
897# CONFIG_MMC is not set
898# CONFIG_MEMSTICK is not set
899# CONFIG_NEW_LEDS is not set
900# CONFIG_ACCESSIBILITY is not set
901# CONFIG_RTC_CLASS is not set
902# CONFIG_DMADEVICES is not set
903# CONFIG_UIO is not set
904# CONFIG_STAGING is not set
905
906#
907# File systems
908#
909CONFIG_EXT2_FS=y
910# CONFIG_EXT2_FS_XATTR is not set
911# CONFIG_EXT2_FS_XIP is not set
912CONFIG_EXT3_FS=y
913CONFIG_EXT3_FS_XATTR=y
914# CONFIG_EXT3_FS_POSIX_ACL is not set
915# CONFIG_EXT3_FS_SECURITY is not set
916# CONFIG_EXT4_FS is not set
917CONFIG_JBD=y
918# CONFIG_JBD_DEBUG is not set
919CONFIG_FS_MBCACHE=y
920# CONFIG_REISERFS_FS is not set
921# CONFIG_JFS_FS is not set
922CONFIG_FS_POSIX_ACL=y
923CONFIG_FILE_LOCKING=y
924# CONFIG_XFS_FS is not set
925# CONFIG_OCFS2_FS is not set
926# CONFIG_BTRFS_FS is not set
927CONFIG_DNOTIFY=y
928CONFIG_INOTIFY=y
929CONFIG_INOTIFY_USER=y
930# CONFIG_QUOTA is not set
931CONFIG_AUTOFS_FS=y
932CONFIG_AUTOFS4_FS=y
933# CONFIG_FUSE_FS is not set
934CONFIG_GENERIC_ACL=y
935
936#
937# CD-ROM/DVD Filesystems
938#
939# CONFIG_ISO9660_FS is not set
940# CONFIG_UDF_FS is not set
941
942#
943# DOS/FAT/NT Filesystems
944#
945# CONFIG_MSDOS_FS is not set
946# CONFIG_VFAT_FS is not set
947# CONFIG_NTFS_FS is not set
948
949#
950# Pseudo filesystems
951#
952CONFIG_PROC_FS=y
953CONFIG_PROC_KCORE=y
954CONFIG_PROC_SYSCTL=y
955CONFIG_PROC_PAGE_MONITOR=y
956CONFIG_SYSFS=y
957CONFIG_TMPFS=y
958CONFIG_TMPFS_POSIX_ACL=y
959# CONFIG_HUGETLBFS is not set
960# CONFIG_HUGETLB_PAGE is not set
961# CONFIG_CONFIGFS_FS is not set
962CONFIG_MISC_FILESYSTEMS=y
963# CONFIG_ADFS_FS is not set
964# CONFIG_AFFS_FS is not set
965# CONFIG_HFS_FS is not set
966# CONFIG_HFSPLUS_FS is not set
967# CONFIG_BEFS_FS is not set
968# CONFIG_BFS_FS is not set
969# CONFIG_EFS_FS is not set
970# CONFIG_JFFS2_FS is not set
971CONFIG_CRAMFS=y
972# CONFIG_SQUASHFS is not set
973# CONFIG_VXFS_FS is not set
974# CONFIG_MINIX_FS is not set
975# CONFIG_OMFS_FS is not set
976# CONFIG_HPFS_FS is not set
977# CONFIG_QNX4FS_FS is not set
978CONFIG_ROMFS_FS=y
979# CONFIG_SYSV_FS is not set
980# CONFIG_UFS_FS is not set
981CONFIG_NETWORK_FILESYSTEMS=y
982CONFIG_NFS_FS=y
983# CONFIG_NFS_V3 is not set
984# CONFIG_NFS_V4 is not set
985CONFIG_ROOT_NFS=y
986# CONFIG_NFSD is not set
987CONFIG_LOCKD=y
988CONFIG_NFS_COMMON=y
989CONFIG_SUNRPC=y
990# CONFIG_SUNRPC_REGISTER_V4 is not set
991# CONFIG_RPCSEC_GSS_KRB5 is not set
992# CONFIG_RPCSEC_GSS_SPKM3 is not set
993# CONFIG_SMB_FS is not set
994# CONFIG_CIFS is not set
995# CONFIG_NCP_FS is not set
996# CONFIG_CODA_FS is not set
997# CONFIG_AFS_FS is not set
998
999#
1000# Partition Types
1001#
1002# CONFIG_PARTITION_ADVANCED is not set
1003CONFIG_MSDOS_PARTITION=y
1004CONFIG_NLS=y
1005CONFIG_NLS_DEFAULT="iso8859-1"
1006CONFIG_NLS_CODEPAGE_437=y
1007CONFIG_NLS_CODEPAGE_737=y
1008CONFIG_NLS_CODEPAGE_775=y
1009CONFIG_NLS_CODEPAGE_850=y
1010CONFIG_NLS_CODEPAGE_852=y
1011CONFIG_NLS_CODEPAGE_855=y
1012CONFIG_NLS_CODEPAGE_857=y
1013CONFIG_NLS_CODEPAGE_860=y
1014CONFIG_NLS_CODEPAGE_861=y
1015CONFIG_NLS_CODEPAGE_862=y
1016CONFIG_NLS_CODEPAGE_863=y
1017CONFIG_NLS_CODEPAGE_864=y
1018CONFIG_NLS_CODEPAGE_865=y
1019CONFIG_NLS_CODEPAGE_866=y
1020CONFIG_NLS_CODEPAGE_869=y
1021CONFIG_NLS_CODEPAGE_936=y
1022CONFIG_NLS_CODEPAGE_950=y
1023CONFIG_NLS_CODEPAGE_932=y
1024CONFIG_NLS_CODEPAGE_949=y
1025CONFIG_NLS_CODEPAGE_874=y
1026CONFIG_NLS_ISO8859_8=y
1027CONFIG_NLS_CODEPAGE_1250=y
1028CONFIG_NLS_CODEPAGE_1251=y
1029CONFIG_NLS_ASCII=y
1030CONFIG_NLS_ISO8859_1=y
1031CONFIG_NLS_ISO8859_2=y
1032CONFIG_NLS_ISO8859_3=y
1033CONFIG_NLS_ISO8859_4=y
1034CONFIG_NLS_ISO8859_5=y
1035CONFIG_NLS_ISO8859_6=y
1036CONFIG_NLS_ISO8859_7=y
1037CONFIG_NLS_ISO8859_9=y
1038CONFIG_NLS_ISO8859_13=y
1039CONFIG_NLS_ISO8859_14=y
1040CONFIG_NLS_ISO8859_15=y
1041CONFIG_NLS_KOI8_R=y
1042CONFIG_NLS_KOI8_U=y
1043CONFIG_NLS_UTF8=y
1044# CONFIG_DLM is not set
1045
1046#
1047# Kernel hacking
1048#
1049CONFIG_TRACE_IRQFLAGS_SUPPORT=y
1050# CONFIG_PRINTK_TIME is not set
1051# CONFIG_ENABLE_WARN_DEPRECATED is not set
1052# CONFIG_ENABLE_MUST_CHECK is not set
1053CONFIG_FRAME_WARN=1024
1054# CONFIG_MAGIC_SYSRQ is not set
1055# CONFIG_UNUSED_SYMBOLS is not set
1056CONFIG_DEBUG_FS=y
1057# CONFIG_HEADERS_CHECK is not set
1058# CONFIG_DEBUG_KERNEL is not set
1059CONFIG_STACKTRACE=y
1060# CONFIG_DEBUG_BUGVERBOSE is not set
1061# CONFIG_DEBUG_MEMORY_INIT is not set
1062# CONFIG_RCU_CPU_STALL_DETECTOR is not set
1063# CONFIG_LATENCYTOP is not set
1064CONFIG_NOP_TRACER=y
1065CONFIG_HAVE_FUNCTION_TRACER=y
1066CONFIG_HAVE_DYNAMIC_FTRACE=y
1067CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1068CONFIG_RING_BUFFER=y
1069CONFIG_TRACING=y
1070
1071#
1072# Tracers
1073#
1074# CONFIG_DYNAMIC_PRINTK_DEBUG is not set
1075# CONFIG_SAMPLES is not set
1076CONFIG_HAVE_ARCH_KGDB=y
1077# CONFIG_SH_STANDARD_BIOS is not set
1078# CONFIG_EARLY_SCIF_CONSOLE is not set
1079# CONFIG_MORE_COMPILE_OPTIONS is not set
1080
1081#
1082# Security options
1083#
1084# CONFIG_KEYS is not set
1085# CONFIG_SECURITY is not set
1086# CONFIG_SECURITYFS is not set
1087# CONFIG_SECURITY_FILE_CAPABILITIES is not set
1088CONFIG_CRYPTO=y
1089
1090#
1091# Crypto core or helper
1092#
1093# CONFIG_CRYPTO_FIPS is not set
1094# CONFIG_CRYPTO_MANAGER is not set
1095# CONFIG_CRYPTO_MANAGER2 is not set
1096# CONFIG_CRYPTO_GF128MUL is not set
1097# CONFIG_CRYPTO_NULL is not set
1098# CONFIG_CRYPTO_CRYPTD is not set
1099# CONFIG_CRYPTO_AUTHENC is not set
1100# CONFIG_CRYPTO_TEST is not set
1101
1102#
1103# Authenticated Encryption with Associated Data
1104#
1105# CONFIG_CRYPTO_CCM is not set
1106# CONFIG_CRYPTO_GCM is not set
1107# CONFIG_CRYPTO_SEQIV is not set
1108
1109#
1110# Block modes
1111#
1112# CONFIG_CRYPTO_CBC is not set
1113# CONFIG_CRYPTO_CTR is not set
1114# CONFIG_CRYPTO_CTS is not set
1115# CONFIG_CRYPTO_ECB is not set
1116# CONFIG_CRYPTO_LRW is not set
1117# CONFIG_CRYPTO_PCBC is not set
1118# CONFIG_CRYPTO_XTS is not set
1119
1120#
1121# Hash modes
1122#
1123# CONFIG_CRYPTO_HMAC is not set
1124# CONFIG_CRYPTO_XCBC is not set
1125
1126#
1127# Digest
1128#
1129# CONFIG_CRYPTO_CRC32C is not set
1130# CONFIG_CRYPTO_MD4 is not set
1131# CONFIG_CRYPTO_MD5 is not set
1132# CONFIG_CRYPTO_MICHAEL_MIC is not set
1133# CONFIG_CRYPTO_RMD128 is not set
1134# CONFIG_CRYPTO_RMD160 is not set
1135# CONFIG_CRYPTO_RMD256 is not set
1136# CONFIG_CRYPTO_RMD320 is not set
1137# CONFIG_CRYPTO_SHA1 is not set
1138# CONFIG_CRYPTO_SHA256 is not set
1139# CONFIG_CRYPTO_SHA512 is not set
1140# CONFIG_CRYPTO_TGR192 is not set
1141# CONFIG_CRYPTO_WP512 is not set
1142
1143#
1144# Ciphers
1145#
1146# CONFIG_CRYPTO_AES is not set
1147# CONFIG_CRYPTO_ANUBIS is not set
1148# CONFIG_CRYPTO_ARC4 is not set
1149# CONFIG_CRYPTO_BLOWFISH is not set
1150# CONFIG_CRYPTO_CAMELLIA is not set
1151# CONFIG_CRYPTO_CAST5 is not set
1152# CONFIG_CRYPTO_CAST6 is not set
1153# CONFIG_CRYPTO_DES is not set
1154# CONFIG_CRYPTO_FCRYPT is not set
1155# CONFIG_CRYPTO_KHAZAD is not set
1156# CONFIG_CRYPTO_SALSA20 is not set
1157# CONFIG_CRYPTO_SEED is not set
1158# CONFIG_CRYPTO_SERPENT is not set
1159# CONFIG_CRYPTO_TEA is not set
1160# CONFIG_CRYPTO_TWOFISH is not set
1161
1162#
1163# Compression
1164#
1165# CONFIG_CRYPTO_DEFLATE is not set
1166# CONFIG_CRYPTO_LZO is not set
1167
1168#
1169# Random Number Generation
1170#
1171# CONFIG_CRYPTO_ANSI_CPRNG is not set
1172CONFIG_CRYPTO_HW=y
1173
1174#
1175# Library routines
1176#
1177CONFIG_BITREVERSE=y
1178CONFIG_GENERIC_FIND_LAST_BIT=y
1179# CONFIG_CRC_CCITT is not set
1180# CONFIG_CRC16 is not set
1181CONFIG_CRC_T10DIF=y
1182# CONFIG_CRC_ITU_T is not set
1183CONFIG_CRC32=y
1184# CONFIG_CRC7 is not set
1185# CONFIG_LIBCRC32C is not set
1186CONFIG_ZLIB_INFLATE=y
1187CONFIG_PLIST=y
1188CONFIG_HAS_IOMEM=y
1189CONFIG_HAS_IOPORT=y
1190CONFIG_HAS_DMA=y
diff --git a/arch/sh/configs/polaris_defconfig b/arch/sh/configs/polaris_defconfig
new file mode 100644
index 000000000000..320def233b2f
--- /dev/null
+++ b/arch/sh/configs/polaris_defconfig
@@ -0,0 +1,969 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29-rc4
4# Wed Feb 11 18:41:59 2009
5#
6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y
11CONFIG_GENERIC_FIND_NEXT_BIT=y
12CONFIG_GENERIC_HWEIGHT=y
13CONFIG_GENERIC_HARDIRQS=y
14CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
15CONFIG_GENERIC_IRQ_PROBE=y
16# CONFIG_GENERIC_GPIO is not set
17CONFIG_GENERIC_TIME=y
18CONFIG_GENERIC_CLOCKEVENTS=y
19# CONFIG_ARCH_SUSPEND_POSSIBLE is not set
20# CONFIG_ARCH_HIBERNATION_POSSIBLE is not set
21CONFIG_STACKTRACE_SUPPORT=y
22CONFIG_LOCKDEP_SUPPORT=y
23CONFIG_HAVE_LATENCYTOP_SUPPORT=y
24# CONFIG_ARCH_HAS_ILOG2_U32 is not set
25# CONFIG_ARCH_HAS_ILOG2_U64 is not set
26CONFIG_ARCH_NO_VIRT_TO_BUS=y
27CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
28
29#
30# General setup
31#
32CONFIG_EXPERIMENTAL=y
33CONFIG_BROKEN_ON_SMP=y
34CONFIG_LOCK_KERNEL=y
35CONFIG_INIT_ENV_ARG_LIMIT=32
36CONFIG_LOCALVERSION=""
37# CONFIG_LOCALVERSION_AUTO is not set
38# CONFIG_SWAP is not set
39CONFIG_SYSVIPC=y
40CONFIG_SYSVIPC_SYSCTL=y
41CONFIG_POSIX_MQUEUE=y
42CONFIG_BSD_PROCESS_ACCT=y
43CONFIG_BSD_PROCESS_ACCT_V3=y
44# CONFIG_TASKSTATS is not set
45CONFIG_AUDIT=y
46# CONFIG_AUDITSYSCALL is not set
47
48#
49# RCU Subsystem
50#
51CONFIG_CLASSIC_RCU=y
52# CONFIG_TREE_RCU is not set
53# CONFIG_PREEMPT_RCU is not set
54# CONFIG_TREE_RCU_TRACE is not set
55# CONFIG_PREEMPT_RCU_TRACE is not set
56# CONFIG_IKCONFIG is not set
57CONFIG_LOG_BUF_SHIFT=14
58CONFIG_GROUP_SCHED=y
59CONFIG_FAIR_GROUP_SCHED=y
60# CONFIG_RT_GROUP_SCHED is not set
61CONFIG_USER_SCHED=y
62# CONFIG_CGROUP_SCHED is not set
63# CONFIG_CGROUPS is not set
64CONFIG_SYSFS_DEPRECATED=y
65CONFIG_SYSFS_DEPRECATED_V2=y
66# CONFIG_RELAY is not set
67# CONFIG_NAMESPACES is not set
68# CONFIG_BLK_DEV_INITRD is not set
69# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
70CONFIG_SYSCTL=y
71CONFIG_EMBEDDED=y
72CONFIG_UID16=y
73CONFIG_SYSCTL_SYSCALL=y
74CONFIG_KALLSYMS=y
75CONFIG_KALLSYMS_ALL=y
76# CONFIG_KALLSYMS_EXTRA_PASS is not set
77CONFIG_HOTPLUG=y
78CONFIG_PRINTK=y
79CONFIG_BUG=y
80CONFIG_ELF_CORE=y
81CONFIG_COMPAT_BRK=y
82CONFIG_BASE_FULL=y
83CONFIG_FUTEX=y
84CONFIG_ANON_INODES=y
85CONFIG_EPOLL=y
86CONFIG_SIGNALFD=y
87CONFIG_TIMERFD=y
88CONFIG_EVENTFD=y
89CONFIG_SHMEM=y
90CONFIG_AIO=y
91CONFIG_VM_EVENT_COUNTERS=y
92CONFIG_SLAB=y
93# CONFIG_SLUB is not set
94# CONFIG_SLOB is not set
95# CONFIG_PROFILING is not set
96CONFIG_HAVE_OPROFILE=y
97# CONFIG_KPROBES is not set
98CONFIG_HAVE_IOREMAP_PROT=y
99CONFIG_HAVE_KPROBES=y
100CONFIG_HAVE_KRETPROBES=y
101CONFIG_HAVE_ARCH_TRACEHOOK=y
102CONFIG_HAVE_CLK=y
103CONFIG_HAVE_GENERIC_DMA_COHERENT=y
104CONFIG_SLABINFO=y
105CONFIG_RT_MUTEXES=y
106CONFIG_BASE_SMALL=0
107CONFIG_MODULES=y
108# CONFIG_MODULE_FORCE_LOAD is not set
109CONFIG_MODULE_UNLOAD=y
110# CONFIG_MODULE_FORCE_UNLOAD is not set
111CONFIG_MODVERSIONS=y
112# CONFIG_MODULE_SRCVERSION_ALL is not set
113CONFIG_BLOCK=y
114# CONFIG_LBD is not set
115# CONFIG_BLK_DEV_IO_TRACE is not set
116# CONFIG_BLK_DEV_BSG is not set
117# CONFIG_BLK_DEV_INTEGRITY is not set
118
119#
120# IO Schedulers
121#
122CONFIG_IOSCHED_NOOP=y
123# CONFIG_IOSCHED_AS is not set
124# CONFIG_IOSCHED_DEADLINE is not set
125CONFIG_IOSCHED_CFQ=y
126# CONFIG_DEFAULT_AS is not set
127# CONFIG_DEFAULT_DEADLINE is not set
128CONFIG_DEFAULT_CFQ=y
129# CONFIG_DEFAULT_NOOP is not set
130CONFIG_DEFAULT_IOSCHED="cfq"
131# CONFIG_FREEZER is not set
132
133#
134# System type
135#
136CONFIG_CPU_SH3=y
137# CONFIG_CPU_SUBTYPE_SH7619 is not set
138# CONFIG_CPU_SUBTYPE_SH7201 is not set
139# CONFIG_CPU_SUBTYPE_SH7203 is not set
140# CONFIG_CPU_SUBTYPE_SH7206 is not set
141# CONFIG_CPU_SUBTYPE_SH7263 is not set
142# CONFIG_CPU_SUBTYPE_MXG is not set
143# CONFIG_CPU_SUBTYPE_SH7705 is not set
144# CONFIG_CPU_SUBTYPE_SH7706 is not set
145# CONFIG_CPU_SUBTYPE_SH7707 is not set
146# CONFIG_CPU_SUBTYPE_SH7708 is not set
147CONFIG_CPU_SUBTYPE_SH7709=y
148# CONFIG_CPU_SUBTYPE_SH7710 is not set
149# CONFIG_CPU_SUBTYPE_SH7712 is not set
150# CONFIG_CPU_SUBTYPE_SH7720 is not set
151# CONFIG_CPU_SUBTYPE_SH7721 is not set
152# CONFIG_CPU_SUBTYPE_SH7750 is not set
153# CONFIG_CPU_SUBTYPE_SH7091 is not set
154# CONFIG_CPU_SUBTYPE_SH7750R is not set
155# CONFIG_CPU_SUBTYPE_SH7750S is not set
156# CONFIG_CPU_SUBTYPE_SH7751 is not set
157# CONFIG_CPU_SUBTYPE_SH7751R is not set
158# CONFIG_CPU_SUBTYPE_SH7760 is not set
159# CONFIG_CPU_SUBTYPE_SH4_202 is not set
160# CONFIG_CPU_SUBTYPE_SH7723 is not set
161# CONFIG_CPU_SUBTYPE_SH7763 is not set
162# CONFIG_CPU_SUBTYPE_SH7770 is not set
163# CONFIG_CPU_SUBTYPE_SH7780 is not set
164# CONFIG_CPU_SUBTYPE_SH7785 is not set
165# CONFIG_CPU_SUBTYPE_SHX3 is not set
166# CONFIG_CPU_SUBTYPE_SH7343 is not set
167# CONFIG_CPU_SUBTYPE_SH7722 is not set
168# CONFIG_CPU_SUBTYPE_SH7366 is not set
169# CONFIG_CPU_SUBTYPE_SH5_101 is not set
170# CONFIG_CPU_SUBTYPE_SH5_103 is not set
171
172#
173# Memory management options
174#
175CONFIG_QUICKLIST=y
176CONFIG_MMU=y
177CONFIG_PAGE_OFFSET=0x80000000
178CONFIG_MEMORY_START=0x0C000000
179CONFIG_MEMORY_SIZE=0x04000000
180CONFIG_29BIT=y
181CONFIG_VSYSCALL=y
182CONFIG_ARCH_FLATMEM_ENABLE=y
183CONFIG_ARCH_SPARSEMEM_ENABLE=y
184CONFIG_ARCH_SPARSEMEM_DEFAULT=y
185CONFIG_MAX_ACTIVE_REGIONS=1
186CONFIG_ARCH_POPULATES_NODE_MAP=y
187CONFIG_ARCH_SELECT_MEMORY_MODEL=y
188CONFIG_PAGE_SIZE_4KB=y
189# CONFIG_PAGE_SIZE_8KB is not set
190# CONFIG_PAGE_SIZE_16KB is not set
191# CONFIG_PAGE_SIZE_64KB is not set
192CONFIG_ENTRY_OFFSET=0x00001000
193CONFIG_SELECT_MEMORY_MODEL=y
194CONFIG_FLATMEM_MANUAL=y
195# CONFIG_DISCONTIGMEM_MANUAL is not set
196# CONFIG_SPARSEMEM_MANUAL is not set
197CONFIG_FLATMEM=y
198CONFIG_FLAT_NODE_MEM_MAP=y
199CONFIG_SPARSEMEM_STATIC=y
200CONFIG_PAGEFLAGS_EXTENDED=y
201CONFIG_SPLIT_PTLOCK_CPUS=4
202# CONFIG_PHYS_ADDR_T_64BIT is not set
203CONFIG_ZONE_DMA_FLAG=0
204CONFIG_NR_QUICK=2
205CONFIG_UNEVICTABLE_LRU=y
206
207#
208# Cache configuration
209#
210# CONFIG_SH_DIRECT_MAPPED is not set
211CONFIG_CACHE_WRITEBACK=y
212# CONFIG_CACHE_WRITETHROUGH is not set
213# CONFIG_CACHE_OFF is not set
214
215#
216# Processor features
217#
218CONFIG_CPU_LITTLE_ENDIAN=y
219# CONFIG_CPU_BIG_ENDIAN is not set
220CONFIG_SH_FPU_EMU=y
221CONFIG_SH_ADC=y
222CONFIG_CPU_HAS_INTEVT=y
223CONFIG_CPU_HAS_IPR_IRQ=y
224CONFIG_CPU_HAS_SR_RB=y
225
226#
227# Board support
228#
229# CONFIG_SH_SOLUTION_ENGINE is not set
230# CONFIG_SH_HP6XX is not set
231CONFIG_SH_POLARIS=y
232
233#
234# Timer and clock configuration
235#
236CONFIG_SH_TMU=y
237CONFIG_SH_TIMER_IRQ=16
238CONFIG_SH_PCLK_FREQ=33000000
239CONFIG_TICK_ONESHOT=y
240CONFIG_NO_HZ=y
241CONFIG_HIGH_RES_TIMERS=y
242CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
243
244#
245# CPU Frequency scaling
246#
247# CONFIG_CPU_FREQ is not set
248
249#
250# DMA support
251#
252CONFIG_SH_DMA_API=y
253CONFIG_SH_DMA=y
254CONFIG_NR_ONCHIP_DMA_CHANNELS=4
255# CONFIG_NR_DMA_CHANNELS_BOOL is not set
256
257#
258# Companion Chips
259#
260
261#
262# Additional SuperH Device Drivers
263#
264CONFIG_HEARTBEAT=y
265# CONFIG_PUSH_SWITCH is not set
266
267#
268# Kernel features
269#
270CONFIG_HZ_100=y
271# CONFIG_HZ_250 is not set
272# CONFIG_HZ_300 is not set
273# CONFIG_HZ_1000 is not set
274CONFIG_HZ=100
275CONFIG_SCHED_HRTICK=y
276# CONFIG_KEXEC is not set
277# CONFIG_CRASH_DUMP is not set
278# CONFIG_SECCOMP is not set
279# CONFIG_PREEMPT_NONE is not set
280# CONFIG_PREEMPT_VOLUNTARY is not set
281CONFIG_PREEMPT=y
282CONFIG_GUSA=y
283# CONFIG_GUSA_RB is not set
284
285#
286# Boot options
287#
288CONFIG_ZERO_PAGE_OFFSET=0x00001000
289CONFIG_BOOT_LINK_OFFSET=0x00800000
290CONFIG_CMDLINE_BOOL=y
291CONFIG_CMDLINE="console=ttySC1,115200 root=/dev/mtdblock2 rootfstype=jffs2 mem=63M mtdparts=physmap-flash.0:0x00100000(bootloader)ro,0x00500000(Kernel)ro,0x00A00000(Filesystem)"
292
293#
294# Bus options
295#
296# CONFIG_ARCH_SUPPORTS_MSI is not set
297# CONFIG_PCCARD is not set
298
299#
300# Executable file formats
301#
302CONFIG_BINFMT_ELF=y
303# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
304# CONFIG_HAVE_AOUT is not set
305# CONFIG_BINFMT_MISC is not set
306
307#
308# Power management options (EXPERIMENTAL)
309#
310# CONFIG_PM is not set
311# CONFIG_CPU_IDLE is not set
312CONFIG_NET=y
313
314#
315# Networking options
316#
317CONFIG_COMPAT_NET_DEV_OPS=y
318CONFIG_PACKET=y
319CONFIG_PACKET_MMAP=y
320CONFIG_UNIX=y
321# CONFIG_NET_KEY is not set
322CONFIG_INET=y
323CONFIG_IP_MULTICAST=y
324# CONFIG_IP_ADVANCED_ROUTER is not set
325CONFIG_IP_FIB_HASH=y
326# CONFIG_IP_PNP is not set
327# CONFIG_NET_IPIP is not set
328# CONFIG_NET_IPGRE is not set
329# CONFIG_IP_MROUTE is not set
330# CONFIG_ARPD is not set
331# CONFIG_SYN_COOKIES is not set
332# CONFIG_INET_AH is not set
333# CONFIG_INET_ESP is not set
334# CONFIG_INET_IPCOMP is not set
335# CONFIG_INET_XFRM_TUNNEL is not set
336# CONFIG_INET_TUNNEL is not set
337# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
338# CONFIG_INET_XFRM_MODE_TUNNEL is not set
339# CONFIG_INET_XFRM_MODE_BEET is not set
340# CONFIG_INET_LRO is not set
341CONFIG_INET_DIAG=y
342CONFIG_INET_TCP_DIAG=y
343# CONFIG_TCP_CONG_ADVANCED is not set
344CONFIG_TCP_CONG_CUBIC=y
345CONFIG_DEFAULT_TCP_CONG="cubic"
346# CONFIG_TCP_MD5SIG is not set
347# CONFIG_IPV6 is not set
348# CONFIG_NETWORK_SECMARK is not set
349# CONFIG_NETFILTER is not set
350# CONFIG_IP_DCCP is not set
351# CONFIG_IP_SCTP is not set
352# CONFIG_TIPC is not set
353# CONFIG_ATM is not set
354# CONFIG_BRIDGE is not set
355# CONFIG_NET_DSA is not set
356# CONFIG_VLAN_8021Q is not set
357# CONFIG_DECNET is not set
358# CONFIG_LLC2 is not set
359# CONFIG_IPX is not set
360# CONFIG_ATALK is not set
361# CONFIG_X25 is not set
362# CONFIG_LAPB is not set
363# CONFIG_ECONET is not set
364# CONFIG_WAN_ROUTER is not set
365# CONFIG_NET_SCHED is not set
366# CONFIG_DCB is not set
367
368#
369# Network testing
370#
371# CONFIG_NET_PKTGEN is not set
372# CONFIG_HAMRADIO is not set
373# CONFIG_CAN is not set
374# CONFIG_IRDA is not set
375# CONFIG_BT is not set
376# CONFIG_AF_RXRPC is not set
377# CONFIG_PHONET is not set
378# CONFIG_WIRELESS is not set
379# CONFIG_WIMAX is not set
380# CONFIG_RFKILL is not set
381# CONFIG_NET_9P is not set
382
383#
384# Device Drivers
385#
386
387#
388# Generic Driver Options
389#
390CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
391CONFIG_STANDALONE=y
392CONFIG_PREVENT_FIRMWARE_BUILD=y
393CONFIG_FW_LOADER=y
394# CONFIG_FIRMWARE_IN_KERNEL is not set
395CONFIG_EXTRA_FIRMWARE=""
396# CONFIG_DEBUG_DRIVER is not set
397# CONFIG_DEBUG_DEVRES is not set
398# CONFIG_SYS_HYPERVISOR is not set
399# CONFIG_CONNECTOR is not set
400CONFIG_MTD=y
401# CONFIG_MTD_DEBUG is not set
402# CONFIG_MTD_CONCAT is not set
403CONFIG_MTD_PARTITIONS=y
404# CONFIG_MTD_TESTS is not set
405# CONFIG_MTD_REDBOOT_PARTS is not set
406CONFIG_MTD_CMDLINE_PARTS=y
407# CONFIG_MTD_AR7_PARTS is not set
408
409#
410# User Modules And Translation Layers
411#
412CONFIG_MTD_CHAR=y
413CONFIG_MTD_BLKDEVS=y
414CONFIG_MTD_BLOCK=y
415# CONFIG_FTL is not set
416# CONFIG_NFTL is not set
417# CONFIG_INFTL is not set
418# CONFIG_RFD_FTL is not set
419# CONFIG_SSFDC is not set
420# CONFIG_MTD_OOPS is not set
421
422#
423# RAM/ROM/Flash chip drivers
424#
425CONFIG_MTD_CFI=y
426# CONFIG_MTD_JEDECPROBE is not set
427CONFIG_MTD_GEN_PROBE=y
428CONFIG_MTD_CFI_ADV_OPTIONS=y
429CONFIG_MTD_CFI_NOSWAP=y
430# CONFIG_MTD_CFI_BE_BYTE_SWAP is not set
431# CONFIG_MTD_CFI_LE_BYTE_SWAP is not set
432# CONFIG_MTD_CFI_GEOMETRY is not set
433CONFIG_MTD_MAP_BANK_WIDTH_1=y
434CONFIG_MTD_MAP_BANK_WIDTH_2=y
435CONFIG_MTD_MAP_BANK_WIDTH_4=y
436# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
437# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
438# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
439CONFIG_MTD_CFI_I1=y
440CONFIG_MTD_CFI_I2=y
441# CONFIG_MTD_CFI_I4 is not set
442# CONFIG_MTD_CFI_I8 is not set
443# CONFIG_MTD_OTP is not set
444CONFIG_MTD_CFI_INTELEXT=y
445# CONFIG_MTD_CFI_AMDSTD is not set
446# CONFIG_MTD_CFI_STAA is not set
447CONFIG_MTD_CFI_UTIL=y
448# CONFIG_MTD_RAM is not set
449# CONFIG_MTD_ROM is not set
450# CONFIG_MTD_ABSENT is not set
451
452#
453# Mapping drivers for chip access
454#
455# CONFIG_MTD_COMPLEX_MAPPINGS is not set
456CONFIG_MTD_PHYSMAP=y
457CONFIG_MTD_PHYSMAP_COMPAT=y
458CONFIG_MTD_PHYSMAP_START=0x00000000
459CONFIG_MTD_PHYSMAP_LEN=0x01000000
460CONFIG_MTD_PHYSMAP_BANKWIDTH=2
461# CONFIG_MTD_PLATRAM is not set
462
463#
464# Self-contained MTD device drivers
465#
466# CONFIG_MTD_SLRAM is not set
467# CONFIG_MTD_PHRAM is not set
468# CONFIG_MTD_MTDRAM is not set
469# CONFIG_MTD_BLOCK2MTD is not set
470
471#
472# Disk-On-Chip Device Drivers
473#
474# CONFIG_MTD_DOC2000 is not set
475# CONFIG_MTD_DOC2001 is not set
476# CONFIG_MTD_DOC2001PLUS is not set
477# CONFIG_MTD_NAND is not set
478# CONFIG_MTD_ONENAND is not set
479
480#
481# LPDDR flash memory drivers
482#
483# CONFIG_MTD_LPDDR is not set
484# CONFIG_MTD_QINFO_PROBE is not set
485
486#
487# UBI - Unsorted block images
488#
489# CONFIG_MTD_UBI is not set
490# CONFIG_PARPORT is not set
491CONFIG_BLK_DEV=y
492# CONFIG_BLK_DEV_COW_COMMON is not set
493# CONFIG_BLK_DEV_LOOP is not set
494# CONFIG_BLK_DEV_NBD is not set
495# CONFIG_BLK_DEV_RAM is not set
496# CONFIG_CDROM_PKTCDVD is not set
497# CONFIG_ATA_OVER_ETH is not set
498# CONFIG_BLK_DEV_HD is not set
499CONFIG_MISC_DEVICES=y
500# CONFIG_ENCLOSURE_SERVICES is not set
501# CONFIG_C2PORT is not set
502
503#
504# EEPROM support
505#
506# CONFIG_EEPROM_93CX6 is not set
507CONFIG_HAVE_IDE=y
508# CONFIG_IDE is not set
509
510#
511# SCSI device support
512#
513# CONFIG_RAID_ATTRS is not set
514# CONFIG_SCSI is not set
515# CONFIG_SCSI_DMA is not set
516# CONFIG_SCSI_NETLINK is not set
517# CONFIG_ATA is not set
518# CONFIG_MD is not set
519CONFIG_NETDEVICES=y
520# CONFIG_DUMMY is not set
521# CONFIG_BONDING is not set
522# CONFIG_MACVLAN is not set
523# CONFIG_EQUALIZER is not set
524# CONFIG_TUN is not set
525# CONFIG_VETH is not set
526CONFIG_PHYLIB=y
527
528#
529# MII PHY device drivers
530#
531# CONFIG_MARVELL_PHY is not set
532# CONFIG_DAVICOM_PHY is not set
533# CONFIG_QSEMI_PHY is not set
534# CONFIG_LXT_PHY is not set
535# CONFIG_CICADA_PHY is not set
536# CONFIG_VITESSE_PHY is not set
537CONFIG_SMSC_PHY=y
538# CONFIG_BROADCOM_PHY is not set
539# CONFIG_ICPLUS_PHY is not set
540# CONFIG_REALTEK_PHY is not set
541# CONFIG_NATIONAL_PHY is not set
542# CONFIG_STE10XP is not set
543# CONFIG_LSI_ET1011C_PHY is not set
544# CONFIG_FIXED_PHY is not set
545# CONFIG_MDIO_BITBANG is not set
546CONFIG_NET_ETHERNET=y
547CONFIG_MII=y
548# CONFIG_AX88796 is not set
549# CONFIG_STNIC is not set
550# CONFIG_SMC91X is not set
551# CONFIG_SMC911X is not set
552CONFIG_SMSC911X=y
553# CONFIG_IBM_NEW_EMAC_ZMII is not set
554# CONFIG_IBM_NEW_EMAC_RGMII is not set
555# CONFIG_IBM_NEW_EMAC_TAH is not set
556# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
557# CONFIG_IBM_NEW_EMAC_NO_FLOW_CTRL is not set
558# CONFIG_IBM_NEW_EMAC_MAL_CLR_ICINTSTAT is not set
559# CONFIG_IBM_NEW_EMAC_MAL_COMMON_ERR is not set
560# CONFIG_B44 is not set
561# CONFIG_NETDEV_1000 is not set
562# CONFIG_NETDEV_10000 is not set
563
564#
565# Wireless LAN
566#
567# CONFIG_WLAN_PRE80211 is not set
568# CONFIG_WLAN_80211 is not set
569# CONFIG_IWLWIFI_LEDS is not set
570
571#
572# Enable WiMAX (Networking options) to see the WiMAX drivers
573#
574# CONFIG_WAN is not set
575# CONFIG_PPP is not set
576# CONFIG_SLIP is not set
577# CONFIG_NETCONSOLE is not set
578# CONFIG_NETPOLL is not set
579# CONFIG_NET_POLL_CONTROLLER is not set
580# CONFIG_ISDN is not set
581# CONFIG_PHONE is not set
582
583#
584# Input device support
585#
586CONFIG_INPUT=y
587# CONFIG_INPUT_FF_MEMLESS is not set
588# CONFIG_INPUT_POLLDEV is not set
589
590#
591# Userland interfaces
592#
593# CONFIG_INPUT_MOUSEDEV is not set
594# CONFIG_INPUT_JOYDEV is not set
595# CONFIG_INPUT_EVDEV is not set
596# CONFIG_INPUT_EVBUG is not set
597
598#
599# Input Device Drivers
600#
601# CONFIG_INPUT_KEYBOARD is not set
602# CONFIG_INPUT_MOUSE is not set
603# CONFIG_INPUT_JOYSTICK is not set
604# CONFIG_INPUT_TABLET is not set
605# CONFIG_INPUT_TOUCHSCREEN is not set
606# CONFIG_INPUT_MISC is not set
607
608#
609# Hardware I/O ports
610#
611# CONFIG_SERIO is not set
612# CONFIG_GAMEPORT is not set
613
614#
615# Character devices
616#
617CONFIG_VT=y
618CONFIG_CONSOLE_TRANSLATIONS=y
619CONFIG_VT_CONSOLE=y
620CONFIG_HW_CONSOLE=y
621CONFIG_VT_HW_CONSOLE_BINDING=y
622CONFIG_DEVKMEM=y
623CONFIG_SERIAL_NONSTANDARD=y
624# CONFIG_N_HDLC is not set
625# CONFIG_RISCOM8 is not set
626# CONFIG_SPECIALIX is not set
627# CONFIG_RIO is not set
628# CONFIG_STALDRV is not set
629
630#
631# Serial drivers
632#
633# CONFIG_SERIAL_8250 is not set
634
635#
636# Non-8250 serial port support
637#
638CONFIG_SERIAL_SH_SCI=y
639CONFIG_SERIAL_SH_SCI_NR_UARTS=3
640CONFIG_SERIAL_SH_SCI_CONSOLE=y
641CONFIG_SERIAL_CORE=y
642CONFIG_SERIAL_CORE_CONSOLE=y
643CONFIG_UNIX98_PTYS=y
644# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
645# CONFIG_LEGACY_PTYS is not set
646# CONFIG_IPMI_HANDLER is not set
647# CONFIG_HW_RANDOM is not set
648# CONFIG_R3964 is not set
649# CONFIG_RAW_DRIVER is not set
650# CONFIG_TCG_TPM is not set
651# CONFIG_I2C is not set
652# CONFIG_SPI is not set
653# CONFIG_W1 is not set
654# CONFIG_POWER_SUPPLY is not set
655# CONFIG_HWMON is not set
656# CONFIG_THERMAL is not set
657# CONFIG_THERMAL_HWMON is not set
658# CONFIG_WATCHDOG is not set
659CONFIG_SSB_POSSIBLE=y
660
661#
662# Sonics Silicon Backplane
663#
664# CONFIG_SSB is not set
665
666#
667# Multifunction device drivers
668#
669# CONFIG_MFD_CORE is not set
670# CONFIG_MFD_SM501 is not set
671# CONFIG_HTC_PASIC3 is not set
672# CONFIG_MFD_TMIO is not set
673# CONFIG_REGULATOR is not set
674
675#
676# Multimedia devices
677#
678
679#
680# Multimedia core support
681#
682# CONFIG_VIDEO_DEV is not set
683# CONFIG_DVB_CORE is not set
684# CONFIG_VIDEO_MEDIA is not set
685
686#
687# Multimedia drivers
688#
689# CONFIG_DAB is not set
690
691#
692# Graphics support
693#
694# CONFIG_VGASTATE is not set
695# CONFIG_VIDEO_OUTPUT_CONTROL is not set
696# CONFIG_FB is not set
697# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
698
699#
700# Display device support
701#
702# CONFIG_DISPLAY_SUPPORT is not set
703
704#
705# Console display driver support
706#
707CONFIG_DUMMY_CONSOLE=y
708# CONFIG_SOUND is not set
709# CONFIG_HID_SUPPORT is not set
710# CONFIG_USB_SUPPORT is not set
711# CONFIG_MMC is not set
712# CONFIG_MEMSTICK is not set
713# CONFIG_NEW_LEDS is not set
714# CONFIG_ACCESSIBILITY is not set
715CONFIG_RTC_LIB=y
716CONFIG_RTC_CLASS=y
717CONFIG_RTC_HCTOSYS=y
718CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
719# CONFIG_RTC_DEBUG is not set
720
721#
722# RTC interfaces
723#
724CONFIG_RTC_INTF_SYSFS=y
725CONFIG_RTC_INTF_PROC=y
726CONFIG_RTC_INTF_DEV=y
727# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
728# CONFIG_RTC_DRV_TEST is not set
729
730#
731# SPI RTC drivers
732#
733
734#
735# Platform RTC drivers
736#
737# CONFIG_RTC_DRV_DS1286 is not set
738# CONFIG_RTC_DRV_DS1511 is not set
739# CONFIG_RTC_DRV_DS1553 is not set
740# CONFIG_RTC_DRV_DS1742 is not set
741# CONFIG_RTC_DRV_STK17TA8 is not set
742# CONFIG_RTC_DRV_M48T86 is not set
743# CONFIG_RTC_DRV_M48T35 is not set
744# CONFIG_RTC_DRV_M48T59 is not set
745# CONFIG_RTC_DRV_BQ4802 is not set
746# CONFIG_RTC_DRV_V3020 is not set
747
748#
749# on-CPU RTC drivers
750#
751CONFIG_RTC_DRV_SH=y
752# CONFIG_DMADEVICES is not set
753# CONFIG_UIO is not set
754# CONFIG_STAGING is not set
755
756#
757# File systems
758#
759# CONFIG_EXT2_FS is not set
760# CONFIG_EXT3_FS is not set
761# CONFIG_EXT4_FS is not set
762# CONFIG_REISERFS_FS is not set
763# CONFIG_JFS_FS is not set
764# CONFIG_FS_POSIX_ACL is not set
765CONFIG_FILE_LOCKING=y
766# CONFIG_XFS_FS is not set
767# CONFIG_OCFS2_FS is not set
768# CONFIG_BTRFS_FS is not set
769# CONFIG_DNOTIFY is not set
770# CONFIG_INOTIFY is not set
771# CONFIG_QUOTA is not set
772# CONFIG_AUTOFS_FS is not set
773# CONFIG_AUTOFS4_FS is not set
774# CONFIG_FUSE_FS is not set
775
776#
777# CD-ROM/DVD Filesystems
778#
779# CONFIG_ISO9660_FS is not set
780# CONFIG_UDF_FS is not set
781
782#
783# DOS/FAT/NT Filesystems
784#
785# CONFIG_MSDOS_FS is not set
786# CONFIG_VFAT_FS is not set
787# CONFIG_NTFS_FS is not set
788
789#
790# Pseudo filesystems
791#
792CONFIG_PROC_FS=y
793CONFIG_PROC_KCORE=y
794CONFIG_PROC_SYSCTL=y
795CONFIG_PROC_PAGE_MONITOR=y
796CONFIG_SYSFS=y
797CONFIG_TMPFS=y
798# CONFIG_TMPFS_POSIX_ACL is not set
799# CONFIG_HUGETLBFS is not set
800# CONFIG_HUGETLB_PAGE is not set
801# CONFIG_CONFIGFS_FS is not set
802CONFIG_MISC_FILESYSTEMS=y
803# CONFIG_ADFS_FS is not set
804# CONFIG_AFFS_FS is not set
805# CONFIG_HFS_FS is not set
806# CONFIG_HFSPLUS_FS is not set
807# CONFIG_BEFS_FS is not set
808# CONFIG_BFS_FS is not set
809# CONFIG_EFS_FS is not set
810CONFIG_JFFS2_FS=y
811CONFIG_JFFS2_FS_DEBUG=0
812# CONFIG_JFFS2_FS_WRITEBUFFER is not set
813# CONFIG_JFFS2_SUMMARY is not set
814# CONFIG_JFFS2_FS_XATTR is not set
815# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
816CONFIG_JFFS2_ZLIB=y
817# CONFIG_JFFS2_LZO is not set
818CONFIG_JFFS2_RTIME=y
819# CONFIG_JFFS2_RUBIN is not set
820# CONFIG_CRAMFS is not set
821# CONFIG_SQUASHFS is not set
822# CONFIG_VXFS_FS is not set
823# CONFIG_MINIX_FS is not set
824# CONFIG_OMFS_FS is not set
825# CONFIG_HPFS_FS is not set
826# CONFIG_QNX4FS_FS is not set
827# CONFIG_ROMFS_FS is not set
828# CONFIG_SYSV_FS is not set
829# CONFIG_UFS_FS is not set
830CONFIG_NETWORK_FILESYSTEMS=y
831CONFIG_NFS_FS=y
832CONFIG_NFS_V3=y
833# CONFIG_NFS_V3_ACL is not set
834# CONFIG_NFS_V4 is not set
835# CONFIG_NFSD is not set
836CONFIG_LOCKD=y
837CONFIG_LOCKD_V4=y
838CONFIG_NFS_COMMON=y
839CONFIG_SUNRPC=y
840# CONFIG_SUNRPC_REGISTER_V4 is not set
841# CONFIG_RPCSEC_GSS_KRB5 is not set
842# CONFIG_RPCSEC_GSS_SPKM3 is not set
843# CONFIG_SMB_FS is not set
844# CONFIG_CIFS is not set
845# CONFIG_NCP_FS is not set
846# CONFIG_CODA_FS is not set
847# CONFIG_AFS_FS is not set
848
849#
850# Partition Types
851#
852# CONFIG_PARTITION_ADVANCED is not set
853CONFIG_MSDOS_PARTITION=y
854# CONFIG_NLS is not set
855# CONFIG_DLM is not set
856
857#
858# Kernel hacking
859#
860CONFIG_TRACE_IRQFLAGS_SUPPORT=y
861# CONFIG_PRINTK_TIME is not set
862CONFIG_ENABLE_WARN_DEPRECATED=y
863CONFIG_ENABLE_MUST_CHECK=y
864CONFIG_FRAME_WARN=1024
865# CONFIG_MAGIC_SYSRQ is not set
866# CONFIG_UNUSED_SYMBOLS is not set
867# CONFIG_DEBUG_FS is not set
868# CONFIG_HEADERS_CHECK is not set
869CONFIG_DEBUG_KERNEL=y
870CONFIG_DEBUG_SHIRQ=y
871CONFIG_DETECT_SOFTLOCKUP=y
872# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
873CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
874# CONFIG_SCHED_DEBUG is not set
875# CONFIG_SCHEDSTATS is not set
876# CONFIG_TIMER_STATS is not set
877# CONFIG_DEBUG_OBJECTS is not set
878# CONFIG_DEBUG_SLAB is not set
879CONFIG_DEBUG_PREEMPT=y
880CONFIG_DEBUG_RT_MUTEXES=y
881CONFIG_DEBUG_PI_LIST=y
882# CONFIG_RT_MUTEX_TESTER is not set
883CONFIG_DEBUG_SPINLOCK=y
884CONFIG_DEBUG_MUTEXES=y
885CONFIG_DEBUG_LOCK_ALLOC=y
886# CONFIG_PROVE_LOCKING is not set
887CONFIG_LOCKDEP=y
888# CONFIG_LOCK_STAT is not set
889# CONFIG_DEBUG_LOCKDEP is not set
890CONFIG_DEBUG_SPINLOCK_SLEEP=y
891# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
892CONFIG_STACKTRACE=y
893# CONFIG_DEBUG_KOBJECT is not set
894CONFIG_DEBUG_BUGVERBOSE=y
895CONFIG_DEBUG_INFO=y
896# CONFIG_DEBUG_VM is not set
897# CONFIG_DEBUG_WRITECOUNT is not set
898# CONFIG_DEBUG_MEMORY_INIT is not set
899# CONFIG_DEBUG_LIST is not set
900CONFIG_DEBUG_SG=y
901# CONFIG_DEBUG_NOTIFIERS is not set
902CONFIG_FRAME_POINTER=y
903# CONFIG_RCU_TORTURE_TEST is not set
904# CONFIG_RCU_CPU_STALL_DETECTOR is not set
905# CONFIG_BACKTRACE_SELF_TEST is not set
906# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
907# CONFIG_FAULT_INJECTION is not set
908# CONFIG_LATENCYTOP is not set
909CONFIG_SYSCTL_SYSCALL_CHECK=y
910CONFIG_HAVE_FUNCTION_TRACER=y
911CONFIG_HAVE_DYNAMIC_FTRACE=y
912CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
913
914#
915# Tracers
916#
917# CONFIG_FUNCTION_TRACER is not set
918# CONFIG_IRQSOFF_TRACER is not set
919# CONFIG_PREEMPT_TRACER is not set
920# CONFIG_SCHED_TRACER is not set
921# CONFIG_CONTEXT_SWITCH_TRACER is not set
922# CONFIG_BOOT_TRACER is not set
923# CONFIG_TRACE_BRANCH_PROFILING is not set
924# CONFIG_STACK_TRACER is not set
925# CONFIG_DYNAMIC_PRINTK_DEBUG is not set
926# CONFIG_SAMPLES is not set
927CONFIG_HAVE_ARCH_KGDB=y
928# CONFIG_KGDB is not set
929# CONFIG_SH_STANDARD_BIOS is not set
930CONFIG_EARLY_SCIF_CONSOLE=y
931CONFIG_EARLY_SCIF_CONSOLE_PORT=0x00000000
932CONFIG_EARLY_PRINTK=y
933# CONFIG_DEBUG_BOOTMEM is not set
934# CONFIG_DEBUG_STACKOVERFLOW is not set
935# CONFIG_DEBUG_STACK_USAGE is not set
936# CONFIG_4KSTACKS is not set
937# CONFIG_IRQSTACKS is not set
938CONFIG_DUMP_CODE=y
939# CONFIG_SH_NO_BSS_INIT is not set
940# CONFIG_MORE_COMPILE_OPTIONS is not set
941
942#
943# Security options
944#
945# CONFIG_KEYS is not set
946# CONFIG_SECURITY is not set
947# CONFIG_SECURITYFS is not set
948# CONFIG_SECURITY_FILE_CAPABILITIES is not set
949# CONFIG_CRYPTO is not set
950
951#
952# Library routines
953#
954CONFIG_BITREVERSE=y
955CONFIG_GENERIC_FIND_LAST_BIT=y
956# CONFIG_CRC_CCITT is not set
957# CONFIG_CRC16 is not set
958# CONFIG_CRC_T10DIF is not set
959# CONFIG_CRC_ITU_T is not set
960CONFIG_CRC32=y
961# CONFIG_CRC7 is not set
962# CONFIG_LIBCRC32C is not set
963CONFIG_AUDIT_GENERIC=y
964CONFIG_ZLIB_INFLATE=y
965CONFIG_ZLIB_DEFLATE=y
966CONFIG_PLIST=y
967CONFIG_HAS_IOMEM=y
968CONFIG_HAS_IOPORT=y
969CONFIG_HAS_DMA=y
diff --git a/arch/sh/configs/sh7785lcr_32bit_defconfig b/arch/sh/configs/sh7785lcr_32bit_defconfig
new file mode 100644
index 000000000000..54e1dee8e24a
--- /dev/null
+++ b/arch/sh/configs/sh7785lcr_32bit_defconfig
@@ -0,0 +1,1553 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29-rc4
4# Fri Feb 20 18:25:29 2009
5#
6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y
11CONFIG_GENERIC_FIND_NEXT_BIT=y
12CONFIG_GENERIC_HWEIGHT=y
13CONFIG_GENERIC_HARDIRQS=y
14CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
15CONFIG_GENERIC_IRQ_PROBE=y
16# CONFIG_GENERIC_GPIO is not set
17CONFIG_GENERIC_TIME=y
18CONFIG_GENERIC_CLOCKEVENTS=y
19# CONFIG_ARCH_SUSPEND_POSSIBLE is not set
20# CONFIG_ARCH_HIBERNATION_POSSIBLE is not set
21CONFIG_SYS_SUPPORTS_NUMA=y
22CONFIG_SYS_SUPPORTS_PCI=y
23CONFIG_STACKTRACE_SUPPORT=y
24CONFIG_LOCKDEP_SUPPORT=y
25CONFIG_HAVE_LATENCYTOP_SUPPORT=y
26# CONFIG_ARCH_HAS_ILOG2_U32 is not set
27# CONFIG_ARCH_HAS_ILOG2_U64 is not set
28CONFIG_ARCH_NO_VIRT_TO_BUS=y
29CONFIG_IO_TRAPPED=y
30CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
31
32#
33# General setup
34#
35CONFIG_EXPERIMENTAL=y
36CONFIG_BROKEN_ON_SMP=y
37CONFIG_LOCK_KERNEL=y
38CONFIG_INIT_ENV_ARG_LIMIT=32
39CONFIG_LOCALVERSION=""
40CONFIG_LOCALVERSION_AUTO=y
41CONFIG_SWAP=y
42CONFIG_SYSVIPC=y
43CONFIG_SYSVIPC_SYSCTL=y
44# CONFIG_POSIX_MQUEUE is not set
45CONFIG_BSD_PROCESS_ACCT=y
46# CONFIG_BSD_PROCESS_ACCT_V3 is not set
47# CONFIG_TASKSTATS is not set
48# CONFIG_AUDIT is not set
49
50#
51# RCU Subsystem
52#
53CONFIG_CLASSIC_RCU=y
54# CONFIG_TREE_RCU is not set
55# CONFIG_PREEMPT_RCU is not set
56# CONFIG_TREE_RCU_TRACE is not set
57# CONFIG_PREEMPT_RCU_TRACE is not set
58CONFIG_IKCONFIG=y
59CONFIG_IKCONFIG_PROC=y
60CONFIG_LOG_BUF_SHIFT=14
61CONFIG_GROUP_SCHED=y
62CONFIG_FAIR_GROUP_SCHED=y
63# CONFIG_RT_GROUP_SCHED is not set
64CONFIG_USER_SCHED=y
65# CONFIG_CGROUP_SCHED is not set
66# CONFIG_CGROUPS is not set
67CONFIG_SYSFS_DEPRECATED=y
68CONFIG_SYSFS_DEPRECATED_V2=y
69# CONFIG_RELAY is not set
70# CONFIG_NAMESPACES is not set
71# CONFIG_BLK_DEV_INITRD is not set
72CONFIG_CC_OPTIMIZE_FOR_SIZE=y
73CONFIG_SYSCTL=y
74CONFIG_EMBEDDED=y
75CONFIG_UID16=y
76CONFIG_SYSCTL_SYSCALL=y
77CONFIG_KALLSYMS=y
78# CONFIG_KALLSYMS_ALL is not set
79# CONFIG_KALLSYMS_EXTRA_PASS is not set
80CONFIG_HOTPLUG=y
81CONFIG_PRINTK=y
82CONFIG_BUG=y
83CONFIG_ELF_CORE=y
84CONFIG_COMPAT_BRK=y
85CONFIG_BASE_FULL=y
86CONFIG_FUTEX=y
87CONFIG_ANON_INODES=y
88CONFIG_EPOLL=y
89CONFIG_SIGNALFD=y
90CONFIG_TIMERFD=y
91CONFIG_EVENTFD=y
92CONFIG_SHMEM=y
93CONFIG_AIO=y
94CONFIG_VM_EVENT_COUNTERS=y
95CONFIG_PCI_QUIRKS=y
96CONFIG_SLAB=y
97# CONFIG_SLUB is not set
98# CONFIG_SLOB is not set
99CONFIG_PROFILING=y
100# CONFIG_OPROFILE is not set
101CONFIG_HAVE_OPROFILE=y
102# CONFIG_KPROBES is not set
103CONFIG_HAVE_IOREMAP_PROT=y
104CONFIG_HAVE_KPROBES=y
105CONFIG_HAVE_KRETPROBES=y
106CONFIG_HAVE_ARCH_TRACEHOOK=y
107CONFIG_HAVE_CLK=y
108CONFIG_HAVE_GENERIC_DMA_COHERENT=y
109CONFIG_SLABINFO=y
110CONFIG_RT_MUTEXES=y
111CONFIG_BASE_SMALL=0
112CONFIG_MODULES=y
113# CONFIG_MODULE_FORCE_LOAD is not set
114CONFIG_MODULE_UNLOAD=y
115# CONFIG_MODULE_FORCE_UNLOAD is not set
116# CONFIG_MODVERSIONS is not set
117# CONFIG_MODULE_SRCVERSION_ALL is not set
118CONFIG_BLOCK=y
119# CONFIG_LBD is not set
120# CONFIG_BLK_DEV_IO_TRACE is not set
121# CONFIG_BLK_DEV_BSG is not set
122# CONFIG_BLK_DEV_INTEGRITY is not set
123
124#
125# IO Schedulers
126#
127CONFIG_IOSCHED_NOOP=y
128CONFIG_IOSCHED_AS=y
129CONFIG_IOSCHED_DEADLINE=y
130CONFIG_IOSCHED_CFQ=y
131# CONFIG_DEFAULT_AS is not set
132# CONFIG_DEFAULT_DEADLINE is not set
133CONFIG_DEFAULT_CFQ=y
134# CONFIG_DEFAULT_NOOP is not set
135CONFIG_DEFAULT_IOSCHED="cfq"
136# CONFIG_FREEZER is not set
137
138#
139# System type
140#
141CONFIG_CPU_SH4=y
142CONFIG_CPU_SH4A=y
143CONFIG_CPU_SHX2=y
144# CONFIG_CPU_SUBTYPE_SH7619 is not set
145# CONFIG_CPU_SUBTYPE_SH7201 is not set
146# CONFIG_CPU_SUBTYPE_SH7203 is not set
147# CONFIG_CPU_SUBTYPE_SH7206 is not set
148# CONFIG_CPU_SUBTYPE_SH7263 is not set
149# CONFIG_CPU_SUBTYPE_MXG is not set
150# CONFIG_CPU_SUBTYPE_SH7705 is not set
151# CONFIG_CPU_SUBTYPE_SH7706 is not set
152# CONFIG_CPU_SUBTYPE_SH7707 is not set
153# CONFIG_CPU_SUBTYPE_SH7708 is not set
154# CONFIG_CPU_SUBTYPE_SH7709 is not set
155# CONFIG_CPU_SUBTYPE_SH7710 is not set
156# CONFIG_CPU_SUBTYPE_SH7712 is not set
157# CONFIG_CPU_SUBTYPE_SH7720 is not set
158# CONFIG_CPU_SUBTYPE_SH7721 is not set
159# CONFIG_CPU_SUBTYPE_SH7750 is not set
160# CONFIG_CPU_SUBTYPE_SH7091 is not set
161# CONFIG_CPU_SUBTYPE_SH7750R is not set
162# CONFIG_CPU_SUBTYPE_SH7750S is not set
163# CONFIG_CPU_SUBTYPE_SH7751 is not set
164# CONFIG_CPU_SUBTYPE_SH7751R is not set
165# CONFIG_CPU_SUBTYPE_SH7760 is not set
166# CONFIG_CPU_SUBTYPE_SH4_202 is not set
167# CONFIG_CPU_SUBTYPE_SH7723 is not set
168# CONFIG_CPU_SUBTYPE_SH7763 is not set
169# CONFIG_CPU_SUBTYPE_SH7770 is not set
170# CONFIG_CPU_SUBTYPE_SH7780 is not set
171CONFIG_CPU_SUBTYPE_SH7785=y
172# CONFIG_CPU_SUBTYPE_SHX3 is not set
173# CONFIG_CPU_SUBTYPE_SH7343 is not set
174# CONFIG_CPU_SUBTYPE_SH7722 is not set
175# CONFIG_CPU_SUBTYPE_SH7366 is not set
176# CONFIG_CPU_SUBTYPE_SH5_101 is not set
177# CONFIG_CPU_SUBTYPE_SH5_103 is not set
178
179#
180# Memory management options
181#
182CONFIG_QUICKLIST=y
183CONFIG_MMU=y
184CONFIG_PAGE_OFFSET=0x80000000
185CONFIG_MEMORY_START=0x40000000
186CONFIG_MEMORY_SIZE=0x20000000
187# CONFIG_29BIT is not set
188CONFIG_32BIT=y
189CONFIG_PMB_ENABLE=y
190# CONFIG_PMB is not set
191CONFIG_PMB_FIXED=y
192# CONFIG_X2TLB is not set
193CONFIG_VSYSCALL=y
194# CONFIG_NUMA is not set
195CONFIG_ARCH_FLATMEM_ENABLE=y
196CONFIG_ARCH_SPARSEMEM_ENABLE=y
197CONFIG_ARCH_SPARSEMEM_DEFAULT=y
198CONFIG_MAX_ACTIVE_REGIONS=2
199CONFIG_ARCH_POPULATES_NODE_MAP=y
200CONFIG_ARCH_SELECT_MEMORY_MODEL=y
201CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
202CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
203CONFIG_PAGE_SIZE_4KB=y
204# CONFIG_PAGE_SIZE_8KB is not set
205# CONFIG_PAGE_SIZE_16KB is not set
206# CONFIG_PAGE_SIZE_64KB is not set
207CONFIG_ENTRY_OFFSET=0x00001000
208CONFIG_SELECT_MEMORY_MODEL=y
209# CONFIG_FLATMEM_MANUAL is not set
210# CONFIG_DISCONTIGMEM_MANUAL is not set
211CONFIG_SPARSEMEM_MANUAL=y
212CONFIG_SPARSEMEM=y
213CONFIG_HAVE_MEMORY_PRESENT=y
214CONFIG_SPARSEMEM_STATIC=y
215# CONFIG_MEMORY_HOTPLUG is not set
216CONFIG_PAGEFLAGS_EXTENDED=y
217CONFIG_SPLIT_PTLOCK_CPUS=4
218CONFIG_MIGRATION=y
219# CONFIG_PHYS_ADDR_T_64BIT is not set
220CONFIG_ZONE_DMA_FLAG=0
221CONFIG_NR_QUICK=2
222CONFIG_UNEVICTABLE_LRU=y
223
224#
225# Cache configuration
226#
227# CONFIG_SH_DIRECT_MAPPED is not set
228CONFIG_CACHE_WRITEBACK=y
229# CONFIG_CACHE_WRITETHROUGH is not set
230# CONFIG_CACHE_OFF is not set
231
232#
233# Processor features
234#
235CONFIG_CPU_LITTLE_ENDIAN=y
236# CONFIG_CPU_BIG_ENDIAN is not set
237CONFIG_SH_FPU=y
238CONFIG_SH_STORE_QUEUES=y
239CONFIG_CPU_HAS_INTEVT=y
240CONFIG_CPU_HAS_SR_RB=y
241CONFIG_CPU_HAS_PTEA=y
242CONFIG_CPU_HAS_FPU=y
243
244#
245# Board support
246#
247# CONFIG_SH_HIGHLANDER is not set
248CONFIG_SH_SH7785LCR=y
249
250#
251# Timer and clock configuration
252#
253CONFIG_SH_TMU=y
254CONFIG_SH_TIMER_IRQ=28
255CONFIG_SH_PCLK_FREQ=50000000
256CONFIG_TICK_ONESHOT=y
257# CONFIG_NO_HZ is not set
258CONFIG_HIGH_RES_TIMERS=y
259CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
260
261#
262# CPU Frequency scaling
263#
264# CONFIG_CPU_FREQ is not set
265
266#
267# DMA support
268#
269# CONFIG_SH_DMA is not set
270
271#
272# Companion Chips
273#
274
275#
276# Additional SuperH Device Drivers
277#
278CONFIG_HEARTBEAT=y
279# CONFIG_PUSH_SWITCH is not set
280
281#
282# Kernel features
283#
284# CONFIG_HZ_100 is not set
285CONFIG_HZ_250=y
286# CONFIG_HZ_300 is not set
287# CONFIG_HZ_1000 is not set
288CONFIG_HZ=250
289CONFIG_SCHED_HRTICK=y
290CONFIG_KEXEC=y
291# CONFIG_CRASH_DUMP is not set
292# CONFIG_SECCOMP is not set
293# CONFIG_PREEMPT_NONE is not set
294# CONFIG_PREEMPT_VOLUNTARY is not set
295CONFIG_PREEMPT=y
296CONFIG_GUSA=y
297
298#
299# Boot options
300#
301CONFIG_ZERO_PAGE_OFFSET=0x00001000
302CONFIG_BOOT_LINK_OFFSET=0x00800000
303# CONFIG_CMDLINE_BOOL is not set
304
305#
306# Bus options
307#
308CONFIG_PCI=y
309CONFIG_SH_PCIDMA_NONCOHERENT=y
310CONFIG_PCI_AUTO=y
311CONFIG_PCI_AUTO_UPDATE_RESOURCES=y
312# CONFIG_PCIEPORTBUS is not set
313# CONFIG_ARCH_SUPPORTS_MSI is not set
314CONFIG_PCI_LEGACY=y
315# CONFIG_PCI_DEBUG is not set
316# CONFIG_PCI_STUB is not set
317# CONFIG_PCCARD is not set
318# CONFIG_HOTPLUG_PCI is not set
319
320#
321# Executable file formats
322#
323CONFIG_BINFMT_ELF=y
324# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
325# CONFIG_HAVE_AOUT is not set
326# CONFIG_BINFMT_MISC is not set
327
328#
329# Power management options (EXPERIMENTAL)
330#
331# CONFIG_PM is not set
332# CONFIG_CPU_IDLE is not set
333CONFIG_NET=y
334
335#
336# Networking options
337#
338CONFIG_COMPAT_NET_DEV_OPS=y
339CONFIG_PACKET=y
340# CONFIG_PACKET_MMAP is not set
341CONFIG_UNIX=y
342CONFIG_XFRM=y
343# CONFIG_XFRM_USER is not set
344# CONFIG_XFRM_SUB_POLICY is not set
345# CONFIG_XFRM_MIGRATE is not set
346# CONFIG_XFRM_STATISTICS is not set
347# CONFIG_NET_KEY is not set
348CONFIG_INET=y
349# CONFIG_IP_MULTICAST is not set
350CONFIG_IP_ADVANCED_ROUTER=y
351CONFIG_ASK_IP_FIB_HASH=y
352# CONFIG_IP_FIB_TRIE is not set
353CONFIG_IP_FIB_HASH=y
354# CONFIG_IP_MULTIPLE_TABLES is not set
355# CONFIG_IP_ROUTE_MULTIPATH is not set
356# CONFIG_IP_ROUTE_VERBOSE is not set
357CONFIG_IP_PNP=y
358CONFIG_IP_PNP_DHCP=y
359# CONFIG_IP_PNP_BOOTP is not set
360# CONFIG_IP_PNP_RARP is not set
361# CONFIG_NET_IPIP is not set
362# CONFIG_NET_IPGRE is not set
363# CONFIG_ARPD is not set
364# CONFIG_SYN_COOKIES is not set
365# CONFIG_INET_AH is not set
366# CONFIG_INET_ESP is not set
367# CONFIG_INET_IPCOMP is not set
368# CONFIG_INET_XFRM_TUNNEL is not set
369# CONFIG_INET_TUNNEL is not set
370CONFIG_INET_XFRM_MODE_TRANSPORT=y
371CONFIG_INET_XFRM_MODE_TUNNEL=y
372CONFIG_INET_XFRM_MODE_BEET=y
373# CONFIG_INET_LRO is not set
374CONFIG_INET_DIAG=y
375CONFIG_INET_TCP_DIAG=y
376# CONFIG_TCP_CONG_ADVANCED is not set
377CONFIG_TCP_CONG_CUBIC=y
378CONFIG_DEFAULT_TCP_CONG="cubic"
379# CONFIG_TCP_MD5SIG is not set
380# CONFIG_IPV6 is not set
381# CONFIG_NETWORK_SECMARK is not set
382# CONFIG_NETFILTER is not set
383# CONFIG_IP_DCCP is not set
384# CONFIG_IP_SCTP is not set
385# CONFIG_TIPC is not set
386# CONFIG_ATM is not set
387# CONFIG_BRIDGE is not set
388# CONFIG_NET_DSA is not set
389# CONFIG_VLAN_8021Q is not set
390# CONFIG_DECNET is not set
391# CONFIG_LLC2 is not set
392# CONFIG_IPX is not set
393# CONFIG_ATALK is not set
394# CONFIG_X25 is not set
395# CONFIG_LAPB is not set
396# CONFIG_ECONET is not set
397# CONFIG_WAN_ROUTER is not set
398# CONFIG_NET_SCHED is not set
399# CONFIG_DCB is not set
400
401#
402# Network testing
403#
404# CONFIG_NET_PKTGEN is not set
405# CONFIG_HAMRADIO is not set
406# CONFIG_CAN is not set
407# CONFIG_IRDA is not set
408# CONFIG_BT is not set
409# CONFIG_AF_RXRPC is not set
410# CONFIG_PHONET is not set
411CONFIG_WIRELESS=y
412# CONFIG_CFG80211 is not set
413# CONFIG_WIRELESS_OLD_REGULATORY is not set
414CONFIG_WIRELESS_EXT=y
415CONFIG_WIRELESS_EXT_SYSFS=y
416# CONFIG_LIB80211 is not set
417# CONFIG_MAC80211 is not set
418# CONFIG_WIMAX is not set
419# CONFIG_RFKILL is not set
420# CONFIG_NET_9P is not set
421
422#
423# Device Drivers
424#
425
426#
427# Generic Driver Options
428#
429CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
430CONFIG_STANDALONE=y
431CONFIG_PREVENT_FIRMWARE_BUILD=y
432# CONFIG_FW_LOADER is not set
433# CONFIG_DEBUG_DRIVER is not set
434# CONFIG_DEBUG_DEVRES is not set
435# CONFIG_SYS_HYPERVISOR is not set
436# CONFIG_CONNECTOR is not set
437CONFIG_MTD=y
438# CONFIG_MTD_DEBUG is not set
439CONFIG_MTD_CONCAT=y
440CONFIG_MTD_PARTITIONS=y
441# CONFIG_MTD_TESTS is not set
442# CONFIG_MTD_REDBOOT_PARTS is not set
443# CONFIG_MTD_CMDLINE_PARTS is not set
444# CONFIG_MTD_AR7_PARTS is not set
445
446#
447# User Modules And Translation Layers
448#
449CONFIG_MTD_CHAR=y
450CONFIG_MTD_BLKDEVS=y
451CONFIG_MTD_BLOCK=y
452# CONFIG_FTL is not set
453# CONFIG_NFTL is not set
454# CONFIG_INFTL is not set
455# CONFIG_RFD_FTL is not set
456# CONFIG_SSFDC is not set
457# CONFIG_MTD_OOPS is not set
458
459#
460# RAM/ROM/Flash chip drivers
461#
462CONFIG_MTD_CFI=y
463# CONFIG_MTD_JEDECPROBE is not set
464CONFIG_MTD_GEN_PROBE=y
465# CONFIG_MTD_CFI_ADV_OPTIONS is not set
466CONFIG_MTD_MAP_BANK_WIDTH_1=y
467CONFIG_MTD_MAP_BANK_WIDTH_2=y
468CONFIG_MTD_MAP_BANK_WIDTH_4=y
469# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
470# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
471# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
472CONFIG_MTD_CFI_I1=y
473CONFIG_MTD_CFI_I2=y
474# CONFIG_MTD_CFI_I4 is not set
475# CONFIG_MTD_CFI_I8 is not set
476# CONFIG_MTD_CFI_INTELEXT is not set
477CONFIG_MTD_CFI_AMDSTD=y
478# CONFIG_MTD_CFI_STAA is not set
479CONFIG_MTD_CFI_UTIL=y
480# CONFIG_MTD_RAM is not set
481# CONFIG_MTD_ROM is not set
482# CONFIG_MTD_ABSENT is not set
483
484#
485# Mapping drivers for chip access
486#
487# CONFIG_MTD_COMPLEX_MAPPINGS is not set
488CONFIG_MTD_PHYSMAP=y
489# CONFIG_MTD_PHYSMAP_COMPAT is not set
490# CONFIG_MTD_INTEL_VR_NOR is not set
491# CONFIG_MTD_PLATRAM is not set
492
493#
494# Self-contained MTD device drivers
495#
496# CONFIG_MTD_PMC551 is not set
497# CONFIG_MTD_SLRAM is not set
498# CONFIG_MTD_PHRAM is not set
499# CONFIG_MTD_MTDRAM is not set
500# CONFIG_MTD_BLOCK2MTD is not set
501
502#
503# Disk-On-Chip Device Drivers
504#
505# CONFIG_MTD_DOC2000 is not set
506# CONFIG_MTD_DOC2001 is not set
507# CONFIG_MTD_DOC2001PLUS is not set
508# CONFIG_MTD_NAND is not set
509# CONFIG_MTD_ONENAND is not set
510
511#
512# LPDDR flash memory drivers
513#
514# CONFIG_MTD_LPDDR is not set
515# CONFIG_MTD_QINFO_PROBE is not set
516
517#
518# UBI - Unsorted block images
519#
520# CONFIG_MTD_UBI is not set
521# CONFIG_PARPORT is not set
522CONFIG_BLK_DEV=y
523# CONFIG_BLK_CPQ_CISS_DA is not set
524# CONFIG_BLK_DEV_DAC960 is not set
525# CONFIG_BLK_DEV_UMEM is not set
526# CONFIG_BLK_DEV_COW_COMMON is not set
527# CONFIG_BLK_DEV_LOOP is not set
528# CONFIG_BLK_DEV_NBD is not set
529# CONFIG_BLK_DEV_SX8 is not set
530# CONFIG_BLK_DEV_UB is not set
531CONFIG_BLK_DEV_RAM=y
532CONFIG_BLK_DEV_RAM_COUNT=16
533CONFIG_BLK_DEV_RAM_SIZE=4096
534# CONFIG_BLK_DEV_XIP is not set
535# CONFIG_CDROM_PKTCDVD is not set
536# CONFIG_ATA_OVER_ETH is not set
537# CONFIG_BLK_DEV_HD is not set
538# CONFIG_MISC_DEVICES is not set
539CONFIG_HAVE_IDE=y
540# CONFIG_IDE is not set
541
542#
543# SCSI device support
544#
545# CONFIG_RAID_ATTRS is not set
546CONFIG_SCSI=y
547CONFIG_SCSI_DMA=y
548# CONFIG_SCSI_TGT is not set
549# CONFIG_SCSI_NETLINK is not set
550CONFIG_SCSI_PROC_FS=y
551
552#
553# SCSI support type (disk, tape, CD-ROM)
554#
555CONFIG_BLK_DEV_SD=y
556# CONFIG_CHR_DEV_ST is not set
557# CONFIG_CHR_DEV_OSST is not set
558# CONFIG_BLK_DEV_SR is not set
559# CONFIG_CHR_DEV_SG is not set
560# CONFIG_CHR_DEV_SCH is not set
561
562#
563# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
564#
565# CONFIG_SCSI_MULTI_LUN is not set
566# CONFIG_SCSI_CONSTANTS is not set
567# CONFIG_SCSI_LOGGING is not set
568# CONFIG_SCSI_SCAN_ASYNC is not set
569CONFIG_SCSI_WAIT_SCAN=m
570
571#
572# SCSI Transports
573#
574# CONFIG_SCSI_SPI_ATTRS is not set
575# CONFIG_SCSI_FC_ATTRS is not set
576# CONFIG_SCSI_ISCSI_ATTRS is not set
577# CONFIG_SCSI_SAS_LIBSAS is not set
578# CONFIG_SCSI_SRP_ATTRS is not set
579# CONFIG_SCSI_LOWLEVEL is not set
580# CONFIG_SCSI_DH is not set
581CONFIG_ATA=y
582# CONFIG_ATA_NONSTANDARD is not set
583CONFIG_SATA_PMP=y
584# CONFIG_SATA_AHCI is not set
585# CONFIG_SATA_SIL24 is not set
586CONFIG_ATA_SFF=y
587# CONFIG_SATA_SVW is not set
588# CONFIG_ATA_PIIX is not set
589# CONFIG_SATA_MV is not set
590# CONFIG_SATA_NV is not set
591# CONFIG_PDC_ADMA is not set
592# CONFIG_SATA_QSTOR is not set
593# CONFIG_SATA_PROMISE is not set
594# CONFIG_SATA_SX4 is not set
595CONFIG_SATA_SIL=y
596# CONFIG_SATA_SIS is not set
597# CONFIG_SATA_ULI is not set
598# CONFIG_SATA_VIA is not set
599# CONFIG_SATA_VITESSE is not set
600# CONFIG_SATA_INIC162X is not set
601# CONFIG_PATA_ALI is not set
602# CONFIG_PATA_AMD is not set
603# CONFIG_PATA_ARTOP is not set
604# CONFIG_PATA_ATIIXP is not set
605# CONFIG_PATA_CMD640_PCI is not set
606# CONFIG_PATA_CMD64X is not set
607# CONFIG_PATA_CS5520 is not set
608# CONFIG_PATA_CS5530 is not set
609# CONFIG_PATA_CYPRESS is not set
610# CONFIG_PATA_EFAR is not set
611# CONFIG_ATA_GENERIC is not set
612# CONFIG_PATA_HPT366 is not set
613# CONFIG_PATA_HPT37X is not set
614# CONFIG_PATA_HPT3X2N is not set
615# CONFIG_PATA_HPT3X3 is not set
616# CONFIG_PATA_IT821X is not set
617# CONFIG_PATA_IT8213 is not set
618# CONFIG_PATA_JMICRON is not set
619# CONFIG_PATA_TRIFLEX is not set
620# CONFIG_PATA_MARVELL is not set
621# CONFIG_PATA_MPIIX is not set
622# CONFIG_PATA_OLDPIIX is not set
623# CONFIG_PATA_NETCELL is not set
624# CONFIG_PATA_NINJA32 is not set
625# CONFIG_PATA_NS87410 is not set
626# CONFIG_PATA_NS87415 is not set
627# CONFIG_PATA_OPTI is not set
628# CONFIG_PATA_OPTIDMA is not set
629# CONFIG_PATA_PDC_OLD is not set
630# CONFIG_PATA_RADISYS is not set
631# CONFIG_PATA_RZ1000 is not set
632# CONFIG_PATA_SC1200 is not set
633# CONFIG_PATA_SERVERWORKS is not set
634# CONFIG_PATA_PDC2027X is not set
635# CONFIG_PATA_SIL680 is not set
636# CONFIG_PATA_SIS is not set
637# CONFIG_PATA_VIA is not set
638# CONFIG_PATA_WINBOND is not set
639# CONFIG_PATA_PLATFORM is not set
640# CONFIG_PATA_SCH is not set
641# CONFIG_MD is not set
642# CONFIG_FUSION is not set
643
644#
645# IEEE 1394 (FireWire) support
646#
647
648#
649# Enable only one of the two stacks, unless you know what you are doing
650#
651# CONFIG_FIREWIRE is not set
652# CONFIG_IEEE1394 is not set
653# CONFIG_I2O is not set
654CONFIG_NETDEVICES=y
655# CONFIG_DUMMY is not set
656# CONFIG_BONDING is not set
657# CONFIG_MACVLAN is not set
658# CONFIG_EQUALIZER is not set
659# CONFIG_TUN is not set
660# CONFIG_VETH is not set
661# CONFIG_ARCNET is not set
662# CONFIG_NET_ETHERNET is not set
663CONFIG_MII=y
664CONFIG_NETDEV_1000=y
665# CONFIG_ACENIC is not set
666# CONFIG_DL2K is not set
667# CONFIG_E1000 is not set
668# CONFIG_E1000E is not set
669# CONFIG_IP1000 is not set
670# CONFIG_IGB is not set
671# CONFIG_NS83820 is not set
672# CONFIG_HAMACHI is not set
673# CONFIG_YELLOWFIN is not set
674CONFIG_R8169=y
675# CONFIG_SIS190 is not set
676# CONFIG_SKGE is not set
677# CONFIG_SKY2 is not set
678# CONFIG_VIA_VELOCITY is not set
679# CONFIG_TIGON3 is not set
680# CONFIG_BNX2 is not set
681# CONFIG_QLA3XXX is not set
682# CONFIG_ATL1 is not set
683# CONFIG_ATL1E is not set
684# CONFIG_JME is not set
685# CONFIG_NETDEV_10000 is not set
686# CONFIG_TR is not set
687
688#
689# Wireless LAN
690#
691# CONFIG_WLAN_PRE80211 is not set
692# CONFIG_WLAN_80211 is not set
693# CONFIG_IWLWIFI_LEDS is not set
694
695#
696# Enable WiMAX (Networking options) to see the WiMAX drivers
697#
698
699#
700# USB Network Adapters
701#
702# CONFIG_USB_CATC is not set
703# CONFIG_USB_KAWETH is not set
704# CONFIG_USB_PEGASUS is not set
705# CONFIG_USB_RTL8150 is not set
706# CONFIG_USB_USBNET is not set
707# CONFIG_WAN is not set
708# CONFIG_FDDI is not set
709# CONFIG_HIPPI is not set
710# CONFIG_PPP is not set
711# CONFIG_SLIP is not set
712# CONFIG_NET_FC is not set
713# CONFIG_NETCONSOLE is not set
714# CONFIG_NETPOLL is not set
715# CONFIG_NET_POLL_CONTROLLER is not set
716# CONFIG_ISDN is not set
717# CONFIG_PHONE is not set
718
719#
720# Input device support
721#
722CONFIG_INPUT=y
723CONFIG_INPUT_FF_MEMLESS=m
724# CONFIG_INPUT_POLLDEV is not set
725
726#
727# Userland interfaces
728#
729CONFIG_INPUT_MOUSEDEV=y
730# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
731CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
732CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
733# CONFIG_INPUT_JOYDEV is not set
734# CONFIG_INPUT_EVDEV is not set
735# CONFIG_INPUT_EVBUG is not set
736
737#
738# Input Device Drivers
739#
740CONFIG_INPUT_KEYBOARD=y
741# CONFIG_KEYBOARD_ATKBD is not set
742# CONFIG_KEYBOARD_SUNKBD is not set
743# CONFIG_KEYBOARD_LKKBD is not set
744# CONFIG_KEYBOARD_XTKBD is not set
745# CONFIG_KEYBOARD_NEWTON is not set
746# CONFIG_KEYBOARD_STOWAWAY is not set
747# CONFIG_KEYBOARD_SH_KEYSC is not set
748# CONFIG_INPUT_MOUSE is not set
749# CONFIG_INPUT_JOYSTICK is not set
750# CONFIG_INPUT_TABLET is not set
751# CONFIG_INPUT_TOUCHSCREEN is not set
752# CONFIG_INPUT_MISC is not set
753
754#
755# Hardware I/O ports
756#
757# CONFIG_SERIO is not set
758# CONFIG_GAMEPORT is not set
759
760#
761# Character devices
762#
763CONFIG_VT=y
764CONFIG_CONSOLE_TRANSLATIONS=y
765CONFIG_VT_CONSOLE=y
766CONFIG_HW_CONSOLE=y
767CONFIG_VT_HW_CONSOLE_BINDING=y
768CONFIG_DEVKMEM=y
769# CONFIG_SERIAL_NONSTANDARD is not set
770# CONFIG_NOZOMI is not set
771
772#
773# Serial drivers
774#
775# CONFIG_SERIAL_8250 is not set
776
777#
778# Non-8250 serial port support
779#
780CONFIG_SERIAL_SH_SCI=y
781CONFIG_SERIAL_SH_SCI_NR_UARTS=6
782CONFIG_SERIAL_SH_SCI_CONSOLE=y
783CONFIG_SERIAL_CORE=y
784CONFIG_SERIAL_CORE_CONSOLE=y
785# CONFIG_SERIAL_JSM is not set
786CONFIG_UNIX98_PTYS=y
787# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
788CONFIG_LEGACY_PTYS=y
789CONFIG_LEGACY_PTY_COUNT=256
790# CONFIG_IPMI_HANDLER is not set
791CONFIG_HW_RANDOM=y
792# CONFIG_R3964 is not set
793# CONFIG_APPLICOM is not set
794# CONFIG_RAW_DRIVER is not set
795# CONFIG_TCG_TPM is not set
796CONFIG_DEVPORT=y
797CONFIG_I2C=y
798CONFIG_I2C_BOARDINFO=y
799# CONFIG_I2C_CHARDEV is not set
800CONFIG_I2C_HELPER_AUTO=y
801CONFIG_I2C_ALGOPCA=y
802
803#
804# I2C Hardware Bus support
805#
806
807#
808# PC SMBus host controller drivers
809#
810# CONFIG_I2C_ALI1535 is not set
811# CONFIG_I2C_ALI1563 is not set
812# CONFIG_I2C_ALI15X3 is not set
813# CONFIG_I2C_AMD756 is not set
814# CONFIG_I2C_AMD8111 is not set
815# CONFIG_I2C_I801 is not set
816# CONFIG_I2C_ISCH is not set
817# CONFIG_I2C_PIIX4 is not set
818# CONFIG_I2C_NFORCE2 is not set
819# CONFIG_I2C_SIS5595 is not set
820# CONFIG_I2C_SIS630 is not set
821# CONFIG_I2C_SIS96X is not set
822# CONFIG_I2C_VIA is not set
823# CONFIG_I2C_VIAPRO is not set
824
825#
826# I2C system bus drivers (mostly embedded / system-on-chip)
827#
828# CONFIG_I2C_OCORES is not set
829# CONFIG_I2C_SH_MOBILE is not set
830# CONFIG_I2C_SIMTEC is not set
831
832#
833# External I2C/SMBus adapter drivers
834#
835# CONFIG_I2C_PARPORT_LIGHT is not set
836# CONFIG_I2C_TAOS_EVM is not set
837# CONFIG_I2C_TINY_USB is not set
838
839#
840# Graphics adapter I2C/DDC channel drivers
841#
842# CONFIG_I2C_VOODOO3 is not set
843
844#
845# Other I2C/SMBus bus drivers
846#
847CONFIG_I2C_PCA_PLATFORM=y
848# CONFIG_I2C_STUB is not set
849
850#
851# Miscellaneous I2C Chip support
852#
853# CONFIG_DS1682 is not set
854# CONFIG_SENSORS_PCF8574 is not set
855# CONFIG_PCF8575 is not set
856# CONFIG_SENSORS_PCA9539 is not set
857# CONFIG_SENSORS_PCF8591 is not set
858# CONFIG_SENSORS_MAX6875 is not set
859# CONFIG_SENSORS_TSL2550 is not set
860# CONFIG_I2C_DEBUG_CORE is not set
861# CONFIG_I2C_DEBUG_ALGO is not set
862# CONFIG_I2C_DEBUG_BUS is not set
863# CONFIG_I2C_DEBUG_CHIP is not set
864# CONFIG_SPI is not set
865# CONFIG_W1 is not set
866# CONFIG_POWER_SUPPLY is not set
867# CONFIG_HWMON is not set
868# CONFIG_THERMAL is not set
869# CONFIG_THERMAL_HWMON is not set
870# CONFIG_WATCHDOG is not set
871CONFIG_SSB_POSSIBLE=y
872
873#
874# Sonics Silicon Backplane
875#
876# CONFIG_SSB is not set
877
878#
879# Multifunction device drivers
880#
881# CONFIG_MFD_CORE is not set
882CONFIG_MFD_SM501=y
883# CONFIG_HTC_PASIC3 is not set
884# CONFIG_TWL4030_CORE is not set
885# CONFIG_MFD_TMIO is not set
886# CONFIG_PMIC_DA903X is not set
887# CONFIG_MFD_WM8400 is not set
888# CONFIG_MFD_WM8350_I2C is not set
889# CONFIG_MFD_PCF50633 is not set
890# CONFIG_REGULATOR is not set
891
892#
893# Multimedia devices
894#
895
896#
897# Multimedia core support
898#
899# CONFIG_VIDEO_DEV is not set
900# CONFIG_DVB_CORE is not set
901# CONFIG_VIDEO_MEDIA is not set
902
903#
904# Multimedia drivers
905#
906# CONFIG_DAB is not set
907
908#
909# Graphics support
910#
911# CONFIG_DRM is not set
912# CONFIG_VGASTATE is not set
913# CONFIG_VIDEO_OUTPUT_CONTROL is not set
914CONFIG_FB=y
915# CONFIG_FIRMWARE_EDID is not set
916# CONFIG_FB_DDC is not set
917# CONFIG_FB_BOOT_VESA_SUPPORT is not set
918CONFIG_FB_CFB_FILLRECT=y
919CONFIG_FB_CFB_COPYAREA=y
920CONFIG_FB_CFB_IMAGEBLIT=y
921# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
922CONFIG_FB_SYS_FILLRECT=m
923CONFIG_FB_SYS_COPYAREA=m
924CONFIG_FB_SYS_IMAGEBLIT=m
925# CONFIG_FB_FOREIGN_ENDIAN is not set
926CONFIG_FB_SYS_FOPS=m
927CONFIG_FB_DEFERRED_IO=y
928# CONFIG_FB_SVGALIB is not set
929# CONFIG_FB_MACMODES is not set
930# CONFIG_FB_BACKLIGHT is not set
931# CONFIG_FB_MODE_HELPERS is not set
932# CONFIG_FB_TILEBLITTING is not set
933
934#
935# Frame buffer hardware drivers
936#
937# CONFIG_FB_CIRRUS is not set
938# CONFIG_FB_PM2 is not set
939# CONFIG_FB_CYBER2000 is not set
940# CONFIG_FB_ASILIANT is not set
941# CONFIG_FB_IMSTT is not set
942# CONFIG_FB_S1D13XXX is not set
943# CONFIG_FB_NVIDIA is not set
944# CONFIG_FB_RIVA is not set
945# CONFIG_FB_MATROX is not set
946# CONFIG_FB_RADEON is not set
947# CONFIG_FB_ATY128 is not set
948# CONFIG_FB_ATY is not set
949# CONFIG_FB_S3 is not set
950# CONFIG_FB_SAVAGE is not set
951# CONFIG_FB_SIS is not set
952# CONFIG_FB_VIA is not set
953# CONFIG_FB_NEOMAGIC is not set
954# CONFIG_FB_KYRO is not set
955# CONFIG_FB_3DFX is not set
956# CONFIG_FB_VOODOO1 is not set
957# CONFIG_FB_VT8623 is not set
958# CONFIG_FB_TRIDENT is not set
959# CONFIG_FB_ARK is not set
960# CONFIG_FB_PM3 is not set
961# CONFIG_FB_CARMINE is not set
962CONFIG_FB_SH_MOBILE_LCDC=m
963CONFIG_FB_SM501=y
964# CONFIG_FB_VIRTUAL is not set
965# CONFIG_FB_METRONOME is not set
966# CONFIG_FB_MB862XX is not set
967# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
968
969#
970# Display device support
971#
972# CONFIG_DISPLAY_SUPPORT is not set
973
974#
975# Console display driver support
976#
977CONFIG_DUMMY_CONSOLE=y
978CONFIG_FRAMEBUFFER_CONSOLE=y
979# CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY is not set
980# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
981# CONFIG_FONTS is not set
982CONFIG_FONT_8x8=y
983CONFIG_FONT_8x16=y
984CONFIG_LOGO=y
985# CONFIG_LOGO_LINUX_MONO is not set
986# CONFIG_LOGO_LINUX_VGA16 is not set
987CONFIG_LOGO_LINUX_CLUT224=y
988# CONFIG_LOGO_SUPERH_MONO is not set
989# CONFIG_LOGO_SUPERH_VGA16 is not set
990# CONFIG_LOGO_SUPERH_CLUT224 is not set
991# CONFIG_SOUND is not set
992CONFIG_HID_SUPPORT=y
993CONFIG_HID=y
994# CONFIG_HID_DEBUG is not set
995# CONFIG_HIDRAW is not set
996
997#
998# USB Input Devices
999#
1000CONFIG_USB_HID=y
1001# CONFIG_HID_PID is not set
1002# CONFIG_USB_HIDDEV is not set
1003
1004#
1005# Special HID drivers
1006#
1007CONFIG_HID_COMPAT=y
1008CONFIG_HID_A4TECH=y
1009CONFIG_HID_APPLE=y
1010CONFIG_HID_BELKIN=y
1011CONFIG_HID_CHERRY=y
1012CONFIG_HID_CHICONY=y
1013CONFIG_HID_CYPRESS=y
1014CONFIG_HID_EZKEY=y
1015CONFIG_HID_GYRATION=y
1016CONFIG_HID_LOGITECH=y
1017# CONFIG_LOGITECH_FF is not set
1018# CONFIG_LOGIRUMBLEPAD2_FF is not set
1019CONFIG_HID_MICROSOFT=y
1020CONFIG_HID_MONTEREY=y
1021# CONFIG_HID_NTRIG is not set
1022CONFIG_HID_PANTHERLORD=y
1023# CONFIG_PANTHERLORD_FF is not set
1024CONFIG_HID_PETALYNX=y
1025CONFIG_HID_SAMSUNG=y
1026CONFIG_HID_SONY=y
1027CONFIG_HID_SUNPLUS=y
1028# CONFIG_GREENASIA_FF is not set
1029# CONFIG_HID_TOPSEED is not set
1030CONFIG_THRUSTMASTER_FF=m
1031CONFIG_ZEROPLUS_FF=m
1032CONFIG_USB_SUPPORT=y
1033CONFIG_USB_ARCH_HAS_HCD=y
1034CONFIG_USB_ARCH_HAS_OHCI=y
1035CONFIG_USB_ARCH_HAS_EHCI=y
1036CONFIG_USB=y
1037# CONFIG_USB_DEBUG is not set
1038# CONFIG_USB_ANNOUNCE_NEW_DEVICES is not set
1039
1040#
1041# Miscellaneous USB options
1042#
1043CONFIG_USB_DEVICEFS=y
1044CONFIG_USB_DEVICE_CLASS=y
1045# CONFIG_USB_DYNAMIC_MINORS is not set
1046# CONFIG_USB_OTG is not set
1047# CONFIG_USB_OTG_WHITELIST is not set
1048# CONFIG_USB_OTG_BLACKLIST_HUB is not set
1049CONFIG_USB_MON=y
1050# CONFIG_USB_WUSB is not set
1051# CONFIG_USB_WUSB_CBAF is not set
1052
1053#
1054# USB Host Controller Drivers
1055#
1056# CONFIG_USB_C67X00_HCD is not set
1057CONFIG_USB_EHCI_HCD=m
1058# CONFIG_USB_EHCI_ROOT_HUB_TT is not set
1059# CONFIG_USB_EHCI_TT_NEWSCHED is not set
1060# CONFIG_USB_OXU210HP_HCD is not set
1061# CONFIG_USB_ISP116X_HCD is not set
1062# CONFIG_USB_ISP1760_HCD is not set
1063CONFIG_USB_OHCI_HCD=m
1064# CONFIG_USB_OHCI_BIG_ENDIAN_DESC is not set
1065# CONFIG_USB_OHCI_BIG_ENDIAN_MMIO is not set
1066CONFIG_USB_OHCI_LITTLE_ENDIAN=y
1067# CONFIG_USB_UHCI_HCD is not set
1068# CONFIG_USB_SL811_HCD is not set
1069CONFIG_USB_R8A66597_HCD=y
1070# CONFIG_USB_WHCI_HCD is not set
1071# CONFIG_USB_HWA_HCD is not set
1072
1073#
1074# USB Device Class drivers
1075#
1076# CONFIG_USB_ACM is not set
1077# CONFIG_USB_PRINTER is not set
1078# CONFIG_USB_WDM is not set
1079# CONFIG_USB_TMC is not set
1080
1081#
1082# NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may also be needed;
1083#
1084
1085#
1086# see USB_STORAGE Help for more information
1087#
1088CONFIG_USB_STORAGE=y
1089# CONFIG_USB_STORAGE_DEBUG is not set
1090# CONFIG_USB_STORAGE_DATAFAB is not set
1091# CONFIG_USB_STORAGE_FREECOM is not set
1092# CONFIG_USB_STORAGE_ISD200 is not set
1093# CONFIG_USB_STORAGE_USBAT is not set
1094# CONFIG_USB_STORAGE_SDDR09 is not set
1095# CONFIG_USB_STORAGE_SDDR55 is not set
1096# CONFIG_USB_STORAGE_JUMPSHOT is not set
1097# CONFIG_USB_STORAGE_ALAUDA is not set
1098# CONFIG_USB_STORAGE_ONETOUCH is not set
1099# CONFIG_USB_STORAGE_KARMA is not set
1100# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
1101# CONFIG_USB_LIBUSUAL is not set
1102
1103#
1104# USB Imaging devices
1105#
1106# CONFIG_USB_MDC800 is not set
1107# CONFIG_USB_MICROTEK is not set
1108
1109#
1110# USB port drivers
1111#
1112# CONFIG_USB_SERIAL is not set
1113
1114#
1115# USB Miscellaneous drivers
1116#
1117# CONFIG_USB_EMI62 is not set
1118# CONFIG_USB_EMI26 is not set
1119# CONFIG_USB_ADUTUX is not set
1120# CONFIG_USB_SEVSEG is not set
1121# CONFIG_USB_RIO500 is not set
1122# CONFIG_USB_LEGOTOWER is not set
1123# CONFIG_USB_LCD is not set
1124# CONFIG_USB_BERRY_CHARGE is not set
1125# CONFIG_USB_LED is not set
1126# CONFIG_USB_CYPRESS_CY7C63 is not set
1127# CONFIG_USB_CYTHERM is not set
1128# CONFIG_USB_PHIDGET is not set
1129# CONFIG_USB_IDMOUSE is not set
1130# CONFIG_USB_FTDI_ELAN is not set
1131# CONFIG_USB_APPLEDISPLAY is not set
1132# CONFIG_USB_SISUSBVGA is not set
1133# CONFIG_USB_LD is not set
1134# CONFIG_USB_TRANCEVIBRATOR is not set
1135# CONFIG_USB_IOWARRIOR is not set
1136CONFIG_USB_TEST=m
1137# CONFIG_USB_ISIGHTFW is not set
1138# CONFIG_USB_VST is not set
1139# CONFIG_USB_GADGET is not set
1140
1141#
1142# OTG and related infrastructure
1143#
1144# CONFIG_UWB is not set
1145# CONFIG_MMC is not set
1146# CONFIG_MEMSTICK is not set
1147# CONFIG_NEW_LEDS is not set
1148# CONFIG_ACCESSIBILITY is not set
1149# CONFIG_INFINIBAND is not set
1150CONFIG_RTC_LIB=y
1151CONFIG_RTC_CLASS=y
1152CONFIG_RTC_HCTOSYS=y
1153CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
1154# CONFIG_RTC_DEBUG is not set
1155
1156#
1157# RTC interfaces
1158#
1159CONFIG_RTC_INTF_SYSFS=y
1160CONFIG_RTC_INTF_PROC=y
1161CONFIG_RTC_INTF_DEV=y
1162# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
1163# CONFIG_RTC_DRV_TEST is not set
1164
1165#
1166# I2C RTC drivers
1167#
1168# CONFIG_RTC_DRV_DS1307 is not set
1169# CONFIG_RTC_DRV_DS1374 is not set
1170# CONFIG_RTC_DRV_DS1672 is not set
1171# CONFIG_RTC_DRV_MAX6900 is not set
1172CONFIG_RTC_DRV_RS5C372=y
1173# CONFIG_RTC_DRV_ISL1208 is not set
1174# CONFIG_RTC_DRV_X1205 is not set
1175# CONFIG_RTC_DRV_PCF8563 is not set
1176# CONFIG_RTC_DRV_PCF8583 is not set
1177# CONFIG_RTC_DRV_M41T80 is not set
1178# CONFIG_RTC_DRV_S35390A is not set
1179# CONFIG_RTC_DRV_FM3130 is not set
1180# CONFIG_RTC_DRV_RX8581 is not set
1181
1182#
1183# SPI RTC drivers
1184#
1185
1186#
1187# Platform RTC drivers
1188#
1189# CONFIG_RTC_DRV_DS1286 is not set
1190# CONFIG_RTC_DRV_DS1511 is not set
1191# CONFIG_RTC_DRV_DS1553 is not set
1192# CONFIG_RTC_DRV_DS1742 is not set
1193# CONFIG_RTC_DRV_STK17TA8 is not set
1194# CONFIG_RTC_DRV_M48T86 is not set
1195# CONFIG_RTC_DRV_M48T35 is not set
1196# CONFIG_RTC_DRV_M48T59 is not set
1197# CONFIG_RTC_DRV_BQ4802 is not set
1198# CONFIG_RTC_DRV_V3020 is not set
1199
1200#
1201# on-CPU RTC drivers
1202#
1203# CONFIG_RTC_DRV_SH is not set
1204# CONFIG_DMADEVICES is not set
1205# CONFIG_UIO is not set
1206# CONFIG_STAGING is not set
1207
1208#
1209# File systems
1210#
1211CONFIG_EXT2_FS=y
1212# CONFIG_EXT2_FS_XATTR is not set
1213# CONFIG_EXT2_FS_XIP is not set
1214CONFIG_EXT3_FS=y
1215CONFIG_EXT3_FS_XATTR=y
1216# CONFIG_EXT3_FS_POSIX_ACL is not set
1217# CONFIG_EXT3_FS_SECURITY is not set
1218# CONFIG_EXT4_FS is not set
1219CONFIG_JBD=y
1220CONFIG_FS_MBCACHE=y
1221# CONFIG_REISERFS_FS is not set
1222# CONFIG_JFS_FS is not set
1223CONFIG_FS_POSIX_ACL=y
1224CONFIG_FILE_LOCKING=y
1225# CONFIG_XFS_FS is not set
1226# CONFIG_OCFS2_FS is not set
1227# CONFIG_BTRFS_FS is not set
1228CONFIG_DNOTIFY=y
1229CONFIG_INOTIFY=y
1230CONFIG_INOTIFY_USER=y
1231# CONFIG_QUOTA is not set
1232# CONFIG_AUTOFS_FS is not set
1233# CONFIG_AUTOFS4_FS is not set
1234# CONFIG_FUSE_FS is not set
1235
1236#
1237# CD-ROM/DVD Filesystems
1238#
1239# CONFIG_ISO9660_FS is not set
1240# CONFIG_UDF_FS is not set
1241
1242#
1243# DOS/FAT/NT Filesystems
1244#
1245CONFIG_FAT_FS=y
1246CONFIG_MSDOS_FS=y
1247CONFIG_VFAT_FS=y
1248CONFIG_FAT_DEFAULT_CODEPAGE=437
1249CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
1250CONFIG_NTFS_FS=y
1251# CONFIG_NTFS_DEBUG is not set
1252CONFIG_NTFS_RW=y
1253
1254#
1255# Pseudo filesystems
1256#
1257CONFIG_PROC_FS=y
1258CONFIG_PROC_KCORE=y
1259CONFIG_PROC_SYSCTL=y
1260CONFIG_PROC_PAGE_MONITOR=y
1261CONFIG_SYSFS=y
1262CONFIG_TMPFS=y
1263# CONFIG_TMPFS_POSIX_ACL is not set
1264# CONFIG_HUGETLBFS is not set
1265# CONFIG_HUGETLB_PAGE is not set
1266# CONFIG_CONFIGFS_FS is not set
1267CONFIG_MISC_FILESYSTEMS=y
1268# CONFIG_ADFS_FS is not set
1269# CONFIG_AFFS_FS is not set
1270# CONFIG_HFS_FS is not set
1271# CONFIG_HFSPLUS_FS is not set
1272# CONFIG_BEFS_FS is not set
1273# CONFIG_BFS_FS is not set
1274# CONFIG_EFS_FS is not set
1275# CONFIG_JFFS2_FS is not set
1276# CONFIG_CRAMFS is not set
1277# CONFIG_SQUASHFS is not set
1278# CONFIG_VXFS_FS is not set
1279CONFIG_MINIX_FS=y
1280# CONFIG_OMFS_FS is not set
1281# CONFIG_HPFS_FS is not set
1282# CONFIG_QNX4FS_FS is not set
1283# CONFIG_ROMFS_FS is not set
1284# CONFIG_SYSV_FS is not set
1285# CONFIG_UFS_FS is not set
1286CONFIG_NETWORK_FILESYSTEMS=y
1287CONFIG_NFS_FS=y
1288CONFIG_NFS_V3=y
1289# CONFIG_NFS_V3_ACL is not set
1290CONFIG_NFS_V4=y
1291CONFIG_ROOT_NFS=y
1292CONFIG_NFSD=y
1293CONFIG_NFSD_V3=y
1294# CONFIG_NFSD_V3_ACL is not set
1295CONFIG_NFSD_V4=y
1296CONFIG_LOCKD=y
1297CONFIG_LOCKD_V4=y
1298CONFIG_EXPORTFS=y
1299CONFIG_NFS_COMMON=y
1300CONFIG_SUNRPC=y
1301CONFIG_SUNRPC_GSS=y
1302# CONFIG_SUNRPC_REGISTER_V4 is not set
1303CONFIG_RPCSEC_GSS_KRB5=y
1304# CONFIG_RPCSEC_GSS_SPKM3 is not set
1305# CONFIG_SMB_FS is not set
1306# CONFIG_CIFS is not set
1307# CONFIG_NCP_FS is not set
1308# CONFIG_CODA_FS is not set
1309# CONFIG_AFS_FS is not set
1310
1311#
1312# Partition Types
1313#
1314# CONFIG_PARTITION_ADVANCED is not set
1315CONFIG_MSDOS_PARTITION=y
1316CONFIG_NLS=y
1317CONFIG_NLS_DEFAULT="iso8859-1"
1318CONFIG_NLS_CODEPAGE_437=y
1319# CONFIG_NLS_CODEPAGE_737 is not set
1320# CONFIG_NLS_CODEPAGE_775 is not set
1321# CONFIG_NLS_CODEPAGE_850 is not set
1322# CONFIG_NLS_CODEPAGE_852 is not set
1323# CONFIG_NLS_CODEPAGE_855 is not set
1324# CONFIG_NLS_CODEPAGE_857 is not set
1325# CONFIG_NLS_CODEPAGE_860 is not set
1326# CONFIG_NLS_CODEPAGE_861 is not set
1327# CONFIG_NLS_CODEPAGE_862 is not set
1328# CONFIG_NLS_CODEPAGE_863 is not set
1329# CONFIG_NLS_CODEPAGE_864 is not set
1330# CONFIG_NLS_CODEPAGE_865 is not set
1331# CONFIG_NLS_CODEPAGE_866 is not set
1332# CONFIG_NLS_CODEPAGE_869 is not set
1333# CONFIG_NLS_CODEPAGE_936 is not set
1334# CONFIG_NLS_CODEPAGE_950 is not set
1335CONFIG_NLS_CODEPAGE_932=y
1336# CONFIG_NLS_CODEPAGE_949 is not set
1337# CONFIG_NLS_CODEPAGE_874 is not set
1338# CONFIG_NLS_ISO8859_8 is not set
1339# CONFIG_NLS_CODEPAGE_1250 is not set
1340# CONFIG_NLS_CODEPAGE_1251 is not set
1341# CONFIG_NLS_ASCII is not set
1342CONFIG_NLS_ISO8859_1=y
1343# CONFIG_NLS_ISO8859_2 is not set
1344# CONFIG_NLS_ISO8859_3 is not set
1345# CONFIG_NLS_ISO8859_4 is not set
1346# CONFIG_NLS_ISO8859_5 is not set
1347# CONFIG_NLS_ISO8859_6 is not set
1348# CONFIG_NLS_ISO8859_7 is not set
1349# CONFIG_NLS_ISO8859_9 is not set
1350# CONFIG_NLS_ISO8859_13 is not set
1351# CONFIG_NLS_ISO8859_14 is not set
1352# CONFIG_NLS_ISO8859_15 is not set
1353# CONFIG_NLS_KOI8_R is not set
1354# CONFIG_NLS_KOI8_U is not set
1355# CONFIG_NLS_UTF8 is not set
1356# CONFIG_DLM is not set
1357
1358#
1359# Kernel hacking
1360#
1361CONFIG_TRACE_IRQFLAGS_SUPPORT=y
1362# CONFIG_PRINTK_TIME is not set
1363# CONFIG_ENABLE_WARN_DEPRECATED is not set
1364# CONFIG_ENABLE_MUST_CHECK is not set
1365CONFIG_FRAME_WARN=1024
1366# CONFIG_MAGIC_SYSRQ is not set
1367# CONFIG_UNUSED_SYMBOLS is not set
1368# CONFIG_DEBUG_FS is not set
1369# CONFIG_HEADERS_CHECK is not set
1370CONFIG_DEBUG_KERNEL=y
1371# CONFIG_DEBUG_SHIRQ is not set
1372CONFIG_DETECT_SOFTLOCKUP=y
1373# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set
1374CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC_VALUE=0
1375CONFIG_SCHED_DEBUG=y
1376# CONFIG_SCHEDSTATS is not set
1377# CONFIG_TIMER_STATS is not set
1378# CONFIG_DEBUG_OBJECTS is not set
1379# CONFIG_DEBUG_SLAB is not set
1380CONFIG_DEBUG_PREEMPT=y
1381# CONFIG_DEBUG_RT_MUTEXES is not set
1382# CONFIG_RT_MUTEX_TESTER is not set
1383# CONFIG_DEBUG_SPINLOCK is not set
1384# CONFIG_DEBUG_MUTEXES is not set
1385# CONFIG_DEBUG_LOCK_ALLOC is not set
1386# CONFIG_PROVE_LOCKING is not set
1387# CONFIG_LOCK_STAT is not set
1388# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
1389# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
1390# CONFIG_DEBUG_KOBJECT is not set
1391# CONFIG_DEBUG_BUGVERBOSE is not set
1392# CONFIG_DEBUG_INFO is not set
1393# CONFIG_DEBUG_VM is not set
1394# CONFIG_DEBUG_WRITECOUNT is not set
1395# CONFIG_DEBUG_MEMORY_INIT is not set
1396# CONFIG_DEBUG_LIST is not set
1397# CONFIG_DEBUG_SG is not set
1398# CONFIG_DEBUG_NOTIFIERS is not set
1399# CONFIG_FRAME_POINTER is not set
1400# CONFIG_RCU_TORTURE_TEST is not set
1401# CONFIG_RCU_CPU_STALL_DETECTOR is not set
1402# CONFIG_BACKTRACE_SELF_TEST is not set
1403# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
1404# CONFIG_FAULT_INJECTION is not set
1405# CONFIG_LATENCYTOP is not set
1406CONFIG_SYSCTL_SYSCALL_CHECK=y
1407CONFIG_HAVE_FUNCTION_TRACER=y
1408CONFIG_HAVE_DYNAMIC_FTRACE=y
1409CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1410
1411#
1412# Tracers
1413#
1414# CONFIG_FUNCTION_TRACER is not set
1415# CONFIG_IRQSOFF_TRACER is not set
1416# CONFIG_PREEMPT_TRACER is not set
1417# CONFIG_SCHED_TRACER is not set
1418# CONFIG_CONTEXT_SWITCH_TRACER is not set
1419# CONFIG_BOOT_TRACER is not set
1420# CONFIG_TRACE_BRANCH_PROFILING is not set
1421# CONFIG_STACK_TRACER is not set
1422# CONFIG_DYNAMIC_PRINTK_DEBUG is not set
1423# CONFIG_SAMPLES is not set
1424CONFIG_HAVE_ARCH_KGDB=y
1425# CONFIG_KGDB is not set
1426# CONFIG_SH_STANDARD_BIOS is not set
1427# CONFIG_EARLY_SCIF_CONSOLE is not set
1428# CONFIG_DEBUG_BOOTMEM is not set
1429# CONFIG_DEBUG_STACKOVERFLOW is not set
1430# CONFIG_DEBUG_STACK_USAGE is not set
1431# CONFIG_4KSTACKS is not set
1432# CONFIG_IRQSTACKS is not set
1433# CONFIG_DUMP_CODE is not set
1434# CONFIG_SH_NO_BSS_INIT is not set
1435# CONFIG_MORE_COMPILE_OPTIONS is not set
1436
1437#
1438# Security options
1439#
1440# CONFIG_KEYS is not set
1441# CONFIG_SECURITY is not set
1442# CONFIG_SECURITYFS is not set
1443# CONFIG_SECURITY_FILE_CAPABILITIES is not set
1444CONFIG_CRYPTO=y
1445
1446#
1447# Crypto core or helper
1448#
1449# CONFIG_CRYPTO_FIPS is not set
1450CONFIG_CRYPTO_ALGAPI=y
1451CONFIG_CRYPTO_ALGAPI2=y
1452CONFIG_CRYPTO_AEAD2=y
1453CONFIG_CRYPTO_BLKCIPHER=y
1454CONFIG_CRYPTO_BLKCIPHER2=y
1455CONFIG_CRYPTO_HASH=y
1456CONFIG_CRYPTO_HASH2=y
1457CONFIG_CRYPTO_RNG2=y
1458CONFIG_CRYPTO_MANAGER=y
1459CONFIG_CRYPTO_MANAGER2=y
1460# CONFIG_CRYPTO_GF128MUL is not set
1461# CONFIG_CRYPTO_NULL is not set
1462# CONFIG_CRYPTO_CRYPTD is not set
1463# CONFIG_CRYPTO_AUTHENC is not set
1464# CONFIG_CRYPTO_TEST is not set
1465
1466#
1467# Authenticated Encryption with Associated Data
1468#
1469# CONFIG_CRYPTO_CCM is not set
1470# CONFIG_CRYPTO_GCM is not set
1471# CONFIG_CRYPTO_SEQIV is not set
1472
1473#
1474# Block modes
1475#
1476CONFIG_CRYPTO_CBC=y
1477# CONFIG_CRYPTO_CTR is not set
1478# CONFIG_CRYPTO_CTS is not set
1479# CONFIG_CRYPTO_ECB is not set
1480# CONFIG_CRYPTO_LRW is not set
1481# CONFIG_CRYPTO_PCBC is not set
1482# CONFIG_CRYPTO_XTS is not set
1483
1484#
1485# Hash modes
1486#
1487CONFIG_CRYPTO_HMAC=y
1488# CONFIG_CRYPTO_XCBC is not set
1489
1490#
1491# Digest
1492#
1493# CONFIG_CRYPTO_CRC32C is not set
1494# CONFIG_CRYPTO_MD4 is not set
1495CONFIG_CRYPTO_MD5=y
1496# CONFIG_CRYPTO_MICHAEL_MIC is not set
1497# CONFIG_CRYPTO_RMD128 is not set
1498# CONFIG_CRYPTO_RMD160 is not set
1499# CONFIG_CRYPTO_RMD256 is not set
1500# CONFIG_CRYPTO_RMD320 is not set
1501# CONFIG_CRYPTO_SHA1 is not set
1502# CONFIG_CRYPTO_SHA256 is not set
1503# CONFIG_CRYPTO_SHA512 is not set
1504# CONFIG_CRYPTO_TGR192 is not set
1505# CONFIG_CRYPTO_WP512 is not set
1506
1507#
1508# Ciphers
1509#
1510# CONFIG_CRYPTO_AES is not set
1511# CONFIG_CRYPTO_ANUBIS is not set
1512# CONFIG_CRYPTO_ARC4 is not set
1513# CONFIG_CRYPTO_BLOWFISH is not set
1514# CONFIG_CRYPTO_CAMELLIA is not set
1515# CONFIG_CRYPTO_CAST5 is not set
1516# CONFIG_CRYPTO_CAST6 is not set
1517CONFIG_CRYPTO_DES=y
1518# CONFIG_CRYPTO_FCRYPT is not set
1519# CONFIG_CRYPTO_KHAZAD is not set
1520# CONFIG_CRYPTO_SALSA20 is not set
1521# CONFIG_CRYPTO_SEED is not set
1522# CONFIG_CRYPTO_SERPENT is not set
1523# CONFIG_CRYPTO_TEA is not set
1524# CONFIG_CRYPTO_TWOFISH is not set
1525
1526#
1527# Compression
1528#
1529# CONFIG_CRYPTO_DEFLATE is not set
1530# CONFIG_CRYPTO_LZO is not set
1531
1532#
1533# Random Number Generation
1534#
1535# CONFIG_CRYPTO_ANSI_CPRNG is not set
1536# CONFIG_CRYPTO_HW is not set
1537
1538#
1539# Library routines
1540#
1541CONFIG_BITREVERSE=y
1542CONFIG_GENERIC_FIND_LAST_BIT=y
1543# CONFIG_CRC_CCITT is not set
1544# CONFIG_CRC16 is not set
1545# CONFIG_CRC_T10DIF is not set
1546# CONFIG_CRC_ITU_T is not set
1547CONFIG_CRC32=y
1548# CONFIG_CRC7 is not set
1549# CONFIG_LIBCRC32C is not set
1550CONFIG_PLIST=y
1551CONFIG_HAS_IOMEM=y
1552CONFIG_HAS_IOPORT=y
1553CONFIG_HAS_DMA=y
diff --git a/arch/sh/configs/urquell_defconfig b/arch/sh/configs/urquell_defconfig
new file mode 100644
index 000000000000..be726c7cdf91
--- /dev/null
+++ b/arch/sh/configs/urquell_defconfig
@@ -0,0 +1,1332 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.29-rc4
4# Thu Mar 5 17:28:13 2009
5#
6CONFIG_SUPERH=y
7CONFIG_SUPERH32=y
8CONFIG_ARCH_DEFCONFIG="arch/sh/configs/shx3_defconfig"
9CONFIG_RWSEM_GENERIC_SPINLOCK=y
10CONFIG_GENERIC_BUG=y
11CONFIG_GENERIC_FIND_NEXT_BIT=y
12CONFIG_GENERIC_HWEIGHT=y
13CONFIG_GENERIC_HARDIRQS=y
14CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ=y
15CONFIG_GENERIC_IRQ_PROBE=y
16CONFIG_GENERIC_GPIO=y
17CONFIG_GENERIC_TIME=y
18CONFIG_GENERIC_CLOCKEVENTS=y
19# CONFIG_ARCH_SUSPEND_POSSIBLE is not set
20# CONFIG_ARCH_HIBERNATION_POSSIBLE is not set
21CONFIG_SYS_SUPPORTS_NUMA=y
22CONFIG_STACKTRACE_SUPPORT=y
23CONFIG_LOCKDEP_SUPPORT=y
24CONFIG_HAVE_LATENCYTOP_SUPPORT=y
25# CONFIG_ARCH_HAS_ILOG2_U32 is not set
26# CONFIG_ARCH_HAS_ILOG2_U64 is not set
27CONFIG_ARCH_NO_VIRT_TO_BUS=y
28CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
29
30#
31# General setup
32#
33CONFIG_EXPERIMENTAL=y
34CONFIG_BROKEN_ON_SMP=y
35CONFIG_LOCK_KERNEL=y
36CONFIG_INIT_ENV_ARG_LIMIT=32
37CONFIG_LOCALVERSION=""
38CONFIG_LOCALVERSION_AUTO=y
39CONFIG_SWAP=y
40CONFIG_SYSVIPC=y
41CONFIG_SYSVIPC_SYSCTL=y
42# CONFIG_POSIX_MQUEUE is not set
43CONFIG_BSD_PROCESS_ACCT=y
44# CONFIG_BSD_PROCESS_ACCT_V3 is not set
45# CONFIG_TASKSTATS is not set
46# CONFIG_AUDIT is not set
47
48#
49# RCU Subsystem
50#
51CONFIG_CLASSIC_RCU=y
52# CONFIG_TREE_RCU is not set
53# CONFIG_PREEMPT_RCU is not set
54# CONFIG_TREE_RCU_TRACE is not set
55# CONFIG_PREEMPT_RCU_TRACE is not set
56CONFIG_IKCONFIG=y
57CONFIG_IKCONFIG_PROC=y
58CONFIG_LOG_BUF_SHIFT=14
59CONFIG_GROUP_SCHED=y
60CONFIG_FAIR_GROUP_SCHED=y
61# CONFIG_RT_GROUP_SCHED is not set
62CONFIG_USER_SCHED=y
63# CONFIG_CGROUP_SCHED is not set
64# CONFIG_CGROUPS is not set
65CONFIG_SYSFS_DEPRECATED=y
66CONFIG_SYSFS_DEPRECATED_V2=y
67# CONFIG_RELAY is not set
68# CONFIG_NAMESPACES is not set
69# CONFIG_BLK_DEV_INITRD is not set
70CONFIG_CC_OPTIMIZE_FOR_SIZE=y
71CONFIG_SYSCTL=y
72CONFIG_EMBEDDED=y
73CONFIG_UID16=y
74CONFIG_SYSCTL_SYSCALL=y
75CONFIG_KALLSYMS=y
76# CONFIG_KALLSYMS_EXTRA_PASS is not set
77CONFIG_HOTPLUG=y
78CONFIG_PRINTK=y
79CONFIG_BUG=y
80CONFIG_ELF_CORE=y
81CONFIG_COMPAT_BRK=y
82CONFIG_BASE_FULL=y
83CONFIG_FUTEX=y
84CONFIG_ANON_INODES=y
85CONFIG_EPOLL=y
86CONFIG_SIGNALFD=y
87CONFIG_TIMERFD=y
88CONFIG_EVENTFD=y
89CONFIG_SHMEM=y
90CONFIG_AIO=y
91CONFIG_VM_EVENT_COUNTERS=y
92CONFIG_SLAB=y
93# CONFIG_SLUB is not set
94# CONFIG_SLOB is not set
95CONFIG_PROFILING=y
96# CONFIG_OPROFILE is not set
97CONFIG_HAVE_OPROFILE=y
98# CONFIG_KPROBES is not set
99CONFIG_HAVE_IOREMAP_PROT=y
100CONFIG_HAVE_KPROBES=y
101CONFIG_HAVE_KRETPROBES=y
102CONFIG_HAVE_ARCH_TRACEHOOK=y
103CONFIG_HAVE_CLK=y
104CONFIG_HAVE_GENERIC_DMA_COHERENT=y
105CONFIG_SLABINFO=y
106CONFIG_RT_MUTEXES=y
107CONFIG_BASE_SMALL=0
108CONFIG_MODULES=y
109# CONFIG_MODULE_FORCE_LOAD is not set
110CONFIG_MODULE_UNLOAD=y
111# CONFIG_MODULE_FORCE_UNLOAD is not set
112# CONFIG_MODVERSIONS is not set
113# CONFIG_MODULE_SRCVERSION_ALL is not set
114CONFIG_BLOCK=y
115# CONFIG_LBD is not set
116# CONFIG_BLK_DEV_IO_TRACE is not set
117# CONFIG_BLK_DEV_BSG is not set
118# CONFIG_BLK_DEV_INTEGRITY is not set
119
120#
121# IO Schedulers
122#
123CONFIG_IOSCHED_NOOP=y
124CONFIG_IOSCHED_AS=y
125CONFIG_IOSCHED_DEADLINE=y
126CONFIG_IOSCHED_CFQ=y
127# CONFIG_DEFAULT_AS is not set
128# CONFIG_DEFAULT_DEADLINE is not set
129CONFIG_DEFAULT_CFQ=y
130# CONFIG_DEFAULT_NOOP is not set
131CONFIG_DEFAULT_IOSCHED="cfq"
132# CONFIG_FREEZER is not set
133
134#
135# System type
136#
137CONFIG_CPU_SH4=y
138CONFIG_CPU_SH4A=y
139CONFIG_CPU_SHX3=y
140# CONFIG_CPU_SUBTYPE_SH7619 is not set
141# CONFIG_CPU_SUBTYPE_SH7201 is not set
142# CONFIG_CPU_SUBTYPE_SH7203 is not set
143# CONFIG_CPU_SUBTYPE_SH7206 is not set
144# CONFIG_CPU_SUBTYPE_SH7263 is not set
145# CONFIG_CPU_SUBTYPE_MXG is not set
146# CONFIG_CPU_SUBTYPE_SH7705 is not set
147# CONFIG_CPU_SUBTYPE_SH7706 is not set
148# CONFIG_CPU_SUBTYPE_SH7707 is not set
149# CONFIG_CPU_SUBTYPE_SH7708 is not set
150# CONFIG_CPU_SUBTYPE_SH7709 is not set
151# CONFIG_CPU_SUBTYPE_SH7710 is not set
152# CONFIG_CPU_SUBTYPE_SH7712 is not set
153# CONFIG_CPU_SUBTYPE_SH7720 is not set
154# CONFIG_CPU_SUBTYPE_SH7721 is not set
155# CONFIG_CPU_SUBTYPE_SH7750 is not set
156# CONFIG_CPU_SUBTYPE_SH7091 is not set
157# CONFIG_CPU_SUBTYPE_SH7750R is not set
158# CONFIG_CPU_SUBTYPE_SH7750S is not set
159# CONFIG_CPU_SUBTYPE_SH7751 is not set
160# CONFIG_CPU_SUBTYPE_SH7751R is not set
161# CONFIG_CPU_SUBTYPE_SH7760 is not set
162# CONFIG_CPU_SUBTYPE_SH4_202 is not set
163# CONFIG_CPU_SUBTYPE_SH7723 is not set
164# CONFIG_CPU_SUBTYPE_SH7763 is not set
165# CONFIG_CPU_SUBTYPE_SH7770 is not set
166# CONFIG_CPU_SUBTYPE_SH7780 is not set
167# CONFIG_CPU_SUBTYPE_SH7785 is not set
168CONFIG_CPU_SUBTYPE_SH7786=y
169# CONFIG_CPU_SUBTYPE_SHX3 is not set
170# CONFIG_CPU_SUBTYPE_SH7343 is not set
171# CONFIG_CPU_SUBTYPE_SH7722 is not set
172# CONFIG_CPU_SUBTYPE_SH7366 is not set
173# CONFIG_CPU_SUBTYPE_SH5_101 is not set
174# CONFIG_CPU_SUBTYPE_SH5_103 is not set
175
176#
177# Memory management options
178#
179CONFIG_QUICKLIST=y
180CONFIG_MMU=y
181CONFIG_PAGE_OFFSET=0x80000000
182CONFIG_MEMORY_START=0x08000000
183CONFIG_MEMORY_SIZE=0x08000000
184CONFIG_29BIT=y
185# CONFIG_X2TLB is not set
186CONFIG_VSYSCALL=y
187# CONFIG_NUMA is not set
188CONFIG_ARCH_FLATMEM_ENABLE=y
189CONFIG_ARCH_SPARSEMEM_ENABLE=y
190CONFIG_ARCH_SPARSEMEM_DEFAULT=y
191CONFIG_MAX_ACTIVE_REGIONS=1
192CONFIG_ARCH_POPULATES_NODE_MAP=y
193CONFIG_ARCH_SELECT_MEMORY_MODEL=y
194CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
195CONFIG_ARCH_ENABLE_MEMORY_HOTREMOVE=y
196CONFIG_PAGE_SIZE_4KB=y
197# CONFIG_PAGE_SIZE_8KB is not set
198# CONFIG_PAGE_SIZE_16KB is not set
199# CONFIG_PAGE_SIZE_64KB is not set
200CONFIG_ENTRY_OFFSET=0x00001000
201CONFIG_SELECT_MEMORY_MODEL=y
202# CONFIG_FLATMEM_MANUAL is not set
203# CONFIG_DISCONTIGMEM_MANUAL is not set
204CONFIG_SPARSEMEM_MANUAL=y
205CONFIG_SPARSEMEM=y
206CONFIG_HAVE_MEMORY_PRESENT=y
207CONFIG_SPARSEMEM_STATIC=y
208# CONFIG_MEMORY_HOTPLUG is not set
209CONFIG_PAGEFLAGS_EXTENDED=y
210CONFIG_SPLIT_PTLOCK_CPUS=4
211CONFIG_MIGRATION=y
212# CONFIG_PHYS_ADDR_T_64BIT is not set
213CONFIG_ZONE_DMA_FLAG=0
214CONFIG_NR_QUICK=2
215CONFIG_UNEVICTABLE_LRU=y
216
217#
218# Cache configuration
219#
220# CONFIG_SH_DIRECT_MAPPED is not set
221CONFIG_CACHE_WRITEBACK=y
222# CONFIG_CACHE_WRITETHROUGH is not set
223# CONFIG_CACHE_OFF is not set
224
225#
226# Processor features
227#
228CONFIG_CPU_LITTLE_ENDIAN=y
229# CONFIG_CPU_BIG_ENDIAN is not set
230CONFIG_SH_FPU=y
231CONFIG_SH_STORE_QUEUES=y
232CONFIG_CPU_HAS_INTEVT=y
233CONFIG_CPU_HAS_SR_RB=y
234CONFIG_CPU_HAS_FPU=y
235
236#
237# Board support
238#
239CONFIG_SH_URQUELL=y
240
241#
242# Timer and clock configuration
243#
244CONFIG_SH_TMU=y
245CONFIG_SH_TIMER_IRQ=16
246CONFIG_SH_PCLK_FREQ=33333333
247CONFIG_TICK_ONESHOT=y
248# CONFIG_NO_HZ is not set
249CONFIG_HIGH_RES_TIMERS=y
250CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
251
252#
253# CPU Frequency scaling
254#
255# CONFIG_CPU_FREQ is not set
256
257#
258# DMA support
259#
260# CONFIG_SH_DMA is not set
261
262#
263# Companion Chips
264#
265
266#
267# Additional SuperH Device Drivers
268#
269CONFIG_HEARTBEAT=y
270# CONFIG_PUSH_SWITCH is not set
271
272#
273# Kernel features
274#
275# CONFIG_HZ_100 is not set
276CONFIG_HZ_250=y
277# CONFIG_HZ_300 is not set
278# CONFIG_HZ_1000 is not set
279CONFIG_HZ=250
280CONFIG_SCHED_HRTICK=y
281CONFIG_KEXEC=y
282# CONFIG_CRASH_DUMP is not set
283# CONFIG_SECCOMP is not set
284# CONFIG_PREEMPT_NONE is not set
285# CONFIG_PREEMPT_VOLUNTARY is not set
286CONFIG_PREEMPT=y
287CONFIG_GUSA=y
288
289#
290# Boot options
291#
292CONFIG_ZERO_PAGE_OFFSET=0x00001000
293CONFIG_BOOT_LINK_OFFSET=0x00800000
294CONFIG_CMDLINE_BOOL=y
295CONFIG_CMDLINE="console=ttySC1, 38400 earlyprintk=serial ip=on ignore_loglevel root=/dev/nfs ip=dhcp memchunk.vpu=4m"
296
297#
298# Bus options
299#
300# CONFIG_ARCH_SUPPORTS_MSI is not set
301# CONFIG_PCCARD is not set
302
303#
304# Executable file formats
305#
306CONFIG_BINFMT_ELF=y
307# CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS is not set
308# CONFIG_HAVE_AOUT is not set
309# CONFIG_BINFMT_MISC is not set
310
311#
312# Power management options (EXPERIMENTAL)
313#
314# CONFIG_PM is not set
315# CONFIG_CPU_IDLE is not set
316CONFIG_NET=y
317
318#
319# Networking options
320#
321CONFIG_COMPAT_NET_DEV_OPS=y
322CONFIG_PACKET=y
323# CONFIG_PACKET_MMAP is not set
324CONFIG_UNIX=y
325CONFIG_XFRM=y
326# CONFIG_XFRM_USER is not set
327# CONFIG_XFRM_SUB_POLICY is not set
328# CONFIG_XFRM_MIGRATE is not set
329# CONFIG_XFRM_STATISTICS is not set
330# CONFIG_NET_KEY is not set
331CONFIG_INET=y
332# CONFIG_IP_MULTICAST is not set
333CONFIG_IP_ADVANCED_ROUTER=y
334CONFIG_ASK_IP_FIB_HASH=y
335# CONFIG_IP_FIB_TRIE is not set
336CONFIG_IP_FIB_HASH=y
337# CONFIG_IP_MULTIPLE_TABLES is not set
338# CONFIG_IP_ROUTE_MULTIPATH is not set
339# CONFIG_IP_ROUTE_VERBOSE is not set
340CONFIG_IP_PNP=y
341CONFIG_IP_PNP_DHCP=y
342# CONFIG_IP_PNP_BOOTP is not set
343# CONFIG_IP_PNP_RARP is not set
344# CONFIG_NET_IPIP is not set
345# CONFIG_NET_IPGRE is not set
346# CONFIG_ARPD is not set
347# CONFIG_SYN_COOKIES is not set
348# CONFIG_INET_AH is not set
349# CONFIG_INET_ESP is not set
350# CONFIG_INET_IPCOMP is not set
351# CONFIG_INET_XFRM_TUNNEL is not set
352# CONFIG_INET_TUNNEL is not set
353CONFIG_INET_XFRM_MODE_TRANSPORT=y
354CONFIG_INET_XFRM_MODE_TUNNEL=y
355CONFIG_INET_XFRM_MODE_BEET=y
356# CONFIG_INET_LRO is not set
357CONFIG_INET_DIAG=y
358CONFIG_INET_TCP_DIAG=y
359# CONFIG_TCP_CONG_ADVANCED is not set
360CONFIG_TCP_CONG_CUBIC=y
361CONFIG_DEFAULT_TCP_CONG="cubic"
362# CONFIG_TCP_MD5SIG is not set
363# CONFIG_IPV6 is not set
364# CONFIG_NETWORK_SECMARK is not set
365# CONFIG_NETFILTER is not set
366# CONFIG_IP_DCCP is not set
367# CONFIG_IP_SCTP is not set
368# CONFIG_TIPC is not set
369# CONFIG_ATM is not set
370# CONFIG_BRIDGE is not set
371# CONFIG_NET_DSA is not set
372# CONFIG_VLAN_8021Q is not set
373# CONFIG_DECNET is not set
374# CONFIG_LLC2 is not set
375# CONFIG_IPX is not set
376# CONFIG_ATALK is not set
377# CONFIG_X25 is not set
378# CONFIG_LAPB is not set
379# CONFIG_ECONET is not set
380# CONFIG_WAN_ROUTER is not set
381# CONFIG_NET_SCHED is not set
382# CONFIG_DCB is not set
383
384#
385# Network testing
386#
387# CONFIG_NET_PKTGEN is not set
388# CONFIG_HAMRADIO is not set
389# CONFIG_CAN is not set
390# CONFIG_IRDA is not set
391# CONFIG_BT is not set
392# CONFIG_AF_RXRPC is not set
393# CONFIG_PHONET is not set
394CONFIG_WIRELESS=y
395# CONFIG_CFG80211 is not set
396# CONFIG_WIRELESS_OLD_REGULATORY is not set
397CONFIG_WIRELESS_EXT=y
398CONFIG_WIRELESS_EXT_SYSFS=y
399# CONFIG_LIB80211 is not set
400# CONFIG_MAC80211 is not set
401# CONFIG_WIMAX is not set
402# CONFIG_RFKILL is not set
403# CONFIG_NET_9P is not set
404
405#
406# Device Drivers
407#
408
409#
410# Generic Driver Options
411#
412CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
413CONFIG_STANDALONE=y
414CONFIG_PREVENT_FIRMWARE_BUILD=y
415# CONFIG_FW_LOADER is not set
416# CONFIG_SYS_HYPERVISOR is not set
417# CONFIG_CONNECTOR is not set
418CONFIG_MTD=y
419# CONFIG_MTD_DEBUG is not set
420CONFIG_MTD_CONCAT=y
421CONFIG_MTD_PARTITIONS=y
422# CONFIG_MTD_TESTS is not set
423# CONFIG_MTD_REDBOOT_PARTS is not set
424# CONFIG_MTD_CMDLINE_PARTS is not set
425# CONFIG_MTD_AR7_PARTS is not set
426
427#
428# User Modules And Translation Layers
429#
430CONFIG_MTD_CHAR=y
431CONFIG_MTD_BLKDEVS=y
432CONFIG_MTD_BLOCK=y
433# CONFIG_FTL is not set
434# CONFIG_NFTL is not set
435# CONFIG_INFTL is not set
436# CONFIG_RFD_FTL is not set
437# CONFIG_SSFDC is not set
438# CONFIG_MTD_OOPS is not set
439
440#
441# RAM/ROM/Flash chip drivers
442#
443CONFIG_MTD_CFI=y
444# CONFIG_MTD_JEDECPROBE is not set
445CONFIG_MTD_GEN_PROBE=y
446# CONFIG_MTD_CFI_ADV_OPTIONS is not set
447CONFIG_MTD_MAP_BANK_WIDTH_1=y
448CONFIG_MTD_MAP_BANK_WIDTH_2=y
449CONFIG_MTD_MAP_BANK_WIDTH_4=y
450# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
451# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
452# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
453CONFIG_MTD_CFI_I1=y
454CONFIG_MTD_CFI_I2=y
455# CONFIG_MTD_CFI_I4 is not set
456# CONFIG_MTD_CFI_I8 is not set
457# CONFIG_MTD_CFI_INTELEXT is not set
458CONFIG_MTD_CFI_AMDSTD=y
459# CONFIG_MTD_CFI_STAA is not set
460CONFIG_MTD_CFI_UTIL=y
461# CONFIG_MTD_RAM is not set
462# CONFIG_MTD_ROM is not set
463# CONFIG_MTD_ABSENT is not set
464
465#
466# Mapping drivers for chip access
467#
468# CONFIG_MTD_COMPLEX_MAPPINGS is not set
469CONFIG_MTD_PHYSMAP=y
470# CONFIG_MTD_PHYSMAP_COMPAT is not set
471# CONFIG_MTD_PLATRAM is not set
472
473#
474# Self-contained MTD device drivers
475#
476# CONFIG_MTD_SLRAM is not set
477# CONFIG_MTD_PHRAM is not set
478# CONFIG_MTD_MTDRAM is not set
479# CONFIG_MTD_BLOCK2MTD is not set
480
481#
482# Disk-On-Chip Device Drivers
483#
484# CONFIG_MTD_DOC2000 is not set
485# CONFIG_MTD_DOC2001 is not set
486# CONFIG_MTD_DOC2001PLUS is not set
487# CONFIG_MTD_NAND is not set
488# CONFIG_MTD_ONENAND is not set
489
490#
491# LPDDR flash memory drivers
492#
493# CONFIG_MTD_LPDDR is not set
494# CONFIG_MTD_QINFO_PROBE is not set
495
496#
497# UBI - Unsorted block images
498#
499# CONFIG_MTD_UBI is not set
500# CONFIG_PARPORT is not set
501CONFIG_BLK_DEV=y
502# CONFIG_BLK_DEV_COW_COMMON is not set
503# CONFIG_BLK_DEV_LOOP is not set
504# CONFIG_BLK_DEV_NBD is not set
505# CONFIG_BLK_DEV_UB is not set
506CONFIG_BLK_DEV_RAM=y
507CONFIG_BLK_DEV_RAM_COUNT=16
508CONFIG_BLK_DEV_RAM_SIZE=4096
509# CONFIG_BLK_DEV_XIP is not set
510# CONFIG_CDROM_PKTCDVD is not set
511# CONFIG_ATA_OVER_ETH is not set
512# CONFIG_BLK_DEV_HD is not set
513# CONFIG_MISC_DEVICES is not set
514CONFIG_HAVE_IDE=y
515# CONFIG_IDE is not set
516
517#
518# SCSI device support
519#
520# CONFIG_RAID_ATTRS is not set
521CONFIG_SCSI=y
522CONFIG_SCSI_DMA=y
523# CONFIG_SCSI_TGT is not set
524# CONFIG_SCSI_NETLINK is not set
525CONFIG_SCSI_PROC_FS=y
526
527#
528# SCSI support type (disk, tape, CD-ROM)
529#
530CONFIG_BLK_DEV_SD=y
531# CONFIG_CHR_DEV_ST is not set
532# CONFIG_CHR_DEV_OSST is not set
533# CONFIG_BLK_DEV_SR is not set
534# CONFIG_CHR_DEV_SG is not set
535# CONFIG_CHR_DEV_SCH is not set
536
537#
538# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
539#
540# CONFIG_SCSI_MULTI_LUN is not set
541# CONFIG_SCSI_CONSTANTS is not set
542# CONFIG_SCSI_LOGGING is not set
543# CONFIG_SCSI_SCAN_ASYNC is not set
544CONFIG_SCSI_WAIT_SCAN=m
545
546#
547# SCSI Transports
548#
549# CONFIG_SCSI_SPI_ATTRS is not set
550# CONFIG_SCSI_FC_ATTRS is not set
551# CONFIG_SCSI_ISCSI_ATTRS is not set
552# CONFIG_SCSI_SAS_LIBSAS is not set
553# CONFIG_SCSI_SRP_ATTRS is not set
554# CONFIG_SCSI_LOWLEVEL is not set
555# CONFIG_SCSI_DH is not set
556CONFIG_ATA=y
557# CONFIG_ATA_NONSTANDARD is not set
558CONFIG_SATA_PMP=y
559CONFIG_ATA_SFF=y
560# CONFIG_SATA_MV is not set
561# CONFIG_PATA_PLATFORM is not set
562# CONFIG_MD is not set
563CONFIG_NETDEVICES=y
564# CONFIG_DUMMY is not set
565# CONFIG_BONDING is not set
566# CONFIG_MACVLAN is not set
567# CONFIG_EQUALIZER is not set
568# CONFIG_TUN is not set
569# CONFIG_VETH is not set
570CONFIG_PHYLIB=y
571
572#
573# MII PHY device drivers
574#
575# CONFIG_MARVELL_PHY is not set
576# CONFIG_DAVICOM_PHY is not set
577# CONFIG_QSEMI_PHY is not set
578# CONFIG_LXT_PHY is not set
579# CONFIG_CICADA_PHY is not set
580# CONFIG_VITESSE_PHY is not set
581# CONFIG_SMSC_PHY is not set
582# CONFIG_BROADCOM_PHY is not set
583# CONFIG_ICPLUS_PHY is not set
584# CONFIG_REALTEK_PHY is not set
585# CONFIG_NATIONAL_PHY is not set
586# CONFIG_STE10XP is not set
587# CONFIG_LSI_ET1011C_PHY is not set
588# CONFIG_FIXED_PHY is not set
589# CONFIG_MDIO_BITBANG is not set
590CONFIG_NET_ETHERNET=y
591CONFIG_MII=y
592# CONFIG_AX88796 is not set
593# CONFIG_STNIC is not set
594CONFIG_SMC91X=y
595# CONFIG_SMC911X is not set
596# CONFIG_SMSC911X is not set
597# CONFIG_IBM_NEW_EMAC_ZMII is not set
598# CONFIG_IBM_NEW_EMAC_RGMII is not set
599# CONFIG_IBM_NEW_EMAC_TAH is not set
600# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
601# CONFIG_IBM_NEW_EMAC_NO_FLOW_CTRL is not set
602# CONFIG_IBM_NEW_EMAC_MAL_CLR_ICINTSTAT is not set
603# CONFIG_IBM_NEW_EMAC_MAL_COMMON_ERR is not set
604# CONFIG_B44 is not set
605# CONFIG_NETDEV_1000 is not set
606# CONFIG_NETDEV_10000 is not set
607
608#
609# Wireless LAN
610#
611# CONFIG_WLAN_PRE80211 is not set
612# CONFIG_WLAN_80211 is not set
613# CONFIG_IWLWIFI_LEDS is not set
614
615#
616# Enable WiMAX (Networking options) to see the WiMAX drivers
617#
618
619#
620# USB Network Adapters
621#
622# CONFIG_USB_CATC is not set
623# CONFIG_USB_KAWETH is not set
624# CONFIG_USB_PEGASUS is not set
625# CONFIG_USB_RTL8150 is not set
626# CONFIG_USB_USBNET is not set
627# CONFIG_WAN is not set
628# CONFIG_PPP is not set
629# CONFIG_SLIP is not set
630# CONFIG_NETCONSOLE is not set
631# CONFIG_NETPOLL is not set
632# CONFIG_NET_POLL_CONTROLLER is not set
633# CONFIG_ISDN is not set
634# CONFIG_PHONE is not set
635
636#
637# Input device support
638#
639CONFIG_INPUT=y
640CONFIG_INPUT_FF_MEMLESS=m
641# CONFIG_INPUT_POLLDEV is not set
642
643#
644# Userland interfaces
645#
646CONFIG_INPUT_MOUSEDEV=y
647# CONFIG_INPUT_MOUSEDEV_PSAUX is not set
648CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024
649CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768
650# CONFIG_INPUT_JOYDEV is not set
651# CONFIG_INPUT_EVDEV is not set
652# CONFIG_INPUT_EVBUG is not set
653
654#
655# Input Device Drivers
656#
657CONFIG_INPUT_KEYBOARD=y
658# CONFIG_KEYBOARD_ATKBD is not set
659# CONFIG_KEYBOARD_SUNKBD is not set
660# CONFIG_KEYBOARD_LKKBD is not set
661# CONFIG_KEYBOARD_XTKBD is not set
662# CONFIG_KEYBOARD_NEWTON is not set
663# CONFIG_KEYBOARD_STOWAWAY is not set
664# CONFIG_KEYBOARD_GPIO is not set
665# CONFIG_KEYBOARD_SH_KEYSC is not set
666# CONFIG_INPUT_MOUSE is not set
667# CONFIG_INPUT_JOYSTICK is not set
668# CONFIG_INPUT_TABLET is not set
669# CONFIG_INPUT_TOUCHSCREEN is not set
670# CONFIG_INPUT_MISC is not set
671
672#
673# Hardware I/O ports
674#
675# CONFIG_SERIO is not set
676# CONFIG_GAMEPORT is not set
677
678#
679# Character devices
680#
681CONFIG_VT=y
682CONFIG_CONSOLE_TRANSLATIONS=y
683CONFIG_VT_CONSOLE=y
684CONFIG_HW_CONSOLE=y
685CONFIG_VT_HW_CONSOLE_BINDING=y
686CONFIG_DEVKMEM=y
687# CONFIG_SERIAL_NONSTANDARD is not set
688
689#
690# Serial drivers
691#
692# CONFIG_SERIAL_8250 is not set
693
694#
695# Non-8250 serial port support
696#
697CONFIG_SERIAL_SH_SCI=y
698CONFIG_SERIAL_SH_SCI_NR_UARTS=6
699CONFIG_SERIAL_SH_SCI_CONSOLE=y
700CONFIG_SERIAL_CORE=y
701CONFIG_SERIAL_CORE_CONSOLE=y
702CONFIG_UNIX98_PTYS=y
703# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
704CONFIG_LEGACY_PTYS=y
705CONFIG_LEGACY_PTY_COUNT=256
706# CONFIG_IPMI_HANDLER is not set
707CONFIG_HW_RANDOM=y
708# CONFIG_R3964 is not set
709# CONFIG_RAW_DRIVER is not set
710# CONFIG_TCG_TPM is not set
711CONFIG_I2C=y
712CONFIG_I2C_BOARDINFO=y
713# CONFIG_I2C_CHARDEV is not set
714CONFIG_I2C_HELPER_AUTO=y
715CONFIG_I2C_ALGOPCA=y
716
717#
718# I2C Hardware Bus support
719#
720
721#
722# I2C system bus drivers (mostly embedded / system-on-chip)
723#
724# CONFIG_I2C_GPIO is not set
725# CONFIG_I2C_OCORES is not set
726# CONFIG_I2C_SH_MOBILE is not set
727# CONFIG_I2C_SIMTEC is not set
728
729#
730# External I2C/SMBus adapter drivers
731#
732# CONFIG_I2C_PARPORT_LIGHT is not set
733# CONFIG_I2C_TAOS_EVM is not set
734# CONFIG_I2C_TINY_USB is not set
735
736#
737# Other I2C/SMBus bus drivers
738#
739CONFIG_I2C_PCA_PLATFORM=y
740# CONFIG_I2C_STUB is not set
741
742#
743# Miscellaneous I2C Chip support
744#
745# CONFIG_DS1682 is not set
746# CONFIG_SENSORS_PCF8574 is not set
747# CONFIG_PCF8575 is not set
748# CONFIG_SENSORS_PCA9539 is not set
749# CONFIG_SENSORS_PCF8591 is not set
750# CONFIG_SENSORS_MAX6875 is not set
751# CONFIG_SENSORS_TSL2550 is not set
752# CONFIG_I2C_DEBUG_CORE is not set
753# CONFIG_I2C_DEBUG_ALGO is not set
754# CONFIG_I2C_DEBUG_BUS is not set
755# CONFIG_I2C_DEBUG_CHIP is not set
756# CONFIG_SPI is not set
757CONFIG_ARCH_REQUIRE_GPIOLIB=y
758CONFIG_GPIOLIB=y
759# CONFIG_GPIO_SYSFS is not set
760
761#
762# Memory mapped GPIO expanders:
763#
764
765#
766# I2C GPIO expanders:
767#
768# CONFIG_GPIO_MAX732X is not set
769# CONFIG_GPIO_PCA953X is not set
770# CONFIG_GPIO_PCF857X is not set
771
772#
773# PCI GPIO expanders:
774#
775
776#
777# SPI GPIO expanders:
778#
779# CONFIG_W1 is not set
780# CONFIG_POWER_SUPPLY is not set
781# CONFIG_HWMON is not set
782# CONFIG_THERMAL is not set
783# CONFIG_THERMAL_HWMON is not set
784# CONFIG_WATCHDOG is not set
785CONFIG_SSB_POSSIBLE=y
786
787#
788# Sonics Silicon Backplane
789#
790# CONFIG_SSB is not set
791
792#
793# Multifunction device drivers
794#
795# CONFIG_MFD_CORE is not set
796CONFIG_MFD_SM501=y
797# CONFIG_MFD_SM501_GPIO is not set
798# CONFIG_HTC_PASIC3 is not set
799# CONFIG_TPS65010 is not set
800# CONFIG_TWL4030_CORE is not set
801# CONFIG_MFD_TMIO is not set
802# CONFIG_PMIC_DA903X is not set
803# CONFIG_MFD_WM8400 is not set
804# CONFIG_MFD_WM8350_I2C is not set
805# CONFIG_MFD_PCF50633 is not set
806# CONFIG_REGULATOR is not set
807
808#
809# Multimedia devices
810#
811
812#
813# Multimedia core support
814#
815# CONFIG_VIDEO_DEV is not set
816# CONFIG_DVB_CORE is not set
817# CONFIG_VIDEO_MEDIA is not set
818
819#
820# Multimedia drivers
821#
822# CONFIG_DAB is not set
823
824#
825# Graphics support
826#
827# CONFIG_VGASTATE is not set
828# CONFIG_VIDEO_OUTPUT_CONTROL is not set
829CONFIG_FB=y
830# CONFIG_FIRMWARE_EDID is not set
831# CONFIG_FB_DDC is not set
832# CONFIG_FB_BOOT_VESA_SUPPORT is not set
833CONFIG_FB_CFB_FILLRECT=y
834CONFIG_FB_CFB_COPYAREA=y
835CONFIG_FB_CFB_IMAGEBLIT=y
836# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
837CONFIG_FB_SYS_FILLRECT=m
838CONFIG_FB_SYS_COPYAREA=m
839CONFIG_FB_SYS_IMAGEBLIT=m
840# CONFIG_FB_FOREIGN_ENDIAN is not set
841CONFIG_FB_SYS_FOPS=m
842CONFIG_FB_DEFERRED_IO=y
843# CONFIG_FB_SVGALIB is not set
844# CONFIG_FB_MACMODES is not set
845# CONFIG_FB_BACKLIGHT is not set
846# CONFIG_FB_MODE_HELPERS is not set
847# CONFIG_FB_TILEBLITTING is not set
848
849#
850# Frame buffer hardware drivers
851#
852# CONFIG_FB_S1D13XXX is not set
853CONFIG_FB_SH_MOBILE_LCDC=m
854CONFIG_FB_SM501=y
855# CONFIG_FB_VIRTUAL is not set
856# CONFIG_FB_METRONOME is not set
857# CONFIG_FB_MB862XX is not set
858# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
859
860#
861# Display device support
862#
863# CONFIG_DISPLAY_SUPPORT is not set
864
865#
866# Console display driver support
867#
868CONFIG_DUMMY_CONSOLE=y
869CONFIG_FRAMEBUFFER_CONSOLE=y
870# CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY is not set
871# CONFIG_FRAMEBUFFER_CONSOLE_ROTATION is not set
872# CONFIG_FONTS is not set
873CONFIG_FONT_8x8=y
874CONFIG_FONT_8x16=y
875CONFIG_LOGO=y
876# CONFIG_LOGO_LINUX_MONO is not set
877# CONFIG_LOGO_LINUX_VGA16 is not set
878CONFIG_LOGO_LINUX_CLUT224=y
879# CONFIG_LOGO_SUPERH_MONO is not set
880# CONFIG_LOGO_SUPERH_VGA16 is not set
881# CONFIG_LOGO_SUPERH_CLUT224 is not set
882# CONFIG_SOUND is not set
883CONFIG_HID_SUPPORT=y
884CONFIG_HID=y
885# CONFIG_HID_DEBUG is not set
886# CONFIG_HIDRAW is not set
887
888#
889# USB Input Devices
890#
891CONFIG_USB_HID=y
892# CONFIG_HID_PID is not set
893# CONFIG_USB_HIDDEV is not set
894
895#
896# Special HID drivers
897#
898CONFIG_HID_COMPAT=y
899CONFIG_HID_A4TECH=y
900CONFIG_HID_APPLE=y
901CONFIG_HID_BELKIN=y
902CONFIG_HID_CHERRY=y
903CONFIG_HID_CHICONY=y
904CONFIG_HID_CYPRESS=y
905CONFIG_HID_EZKEY=y
906CONFIG_HID_GYRATION=y
907CONFIG_HID_LOGITECH=y
908# CONFIG_LOGITECH_FF is not set
909# CONFIG_LOGIRUMBLEPAD2_FF is not set
910CONFIG_HID_MICROSOFT=y
911CONFIG_HID_MONTEREY=y
912# CONFIG_HID_NTRIG is not set
913CONFIG_HID_PANTHERLORD=y
914# CONFIG_PANTHERLORD_FF is not set
915CONFIG_HID_PETALYNX=y
916CONFIG_HID_SAMSUNG=y
917CONFIG_HID_SONY=y
918CONFIG_HID_SUNPLUS=y
919# CONFIG_GREENASIA_FF is not set
920# CONFIG_HID_TOPSEED is not set
921CONFIG_THRUSTMASTER_FF=m
922CONFIG_ZEROPLUS_FF=m
923CONFIG_USB_SUPPORT=y
924CONFIG_USB_ARCH_HAS_HCD=y
925# CONFIG_USB_ARCH_HAS_OHCI is not set
926# CONFIG_USB_ARCH_HAS_EHCI is not set
927CONFIG_USB=y
928# CONFIG_USB_DEBUG is not set
929CONFIG_USB_ANNOUNCE_NEW_DEVICES=y
930
931#
932# Miscellaneous USB options
933#
934CONFIG_USB_DEVICEFS=y
935CONFIG_USB_DEVICE_CLASS=y
936# CONFIG_USB_DYNAMIC_MINORS is not set
937# CONFIG_USB_OTG is not set
938# CONFIG_USB_OTG_WHITELIST is not set
939# CONFIG_USB_OTG_BLACKLIST_HUB is not set
940CONFIG_USB_MON=y
941# CONFIG_USB_WUSB is not set
942# CONFIG_USB_WUSB_CBAF is not set
943
944#
945# USB Host Controller Drivers
946#
947# CONFIG_USB_C67X00_HCD is not set
948# CONFIG_USB_OXU210HP_HCD is not set
949# CONFIG_USB_ISP116X_HCD is not set
950# CONFIG_USB_SL811_HCD is not set
951# CONFIG_USB_R8A66597_HCD is not set
952# CONFIG_USB_HWA_HCD is not set
953
954#
955# USB Device Class drivers
956#
957# CONFIG_USB_ACM is not set
958# CONFIG_USB_PRINTER is not set
959# CONFIG_USB_WDM is not set
960# CONFIG_USB_TMC is not set
961
962#
963# NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may also be needed;
964#
965
966#
967# see USB_STORAGE Help for more information
968#
969CONFIG_USB_STORAGE=y
970# CONFIG_USB_STORAGE_DEBUG is not set
971# CONFIG_USB_STORAGE_DATAFAB is not set
972# CONFIG_USB_STORAGE_FREECOM is not set
973# CONFIG_USB_STORAGE_ISD200 is not set
974# CONFIG_USB_STORAGE_USBAT is not set
975# CONFIG_USB_STORAGE_SDDR09 is not set
976# CONFIG_USB_STORAGE_SDDR55 is not set
977# CONFIG_USB_STORAGE_JUMPSHOT is not set
978# CONFIG_USB_STORAGE_ALAUDA is not set
979# CONFIG_USB_STORAGE_ONETOUCH is not set
980# CONFIG_USB_STORAGE_KARMA is not set
981# CONFIG_USB_STORAGE_CYPRESS_ATACB is not set
982# CONFIG_USB_LIBUSUAL is not set
983
984#
985# USB Imaging devices
986#
987# CONFIG_USB_MDC800 is not set
988# CONFIG_USB_MICROTEK is not set
989
990#
991# USB port drivers
992#
993# CONFIG_USB_SERIAL is not set
994
995#
996# USB Miscellaneous drivers
997#
998# CONFIG_USB_EMI62 is not set
999# CONFIG_USB_EMI26 is not set
1000# CONFIG_USB_ADUTUX is not set
1001# CONFIG_USB_SEVSEG is not set
1002# CONFIG_USB_RIO500 is not set
1003# CONFIG_USB_LEGOTOWER is not set
1004# CONFIG_USB_LCD is not set
1005# CONFIG_USB_BERRY_CHARGE is not set
1006# CONFIG_USB_LED is not set
1007# CONFIG_USB_CYPRESS_CY7C63 is not set
1008# CONFIG_USB_CYTHERM is not set
1009# CONFIG_USB_PHIDGET is not set
1010# CONFIG_USB_IDMOUSE is not set
1011# CONFIG_USB_FTDI_ELAN is not set
1012# CONFIG_USB_APPLEDISPLAY is not set
1013# CONFIG_USB_LD is not set
1014# CONFIG_USB_TRANCEVIBRATOR is not set
1015# CONFIG_USB_IOWARRIOR is not set
1016# CONFIG_USB_TEST is not set
1017# CONFIG_USB_ISIGHTFW is not set
1018# CONFIG_USB_VST is not set
1019# CONFIG_USB_GADGET is not set
1020
1021#
1022# OTG and related infrastructure
1023#
1024# CONFIG_USB_GPIO_VBUS is not set
1025# CONFIG_MMC is not set
1026# CONFIG_MEMSTICK is not set
1027# CONFIG_NEW_LEDS is not set
1028# CONFIG_ACCESSIBILITY is not set
1029# CONFIG_RTC_CLASS is not set
1030# CONFIG_DMADEVICES is not set
1031# CONFIG_UIO is not set
1032# CONFIG_STAGING is not set
1033
1034#
1035# File systems
1036#
1037CONFIG_EXT2_FS=y
1038# CONFIG_EXT2_FS_XATTR is not set
1039# CONFIG_EXT2_FS_XIP is not set
1040CONFIG_EXT3_FS=y
1041CONFIG_EXT3_FS_XATTR=y
1042# CONFIG_EXT3_FS_POSIX_ACL is not set
1043# CONFIG_EXT3_FS_SECURITY is not set
1044# CONFIG_EXT4_FS is not set
1045CONFIG_JBD=y
1046CONFIG_FS_MBCACHE=y
1047# CONFIG_REISERFS_FS is not set
1048# CONFIG_JFS_FS is not set
1049CONFIG_FS_POSIX_ACL=y
1050CONFIG_FILE_LOCKING=y
1051# CONFIG_XFS_FS is not set
1052# CONFIG_OCFS2_FS is not set
1053# CONFIG_BTRFS_FS is not set
1054CONFIG_DNOTIFY=y
1055CONFIG_INOTIFY=y
1056CONFIG_INOTIFY_USER=y
1057# CONFIG_QUOTA is not set
1058# CONFIG_AUTOFS_FS is not set
1059# CONFIG_AUTOFS4_FS is not set
1060# CONFIG_FUSE_FS is not set
1061
1062#
1063# CD-ROM/DVD Filesystems
1064#
1065# CONFIG_ISO9660_FS is not set
1066# CONFIG_UDF_FS is not set
1067
1068#
1069# DOS/FAT/NT Filesystems
1070#
1071CONFIG_FAT_FS=y
1072CONFIG_MSDOS_FS=y
1073CONFIG_VFAT_FS=y
1074CONFIG_FAT_DEFAULT_CODEPAGE=437
1075CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
1076CONFIG_NTFS_FS=y
1077# CONFIG_NTFS_DEBUG is not set
1078CONFIG_NTFS_RW=y
1079
1080#
1081# Pseudo filesystems
1082#
1083CONFIG_PROC_FS=y
1084CONFIG_PROC_KCORE=y
1085CONFIG_PROC_SYSCTL=y
1086CONFIG_PROC_PAGE_MONITOR=y
1087CONFIG_SYSFS=y
1088CONFIG_TMPFS=y
1089# CONFIG_TMPFS_POSIX_ACL is not set
1090# CONFIG_HUGETLBFS is not set
1091# CONFIG_HUGETLB_PAGE is not set
1092# CONFIG_CONFIGFS_FS is not set
1093CONFIG_MISC_FILESYSTEMS=y
1094# CONFIG_ADFS_FS is not set
1095# CONFIG_AFFS_FS is not set
1096# CONFIG_HFS_FS is not set
1097# CONFIG_HFSPLUS_FS is not set
1098# CONFIG_BEFS_FS is not set
1099# CONFIG_BFS_FS is not set
1100# CONFIG_EFS_FS is not set
1101# CONFIG_JFFS2_FS is not set
1102# CONFIG_CRAMFS is not set
1103# CONFIG_SQUASHFS is not set
1104# CONFIG_VXFS_FS is not set
1105CONFIG_MINIX_FS=y
1106# CONFIG_OMFS_FS is not set
1107# CONFIG_HPFS_FS is not set
1108# CONFIG_QNX4FS_FS is not set
1109# CONFIG_ROMFS_FS is not set
1110# CONFIG_SYSV_FS is not set
1111# CONFIG_UFS_FS is not set
1112CONFIG_NETWORK_FILESYSTEMS=y
1113CONFIG_NFS_FS=y
1114CONFIG_NFS_V3=y
1115# CONFIG_NFS_V3_ACL is not set
1116CONFIG_NFS_V4=y
1117CONFIG_ROOT_NFS=y
1118CONFIG_NFSD=y
1119CONFIG_NFSD_V3=y
1120# CONFIG_NFSD_V3_ACL is not set
1121CONFIG_NFSD_V4=y
1122CONFIG_LOCKD=y
1123CONFIG_LOCKD_V4=y
1124CONFIG_EXPORTFS=y
1125CONFIG_NFS_COMMON=y
1126CONFIG_SUNRPC=y
1127CONFIG_SUNRPC_GSS=y
1128# CONFIG_SUNRPC_REGISTER_V4 is not set
1129CONFIG_RPCSEC_GSS_KRB5=y
1130# CONFIG_RPCSEC_GSS_SPKM3 is not set
1131# CONFIG_SMB_FS is not set
1132# CONFIG_CIFS is not set
1133# CONFIG_NCP_FS is not set
1134# CONFIG_CODA_FS is not set
1135# CONFIG_AFS_FS is not set
1136
1137#
1138# Partition Types
1139#
1140# CONFIG_PARTITION_ADVANCED is not set
1141CONFIG_MSDOS_PARTITION=y
1142CONFIG_NLS=y
1143CONFIG_NLS_DEFAULT="iso8859-1"
1144CONFIG_NLS_CODEPAGE_437=y
1145# CONFIG_NLS_CODEPAGE_737 is not set
1146# CONFIG_NLS_CODEPAGE_775 is not set
1147# CONFIG_NLS_CODEPAGE_850 is not set
1148# CONFIG_NLS_CODEPAGE_852 is not set
1149# CONFIG_NLS_CODEPAGE_855 is not set
1150# CONFIG_NLS_CODEPAGE_857 is not set
1151# CONFIG_NLS_CODEPAGE_860 is not set
1152# CONFIG_NLS_CODEPAGE_861 is not set
1153# CONFIG_NLS_CODEPAGE_862 is not set
1154# CONFIG_NLS_CODEPAGE_863 is not set
1155# CONFIG_NLS_CODEPAGE_864 is not set
1156# CONFIG_NLS_CODEPAGE_865 is not set
1157# CONFIG_NLS_CODEPAGE_866 is not set
1158# CONFIG_NLS_CODEPAGE_869 is not set
1159# CONFIG_NLS_CODEPAGE_936 is not set
1160# CONFIG_NLS_CODEPAGE_950 is not set
1161CONFIG_NLS_CODEPAGE_932=y
1162# CONFIG_NLS_CODEPAGE_949 is not set
1163# CONFIG_NLS_CODEPAGE_874 is not set
1164# CONFIG_NLS_ISO8859_8 is not set
1165# CONFIG_NLS_CODEPAGE_1250 is not set
1166# CONFIG_NLS_CODEPAGE_1251 is not set
1167# CONFIG_NLS_ASCII is not set
1168CONFIG_NLS_ISO8859_1=y
1169# CONFIG_NLS_ISO8859_2 is not set
1170# CONFIG_NLS_ISO8859_3 is not set
1171# CONFIG_NLS_ISO8859_4 is not set
1172# CONFIG_NLS_ISO8859_5 is not set
1173# CONFIG_NLS_ISO8859_6 is not set
1174# CONFIG_NLS_ISO8859_7 is not set
1175# CONFIG_NLS_ISO8859_9 is not set
1176# CONFIG_NLS_ISO8859_13 is not set
1177# CONFIG_NLS_ISO8859_14 is not set
1178# CONFIG_NLS_ISO8859_15 is not set
1179# CONFIG_NLS_KOI8_R is not set
1180# CONFIG_NLS_KOI8_U is not set
1181# CONFIG_NLS_UTF8 is not set
1182# CONFIG_DLM is not set
1183
1184#
1185# Kernel hacking
1186#
1187CONFIG_TRACE_IRQFLAGS_SUPPORT=y
1188# CONFIG_PRINTK_TIME is not set
1189# CONFIG_ENABLE_WARN_DEPRECATED is not set
1190# CONFIG_ENABLE_MUST_CHECK is not set
1191CONFIG_FRAME_WARN=1024
1192# CONFIG_MAGIC_SYSRQ is not set
1193# CONFIG_UNUSED_SYMBOLS is not set
1194# CONFIG_DEBUG_FS is not set
1195# CONFIG_HEADERS_CHECK is not set
1196# CONFIG_DEBUG_KERNEL is not set
1197# CONFIG_DEBUG_BUGVERBOSE is not set
1198# CONFIG_DEBUG_MEMORY_INIT is not set
1199# CONFIG_RCU_CPU_STALL_DETECTOR is not set
1200# CONFIG_LATENCYTOP is not set
1201CONFIG_SYSCTL_SYSCALL_CHECK=y
1202CONFIG_HAVE_FUNCTION_TRACER=y
1203CONFIG_HAVE_DYNAMIC_FTRACE=y
1204CONFIG_HAVE_FTRACE_MCOUNT_RECORD=y
1205
1206#
1207# Tracers
1208#
1209# CONFIG_DYNAMIC_PRINTK_DEBUG is not set
1210# CONFIG_SAMPLES is not set
1211CONFIG_HAVE_ARCH_KGDB=y
1212# CONFIG_SH_STANDARD_BIOS is not set
1213# CONFIG_EARLY_SCIF_CONSOLE is not set
1214# CONFIG_MORE_COMPILE_OPTIONS is not set
1215
1216#
1217# Security options
1218#
1219# CONFIG_KEYS is not set
1220# CONFIG_SECURITY is not set
1221# CONFIG_SECURITYFS is not set
1222# CONFIG_SECURITY_FILE_CAPABILITIES is not set
1223CONFIG_CRYPTO=y
1224
1225#
1226# Crypto core or helper
1227#
1228# CONFIG_CRYPTO_FIPS is not set
1229CONFIG_CRYPTO_ALGAPI=y
1230CONFIG_CRYPTO_ALGAPI2=y
1231CONFIG_CRYPTO_AEAD2=y
1232CONFIG_CRYPTO_BLKCIPHER=y
1233CONFIG_CRYPTO_BLKCIPHER2=y
1234CONFIG_CRYPTO_HASH=y
1235CONFIG_CRYPTO_HASH2=y
1236CONFIG_CRYPTO_RNG2=y
1237CONFIG_CRYPTO_MANAGER=y
1238CONFIG_CRYPTO_MANAGER2=y
1239# CONFIG_CRYPTO_GF128MUL is not set
1240# CONFIG_CRYPTO_NULL is not set
1241# CONFIG_CRYPTO_CRYPTD is not set
1242# CONFIG_CRYPTO_AUTHENC is not set
1243# CONFIG_CRYPTO_TEST is not set
1244
1245#
1246# Authenticated Encryption with Associated Data
1247#
1248# CONFIG_CRYPTO_CCM is not set
1249# CONFIG_CRYPTO_GCM is not set
1250# CONFIG_CRYPTO_SEQIV is not set
1251
1252#
1253# Block modes
1254#
1255CONFIG_CRYPTO_CBC=y
1256# CONFIG_CRYPTO_CTR is not set
1257# CONFIG_CRYPTO_CTS is not set
1258# CONFIG_CRYPTO_ECB is not set
1259# CONFIG_CRYPTO_LRW is not set
1260# CONFIG_CRYPTO_PCBC is not set
1261# CONFIG_CRYPTO_XTS is not set
1262
1263#
1264# Hash modes
1265#
1266CONFIG_CRYPTO_HMAC=y
1267# CONFIG_CRYPTO_XCBC is not set
1268
1269#
1270# Digest
1271#
1272# CONFIG_CRYPTO_CRC32C is not set
1273# CONFIG_CRYPTO_MD4 is not set
1274CONFIG_CRYPTO_MD5=y
1275# CONFIG_CRYPTO_MICHAEL_MIC is not set
1276# CONFIG_CRYPTO_RMD128 is not set
1277# CONFIG_CRYPTO_RMD160 is not set
1278# CONFIG_CRYPTO_RMD256 is not set
1279# CONFIG_CRYPTO_RMD320 is not set
1280# CONFIG_CRYPTO_SHA1 is not set
1281# CONFIG_CRYPTO_SHA256 is not set
1282# CONFIG_CRYPTO_SHA512 is not set
1283# CONFIG_CRYPTO_TGR192 is not set
1284# CONFIG_CRYPTO_WP512 is not set
1285
1286#
1287# Ciphers
1288#
1289# CONFIG_CRYPTO_AES is not set
1290# CONFIG_CRYPTO_ANUBIS is not set
1291# CONFIG_CRYPTO_ARC4 is not set
1292# CONFIG_CRYPTO_BLOWFISH is not set
1293# CONFIG_CRYPTO_CAMELLIA is not set
1294# CONFIG_CRYPTO_CAST5 is not set
1295# CONFIG_CRYPTO_CAST6 is not set
1296CONFIG_CRYPTO_DES=y
1297# CONFIG_CRYPTO_FCRYPT is not set
1298# CONFIG_CRYPTO_KHAZAD is not set
1299# CONFIG_CRYPTO_SALSA20 is not set
1300# CONFIG_CRYPTO_SEED is not set
1301# CONFIG_CRYPTO_SERPENT is not set
1302# CONFIG_CRYPTO_TEA is not set
1303# CONFIG_CRYPTO_TWOFISH is not set
1304
1305#
1306# Compression
1307#
1308# CONFIG_CRYPTO_DEFLATE is not set
1309# CONFIG_CRYPTO_LZO is not set
1310
1311#
1312# Random Number Generation
1313#
1314# CONFIG_CRYPTO_ANSI_CPRNG is not set
1315# CONFIG_CRYPTO_HW is not set
1316
1317#
1318# Library routines
1319#
1320CONFIG_BITREVERSE=y
1321CONFIG_GENERIC_FIND_LAST_BIT=y
1322# CONFIG_CRC_CCITT is not set
1323# CONFIG_CRC16 is not set
1324# CONFIG_CRC_T10DIF is not set
1325# CONFIG_CRC_ITU_T is not set
1326CONFIG_CRC32=y
1327# CONFIG_CRC7 is not set
1328# CONFIG_LIBCRC32C is not set
1329CONFIG_PLIST=y
1330CONFIG_HAS_IOMEM=y
1331CONFIG_HAS_IOPORT=y
1332CONFIG_HAS_DMA=y
diff --git a/arch/sh/drivers/dma/Kconfig b/arch/sh/drivers/dma/Kconfig
index 01936368b8b0..f13a05285a9d 100644
--- a/arch/sh/drivers/dma/Kconfig
+++ b/arch/sh/drivers/dma/Kconfig
@@ -9,13 +9,21 @@ config SH_DMA
9 select SH_DMA_API 9 select SH_DMA_API
10 default n 10 default n
11 11
12config SH_DMA_IRQ_MULTI
13 bool
14 depends on SH_DMA
15 default y if CPU_SUBTYPE_SH7750 || CPU_SUBTYPE_SH7751 || \
16 CPU_SUBTYPE_SH7750S || CPU_SUBTYPE_SH7750R || CPU_SUBTYPE_SH7751R || \
17 CPU_SUBTYPE_SH7091 || CPU_SUBTYPE_SH7763 || CPU_SUBTYPE_SH7764 || \
18 CPU_SUBTYPE_SH7780 || CPU_SUBTYPE_SH7785
19
12config NR_ONCHIP_DMA_CHANNELS 20config NR_ONCHIP_DMA_CHANNELS
13 int 21 int
14 depends on SH_DMA 22 depends on SH_DMA
15 default "6" if CPU_SUBTYPE_SH7720 || CPU_SUBTYPE_SH7721 23 default "4" if CPU_SUBTYPE_SH7750 || CPU_SUBTYPE_SH7751 || CPU_SUBTYPE_SH7750S
16 default "8" if CPU_SUBTYPE_SH7750R || CPU_SUBTYPE_SH7751R 24 default "8" if CPU_SUBTYPE_SH7750R || CPU_SUBTYPE_SH7751R || CPU_SUBTYPE_SH7760
17 default "12" if CPU_SUBTYPE_SH7780 25 default "12" if CPU_SUBTYPE_SH7723 || CPU_SUBTYPE_SH7780 || CPU_SUBTYPE_SH7785
18 default "4" 26 default "6"
19 help 27 help
20 This allows you to specify the number of channels that the on-chip 28 This allows you to specify the number of channels that the on-chip
21 DMAC supports. This will be 4 for SH7750/SH7751 and 8 for the 29 DMAC supports. This will be 4 for SH7750/SH7751 and 8 for the
@@ -46,4 +54,28 @@ config SH_DMABRG
46 of the SH7760. 54 of the SH7760.
47 Say Y if you want to use Audio/USB DMA on your SH7760 board. 55 Say Y if you want to use Audio/USB DMA on your SH7760 board.
48 56
57config PVR2_DMA
58 tristate "PowerVR 2 DMAC support"
59 depends on SH_DREAMCAST && SH_DMA
60 help
61 Selecting this will enable support for the PVR2 DMA controller.
62 As this chains off of the on-chip DMAC, that must also be
63 enabled by default.
64
65 This is primarily used by the pvr2fb framebuffer driver for
66 certain optimizations, but is not necessary for functionality.
67
68 If in doubt, say N.
69
70config G2_DMA
71 tristate "G2 Bus DMA support"
72 depends on SH_DREAMCAST
73 select SH_DMA_API
74 help
75 This enables support for the DMA controller for the Dreamcast's
76 G2 bus. Drivers that want this will generally enable this on
77 their own.
78
79 If in doubt, say N.
80
49endmenu 81endmenu
diff --git a/arch/sh/drivers/dma/Makefile b/arch/sh/drivers/dma/Makefile
index ab956adacb47..c6068137b46f 100644
--- a/arch/sh/drivers/dma/Makefile
+++ b/arch/sh/drivers/dma/Makefile
@@ -4,5 +4,6 @@
4 4
5obj-$(CONFIG_SH_DMA_API) += dma-api.o dma-sysfs.o 5obj-$(CONFIG_SH_DMA_API) += dma-api.o dma-sysfs.o
6obj-$(CONFIG_SH_DMA) += dma-sh.o 6obj-$(CONFIG_SH_DMA) += dma-sh.o
7obj-$(CONFIG_SH_DREAMCAST) += dma-pvr2.o dma-g2.o 7obj-$(CONFIG_PVR2_DMA) += dma-pvr2.o
8obj-$(CONFIG_G2_DMA) += dma-g2.o
8obj-$(CONFIG_SH_DMABRG) += dmabrg.o 9obj-$(CONFIG_SH_DMABRG) += dmabrg.o
diff --git a/arch/sh/drivers/dma/dma-sh.c b/arch/sh/drivers/dma/dma-sh.c
index 50887a592dd0..37fb5b8bbc3f 100644
--- a/arch/sh/drivers/dma/dma-sh.c
+++ b/arch/sh/drivers/dma/dma-sh.c
@@ -17,28 +17,16 @@
17#include <mach-dreamcast/mach/dma.h> 17#include <mach-dreamcast/mach/dma.h>
18#include <asm/dma.h> 18#include <asm/dma.h>
19#include <asm/io.h> 19#include <asm/io.h>
20#include "dma-sh.h" 20#include <asm/dma-sh.h>
21 21
22static int dmte_irq_map[] = { 22#if defined(DMAE1_IRQ)
23 DMTE0_IRQ, 23#define NR_DMAE 2
24 DMTE1_IRQ, 24#else
25 DMTE2_IRQ, 25#define NR_DMAE 1
26 DMTE3_IRQ,
27#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
28 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
29 defined(CONFIG_CPU_SUBTYPE_SH7751R) || \
30 defined(CONFIG_CPU_SUBTYPE_SH7760) || \
31 defined(CONFIG_CPU_SUBTYPE_SH7709) || \
32 defined(CONFIG_CPU_SUBTYPE_SH7780)
33 DMTE4_IRQ,
34 DMTE5_IRQ,
35#endif
36#if defined(CONFIG_CPU_SUBTYPE_SH7751R) || \
37 defined(CONFIG_CPU_SUBTYPE_SH7760) || \
38 defined(CONFIG_CPU_SUBTYPE_SH7780)
39 DMTE6_IRQ,
40 DMTE7_IRQ,
41#endif 26#endif
27
28static const char *dmae_name[] = {
29 "DMAC Address Error0", "DMAC Address Error1"
42}; 30};
43 31
44static inline unsigned int get_dmte_irq(unsigned int chan) 32static inline unsigned int get_dmte_irq(unsigned int chan)
@@ -46,7 +34,14 @@ static inline unsigned int get_dmte_irq(unsigned int chan)
46 unsigned int irq = 0; 34 unsigned int irq = 0;
47 if (chan < ARRAY_SIZE(dmte_irq_map)) 35 if (chan < ARRAY_SIZE(dmte_irq_map))
48 irq = dmte_irq_map[chan]; 36 irq = dmte_irq_map[chan];
37
38#if defined(CONFIG_SH_DMA_IRQ_MULTI)
39 if (irq > DMTE6_IRQ)
40 return DMTE6_IRQ;
41 return DMTE0_IRQ;
42#else
49 return irq; 43 return irq;
44#endif
50} 45}
51 46
52/* 47/*
@@ -59,7 +54,7 @@ static inline unsigned int get_dmte_irq(unsigned int chan)
59 */ 54 */
60static inline unsigned int calc_xmit_shift(struct dma_channel *chan) 55static inline unsigned int calc_xmit_shift(struct dma_channel *chan)
61{ 56{
62 u32 chcr = ctrl_inl(CHCR[chan->chan]); 57 u32 chcr = ctrl_inl(dma_base_addr[chan->chan] + CHCR);
63 58
64 return ts_shift[(chcr & CHCR_TS_MASK)>>CHCR_TS_SHIFT]; 59 return ts_shift[(chcr & CHCR_TS_MASK)>>CHCR_TS_SHIFT];
65} 60}
@@ -75,13 +70,13 @@ static irqreturn_t dma_tei(int irq, void *dev_id)
75 struct dma_channel *chan = dev_id; 70 struct dma_channel *chan = dev_id;
76 u32 chcr; 71 u32 chcr;
77 72
78 chcr = ctrl_inl(CHCR[chan->chan]); 73 chcr = ctrl_inl(dma_base_addr[chan->chan] + CHCR);
79 74
80 if (!(chcr & CHCR_TE)) 75 if (!(chcr & CHCR_TE))
81 return IRQ_NONE; 76 return IRQ_NONE;
82 77
83 chcr &= ~(CHCR_IE | CHCR_DE); 78 chcr &= ~(CHCR_IE | CHCR_DE);
84 ctrl_outl(chcr, CHCR[chan->chan]); 79 ctrl_outl(chcr, (dma_base_addr[chan->chan] + CHCR));
85 80
86 wake_up(&chan->wait_queue); 81 wake_up(&chan->wait_queue);
87 82
@@ -94,7 +89,12 @@ static int sh_dmac_request_dma(struct dma_channel *chan)
94 return 0; 89 return 0;
95 90
96 return request_irq(get_dmte_irq(chan->chan), dma_tei, 91 return request_irq(get_dmte_irq(chan->chan), dma_tei,
97 IRQF_DISABLED, chan->dev_id, chan); 92#if defined(CONFIG_SH_DMA_IRQ_MULTI)
93 IRQF_SHARED,
94#else
95 IRQF_DISABLED,
96#endif
97 chan->dev_id, chan);
98} 98}
99 99
100static void sh_dmac_free_dma(struct dma_channel *chan) 100static void sh_dmac_free_dma(struct dma_channel *chan)
@@ -115,7 +115,7 @@ sh_dmac_configure_channel(struct dma_channel *chan, unsigned long chcr)
115 chan->flags &= ~DMA_TEI_CAPABLE; 115 chan->flags &= ~DMA_TEI_CAPABLE;
116 } 116 }
117 117
118 ctrl_outl(chcr, CHCR[chan->chan]); 118 ctrl_outl(chcr, (dma_base_addr[chan->chan] + CHCR));
119 119
120 chan->flags |= DMA_CONFIGURED; 120 chan->flags |= DMA_CONFIGURED;
121 return 0; 121 return 0;
@@ -126,13 +126,13 @@ static void sh_dmac_enable_dma(struct dma_channel *chan)
126 int irq; 126 int irq;
127 u32 chcr; 127 u32 chcr;
128 128
129 chcr = ctrl_inl(CHCR[chan->chan]); 129 chcr = ctrl_inl(dma_base_addr[chan->chan] + CHCR);
130 chcr |= CHCR_DE; 130 chcr |= CHCR_DE;
131 131
132 if (chan->flags & DMA_TEI_CAPABLE) 132 if (chan->flags & DMA_TEI_CAPABLE)
133 chcr |= CHCR_IE; 133 chcr |= CHCR_IE;
134 134
135 ctrl_outl(chcr, CHCR[chan->chan]); 135 ctrl_outl(chcr, (dma_base_addr[chan->chan] + CHCR));
136 136
137 if (chan->flags & DMA_TEI_CAPABLE) { 137 if (chan->flags & DMA_TEI_CAPABLE) {
138 irq = get_dmte_irq(chan->chan); 138 irq = get_dmte_irq(chan->chan);
@@ -150,9 +150,9 @@ static void sh_dmac_disable_dma(struct dma_channel *chan)
150 disable_irq(irq); 150 disable_irq(irq);
151 } 151 }
152 152
153 chcr = ctrl_inl(CHCR[chan->chan]); 153 chcr = ctrl_inl(dma_base_addr[chan->chan] + CHCR);
154 chcr &= ~(CHCR_DE | CHCR_TE | CHCR_IE); 154 chcr &= ~(CHCR_DE | CHCR_TE | CHCR_IE);
155 ctrl_outl(chcr, CHCR[chan->chan]); 155 ctrl_outl(chcr, (dma_base_addr[chan->chan] + CHCR));
156} 156}
157 157
158static int sh_dmac_xfer_dma(struct dma_channel *chan) 158static int sh_dmac_xfer_dma(struct dma_channel *chan)
@@ -183,12 +183,13 @@ static int sh_dmac_xfer_dma(struct dma_channel *chan)
183 */ 183 */
184 if (chan->sar || (mach_is_dreamcast() && 184 if (chan->sar || (mach_is_dreamcast() &&
185 chan->chan == PVR2_CASCADE_CHAN)) 185 chan->chan == PVR2_CASCADE_CHAN))
186 ctrl_outl(chan->sar, SAR[chan->chan]); 186 ctrl_outl(chan->sar, (dma_base_addr[chan->chan]+SAR));
187 if (chan->dar || (mach_is_dreamcast() && 187 if (chan->dar || (mach_is_dreamcast() &&
188 chan->chan == PVR2_CASCADE_CHAN)) 188 chan->chan == PVR2_CASCADE_CHAN))
189 ctrl_outl(chan->dar, DAR[chan->chan]); 189 ctrl_outl(chan->dar, (dma_base_addr[chan->chan] + DAR));
190 190
191 ctrl_outl(chan->count >> calc_xmit_shift(chan), DMATCR[chan->chan]); 191 ctrl_outl(chan->count >> calc_xmit_shift(chan),
192 (dma_base_addr[chan->chan] + TCR));
192 193
193 sh_dmac_enable_dma(chan); 194 sh_dmac_enable_dma(chan);
194 195
@@ -197,36 +198,26 @@ static int sh_dmac_xfer_dma(struct dma_channel *chan)
197 198
198static int sh_dmac_get_dma_residue(struct dma_channel *chan) 199static int sh_dmac_get_dma_residue(struct dma_channel *chan)
199{ 200{
200 if (!(ctrl_inl(CHCR[chan->chan]) & CHCR_DE)) 201 if (!(ctrl_inl(dma_base_addr[chan->chan] + CHCR) & CHCR_DE))
201 return 0; 202 return 0;
202 203
203 return ctrl_inl(DMATCR[chan->chan]) << calc_xmit_shift(chan); 204 return ctrl_inl(dma_base_addr[chan->chan] + TCR)
205 << calc_xmit_shift(chan);
204} 206}
205 207
206#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 208static inline int dmaor_reset(int no)
207 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
208 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
209 defined(CONFIG_CPU_SUBTYPE_SH7709)
210#define dmaor_read_reg() ctrl_inw(DMAOR)
211#define dmaor_write_reg(data) ctrl_outw(data, DMAOR)
212#else
213#define dmaor_read_reg() ctrl_inl(DMAOR)
214#define dmaor_write_reg(data) ctrl_outl(data, DMAOR)
215#endif
216
217static inline int dmaor_reset(void)
218{ 209{
219 unsigned long dmaor = dmaor_read_reg(); 210 unsigned long dmaor = dmaor_read_reg(no);
220 211
221 /* Try to clear the error flags first, incase they are set */ 212 /* Try to clear the error flags first, incase they are set */
222 dmaor &= ~(DMAOR_NMIF | DMAOR_AE); 213 dmaor &= ~(DMAOR_NMIF | DMAOR_AE);
223 dmaor_write_reg(dmaor); 214 dmaor_write_reg(no, dmaor);
224 215
225 dmaor |= DMAOR_INIT; 216 dmaor |= DMAOR_INIT;
226 dmaor_write_reg(dmaor); 217 dmaor_write_reg(no, dmaor);
227 218
228 /* See if we got an error again */ 219 /* See if we got an error again */
229 if ((dmaor_read_reg() & (DMAOR_AE | DMAOR_NMIF))) { 220 if ((dmaor_read_reg(no) & (DMAOR_AE | DMAOR_NMIF))) {
230 printk(KERN_ERR "dma-sh: Can't initialize DMAOR.\n"); 221 printk(KERN_ERR "dma-sh: Can't initialize DMAOR.\n");
231 return -EINVAL; 222 return -EINVAL;
232 } 223 }
@@ -237,10 +228,33 @@ static inline int dmaor_reset(void)
237#if defined(CONFIG_CPU_SH4) 228#if defined(CONFIG_CPU_SH4)
238static irqreturn_t dma_err(int irq, void *dummy) 229static irqreturn_t dma_err(int irq, void *dummy)
239{ 230{
240 dmaor_reset(); 231#if defined(CONFIG_SH_DMA_IRQ_MULTI)
232 int cnt = 0;
233 switch (irq) {
234#if defined(DMTE6_IRQ) && defined(DMAE1_IRQ)
235 case DMTE6_IRQ:
236 cnt++;
237#endif
238 case DMTE0_IRQ:
239 if (dmaor_read_reg(cnt) & (DMAOR_NMIF | DMAOR_AE)) {
240 disable_irq(irq);
241 /* DMA multi and error IRQ */
242 return IRQ_HANDLED;
243 }
244 default:
245 return IRQ_NONE;
246 }
247#else
248 dmaor_reset(0);
249#if defined(CONFIG_CPU_SUBTYPE_SH7723) || \
250 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
251 defined(CONFIG_CPU_SUBTYPE_SH7785)
252 dmaor_reset(1);
253#endif
241 disable_irq(irq); 254 disable_irq(irq);
242 255
243 return IRQ_HANDLED; 256 return IRQ_HANDLED;
257#endif
244} 258}
245#endif 259#endif
246 260
@@ -259,24 +273,59 @@ static struct dma_info sh_dmac_info = {
259 .flags = DMAC_CHANNELS_TEI_CAPABLE, 273 .flags = DMAC_CHANNELS_TEI_CAPABLE,
260}; 274};
261 275
276#ifdef CONFIG_CPU_SH4
277static unsigned int get_dma_error_irq(int n)
278{
279#if defined(CONFIG_SH_DMA_IRQ_MULTI)
280 return (n == 0) ? get_dmte_irq(0) : get_dmte_irq(6);
281#else
282 return (n == 0) ? DMAE0_IRQ :
283#if defined(DMAE1_IRQ)
284 DMAE1_IRQ;
285#else
286 -1;
287#endif
288#endif
289}
290#endif
291
262static int __init sh_dmac_init(void) 292static int __init sh_dmac_init(void)
263{ 293{
264 struct dma_info *info = &sh_dmac_info; 294 struct dma_info *info = &sh_dmac_info;
265 int i; 295 int i;
266 296
267#ifdef CONFIG_CPU_SH4 297#ifdef CONFIG_CPU_SH4
268 i = request_irq(DMAE_IRQ, dma_err, IRQF_DISABLED, "DMAC Address Error", 0); 298 int n;
269 if (unlikely(i < 0)) 299
270 return i; 300 for (n = 0; n < NR_DMAE; n++) {
301 i = request_irq(get_dma_error_irq(n), dma_err,
302#if defined(CONFIG_SH_DMA_IRQ_MULTI)
303 IRQF_SHARED,
304#else
305 IRQF_DISABLED,
271#endif 306#endif
307 dmae_name[n], (void *)dmae_name[n]);
308 if (unlikely(i < 0)) {
309 printk(KERN_ERR "%s request_irq fail\n", dmae_name[n]);
310 return i;
311 }
312 }
313#endif /* CONFIG_CPU_SH4 */
272 314
273 /* 315 /*
274 * Initialize DMAOR, and clean up any error flags that may have 316 * Initialize DMAOR, and clean up any error flags that may have
275 * been set. 317 * been set.
276 */ 318 */
277 i = dmaor_reset(); 319 i = dmaor_reset(0);
320 if (unlikely(i != 0))
321 return i;
322#if defined(CONFIG_CPU_SUBTYPE_SH7723) || \
323 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
324 defined(CONFIG_CPU_SUBTYPE_SH7785)
325 i = dmaor_reset(1);
278 if (unlikely(i != 0)) 326 if (unlikely(i != 0))
279 return i; 327 return i;
328#endif
280 329
281 return register_dmac(info); 330 return register_dmac(info);
282} 331}
@@ -284,8 +333,12 @@ static int __init sh_dmac_init(void)
284static void __exit sh_dmac_exit(void) 333static void __exit sh_dmac_exit(void)
285{ 334{
286#ifdef CONFIG_CPU_SH4 335#ifdef CONFIG_CPU_SH4
287 free_irq(DMAE_IRQ, 0); 336 int n;
288#endif 337
338 for (n = 0; n < NR_DMAE; n++) {
339 free_irq(get_dma_error_irq(n), (void *)dmae_name[n]);
340 }
341#endif /* CONFIG_CPU_SH4 */
289 unregister_dmac(&sh_dmac_info); 342 unregister_dmac(&sh_dmac_info);
290} 343}
291 344
diff --git a/arch/sh/drivers/dma/dma-sh.h b/arch/sh/drivers/dma/dma-sh.h
deleted file mode 100644
index 05fecd5428e4..000000000000
--- a/arch/sh/drivers/dma/dma-sh.h
+++ /dev/null
@@ -1,75 +0,0 @@
1/*
2 * arch/sh/drivers/dma/dma-sh.h
3 *
4 * Copyright (C) 2000 Takashi YOSHII
5 * Copyright (C) 2003 Paul Mundt
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11#ifndef __DMA_SH_H
12#define __DMA_SH_H
13
14#include <cpu/dma.h>
15
16/* Definitions for the SuperH DMAC */
17#define REQ_L 0x00000000
18#define REQ_E 0x00080000
19#define RACK_H 0x00000000
20#define RACK_L 0x00040000
21#define ACK_R 0x00000000
22#define ACK_W 0x00020000
23#define ACK_H 0x00000000
24#define ACK_L 0x00010000
25#define DM_INC 0x00004000
26#define DM_DEC 0x00008000
27#define SM_INC 0x00001000
28#define SM_DEC 0x00002000
29#define RS_IN 0x00000200
30#define RS_OUT 0x00000300
31#define TS_BLK 0x00000040
32#define TM_BUR 0x00000020
33#define CHCR_DE 0x00000001
34#define CHCR_TE 0x00000002
35#define CHCR_IE 0x00000004
36
37/* DMAOR definitions */
38#define DMAOR_AE 0x00000004
39#define DMAOR_NMIF 0x00000002
40#define DMAOR_DME 0x00000001
41
42/*
43 * Define the default configuration for dual address memory-memory transfer.
44 * The 0x400 value represents auto-request, external->external.
45 */
46#define RS_DUAL (DM_INC | SM_INC | 0x400 | TS_32)
47
48#define MAX_DMAC_CHANNELS (CONFIG_NR_ONCHIP_DMA_CHANNELS)
49
50/*
51 * Subtypes that have fewer channels than this simply need to change
52 * CONFIG_NR_ONCHIP_DMA_CHANNELS. Likewise, subtypes with a larger number
53 * of channels should expand on this.
54 *
55 * For most subtypes we can easily figure these values out with some
56 * basic calculation, unfortunately on other subtypes these are more
57 * scattered, so we just leave it unrolled for simplicity.
58 */
59#define SAR ((unsigned long[]){SH_DMAC_BASE + 0x00, SH_DMAC_BASE + 0x10, \
60 SH_DMAC_BASE + 0x20, SH_DMAC_BASE + 0x30, \
61 SH_DMAC_BASE + 0x50, SH_DMAC_BASE + 0x60})
62#define DAR ((unsigned long[]){SH_DMAC_BASE + 0x04, SH_DMAC_BASE + 0x14, \
63 SH_DMAC_BASE + 0x24, SH_DMAC_BASE + 0x34, \
64 SH_DMAC_BASE + 0x54, SH_DMAC_BASE + 0x64})
65#define DMATCR ((unsigned long[]){SH_DMAC_BASE + 0x08, SH_DMAC_BASE + 0x18, \
66 SH_DMAC_BASE + 0x28, SH_DMAC_BASE + 0x38, \
67 SH_DMAC_BASE + 0x58, SH_DMAC_BASE + 0x68})
68#define CHCR ((unsigned long[]){SH_DMAC_BASE + 0x0c, SH_DMAC_BASE + 0x1c, \
69 SH_DMAC_BASE + 0x2c, SH_DMAC_BASE + 0x3c, \
70 SH_DMAC_BASE + 0x5c, SH_DMAC_BASE + 0x6c})
71
72#define DMAOR (SH_DMAC_BASE + 0x40)
73
74#endif /* __DMA_SH_H */
75
diff --git a/arch/sh/drivers/pci/pci-sh7780.c b/arch/sh/drivers/pci/pci-sh7780.c
index 078dc44d6b08..773d575a04b9 100644
--- a/arch/sh/drivers/pci/pci-sh7780.c
+++ b/arch/sh/drivers/pci/pci-sh7780.c
@@ -127,8 +127,8 @@ int __init sh7780_pcic_init(struct sh4_pci_address_map *map)
127 pci_write_reg(word, SH4_PCILSR0); 127 pci_write_reg(word, SH4_PCILSR0);
128 pci_write_reg(0x00000001, SH4_PCILSR1); 128 pci_write_reg(0x00000001, SH4_PCILSR1);
129 /* Set the values on window 0 PCI config registers */ 129 /* Set the values on window 0 PCI config registers */
130 word = (CONFIG_MEMORY_SIZE > 0x08000000) ? 0x10000000 : 0x08000000; 130 word = CONFIG_MEMORY_START | (CONFIG_MEMORY_SIZE - 0x01000000);
131 pci_write_reg(word | 0xa0000000, SH4_PCILAR0); 131 pci_write_reg(word, SH4_PCILAR0);
132 pci_write_reg(word, SH7780_PCIMBAR0); 132 pci_write_reg(word, SH7780_PCIMBAR0);
133 /* Set the values on window 1 PCI config registers */ 133 /* Set the values on window 1 PCI config registers */
134 pci_write_reg(0x00000000, SH4_PCILAR1); 134 pci_write_reg(0x00000000, SH4_PCILAR1);
diff --git a/arch/sh/include/asm/addrspace.h b/arch/sh/include/asm/addrspace.h
index 36736c7e93db..80d40813e057 100644
--- a/arch/sh/include/asm/addrspace.h
+++ b/arch/sh/include/asm/addrspace.h
@@ -31,7 +31,7 @@
31/* Returns the physical address of a PnSEG (n=1,2) address */ 31/* Returns the physical address of a PnSEG (n=1,2) address */
32#define PHYSADDR(a) (((unsigned long)(a)) & 0x1fffffff) 32#define PHYSADDR(a) (((unsigned long)(a)) & 0x1fffffff)
33 33
34#ifdef CONFIG_29BIT 34#if defined(CONFIG_29BIT) || defined(CONFIG_PMB_FIXED)
35/* 35/*
36 * Map an address to a certain privileged segment 36 * Map an address to a certain privileged segment
37 */ 37 */
@@ -43,7 +43,7 @@
43 ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P3SEG)) 43 ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P3SEG))
44#define P4SEGADDR(a) \ 44#define P4SEGADDR(a) \
45 ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P4SEG)) 45 ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P4SEG))
46#endif /* 29BIT */ 46#endif /* 29BIT || PMB_FIXED */
47#endif /* P1SEG */ 47#endif /* P1SEG */
48 48
49/* Check if an address can be reached in 29 bits */ 49/* Check if an address can be reached in 29 bits */
diff --git a/arch/sh/include/asm/atomic-irq.h b/arch/sh/include/asm/atomic-irq.h
index 74f7943cff6f..a0b348068cae 100644
--- a/arch/sh/include/asm/atomic-irq.h
+++ b/arch/sh/include/asm/atomic-irq.h
@@ -11,7 +11,7 @@ static inline void atomic_add(int i, atomic_t *v)
11 unsigned long flags; 11 unsigned long flags;
12 12
13 local_irq_save(flags); 13 local_irq_save(flags);
14 *(long *)v += i; 14 v->counter += i;
15 local_irq_restore(flags); 15 local_irq_restore(flags);
16} 16}
17 17
@@ -20,7 +20,7 @@ static inline void atomic_sub(int i, atomic_t *v)
20 unsigned long flags; 20 unsigned long flags;
21 21
22 local_irq_save(flags); 22 local_irq_save(flags);
23 *(long *)v -= i; 23 v->counter -= i;
24 local_irq_restore(flags); 24 local_irq_restore(flags);
25} 25}
26 26
@@ -29,9 +29,9 @@ static inline int atomic_add_return(int i, atomic_t *v)
29 unsigned long temp, flags; 29 unsigned long temp, flags;
30 30
31 local_irq_save(flags); 31 local_irq_save(flags);
32 temp = *(long *)v; 32 temp = v->counter;
33 temp += i; 33 temp += i;
34 *(long *)v = temp; 34 v->counter = temp;
35 local_irq_restore(flags); 35 local_irq_restore(flags);
36 36
37 return temp; 37 return temp;
@@ -42,9 +42,9 @@ static inline int atomic_sub_return(int i, atomic_t *v)
42 unsigned long temp, flags; 42 unsigned long temp, flags;
43 43
44 local_irq_save(flags); 44 local_irq_save(flags);
45 temp = *(long *)v; 45 temp = v->counter;
46 temp -= i; 46 temp -= i;
47 *(long *)v = temp; 47 v->counter = temp;
48 local_irq_restore(flags); 48 local_irq_restore(flags);
49 49
50 return temp; 50 return temp;
@@ -55,7 +55,7 @@ static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
55 unsigned long flags; 55 unsigned long flags;
56 56
57 local_irq_save(flags); 57 local_irq_save(flags);
58 *(long *)v &= ~mask; 58 v->counter &= ~mask;
59 local_irq_restore(flags); 59 local_irq_restore(flags);
60} 60}
61 61
@@ -64,7 +64,7 @@ static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
64 unsigned long flags; 64 unsigned long flags;
65 65
66 local_irq_save(flags); 66 local_irq_save(flags);
67 *(long *)v |= mask; 67 v->counter |= mask;
68 local_irq_restore(flags); 68 local_irq_restore(flags);
69} 69}
70 70
diff --git a/arch/sh/include/asm/bitops-llsc.h b/arch/sh/include/asm/bitops-llsc.h
index 1d2fc0b010ad..d8328be06191 100644
--- a/arch/sh/include/asm/bitops-llsc.h
+++ b/arch/sh/include/asm/bitops-llsc.h
@@ -1,7 +1,7 @@
1#ifndef __ASM_SH_BITOPS_LLSC_H 1#ifndef __ASM_SH_BITOPS_LLSC_H
2#define __ASM_SH_BITOPS_LLSC_H 2#define __ASM_SH_BITOPS_LLSC_H
3 3
4static inline void set_bit(int nr, volatile void * addr) 4static inline void set_bit(int nr, volatile void *addr)
5{ 5{
6 int mask; 6 int mask;
7 volatile unsigned int *a = addr; 7 volatile unsigned int *a = addr;
@@ -13,16 +13,16 @@ static inline void set_bit(int nr, volatile void * addr)
13 __asm__ __volatile__ ( 13 __asm__ __volatile__ (
14 "1: \n\t" 14 "1: \n\t"
15 "movli.l @%1, %0 ! set_bit \n\t" 15 "movli.l @%1, %0 ! set_bit \n\t"
16 "or %3, %0 \n\t" 16 "or %2, %0 \n\t"
17 "movco.l %0, @%1 \n\t" 17 "movco.l %0, @%1 \n\t"
18 "bf 1b \n\t" 18 "bf 1b \n\t"
19 : "=&z" (tmp), "=r" (a) 19 : "=&z" (tmp)
20 : "1" (a), "r" (mask) 20 : "r" (a), "r" (mask)
21 : "t", "memory" 21 : "t", "memory"
22 ); 22 );
23} 23}
24 24
25static inline void clear_bit(int nr, volatile void * addr) 25static inline void clear_bit(int nr, volatile void *addr)
26{ 26{
27 int mask; 27 int mask;
28 volatile unsigned int *a = addr; 28 volatile unsigned int *a = addr;
@@ -34,16 +34,16 @@ static inline void clear_bit(int nr, volatile void * addr)
34 __asm__ __volatile__ ( 34 __asm__ __volatile__ (
35 "1: \n\t" 35 "1: \n\t"
36 "movli.l @%1, %0 ! clear_bit \n\t" 36 "movli.l @%1, %0 ! clear_bit \n\t"
37 "and %3, %0 \n\t" 37 "and %2, %0 \n\t"
38 "movco.l %0, @%1 \n\t" 38 "movco.l %0, @%1 \n\t"
39 "bf 1b \n\t" 39 "bf 1b \n\t"
40 : "=&z" (tmp), "=r" (a) 40 : "=&z" (tmp)
41 : "1" (a), "r" (~mask) 41 : "r" (a), "r" (~mask)
42 : "t", "memory" 42 : "t", "memory"
43 ); 43 );
44} 44}
45 45
46static inline void change_bit(int nr, volatile void * addr) 46static inline void change_bit(int nr, volatile void *addr)
47{ 47{
48 int mask; 48 int mask;
49 volatile unsigned int *a = addr; 49 volatile unsigned int *a = addr;
@@ -55,16 +55,16 @@ static inline void change_bit(int nr, volatile void * addr)
55 __asm__ __volatile__ ( 55 __asm__ __volatile__ (
56 "1: \n\t" 56 "1: \n\t"
57 "movli.l @%1, %0 ! change_bit \n\t" 57 "movli.l @%1, %0 ! change_bit \n\t"
58 "xor %3, %0 \n\t" 58 "xor %2, %0 \n\t"
59 "movco.l %0, @%1 \n\t" 59 "movco.l %0, @%1 \n\t"
60 "bf 1b \n\t" 60 "bf 1b \n\t"
61 : "=&z" (tmp), "=r" (a) 61 : "=&z" (tmp)
62 : "1" (a), "r" (mask) 62 : "r" (a), "r" (mask)
63 : "t", "memory" 63 : "t", "memory"
64 ); 64 );
65} 65}
66 66
67static inline int test_and_set_bit(int nr, volatile void * addr) 67static inline int test_and_set_bit(int nr, volatile void *addr)
68{ 68{
69 int mask, retval; 69 int mask, retval;
70 volatile unsigned int *a = addr; 70 volatile unsigned int *a = addr;
@@ -75,21 +75,21 @@ static inline int test_and_set_bit(int nr, volatile void * addr)
75 75
76 __asm__ __volatile__ ( 76 __asm__ __volatile__ (
77 "1: \n\t" 77 "1: \n\t"
78 "movli.l @%1, %0 ! test_and_set_bit \n\t" 78 "movli.l @%2, %0 ! test_and_set_bit \n\t"
79 "mov %0, %2 \n\t" 79 "mov %0, %1 \n\t"
80 "or %4, %0 \n\t" 80 "or %3, %0 \n\t"
81 "movco.l %0, @%1 \n\t" 81 "movco.l %0, @%2 \n\t"
82 "bf 1b \n\t" 82 "bf 1b \n\t"
83 "and %4, %2 \n\t" 83 "and %3, %1 \n\t"
84 : "=&z" (tmp), "=r" (a), "=&r" (retval) 84 : "=&z" (tmp), "=&r" (retval)
85 : "1" (a), "r" (mask) 85 : "r" (a), "r" (mask)
86 : "t", "memory" 86 : "t", "memory"
87 ); 87 );
88 88
89 return retval != 0; 89 return retval != 0;
90} 90}
91 91
92static inline int test_and_clear_bit(int nr, volatile void * addr) 92static inline int test_and_clear_bit(int nr, volatile void *addr)
93{ 93{
94 int mask, retval; 94 int mask, retval;
95 volatile unsigned int *a = addr; 95 volatile unsigned int *a = addr;
@@ -100,22 +100,22 @@ static inline int test_and_clear_bit(int nr, volatile void * addr)
100 100
101 __asm__ __volatile__ ( 101 __asm__ __volatile__ (
102 "1: \n\t" 102 "1: \n\t"
103 "movli.l @%1, %0 ! test_and_clear_bit \n\t" 103 "movli.l @%2, %0 ! test_and_clear_bit \n\t"
104 "mov %0, %2 \n\t" 104 "mov %0, %1 \n\t"
105 "and %5, %0 \n\t" 105 "and %4, %0 \n\t"
106 "movco.l %0, @%1 \n\t" 106 "movco.l %0, @%2 \n\t"
107 "bf 1b \n\t" 107 "bf 1b \n\t"
108 "and %4, %2 \n\t" 108 "and %3, %1 \n\t"
109 "synco \n\t" 109 "synco \n\t"
110 : "=&z" (tmp), "=r" (a), "=&r" (retval) 110 : "=&z" (tmp), "=&r" (retval)
111 : "1" (a), "r" (mask), "r" (~mask) 111 : "r" (a), "r" (mask), "r" (~mask)
112 : "t", "memory" 112 : "t", "memory"
113 ); 113 );
114 114
115 return retval != 0; 115 return retval != 0;
116} 116}
117 117
118static inline int test_and_change_bit(int nr, volatile void * addr) 118static inline int test_and_change_bit(int nr, volatile void *addr)
119{ 119{
120 int mask, retval; 120 int mask, retval;
121 volatile unsigned int *a = addr; 121 volatile unsigned int *a = addr;
@@ -126,15 +126,15 @@ static inline int test_and_change_bit(int nr, volatile void * addr)
126 126
127 __asm__ __volatile__ ( 127 __asm__ __volatile__ (
128 "1: \n\t" 128 "1: \n\t"
129 "movli.l @%1, %0 ! test_and_change_bit \n\t" 129 "movli.l @%2, %0 ! test_and_change_bit \n\t"
130 "mov %0, %2 \n\t" 130 "mov %0, %1 \n\t"
131 "xor %4, %0 \n\t" 131 "xor %3, %0 \n\t"
132 "movco.l %0, @%1 \n\t" 132 "movco.l %0, @%2 \n\t"
133 "bf 1b \n\t" 133 "bf 1b \n\t"
134 "and %4, %2 \n\t" 134 "and %3, %1 \n\t"
135 "synco \n\t" 135 "synco \n\t"
136 : "=&z" (tmp), "=r" (a), "=&r" (retval) 136 : "=&z" (tmp), "=&r" (retval)
137 : "1" (a), "r" (mask) 137 : "r" (a), "r" (mask)
138 : "t", "memory" 138 : "t", "memory"
139 ); 139 );
140 140
diff --git a/arch/sh/include/asm/clock.h b/arch/sh/include/asm/clock.h
index f9c88583d90a..2f6c9627bc1f 100644
--- a/arch/sh/include/asm/clock.h
+++ b/arch/sh/include/asm/clock.h
@@ -15,6 +15,7 @@ struct clk_ops {
15 void (*disable)(struct clk *clk); 15 void (*disable)(struct clk *clk);
16 void (*recalc)(struct clk *clk); 16 void (*recalc)(struct clk *clk);
17 int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id); 17 int (*set_rate)(struct clk *clk, unsigned long rate, int algo_id);
18 int (*set_parent)(struct clk *clk, struct clk *parent);
18 long (*round_rate)(struct clk *clk, unsigned long rate); 19 long (*round_rate)(struct clk *clk, unsigned long rate);
19}; 20};
20 21
diff --git a/arch/sh/include/asm/cmpxchg-llsc.h b/arch/sh/include/asm/cmpxchg-llsc.h
index aee3bf286581..0fac3da536ca 100644
--- a/arch/sh/include/asm/cmpxchg-llsc.h
+++ b/arch/sh/include/asm/cmpxchg-llsc.h
@@ -8,14 +8,14 @@ static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
8 8
9 __asm__ __volatile__ ( 9 __asm__ __volatile__ (
10 "1: \n\t" 10 "1: \n\t"
11 "movli.l @%1, %0 ! xchg_u32 \n\t" 11 "movli.l @%2, %0 ! xchg_u32 \n\t"
12 "mov %0, %2 \n\t" 12 "mov %0, %1 \n\t"
13 "mov %4, %0 \n\t" 13 "mov %3, %0 \n\t"
14 "movco.l %0, @%1 \n\t" 14 "movco.l %0, @%2 \n\t"
15 "bf 1b \n\t" 15 "bf 1b \n\t"
16 "synco \n\t" 16 "synco \n\t"
17 : "=&z"(tmp), "=r" (m), "=&r" (retval) 17 : "=&z"(tmp), "=&r" (retval)
18 : "1" (m), "r" (val) 18 : "r" (m), "r" (val)
19 : "t", "memory" 19 : "t", "memory"
20 ); 20 );
21 21
@@ -29,14 +29,14 @@ static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val)
29 29
30 __asm__ __volatile__ ( 30 __asm__ __volatile__ (
31 "1: \n\t" 31 "1: \n\t"
32 "movli.l @%1, %0 ! xchg_u8 \n\t" 32 "movli.l @%2, %0 ! xchg_u8 \n\t"
33 "mov %0, %2 \n\t" 33 "mov %0, %1 \n\t"
34 "mov %4, %0 \n\t" 34 "mov %3, %0 \n\t"
35 "movco.l %0, @%1 \n\t" 35 "movco.l %0, @%2 \n\t"
36 "bf 1b \n\t" 36 "bf 1b \n\t"
37 "synco \n\t" 37 "synco \n\t"
38 : "=&z"(tmp), "=r" (m), "=&r" (retval) 38 : "=&z"(tmp), "=&r" (retval)
39 : "1" (m), "r" (val & 0xff) 39 : "r" (m), "r" (val & 0xff)
40 : "t", "memory" 40 : "t", "memory"
41 ); 41 );
42 42
@@ -51,17 +51,17 @@ __cmpxchg_u32(volatile int *m, unsigned long old, unsigned long new)
51 51
52 __asm__ __volatile__ ( 52 __asm__ __volatile__ (
53 "1: \n\t" 53 "1: \n\t"
54 "movli.l @%1, %0 ! __cmpxchg_u32 \n\t" 54 "movli.l @%2, %0 ! __cmpxchg_u32 \n\t"
55 "mov %0, %2 \n\t" 55 "mov %0, %1 \n\t"
56 "cmp/eq %2, %4 \n\t" 56 "cmp/eq %1, %3 \n\t"
57 "bf 2f \n\t" 57 "bf 2f \n\t"
58 "mov %5, %0 \n\t" 58 "mov %3, %0 \n\t"
59 "2: \n\t" 59 "2: \n\t"
60 "movco.l %0, @%1 \n\t" 60 "movco.l %0, @%2 \n\t"
61 "bf 1b \n\t" 61 "bf 1b \n\t"
62 "synco \n\t" 62 "synco \n\t"
63 : "=&z" (tmp), "=r" (m), "=&r" (retval) 63 : "=&z" (tmp), "=&r" (retval)
64 : "1" (m), "r" (old), "r" (new) 64 : "r" (m), "r" (old), "r" (new)
65 : "t", "memory" 65 : "t", "memory"
66 ); 66 );
67 67
diff --git a/arch/sh/include/asm/cpu-features.h b/arch/sh/include/asm/cpu-features.h
index 86308aa39731..694abe490edb 100644
--- a/arch/sh/include/asm/cpu-features.h
+++ b/arch/sh/include/asm/cpu-features.h
@@ -21,5 +21,6 @@
21#define CPU_HAS_LLSC 0x0040 /* movli.l/movco.l */ 21#define CPU_HAS_LLSC 0x0040 /* movli.l/movco.l */
22#define CPU_HAS_L2_CACHE 0x0080 /* Secondary cache / URAM */ 22#define CPU_HAS_L2_CACHE 0x0080 /* Secondary cache / URAM */
23#define CPU_HAS_OP32 0x0100 /* 32-bit instruction support */ 23#define CPU_HAS_OP32 0x0100 /* 32-bit instruction support */
24#define CPU_HAS_PTEAEX 0x0200 /* PTE ASID Extension support */
24 25
25#endif /* __ASM_SH_CPU_FEATURES_H */ 26#endif /* __ASM_SH_CPU_FEATURES_H */
diff --git a/arch/sh/include/asm/dma-sh.h b/arch/sh/include/asm/dma-sh.h
new file mode 100644
index 000000000000..0c8f8e14622a
--- /dev/null
+++ b/arch/sh/include/asm/dma-sh.h
@@ -0,0 +1,118 @@
1/*
2 * arch/sh/include/asm/dma-sh.h
3 *
4 * Copyright (C) 2000 Takashi YOSHII
5 * Copyright (C) 2003 Paul Mundt
6 *
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
9 * for more details.
10 */
11#ifndef __DMA_SH_H
12#define __DMA_SH_H
13
14#include <asm/dma.h>
15#include <cpu/dma.h>
16
17/* DMAOR contorl: The DMAOR access size is different by CPU.*/
18#if defined(CONFIG_CPU_SUBTYPE_SH7723) || \
19 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
20 defined(CONFIG_CPU_SUBTYPE_SH7785)
21#define dmaor_read_reg(n) \
22 (n ? ctrl_inw(SH_DMAC_BASE1 + DMAOR) \
23 : ctrl_inw(SH_DMAC_BASE0 + DMAOR))
24#define dmaor_write_reg(n, data) \
25 (n ? ctrl_outw(data, SH_DMAC_BASE1 + DMAOR) \
26 : ctrl_outw(data, SH_DMAC_BASE0 + DMAOR))
27#else /* Other CPU */
28#define dmaor_read_reg(n) ctrl_inw(SH_DMAC_BASE0 + DMAOR)
29#define dmaor_write_reg(n, data) ctrl_outw(data, SH_DMAC_BASE0 + DMAOR)
30#endif
31
32static int dmte_irq_map[] __maybe_unused = {
33#if (MAX_DMA_CHANNELS >= 4)
34 DMTE0_IRQ,
35 DMTE0_IRQ + 1,
36 DMTE0_IRQ + 2,
37 DMTE0_IRQ + 3,
38#endif
39#if (MAX_DMA_CHANNELS >= 6)
40 DMTE4_IRQ,
41 DMTE4_IRQ + 1,
42#endif
43#if (MAX_DMA_CHANNELS >= 8)
44 DMTE6_IRQ,
45 DMTE6_IRQ + 1,
46#endif
47#if (MAX_DMA_CHANNELS >= 12)
48 DMTE8_IRQ,
49 DMTE9_IRQ,
50 DMTE10_IRQ,
51 DMTE11_IRQ,
52#endif
53};
54
55/* Definitions for the SuperH DMAC */
56#define REQ_L 0x00000000
57#define REQ_E 0x00080000
58#define RACK_H 0x00000000
59#define RACK_L 0x00040000
60#define ACK_R 0x00000000
61#define ACK_W 0x00020000
62#define ACK_H 0x00000000
63#define ACK_L 0x00010000
64#define DM_INC 0x00004000
65#define DM_DEC 0x00008000
66#define SM_INC 0x00001000
67#define SM_DEC 0x00002000
68#define RS_IN 0x00000200
69#define RS_OUT 0x00000300
70#define TS_BLK 0x00000040
71#define TM_BUR 0x00000020
72#define CHCR_DE 0x00000001
73#define CHCR_TE 0x00000002
74#define CHCR_IE 0x00000004
75
76/* DMAOR definitions */
77#define DMAOR_AE 0x00000004
78#define DMAOR_NMIF 0x00000002
79#define DMAOR_DME 0x00000001
80
81/*
82 * Define the default configuration for dual address memory-memory transfer.
83 * The 0x400 value represents auto-request, external->external.
84 */
85#define RS_DUAL (DM_INC | SM_INC | 0x400 | TS_32)
86
87/* DMA base address */
88static u32 dma_base_addr[] __maybe_unused = {
89#if (MAX_DMA_CHANNELS >= 4)
90 SH_DMAC_BASE0 + 0x00, /* channel 0 */
91 SH_DMAC_BASE0 + 0x10,
92 SH_DMAC_BASE0 + 0x20,
93 SH_DMAC_BASE0 + 0x30,
94#endif
95#if (MAX_DMA_CHANNELS >= 6)
96 SH_DMAC_BASE0 + 0x50,
97 SH_DMAC_BASE0 + 0x60,
98#endif
99#if (MAX_DMA_CHANNELS >= 8)
100 SH_DMAC_BASE1 + 0x00,
101 SH_DMAC_BASE1 + 0x10,
102#endif
103#if (MAX_DMA_CHANNELS >= 12)
104 SH_DMAC_BASE1 + 0x20,
105 SH_DMAC_BASE1 + 0x30,
106 SH_DMAC_BASE1 + 0x50,
107 SH_DMAC_BASE1 + 0x60, /* channel 11 */
108#endif
109};
110
111/* DMA register */
112#define SAR 0x00
113#define DAR 0x04
114#define TCR 0x08
115#define CHCR 0x0C
116#define DMAOR 0x40
117
118#endif /* __DMA_SH_H */
diff --git a/arch/sh/include/asm/dma.h b/arch/sh/include/asm/dma.h
index beca7128e2ab..6bd178473878 100644
--- a/arch/sh/include/asm/dma.h
+++ b/arch/sh/include/asm/dma.h
@@ -25,9 +25,9 @@
25#define MAX_DMA_ADDRESS (PAGE_OFFSET+0x10000000) 25#define MAX_DMA_ADDRESS (PAGE_OFFSET+0x10000000)
26 26
27#ifdef CONFIG_NR_DMA_CHANNELS 27#ifdef CONFIG_NR_DMA_CHANNELS
28# define MAX_DMA_CHANNELS (CONFIG_NR_DMA_CHANNELS) 28# define MAX_DMA_CHANNELS (CONFIG_NR_DMA_CHANNELS)
29#else 29#else
30# define MAX_DMA_CHANNELS (CONFIG_NR_ONCHIP_DMA_CHANNELS) 30# define MAX_DMA_CHANNELS (CONFIG_NR_ONCHIP_DMA_CHANNELS)
31#endif 31#endif
32 32
33/* 33/*
diff --git a/arch/sh/include/asm/entry-macros.S b/arch/sh/include/asm/entry-macros.S
index 2dab0b8d9454..3a4752a65722 100644
--- a/arch/sh/include/asm/entry-macros.S
+++ b/arch/sh/include/asm/entry-macros.S
@@ -31,3 +31,8 @@
31#endif 31#endif
32 .endm 32 .endm
33 33
34#if defined(CONFIG_CPU_SH2A) || defined(CONFIG_CPU_SH4)
35# define PREF(x) pref @x
36#else
37# define PREF(x) nop
38#endif
diff --git a/arch/sh/include/asm/gpio.h b/arch/sh/include/asm/gpio.h
index 90673658eb14..61f93da2c62e 100644
--- a/arch/sh/include/asm/gpio.h
+++ b/arch/sh/include/asm/gpio.h
@@ -19,8 +19,42 @@
19#include <cpu/gpio.h> 19#include <cpu/gpio.h>
20#endif 20#endif
21 21
22#define ARCH_NR_GPIOS 512
23#include <asm-generic/gpio.h>
24
25#ifdef CONFIG_GPIOLIB
26
27static inline int gpio_get_value(unsigned gpio)
28{
29 return __gpio_get_value(gpio);
30}
31
32static inline void gpio_set_value(unsigned gpio, int value)
33{
34 __gpio_set_value(gpio, value);
35}
36
37static inline int gpio_cansleep(unsigned gpio)
38{
39 return __gpio_cansleep(gpio);
40}
41
42static inline int gpio_to_irq(unsigned gpio)
43{
44 WARN_ON(1);
45 return -ENOSYS;
46}
47
48static inline int irq_to_gpio(unsigned int irq)
49{
50 WARN_ON(1);
51 return -EINVAL;
52}
53
54#endif /* CONFIG_GPIOLIB */
55
22typedef unsigned short pinmux_enum_t; 56typedef unsigned short pinmux_enum_t;
23typedef unsigned char pinmux_flag_t; 57typedef unsigned short pinmux_flag_t;
24 58
25#define PINMUX_TYPE_NONE 0 59#define PINMUX_TYPE_NONE 0
26#define PINMUX_TYPE_FUNCTION 1 60#define PINMUX_TYPE_FUNCTION 1
@@ -34,6 +68,11 @@ typedef unsigned char pinmux_flag_t;
34#define PINMUX_FLAG_WANT_PULLUP (1 << 3) 68#define PINMUX_FLAG_WANT_PULLUP (1 << 3)
35#define PINMUX_FLAG_WANT_PULLDOWN (1 << 4) 69#define PINMUX_FLAG_WANT_PULLDOWN (1 << 4)
36 70
71#define PINMUX_FLAG_DBIT_SHIFT 5
72#define PINMUX_FLAG_DBIT (0x1f << PINMUX_FLAG_DBIT_SHIFT)
73#define PINMUX_FLAG_DREG_SHIFT 10
74#define PINMUX_FLAG_DREG (0x3f << PINMUX_FLAG_DREG_SHIFT)
75
37struct pinmux_gpio { 76struct pinmux_gpio {
38 pinmux_enum_t enum_id; 77 pinmux_enum_t enum_id;
39 pinmux_flag_t flags; 78 pinmux_flag_t flags;
@@ -54,7 +93,7 @@ struct pinmux_cfg_reg {
54 .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)]) \ 93 .enum_ids = (pinmux_enum_t [(r_width / f_width) * (1 << f_width)]) \
55 94
56struct pinmux_data_reg { 95struct pinmux_data_reg {
57 unsigned long reg, reg_width; 96 unsigned long reg, reg_width, reg_shadow;
58 pinmux_enum_t *enum_ids; 97 pinmux_enum_t *enum_ids;
59}; 98};
60 99
@@ -89,34 +128,9 @@ struct pinmux_info {
89 unsigned int gpio_data_size; 128 unsigned int gpio_data_size;
90 129
91 unsigned long *gpio_in_use; 130 unsigned long *gpio_in_use;
131 struct gpio_chip chip;
92}; 132};
93 133
94int register_pinmux(struct pinmux_info *pip); 134int register_pinmux(struct pinmux_info *pip);
95 135
96int __gpio_request(unsigned gpio);
97static inline int gpio_request(unsigned gpio, const char *label)
98{
99 return __gpio_request(gpio);
100}
101void gpio_free(unsigned gpio);
102int gpio_direction_input(unsigned gpio);
103int gpio_direction_output(unsigned gpio, int value);
104int gpio_get_value(unsigned gpio);
105void gpio_set_value(unsigned gpio, int value);
106
107/* IRQ modes are unspported */
108static inline int gpio_to_irq(unsigned gpio)
109{
110 WARN_ON(1);
111 return -EINVAL;
112}
113
114static inline int irq_to_gpio(unsigned irq)
115{
116 WARN_ON(1);
117 return -EINVAL;
118}
119
120#include <asm-generic/gpio.h>
121
122#endif /* __ASM_SH_GPIO_H */ 136#endif /* __ASM_SH_GPIO_H */
diff --git a/arch/sh/include/asm/hd64461.h b/arch/sh/include/asm/hd64461.h
index 8c1353baf00f..52b4b6238277 100644
--- a/arch/sh/include/asm/hd64461.h
+++ b/arch/sh/include/asm/hd64461.h
@@ -242,7 +242,6 @@
242#include <asm/io_generic.h> 242#include <asm/io_generic.h>
243 243
244/* arch/sh/cchips/hd6446x/hd64461/setup.c */ 244/* arch/sh/cchips/hd6446x/hd64461/setup.c */
245int hd64461_irq_demux(int irq);
246void hd64461_register_irq_demux(int irq, 245void hd64461_register_irq_demux(int irq,
247 int (*demux) (int irq, void *dev), void *dev); 246 int (*demux) (int irq, void *dev), void *dev);
248void hd64461_unregister_irq_demux(int irq); 247void hd64461_unregister_irq_demux(int irq);
diff --git a/arch/sh/include/asm/io.h b/arch/sh/include/asm/io.h
index 61f6dae40534..0454f8d68059 100644
--- a/arch/sh/include/asm/io.h
+++ b/arch/sh/include/asm/io.h
@@ -238,7 +238,7 @@ extern void onchip_unmap(unsigned long vaddr);
238static inline void __iomem * 238static inline void __iomem *
239__ioremap_mode(unsigned long offset, unsigned long size, unsigned long flags) 239__ioremap_mode(unsigned long offset, unsigned long size, unsigned long flags)
240{ 240{
241#ifdef CONFIG_SUPERH32 241#if defined(CONFIG_SUPERH32) && !defined(CONFIG_PMB_FIXED)
242 unsigned long last_addr = offset + size - 1; 242 unsigned long last_addr = offset + size - 1;
243#endif 243#endif
244 void __iomem *ret; 244 void __iomem *ret;
@@ -247,7 +247,7 @@ __ioremap_mode(unsigned long offset, unsigned long size, unsigned long flags)
247 if (ret) 247 if (ret)
248 return ret; 248 return ret;
249 249
250#ifdef CONFIG_SUPERH32 250#if defined(CONFIG_SUPERH32) && !defined(CONFIG_PMB_FIXED)
251 /* 251 /*
252 * For P1 and P2 space this is trivial, as everything is already 252 * For P1 and P2 space this is trivial, as everything is already
253 * mapped. Uncached access for P1 addresses are done through P2. 253 * mapped. Uncached access for P1 addresses are done through P2.
diff --git a/arch/sh/include/asm/kprobes.h b/arch/sh/include/asm/kprobes.h
index 6078d8e551d4..613644a758e8 100644
--- a/arch/sh/include/asm/kprobes.h
+++ b/arch/sh/include/asm/kprobes.h
@@ -16,7 +16,7 @@ typedef u16 kprobe_opcode_t;
16 ? (MAX_STACK_SIZE) \ 16 ? (MAX_STACK_SIZE) \
17 : (((unsigned long)current_thread_info()) + THREAD_SIZE - (ADDR))) 17 : (((unsigned long)current_thread_info()) + THREAD_SIZE - (ADDR)))
18 18
19#define regs_return_value(regs) ((regs)->regs[0]) 19#define regs_return_value(_regs) ((_regs)->regs[0])
20#define flush_insn_slot(p) do { } while (0) 20#define flush_insn_slot(p) do { } while (0)
21#define kretprobe_blacklist_size 0 21#define kretprobe_blacklist_size 0
22 22
diff --git a/arch/sh/include/asm/mmu_context.h b/arch/sh/include/asm/mmu_context.h
index 5d9157bd474d..2a9c55f1a83f 100644
--- a/arch/sh/include/asm/mmu_context.h
+++ b/arch/sh/include/asm/mmu_context.h
@@ -19,13 +19,18 @@
19 * (a) TLB cache version (or round, cycle whatever expression you like) 19 * (a) TLB cache version (or round, cycle whatever expression you like)
20 * (b) ASID (Address Space IDentifier) 20 * (b) ASID (Address Space IDentifier)
21 */ 21 */
22#ifdef CONFIG_CPU_HAS_PTEAEX
23#define MMU_CONTEXT_ASID_MASK 0x0000ffff
24#else
22#define MMU_CONTEXT_ASID_MASK 0x000000ff 25#define MMU_CONTEXT_ASID_MASK 0x000000ff
23#define MMU_CONTEXT_VERSION_MASK 0xffffff00 26#endif
24#define MMU_CONTEXT_FIRST_VERSION 0x00000100
25#define NO_CONTEXT 0UL
26 27
27/* ASID is 8-bit value, so it can't be 0x100 */ 28#define MMU_CONTEXT_VERSION_MASK (~0UL & ~MMU_CONTEXT_ASID_MASK)
28#define MMU_NO_ASID 0x100 29#define MMU_CONTEXT_FIRST_VERSION (MMU_CONTEXT_ASID_MASK + 1)
30
31/* Impossible ASID value, to differentiate from NO_CONTEXT. */
32#define MMU_NO_ASID MMU_CONTEXT_FIRST_VERSION
33#define NO_CONTEXT 0UL
29 34
30#define asid_cache(cpu) (cpu_data[cpu].asid_cache) 35#define asid_cache(cpu) (cpu_data[cpu].asid_cache)
31 36
diff --git a/arch/sh/include/asm/mmu_context_32.h b/arch/sh/include/asm/mmu_context_32.h
index f4f9aebd68b7..8ef800c549ab 100644
--- a/arch/sh/include/asm/mmu_context_32.h
+++ b/arch/sh/include/asm/mmu_context_32.h
@@ -10,6 +10,17 @@ static inline void destroy_context(struct mm_struct *mm)
10 /* Do nothing */ 10 /* Do nothing */
11} 11}
12 12
13#ifdef CONFIG_CPU_HAS_PTEAEX
14static inline void set_asid(unsigned long asid)
15{
16 __raw_writel(asid, MMU_PTEAEX);
17}
18
19static inline unsigned long get_asid(void)
20{
21 return __raw_readl(MMU_PTEAEX) & MMU_CONTEXT_ASID_MASK;
22}
23#else
13static inline void set_asid(unsigned long asid) 24static inline void set_asid(unsigned long asid)
14{ 25{
15 unsigned long __dummy; 26 unsigned long __dummy;
@@ -33,6 +44,7 @@ static inline unsigned long get_asid(void)
33 asid &= MMU_CONTEXT_ASID_MASK; 44 asid &= MMU_CONTEXT_ASID_MASK;
34 return asid; 45 return asid;
35} 46}
47#endif /* CONFIG_CPU_HAS_PTEAEX */
36 48
37/* MMU_TTB is used for optimizing the fault handling. */ 49/* MMU_TTB is used for optimizing the fault handling. */
38static inline void set_TTB(pgd_t *pgd) 50static inline void set_TTB(pgd_t *pgd)
diff --git a/arch/sh/include/asm/page.h b/arch/sh/include/asm/page.h
index 5871d78e47e5..9c6d21ec0240 100644
--- a/arch/sh/include/asm/page.h
+++ b/arch/sh/include/asm/page.h
@@ -129,7 +129,12 @@ typedef struct page *pgtable_t;
129 * is not visible (it is part of the PMB mapping) and so needs to be 129 * is not visible (it is part of the PMB mapping) and so needs to be
130 * added or subtracted as required. 130 * added or subtracted as required.
131 */ 131 */
132#ifdef CONFIG_32BIT 132#if defined(CONFIG_PMB_FIXED)
133/* phys = virt - PAGE_OFFSET - (__MEMORY_START & 0xe0000000) */
134#define PMB_OFFSET (PAGE_OFFSET - PXSEG(__MEMORY_START))
135#define __pa(x) ((unsigned long)(x) - PMB_OFFSET)
136#define __va(x) ((void *)((unsigned long)(x) + PMB_OFFSET))
137#elif defined(CONFIG_32BIT)
133#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET+__MEMORY_START) 138#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET+__MEMORY_START)
134#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET-__MEMORY_START)) 139#define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET-__MEMORY_START))
135#else 140#else
diff --git a/arch/sh/include/asm/processor.h b/arch/sh/include/asm/processor.h
index 1ef4b24d7619..1fd58b421438 100644
--- a/arch/sh/include/asm/processor.h
+++ b/arch/sh/include/asm/processor.h
@@ -31,7 +31,7 @@ enum cpu_type {
31 CPU_SH7760, CPU_SH4_202, CPU_SH4_501, 31 CPU_SH7760, CPU_SH4_202, CPU_SH4_501,
32 32
33 /* SH-4A types */ 33 /* SH-4A types */
34 CPU_SH7763, CPU_SH7770, CPU_SH7780, CPU_SH7781, CPU_SH7785, 34 CPU_SH7763, CPU_SH7770, CPU_SH7780, CPU_SH7781, CPU_SH7785, CPU_SH7786,
35 CPU_SH7723, CPU_SHX3, 35 CPU_SH7723, CPU_SHX3,
36 36
37 /* SH4AL-DSP types */ 37 /* SH4AL-DSP types */
diff --git a/arch/sh/include/asm/processor_32.h b/arch/sh/include/asm/processor_32.h
index d79063c5eb9c..efdd78a53b11 100644
--- a/arch/sh/include/asm/processor_32.h
+++ b/arch/sh/include/asm/processor_32.h
@@ -108,12 +108,12 @@ extern int ubc_usercnt;
108/* 108/*
109 * Do necessary setup to start up a newly executed thread. 109 * Do necessary setup to start up a newly executed thread.
110 */ 110 */
111#define start_thread(regs, new_pc, new_sp) \ 111#define start_thread(_regs, new_pc, new_sp) \
112 set_fs(USER_DS); \ 112 set_fs(USER_DS); \
113 regs->pr = 0; \ 113 _regs->pr = 0; \
114 regs->sr = SR_FD; /* User mode. */ \ 114 _regs->sr = SR_FD; /* User mode. */ \
115 regs->pc = new_pc; \ 115 _regs->pc = new_pc; \
116 regs->regs[15] = new_sp 116 _regs->regs[15] = new_sp
117 117
118/* Forward declaration, a strange C thing */ 118/* Forward declaration, a strange C thing */
119struct task_struct; 119struct task_struct;
@@ -189,10 +189,9 @@ extern unsigned long get_wchan(struct task_struct *p);
189#define KSTK_EIP(tsk) (task_pt_regs(tsk)->pc) 189#define KSTK_EIP(tsk) (task_pt_regs(tsk)->pc)
190#define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[15]) 190#define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[15])
191 191
192#define user_stack_pointer(regs) ((regs)->regs[15]) 192#define user_stack_pointer(_regs) ((_regs)->regs[15])
193 193
194#if defined(CONFIG_CPU_SH2A) || defined(CONFIG_CPU_SH3) || \ 194#if defined(CONFIG_CPU_SH2A) || defined(CONFIG_CPU_SH4)
195 defined(CONFIG_CPU_SH4)
196#define PREFETCH_STRIDE L1_CACHE_BYTES 195#define PREFETCH_STRIDE L1_CACHE_BYTES
197#define ARCH_HAS_PREFETCH 196#define ARCH_HAS_PREFETCH
198#define ARCH_HAS_PREFETCHW 197#define ARCH_HAS_PREFETCHW
diff --git a/arch/sh/include/asm/processor_64.h b/arch/sh/include/asm/processor_64.h
index 803177fcf086..5727d31b0ccf 100644
--- a/arch/sh/include/asm/processor_64.h
+++ b/arch/sh/include/asm/processor_64.h
@@ -145,13 +145,13 @@ struct thread_struct {
145 */ 145 */
146#define SR_USER (SR_MMU | SR_FD) 146#define SR_USER (SR_MMU | SR_FD)
147 147
148#define start_thread(regs, new_pc, new_sp) \ 148#define start_thread(_regs, new_pc, new_sp) \
149 set_fs(USER_DS); \ 149 set_fs(USER_DS); \
150 regs->sr = SR_USER; /* User mode. */ \ 150 _regs->sr = SR_USER; /* User mode. */ \
151 regs->pc = new_pc - 4; /* Compensate syscall exit */ \ 151 _regs->pc = new_pc - 4; /* Compensate syscall exit */ \
152 regs->pc |= 1; /* Set SHmedia ! */ \ 152 _regs->pc |= 1; /* Set SHmedia ! */ \
153 regs->regs[18] = 0; \ 153 _regs->regs[18] = 0; \
154 regs->regs[15] = new_sp 154 _regs->regs[15] = new_sp
155 155
156/* Forward declaration, a strange C thing */ 156/* Forward declaration, a strange C thing */
157struct task_struct; 157struct task_struct;
@@ -226,7 +226,7 @@ extern unsigned long get_wchan(struct task_struct *p);
226#define KSTK_EIP(tsk) ((tsk)->thread.pc) 226#define KSTK_EIP(tsk) ((tsk)->thread.pc)
227#define KSTK_ESP(tsk) ((tsk)->thread.sp) 227#define KSTK_ESP(tsk) ((tsk)->thread.sp)
228 228
229#define user_stack_pointer(regs) ((regs)->regs[15]) 229#define user_stack_pointer(_regs) ((_regs)->regs[15])
230 230
231#endif /* __ASSEMBLY__ */ 231#endif /* __ASSEMBLY__ */
232#endif /* __ASM_SH_PROCESSOR_64_H */ 232#endif /* __ASM_SH_PROCESSOR_64_H */
diff --git a/arch/sh/include/asm/ptrace.h b/arch/sh/include/asm/ptrace.h
index 12912ab80c15..81c6568fdb3e 100644
--- a/arch/sh/include/asm/ptrace.h
+++ b/arch/sh/include/asm/ptrace.h
@@ -122,14 +122,12 @@ extern void user_disable_single_step(struct task_struct *);
122#ifdef CONFIG_SH_DSP 122#ifdef CONFIG_SH_DSP
123#define task_pt_regs(task) \ 123#define task_pt_regs(task) \
124 ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE \ 124 ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE \
125 - sizeof(struct pt_dspregs) - sizeof(unsigned long)) - 1) 125 - sizeof(struct pt_dspregs)) - 1)
126#define task_pt_dspregs(task) \ 126#define task_pt_dspregs(task) \
127 ((struct pt_dspregs *) (task_stack_page(task) + THREAD_SIZE \ 127 ((struct pt_dspregs *) (task_stack_page(task) + THREAD_SIZE) - 1)
128 - sizeof(unsigned long)) - 1)
129#else 128#else
130#define task_pt_regs(task) \ 129#define task_pt_regs(task) \
131 ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE \ 130 ((struct pt_regs *) (task_stack_page(task) + THREAD_SIZE) - 1)
132 - sizeof(unsigned long)) - 1)
133#endif 131#endif
134 132
135static inline unsigned long profile_pc(struct pt_regs *regs) 133static inline unsigned long profile_pc(struct pt_regs *regs)
diff --git a/arch/sh/include/asm/sections.h b/arch/sh/include/asm/sections.h
index 8f8f4ad400df..01a4076a3719 100644
--- a/arch/sh/include/asm/sections.h
+++ b/arch/sh/include/asm/sections.h
@@ -3,6 +3,7 @@
3 3
4#include <asm-generic/sections.h> 4#include <asm-generic/sections.h>
5 5
6extern void __nosave_begin, __nosave_end;
6extern long __machvec_start, __machvec_end; 7extern long __machvec_start, __machvec_end;
7extern char __uncached_start, __uncached_end; 8extern char __uncached_start, __uncached_end;
8extern char _ebss[]; 9extern char _ebss[];
diff --git a/arch/sh/include/asm/suspend.h b/arch/sh/include/asm/suspend.h
new file mode 100644
index 000000000000..b1b995370e79
--- /dev/null
+++ b/arch/sh/include/asm/suspend.h
@@ -0,0 +1,22 @@
1#ifndef _ASM_SH_SUSPEND_H
2#define _ASM_SH_SUSPEND_H
3
4#ifndef __ASSEMBLY__
5static inline int arch_prepare_suspend(void) { return 0; }
6
7#include <asm/ptrace.h>
8
9struct swsusp_arch_regs {
10 struct pt_regs user_regs;
11 unsigned long bank1_regs[8];
12};
13#endif
14
15/* flags passed to assembly suspend code */
16#define SUSP_SH_SLEEP (1 << 0) /* Regular sleep mode */
17#define SUSP_SH_STANDBY (1 << 1) /* SH-Mobile Software standby mode */
18#define SUSP_SH_RSTANDBY (1 << 2) /* SH-Mobile R-standby mode */
19#define SUSP_SH_USTANDBY (1 << 3) /* SH-Mobile U-standby mode */
20#define SUSP_SH_SF (1 << 4) /* Enable self-refresh */
21
22#endif /* _ASM_SH_SUSPEND_H */
diff --git a/arch/sh/include/asm/timer.h b/arch/sh/include/asm/timer.h
index a7ca3a195bb5..4c3b66e30af2 100644
--- a/arch/sh/include/asm/timer.h
+++ b/arch/sh/include/asm/timer.h
@@ -9,7 +9,6 @@ struct sys_timer_ops {
9 int (*init)(void); 9 int (*init)(void);
10 int (*start)(void); 10 int (*start)(void);
11 int (*stop)(void); 11 int (*stop)(void);
12 cycle_t (*read)(void);
13#ifndef CONFIG_GENERIC_TIME 12#ifndef CONFIG_GENERIC_TIME
14 unsigned long (*get_offset)(void); 13 unsigned long (*get_offset)(void);
15#endif 14#endif
@@ -39,6 +38,7 @@ struct sys_timer *get_sys_timer(void);
39 38
40/* arch/sh/kernel/time.c */ 39/* arch/sh/kernel/time.c */
41void handle_timer_tick(void); 40void handle_timer_tick(void);
42extern unsigned long sh_hpt_frequency; 41
42extern struct clocksource clocksource_sh;
43 43
44#endif /* __ASM_SH_TIMER_H */ 44#endif /* __ASM_SH_TIMER_H */
diff --git a/arch/sh/include/asm/tlb.h b/arch/sh/include/asm/tlb.h
index 88ff1ae8a6b8..9c16f737074a 100644
--- a/arch/sh/include/asm/tlb.h
+++ b/arch/sh/include/asm/tlb.h
@@ -6,22 +6,106 @@
6#endif 6#endif
7 7
8#ifndef __ASSEMBLY__ 8#ifndef __ASSEMBLY__
9#include <linux/pagemap.h>
10
11#ifdef CONFIG_MMU
12#include <asm/pgalloc.h>
13#include <asm/tlbflush.h>
14
15/*
16 * TLB handling. This allows us to remove pages from the page
17 * tables, and efficiently handle the TLB issues.
18 */
19struct mmu_gather {
20 struct mm_struct *mm;
21 unsigned int fullmm;
22 unsigned long start, end;
23};
9 24
10#define tlb_start_vma(tlb, vma) \ 25DECLARE_PER_CPU(struct mmu_gather, mmu_gathers);
11 flush_cache_range(vma, vma->vm_start, vma->vm_end)
12 26
13#define tlb_end_vma(tlb, vma) \ 27static inline void init_tlb_gather(struct mmu_gather *tlb)
14 flush_tlb_range(vma, vma->vm_start, vma->vm_end) 28{
29 tlb->start = TASK_SIZE;
30 tlb->end = 0;
15 31
16#define __tlb_remove_tlb_entry(tlb, pte, address) do { } while (0) 32 if (tlb->fullmm) {
33 tlb->start = 0;
34 tlb->end = TASK_SIZE;
35 }
36}
37
38static inline struct mmu_gather *
39tlb_gather_mmu(struct mm_struct *mm, unsigned int full_mm_flush)
40{
41 struct mmu_gather *tlb = &get_cpu_var(mmu_gathers);
42
43 tlb->mm = mm;
44 tlb->fullmm = full_mm_flush;
45
46 init_tlb_gather(tlb);
47
48 return tlb;
49}
50
51static inline void
52tlb_finish_mmu(struct mmu_gather *tlb, unsigned long start, unsigned long end)
53{
54 if (tlb->fullmm)
55 flush_tlb_mm(tlb->mm);
56
57 /* keep the page table cache within bounds */
58 check_pgt_cache();
59
60 put_cpu_var(mmu_gathers);
61}
62
63static inline void
64tlb_remove_tlb_entry(struct mmu_gather *tlb, pte_t *ptep, unsigned long address)
65{
66 if (tlb->start > address)
67 tlb->start = address;
68 if (tlb->end < address + PAGE_SIZE)
69 tlb->end = address + PAGE_SIZE;
70}
17 71
18/* 72/*
19 * Flush whole TLBs for MM 73 * In the case of tlb vma handling, we can optimise these away in the
74 * case where we're doing a full MM flush. When we're doing a munmap,
75 * the vmas are adjusted to only cover the region to be torn down.
20 */ 76 */
21#define tlb_flush(tlb) flush_tlb_mm((tlb)->mm) 77static inline void
78tlb_start_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
79{
80 if (!tlb->fullmm)
81 flush_cache_range(vma, vma->vm_start, vma->vm_end);
82}
83
84static inline void
85tlb_end_vma(struct mmu_gather *tlb, struct vm_area_struct *vma)
86{
87 if (!tlb->fullmm && tlb->end) {
88 flush_tlb_range(vma, tlb->start, tlb->end);
89 init_tlb_gather(tlb);
90 }
91}
92
93#define tlb_remove_page(tlb,page) free_page_and_swap_cache(page)
94#define pte_free_tlb(tlb, ptep) pte_free((tlb)->mm, ptep)
95#define pmd_free_tlb(tlb, pmdp) pmd_free((tlb)->mm, pmdp)
96#define pud_free_tlb(tlb, pudp) pud_free((tlb)->mm, pudp)
97
98#define tlb_migrate_finish(mm) do { } while (0)
99
100#else /* CONFIG_MMU */
101
102#define tlb_start_vma(tlb, vma) do { } while (0)
103#define tlb_end_vma(tlb, vma) do { } while (0)
104#define __tlb_remove_tlb_entry(tlb, pte, address) do { } while (0)
105#define tlb_flush(tlb) do { } while (0)
22 106
23#include <linux/pagemap.h>
24#include <asm-generic/tlb.h> 107#include <asm-generic/tlb.h>
25 108
109#endif /* CONFIG_MMU */
26#endif /* __ASSEMBLY__ */ 110#endif /* __ASSEMBLY__ */
27#endif /* __ASM_SH_TLB_H */ 111#endif /* __ASM_SH_TLB_H */
diff --git a/arch/sh/include/cpu-sh3/cpu/dma.h b/arch/sh/include/cpu-sh3/cpu/dma.h
index 6813c3220a1d..0ea15f3f2363 100644
--- a/arch/sh/include/cpu-sh3/cpu/dma.h
+++ b/arch/sh/include/cpu-sh3/cpu/dma.h
@@ -1,22 +1,17 @@
1#ifndef __ASM_CPU_SH3_DMA_H 1#ifndef __ASM_CPU_SH3_DMA_H
2#define __ASM_CPU_SH3_DMA_H 2#define __ASM_CPU_SH3_DMA_H
3 3
4
5#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 4#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
6 defined(CONFIG_CPU_SUBTYPE_SH7721) 5 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
7#define SH_DMAC_BASE 0xa4010020 6 defined(CONFIG_CPU_SUBTYPE_SH7710) || \
8#else 7 defined(CONFIG_CPU_SUBTYPE_SH7712)
9#define SH_DMAC_BASE 0xa4000020 8#define SH_DMAC_BASE0 0xa4010020
9#else /* SH7705/06/07/09 */
10#define SH_DMAC_BASE0 0xa4000020
10#endif 11#endif
11 12
12#if defined(CONFIG_CPU_SUBTYPE_SH7720) || defined(CONFIG_CPU_SUBTYPE_SH7709)
13#define DMTE0_IRQ 48 13#define DMTE0_IRQ 48
14#define DMTE1_IRQ 49
15#define DMTE2_IRQ 50
16#define DMTE3_IRQ 51
17#define DMTE4_IRQ 76 14#define DMTE4_IRQ 76
18#define DMTE5_IRQ 77
19#endif
20 15
21/* Definitions for the SuperH DMAC */ 16/* Definitions for the SuperH DMAC */
22#define TM_BURST 0x00000020 17#define TM_BURST 0x00000020
diff --git a/arch/sh/include/cpu-sh4/cpu/dma-sh4a.h b/arch/sh/include/cpu-sh4/cpu/dma-sh4a.h
new file mode 100644
index 000000000000..0ed5178fed69
--- /dev/null
+++ b/arch/sh/include/cpu-sh4/cpu/dma-sh4a.h
@@ -0,0 +1,94 @@
1#ifndef __ASM_SH_CPU_SH4_DMA_SH7780_H
2#define __ASM_SH_CPU_SH4_DMA_SH7780_H
3
4#if defined(CONFIG_CPU_SUBTYPE_SH7343) || \
5 defined(CONFIG_CPU_SUBTYPE_SH7722) || \
6 defined(CONFIG_CPU_SUBTYPE_SH7730)
7#define DMTE0_IRQ 48
8#define DMTE4_IRQ 76
9#define DMAE0_IRQ 78 /* DMA Error IRQ*/
10#define SH_DMAC_BASE0 0xFE008020
11#define SH_DMARS_BASE 0xFE009000
12#elif defined(CONFIG_CPU_SUBTYPE_SH7763) || \
13 defined(CONFIG_CPU_SUBTYPE_SH7764)
14#define DMTE0_IRQ 34
15#define DMTE4_IRQ 44
16#define DMAE0_IRQ 38
17#define SH_DMAC_BASE0 0xFF608020
18#define SH_DMARS_BASE 0xFF609000
19#elif defined(CONFIG_CPU_SUBTYPE_SH7723)
20#define DMTE0_IRQ 48 /* DMAC0A*/
21#define DMTE4_IRQ 40 /* DMAC0B */
22#define DMTE6_IRQ 42
23#define DMTE8_IRQ 76 /* DMAC1A */
24#define DMTE9_IRQ 77
25#define DMTE10_IRQ 72 /* DMAC1B */
26#define DMTE11_IRQ 73
27#define DMAE0_IRQ 78 /* DMA Error IRQ*/
28#define DMAE1_IRQ 74 /* DMA Error IRQ*/
29#define SH_DMAC_BASE0 0xFE008020
30#define SH_DMAC_BASE1 0xFDC08020
31#define SH_DMARS_BASE 0xFDC09000
32#elif defined(CONFIG_CPU_SUBTYPE_SH7780)
33#define DMTE0_IRQ 34
34#define DMTE4_IRQ 44
35#define DMTE6_IRQ 46
36#define DMTE8_IRQ 92
37#define DMTE9_IRQ 93
38#define DMTE10_IRQ 94
39#define DMTE11_IRQ 95
40#define DMAE0_IRQ 38 /* DMA Error IRQ */
41#define SH_DMAC_BASE0 0xFC808020
42#define SH_DMAC_BASE1 0xFC818020
43#define SH_DMARS_BASE 0xFC809000
44#else /* SH7785 */
45#define DMTE0_IRQ 33
46#define DMTE4_IRQ 37
47#define DMTE6_IRQ 52
48#define DMTE8_IRQ 54
49#define DMTE9_IRQ 55
50#define DMTE10_IRQ 56
51#define DMTE11_IRQ 57
52#define DMAE0_IRQ 39 /* DMA Error IRQ0 */
53#define DMAE1_IRQ 58 /* DMA Error IRQ1 */
54#define SH_DMAC_BASE0 0xFC808020
55#define SH_DMAC_BASE1 0xFCC08020
56#define SH_DMARS_BASE 0xFC809000
57#endif
58
59#define REQ_HE 0x000000C0
60#define REQ_H 0x00000080
61#define REQ_LE 0x00000040
62#define TM_BURST 0x0000020
63#define TS_8 0x00000000
64#define TS_16 0x00000008
65#define TS_32 0x00000010
66#define TS_16BLK 0x00000018
67#define TS_32BLK 0x00100000
68
69/*
70 * The SuperH DMAC supports a number of transmit sizes, we list them here,
71 * with their respective values as they appear in the CHCR registers.
72 *
73 * Defaults to a 64-bit transfer size.
74 */
75enum {
76 XMIT_SZ_8BIT,
77 XMIT_SZ_16BIT,
78 XMIT_SZ_32BIT,
79 XMIT_SZ_128BIT,
80 XMIT_SZ_256BIT,
81};
82
83/*
84 * The DMA count is defined as the number of bytes to transfer.
85 */
86static unsigned int ts_shift[] __maybe_unused = {
87 [XMIT_SZ_8BIT] = 0,
88 [XMIT_SZ_16BIT] = 1,
89 [XMIT_SZ_32BIT] = 2,
90 [XMIT_SZ_128BIT] = 4,
91 [XMIT_SZ_256BIT] = 5,
92};
93
94#endif /* __ASM_SH_CPU_SH4_DMA_SH7780_H */
diff --git a/arch/sh/include/cpu-sh4/cpu/dma-sh7780.h b/arch/sh/include/cpu-sh4/cpu/dma-sh7780.h
deleted file mode 100644
index 71b426a6e482..000000000000
--- a/arch/sh/include/cpu-sh4/cpu/dma-sh7780.h
+++ /dev/null
@@ -1,39 +0,0 @@
1#ifndef __ASM_SH_CPU_SH4_DMA_SH7780_H
2#define __ASM_SH_CPU_SH4_DMA_SH7780_H
3
4#define REQ_HE 0x000000C0
5#define REQ_H 0x00000080
6#define REQ_LE 0x00000040
7#define TM_BURST 0x0000020
8#define TS_8 0x00000000
9#define TS_16 0x00000008
10#define TS_32 0x00000010
11#define TS_16BLK 0x00000018
12#define TS_32BLK 0x00100000
13
14/*
15 * The SuperH DMAC supports a number of transmit sizes, we list them here,
16 * with their respective values as they appear in the CHCR registers.
17 *
18 * Defaults to a 64-bit transfer size.
19 */
20enum {
21 XMIT_SZ_8BIT,
22 XMIT_SZ_16BIT,
23 XMIT_SZ_32BIT,
24 XMIT_SZ_128BIT,
25 XMIT_SZ_256BIT,
26};
27
28/*
29 * The DMA count is defined as the number of bytes to transfer.
30 */
31static unsigned int ts_shift[] __maybe_unused = {
32 [XMIT_SZ_8BIT] = 0,
33 [XMIT_SZ_16BIT] = 1,
34 [XMIT_SZ_32BIT] = 2,
35 [XMIT_SZ_128BIT] = 4,
36 [XMIT_SZ_256BIT] = 5,
37};
38
39#endif /* __ASM_SH_CPU_SH4_DMA_SH7780_H */
diff --git a/arch/sh/include/cpu-sh4/cpu/dma.h b/arch/sh/include/cpu-sh4/cpu/dma.h
index 235b7cd1fc9a..bcb30246e85c 100644
--- a/arch/sh/include/cpu-sh4/cpu/dma.h
+++ b/arch/sh/include/cpu-sh4/cpu/dma.h
@@ -1,31 +1,29 @@
1#ifndef __ASM_CPU_SH4_DMA_H 1#ifndef __ASM_CPU_SH4_DMA_H
2#define __ASM_CPU_SH4_DMA_H 2#define __ASM_CPU_SH4_DMA_H
3 3
4#define DMAOR_INIT ( 0x8000 | DMAOR_DME )
5
6/* SH7751/7760/7780 DMA IRQ sources */ 4/* SH7751/7760/7780 DMA IRQ sources */
7#define DMTE0_IRQ 34
8#define DMTE1_IRQ 35
9#define DMTE2_IRQ 36
10#define DMTE3_IRQ 37
11#define DMTE4_IRQ 44
12#define DMTE5_IRQ 45
13#define DMTE6_IRQ 46
14#define DMTE7_IRQ 47
15#define DMAE_IRQ 38
16 5
17#ifdef CONFIG_CPU_SH4A 6#ifdef CONFIG_CPU_SH4A
18#define SH_DMAC_BASE 0xfc808020
19 7
8#define DMAOR_INIT (DMAOR_DME)
20#define CHCR_TS_MASK 0x18 9#define CHCR_TS_MASK 0x18
21#define CHCR_TS_SHIFT 3 10#define CHCR_TS_SHIFT 3
22 11
23#include <cpu/dma-sh7780.h> 12#include <cpu/dma-sh4a.h>
24#else 13#else /* CONFIG_CPU_SH4A */
25#define SH_DMAC_BASE 0xffa00000 14/*
15 * SH7750/SH7751/SH7760
16 */
17#define DMTE0_IRQ 34
18#define DMTE4_IRQ 44
19#define DMTE6_IRQ 46
20#define DMAE0_IRQ 38
26 21
22#define DMAOR_INIT (0x8000|DMAOR_DME)
23#define SH_DMAC_BASE0 0xffa00000
24#define SH_DMAC_BASE1 0xffa00070
27/* Definitions for the SuperH DMAC */ 25/* Definitions for the SuperH DMAC */
28#define TM_BURST 0x0000080 26#define TM_BURST 0x00000080
29#define TS_8 0x00000010 27#define TS_8 0x00000010
30#define TS_16 0x00000020 28#define TS_16 0x00000020
31#define TS_32 0x00000030 29#define TS_32 0x00000030
diff --git a/arch/sh/include/cpu-sh4/cpu/freq.h b/arch/sh/include/cpu-sh4/cpu/freq.h
index c23af81c2e70..749d1c434337 100644
--- a/arch/sh/include/cpu-sh4/cpu/freq.h
+++ b/arch/sh/include/cpu-sh4/cpu/freq.h
@@ -29,6 +29,10 @@
29#define FRQCR0 0xffc80000 29#define FRQCR0 0xffc80000
30#define FRQCR1 0xffc80004 30#define FRQCR1 0xffc80004
31#define FRQMR1 0xffc80014 31#define FRQMR1 0xffc80014
32#elif defined(CONFIG_CPU_SUBTYPE_SH7786)
33#define FRQCR0 0xffc40000
34#define FRQCR1 0xffc40004
35#define FRQMR1 0xffc40014
32#elif defined(CONFIG_CPU_SUBTYPE_SHX3) 36#elif defined(CONFIG_CPU_SUBTYPE_SHX3)
33#define FRQCR 0xffc00014 37#define FRQCR 0xffc00014
34#else 38#else
diff --git a/arch/sh/include/cpu-sh4/cpu/mmu_context.h b/arch/sh/include/cpu-sh4/cpu/mmu_context.h
index 9ea8eb27b18e..3ce7ef6c2978 100644
--- a/arch/sh/include/cpu-sh4/cpu/mmu_context.h
+++ b/arch/sh/include/cpu-sh4/cpu/mmu_context.h
@@ -14,28 +14,35 @@
14#define MMU_PTEL 0xFF000004 /* Page table entry register LOW */ 14#define MMU_PTEL 0xFF000004 /* Page table entry register LOW */
15#define MMU_TTB 0xFF000008 /* Translation table base register */ 15#define MMU_TTB 0xFF000008 /* Translation table base register */
16#define MMU_TEA 0xFF00000C /* TLB Exception Address */ 16#define MMU_TEA 0xFF00000C /* TLB Exception Address */
17#define MMU_PTEA 0xFF000034 /* Page table entry assistance register */ 17#define MMU_PTEA 0xFF000034 /* PTE assistance register */
18#define MMU_PTEAEX 0xFF00007C /* PTE ASID extension register */
18 19
19#define MMUCR 0xFF000010 /* MMU Control Register */ 20#define MMUCR 0xFF000010 /* MMU Control Register */
20 21
21#define MMU_ITLB_ADDRESS_ARRAY 0xF2000000
22#define MMU_UTLB_ADDRESS_ARRAY 0xF6000000 22#define MMU_UTLB_ADDRESS_ARRAY 0xF6000000
23#define MMU_UTLB_ADDRESS_ARRAY2 0xF6800000
23#define MMU_PAGE_ASSOC_BIT 0x80 24#define MMU_PAGE_ASSOC_BIT 0x80
24 25
25#define MMUCR_TI (1<<2) 26#define MMUCR_TI (1<<2)
26 27
27#ifdef CONFIG_X2TLB
28#define MMUCR_ME (1 << 7)
29#else
30#define MMUCR_ME (0)
31#endif
32
33#if defined(CONFIG_32BIT) && defined(CONFIG_CPU_SUBTYPE_ST40) 28#if defined(CONFIG_32BIT) && defined(CONFIG_CPU_SUBTYPE_ST40)
34#define MMUCR_SE (1 << 4) 29#define MMUCR_SE (1 << 4)
35#else 30#else
36#define MMUCR_SE (0) 31#define MMUCR_SE (0)
37#endif 32#endif
38 33
34#ifdef CONFIG_CPU_HAS_PTEAEX
35#define MMUCR_AEX (1 << 6)
36#else
37#define MMUCR_AEX (0)
38#endif
39
40#ifdef CONFIG_X2TLB
41#define MMUCR_ME (1 << 7)
42#else
43#define MMUCR_ME (0)
44#endif
45
39#ifdef CONFIG_SH_STORE_QUEUES 46#ifdef CONFIG_SH_STORE_QUEUES
40#define MMUCR_SQMD (1 << 9) 47#define MMUCR_SQMD (1 << 9)
41#else 48#else
@@ -43,17 +50,7 @@
43#endif 50#endif
44 51
45#define MMU_NTLB_ENTRIES 64 52#define MMU_NTLB_ENTRIES 64
46#define MMU_CONTROL_INIT (0x05|MMUCR_SQMD|MMUCR_ME|MMUCR_SE) 53#define MMU_CONTROL_INIT (0x05|MMUCR_SQMD|MMUCR_ME|MMUCR_SE|MMUCR_AEX)
47
48#define MMU_ITLB_DATA_ARRAY 0xF3000000
49#define MMU_UTLB_DATA_ARRAY 0xF7000000
50
51#define MMU_UTLB_ENTRIES 64
52#define MMU_U_ENTRY_SHIFT 8
53#define MMU_UTLB_VALID 0x100
54#define MMU_ITLB_ENTRIES 4
55#define MMU_I_ENTRY_SHIFT 8
56#define MMU_ITLB_VALID 0x100
57 54
58#define TRA 0xff000020 55#define TRA 0xff000020
59#define EXPEVT 0xff000024 56#define EXPEVT 0xff000024
diff --git a/arch/sh/include/cpu-sh4/cpu/sh7786.h b/arch/sh/include/cpu-sh4/cpu/sh7786.h
new file mode 100644
index 000000000000..48688adc0c84
--- /dev/null
+++ b/arch/sh/include/cpu-sh4/cpu/sh7786.h
@@ -0,0 +1,192 @@
1/*
2 * SH7786 Pinmux
3 *
4 * Copyright (C) 2008, 2009 Renesas Solutions Corp.
5 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
6 *
7 * Based on sh7785.h
8 *
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
11 * for more details.
12 */
13
14#ifndef __CPU_SH7786_H__
15#define __CPU_SH7786_H__
16
17enum {
18 /* PA */
19 GPIO_PA7, GPIO_PA6, GPIO_PA5, GPIO_PA4,
20 GPIO_PA3, GPIO_PA2, GPIO_PA1, GPIO_PA0,
21
22 /* PB */
23 GPIO_PB7, GPIO_PB6, GPIO_PB5, GPIO_PB4,
24 GPIO_PB3, GPIO_PB2, GPIO_PB1, GPIO_PB0,
25
26 /* PC */
27 GPIO_PC7, GPIO_PC6, GPIO_PC5, GPIO_PC4,
28 GPIO_PC3, GPIO_PC2, GPIO_PC1, GPIO_PC0,
29
30 /* PD */
31 GPIO_PD7, GPIO_PD6, GPIO_PD5, GPIO_PD4,
32 GPIO_PD3, GPIO_PD2, GPIO_PD1, GPIO_PD0,
33
34 /* PE */
35 GPIO_PE5, GPIO_PE4, GPIO_PE3, GPIO_PE2,
36 GPIO_PE1, GPIO_PE0,
37
38 /* PF */
39 GPIO_PF7, GPIO_PF6, GPIO_PF5, GPIO_PF4,
40 GPIO_PF3, GPIO_PF2, GPIO_PF1, GPIO_PF0,
41
42 /* PG */
43 GPIO_PG7, GPIO_PG6, GPIO_PG5, GPIO_PG4,
44 GPIO_PG3, GPIO_PG2, GPIO_PG1, GPIO_PG0,
45
46 /* PH */
47 GPIO_PH7, GPIO_PH6, GPIO_PH5, GPIO_PH4,
48 GPIO_PH3, GPIO_PH2, GPIO_PH1, GPIO_PH0,
49
50 /* PJ */
51 GPIO_PJ7, GPIO_PJ6, GPIO_PJ5, GPIO_PJ4,
52 GPIO_PJ3, GPIO_PJ2, GPIO_PJ1, GPIO_PJ0,
53
54 GPIO_FN_CDE,
55 GPIO_FN_ETH_MAGIC,
56 GPIO_FN_DISP,
57 GPIO_FN_ETH_LINK,
58 GPIO_FN_DR5,
59 GPIO_FN_ETH_TX_ER,
60 GPIO_FN_DR4,
61 GPIO_FN_ETH_TX_EN,
62 GPIO_FN_DR3,
63 GPIO_FN_ETH_TXD3,
64 GPIO_FN_DR2,
65 GPIO_FN_ETH_TXD2,
66 GPIO_FN_DR1,
67 GPIO_FN_ETH_TXD1,
68 GPIO_FN_DR0,
69 GPIO_FN_ETH_TXD0,
70 GPIO_FN_VSYNC,
71 GPIO_FN_HSPI_CLK,
72 GPIO_FN_ODDF,
73 GPIO_FN_HSPI_CS,
74 GPIO_FN_DG5,
75 GPIO_FN_ETH_MDIO,
76 GPIO_FN_DG4,
77 GPIO_FN_ETH_RX_CLK,
78 GPIO_FN_DG3,
79 GPIO_FN_ETH_MDC,
80 GPIO_FN_DG2,
81 GPIO_FN_ETH_COL,
82 GPIO_FN_DG1,
83 GPIO_FN_ETH_TX_CLK,
84 GPIO_FN_DG0,
85 GPIO_FN_ETH_CRS,
86 GPIO_FN_DCLKIN,
87 GPIO_FN_HSPI_RX,
88 GPIO_FN_HSYNC,
89 GPIO_FN_HSPI_TX,
90 GPIO_FN_DB5,
91 GPIO_FN_ETH_RXD3,
92 GPIO_FN_DB4,
93 GPIO_FN_ETH_RXD2,
94 GPIO_FN_DB3,
95 GPIO_FN_ETH_RXD1,
96 GPIO_FN_DB2,
97 GPIO_FN_ETH_RXD0,
98 GPIO_FN_DB1,
99 GPIO_FN_ETH_RX_DV,
100 GPIO_FN_DB0,
101 GPIO_FN_ETH_RX_ER,
102 GPIO_FN_DCLKOUT,
103 GPIO_FN_SCIF1_SLK,
104 GPIO_FN_SCIF1_RXD,
105 GPIO_FN_SCIF1_TXD,
106 GPIO_FN_DACK1,
107 GPIO_FN_BACK,
108 GPIO_FN_FALE,
109 GPIO_FN_DACK0,
110 GPIO_FN_FCLE,
111 GPIO_FN_DREQ1,
112 GPIO_FN_BREQ,
113 GPIO_FN_USB_OVC1,
114 GPIO_FN_DREQ0,
115 GPIO_FN_USB_OVC0,
116 GPIO_FN_USB_PENC1,
117 GPIO_FN_USB_PENC0,
118 GPIO_FN_HAC1_SDOUT,
119 GPIO_FN_SSI1_SDATA,
120 GPIO_FN_SDIF1CMD,
121 GPIO_FN_HAC1_SDIN,
122 GPIO_FN_SSI1_SCK,
123 GPIO_FN_SDIF1CD,
124 GPIO_FN_HAC1_SYNC,
125 GPIO_FN_SSI1_WS,
126 GPIO_FN_SDIF1WP,
127 GPIO_FN_HAC1_BITCLK,
128 GPIO_FN_SSI1_CLK,
129 GPIO_FN_SDIF1CLK,
130 GPIO_FN_HAC0_SDOUT,
131 GPIO_FN_SSI0_SDATA,
132 GPIO_FN_SDIF1D3,
133 GPIO_FN_HAC0_SDIN,
134 GPIO_FN_SSI0_SCK,
135 GPIO_FN_SDIF1D2,
136 GPIO_FN_HAC0_SYNC,
137 GPIO_FN_SSI0_WS,
138 GPIO_FN_SDIF1D1,
139 GPIO_FN_HAC0_BITCLK,
140 GPIO_FN_SSI0_CLK,
141 GPIO_FN_SDIF1D0,
142 GPIO_FN_SCIF3_SCK,
143 GPIO_FN_SSI2_SDATA,
144 GPIO_FN_SCIF3_RXD,
145 GPIO_FN_TCLK,
146 GPIO_FN_SSI2_SCK,
147 GPIO_FN_SCIF3_TXD,
148 GPIO_FN_HAC_RES,
149 GPIO_FN_SSI2_WS,
150 GPIO_FN_DACK3,
151 GPIO_FN_SDIF0CMD,
152 GPIO_FN_DACK2,
153 GPIO_FN_SDIF0CD,
154 GPIO_FN_DREQ3,
155 GPIO_FN_SDIF0WP,
156 GPIO_FN_SCIF0_CTS,
157 GPIO_FN_DREQ2,
158 GPIO_FN_SDIF0CLK,
159 GPIO_FN_SCIF0_RTS,
160 GPIO_FN_IRL7,
161 GPIO_FN_SDIF0D3,
162 GPIO_FN_SCIF0_SCK,
163 GPIO_FN_IRL6,
164 GPIO_FN_SDIF0D2,
165 GPIO_FN_SCIF0_RXD,
166 GPIO_FN_IRL5,
167 GPIO_FN_SDIF0D1,
168 GPIO_FN_SCIF0_TXD,
169 GPIO_FN_IRL4,
170 GPIO_FN_SDIF0D0,
171 GPIO_FN_SCIF5_SCK,
172 GPIO_FN_FRB,
173 GPIO_FN_SCIF5_RXD,
174 GPIO_FN_IOIS16,
175 GPIO_FN_SCIF5_TXD,
176 GPIO_FN_CE2B,
177 GPIO_FN_DRAK3,
178 GPIO_FN_CE2A,
179 GPIO_FN_SCIF4_SCK,
180 GPIO_FN_DRAK2,
181 GPIO_FN_SSI3_WS,
182 GPIO_FN_SCIF4_RXD,
183 GPIO_FN_DRAK1,
184 GPIO_FN_SSI3_SDATA,
185 GPIO_FN_FSTATUS,
186 GPIO_FN_SCIF4_TXD,
187 GPIO_FN_DRAK0,
188 GPIO_FN_SSI3_SCK,
189 GPIO_FN_FSE,
190};
191
192#endif /* __CPU_SH7786_H__ */
diff --git a/arch/sh/include/mach-common/mach/urquell.h b/arch/sh/include/mach-common/mach/urquell.h
new file mode 100644
index 000000000000..14b3e1d01777
--- /dev/null
+++ b/arch/sh/include/mach-common/mach/urquell.h
@@ -0,0 +1,68 @@
1#ifndef __MACH_URQUELL_H
2#define __MACH_URQUELL_H
3
4/*
5 * ------ 0x00000000 ------------------------------------
6 * CS0 | (SW1,SW47) EEPROM, SRAM, NOR FLASH
7 * -----+ 0x04000000 ------------------------------------
8 * CS1 | (SW47) SRAM, SRAM-LAN-PCMCIA, NOR FLASH
9 * -----+ 0x08000000 ------------------------------------
10 * CS2 | DDR3
11 * CS3 |
12 * -----+ 0x10000000 ------------------------------------
13 * CS4 | PCIe
14 * -----+ 0x14000000 ------------------------------------
15 * CS5 | (SW47) LRAM/URAM, SRAM-LAN-PCMCIA
16 * -----+ 0x18000000 ------------------------------------
17 * CS6 | ATA, NAND FLASH
18 * -----+ 0x1c000000 ------------------------------------
19 * CS7 | SH7786 register
20 * -----+------------------------------------------------
21 */
22
23#define NOR_FLASH_ADDR 0x00000000
24#define NOR_FLASH_SIZE 0x04000000
25
26#define CS1_BASE 0x05000000
27#define CS5_BASE 0x15000000
28#define FPGA_BASE CS1_BASE
29
30#define BOARDREG(ofs) (FPGA_BASE + ofs##_OFS)
31#define UBOARDREG(ofs) (0xa0000000 + FPGA_BASE + ofs##_OFS)
32
33#define SRSTR_OFS 0x0000 /* System reset register */
34#define BDMR_OFS 0x0010 /* Board operating mode resister */
35#define IRL0SR_OFS 0x0020 /* IRL0 Status register */
36#define IRL0MSKR_OFS 0x0030 /* IRL0 Mask register */
37#define IRL1SR_OFS 0x0040 /* IRL1 Status register */
38#define IRL1MSKR_OFS 0x0050 /* IRL1 Mask register */
39#define IRL2SR_OFS 0x0060 /* IRL2 Status register */
40#define IRL2MSKR_OFS 0x0070 /* IRL2 Mask register */
41#define IRL3SR_OFS 0x0080 /* IRL3 Status register */
42#define IRL3MSKR_OFS 0x0090 /* IRL3 Mask register */
43#define SOFTINTR_OFS 0x0120 /* Softwear Interrupt register */
44#define SLEDR_OFS 0x0130 /* LED control resister */
45#define MAPSCIFSWR_OFS 0x0140 /* Map/SCIF Switch register */
46#define FPVERR_OFS 0x0150 /* FPGA Version register */
47#define FPDATER_OFS 0x0160 /* FPGA Date register */
48#define FPYEARR_OFS 0x0170 /* FPGA Year register */
49#define TCLKCR_OFS 0x0180 /* TCLK Control register */
50#define DIPSWMR_OFS 0x1000 /* DIPSW monitor register */
51#define FPODR_OFS 0x1010 /* Output port data register */
52#define ATACNR_OFS 0x1020 /* ATA-CN Control/status register */
53#define FPINDR_OFS 0x1030 /* Input port data register */
54#define MDSWMR_OFS 0x1040 /* MODE SW monitor register */
55#define DDR3BUPCR_OFS 0x1050 /* DDR3 Backup control register */
56#define SSICODECCR_OFS 0x1060 /* SSI-CODEC control register */
57#define PCIESLOTSR_OFS 0x1070 /* PCIexpress Slot status register */
58#define ETHERPORTSR_OFS 0x1080 /* EtherPhy Port status register */
59#define LATCHCR_OFS 0x3000 /* Latch control register */
60#define LATCUAR_OFS 0x3010 /* Latch upper address register */
61#define LATCLAR_OFS 0x3012 /* Latch lower address register */
62#define LATCLUDR_OFS 0x3024 /* Latch D31-16 register */
63#define LATCLLDR_OFS 0x3026 /* Latch D15-0 register */
64
65#define CHARLED_OFS 0x2000 /* Character LED */
66
67#endif /* __MACH_URQUELL_H */
68
diff --git a/arch/sh/kernel/Makefile_32 b/arch/sh/kernel/Makefile_32
index 2e1b86e16ab5..82a3a150c00d 100644
--- a/arch/sh/kernel/Makefile_32
+++ b/arch/sh/kernel/Makefile_32
@@ -30,5 +30,6 @@ obj-$(CONFIG_KPROBES) += kprobes.o
30obj-$(CONFIG_GENERIC_GPIO) += gpio.o 30obj-$(CONFIG_GENERIC_GPIO) += gpio.o
31obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o 31obj-$(CONFIG_DYNAMIC_FTRACE) += ftrace.o
32obj-$(CONFIG_DUMP_CODE) += disassemble.o 32obj-$(CONFIG_DUMP_CODE) += disassemble.o
33obj-$(CONFIG_HIBERNATION) += swsusp.o
33 34
34EXTRA_CFLAGS += -Werror 35EXTRA_CFLAGS += -Werror
diff --git a/arch/sh/kernel/asm-offsets.c b/arch/sh/kernel/asm-offsets.c
index 57cf0e0680f3..99aceb28ee24 100644
--- a/arch/sh/kernel/asm-offsets.c
+++ b/arch/sh/kernel/asm-offsets.c
@@ -12,8 +12,10 @@
12#include <linux/types.h> 12#include <linux/types.h>
13#include <linux/mm.h> 13#include <linux/mm.h>
14#include <linux/kbuild.h> 14#include <linux/kbuild.h>
15#include <linux/suspend.h>
15 16
16#include <asm/thread_info.h> 17#include <asm/thread_info.h>
18#include <asm/suspend.h>
17 19
18int main(void) 20int main(void)
19{ 21{
@@ -25,5 +27,11 @@ int main(void)
25 DEFINE(TI_PRE_COUNT, offsetof(struct thread_info, preempt_count)); 27 DEFINE(TI_PRE_COUNT, offsetof(struct thread_info, preempt_count));
26 DEFINE(TI_RESTART_BLOCK,offsetof(struct thread_info, restart_block)); 28 DEFINE(TI_RESTART_BLOCK,offsetof(struct thread_info, restart_block));
27 29
30#ifdef CONFIG_HIBERNATION
31 DEFINE(PBE_ADDRESS, offsetof(struct pbe, address));
32 DEFINE(PBE_ORIG_ADDRESS, offsetof(struct pbe, orig_address));
33 DEFINE(PBE_NEXT, offsetof(struct pbe, next));
34 DEFINE(SWSUSP_ARCH_REGS_SIZE, sizeof(struct swsusp_arch_regs));
35#endif
28 return 0; 36 return 0;
29} 37}
diff --git a/arch/sh/kernel/cpu/Makefile b/arch/sh/kernel/cpu/Makefile
index f471d242774e..2600641a483f 100644
--- a/arch/sh/kernel/cpu/Makefile
+++ b/arch/sh/kernel/cpu/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_CPU_SH5) = sh5/
11# Special cases for family ancestry. 11# Special cases for family ancestry.
12 12
13obj-$(CONFIG_CPU_SH4A) += sh4a/ 13obj-$(CONFIG_CPU_SH4A) += sh4a/
14obj-$(CONFIG_ARCH_SHMOBILE) += shmobile/
14 15
15# Common interfaces. 16# Common interfaces.
16 17
diff --git a/arch/sh/kernel/cpu/clock.c b/arch/sh/kernel/cpu/clock.c
index 7b17137536d6..1dc896483b59 100644
--- a/arch/sh/kernel/cpu/clock.c
+++ b/arch/sh/kernel/cpu/clock.c
@@ -20,6 +20,8 @@
20#include <linux/mutex.h> 20#include <linux/mutex.h>
21#include <linux/list.h> 21#include <linux/list.h>
22#include <linux/kref.h> 22#include <linux/kref.h>
23#include <linux/kobject.h>
24#include <linux/sysdev.h>
23#include <linux/seq_file.h> 25#include <linux/seq_file.h>
24#include <linux/err.h> 26#include <linux/err.h>
25#include <linux/platform_device.h> 27#include <linux/platform_device.h>
@@ -239,6 +241,35 @@ void clk_recalc_rate(struct clk *clk)
239} 241}
240EXPORT_SYMBOL_GPL(clk_recalc_rate); 242EXPORT_SYMBOL_GPL(clk_recalc_rate);
241 243
244int clk_set_parent(struct clk *clk, struct clk *parent)
245{
246 int ret = -EINVAL;
247 struct clk *old;
248
249 if (!parent || !clk)
250 return ret;
251
252 old = clk->parent;
253 if (likely(clk->ops && clk->ops->set_parent)) {
254 unsigned long flags;
255 spin_lock_irqsave(&clock_lock, flags);
256 ret = clk->ops->set_parent(clk, parent);
257 spin_unlock_irqrestore(&clock_lock, flags);
258 clk->parent = (ret ? old : parent);
259 }
260
261 if (unlikely(clk->flags & CLK_RATE_PROPAGATES))
262 propagate_rate(clk);
263 return ret;
264}
265EXPORT_SYMBOL_GPL(clk_set_parent);
266
267struct clk *clk_get_parent(struct clk *clk)
268{
269 return clk->parent;
270}
271EXPORT_SYMBOL_GPL(clk_get_parent);
272
242long clk_round_rate(struct clk *clk, unsigned long rate) 273long clk_round_rate(struct clk *clk, unsigned long rate)
243{ 274{
244 if (likely(clk->ops && clk->ops->round_rate)) { 275 if (likely(clk->ops && clk->ops->round_rate)) {
@@ -329,6 +360,70 @@ static int show_clocks(char *buf, char **start, off_t off,
329 return p - buf; 360 return p - buf;
330} 361}
331 362
363#ifdef CONFIG_PM
364static int clks_sysdev_suspend(struct sys_device *dev, pm_message_t state)
365{
366 static pm_message_t prev_state;
367 struct clk *clkp;
368
369 switch (state.event) {
370 case PM_EVENT_ON:
371 /* Resumeing from hibernation */
372 if (prev_state.event == PM_EVENT_FREEZE) {
373 list_for_each_entry(clkp, &clock_list, node)
374 if (likely(clkp->ops)) {
375 unsigned long rate = clkp->rate;
376
377 if (likely(clkp->ops->set_parent))
378 clkp->ops->set_parent(clkp,
379 clkp->parent);
380 if (likely(clkp->ops->set_rate))
381 clkp->ops->set_rate(clkp,
382 rate, NO_CHANGE);
383 else if (likely(clkp->ops->recalc))
384 clkp->ops->recalc(clkp);
385 }
386 }
387 break;
388 case PM_EVENT_FREEZE:
389 break;
390 case PM_EVENT_SUSPEND:
391 break;
392 }
393
394 prev_state = state;
395 return 0;
396}
397
398static int clks_sysdev_resume(struct sys_device *dev)
399{
400 return clks_sysdev_suspend(dev, PMSG_ON);
401}
402
403static struct sysdev_class clks_sysdev_class = {
404 .name = "clks",
405};
406
407static struct sysdev_driver clks_sysdev_driver = {
408 .suspend = clks_sysdev_suspend,
409 .resume = clks_sysdev_resume,
410};
411
412static struct sys_device clks_sysdev_dev = {
413 .cls = &clks_sysdev_class,
414};
415
416static int __init clk_sysdev_init(void)
417{
418 sysdev_class_register(&clks_sysdev_class);
419 sysdev_driver_register(&clks_sysdev_class, &clks_sysdev_driver);
420 sysdev_register(&clks_sysdev_dev);
421
422 return 0;
423}
424subsys_initcall(clk_sysdev_init);
425#endif
426
332int __init clk_init(void) 427int __init clk_init(void)
333{ 428{
334 int i, ret = 0; 429 int i, ret = 0;
diff --git a/arch/sh/kernel/cpu/sh2/setup-sh7619.c b/arch/sh/kernel/cpu/sh2/setup-sh7619.c
index 56e5878e5516..0e32d8e448ca 100644
--- a/arch/sh/kernel/cpu/sh2/setup-sh7619.c
+++ b/arch/sh/kernel/cpu/sh2/setup-sh7619.c
@@ -2,6 +2,7 @@
2 * SH7619 Setup 2 * SH7619 Setup
3 * 3 *
4 * Copyright (C) 2006 Yoshinori Sato 4 * Copyright (C) 2006 Yoshinori Sato
5 * Copyright (C) 2009 Paul Mundt
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public 7 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive 8 * License. See the file "COPYING" in the main directory of this archive
@@ -18,15 +19,10 @@ enum {
18 /* interrupt sources */ 19 /* interrupt sources */
19 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7, 20 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7,
20 WDT, EDMAC, CMT0, CMT1, 21 WDT, EDMAC, CMT0, CMT1,
21 SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI, 22 SCIF0, SCIF1, SCIF2,
22 SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI,
23 SCIF2_ERI, SCIF2_RXI, SCIF2_BRI, SCIF2_TXI,
24 HIF_HIFI, HIF_HIFBI, 23 HIF_HIFI, HIF_HIFBI,
25 DMAC0, DMAC1, DMAC2, DMAC3, 24 DMAC0, DMAC1, DMAC2, DMAC3,
26 SIOF, 25 SIOF,
27
28 /* interrupt groups */
29 SCIF0, SCIF1, SCIF2,
30}; 26};
31 27
32static struct intc_vect vectors[] __initdata = { 28static struct intc_vect vectors[] __initdata = {
@@ -36,24 +32,18 @@ static struct intc_vect vectors[] __initdata = {
36 INTC_IRQ(IRQ6, 82), INTC_IRQ(IRQ7, 83), 32 INTC_IRQ(IRQ6, 82), INTC_IRQ(IRQ7, 83),
37 INTC_IRQ(WDT, 84), INTC_IRQ(EDMAC, 85), 33 INTC_IRQ(WDT, 84), INTC_IRQ(EDMAC, 85),
38 INTC_IRQ(CMT0, 86), INTC_IRQ(CMT1, 87), 34 INTC_IRQ(CMT0, 86), INTC_IRQ(CMT1, 87),
39 INTC_IRQ(SCIF0_ERI, 88), INTC_IRQ(SCIF0_RXI, 89), 35 INTC_IRQ(SCIF0, 88), INTC_IRQ(SCIF0, 89),
40 INTC_IRQ(SCIF0_BRI, 90), INTC_IRQ(SCIF0_TXI, 91), 36 INTC_IRQ(SCIF0, 90), INTC_IRQ(SCIF0, 91),
41 INTC_IRQ(SCIF1_ERI, 92), INTC_IRQ(SCIF1_RXI, 93), 37 INTC_IRQ(SCIF1, 92), INTC_IRQ(SCIF1, 93),
42 INTC_IRQ(SCIF1_BRI, 94), INTC_IRQ(SCIF1_TXI, 95), 38 INTC_IRQ(SCIF1, 94), INTC_IRQ(SCIF1, 95),
43 INTC_IRQ(SCIF2_ERI, 96), INTC_IRQ(SCIF2_RXI, 97), 39 INTC_IRQ(SCIF2, 96), INTC_IRQ(SCIF2, 97),
44 INTC_IRQ(SCIF2_BRI, 98), INTC_IRQ(SCIF2_TXI, 99), 40 INTC_IRQ(SCIF2, 98), INTC_IRQ(SCIF2, 99),
45 INTC_IRQ(HIF_HIFI, 100), INTC_IRQ(HIF_HIFBI, 101), 41 INTC_IRQ(HIF_HIFI, 100), INTC_IRQ(HIF_HIFBI, 101),
46 INTC_IRQ(DMAC0, 104), INTC_IRQ(DMAC1, 105), 42 INTC_IRQ(DMAC0, 104), INTC_IRQ(DMAC1, 105),
47 INTC_IRQ(DMAC2, 106), INTC_IRQ(DMAC3, 107), 43 INTC_IRQ(DMAC2, 106), INTC_IRQ(DMAC3, 107),
48 INTC_IRQ(SIOF, 108), 44 INTC_IRQ(SIOF, 108),
49}; 45};
50 46
51static struct intc_group groups[] __initdata = {
52 INTC_GROUP(SCIF0, SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI),
53 INTC_GROUP(SCIF1, SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI),
54 INTC_GROUP(SCIF2, SCIF2_ERI, SCIF2_RXI, SCIF2_BRI, SCIF2_TXI),
55};
56
57static struct intc_prio_reg prio_registers[] __initdata = { 47static struct intc_prio_reg prio_registers[] __initdata = {
58 { 0xf8140006, 0, 16, 4, /* IPRA */ { IRQ0, IRQ1, IRQ2, IRQ3 } }, 48 { 0xf8140006, 0, 16, 4, /* IPRA */ { IRQ0, IRQ1, IRQ2, IRQ3 } },
59 { 0xf8140008, 0, 16, 4, /* IPRB */ { IRQ4, IRQ5, IRQ6, IRQ7 } }, 49 { 0xf8140008, 0, 16, 4, /* IPRB */ { IRQ4, IRQ5, IRQ6, IRQ7 } },
@@ -64,7 +54,7 @@ static struct intc_prio_reg prio_registers[] __initdata = {
64 { 0xf8080008, 0, 16, 4, /* IPRG */ { SIOF } }, 54 { 0xf8080008, 0, 16, 4, /* IPRG */ { SIOF } },
65}; 55};
66 56
67static DECLARE_INTC_DESC(intc_desc, "sh7619", vectors, groups, 57static DECLARE_INTC_DESC(intc_desc, "sh7619", vectors, NULL,
68 NULL, prio_registers, NULL); 58 NULL, prio_registers, NULL);
69 59
70static struct plat_sci_port sci_platform_data[] = { 60static struct plat_sci_port sci_platform_data[] = {
@@ -72,17 +62,17 @@ static struct plat_sci_port sci_platform_data[] = {
72 .mapbase = 0xf8400000, 62 .mapbase = 0xf8400000,
73 .flags = UPF_BOOT_AUTOCONF, 63 .flags = UPF_BOOT_AUTOCONF,
74 .type = PORT_SCIF, 64 .type = PORT_SCIF,
75 .irqs = { 88, 89, 91, 90}, 65 .irqs = { 88, 88, 88, 88 },
76 }, { 66 }, {
77 .mapbase = 0xf8410000, 67 .mapbase = 0xf8410000,
78 .flags = UPF_BOOT_AUTOCONF, 68 .flags = UPF_BOOT_AUTOCONF,
79 .type = PORT_SCIF, 69 .type = PORT_SCIF,
80 .irqs = { 92, 93, 95, 94}, 70 .irqs = { 92, 92, 92, 92 },
81 }, { 71 }, {
82 .mapbase = 0xf8420000, 72 .mapbase = 0xf8420000,
83 .flags = UPF_BOOT_AUTOCONF, 73 .flags = UPF_BOOT_AUTOCONF,
84 .type = PORT_SCIF, 74 .type = PORT_SCIF,
85 .irqs = { 96, 97, 99, 98}, 75 .irqs = { 96, 96, 96, 96 },
86 }, { 76 }, {
87 .flags = 0, 77 .flags = 0,
88 } 78 }
diff --git a/arch/sh/kernel/cpu/sh2a/setup-mxg.c b/arch/sh/kernel/cpu/sh2a/setup-mxg.c
index e611d79fac4c..844293723cfc 100644
--- a/arch/sh/kernel/cpu/sh2a/setup-mxg.c
+++ b/arch/sh/kernel/cpu/sh2a/setup-mxg.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Renesas MX-G (R8A03022BG) Setup 2 * Renesas MX-G (R8A03022BG) Setup
3 * 3 *
4 * Copyright (C) 2008 Paul Mundt 4 * Copyright (C) 2008, 2009 Paul Mundt
5 * 5 *
6 * This file is subject to the terms and conditions of the GNU General Public 6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive 7 * License. See the file "COPYING" in the main directory of this archive
@@ -20,23 +20,15 @@ enum {
20 IRQ8, IRQ9, IRQ10, IRQ11, IRQ12, IRQ13, IRQ14, IRQ15, 20 IRQ8, IRQ9, IRQ10, IRQ11, IRQ12, IRQ13, IRQ14, IRQ15,
21 21
22 PINT0, PINT1, PINT2, PINT3, PINT4, PINT5, PINT6, PINT7, 22 PINT0, PINT1, PINT2, PINT3, PINT4, PINT5, PINT6, PINT7,
23
24 SINT8, SINT7, SINT6, SINT5, SINT4, SINT3, SINT2, SINT1, 23 SINT8, SINT7, SINT6, SINT5, SINT4, SINT3, SINT2, SINT1,
25 24
26 SCIF0_BRI, SCIF0_ERI, SCIF0_RXI, SCIF0_TXI, 25 SCIF0, SCIF1,
27 SCIF1_BRI, SCIF1_ERI, SCIF1_RXI, SCIF1_TXI,
28 26
29 MTU2_TGI0A, MTU2_TGI0B, MTU2_TGI0C, MTU2_TGI0D, 27 MTU2_GROUP1, MTU2_GROUP2, MTU2_GROUP3, MTU2_GROUP4, MTU2_GROUP5
30 MTU2_TCI0V, MTU2_TGI0E, MTU2_TGI0F, 28 MTU2_TGI3B, MTU2_TGI3C,
31 MTU2_TGI1A, MTU2_TGI1B, MTU2_TCI1V, MTU2_TCI1U,
32 MTU2_TGI2A, MTU2_TGI2B, MTU2_TCI2V, MTU2_TCI2U,
33 MTU2_TGI3A, MTU2_TGI3B, MTU2_TGI3C, MTU2_TGI3D, MTU2_TCI3V,
34 MTU2_TGI4A, MTU2_TGI4B, MTU2_TGI4C, MTU2_TGI4D, MTU2_TCI4V,
35 MTU2_TGI5U, MTU2_TGI5V, MTU2_TGI5W,
36 29
37 /* interrupt groups */ 30 /* interrupt groups */
38 PINT, SCIF0, SCIF1, 31 PINT,
39 MTU2_GROUP1, MTU2_GROUP2, MTU2_GROUP3, MTU2_GROUP4, MTU2_GROUP5
40}; 32};
41 33
42static struct intc_vect vectors[] __initdata = { 34static struct intc_vect vectors[] __initdata = {
@@ -59,47 +51,36 @@ static struct intc_vect vectors[] __initdata = {
59 INTC_IRQ(SINT4, 98), INTC_IRQ(SINT3, 99), 51 INTC_IRQ(SINT4, 98), INTC_IRQ(SINT3, 99),
60 INTC_IRQ(SINT2, 100), INTC_IRQ(SINT1, 101), 52 INTC_IRQ(SINT2, 100), INTC_IRQ(SINT1, 101),
61 53
62 INTC_IRQ(SCIF0_RXI, 220), INTC_IRQ(SCIF0_TXI, 221), 54 INTC_IRQ(SCIF0, 220), INTC_IRQ(SCIF0, 221),
63 INTC_IRQ(SCIF0_BRI, 222), INTC_IRQ(SCIF0_ERI, 223), 55 INTC_IRQ(SCIF0, 222), INTC_IRQ(SCIF0, 223),
64 INTC_IRQ(SCIF1_RXI, 224), INTC_IRQ(SCIF1_TXI, 225), 56 INTC_IRQ(SCIF1, 224), INTC_IRQ(SCIF1, 225),
65 INTC_IRQ(SCIF1_BRI, 226), INTC_IRQ(SCIF1_ERI, 227), 57 INTC_IRQ(SCIF1, 226), INTC_IRQ(SCIF1, 227),
66 58
67 INTC_IRQ(MTU2_TGI0A, 228), INTC_IRQ(MTU2_TGI0B, 229), 59 INTC_IRQ(MTU2_GROUP1, 228), INTC_IRQ(MTU2_GROUP1, 229),
68 INTC_IRQ(MTU2_TGI0C, 230), INTC_IRQ(MTU2_TGI0D, 231), 60 INTC_IRQ(MTU2_GROUP1, 230), INTC_IRQ(MTU2_GROUP1, 231),
69 INTC_IRQ(MTU2_TCI0V, 232), INTC_IRQ(MTU2_TGI0E, 233), 61 INTC_IRQ(MTU2_GROUP1, 232), INTC_IRQ(MTU2_GROUP1, 233),
70 62
71 INTC_IRQ(MTU2_TGI0F, 234), INTC_IRQ(MTU2_TGI1A, 235), 63 INTC_IRQ(MTU2_GROUP2, 234), INTC_IRQ(MTU2_GROUP2, 235),
72 INTC_IRQ(MTU2_TGI1B, 236), INTC_IRQ(MTU2_TCI1V, 237), 64 INTC_IRQ(MTU2_GROUP2, 236), INTC_IRQ(MTU2_GROUP2, 237),
73 INTC_IRQ(MTU2_TCI1U, 238), INTC_IRQ(MTU2_TGI2A, 239), 65 INTC_IRQ(MTU2_GROUP2, 238), INTC_IRQ(MTU2_GROUP2, 239),
74 66
75 INTC_IRQ(MTU2_TGI2B, 240), INTC_IRQ(MTU2_TCI2V, 241), 67 INTC_IRQ(MTU2_GROUP3, 240), INTC_IRQ(MTU2_GROUP3, 241),
76 INTC_IRQ(MTU2_TCI2U, 242), INTC_IRQ(MTU2_TGI3A, 243), 68 INTC_IRQ(MTU2_GROUP3, 242), INTC_IRQ(MTU2_GROUP3, 243),
77 69
78 INTC_IRQ(MTU2_TGI3B, 244), 70 INTC_IRQ(MTU2_TGI3B, 244),
79 INTC_IRQ(MTU2_TGI3C, 245), 71 INTC_IRQ(MTU2_TGI3C, 245),
80 72
81 INTC_IRQ(MTU2_TGI3D, 246), INTC_IRQ(MTU2_TCI3V, 247), 73 INTC_IRQ(MTU2_GROUP4, 246), INTC_IRQ(MTU2_GROUP4, 247),
82 INTC_IRQ(MTU2_TGI4A, 248), INTC_IRQ(MTU2_TGI4B, 249), 74 INTC_IRQ(MTU2_GROUP4, 248), INTC_IRQ(MTU2_GROUP4, 249),
83 INTC_IRQ(MTU2_TGI4C, 250), INTC_IRQ(MTU2_TGI4D, 251), 75 INTC_IRQ(MTU2_GROUP4, 250), INTC_IRQ(MTU2_GROUP4, 251),
84 76
85 INTC_IRQ(MTU2_TCI4V, 252), INTC_IRQ(MTU2_TGI5U, 253), 77 INTC_IRQ(MTU2_GROUP5, 252), INTC_IRQ(MTU2_GROUP5, 253),
86 INTC_IRQ(MTU2_TGI5V, 254), INTC_IRQ(MTU2_TGI5W, 255), 78 INTC_IRQ(MTU2_GROUP5, 254), INTC_IRQ(MTU2_GROUP5, 255),
87}; 79};
88 80
89static struct intc_group groups[] __initdata = { 81static struct intc_group groups[] __initdata = {
90 INTC_GROUP(PINT, PINT0, PINT1, PINT2, PINT3, 82 INTC_GROUP(PINT, PINT0, PINT1, PINT2, PINT3,
91 PINT4, PINT5, PINT6, PINT7), 83 PINT4, PINT5, PINT6, PINT7),
92 INTC_GROUP(MTU2_GROUP1, MTU2_TGI0A, MTU2_TGI0B, MTU2_TGI0C, MTU2_TGI0D,
93 MTU2_TCI0V, MTU2_TGI0E),
94 INTC_GROUP(MTU2_GROUP2, MTU2_TGI0F, MTU2_TGI1A, MTU2_TGI1B,
95 MTU2_TCI1V, MTU2_TCI1U, MTU2_TGI2A),
96 INTC_GROUP(MTU2_GROUP3, MTU2_TGI2B, MTU2_TCI2V, MTU2_TCI2U,
97 MTU2_TGI3A),
98 INTC_GROUP(MTU2_GROUP4, MTU2_TGI3D, MTU2_TCI3V, MTU2_TGI4A,
99 MTU2_TGI4B, MTU2_TGI4C, MTU2_TGI4D),
100 INTC_GROUP(MTU2_GROUP5, MTU2_TCI4V, MTU2_TGI5U, MTU2_TGI5V, MTU2_TGI5W),
101 INTC_GROUP(SCIF0, SCIF0_BRI, SCIF0_ERI, SCIF0_RXI, SCIF0_TXI),
102 INTC_GROUP(SCIF1, SCIF1_BRI, SCIF1_ERI, SCIF1_RXI, SCIF1_TXI),
103}; 84};
104 85
105static struct intc_prio_reg prio_registers[] __initdata = { 86static struct intc_prio_reg prio_registers[] __initdata = {
@@ -137,7 +118,7 @@ static struct plat_sci_port sci_platform_data[] = {
137 .mapbase = 0xff804000, 118 .mapbase = 0xff804000,
138 .flags = UPF_BOOT_AUTOCONF, 119 .flags = UPF_BOOT_AUTOCONF,
139 .type = PORT_SCIF, 120 .type = PORT_SCIF,
140 .irqs = { 223, 220, 221, 222 }, 121 .irqs = { 220, 220, 220, 220 },
141 }, { 122 }, {
142 .flags = 0, 123 .flags = 0,
143 } 124 }
diff --git a/arch/sh/kernel/cpu/sh2a/setup-sh7201.c b/arch/sh/kernel/cpu/sh2a/setup-sh7201.c
index 0631e421c022..00f42f9e3f5c 100644
--- a/arch/sh/kernel/cpu/sh2a/setup-sh7201.c
+++ b/arch/sh/kernel/cpu/sh2a/setup-sh7201.c
@@ -2,6 +2,7 @@
2 * SH7201 setup 2 * SH7201 setup
3 * 3 *
4 * Copyright (C) 2008 Peter Griffin pgriffin@mpc-data.co.uk 4 * Copyright (C) 2008 Peter Griffin pgriffin@mpc-data.co.uk
5 * Copyright (C) 2009 Paul Mundt
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public 7 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive 8 * License. See the file "COPYING" in the main directory of this archive
@@ -18,57 +19,32 @@ enum {
18 /* interrupt sources */ 19 /* interrupt sources */
19 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7, 20 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7,
20 PINT0, PINT1, PINT2, PINT3, PINT4, PINT5, PINT6, PINT7, 21 PINT0, PINT1, PINT2, PINT3, PINT4, PINT5, PINT6, PINT7,
22
21 ADC_ADI, 23 ADC_ADI,
22 MTU2_TGI0A, MTU2_TGI0B, MTU2_TGI0C, MTU2_TGI0D, 24
23 MTU2_TCI0V, MTU2_TGI0E, MTU2_TGI0F, 25 MTU20_ABCD, MTU20_VEF, MTU21_AB, MTU21_VU, MTU22_AB, MTU22_VU,
24 MTU2_TGI1A, MTU2_TGI1B, MTU2_TCI1V, MTU2_TCI1U, 26 MTU23_ABCD, MTU24_ABCD, MTU25_UVW, MTU2_TCI3V, MTU2_TCI4V,
25 MTU2_TGI2A, MTU2_TGI2B, MTU2_TCI2V, MTU2_TCI2U, 27
26 MTU2_TGI3A, MTU2_TGI3B, MTU2_TGI3C, MTU2_TGI3D, MTU2_TCI3V, 28 RTC, WDT,
27 MTU2_TGI4A, MTU2_TGI4B, MTU2_TGI4C, MTU2_TGI4D, MTU2_TCI4V, 29
28 MTU2_TGI5U, MTU2_TGI5V, MTU2_TGI5W, 30 IIC30, IIC31, IIC32,
29 RTC_ARM, RTC_PRD, RTC_CUP,
30 WDT,
31 IIC30_STPI, IIC30_NAKI, IIC30_RXI, IIC30_TXI, IIC30_TEI,
32 IIC31_STPI, IIC31_NAKI, IIC31_RXI, IIC31_TXI, IIC31_TEI,
33 IIC32_STPI, IIC32_NAKI, IIC32_RXI, IIC32_TXI, IIC32_TEI,
34 31
35 DMAC0_DMINT0, DMAC1_DMINT1, 32 DMAC0_DMINT0, DMAC1_DMINT1,
36 DMAC2_DMINT2, DMAC3_DMINT3, 33 DMAC2_DMINT2, DMAC3_DMINT3,
37 34
38 SCIF0_BRI, SCIF0_ERI, SCIF0_RXI, SCIF0_TXI, 35 SCIF0, SCIF1, SCIF2, SCIF3, SCIF4, SCIF5, SCIF6, SCIF7,
39 SCIF1_BRI, SCIF1_ERI, SCIF1_RXI, SCIF1_TXI,
40 SCIF2_BRI, SCIF2_ERI, SCIF2_RXI, SCIF2_TXI,
41 SCIF3_BRI, SCIF3_ERI, SCIF3_RXI, SCIF3_TXI,
42 SCIF4_BRI, SCIF4_ERI, SCIF4_RXI, SCIF4_TXI,
43 SCIF5_BRI, SCIF5_ERI, SCIF5_RXI, SCIF5_TXI,
44 SCIF6_BRI, SCIF6_ERI, SCIF6_RXI, SCIF6_TXI,
45 SCIF7_BRI, SCIF7_ERI, SCIF7_RXI, SCIF7_TXI,
46 36
47 DMAC0_DMINTA, DMAC4_DMINT4, DMAC5_DMINT5, DMAC6_DMINT6, 37 DMAC0_DMINTA, DMAC4_DMINT4, DMAC5_DMINT5, DMAC6_DMINT6,
48 DMAC7_DMINT7, 38 DMAC7_DMINT7,
49 39
50 RCAN0_ERS, RCAN0_OVR, 40 RCAN0, RCAN1,
51 RCAN0_SLE,
52 RCAN0_RM0, RCAN0_RM1,
53
54 RCAN1_ERS, RCAN1_OVR,
55 RCAN1_SLE,
56 RCAN1_RM0, RCAN1_RM1,
57 41
58 SSI0_SSII, SSI1_SSII, 42 SSI0_SSII, SSI1_SSII,
59 43
60 TMR0_CMIA0, TMR0_CMIB0, TMR0_OVI0, 44 TMR0, TMR1,
61 TMR1_CMIA1, TMR1_CMIB1, TMR1_OVI1,
62 45
63 /* interrupt groups */ 46 /* interrupt groups */
64 47 PINT,
65 IRQ, PINT, ADC,
66 MTU20_ABCD, MTU20_VEF, MTU21_AB, MTU21_VU, MTU22_AB, MTU22_VU,
67 MTU23_ABCD, MTU24_ABCD, MTU25_UVW,
68 RTC, IIC30, IIC31, IIC32,
69 SCIF0, SCIF1, SCIF2, SCIF3, SCIF4, SCIF5, SCIF6, SCIF7,
70 RCAN0, RCAN1, TMR0, TMR1
71
72}; 48};
73 49
74static struct intc_vect vectors[] __initdata = { 50static struct intc_vect vectors[] __initdata = {
@@ -76,6 +52,7 @@ static struct intc_vect vectors[] __initdata = {
76 INTC_IRQ(IRQ2, 66), INTC_IRQ(IRQ3, 67), 52 INTC_IRQ(IRQ2, 66), INTC_IRQ(IRQ3, 67),
77 INTC_IRQ(IRQ4, 68), INTC_IRQ(IRQ5, 69), 53 INTC_IRQ(IRQ4, 68), INTC_IRQ(IRQ5, 69),
78 INTC_IRQ(IRQ6, 70), INTC_IRQ(IRQ7, 71), 54 INTC_IRQ(IRQ6, 70), INTC_IRQ(IRQ7, 71),
55
79 INTC_IRQ(PINT0, 80), INTC_IRQ(PINT1, 81), 56 INTC_IRQ(PINT0, 80), INTC_IRQ(PINT1, 81),
80 INTC_IRQ(PINT2, 82), INTC_IRQ(PINT3, 83), 57 INTC_IRQ(PINT2, 82), INTC_IRQ(PINT3, 83),
81 INTC_IRQ(PINT4, 84), INTC_IRQ(PINT5, 85), 58 INTC_IRQ(PINT4, 84), INTC_IRQ(PINT5, 85),
@@ -83,123 +60,92 @@ static struct intc_vect vectors[] __initdata = {
83 60
84 INTC_IRQ(ADC_ADI, 92), 61 INTC_IRQ(ADC_ADI, 92),
85 62
86 INTC_IRQ(MTU2_TGI0A, 108), INTC_IRQ(MTU2_TGI0B, 109), 63 INTC_IRQ(MTU20_ABCD, 108), INTC_IRQ(MTU20_ABCD, 109),
87 INTC_IRQ(MTU2_TGI0C, 110), INTC_IRQ(MTU2_TGI0D, 111), 64 INTC_IRQ(MTU20_ABCD, 110), INTC_IRQ(MTU20_ABCD, 111),
88 INTC_IRQ(MTU2_TCI0V, 112), 65
89 INTC_IRQ(MTU2_TGI0E, 113), INTC_IRQ(MTU2_TGI0F, 114), 66 INTC_IRQ(MTU20_VEF, 112), INTC_IRQ(MTU20_VEF, 113),
67 INTC_IRQ(MTU20_VEF, 114),
68
69 INTC_IRQ(MTU21_AB, 116), INTC_IRQ(MTU21_AB, 117),
70 INTC_IRQ(MTU21_VU, 120), INTC_IRQ(MTU21_VU, 121),
90 71
91 INTC_IRQ(MTU2_TGI1A, 116), INTC_IRQ(MTU2_TGI1B, 117), 72 INTC_IRQ(MTU22_AB, 124), INTC_IRQ(MTU22_AB, 125),
92 INTC_IRQ(MTU2_TCI1V, 120), INTC_IRQ(MTU2_TCI1U, 121), 73 INTC_IRQ(MTU22_VU, 128), INTC_IRQ(MTU22_VU, 129),
93 74
94 INTC_IRQ(MTU2_TGI2A, 124), INTC_IRQ(MTU2_TGI2B, 125), 75 INTC_IRQ(MTU23_ABCD, 132), INTC_IRQ(MTU23_ABCD, 133),
95 INTC_IRQ(MTU2_TCI2V, 128), INTC_IRQ(MTU2_TCI2U, 129), 76 INTC_IRQ(MTU23_ABCD, 134), INTC_IRQ(MTU23_ABCD, 135),
96 77
97 INTC_IRQ(MTU2_TGI3A, 132), INTC_IRQ(MTU2_TGI3B, 133),
98 INTC_IRQ(MTU2_TGI3C, 134), INTC_IRQ(MTU2_TGI3D, 135),
99 INTC_IRQ(MTU2_TCI3V, 136), 78 INTC_IRQ(MTU2_TCI3V, 136),
100 79
101 INTC_IRQ(MTU2_TGI4A, 140), INTC_IRQ(MTU2_TGI4B, 141), 80 INTC_IRQ(MTU24_ABCD, 140), INTC_IRQ(MTU24_ABCD, 141),
102 INTC_IRQ(MTU2_TGI4C, 142), INTC_IRQ(MTU2_TGI4D, 143), 81 INTC_IRQ(MTU24_ABCD, 142), INTC_IRQ(MTU24_ABCD, 143),
82
103 INTC_IRQ(MTU2_TCI4V, 144), 83 INTC_IRQ(MTU2_TCI4V, 144),
104 84
105 INTC_IRQ(MTU2_TGI5U, 148), INTC_IRQ(MTU2_TGI5V, 149), 85 INTC_IRQ(MTU25_UVW, 148), INTC_IRQ(MTU25_UVW, 149),
106 INTC_IRQ(MTU2_TGI5W, 150), 86 INTC_IRQ(MTU25_UVW, 150),
87
88 INTC_IRQ(RTC, 152), INTC_IRQ(RTC, 153),
89 INTC_IRQ(RTC, 154),
107 90
108 INTC_IRQ(RTC_ARM, 152), INTC_IRQ(RTC_PRD, 153), 91 INTC_IRQ(WDT, 156),
109 INTC_IRQ(RTC_CUP, 154), INTC_IRQ(WDT, 156),
110 92
111 INTC_IRQ(IIC30_STPI, 157), INTC_IRQ(IIC30_NAKI, 158), 93 INTC_IRQ(IIC30, 157), INTC_IRQ(IIC30, 158),
112 INTC_IRQ(IIC30_RXI, 159), INTC_IRQ(IIC30_TXI, 160), 94 INTC_IRQ(IIC30, 159), INTC_IRQ(IIC30, 160),
113 INTC_IRQ(IIC30_TEI, 161), 95 INTC_IRQ(IIC30, 161),
114 96
115 INTC_IRQ(IIC31_STPI, 164), INTC_IRQ(IIC31_NAKI, 165), 97 INTC_IRQ(IIC31, 164), INTC_IRQ(IIC31, 165),
116 INTC_IRQ(IIC31_RXI, 166), INTC_IRQ(IIC31_TXI, 167), 98 INTC_IRQ(IIC31, 166), INTC_IRQ(IIC31, 167),
117 INTC_IRQ(IIC31_TEI, 168), 99 INTC_IRQ(IIC31, 168),
118 100
119 INTC_IRQ(IIC32_STPI, 170), INTC_IRQ(IIC32_NAKI, 171), 101 INTC_IRQ(IIC32, 170), INTC_IRQ(IIC32, 171),
120 INTC_IRQ(IIC32_RXI, 172), INTC_IRQ(IIC32_TXI, 173), 102 INTC_IRQ(IIC32, 172), INTC_IRQ(IIC32, 173),
121 INTC_IRQ(IIC32_TEI, 174), 103 INTC_IRQ(IIC32, 174),
122 104
123 INTC_IRQ(DMAC0_DMINT0, 176), INTC_IRQ(DMAC1_DMINT1, 177), 105 INTC_IRQ(DMAC0_DMINT0, 176), INTC_IRQ(DMAC1_DMINT1, 177),
124 INTC_IRQ(DMAC2_DMINT2, 178), INTC_IRQ(DMAC3_DMINT3, 179), 106 INTC_IRQ(DMAC2_DMINT2, 178), INTC_IRQ(DMAC3_DMINT3, 179),
125 107
126 INTC_IRQ(SCIF0_BRI, 180), INTC_IRQ(SCIF0_ERI, 181), 108 INTC_IRQ(SCIF0, 180), INTC_IRQ(SCIF0, 181),
127 INTC_IRQ(SCIF0_RXI, 182), INTC_IRQ(SCIF0_TXI, 183), 109 INTC_IRQ(SCIF0, 182), INTC_IRQ(SCIF0, 183),
128 INTC_IRQ(SCIF1_BRI, 184), INTC_IRQ(SCIF1_ERI, 185), 110 INTC_IRQ(SCIF1, 184), INTC_IRQ(SCIF1, 185),
129 INTC_IRQ(SCIF1_RXI, 186), INTC_IRQ(SCIF1_TXI, 187), 111 INTC_IRQ(SCIF1, 186), INTC_IRQ(SCIF1, 187),
130 INTC_IRQ(SCIF2_BRI, 188), INTC_IRQ(SCIF2_ERI, 189), 112 INTC_IRQ(SCIF2, 188), INTC_IRQ(SCIF2, 189),
131 INTC_IRQ(SCIF2_RXI, 190), INTC_IRQ(SCIF2_TXI, 191), 113 INTC_IRQ(SCIF2, 190), INTC_IRQ(SCIF2, 191),
132 INTC_IRQ(SCIF3_BRI, 192), INTC_IRQ(SCIF3_ERI, 193), 114 INTC_IRQ(SCIF3, 192), INTC_IRQ(SCIF3, 193),
133 INTC_IRQ(SCIF3_RXI, 194), INTC_IRQ(SCIF3_TXI, 195), 115 INTC_IRQ(SCIF3, 194), INTC_IRQ(SCIF3, 195),
134 INTC_IRQ(SCIF4_BRI, 196), INTC_IRQ(SCIF4_ERI, 197), 116 INTC_IRQ(SCIF4, 196), INTC_IRQ(SCIF4, 197),
135 INTC_IRQ(SCIF4_RXI, 198), INTC_IRQ(SCIF4_TXI, 199), 117 INTC_IRQ(SCIF4, 198), INTC_IRQ(SCIF4, 199),
136 INTC_IRQ(SCIF5_BRI, 200), INTC_IRQ(SCIF5_ERI, 201), 118 INTC_IRQ(SCIF5, 200), INTC_IRQ(SCIF5, 201),
137 INTC_IRQ(SCIF5_RXI, 202), INTC_IRQ(SCIF5_TXI, 203), 119 INTC_IRQ(SCIF5, 202), INTC_IRQ(SCIF5, 203),
138 INTC_IRQ(SCIF6_BRI, 204), INTC_IRQ(SCIF6_ERI, 205), 120 INTC_IRQ(SCIF6, 204), INTC_IRQ(SCIF6, 205),
139 INTC_IRQ(SCIF6_RXI, 206), INTC_IRQ(SCIF6_TXI, 207), 121 INTC_IRQ(SCIF6, 206), INTC_IRQ(SCIF6, 207),
140 INTC_IRQ(SCIF7_BRI, 208), INTC_IRQ(SCIF7_ERI, 209), 122 INTC_IRQ(SCIF7, 208), INTC_IRQ(SCIF7, 209),
141 INTC_IRQ(SCIF7_RXI, 210), INTC_IRQ(SCIF7_TXI, 211), 123 INTC_IRQ(SCIF7, 210), INTC_IRQ(SCIF7, 211),
142 124
143 INTC_IRQ(DMAC0_DMINTA, 212), INTC_IRQ(DMAC4_DMINT4, 216), 125 INTC_IRQ(DMAC0_DMINTA, 212), INTC_IRQ(DMAC4_DMINT4, 216),
144 INTC_IRQ(DMAC5_DMINT5, 217), INTC_IRQ(DMAC6_DMINT6, 218), 126 INTC_IRQ(DMAC5_DMINT5, 217), INTC_IRQ(DMAC6_DMINT6, 218),
145 INTC_IRQ(DMAC7_DMINT7, 219), 127 INTC_IRQ(DMAC7_DMINT7, 219),
146 128
147 INTC_IRQ(RCAN0_ERS, 228), INTC_IRQ(RCAN0_OVR, 229), 129 INTC_IRQ(RCAN0, 228), INTC_IRQ(RCAN0, 229),
148 INTC_IRQ(RCAN0_SLE, 230), 130 INTC_IRQ(RCAN0, 230),
149 INTC_IRQ(RCAN0_RM0, 231), INTC_IRQ(RCAN0_RM1, 232), 131 INTC_IRQ(RCAN0, 231), INTC_IRQ(RCAN0, 232),
150 132
151 INTC_IRQ(RCAN1_ERS, 234), INTC_IRQ(RCAN1_OVR, 235), 133 INTC_IRQ(RCAN1, 234), INTC_IRQ(RCAN1, 235),
152 INTC_IRQ(RCAN1_SLE, 236), 134 INTC_IRQ(RCAN1, 236),
153 INTC_IRQ(RCAN1_RM0, 237), INTC_IRQ(RCAN1_RM1, 238), 135 INTC_IRQ(RCAN1, 237), INTC_IRQ(RCAN1, 238),
154 136
155 INTC_IRQ(SSI0_SSII, 244), INTC_IRQ(SSI1_SSII, 245), 137 INTC_IRQ(SSI0_SSII, 244), INTC_IRQ(SSI1_SSII, 245),
156 138
157 INTC_IRQ(TMR0_CMIA0, 246), INTC_IRQ(TMR0_CMIB0, 247), 139 INTC_IRQ(TMR0, 246), INTC_IRQ(TMR0, 247),
158 INTC_IRQ(TMR0_OVI0, 248), 140 INTC_IRQ(TMR0, 248),
159
160 INTC_IRQ(TMR1_CMIA1, 252), INTC_IRQ(TMR1_CMIB1, 253),
161 INTC_IRQ(TMR1_OVI1, 254),
162 141
142 INTC_IRQ(TMR1, 252), INTC_IRQ(TMR1, 253),
143 INTC_IRQ(TMR1, 254),
163}; 144};
164 145
165static struct intc_group groups[] __initdata = { 146static struct intc_group groups[] __initdata = {
166 INTC_GROUP(PINT, PINT0, PINT1, PINT2, PINT3, 147 INTC_GROUP(PINT, PINT0, PINT1, PINT2, PINT3,
167 PINT4, PINT5, PINT6, PINT7), 148 PINT4, PINT5, PINT6, PINT7),
168 INTC_GROUP(MTU20_ABCD, MTU2_TGI0A, MTU2_TGI0B, MTU2_TGI0C, MTU2_TGI0D),
169 INTC_GROUP(MTU20_VEF, MTU2_TCI0V, MTU2_TGI0E, MTU2_TGI0F),
170
171 INTC_GROUP(MTU21_AB, MTU2_TGI1A, MTU2_TGI1B),
172 INTC_GROUP(MTU21_VU, MTU2_TCI1V, MTU2_TCI1U),
173 INTC_GROUP(MTU22_AB, MTU2_TGI2A, MTU2_TGI2B),
174 INTC_GROUP(MTU22_VU, MTU2_TCI2V, MTU2_TCI2U),
175 INTC_GROUP(MTU23_ABCD, MTU2_TGI3A, MTU2_TGI3B, MTU2_TGI3C, MTU2_TGI3D),
176 INTC_GROUP(MTU24_ABCD, MTU2_TGI4A, MTU2_TGI4B, MTU2_TGI4C, MTU2_TGI4D),
177 INTC_GROUP(MTU25_UVW, MTU2_TGI5U, MTU2_TGI5V, MTU2_TGI5W),
178 INTC_GROUP(RTC, RTC_ARM, RTC_PRD, RTC_CUP ),
179
180 INTC_GROUP(IIC30, IIC30_STPI, IIC30_NAKI, IIC30_RXI, IIC30_TXI,
181 IIC30_TEI),
182 INTC_GROUP(IIC31, IIC31_STPI, IIC31_NAKI, IIC31_RXI, IIC31_TXI,
183 IIC31_TEI),
184 INTC_GROUP(IIC32, IIC32_STPI, IIC32_NAKI, IIC32_RXI, IIC32_TXI,
185 IIC32_TEI),
186
187 INTC_GROUP(SCIF0, SCIF0_BRI, SCIF0_ERI, SCIF0_RXI, SCIF0_TXI),
188 INTC_GROUP(SCIF1, SCIF1_BRI, SCIF1_ERI, SCIF1_RXI, SCIF1_TXI),
189 INTC_GROUP(SCIF2, SCIF2_BRI, SCIF2_ERI, SCIF2_RXI, SCIF2_TXI),
190 INTC_GROUP(SCIF3, SCIF3_BRI, SCIF3_ERI, SCIF3_RXI, SCIF3_TXI),
191 INTC_GROUP(SCIF4, SCIF4_BRI, SCIF4_ERI, SCIF4_RXI, SCIF4_TXI),
192 INTC_GROUP(SCIF5, SCIF5_BRI, SCIF5_ERI, SCIF5_RXI, SCIF5_TXI),
193 INTC_GROUP(SCIF6, SCIF6_BRI, SCIF6_ERI, SCIF6_RXI, SCIF6_TXI),
194 INTC_GROUP(SCIF7, SCIF7_BRI, SCIF7_ERI, SCIF7_RXI, SCIF7_TXI),
195
196 INTC_GROUP(RCAN0, RCAN0_ERS, RCAN0_OVR, RCAN0_RM0, RCAN0_RM1,
197 RCAN0_SLE),
198 INTC_GROUP(RCAN1, RCAN1_ERS, RCAN1_OVR, RCAN1_RM0, RCAN1_RM1,
199 RCAN1_SLE),
200
201 INTC_GROUP(TMR0, TMR0_CMIA0, TMR0_CMIB0, TMR0_OVI0),
202 INTC_GROUP(TMR1, TMR1_CMIA1, TMR1_CMIB1, TMR1_OVI1),
203}; 149};
204 150
205static struct intc_prio_reg prio_registers[] __initdata = { 151static struct intc_prio_reg prio_registers[] __initdata = {
@@ -212,7 +158,7 @@ static struct intc_prio_reg prio_registers[] __initdata = {
212 158
213 { 0xfffe9806, 0, 16, 4, /* IPR09 */ { RTC, WDT, IIC30, 0 } }, 159 { 0xfffe9806, 0, 16, 4, /* IPR09 */ { RTC, WDT, IIC30, 0 } },
214 { 0xfffe9808, 0, 16, 4, /* IPR10 */ { IIC31, IIC32, DMAC0_DMINT0, DMAC1_DMINT1 } }, 160 { 0xfffe9808, 0, 16, 4, /* IPR10 */ { IIC31, IIC32, DMAC0_DMINT0, DMAC1_DMINT1 } },
215 { 0xfffe980a, 0, 16, 4, /* IPR11 */ { DMAC2_DMINT2, DMAC3_DMINT3, SCIF0 , SCIF1 } }, 161 { 0xfffe980a, 0, 16, 4, /* IPR11 */ { DMAC2_DMINT2, DMAC3_DMINT3, SCIF0, SCIF1 } },
216 { 0xfffe980c, 0, 16, 4, /* IPR12 */ { SCIF2, SCIF3, SCIF4, SCIF5 } }, 162 { 0xfffe980c, 0, 16, 4, /* IPR12 */ { SCIF2, SCIF3, SCIF4, SCIF5 } },
217 { 0xfffe980e, 0, 16, 4, /* IPR13 */ { SCIF6, SCIF7, DMAC0_DMINTA, DMAC4_DMINT4 } }, 163 { 0xfffe980e, 0, 16, 4, /* IPR13 */ { SCIF6, SCIF7, DMAC0_DMINTA, DMAC4_DMINT4 } },
218 { 0xfffe9810, 0, 16, 4, /* IPR14 */ { DMAC5_DMINT5, DMAC6_DMINT6, DMAC7_DMINT7, 0 } }, 164 { 0xfffe9810, 0, 16, 4, /* IPR14 */ { DMAC5_DMINT5, DMAC6_DMINT6, DMAC7_DMINT7, 0 } },
@@ -234,42 +180,42 @@ static struct plat_sci_port sci_platform_data[] = {
234 .mapbase = 0xfffe8000, 180 .mapbase = 0xfffe8000,
235 .flags = UPF_BOOT_AUTOCONF, 181 .flags = UPF_BOOT_AUTOCONF,
236 .type = PORT_SCIF, 182 .type = PORT_SCIF,
237 .irqs = { 181, 182, 183, 180} 183 .irqs = { 180, 180, 180, 180 }
238 }, { 184 }, {
239 .mapbase = 0xfffe8800, 185 .mapbase = 0xfffe8800,
240 .flags = UPF_BOOT_AUTOCONF, 186 .flags = UPF_BOOT_AUTOCONF,
241 .type = PORT_SCIF, 187 .type = PORT_SCIF,
242 .irqs = { 185, 186, 187, 184} 188 .irqs = { 184, 184, 184, 184 }
243 }, { 189 }, {
244 .mapbase = 0xfffe9000, 190 .mapbase = 0xfffe9000,
245 .flags = UPF_BOOT_AUTOCONF, 191 .flags = UPF_BOOT_AUTOCONF,
246 .type = PORT_SCIF, 192 .type = PORT_SCIF,
247 .irqs = { 189, 186, 187, 188} 193 .irqs = { 188, 188, 188, 188 }
248 }, { 194 }, {
249 .mapbase = 0xfffe9800, 195 .mapbase = 0xfffe9800,
250 .flags = UPF_BOOT_AUTOCONF, 196 .flags = UPF_BOOT_AUTOCONF,
251 .type = PORT_SCIF, 197 .type = PORT_SCIF,
252 .irqs = { 193, 194, 195, 192} 198 .irqs = { 192, 192, 192, 192 }
253 }, { 199 }, {
254 .mapbase = 0xfffea000, 200 .mapbase = 0xfffea000,
255 .flags = UPF_BOOT_AUTOCONF, 201 .flags = UPF_BOOT_AUTOCONF,
256 .type = PORT_SCIF, 202 .type = PORT_SCIF,
257 .irqs = { 196, 198, 199, 196} 203 .irqs = { 196, 196, 196, 196 }
258 }, { 204 }, {
259 .mapbase = 0xfffea800, 205 .mapbase = 0xfffea800,
260 .flags = UPF_BOOT_AUTOCONF, 206 .flags = UPF_BOOT_AUTOCONF,
261 .type = PORT_SCIF, 207 .type = PORT_SCIF,
262 .irqs = { 201, 202, 203, 200} 208 .irqs = { 200, 200, 200, 200 }
263 }, { 209 }, {
264 .mapbase = 0xfffeb000, 210 .mapbase = 0xfffeb000,
265 .flags = UPF_BOOT_AUTOCONF, 211 .flags = UPF_BOOT_AUTOCONF,
266 .type = PORT_SCIF, 212 .type = PORT_SCIF,
267 .irqs = { 205, 206, 207, 204} 213 .irqs = { 204, 204, 204, 204 }
268 }, { 214 }, {
269 .mapbase = 0xfffeb800, 215 .mapbase = 0xfffeb800,
270 .flags = UPF_BOOT_AUTOCONF, 216 .flags = UPF_BOOT_AUTOCONF,
271 .type = PORT_SCIF, 217 .type = PORT_SCIF,
272 .irqs = { 209, 210, 211, 208} 218 .irqs = { 208, 208, 208, 208 }
273 }, { 219 }, {
274 .flags = 0, 220 .flags = 0,
275 } 221 }
@@ -290,17 +236,7 @@ static struct resource rtc_resources[] = {
290 .flags = IORESOURCE_IO, 236 .flags = IORESOURCE_IO,
291 }, 237 },
292 [1] = { 238 [1] = {
293 /* Period IRQ */ 239 /* Shared Period/Carry/Alarm IRQ */
294 .start = 153,
295 .flags = IORESOURCE_IRQ,
296 },
297 [2] = {
298 /* Carry IRQ */
299 .start = 154,
300 .flags = IORESOURCE_IRQ,
301 },
302 [3] = {
303 /* Alarm IRQ */
304 .start = 152, 240 .start = 152,
305 .flags = IORESOURCE_IRQ, 241 .flags = IORESOURCE_IRQ,
306 }, 242 },
diff --git a/arch/sh/kernel/cpu/sh2a/setup-sh7203.c b/arch/sh/kernel/cpu/sh2a/setup-sh7203.c
index e98dc4450352..820dfb2e8656 100644
--- a/arch/sh/kernel/cpu/sh2a/setup-sh7203.c
+++ b/arch/sh/kernel/cpu/sh2a/setup-sh7203.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * SH7203 and SH7263 Setup 2 * SH7203 and SH7263 Setup
3 * 3 *
4 * Copyright (C) 2007 Paul Mundt 4 * Copyright (C) 2007 - 2009 Paul Mundt
5 * 5 *
6 * This file is subject to the terms and conditions of the GNU General Public 6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive 7 * License. See the file "COPYING" in the main directory of this archive
@@ -18,50 +18,27 @@ enum {
18 /* interrupt sources */ 18 /* interrupt sources */
19 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7, 19 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7,
20 PINT0, PINT1, PINT2, PINT3, PINT4, PINT5, PINT6, PINT7, 20 PINT0, PINT1, PINT2, PINT3, PINT4, PINT5, PINT6, PINT7,
21 DMAC0_DEI, DMAC0_HEI, DMAC1_DEI, DMAC1_HEI, 21 DMAC0, DMAC1, DMAC2, DMAC3, DMAC4, DMAC5, DMAC6, DMAC7,
22 DMAC2_DEI, DMAC2_HEI, DMAC3_DEI, DMAC3_HEI,
23 DMAC4_DEI, DMAC4_HEI, DMAC5_DEI, DMAC5_HEI,
24 DMAC6_DEI, DMAC6_HEI, DMAC7_DEI, DMAC7_HEI,
25 USB, LCDC, CMT0, CMT1, BSC, WDT, 22 USB, LCDC, CMT0, CMT1, BSC, WDT,
26 MTU2_TGI0A, MTU2_TGI0B, MTU2_TGI0C, MTU2_TGI0D,
27 MTU2_TCI0V, MTU2_TGI0E, MTU2_TGI0F,
28 MTU2_TGI1A, MTU2_TGI1B, MTU2_TCI1V, MTU2_TCI1U,
29 MTU2_TGI2A, MTU2_TGI2B, MTU2_TCI2V, MTU2_TCI2U,
30 MTU2_TGI3A, MTU2_TGI3B, MTU2_TGI3C, MTU2_TGI3D, MTU2_TCI3V,
31 MTU2_TGI4A, MTU2_TGI4B, MTU2_TGI4C, MTU2_TGI4D, MTU2_TCI4V,
32 ADC_ADI,
33 IIC30_STPI, IIC30_NAKI, IIC30_RXI, IIC30_TXI, IIC30_TEI,
34 IIC31_STPI, IIC31_NAKI, IIC31_RXI, IIC31_TXI, IIC31_TEI,
35 IIC32_STPI, IIC32_NAKI, IIC32_RXI, IIC32_TXI, IIC32_TEI,
36 IIC33_STPI, IIC33_NAKI, IIC33_RXI, IIC33_TXI, IIC33_TEI,
37 SCIF0_BRI, SCIF0_ERI, SCIF0_RXI, SCIF0_TXI,
38 SCIF1_BRI, SCIF1_ERI, SCIF1_RXI, SCIF1_TXI,
39 SCIF2_BRI, SCIF2_ERI, SCIF2_RXI, SCIF2_TXI,
40 SCIF3_BRI, SCIF3_ERI, SCIF3_RXI, SCIF3_TXI,
41 SSU0_SSERI, SSU0_SSRXI, SSU0_SSTXI,
42 SSU1_SSERI, SSU1_SSRXI, SSU1_SSTXI,
43 SSI0_SSII, SSI1_SSII, SSI2_SSII, SSI3_SSII,
44 23
45 /* ROM-DEC, SDHI, SRC, and IEB are SH7263 specific */ 24 MTU0_ABCD, MTU0_VEF, MTU1_AB, MTU1_VU, MTU2_AB, MTU2_VU,
46 ROMDEC_ISY, ROMDEC_IERR, ROMDEC_IARG, ROMDEC_ISEC, ROMDEC_IBUF, 25 MTU3_ABCD, MTU4_ABCD, MTU2_TCI3V, MTU2_TCI4V,
47 ROMDEC_IREADY,
48 26
49 FLCTL_FLSTEI, FLCTL_FLTENDI, FLCTL_FLTREQ0I, FLCTL_FLTREQ1I, 27 ADC_ADI,
28
29 IIC30, IIC31, IIC32, IIC33,
30 SCIF0, SCIF1, SCIF2, SCIF3,
50 31
51 SDHI3, SDHI0, SDHI1, 32 SSU0, SSU1,
52 33
53 RTC_ARM, RTC_PRD, RTC_CUP, 34 SSI0_SSII, SSI1_SSII, SSI2_SSII, SSI3_SSII,
54 RCAN0_ERS, RCAN0_OVR, RCAN0_RM0, RCAN0_RM1, RCAN0_SLE,
55 RCAN1_ERS, RCAN1_OVR, RCAN1_RM0, RCAN1_RM1, RCAN1_SLE,
56 35
57 SRC_OVF, SRC_ODFI, SRC_IDEI, IEBI, 36 /* ROM-DEC, SDHI, SRC, and IEB are SH7263 specific */
37 ROMDEC, FLCTL, SDHI, RTC, RCAN0, RCAN1,
38 SRC, IEBI,
58 39
59 /* interrupt groups */ 40 /* interrupt groups */
60 PINT, DMAC0, DMAC1, DMAC2, DMAC3, DMAC4, DMAC5, DMAC6, DMAC7, 41 PINT,
61 MTU0_ABCD, MTU0_VEF, MTU1_AB, MTU1_VU, MTU2_AB, MTU2_VU,
62 MTU3_ABCD, MTU4_ABCD,
63 IIC30, IIC31, IIC32, IIC33, SCIF0, SCIF1, SCIF2, SCIF3,
64 SSU0, SSU1, ROMDEC, SDHI, FLCTL, RTC, RCAN0, RCAN1, SRC
65}; 42};
66 43
67static struct intc_vect vectors[] __initdata = { 44static struct intc_vect vectors[] __initdata = {
@@ -73,79 +50,80 @@ static struct intc_vect vectors[] __initdata = {
73 INTC_IRQ(PINT2, 82), INTC_IRQ(PINT3, 83), 50 INTC_IRQ(PINT2, 82), INTC_IRQ(PINT3, 83),
74 INTC_IRQ(PINT4, 84), INTC_IRQ(PINT5, 85), 51 INTC_IRQ(PINT4, 84), INTC_IRQ(PINT5, 85),
75 INTC_IRQ(PINT6, 86), INTC_IRQ(PINT7, 87), 52 INTC_IRQ(PINT6, 86), INTC_IRQ(PINT7, 87),
76 INTC_IRQ(DMAC0_DEI, 108), INTC_IRQ(DMAC0_HEI, 109), 53 INTC_IRQ(DMAC0, 108), INTC_IRQ(DMAC0, 109),
77 INTC_IRQ(DMAC1_DEI, 112), INTC_IRQ(DMAC1_HEI, 113), 54 INTC_IRQ(DMAC1, 112), INTC_IRQ(DMAC1, 113),
78 INTC_IRQ(DMAC2_DEI, 116), INTC_IRQ(DMAC2_HEI, 117), 55 INTC_IRQ(DMAC2, 116), INTC_IRQ(DMAC2, 117),
79 INTC_IRQ(DMAC3_DEI, 120), INTC_IRQ(DMAC3_HEI, 121), 56 INTC_IRQ(DMAC3, 120), INTC_IRQ(DMAC3, 121),
80 INTC_IRQ(DMAC4_DEI, 124), INTC_IRQ(DMAC4_HEI, 125), 57 INTC_IRQ(DMAC4, 124), INTC_IRQ(DMAC4, 125),
81 INTC_IRQ(DMAC5_DEI, 128), INTC_IRQ(DMAC5_HEI, 129), 58 INTC_IRQ(DMAC5, 128), INTC_IRQ(DMAC5, 129),
82 INTC_IRQ(DMAC6_DEI, 132), INTC_IRQ(DMAC6_HEI, 133), 59 INTC_IRQ(DMAC6, 132), INTC_IRQ(DMAC6, 133),
83 INTC_IRQ(DMAC7_DEI, 136), INTC_IRQ(DMAC7_HEI, 137), 60 INTC_IRQ(DMAC7, 136), INTC_IRQ(DMAC7, 137),
84 INTC_IRQ(USB, 140), INTC_IRQ(LCDC, 141), 61 INTC_IRQ(USB, 140), INTC_IRQ(LCDC, 141),
85 INTC_IRQ(CMT0, 142), INTC_IRQ(CMT1, 143), 62 INTC_IRQ(CMT0, 142), INTC_IRQ(CMT1, 143),
86 INTC_IRQ(BSC, 144), INTC_IRQ(WDT, 145), 63 INTC_IRQ(BSC, 144), INTC_IRQ(WDT, 145),
87 INTC_IRQ(MTU2_TGI0A, 146), INTC_IRQ(MTU2_TGI0B, 147), 64 INTC_IRQ(MTU0_ABCD, 146), INTC_IRQ(MTU0_ABCD, 147),
88 INTC_IRQ(MTU2_TGI0C, 148), INTC_IRQ(MTU2_TGI0D, 149), 65 INTC_IRQ(MTU0_ABCD, 148), INTC_IRQ(MTU0_ABCD, 149),
89 INTC_IRQ(MTU2_TCI0V, 150), 66 INTC_IRQ(MTU0_VEF, 150),
90 INTC_IRQ(MTU2_TGI0E, 151), INTC_IRQ(MTU2_TGI0F, 152), 67 INTC_IRQ(MTU0_VEF, 151), INTC_IRQ(MTU0_VEF, 152),
91 INTC_IRQ(MTU2_TGI1A, 153), INTC_IRQ(MTU2_TGI1B, 154), 68 INTC_IRQ(MTU1_AB, 153), INTC_IRQ(MTU1_AB, 154),
92 INTC_IRQ(MTU2_TCI1V, 155), INTC_IRQ(MTU2_TCI1U, 156), 69 INTC_IRQ(MTU1_VU, 155), INTC_IRQ(MTU1_VU, 156),
93 INTC_IRQ(MTU2_TGI2A, 157), INTC_IRQ(MTU2_TGI2B, 158), 70 INTC_IRQ(MTU2_AB, 157), INTC_IRQ(MTU2_AB, 158),
94 INTC_IRQ(MTU2_TCI2V, 159), INTC_IRQ(MTU2_TCI2U, 160), 71 INTC_IRQ(MTU2_VU, 159), INTC_IRQ(MTU2_VU, 160),
95 INTC_IRQ(MTU2_TGI3A, 161), INTC_IRQ(MTU2_TGI3B, 162), 72 INTC_IRQ(MTU3_ABCD, 161), INTC_IRQ(MTU3_ABCD, 162),
96 INTC_IRQ(MTU2_TGI3C, 163), INTC_IRQ(MTU2_TGI3D, 164), 73 INTC_IRQ(MTU3_ABCD, 163), INTC_IRQ(MTU3_ABCD, 164),
97 INTC_IRQ(MTU2_TCI3V, 165), 74 INTC_IRQ(MTU2_TCI3V, 165),
98 INTC_IRQ(MTU2_TGI4A, 166), INTC_IRQ(MTU2_TGI4B, 167), 75 INTC_IRQ(MTU4_ABCD, 166), INTC_IRQ(MTU4_ABCD, 167),
99 INTC_IRQ(MTU2_TGI4C, 168), INTC_IRQ(MTU2_TGI4D, 169), 76 INTC_IRQ(MTU4_ABCD, 168), INTC_IRQ(MTU4_ABCD, 169),
100 INTC_IRQ(MTU2_TCI4V, 170), 77 INTC_IRQ(MTU2_TCI4V, 170),
101 INTC_IRQ(ADC_ADI, 171), 78 INTC_IRQ(ADC_ADI, 171),
102 INTC_IRQ(IIC30_STPI, 172), INTC_IRQ(IIC30_NAKI, 173), 79 INTC_IRQ(IIC30, 172), INTC_IRQ(IIC30, 173),
103 INTC_IRQ(IIC30_RXI, 174), INTC_IRQ(IIC30_TXI, 175), 80 INTC_IRQ(IIC30, 174), INTC_IRQ(IIC30, 175),
104 INTC_IRQ(IIC30_TEI, 176), 81 INTC_IRQ(IIC30, 176),
105 INTC_IRQ(IIC31_STPI, 177), INTC_IRQ(IIC31_NAKI, 178), 82 INTC_IRQ(IIC31, 177), INTC_IRQ(IIC31, 178),
106 INTC_IRQ(IIC31_RXI, 179), INTC_IRQ(IIC31_TXI, 180), 83 INTC_IRQ(IIC31, 179), INTC_IRQ(IIC31, 180),
107 INTC_IRQ(IIC31_TEI, 181), 84 INTC_IRQ(IIC31, 181),
108 INTC_IRQ(IIC32_STPI, 182), INTC_IRQ(IIC32_NAKI, 183), 85 INTC_IRQ(IIC32, 182), INTC_IRQ(IIC32, 183),
109 INTC_IRQ(IIC32_RXI, 184), INTC_IRQ(IIC32_TXI, 185), 86 INTC_IRQ(IIC32, 184), INTC_IRQ(IIC32, 185),
110 INTC_IRQ(IIC32_TEI, 186), 87 INTC_IRQ(IIC32, 186),
111 INTC_IRQ(IIC33_STPI, 187), INTC_IRQ(IIC33_NAKI, 188), 88 INTC_IRQ(IIC33, 187), INTC_IRQ(IIC33, 188),
112 INTC_IRQ(IIC33_RXI, 189), INTC_IRQ(IIC33_TXI, 190), 89 INTC_IRQ(IIC33, 189), INTC_IRQ(IIC33, 190),
113 INTC_IRQ(IIC33_TEI, 191), 90 INTC_IRQ(IIC33, 191),
114 INTC_IRQ(SCIF0_BRI, 192), INTC_IRQ(SCIF0_ERI, 193), 91 INTC_IRQ(SCIF0, 192), INTC_IRQ(SCIF0, 193),
115 INTC_IRQ(SCIF0_RXI, 194), INTC_IRQ(SCIF0_TXI, 195), 92 INTC_IRQ(SCIF0, 194), INTC_IRQ(SCIF0, 195),
116 INTC_IRQ(SCIF1_BRI, 196), INTC_IRQ(SCIF1_ERI, 197), 93 INTC_IRQ(SCIF1, 196), INTC_IRQ(SCIF1, 197),
117 INTC_IRQ(SCIF1_RXI, 198), INTC_IRQ(SCIF1_TXI, 199), 94 INTC_IRQ(SCIF1, 198), INTC_IRQ(SCIF1, 199),
118 INTC_IRQ(SCIF2_BRI, 200), INTC_IRQ(SCIF2_ERI, 201), 95 INTC_IRQ(SCIF2, 200), INTC_IRQ(SCIF2, 201),
119 INTC_IRQ(SCIF2_RXI, 202), INTC_IRQ(SCIF2_TXI, 203), 96 INTC_IRQ(SCIF2, 202), INTC_IRQ(SCIF2, 203),
120 INTC_IRQ(SCIF3_BRI, 204), INTC_IRQ(SCIF3_ERI, 205), 97 INTC_IRQ(SCIF3, 204), INTC_IRQ(SCIF3, 205),
121 INTC_IRQ(SCIF3_RXI, 206), INTC_IRQ(SCIF3_TXI, 207), 98 INTC_IRQ(SCIF3, 206), INTC_IRQ(SCIF3, 207),
122 INTC_IRQ(SSU0_SSERI, 208), INTC_IRQ(SSU0_SSRXI, 209), 99 INTC_IRQ(SSU0, 208), INTC_IRQ(SSU0, 209),
123 INTC_IRQ(SSU0_SSTXI, 210), 100 INTC_IRQ(SSU0, 210),
124 INTC_IRQ(SSU1_SSERI, 211), INTC_IRQ(SSU1_SSRXI, 212), 101 INTC_IRQ(SSU1, 211), INTC_IRQ(SSU1, 212),
125 INTC_IRQ(SSU1_SSTXI, 213), 102 INTC_IRQ(SSU1, 213),
126 INTC_IRQ(SSI0_SSII, 214), INTC_IRQ(SSI1_SSII, 215), 103 INTC_IRQ(SSI0_SSII, 214), INTC_IRQ(SSI1_SSII, 215),
127 INTC_IRQ(SSI2_SSII, 216), INTC_IRQ(SSI3_SSII, 217), 104 INTC_IRQ(SSI2_SSII, 216), INTC_IRQ(SSI3_SSII, 217),
128 INTC_IRQ(FLCTL_FLSTEI, 224), INTC_IRQ(FLCTL_FLTENDI, 225), 105 INTC_IRQ(FLCTL, 224), INTC_IRQ(FLCTL, 225),
129 INTC_IRQ(FLCTL_FLTREQ0I, 226), INTC_IRQ(FLCTL_FLTREQ1I, 227), 106 INTC_IRQ(FLCTL, 226), INTC_IRQ(FLCTL, 227),
130 INTC_IRQ(RTC_ARM, 231), INTC_IRQ(RTC_PRD, 232), 107 INTC_IRQ(RTC, 231), INTC_IRQ(RTC, 232),
131 INTC_IRQ(RTC_CUP, 233), 108 INTC_IRQ(RTC, 233),
132 INTC_IRQ(RCAN0_ERS, 234), INTC_IRQ(RCAN0_OVR, 235), 109 INTC_IRQ(RCAN0, 234), INTC_IRQ(RCAN0, 235),
133 INTC_IRQ(RCAN0_RM0, 236), INTC_IRQ(RCAN0_RM1, 237), 110 INTC_IRQ(RCAN0, 236), INTC_IRQ(RCAN0, 237),
134 INTC_IRQ(RCAN0_SLE, 238), 111 INTC_IRQ(RCAN0, 238),
135 INTC_IRQ(RCAN1_ERS, 239), INTC_IRQ(RCAN1_OVR, 240), 112 INTC_IRQ(RCAN1, 239), INTC_IRQ(RCAN1, 240),
136 INTC_IRQ(RCAN1_RM0, 241), INTC_IRQ(RCAN1_RM1, 242), 113 INTC_IRQ(RCAN1, 241), INTC_IRQ(RCAN1, 242),
137 INTC_IRQ(RCAN1_SLE, 243), 114 INTC_IRQ(RCAN1, 243),
138 115
139 /* SH7263-specific trash */ 116 /* SH7263-specific trash */
140#ifdef CONFIG_CPU_SUBTYPE_SH7263 117#ifdef CONFIG_CPU_SUBTYPE_SH7263
141 INTC_IRQ(ROMDEC_ISY, 218), INTC_IRQ(ROMDEC_IERR, 219), 118 INTC_IRQ(ROMDEC, 218), INTC_IRQ(ROMDEC, 219),
142 INTC_IRQ(ROMDEC_IARG, 220), INTC_IRQ(ROMDEC_ISEC, 221), 119 INTC_IRQ(ROMDEC, 220), INTC_IRQ(ROMDEC, 221),
143 INTC_IRQ(ROMDEC_IBUF, 222), INTC_IRQ(ROMDEC_IREADY, 223), 120 INTC_IRQ(ROMDEC, 222), INTC_IRQ(ROMDEC, 223),
144 121
145 INTC_IRQ(SDHI3, 228), INTC_IRQ(SDHI0, 229), INTC_IRQ(SDHI1, 230), 122 INTC_IRQ(SDHI, 228), INTC_IRQ(SDHI, 229),
123 INTC_IRQ(SDHI, 230),
146 124
147 INTC_IRQ(SRC_OVF, 244), INTC_IRQ(SRC_ODFI, 245), 125 INTC_IRQ(SRC, 244), INTC_IRQ(SRC, 245),
148 INTC_IRQ(SRC_IDEI, 246), 126 INTC_IRQ(SRC, 246),
149 127
150 INTC_IRQ(IEBI, 247), 128 INTC_IRQ(IEBI, 247),
151#endif 129#endif
@@ -154,50 +132,6 @@ static struct intc_vect vectors[] __initdata = {
154static struct intc_group groups[] __initdata = { 132static struct intc_group groups[] __initdata = {
155 INTC_GROUP(PINT, PINT0, PINT1, PINT2, PINT3, 133 INTC_GROUP(PINT, PINT0, PINT1, PINT2, PINT3,
156 PINT4, PINT5, PINT6, PINT7), 134 PINT4, PINT5, PINT6, PINT7),
157 INTC_GROUP(DMAC0, DMAC0_DEI, DMAC0_HEI),
158 INTC_GROUP(DMAC1, DMAC1_DEI, DMAC1_HEI),
159 INTC_GROUP(DMAC2, DMAC2_DEI, DMAC2_HEI),
160 INTC_GROUP(DMAC3, DMAC3_DEI, DMAC3_HEI),
161 INTC_GROUP(DMAC4, DMAC4_DEI, DMAC4_HEI),
162 INTC_GROUP(DMAC5, DMAC5_DEI, DMAC5_HEI),
163 INTC_GROUP(DMAC6, DMAC6_DEI, DMAC6_HEI),
164 INTC_GROUP(DMAC7, DMAC7_DEI, DMAC7_HEI),
165 INTC_GROUP(MTU0_ABCD, MTU2_TGI0A, MTU2_TGI0B, MTU2_TGI0C, MTU2_TGI0D),
166 INTC_GROUP(MTU0_VEF, MTU2_TCI0V, MTU2_TGI0E, MTU2_TGI0F),
167 INTC_GROUP(MTU1_AB, MTU2_TGI1A, MTU2_TGI1B),
168 INTC_GROUP(MTU1_VU, MTU2_TCI1V, MTU2_TCI1U),
169 INTC_GROUP(MTU2_AB, MTU2_TGI2A, MTU2_TGI2B),
170 INTC_GROUP(MTU2_VU, MTU2_TCI2V, MTU2_TCI2U),
171 INTC_GROUP(MTU3_ABCD, MTU2_TGI3A, MTU2_TGI3B, MTU2_TGI3C, MTU2_TGI3D),
172 INTC_GROUP(MTU4_ABCD, MTU2_TGI4A, MTU2_TGI4B, MTU2_TGI4C, MTU2_TGI4D),
173 INTC_GROUP(IIC30, IIC30_STPI, IIC30_NAKI, IIC30_RXI, IIC30_TXI,
174 IIC30_TEI),
175 INTC_GROUP(IIC31, IIC31_STPI, IIC31_NAKI, IIC31_RXI, IIC31_TXI,
176 IIC31_TEI),
177 INTC_GROUP(IIC32, IIC32_STPI, IIC32_NAKI, IIC32_RXI, IIC32_TXI,
178 IIC32_TEI),
179 INTC_GROUP(IIC33, IIC33_STPI, IIC33_NAKI, IIC33_RXI, IIC33_TXI,
180 IIC33_TEI),
181 INTC_GROUP(SCIF0, SCIF0_BRI, SCIF0_ERI, SCIF0_RXI, SCIF0_TXI),
182 INTC_GROUP(SCIF1, SCIF1_BRI, SCIF1_ERI, SCIF1_RXI, SCIF1_TXI),
183 INTC_GROUP(SCIF2, SCIF2_BRI, SCIF2_ERI, SCIF2_RXI, SCIF2_TXI),
184 INTC_GROUP(SCIF3, SCIF3_BRI, SCIF3_ERI, SCIF3_RXI, SCIF3_TXI),
185 INTC_GROUP(SSU0, SSU0_SSERI, SSU0_SSRXI, SSU0_SSTXI),
186 INTC_GROUP(SSU1, SSU1_SSERI, SSU1_SSRXI, SSU1_SSTXI),
187 INTC_GROUP(FLCTL, FLCTL_FLSTEI, FLCTL_FLTENDI, FLCTL_FLTREQ0I,
188 FLCTL_FLTREQ1I),
189 INTC_GROUP(RTC, RTC_ARM, RTC_PRD, RTC_CUP),
190 INTC_GROUP(RCAN0, RCAN0_ERS, RCAN0_OVR, RCAN0_RM0, RCAN0_RM1,
191 RCAN0_SLE),
192 INTC_GROUP(RCAN1, RCAN1_ERS, RCAN1_OVR, RCAN1_RM0, RCAN1_RM1,
193 RCAN1_SLE),
194
195#ifdef CONFIG_CPU_SUBTYPE_SH7263
196 INTC_GROUP(ROMDEC, ROMDEC_ISY, ROMDEC_IERR, ROMDEC_IARG,
197 ROMDEC_ISEC, ROMDEC_IBUF, ROMDEC_IREADY),
198 INTC_GROUP(SDHI, SDHI3, SDHI0, SDHI1),
199 INTC_GROUP(SRC, SRC_OVF, SRC_ODFI, SRC_IDEI),
200#endif
201}; 135};
202 136
203static struct intc_prio_reg prio_registers[] __initdata = { 137static struct intc_prio_reg prio_registers[] __initdata = {
@@ -242,22 +176,22 @@ static struct plat_sci_port sci_platform_data[] = {
242 .mapbase = 0xfffe8000, 176 .mapbase = 0xfffe8000,
243 .flags = UPF_BOOT_AUTOCONF, 177 .flags = UPF_BOOT_AUTOCONF,
244 .type = PORT_SCIF, 178 .type = PORT_SCIF,
245 .irqs = { 193, 194, 195, 192 }, 179 .irqs = { 192, 192, 192, 192 },
246 }, { 180 }, {
247 .mapbase = 0xfffe8800, 181 .mapbase = 0xfffe8800,
248 .flags = UPF_BOOT_AUTOCONF, 182 .flags = UPF_BOOT_AUTOCONF,
249 .type = PORT_SCIF, 183 .type = PORT_SCIF,
250 .irqs = { 197, 198, 199, 196 }, 184 .irqs = { 196, 196, 196, 196 },
251 }, { 185 }, {
252 .mapbase = 0xfffe9000, 186 .mapbase = 0xfffe9000,
253 .flags = UPF_BOOT_AUTOCONF, 187 .flags = UPF_BOOT_AUTOCONF,
254 .type = PORT_SCIF, 188 .type = PORT_SCIF,
255 .irqs = { 201, 202, 203, 200 }, 189 .irqs = { 200, 200, 200, 200 },
256 }, { 190 }, {
257 .mapbase = 0xfffe9800, 191 .mapbase = 0xfffe9800,
258 .flags = UPF_BOOT_AUTOCONF, 192 .flags = UPF_BOOT_AUTOCONF,
259 .type = PORT_SCIF, 193 .type = PORT_SCIF,
260 .irqs = { 205, 206, 207, 204 }, 194 .irqs = { 204, 204, 204, 204 },
261 }, { 195 }, {
262 .flags = 0, 196 .flags = 0,
263 } 197 }
@@ -278,17 +212,7 @@ static struct resource rtc_resources[] = {
278 .flags = IORESOURCE_IO, 212 .flags = IORESOURCE_IO,
279 }, 213 },
280 [1] = { 214 [1] = {
281 /* Period IRQ */ 215 /* Shared Period/Carry/Alarm IRQ */
282 .start = 232,
283 .flags = IORESOURCE_IRQ,
284 },
285 [2] = {
286 /* Carry IRQ */
287 .start = 233,
288 .flags = IORESOURCE_IRQ,
289 },
290 [3] = {
291 /* Alarm IRQ */
292 .start = 231, 216 .start = 231,
293 .flags = IORESOURCE_IRQ, 217 .flags = IORESOURCE_IRQ,
294 }, 218 },
diff --git a/arch/sh/kernel/cpu/sh2a/setup-sh7206.c b/arch/sh/kernel/cpu/sh2a/setup-sh7206.c
index e6d4ec445dd8..c46a8355726d 100644
--- a/arch/sh/kernel/cpu/sh2a/setup-sh7206.c
+++ b/arch/sh/kernel/cpu/sh2a/setup-sh7206.c
@@ -2,6 +2,7 @@
2 * SH7206 Setup 2 * SH7206 Setup
3 * 3 *
4 * Copyright (C) 2006 Yoshinori Sato 4 * Copyright (C) 2006 Yoshinori Sato
5 * Copyright (C) 2009 Paul Mundt
5 * 6 *
6 * This file is subject to the terms and conditions of the GNU General Public 7 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive 8 * License. See the file "COPYING" in the main directory of this archive
@@ -19,34 +20,23 @@ enum {
19 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7, 20 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7,
20 PINT0, PINT1, PINT2, PINT3, PINT4, PINT5, PINT6, PINT7, 21 PINT0, PINT1, PINT2, PINT3, PINT4, PINT5, PINT6, PINT7,
21 ADC_ADI0, ADC_ADI1, 22 ADC_ADI0, ADC_ADI1,
22 DMAC0_DEI, DMAC0_HEI, DMAC1_DEI, DMAC1_HEI, 23
23 DMAC2_DEI, DMAC2_HEI, DMAC3_DEI, DMAC3_HEI, 24 DMAC0, DMAC1, DMAC2, DMAC3, DMAC4, DMAC5, DMAC6, DMAC7,
24 DMAC4_DEI, DMAC4_HEI, DMAC5_DEI, DMAC5_HEI, 25
25 DMAC6_DEI, DMAC6_HEI, DMAC7_DEI, DMAC7_HEI, 26 MTU0_ABCD, MTU0_VEF, MTU1_AB, MTU1_VU, MTU2_AB, MTU2_VU,
27 MTU3_ABCD, MTU4_ABCD, MTU5, POE2_12, MTU3S_ABCD, MTU4S_ABCD, MTU5S,
28 IIC3,
29
26 CMT0, CMT1, BSC, WDT, 30 CMT0, CMT1, BSC, WDT,
27 MTU2_TGI0A, MTU2_TGI0B, MTU2_TGI0C, MTU2_TGI0D, 31
28 MTU2_TCI0V, MTU2_TGI0E, MTU2_TGI0F, 32 MTU2_TCI3V, MTU2_TCI4V, MTU2S_TCI3V, MTU2S_TCI4V,
29 MTU2_TGI1A, MTU2_TGI1B, MTU2_TCI1V, MTU2_TCI1U, 33
30 MTU2_TGI2A, MTU2_TGI2B, MTU2_TCI2V, MTU2_TCI2U,
31 MTU2_TGI3A, MTU2_TGI3B, MTU2_TGI3C, MTU2_TGI3D, MTU2_TCI3V,
32 MTU2_TGI4A, MTU2_TGI4B, MTU2_TGI4C, MTU2_TGI4D, MTU2_TCI4V,
33 MTU2_TGI5U, MTU2_TGI5V, MTU2_TGI5W,
34 POE2_OEI1, POE2_OEI2,
35 MTU2S_TGI3A, MTU2S_TGI3B, MTU2S_TGI3C, MTU2S_TGI3D, MTU2S_TCI3V,
36 MTU2S_TGI4A, MTU2S_TGI4B, MTU2S_TGI4C, MTU2S_TGI4D, MTU2S_TCI4V,
37 MTU2S_TGI5U, MTU2S_TGI5V, MTU2S_TGI5W,
38 POE2_OEI3, 34 POE2_OEI3,
39 IIC3_STPI, IIC3_NAKI, IIC3_RXI, IIC3_TXI, IIC3_TEI, 35
40 SCIF0_BRI, SCIF0_ERI, SCIF0_RXI, SCIF0_TXI, 36 SCIF0, SCIF1, SCIF2, SCIF3,
41 SCIF1_BRI, SCIF1_ERI, SCIF1_RXI, SCIF1_TXI,
42 SCIF2_BRI, SCIF2_ERI, SCIF2_RXI, SCIF2_TXI,
43 SCIF3_BRI, SCIF3_ERI, SCIF3_RXI, SCIF3_TXI,
44 37
45 /* interrupt groups */ 38 /* interrupt groups */
46 PINT, DMAC0, DMAC1, DMAC2, DMAC3, DMAC4, DMAC5, DMAC6, DMAC7, 39 PINT,
47 MTU0_ABCD, MTU0_VEF, MTU1_AB, MTU1_VU, MTU2_AB, MTU2_VU,
48 MTU3_ABCD, MTU4_ABCD, MTU5, POE2_12, MTU3S_ABCD, MTU4S_ABCD, MTU5S,
49 IIC3, SCIF0, SCIF1, SCIF2, SCIF3,
50}; 40};
51 41
52static struct intc_vect vectors[] __initdata = { 42static struct intc_vect vectors[] __initdata = {
@@ -59,86 +49,58 @@ static struct intc_vect vectors[] __initdata = {
59 INTC_IRQ(PINT4, 84), INTC_IRQ(PINT5, 85), 49 INTC_IRQ(PINT4, 84), INTC_IRQ(PINT5, 85),
60 INTC_IRQ(PINT6, 86), INTC_IRQ(PINT7, 87), 50 INTC_IRQ(PINT6, 86), INTC_IRQ(PINT7, 87),
61 INTC_IRQ(ADC_ADI0, 92), INTC_IRQ(ADC_ADI1, 96), 51 INTC_IRQ(ADC_ADI0, 92), INTC_IRQ(ADC_ADI1, 96),
62 INTC_IRQ(DMAC0_DEI, 108), INTC_IRQ(DMAC0_HEI, 109), 52 INTC_IRQ(DMAC0, 108), INTC_IRQ(DMAC0, 109),
63 INTC_IRQ(DMAC1_DEI, 112), INTC_IRQ(DMAC1_HEI, 113), 53 INTC_IRQ(DMAC1, 112), INTC_IRQ(DMAC1, 113),
64 INTC_IRQ(DMAC2_DEI, 116), INTC_IRQ(DMAC2_HEI, 117), 54 INTC_IRQ(DMAC2, 116), INTC_IRQ(DMAC2, 117),
65 INTC_IRQ(DMAC3_DEI, 120), INTC_IRQ(DMAC3_HEI, 121), 55 INTC_IRQ(DMAC3, 120), INTC_IRQ(DMAC3, 121),
66 INTC_IRQ(DMAC4_DEI, 124), INTC_IRQ(DMAC4_HEI, 125), 56 INTC_IRQ(DMAC4, 124), INTC_IRQ(DMAC4, 125),
67 INTC_IRQ(DMAC5_DEI, 128), INTC_IRQ(DMAC5_HEI, 129), 57 INTC_IRQ(DMAC5, 128), INTC_IRQ(DMAC5, 129),
68 INTC_IRQ(DMAC6_DEI, 132), INTC_IRQ(DMAC6_HEI, 133), 58 INTC_IRQ(DMAC6, 132), INTC_IRQ(DMAC6, 133),
69 INTC_IRQ(DMAC7_DEI, 136), INTC_IRQ(DMAC7_HEI, 137), 59 INTC_IRQ(DMAC7, 136), INTC_IRQ(DMAC7, 137),
70 INTC_IRQ(CMT0, 140), INTC_IRQ(CMT1, 144), 60 INTC_IRQ(CMT0, 140), INTC_IRQ(CMT1, 144),
71 INTC_IRQ(BSC, 148), INTC_IRQ(WDT, 152), 61 INTC_IRQ(BSC, 148), INTC_IRQ(WDT, 152),
72 INTC_IRQ(MTU2_TGI0A, 156), INTC_IRQ(MTU2_TGI0B, 157), 62 INTC_IRQ(MTU0_ABCD, 156), INTC_IRQ(MTU0_ABCD, 157),
73 INTC_IRQ(MTU2_TGI0C, 158), INTC_IRQ(MTU2_TGI0D, 159), 63 INTC_IRQ(MTU0_ABCD, 158), INTC_IRQ(MTU0_ABCD, 159),
74 INTC_IRQ(MTU2_TCI0V, 160), 64 INTC_IRQ(MTU0_VEF, 160), INTC_IRQ(MTU0_VEF, 161),
75 INTC_IRQ(MTU2_TGI0E, 161), INTC_IRQ(MTU2_TGI0F, 162), 65 INTC_IRQ(MTU0_VEF, 162),
76 INTC_IRQ(MTU2_TGI1A, 164), INTC_IRQ(MTU2_TGI1B, 165), 66 INTC_IRQ(MTU1_AB, 164), INTC_IRQ(MTU1_AB, 165),
77 INTC_IRQ(MTU2_TCI1V, 168), INTC_IRQ(MTU2_TCI1U, 169), 67 INTC_IRQ(MTU1_VU, 168), INTC_IRQ(MTU1_VU, 169),
78 INTC_IRQ(MTU2_TGI2A, 172), INTC_IRQ(MTU2_TGI2B, 173), 68 INTC_IRQ(MTU2_AB, 172), INTC_IRQ(MTU2_AB, 173),
79 INTC_IRQ(MTU2_TCI2V, 176), INTC_IRQ(MTU2_TCI2U, 177), 69 INTC_IRQ(MTU2_VU, 176), INTC_IRQ(MTU2_VU, 177),
80 INTC_IRQ(MTU2_TGI3A, 180), INTC_IRQ(MTU2_TGI3B, 181), 70 INTC_IRQ(MTU3_ABCD, 180), INTC_IRQ(MTU3_ABCD, 181),
81 INTC_IRQ(MTU2_TGI3C, 182), INTC_IRQ(MTU2_TGI3D, 183), 71 INTC_IRQ(MTU3_ABCD, 182), INTC_IRQ(MTU3_ABCD, 183),
82 INTC_IRQ(MTU2_TCI3V, 184), 72 INTC_IRQ(MTU2_TCI3V, 184),
83 INTC_IRQ(MTU2_TGI4A, 188), INTC_IRQ(MTU2_TGI4B, 189), 73 INTC_IRQ(MTU4_ABCD, 188), INTC_IRQ(MTU4_ABCD, 189),
84 INTC_IRQ(MTU2_TGI4C, 190), INTC_IRQ(MTU2_TGI4D, 191), 74 INTC_IRQ(MTU4_ABCD, 190), INTC_IRQ(MTU4_ABCD, 191),
85 INTC_IRQ(MTU2_TCI4V, 192), 75 INTC_IRQ(MTU2_TCI4V, 192),
86 INTC_IRQ(MTU2_TGI5U, 196), INTC_IRQ(MTU2_TGI5V, 197), 76 INTC_IRQ(MTU5, 196), INTC_IRQ(MTU5, 197),
87 INTC_IRQ(MTU2_TGI5W, 198), 77 INTC_IRQ(MTU5, 198),
88 INTC_IRQ(POE2_OEI1, 200), INTC_IRQ(POE2_OEI2, 201), 78 INTC_IRQ(POE2_12, 200), INTC_IRQ(POE2_12, 201),
89 INTC_IRQ(MTU2S_TGI3A, 204), INTC_IRQ(MTU2S_TGI3B, 205), 79 INTC_IRQ(MTU3S_ABCD, 204), INTC_IRQ(MTU3S_ABCD, 205),
90 INTC_IRQ(MTU2S_TGI3C, 206), INTC_IRQ(MTU2S_TGI3D, 207), 80 INTC_IRQ(MTU3S_ABCD, 206), INTC_IRQ(MTU3S_ABCD, 207),
91 INTC_IRQ(MTU2S_TCI3V, 208), 81 INTC_IRQ(MTU2S_TCI3V, 208),
92 INTC_IRQ(MTU2S_TGI4A, 212), INTC_IRQ(MTU2S_TGI4B, 213), 82 INTC_IRQ(MTU4S_ABCD, 212), INTC_IRQ(MTU4S_ABCD, 213),
93 INTC_IRQ(MTU2S_TGI4C, 214), INTC_IRQ(MTU2S_TGI4D, 215), 83 INTC_IRQ(MTU4S_ABCD, 214), INTC_IRQ(MTU4S_ABCD, 215),
94 INTC_IRQ(MTU2S_TCI4V, 216), 84 INTC_IRQ(MTU2S_TCI4V, 216),
95 INTC_IRQ(MTU2S_TGI5U, 220), INTC_IRQ(MTU2S_TGI5V, 221), 85 INTC_IRQ(MTU5S, 220), INTC_IRQ(MTU5S, 221),
96 INTC_IRQ(MTU2S_TGI5W, 222), 86 INTC_IRQ(MTU5S, 222),
97 INTC_IRQ(POE2_OEI3, 224), 87 INTC_IRQ(POE2_OEI3, 224),
98 INTC_IRQ(IIC3_STPI, 228), INTC_IRQ(IIC3_NAKI, 229), 88 INTC_IRQ(IIC3, 228), INTC_IRQ(IIC3, 229),
99 INTC_IRQ(IIC3_RXI, 230), INTC_IRQ(IIC3_TXI, 231), 89 INTC_IRQ(IIC3, 230), INTC_IRQ(IIC3, 231),
100 INTC_IRQ(IIC3_TEI, 232), 90 INTC_IRQ(IIC3, 232),
101 INTC_IRQ(SCIF0_BRI, 240), INTC_IRQ(SCIF0_ERI, 241), 91 INTC_IRQ(SCIF0, 240), INTC_IRQ(SCIF0, 241),
102 INTC_IRQ(SCIF0_RXI, 242), INTC_IRQ(SCIF0_TXI, 243), 92 INTC_IRQ(SCIF0, 242), INTC_IRQ(SCIF0, 243),
103 INTC_IRQ(SCIF1_BRI, 244), INTC_IRQ(SCIF1_ERI, 245), 93 INTC_IRQ(SCIF1, 244), INTC_IRQ(SCIF1, 245),
104 INTC_IRQ(SCIF1_RXI, 246), INTC_IRQ(SCIF1_TXI, 247), 94 INTC_IRQ(SCIF1, 246), INTC_IRQ(SCIF1, 247),
105 INTC_IRQ(SCIF2_BRI, 248), INTC_IRQ(SCIF2_ERI, 249), 95 INTC_IRQ(SCIF2, 248), INTC_IRQ(SCIF2, 249),
106 INTC_IRQ(SCIF2_RXI, 250), INTC_IRQ(SCIF2_TXI, 251), 96 INTC_IRQ(SCIF2, 250), INTC_IRQ(SCIF2, 251),
107 INTC_IRQ(SCIF3_BRI, 252), INTC_IRQ(SCIF3_ERI, 253), 97 INTC_IRQ(SCIF3, 252), INTC_IRQ(SCIF3, 253),
108 INTC_IRQ(SCIF3_RXI, 254), INTC_IRQ(SCIF3_TXI, 255), 98 INTC_IRQ(SCIF3, 254), INTC_IRQ(SCIF3, 255),
109}; 99};
110 100
111static struct intc_group groups[] __initdata = { 101static struct intc_group groups[] __initdata = {
112 INTC_GROUP(PINT, PINT0, PINT1, PINT2, PINT3, 102 INTC_GROUP(PINT, PINT0, PINT1, PINT2, PINT3,
113 PINT4, PINT5, PINT6, PINT7), 103 PINT4, PINT5, PINT6, PINT7),
114 INTC_GROUP(DMAC0, DMAC0_DEI, DMAC0_HEI),
115 INTC_GROUP(DMAC1, DMAC1_DEI, DMAC1_HEI),
116 INTC_GROUP(DMAC2, DMAC2_DEI, DMAC2_HEI),
117 INTC_GROUP(DMAC3, DMAC3_DEI, DMAC3_HEI),
118 INTC_GROUP(DMAC4, DMAC4_DEI, DMAC4_HEI),
119 INTC_GROUP(DMAC5, DMAC5_DEI, DMAC5_HEI),
120 INTC_GROUP(DMAC6, DMAC6_DEI, DMAC6_HEI),
121 INTC_GROUP(DMAC7, DMAC7_DEI, DMAC7_HEI),
122 INTC_GROUP(MTU0_ABCD, MTU2_TGI0A, MTU2_TGI0B, MTU2_TGI0C, MTU2_TGI0D),
123 INTC_GROUP(MTU0_VEF, MTU2_TCI0V, MTU2_TGI0E, MTU2_TGI0F),
124 INTC_GROUP(MTU1_AB, MTU2_TGI1A, MTU2_TGI1B),
125 INTC_GROUP(MTU1_VU, MTU2_TCI1V, MTU2_TCI1U),
126 INTC_GROUP(MTU2_AB, MTU2_TGI2A, MTU2_TGI2B),
127 INTC_GROUP(MTU2_VU, MTU2_TCI2V, MTU2_TCI2U),
128 INTC_GROUP(MTU3_ABCD, MTU2_TGI3A, MTU2_TGI3B, MTU2_TGI3C, MTU2_TGI3D),
129 INTC_GROUP(MTU4_ABCD, MTU2_TGI4A, MTU2_TGI4B, MTU2_TGI4C, MTU2_TGI4D),
130 INTC_GROUP(MTU5, MTU2_TGI5U, MTU2_TGI5V, MTU2_TGI5W),
131 INTC_GROUP(POE2_12, POE2_OEI1, POE2_OEI2),
132 INTC_GROUP(MTU3S_ABCD, MTU2S_TGI3A, MTU2S_TGI3B,
133 MTU2S_TGI3C, MTU2S_TGI3D),
134 INTC_GROUP(MTU4S_ABCD, MTU2S_TGI4A, MTU2S_TGI4B,
135 MTU2S_TGI4C, MTU2S_TGI4D),
136 INTC_GROUP(MTU5S, MTU2S_TGI5U, MTU2S_TGI5V, MTU2S_TGI5W),
137 INTC_GROUP(IIC3, IIC3_STPI, IIC3_NAKI, IIC3_RXI, IIC3_TXI, IIC3_TEI),
138 INTC_GROUP(SCIF0, SCIF0_BRI, SCIF0_ERI, SCIF0_RXI, SCIF0_TXI),
139 INTC_GROUP(SCIF1, SCIF1_BRI, SCIF1_ERI, SCIF1_RXI, SCIF1_TXI),
140 INTC_GROUP(SCIF2, SCIF2_BRI, SCIF2_ERI, SCIF2_RXI, SCIF2_TXI),
141 INTC_GROUP(SCIF3, SCIF3_BRI, SCIF3_ERI, SCIF3_RXI, SCIF3_TXI),
142}; 104};
143 105
144static struct intc_prio_reg prio_registers[] __initdata = { 106static struct intc_prio_reg prio_registers[] __initdata = {
@@ -174,22 +136,22 @@ static struct plat_sci_port sci_platform_data[] = {
174 .mapbase = 0xfffe8000, 136 .mapbase = 0xfffe8000,
175 .flags = UPF_BOOT_AUTOCONF, 137 .flags = UPF_BOOT_AUTOCONF,
176 .type = PORT_SCIF, 138 .type = PORT_SCIF,
177 .irqs = { 241, 242, 243, 240 }, 139 .irqs = { 240, 240, 240, 240 },
178 }, { 140 }, {
179 .mapbase = 0xfffe8800, 141 .mapbase = 0xfffe8800,
180 .flags = UPF_BOOT_AUTOCONF, 142 .flags = UPF_BOOT_AUTOCONF,
181 .type = PORT_SCIF, 143 .type = PORT_SCIF,
182 .irqs = { 245, 246, 247, 244 }, 144 .irqs = { 244, 244, 244, 244 },
183 }, { 145 }, {
184 .mapbase = 0xfffe9000, 146 .mapbase = 0xfffe9000,
185 .flags = UPF_BOOT_AUTOCONF, 147 .flags = UPF_BOOT_AUTOCONF,
186 .type = PORT_SCIF, 148 .type = PORT_SCIF,
187 .irqs = { 249, 250, 251, 248 }, 149 .irqs = { 248, 248, 248, 248 },
188 }, { 150 }, {
189 .mapbase = 0xfffe9800, 151 .mapbase = 0xfffe9800,
190 .flags = UPF_BOOT_AUTOCONF, 152 .flags = UPF_BOOT_AUTOCONF,
191 .type = PORT_SCIF, 153 .type = PORT_SCIF,
192 .irqs = { 253, 254, 255, 252 }, 154 .irqs = { 252, 252, 252, 252 },
193 }, { 155 }, {
194 .flags = 0, 156 .flags = 0,
195 } 157 }
diff --git a/arch/sh/kernel/cpu/sh3/Makefile b/arch/sh/kernel/cpu/sh3/Makefile
index e07c69e16d9b..ecab274141a8 100644
--- a/arch/sh/kernel/cpu/sh3/Makefile
+++ b/arch/sh/kernel/cpu/sh3/Makefile
@@ -4,6 +4,8 @@
4 4
5obj-y := ex.o probe.o entry.o setup-sh3.o 5obj-y := ex.o probe.o entry.o setup-sh3.o
6 6
7obj-$(CONFIG_HIBERNATION) += swsusp.o
8
7# CPU subtype setup 9# CPU subtype setup
8obj-$(CONFIG_CPU_SUBTYPE_SH7705) += setup-sh7705.o 10obj-$(CONFIG_CPU_SUBTYPE_SH7705) += setup-sh7705.o
9obj-$(CONFIG_CPU_SUBTYPE_SH7706) += setup-sh770x.o 11obj-$(CONFIG_CPU_SUBTYPE_SH7706) += setup-sh770x.o
diff --git a/arch/sh/kernel/cpu/sh3/entry.S b/arch/sh/kernel/cpu/sh3/entry.S
index b4106d0c68ec..55da0ff9848d 100644
--- a/arch/sh/kernel/cpu/sh3/entry.S
+++ b/arch/sh/kernel/cpu/sh3/entry.S
@@ -16,6 +16,7 @@
16#include <asm/unistd.h> 16#include <asm/unistd.h>
17#include <cpu/mmu_context.h> 17#include <cpu/mmu_context.h>
18#include <asm/page.h> 18#include <asm/page.h>
19#include <asm/cache.h>
19 20
20! NOTE: 21! NOTE:
21! GNU as (as of 2.9.1) changes bf/s into bt/s and bra, when the address 22! GNU as (as of 2.9.1) changes bf/s into bt/s and bra, when the address
@@ -187,44 +188,35 @@ call_dae:
187#if defined(CONFIG_SH_STANDARD_BIOS) 188#if defined(CONFIG_SH_STANDARD_BIOS)
188 /* Unwind the stack and jmp to the debug entry */ 189 /* Unwind the stack and jmp to the debug entry */
189ENTRY(sh_bios_handler) 190ENTRY(sh_bios_handler)
190 mov.l @r15+, r0 191 mov.l 1f, r8
191 mov.l @r15+, r1 192 bsr restore_regs
192 mov.l @r15+, r2 193 nop
193 mov.l @r15+, r3 194
194 mov.l @r15+, r4 195 lds k2, pr ! restore pr
195 mov.l @r15+, r5 196 mov k4, r15
196 mov.l @r15+, r6
197 mov.l @r15+, r7
198 stc sr, r8
199 mov.l 1f, r9 ! BL =1, RB=1, IMASK=0x0F
200 or r9, r8
201 ldc r8, sr ! here, change the register bank
202 mov.l @r15+, r8
203 mov.l @r15+, r9
204 mov.l @r15+, r10
205 mov.l @r15+, r11
206 mov.l @r15+, r12
207 mov.l @r15+, r13
208 mov.l @r15+, r14
209 mov.l @r15+, k0
210 ldc.l @r15+, spc
211 lds.l @r15+, pr
212 mov.l @r15+, k1
213 ldc.l @r15+, gbr
214 lds.l @r15+, mach
215 lds.l @r15+, macl
216 mov k0, r15
217 ! 197 !
218 mov.l 2f, k0 198 mov.l 2f, k0
219 mov.l @k0, k0 199 mov.l @k0, k0
220 jmp @k0 200 jmp @k0
221 ldc k1, ssr 201 ldc k3, ssr
222 .align 2 202 .align 2
2231: .long 0x300000f0 2031: .long 0x300000f0
2242: .long gdb_vbr_vector 2042: .long gdb_vbr_vector
225#endif /* CONFIG_SH_STANDARD_BIOS */ 205#endif /* CONFIG_SH_STANDARD_BIOS */
226 206
227restore_all: 207! restore_regs()
208! - restore r0, r1, r2, r3, r4, r5, r6, r7 from the stack
209! - switch bank
210! - restore r8, r9, r10, r11, r12, r13, r14, r15 from the stack
211! - restore spc, pr*, ssr, gbr, mach, macl, skip default tra
212! k2 returns original pr
213! k3 returns original sr
214! k4 returns original stack pointer
215! r8 passes SR bitmask, overwritten with restored data on return
216! r9 trashed
217! BL=0 on entry, on exit BL=1 (depending on r8).
218
219ENTRY(restore_regs)
228 mov.l @r15+, r0 220 mov.l @r15+, r0
229 mov.l @r15+, r1 221 mov.l @r15+, r1
230 mov.l @r15+, r2 222 mov.l @r15+, r2
@@ -234,10 +226,9 @@ restore_all:
234 mov.l @r15+, r6 226 mov.l @r15+, r6
235 mov.l @r15+, r7 227 mov.l @r15+, r7
236 ! 228 !
237 stc sr, r8 229 stc sr, r9
238 mov.l 7f, r9 230 or r8, r9
239 or r9, r8 ! BL =1, RB=1 231 ldc r9, sr
240 ldc r8, sr ! here, change the register bank
241 ! 232 !
242 mov.l @r15+, r8 233 mov.l @r15+, r8
243 mov.l @r15+, r9 234 mov.l @r15+, r9
@@ -248,12 +239,20 @@ restore_all:
248 mov.l @r15+, r14 239 mov.l @r15+, r14
249 mov.l @r15+, k4 ! original stack pointer 240 mov.l @r15+, k4 ! original stack pointer
250 ldc.l @r15+, spc 241 ldc.l @r15+, spc
251 lds.l @r15+, pr 242 mov.l @r15+, k2 ! original PR
252 mov.l @r15+, k3 ! original SR 243 mov.l @r15+, k3 ! original SR
253 ldc.l @r15+, gbr 244 ldc.l @r15+, gbr
254 lds.l @r15+, mach 245 lds.l @r15+, mach
255 lds.l @r15+, macl 246 lds.l @r15+, macl
256 add #4, r15 ! Skip syscall number 247 rts
248 add #4, r15 ! Skip syscall number
249
250restore_all:
251 mov.l 7f, r8
252 bsr restore_regs
253 nop
254
255 lds k2, pr ! restore pr
257 ! 256 !
258#ifdef CONFIG_SH_DSP 257#ifdef CONFIG_SH_DSP
259 mov.l @r15+, k0 ! DSP mode marker 258 mov.l @r15+, k0 ! DSP mode marker
@@ -294,7 +293,7 @@ skip_restore:
294 mov #0xf0, k1 293 mov #0xf0, k1
295 extu.b k1, k1 294 extu.b k1, k1
296 not k1, k1 295 not k1, k1
297 and k1, k2 ! Mask orignal SR value 296 and k1, k2 ! Mask original SR value
298 ! 297 !
299 mov k3, k0 ! Calculate IMASK-bits 298 mov k3, k0 ! Calculate IMASK-bits
300 shlr2 k0 299 shlr2 k0
@@ -313,7 +312,6 @@ skip_restore:
313 mov #0, k1 312 mov #0, k1
314 mov.b k1, @k0 313 mov.b k1, @k0
315#endif 314#endif
316 mov.l @r15+, k2 ! restore EXPEVT
317 mov k4, r15 315 mov k4, r15
318 rte 316 rte
319 nop 317 nop
@@ -336,81 +334,55 @@ skip_restore:
336ENTRY(vbr_base) 334ENTRY(vbr_base)
337 .long 0 335 .long 0
338! 336!
337! 0x100: General exception vector
338!
339 .balign 256,0,256 339 .balign 256,0,256
340general_exception: 340general_exception:
341 mov.l 1f, k2 341#ifndef CONFIG_CPU_SUBTYPE_SHX3
342 mov.l 2f, k3 342 bra handle_exception
343#ifdef CONFIG_CPU_SUBTYPE_SHX3 343 sts pr, k3 ! save original pr value in k3
344 mov.l @k2, k2 344#else
345 mov.l 1f, k4
346 mov.l @k4, k4
345 347
346 ! Is EXPEVT larger than 0x800? 348 ! Is EXPEVT larger than 0x800?
347 mov #0x8, k0 349 mov #0x8, k0
348 shll8 k0 350 shll8 k0
349 cmp/hs k0, k2 351 cmp/hs k0, k4
350 bf 0f 352 bf 0f
351 353
352 ! then add 0x580 (k2 is 0xd80 or 0xda0) 354 ! then add 0x580 (k2 is 0xd80 or 0xda0)
353 mov #0x58, k0 355 mov #0x58, k0
354 shll2 k0 356 shll2 k0
355 shll2 k0 357 shll2 k0
356 add k0, k2 358 add k0, k4
3570: 3590:
358 bra handle_exception 360 ! Setup stack and save DSP context (k0 contains original r15 on return)
361 bsr prepare_stack_save_dsp
359 nop 362 nop
360#else
361 bra handle_exception
362 mov.l @k2, k2
363#endif
364 .align 2
3651: .long EXPEVT
3662: .long ret_from_exception
367!
368!
369 363
370 .balign 1024,0,1024 364 ! Save registers / Switch to bank 0
371tlb_miss: 365 mov k4, k2 ! keep vector in k2
372 mov.l 1f, k2 366 mov.l 1f, k4 ! SR bits to clear in k4
373 mov.l 4f, k3 367 bsr save_regs ! needs original pr value in k3
374 bra handle_exception 368 nop
375 mov.l @k2, k2 369
376! 370 bra handle_exception_special
377 .balign 512,0,512
378interrupt:
379 mov.l 3f, k3
380#if defined(CONFIG_KGDB)
381 mov.l 2f, k2
382 ! Debounce (filter nested NMI)
383 mov.l @k2, k0
384 mov.l 5f, k1
385 cmp/eq k1, k0
386 bf 0f
387 mov.l 6f, k1
388 tas.b @k1
389 bt 0f
390 rte
391 nop 371 nop
392 .align 2
3932: .long INTEVT
3945: .long NMI_VEC
3956: .long in_nmi
3960:
397#endif /* defined(CONFIG_KGDB) */
398 bra handle_exception
399 mov #-1, k2 ! interrupt exception marker
400 372
401 .align 2 373 .align 2
4021: .long EXPEVT 3741: .long EXPEVT
4033: .long ret_from_irq 375#endif
4044: .long ret_from_exception
405 376
406! 377! prepare_stack_save_dsp()
407! 378! - roll back gRB
408 .align 2 379! - switch to kernel stack
409ENTRY(handle_exception) 380! - save DSP
410 ! Using k0, k1 for scratch registers (r0_bank1, r1_bank), 381! k0 returns original sp (after roll back)
411 ! save all registers onto stack. 382! k1 trashed
412 ! 383! k2 trashed
413 384
385prepare_stack_save_dsp:
414#ifdef CONFIG_GUSA 386#ifdef CONFIG_GUSA
415 ! Check for roll back gRB (User and Kernel) 387 ! Check for roll back gRB (User and Kernel)
416 mov r15, k0 388 mov r15, k0
@@ -430,7 +402,7 @@ ENTRY(handle_exception)
4302: mov k1, r15 ! SP = r1 4022: mov k1, r15 ! SP = r1
4311: 4031:
432#endif 404#endif
433 405 ! Switch to kernel stack if needed
434 stc ssr, k0 ! Is it from kernel space? 406 stc ssr, k0 ! Is it from kernel space?
435 shll k0 ! Check MD bit (bit30) by shifting it into... 407 shll k0 ! Check MD bit (bit30) by shifting it into...
436 shll k0 ! ...the T bit 408 shll k0 ! ...the T bit
@@ -443,18 +415,17 @@ ENTRY(handle_exception)
443 add current, k1 415 add current, k1
444 mov k1, r15 ! change to kernel stack 416 mov k1, r15 ! change to kernel stack
445 ! 417 !
4461: mov.l 2f, k1 4181:
447 !
448#ifdef CONFIG_SH_DSP 419#ifdef CONFIG_SH_DSP
449 mov.l r2, @-r15 ! Save r2, we need another reg 420 ! Save DSP context if needed
450 stc sr, k4 421 stc sr, k1
451 mov.l 1f, r2 422 mov #0x10, k2
452 tst r2, k4 ! Check if in DSP mode 423 shll8 k2 ! DSP=1 (0x00001000)
453 mov.l @r15+, r2 ! Restore r2 now 424 tst k2, k1 ! Check if in DSP mode (passed in k2)
454 bt/s skip_save 425 bt/s skip_save
455 mov #0, k4 ! Set marker for no stack frame 426 mov #0, k1 ! Set marker for no stack frame
456 427
457 mov r2, k4 ! Backup r2 (in k4) for later 428 mov k2, k1 ! Save has-frame marker
458 429
459 ! Save DSP registers on stack 430 ! Save DSP registers on stack
460 stc.l mod, @-r15 431 stc.l mod, @-r15
@@ -473,35 +444,74 @@ ENTRY(handle_exception)
473 ! as we're not at all interested in supporting ancient toolchains at 444 ! as we're not at all interested in supporting ancient toolchains at
474 ! this point. -- PFM. 445 ! this point. -- PFM.
475 446
476 mov r15, r2 447 mov r15, k2
477 .word 0xf653 ! movs.l a1, @-r2 448 .word 0xf653 ! movs.l a1, @-r2
478 .word 0xf6f3 ! movs.l a0g, @-r2 449 .word 0xf6f3 ! movs.l a0g, @-r2
479 .word 0xf6d3 ! movs.l a1g, @-r2 450 .word 0xf6d3 ! movs.l a1g, @-r2
480 .word 0xf6c3 ! movs.l m0, @-r2 451 .word 0xf6c3 ! movs.l m0, @-r2
481 .word 0xf6e3 ! movs.l m1, @-r2 452 .word 0xf6e3 ! movs.l m1, @-r2
482 mov r2, r15 453 mov k2, r15
483 454
484 mov k4, r2 ! Restore r2
485 mov.l 1f, k4 ! Force DSP stack frame
486skip_save: 455skip_save:
487 mov.l k4, @-r15 ! Push DSP mode marker onto stack 456 mov.l k1, @-r15 ! Push DSP mode marker onto stack
488#endif 457#endif
489 ! Save the user registers on the stack. 458 rts
490 mov.l k2, @-r15 ! EXPEVT 459 nop
491 460!
492 mov #-1, k4 461! 0x400: Instruction and Data TLB miss exception vector
493 mov.l k4, @-r15 ! set TRA (default: -1) 462!
494 ! 463 .balign 1024,0,1024
464tlb_miss:
465 sts pr, k3 ! save original pr value in k3
466
467handle_exception:
468 mova exception_data, k0
469
470 ! Setup stack and save DSP context (k0 contains original r15 on return)
471 bsr prepare_stack_save_dsp
472 PREF(k0)
473
474 ! Save registers / Switch to bank 0
475 mov.l 5f, k2 ! vector register address
476 mov.l 1f, k4 ! SR bits to clear in k4
477 bsr save_regs ! needs original pr value in k3
478 mov.l @k2, k2 ! read out vector and keep in k2
479
480handle_exception_special:
481 ! Setup return address and jump to exception handler
482 mov.l 7f, r9 ! fetch return address
483 stc r2_bank, r0 ! k2 (vector)
484 mov.l 6f, r10
485 shlr2 r0
486 shlr r0
487 mov.l @(r0, r10), r10
488 jmp @r10
489 lds r9, pr ! put return address in pr
490
491 .align L1_CACHE_SHIFT
492
493! save_regs()
494! - save default tra, macl, mach, gbr, ssr, pr* and spc on the stack
495! - save r15*, r14, r13, r12, r11, r10, r9, r8 on the stack
496! - switch bank
497! - save r7, r6, r5, r4, r3, r2, r1, r0 on the stack
498! k0 contains original stack pointer*
499! k1 trashed
500! k3 passes original pr*
501! k4 passes SR bitmask
502! BL=1 on entry, on exit BL=0.
503
504ENTRY(save_regs)
505 mov #-1, r1
506 mov.l k1, @-r15 ! set TRA (default: -1)
495 sts.l macl, @-r15 507 sts.l macl, @-r15
496 sts.l mach, @-r15 508 sts.l mach, @-r15
497 stc.l gbr, @-r15 509 stc.l gbr, @-r15
498 stc.l ssr, @-r15 510 stc.l ssr, @-r15
499 sts.l pr, @-r15 511 mov.l k3, @-r15 ! original pr in k3
500 stc.l spc, @-r15 512 stc.l spc, @-r15
501 ! 513
502 lds k3, pr ! Set the return address to pr 514 mov.l k0, @-r15 ! original stack pointer in k0
503 !
504 mov.l k0, @-r15 ! save orignal stack
505 mov.l r14, @-r15 515 mov.l r14, @-r15
506 mov.l r13, @-r15 516 mov.l r13, @-r15
507 mov.l r12, @-r15 517 mov.l r12, @-r15
@@ -509,13 +519,23 @@ skip_save:
509 mov.l r10, @-r15 519 mov.l r10, @-r15
510 mov.l r9, @-r15 520 mov.l r9, @-r15
511 mov.l r8, @-r15 521 mov.l r8, @-r15
512 ! 522
513 stc sr, r8 ! Back to normal register bank, and 523 mov.l 0f, k3 ! SR bits to set in k3
514 or k1, r8 ! Block all interrupts 524
515 mov.l 3f, k1 525 ! fall-through
516 and k1, r8 ! ... 526
517 ldc r8, sr ! ...changed here. 527! save_low_regs()
518 ! 528! - modify SR for bank switch
529! - save r7, r6, r5, r4, r3, r2, r1, r0 on the stack
530! k3 passes bits to set in SR
531! k4 passes bits to clear in SR
532
533ENTRY(save_low_regs)
534 stc sr, r8
535 or k3, r8
536 and k4, r8
537 ldc r8, sr
538
519 mov.l r7, @-r15 539 mov.l r7, @-r15
520 mov.l r6, @-r15 540 mov.l r6, @-r15
521 mov.l r5, @-r15 541 mov.l r5, @-r15
@@ -523,52 +543,63 @@ skip_save:
523 mov.l r3, @-r15 543 mov.l r3, @-r15
524 mov.l r2, @-r15 544 mov.l r2, @-r15
525 mov.l r1, @-r15 545 mov.l r1, @-r15
526 mov.l r0, @-r15
527
528 /*
529 * This gets a bit tricky.. in the INTEVT case we don't want to use
530 * the VBR offset as a destination in the jump call table, since all
531 * of the destinations are the same. In this case, (interrupt) sets
532 * a marker in r2 (now r2_bank since SR.RB changed), which we check
533 * to determine the exception type. For all other exceptions, we
534 * forcibly read EXPEVT from memory and fix up the jump address, in
535 * the interrupt exception case we jump to do_IRQ() and defer the
536 * INTEVT read until there. As a bonus, we can also clean up the SR.RB
537 * checks that do_IRQ() was doing..
538 */
539 stc r2_bank, r8
540 cmp/pz r8
541 bf interrupt_exception
542 shlr2 r8
543 shlr r8
544 mov.l 4f, r9
545 add r8, r9
546 mov.l @r9, r9
547 jmp @r9
548 nop
549 rts 546 rts
550 nop 547 mov.l r0, @-r15
551 548
549!
550! 0x600: Interrupt / NMI vector
551!
552 .balign 512,0,512
553ENTRY(handle_interrupt)
554#if defined(CONFIG_KGDB)
555 mov.l 2f, k2
556 ! Debounce (filter nested NMI)
557 mov.l @k2, k0
558 mov.l 9f, k1
559 cmp/eq k1, k0
560 bf 11f
561 mov.l 10f, k1
562 tas.b @k1
563 bt 11f
564 rte
565 nop
552 .align 2 566 .align 2
5531: .long 0x00001000 ! DSP=1 5679: .long NMI_VEC
5542: .long 0x000080f0 ! FD=1, IMASK=15 56810: .long in_nmi
5553: .long 0xcfffffff ! RB=0, BL=0 56911:
5564: .long exception_handling_table 570#endif /* defined(CONFIG_KGDB) */
571 sts pr, k3 ! save original pr value in k3
572 mova exception_data, k0
557 573
558interrupt_exception: 574 ! Setup stack and save DSP context (k0 contains original r15 on return)
559 mov.l 1f, r9 575 bsr prepare_stack_save_dsp
576 PREF(k0)
577
578 ! Save registers / Switch to bank 0
579 mov.l 1f, k4 ! SR bits to clear in k4
580 bsr save_regs ! needs original pr value in k3
581 mov #-1, k2 ! default vector kept in k2
582
583 ! Setup return address and jump to do_IRQ
584 mov.l 4f, r9 ! fetch return address
585 lds r9, pr ! put return address in pr
560 mov.l 2f, r4 586 mov.l 2f, r4
561 mov.l @r4, r4 587 mov.l 3f, r9
588 mov.l @r4, r4 ! pass INTEVT vector as arg0
562 jmp @r9 589 jmp @r9
563 mov r15, r5 590 mov r15, r5 ! pass saved registers as arg1
564 rts
565 nop
566
567 .align 2
5681: .long do_IRQ
5692: .long INTEVT
570 591
571 .align 2
572ENTRY(exception_none) 592ENTRY(exception_none)
573 rts 593 rts
574 nop 594 nop
595
596 .align L1_CACHE_SHIFT
597exception_data:
5980: .long 0x000080f0 ! FD=1, IMASK=15
5991: .long 0xcfffffff ! RB=0, BL=0
6002: .long INTEVT
6013: .long do_IRQ
6024: .long ret_from_irq
6035: .long EXPEVT
6046: .long exception_handling_table
6057: .long ret_from_exception
diff --git a/arch/sh/kernel/cpu/sh3/setup-sh7705.c b/arch/sh/kernel/cpu/sh3/setup-sh7705.c
index 6468ae86b944..63b67badd67e 100644
--- a/arch/sh/kernel/cpu/sh3/setup-sh7705.c
+++ b/arch/sh/kernel/cpu/sh3/setup-sh7705.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * SH7705 Setup 2 * SH7705 Setup
3 * 3 *
4 * Copyright (C) 2006, 2007 Paul Mundt 4 * Copyright (C) 2006 - 2009 Paul Mundt
5 * Copyright (C) 2007 Nobuhiro Iwamatsu 5 * Copyright (C) 2007 Nobuhiro Iwamatsu
6 * 6 *
7 * This file is subject to the terms and conditions of the GNU General Public 7 * This file is subject to the terms and conditions of the GNU General Public
@@ -21,51 +21,36 @@ enum {
21 /* interrupt sources */ 21 /* interrupt sources */
22 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, 22 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5,
23 PINT07, PINT815, 23 PINT07, PINT815,
24 DMAC_DEI0, DMAC_DEI1, DMAC_DEI2, DMAC_DEI3, 24
25 SCIF0_ERI, SCIF0_RXI, SCIF0_TXI, 25 DMAC, SCIF0, SCIF2, ADC_ADI, USB,
26 SCIF2_ERI, SCIF2_RXI, SCIF2_TXI, 26
27 ADC_ADI,
28 USB_USI0, USB_USI1,
29 TPU0, TPU1, TPU2, TPU3, 27 TPU0, TPU1, TPU2, TPU3,
30 TMU0, TMU1, TMU2_TUNI, TMU2_TICPI, 28 TMU0, TMU1, TMU2,
31 RTC_ATI, RTC_PRI, RTC_CUI,
32 WDT,
33 REF_RCMI,
34 29
35 /* interrupt groups */ 30 RTC, WDT, REF_RCMI,
36 RTC, TMU2, DMAC, USB, SCIF2, SCIF0,
37}; 31};
38 32
39static struct intc_vect vectors[] __initdata = { 33static struct intc_vect vectors[] __initdata = {
40 /* IRQ0->5 are handled in setup-sh3.c */ 34 /* IRQ0->5 are handled in setup-sh3.c */
41 INTC_VECT(PINT07, 0x700), INTC_VECT(PINT815, 0x720), 35 INTC_VECT(PINT07, 0x700), INTC_VECT(PINT815, 0x720),
42 INTC_VECT(DMAC_DEI0, 0x800), INTC_VECT(DMAC_DEI1, 0x820), 36 INTC_VECT(DMAC, 0x800), INTC_VECT(DMAC, 0x820),
43 INTC_VECT(DMAC_DEI2, 0x840), INTC_VECT(DMAC_DEI3, 0x860), 37 INTC_VECT(DMAC, 0x840), INTC_VECT(DMAC, 0x860),
44 INTC_VECT(SCIF0_ERI, 0x880), INTC_VECT(SCIF0_RXI, 0x8a0), 38 INTC_VECT(SCIF0, 0x880), INTC_VECT(SCIF0, 0x8a0),
45 INTC_VECT(SCIF0_TXI, 0x8e0), 39 INTC_VECT(SCIF0, 0x8e0),
46 INTC_VECT(SCIF2_ERI, 0x900), INTC_VECT(SCIF2_RXI, 0x920), 40 INTC_VECT(SCIF2, 0x900), INTC_VECT(SCIF2, 0x920),
47 INTC_VECT(SCIF2_TXI, 0x960), 41 INTC_VECT(SCIF2, 0x960),
48 INTC_VECT(ADC_ADI, 0x980), 42 INTC_VECT(ADC_ADI, 0x980),
49 INTC_VECT(USB_USI0, 0xa20), INTC_VECT(USB_USI1, 0xa40), 43 INTC_VECT(USB, 0xa20), INTC_VECT(USB, 0xa40),
50 INTC_VECT(TPU0, 0xc00), INTC_VECT(TPU1, 0xc20), 44 INTC_VECT(TPU0, 0xc00), INTC_VECT(TPU1, 0xc20),
51 INTC_VECT(TPU2, 0xc80), INTC_VECT(TPU3, 0xca0), 45 INTC_VECT(TPU2, 0xc80), INTC_VECT(TPU3, 0xca0),
52 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420), 46 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
53 INTC_VECT(TMU2_TUNI, 0x440), INTC_VECT(TMU2_TICPI, 0x460), 47 INTC_VECT(TMU2, 0x440), INTC_VECT(TMU2, 0x460),
54 INTC_VECT(RTC_ATI, 0x480), INTC_VECT(RTC_PRI, 0x4a0), 48 INTC_VECT(RTC, 0x480), INTC_VECT(RTC, 0x4a0),
55 INTC_VECT(RTC_CUI, 0x4c0), 49 INTC_VECT(RTC, 0x4c0),
56 INTC_VECT(WDT, 0x560), 50 INTC_VECT(WDT, 0x560),
57 INTC_VECT(REF_RCMI, 0x580), 51 INTC_VECT(REF_RCMI, 0x580),
58}; 52};
59 53
60static struct intc_group groups[] __initdata = {
61 INTC_GROUP(RTC, RTC_ATI, RTC_PRI, RTC_CUI),
62 INTC_GROUP(TMU2, TMU2_TUNI, TMU2_TICPI),
63 INTC_GROUP(DMAC, DMAC_DEI0, DMAC_DEI1, DMAC_DEI2, DMAC_DEI3),
64 INTC_GROUP(USB, USB_USI0, USB_USI1),
65 INTC_GROUP(SCIF0, SCIF0_ERI, SCIF0_RXI, SCIF0_TXI),
66 INTC_GROUP(SCIF2, SCIF2_ERI, SCIF2_RXI, SCIF2_TXI),
67};
68
69static struct intc_prio_reg prio_registers[] __initdata = { 54static struct intc_prio_reg prio_registers[] __initdata = {
70 { 0xfffffee2, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } }, 55 { 0xfffffee2, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
71 { 0xfffffee4, 0, 16, 4, /* IPRB */ { WDT, REF_RCMI, 0, 0 } }, 56 { 0xfffffee4, 0, 16, 4, /* IPRB */ { WDT, REF_RCMI, 0, 0 } },
@@ -78,7 +63,7 @@ static struct intc_prio_reg prio_registers[] __initdata = {
78 63
79}; 64};
80 65
81static DECLARE_INTC_DESC(intc_desc, "sh7705", vectors, groups, 66static DECLARE_INTC_DESC(intc_desc, "sh7705", vectors, NULL,
82 NULL, prio_registers, NULL); 67 NULL, prio_registers, NULL);
83 68
84static struct plat_sci_port sci_platform_data[] = { 69static struct plat_sci_port sci_platform_data[] = {
@@ -86,12 +71,12 @@ static struct plat_sci_port sci_platform_data[] = {
86 .mapbase = 0xa4410000, 71 .mapbase = 0xa4410000,
87 .flags = UPF_BOOT_AUTOCONF, 72 .flags = UPF_BOOT_AUTOCONF,
88 .type = PORT_SCIF, 73 .type = PORT_SCIF,
89 .irqs = { 56, 57, 59 }, 74 .irqs = { 56, 56, 56 },
90 }, { 75 }, {
91 .mapbase = 0xa4400000, 76 .mapbase = 0xa4400000,
92 .flags = UPF_BOOT_AUTOCONF, 77 .flags = UPF_BOOT_AUTOCONF,
93 .type = PORT_SCIF, 78 .type = PORT_SCIF,
94 .irqs = { 52, 53, 55 }, 79 .irqs = { 52, 52, 52 },
95 }, { 80 }, {
96 .flags = 0, 81 .flags = 0,
97 } 82 }
@@ -115,14 +100,6 @@ static struct resource rtc_resources[] = {
115 .start = 20, 100 .start = 20,
116 .flags = IORESOURCE_IRQ, 101 .flags = IORESOURCE_IRQ,
117 }, 102 },
118 [2] = {
119 .start = 21,
120 .flags = IORESOURCE_IRQ,
121 },
122 [3] = {
123 .start = 22,
124 .flags = IORESOURCE_IRQ,
125 },
126}; 103};
127 104
128static struct sh_rtc_platform_info rtc_info = { 105static struct sh_rtc_platform_info rtc_info = {
diff --git a/arch/sh/kernel/cpu/sh3/setup-sh770x.c b/arch/sh/kernel/cpu/sh3/setup-sh770x.c
index 93c55e2ed952..a74f960b5e79 100644
--- a/arch/sh/kernel/cpu/sh3/setup-sh770x.c
+++ b/arch/sh/kernel/cpu/sh3/setup-sh770x.c
@@ -2,6 +2,7 @@
2 * SH3 Setup code for SH7706, SH7707, SH7708, SH7709 2 * SH3 Setup code for SH7706, SH7707, SH7708, SH7709
3 * 3 *
4 * Copyright (C) 2007 Magnus Damm 4 * Copyright (C) 2007 Magnus Damm
5 * Copyright (C) 2009 Paul Mundt
5 * 6 *
6 * Based on setup-sh7709.c 7 * Based on setup-sh7709.c
7 * 8 *
@@ -24,46 +25,37 @@ enum {
24 /* interrupt sources */ 25 /* interrupt sources */
25 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, 26 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5,
26 PINT07, PINT815, 27 PINT07, PINT815,
27 DMAC_DEI0, DMAC_DEI1, DMAC_DEI2, DMAC_DEI3, 28 DMAC, SCIF0, SCIF2, SCI, ADC_ADI,
28 SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI,
29 SCIF2_ERI, SCIF2_RXI, SCIF2_BRI, SCIF2_TXI,
30 SCI_ERI, SCI_RXI, SCI_TXI, SCI_TEI,
31 ADC_ADI,
32 LCDC, PCC0, PCC1, 29 LCDC, PCC0, PCC1,
33 TMU0, TMU1, TMU2_TUNI, TMU2_TICPI, 30 TMU0, TMU1, TMU2,
34 RTC_ATI, RTC_PRI, RTC_CUI, 31 RTC, WDT, REF,
35 WDT,
36 REF_RCMI, REF_ROVI,
37
38 /* interrupt groups */
39 RTC, REF, TMU2, DMAC, SCI, SCIF2, SCIF0,
40}; 32};
41 33
42static struct intc_vect vectors[] __initdata = { 34static struct intc_vect vectors[] __initdata = {
43 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420), 35 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
44 INTC_VECT(TMU2_TUNI, 0x440), INTC_VECT(TMU2_TICPI, 0x460), 36 INTC_VECT(TMU2, 0x440), INTC_VECT(TMU2, 0x460),
45 INTC_VECT(RTC_ATI, 0x480), INTC_VECT(RTC_PRI, 0x4a0), 37 INTC_VECT(RTC, 0x480), INTC_VECT(RTC, 0x4a0),
46 INTC_VECT(RTC_CUI, 0x4c0), 38 INTC_VECT(RTC, 0x4c0),
47 INTC_VECT(SCI_ERI, 0x4e0), INTC_VECT(SCI_RXI, 0x500), 39 INTC_VECT(SCI, 0x4e0), INTC_VECT(SCI, 0x500),
48 INTC_VECT(SCI_TXI, 0x520), INTC_VECT(SCI_TEI, 0x540), 40 INTC_VECT(SCI, 0x520), INTC_VECT(SCI, 0x540),
49 INTC_VECT(WDT, 0x560), 41 INTC_VECT(WDT, 0x560),
50 INTC_VECT(REF_RCMI, 0x580), 42 INTC_VECT(REF, 0x580),
51 INTC_VECT(REF_ROVI, 0x5a0), 43 INTC_VECT(REF, 0x5a0),
52#if defined(CONFIG_CPU_SUBTYPE_SH7706) || \ 44#if defined(CONFIG_CPU_SUBTYPE_SH7706) || \
53 defined(CONFIG_CPU_SUBTYPE_SH7707) || \ 45 defined(CONFIG_CPU_SUBTYPE_SH7707) || \
54 defined(CONFIG_CPU_SUBTYPE_SH7709) 46 defined(CONFIG_CPU_SUBTYPE_SH7709)
55 /* IRQ0->5 are handled in setup-sh3.c */ 47 /* IRQ0->5 are handled in setup-sh3.c */
56 INTC_VECT(DMAC_DEI0, 0x800), INTC_VECT(DMAC_DEI1, 0x820), 48 INTC_VECT(DMAC, 0x800), INTC_VECT(DMAC, 0x820),
57 INTC_VECT(DMAC_DEI2, 0x840), INTC_VECT(DMAC_DEI3, 0x860), 49 INTC_VECT(DMAC, 0x840), INTC_VECT(DMAC, 0x860),
58 INTC_VECT(ADC_ADI, 0x980), 50 INTC_VECT(ADC_ADI, 0x980),
59 INTC_VECT(SCIF2_ERI, 0x900), INTC_VECT(SCIF2_RXI, 0x920), 51 INTC_VECT(SCIF2, 0x900), INTC_VECT(SCIF2, 0x920),
60 INTC_VECT(SCIF2_BRI, 0x940), INTC_VECT(SCIF2_TXI, 0x960), 52 INTC_VECT(SCIF2, 0x940), INTC_VECT(SCIF2, 0x960),
61#endif 53#endif
62#if defined(CONFIG_CPU_SUBTYPE_SH7707) || \ 54#if defined(CONFIG_CPU_SUBTYPE_SH7707) || \
63 defined(CONFIG_CPU_SUBTYPE_SH7709) 55 defined(CONFIG_CPU_SUBTYPE_SH7709)
64 INTC_VECT(PINT07, 0x700), INTC_VECT(PINT815, 0x720), 56 INTC_VECT(PINT07, 0x700), INTC_VECT(PINT815, 0x720),
65 INTC_VECT(SCIF0_ERI, 0x880), INTC_VECT(SCIF0_RXI, 0x8a0), 57 INTC_VECT(SCIF0, 0x880), INTC_VECT(SCIF0, 0x8a0),
66 INTC_VECT(SCIF0_BRI, 0x8c0), INTC_VECT(SCIF0_TXI, 0x8e0), 58 INTC_VECT(SCIF0, 0x8c0), INTC_VECT(SCIF0, 0x8e0),
67#endif 59#endif
68#if defined(CONFIG_CPU_SUBTYPE_SH7707) 60#if defined(CONFIG_CPU_SUBTYPE_SH7707)
69 INTC_VECT(LCDC, 0x9a0), 61 INTC_VECT(LCDC, 0x9a0),
@@ -71,16 +63,6 @@ static struct intc_vect vectors[] __initdata = {
71#endif 63#endif
72}; 64};
73 65
74static struct intc_group groups[] __initdata = {
75 INTC_GROUP(RTC, RTC_ATI, RTC_PRI, RTC_CUI),
76 INTC_GROUP(TMU2, TMU2_TUNI, TMU2_TICPI),
77 INTC_GROUP(REF, REF_RCMI, REF_ROVI),
78 INTC_GROUP(DMAC, DMAC_DEI0, DMAC_DEI1, DMAC_DEI2, DMAC_DEI3),
79 INTC_GROUP(SCI, SCI_ERI, SCI_RXI, SCI_TXI, SCI_TEI),
80 INTC_GROUP(SCIF0, SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI),
81 INTC_GROUP(SCIF2, SCIF2_ERI, SCIF2_RXI, SCIF2_BRI, SCIF2_TXI),
82};
83
84static struct intc_prio_reg prio_registers[] __initdata = { 66static struct intc_prio_reg prio_registers[] __initdata = {
85 { 0xfffffee2, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } }, 67 { 0xfffffee2, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
86 { 0xfffffee4, 0, 16, 4, /* IPRB */ { WDT, REF, SCI, 0 } }, 68 { 0xfffffee4, 0, 16, 4, /* IPRB */ { WDT, REF, SCI, 0 } },
@@ -101,7 +83,7 @@ static struct intc_prio_reg prio_registers[] __initdata = {
101#endif 83#endif
102}; 84};
103 85
104static DECLARE_INTC_DESC(intc_desc, "sh770x", vectors, groups, 86static DECLARE_INTC_DESC(intc_desc, "sh770x", vectors, NULL,
105 NULL, prio_registers, NULL); 87 NULL, prio_registers, NULL);
106 88
107static struct resource rtc_resources[] = { 89static struct resource rtc_resources[] = {
@@ -111,14 +93,6 @@ static struct resource rtc_resources[] = {
111 .flags = IORESOURCE_IO, 93 .flags = IORESOURCE_IO,
112 }, 94 },
113 [1] = { 95 [1] = {
114 .start = 21,
115 .flags = IORESOURCE_IRQ,
116 },
117 [2] = {
118 .start = 22,
119 .flags = IORESOURCE_IRQ,
120 },
121 [3] = {
122 .start = 20, 96 .start = 20,
123 .flags = IORESOURCE_IRQ, 97 .flags = IORESOURCE_IRQ,
124 }, 98 },
@@ -136,7 +110,7 @@ static struct plat_sci_port sci_platform_data[] = {
136 .mapbase = 0xfffffe80, 110 .mapbase = 0xfffffe80,
137 .flags = UPF_BOOT_AUTOCONF, 111 .flags = UPF_BOOT_AUTOCONF,
138 .type = PORT_SCI, 112 .type = PORT_SCI,
139 .irqs = { 23, 24, 25, 0 }, 113 .irqs = { 23, 23, 23, 0 },
140 }, 114 },
141#if defined(CONFIG_CPU_SUBTYPE_SH7706) || \ 115#if defined(CONFIG_CPU_SUBTYPE_SH7706) || \
142 defined(CONFIG_CPU_SUBTYPE_SH7707) || \ 116 defined(CONFIG_CPU_SUBTYPE_SH7707) || \
@@ -145,7 +119,7 @@ static struct plat_sci_port sci_platform_data[] = {
145 .mapbase = 0xa4000150, 119 .mapbase = 0xa4000150,
146 .flags = UPF_BOOT_AUTOCONF, 120 .flags = UPF_BOOT_AUTOCONF,
147 .type = PORT_SCIF, 121 .type = PORT_SCIF,
148 .irqs = { 56, 57, 59, 58 }, 122 .irqs = { 56, 56, 56, 56 },
149 }, 123 },
150#endif 124#endif
151#if defined(CONFIG_CPU_SUBTYPE_SH7707) || \ 125#if defined(CONFIG_CPU_SUBTYPE_SH7707) || \
@@ -154,7 +128,7 @@ static struct plat_sci_port sci_platform_data[] = {
154 .mapbase = 0xa4000140, 128 .mapbase = 0xa4000140,
155 .flags = UPF_BOOT_AUTOCONF, 129 .flags = UPF_BOOT_AUTOCONF,
156 .type = PORT_IRDA, 130 .type = PORT_IRDA,
157 .irqs = { 52, 53, 55, 54 }, 131 .irqs = { 52, 52, 52, 52 },
158 }, 132 },
159#endif 133#endif
160 { 134 {
diff --git a/arch/sh/kernel/cpu/sh3/setup-sh7710.c b/arch/sh/kernel/cpu/sh3/setup-sh7710.c
index 77eee481de47..335098b66e2f 100644
--- a/arch/sh/kernel/cpu/sh3/setup-sh7710.c
+++ b/arch/sh/kernel/cpu/sh3/setup-sh7710.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * SH3 Setup code for SH7710, SH7712 2 * SH3 Setup code for SH7710, SH7712
3 * 3 *
4 * Copyright (C) 2006, 2007 Paul Mundt 4 * Copyright (C) 2006 - 2009 Paul Mundt
5 * Copyright (C) 2007 Nobuhiro Iwamatsu 5 * Copyright (C) 2007 Nobuhiro Iwamatsu
6 * 6 *
7 * This file is subject to the terms and conditions of the GNU General Public 7 * This file is subject to the terms and conditions of the GNU General Public
@@ -20,59 +20,40 @@ enum {
20 20
21 /* interrupt sources */ 21 /* interrupt sources */
22 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, 22 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5,
23 DMAC_DEI0, DMAC_DEI1, DMAC_DEI2, DMAC_DEI3, 23 DMAC1, SCIF0, SCIF1, DMAC2, IPSEC,
24 SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI,
25 SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI,
26 DMAC_DEI4, DMAC_DEI5,
27 IPSEC,
28 EDMAC0, EDMAC1, EDMAC2, 24 EDMAC0, EDMAC1, EDMAC2,
29 SIOF0_ERI, SIOF0_TXI, SIOF0_RXI, SIOF0_CCI, 25 SIOF0, SIOF1,
30 SIOF1_ERI, SIOF1_TXI, SIOF1_RXI, SIOF1_CCI,
31 TMU0, TMU1, TMU2,
32 RTC_ATI, RTC_PRI, RTC_CUI,
33 WDT,
34 REF,
35 26
36 /* interrupt groups */ 27 TMU0, TMU1, TMU2,
37 RTC, DMAC1, SCIF0, SCIF1, DMAC2, SIOF0, SIOF1, 28 RTC, WDT, REF,
38}; 29};
39 30
40static struct intc_vect vectors[] __initdata = { 31static struct intc_vect vectors[] __initdata = {
41 /* IRQ0->5 are handled in setup-sh3.c */ 32 /* IRQ0->5 are handled in setup-sh3.c */
42 INTC_VECT(DMAC_DEI0, 0x800), INTC_VECT(DMAC_DEI1, 0x820), 33 INTC_VECT(DMAC1, 0x800), INTC_VECT(DMAC1, 0x820),
43 INTC_VECT(DMAC_DEI2, 0x840), INTC_VECT(DMAC_DEI3, 0x860), 34 INTC_VECT(DMAC1, 0x840), INTC_VECT(DMAC1, 0x860),
44 INTC_VECT(SCIF0_ERI, 0x880), INTC_VECT(SCIF0_RXI, 0x8a0), 35 INTC_VECT(SCIF0, 0x880), INTC_VECT(SCIF0, 0x8a0),
45 INTC_VECT(SCIF0_BRI, 0x8c0), INTC_VECT(SCIF0_TXI, 0x8e0), 36 INTC_VECT(SCIF0, 0x8c0), INTC_VECT(SCIF0, 0x8e0),
46 INTC_VECT(SCIF1_ERI, 0x900), INTC_VECT(SCIF1_RXI, 0x920), 37 INTC_VECT(SCIF1, 0x900), INTC_VECT(SCIF1, 0x920),
47 INTC_VECT(SCIF1_BRI, 0x940), INTC_VECT(SCIF1_TXI, 0x960), 38 INTC_VECT(SCIF1, 0x940), INTC_VECT(SCIF1, 0x960),
48 INTC_VECT(DMAC_DEI4, 0xb80), INTC_VECT(DMAC_DEI5, 0xba0), 39 INTC_VECT(DMAC2, 0xb80), INTC_VECT(DMAC2, 0xba0),
49#ifdef CONFIG_CPU_SUBTYPE_SH7710 40#ifdef CONFIG_CPU_SUBTYPE_SH7710
50 INTC_VECT(IPSEC, 0xbe0), 41 INTC_VECT(IPSEC, 0xbe0),
51#endif 42#endif
52 INTC_VECT(EDMAC0, 0xc00), INTC_VECT(EDMAC1, 0xc20), 43 INTC_VECT(EDMAC0, 0xc00), INTC_VECT(EDMAC1, 0xc20),
53 INTC_VECT(EDMAC2, 0xc40), 44 INTC_VECT(EDMAC2, 0xc40),
54 INTC_VECT(SIOF0_ERI, 0xe00), INTC_VECT(SIOF0_TXI, 0xe20), 45 INTC_VECT(SIOF0, 0xe00), INTC_VECT(SIOF0, 0xe20),
55 INTC_VECT(SIOF0_RXI, 0xe40), INTC_VECT(SIOF0_CCI, 0xe60), 46 INTC_VECT(SIOF0, 0xe40), INTC_VECT(SIOF0, 0xe60),
56 INTC_VECT(SIOF1_ERI, 0xe80), INTC_VECT(SIOF1_TXI, 0xea0), 47 INTC_VECT(SIOF1, 0xe80), INTC_VECT(SIOF1, 0xea0),
57 INTC_VECT(SIOF1_RXI, 0xec0), INTC_VECT(SIOF1_CCI, 0xee0), 48 INTC_VECT(SIOF1, 0xec0), INTC_VECT(SIOF1, 0xee0),
58 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420), 49 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
59 INTC_VECT(TMU2, 0x440), 50 INTC_VECT(TMU2, 0x440),
60 INTC_VECT(RTC_ATI, 0x480), INTC_VECT(RTC_PRI, 0x4a0), 51 INTC_VECT(RTC, 0x480), INTC_VECT(RTC, 0x4a0),
61 INTC_VECT(RTC_CUI, 0x4c0), 52 INTC_VECT(RTC, 0x4c0),
62 INTC_VECT(WDT, 0x560), 53 INTC_VECT(WDT, 0x560),
63 INTC_VECT(REF, 0x580), 54 INTC_VECT(REF, 0x580),
64}; 55};
65 56
66static struct intc_group groups[] __initdata = {
67 INTC_GROUP(RTC, RTC_ATI, RTC_PRI, RTC_CUI),
68 INTC_GROUP(DMAC1, DMAC_DEI0, DMAC_DEI1, DMAC_DEI2, DMAC_DEI3),
69 INTC_GROUP(SCIF0, SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI),
70 INTC_GROUP(SCIF1, SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI),
71 INTC_GROUP(DMAC2, DMAC_DEI4, DMAC_DEI5),
72 INTC_GROUP(SIOF0, SIOF0_ERI, SIOF0_TXI, SIOF0_RXI, SIOF0_CCI),
73 INTC_GROUP(SIOF1, SIOF1_ERI, SIOF1_TXI, SIOF1_RXI, SIOF1_CCI),
74};
75
76static struct intc_prio_reg prio_registers[] __initdata = { 57static struct intc_prio_reg prio_registers[] __initdata = {
77 { 0xfffffee2, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } }, 58 { 0xfffffee2, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
78 { 0xfffffee4, 0, 16, 4, /* IPRB */ { WDT, REF, 0, 0 } }, 59 { 0xfffffee4, 0, 16, 4, /* IPRB */ { WDT, REF, 0, 0 } },
@@ -85,7 +66,7 @@ static struct intc_prio_reg prio_registers[] __initdata = {
85 { 0xa4080006, 0, 16, 4, /* IPRI */ { 0, 0, SIOF1 } }, 66 { 0xa4080006, 0, 16, 4, /* IPRI */ { 0, 0, SIOF1 } },
86}; 67};
87 68
88static DECLARE_INTC_DESC(intc_desc, "sh7710", vectors, groups, 69static DECLARE_INTC_DESC(intc_desc, "sh7710", vectors, NULL,
89 NULL, prio_registers, NULL); 70 NULL, prio_registers, NULL);
90 71
91static struct resource rtc_resources[] = { 72static struct resource rtc_resources[] = {
@@ -98,14 +79,6 @@ static struct resource rtc_resources[] = {
98 .start = 20, 79 .start = 20,
99 .flags = IORESOURCE_IRQ, 80 .flags = IORESOURCE_IRQ,
100 }, 81 },
101 [2] = {
102 .start = 21,
103 .flags = IORESOURCE_IRQ,
104 },
105 [3] = {
106 .start = 22,
107 .flags = IORESOURCE_IRQ,
108 },
109}; 82};
110 83
111static struct sh_rtc_platform_info rtc_info = { 84static struct sh_rtc_platform_info rtc_info = {
@@ -127,12 +100,12 @@ static struct plat_sci_port sci_platform_data[] = {
127 .mapbase = 0xa4400000, 100 .mapbase = 0xa4400000,
128 .flags = UPF_BOOT_AUTOCONF, 101 .flags = UPF_BOOT_AUTOCONF,
129 .type = PORT_SCIF, 102 .type = PORT_SCIF,
130 .irqs = { 52, 53, 55, 54 }, 103 .irqs = { 52, 52, 52, 52 },
131 }, { 104 }, {
132 .mapbase = 0xa4410000, 105 .mapbase = 0xa4410000,
133 .flags = UPF_BOOT_AUTOCONF, 106 .flags = UPF_BOOT_AUTOCONF,
134 .type = PORT_SCIF, 107 .type = PORT_SCIF,
135 .irqs = { 56, 57, 59, 58 }, 108 .irqs = { 56, 56, 56, 56 },
136 }, { 109 }, {
137 110
138 .flags = 0, 111 .flags = 0,
diff --git a/arch/sh/kernel/cpu/sh3/setup-sh7720.c b/arch/sh/kernel/cpu/sh3/setup-sh7720.c
index f807a21b066c..003874a2fd2a 100644
--- a/arch/sh/kernel/cpu/sh3/setup-sh7720.c
+++ b/arch/sh/kernel/cpu/sh3/setup-sh7720.c
@@ -2,6 +2,7 @@
2 * SH7720 Setup 2 * SH7720 Setup
3 * 3 *
4 * Copyright (C) 2007 Markus Brunner, Mark Jonas 4 * Copyright (C) 2007 Markus Brunner, Mark Jonas
5 * Copyright (C) 2009 Paul Mundt
5 * 6 *
6 * Based on arch/sh/kernel/cpu/sh4/setup-sh7750.c: 7 * Based on arch/sh/kernel/cpu/sh4/setup-sh7750.c:
7 * 8 *
@@ -26,17 +27,7 @@ static struct resource rtc_resources[] = {
26 .flags = IORESOURCE_IO, 27 .flags = IORESOURCE_IO,
27 }, 28 },
28 [1] = { 29 [1] = {
29 /* Period IRQ */ 30 /* Shared Period/Carry/Alarm IRQ */
30 .start = 21,
31 .flags = IORESOURCE_IRQ,
32 },
33 [2] = {
34 /* Carry IRQ */
35 .start = 22,
36 .flags = IORESOURCE_IRQ,
37 },
38 [3] = {
39 /* Alarm IRQ */
40 .start = 20, 31 .start = 20,
41 .flags = IORESOURCE_IRQ, 32 .flags = IORESOURCE_IRQ,
42 }, 33 },
@@ -150,62 +141,49 @@ enum {
150 UNUSED = 0, 141 UNUSED = 0,
151 142
152 /* interrupt sources */ 143 /* interrupt sources */
153 TMU0, TMU1, TMU2, RTC_ATI, RTC_PRI, RTC_CUI, 144 TMU0, TMU1, TMU2, RTC,
154 WDT, REF_RCMI, SIM_ERI, SIM_RXI, SIM_TXI, SIM_TEND, 145 WDT, REF_RCMI, SIM,
155 IRQ0, IRQ1, IRQ2, IRQ3, 146 IRQ0, IRQ1, IRQ2, IRQ3,
156 USBF_SPD, TMU_SUNI, IRQ5, IRQ4, 147 USBF_SPD, TMU_SUNI, IRQ5, IRQ4,
157 DMAC1_DEI0, DMAC1_DEI1, DMAC1_DEI2, DMAC1_DEI3, LCDC, SSL, 148 DMAC1, LCDC, SSL,
158 ADC, DMAC2_DEI4, DMAC2_DEI5, USBFI0, USBFI1, CMT, 149 ADC, DMAC2, USBFI, CMT,
159 SCIF0, SCIF1, 150 SCIF0, SCIF1,
160 PINT07, PINT815, TPU0, TPU1, TPU2, TPU3, IIC, 151 PINT07, PINT815, TPU, IIC,
161 SIOF0, SIOF1, MMCI0, MMCI1, MMCI2, MMCI3, PCC, 152 SIOF0, SIOF1, MMC, PCC,
162 USBHI, AFEIF, 153 USBHI, AFEIF,
163 H_UDI, 154 H_UDI,
164 /* interrupt groups */
165 TMU, RTC, SIM, DMAC1, USBFI, DMAC2, USB, TPU, MMC,
166}; 155};
167 156
168static struct intc_vect vectors[] __initdata = { 157static struct intc_vect vectors[] __initdata = {
169 /* IRQ0->5 are handled in setup-sh3.c */ 158 /* IRQ0->5 are handled in setup-sh3.c */
170 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420), 159 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
171 INTC_VECT(TMU2, 0x440), INTC_VECT(RTC_ATI, 0x480), 160 INTC_VECT(TMU2, 0x440), INTC_VECT(RTC, 0x480),
172 INTC_VECT(RTC_PRI, 0x4a0), INTC_VECT(RTC_CUI, 0x4c0), 161 INTC_VECT(RTC, 0x4a0), INTC_VECT(RTC, 0x4c0),
173 INTC_VECT(SIM_ERI, 0x4e0), INTC_VECT(SIM_RXI, 0x500), 162 INTC_VECT(SIM, 0x4e0), INTC_VECT(SIM, 0x500),
174 INTC_VECT(SIM_TXI, 0x520), INTC_VECT(SIM_TEND, 0x540), 163 INTC_VECT(SIM, 0x520), INTC_VECT(SIM, 0x540),
175 INTC_VECT(WDT, 0x560), INTC_VECT(REF_RCMI, 0x580), 164 INTC_VECT(WDT, 0x560), INTC_VECT(REF_RCMI, 0x580),
176 /* H_UDI cannot be masked */ INTC_VECT(TMU_SUNI, 0x6c0), 165 /* H_UDI cannot be masked */ INTC_VECT(TMU_SUNI, 0x6c0),
177 INTC_VECT(USBF_SPD, 0x6e0), INTC_VECT(DMAC1_DEI0, 0x800), 166 INTC_VECT(USBF_SPD, 0x6e0), INTC_VECT(DMAC1, 0x800),
178 INTC_VECT(DMAC1_DEI1, 0x820), INTC_VECT(DMAC1_DEI2, 0x840), 167 INTC_VECT(DMAC1, 0x820), INTC_VECT(DMAC1, 0x840),
179 INTC_VECT(DMAC1_DEI3, 0x860), INTC_VECT(LCDC, 0x900), 168 INTC_VECT(DMAC1, 0x860), INTC_VECT(LCDC, 0x900),
180#if defined(CONFIG_CPU_SUBTYPE_SH7720) 169#if defined(CONFIG_CPU_SUBTYPE_SH7720)
181 INTC_VECT(SSL, 0x980), 170 INTC_VECT(SSL, 0x980),
182#endif 171#endif
183 INTC_VECT(USBFI0, 0xa20), INTC_VECT(USBFI1, 0xa40), 172 INTC_VECT(USBFI, 0xa20), INTC_VECT(USBFI, 0xa40),
184 INTC_VECT(USBHI, 0xa60), 173 INTC_VECT(USBHI, 0xa60),
185 INTC_VECT(DMAC2_DEI4, 0xb80), INTC_VECT(DMAC2_DEI5, 0xba0), 174 INTC_VECT(DMAC2, 0xb80), INTC_VECT(DMAC2, 0xba0),
186 INTC_VECT(ADC, 0xbe0), INTC_VECT(SCIF0, 0xc00), 175 INTC_VECT(ADC, 0xbe0), INTC_VECT(SCIF0, 0xc00),
187 INTC_VECT(SCIF1, 0xc20), INTC_VECT(PINT07, 0xc80), 176 INTC_VECT(SCIF1, 0xc20), INTC_VECT(PINT07, 0xc80),
188 INTC_VECT(PINT815, 0xca0), INTC_VECT(SIOF0, 0xd00), 177 INTC_VECT(PINT815, 0xca0), INTC_VECT(SIOF0, 0xd00),
189 INTC_VECT(SIOF1, 0xd20), INTC_VECT(TPU0, 0xd80), 178 INTC_VECT(SIOF1, 0xd20), INTC_VECT(TPU, 0xd80),
190 INTC_VECT(TPU1, 0xda0), INTC_VECT(TPU2, 0xdc0), 179 INTC_VECT(TPU, 0xda0), INTC_VECT(TPU, 0xdc0),
191 INTC_VECT(TPU3, 0xde0), INTC_VECT(IIC, 0xe00), 180 INTC_VECT(TPU, 0xde0), INTC_VECT(IIC, 0xe00),
192 INTC_VECT(MMCI0, 0xe80), INTC_VECT(MMCI1, 0xea0), 181 INTC_VECT(MMC, 0xe80), INTC_VECT(MMC, 0xea0),
193 INTC_VECT(MMCI2, 0xec0), INTC_VECT(MMCI3, 0xee0), 182 INTC_VECT(MMC, 0xec0), INTC_VECT(MMC, 0xee0),
194 INTC_VECT(CMT, 0xf00), INTC_VECT(PCC, 0xf60), 183 INTC_VECT(CMT, 0xf00), INTC_VECT(PCC, 0xf60),
195 INTC_VECT(AFEIF, 0xfe0), 184 INTC_VECT(AFEIF, 0xfe0),
196}; 185};
197 186
198static struct intc_group groups[] __initdata = {
199 INTC_GROUP(TMU, TMU0, TMU1, TMU2),
200 INTC_GROUP(RTC, RTC_ATI, RTC_PRI, RTC_CUI),
201 INTC_GROUP(SIM, SIM_ERI, SIM_RXI, SIM_TXI, SIM_TEND),
202 INTC_GROUP(DMAC1, DMAC1_DEI0, DMAC1_DEI1, DMAC1_DEI2, DMAC1_DEI3),
203 INTC_GROUP(USBFI, USBFI0, USBFI1),
204 INTC_GROUP(DMAC2, DMAC2_DEI4, DMAC2_DEI5),
205 INTC_GROUP(TPU, TPU0, TPU1, TPU2, TPU3),
206 INTC_GROUP(MMC, MMCI0, MMCI1, MMCI2, MMCI3),
207};
208
209static struct intc_prio_reg prio_registers[] __initdata = { 187static struct intc_prio_reg prio_registers[] __initdata = {
210 { 0xA414FEE2UL, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } }, 188 { 0xA414FEE2UL, 0, 16, 4, /* IPRA */ { TMU0, TMU1, TMU2, RTC } },
211 { 0xA414FEE4UL, 0, 16, 4, /* IPRB */ { WDT, REF_RCMI, SIM, 0 } }, 189 { 0xA414FEE4UL, 0, 16, 4, /* IPRB */ { WDT, REF_RCMI, SIM, 0 } },
@@ -219,7 +197,7 @@ static struct intc_prio_reg prio_registers[] __initdata = {
219 { 0xA4080008UL, 0, 16, 4, /* IPRJ */ { 0, USBHI, 0, AFEIF } }, 197 { 0xA4080008UL, 0, 16, 4, /* IPRJ */ { 0, USBHI, 0, AFEIF } },
220}; 198};
221 199
222static DECLARE_INTC_DESC(intc_desc, "sh7720", vectors, groups, 200static DECLARE_INTC_DESC(intc_desc, "sh7720", vectors, NULL,
223 NULL, prio_registers, NULL); 201 NULL, prio_registers, NULL);
224 202
225void __init plat_irq_setup(void) 203void __init plat_irq_setup(void)
diff --git a/arch/sh/kernel/cpu/sh3/swsusp.S b/arch/sh/kernel/cpu/sh3/swsusp.S
new file mode 100644
index 000000000000..01145426a2b8
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh3/swsusp.S
@@ -0,0 +1,147 @@
1/*
2 * arch/sh/kernel/cpu/sh3/swsusp.S
3 *
4 * Copyright (C) 2009 Magnus Damm
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10#include <linux/sys.h>
11#include <linux/errno.h>
12#include <linux/linkage.h>
13#include <asm/asm-offsets.h>
14#include <asm/page.h>
15
16#define k0 r0
17#define k1 r1
18#define k2 r2
19#define k3 r3
20#define k4 r4
21
22! swsusp_arch_resume()
23! - copy restore_pblist pages
24! - restore registers from swsusp_arch_regs_cpu0
25
26ENTRY(swsusp_arch_resume)
27 mov.l 1f, r15
28 mov.l 2f, r4
29 mov.l @r4, r4
30
31swsusp_copy_loop:
32 mov r4, r0
33 cmp/eq #0, r0
34 bt swsusp_restore_regs
35
36 mov.l @(PBE_ADDRESS, r4), r2
37 mov.l @(PBE_ORIG_ADDRESS, r4), r5
38
39 mov #(PAGE_SIZE >> 10), r3
40 shll8 r3
41 shlr2 r3 /* PAGE_SIZE / 16 */
42swsusp_copy_page:
43 dt r3
44 mov.l @r2+,r1 /* 16n+0 */
45 mov.l r1,@r5
46 add #4,r5
47 mov.l @r2+,r1 /* 16n+4 */
48 mov.l r1,@r5
49 add #4,r5
50 mov.l @r2+,r1 /* 16n+8 */
51 mov.l r1,@r5
52 add #4,r5
53 mov.l @r2+,r1 /* 16n+12 */
54 mov.l r1,@r5
55 bf/s swsusp_copy_page
56 add #4,r5
57
58 bra swsusp_copy_loop
59 mov.l @(PBE_NEXT, r4), r4
60
61swsusp_restore_regs:
62 ! BL=0: R7->R0 is bank0
63 mov.l 3f, r8
64 mov.l 4f, r5
65 jsr @r5
66 nop
67
68 ! BL=1: R7->R0 is bank1
69 lds k2, pr
70 ldc k3, ssr
71
72 mov.l @r15+, r0
73 mov.l @r15+, r1
74 mov.l @r15+, r2
75 mov.l @r15+, r3
76 mov.l @r15+, r4
77 mov.l @r15+, r5
78 mov.l @r15+, r6
79 mov.l @r15+, r7
80
81 rte
82 nop
83 ! BL=0: R7->R0 is bank0
84
85 .align 2
861: .long swsusp_arch_regs_cpu0
872: .long restore_pblist
883: .long 0x20000000 ! RB=1
894: .long restore_regs
90
91! swsusp_arch_suspend()
92! - prepare pc for resume, return from function without swsusp_save on resume
93! - save registers in swsusp_arch_regs_cpu0
94! - call swsusp_save write suspend image
95
96ENTRY(swsusp_arch_suspend)
97 sts pr, r0 ! save pr in r0
98 mov r15, r2 ! save sp in r2
99 mov r8, r5 ! save r8 in r5
100 stc sr, r1
101 ldc r1, ssr ! save sr in ssr
102 mov.l 1f, r1
103 ldc r1, spc ! setup pc value for resuming
104 mov.l 5f, r15 ! use swsusp_arch_regs_cpu0 as stack
105 mov.l 6f, r3
106 add r3, r15 ! save from top of structure
107
108 ! BL=0: R7->R0 is bank0
109 mov.l 2f, r3 ! get new SR value for bank1
110 mov #0, r4
111 mov.l 7f, r1
112 jsr @r1 ! switch to bank1 and save bank1 r7->r0
113 not r4, r4
114
115 ! BL=1: R7->R0 is bank1
116 stc r2_bank, k0 ! fetch old sp from r2_bank0
117 mov.l 3f, k4 ! SR bits to clear in k4
118 mov.l 8f, k1
119 jsr @k1 ! switch to bank0 and save all regs
120 stc r0_bank, k3 ! fetch old pr from r0_bank0
121
122 ! BL=0: R7->R0 is bank0
123 mov r2, r15 ! restore old sp
124 mov r5, r8 ! restore old r8
125 stc ssr, r1
126 ldc r1, sr ! restore old sr
127 lds r0, pr ! restore old pr
128 mov.l 4f, r0
129 jmp @r0
130 nop
131
132swsusp_call_save:
133 mov r2, r15 ! restore old sp
134 mov r5, r8 ! restore old r8
135 lds r0, pr ! restore old pr
136 rts
137 mov #0, r0
138
139 .align 2
1401: .long swsusp_call_save
1412: .long 0x20000000 ! RB=1
1423: .long 0xdfffffff ! RB=0
1434: .long swsusp_save
1445: .long swsusp_arch_regs_cpu0
1456: .long SWSUSP_ARCH_REGS_SIZE
1467: .long save_low_regs
1478: .long save_regs
diff --git a/arch/sh/kernel/cpu/sh4/Makefile b/arch/sh/kernel/cpu/sh4/Makefile
index d608557c7a3f..203b18347b83 100644
--- a/arch/sh/kernel/cpu/sh4/Makefile
+++ b/arch/sh/kernel/cpu/sh4/Makefile
@@ -5,6 +5,7 @@
5obj-y := probe.o common.o 5obj-y := probe.o common.o
6common-y += $(addprefix ../sh3/, entry.o ex.o) 6common-y += $(addprefix ../sh3/, entry.o ex.o)
7 7
8obj-$(CONFIG_HIBERNATION) += $(addprefix ../sh3/, swsusp.o)
8obj-$(CONFIG_SH_FPU) += fpu.o softfloat.o 9obj-$(CONFIG_SH_FPU) += fpu.o softfloat.o
9obj-$(CONFIG_SH_STORE_QUEUES) += sq.o 10obj-$(CONFIG_SH_STORE_QUEUES) += sq.o
10 11
diff --git a/arch/sh/kernel/cpu/sh4/probe.c b/arch/sh/kernel/cpu/sh4/probe.c
index 2e42572b1b11..3d3a3c4425a9 100644
--- a/arch/sh/kernel/cpu/sh4/probe.c
+++ b/arch/sh/kernel/cpu/sh4/probe.c
@@ -129,6 +129,13 @@ int __init detect_cpu_and_cache_system(void)
129 boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER | 129 boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
130 CPU_HAS_LLSC; 130 CPU_HAS_LLSC;
131 break; 131 break;
132 case 0x4004:
133 boot_cpu_data.type = CPU_SH7786;
134 boot_cpu_data.icache.ways = 4;
135 boot_cpu_data.dcache.ways = 4;
136 boot_cpu_data.flags |= CPU_HAS_FPU | CPU_HAS_PERF_COUNTER |
137 CPU_HAS_LLSC | CPU_HAS_PTEAEX;
138 break;
132 case 0x3008: 139 case 0x3008:
133 boot_cpu_data.icache.ways = 4; 140 boot_cpu_data.icache.ways = 4;
134 boot_cpu_data.dcache.ways = 4; 141 boot_cpu_data.dcache.ways = 4;
diff --git a/arch/sh/kernel/cpu/sh4/setup-sh7750.c b/arch/sh/kernel/cpu/sh4/setup-sh7750.c
index ec884039b914..a1c80d909cd6 100644
--- a/arch/sh/kernel/cpu/sh4/setup-sh7750.c
+++ b/arch/sh/kernel/cpu/sh4/setup-sh7750.c
@@ -21,17 +21,7 @@ static struct resource rtc_resources[] = {
21 .flags = IORESOURCE_IO, 21 .flags = IORESOURCE_IO,
22 }, 22 },
23 [1] = { 23 [1] = {
24 /* Period IRQ */ 24 /* Shared Period/Carry/Alarm IRQ */
25 .start = 21,
26 .flags = IORESOURCE_IRQ,
27 },
28 [2] = {
29 /* Carry IRQ */
30 .start = 22,
31 .flags = IORESOURCE_IRQ,
32 },
33 [3] = {
34 /* Alarm IRQ */
35 .start = 20, 25 .start = 20,
36 .flags = IORESOURCE_IRQ, 26 .flags = IORESOURCE_IRQ,
37 }, 27 },
@@ -50,13 +40,13 @@ static struct plat_sci_port sci_platform_data[] = {
50 .mapbase = 0xffe00000, 40 .mapbase = 0xffe00000,
51 .flags = UPF_BOOT_AUTOCONF, 41 .flags = UPF_BOOT_AUTOCONF,
52 .type = PORT_SCI, 42 .type = PORT_SCI,
53 .irqs = { 23, 24, 25, 0 }, 43 .irqs = { 23, 23, 23, 0 },
54 }, { 44 }, {
55#endif 45#endif
56 .mapbase = 0xffe80000, 46 .mapbase = 0xffe80000,
57 .flags = UPF_BOOT_AUTOCONF, 47 .flags = UPF_BOOT_AUTOCONF,
58 .type = PORT_SCIF, 48 .type = PORT_SCIF,
59 .irqs = { 40, 41, 43, 42 }, 49 .irqs = { 40, 40, 40, 40 },
60 }, { 50 }, {
61 .flags = 0, 51 .flags = 0,
62 } 52 }
@@ -87,43 +77,27 @@ enum {
87 77
88 /* interrupt sources */ 78 /* interrupt sources */
89 IRL0, IRL1, IRL2, IRL3, /* only IRLM mode supported */ 79 IRL0, IRL1, IRL2, IRL3, /* only IRLM mode supported */
90 HUDI, GPIOI, 80 HUDI, GPIOI, DMAC,
91 DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2, DMAC_DMTE3,
92 DMAC_DMTE4, DMAC_DMTE5, DMAC_DMTE6, DMAC_DMTE7,
93 DMAC_DMAE,
94 PCIC0_PCISERR, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON, 81 PCIC0_PCISERR, PCIC1_PCIERR, PCIC1_PCIPWDWN, PCIC1_PCIPWON,
95 PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3, 82 PCIC1_PCIDMA0, PCIC1_PCIDMA1, PCIC1_PCIDMA2, PCIC1_PCIDMA3,
96 TMU3, TMU4, TMU0, TMU1, TMU2_TUNI, TMU2_TICPI, 83 TMU3, TMU4, TMU0, TMU1, TMU2, RTC, SCI1, SCIF, WDT, REF,
97 RTC_ATI, RTC_PRI, RTC_CUI,
98 SCI1_ERI, SCI1_RXI, SCI1_TXI, SCI1_TEI,
99 SCIF_ERI, SCIF_RXI, SCIF_BRI, SCIF_TXI,
100 WDT,
101 REF_RCMI, REF_ROVI,
102 84
103 /* interrupt groups */ 85 /* interrupt groups */
104 DMAC, PCIC1, TMU2, RTC, SCI1, SCIF, REF, 86 PCIC1,
105}; 87};
106 88
107static struct intc_vect vectors[] __initdata = { 89static struct intc_vect vectors[] __initdata = {
108 INTC_VECT(HUDI, 0x600), INTC_VECT(GPIOI, 0x620), 90 INTC_VECT(HUDI, 0x600), INTC_VECT(GPIOI, 0x620),
109 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420), 91 INTC_VECT(TMU0, 0x400), INTC_VECT(TMU1, 0x420),
110 INTC_VECT(TMU2_TUNI, 0x440), INTC_VECT(TMU2_TICPI, 0x460), 92 INTC_VECT(TMU2, 0x440), INTC_VECT(TMU2, 0x460),
111 INTC_VECT(RTC_ATI, 0x480), INTC_VECT(RTC_PRI, 0x4a0), 93 INTC_VECT(RTC, 0x480), INTC_VECT(RTC, 0x4a0),
112 INTC_VECT(RTC_CUI, 0x4c0), 94 INTC_VECT(RTC, 0x4c0),
113 INTC_VECT(SCI1_ERI, 0x4e0), INTC_VECT(SCI1_RXI, 0x500), 95 INTC_VECT(SCI1, 0x4e0), INTC_VECT(SCI1, 0x500),
114 INTC_VECT(SCI1_TXI, 0x520), INTC_VECT(SCI1_TEI, 0x540), 96 INTC_VECT(SCI1, 0x520), INTC_VECT(SCI1, 0x540),
115 INTC_VECT(SCIF_ERI, 0x700), INTC_VECT(SCIF_RXI, 0x720), 97 INTC_VECT(SCIF, 0x700), INTC_VECT(SCIF, 0x720),
116 INTC_VECT(SCIF_BRI, 0x740), INTC_VECT(SCIF_TXI, 0x760), 98 INTC_VECT(SCIF, 0x740), INTC_VECT(SCIF, 0x760),
117 INTC_VECT(WDT, 0x560), 99 INTC_VECT(WDT, 0x560),
118 INTC_VECT(REF_RCMI, 0x580), INTC_VECT(REF_ROVI, 0x5a0), 100 INTC_VECT(REF, 0x580), INTC_VECT(REF, 0x5a0),
119};
120
121static struct intc_group groups[] __initdata = {
122 INTC_GROUP(TMU2, TMU2_TUNI, TMU2_TICPI),
123 INTC_GROUP(RTC, RTC_ATI, RTC_PRI, RTC_CUI),
124 INTC_GROUP(SCI1, SCI1_ERI, SCI1_RXI, SCI1_TXI, SCI1_TEI),
125 INTC_GROUP(SCIF, SCIF_ERI, SCIF_RXI, SCIF_BRI, SCIF_TXI),
126 INTC_GROUP(REF, REF_RCMI, REF_ROVI),
127}; 101};
128 102
129static struct intc_prio_reg prio_registers[] __initdata = { 103static struct intc_prio_reg prio_registers[] __initdata = {
@@ -136,7 +110,7 @@ static struct intc_prio_reg prio_registers[] __initdata = {
136 PCIC1, PCIC0_PCISERR } }, 110 PCIC1, PCIC0_PCISERR } },
137}; 111};
138 112
139static DECLARE_INTC_DESC(intc_desc, "sh7750", vectors, groups, 113static DECLARE_INTC_DESC(intc_desc, "sh7750", vectors, NULL,
140 NULL, prio_registers, NULL); 114 NULL, prio_registers, NULL);
141 115
142/* SH7750, SH7750S, SH7751 and SH7091 all have 4-channel DMA controllers */ 116/* SH7750, SH7750S, SH7751 and SH7091 all have 4-channel DMA controllers */
@@ -145,39 +119,28 @@ static DECLARE_INTC_DESC(intc_desc, "sh7750", vectors, groups,
145 defined(CONFIG_CPU_SUBTYPE_SH7751) || \ 119 defined(CONFIG_CPU_SUBTYPE_SH7751) || \
146 defined(CONFIG_CPU_SUBTYPE_SH7091) 120 defined(CONFIG_CPU_SUBTYPE_SH7091)
147static struct intc_vect vectors_dma4[] __initdata = { 121static struct intc_vect vectors_dma4[] __initdata = {
148 INTC_VECT(DMAC_DMTE0, 0x640), INTC_VECT(DMAC_DMTE1, 0x660), 122 INTC_VECT(DMAC, 0x640), INTC_VECT(DMAC, 0x660),
149 INTC_VECT(DMAC_DMTE2, 0x680), INTC_VECT(DMAC_DMTE3, 0x6a0), 123 INTC_VECT(DMAC, 0x680), INTC_VECT(DMAC, 0x6a0),
150 INTC_VECT(DMAC_DMAE, 0x6c0), 124 INTC_VECT(DMAC, 0x6c0),
151};
152
153static struct intc_group groups_dma4[] __initdata = {
154 INTC_GROUP(DMAC, DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2,
155 DMAC_DMTE3, DMAC_DMAE),
156}; 125};
157 126
158static DECLARE_INTC_DESC(intc_desc_dma4, "sh7750_dma4", 127static DECLARE_INTC_DESC(intc_desc_dma4, "sh7750_dma4",
159 vectors_dma4, groups_dma4, 128 vectors_dma4, NULL,
160 NULL, prio_registers, NULL); 129 NULL, prio_registers, NULL);
161#endif 130#endif
162 131
163/* SH7750R and SH7751R both have 8-channel DMA controllers */ 132/* SH7750R and SH7751R both have 8-channel DMA controllers */
164#if defined(CONFIG_CPU_SUBTYPE_SH7750R) || defined(CONFIG_CPU_SUBTYPE_SH7751R) 133#if defined(CONFIG_CPU_SUBTYPE_SH7750R) || defined(CONFIG_CPU_SUBTYPE_SH7751R)
165static struct intc_vect vectors_dma8[] __initdata = { 134static struct intc_vect vectors_dma8[] __initdata = {
166 INTC_VECT(DMAC_DMTE0, 0x640), INTC_VECT(DMAC_DMTE1, 0x660), 135 INTC_VECT(DMAC, 0x640), INTC_VECT(DMAC, 0x660),
167 INTC_VECT(DMAC_DMTE2, 0x680), INTC_VECT(DMAC_DMTE3, 0x6a0), 136 INTC_VECT(DMAC, 0x680), INTC_VECT(DMAC, 0x6a0),
168 INTC_VECT(DMAC_DMTE4, 0x780), INTC_VECT(DMAC_DMTE5, 0x7a0), 137 INTC_VECT(DMAC, 0x780), INTC_VECT(DMAC, 0x7a0),
169 INTC_VECT(DMAC_DMTE6, 0x7c0), INTC_VECT(DMAC_DMTE7, 0x7e0), 138 INTC_VECT(DMAC, 0x7c0), INTC_VECT(DMAC, 0x7e0),
170 INTC_VECT(DMAC_DMAE, 0x6c0), 139 INTC_VECT(DMAC, 0x6c0),
171};
172
173static struct intc_group groups_dma8[] __initdata = {
174 INTC_GROUP(DMAC, DMAC_DMTE0, DMAC_DMTE1, DMAC_DMTE2,
175 DMAC_DMTE3, DMAC_DMTE4, DMAC_DMTE5,
176 DMAC_DMTE6, DMAC_DMTE7, DMAC_DMAE),
177}; 140};
178 141
179static DECLARE_INTC_DESC(intc_desc_dma8, "sh7750_dma8", 142static DECLARE_INTC_DESC(intc_desc_dma8, "sh7750_dma8",
180 vectors_dma8, groups_dma8, 143 vectors_dma8, NULL,
181 NULL, prio_registers, NULL); 144 NULL, prio_registers, NULL);
182#endif 145#endif
183 146
diff --git a/arch/sh/kernel/cpu/sh4a/Makefile b/arch/sh/kernel/cpu/sh4a/Makefile
index 8e344ec5847e..1a92361feeb9 100644
--- a/arch/sh/kernel/cpu/sh4a/Makefile
+++ b/arch/sh/kernel/cpu/sh4a/Makefile
@@ -7,6 +7,7 @@ obj-$(CONFIG_CPU_SUBTYPE_SH7763) += setup-sh7763.o
7obj-$(CONFIG_CPU_SUBTYPE_SH7770) += setup-sh7770.o 7obj-$(CONFIG_CPU_SUBTYPE_SH7770) += setup-sh7770.o
8obj-$(CONFIG_CPU_SUBTYPE_SH7780) += setup-sh7780.o 8obj-$(CONFIG_CPU_SUBTYPE_SH7780) += setup-sh7780.o
9obj-$(CONFIG_CPU_SUBTYPE_SH7785) += setup-sh7785.o 9obj-$(CONFIG_CPU_SUBTYPE_SH7785) += setup-sh7785.o
10obj-$(CONFIG_CPU_SUBTYPE_SH7786) += setup-sh7786.o
10obj-$(CONFIG_CPU_SUBTYPE_SH7343) += setup-sh7343.o 11obj-$(CONFIG_CPU_SUBTYPE_SH7343) += setup-sh7343.o
11obj-$(CONFIG_CPU_SUBTYPE_SH7722) += setup-sh7722.o 12obj-$(CONFIG_CPU_SUBTYPE_SH7722) += setup-sh7722.o
12obj-$(CONFIG_CPU_SUBTYPE_SH7723) += setup-sh7723.o 13obj-$(CONFIG_CPU_SUBTYPE_SH7723) += setup-sh7723.o
@@ -21,6 +22,7 @@ clock-$(CONFIG_CPU_SUBTYPE_SH7763) := clock-sh7763.o
21clock-$(CONFIG_CPU_SUBTYPE_SH7770) := clock-sh7770.o 22clock-$(CONFIG_CPU_SUBTYPE_SH7770) := clock-sh7770.o
22clock-$(CONFIG_CPU_SUBTYPE_SH7780) := clock-sh7780.o 23clock-$(CONFIG_CPU_SUBTYPE_SH7780) := clock-sh7780.o
23clock-$(CONFIG_CPU_SUBTYPE_SH7785) := clock-sh7785.o 24clock-$(CONFIG_CPU_SUBTYPE_SH7785) := clock-sh7785.o
25clock-$(CONFIG_CPU_SUBTYPE_SH7786) := clock-sh7786.o
24clock-$(CONFIG_CPU_SUBTYPE_SH7343) := clock-sh7722.o 26clock-$(CONFIG_CPU_SUBTYPE_SH7343) := clock-sh7722.o
25clock-$(CONFIG_CPU_SUBTYPE_SH7722) := clock-sh7722.o 27clock-$(CONFIG_CPU_SUBTYPE_SH7722) := clock-sh7722.o
26clock-$(CONFIG_CPU_SUBTYPE_SH7723) := clock-sh7722.o 28clock-$(CONFIG_CPU_SUBTYPE_SH7723) := clock-sh7722.o
@@ -31,6 +33,7 @@ clock-$(CONFIG_CPU_SUBTYPE_SHX3) := clock-shx3.o
31pinmux-$(CONFIG_CPU_SUBTYPE_SH7722) := pinmux-sh7722.o 33pinmux-$(CONFIG_CPU_SUBTYPE_SH7722) := pinmux-sh7722.o
32pinmux-$(CONFIG_CPU_SUBTYPE_SH7723) := pinmux-sh7723.o 34pinmux-$(CONFIG_CPU_SUBTYPE_SH7723) := pinmux-sh7723.o
33pinmux-$(CONFIG_CPU_SUBTYPE_SH7785) := pinmux-sh7785.o 35pinmux-$(CONFIG_CPU_SUBTYPE_SH7785) := pinmux-sh7785.o
36pinmux-$(CONFIG_CPU_SUBTYPE_SH7786) := pinmux-sh7786.o
34 37
35obj-y += $(clock-y) 38obj-y += $(clock-y)
36obj-$(CONFIG_SMP) += $(smp-y) 39obj-$(CONFIG_SMP) += $(smp-y)
diff --git a/arch/sh/kernel/cpu/sh4a/clock-sh7786.c b/arch/sh/kernel/cpu/sh4a/clock-sh7786.c
new file mode 100644
index 000000000000..f84a9c134471
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh4a/clock-sh7786.c
@@ -0,0 +1,148 @@
1/*
2 * arch/sh/kernel/cpu/sh4a/clock-sh7786.c
3 *
4 * SH7786 support for the clock framework
5 *
6 * Copyright (C) 2008, 2009 Renesas Solutions Corp.
7 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
8 *
9 * Based on SH7785
10 * Copyright (C) 2007 Paul Mundt
11 *
12 * This file is subject to the terms and conditions of the GNU General Public
13 * License. See the file "COPYING" in the main directory of this archive
14 * for more details.
15 */
16#include <linux/init.h>
17#include <linux/kernel.h>
18#include <asm/clock.h>
19#include <asm/freq.h>
20#include <asm/io.h>
21
22static int ifc_divisors[] = { 1, 2, 4, 1 };
23static int sfc_divisors[] = { 1, 1, 4, 1 };
24static int bfc_divisors[] = { 1, 1, 1, 1, 1, 12, 16, 1,
25 24, 32, 1, 1, 1, 1, 1, 1 };
26static int mfc_divisors[] = { 1, 1, 4, 1 };
27static int pfc_divisors[] = { 1, 1, 1, 1, 1, 1, 16, 1,
28 24, 32, 1, 48, 1, 1, 1, 1 };
29
30static void master_clk_init(struct clk *clk)
31{
32 clk->rate *= pfc_divisors[ctrl_inl(FRQMR1) & 0x000f];
33}
34
35static struct clk_ops sh7786_master_clk_ops = {
36 .init = master_clk_init,
37};
38
39static void module_clk_recalc(struct clk *clk)
40{
41 int idx = (ctrl_inl(FRQMR1) & 0x000f);
42 clk->rate = clk->parent->rate / pfc_divisors[idx];
43}
44
45static struct clk_ops sh7786_module_clk_ops = {
46 .recalc = module_clk_recalc,
47};
48
49static void bus_clk_recalc(struct clk *clk)
50{
51 int idx = ((ctrl_inl(FRQMR1) >> 16) & 0x000f);
52 clk->rate = clk->parent->rate / bfc_divisors[idx];
53}
54
55static struct clk_ops sh7786_bus_clk_ops = {
56 .recalc = bus_clk_recalc,
57};
58
59static void cpu_clk_recalc(struct clk *clk)
60{
61 int idx = ((ctrl_inl(FRQMR1) >> 28) & 0x0003);
62 clk->rate = clk->parent->rate / ifc_divisors[idx];
63}
64
65static struct clk_ops sh7786_cpu_clk_ops = {
66 .recalc = cpu_clk_recalc,
67};
68
69static struct clk_ops *sh7786_clk_ops[] = {
70 &sh7786_master_clk_ops,
71 &sh7786_module_clk_ops,
72 &sh7786_bus_clk_ops,
73 &sh7786_cpu_clk_ops,
74};
75
76void __init arch_init_clk_ops(struct clk_ops **ops, int idx)
77{
78 if (idx < ARRAY_SIZE(sh7786_clk_ops))
79 *ops = sh7786_clk_ops[idx];
80}
81
82static void shyway_clk_recalc(struct clk *clk)
83{
84 int idx = ((ctrl_inl(FRQMR1) >> 20) & 0x0003);
85 clk->rate = clk->parent->rate / sfc_divisors[idx];
86}
87
88static struct clk_ops sh7786_shyway_clk_ops = {
89 .recalc = shyway_clk_recalc,
90};
91
92static struct clk sh7786_shyway_clk = {
93 .name = "shyway_clk",
94 .flags = CLK_ALWAYS_ENABLED,
95 .ops = &sh7786_shyway_clk_ops,
96};
97
98static void ddr_clk_recalc(struct clk *clk)
99{
100 int idx = ((ctrl_inl(FRQMR1) >> 12) & 0x0003);
101 clk->rate = clk->parent->rate / mfc_divisors[idx];
102}
103
104static struct clk_ops sh7786_ddr_clk_ops = {
105 .recalc = ddr_clk_recalc,
106};
107
108static struct clk sh7786_ddr_clk = {
109 .name = "ddr_clk",
110 .flags = CLK_ALWAYS_ENABLED,
111 .ops = &sh7786_ddr_clk_ops,
112};
113
114/*
115 * Additional SH7786-specific on-chip clocks that aren't already part of the
116 * clock framework
117 */
118static struct clk *sh7786_onchip_clocks[] = {
119 &sh7786_shyway_clk,
120 &sh7786_ddr_clk,
121};
122
123static int __init sh7786_clk_init(void)
124{
125 struct clk *clk = clk_get(NULL, "master_clk");
126 int i;
127
128 for (i = 0; i < ARRAY_SIZE(sh7786_onchip_clocks); i++) {
129 struct clk *clkp = sh7786_onchip_clocks[i];
130
131 clkp->parent = clk;
132 clk_register(clkp);
133 clk_enable(clkp);
134 }
135
136 /*
137 * Now that we have the rest of the clocks registered, we need to
138 * force the parent clock to propagate so that these clocks will
139 * automatically figure out their rate. We cheat by handing the
140 * parent clock its current rate and forcing child propagation.
141 */
142 clk_set_rate(clk, clk_get_rate(clk));
143
144 clk_put(clk);
145
146 return 0;
147}
148arch_initcall(sh7786_clk_init);
diff --git a/arch/sh/kernel/cpu/sh4a/pinmux-sh7786.c b/arch/sh/kernel/cpu/sh4a/pinmux-sh7786.c
new file mode 100644
index 000000000000..373b3447bfdf
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh4a/pinmux-sh7786.c
@@ -0,0 +1,950 @@
1/*
2 * SH7786 Pinmux
3 *
4 * Copyright (C) 2008, 2009 Renesas Solutions Corp.
5 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
6 *
7 * Based on SH7785 pinmux
8 *
9 * Copyright (C) 2008 Magnus Damm
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
13 * for more details.
14 */
15
16#include <linux/init.h>
17#include <linux/kernel.h>
18#include <linux/gpio.h>
19#include <cpu/sh7786.h>
20
21enum {
22 PINMUX_RESERVED = 0,
23
24 PINMUX_DATA_BEGIN,
25 PA7_DATA, PA6_DATA, PA5_DATA, PA4_DATA,
26 PA3_DATA, PA2_DATA, PA1_DATA, PA0_DATA,
27 PB7_DATA, PB6_DATA, PB5_DATA, PB4_DATA,
28 PB3_DATA, PB2_DATA, PB1_DATA, PB0_DATA,
29 PC7_DATA, PC6_DATA, PC5_DATA, PC4_DATA,
30 PC3_DATA, PC2_DATA, PC1_DATA, PC0_DATA,
31 PD7_DATA, PD6_DATA, PD5_DATA, PD4_DATA,
32 PD3_DATA, PD2_DATA, PD1_DATA, PD0_DATA,
33 PE7_DATA, PE6_DATA,
34 PF7_DATA, PF6_DATA, PF5_DATA, PF4_DATA,
35 PF3_DATA, PF2_DATA, PF1_DATA, PF0_DATA,
36 PG7_DATA, PG6_DATA, PG5_DATA,
37 PH7_DATA, PH6_DATA, PH5_DATA, PH4_DATA,
38 PH3_DATA, PH2_DATA, PH1_DATA, PH0_DATA,
39 PJ7_DATA, PJ6_DATA, PJ5_DATA, PJ4_DATA,
40 PJ3_DATA, PJ2_DATA, PJ1_DATA,
41 PINMUX_DATA_END,
42
43 PINMUX_INPUT_BEGIN,
44 PA7_IN, PA6_IN, PA5_IN, PA4_IN,
45 PA3_IN, PA2_IN, PA1_IN, PA0_IN,
46 PB7_IN, PB6_IN, PB5_IN, PB4_IN,
47 PB3_IN, PB2_IN, PB1_IN, PB0_IN,
48 PC7_IN, PC6_IN, PC5_IN, PC4_IN,
49 PC3_IN, PC2_IN, PC1_IN, PC0_IN,
50 PD7_IN, PD6_IN, PD5_IN, PD4_IN,
51 PD3_IN, PD2_IN, PD1_IN, PD0_IN,
52 PE7_IN, PE6_IN,
53 PF7_IN, PF6_IN, PF5_IN, PF4_IN,
54 PF3_IN, PF2_IN, PF1_IN, PF0_IN,
55 PG7_IN, PG6_IN, PG5_IN,
56 PH7_IN, PH6_IN, PH5_IN, PH4_IN,
57 PH3_IN, PH2_IN, PH1_IN, PH0_IN,
58 PJ7_IN, PJ6_IN, PJ5_IN, PJ4_IN,
59 PJ3_IN, PJ2_IN, PJ1_IN,
60 PINMUX_INPUT_END,
61
62 PINMUX_INPUT_PULLUP_BEGIN,
63 PA7_IN_PU, PA6_IN_PU, PA5_IN_PU, PA4_IN_PU,
64 PA3_IN_PU, PA2_IN_PU, PA1_IN_PU, PA0_IN_PU,
65 PB7_IN_PU, PB6_IN_PU, PB5_IN_PU, PB4_IN_PU,
66 PB3_IN_PU, PB2_IN_PU, PB1_IN_PU, PB0_IN_PU,
67 PC7_IN_PU, PC6_IN_PU, PC5_IN_PU, PC4_IN_PU,
68 PC3_IN_PU, PC2_IN_PU, PC1_IN_PU, PC0_IN_PU,
69 PD7_IN_PU, PD6_IN_PU, PD5_IN_PU, PD4_IN_PU,
70 PD3_IN_PU, PD2_IN_PU, PD1_IN_PU, PD0_IN_PU,
71 PE7_IN_PU, PE6_IN_PU,
72 PF7_IN_PU, PF6_IN_PU, PF5_IN_PU, PF4_IN_PU,
73 PF3_IN_PU, PF2_IN_PU, PF1_IN_PU, PF0_IN_PU,
74 PG7_IN_PU, PG6_IN_PU, PG5_IN_PU,
75 PH7_IN_PU, PH6_IN_PU, PH5_IN_PU, PH4_IN_PU,
76 PH3_IN_PU, PH2_IN_PU, PH1_IN_PU, PH0_IN_PU,
77 PJ7_IN_PU, PJ6_IN_PU, PJ5_IN_PU, PJ4_IN_PU,
78 PJ3_IN_PU, PJ2_IN_PU, PJ1_IN_PU,
79 PINMUX_INPUT_PULLUP_END,
80
81 PINMUX_OUTPUT_BEGIN,
82 PA7_OUT, PA6_OUT, PA5_OUT, PA4_OUT,
83 PA3_OUT, PA2_OUT, PA1_OUT, PA0_OUT,
84 PB7_OUT, PB6_OUT, PB5_OUT, PB4_OUT,
85 PB3_OUT, PB2_OUT, PB1_OUT, PB0_OUT,
86 PC7_OUT, PC6_OUT, PC5_OUT, PC4_OUT,
87 PC3_OUT, PC2_OUT, PC1_OUT, PC0_OUT,
88 PD7_OUT, PD6_OUT, PD5_OUT, PD4_OUT,
89 PD3_OUT, PD2_OUT, PD1_OUT, PD0_OUT,
90 PE7_OUT, PE6_OUT,
91 PF7_OUT, PF6_OUT, PF5_OUT, PF4_OUT,
92 PF3_OUT, PF2_OUT, PF1_OUT, PF0_OUT,
93 PG7_OUT, PG6_OUT, PG5_OUT,
94 PH7_OUT, PH6_OUT, PH5_OUT, PH4_OUT,
95 PH3_OUT, PH2_OUT, PH1_OUT, PH0_OUT,
96 PJ7_OUT, PJ6_OUT, PJ5_OUT, PJ4_OUT,
97 PJ3_OUT, PJ2_OUT, PJ1_OUT,
98 PINMUX_OUTPUT_END,
99
100 PINMUX_FUNCTION_BEGIN,
101 PA7_FN, PA6_FN, PA5_FN, PA4_FN,
102 PA3_FN, PA2_FN, PA1_FN, PA0_FN,
103 PB7_FN, PB6_FN, PB5_FN, PB4_FN,
104 PB3_FN, PB2_FN, PB1_FN, PB0_FN,
105 PC7_FN, PC6_FN, PC5_FN, PC4_FN,
106 PC3_FN, PC2_FN, PC1_FN, PC0_FN,
107 PD7_FN, PD6_FN, PD5_FN, PD4_FN,
108 PD3_FN, PD2_FN, PD1_FN, PD0_FN,
109 PE7_FN, PE6_FN,
110 PF7_FN, PF6_FN, PF5_FN, PF4_FN,
111 PF3_FN, PF2_FN, PF1_FN, PF0_FN,
112 PG7_FN, PG6_FN, PG5_FN,
113 PH7_FN, PH6_FN, PH5_FN, PH4_FN,
114 PH3_FN, PH2_FN, PH1_FN, PH0_FN,
115 PJ7_FN, PJ6_FN, PJ5_FN, PJ4_FN,
116 PJ3_FN, PJ2_FN, PJ1_FN,
117 P1MSEL14_0, P1MSEL14_1,
118 P1MSEL13_0, P1MSEL13_1,
119 P1MSEL12_0, P1MSEL12_1,
120 P1MSEL11_0, P1MSEL11_1,
121 P1MSEL10_0, P1MSEL10_1,
122 P1MSEL9_0, P1MSEL9_1,
123 P1MSEL8_0, P1MSEL8_1,
124 P1MSEL7_0, P1MSEL7_1,
125 P1MSEL6_0, P1MSEL6_1,
126 P1MSEL5_0, P1MSEL5_1,
127 P1MSEL4_0, P1MSEL4_1,
128 P1MSEL3_0, P1MSEL3_1,
129 P1MSEL2_0, P1MSEL2_1,
130 P1MSEL1_0, P1MSEL1_1,
131 P1MSEL0_0, P1MSEL0_1,
132
133 P2MSEL15_0, P2MSEL15_1,
134 P2MSEL14_0, P2MSEL14_1,
135 P2MSEL13_0, P2MSEL13_1,
136 P2MSEL12_0, P2MSEL12_1,
137 P2MSEL11_0, P2MSEL11_1,
138 P2MSEL10_0, P2MSEL10_1,
139 P2MSEL9_0, P2MSEL9_1,
140 P2MSEL8_0, P2MSEL8_1,
141 P2MSEL7_0, P2MSEL7_1,
142 P2MSEL6_0, P2MSEL6_1,
143 P2MSEL5_0, P2MSEL5_1,
144 P2MSEL4_0, P2MSEL4_1,
145 P2MSEL3_0, P2MSEL3_1,
146 P2MSEL2_0, P2MSEL2_1,
147 P2MSEL1_0, P2MSEL1_1,
148 P2MSEL0_0, P2MSEL0_1,
149 PINMUX_FUNCTION_END,
150
151 PINMUX_MARK_BEGIN,
152 CDE_MARK,
153 ETH_MAGIC_MARK,
154 DISP_MARK,
155 ETH_LINK_MARK,
156 DR5_MARK,
157 ETH_TX_ER_MARK,
158 DR4_MARK,
159 ETH_TX_EN_MARK,
160 DR3_MARK,
161 ETH_TXD3_MARK,
162 DR2_MARK,
163 ETH_TXD2_MARK,
164 DR1_MARK,
165 ETH_TXD1_MARK,
166 DR0_MARK,
167 ETH_TXD0_MARK,
168
169 VSYNC_MARK,
170 HSPI_CLK_MARK,
171 ODDF_MARK,
172 HSPI_CS_MARK,
173 DG5_MARK,
174 ETH_MDIO_MARK,
175 DG4_MARK,
176 ETH_RX_CLK_MARK,
177 DG3_MARK,
178 ETH_MDC_MARK,
179 DG2_MARK,
180 ETH_COL_MARK,
181 DG1_MARK,
182 ETH_TX_CLK_MARK,
183 DG0_MARK,
184 ETH_CRS_MARK,
185
186 DCLKIN_MARK,
187 HSPI_RX_MARK,
188 HSYNC_MARK,
189 HSPI_TX_MARK,
190 DB5_MARK,
191 ETH_RXD3_MARK,
192 DB4_MARK,
193 ETH_RXD2_MARK,
194 DB3_MARK,
195 ETH_RXD1_MARK,
196 DB2_MARK,
197 ETH_RXD0_MARK,
198 DB1_MARK,
199 ETH_RX_DV_MARK,
200 DB0_MARK,
201 ETH_RX_ER_MARK,
202
203 DCLKOUT_MARK,
204 SCIF1_SLK_MARK,
205 SCIF1_RXD_MARK,
206 SCIF1_TXD_MARK,
207 DACK1_MARK,
208 BACK_MARK,
209 FALE_MARK,
210 DACK0_MARK,
211 FCLE_MARK,
212 DREQ1_MARK,
213 BREQ_MARK,
214 USB_OVC1_MARK,
215 DREQ0_MARK,
216 USB_OVC0_MARK,
217
218 USB_PENC1_MARK,
219 USB_PENC0_MARK,
220
221 HAC1_SDOUT_MARK,
222 SSI1_SDATA_MARK,
223 SDIF1CMD_MARK,
224 HAC1_SDIN_MARK,
225 SSI1_SCK_MARK,
226 SDIF1CD_MARK,
227 HAC1_SYNC_MARK,
228 SSI1_WS_MARK,
229 SDIF1WP_MARK,
230 HAC1_BITCLK_MARK,
231 SSI1_CLK_MARK,
232 SDIF1CLK_MARK,
233 HAC0_SDOUT_MARK,
234 SSI0_SDATA_MARK,
235 SDIF1D3_MARK,
236 HAC0_SDIN_MARK,
237 SSI0_SCK_MARK,
238 SDIF1D2_MARK,
239 HAC0_SYNC_MARK,
240 SSI0_WS_MARK,
241 SDIF1D1_MARK,
242 HAC0_BITCLK_MARK,
243 SSI0_CLK_MARK,
244 SDIF1D0_MARK,
245
246 SCIF3_SCK_MARK,
247 SSI2_SDATA_MARK,
248 SCIF3_RXD_MARK,
249 TCLK_MARK,
250 SSI2_SCK_MARK,
251 SCIF3_TXD_MARK,
252 HAC_RES_MARK,
253 SSI2_WS_MARK,
254
255 DACK3_MARK,
256 SDIF0CMD_MARK,
257 DACK2_MARK,
258 SDIF0CD_MARK,
259 DREQ3_MARK,
260 SDIF0WP_MARK,
261 SCIF0_CTS_MARK,
262 DREQ2_MARK,
263 SDIF0CLK_MARK,
264 SCIF0_RTS_MARK,
265 IRL7_MARK,
266 SDIF0D3_MARK,
267 SCIF0_SCK_MARK,
268 IRL6_MARK,
269 SDIF0D2_MARK,
270 SCIF0_RXD_MARK,
271 IRL5_MARK,
272 SDIF0D1_MARK,
273 SCIF0_TXD_MARK,
274 IRL4_MARK,
275 SDIF0D0_MARK,
276
277 SCIF5_SCK_MARK,
278 FRB_MARK,
279 SCIF5_RXD_MARK,
280 IOIS16_MARK,
281 SCIF5_TXD_MARK,
282 CE2B_MARK,
283 DRAK3_MARK,
284 CE2A_MARK,
285 SCIF4_SCK_MARK,
286 DRAK2_MARK,
287 SSI3_WS_MARK,
288 SCIF4_RXD_MARK,
289 DRAK1_MARK,
290 SSI3_SDATA_MARK,
291 FSTATUS_MARK,
292 SCIF4_TXD_MARK,
293 DRAK0_MARK,
294 SSI3_SCK_MARK,
295 FSE_MARK,
296 PINMUX_MARK_END,
297};
298
299static pinmux_enum_t pinmux_data[] = {
300
301 /* PA GPIO */
302 PINMUX_DATA(PA7_DATA, PA7_IN, PA7_OUT, PA7_IN_PU),
303 PINMUX_DATA(PA6_DATA, PA6_IN, PA6_OUT, PA6_IN_PU),
304 PINMUX_DATA(PA5_DATA, PA5_IN, PA5_OUT, PA5_IN_PU),
305 PINMUX_DATA(PA4_DATA, PA4_IN, PA4_OUT, PA4_IN_PU),
306 PINMUX_DATA(PA3_DATA, PA3_IN, PA3_OUT, PA3_IN_PU),
307 PINMUX_DATA(PA2_DATA, PA2_IN, PA2_OUT, PA2_IN_PU),
308 PINMUX_DATA(PA1_DATA, PA1_IN, PA1_OUT, PA1_IN_PU),
309 PINMUX_DATA(PA0_DATA, PA0_IN, PA0_OUT, PA0_IN_PU),
310
311 /* PB GPIO */
312 PINMUX_DATA(PB7_DATA, PB7_IN, PB7_OUT, PB7_IN_PU),
313 PINMUX_DATA(PB6_DATA, PB6_IN, PB6_OUT, PB6_IN_PU),
314 PINMUX_DATA(PB5_DATA, PB5_IN, PB5_OUT, PB5_IN_PU),
315 PINMUX_DATA(PB4_DATA, PB4_IN, PB4_OUT, PB4_IN_PU),
316 PINMUX_DATA(PB3_DATA, PB3_IN, PB3_OUT, PB3_IN_PU),
317 PINMUX_DATA(PB2_DATA, PB2_IN, PB2_OUT, PB2_IN_PU),
318 PINMUX_DATA(PB1_DATA, PB1_IN, PB1_OUT, PB1_IN_PU),
319 PINMUX_DATA(PB0_DATA, PB0_IN, PB0_OUT, PB0_IN_PU),
320
321 /* PC GPIO */
322 PINMUX_DATA(PC7_DATA, PC7_IN, PC7_OUT, PC7_IN_PU),
323 PINMUX_DATA(PC6_DATA, PC6_IN, PC6_OUT, PC6_IN_PU),
324 PINMUX_DATA(PC5_DATA, PC5_IN, PC5_OUT, PC5_IN_PU),
325 PINMUX_DATA(PC4_DATA, PC4_IN, PC4_OUT, PC4_IN_PU),
326 PINMUX_DATA(PC3_DATA, PC3_IN, PC3_OUT, PC3_IN_PU),
327 PINMUX_DATA(PC2_DATA, PC2_IN, PC2_OUT, PC2_IN_PU),
328 PINMUX_DATA(PC1_DATA, PC1_IN, PC1_OUT, PC1_IN_PU),
329 PINMUX_DATA(PC0_DATA, PC0_IN, PC0_OUT, PC0_IN_PU),
330
331 /* PD GPIO */
332 PINMUX_DATA(PD7_DATA, PD7_IN, PD7_OUT, PD7_IN_PU),
333 PINMUX_DATA(PD6_DATA, PD6_IN, PD6_OUT, PD6_IN_PU),
334 PINMUX_DATA(PD5_DATA, PD5_IN, PD5_OUT, PD5_IN_PU),
335 PINMUX_DATA(PD4_DATA, PD4_IN, PD4_OUT, PD4_IN_PU),
336 PINMUX_DATA(PD3_DATA, PD3_IN, PD3_OUT, PD3_IN_PU),
337 PINMUX_DATA(PD2_DATA, PD2_IN, PD2_OUT, PD2_IN_PU),
338 PINMUX_DATA(PD1_DATA, PD1_IN, PD1_OUT, PD1_IN_PU),
339 PINMUX_DATA(PD0_DATA, PD0_IN, PD0_OUT, PD0_IN_PU),
340
341 /* PE GPIO */
342 PINMUX_DATA(PE7_DATA, PE7_IN, PE7_OUT, PE7_IN_PU),
343 PINMUX_DATA(PE6_DATA, PE6_IN, PE6_OUT, PE6_IN_PU),
344
345 /* PF GPIO */
346 PINMUX_DATA(PF7_DATA, PF7_IN, PF7_OUT, PF7_IN_PU),
347 PINMUX_DATA(PF6_DATA, PF6_IN, PF6_OUT, PF6_IN_PU),
348 PINMUX_DATA(PF5_DATA, PF5_IN, PF5_OUT, PF5_IN_PU),
349 PINMUX_DATA(PF4_DATA, PF4_IN, PF4_OUT, PF4_IN_PU),
350 PINMUX_DATA(PF3_DATA, PF3_IN, PF3_OUT, PF3_IN_PU),
351 PINMUX_DATA(PF2_DATA, PF2_IN, PF2_OUT, PF2_IN_PU),
352 PINMUX_DATA(PF1_DATA, PF1_IN, PF1_OUT, PF1_IN_PU),
353 PINMUX_DATA(PF0_DATA, PF0_IN, PF0_OUT, PF0_IN_PU),
354
355 /* PG GPIO */
356 PINMUX_DATA(PG7_DATA, PG7_IN, PG7_OUT, PG7_IN_PU),
357 PINMUX_DATA(PG6_DATA, PG6_IN, PG6_OUT, PG6_IN_PU),
358 PINMUX_DATA(PG5_DATA, PG5_IN, PG5_OUT, PG5_IN_PU),
359
360 /* PH GPIO */
361 PINMUX_DATA(PH7_DATA, PH7_IN, PH7_OUT, PH7_IN_PU),
362 PINMUX_DATA(PH6_DATA, PH6_IN, PH6_OUT, PH6_IN_PU),
363 PINMUX_DATA(PH5_DATA, PH5_IN, PH5_OUT, PH5_IN_PU),
364 PINMUX_DATA(PH4_DATA, PH4_IN, PH4_OUT, PH4_IN_PU),
365 PINMUX_DATA(PH3_DATA, PH3_IN, PH3_OUT, PH3_IN_PU),
366 PINMUX_DATA(PH2_DATA, PH2_IN, PH2_OUT, PH2_IN_PU),
367 PINMUX_DATA(PH1_DATA, PH1_IN, PH1_OUT, PH1_IN_PU),
368 PINMUX_DATA(PH0_DATA, PH0_IN, PH0_OUT, PH0_IN_PU),
369
370 /* PJ GPIO */
371 PINMUX_DATA(PJ7_DATA, PJ7_IN, PJ7_OUT, PJ7_IN_PU),
372 PINMUX_DATA(PJ6_DATA, PJ6_IN, PJ6_OUT, PJ6_IN_PU),
373 PINMUX_DATA(PJ5_DATA, PJ5_IN, PJ5_OUT, PJ5_IN_PU),
374 PINMUX_DATA(PJ4_DATA, PJ4_IN, PJ4_OUT, PJ4_IN_PU),
375 PINMUX_DATA(PJ3_DATA, PJ3_IN, PJ3_OUT, PJ3_IN_PU),
376 PINMUX_DATA(PJ2_DATA, PJ2_IN, PJ2_OUT, PJ2_IN_PU),
377 PINMUX_DATA(PJ1_DATA, PJ1_IN, PJ1_OUT, PJ1_IN_PU),
378
379 /* PA FN */
380 PINMUX_MARK_BEGIN,
381 PINMUX_DATA(CDE_MARK, P1MSEL2_0, PA7_FN),
382 PINMUX_DATA(DISP_MARK, P1MSEL2_0, PA6_FN),
383 PINMUX_DATA(DR5_MARK, P1MSEL2_0, PA5_FN),
384 PINMUX_DATA(DR4_MARK, P1MSEL2_0, PA4_FN),
385 PINMUX_DATA(DR3_MARK, P1MSEL2_0, PA3_FN),
386 PINMUX_DATA(DR2_MARK, P1MSEL2_0, PA2_FN),
387 PINMUX_DATA(DR1_MARK, P1MSEL2_0, PA1_FN),
388 PINMUX_DATA(DR0_MARK, P1MSEL2_0, PA0_FN),
389 PINMUX_DATA(ETH_MAGIC_MARK, P1MSEL2_1, PA7_FN),
390 PINMUX_DATA(ETH_LINK_MARK, P1MSEL2_1, PA6_FN),
391 PINMUX_DATA(ETH_TX_ER_MARK, P1MSEL2_1, PA5_FN),
392 PINMUX_DATA(ETH_TX_EN_MARK, P1MSEL2_1, PA4_FN),
393 PINMUX_DATA(ETH_TXD3_MARK, P1MSEL2_1, PA3_FN),
394 PINMUX_DATA(ETH_TXD2_MARK, P1MSEL2_1, PA2_FN),
395 PINMUX_DATA(ETH_TXD1_MARK, P1MSEL2_1, PA1_FN),
396 PINMUX_DATA(ETH_TXD0_MARK, P1MSEL2_1, PA0_FN),
397
398 /* PB FN */
399 PINMUX_DATA(VSYNC_MARK, P1MSEL3_0, PB7_FN),
400 PINMUX_DATA(ODDF_MARK, P1MSEL3_0, PB6_FN),
401 PINMUX_DATA(DG5_MARK, P1MSEL2_0, PB5_FN),
402 PINMUX_DATA(DG4_MARK, P1MSEL2_0, PB4_FN),
403 PINMUX_DATA(DG3_MARK, P1MSEL2_0, PB3_FN),
404 PINMUX_DATA(DG2_MARK, P1MSEL2_0, PB2_FN),
405 PINMUX_DATA(DG1_MARK, P1MSEL2_0, PB1_FN),
406 PINMUX_DATA(DG0_MARK, P1MSEL2_0, PB0_FN),
407 PINMUX_DATA(HSPI_CLK_MARK, P1MSEL3_1, PB7_FN),
408 PINMUX_DATA(HSPI_CS_MARK, P1MSEL3_1, PB6_FN),
409 PINMUX_DATA(ETH_MDIO_MARK, P1MSEL2_1, PB5_FN),
410 PINMUX_DATA(ETH_RX_CLK_MARK, P1MSEL2_1, PB4_FN),
411 PINMUX_DATA(ETH_MDC_MARK, P1MSEL2_1, PB3_FN),
412 PINMUX_DATA(ETH_COL_MARK, P1MSEL2_1, PB2_FN),
413 PINMUX_DATA(ETH_TX_CLK_MARK, P1MSEL2_1, PB1_FN),
414 PINMUX_DATA(ETH_CRS_MARK, P1MSEL2_1, PB0_FN),
415
416 /* PC FN */
417 PINMUX_DATA(DCLKIN_MARK, P1MSEL3_0, PC7_FN),
418 PINMUX_DATA(HSYNC_MARK, P1MSEL3_0, PC6_FN),
419 PINMUX_DATA(DB5_MARK, P1MSEL2_0, PC5_FN),
420 PINMUX_DATA(DB4_MARK, P1MSEL2_0, PC4_FN),
421 PINMUX_DATA(DB3_MARK, P1MSEL2_0, PC3_FN),
422 PINMUX_DATA(DB2_MARK, P1MSEL2_0, PC2_FN),
423 PINMUX_DATA(DB1_MARK, P1MSEL2_0, PC1_FN),
424 PINMUX_DATA(DB0_MARK, P1MSEL2_0, PC0_FN),
425
426 PINMUX_DATA(HSPI_RX_MARK, P1MSEL3_1, PC7_FN),
427 PINMUX_DATA(HSPI_TX_MARK, P1MSEL3_1, PC6_FN),
428 PINMUX_DATA(ETH_RXD3_MARK, P1MSEL2_1, PC5_FN),
429 PINMUX_DATA(ETH_RXD2_MARK, P1MSEL2_1, PC4_FN),
430 PINMUX_DATA(ETH_RXD1_MARK, P1MSEL2_1, PC3_FN),
431 PINMUX_DATA(ETH_RXD0_MARK, P1MSEL2_1, PC2_FN),
432 PINMUX_DATA(ETH_RX_DV_MARK, P1MSEL2_1, PC1_FN),
433 PINMUX_DATA(ETH_RX_ER_MARK, P1MSEL2_1, PC0_FN),
434
435 /* PD FN */
436 PINMUX_DATA(DCLKOUT_MARK, PD7_FN),
437 PINMUX_DATA(SCIF1_SLK_MARK, PD6_FN),
438 PINMUX_DATA(SCIF1_RXD_MARK, PD5_FN),
439 PINMUX_DATA(SCIF1_TXD_MARK, PD4_FN),
440 PINMUX_DATA(DACK1_MARK, P1MSEL13_1, P1MSEL12_0, PD3_FN),
441 PINMUX_DATA(BACK_MARK, P1MSEL13_0, P1MSEL12_1, PD3_FN),
442 PINMUX_DATA(FALE_MARK, P1MSEL13_0, P1MSEL12_0, PD3_FN),
443 PINMUX_DATA(DACK0_MARK, P1MSEL14_1, PD2_FN),
444 PINMUX_DATA(FCLE_MARK, P1MSEL14_0, PD2_FN),
445 PINMUX_DATA(DREQ1_MARK, P1MSEL10_0, P1MSEL9_1, PD1_FN),
446 PINMUX_DATA(BREQ_MARK, P1MSEL10_1, P1MSEL9_0, PD1_FN),
447 PINMUX_DATA(USB_OVC1_MARK, P1MSEL10_0, P1MSEL9_0, PD1_FN),
448 PINMUX_DATA(DREQ0_MARK, P1MSEL11_1, PD0_FN),
449 PINMUX_DATA(USB_OVC0_MARK, P1MSEL11_0, PD0_FN),
450
451 /* PE FN */
452 PINMUX_DATA(USB_PENC1_MARK, PE7_FN),
453 PINMUX_DATA(USB_PENC0_MARK, PE6_FN),
454
455 /* PF FN */
456 PINMUX_DATA(HAC1_SDOUT_MARK, P2MSEL15_0, P2MSEL14_0, PF7_FN),
457 PINMUX_DATA(HAC1_SDIN_MARK, P2MSEL15_0, P2MSEL14_0, PF6_FN),
458 PINMUX_DATA(HAC1_SYNC_MARK, P2MSEL15_0, P2MSEL14_0, PF5_FN),
459 PINMUX_DATA(HAC1_BITCLK_MARK, P2MSEL15_0, P2MSEL14_0, PF4_FN),
460 PINMUX_DATA(HAC0_SDOUT_MARK, P2MSEL13_0, P2MSEL12_0, PF3_FN),
461 PINMUX_DATA(HAC0_SDIN_MARK, P2MSEL13_0, P2MSEL12_0, PF2_FN),
462 PINMUX_DATA(HAC0_SYNC_MARK, P2MSEL13_0, P2MSEL12_0, PF1_FN),
463 PINMUX_DATA(HAC0_BITCLK_MARK, P2MSEL13_0, P2MSEL12_0, PF0_FN),
464 PINMUX_DATA(SSI1_SDATA_MARK, P2MSEL15_0, P2MSEL14_1, PF7_FN),
465 PINMUX_DATA(SSI1_SCK_MARK, P2MSEL15_0, P2MSEL14_1, PF6_FN),
466 PINMUX_DATA(SSI1_WS_MARK, P2MSEL15_0, P2MSEL14_1, PF5_FN),
467 PINMUX_DATA(SSI1_CLK_MARK, P2MSEL15_0, P2MSEL14_1, PF4_FN),
468 PINMUX_DATA(SSI0_SDATA_MARK, P2MSEL13_0, P2MSEL12_1, PF3_FN),
469 PINMUX_DATA(SSI0_SCK_MARK, P2MSEL13_0, P2MSEL12_1, PF2_FN),
470 PINMUX_DATA(SSI0_WS_MARK, P2MSEL13_0, P2MSEL12_1, PF1_FN),
471 PINMUX_DATA(SSI0_CLK_MARK, P2MSEL13_0, P2MSEL12_1, PF0_FN),
472 PINMUX_DATA(SDIF1CMD_MARK, P2MSEL15_1, P2MSEL14_0, PF7_FN),
473 PINMUX_DATA(SDIF1CD_MARK, P2MSEL15_1, P2MSEL14_0, PF6_FN),
474 PINMUX_DATA(SDIF1WP_MARK, P2MSEL15_1, P2MSEL14_0, PF5_FN),
475 PINMUX_DATA(SDIF1CLK_MARK, P2MSEL15_1, P2MSEL14_0, PF4_FN),
476 PINMUX_DATA(SDIF1D3_MARK, P2MSEL13_1, P2MSEL12_0, PF3_FN),
477 PINMUX_DATA(SDIF1D2_MARK, P2MSEL13_1, P2MSEL12_0, PF2_FN),
478 PINMUX_DATA(SDIF1D1_MARK, P2MSEL13_1, P2MSEL12_0, PF1_FN),
479 PINMUX_DATA(SDIF1D0_MARK, P2MSEL13_1, P2MSEL12_0, PF0_FN),
480
481 /* PG FN */
482 PINMUX_DATA(SCIF3_SCK_MARK, P1MSEL8_0, PG7_FN),
483 PINMUX_DATA(SSI2_SDATA_MARK, P1MSEL8_1, PG7_FN),
484 PINMUX_DATA(SCIF3_RXD_MARK, P1MSEL7_0, P1MSEL6_0, PG6_FN),
485 PINMUX_DATA(SSI2_SCK_MARK, P1MSEL7_1, P1MSEL6_0, PG6_FN),
486 PINMUX_DATA(TCLK_MARK, P1MSEL7_0, P1MSEL6_1, PG6_FN),
487 PINMUX_DATA(SCIF3_TXD_MARK, P1MSEL5_0, P1MSEL4_0, PG5_FN),
488 PINMUX_DATA(SSI2_WS_MARK, P1MSEL5_1, P1MSEL4_0, PG5_FN),
489 PINMUX_DATA(HAC_RES_MARK, P1MSEL5_0, P1MSEL4_1, PG5_FN),
490
491 /* PH FN */
492 PINMUX_DATA(DACK3_MARK, P2MSEL4_0, PH7_FN),
493 PINMUX_DATA(SDIF0CMD_MARK, P2MSEL4_1, PH7_FN),
494 PINMUX_DATA(DACK2_MARK, P2MSEL4_0, PH6_FN),
495 PINMUX_DATA(SDIF0CD_MARK, P2MSEL4_1, PH6_FN),
496 PINMUX_DATA(DREQ3_MARK, P2MSEL4_0, PH5_FN),
497 PINMUX_DATA(SDIF0WP_MARK, P2MSEL4_1, PH5_FN),
498 PINMUX_DATA(DREQ2_MARK, P2MSEL3_0, P2MSEL2_1, PH4_FN),
499 PINMUX_DATA(SDIF0CLK_MARK, P2MSEL3_1, P2MSEL2_0, PH4_FN),
500 PINMUX_DATA(SCIF0_CTS_MARK, P2MSEL3_0, P2MSEL2_0, PH4_FN),
501 PINMUX_DATA(SDIF0D3_MARK, P2MSEL1_1, P2MSEL0_0, PH3_FN),
502 PINMUX_DATA(SCIF0_RTS_MARK, P2MSEL1_0, P2MSEL0_0, PH3_FN),
503 PINMUX_DATA(IRL7_MARK, P2MSEL1_0, P2MSEL0_1, PH3_FN),
504 PINMUX_DATA(SDIF0D2_MARK, P2MSEL1_1, P2MSEL0_0, PH2_FN),
505 PINMUX_DATA(SCIF0_SCK_MARK, P2MSEL1_0, P2MSEL0_0, PH2_FN),
506 PINMUX_DATA(IRL6_MARK, P2MSEL1_0, P2MSEL0_1, PH2_FN),
507 PINMUX_DATA(SDIF0D1_MARK, P2MSEL1_1, P2MSEL0_0, PH1_FN),
508 PINMUX_DATA(SCIF0_RXD_MARK, P2MSEL1_0, P2MSEL0_0, PH1_FN),
509 PINMUX_DATA(IRL5_MARK, P2MSEL1_0, P2MSEL0_1, PH1_FN),
510 PINMUX_DATA(SDIF0D0_MARK, P2MSEL1_1, P2MSEL0_0, PH0_FN),
511 PINMUX_DATA(SCIF0_TXD_MARK, P2MSEL1_0, P2MSEL0_0, PH0_FN),
512 PINMUX_DATA(IRL4_MARK, P2MSEL1_0, P2MSEL0_1, PH0_FN),
513
514 /* PJ FN */
515 PINMUX_DATA(SCIF5_SCK_MARK, P2MSEL11_1, PJ7_FN),
516 PINMUX_DATA(FRB_MARK, P2MSEL11_0, PJ7_FN),
517 PINMUX_DATA(SCIF5_RXD_MARK, P2MSEL10_0, PJ6_FN),
518 PINMUX_DATA(IOIS16_MARK, P2MSEL10_1, PJ6_FN),
519 PINMUX_DATA(SCIF5_TXD_MARK, P2MSEL10_0, PJ5_FN),
520 PINMUX_DATA(CE2B_MARK, P2MSEL10_1, PJ5_FN),
521 PINMUX_DATA(DRAK3_MARK, P2MSEL7_0, PJ4_FN),
522 PINMUX_DATA(CE2A_MARK, P2MSEL7_1, PJ4_FN),
523 PINMUX_DATA(SCIF4_SCK_MARK, P2MSEL9_0, P2MSEL8_0, PJ3_FN),
524 PINMUX_DATA(DRAK2_MARK, P2MSEL9_0, P2MSEL8_1, PJ3_FN),
525 PINMUX_DATA(SSI3_WS_MARK, P2MSEL9_1, P2MSEL8_0, PJ3_FN),
526 PINMUX_DATA(SCIF4_RXD_MARK, P2MSEL6_1, P2MSEL5_0, PJ2_FN),
527 PINMUX_DATA(DRAK1_MARK, P2MSEL6_0, P2MSEL5_1, PJ2_FN),
528 PINMUX_DATA(FSTATUS_MARK, P2MSEL6_0, P2MSEL5_0, PJ2_FN),
529 PINMUX_DATA(SSI3_SDATA_MARK, P2MSEL6_1, P2MSEL5_1, PJ2_FN),
530 PINMUX_DATA(SCIF4_TXD_MARK, P2MSEL6_1, P2MSEL5_0, PJ1_FN),
531 PINMUX_DATA(DRAK0_MARK, P2MSEL6_0, P2MSEL5_1, PJ1_FN),
532 PINMUX_DATA(FSE_MARK, P2MSEL6_0, P2MSEL5_0, PJ1_FN),
533 PINMUX_DATA(SSI3_SCK_MARK, P2MSEL6_1, P2MSEL5_1, PJ1_FN),
534};
535
536static struct pinmux_gpio pinmux_gpios[] = {
537 /* PA */
538 PINMUX_GPIO(GPIO_PA7, PA7_DATA),
539 PINMUX_GPIO(GPIO_PA6, PA6_DATA),
540 PINMUX_GPIO(GPIO_PA5, PA5_DATA),
541 PINMUX_GPIO(GPIO_PA4, PA4_DATA),
542 PINMUX_GPIO(GPIO_PA3, PA3_DATA),
543 PINMUX_GPIO(GPIO_PA2, PA2_DATA),
544 PINMUX_GPIO(GPIO_PA1, PA1_DATA),
545 PINMUX_GPIO(GPIO_PA0, PA0_DATA),
546
547 /* PB */
548 PINMUX_GPIO(GPIO_PB7, PB7_DATA),
549 PINMUX_GPIO(GPIO_PB6, PB6_DATA),
550 PINMUX_GPIO(GPIO_PB5, PB5_DATA),
551 PINMUX_GPIO(GPIO_PB4, PB4_DATA),
552 PINMUX_GPIO(GPIO_PB3, PB3_DATA),
553 PINMUX_GPIO(GPIO_PB2, PB2_DATA),
554 PINMUX_GPIO(GPIO_PB1, PB1_DATA),
555 PINMUX_GPIO(GPIO_PB0, PB0_DATA),
556
557 /* PC */
558 PINMUX_GPIO(GPIO_PC7, PC7_DATA),
559 PINMUX_GPIO(GPIO_PC6, PC6_DATA),
560 PINMUX_GPIO(GPIO_PC5, PC5_DATA),
561 PINMUX_GPIO(GPIO_PC4, PC4_DATA),
562 PINMUX_GPIO(GPIO_PC3, PC3_DATA),
563 PINMUX_GPIO(GPIO_PC2, PC2_DATA),
564 PINMUX_GPIO(GPIO_PC1, PC1_DATA),
565 PINMUX_GPIO(GPIO_PC0, PC0_DATA),
566
567 /* PD */
568 PINMUX_GPIO(GPIO_PD7, PD7_DATA),
569 PINMUX_GPIO(GPIO_PD6, PD6_DATA),
570 PINMUX_GPIO(GPIO_PD5, PD5_DATA),
571 PINMUX_GPIO(GPIO_PD4, PD4_DATA),
572 PINMUX_GPIO(GPIO_PD3, PD3_DATA),
573 PINMUX_GPIO(GPIO_PD2, PD2_DATA),
574 PINMUX_GPIO(GPIO_PD1, PD1_DATA),
575 PINMUX_GPIO(GPIO_PD0, PD0_DATA),
576
577 /* PE */
578 PINMUX_GPIO(GPIO_PE5, PE7_DATA),
579 PINMUX_GPIO(GPIO_PE4, PE6_DATA),
580
581 /* PF */
582 PINMUX_GPIO(GPIO_PF7, PF7_DATA),
583 PINMUX_GPIO(GPIO_PF6, PF6_DATA),
584 PINMUX_GPIO(GPIO_PF5, PF5_DATA),
585 PINMUX_GPIO(GPIO_PF4, PF4_DATA),
586 PINMUX_GPIO(GPIO_PF3, PF3_DATA),
587 PINMUX_GPIO(GPIO_PF2, PF2_DATA),
588 PINMUX_GPIO(GPIO_PF1, PF1_DATA),
589 PINMUX_GPIO(GPIO_PF0, PF0_DATA),
590
591 /* PG */
592 PINMUX_GPIO(GPIO_PG7, PG7_DATA),
593 PINMUX_GPIO(GPIO_PG6, PG6_DATA),
594 PINMUX_GPIO(GPIO_PG5, PG5_DATA),
595
596 /* PH */
597 PINMUX_GPIO(GPIO_PH7, PH7_DATA),
598 PINMUX_GPIO(GPIO_PH6, PH6_DATA),
599 PINMUX_GPIO(GPIO_PH5, PH5_DATA),
600 PINMUX_GPIO(GPIO_PH4, PH4_DATA),
601 PINMUX_GPIO(GPIO_PH3, PH3_DATA),
602 PINMUX_GPIO(GPIO_PH2, PH2_DATA),
603 PINMUX_GPIO(GPIO_PH1, PH1_DATA),
604 PINMUX_GPIO(GPIO_PH0, PH0_DATA),
605
606 /* PJ */
607 PINMUX_GPIO(GPIO_PJ7, PJ7_DATA),
608 PINMUX_GPIO(GPIO_PJ6, PJ6_DATA),
609 PINMUX_GPIO(GPIO_PJ5, PJ5_DATA),
610 PINMUX_GPIO(GPIO_PJ4, PJ4_DATA),
611 PINMUX_GPIO(GPIO_PJ3, PJ3_DATA),
612 PINMUX_GPIO(GPIO_PJ2, PJ2_DATA),
613 PINMUX_GPIO(GPIO_PJ1, PJ1_DATA),
614
615 /* FN */
616 PINMUX_GPIO(GPIO_FN_CDE, CDE_MARK),
617 PINMUX_GPIO(GPIO_FN_ETH_MAGIC, ETH_MAGIC_MARK),
618 PINMUX_GPIO(GPIO_FN_DISP, DISP_MARK),
619 PINMUX_GPIO(GPIO_FN_ETH_LINK, ETH_LINK_MARK),
620 PINMUX_GPIO(GPIO_FN_DR5, DR5_MARK),
621 PINMUX_GPIO(GPIO_FN_ETH_TX_ER, ETH_TX_ER_MARK),
622 PINMUX_GPIO(GPIO_FN_DR4, DR4_MARK),
623 PINMUX_GPIO(GPIO_FN_ETH_TX_EN, ETH_TX_EN_MARK),
624 PINMUX_GPIO(GPIO_FN_DR3, DR3_MARK),
625 PINMUX_GPIO(GPIO_FN_ETH_TXD3, ETH_TXD3_MARK),
626 PINMUX_GPIO(GPIO_FN_DR2, DR2_MARK),
627 PINMUX_GPIO(GPIO_FN_ETH_TXD2, ETH_TXD2_MARK),
628 PINMUX_GPIO(GPIO_FN_DR1, DR1_MARK),
629 PINMUX_GPIO(GPIO_FN_ETH_TXD1, ETH_TXD1_MARK),
630 PINMUX_GPIO(GPIO_FN_DR0, DR0_MARK),
631 PINMUX_GPIO(GPIO_FN_ETH_TXD0, ETH_TXD0_MARK),
632 PINMUX_GPIO(GPIO_FN_VSYNC, VSYNC_MARK),
633 PINMUX_GPIO(GPIO_FN_HSPI_CLK, HSPI_CLK_MARK),
634 PINMUX_GPIO(GPIO_FN_ODDF, ODDF_MARK),
635 PINMUX_GPIO(GPIO_FN_HSPI_CS, HSPI_CS_MARK),
636 PINMUX_GPIO(GPIO_FN_DG5, DG5_MARK),
637 PINMUX_GPIO(GPIO_FN_ETH_MDIO, ETH_MDIO_MARK),
638 PINMUX_GPIO(GPIO_FN_DG4, DG4_MARK),
639 PINMUX_GPIO(GPIO_FN_ETH_RX_CLK, ETH_RX_CLK_MARK),
640 PINMUX_GPIO(GPIO_FN_DG3, DG3_MARK),
641 PINMUX_GPIO(GPIO_FN_ETH_MDC, ETH_MDC_MARK),
642 PINMUX_GPIO(GPIO_FN_DG2, DG2_MARK),
643 PINMUX_GPIO(GPIO_FN_ETH_COL, ETH_COL_MARK),
644 PINMUX_GPIO(GPIO_FN_DG1, DG1_MARK),
645 PINMUX_GPIO(GPIO_FN_ETH_TX_CLK, ETH_TX_CLK_MARK),
646 PINMUX_GPIO(GPIO_FN_DG0, DG0_MARK),
647 PINMUX_GPIO(GPIO_FN_ETH_CRS, ETH_CRS_MARK),
648 PINMUX_GPIO(GPIO_FN_DCLKIN, DCLKIN_MARK),
649 PINMUX_GPIO(GPIO_FN_HSPI_RX, HSPI_RX_MARK),
650 PINMUX_GPIO(GPIO_FN_HSYNC, HSYNC_MARK),
651 PINMUX_GPIO(GPIO_FN_HSPI_TX, HSPI_TX_MARK),
652 PINMUX_GPIO(GPIO_FN_DB5, DB5_MARK),
653 PINMUX_GPIO(GPIO_FN_ETH_RXD3, ETH_RXD3_MARK),
654 PINMUX_GPIO(GPIO_FN_DB4, DB4_MARK),
655 PINMUX_GPIO(GPIO_FN_ETH_RXD2, ETH_RXD2_MARK),
656 PINMUX_GPIO(GPIO_FN_DB3, DB3_MARK),
657 PINMUX_GPIO(GPIO_FN_ETH_RXD1, ETH_RXD1_MARK),
658 PINMUX_GPIO(GPIO_FN_DB2, DB2_MARK),
659 PINMUX_GPIO(GPIO_FN_ETH_RXD0, ETH_RXD0_MARK),
660 PINMUX_GPIO(GPIO_FN_DB1, DB1_MARK),
661 PINMUX_GPIO(GPIO_FN_ETH_RX_DV, ETH_RX_DV_MARK),
662 PINMUX_GPIO(GPIO_FN_DB0, DB0_MARK),
663 PINMUX_GPIO(GPIO_FN_ETH_RX_ER, ETH_RX_ER_MARK),
664 PINMUX_GPIO(GPIO_FN_DCLKOUT, DCLKOUT_MARK),
665 PINMUX_GPIO(GPIO_FN_SCIF1_SLK, SCIF1_SLK_MARK),
666 PINMUX_GPIO(GPIO_FN_SCIF1_RXD, SCIF1_RXD_MARK),
667 PINMUX_GPIO(GPIO_FN_SCIF1_TXD, SCIF1_TXD_MARK),
668 PINMUX_GPIO(GPIO_FN_DACK1, DACK1_MARK),
669 PINMUX_GPIO(GPIO_FN_BACK, BACK_MARK),
670 PINMUX_GPIO(GPIO_FN_FALE, FALE_MARK),
671 PINMUX_GPIO(GPIO_FN_DACK0, DACK0_MARK),
672 PINMUX_GPIO(GPIO_FN_FCLE, FCLE_MARK),
673 PINMUX_GPIO(GPIO_FN_DREQ1, DREQ1_MARK),
674 PINMUX_GPIO(GPIO_FN_BREQ, BREQ_MARK),
675 PINMUX_GPIO(GPIO_FN_USB_OVC1, USB_OVC1_MARK),
676 PINMUX_GPIO(GPIO_FN_DREQ0, DREQ0_MARK),
677 PINMUX_GPIO(GPIO_FN_USB_OVC0, USB_OVC0_MARK),
678 PINMUX_GPIO(GPIO_FN_USB_PENC1, USB_PENC1_MARK),
679 PINMUX_GPIO(GPIO_FN_USB_PENC0, USB_PENC0_MARK),
680 PINMUX_GPIO(GPIO_FN_HAC1_SDOUT, HAC1_SDOUT_MARK),
681 PINMUX_GPIO(GPIO_FN_SSI1_SDATA, SSI1_SDATA_MARK),
682 PINMUX_GPIO(GPIO_FN_SDIF1CMD, SDIF1CMD_MARK),
683 PINMUX_GPIO(GPIO_FN_HAC1_SDIN, HAC1_SDIN_MARK),
684 PINMUX_GPIO(GPIO_FN_SSI1_SCK, SSI1_SCK_MARK),
685 PINMUX_GPIO(GPIO_FN_SDIF1CD, SDIF1CD_MARK),
686 PINMUX_GPIO(GPIO_FN_HAC1_SYNC, HAC1_SYNC_MARK),
687 PINMUX_GPIO(GPIO_FN_SSI1_WS, SSI1_WS_MARK),
688 PINMUX_GPIO(GPIO_FN_SDIF1WP, SDIF1WP_MARK),
689 PINMUX_GPIO(GPIO_FN_HAC1_BITCLK, HAC1_BITCLK_MARK),
690 PINMUX_GPIO(GPIO_FN_SSI1_CLK, SSI1_CLK_MARK),
691 PINMUX_GPIO(GPIO_FN_SDIF1CLK, SDIF1CLK_MARK),
692 PINMUX_GPIO(GPIO_FN_HAC0_SDOUT, HAC0_SDOUT_MARK),
693 PINMUX_GPIO(GPIO_FN_SSI0_SDATA, SSI0_SDATA_MARK),
694 PINMUX_GPIO(GPIO_FN_SDIF1D3, SDIF1D3_MARK),
695 PINMUX_GPIO(GPIO_FN_HAC0_SDIN, HAC0_SDIN_MARK),
696 PINMUX_GPIO(GPIO_FN_SSI0_SCK, SSI0_SCK_MARK),
697 PINMUX_GPIO(GPIO_FN_SDIF1D2, SDIF1D2_MARK),
698 PINMUX_GPIO(GPIO_FN_HAC0_SYNC, HAC0_SYNC_MARK),
699 PINMUX_GPIO(GPIO_FN_SSI0_WS, SSI0_WS_MARK),
700 PINMUX_GPIO(GPIO_FN_SDIF1D1, SDIF1D1_MARK),
701 PINMUX_GPIO(GPIO_FN_HAC0_BITCLK, HAC0_BITCLK_MARK),
702 PINMUX_GPIO(GPIO_FN_SSI0_CLK, SSI0_CLK_MARK),
703 PINMUX_GPIO(GPIO_FN_SDIF1D0, SDIF1D0_MARK),
704 PINMUX_GPIO(GPIO_FN_SCIF3_SCK, SCIF3_SCK_MARK),
705 PINMUX_GPIO(GPIO_FN_SSI2_SDATA, SSI2_SDATA_MARK),
706 PINMUX_GPIO(GPIO_FN_SCIF3_RXD, SCIF3_RXD_MARK),
707 PINMUX_GPIO(GPIO_FN_TCLK, TCLK_MARK),
708 PINMUX_GPIO(GPIO_FN_SSI2_SCK, SSI2_SCK_MARK),
709 PINMUX_GPIO(GPIO_FN_SCIF3_TXD, SCIF3_TXD_MARK),
710 PINMUX_GPIO(GPIO_FN_HAC_RES, HAC_RES_MARK),
711 PINMUX_GPIO(GPIO_FN_SSI2_WS, SSI2_WS_MARK),
712 PINMUX_GPIO(GPIO_FN_DACK3, DACK3_MARK),
713 PINMUX_GPIO(GPIO_FN_SDIF0CMD, SDIF0CMD_MARK),
714 PINMUX_GPIO(GPIO_FN_DACK2, DACK2_MARK),
715 PINMUX_GPIO(GPIO_FN_SDIF0CD, SDIF0CD_MARK),
716 PINMUX_GPIO(GPIO_FN_DREQ3, DREQ3_MARK),
717 PINMUX_GPIO(GPIO_FN_SDIF0WP, SDIF0WP_MARK),
718 PINMUX_GPIO(GPIO_FN_SCIF0_CTS, SCIF0_CTS_MARK),
719 PINMUX_GPIO(GPIO_FN_DREQ2, DREQ2_MARK),
720 PINMUX_GPIO(GPIO_FN_SDIF0CLK, SDIF0CLK_MARK),
721 PINMUX_GPIO(GPIO_FN_SCIF0_RTS, SCIF0_RTS_MARK),
722 PINMUX_GPIO(GPIO_FN_IRL7, IRL7_MARK),
723 PINMUX_GPIO(GPIO_FN_SDIF0D3, SDIF0D3_MARK),
724 PINMUX_GPIO(GPIO_FN_SCIF0_SCK, SCIF0_SCK_MARK),
725 PINMUX_GPIO(GPIO_FN_IRL6, IRL6_MARK),
726 PINMUX_GPIO(GPIO_FN_SDIF0D2, SDIF0D2_MARK),
727 PINMUX_GPIO(GPIO_FN_SCIF0_RXD, SCIF0_RXD_MARK),
728 PINMUX_GPIO(GPIO_FN_IRL5, IRL5_MARK),
729 PINMUX_GPIO(GPIO_FN_SDIF0D1, SDIF0D1_MARK),
730 PINMUX_GPIO(GPIO_FN_SCIF0_TXD, SCIF0_TXD_MARK),
731 PINMUX_GPIO(GPIO_FN_IRL4, IRL4_MARK),
732 PINMUX_GPIO(GPIO_FN_SDIF0D0, SDIF0D0_MARK),
733 PINMUX_GPIO(GPIO_FN_SCIF5_SCK, SCIF5_SCK_MARK),
734 PINMUX_GPIO(GPIO_FN_FRB, FRB_MARK),
735 PINMUX_GPIO(GPIO_FN_SCIF5_RXD, SCIF5_RXD_MARK),
736 PINMUX_GPIO(GPIO_FN_IOIS16, IOIS16_MARK),
737 PINMUX_GPIO(GPIO_FN_SCIF5_TXD, SCIF5_TXD_MARK),
738 PINMUX_GPIO(GPIO_FN_CE2B, CE2B_MARK),
739 PINMUX_GPIO(GPIO_FN_DRAK3, DRAK3_MARK),
740 PINMUX_GPIO(GPIO_FN_CE2A, CE2A_MARK),
741 PINMUX_GPIO(GPIO_FN_SCIF4_SCK, SCIF4_SCK_MARK),
742 PINMUX_GPIO(GPIO_FN_DRAK2, DRAK2_MARK),
743 PINMUX_GPIO(GPIO_FN_SSI3_WS, SSI3_WS_MARK),
744 PINMUX_GPIO(GPIO_FN_SCIF4_RXD, SCIF4_RXD_MARK),
745 PINMUX_GPIO(GPIO_FN_DRAK1, DRAK1_MARK),
746 PINMUX_GPIO(GPIO_FN_SSI3_SDATA, SSI3_SDATA_MARK),
747 PINMUX_GPIO(GPIO_FN_FSTATUS, FSTATUS_MARK),
748 PINMUX_GPIO(GPIO_FN_SCIF4_TXD, SCIF4_TXD_MARK),
749 PINMUX_GPIO(GPIO_FN_DRAK0, DRAK0_MARK),
750 PINMUX_GPIO(GPIO_FN_SSI3_SCK, SSI3_SCK_MARK),
751 PINMUX_GPIO(GPIO_FN_FSE, FSE_MARK),
752};
753
754static struct pinmux_cfg_reg pinmux_config_regs[] = {
755 { PINMUX_CFG_REG("PACR", 0xffcc0000, 16, 2) {
756 PA7_FN, PA7_OUT, PA7_IN, PA7_IN_PU,
757 PA6_FN, PA6_OUT, PA6_IN, PA6_IN_PU,
758 PA5_FN, PA5_OUT, PA5_IN, PA5_IN_PU,
759 PA4_FN, PA4_OUT, PA4_IN, PA4_IN_PU,
760 PA3_FN, PA3_OUT, PA3_IN, PA3_IN_PU,
761 PA2_FN, PA2_OUT, PA2_IN, PA2_IN_PU,
762 PA1_FN, PA1_OUT, PA1_IN, PA1_IN_PU,
763 PA0_FN, PA0_OUT, PA0_IN, PA0_IN_PU }
764 },
765 { PINMUX_CFG_REG("PBCR", 0xffcc0002, 16, 2) {
766 PB7_FN, PB7_OUT, PB7_IN, PB7_IN_PU,
767 PB6_FN, PB6_OUT, PB6_IN, PB6_IN_PU,
768 PB5_FN, PB5_OUT, PB5_IN, PB5_IN_PU,
769 PB4_FN, PB4_OUT, PB4_IN, PB4_IN_PU,
770 PB3_FN, PB3_OUT, PB3_IN, PB3_IN_PU,
771 PB2_FN, PB2_OUT, PB2_IN, PB2_IN_PU,
772 PB1_FN, PB1_OUT, PB1_IN, PB1_IN_PU,
773 PB0_FN, PB0_OUT, PB0_IN, PB0_IN_PU }
774 },
775 { PINMUX_CFG_REG("PCCR", 0xffcc0004, 16, 2) {
776 PC7_FN, PC7_OUT, PC7_IN, PC7_IN_PU,
777 PC6_FN, PC6_OUT, PC6_IN, PC6_IN_PU,
778 PC5_FN, PC5_OUT, PC5_IN, PC5_IN_PU,
779 PC4_FN, PC4_OUT, PC4_IN, PC4_IN_PU,
780 PC3_FN, PC3_OUT, PC3_IN, PC3_IN_PU,
781 PC2_FN, PC2_OUT, PC2_IN, PC2_IN_PU,
782 PC1_FN, PC1_OUT, PC1_IN, PC1_IN_PU,
783 PC0_FN, PC0_OUT, PC0_IN, PC0_IN_PU }
784 },
785 { PINMUX_CFG_REG("PDCR", 0xffcc0006, 16, 2) {
786 PD7_FN, PD7_OUT, PD7_IN, PD7_IN_PU,
787 PD6_FN, PD6_OUT, PD6_IN, PD6_IN_PU,
788 PD5_FN, PD5_OUT, PD5_IN, PD5_IN_PU,
789 PD4_FN, PD4_OUT, PD4_IN, PD4_IN_PU,
790 PD3_FN, PD3_OUT, PD3_IN, PD3_IN_PU,
791 PD2_FN, PD2_OUT, PD2_IN, PD2_IN_PU,
792 PD1_FN, PD1_OUT, PD1_IN, PD1_IN_PU,
793 PD0_FN, PD0_OUT, PD0_IN, PD0_IN_PU }
794 },
795 { PINMUX_CFG_REG("PECR", 0xffcc0008, 16, 2) {
796 PE7_FN, PE7_OUT, PE7_IN, PE7_IN_PU,
797 PE6_FN, PE6_OUT, PE6_IN, PE6_IN_PU,
798 0, 0, 0, 0,
799 0, 0, 0, 0,
800 0, 0, 0, 0,
801 0, 0, 0, 0,
802 0, 0, 0, 0,
803 0, 0, 0, 0, }
804 },
805 { PINMUX_CFG_REG("PFCR", 0xffcc000a, 16, 2) {
806 PF7_FN, PF7_OUT, PF7_IN, PF7_IN_PU,
807 PF6_FN, PF6_OUT, PF6_IN, PF6_IN_PU,
808 PF5_FN, PF5_OUT, PF5_IN, PF5_IN_PU,
809 PF4_FN, PF4_OUT, PF4_IN, PF4_IN_PU,
810 PF3_FN, PF3_OUT, PF3_IN, PF3_IN_PU,
811 PF2_FN, PF2_OUT, PF2_IN, PF2_IN_PU,
812 PF1_FN, PF1_OUT, PF1_IN, PF1_IN_PU,
813 PF0_FN, PF0_OUT, PF0_IN, PF0_IN_PU }
814 },
815 { PINMUX_CFG_REG("PGCR", 0xffcc000c, 16, 2) {
816 PG7_FN, PG7_OUT, PG7_IN, PG7_IN_PU,
817 PG6_FN, PG6_OUT, PG6_IN, PG6_IN_PU,
818 PG5_FN, PG5_OUT, PG5_IN, PG5_IN_PU,
819 0, 0, 0, 0,
820 0, 0, 0, 0,
821 0, 0, 0, 0,
822 0, 0, 0, 0,
823 0, 0, 0, 0, }
824 },
825 { PINMUX_CFG_REG("PHCR", 0xffcc000e, 16, 2) {
826 PH7_FN, PH7_OUT, PH7_IN, PH7_IN_PU,
827 PH6_FN, PH6_OUT, PH6_IN, PH6_IN_PU,
828 PH5_FN, PH5_OUT, PH5_IN, PH5_IN_PU,
829 PH4_FN, PH4_OUT, PH4_IN, PH4_IN_PU,
830 PH3_FN, PH3_OUT, PH3_IN, PH3_IN_PU,
831 PH2_FN, PH2_OUT, PH2_IN, PH2_IN_PU,
832 PH1_FN, PH1_OUT, PH1_IN, PH1_IN_PU,
833 PH0_FN, PH0_OUT, PH0_IN, PH0_IN_PU }
834 },
835 { PINMUX_CFG_REG("PJCR", 0xffcc0010, 16, 2) {
836 PJ7_FN, PJ7_OUT, PJ7_IN, PJ7_IN_PU,
837 PJ6_FN, PJ6_OUT, PJ6_IN, PJ6_IN_PU,
838 PJ5_FN, PJ5_OUT, PJ5_IN, PJ5_IN_PU,
839 PJ4_FN, PJ4_OUT, PJ4_IN, PJ4_IN_PU,
840 PJ3_FN, PJ3_OUT, PJ3_IN, PJ3_IN_PU,
841 PJ2_FN, PJ2_OUT, PJ2_IN, PJ2_IN_PU,
842 PJ1_FN, PJ1_OUT, PJ1_IN, PJ1_IN_PU,
843 0, 0, 0, 0, }
844 },
845 { PINMUX_CFG_REG("P1MSELR", 0xffcc0080, 16, 1) {
846 0, 0,
847 P1MSEL14_0, P1MSEL14_1,
848 P1MSEL13_0, P1MSEL13_1,
849 P1MSEL12_0, P1MSEL12_1,
850 P1MSEL11_0, P1MSEL11_1,
851 P1MSEL10_0, P1MSEL10_1,
852 P1MSEL9_0, P1MSEL9_1,
853 P1MSEL8_0, P1MSEL8_1,
854 P1MSEL7_0, P1MSEL7_1,
855 P1MSEL6_0, P1MSEL6_1,
856 P1MSEL5_0, P1MSEL5_1,
857 P1MSEL4_0, P1MSEL4_1,
858 P1MSEL3_0, P1MSEL3_1,
859 P1MSEL2_0, P1MSEL2_1,
860 P1MSEL1_0, P1MSEL1_1,
861 P1MSEL0_0, P1MSEL0_1 }
862 },
863 { PINMUX_CFG_REG("P2MSELR", 0xffcc0082, 16, 1) {
864 P2MSEL15_0, P2MSEL15_1,
865 P2MSEL14_0, P2MSEL14_1,
866 P2MSEL13_0, P2MSEL13_1,
867 P2MSEL12_0, P2MSEL12_1,
868 P2MSEL11_0, P2MSEL11_1,
869 P2MSEL10_0, P2MSEL10_1,
870 P2MSEL9_0, P2MSEL9_1,
871 P2MSEL8_0, P2MSEL8_1,
872 P2MSEL7_0, P2MSEL7_1,
873 P2MSEL6_0, P2MSEL6_1,
874 P2MSEL5_0, P2MSEL5_1,
875 P2MSEL4_0, P2MSEL4_1,
876 P2MSEL3_0, P2MSEL3_1,
877 P2MSEL2_0, P2MSEL2_1,
878 P2MSEL1_0, P2MSEL1_1,
879 P2MSEL0_0, P2MSEL0_1 }
880 },
881 {}
882};
883
884static struct pinmux_data_reg pinmux_data_regs[] = {
885 { PINMUX_DATA_REG("PADR", 0xffcc0020, 8) {
886 PA7_DATA, PA6_DATA, PA5_DATA, PA4_DATA,
887 PA3_DATA, PA2_DATA, PA1_DATA, PA0_DATA }
888 },
889 { PINMUX_DATA_REG("PBDR", 0xffcc0022, 8) {
890 PB7_DATA, PB6_DATA, PB5_DATA, PB4_DATA,
891 PB3_DATA, PB2_DATA, PB1_DATA, PB0_DATA }
892 },
893 { PINMUX_DATA_REG("PCDR", 0xffcc0024, 8) {
894 PC7_DATA, PC6_DATA, PC5_DATA, PC4_DATA,
895 PC3_DATA, PC2_DATA, PC1_DATA, PC0_DATA }
896 },
897 { PINMUX_DATA_REG("PDDR", 0xffcc0026, 8) {
898 PD7_DATA, PD6_DATA, PD5_DATA, PD4_DATA,
899 PD3_DATA, PD2_DATA, PD1_DATA, PD0_DATA }
900 },
901 { PINMUX_DATA_REG("PEDR", 0xffcc0028, 8) {
902 PE7_DATA, PE6_DATA,
903 0, 0, 0, 0, 0, 0 }
904 },
905 { PINMUX_DATA_REG("PFDR", 0xffcc002a, 8) {
906 PF7_DATA, PF6_DATA, PF5_DATA, PF4_DATA,
907 PF3_DATA, PF2_DATA, PF1_DATA, PF0_DATA }
908 },
909 { PINMUX_DATA_REG("PGDR", 0xffcc002c, 8) {
910 PG7_DATA, PG6_DATA, PG5_DATA, 0,
911 0, 0, 0, 0 }
912 },
913 { PINMUX_DATA_REG("PHDR", 0xffcc002e, 8) {
914 PH7_DATA, PH6_DATA, PH5_DATA, PH4_DATA,
915 PH3_DATA, PH2_DATA, PH1_DATA, PH0_DATA }
916 },
917 { PINMUX_DATA_REG("PJDR", 0xffcc0030, 8) {
918 PJ7_DATA, PJ6_DATA, PJ5_DATA, PJ4_DATA,
919 PJ3_DATA, PJ2_DATA, PJ1_DATA, 0 }
920 },
921 { },
922};
923
924static struct pinmux_info sh7786_pinmux_info = {
925 .name = "sh7786_pfc",
926 .reserved_id = PINMUX_RESERVED,
927 .data = { PINMUX_DATA_BEGIN, PINMUX_DATA_END },
928 .input = { PINMUX_INPUT_BEGIN, PINMUX_INPUT_END },
929 .input_pu = { PINMUX_INPUT_PULLUP_BEGIN, PINMUX_INPUT_PULLUP_END },
930 .output = { PINMUX_OUTPUT_BEGIN, PINMUX_OUTPUT_END },
931 .mark = { PINMUX_MARK_BEGIN, PINMUX_MARK_END },
932 .function = { PINMUX_FUNCTION_BEGIN, PINMUX_FUNCTION_END },
933
934 .first_gpio = GPIO_PA7,
935 .last_gpio = GPIO_FN_FSE,
936
937 .gpios = pinmux_gpios,
938 .cfg_regs = pinmux_config_regs,
939 .data_regs = pinmux_data_regs,
940
941 .gpio_data = pinmux_data,
942 .gpio_data_size = ARRAY_SIZE(pinmux_data),
943};
944
945static int __init plat_pinmux_setup(void)
946{
947 return register_pinmux(&sh7786_pinmux_info);
948}
949
950arch_initcall(plat_pinmux_setup);
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7343.c b/arch/sh/kernel/cpu/sh4a/setup-sh7343.c
index 4ff4dc64520c..c1549382c87c 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7343.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7343.c
@@ -12,6 +12,7 @@
12#include <linux/serial.h> 12#include <linux/serial.h>
13#include <linux/serial_sci.h> 13#include <linux/serial_sci.h>
14#include <linux/uio_driver.h> 14#include <linux/uio_driver.h>
15#include <linux/sh_cmt.h>
15#include <asm/clock.h> 16#include <asm/clock.h>
16 17
17static struct resource iic0_resources[] = { 18static struct resource iic0_resources[] = {
@@ -140,6 +141,38 @@ static struct platform_device jpu_device = {
140 .num_resources = ARRAY_SIZE(jpu_resources), 141 .num_resources = ARRAY_SIZE(jpu_resources),
141}; 142};
142 143
144static struct sh_cmt_config cmt_platform_data = {
145 .name = "CMT",
146 .channel_offset = 0x60,
147 .timer_bit = 5,
148 .clk = "cmt0",
149 .clockevent_rating = 125,
150 .clocksource_rating = 200,
151};
152
153static struct resource cmt_resources[] = {
154 [0] = {
155 .name = "CMT",
156 .start = 0x044a0060,
157 .end = 0x044a006b,
158 .flags = IORESOURCE_MEM,
159 },
160 [1] = {
161 .start = 104,
162 .flags = IORESOURCE_IRQ,
163 },
164};
165
166static struct platform_device cmt_device = {
167 .name = "sh_cmt",
168 .id = 0,
169 .dev = {
170 .platform_data = &cmt_platform_data,
171 },
172 .resource = cmt_resources,
173 .num_resources = ARRAY_SIZE(cmt_resources),
174};
175
143static struct plat_sci_port sci_platform_data[] = { 176static struct plat_sci_port sci_platform_data[] = {
144 { 177 {
145 .mapbase = 0xffe00000, 178 .mapbase = 0xffe00000,
@@ -175,6 +208,7 @@ static struct platform_device sci_device = {
175}; 208};
176 209
177static struct platform_device *sh7343_devices[] __initdata = { 210static struct platform_device *sh7343_devices[] __initdata = {
211 &cmt_device,
178 &iic0_device, 212 &iic0_device,
179 &iic1_device, 213 &iic1_device,
180 &sci_device, 214 &sci_device,
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7366.c b/arch/sh/kernel/cpu/sh4a/setup-sh7366.c
index 839ae97a7fd2..93ecf8ed5c6c 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7366.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7366.c
@@ -14,6 +14,7 @@
14#include <linux/serial.h> 14#include <linux/serial.h>
15#include <linux/serial_sci.h> 15#include <linux/serial_sci.h>
16#include <linux/uio_driver.h> 16#include <linux/uio_driver.h>
17#include <linux/sh_cmt.h>
17#include <asm/clock.h> 18#include <asm/clock.h>
18 19
19static struct resource iic_resources[] = { 20static struct resource iic_resources[] = {
@@ -147,6 +148,38 @@ static struct platform_device veu1_device = {
147 .num_resources = ARRAY_SIZE(veu1_resources), 148 .num_resources = ARRAY_SIZE(veu1_resources),
148}; 149};
149 150
151static struct sh_cmt_config cmt_platform_data = {
152 .name = "CMT",
153 .channel_offset = 0x60,
154 .timer_bit = 5,
155 .clk = "cmt0",
156 .clockevent_rating = 125,
157 .clocksource_rating = 200,
158};
159
160static struct resource cmt_resources[] = {
161 [0] = {
162 .name = "CMT",
163 .start = 0x044a0060,
164 .end = 0x044a006b,
165 .flags = IORESOURCE_MEM,
166 },
167 [1] = {
168 .start = 104,
169 .flags = IORESOURCE_IRQ,
170 },
171};
172
173static struct platform_device cmt_device = {
174 .name = "sh_cmt",
175 .id = 0,
176 .dev = {
177 .platform_data = &cmt_platform_data,
178 },
179 .resource = cmt_resources,
180 .num_resources = ARRAY_SIZE(cmt_resources),
181};
182
150static struct plat_sci_port sci_platform_data[] = { 183static struct plat_sci_port sci_platform_data[] = {
151 { 184 {
152 .mapbase = 0xffe00000, 185 .mapbase = 0xffe00000,
@@ -167,6 +200,7 @@ static struct platform_device sci_device = {
167}; 200};
168 201
169static struct platform_device *sh7366_devices[] __initdata = { 202static struct platform_device *sh7366_devices[] __initdata = {
203 &cmt_device,
170 &iic_device, 204 &iic_device,
171 &sci_device, 205 &sci_device,
172 &usb_host_device, 206 &usb_host_device,
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7722.c b/arch/sh/kernel/cpu/sh4a/setup-sh7722.c
index 5146afc156e0..0e5d204bc792 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7722.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7722.c
@@ -13,6 +13,7 @@
13#include <linux/serial_sci.h> 13#include <linux/serial_sci.h>
14#include <linux/mm.h> 14#include <linux/mm.h>
15#include <linux/uio_driver.h> 15#include <linux/uio_driver.h>
16#include <linux/sh_cmt.h>
16#include <asm/clock.h> 17#include <asm/clock.h>
17#include <asm/mmzone.h> 18#include <asm/mmzone.h>
18 19
@@ -176,6 +177,38 @@ static struct platform_device jpu_device = {
176 .num_resources = ARRAY_SIZE(jpu_resources), 177 .num_resources = ARRAY_SIZE(jpu_resources),
177}; 178};
178 179
180static struct sh_cmt_config cmt_platform_data = {
181 .name = "CMT",
182 .channel_offset = 0x60,
183 .timer_bit = 5,
184 .clk = "cmt0",
185 .clockevent_rating = 125,
186 .clocksource_rating = 200,
187};
188
189static struct resource cmt_resources[] = {
190 [0] = {
191 .name = "CMT",
192 .start = 0x044a0060,
193 .end = 0x044a006b,
194 .flags = IORESOURCE_MEM,
195 },
196 [1] = {
197 .start = 104,
198 .flags = IORESOURCE_IRQ,
199 },
200};
201
202static struct platform_device cmt_device = {
203 .name = "sh_cmt",
204 .id = 0,
205 .dev = {
206 .platform_data = &cmt_platform_data,
207 },
208 .resource = cmt_resources,
209 .num_resources = ARRAY_SIZE(cmt_resources),
210};
211
179static struct plat_sci_port sci_platform_data[] = { 212static struct plat_sci_port sci_platform_data[] = {
180 { 213 {
181 .mapbase = 0xffe00000, 214 .mapbase = 0xffe00000,
@@ -209,6 +242,7 @@ static struct platform_device sci_device = {
209}; 242};
210 243
211static struct platform_device *sh7722_devices[] __initdata = { 244static struct platform_device *sh7722_devices[] __initdata = {
245 &cmt_device,
212 &rtc_device, 246 &rtc_device,
213 &usbf_device, 247 &usbf_device,
214 &iic_device, 248 &iic_device,
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7723.c b/arch/sh/kernel/cpu/sh4a/setup-sh7723.c
index 849770d780ae..5338dacbcfba 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7723.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7723.c
@@ -13,6 +13,7 @@
13#include <linux/mm.h> 13#include <linux/mm.h>
14#include <linux/serial_sci.h> 14#include <linux/serial_sci.h>
15#include <linux/uio_driver.h> 15#include <linux/uio_driver.h>
16#include <linux/sh_cmt.h>
16#include <asm/clock.h> 17#include <asm/clock.h>
17#include <asm/mmzone.h> 18#include <asm/mmzone.h>
18 19
@@ -100,6 +101,38 @@ static struct platform_device veu1_device = {
100 .num_resources = ARRAY_SIZE(veu1_resources), 101 .num_resources = ARRAY_SIZE(veu1_resources),
101}; 102};
102 103
104static struct sh_cmt_config cmt_platform_data = {
105 .name = "CMT",
106 .channel_offset = 0x60,
107 .timer_bit = 5,
108 .clk = "cmt0",
109 .clockevent_rating = 125,
110 .clocksource_rating = 200,
111};
112
113static struct resource cmt_resources[] = {
114 [0] = {
115 .name = "CMT",
116 .start = 0x044a0060,
117 .end = 0x044a006b,
118 .flags = IORESOURCE_MEM,
119 },
120 [1] = {
121 .start = 104,
122 .flags = IORESOURCE_IRQ,
123 },
124};
125
126static struct platform_device cmt_device = {
127 .name = "sh_cmt",
128 .id = 0,
129 .dev = {
130 .platform_data = &cmt_platform_data,
131 },
132 .resource = cmt_resources,
133 .num_resources = ARRAY_SIZE(cmt_resources),
134};
135
103static struct plat_sci_port sci_platform_data[] = { 136static struct plat_sci_port sci_platform_data[] = {
104 { 137 {
105 .mapbase = 0xffe00000, 138 .mapbase = 0xffe00000,
@@ -221,6 +254,7 @@ static struct platform_device iic_device = {
221}; 254};
222 255
223static struct platform_device *sh7723_devices[] __initdata = { 256static struct platform_device *sh7723_devices[] __initdata = {
257 &cmt_device,
224 &sci_device, 258 &sci_device,
225 &rtc_device, 259 &rtc_device,
226 &iic_device, 260 &iic_device,
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7763.c b/arch/sh/kernel/cpu/sh4a/setup-sh7763.c
index 3c5b629887a8..bdf0f61ae1ed 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7763.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7763.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2006 Paul Mundt 4 * Copyright (C) 2006 Paul Mundt
5 * Copyright (C) 2007 Yoshihiro Shimoda 5 * Copyright (C) 2007 Yoshihiro Shimoda
6 * Copyright (C) 2008 Nobuhiro Iwamatsu 6 * Copyright (C) 2008, 2009 Nobuhiro Iwamatsu
7 * 7 *
8 * This file is subject to the terms and conditions of the GNU General Public 8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive 9 * License. See the file "COPYING" in the main directory of this archive
@@ -22,18 +22,8 @@ static struct resource rtc_resources[] = {
22 .flags = IORESOURCE_IO, 22 .flags = IORESOURCE_IO,
23 }, 23 },
24 [1] = { 24 [1] = {
25 /* Period IRQ */ 25 /* Shared Period/Carry/Alarm IRQ */
26 .start = 21, 26 .start = 20,
27 .flags = IORESOURCE_IRQ,
28 },
29 [2] = {
30 /* Carry IRQ */
31 .start = 22,
32 .flags = IORESOURCE_IRQ,
33 },
34 [3] = {
35 /* Alarm IRQ */
36 .start = 20,
37 .flags = IORESOURCE_IRQ, 27 .flags = IORESOURCE_IRQ,
38 }, 28 },
39}; 29};
@@ -50,17 +40,17 @@ static struct plat_sci_port sci_platform_data[] = {
50 .mapbase = 0xffe00000, 40 .mapbase = 0xffe00000,
51 .flags = UPF_BOOT_AUTOCONF, 41 .flags = UPF_BOOT_AUTOCONF,
52 .type = PORT_SCIF, 42 .type = PORT_SCIF,
53 .irqs = { 40, 41, 43, 42 }, 43 .irqs = { 40, 40, 40, 40 },
54 }, { 44 }, {
55 .mapbase = 0xffe08000, 45 .mapbase = 0xffe08000,
56 .flags = UPF_BOOT_AUTOCONF, 46 .flags = UPF_BOOT_AUTOCONF,
57 .type = PORT_SCIF, 47 .type = PORT_SCIF,
58 .irqs = { 76, 77, 79, 78 }, 48 .irqs = { 76, 76, 76, 76 },
59 }, { 49 }, {
60 .mapbase = 0xffe10000, 50 .mapbase = 0xffe10000,
61 .flags = UPF_BOOT_AUTOCONF, 51 .flags = UPF_BOOT_AUTOCONF,
62 .type = PORT_SCIF, 52 .type = PORT_SCIF,
63 .irqs = { 104, 105, 107, 106 }, 53 .irqs = { 104, 104, 104, 104 },
64 }, { 54 }, {
65 .flags = 0, 55 .flags = 0,
66 } 56 }
@@ -148,93 +138,65 @@ enum {
148 IRL_HHLL, IRL_HHLH, IRL_HHHL, 138 IRL_HHLL, IRL_HHLH, IRL_HHHL,
149 139
150 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7, 140 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7,
151 RTC_ATI, RTC_PRI, RTC_CUI, 141 RTC, WDT, TMU0, TMU1, TMU2, TMU2_TICPI,
152 WDT, TMU0, TMU1, TMU2, TMU2_TICPI, 142 HUDI, LCDC, DMAC, SCIF0, IIC0, IIC1, CMT, GETHER, HAC,
153 HUDI, LCDC, 143 PCISERR, PCIINTA, PCIINTB, PCIINTC, PCIINTD, PCIC5,
154 DMAC0_DMINT0, DMAC0_DMINT1, DMAC0_DMINT2, DMAC0_DMINT3, DMAC0_DMAE, 144 STIF0, STIF1, SCIF1, SIOF0, SIOF1, SIOF2,
155 SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI, 145 USBH, USBF, TPU, PCC, MMCIF, SIM,
156 DMAC0_DMINT4, DMAC0_DMINT5,
157 IIC0, IIC1,
158 CMT,
159 GEINT0, GEINT1, GEINT2,
160 HAC,
161 PCISERR, PCIINTA, PCIINTB, PCIINTC, PCIINTD,
162 PCIERR, PCIPWD3, PCIPWD2, PCIPWD1, PCIPWD0,
163 STIF0, STIF1,
164 SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI,
165 SIOF0, SIOF1, SIOF2,
166 USBH, USBFI0, USBFI1,
167 TPU, PCC,
168 MMCIF_FSTAT, MMCIF_TRAN, MMCIF_ERR, MMCIF_FRDY,
169 SIM_ERI, SIM_RXI, SIM_TXI, SIM_TEND,
170 TMU3, TMU4, TMU5, ADC, SSI0, SSI1, SSI2, SSI3, 146 TMU3, TMU4, TMU5, ADC, SSI0, SSI1, SSI2, SSI3,
171 SCIF2_ERI, SCIF2_RXI, SCIF2_BRI, SCIF2_TXI, 147 SCIF2, GPIO,
172 GPIO_CH0, GPIO_CH1, GPIO_CH2, GPIO_CH3,
173 148
174 /* interrupt groups */ 149 /* interrupt groups */
175 150
176 TMU012, TMU345, RTC, DMAC, SCIF0, GETHER, PCIC5, 151 TMU012, TMU345,
177 SCIF1, USBF, MMCIF, SIM, SCIF2, GPIO,
178}; 152};
179 153
180static struct intc_vect vectors[] __initdata = { 154static struct intc_vect vectors[] __initdata = {
181 INTC_VECT(RTC_ATI, 0x480), INTC_VECT(RTC_PRI, 0x4a0), 155 INTC_VECT(RTC, 0x480), INTC_VECT(RTC, 0x4a0),
182 INTC_VECT(RTC_CUI, 0x4c0), 156 INTC_VECT(RTC, 0x4c0),
183 INTC_VECT(WDT, 0x560), INTC_VECT(TMU0, 0x580), 157 INTC_VECT(WDT, 0x560), INTC_VECT(TMU0, 0x580),
184 INTC_VECT(TMU1, 0x5a0), INTC_VECT(TMU2, 0x5c0), 158 INTC_VECT(TMU1, 0x5a0), INTC_VECT(TMU2, 0x5c0),
185 INTC_VECT(TMU2_TICPI, 0x5e0), INTC_VECT(HUDI, 0x600), 159 INTC_VECT(TMU2_TICPI, 0x5e0), INTC_VECT(HUDI, 0x600),
186 INTC_VECT(LCDC, 0x620), 160 INTC_VECT(LCDC, 0x620),
187 INTC_VECT(DMAC0_DMINT0, 0x640), INTC_VECT(DMAC0_DMINT1, 0x660), 161 INTC_VECT(DMAC, 0x640), INTC_VECT(DMAC, 0x660),
188 INTC_VECT(DMAC0_DMINT2, 0x680), INTC_VECT(DMAC0_DMINT3, 0x6a0), 162 INTC_VECT(DMAC, 0x680), INTC_VECT(DMAC, 0x6a0),
189 INTC_VECT(DMAC0_DMAE, 0x6c0), 163 INTC_VECT(DMAC, 0x6c0),
190 INTC_VECT(SCIF0_ERI, 0x700), INTC_VECT(SCIF0_RXI, 0x720), 164 INTC_VECT(SCIF0, 0x700), INTC_VECT(SCIF0, 0x720),
191 INTC_VECT(SCIF0_BRI, 0x740), INTC_VECT(SCIF0_TXI, 0x760), 165 INTC_VECT(SCIF0, 0x740), INTC_VECT(SCIF0, 0x760),
192 INTC_VECT(DMAC0_DMINT4, 0x780), INTC_VECT(DMAC0_DMINT5, 0x7a0), 166 INTC_VECT(DMAC, 0x780), INTC_VECT(DMAC, 0x7a0),
193 INTC_VECT(IIC0, 0x8A0), INTC_VECT(IIC1, 0x8C0), 167 INTC_VECT(IIC0, 0x8A0), INTC_VECT(IIC1, 0x8C0),
194 INTC_VECT(CMT, 0x900), INTC_VECT(GEINT0, 0x920), 168 INTC_VECT(CMT, 0x900), INTC_VECT(GETHER, 0x920),
195 INTC_VECT(GEINT1, 0x940), INTC_VECT(GEINT2, 0x960), 169 INTC_VECT(GETHER, 0x940), INTC_VECT(GETHER, 0x960),
196 INTC_VECT(HAC, 0x980), 170 INTC_VECT(HAC, 0x980),
197 INTC_VECT(PCISERR, 0xa00), INTC_VECT(PCIINTA, 0xa20), 171 INTC_VECT(PCISERR, 0xa00), INTC_VECT(PCIINTA, 0xa20),
198 INTC_VECT(PCIINTB, 0xa40), INTC_VECT(PCIINTC, 0xa60), 172 INTC_VECT(PCIINTB, 0xa40), INTC_VECT(PCIINTC, 0xa60),
199 INTC_VECT(PCIINTD, 0xa80), INTC_VECT(PCIERR, 0xaa0), 173 INTC_VECT(PCIINTD, 0xa80), INTC_VECT(PCIC5, 0xaa0),
200 INTC_VECT(PCIPWD3, 0xac0), INTC_VECT(PCIPWD2, 0xae0), 174 INTC_VECT(PCIC5, 0xac0), INTC_VECT(PCIC5, 0xae0),
201 INTC_VECT(PCIPWD1, 0xb00), INTC_VECT(PCIPWD0, 0xb20), 175 INTC_VECT(PCIC5, 0xb00), INTC_VECT(PCIC5, 0xb20),
202 INTC_VECT(STIF0, 0xb40), INTC_VECT(STIF1, 0xb60), 176 INTC_VECT(STIF0, 0xb40), INTC_VECT(STIF1, 0xb60),
203 INTC_VECT(SCIF1_ERI, 0xb80), INTC_VECT(SCIF1_RXI, 0xba0), 177 INTC_VECT(SCIF1, 0xb80), INTC_VECT(SCIF1, 0xba0),
204 INTC_VECT(SCIF1_BRI, 0xbc0), INTC_VECT(SCIF1_TXI, 0xbe0), 178 INTC_VECT(SCIF1, 0xbc0), INTC_VECT(SCIF1, 0xbe0),
205 INTC_VECT(SIOF0, 0xc00), INTC_VECT(SIOF1, 0xc20), 179 INTC_VECT(SIOF0, 0xc00), INTC_VECT(SIOF1, 0xc20),
206 INTC_VECT(USBH, 0xc60), INTC_VECT(USBFI0, 0xc80), 180 INTC_VECT(USBH, 0xc60), INTC_VECT(USBF, 0xc80),
207 INTC_VECT(USBFI1, 0xca0), 181 INTC_VECT(USBF, 0xca0),
208 INTC_VECT(TPU, 0xcc0), INTC_VECT(PCC, 0xce0), 182 INTC_VECT(TPU, 0xcc0), INTC_VECT(PCC, 0xce0),
209 INTC_VECT(MMCIF_FSTAT, 0xd00), INTC_VECT(MMCIF_TRAN, 0xd20), 183 INTC_VECT(MMCIF, 0xd00), INTC_VECT(MMCIF, 0xd20),
210 INTC_VECT(MMCIF_ERR, 0xd40), INTC_VECT(MMCIF_FRDY, 0xd60), 184 INTC_VECT(MMCIF, 0xd40), INTC_VECT(MMCIF, 0xd60),
211 INTC_VECT(SIM_ERI, 0xd80), INTC_VECT(SIM_RXI, 0xda0), 185 INTC_VECT(SIM, 0xd80), INTC_VECT(SIM, 0xda0),
212 INTC_VECT(SIM_TXI, 0xdc0), INTC_VECT(SIM_TEND, 0xde0), 186 INTC_VECT(SIM, 0xdc0), INTC_VECT(SIM, 0xde0),
213 INTC_VECT(TMU3, 0xe00), INTC_VECT(TMU4, 0xe20), 187 INTC_VECT(TMU3, 0xe00), INTC_VECT(TMU4, 0xe20),
214 INTC_VECT(TMU5, 0xe40), INTC_VECT(ADC, 0xe60), 188 INTC_VECT(TMU5, 0xe40), INTC_VECT(ADC, 0xe60),
215 INTC_VECT(SSI0, 0xe80), INTC_VECT(SSI1, 0xea0), 189 INTC_VECT(SSI0, 0xe80), INTC_VECT(SSI1, 0xea0),
216 INTC_VECT(SSI2, 0xec0), INTC_VECT(SSI3, 0xee0), 190 INTC_VECT(SSI2, 0xec0), INTC_VECT(SSI3, 0xee0),
217 INTC_VECT(SCIF2_ERI, 0xf00), INTC_VECT(SCIF2_RXI, 0xf20), 191 INTC_VECT(SCIF2, 0xf00), INTC_VECT(SCIF2, 0xf20),
218 INTC_VECT(SCIF2_BRI, 0xf40), INTC_VECT(SCIF2_TXI, 0xf60), 192 INTC_VECT(SCIF2, 0xf40), INTC_VECT(SCIF2, 0xf60),
219 INTC_VECT(GPIO_CH0, 0xf80), INTC_VECT(GPIO_CH1, 0xfa0), 193 INTC_VECT(GPIO, 0xf80), INTC_VECT(GPIO, 0xfa0),
220 INTC_VECT(GPIO_CH2, 0xfc0), INTC_VECT(GPIO_CH3, 0xfe0), 194 INTC_VECT(GPIO, 0xfc0), INTC_VECT(GPIO, 0xfe0),
221}; 195};
222 196
223static struct intc_group groups[] __initdata = { 197static struct intc_group groups[] __initdata = {
224 INTC_GROUP(TMU012, TMU0, TMU1, TMU2, TMU2_TICPI), 198 INTC_GROUP(TMU012, TMU0, TMU1, TMU2, TMU2_TICPI),
225 INTC_GROUP(TMU345, TMU3, TMU4, TMU5), 199 INTC_GROUP(TMU345, TMU3, TMU4, TMU5),
226 INTC_GROUP(RTC, RTC_ATI, RTC_PRI, RTC_CUI),
227 INTC_GROUP(DMAC, DMAC0_DMINT0, DMAC0_DMINT1, DMAC0_DMINT2,
228 DMAC0_DMINT3, DMAC0_DMINT4, DMAC0_DMINT5, DMAC0_DMAE),
229 INTC_GROUP(SCIF0, SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI),
230 INTC_GROUP(GETHER, GEINT0, GEINT1, GEINT2),
231 INTC_GROUP(PCIC5, PCIERR, PCIPWD3, PCIPWD2, PCIPWD1, PCIPWD0),
232 INTC_GROUP(SCIF1, SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI),
233 INTC_GROUP(USBF, USBFI0, USBFI1),
234 INTC_GROUP(MMCIF, MMCIF_FSTAT, MMCIF_TRAN, MMCIF_ERR, MMCIF_FRDY),
235 INTC_GROUP(SIM, SIM_ERI, SIM_RXI, SIM_TXI, SIM_TEND),
236 INTC_GROUP(SCIF2, SCIF2_ERI, SCIF2_RXI, SCIF2_BRI, SCIF2_TXI),
237 INTC_GROUP(GPIO, GPIO_CH0, GPIO_CH1, GPIO_CH2, GPIO_CH3),
238}; 200};
239 201
240static struct intc_mask_reg mask_registers[] __initdata = { 202static struct intc_mask_reg mask_registers[] __initdata = {
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7780.c b/arch/sh/kernel/cpu/sh4a/setup-sh7780.c
index fb8200cc7440..6f7227cd65bf 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7780.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7780.c
@@ -20,17 +20,7 @@ static struct resource rtc_resources[] = {
20 .flags = IORESOURCE_IO, 20 .flags = IORESOURCE_IO,
21 }, 21 },
22 [1] = { 22 [1] = {
23 /* Period IRQ */ 23 /* Shared Period/Carry/Alarm IRQ */
24 .start = 21,
25 .flags = IORESOURCE_IRQ,
26 },
27 [2] = {
28 /* Carry IRQ */
29 .start = 22,
30 .flags = IORESOURCE_IRQ,
31 },
32 [3] = {
33 /* Alarm IRQ */
34 .start = 20, 24 .start = 20,
35 .flags = IORESOURCE_IRQ, 25 .flags = IORESOURCE_IRQ,
36 }, 26 },
@@ -48,12 +38,12 @@ static struct plat_sci_port sci_platform_data[] = {
48 .mapbase = 0xffe00000, 38 .mapbase = 0xffe00000,
49 .flags = UPF_BOOT_AUTOCONF, 39 .flags = UPF_BOOT_AUTOCONF,
50 .type = PORT_SCIF, 40 .type = PORT_SCIF,
51 .irqs = { 40, 41, 43, 42 }, 41 .irqs = { 40, 40, 40, 40 },
52 }, { 42 }, {
53 .mapbase = 0xffe10000, 43 .mapbase = 0xffe10000,
54 .flags = UPF_BOOT_AUTOCONF, 44 .flags = UPF_BOOT_AUTOCONF,
55 .type = PORT_SCIF, 45 .type = PORT_SCIF,
56 .irqs = { 76, 77, 79, 78 }, 46 .irqs = { 76, 76, 76, 76 },
57 }, { 47 }, {
58 .flags = 0, 48 .flags = 0,
59 } 49 }
@@ -90,82 +80,55 @@ enum {
90 IRL_HHLL, IRL_HHLH, IRL_HHHL, 80 IRL_HHLL, IRL_HHLH, IRL_HHHL,
91 81
92 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7, 82 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7,
93 RTC_ATI, RTC_PRI, RTC_CUI, 83 RTC, WDT, TMU0, TMU1, TMU2, TMU2_TICPI,
94 WDT, 84 HUDI, DMAC0, SCIF0, DMAC1, CMT, HAC,
95 TMU0, TMU1, TMU2, TMU2_TICPI, 85 PCISERR, PCIINTA, PCIINTB, PCIINTC, PCIINTD, PCIC5,
96 HUDI, 86 SCIF1, SIOF, HSPI, MMCIF, TMU3, TMU4, TMU5, SSI, FLCTL, GPIO,
97 DMAC0_DMINT0, DMAC0_DMINT1, DMAC0_DMINT2, DMAC0_DMINT3, DMAC0_DMAE,
98 SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI,
99 DMAC0_DMINT4, DMAC0_DMINT5, DMAC1_DMINT6, DMAC1_DMINT7,
100 CMT, HAC,
101 PCISERR, PCIINTA, PCIINTB, PCIINTC, PCIINTD,
102 PCIERR, PCIPWD3, PCIPWD2, PCIPWD1, PCIPWD0,
103 SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI,
104 SIOF, HSPI,
105 MMCIF_FSTAT, MMCIF_TRAN, MMCIF_ERR, MMCIF_FRDY,
106 DMAC1_DMINT8, DMAC1_DMINT9, DMAC1_DMINT10, DMAC1_DMINT11,
107 TMU3, TMU4, TMU5,
108 SSI,
109 FLCTL_FLSTE, FLCTL_FLEND, FLCTL_FLTRQ0, FLCTL_FLTRQ1,
110 GPIOI0, GPIOI1, GPIOI2, GPIOI3,
111 87
112 /* interrupt groups */ 88 /* interrupt groups */
113 89
114 RTC, TMU012, DMAC0, SCIF0, DMAC45, DMAC1, 90 TMU012, TMU345,
115 PCIC5, SCIF1, MMCIF, TMU345, FLCTL, GPIO,
116}; 91};
117 92
118static struct intc_vect vectors[] __initdata = { 93static struct intc_vect vectors[] __initdata = {
119 INTC_VECT(RTC_ATI, 0x480), INTC_VECT(RTC_PRI, 0x4a0), 94 INTC_VECT(RTC, 0x480), INTC_VECT(RTC, 0x4a0),
120 INTC_VECT(RTC_CUI, 0x4c0), 95 INTC_VECT(RTC, 0x4c0),
121 INTC_VECT(WDT, 0x560), 96 INTC_VECT(WDT, 0x560),
122 INTC_VECT(TMU0, 0x580), INTC_VECT(TMU1, 0x5a0), 97 INTC_VECT(TMU0, 0x580), INTC_VECT(TMU1, 0x5a0),
123 INTC_VECT(TMU2, 0x5c0), INTC_VECT(TMU2_TICPI, 0x5e0), 98 INTC_VECT(TMU2, 0x5c0), INTC_VECT(TMU2_TICPI, 0x5e0),
124 INTC_VECT(HUDI, 0x600), 99 INTC_VECT(HUDI, 0x600),
125 INTC_VECT(DMAC0_DMINT0, 0x640), INTC_VECT(DMAC0_DMINT1, 0x660), 100 INTC_VECT(DMAC0, 0x640), INTC_VECT(DMAC0, 0x660),
126 INTC_VECT(DMAC0_DMINT2, 0x680), INTC_VECT(DMAC0_DMINT3, 0x6a0), 101 INTC_VECT(DMAC0, 0x680), INTC_VECT(DMAC0, 0x6a0),
127 INTC_VECT(DMAC0_DMAE, 0x6c0), 102 INTC_VECT(DMAC0, 0x6c0),
128 INTC_VECT(SCIF0_ERI, 0x700), INTC_VECT(SCIF0_RXI, 0x720), 103 INTC_VECT(SCIF0, 0x700), INTC_VECT(SCIF0, 0x720),
129 INTC_VECT(SCIF0_BRI, 0x740), INTC_VECT(SCIF0_TXI, 0x760), 104 INTC_VECT(SCIF0, 0x740), INTC_VECT(SCIF0, 0x760),
130 INTC_VECT(DMAC0_DMINT4, 0x780), INTC_VECT(DMAC0_DMINT5, 0x7a0), 105 INTC_VECT(DMAC0, 0x780), INTC_VECT(DMAC0, 0x7a0),
131 INTC_VECT(DMAC1_DMINT6, 0x7c0), INTC_VECT(DMAC1_DMINT7, 0x7e0), 106 INTC_VECT(DMAC1, 0x7c0), INTC_VECT(DMAC1, 0x7e0),
132 INTC_VECT(CMT, 0x900), INTC_VECT(HAC, 0x980), 107 INTC_VECT(CMT, 0x900), INTC_VECT(HAC, 0x980),
133 INTC_VECT(PCISERR, 0xa00), INTC_VECT(PCIINTA, 0xa20), 108 INTC_VECT(PCISERR, 0xa00), INTC_VECT(PCIINTA, 0xa20),
134 INTC_VECT(PCIINTB, 0xa40), INTC_VECT(PCIINTC, 0xa60), 109 INTC_VECT(PCIINTB, 0xa40), INTC_VECT(PCIINTC, 0xa60),
135 INTC_VECT(PCIINTD, 0xa80), INTC_VECT(PCIERR, 0xaa0), 110 INTC_VECT(PCIINTD, 0xa80), INTC_VECT(PCIC5, 0xaa0),
136 INTC_VECT(PCIPWD3, 0xac0), INTC_VECT(PCIPWD2, 0xae0), 111 INTC_VECT(PCIC5, 0xac0), INTC_VECT(PCIC5, 0xae0),
137 INTC_VECT(PCIPWD1, 0xb00), INTC_VECT(PCIPWD0, 0xb20), 112 INTC_VECT(PCIC5, 0xb00), INTC_VECT(PCIC5, 0xb20),
138 INTC_VECT(SCIF1_ERI, 0xb80), INTC_VECT(SCIF1_RXI, 0xba0), 113 INTC_VECT(SCIF1, 0xb80), INTC_VECT(SCIF1, 0xba0),
139 INTC_VECT(SCIF1_BRI, 0xbc0), INTC_VECT(SCIF1_TXI, 0xbe0), 114 INTC_VECT(SCIF1, 0xbc0), INTC_VECT(SCIF1, 0xbe0),
140 INTC_VECT(SIOF, 0xc00), INTC_VECT(HSPI, 0xc80), 115 INTC_VECT(SIOF, 0xc00), INTC_VECT(HSPI, 0xc80),
141 INTC_VECT(MMCIF_FSTAT, 0xd00), INTC_VECT(MMCIF_TRAN, 0xd20), 116 INTC_VECT(MMCIF, 0xd00), INTC_VECT(MMCIF, 0xd20),
142 INTC_VECT(MMCIF_ERR, 0xd40), INTC_VECT(MMCIF_FRDY, 0xd60), 117 INTC_VECT(MMCIF, 0xd40), INTC_VECT(MMCIF, 0xd60),
143 INTC_VECT(DMAC1_DMINT8, 0xd80), INTC_VECT(DMAC1_DMINT9, 0xda0), 118 INTC_VECT(DMAC1, 0xd80), INTC_VECT(DMAC1, 0xda0),
144 INTC_VECT(DMAC1_DMINT10, 0xdc0), INTC_VECT(DMAC1_DMINT11, 0xde0), 119 INTC_VECT(DMAC1, 0xdc0), INTC_VECT(DMAC1, 0xde0),
145 INTC_VECT(TMU3, 0xe00), INTC_VECT(TMU4, 0xe20), 120 INTC_VECT(TMU3, 0xe00), INTC_VECT(TMU4, 0xe20),
146 INTC_VECT(TMU5, 0xe40), 121 INTC_VECT(TMU5, 0xe40),
147 INTC_VECT(SSI, 0xe80), 122 INTC_VECT(SSI, 0xe80),
148 INTC_VECT(FLCTL_FLSTE, 0xf00), INTC_VECT(FLCTL_FLEND, 0xf20), 123 INTC_VECT(FLCTL, 0xf00), INTC_VECT(FLCTL, 0xf20),
149 INTC_VECT(FLCTL_FLTRQ0, 0xf40), INTC_VECT(FLCTL_FLTRQ1, 0xf60), 124 INTC_VECT(FLCTL, 0xf40), INTC_VECT(FLCTL, 0xf60),
150 INTC_VECT(GPIOI0, 0xf80), INTC_VECT(GPIOI1, 0xfa0), 125 INTC_VECT(GPIO, 0xf80), INTC_VECT(GPIO, 0xfa0),
151 INTC_VECT(GPIOI2, 0xfc0), INTC_VECT(GPIOI3, 0xfe0), 126 INTC_VECT(GPIO, 0xfc0), INTC_VECT(GPIO, 0xfe0),
152}; 127};
153 128
154static struct intc_group groups[] __initdata = { 129static struct intc_group groups[] __initdata = {
155 INTC_GROUP(RTC, RTC_ATI, RTC_PRI, RTC_CUI),
156 INTC_GROUP(TMU012, TMU0, TMU1, TMU2, TMU2_TICPI), 130 INTC_GROUP(TMU012, TMU0, TMU1, TMU2, TMU2_TICPI),
157 INTC_GROUP(DMAC0, DMAC0_DMINT0, DMAC0_DMINT1, DMAC0_DMINT2,
158 DMAC0_DMINT3, DMAC0_DMINT4, DMAC0_DMINT5, DMAC0_DMAE),
159 INTC_GROUP(SCIF0, SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI),
160 INTC_GROUP(DMAC1, DMAC1_DMINT6, DMAC1_DMINT7, DMAC1_DMINT8,
161 DMAC1_DMINT9, DMAC1_DMINT10, DMAC1_DMINT11),
162 INTC_GROUP(PCIC5, PCIERR, PCIPWD3, PCIPWD2, PCIPWD1, PCIPWD0),
163 INTC_GROUP(SCIF1, SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI),
164 INTC_GROUP(MMCIF, MMCIF_FSTAT, MMCIF_TRAN, MMCIF_ERR, MMCIF_FRDY),
165 INTC_GROUP(TMU345, TMU3, TMU4, TMU5), 131 INTC_GROUP(TMU345, TMU3, TMU4, TMU5),
166 INTC_GROUP(FLCTL, FLCTL_FLSTE, FLCTL_FLEND,
167 FLCTL_FLTRQ0, FLCTL_FLTRQ1),
168 INTC_GROUP(GPIO, GPIOI0, GPIOI1, GPIOI2, GPIOI3),
169}; 132};
170 133
171static struct intc_mask_reg mask_registers[] __initdata = { 134static struct intc_mask_reg mask_registers[] __initdata = {
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7785.c b/arch/sh/kernel/cpu/sh4a/setup-sh7785.c
index 30baa63b24c8..d80802a49dbd 100644
--- a/arch/sh/kernel/cpu/sh4a/setup-sh7785.c
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7785.c
@@ -20,18 +20,13 @@ static struct plat_sci_port sci_platform_data[] = {
20 .mapbase = 0xffea0000, 20 .mapbase = 0xffea0000,
21 .flags = UPF_BOOT_AUTOCONF, 21 .flags = UPF_BOOT_AUTOCONF,
22 .type = PORT_SCIF, 22 .type = PORT_SCIF,
23 .irqs = { 40, 41, 43, 42 }, 23 .irqs = { 40, 40, 40, 40 },
24 }, { 24 }, {
25 .mapbase = 0xffeb0000, 25 .mapbase = 0xffeb0000,
26 .flags = UPF_BOOT_AUTOCONF, 26 .flags = UPF_BOOT_AUTOCONF,
27 .type = PORT_SCIF, 27 .type = PORT_SCIF,
28 .irqs = { 44, 45, 47, 46 }, 28 .irqs = { 44, 44, 44, 44 },
29 }, 29 }, {
30
31 /*
32 * The rest of these all have multiplexed IRQs
33 */
34 {
35 .mapbase = 0xffec0000, 30 .mapbase = 0xffec0000,
36 .flags = UPF_BOOT_AUTOCONF, 31 .flags = UPF_BOOT_AUTOCONF,
37 .type = PORT_SCIF, 32 .type = PORT_SCIF,
@@ -91,33 +86,19 @@ enum {
91 IRL4_HHLL, IRL4_HHLH, IRL4_HHHL, 86 IRL4_HHLL, IRL4_HHLH, IRL4_HHHL,
92 87
93 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7, 88 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7,
94 WDT, 89 WDT, TMU0, TMU1, TMU2, TMU2_TICPI,
95 TMU0, TMU1, TMU2, TMU2_TICPI, 90 HUDI, DMAC0, SCIF0, SCIF1, DMAC1, HSPI,
96 HUDI,
97 DMAC0_DMINT0, DMAC0_DMINT1, DMAC0_DMINT2, DMAC0_DMINT3,
98 DMAC0_DMINT4, DMAC0_DMINT5, DMAC0_DMAE,
99 SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI,
100 SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI,
101 DMAC1_DMINT6, DMAC1_DMINT7, DMAC1_DMINT8, DMAC1_DMINT9,
102 DMAC1_DMINT10, DMAC1_DMINT11, DMAC1_DMAE,
103 HSPI,
104 SCIF2, SCIF3, SCIF4, SCIF5, 91 SCIF2, SCIF3, SCIF4, SCIF5,
105 PCISERR, PCIINTA, PCIINTB, PCIINTC, PCIINTD, 92 PCISERR, PCIINTA, PCIINTB, PCIINTC, PCIINTD, PCIC5,
106 PCIERR, PCIPWD3, PCIPWD2, PCIPWD1, PCIPWD0, 93 SIOF, MMCIF, DU, GDTA,
107 SIOF,
108 MMCIF_FSTAT, MMCIF_TRAN, MMCIF_ERR, MMCIF_FRDY,
109 DU,
110 GDTA_GACLI, GDTA_GAMCI, GDTA_GAERI,
111 TMU3, TMU4, TMU5, 94 TMU3, TMU4, TMU5,
112 SSI0, SSI1, 95 SSI0, SSI1,
113 HAC0, HAC1, 96 HAC0, HAC1,
114 FLCTL_FLSTE, FLCTL_FLEND, FLCTL_FLTRQ0, FLCTL_FLTRQ1, 97 FLCTL, GPIO,
115 GPIOI0, GPIOI1, GPIOI2, GPIOI3,
116 98
117 /* interrupt groups */ 99 /* interrupt groups */
118 100
119 TMU012, DMAC0, SCIF0, SCIF1, DMAC1, 101 TMU012, TMU345
120 PCIC5, MMCIF, GDTA, TMU345, FLCTL, GPIO
121}; 102};
122 103
123static struct intc_vect vectors[] __initdata = { 104static struct intc_vect vectors[] __initdata = {
@@ -125,57 +106,45 @@ static struct intc_vect vectors[] __initdata = {
125 INTC_VECT(TMU0, 0x580), INTC_VECT(TMU1, 0x5a0), 106 INTC_VECT(TMU0, 0x580), INTC_VECT(TMU1, 0x5a0),
126 INTC_VECT(TMU2, 0x5c0), INTC_VECT(TMU2_TICPI, 0x5e0), 107 INTC_VECT(TMU2, 0x5c0), INTC_VECT(TMU2_TICPI, 0x5e0),
127 INTC_VECT(HUDI, 0x600), 108 INTC_VECT(HUDI, 0x600),
128 INTC_VECT(DMAC0_DMINT0, 0x620), INTC_VECT(DMAC0_DMINT1, 0x640), 109 INTC_VECT(DMAC0, 0x620), INTC_VECT(DMAC0, 0x640),
129 INTC_VECT(DMAC0_DMINT2, 0x660), INTC_VECT(DMAC0_DMINT3, 0x680), 110 INTC_VECT(DMAC0, 0x660), INTC_VECT(DMAC0, 0x680),
130 INTC_VECT(DMAC0_DMINT4, 0x6a0), INTC_VECT(DMAC0_DMINT5, 0x6c0), 111 INTC_VECT(DMAC0, 0x6a0), INTC_VECT(DMAC0, 0x6c0),
131 INTC_VECT(DMAC0_DMAE, 0x6e0), 112 INTC_VECT(DMAC0, 0x6e0),
132 INTC_VECT(SCIF0_ERI, 0x700), INTC_VECT(SCIF0_RXI, 0x720), 113 INTC_VECT(SCIF0, 0x700), INTC_VECT(SCIF0, 0x720),
133 INTC_VECT(SCIF0_BRI, 0x740), INTC_VECT(SCIF0_TXI, 0x760), 114 INTC_VECT(SCIF0, 0x740), INTC_VECT(SCIF0, 0x760),
134 INTC_VECT(SCIF1_ERI, 0x780), INTC_VECT(SCIF1_RXI, 0x7a0), 115 INTC_VECT(SCIF1, 0x780), INTC_VECT(SCIF1, 0x7a0),
135 INTC_VECT(SCIF1_BRI, 0x7c0), INTC_VECT(SCIF1_TXI, 0x7e0), 116 INTC_VECT(SCIF1, 0x7c0), INTC_VECT(SCIF1, 0x7e0),
136 INTC_VECT(DMAC1_DMINT6, 0x880), INTC_VECT(DMAC1_DMINT7, 0x8a0), 117 INTC_VECT(DMAC1, 0x880), INTC_VECT(DMAC1, 0x8a0),
137 INTC_VECT(DMAC1_DMINT8, 0x8c0), INTC_VECT(DMAC1_DMINT9, 0x8e0), 118 INTC_VECT(DMAC1, 0x8c0), INTC_VECT(DMAC1, 0x8e0),
138 INTC_VECT(DMAC1_DMINT10, 0x900), INTC_VECT(DMAC1_DMINT11, 0x920), 119 INTC_VECT(DMAC1, 0x900), INTC_VECT(DMAC1, 0x920),
139 INTC_VECT(DMAC1_DMAE, 0x940), 120 INTC_VECT(DMAC1, 0x940),
140 INTC_VECT(HSPI, 0x960), 121 INTC_VECT(HSPI, 0x960),
141 INTC_VECT(SCIF2, 0x980), INTC_VECT(SCIF3, 0x9a0), 122 INTC_VECT(SCIF2, 0x980), INTC_VECT(SCIF3, 0x9a0),
142 INTC_VECT(SCIF4, 0x9c0), INTC_VECT(SCIF5, 0x9e0), 123 INTC_VECT(SCIF4, 0x9c0), INTC_VECT(SCIF5, 0x9e0),
143 INTC_VECT(PCISERR, 0xa00), INTC_VECT(PCIINTA, 0xa20), 124 INTC_VECT(PCISERR, 0xa00), INTC_VECT(PCIINTA, 0xa20),
144 INTC_VECT(PCIINTB, 0xa40), INTC_VECT(PCIINTC, 0xa60), 125 INTC_VECT(PCIINTB, 0xa40), INTC_VECT(PCIINTC, 0xa60),
145 INTC_VECT(PCIINTD, 0xa80), INTC_VECT(PCIERR, 0xaa0), 126 INTC_VECT(PCIINTD, 0xa80), INTC_VECT(PCIC5, 0xaa0),
146 INTC_VECT(PCIPWD3, 0xac0), INTC_VECT(PCIPWD2, 0xae0), 127 INTC_VECT(PCIC5, 0xac0), INTC_VECT(PCIC5, 0xae0),
147 INTC_VECT(PCIPWD1, 0xb00), INTC_VECT(PCIPWD0, 0xb20), 128 INTC_VECT(PCIC5, 0xb00), INTC_VECT(PCIC5, 0xb20),
148 INTC_VECT(SIOF, 0xc00), 129 INTC_VECT(SIOF, 0xc00),
149 INTC_VECT(MMCIF_FSTAT, 0xd00), INTC_VECT(MMCIF_TRAN, 0xd20), 130 INTC_VECT(MMCIF, 0xd00), INTC_VECT(MMCIF, 0xd20),
150 INTC_VECT(MMCIF_ERR, 0xd40), INTC_VECT(MMCIF_FRDY, 0xd60), 131 INTC_VECT(MMCIF, 0xd40), INTC_VECT(MMCIF, 0xd60),
151 INTC_VECT(DU, 0xd80), 132 INTC_VECT(DU, 0xd80),
152 INTC_VECT(GDTA_GACLI, 0xda0), INTC_VECT(GDTA_GAMCI, 0xdc0), 133 INTC_VECT(GDTA, 0xda0), INTC_VECT(GDTA, 0xdc0),
153 INTC_VECT(GDTA_GAERI, 0xde0), 134 INTC_VECT(GDTA, 0xde0),
154 INTC_VECT(TMU3, 0xe00), INTC_VECT(TMU4, 0xe20), 135 INTC_VECT(TMU3, 0xe00), INTC_VECT(TMU4, 0xe20),
155 INTC_VECT(TMU5, 0xe40), 136 INTC_VECT(TMU5, 0xe40),
156 INTC_VECT(SSI0, 0xe80), INTC_VECT(SSI1, 0xea0), 137 INTC_VECT(SSI0, 0xe80), INTC_VECT(SSI1, 0xea0),
157 INTC_VECT(HAC0, 0xec0), INTC_VECT(HAC1, 0xee0), 138 INTC_VECT(HAC0, 0xec0), INTC_VECT(HAC1, 0xee0),
158 INTC_VECT(FLCTL_FLSTE, 0xf00), INTC_VECT(FLCTL_FLEND, 0xf20), 139 INTC_VECT(FLCTL, 0xf00), INTC_VECT(FLCTL, 0xf20),
159 INTC_VECT(FLCTL_FLTRQ0, 0xf40), INTC_VECT(FLCTL_FLTRQ1, 0xf60), 140 INTC_VECT(FLCTL, 0xf40), INTC_VECT(FLCTL, 0xf60),
160 INTC_VECT(GPIOI0, 0xf80), INTC_VECT(GPIOI1, 0xfa0), 141 INTC_VECT(GPIO, 0xf80), INTC_VECT(GPIO, 0xfa0),
161 INTC_VECT(GPIOI2, 0xfc0), INTC_VECT(GPIOI3, 0xfe0), 142 INTC_VECT(GPIO, 0xfc0), INTC_VECT(GPIO, 0xfe0),
162}; 143};
163 144
164static struct intc_group groups[] __initdata = { 145static struct intc_group groups[] __initdata = {
165 INTC_GROUP(TMU012, TMU0, TMU1, TMU2, TMU2_TICPI), 146 INTC_GROUP(TMU012, TMU0, TMU1, TMU2, TMU2_TICPI),
166 INTC_GROUP(DMAC0, DMAC0_DMINT0, DMAC0_DMINT1, DMAC0_DMINT2,
167 DMAC0_DMINT3, DMAC0_DMINT4, DMAC0_DMINT5, DMAC0_DMAE),
168 INTC_GROUP(SCIF0, SCIF0_ERI, SCIF0_RXI, SCIF0_BRI, SCIF0_TXI),
169 INTC_GROUP(SCIF1, SCIF1_ERI, SCIF1_RXI, SCIF1_BRI, SCIF1_TXI),
170 INTC_GROUP(DMAC1, DMAC1_DMINT6, DMAC1_DMINT7, DMAC1_DMINT8,
171 DMAC1_DMINT9, DMAC1_DMINT10, DMAC1_DMINT11, DMAC1_DMAE),
172 INTC_GROUP(PCIC5, PCIERR, PCIPWD3, PCIPWD2, PCIPWD1, PCIPWD0),
173 INTC_GROUP(MMCIF, MMCIF_FSTAT, MMCIF_TRAN, MMCIF_ERR, MMCIF_FRDY),
174 INTC_GROUP(GDTA, GDTA_GACLI, GDTA_GAMCI, GDTA_GAERI),
175 INTC_GROUP(TMU345, TMU3, TMU4, TMU5), 147 INTC_GROUP(TMU345, TMU3, TMU4, TMU5),
176 INTC_GROUP(FLCTL, FLCTL_FLSTE, FLCTL_FLEND,
177 FLCTL_FLTRQ0, FLCTL_FLTRQ1),
178 INTC_GROUP(GPIO, GPIOI0, GPIOI1, GPIOI2, GPIOI3),
179}; 148};
180 149
181static struct intc_mask_reg mask_registers[] __initdata = { 150static struct intc_mask_reg mask_registers[] __initdata = {
diff --git a/arch/sh/kernel/cpu/sh4a/setup-sh7786.c b/arch/sh/kernel/cpu/sh4a/setup-sh7786.c
new file mode 100644
index 000000000000..5a47e1cf442e
--- /dev/null
+++ b/arch/sh/kernel/cpu/sh4a/setup-sh7786.c
@@ -0,0 +1,490 @@
1/*
2 * SH7786 Setup
3 *
4 * Copyright (C) 2009 Renesas Solutions Corp.
5 * Kuninori Morimoto <morimoto.kuninori@renesas.com>
6 *
7 * Based on SH7785 Setup
8 *
9 * Copyright (C) 2007 Paul Mundt
10 *
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
13 * for more details.
14 */
15#include <linux/platform_device.h>
16#include <linux/init.h>
17#include <linux/serial.h>
18#include <linux/serial_sci.h>
19#include <linux/io.h>
20#include <linux/mm.h>
21#include <linux/dma-mapping.h>
22#include <asm/mmzone.h>
23
24static struct plat_sci_port sci_platform_data[] = {
25 {
26 .mapbase = 0xffea0000,
27 .flags = UPF_BOOT_AUTOCONF,
28 .type = PORT_SCIF,
29 .irqs = { 40, 41, 43, 42 },
30 },
31 /*
32 * The rest of these all have multiplexed IRQs
33 */
34 {
35 .mapbase = 0xffeb0000,
36 .flags = UPF_BOOT_AUTOCONF,
37 .type = PORT_SCIF,
38 .irqs = { 44, 44, 44, 44 },
39 }, {
40 .mapbase = 0xffec0000,
41 .flags = UPF_BOOT_AUTOCONF,
42 .type = PORT_SCIF,
43 .irqs = { 50, 50, 50, 50 },
44 }, {
45 .mapbase = 0xffed0000,
46 .flags = UPF_BOOT_AUTOCONF,
47 .type = PORT_SCIF,
48 .irqs = { 51, 51, 51, 51 },
49 }, {
50 .mapbase = 0xffee0000,
51 .flags = UPF_BOOT_AUTOCONF,
52 .type = PORT_SCIF,
53 .irqs = { 52, 52, 52, 52 },
54 }, {
55 .mapbase = 0xffef0000,
56 .flags = UPF_BOOT_AUTOCONF,
57 .type = PORT_SCIF,
58 .irqs = { 53, 53, 53, 53 },
59 }, {
60 .flags = 0,
61 }
62};
63
64static struct platform_device sci_device = {
65 .name = "sh-sci",
66 .id = -1,
67 .dev = {
68 .platform_data = sci_platform_data,
69 },
70};
71
72static struct resource usb_ohci_resources[] = {
73 [0] = {
74 .start = 0xffe70400,
75 .end = 0xffe704ff,
76 .flags = IORESOURCE_MEM,
77 },
78 [1] = {
79 .start = 77,
80 .end = 77,
81 .flags = IORESOURCE_IRQ,
82 },
83};
84
85static u64 usb_ohci_dma_mask = DMA_BIT_MASK(32);
86static struct platform_device usb_ohci_device = {
87 .name = "sh_ohci",
88 .id = -1,
89 .dev = {
90 .dma_mask = &usb_ohci_dma_mask,
91 .coherent_dma_mask = DMA_BIT_MASK(32),
92 },
93 .num_resources = ARRAY_SIZE(usb_ohci_resources),
94 .resource = usb_ohci_resources,
95};
96
97static struct platform_device *sh7786_devices[] __initdata = {
98 &sci_device,
99 &usb_ohci_device,
100};
101
102
103/*
104 * Please call this function if your platform board
105 * use external clock for USB
106 * */
107#define USBCTL0 0xffe70858
108#define CLOCK_MODE_MASK 0xffffff7f
109#define EXT_CLOCK_MODE 0x00000080
110void __init sh7786_usb_use_exclock(void)
111{
112 u32 val = __raw_readl(USBCTL0) & CLOCK_MODE_MASK;
113 __raw_writel(val | EXT_CLOCK_MODE, USBCTL0);
114}
115
116#define USBINITREG1 0xffe70094
117#define USBINITREG2 0xffe7009c
118#define USBINITVAL1 0x00ff0040
119#define USBINITVAL2 0x00000001
120
121#define USBPCTL1 0xffe70804
122#define USBST 0xffe70808
123#define PHY_ENB 0x00000001
124#define PLL_ENB 0x00000002
125#define PHY_RST 0x00000004
126#define ACT_PLL_STATUS 0xc0000000
127static void __init sh7786_usb_setup(void)
128{
129 int i = 1000000;
130
131 /*
132 * USB initial settings
133 *
134 * The following settings are necessary
135 * for using the USB modules.
136 *
137 * see "USB Inital Settings" for detail
138 */
139 __raw_writel(USBINITVAL1, USBINITREG1);
140 __raw_writel(USBINITVAL2, USBINITREG2);
141
142 /*
143 * Set the PHY and PLL enable bit
144 */
145 __raw_writel(PHY_ENB | PLL_ENB, USBPCTL1);
146 while (i-- &&
147 ((__raw_readl(USBST) & ACT_PLL_STATUS) != ACT_PLL_STATUS))
148 cpu_relax();
149
150 if (i) {
151 /* Set the PHY RST bit */
152 __raw_writel(PHY_ENB | PLL_ENB | PHY_RST, USBPCTL1);
153 printk(KERN_INFO "sh7786 usb setup done\n");
154 }
155}
156
157static int __init sh7786_devices_setup(void)
158{
159 sh7786_usb_setup();
160 return platform_add_devices(sh7786_devices,
161 ARRAY_SIZE(sh7786_devices));
162}
163device_initcall(sh7786_devices_setup);
164
165enum {
166 UNUSED = 0,
167
168 /* interrupt sources */
169
170 IRL0_LLLL, IRL0_LLLH, IRL0_LLHL, IRL0_LLHH,
171 IRL0_LHLL, IRL0_LHLH, IRL0_LHHL, IRL0_LHHH,
172 IRL0_HLLL, IRL0_HLLH, IRL0_HLHL, IRL0_HLHH,
173 IRL0_HHLL, IRL0_HHLH, IRL0_HHHL,
174
175 IRL4_LLLL, IRL4_LLLH, IRL4_LLHL, IRL4_LLHH,
176 IRL4_LHLL, IRL4_LHLH, IRL4_LHHL, IRL4_LHHH,
177 IRL4_HLLL, IRL4_HLLH, IRL4_HLHL, IRL4_HLHH,
178 IRL4_HHLL, IRL4_HHLH, IRL4_HHHL,
179
180 IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7,
181 WDT,
182 TMU0_0, TMU0_1, TMU0_2, TMU0_3,
183 TMU1_0, TMU1_1, TMU1_2,
184 DMAC0_0, DMAC0_1, DMAC0_2, DMAC0_3, DMAC0_4, DMAC0_5, DMAC0_6,
185 HUDI1, HUDI0,
186 DMAC1_0, DMAC1_1, DMAC1_2, DMAC1_3,
187 HPB_0, HPB_1, HPB_2,
188 SCIF0_0, SCIF0_1, SCIF0_2, SCIF0_3,
189 SCIF1,
190 TMU2, TMU3,
191 SCIF2, SCIF3, SCIF4, SCIF5,
192 Eth_0, Eth_1,
193 PCIeC0_0, PCIeC0_1, PCIeC0_2,
194 PCIeC1_0, PCIeC1_1, PCIeC1_2,
195 USB,
196 I2C0, I2C1,
197 DU,
198 SSI0, SSI1, SSI2, SSI3,
199 PCIeC2_0, PCIeC2_1, PCIeC2_2,
200 HAC0, HAC1,
201 FLCTL,
202 HSPI,
203 GPIO0, GPIO1,
204 Thermal,
205 INTC0, INTC1, INTC2, INTC3, INTC4, INTC5, INTC6, INTC7,
206
207 /* interrupt groups */
208};
209
210static struct intc_vect vectors[] __initdata = {
211 INTC_VECT(WDT, 0x3e0),
212 INTC_VECT(TMU0_0, 0x400), INTC_VECT(TMU0_1, 0x420),
213 INTC_VECT(TMU0_2, 0x440), INTC_VECT(TMU0_3, 0x460),
214 INTC_VECT(TMU1_0, 0x480), INTC_VECT(TMU1_1, 0x4a0),
215 INTC_VECT(TMU1_2, 0x4c0),
216 INTC_VECT(DMAC0_0, 0x500), INTC_VECT(DMAC0_1, 0x520),
217 INTC_VECT(DMAC0_2, 0x540), INTC_VECT(DMAC0_3, 0x560),
218 INTC_VECT(DMAC0_4, 0x580), INTC_VECT(DMAC0_5, 0x5a0),
219 INTC_VECT(DMAC0_6, 0x5c0),
220 INTC_VECT(HUDI1, 0x5e0), INTC_VECT(HUDI0, 0x600),
221 INTC_VECT(DMAC1_0, 0x620), INTC_VECT(DMAC1_1, 0x640),
222 INTC_VECT(DMAC1_2, 0x660), INTC_VECT(DMAC1_3, 0x680),
223 INTC_VECT(HPB_0, 0x6a0), INTC_VECT(HPB_1, 0x6c0),
224 INTC_VECT(HPB_2, 0x6e0),
225 INTC_VECT(SCIF0_0, 0x700), INTC_VECT(SCIF0_1, 0x720),
226 INTC_VECT(SCIF0_2, 0x740), INTC_VECT(SCIF0_3, 0x760),
227 INTC_VECT(SCIF1, 0x780),
228 INTC_VECT(TMU2, 0x7a0), INTC_VECT(TMU3, 0x7c0),
229 INTC_VECT(SCIF2, 0x840), INTC_VECT(SCIF3, 0x860),
230 INTC_VECT(SCIF4, 0x880), INTC_VECT(SCIF5, 0x8a0),
231 INTC_VECT(Eth_0, 0x8c0), INTC_VECT(Eth_1, 0x8e0),
232 INTC_VECT(PCIeC0_0, 0xae0), INTC_VECT(PCIeC0_1, 0xb00),
233 INTC_VECT(PCIeC0_2, 0xb20),
234 INTC_VECT(PCIeC1_0, 0xb40), INTC_VECT(PCIeC1_1, 0xb60),
235 INTC_VECT(PCIeC1_2, 0xb80),
236 INTC_VECT(USB, 0xba0),
237 INTC_VECT(I2C0, 0xcc0), INTC_VECT(I2C1, 0xce0),
238 INTC_VECT(DU, 0xd00),
239 INTC_VECT(SSI0, 0xd20), INTC_VECT(SSI1, 0xd40),
240 INTC_VECT(SSI2, 0xd60), INTC_VECT(SSI3, 0xd80),
241 INTC_VECT(PCIeC2_0, 0xda0), INTC_VECT(PCIeC2_1, 0xdc0),
242 INTC_VECT(PCIeC2_2, 0xde0),
243 INTC_VECT(HAC0, 0xe00), INTC_VECT(HAC1, 0xe20),
244 INTC_VECT(FLCTL, 0xe40),
245 INTC_VECT(HSPI, 0xe80),
246 INTC_VECT(GPIO0, 0xea0), INTC_VECT(GPIO1, 0xec0),
247 INTC_VECT(Thermal, 0xee0),
248};
249
250/* FIXME: Main CPU support only now */
251#if 1 /* Main CPU */
252#define CnINTMSK0 0xfe410030
253#define CnINTMSK1 0xfe410040
254#define CnINTMSKCLR0 0xfe410050
255#define CnINTMSKCLR1 0xfe410060
256#define CnINT2MSKR0 0xfe410a20
257#define CnINT2MSKR1 0xfe410a24
258#define CnINT2MSKR2 0xfe410a28
259#define CnINT2MSKR3 0xfe410a2c
260#define CnINT2MSKCR0 0xfe410a30
261#define CnINT2MSKCR1 0xfe410a34
262#define CnINT2MSKCR2 0xfe410a38
263#define CnINT2MSKCR3 0xfe410a3c
264#else /* Sub CPU */
265#define CnINTMSK0 0xfe410034
266#define CnINTMSK1 0xfe410044
267#define CnINTMSKCLR0 0xfe410054
268#define CnINTMSKCLR1 0xfe410064
269#define CnINT2MSKR0 0xfe410b20
270#define CnINT2MSKR1 0xfe410b24
271#define CnINT2MSKR2 0xfe410b28
272#define CnINT2MSKR3 0xfe410b2c
273#define CnINT2MSKCR0 0xfe410b30
274#define CnINT2MSKCR1 0xfe410b34
275#define CnINT2MSKCR2 0xfe410b38
276#define CnINT2MSKCR3 0xfe410b3c
277#endif
278
279#define INTMSK2 0xfe410068
280#define INTMSKCLR2 0xfe41006c
281
282static struct intc_mask_reg mask_registers[] __initdata = {
283 { CnINTMSK0, CnINTMSKCLR0, 32,
284 { IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7 } },
285 { INTMSK2, INTMSKCLR2, 32,
286 { IRL0_LLLL, IRL0_LLLH, IRL0_LLHL, IRL0_LLHH,
287 IRL0_LHLL, IRL0_LHLH, IRL0_LHHL, IRL0_LHHH,
288 IRL0_HLLL, IRL0_HLLH, IRL0_HLHL, IRL0_HLHH,
289 IRL0_HHLL, IRL0_HHLH, IRL0_HHHL, 0,
290 IRL4_LLLL, IRL4_LLLH, IRL4_LLHL, IRL4_LLHH,
291 IRL4_LHLL, IRL4_LHLH, IRL4_LHHL, IRL4_LHHH,
292 IRL4_HLLL, IRL4_HLLH, IRL4_HLHL, IRL4_HLHH,
293 IRL4_HHLL, IRL4_HHLH, IRL4_HHHL, 0, } },
294 { CnINT2MSKR0, CnINT2MSKCR0 , 32,
295 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
296 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, WDT } },
297 { CnINT2MSKR1, CnINT2MSKCR1, 32,
298 { TMU0_0, TMU0_1, TMU0_2, TMU0_3, TMU1_0, TMU1_1, TMU1_2, 0,
299 DMAC0_0, DMAC0_1, DMAC0_2, DMAC0_3, DMAC0_4, DMAC0_5, DMAC0_6,
300 HUDI1, HUDI0,
301 DMAC1_0, DMAC1_1, DMAC1_2, DMAC1_3,
302 HPB_0, HPB_1, HPB_2,
303 SCIF0_0, SCIF0_1, SCIF0_2, SCIF0_3,
304 SCIF1,
305 TMU2, TMU3, 0, } },
306 { CnINT2MSKR2, CnINT2MSKCR2, 32,
307 { 0, 0, SCIF2, SCIF3, SCIF4, SCIF5,
308 Eth_0, Eth_1,
309 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
310 PCIeC0_0, PCIeC0_1, PCIeC0_2,
311 PCIeC1_0, PCIeC1_1, PCIeC1_2,
312 USB, 0, 0 } },
313 { CnINT2MSKR3, CnINT2MSKCR3, 32,
314 { 0, 0, 0, 0, 0, 0,
315 I2C0, I2C1,
316 DU, SSI0, SSI1, SSI2, SSI3,
317 PCIeC2_0, PCIeC2_1, PCIeC2_2,
318 HAC0, HAC1,
319 FLCTL, 0,
320 HSPI, GPIO0, GPIO1, Thermal,
321 0, 0, 0, 0, 0, 0, 0, 0 } },
322};
323
324static struct intc_prio_reg prio_registers[] __initdata = {
325 { 0xfe410010, 0, 32, 4, /* INTPRI */ { IRQ0, IRQ1, IRQ2, IRQ3,
326 IRQ4, IRQ5, IRQ6, IRQ7 } },
327 { 0xfe410800, 0, 32, 8, /* INT2PRI0 */ { 0, 0, 0, WDT } },
328 { 0xfe410804, 0, 32, 8, /* INT2PRI1 */ { TMU0_0, TMU0_1,
329 TMU0_2, TMU0_3 } },
330 { 0xfe410808, 0, 32, 8, /* INT2PRI2 */ { TMU1_0, TMU1_1,
331 TMU1_2, 0 } },
332 { 0xfe41080c, 0, 32, 8, /* INT2PRI3 */ { DMAC0_0, DMAC0_1,
333 DMAC0_2, DMAC0_3 } },
334 { 0xfe410810, 0, 32, 8, /* INT2PRI4 */ { DMAC0_4, DMAC0_5,
335 DMAC0_6, HUDI1 } },
336 { 0xfe410814, 0, 32, 8, /* INT2PRI5 */ { HUDI0, DMAC1_0,
337 DMAC1_1, DMAC1_2 } },
338 { 0xfe410818, 0, 32, 8, /* INT2PRI6 */ { DMAC1_3, HPB_0,
339 HPB_1, HPB_2 } },
340 { 0xfe41081c, 0, 32, 8, /* INT2PRI7 */ { SCIF0_0, SCIF0_1,
341 SCIF0_2, SCIF0_3 } },
342 { 0xfe410820, 0, 32, 8, /* INT2PRI8 */ { SCIF1, TMU2, TMU3, 0 } },
343 { 0xfe410824, 0, 32, 8, /* INT2PRI9 */ { 0, 0, SCIF2, SCIF3 } },
344 { 0xfe410828, 0, 32, 8, /* INT2PRI10 */ { SCIF4, SCIF5,
345 Eth_0, Eth_1 } },
346 { 0xfe41082c, 0, 32, 8, /* INT2PRI11 */ { 0, 0, 0, 0 } },
347 { 0xfe410830, 0, 32, 8, /* INT2PRI12 */ { 0, 0, 0, 0 } },
348 { 0xfe410834, 0, 32, 8, /* INT2PRI13 */ { 0, 0, 0, 0 } },
349 { 0xfe410838, 0, 32, 8, /* INT2PRI14 */ { 0, 0, 0, PCIeC0_0 } },
350 { 0xfe41083c, 0, 32, 8, /* INT2PRI15 */ { PCIeC0_1, PCIeC0_2,
351 PCIeC1_0, PCIeC1_1 } },
352 { 0xfe410840, 0, 32, 8, /* INT2PRI16 */ { PCIeC1_2, USB, 0, 0 } },
353 { 0xfe410844, 0, 32, 8, /* INT2PRI17 */ { 0, 0, 0, 0 } },
354 { 0xfe410848, 0, 32, 8, /* INT2PRI18 */ { 0, 0, I2C0, I2C1 } },
355 { 0xfe41084c, 0, 32, 8, /* INT2PRI19 */ { DU, SSI0, SSI1, SSI2 } },
356 { 0xfe410850, 0, 32, 8, /* INT2PRI20 */ { SSI3, PCIeC2_0,
357 PCIeC2_1, PCIeC2_2 } },
358 { 0xfe410854, 0, 32, 8, /* INT2PRI21 */ { HAC0, HAC1, FLCTL, 0 } },
359 { 0xfe410858, 0, 32, 8, /* INT2PRI22 */ { HSPI, GPIO0,
360 GPIO1, Thermal } },
361 { 0xfe41085c, 0, 32, 8, /* INT2PRI23 */ { 0, 0, 0, 0 } },
362 { 0xfe410860, 0, 32, 8, /* INT2PRI24 */ { 0, 0, 0, 0 } },
363};
364
365static DECLARE_INTC_DESC(intc_desc, "sh7786", vectors, NULL,
366 mask_registers, prio_registers, NULL);
367
368/* Support for external interrupt pins in IRQ mode */
369
370static struct intc_vect vectors_irq0123[] __initdata = {
371 INTC_VECT(IRQ0, 0x200), INTC_VECT(IRQ1, 0x240),
372 INTC_VECT(IRQ2, 0x280), INTC_VECT(IRQ3, 0x2c0),
373};
374
375static struct intc_vect vectors_irq4567[] __initdata = {
376 INTC_VECT(IRQ4, 0x300), INTC_VECT(IRQ5, 0x340),
377 INTC_VECT(IRQ6, 0x380), INTC_VECT(IRQ7, 0x3c0),
378};
379
380static struct intc_sense_reg sense_registers[] __initdata = {
381 { 0xfe41001c, 32, 2, /* ICR1 */ { IRQ0, IRQ1, IRQ2, IRQ3,
382 IRQ4, IRQ5, IRQ6, IRQ7 } },
383};
384
385static struct intc_mask_reg ack_registers[] __initdata = {
386 { 0xfe410024, 0, 32, /* INTREQ */
387 { IRQ0, IRQ1, IRQ2, IRQ3, IRQ4, IRQ5, IRQ6, IRQ7 } },
388};
389
390static DECLARE_INTC_DESC_ACK(intc_desc_irq0123, "sh7786-irq0123",
391 vectors_irq0123, NULL, mask_registers,
392 prio_registers, sense_registers, ack_registers);
393
394static DECLARE_INTC_DESC_ACK(intc_desc_irq4567, "sh7786-irq4567",
395 vectors_irq4567, NULL, mask_registers,
396 prio_registers, sense_registers, ack_registers);
397
398/* External interrupt pins in IRL mode */
399
400static struct intc_vect vectors_irl0123[] __initdata = {
401 INTC_VECT(IRL0_LLLL, 0x200), INTC_VECT(IRL0_LLLH, 0x220),
402 INTC_VECT(IRL0_LLHL, 0x240), INTC_VECT(IRL0_LLHH, 0x260),
403 INTC_VECT(IRL0_LHLL, 0x280), INTC_VECT(IRL0_LHLH, 0x2a0),
404 INTC_VECT(IRL0_LHHL, 0x2c0), INTC_VECT(IRL0_LHHH, 0x2e0),
405 INTC_VECT(IRL0_HLLL, 0x300), INTC_VECT(IRL0_HLLH, 0x320),
406 INTC_VECT(IRL0_HLHL, 0x340), INTC_VECT(IRL0_HLHH, 0x360),
407 INTC_VECT(IRL0_HHLL, 0x380), INTC_VECT(IRL0_HHLH, 0x3a0),
408 INTC_VECT(IRL0_HHHL, 0x3c0),
409};
410
411static struct intc_vect vectors_irl4567[] __initdata = {
412 INTC_VECT(IRL4_LLLL, 0x900), INTC_VECT(IRL4_LLLH, 0x920),
413 INTC_VECT(IRL4_LLHL, 0x940), INTC_VECT(IRL4_LLHH, 0x960),
414 INTC_VECT(IRL4_LHLL, 0x980), INTC_VECT(IRL4_LHLH, 0x9a0),
415 INTC_VECT(IRL4_LHHL, 0x9c0), INTC_VECT(IRL4_LHHH, 0x9e0),
416 INTC_VECT(IRL4_HLLL, 0xa00), INTC_VECT(IRL4_HLLH, 0xa20),
417 INTC_VECT(IRL4_HLHL, 0xa40), INTC_VECT(IRL4_HLHH, 0xa60),
418 INTC_VECT(IRL4_HHLL, 0xa80), INTC_VECT(IRL4_HHLH, 0xaa0),
419 INTC_VECT(IRL4_HHHL, 0xac0),
420};
421
422static DECLARE_INTC_DESC(intc_desc_irl0123, "sh7786-irl0123", vectors_irl0123,
423 NULL, mask_registers, NULL, NULL);
424
425static DECLARE_INTC_DESC(intc_desc_irl4567, "sh7786-irl4567", vectors_irl4567,
426 NULL, mask_registers, NULL, NULL);
427
428#define INTC_ICR0 0xfe410000
429#define INTC_INTMSK0 CnINTMSK0
430#define INTC_INTMSK1 CnINTMSK1
431#define INTC_INTMSK2 INTMSK2
432#define INTC_INTMSKCLR1 CnINTMSKCLR1
433#define INTC_INTMSKCLR2 INTMSKCLR2
434
435void __init plat_irq_setup(void)
436{
437 /* disable IRQ3-0 + IRQ7-4 */
438 ctrl_outl(0xff000000, INTC_INTMSK0);
439
440 /* disable IRL3-0 + IRL7-4 */
441 ctrl_outl(0xc0000000, INTC_INTMSK1);
442 ctrl_outl(0xfffefffe, INTC_INTMSK2);
443
444 /* select IRL mode for IRL3-0 + IRL7-4 */
445 ctrl_outl(ctrl_inl(INTC_ICR0) & ~0x00c00000, INTC_ICR0);
446
447 register_intc_controller(&intc_desc);
448}
449
450void __init plat_irq_setup_pins(int mode)
451{
452 switch (mode) {
453 case IRQ_MODE_IRQ7654:
454 /* select IRQ mode for IRL7-4 */
455 ctrl_outl(ctrl_inl(INTC_ICR0) | 0x00400000, INTC_ICR0);
456 register_intc_controller(&intc_desc_irq4567);
457 break;
458 case IRQ_MODE_IRQ3210:
459 /* select IRQ mode for IRL3-0 */
460 ctrl_outl(ctrl_inl(INTC_ICR0) | 0x00800000, INTC_ICR0);
461 register_intc_controller(&intc_desc_irq0123);
462 break;
463 case IRQ_MODE_IRL7654:
464 /* enable IRL7-4 but don't provide any masking */
465 ctrl_outl(0x40000000, INTC_INTMSKCLR1);
466 ctrl_outl(0x0000fffe, INTC_INTMSKCLR2);
467 break;
468 case IRQ_MODE_IRL3210:
469 /* enable IRL0-3 but don't provide any masking */
470 ctrl_outl(0x80000000, INTC_INTMSKCLR1);
471 ctrl_outl(0xfffe0000, INTC_INTMSKCLR2);
472 break;
473 case IRQ_MODE_IRL7654_MASK:
474 /* enable IRL7-4 and mask using cpu intc controller */
475 ctrl_outl(0x40000000, INTC_INTMSKCLR1);
476 register_intc_controller(&intc_desc_irl4567);
477 break;
478 case IRQ_MODE_IRL3210_MASK:
479 /* enable IRL0-3 and mask using cpu intc controller */
480 ctrl_outl(0x80000000, INTC_INTMSKCLR1);
481 register_intc_controller(&intc_desc_irl0123);
482 break;
483 default:
484 BUG();
485 }
486}
487
488void __init plat_mem_setup(void)
489{
490}
diff --git a/arch/sh/kernel/cpu/shmobile/Makefile b/arch/sh/kernel/cpu/shmobile/Makefile
new file mode 100644
index 000000000000..08bfa7c7db29
--- /dev/null
+++ b/arch/sh/kernel/cpu/shmobile/Makefile
@@ -0,0 +1,6 @@
1#
2# Makefile for the Linux/SuperH SH-Mobile backends.
3#
4
5# Power Management & Sleep mode
6obj-$(CONFIG_PM) += pm.o sleep.o
diff --git a/arch/sh/kernel/cpu/shmobile/pm.c b/arch/sh/kernel/cpu/shmobile/pm.c
new file mode 100644
index 000000000000..8c067adf6830
--- /dev/null
+++ b/arch/sh/kernel/cpu/shmobile/pm.c
@@ -0,0 +1,92 @@
1/*
2 * arch/sh/kernel/cpu/sh4a/pm-sh_mobile.c
3 *
4 * Power management support code for SuperH Mobile
5 *
6 * Copyright (C) 2009 Magnus Damm
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/io.h>
15#include <linux/suspend.h>
16#include <asm/suspend.h>
17#include <asm/uaccess.h>
18
19/*
20 * Sleep modes available on SuperH Mobile:
21 *
22 * Sleep mode is just plain "sleep" instruction
23 * Sleep Self-Refresh mode is above plus RAM put in Self-Refresh
24 * Standby Self-Refresh mode is above plus stopped clocks
25 */
26#define SUSP_MODE_SLEEP (SUSP_SH_SLEEP)
27#define SUSP_MODE_SLEEP_SF (SUSP_SH_SLEEP | SUSP_SH_SF)
28#define SUSP_MODE_STANDBY_SF (SUSP_SH_STANDBY | SUSP_SH_SF)
29
30/*
31 * The following modes are not there yet:
32 *
33 * R-standby mode is unsupported, but will be added in the future
34 * U-standby mode is low priority since it needs bootloader hacks
35 *
36 * All modes should be tied in with cpuidle. But before that can
37 * happen we need to keep track of enabled hardware blocks so we
38 * can avoid entering sleep modes that stop clocks to hardware
39 * blocks that are in use even though the cpu core is idle.
40 */
41
42extern const unsigned char sh_mobile_standby[];
43extern const unsigned int sh_mobile_standby_size;
44
45static void sh_mobile_call_standby(unsigned long mode)
46{
47 extern void *vbr_base;
48 void *onchip_mem = (void *)0xe5200000; /* ILRAM */
49 void (*standby_onchip_mem)(unsigned long) = onchip_mem;
50
51 /* Note: Wake up from sleep may generate exceptions!
52 * Setup VBR to point to on-chip ram if self-refresh is
53 * going to be used.
54 */
55 if (mode & SUSP_SH_SF)
56 asm volatile("ldc %0, vbr" : : "r" (onchip_mem) : "memory");
57
58 /* Copy the assembly snippet to the otherwise ununsed ILRAM */
59 memcpy(onchip_mem, sh_mobile_standby, sh_mobile_standby_size);
60 wmb();
61 ctrl_barrier();
62
63 /* Let assembly snippet in on-chip memory handle the rest */
64 standby_onchip_mem(mode);
65
66 /* Put VBR back in System RAM again */
67 if (mode & SUSP_SH_SF)
68 asm volatile("ldc %0, vbr" : : "r" (&vbr_base) : "memory");
69}
70
71static int sh_pm_enter(suspend_state_t state)
72{
73 local_irq_disable();
74 set_bl_bit();
75 sh_mobile_call_standby(SUSP_MODE_STANDBY_SF);
76 local_irq_disable();
77 clear_bl_bit();
78 return 0;
79}
80
81static struct platform_suspend_ops sh_pm_ops = {
82 .enter = sh_pm_enter,
83 .valid = suspend_valid_only_mem,
84};
85
86static int __init sh_pm_init(void)
87{
88 suspend_set_ops(&sh_pm_ops);
89 return 0;
90}
91
92late_initcall(sh_pm_init);
diff --git a/arch/sh/kernel/cpu/shmobile/sleep.S b/arch/sh/kernel/cpu/shmobile/sleep.S
new file mode 100644
index 000000000000..5d888ef53d82
--- /dev/null
+++ b/arch/sh/kernel/cpu/shmobile/sleep.S
@@ -0,0 +1,125 @@
1/*
2 * arch/sh/kernel/cpu/sh4a/sleep-sh_mobile.S
3 *
4 * Sleep mode and Standby modes support for SuperH Mobile
5 *
6 * Copyright (C) 2009 Magnus Damm
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12
13#include <linux/sys.h>
14#include <linux/errno.h>
15#include <linux/linkage.h>
16#include <asm/asm-offsets.h>
17#include <asm/suspend.h>
18
19/* manage self-refresh and enter standby mode.
20 * this code will be copied to on-chip memory and executed from there.
21 */
22
23 .balign 4096,0,4096
24ENTRY(sh_mobile_standby)
25 mov r4, r0
26
27 tst #SUSP_SH_SF, r0
28 bt skip_set_sf
29
30 /* SDRAM: disable power down and put in self-refresh mode */
31 mov.l 1f, r4
32 mov.l 2f, r1
33 mov.l @r4, r2
34 or r1, r2
35 mov.l 3f, r3
36 and r3, r2
37 mov.l r2, @r4
38
39skip_set_sf:
40 tst #SUSP_SH_SLEEP, r0
41 bt test_standby
42
43 /* set mode to "sleep mode" */
44 bra do_sleep
45 mov #0x00, r1
46
47test_standby:
48 tst #SUSP_SH_STANDBY, r0
49 bt test_rstandby
50
51 /* set mode to "software standby mode" */
52 bra do_sleep
53 mov #0x80, r1
54
55test_rstandby:
56 tst #SUSP_SH_RSTANDBY, r0
57 bt test_ustandby
58
59 /* set mode to "r-standby mode" */
60 bra do_sleep
61 mov #0x20, r1
62
63test_ustandby:
64 tst #SUSP_SH_USTANDBY, r0
65 bt done_sleep
66
67 /* set mode to "u-standby mode" */
68 mov #0x10, r1
69
70 /* fall-through */
71
72do_sleep:
73 /* setup and enter selected standby mode */
74 mov.l 5f, r4
75 mov.l r1, @r4
76 sleep
77
78done_sleep:
79 /* reset standby mode to sleep mode */
80 mov.l 5f, r4
81 mov #0x00, r1
82 mov.l r1, @r4
83
84 tst #SUSP_SH_SF, r0
85 bt skip_restore_sf
86
87 /* SDRAM: set auto-refresh mode */
88 mov.l 1f, r4
89 mov.l @r4, r2
90 mov.l 4f, r3
91 and r3, r2
92 mov.l r2, @r4
93 mov.l 6f, r4
94 mov.l 7f, r1
95 mov.l 8f, r2
96 mov.l @r4, r3
97 mov #-1, r4
98 add r4, r3
99 or r2, r3
100 mov.l r3, @r1
101skip_restore_sf:
102 rts
103 nop
104
105 .balign 4
1061: .long 0xfe400008 /* SDCR0 */
1072: .long 0x00000400
1083: .long 0xffff7fff
1094: .long 0xfffffbff
1105: .long 0xa4150020 /* STBCR */
1116: .long 0xfe40001c /* RTCOR */
1127: .long 0xfe400018 /* RTCNT */
1138: .long 0xa55a0000
114
115/* interrupt vector @ 0x600 */
116 .balign 0x400,0,0x400
117 .long 0xdeadbeef
118 .balign 0x200,0,0x200
119 /* sh7722 will end up here in sleep mode */
120 rte
121 nop
122sh_mobile_standby_end:
123
124ENTRY(sh_mobile_standby_size)
125 .long sh_mobile_standby_end - sh_mobile_standby
diff --git a/arch/sh/kernel/gpio.c b/arch/sh/kernel/gpio.c
index d37165361034..d22e5af699f9 100644
--- a/arch/sh/kernel/gpio.c
+++ b/arch/sh/kernel/gpio.c
@@ -19,36 +19,75 @@
19#include <linux/bitops.h> 19#include <linux/bitops.h>
20#include <linux/gpio.h> 20#include <linux/gpio.h>
21 21
22static struct pinmux_info *registered_gpio; 22static int enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r)
23{
24 if (enum_id < r->begin)
25 return 0;
23 26
24static struct pinmux_info *gpio_controller(unsigned gpio) 27 if (enum_id > r->end)
28 return 0;
29
30 return 1;
31}
32
33static unsigned long gpio_read_raw_reg(unsigned long reg,
34 unsigned long reg_width)
25{ 35{
26 if (!registered_gpio) 36 switch (reg_width) {
27 return NULL; 37 case 8:
38 return ctrl_inb(reg);
39 case 16:
40 return ctrl_inw(reg);
41 case 32:
42 return ctrl_inl(reg);
43 }
28 44
29 if (gpio < registered_gpio->first_gpio) 45 BUG();
30 return NULL; 46 return 0;
47}
31 48
32 if (gpio > registered_gpio->last_gpio) 49static void gpio_write_raw_reg(unsigned long reg,
33 return NULL; 50 unsigned long reg_width,
51 unsigned long data)
52{
53 switch (reg_width) {
54 case 8:
55 ctrl_outb(data, reg);
56 return;
57 case 16:
58 ctrl_outw(data, reg);
59 return;
60 case 32:
61 ctrl_outl(data, reg);
62 return;
63 }
34 64
35 return registered_gpio; 65 BUG();
36} 66}
37 67
38static int enum_in_range(pinmux_enum_t enum_id, struct pinmux_range *r) 68static void gpio_write_bit(struct pinmux_data_reg *dr,
69 unsigned long in_pos, unsigned long value)
39{ 70{
40 if (enum_id < r->begin) 71 unsigned long pos;
41 return 0;
42 72
43 if (enum_id > r->end) 73 pos = dr->reg_width - (in_pos + 1);
44 return 0;
45 74
46 return 1; 75#ifdef DEBUG
76 pr_info("write_bit addr = %lx, value = %ld, pos = %ld, "
77 "r_width = %ld\n",
78 dr->reg, !!value, pos, dr->reg_width);
79#endif
80
81 if (value)
82 set_bit(pos, &dr->reg_shadow);
83 else
84 clear_bit(pos, &dr->reg_shadow);
85
86 gpio_write_raw_reg(dr->reg, dr->reg_width, dr->reg_shadow);
47} 87}
48 88
49static int read_write_reg(unsigned long reg, unsigned long reg_width, 89static int gpio_read_reg(unsigned long reg, unsigned long reg_width,
50 unsigned long field_width, unsigned long in_pos, 90 unsigned long field_width, unsigned long in_pos)
51 unsigned long value, int do_write)
52{ 91{
53 unsigned long data, mask, pos; 92 unsigned long data, mask, pos;
54 93
@@ -57,52 +96,53 @@ static int read_write_reg(unsigned long reg, unsigned long reg_width,
57 pos = reg_width - ((in_pos + 1) * field_width); 96 pos = reg_width - ((in_pos + 1) * field_width);
58 97
59#ifdef DEBUG 98#ifdef DEBUG
60 pr_info("%s, addr = %lx, value = %ld, pos = %ld, " 99 pr_info("read_reg: addr = %lx, pos = %ld, "
61 "r_width = %ld, f_width = %ld\n", 100 "r_width = %ld, f_width = %ld\n",
62 do_write ? "write" : "read", reg, value, pos, 101 reg, pos, reg_width, field_width);
63 reg_width, field_width);
64#endif 102#endif
65 103
66 switch (reg_width) { 104 data = gpio_read_raw_reg(reg, reg_width);
67 case 8: 105 return (data >> pos) & mask;
68 data = ctrl_inb(reg); 106}
69 break;
70 case 16:
71 data = ctrl_inw(reg);
72 break;
73 case 32:
74 data = ctrl_inl(reg);
75 break;
76 }
77 107
78 if (!do_write) 108static void gpio_write_reg(unsigned long reg, unsigned long reg_width,
79 return (data >> pos) & mask; 109 unsigned long field_width, unsigned long in_pos,
110 unsigned long value)
111{
112 unsigned long mask, pos;
80 113
81 data &= ~(mask << pos); 114 mask = (1 << field_width) - 1;
82 data |= value << pos; 115 pos = reg_width - ((in_pos + 1) * field_width);
116
117#ifdef DEBUG
118 pr_info("write_reg addr = %lx, value = %ld, pos = %ld, "
119 "r_width = %ld, f_width = %ld\n",
120 reg, value, pos, reg_width, field_width);
121#endif
122
123 mask = ~(mask << pos);
124 value = value << pos;
83 125
84 switch (reg_width) { 126 switch (reg_width) {
85 case 8: 127 case 8:
86 ctrl_outb(data, reg); 128 ctrl_outb((ctrl_inb(reg) & mask) | value, reg);
87 break; 129 break;
88 case 16: 130 case 16:
89 ctrl_outw(data, reg); 131 ctrl_outw((ctrl_inw(reg) & mask) | value, reg);
90 break; 132 break;
91 case 32: 133 case 32:
92 ctrl_outl(data, reg); 134 ctrl_outl((ctrl_inl(reg) & mask) | value, reg);
93 break; 135 break;
94 } 136 }
95 return 0;
96} 137}
97 138
98static int get_data_reg(struct pinmux_info *gpioc, unsigned gpio, 139static int setup_data_reg(struct pinmux_info *gpioc, unsigned gpio)
99 struct pinmux_data_reg **drp, int *bitp)
100{ 140{
101 pinmux_enum_t enum_id = gpioc->gpios[gpio].enum_id; 141 struct pinmux_gpio *gpiop = &gpioc->gpios[gpio];
102 struct pinmux_data_reg *data_reg; 142 struct pinmux_data_reg *data_reg;
103 int k, n; 143 int k, n;
104 144
105 if (!enum_in_range(enum_id, &gpioc->data)) 145 if (!enum_in_range(gpiop->enum_id, &gpioc->data))
106 return -1; 146 return -1;
107 147
108 k = 0; 148 k = 0;
@@ -113,19 +153,58 @@ static int get_data_reg(struct pinmux_info *gpioc, unsigned gpio,
113 break; 153 break;
114 154
115 for (n = 0; n < data_reg->reg_width; n++) { 155 for (n = 0; n < data_reg->reg_width; n++) {
116 if (data_reg->enum_ids[n] == enum_id) { 156 if (data_reg->enum_ids[n] == gpiop->enum_id) {
117 *drp = data_reg; 157 gpiop->flags &= ~PINMUX_FLAG_DREG;
118 *bitp = n; 158 gpiop->flags |= (k << PINMUX_FLAG_DREG_SHIFT);
159 gpiop->flags &= ~PINMUX_FLAG_DBIT;
160 gpiop->flags |= (n << PINMUX_FLAG_DBIT_SHIFT);
119 return 0; 161 return 0;
120
121 } 162 }
122 } 163 }
123 k++; 164 k++;
124 } 165 }
125 166
167 BUG();
168
126 return -1; 169 return -1;
127} 170}
128 171
172static void setup_data_regs(struct pinmux_info *gpioc)
173{
174 struct pinmux_data_reg *drp;
175 int k;
176
177 for (k = gpioc->first_gpio; k <= gpioc->last_gpio; k++)
178 setup_data_reg(gpioc, k);
179
180 k = 0;
181 while (1) {
182 drp = gpioc->data_regs + k;
183
184 if (!drp->reg_width)
185 break;
186
187 drp->reg_shadow = gpio_read_raw_reg(drp->reg, drp->reg_width);
188 k++;
189 }
190}
191
192static int get_data_reg(struct pinmux_info *gpioc, unsigned gpio,
193 struct pinmux_data_reg **drp, int *bitp)
194{
195 struct pinmux_gpio *gpiop = &gpioc->gpios[gpio];
196 int k, n;
197
198 if (!enum_in_range(gpiop->enum_id, &gpioc->data))
199 return -1;
200
201 k = (gpiop->flags & PINMUX_FLAG_DREG) >> PINMUX_FLAG_DREG_SHIFT;
202 n = (gpiop->flags & PINMUX_FLAG_DBIT) >> PINMUX_FLAG_DBIT_SHIFT;
203 *drp = gpioc->data_regs + k;
204 *bitp = n;
205 return 0;
206}
207
129static int get_config_reg(struct pinmux_info *gpioc, pinmux_enum_t enum_id, 208static int get_config_reg(struct pinmux_info *gpioc, pinmux_enum_t enum_id,
130 struct pinmux_cfg_reg **crp, int *indexp, 209 struct pinmux_cfg_reg **crp, int *indexp,
131 unsigned long **cntp) 210 unsigned long **cntp)
@@ -187,9 +266,9 @@ static int get_gpio_enum_id(struct pinmux_info *gpioc, unsigned gpio,
187 return -1; 266 return -1;
188} 267}
189 268
190static int write_config_reg(struct pinmux_info *gpioc, 269static void write_config_reg(struct pinmux_info *gpioc,
191 struct pinmux_cfg_reg *crp, 270 struct pinmux_cfg_reg *crp,
192 int index) 271 int index)
193{ 272{
194 unsigned long ncomb, pos, value; 273 unsigned long ncomb, pos, value;
195 274
@@ -197,8 +276,7 @@ static int write_config_reg(struct pinmux_info *gpioc,
197 pos = index / ncomb; 276 pos = index / ncomb;
198 value = index % ncomb; 277 value = index % ncomb;
199 278
200 return read_write_reg(crp->reg, crp->reg_width, 279 gpio_write_reg(crp->reg, crp->reg_width, crp->field_width, pos, value);
201 crp->field_width, pos, value, 1);
202} 280}
203 281
204static int check_config_reg(struct pinmux_info *gpioc, 282static int check_config_reg(struct pinmux_info *gpioc,
@@ -211,8 +289,8 @@ static int check_config_reg(struct pinmux_info *gpioc,
211 pos = index / ncomb; 289 pos = index / ncomb;
212 value = index % ncomb; 290 value = index % ncomb;
213 291
214 if (read_write_reg(crp->reg, crp->reg_width, 292 if (gpio_read_reg(crp->reg, crp->reg_width,
215 crp->field_width, pos, 0, 0) == value) 293 crp->field_width, pos) == value)
216 return 0; 294 return 0;
217 295
218 return -1; 296 return -1;
@@ -220,8 +298,8 @@ static int check_config_reg(struct pinmux_info *gpioc,
220 298
221enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE }; 299enum { GPIO_CFG_DRYRUN, GPIO_CFG_REQ, GPIO_CFG_FREE };
222 300
223int pinmux_config_gpio(struct pinmux_info *gpioc, unsigned gpio, 301static int pinmux_config_gpio(struct pinmux_info *gpioc, unsigned gpio,
224 int pinmux_type, int cfg_mode) 302 int pinmux_type, int cfg_mode)
225{ 303{
226 struct pinmux_cfg_reg *cr = NULL; 304 struct pinmux_cfg_reg *cr = NULL;
227 pinmux_enum_t enum_id; 305 pinmux_enum_t enum_id;
@@ -287,8 +365,7 @@ int pinmux_config_gpio(struct pinmux_info *gpioc, unsigned gpio,
287 break; 365 break;
288 366
289 case GPIO_CFG_REQ: 367 case GPIO_CFG_REQ:
290 if (write_config_reg(gpioc, cr, index) != 0) 368 write_config_reg(gpioc, cr, index);
291 goto out_err;
292 *cntp = *cntp + 1; 369 *cntp = *cntp + 1;
293 break; 370 break;
294 371
@@ -305,9 +382,14 @@ int pinmux_config_gpio(struct pinmux_info *gpioc, unsigned gpio,
305 382
306static DEFINE_SPINLOCK(gpio_lock); 383static DEFINE_SPINLOCK(gpio_lock);
307 384
308int __gpio_request(unsigned gpio) 385static struct pinmux_info *chip_to_pinmux(struct gpio_chip *chip)
309{ 386{
310 struct pinmux_info *gpioc = gpio_controller(gpio); 387 return container_of(chip, struct pinmux_info, chip);
388}
389
390static int sh_gpio_request(struct gpio_chip *chip, unsigned offset)
391{
392 struct pinmux_info *gpioc = chip_to_pinmux(chip);
311 struct pinmux_data_reg *dummy; 393 struct pinmux_data_reg *dummy;
312 unsigned long flags; 394 unsigned long flags;
313 int i, ret, pinmux_type; 395 int i, ret, pinmux_type;
@@ -319,29 +401,30 @@ int __gpio_request(unsigned gpio)
319 401
320 spin_lock_irqsave(&gpio_lock, flags); 402 spin_lock_irqsave(&gpio_lock, flags);
321 403
322 if ((gpioc->gpios[gpio].flags & PINMUX_FLAG_TYPE) != PINMUX_TYPE_NONE) 404 if ((gpioc->gpios[offset].flags & PINMUX_FLAG_TYPE) != PINMUX_TYPE_NONE)
323 goto err_unlock; 405 goto err_unlock;
324 406
325 /* setup pin function here if no data is associated with pin */ 407 /* setup pin function here if no data is associated with pin */
326 408
327 if (get_data_reg(gpioc, gpio, &dummy, &i) != 0) 409 if (get_data_reg(gpioc, offset, &dummy, &i) != 0)
328 pinmux_type = PINMUX_TYPE_FUNCTION; 410 pinmux_type = PINMUX_TYPE_FUNCTION;
329 else 411 else
330 pinmux_type = PINMUX_TYPE_GPIO; 412 pinmux_type = PINMUX_TYPE_GPIO;
331 413
332 if (pinmux_type == PINMUX_TYPE_FUNCTION) { 414 if (pinmux_type == PINMUX_TYPE_FUNCTION) {
333 if (pinmux_config_gpio(gpioc, gpio, 415 if (pinmux_config_gpio(gpioc, offset,
334 pinmux_type, 416 pinmux_type,
335 GPIO_CFG_DRYRUN) != 0) 417 GPIO_CFG_DRYRUN) != 0)
336 goto err_unlock; 418 goto err_unlock;
337 419
338 if (pinmux_config_gpio(gpioc, gpio, 420 if (pinmux_config_gpio(gpioc, offset,
339 pinmux_type, 421 pinmux_type,
340 GPIO_CFG_REQ) != 0) 422 GPIO_CFG_REQ) != 0)
341 BUG(); 423 BUG();
342 } 424 }
343 425
344 gpioc->gpios[gpio].flags = pinmux_type; 426 gpioc->gpios[offset].flags &= ~PINMUX_FLAG_TYPE;
427 gpioc->gpios[offset].flags |= pinmux_type;
345 428
346 ret = 0; 429 ret = 0;
347 err_unlock: 430 err_unlock:
@@ -349,11 +432,10 @@ int __gpio_request(unsigned gpio)
349 err_out: 432 err_out:
350 return ret; 433 return ret;
351} 434}
352EXPORT_SYMBOL(__gpio_request);
353 435
354void gpio_free(unsigned gpio) 436static void sh_gpio_free(struct gpio_chip *chip, unsigned offset)
355{ 437{
356 struct pinmux_info *gpioc = gpio_controller(gpio); 438 struct pinmux_info *gpioc = chip_to_pinmux(chip);
357 unsigned long flags; 439 unsigned long flags;
358 int pinmux_type; 440 int pinmux_type;
359 441
@@ -362,20 +444,23 @@ void gpio_free(unsigned gpio)
362 444
363 spin_lock_irqsave(&gpio_lock, flags); 445 spin_lock_irqsave(&gpio_lock, flags);
364 446
365 pinmux_type = gpioc->gpios[gpio].flags & PINMUX_FLAG_TYPE; 447 pinmux_type = gpioc->gpios[offset].flags & PINMUX_FLAG_TYPE;
366 pinmux_config_gpio(gpioc, gpio, pinmux_type, GPIO_CFG_FREE); 448 pinmux_config_gpio(gpioc, offset, pinmux_type, GPIO_CFG_FREE);
367 gpioc->gpios[gpio].flags = PINMUX_TYPE_NONE; 449 gpioc->gpios[offset].flags &= ~PINMUX_FLAG_TYPE;
450 gpioc->gpios[offset].flags |= PINMUX_TYPE_NONE;
368 451
369 spin_unlock_irqrestore(&gpio_lock, flags); 452 spin_unlock_irqrestore(&gpio_lock, flags);
370} 453}
371EXPORT_SYMBOL(gpio_free);
372 454
373static int pinmux_direction(struct pinmux_info *gpioc, 455static int pinmux_direction(struct pinmux_info *gpioc,
374 unsigned gpio, int new_pinmux_type) 456 unsigned gpio, int new_pinmux_type)
375{ 457{
376 int ret, pinmux_type; 458 int pinmux_type;
459 int ret = -EINVAL;
460
461 if (!gpioc)
462 goto err_out;
377 463
378 ret = -EINVAL;
379 pinmux_type = gpioc->gpios[gpio].flags & PINMUX_FLAG_TYPE; 464 pinmux_type = gpioc->gpios[gpio].flags & PINMUX_FLAG_TYPE;
380 465
381 switch (pinmux_type) { 466 switch (pinmux_type) {
@@ -401,102 +486,99 @@ static int pinmux_direction(struct pinmux_info *gpioc,
401 GPIO_CFG_REQ) != 0) 486 GPIO_CFG_REQ) != 0)
402 BUG(); 487 BUG();
403 488
404 gpioc->gpios[gpio].flags = new_pinmux_type; 489 gpioc->gpios[gpio].flags &= ~PINMUX_FLAG_TYPE;
490 gpioc->gpios[gpio].flags |= new_pinmux_type;
405 491
406 ret = 0; 492 ret = 0;
407 err_out: 493 err_out:
408 return ret; 494 return ret;
409} 495}
410 496
411int gpio_direction_input(unsigned gpio) 497static int sh_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
412{ 498{
413 struct pinmux_info *gpioc = gpio_controller(gpio); 499 struct pinmux_info *gpioc = chip_to_pinmux(chip);
414 unsigned long flags; 500 unsigned long flags;
415 int ret = -EINVAL; 501 int ret;
416
417 if (!gpioc)
418 goto err_out;
419 502
420 spin_lock_irqsave(&gpio_lock, flags); 503 spin_lock_irqsave(&gpio_lock, flags);
421 ret = pinmux_direction(gpioc, gpio, PINMUX_TYPE_INPUT); 504 ret = pinmux_direction(gpioc, offset, PINMUX_TYPE_INPUT);
422 spin_unlock_irqrestore(&gpio_lock, flags); 505 spin_unlock_irqrestore(&gpio_lock, flags);
423 err_out: 506
424 return ret; 507 return ret;
425} 508}
426EXPORT_SYMBOL(gpio_direction_input);
427 509
428static int __gpio_get_set_value(struct pinmux_info *gpioc, 510static void sh_gpio_set_value(struct pinmux_info *gpioc,
429 unsigned gpio, int value, 511 unsigned gpio, int value)
430 int do_write)
431{ 512{
432 struct pinmux_data_reg *dr = NULL; 513 struct pinmux_data_reg *dr = NULL;
433 int bit = 0; 514 int bit = 0;
434 515
435 if (get_data_reg(gpioc, gpio, &dr, &bit) != 0) 516 if (!gpioc || get_data_reg(gpioc, gpio, &dr, &bit) != 0)
436 BUG(); 517 BUG();
437 else 518 else
438 value = read_write_reg(dr->reg, dr->reg_width, 519 gpio_write_bit(dr, bit, value);
439 1, bit, !!value, do_write);
440
441 return value;
442} 520}
443 521
444int gpio_direction_output(unsigned gpio, int value) 522static int sh_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
523 int value)
445{ 524{
446 struct pinmux_info *gpioc = gpio_controller(gpio); 525 struct pinmux_info *gpioc = chip_to_pinmux(chip);
447 unsigned long flags; 526 unsigned long flags;
448 int ret = -EINVAL; 527 int ret;
449
450 if (!gpioc)
451 goto err_out;
452 528
529 sh_gpio_set_value(gpioc, offset, value);
453 spin_lock_irqsave(&gpio_lock, flags); 530 spin_lock_irqsave(&gpio_lock, flags);
454 __gpio_get_set_value(gpioc, gpio, value, 1); 531 ret = pinmux_direction(gpioc, offset, PINMUX_TYPE_OUTPUT);
455 ret = pinmux_direction(gpioc, gpio, PINMUX_TYPE_OUTPUT);
456 spin_unlock_irqrestore(&gpio_lock, flags); 532 spin_unlock_irqrestore(&gpio_lock, flags);
457 err_out: 533
458 return ret; 534 return ret;
459} 535}
460EXPORT_SYMBOL(gpio_direction_output);
461 536
462int gpio_get_value(unsigned gpio) 537static int sh_gpio_get_value(struct pinmux_info *gpioc, unsigned gpio)
463{ 538{
464 struct pinmux_info *gpioc = gpio_controller(gpio); 539 struct pinmux_data_reg *dr = NULL;
465 unsigned long flags; 540 int bit = 0;
466 int value = 0;
467 541
468 if (!gpioc) 542 if (!gpioc || get_data_reg(gpioc, gpio, &dr, &bit) != 0) {
469 BUG(); 543 BUG();
470 else { 544 return 0;
471 spin_lock_irqsave(&gpio_lock, flags);
472 value = __gpio_get_set_value(gpioc, gpio, 0, 0);
473 spin_unlock_irqrestore(&gpio_lock, flags);
474 } 545 }
475 546
476 return value; 547 return gpio_read_reg(dr->reg, dr->reg_width, 1, bit);
477} 548}
478EXPORT_SYMBOL(gpio_get_value);
479 549
480void gpio_set_value(unsigned gpio, int value) 550static int sh_gpio_get(struct gpio_chip *chip, unsigned offset)
481{ 551{
482 struct pinmux_info *gpioc = gpio_controller(gpio); 552 return sh_gpio_get_value(chip_to_pinmux(chip), offset);
483 unsigned long flags; 553}
484 554
485 if (!gpioc) 555static void sh_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
486 BUG(); 556{
487 else { 557 sh_gpio_set_value(chip_to_pinmux(chip), offset, value);
488 spin_lock_irqsave(&gpio_lock, flags);
489 __gpio_get_set_value(gpioc, gpio, value, 1);
490 spin_unlock_irqrestore(&gpio_lock, flags);
491 }
492} 558}
493EXPORT_SYMBOL(gpio_set_value);
494 559
495int register_pinmux(struct pinmux_info *pip) 560int register_pinmux(struct pinmux_info *pip)
496{ 561{
497 registered_gpio = pip; 562 struct gpio_chip *chip = &pip->chip;
498 pr_info("pinmux: %s handling gpio %d -> %d\n", 563
564 pr_info("sh pinmux: %s handling gpio %d -> %d\n",
499 pip->name, pip->first_gpio, pip->last_gpio); 565 pip->name, pip->first_gpio, pip->last_gpio);
500 566
501 return 0; 567 setup_data_regs(pip);
568
569 chip->request = sh_gpio_request;
570 chip->free = sh_gpio_free;
571 chip->direction_input = sh_gpio_direction_input;
572 chip->get = sh_gpio_get;
573 chip->direction_output = sh_gpio_direction_output;
574 chip->set = sh_gpio_set;
575
576 WARN_ON(pip->first_gpio != 0); /* needs testing */
577
578 chip->label = pip->name;
579 chip->owner = THIS_MODULE;
580 chip->base = pip->first_gpio;
581 chip->ngpio = (pip->last_gpio - pip->first_gpio) + 1;
582
583 return gpiochip_add(chip);
502} 584}
diff --git a/arch/sh/kernel/irq.c b/arch/sh/kernel/irq.c
index 64b7690c664c..90d63aefd275 100644
--- a/arch/sh/kernel/irq.c
+++ b/arch/sh/kernel/irq.c
@@ -106,7 +106,7 @@ asmlinkage int do_IRQ(unsigned int irq, struct pt_regs *regs)
106 } 106 }
107#endif 107#endif
108 108
109 irq = irq_demux(evt2irq(irq)); 109 irq = irq_demux(intc_evt2irq(irq));
110 110
111#ifdef CONFIG_IRQSTACKS 111#ifdef CONFIG_IRQSTACKS
112 curctx = (union irq_ctx *)current_thread_info(); 112 curctx = (union irq_ctx *)current_thread_info();
diff --git a/arch/sh/kernel/machine_kexec.c b/arch/sh/kernel/machine_kexec.c
index 94df56b0d1f6..7ea2704ea033 100644
--- a/arch/sh/kernel/machine_kexec.c
+++ b/arch/sh/kernel/machine_kexec.c
@@ -14,21 +14,22 @@
14#include <linux/delay.h> 14#include <linux/delay.h>
15#include <linux/reboot.h> 15#include <linux/reboot.h>
16#include <linux/numa.h> 16#include <linux/numa.h>
17#include <linux/ftrace.h>
18#include <linux/suspend.h>
17#include <asm/pgtable.h> 19#include <asm/pgtable.h>
18#include <asm/pgalloc.h> 20#include <asm/pgalloc.h>
19#include <asm/mmu_context.h> 21#include <asm/mmu_context.h>
20#include <asm/io.h> 22#include <asm/io.h>
21#include <asm/cacheflush.h> 23#include <asm/cacheflush.h>
22 24
23typedef NORET_TYPE void (*relocate_new_kernel_t)( 25typedef void (*relocate_new_kernel_t)(unsigned long indirection_page,
24 unsigned long indirection_page, 26 unsigned long reboot_code_buffer,
25 unsigned long reboot_code_buffer, 27 unsigned long start_address);
26 unsigned long start_address,
27 unsigned long vbr_reg) ATTRIB_NORET;
28 28
29extern const unsigned char relocate_new_kernel[]; 29extern const unsigned char relocate_new_kernel[];
30extern const unsigned int relocate_new_kernel_size; 30extern const unsigned int relocate_new_kernel_size;
31extern void *gdb_vbr_vector; 31extern void *gdb_vbr_vector;
32extern void *vbr_base;
32 33
33void machine_shutdown(void) 34void machine_shutdown(void)
34{ 35{
@@ -45,6 +46,12 @@ void machine_crash_shutdown(struct pt_regs *regs)
45 */ 46 */
46int machine_kexec_prepare(struct kimage *image) 47int machine_kexec_prepare(struct kimage *image)
47{ 48{
49 /* older versions of kexec-tools are passing
50 * the zImage entry point as a virtual address.
51 */
52 if (image->start != PHYSADDR(image->start))
53 return -EINVAL; /* upgrade your kexec-tools */
54
48 return 0; 55 return 0;
49} 56}
50 57
@@ -73,17 +80,33 @@ static void kexec_info(struct kimage *image)
73 */ 80 */
74void machine_kexec(struct kimage *image) 81void machine_kexec(struct kimage *image)
75{ 82{
76
77 unsigned long page_list; 83 unsigned long page_list;
78 unsigned long reboot_code_buffer; 84 unsigned long reboot_code_buffer;
79 unsigned long vbr_reg;
80 relocate_new_kernel_t rnk; 85 relocate_new_kernel_t rnk;
86 unsigned long entry;
87 unsigned long *ptr;
88 int save_ftrace_enabled;
89
90 /*
91 * Nicked from the mips version of machine_kexec():
92 * The generic kexec code builds a page list with physical
93 * addresses. Use phys_to_virt() to convert them to virtual.
94 */
95 for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);
96 ptr = (entry & IND_INDIRECTION) ?
97 phys_to_virt(entry & PAGE_MASK) : ptr + 1) {
98 if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
99 *ptr & IND_DESTINATION)
100 *ptr = (unsigned long) phys_to_virt(*ptr);
101 }
81 102
82#if defined(CONFIG_SH_STANDARD_BIOS) 103#ifdef CONFIG_KEXEC_JUMP
83 vbr_reg = ((unsigned long )gdb_vbr_vector) - 0x100; 104 if (image->preserve_context)
84#else 105 save_processor_state();
85 vbr_reg = 0x80000000; // dummy
86#endif 106#endif
107
108 save_ftrace_enabled = __ftrace_enabled_save();
109
87 /* Interrupts aren't acceptable while we reboot */ 110 /* Interrupts aren't acceptable while we reboot */
88 local_irq_disable(); 111 local_irq_disable();
89 112
@@ -97,12 +120,37 @@ void machine_kexec(struct kimage *image)
97 memcpy((void *)reboot_code_buffer, relocate_new_kernel, 120 memcpy((void *)reboot_code_buffer, relocate_new_kernel,
98 relocate_new_kernel_size); 121 relocate_new_kernel_size);
99 122
100 kexec_info(image); 123 kexec_info(image);
101 flush_cache_all(); 124 flush_cache_all();
102 125
126#if defined(CONFIG_SH_STANDARD_BIOS)
127 asm volatile("ldc %0, vbr" :
128 : "r" (((unsigned long) gdb_vbr_vector) - 0x100)
129 : "memory");
130#endif
131
103 /* now call it */ 132 /* now call it */
104 rnk = (relocate_new_kernel_t) reboot_code_buffer; 133 rnk = (relocate_new_kernel_t) reboot_code_buffer;
105 (*rnk)(page_list, reboot_code_buffer, P2SEGADDR(image->start), vbr_reg); 134 (*rnk)(page_list, reboot_code_buffer,
135 (unsigned long)phys_to_virt(image->start));
136
137#ifdef CONFIG_KEXEC_JUMP
138 asm volatile("ldc %0, vbr" : : "r" (&vbr_base) : "memory");
139
140 if (image->preserve_context)
141 restore_processor_state();
142
143 /* Convert page list back to physical addresses, what a mess. */
144 for (ptr = &image->head; (entry = *ptr) && !(entry & IND_DONE);
145 ptr = (*ptr & IND_INDIRECTION) ?
146 phys_to_virt(*ptr & PAGE_MASK) : ptr + 1) {
147 if (*ptr & IND_SOURCE || *ptr & IND_INDIRECTION ||
148 *ptr & IND_DESTINATION)
149 *ptr = virt_to_phys(*ptr);
150 }
151#endif
152
153 __ftrace_enabled_restore(save_ftrace_enabled);
106} 154}
107 155
108void arch_crash_save_vmcoreinfo(void) 156void arch_crash_save_vmcoreinfo(void)
diff --git a/arch/sh/kernel/relocate_kernel.S b/arch/sh/kernel/relocate_kernel.S
index c66cb3209db5..fcc9934fb97b 100644
--- a/arch/sh/kernel/relocate_kernel.S
+++ b/arch/sh/kernel/relocate_kernel.S
@@ -4,6 +4,8 @@
4 * 4 *
5 * LANDISK/sh4 is supported. Maybe, SH archtecture works well. 5 * LANDISK/sh4 is supported. Maybe, SH archtecture works well.
6 * 6 *
7 * 2009-03-18 Magnus Damm - Added Kexec Jump support
8 *
7 * This source code is licensed under the GNU General Public License, 9 * This source code is licensed under the GNU General Public License,
8 * Version 2. See the file COPYING for more details. 10 * Version 2. See the file COPYING for more details.
9 */ 11 */
@@ -16,23 +18,141 @@ relocate_new_kernel:
16 /* r4 = indirection_page */ 18 /* r4 = indirection_page */
17 /* r5 = reboot_code_buffer */ 19 /* r5 = reboot_code_buffer */
18 /* r6 = start_address */ 20 /* r6 = start_address */
19 /* r7 = vbr_reg */
20 21
21 mov.l 10f,r8 /* PAGE_SIZE */ 22 mov.l 10f, r0 /* PAGE_SIZE */
22 mov.l 11f,r9 /* P2SEG */ 23 add r5, r0 /* setup new stack at end of control page */
24
25 /* save r15->r8 to new stack */
26 mov.l r15, @-r0
27 mov r0, r15
28 mov.l r14, @-r15
29 mov.l r13, @-r15
30 mov.l r12, @-r15
31 mov.l r11, @-r15
32 mov.l r10, @-r15
33 mov.l r9, @-r15
34 mov.l r8, @-r15
35
36 /* save other random registers */
37 sts.l macl, @-r15
38 sts.l mach, @-r15
39 stc.l gbr, @-r15
40 stc.l ssr, @-r15
41 stc.l sr, @-r15
42 sts.l pr, @-r15
43 stc.l spc, @-r15
44
45 /* switch to bank1 and save r7->r0 */
46 mov.l 12f, r9
47 stc sr, r8
48 or r9, r8
49 ldc r8, sr
50 mov.l r7, @-r15
51 mov.l r6, @-r15
52 mov.l r5, @-r15
53 mov.l r4, @-r15
54 mov.l r3, @-r15
55 mov.l r2, @-r15
56 mov.l r1, @-r15
57 mov.l r0, @-r15
58
59 /* switch to bank0 and save r7->r0 */
60 mov.l 12f, r9
61 not r9, r9
62 stc sr, r8
63 and r9, r8
64 ldc r8, sr
65 mov.l r7, @-r15
66 mov.l r6, @-r15
67 mov.l r5, @-r15
68 mov.l r4, @-r15
69 mov.l r3, @-r15
70 mov.l r2, @-r15
71 mov.l r1, @-r15
72 mov.l r0, @-r15
73
74 mov.l r4, @-r15 /* save indirection page again */
75
76 bsr swap_pages /* swap pages before jumping to new kernel */
77 nop
78
79 mova 11f, r0
80 mov.l r15, @r0 /* save pointer to stack */
81
82 jsr @r6 /* hand over control to new kernel */
83 nop
84
85 mov.l 11f, r15 /* get pointer to stack */
86 mov.l @r15+, r4 /* restore r4 to get indirection page */
23 87
24 /* stack setting */ 88 bsr swap_pages /* swap pages back to previous state */
25 add r8,r5 89 nop
26 mov r5,r15
27 90
91 /* make sure bank0 is active and restore r0->r7 */
92 mov.l 12f, r9
93 not r9, r9
94 stc sr, r8
95 and r9, r8
96 ldc r8, sr
97 mov.l @r15+, r0
98 mov.l @r15+, r1
99 mov.l @r15+, r2
100 mov.l @r15+, r3
101 mov.l @r15+, r4
102 mov.l @r15+, r5
103 mov.l @r15+, r6
104 mov.l @r15+, r7
105
106 /* switch to bank1 and restore r0->r7 */
107 mov.l 12f, r9
108 stc sr, r8
109 or r9, r8
110 ldc r8, sr
111 mov.l @r15+, r0
112 mov.l @r15+, r1
113 mov.l @r15+, r2
114 mov.l @r15+, r3
115 mov.l @r15+, r4
116 mov.l @r15+, r5
117 mov.l @r15+, r6
118 mov.l @r15+, r7
119
120 /* switch back to bank0 */
121 mov.l 12f, r9
122 not r9, r9
123 stc sr, r8
124 and r9, r8
125 ldc r8, sr
126
127 /* restore other random registers */
128 ldc.l @r15+, spc
129 lds.l @r15+, pr
130 ldc.l @r15+, sr
131 ldc.l @r15+, ssr
132 ldc.l @r15+, gbr
133 lds.l @r15+, mach
134 lds.l @r15+, macl
135
136 /* restore r8->r15 */
137 mov.l @r15+, r8
138 mov.l @r15+, r9
139 mov.l @r15+, r10
140 mov.l @r15+, r11
141 mov.l @r15+, r12
142 mov.l @r15+, r13
143 mov.l @r15+, r14
144 mov.l @r15+, r15
145 rts
146 nop
147
148swap_pages:
28 bra 1f 149 bra 1f
29 mov r4,r0 /* cmd = indirection_page */ 150 mov r4,r0 /* cmd = indirection_page */
300: 1510:
31 mov.l @r4+,r0 /* cmd = *ind++ */ 152 mov.l @r4+,r0 /* cmd = *ind++ */
32 153
331: /* addr = (cmd | P2SEG) & 0xfffffff0 */ 1541: /* addr = cmd & 0xfffffff0 */
34 mov r0,r2 155 mov r0,r2
35 or r9,r2
36 mov #-16,r1 156 mov #-16,r1
37 and r1,r2 157 and r1,r2
38 158
@@ -40,57 +160,70 @@ relocate_new_kernel:
40 tst #1,r0 160 tst #1,r0
41 bt 2f 161 bt 2f
42 bra 0b 162 bra 0b
43 mov r2,r5 163 mov r2,r5
44 164
452: /* else if(cmd & IND_INDIRECTION) ind = addr */ 1652: /* else if(cmd & IND_INDIRECTION) ind = addr */
46 tst #2,r0 166 tst #2,r0
47 bt 3f 167 bt 3f
48 bra 0b 168 bra 0b
49 mov r2,r4 169 mov r2,r4
50 170
513: /* else if(cmd & IND_DONE) goto 6 */ 1713: /* else if(cmd & IND_DONE) return */
52 tst #4,r0 172 tst #4,r0
53 bt 4f 173 bt 4f
54 bra 6f 174 rts
55 nop 175 nop
56 176
574: /* else if(cmd & IND_SOURCE) memcpy(dst,addr,PAGE_SIZE) */ 1774: /* else if(cmd & IND_SOURCE) memcpy(dst,addr,PAGE_SIZE) */
58 tst #8,r0 178 tst #8,r0
59 bt 0b 179 bt 0b
60 180
61 mov r8,r3 181 mov.l 10f,r3 /* PAGE_SIZE */
62 shlr2 r3 182 shlr2 r3
63 shlr2 r3 183 shlr2 r3
645: 1845:
65 dt r3 185 dt r3
66 mov.l @r2+,r1 /* 16n+0 */ 186
67 mov.l r1,@r5 187 /* regular kexec just overwrites the destination page
68 add #4,r5 188 * with the contents of the source page.
69 mov.l @r2+,r1 /* 16n+4 */ 189 * for the kexec jump case we need to swap the contents
70 mov.l r1,@r5 190 * of the pages.
71 add #4,r5 191 * to keep it simple swap the contents for both cases.
72 mov.l @r2+,r1 /* 16n+8 */ 192 */
73 mov.l r1,@r5 193 mov.l @(0, r2), r8
74 add #4,r5 194 mov.l @(0, r5), r1
75 mov.l @r2+,r1 /* 16n+12 */ 195 mov.l r8, @(0, r5)
76 mov.l r1,@r5 196 mov.l r1, @(0, r2)
77 add #4,r5 197
198 mov.l @(4, r2), r8
199 mov.l @(4, r5), r1
200 mov.l r8, @(4, r5)
201 mov.l r1, @(4, r2)
202
203 mov.l @(8, r2), r8
204 mov.l @(8, r5), r1
205 mov.l r8, @(8, r5)
206 mov.l r1, @(8, r2)
207
208 mov.l @(12, r2), r8
209 mov.l @(12, r5), r1
210 mov.l r8, @(12, r5)
211 mov.l r1, @(12, r2)
212
213 add #16,r5
214 add #16,r2
78 bf 5b 215 bf 5b
79 216
80 bra 0b 217 bra 0b
81 nop 218 nop
826:
83#ifdef CONFIG_SH_STANDARD_BIOS
84 ldc r7, vbr
85#endif
86 jmp @r6
87 nop
88 219
89 .align 2 220 .align 2
9010: 22110:
91 .long PAGE_SIZE 222 .long PAGE_SIZE
9211: 22311:
93 .long P2SEG 224 .long 0
22512:
226 .long 0x20000000 ! RB=1
94 227
95relocate_new_kernel_end: 228relocate_new_kernel_end:
96 229
diff --git a/arch/sh/kernel/setup.c b/arch/sh/kernel/setup.c
index 370d2cfa34eb..24c60251f680 100644
--- a/arch/sh/kernel/setup.c
+++ b/arch/sh/kernel/setup.c
@@ -432,6 +432,7 @@ static const char *cpu_name[] = {
432 [CPU_SH7763] = "SH7763", [CPU_SH7770] = "SH7770", 432 [CPU_SH7763] = "SH7763", [CPU_SH7770] = "SH7770",
433 [CPU_SH7780] = "SH7780", [CPU_SH7781] = "SH7781", 433 [CPU_SH7780] = "SH7780", [CPU_SH7781] = "SH7781",
434 [CPU_SH7343] = "SH7343", [CPU_SH7785] = "SH7785", 434 [CPU_SH7343] = "SH7343", [CPU_SH7785] = "SH7785",
435 [CPU_SH7786] = "SH7786",
435 [CPU_SH7722] = "SH7722", [CPU_SHX3] = "SH-X3", 436 [CPU_SH7722] = "SH7722", [CPU_SHX3] = "SH-X3",
436 [CPU_SH5_101] = "SH5-101", [CPU_SH5_103] = "SH5-103", 437 [CPU_SH5_101] = "SH5-101", [CPU_SH5_103] = "SH5-103",
437 [CPU_MXG] = "MX-G", [CPU_SH7723] = "SH7723", 438 [CPU_MXG] = "MX-G", [CPU_SH7723] = "SH7723",
@@ -448,7 +449,7 @@ EXPORT_SYMBOL(get_cpu_subtype);
448/* Symbolic CPU flags, keep in sync with asm/cpu-features.h */ 449/* Symbolic CPU flags, keep in sync with asm/cpu-features.h */
449static const char *cpu_flags[] = { 450static const char *cpu_flags[] = {
450 "none", "fpu", "p2flush", "mmuassoc", "dsp", "perfctr", 451 "none", "fpu", "p2flush", "mmuassoc", "dsp", "perfctr",
451 "ptea", "llsc", "l2", "op32", NULL 452 "ptea", "llsc", "l2", "op32", "pteaex", NULL
452}; 453};
453 454
454static void show_cpuflags(struct seq_file *m, struct sh_cpuinfo *c) 455static void show_cpuflags(struct seq_file *m, struct sh_cpuinfo *c)
diff --git a/arch/sh/kernel/swsusp.c b/arch/sh/kernel/swsusp.c
new file mode 100644
index 000000000000..12b64a0f2f01
--- /dev/null
+++ b/arch/sh/kernel/swsusp.c
@@ -0,0 +1,38 @@
1/*
2 * swsusp.c - SuperH hibernation support
3 *
4 * Copyright (C) 2009 Magnus Damm
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/mm.h>
12#include <linux/sched.h>
13#include <linux/suspend.h>
14#include <asm/suspend.h>
15#include <asm/sections.h>
16#include <asm/tlbflush.h>
17#include <asm/page.h>
18#include <asm/fpu.h>
19
20struct swsusp_arch_regs swsusp_arch_regs_cpu0;
21
22int pfn_is_nosave(unsigned long pfn)
23{
24 unsigned long begin_pfn = __pa(&__nosave_begin) >> PAGE_SHIFT;
25 unsigned long end_pfn = PAGE_ALIGN(__pa(&__nosave_end)) >> PAGE_SHIFT;
26
27 return (pfn >= begin_pfn) && (pfn < end_pfn);
28}
29
30void save_processor_state(void)
31{
32 init_fpu(current);
33}
34
35void restore_processor_state(void)
36{
37 local_flush_tlb_all();
38}
diff --git a/arch/sh/kernel/time_32.c b/arch/sh/kernel/time_32.c
index 8457f83242c5..c34e1e0f9b02 100644
--- a/arch/sh/kernel/time_32.c
+++ b/arch/sh/kernel/time_32.c
@@ -41,14 +41,6 @@ static int null_rtc_set_time(const time_t secs)
41 return 0; 41 return 0;
42} 42}
43 43
44/*
45 * Null high precision timer functions for systems lacking one.
46 */
47static cycle_t null_hpt_read(void)
48{
49 return 0;
50}
51
52void (*rtc_sh_get_time)(struct timespec *) = null_rtc_get_time; 44void (*rtc_sh_get_time)(struct timespec *) = null_rtc_get_time;
53int (*rtc_sh_set_time)(const time_t) = null_rtc_set_time; 45int (*rtc_sh_set_time)(const time_t) = null_rtc_set_time;
54 46
@@ -112,7 +104,6 @@ int do_settimeofday(struct timespec *tv)
112EXPORT_SYMBOL(do_settimeofday); 104EXPORT_SYMBOL(do_settimeofday);
113#endif /* !CONFIG_GENERIC_TIME */ 105#endif /* !CONFIG_GENERIC_TIME */
114 106
115#ifndef CONFIG_GENERIC_CLOCKEVENTS
116/* last time the RTC clock got updated */ 107/* last time the RTC clock got updated */
117static long last_rtc_update; 108static long last_rtc_update;
118 109
@@ -156,7 +147,6 @@ void handle_timer_tick(void)
156 update_process_times(user_mode(get_irq_regs())); 147 update_process_times(user_mode(get_irq_regs()));
157#endif 148#endif
158} 149}
159#endif /* !CONFIG_GENERIC_CLOCKEVENTS */
160 150
161#ifdef CONFIG_PM 151#ifdef CONFIG_PM
162int timer_suspend(struct sys_device *dev, pm_message_t state) 152int timer_suspend(struct sys_device *dev, pm_message_t state)
@@ -189,7 +179,12 @@ static struct sysdev_class timer_sysclass = {
189 179
190static int __init timer_init_sysfs(void) 180static int __init timer_init_sysfs(void)
191{ 181{
192 int ret = sysdev_class_register(&timer_sysclass); 182 int ret;
183
184 if (!sys_timer)
185 return 0;
186
187 ret = sysdev_class_register(&timer_sysclass);
193 if (ret != 0) 188 if (ret != 0)
194 return ret; 189 return ret;
195 190
@@ -200,42 +195,21 @@ device_initcall(timer_init_sysfs);
200 195
201void (*board_time_init)(void); 196void (*board_time_init)(void);
202 197
203/* 198struct clocksource clocksource_sh = {
204 * Shamelessly based on the MIPS and Sparc64 work.
205 */
206static unsigned long timer_ticks_per_nsec_quotient __read_mostly;
207unsigned long sh_hpt_frequency = 0;
208
209#define NSEC_PER_CYC_SHIFT 10
210
211static struct clocksource clocksource_sh = {
212 .name = "SuperH", 199 .name = "SuperH",
213 .rating = 200,
214 .mask = CLOCKSOURCE_MASK(32),
215 .read = null_hpt_read,
216 .shift = 16,
217 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
218}; 200};
219 201
220static void __init init_sh_clocksource(void)
221{
222 if (!sh_hpt_frequency || clocksource_sh.read == null_hpt_read)
223 return;
224
225 clocksource_sh.mult = clocksource_hz2mult(sh_hpt_frequency,
226 clocksource_sh.shift);
227
228 timer_ticks_per_nsec_quotient =
229 clocksource_hz2mult(sh_hpt_frequency, NSEC_PER_CYC_SHIFT);
230
231 clocksource_register(&clocksource_sh);
232}
233
234#ifdef CONFIG_GENERIC_TIME 202#ifdef CONFIG_GENERIC_TIME
235unsigned long long sched_clock(void) 203unsigned long long sched_clock(void)
236{ 204{
237 unsigned long long ticks = clocksource_sh.read(); 205 unsigned long long cycles;
238 return (ticks * timer_ticks_per_nsec_quotient) >> NSEC_PER_CYC_SHIFT; 206
207 /* jiffies based sched_clock if no clocksource is installed */
208 if (!clocksource_sh.rating)
209 return (unsigned long long)jiffies * (NSEC_PER_SEC / HZ);
210
211 cycles = clocksource_sh.read();
212 return cyc2ns(&clocksource_sh, cycles);
239} 213}
240#endif 214#endif
241 215
@@ -259,17 +233,8 @@ void __init time_init(void)
259 * initialized for us. 233 * initialized for us.
260 */ 234 */
261 sys_timer = get_sys_timer(); 235 sys_timer = get_sys_timer();
262 printk(KERN_INFO "Using %s for system timer\n", sys_timer->name); 236 if (unlikely(!sys_timer))
263 237 panic("System timer missing.\n");
264
265 if (sys_timer->ops->read)
266 clocksource_sh.read = sys_timer->ops->read;
267
268 init_sh_clocksource();
269
270 if (sh_hpt_frequency)
271 printk("Using %lu.%03lu MHz high precision timer.\n",
272 ((sh_hpt_frequency + 500) / 1000) / 1000,
273 ((sh_hpt_frequency + 500) / 1000) % 1000);
274 238
239 printk(KERN_INFO "Using %s for system timer\n", sys_timer->name);
275} 240}
diff --git a/arch/sh/kernel/timers/timer-mtu2.c b/arch/sh/kernel/timers/timer-mtu2.c
index c3d237e1d566..9a77ae86b403 100644
--- a/arch/sh/kernel/timers/timer-mtu2.c
+++ b/arch/sh/kernel/timers/timer-mtu2.c
@@ -35,7 +35,8 @@
35#define MTU2_TSR_1 0xfffe4385 35#define MTU2_TSR_1 0xfffe4385
36#define MTU2_TCNT_1 0xfffe4386 /* 16-bit counter */ 36#define MTU2_TCNT_1 0xfffe4386 /* 16-bit counter */
37 37
38#if defined(CONFIG_CPU_SUBTYPE_SH7201) 38#if defined(CONFIG_CPU_SUBTYPE_SH7201) || \
39 defined(CONFIG_CPU_SUBTYPE_SH7203)
39#define MTU2_TGRA_1 0xfffe4388 40#define MTU2_TGRA_1 0xfffe4388
40#else 41#else
41#define MTU2_TGRA_1 0xfffe438a 42#define MTU2_TGRA_1 0xfffe438a
diff --git a/arch/sh/kernel/timers/timer-tmu.c b/arch/sh/kernel/timers/timer-tmu.c
index 0db3f9510336..10b5a6f17cc0 100644
--- a/arch/sh/kernel/timers/timer-tmu.c
+++ b/arch/sh/kernel/timers/timer-tmu.c
@@ -146,7 +146,14 @@ static irqreturn_t tmu_timer_interrupt(int irq, void *dummy)
146 _tmu_clear_status(TMU0); 146 _tmu_clear_status(TMU0);
147 _tmu_set_irq(TMU0,tmu0_clockevent.mode != CLOCK_EVT_MODE_ONESHOT); 147 _tmu_set_irq(TMU0,tmu0_clockevent.mode != CLOCK_EVT_MODE_ONESHOT);
148 148
149 evt->event_handler(evt); 149 switch (tmu0_clockevent.mode) {
150 case CLOCK_EVT_MODE_ONESHOT:
151 case CLOCK_EVT_MODE_PERIODIC:
152 evt->event_handler(evt);
153 break;
154 default:
155 break;
156 }
150 157
151 return IRQ_HANDLED; 158 return IRQ_HANDLED;
152} 159}
@@ -237,6 +244,7 @@ static int tmu_timer_init(void)
237 !defined(CONFIG_CPU_SUBTYPE_SH7721) && \ 244 !defined(CONFIG_CPU_SUBTYPE_SH7721) && \
238 !defined(CONFIG_CPU_SUBTYPE_SH7760) && \ 245 !defined(CONFIG_CPU_SUBTYPE_SH7760) && \
239 !defined(CONFIG_CPU_SUBTYPE_SH7785) && \ 246 !defined(CONFIG_CPU_SUBTYPE_SH7785) && \
247 !defined(CONFIG_CPU_SUBTYPE_SH7786) && \
240 !defined(CONFIG_CPU_SUBTYPE_SHX3) 248 !defined(CONFIG_CPU_SUBTYPE_SHX3)
241 ctrl_outb(TMU_TOCR_INIT, TMU_TOCR); 249 ctrl_outb(TMU_TOCR_INIT, TMU_TOCR);
242#endif 250#endif
@@ -254,7 +262,14 @@ static int tmu_timer_init(void)
254 262
255 _tmu_start(TMU1); 263 _tmu_start(TMU1);
256 264
257 sh_hpt_frequency = clk_get_rate(&tmu1_clk); 265 clocksource_sh.rating = 200;
266 clocksource_sh.mask = CLOCKSOURCE_MASK(32);
267 clocksource_sh.read = tmu_timer_read;
268 clocksource_sh.shift = 10;
269 clocksource_sh.mult = clocksource_hz2mult(clk_get_rate(&tmu1_clk),
270 clocksource_sh.shift);
271 clocksource_sh.flags = CLOCK_SOURCE_IS_CONTINUOUS;
272 clocksource_register(&clocksource_sh);
258 273
259 tmu0_clockevent.mult = div_sc(frequency, NSEC_PER_SEC, 274 tmu0_clockevent.mult = div_sc(frequency, NSEC_PER_SEC,
260 tmu0_clockevent.shift); 275 tmu0_clockevent.shift);
@@ -264,6 +279,7 @@ static int tmu_timer_init(void)
264 clockevent_delta2ns(1, &tmu0_clockevent); 279 clockevent_delta2ns(1, &tmu0_clockevent);
265 280
266 tmu0_clockevent.cpumask = cpumask_of(0); 281 tmu0_clockevent.cpumask = cpumask_of(0);
282 tmu0_clockevent.rating = 100;
267 283
268 clockevents_register_device(&tmu0_clockevent); 284 clockevents_register_device(&tmu0_clockevent);
269 285
@@ -274,7 +290,6 @@ static struct sys_timer_ops tmu_timer_ops = {
274 .init = tmu_timer_init, 290 .init = tmu_timer_init,
275 .start = tmu_timer_start, 291 .start = tmu_timer_start,
276 .stop = tmu_timer_stop, 292 .stop = tmu_timer_stop,
277 .read = tmu_timer_read,
278}; 293};
279 294
280struct sys_timer tmu_timer = { 295struct sys_timer tmu_timer = {
diff --git a/arch/sh/kernel/vmlinux_32.lds.S b/arch/sh/kernel/vmlinux_32.lds.S
index 7b4b82bd1156..d0b2a715cd14 100644
--- a/arch/sh/kernel/vmlinux_32.lds.S
+++ b/arch/sh/kernel/vmlinux_32.lds.S
@@ -15,7 +15,10 @@ OUTPUT_ARCH(sh)
15ENTRY(_start) 15ENTRY(_start)
16SECTIONS 16SECTIONS
17{ 17{
18#ifdef CONFIG_32BIT 18#ifdef CONFIG_PMB_FIXED
19 . = CONFIG_PAGE_OFFSET + (CONFIG_MEMORY_START & 0x1fffffff) +
20 CONFIG_ZERO_PAGE_OFFSET;
21#elif defined(CONFIG_32BIT)
19 . = CONFIG_PAGE_OFFSET + CONFIG_ZERO_PAGE_OFFSET; 22 . = CONFIG_PAGE_OFFSET + CONFIG_ZERO_PAGE_OFFSET;
20#else 23#else
21 . = CONFIG_PAGE_OFFSET + CONFIG_MEMORY_START + CONFIG_ZERO_PAGE_OFFSET; 24 . = CONFIG_PAGE_OFFSET + CONFIG_MEMORY_START + CONFIG_ZERO_PAGE_OFFSET;
diff --git a/arch/sh/mm/Kconfig b/arch/sh/mm/Kconfig
index 555ec9714b9e..10c24356d2d5 100644
--- a/arch/sh/mm/Kconfig
+++ b/arch/sh/mm/Kconfig
@@ -57,7 +57,7 @@ config 32BIT
57 bool 57 bool
58 default y if CPU_SH5 58 default y if CPU_SH5
59 59
60config PMB 60config PMB_ENABLE
61 bool "Support 32-bit physical addressing through PMB" 61 bool "Support 32-bit physical addressing through PMB"
62 depends on MMU && EXPERIMENTAL && (CPU_SUBTYPE_SH7780 || CPU_SUBTYPE_SH7785) 62 depends on MMU && EXPERIMENTAL && (CPU_SUBTYPE_SH7780 || CPU_SUBTYPE_SH7785)
63 select 32BIT 63 select 32BIT
@@ -67,6 +67,33 @@ config PMB
67 32-bits through the SH-4A PMB. If this is not set, legacy 67 32-bits through the SH-4A PMB. If this is not set, legacy
68 29-bit physical addressing will be used. 68 29-bit physical addressing will be used.
69 69
70choice
71 prompt "PMB handling type"
72 depends on PMB_ENABLE
73 default PMB_FIXED
74
75config PMB
76 bool "PMB"
77 depends on MMU && EXPERIMENTAL && (CPU_SUBTYPE_SH7780 || CPU_SUBTYPE_SH7785)
78 select 32BIT
79 help
80 If you say Y here, physical addressing will be extended to
81 32-bits through the SH-4A PMB. If this is not set, legacy
82 29-bit physical addressing will be used.
83
84config PMB_FIXED
85 bool "fixed PMB"
86 depends on MMU && EXPERIMENTAL && (CPU_SUBTYPE_SH7780 || \
87 CPU_SUBTYPE_SH7785)
88 select 32BIT
89 help
90 If this option is enabled, fixed PMB mappings are inherited
91 from the boot loader, and the kernel does not attempt dynamic
92 management. This is the closest to legacy 29-bit physical mode,
93 and allows systems to support up to 512MiB of system memory.
94
95endchoice
96
70config X2TLB 97config X2TLB
71 bool "Enable extended TLB mode" 98 bool "Enable extended TLB mode"
72 depends on (CPU_SHX2 || CPU_SHX3) && MMU && EXPERIMENTAL 99 depends on (CPU_SHX2 || CPU_SHX3) && MMU && EXPERIMENTAL
diff --git a/arch/sh/mm/Makefile_32 b/arch/sh/mm/Makefile_32
index cb2f3f299591..986a1e055834 100644
--- a/arch/sh/mm/Makefile_32
+++ b/arch/sh/mm/Makefile_32
@@ -25,8 +25,10 @@ obj-$(CONFIG_CPU_SH4) += cache-debugfs.o
25endif 25endif
26 26
27ifdef CONFIG_MMU 27ifdef CONFIG_MMU
28obj-$(CONFIG_CPU_SH3) += tlb-sh3.o 28tlb-$(CONFIG_CPU_SH3) := tlb-sh3.o
29obj-$(CONFIG_CPU_SH4) += tlb-sh4.o 29tlb-$(CONFIG_CPU_SH4) := tlb-sh4.o
30tlb-$(CONFIG_CPU_HAS_PTEAEX) := tlb-pteaex.o
31obj-y += $(tlb-y)
30ifndef CONFIG_CACHE_OFF 32ifndef CONFIG_CACHE_OFF
31obj-$(CONFIG_CPU_SH4) += pg-sh4.o 33obj-$(CONFIG_CPU_SH4) += pg-sh4.o
32obj-$(CONFIG_SH7705_CACHE_32KB) += pg-sh7705.o 34obj-$(CONFIG_SH7705_CACHE_32KB) += pg-sh7705.o
@@ -35,6 +37,7 @@ endif
35 37
36obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o 38obj-$(CONFIG_HUGETLB_PAGE) += hugetlbpage.o
37obj-$(CONFIG_PMB) += pmb.o 39obj-$(CONFIG_PMB) += pmb.o
40obj-$(CONFIG_PMB_FIXED) += pmb-fixed.o
38obj-$(CONFIG_NUMA) += numa.o 41obj-$(CONFIG_NUMA) += numa.o
39 42
40EXTRA_CFLAGS += -Werror 43EXTRA_CFLAGS += -Werror
diff --git a/arch/sh/mm/asids-debugfs.c b/arch/sh/mm/asids-debugfs.c
index 8e912a15e94f..cd8c3bf39b5a 100644
--- a/arch/sh/mm/asids-debugfs.c
+++ b/arch/sh/mm/asids-debugfs.c
@@ -37,10 +37,8 @@ static int asids_seq_show(struct seq_file *file, void *iter)
37 continue; 37 continue;
38 38
39 if (p->mm) 39 if (p->mm)
40 seq_printf(file, "%5d : %02lx\n", pid, 40 seq_printf(file, "%5d : %04lx\n", pid,
41 cpu_asid(smp_processor_id(), p->mm)); 41 cpu_asid(smp_processor_id(), p->mm));
42 else
43 seq_printf(file, "%5d : (none)\n", pid);
44 } 42 }
45 43
46 read_unlock(&tasklist_lock); 44 read_unlock(&tasklist_lock);
diff --git a/arch/sh/mm/ioremap_32.c b/arch/sh/mm/ioremap_32.c
index 32946fba123e..60cc486d2c2c 100644
--- a/arch/sh/mm/ioremap_32.c
+++ b/arch/sh/mm/ioremap_32.c
@@ -59,11 +59,13 @@ void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
59 if (is_pci_memaddr(phys_addr) && is_pci_memaddr(last_addr)) 59 if (is_pci_memaddr(phys_addr) && is_pci_memaddr(last_addr))
60 return (void __iomem *)phys_addr; 60 return (void __iomem *)phys_addr;
61 61
62#if !defined(CONFIG_PMB_FIXED)
62 /* 63 /*
63 * Don't allow anybody to remap normal RAM that we're using.. 64 * Don't allow anybody to remap normal RAM that we're using..
64 */ 65 */
65 if (phys_addr < virt_to_phys(high_memory)) 66 if (phys_addr < virt_to_phys(high_memory))
66 return NULL; 67 return NULL;
68#endif
67 69
68 /* 70 /*
69 * Mappings have to be page-aligned 71 * Mappings have to be page-aligned
@@ -81,7 +83,7 @@ void __iomem *__ioremap(unsigned long phys_addr, unsigned long size,
81 area->phys_addr = phys_addr; 83 area->phys_addr = phys_addr;
82 orig_addr = addr = (unsigned long)area->addr; 84 orig_addr = addr = (unsigned long)area->addr;
83 85
84#ifdef CONFIG_32BIT 86#ifdef CONFIG_PMB
85 /* 87 /*
86 * First try to remap through the PMB once a valid VMA has been 88 * First try to remap through the PMB once a valid VMA has been
87 * established. Smaller allocations (or the rest of the size 89 * established. Smaller allocations (or the rest of the size
@@ -119,10 +121,10 @@ void __iounmap(void __iomem *addr)
119 unsigned long seg = PXSEG(vaddr); 121 unsigned long seg = PXSEG(vaddr);
120 struct vm_struct *p; 122 struct vm_struct *p;
121 123
122 if (seg < P3SEG || seg >= P3_ADDR_MAX || is_pci_memaddr(vaddr)) 124 if (seg < P3SEG || vaddr >= P3_ADDR_MAX || is_pci_memaddr(vaddr))
123 return; 125 return;
124 126
125#ifdef CONFIG_32BIT 127#ifdef CONFIG_PMB
126 /* 128 /*
127 * Purge any PMB entries that may have been established for this 129 * Purge any PMB entries that may have been established for this
128 * mapping, then proceed with conventional VMA teardown. 130 * mapping, then proceed with conventional VMA teardown.
diff --git a/arch/sh/mm/pmb-fixed.c b/arch/sh/mm/pmb-fixed.c
new file mode 100644
index 000000000000..43c8eac4d8a1
--- /dev/null
+++ b/arch/sh/mm/pmb-fixed.c
@@ -0,0 +1,45 @@
1/*
2 * arch/sh/mm/fixed_pmb.c
3 *
4 * Copyright (C) 2009 Renesas Solutions Corp.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10#include <linux/init.h>
11#include <linux/mm.h>
12#include <linux/io.h>
13#include <asm/mmu.h>
14#include <asm/mmu_context.h>
15
16static int __uses_jump_to_uncached fixed_pmb_init(void)
17{
18 int i;
19 unsigned long addr, data;
20
21 jump_to_uncached();
22
23 for (i = 0; i < PMB_ENTRY_MAX; i++) {
24 addr = PMB_DATA + (i << PMB_E_SHIFT);
25 data = ctrl_inl(addr);
26 if (!(data & PMB_V))
27 continue;
28
29 if (data & PMB_C) {
30#if defined(CONFIG_CACHE_WRITETHROUGH)
31 data |= PMB_WT;
32#elif defined(CONFIG_CACHE_WRITEBACK)
33 data &= ~PMB_WT;
34#else
35 data &= ~(PMB_C | PMB_WT);
36#endif
37 }
38 ctrl_outl(data, addr);
39 }
40
41 back_to_cached();
42
43 return 0;
44}
45arch_initcall(fixed_pmb_init);
diff --git a/arch/sh/mm/pmb.c b/arch/sh/mm/pmb.c
index 84241676265e..b1a714a92b14 100644
--- a/arch/sh/mm/pmb.c
+++ b/arch/sh/mm/pmb.c
@@ -15,6 +15,8 @@
15 */ 15 */
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/kernel.h> 17#include <linux/kernel.h>
18#include <linux/sysdev.h>
19#include <linux/cpu.h>
18#include <linux/module.h> 20#include <linux/module.h>
19#include <linux/slab.h> 21#include <linux/slab.h>
20#include <linux/bitops.h> 22#include <linux/bitops.h>
@@ -402,3 +404,39 @@ static int __init pmb_debugfs_init(void)
402 return 0; 404 return 0;
403} 405}
404postcore_initcall(pmb_debugfs_init); 406postcore_initcall(pmb_debugfs_init);
407
408#ifdef CONFIG_PM
409static int pmb_sysdev_suspend(struct sys_device *dev, pm_message_t state)
410{
411 static pm_message_t prev_state;
412
413 /* Restore the PMB after a resume from hibernation */
414 if (state.event == PM_EVENT_ON &&
415 prev_state.event == PM_EVENT_FREEZE) {
416 struct pmb_entry *pmbe;
417 spin_lock_irq(&pmb_list_lock);
418 for (pmbe = pmb_list; pmbe; pmbe = pmbe->next)
419 set_pmb_entry(pmbe);
420 spin_unlock_irq(&pmb_list_lock);
421 }
422 prev_state = state;
423 return 0;
424}
425
426static int pmb_sysdev_resume(struct sys_device *dev)
427{
428 return pmb_sysdev_suspend(dev, PMSG_ON);
429}
430
431static struct sysdev_driver pmb_sysdev_driver = {
432 .suspend = pmb_sysdev_suspend,
433 .resume = pmb_sysdev_resume,
434};
435
436static int __init pmb_sysdev_init(void)
437{
438 return sysdev_driver_register(&cpu_sysdev_class, &pmb_sysdev_driver);
439}
440
441subsys_initcall(pmb_sysdev_init);
442#endif
diff --git a/arch/sh/mm/tlb-pteaex.c b/arch/sh/mm/tlb-pteaex.c
new file mode 100644
index 000000000000..2aab3ea934d7
--- /dev/null
+++ b/arch/sh/mm/tlb-pteaex.c
@@ -0,0 +1,96 @@
1/*
2 * arch/sh/mm/tlb-pteaex.c
3 *
4 * TLB operations for SH-X3 CPUs featuring PTE ASID Extensions.
5 *
6 * Copyright (C) 2009 Paul Mundt
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12#include <linux/kernel.h>
13#include <linux/mm.h>
14#include <linux/io.h>
15#include <asm/system.h>
16#include <asm/mmu_context.h>
17#include <asm/cacheflush.h>
18
19void update_mmu_cache(struct vm_area_struct * vma,
20 unsigned long address, pte_t pte)
21{
22 unsigned long flags;
23 unsigned long pteval;
24 unsigned long vpn;
25
26 /* Ptrace may call this routine. */
27 if (vma && current->active_mm != vma->vm_mm)
28 return;
29
30#ifndef CONFIG_CACHE_OFF
31 {
32 unsigned long pfn = pte_pfn(pte);
33
34 if (pfn_valid(pfn)) {
35 struct page *page = pfn_to_page(pfn);
36
37 if (!test_bit(PG_mapped, &page->flags)) {
38 unsigned long phys = pte_val(pte) & PTE_PHYS_MASK;
39 __flush_wback_region((void *)P1SEGADDR(phys),
40 PAGE_SIZE);
41 __set_bit(PG_mapped, &page->flags);
42 }
43 }
44 }
45#endif
46
47 local_irq_save(flags);
48
49 /* Set PTEH register */
50 vpn = address & MMU_VPN_MASK;
51 __raw_writel(vpn, MMU_PTEH);
52
53 /* Set PTEAEX */
54 __raw_writel(get_asid(), MMU_PTEAEX);
55
56 pteval = pte.pte_low;
57
58 /* Set PTEA register */
59#ifdef CONFIG_X2TLB
60 /*
61 * For the extended mode TLB this is trivial, only the ESZ and
62 * EPR bits need to be written out to PTEA, with the remainder of
63 * the protection bits (with the exception of the compat-mode SZ
64 * and PR bits, which are cleared) being written out in PTEL.
65 */
66 __raw_writel(pte.pte_high, MMU_PTEA);
67#endif
68
69 /* Set PTEL register */
70 pteval &= _PAGE_FLAGS_HARDWARE_MASK; /* drop software flags */
71#ifdef CONFIG_CACHE_WRITETHROUGH
72 pteval |= _PAGE_WT;
73#endif
74 /* conveniently, we want all the software flags to be 0 anyway */
75 __raw_writel(pteval, MMU_PTEL);
76
77 /* Load the TLB */
78 asm volatile("ldtlb": /* no output */ : /* no input */ : "memory");
79 local_irq_restore(flags);
80}
81
82/*
83 * While SH-X2 extended TLB mode splits out the memory-mapped I/UTLB
84 * data arrays, SH-X3 cores with PTEAEX split out the memory-mapped
85 * address arrays. In compat mode the second array is inaccessible, while
86 * in extended mode, the legacy 8-bit ASID field in address array 1 has
87 * undefined behaviour.
88 */
89void __uses_jump_to_uncached local_flush_tlb_one(unsigned long asid,
90 unsigned long page)
91{
92 jump_to_uncached();
93 __raw_writel(page, MMU_UTLB_ADDRESS_ARRAY | MMU_PAGE_ASSOC_BIT);
94 __raw_writel(asid, MMU_UTLB_ADDRESS_ARRAY2 | MMU_PAGE_ASSOC_BIT);
95 back_to_cached();
96}
diff --git a/arch/sh/oprofile/common.c b/arch/sh/oprofile/common.c
index 1d97d64cb95f..1b9d4304b3bf 100644
--- a/arch/sh/oprofile/common.c
+++ b/arch/sh/oprofile/common.c
@@ -107,6 +107,7 @@ int __init oprofile_arch_init(struct oprofile_operations *ops)
107 case CPU_SH7780: 107 case CPU_SH7780:
108 case CPU_SH7781: 108 case CPU_SH7781:
109 case CPU_SH7785: 109 case CPU_SH7785:
110 case CPU_SH7786:
110 case CPU_SH7723: 111 case CPU_SH7723:
111 case CPU_SHX3: 112 case CPU_SHX3:
112 lmodel = &op_model_sh4a_ops; 113 lmodel = &op_model_sh4a_ops;
diff --git a/arch/sh/tools/mach-types b/arch/sh/tools/mach-types
index 284b7e867496..8477b5d884fd 100644
--- a/arch/sh/tools/mach-types
+++ b/arch/sh/tools/mach-types
@@ -52,3 +52,6 @@ RSK7203 SH_RSK7203
52AP325RXA SH_AP325RXA 52AP325RXA SH_AP325RXA
53SH7763RDP SH_SH7763RDP 53SH7763RDP SH_SH7763RDP
54SH7785LCR SH_SH7785LCR 54SH7785LCR SH_SH7785LCR
55URQUELL SH_URQUELL
56ESPT SH_ESPT
57POLARIS SH_POLARIS
diff --git a/arch/x86/crypto/Makefile b/arch/x86/crypto/Makefile
index 903de4aa5094..ebe7deedd5b4 100644
--- a/arch/x86/crypto/Makefile
+++ b/arch/x86/crypto/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_CRYPTO_SALSA20_586) += salsa20-i586.o
9obj-$(CONFIG_CRYPTO_AES_X86_64) += aes-x86_64.o 9obj-$(CONFIG_CRYPTO_AES_X86_64) += aes-x86_64.o
10obj-$(CONFIG_CRYPTO_TWOFISH_X86_64) += twofish-x86_64.o 10obj-$(CONFIG_CRYPTO_TWOFISH_X86_64) += twofish-x86_64.o
11obj-$(CONFIG_CRYPTO_SALSA20_X86_64) += salsa20-x86_64.o 11obj-$(CONFIG_CRYPTO_SALSA20_X86_64) += salsa20-x86_64.o
12obj-$(CONFIG_CRYPTO_AES_NI_INTEL) += aesni-intel.o
12 13
13obj-$(CONFIG_CRYPTO_CRC32C_INTEL) += crc32c-intel.o 14obj-$(CONFIG_CRYPTO_CRC32C_INTEL) += crc32c-intel.o
14 15
@@ -19,3 +20,5 @@ salsa20-i586-y := salsa20-i586-asm_32.o salsa20_glue.o
19aes-x86_64-y := aes-x86_64-asm_64.o aes_glue.o 20aes-x86_64-y := aes-x86_64-asm_64.o aes_glue.o
20twofish-x86_64-y := twofish-x86_64-asm_64.o twofish_glue.o 21twofish-x86_64-y := twofish-x86_64-asm_64.o twofish_glue.o
21salsa20-x86_64-y := salsa20-x86_64-asm_64.o salsa20_glue.o 22salsa20-x86_64-y := salsa20-x86_64-asm_64.o salsa20_glue.o
23
24aesni-intel-y := aesni-intel_asm.o aesni-intel_glue.o
diff --git a/arch/x86/crypto/aes-i586-asm_32.S b/arch/x86/crypto/aes-i586-asm_32.S
index e41b147f4509..b949ec2f9af4 100644
--- a/arch/x86/crypto/aes-i586-asm_32.S
+++ b/arch/x86/crypto/aes-i586-asm_32.S
@@ -41,14 +41,14 @@
41#define tlen 1024 // length of each of 4 'xor' arrays (256 32-bit words) 41#define tlen 1024 // length of each of 4 'xor' arrays (256 32-bit words)
42 42
43/* offsets to parameters with one register pushed onto stack */ 43/* offsets to parameters with one register pushed onto stack */
44#define tfm 8 44#define ctx 8
45#define out_blk 12 45#define out_blk 12
46#define in_blk 16 46#define in_blk 16
47 47
48/* offsets in crypto_tfm structure */ 48/* offsets in crypto_aes_ctx structure */
49#define klen (crypto_tfm_ctx_offset + 0) 49#define klen (480)
50#define ekey (crypto_tfm_ctx_offset + 4) 50#define ekey (0)
51#define dkey (crypto_tfm_ctx_offset + 244) 51#define dkey (240)
52 52
53// register mapping for encrypt and decrypt subroutines 53// register mapping for encrypt and decrypt subroutines
54 54
@@ -217,7 +217,7 @@
217 do_col (table, r5,r0,r1,r4, r2,r3); /* idx=r5 */ 217 do_col (table, r5,r0,r1,r4, r2,r3); /* idx=r5 */
218 218
219// AES (Rijndael) Encryption Subroutine 219// AES (Rijndael) Encryption Subroutine
220/* void aes_enc_blk(struct crypto_tfm *tfm, u8 *out_blk, const u8 *in_blk) */ 220/* void aes_enc_blk(struct crypto_aes_ctx *ctx, u8 *out_blk, const u8 *in_blk) */
221 221
222.global aes_enc_blk 222.global aes_enc_blk
223 223
@@ -228,7 +228,7 @@
228 228
229aes_enc_blk: 229aes_enc_blk:
230 push %ebp 230 push %ebp
231 mov tfm(%esp),%ebp 231 mov ctx(%esp),%ebp
232 232
233// CAUTION: the order and the values used in these assigns 233// CAUTION: the order and the values used in these assigns
234// rely on the register mappings 234// rely on the register mappings
@@ -292,7 +292,7 @@ aes_enc_blk:
292 ret 292 ret
293 293
294// AES (Rijndael) Decryption Subroutine 294// AES (Rijndael) Decryption Subroutine
295/* void aes_dec_blk(struct crypto_tfm *tfm, u8 *out_blk, const u8 *in_blk) */ 295/* void aes_dec_blk(struct crypto_aes_ctx *ctx, u8 *out_blk, const u8 *in_blk) */
296 296
297.global aes_dec_blk 297.global aes_dec_blk
298 298
@@ -303,7 +303,7 @@ aes_enc_blk:
303 303
304aes_dec_blk: 304aes_dec_blk:
305 push %ebp 305 push %ebp
306 mov tfm(%esp),%ebp 306 mov ctx(%esp),%ebp
307 307
308// CAUTION: the order and the values used in these assigns 308// CAUTION: the order and the values used in these assigns
309// rely on the register mappings 309// rely on the register mappings
diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
index a120f526c3df..5b577d5a059b 100644
--- a/arch/x86/crypto/aes-x86_64-asm_64.S
+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
@@ -17,8 +17,6 @@
17 17
18#include <asm/asm-offsets.h> 18#include <asm/asm-offsets.h>
19 19
20#define BASE crypto_tfm_ctx_offset
21
22#define R1 %rax 20#define R1 %rax
23#define R1E %eax 21#define R1E %eax
24#define R1X %ax 22#define R1X %ax
@@ -56,13 +54,13 @@
56 .align 8; \ 54 .align 8; \
57FUNC: movq r1,r2; \ 55FUNC: movq r1,r2; \
58 movq r3,r4; \ 56 movq r3,r4; \
59 leaq BASE+KEY+48+4(r8),r9; \ 57 leaq KEY+48(r8),r9; \
60 movq r10,r11; \ 58 movq r10,r11; \
61 movl (r7),r5 ## E; \ 59 movl (r7),r5 ## E; \
62 movl 4(r7),r1 ## E; \ 60 movl 4(r7),r1 ## E; \
63 movl 8(r7),r6 ## E; \ 61 movl 8(r7),r6 ## E; \
64 movl 12(r7),r7 ## E; \ 62 movl 12(r7),r7 ## E; \
65 movl BASE+0(r8),r10 ## E; \ 63 movl 480(r8),r10 ## E; \
66 xorl -48(r9),r5 ## E; \ 64 xorl -48(r9),r5 ## E; \
67 xorl -44(r9),r1 ## E; \ 65 xorl -44(r9),r1 ## E; \
68 xorl -40(r9),r6 ## E; \ 66 xorl -40(r9),r6 ## E; \
diff --git a/arch/x86/crypto/aes_glue.c b/arch/x86/crypto/aes_glue.c
index 71f457827116..49ae9fe32b22 100644
--- a/arch/x86/crypto/aes_glue.c
+++ b/arch/x86/crypto/aes_glue.c
@@ -5,17 +5,29 @@
5 5
6#include <crypto/aes.h> 6#include <crypto/aes.h>
7 7
8asmlinkage void aes_enc_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in); 8asmlinkage void aes_enc_blk(struct crypto_aes_ctx *ctx, u8 *out, const u8 *in);
9asmlinkage void aes_dec_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in); 9asmlinkage void aes_dec_blk(struct crypto_aes_ctx *ctx, u8 *out, const u8 *in);
10
11void crypto_aes_encrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
12{
13 aes_enc_blk(ctx, dst, src);
14}
15EXPORT_SYMBOL_GPL(crypto_aes_encrypt_x86);
16
17void crypto_aes_decrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
18{
19 aes_dec_blk(ctx, dst, src);
20}
21EXPORT_SYMBOL_GPL(crypto_aes_decrypt_x86);
10 22
11static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 23static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
12{ 24{
13 aes_enc_blk(tfm, dst, src); 25 aes_enc_blk(crypto_tfm_ctx(tfm), dst, src);
14} 26}
15 27
16static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 28static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
17{ 29{
18 aes_dec_blk(tfm, dst, src); 30 aes_dec_blk(crypto_tfm_ctx(tfm), dst, src);
19} 31}
20 32
21static struct crypto_alg aes_alg = { 33static struct crypto_alg aes_alg = {
diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
new file mode 100644
index 000000000000..caba99601703
--- /dev/null
+++ b/arch/x86/crypto/aesni-intel_asm.S
@@ -0,0 +1,896 @@
1/*
2 * Implement AES algorithm in Intel AES-NI instructions.
3 *
4 * The white paper of AES-NI instructions can be downloaded from:
5 * http://softwarecommunity.intel.com/isn/downloads/intelavx/AES-Instructions-Set_WP.pdf
6 *
7 * Copyright (C) 2008, Intel Corp.
8 * Author: Huang Ying <ying.huang@intel.com>
9 * Vinodh Gopal <vinodh.gopal@intel.com>
10 * Kahraman Akdemir
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 */
17
18#include <linux/linkage.h>
19
20.text
21
22#define STATE1 %xmm0
23#define STATE2 %xmm4
24#define STATE3 %xmm5
25#define STATE4 %xmm6
26#define STATE STATE1
27#define IN1 %xmm1
28#define IN2 %xmm7
29#define IN3 %xmm8
30#define IN4 %xmm9
31#define IN IN1
32#define KEY %xmm2
33#define IV %xmm3
34
35#define KEYP %rdi
36#define OUTP %rsi
37#define INP %rdx
38#define LEN %rcx
39#define IVP %r8
40#define KLEN %r9d
41#define T1 %r10
42#define TKEYP T1
43#define T2 %r11
44
45_key_expansion_128:
46_key_expansion_256a:
47 pshufd $0b11111111, %xmm1, %xmm1
48 shufps $0b00010000, %xmm0, %xmm4
49 pxor %xmm4, %xmm0
50 shufps $0b10001100, %xmm0, %xmm4
51 pxor %xmm4, %xmm0
52 pxor %xmm1, %xmm0
53 movaps %xmm0, (%rcx)
54 add $0x10, %rcx
55 ret
56
57_key_expansion_192a:
58 pshufd $0b01010101, %xmm1, %xmm1
59 shufps $0b00010000, %xmm0, %xmm4
60 pxor %xmm4, %xmm0
61 shufps $0b10001100, %xmm0, %xmm4
62 pxor %xmm4, %xmm0
63 pxor %xmm1, %xmm0
64
65 movaps %xmm2, %xmm5
66 movaps %xmm2, %xmm6
67 pslldq $4, %xmm5
68 pshufd $0b11111111, %xmm0, %xmm3
69 pxor %xmm3, %xmm2
70 pxor %xmm5, %xmm2
71
72 movaps %xmm0, %xmm1
73 shufps $0b01000100, %xmm0, %xmm6
74 movaps %xmm6, (%rcx)
75 shufps $0b01001110, %xmm2, %xmm1
76 movaps %xmm1, 16(%rcx)
77 add $0x20, %rcx
78 ret
79
80_key_expansion_192b:
81 pshufd $0b01010101, %xmm1, %xmm1
82 shufps $0b00010000, %xmm0, %xmm4
83 pxor %xmm4, %xmm0
84 shufps $0b10001100, %xmm0, %xmm4
85 pxor %xmm4, %xmm0
86 pxor %xmm1, %xmm0
87
88 movaps %xmm2, %xmm5
89 pslldq $4, %xmm5
90 pshufd $0b11111111, %xmm0, %xmm3
91 pxor %xmm3, %xmm2
92 pxor %xmm5, %xmm2
93
94 movaps %xmm0, (%rcx)
95 add $0x10, %rcx
96 ret
97
98_key_expansion_256b:
99 pshufd $0b10101010, %xmm1, %xmm1
100 shufps $0b00010000, %xmm2, %xmm4
101 pxor %xmm4, %xmm2
102 shufps $0b10001100, %xmm2, %xmm4
103 pxor %xmm4, %xmm2
104 pxor %xmm1, %xmm2
105 movaps %xmm2, (%rcx)
106 add $0x10, %rcx
107 ret
108
109/*
110 * int aesni_set_key(struct crypto_aes_ctx *ctx, const u8 *in_key,
111 * unsigned int key_len)
112 */
113ENTRY(aesni_set_key)
114 movups (%rsi), %xmm0 # user key (first 16 bytes)
115 movaps %xmm0, (%rdi)
116 lea 0x10(%rdi), %rcx # key addr
117 movl %edx, 480(%rdi)
118 pxor %xmm4, %xmm4 # xmm4 is assumed 0 in _key_expansion_x
119 cmp $24, %dl
120 jb .Lenc_key128
121 je .Lenc_key192
122 movups 0x10(%rsi), %xmm2 # other user key
123 movaps %xmm2, (%rcx)
124 add $0x10, %rcx
125 # aeskeygenassist $0x1, %xmm2, %xmm1 # round 1
126 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x01
127 call _key_expansion_256a
128 # aeskeygenassist $0x1, %xmm0, %xmm1
129 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x01
130 call _key_expansion_256b
131 # aeskeygenassist $0x2, %xmm2, %xmm1 # round 2
132 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x02
133 call _key_expansion_256a
134 # aeskeygenassist $0x2, %xmm0, %xmm1
135 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x02
136 call _key_expansion_256b
137 # aeskeygenassist $0x4, %xmm2, %xmm1 # round 3
138 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x04
139 call _key_expansion_256a
140 # aeskeygenassist $0x4, %xmm0, %xmm1
141 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x04
142 call _key_expansion_256b
143 # aeskeygenassist $0x8, %xmm2, %xmm1 # round 4
144 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x08
145 call _key_expansion_256a
146 # aeskeygenassist $0x8, %xmm0, %xmm1
147 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x08
148 call _key_expansion_256b
149 # aeskeygenassist $0x10, %xmm2, %xmm1 # round 5
150 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x10
151 call _key_expansion_256a
152 # aeskeygenassist $0x10, %xmm0, %xmm1
153 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x10
154 call _key_expansion_256b
155 # aeskeygenassist $0x20, %xmm2, %xmm1 # round 6
156 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x20
157 call _key_expansion_256a
158 # aeskeygenassist $0x20, %xmm0, %xmm1
159 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x20
160 call _key_expansion_256b
161 # aeskeygenassist $0x40, %xmm2, %xmm1 # round 7
162 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x40
163 call _key_expansion_256a
164 jmp .Ldec_key
165.Lenc_key192:
166 movq 0x10(%rsi), %xmm2 # other user key
167 # aeskeygenassist $0x1, %xmm2, %xmm1 # round 1
168 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x01
169 call _key_expansion_192a
170 # aeskeygenassist $0x2, %xmm2, %xmm1 # round 2
171 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x02
172 call _key_expansion_192b
173 # aeskeygenassist $0x4, %xmm2, %xmm1 # round 3
174 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x04
175 call _key_expansion_192a
176 # aeskeygenassist $0x8, %xmm2, %xmm1 # round 4
177 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x08
178 call _key_expansion_192b
179 # aeskeygenassist $0x10, %xmm2, %xmm1 # round 5
180 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x10
181 call _key_expansion_192a
182 # aeskeygenassist $0x20, %xmm2, %xmm1 # round 6
183 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x20
184 call _key_expansion_192b
185 # aeskeygenassist $0x40, %xmm2, %xmm1 # round 7
186 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x40
187 call _key_expansion_192a
188 # aeskeygenassist $0x80, %xmm2, %xmm1 # round 8
189 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xca, 0x80
190 call _key_expansion_192b
191 jmp .Ldec_key
192.Lenc_key128:
193 # aeskeygenassist $0x1, %xmm0, %xmm1 # round 1
194 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x01
195 call _key_expansion_128
196 # aeskeygenassist $0x2, %xmm0, %xmm1 # round 2
197 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x02
198 call _key_expansion_128
199 # aeskeygenassist $0x4, %xmm0, %xmm1 # round 3
200 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x04
201 call _key_expansion_128
202 # aeskeygenassist $0x8, %xmm0, %xmm1 # round 4
203 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x08
204 call _key_expansion_128
205 # aeskeygenassist $0x10, %xmm0, %xmm1 # round 5
206 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x10
207 call _key_expansion_128
208 # aeskeygenassist $0x20, %xmm0, %xmm1 # round 6
209 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x20
210 call _key_expansion_128
211 # aeskeygenassist $0x40, %xmm0, %xmm1 # round 7
212 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x40
213 call _key_expansion_128
214 # aeskeygenassist $0x80, %xmm0, %xmm1 # round 8
215 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x80
216 call _key_expansion_128
217 # aeskeygenassist $0x1b, %xmm0, %xmm1 # round 9
218 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x1b
219 call _key_expansion_128
220 # aeskeygenassist $0x36, %xmm0, %xmm1 # round 10
221 .byte 0x66, 0x0f, 0x3a, 0xdf, 0xc8, 0x36
222 call _key_expansion_128
223.Ldec_key:
224 sub $0x10, %rcx
225 movaps (%rdi), %xmm0
226 movaps (%rcx), %xmm1
227 movaps %xmm0, 240(%rcx)
228 movaps %xmm1, 240(%rdi)
229 add $0x10, %rdi
230 lea 240-16(%rcx), %rsi
231.align 4
232.Ldec_key_loop:
233 movaps (%rdi), %xmm0
234 # aesimc %xmm0, %xmm1
235 .byte 0x66, 0x0f, 0x38, 0xdb, 0xc8
236 movaps %xmm1, (%rsi)
237 add $0x10, %rdi
238 sub $0x10, %rsi
239 cmp %rcx, %rdi
240 jb .Ldec_key_loop
241 xor %rax, %rax
242 ret
243
244/*
245 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
246 */
247ENTRY(aesni_enc)
248 movl 480(KEYP), KLEN # key length
249 movups (INP), STATE # input
250 call _aesni_enc1
251 movups STATE, (OUTP) # output
252 ret
253
254/*
255 * _aesni_enc1: internal ABI
256 * input:
257 * KEYP: key struct pointer
258 * KLEN: round count
259 * STATE: initial state (input)
260 * output:
261 * STATE: finial state (output)
262 * changed:
263 * KEY
264 * TKEYP (T1)
265 */
266_aesni_enc1:
267 movaps (KEYP), KEY # key
268 mov KEYP, TKEYP
269 pxor KEY, STATE # round 0
270 add $0x30, TKEYP
271 cmp $24, KLEN
272 jb .Lenc128
273 lea 0x20(TKEYP), TKEYP
274 je .Lenc192
275 add $0x20, TKEYP
276 movaps -0x60(TKEYP), KEY
277 # aesenc KEY, STATE
278 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
279 movaps -0x50(TKEYP), KEY
280 # aesenc KEY, STATE
281 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
282.align 4
283.Lenc192:
284 movaps -0x40(TKEYP), KEY
285 # aesenc KEY, STATE
286 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
287 movaps -0x30(TKEYP), KEY
288 # aesenc KEY, STATE
289 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
290.align 4
291.Lenc128:
292 movaps -0x20(TKEYP), KEY
293 # aesenc KEY, STATE
294 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
295 movaps -0x10(TKEYP), KEY
296 # aesenc KEY, STATE
297 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
298 movaps (TKEYP), KEY
299 # aesenc KEY, STATE
300 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
301 movaps 0x10(TKEYP), KEY
302 # aesenc KEY, STATE
303 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
304 movaps 0x20(TKEYP), KEY
305 # aesenc KEY, STATE
306 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
307 movaps 0x30(TKEYP), KEY
308 # aesenc KEY, STATE
309 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
310 movaps 0x40(TKEYP), KEY
311 # aesenc KEY, STATE
312 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
313 movaps 0x50(TKEYP), KEY
314 # aesenc KEY, STATE
315 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
316 movaps 0x60(TKEYP), KEY
317 # aesenc KEY, STATE
318 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
319 movaps 0x70(TKEYP), KEY
320 # aesenclast KEY, STATE # last round
321 .byte 0x66, 0x0f, 0x38, 0xdd, 0xc2
322 ret
323
324/*
325 * _aesni_enc4: internal ABI
326 * input:
327 * KEYP: key struct pointer
328 * KLEN: round count
329 * STATE1: initial state (input)
330 * STATE2
331 * STATE3
332 * STATE4
333 * output:
334 * STATE1: finial state (output)
335 * STATE2
336 * STATE3
337 * STATE4
338 * changed:
339 * KEY
340 * TKEYP (T1)
341 */
342_aesni_enc4:
343 movaps (KEYP), KEY # key
344 mov KEYP, TKEYP
345 pxor KEY, STATE1 # round 0
346 pxor KEY, STATE2
347 pxor KEY, STATE3
348 pxor KEY, STATE4
349 add $0x30, TKEYP
350 cmp $24, KLEN
351 jb .L4enc128
352 lea 0x20(TKEYP), TKEYP
353 je .L4enc192
354 add $0x20, TKEYP
355 movaps -0x60(TKEYP), KEY
356 # aesenc KEY, STATE1
357 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
358 # aesenc KEY, STATE2
359 .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
360 # aesenc KEY, STATE3
361 .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
362 # aesenc KEY, STATE4
363 .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
364 movaps -0x50(TKEYP), KEY
365 # aesenc KEY, STATE1
366 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
367 # aesenc KEY, STATE2
368 .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
369 # aesenc KEY, STATE3
370 .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
371 # aesenc KEY, STATE4
372 .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
373#.align 4
374.L4enc192:
375 movaps -0x40(TKEYP), KEY
376 # aesenc KEY, STATE1
377 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
378 # aesenc KEY, STATE2
379 .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
380 # aesenc KEY, STATE3
381 .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
382 # aesenc KEY, STATE4
383 .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
384 movaps -0x30(TKEYP), KEY
385 # aesenc KEY, STATE1
386 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
387 # aesenc KEY, STATE2
388 .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
389 # aesenc KEY, STATE3
390 .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
391 # aesenc KEY, STATE4
392 .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
393#.align 4
394.L4enc128:
395 movaps -0x20(TKEYP), KEY
396 # aesenc KEY, STATE1
397 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
398 # aesenc KEY, STATE2
399 .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
400 # aesenc KEY, STATE3
401 .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
402 # aesenc KEY, STATE4
403 .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
404 movaps -0x10(TKEYP), KEY
405 # aesenc KEY, STATE1
406 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
407 # aesenc KEY, STATE2
408 .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
409 # aesenc KEY, STATE3
410 .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
411 # aesenc KEY, STATE4
412 .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
413 movaps (TKEYP), KEY
414 # aesenc KEY, STATE1
415 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
416 # aesenc KEY, STATE2
417 .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
418 # aesenc KEY, STATE3
419 .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
420 # aesenc KEY, STATE4
421 .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
422 movaps 0x10(TKEYP), KEY
423 # aesenc KEY, STATE1
424 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
425 # aesenc KEY, STATE2
426 .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
427 # aesenc KEY, STATE3
428 .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
429 # aesenc KEY, STATE4
430 .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
431 movaps 0x20(TKEYP), KEY
432 # aesenc KEY, STATE1
433 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
434 # aesenc KEY, STATE2
435 .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
436 # aesenc KEY, STATE3
437 .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
438 # aesenc KEY, STATE4
439 .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
440 movaps 0x30(TKEYP), KEY
441 # aesenc KEY, STATE1
442 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
443 # aesenc KEY, STATE2
444 .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
445 # aesenc KEY, STATE3
446 .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
447 # aesenc KEY, STATE4
448 .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
449 movaps 0x40(TKEYP), KEY
450 # aesenc KEY, STATE1
451 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
452 # aesenc KEY, STATE2
453 .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
454 # aesenc KEY, STATE3
455 .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
456 # aesenc KEY, STATE4
457 .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
458 movaps 0x50(TKEYP), KEY
459 # aesenc KEY, STATE1
460 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
461 # aesenc KEY, STATE2
462 .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
463 # aesenc KEY, STATE3
464 .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
465 # aesenc KEY, STATE4
466 .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
467 movaps 0x60(TKEYP), KEY
468 # aesenc KEY, STATE1
469 .byte 0x66, 0x0f, 0x38, 0xdc, 0xc2
470 # aesenc KEY, STATE2
471 .byte 0x66, 0x0f, 0x38, 0xdc, 0xe2
472 # aesenc KEY, STATE3
473 .byte 0x66, 0x0f, 0x38, 0xdc, 0xea
474 # aesenc KEY, STATE4
475 .byte 0x66, 0x0f, 0x38, 0xdc, 0xf2
476 movaps 0x70(TKEYP), KEY
477 # aesenclast KEY, STATE1 # last round
478 .byte 0x66, 0x0f, 0x38, 0xdd, 0xc2
479 # aesenclast KEY, STATE2
480 .byte 0x66, 0x0f, 0x38, 0xdd, 0xe2
481 # aesenclast KEY, STATE3
482 .byte 0x66, 0x0f, 0x38, 0xdd, 0xea
483 # aesenclast KEY, STATE4
484 .byte 0x66, 0x0f, 0x38, 0xdd, 0xf2
485 ret
486
487/*
488 * void aesni_dec (struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
489 */
490ENTRY(aesni_dec)
491 mov 480(KEYP), KLEN # key length
492 add $240, KEYP
493 movups (INP), STATE # input
494 call _aesni_dec1
495 movups STATE, (OUTP) #output
496 ret
497
498/*
499 * _aesni_dec1: internal ABI
500 * input:
501 * KEYP: key struct pointer
502 * KLEN: key length
503 * STATE: initial state (input)
504 * output:
505 * STATE: finial state (output)
506 * changed:
507 * KEY
508 * TKEYP (T1)
509 */
510_aesni_dec1:
511 movaps (KEYP), KEY # key
512 mov KEYP, TKEYP
513 pxor KEY, STATE # round 0
514 add $0x30, TKEYP
515 cmp $24, KLEN
516 jb .Ldec128
517 lea 0x20(TKEYP), TKEYP
518 je .Ldec192
519 add $0x20, TKEYP
520 movaps -0x60(TKEYP), KEY
521 # aesdec KEY, STATE
522 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
523 movaps -0x50(TKEYP), KEY
524 # aesdec KEY, STATE
525 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
526.align 4
527.Ldec192:
528 movaps -0x40(TKEYP), KEY
529 # aesdec KEY, STATE
530 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
531 movaps -0x30(TKEYP), KEY
532 # aesdec KEY, STATE
533 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
534.align 4
535.Ldec128:
536 movaps -0x20(TKEYP), KEY
537 # aesdec KEY, STATE
538 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
539 movaps -0x10(TKEYP), KEY
540 # aesdec KEY, STATE
541 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
542 movaps (TKEYP), KEY
543 # aesdec KEY, STATE
544 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
545 movaps 0x10(TKEYP), KEY
546 # aesdec KEY, STATE
547 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
548 movaps 0x20(TKEYP), KEY
549 # aesdec KEY, STATE
550 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
551 movaps 0x30(TKEYP), KEY
552 # aesdec KEY, STATE
553 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
554 movaps 0x40(TKEYP), KEY
555 # aesdec KEY, STATE
556 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
557 movaps 0x50(TKEYP), KEY
558 # aesdec KEY, STATE
559 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
560 movaps 0x60(TKEYP), KEY
561 # aesdec KEY, STATE
562 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
563 movaps 0x70(TKEYP), KEY
564 # aesdeclast KEY, STATE # last round
565 .byte 0x66, 0x0f, 0x38, 0xdf, 0xc2
566 ret
567
568/*
569 * _aesni_dec4: internal ABI
570 * input:
571 * KEYP: key struct pointer
572 * KLEN: key length
573 * STATE1: initial state (input)
574 * STATE2
575 * STATE3
576 * STATE4
577 * output:
578 * STATE1: finial state (output)
579 * STATE2
580 * STATE3
581 * STATE4
582 * changed:
583 * KEY
584 * TKEYP (T1)
585 */
586_aesni_dec4:
587 movaps (KEYP), KEY # key
588 mov KEYP, TKEYP
589 pxor KEY, STATE1 # round 0
590 pxor KEY, STATE2
591 pxor KEY, STATE3
592 pxor KEY, STATE4
593 add $0x30, TKEYP
594 cmp $24, KLEN
595 jb .L4dec128
596 lea 0x20(TKEYP), TKEYP
597 je .L4dec192
598 add $0x20, TKEYP
599 movaps -0x60(TKEYP), KEY
600 # aesdec KEY, STATE1
601 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
602 # aesdec KEY, STATE2
603 .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
604 # aesdec KEY, STATE3
605 .byte 0x66, 0x0f, 0x38, 0xde, 0xea
606 # aesdec KEY, STATE4
607 .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
608 movaps -0x50(TKEYP), KEY
609 # aesdec KEY, STATE1
610 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
611 # aesdec KEY, STATE2
612 .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
613 # aesdec KEY, STATE3
614 .byte 0x66, 0x0f, 0x38, 0xde, 0xea
615 # aesdec KEY, STATE4
616 .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
617.align 4
618.L4dec192:
619 movaps -0x40(TKEYP), KEY
620 # aesdec KEY, STATE1
621 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
622 # aesdec KEY, STATE2
623 .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
624 # aesdec KEY, STATE3
625 .byte 0x66, 0x0f, 0x38, 0xde, 0xea
626 # aesdec KEY, STATE4
627 .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
628 movaps -0x30(TKEYP), KEY
629 # aesdec KEY, STATE1
630 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
631 # aesdec KEY, STATE2
632 .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
633 # aesdec KEY, STATE3
634 .byte 0x66, 0x0f, 0x38, 0xde, 0xea
635 # aesdec KEY, STATE4
636 .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
637.align 4
638.L4dec128:
639 movaps -0x20(TKEYP), KEY
640 # aesdec KEY, STATE1
641 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
642 # aesdec KEY, STATE2
643 .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
644 # aesdec KEY, STATE3
645 .byte 0x66, 0x0f, 0x38, 0xde, 0xea
646 # aesdec KEY, STATE4
647 .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
648 movaps -0x10(TKEYP), KEY
649 # aesdec KEY, STATE1
650 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
651 # aesdec KEY, STATE2
652 .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
653 # aesdec KEY, STATE3
654 .byte 0x66, 0x0f, 0x38, 0xde, 0xea
655 # aesdec KEY, STATE4
656 .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
657 movaps (TKEYP), KEY
658 # aesdec KEY, STATE1
659 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
660 # aesdec KEY, STATE2
661 .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
662 # aesdec KEY, STATE3
663 .byte 0x66, 0x0f, 0x38, 0xde, 0xea
664 # aesdec KEY, STATE4
665 .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
666 movaps 0x10(TKEYP), KEY
667 # aesdec KEY, STATE1
668 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
669 # aesdec KEY, STATE2
670 .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
671 # aesdec KEY, STATE3
672 .byte 0x66, 0x0f, 0x38, 0xde, 0xea
673 # aesdec KEY, STATE4
674 .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
675 movaps 0x20(TKEYP), KEY
676 # aesdec KEY, STATE1
677 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
678 # aesdec KEY, STATE2
679 .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
680 # aesdec KEY, STATE3
681 .byte 0x66, 0x0f, 0x38, 0xde, 0xea
682 # aesdec KEY, STATE4
683 .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
684 movaps 0x30(TKEYP), KEY
685 # aesdec KEY, STATE1
686 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
687 # aesdec KEY, STATE2
688 .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
689 # aesdec KEY, STATE3
690 .byte 0x66, 0x0f, 0x38, 0xde, 0xea
691 # aesdec KEY, STATE4
692 .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
693 movaps 0x40(TKEYP), KEY
694 # aesdec KEY, STATE1
695 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
696 # aesdec KEY, STATE2
697 .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
698 # aesdec KEY, STATE3
699 .byte 0x66, 0x0f, 0x38, 0xde, 0xea
700 # aesdec KEY, STATE4
701 .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
702 movaps 0x50(TKEYP), KEY
703 # aesdec KEY, STATE1
704 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
705 # aesdec KEY, STATE2
706 .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
707 # aesdec KEY, STATE3
708 .byte 0x66, 0x0f, 0x38, 0xde, 0xea
709 # aesdec KEY, STATE4
710 .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
711 movaps 0x60(TKEYP), KEY
712 # aesdec KEY, STATE1
713 .byte 0x66, 0x0f, 0x38, 0xde, 0xc2
714 # aesdec KEY, STATE2
715 .byte 0x66, 0x0f, 0x38, 0xde, 0xe2
716 # aesdec KEY, STATE3
717 .byte 0x66, 0x0f, 0x38, 0xde, 0xea
718 # aesdec KEY, STATE4
719 .byte 0x66, 0x0f, 0x38, 0xde, 0xf2
720 movaps 0x70(TKEYP), KEY
721 # aesdeclast KEY, STATE1 # last round
722 .byte 0x66, 0x0f, 0x38, 0xdf, 0xc2
723 # aesdeclast KEY, STATE2
724 .byte 0x66, 0x0f, 0x38, 0xdf, 0xe2
725 # aesdeclast KEY, STATE3
726 .byte 0x66, 0x0f, 0x38, 0xdf, 0xea
727 # aesdeclast KEY, STATE4
728 .byte 0x66, 0x0f, 0x38, 0xdf, 0xf2
729 ret
730
731/*
732 * void aesni_ecb_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
733 * size_t len)
734 */
735ENTRY(aesni_ecb_enc)
736 test LEN, LEN # check length
737 jz .Lecb_enc_ret
738 mov 480(KEYP), KLEN
739 cmp $16, LEN
740 jb .Lecb_enc_ret
741 cmp $64, LEN
742 jb .Lecb_enc_loop1
743.align 4
744.Lecb_enc_loop4:
745 movups (INP), STATE1
746 movups 0x10(INP), STATE2
747 movups 0x20(INP), STATE3
748 movups 0x30(INP), STATE4
749 call _aesni_enc4
750 movups STATE1, (OUTP)
751 movups STATE2, 0x10(OUTP)
752 movups STATE3, 0x20(OUTP)
753 movups STATE4, 0x30(OUTP)
754 sub $64, LEN
755 add $64, INP
756 add $64, OUTP
757 cmp $64, LEN
758 jge .Lecb_enc_loop4
759 cmp $16, LEN
760 jb .Lecb_enc_ret
761.align 4
762.Lecb_enc_loop1:
763 movups (INP), STATE1
764 call _aesni_enc1
765 movups STATE1, (OUTP)
766 sub $16, LEN
767 add $16, INP
768 add $16, OUTP
769 cmp $16, LEN
770 jge .Lecb_enc_loop1
771.Lecb_enc_ret:
772 ret
773
774/*
775 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
776 * size_t len);
777 */
778ENTRY(aesni_ecb_dec)
779 test LEN, LEN
780 jz .Lecb_dec_ret
781 mov 480(KEYP), KLEN
782 add $240, KEYP
783 cmp $16, LEN
784 jb .Lecb_dec_ret
785 cmp $64, LEN
786 jb .Lecb_dec_loop1
787.align 4
788.Lecb_dec_loop4:
789 movups (INP), STATE1
790 movups 0x10(INP), STATE2
791 movups 0x20(INP), STATE3
792 movups 0x30(INP), STATE4
793 call _aesni_dec4
794 movups STATE1, (OUTP)
795 movups STATE2, 0x10(OUTP)
796 movups STATE3, 0x20(OUTP)
797 movups STATE4, 0x30(OUTP)
798 sub $64, LEN
799 add $64, INP
800 add $64, OUTP
801 cmp $64, LEN
802 jge .Lecb_dec_loop4
803 cmp $16, LEN
804 jb .Lecb_dec_ret
805.align 4
806.Lecb_dec_loop1:
807 movups (INP), STATE1
808 call _aesni_dec1
809 movups STATE1, (OUTP)
810 sub $16, LEN
811 add $16, INP
812 add $16, OUTP
813 cmp $16, LEN
814 jge .Lecb_dec_loop1
815.Lecb_dec_ret:
816 ret
817
818/*
819 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
820 * size_t len, u8 *iv)
821 */
822ENTRY(aesni_cbc_enc)
823 cmp $16, LEN
824 jb .Lcbc_enc_ret
825 mov 480(KEYP), KLEN
826 movups (IVP), STATE # load iv as initial state
827.align 4
828.Lcbc_enc_loop:
829 movups (INP), IN # load input
830 pxor IN, STATE
831 call _aesni_enc1
832 movups STATE, (OUTP) # store output
833 sub $16, LEN
834 add $16, INP
835 add $16, OUTP
836 cmp $16, LEN
837 jge .Lcbc_enc_loop
838 movups STATE, (IVP)
839.Lcbc_enc_ret:
840 ret
841
842/*
843 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
844 * size_t len, u8 *iv)
845 */
846ENTRY(aesni_cbc_dec)
847 cmp $16, LEN
848 jb .Lcbc_dec_ret
849 mov 480(KEYP), KLEN
850 add $240, KEYP
851 movups (IVP), IV
852 cmp $64, LEN
853 jb .Lcbc_dec_loop1
854.align 4
855.Lcbc_dec_loop4:
856 movups (INP), IN1
857 movaps IN1, STATE1
858 movups 0x10(INP), IN2
859 movaps IN2, STATE2
860 movups 0x20(INP), IN3
861 movaps IN3, STATE3
862 movups 0x30(INP), IN4
863 movaps IN4, STATE4
864 call _aesni_dec4
865 pxor IV, STATE1
866 pxor IN1, STATE2
867 pxor IN2, STATE3
868 pxor IN3, STATE4
869 movaps IN4, IV
870 movups STATE1, (OUTP)
871 movups STATE2, 0x10(OUTP)
872 movups STATE3, 0x20(OUTP)
873 movups STATE4, 0x30(OUTP)
874 sub $64, LEN
875 add $64, INP
876 add $64, OUTP
877 cmp $64, LEN
878 jge .Lcbc_dec_loop4
879 cmp $16, LEN
880 jb .Lcbc_dec_ret
881.align 4
882.Lcbc_dec_loop1:
883 movups (INP), IN
884 movaps IN, STATE
885 call _aesni_dec1
886 pxor IV, STATE
887 movups STATE, (OUTP)
888 movaps IN, IV
889 sub $16, LEN
890 add $16, INP
891 add $16, OUTP
892 cmp $16, LEN
893 jge .Lcbc_dec_loop1
894 movups IV, (IVP)
895.Lcbc_dec_ret:
896 ret
diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c
new file mode 100644
index 000000000000..02af0af65497
--- /dev/null
+++ b/arch/x86/crypto/aesni-intel_glue.c
@@ -0,0 +1,461 @@
1/*
2 * Support for Intel AES-NI instructions. This file contains glue
3 * code, the real AES implementation is in intel-aes_asm.S.
4 *
5 * Copyright (C) 2008, Intel Corp.
6 * Author: Huang Ying <ying.huang@intel.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <linux/hardirq.h>
15#include <linux/types.h>
16#include <linux/crypto.h>
17#include <linux/err.h>
18#include <crypto/algapi.h>
19#include <crypto/aes.h>
20#include <crypto/cryptd.h>
21#include <asm/i387.h>
22#include <asm/aes.h>
23
24struct async_aes_ctx {
25 struct cryptd_ablkcipher *cryptd_tfm;
26};
27
28#define AESNI_ALIGN 16
29#define AES_BLOCK_MASK (~(AES_BLOCK_SIZE-1))
30
31asmlinkage int aesni_set_key(struct crypto_aes_ctx *ctx, const u8 *in_key,
32 unsigned int key_len);
33asmlinkage void aesni_enc(struct crypto_aes_ctx *ctx, u8 *out,
34 const u8 *in);
35asmlinkage void aesni_dec(struct crypto_aes_ctx *ctx, u8 *out,
36 const u8 *in);
37asmlinkage void aesni_ecb_enc(struct crypto_aes_ctx *ctx, u8 *out,
38 const u8 *in, unsigned int len);
39asmlinkage void aesni_ecb_dec(struct crypto_aes_ctx *ctx, u8 *out,
40 const u8 *in, unsigned int len);
41asmlinkage void aesni_cbc_enc(struct crypto_aes_ctx *ctx, u8 *out,
42 const u8 *in, unsigned int len, u8 *iv);
43asmlinkage void aesni_cbc_dec(struct crypto_aes_ctx *ctx, u8 *out,
44 const u8 *in, unsigned int len, u8 *iv);
45
46static inline int kernel_fpu_using(void)
47{
48 if (in_interrupt() && !(read_cr0() & X86_CR0_TS))
49 return 1;
50 return 0;
51}
52
53static inline struct crypto_aes_ctx *aes_ctx(void *raw_ctx)
54{
55 unsigned long addr = (unsigned long)raw_ctx;
56 unsigned long align = AESNI_ALIGN;
57
58 if (align <= crypto_tfm_ctx_alignment())
59 align = 1;
60 return (struct crypto_aes_ctx *)ALIGN(addr, align);
61}
62
63static int aes_set_key_common(struct crypto_tfm *tfm, void *raw_ctx,
64 const u8 *in_key, unsigned int key_len)
65{
66 struct crypto_aes_ctx *ctx = aes_ctx(raw_ctx);
67 u32 *flags = &tfm->crt_flags;
68 int err;
69
70 if (key_len != AES_KEYSIZE_128 && key_len != AES_KEYSIZE_192 &&
71 key_len != AES_KEYSIZE_256) {
72 *flags |= CRYPTO_TFM_RES_BAD_KEY_LEN;
73 return -EINVAL;
74 }
75
76 if (kernel_fpu_using())
77 err = crypto_aes_expand_key(ctx, in_key, key_len);
78 else {
79 kernel_fpu_begin();
80 err = aesni_set_key(ctx, in_key, key_len);
81 kernel_fpu_end();
82 }
83
84 return err;
85}
86
87static int aes_set_key(struct crypto_tfm *tfm, const u8 *in_key,
88 unsigned int key_len)
89{
90 return aes_set_key_common(tfm, crypto_tfm_ctx(tfm), in_key, key_len);
91}
92
93static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
94{
95 struct crypto_aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(tfm));
96
97 if (kernel_fpu_using())
98 crypto_aes_encrypt_x86(ctx, dst, src);
99 else {
100 kernel_fpu_begin();
101 aesni_enc(ctx, dst, src);
102 kernel_fpu_end();
103 }
104}
105
106static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
107{
108 struct crypto_aes_ctx *ctx = aes_ctx(crypto_tfm_ctx(tfm));
109
110 if (kernel_fpu_using())
111 crypto_aes_decrypt_x86(ctx, dst, src);
112 else {
113 kernel_fpu_begin();
114 aesni_dec(ctx, dst, src);
115 kernel_fpu_end();
116 }
117}
118
119static struct crypto_alg aesni_alg = {
120 .cra_name = "aes",
121 .cra_driver_name = "aes-aesni",
122 .cra_priority = 300,
123 .cra_flags = CRYPTO_ALG_TYPE_CIPHER,
124 .cra_blocksize = AES_BLOCK_SIZE,
125 .cra_ctxsize = sizeof(struct crypto_aes_ctx)+AESNI_ALIGN-1,
126 .cra_alignmask = 0,
127 .cra_module = THIS_MODULE,
128 .cra_list = LIST_HEAD_INIT(aesni_alg.cra_list),
129 .cra_u = {
130 .cipher = {
131 .cia_min_keysize = AES_MIN_KEY_SIZE,
132 .cia_max_keysize = AES_MAX_KEY_SIZE,
133 .cia_setkey = aes_set_key,
134 .cia_encrypt = aes_encrypt,
135 .cia_decrypt = aes_decrypt
136 }
137 }
138};
139
140static int ecb_encrypt(struct blkcipher_desc *desc,
141 struct scatterlist *dst, struct scatterlist *src,
142 unsigned int nbytes)
143{
144 struct crypto_aes_ctx *ctx = aes_ctx(crypto_blkcipher_ctx(desc->tfm));
145 struct blkcipher_walk walk;
146 int err;
147
148 blkcipher_walk_init(&walk, dst, src, nbytes);
149 err = blkcipher_walk_virt(desc, &walk);
150
151 kernel_fpu_begin();
152 while ((nbytes = walk.nbytes)) {
153 aesni_ecb_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
154 nbytes & AES_BLOCK_MASK);
155 nbytes &= AES_BLOCK_SIZE - 1;
156 err = blkcipher_walk_done(desc, &walk, nbytes);
157 }
158 kernel_fpu_end();
159
160 return err;
161}
162
163static int ecb_decrypt(struct blkcipher_desc *desc,
164 struct scatterlist *dst, struct scatterlist *src,
165 unsigned int nbytes)
166{
167 struct crypto_aes_ctx *ctx = aes_ctx(crypto_blkcipher_ctx(desc->tfm));
168 struct blkcipher_walk walk;
169 int err;
170
171 blkcipher_walk_init(&walk, dst, src, nbytes);
172 err = blkcipher_walk_virt(desc, &walk);
173
174 kernel_fpu_begin();
175 while ((nbytes = walk.nbytes)) {
176 aesni_ecb_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
177 nbytes & AES_BLOCK_MASK);
178 nbytes &= AES_BLOCK_SIZE - 1;
179 err = blkcipher_walk_done(desc, &walk, nbytes);
180 }
181 kernel_fpu_end();
182
183 return err;
184}
185
186static struct crypto_alg blk_ecb_alg = {
187 .cra_name = "__ecb-aes-aesni",
188 .cra_driver_name = "__driver-ecb-aes-aesni",
189 .cra_priority = 0,
190 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
191 .cra_blocksize = AES_BLOCK_SIZE,
192 .cra_ctxsize = sizeof(struct crypto_aes_ctx)+AESNI_ALIGN-1,
193 .cra_alignmask = 0,
194 .cra_type = &crypto_blkcipher_type,
195 .cra_module = THIS_MODULE,
196 .cra_list = LIST_HEAD_INIT(blk_ecb_alg.cra_list),
197 .cra_u = {
198 .blkcipher = {
199 .min_keysize = AES_MIN_KEY_SIZE,
200 .max_keysize = AES_MAX_KEY_SIZE,
201 .setkey = aes_set_key,
202 .encrypt = ecb_encrypt,
203 .decrypt = ecb_decrypt,
204 },
205 },
206};
207
208static int cbc_encrypt(struct blkcipher_desc *desc,
209 struct scatterlist *dst, struct scatterlist *src,
210 unsigned int nbytes)
211{
212 struct crypto_aes_ctx *ctx = aes_ctx(crypto_blkcipher_ctx(desc->tfm));
213 struct blkcipher_walk walk;
214 int err;
215
216 blkcipher_walk_init(&walk, dst, src, nbytes);
217 err = blkcipher_walk_virt(desc, &walk);
218
219 kernel_fpu_begin();
220 while ((nbytes = walk.nbytes)) {
221 aesni_cbc_enc(ctx, walk.dst.virt.addr, walk.src.virt.addr,
222 nbytes & AES_BLOCK_MASK, walk.iv);
223 nbytes &= AES_BLOCK_SIZE - 1;
224 err = blkcipher_walk_done(desc, &walk, nbytes);
225 }
226 kernel_fpu_end();
227
228 return err;
229}
230
231static int cbc_decrypt(struct blkcipher_desc *desc,
232 struct scatterlist *dst, struct scatterlist *src,
233 unsigned int nbytes)
234{
235 struct crypto_aes_ctx *ctx = aes_ctx(crypto_blkcipher_ctx(desc->tfm));
236 struct blkcipher_walk walk;
237 int err;
238
239 blkcipher_walk_init(&walk, dst, src, nbytes);
240 err = blkcipher_walk_virt(desc, &walk);
241
242 kernel_fpu_begin();
243 while ((nbytes = walk.nbytes)) {
244 aesni_cbc_dec(ctx, walk.dst.virt.addr, walk.src.virt.addr,
245 nbytes & AES_BLOCK_MASK, walk.iv);
246 nbytes &= AES_BLOCK_SIZE - 1;
247 err = blkcipher_walk_done(desc, &walk, nbytes);
248 }
249 kernel_fpu_end();
250
251 return err;
252}
253
254static struct crypto_alg blk_cbc_alg = {
255 .cra_name = "__cbc-aes-aesni",
256 .cra_driver_name = "__driver-cbc-aes-aesni",
257 .cra_priority = 0,
258 .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER,
259 .cra_blocksize = AES_BLOCK_SIZE,
260 .cra_ctxsize = sizeof(struct crypto_aes_ctx)+AESNI_ALIGN-1,
261 .cra_alignmask = 0,
262 .cra_type = &crypto_blkcipher_type,
263 .cra_module = THIS_MODULE,
264 .cra_list = LIST_HEAD_INIT(blk_cbc_alg.cra_list),
265 .cra_u = {
266 .blkcipher = {
267 .min_keysize = AES_MIN_KEY_SIZE,
268 .max_keysize = AES_MAX_KEY_SIZE,
269 .setkey = aes_set_key,
270 .encrypt = cbc_encrypt,
271 .decrypt = cbc_decrypt,
272 },
273 },
274};
275
276static int ablk_set_key(struct crypto_ablkcipher *tfm, const u8 *key,
277 unsigned int key_len)
278{
279 struct async_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm);
280
281 return crypto_ablkcipher_setkey(&ctx->cryptd_tfm->base, key, key_len);
282}
283
284static int ablk_encrypt(struct ablkcipher_request *req)
285{
286 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
287 struct async_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm);
288
289 if (kernel_fpu_using()) {
290 struct ablkcipher_request *cryptd_req =
291 ablkcipher_request_ctx(req);
292 memcpy(cryptd_req, req, sizeof(*req));
293 ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
294 return crypto_ablkcipher_encrypt(cryptd_req);
295 } else {
296 struct blkcipher_desc desc;
297 desc.tfm = cryptd_ablkcipher_child(ctx->cryptd_tfm);
298 desc.info = req->info;
299 desc.flags = 0;
300 return crypto_blkcipher_crt(desc.tfm)->encrypt(
301 &desc, req->dst, req->src, req->nbytes);
302 }
303}
304
305static int ablk_decrypt(struct ablkcipher_request *req)
306{
307 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
308 struct async_aes_ctx *ctx = crypto_ablkcipher_ctx(tfm);
309
310 if (kernel_fpu_using()) {
311 struct ablkcipher_request *cryptd_req =
312 ablkcipher_request_ctx(req);
313 memcpy(cryptd_req, req, sizeof(*req));
314 ablkcipher_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
315 return crypto_ablkcipher_decrypt(cryptd_req);
316 } else {
317 struct blkcipher_desc desc;
318 desc.tfm = cryptd_ablkcipher_child(ctx->cryptd_tfm);
319 desc.info = req->info;
320 desc.flags = 0;
321 return crypto_blkcipher_crt(desc.tfm)->decrypt(
322 &desc, req->dst, req->src, req->nbytes);
323 }
324}
325
326static void ablk_exit(struct crypto_tfm *tfm)
327{
328 struct async_aes_ctx *ctx = crypto_tfm_ctx(tfm);
329
330 cryptd_free_ablkcipher(ctx->cryptd_tfm);
331}
332
333static void ablk_init_common(struct crypto_tfm *tfm,
334 struct cryptd_ablkcipher *cryptd_tfm)
335{
336 struct async_aes_ctx *ctx = crypto_tfm_ctx(tfm);
337
338 ctx->cryptd_tfm = cryptd_tfm;
339 tfm->crt_ablkcipher.reqsize = sizeof(struct ablkcipher_request) +
340 crypto_ablkcipher_reqsize(&cryptd_tfm->base);
341}
342
343static int ablk_ecb_init(struct crypto_tfm *tfm)
344{
345 struct cryptd_ablkcipher *cryptd_tfm;
346
347 cryptd_tfm = cryptd_alloc_ablkcipher("__driver-ecb-aes-aesni", 0, 0);
348 if (IS_ERR(cryptd_tfm))
349 return PTR_ERR(cryptd_tfm);
350 ablk_init_common(tfm, cryptd_tfm);
351 return 0;
352}
353
354static struct crypto_alg ablk_ecb_alg = {
355 .cra_name = "ecb(aes)",
356 .cra_driver_name = "ecb-aes-aesni",
357 .cra_priority = 400,
358 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC,
359 .cra_blocksize = AES_BLOCK_SIZE,
360 .cra_ctxsize = sizeof(struct async_aes_ctx),
361 .cra_alignmask = 0,
362 .cra_type = &crypto_ablkcipher_type,
363 .cra_module = THIS_MODULE,
364 .cra_list = LIST_HEAD_INIT(ablk_ecb_alg.cra_list),
365 .cra_init = ablk_ecb_init,
366 .cra_exit = ablk_exit,
367 .cra_u = {
368 .ablkcipher = {
369 .min_keysize = AES_MIN_KEY_SIZE,
370 .max_keysize = AES_MAX_KEY_SIZE,
371 .setkey = ablk_set_key,
372 .encrypt = ablk_encrypt,
373 .decrypt = ablk_decrypt,
374 },
375 },
376};
377
378static int ablk_cbc_init(struct crypto_tfm *tfm)
379{
380 struct cryptd_ablkcipher *cryptd_tfm;
381
382 cryptd_tfm = cryptd_alloc_ablkcipher("__driver-cbc-aes-aesni", 0, 0);
383 if (IS_ERR(cryptd_tfm))
384 return PTR_ERR(cryptd_tfm);
385 ablk_init_common(tfm, cryptd_tfm);
386 return 0;
387}
388
389static struct crypto_alg ablk_cbc_alg = {
390 .cra_name = "cbc(aes)",
391 .cra_driver_name = "cbc-aes-aesni",
392 .cra_priority = 400,
393 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER|CRYPTO_ALG_ASYNC,
394 .cra_blocksize = AES_BLOCK_SIZE,
395 .cra_ctxsize = sizeof(struct async_aes_ctx),
396 .cra_alignmask = 0,
397 .cra_type = &crypto_ablkcipher_type,
398 .cra_module = THIS_MODULE,
399 .cra_list = LIST_HEAD_INIT(ablk_cbc_alg.cra_list),
400 .cra_init = ablk_cbc_init,
401 .cra_exit = ablk_exit,
402 .cra_u = {
403 .ablkcipher = {
404 .min_keysize = AES_MIN_KEY_SIZE,
405 .max_keysize = AES_MAX_KEY_SIZE,
406 .ivsize = AES_BLOCK_SIZE,
407 .setkey = ablk_set_key,
408 .encrypt = ablk_encrypt,
409 .decrypt = ablk_decrypt,
410 },
411 },
412};
413
414static int __init aesni_init(void)
415{
416 int err;
417
418 if (!cpu_has_aes) {
419 printk(KERN_ERR "Intel AES-NI instructions are not detected.\n");
420 return -ENODEV;
421 }
422 if ((err = crypto_register_alg(&aesni_alg)))
423 goto aes_err;
424 if ((err = crypto_register_alg(&blk_ecb_alg)))
425 goto blk_ecb_err;
426 if ((err = crypto_register_alg(&blk_cbc_alg)))
427 goto blk_cbc_err;
428 if ((err = crypto_register_alg(&ablk_ecb_alg)))
429 goto ablk_ecb_err;
430 if ((err = crypto_register_alg(&ablk_cbc_alg)))
431 goto ablk_cbc_err;
432
433 return err;
434
435ablk_cbc_err:
436 crypto_unregister_alg(&ablk_ecb_alg);
437ablk_ecb_err:
438 crypto_unregister_alg(&blk_cbc_alg);
439blk_cbc_err:
440 crypto_unregister_alg(&blk_ecb_alg);
441blk_ecb_err:
442 crypto_unregister_alg(&aesni_alg);
443aes_err:
444 return err;
445}
446
447static void __exit aesni_exit(void)
448{
449 crypto_unregister_alg(&ablk_cbc_alg);
450 crypto_unregister_alg(&ablk_ecb_alg);
451 crypto_unregister_alg(&blk_cbc_alg);
452 crypto_unregister_alg(&blk_ecb_alg);
453 crypto_unregister_alg(&aesni_alg);
454}
455
456module_init(aesni_init);
457module_exit(aesni_exit);
458
459MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm, Intel AES-NI instructions optimized");
460MODULE_LICENSE("GPL");
461MODULE_ALIAS("aes");
diff --git a/arch/x86/include/asm/aes.h b/arch/x86/include/asm/aes.h
new file mode 100644
index 000000000000..80545a1cbe39
--- /dev/null
+++ b/arch/x86/include/asm/aes.h
@@ -0,0 +1,11 @@
1#ifndef ASM_X86_AES_H
2#define ASM_X86_AES_H
3
4#include <linux/crypto.h>
5#include <crypto/aes.h>
6
7void crypto_aes_encrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst,
8 const u8 *src);
9void crypto_aes_decrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst,
10 const u8 *src);
11#endif
diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index 7301e60dc4a8..0beba0d1468d 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -213,6 +213,7 @@ extern const char * const x86_power_flags[32];
213#define cpu_has_xmm boot_cpu_has(X86_FEATURE_XMM) 213#define cpu_has_xmm boot_cpu_has(X86_FEATURE_XMM)
214#define cpu_has_xmm2 boot_cpu_has(X86_FEATURE_XMM2) 214#define cpu_has_xmm2 boot_cpu_has(X86_FEATURE_XMM2)
215#define cpu_has_xmm3 boot_cpu_has(X86_FEATURE_XMM3) 215#define cpu_has_xmm3 boot_cpu_has(X86_FEATURE_XMM3)
216#define cpu_has_aes boot_cpu_has(X86_FEATURE_AES)
216#define cpu_has_ht boot_cpu_has(X86_FEATURE_HT) 217#define cpu_has_ht boot_cpu_has(X86_FEATURE_HT)
217#define cpu_has_mp boot_cpu_has(X86_FEATURE_MP) 218#define cpu_has_mp boot_cpu_has(X86_FEATURE_MP)
218#define cpu_has_nx boot_cpu_has(X86_FEATURE_NX) 219#define cpu_has_nx boot_cpu_has(X86_FEATURE_NX)
diff --git a/arch/x86/include/asm/timer.h b/arch/x86/include/asm/timer.h
index 2bb6a835c453..4f5c24724856 100644
--- a/arch/x86/include/asm/timer.h
+++ b/arch/x86/include/asm/timer.h
@@ -11,8 +11,8 @@ unsigned long native_calibrate_tsc(void);
11 11
12#ifdef CONFIG_X86_32 12#ifdef CONFIG_X86_32
13extern int timer_ack; 13extern int timer_ack;
14#endif
14extern int recalibrate_cpu_khz(void); 15extern int recalibrate_cpu_khz(void);
15#endif /* CONFIG_X86_32 */
16 16
17extern int no_timer_check; 17extern int no_timer_check;
18 18
diff --git a/arch/x86/kernel/cpu/cpufreq/Kconfig b/arch/x86/kernel/cpu/cpufreq/Kconfig
index 65792c2cc462..52c839875478 100644
--- a/arch/x86/kernel/cpu/cpufreq/Kconfig
+++ b/arch/x86/kernel/cpu/cpufreq/Kconfig
@@ -87,30 +87,15 @@ config X86_POWERNOW_K7_ACPI
87config X86_POWERNOW_K8 87config X86_POWERNOW_K8
88 tristate "AMD Opteron/Athlon64 PowerNow!" 88 tristate "AMD Opteron/Athlon64 PowerNow!"
89 select CPU_FREQ_TABLE 89 select CPU_FREQ_TABLE
90 depends on ACPI && ACPI_PROCESSOR
90 help 91 help
91 This adds the CPUFreq driver for mobile AMD Opteron/Athlon64 processors. 92 This adds the CPUFreq driver for K8/K10 Opteron/Athlon64 processors.
92 93
93 To compile this driver as a module, choose M here: the 94 To compile this driver as a module, choose M here: the
94 module will be called powernow-k8. 95 module will be called powernow-k8.
95 96
96 For details, take a look at <file:Documentation/cpu-freq/>. 97 For details, take a look at <file:Documentation/cpu-freq/>.
97 98
98 If in doubt, say N.
99
100config X86_POWERNOW_K8_ACPI
101 bool
102 prompt "ACPI Support" if X86_32
103 depends on ACPI && X86_POWERNOW_K8 && ACPI_PROCESSOR
104 depends on !(X86_POWERNOW_K8 = y && ACPI_PROCESSOR = m)
105 default y
106 help
107 This provides access to the K8s Processor Performance States via ACPI.
108 This driver is probably required for CPUFreq to work with multi-socket and
109 SMP systems. It is not required on at least some single-socket yet
110 multi-core systems, even if SMP is enabled.
111
112 It is safe to say Y here.
113
114config X86_GX_SUSPMOD 99config X86_GX_SUSPMOD
115 tristate "Cyrix MediaGX/NatSemi Geode Suspend Modulation" 100 tristate "Cyrix MediaGX/NatSemi Geode Suspend Modulation"
116 depends on X86_32 && PCI 101 depends on X86_32 && PCI
diff --git a/arch/x86/kernel/cpu/cpufreq/Makefile b/arch/x86/kernel/cpu/cpufreq/Makefile
index 560f7760dae5..509296df294d 100644
--- a/arch/x86/kernel/cpu/cpufreq/Makefile
+++ b/arch/x86/kernel/cpu/cpufreq/Makefile
@@ -1,6 +1,11 @@
1# Link order matters. K8 is preferred to ACPI because of firmware bugs in early
2# K8 systems. ACPI is preferred to all other hardware-specific drivers.
3# speedstep-* is preferred over p4-clockmod.
4
5obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o
6obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o
1obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o 7obj-$(CONFIG_X86_POWERNOW_K6) += powernow-k6.o
2obj-$(CONFIG_X86_POWERNOW_K7) += powernow-k7.o 8obj-$(CONFIG_X86_POWERNOW_K7) += powernow-k7.o
3obj-$(CONFIG_X86_POWERNOW_K8) += powernow-k8.o
4obj-$(CONFIG_X86_LONGHAUL) += longhaul.o 9obj-$(CONFIG_X86_LONGHAUL) += longhaul.o
5obj-$(CONFIG_X86_E_POWERSAVER) += e_powersaver.o 10obj-$(CONFIG_X86_E_POWERSAVER) += e_powersaver.o
6obj-$(CONFIG_ELAN_CPUFREQ) += elanfreq.o 11obj-$(CONFIG_ELAN_CPUFREQ) += elanfreq.o
@@ -10,7 +15,6 @@ obj-$(CONFIG_X86_GX_SUSPMOD) += gx-suspmod.o
10obj-$(CONFIG_X86_SPEEDSTEP_ICH) += speedstep-ich.o 15obj-$(CONFIG_X86_SPEEDSTEP_ICH) += speedstep-ich.o
11obj-$(CONFIG_X86_SPEEDSTEP_LIB) += speedstep-lib.o 16obj-$(CONFIG_X86_SPEEDSTEP_LIB) += speedstep-lib.o
12obj-$(CONFIG_X86_SPEEDSTEP_SMI) += speedstep-smi.o 17obj-$(CONFIG_X86_SPEEDSTEP_SMI) += speedstep-smi.o
13obj-$(CONFIG_X86_ACPI_CPUFREQ) += acpi-cpufreq.o
14obj-$(CONFIG_X86_SPEEDSTEP_CENTRINO) += speedstep-centrino.o 18obj-$(CONFIG_X86_SPEEDSTEP_CENTRINO) += speedstep-centrino.o
15obj-$(CONFIG_X86_P4_CLOCKMOD) += p4-clockmod.o 19obj-$(CONFIG_X86_P4_CLOCKMOD) += p4-clockmod.o
16obj-$(CONFIG_X86_CPUFREQ_NFORCE2) += cpufreq-nforce2.o 20obj-$(CONFIG_X86_CPUFREQ_NFORCE2) += cpufreq-nforce2.o
diff --git a/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c b/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
index 4b1c319d30c3..3babe1f1e912 100644
--- a/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
+++ b/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * acpi-cpufreq.c - ACPI Processor P-States Driver ($Revision: 1.4 $) 2 * acpi-cpufreq.c - ACPI Processor P-States Driver
3 * 3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> 4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> 5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
@@ -36,16 +36,18 @@
36#include <linux/ftrace.h> 36#include <linux/ftrace.h>
37 37
38#include <linux/acpi.h> 38#include <linux/acpi.h>
39#include <linux/io.h>
40#include <linux/delay.h>
41#include <linux/uaccess.h>
42
39#include <acpi/processor.h> 43#include <acpi/processor.h>
40 44
41#include <asm/io.h>
42#include <asm/msr.h> 45#include <asm/msr.h>
43#include <asm/processor.h> 46#include <asm/processor.h>
44#include <asm/cpufeature.h> 47#include <asm/cpufeature.h>
45#include <asm/delay.h>
46#include <asm/uaccess.h>
47 48
48#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "acpi-cpufreq", msg) 49#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
50 "acpi-cpufreq", msg)
49 51
50MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski"); 52MODULE_AUTHOR("Paul Diefenbaugh, Dominik Brodowski");
51MODULE_DESCRIPTION("ACPI Processor P-States Driver"); 53MODULE_DESCRIPTION("ACPI Processor P-States Driver");
@@ -95,7 +97,7 @@ static unsigned extract_io(u32 value, struct acpi_cpufreq_data *data)
95 97
96 perf = data->acpi_data; 98 perf = data->acpi_data;
97 99
98 for (i=0; i<perf->state_count; i++) { 100 for (i = 0; i < perf->state_count; i++) {
99 if (value == perf->states[i].status) 101 if (value == perf->states[i].status)
100 return data->freq_table[i].frequency; 102 return data->freq_table[i].frequency;
101 } 103 }
@@ -110,7 +112,7 @@ static unsigned extract_msr(u32 msr, struct acpi_cpufreq_data *data)
110 msr &= INTEL_MSR_RANGE; 112 msr &= INTEL_MSR_RANGE;
111 perf = data->acpi_data; 113 perf = data->acpi_data;
112 114
113 for (i=0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) { 115 for (i = 0; data->freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
114 if (msr == perf->states[data->freq_table[i].index].status) 116 if (msr == perf->states[data->freq_table[i].index].status)
115 return data->freq_table[i].frequency; 117 return data->freq_table[i].frequency;
116 } 118 }
@@ -138,15 +140,13 @@ struct io_addr {
138 u8 bit_width; 140 u8 bit_width;
139}; 141};
140 142
141typedef union {
142 struct msr_addr msr;
143 struct io_addr io;
144} drv_addr_union;
145
146struct drv_cmd { 143struct drv_cmd {
147 unsigned int type; 144 unsigned int type;
148 const struct cpumask *mask; 145 const struct cpumask *mask;
149 drv_addr_union addr; 146 union {
147 struct msr_addr msr;
148 struct io_addr io;
149 } addr;
150 u32 val; 150 u32 val;
151}; 151};
152 152
@@ -369,7 +369,7 @@ static unsigned int check_freqs(const struct cpumask *mask, unsigned int freq,
369 unsigned int cur_freq; 369 unsigned int cur_freq;
370 unsigned int i; 370 unsigned int i;
371 371
372 for (i=0; i<100; i++) { 372 for (i = 0; i < 100; i++) {
373 cur_freq = extract_freq(get_cur_val(mask), data); 373 cur_freq = extract_freq(get_cur_val(mask), data);
374 if (cur_freq == freq) 374 if (cur_freq == freq)
375 return 1; 375 return 1;
@@ -494,7 +494,7 @@ acpi_cpufreq_guess_freq(struct acpi_cpufreq_data *data, unsigned int cpu)
494 unsigned long freq; 494 unsigned long freq;
495 unsigned long freqn = perf->states[0].core_frequency * 1000; 495 unsigned long freqn = perf->states[0].core_frequency * 1000;
496 496
497 for (i=0; i<(perf->state_count-1); i++) { 497 for (i = 0; i < (perf->state_count-1); i++) {
498 freq = freqn; 498 freq = freqn;
499 freqn = perf->states[i+1].core_frequency * 1000; 499 freqn = perf->states[i+1].core_frequency * 1000;
500 if ((2 * cpu_khz) > (freqn + freq)) { 500 if ((2 * cpu_khz) > (freqn + freq)) {
@@ -673,7 +673,7 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
673 673
674 /* detect transition latency */ 674 /* detect transition latency */
675 policy->cpuinfo.transition_latency = 0; 675 policy->cpuinfo.transition_latency = 0;
676 for (i=0; i<perf->state_count; i++) { 676 for (i = 0; i < perf->state_count; i++) {
677 if ((perf->states[i].transition_latency * 1000) > 677 if ((perf->states[i].transition_latency * 1000) >
678 policy->cpuinfo.transition_latency) 678 policy->cpuinfo.transition_latency)
679 policy->cpuinfo.transition_latency = 679 policy->cpuinfo.transition_latency =
@@ -682,8 +682,8 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
682 682
683 data->max_freq = perf->states[0].core_frequency * 1000; 683 data->max_freq = perf->states[0].core_frequency * 1000;
684 /* table init */ 684 /* table init */
685 for (i=0; i<perf->state_count; i++) { 685 for (i = 0; i < perf->state_count; i++) {
686 if (i>0 && perf->states[i].core_frequency >= 686 if (i > 0 && perf->states[i].core_frequency >=
687 data->freq_table[valid_states-1].frequency / 1000) 687 data->freq_table[valid_states-1].frequency / 1000)
688 continue; 688 continue;
689 689
diff --git a/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c b/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c
index 965ea52767ac..733093d60436 100644
--- a/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c
+++ b/arch/x86/kernel/cpu/cpufreq/cpufreq-nforce2.c
@@ -32,7 +32,7 @@
32 * nforce2_chipset: 32 * nforce2_chipset:
33 * FSB is changed using the chipset 33 * FSB is changed using the chipset
34 */ 34 */
35static struct pci_dev *nforce2_chipset_dev; 35static struct pci_dev *nforce2_dev;
36 36
37/* fid: 37/* fid:
38 * multiplier * 10 38 * multiplier * 10
@@ -56,7 +56,9 @@ MODULE_PARM_DESC(fid, "CPU multiplier to use (11.5 = 115)");
56MODULE_PARM_DESC(min_fsb, 56MODULE_PARM_DESC(min_fsb,
57 "Minimum FSB to use, if not defined: current FSB - 50"); 57 "Minimum FSB to use, if not defined: current FSB - 50");
58 58
59#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "cpufreq-nforce2", msg) 59#define PFX "cpufreq-nforce2: "
60#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
61 "cpufreq-nforce2", msg)
60 62
61/** 63/**
62 * nforce2_calc_fsb - calculate FSB 64 * nforce2_calc_fsb - calculate FSB
@@ -118,11 +120,11 @@ static void nforce2_write_pll(int pll)
118 int temp; 120 int temp;
119 121
120 /* Set the pll addr. to 0x00 */ 122 /* Set the pll addr. to 0x00 */
121 pci_write_config_dword(nforce2_chipset_dev, NFORCE2_PLLADR, 0); 123 pci_write_config_dword(nforce2_dev, NFORCE2_PLLADR, 0);
122 124
123 /* Now write the value in all 64 registers */ 125 /* Now write the value in all 64 registers */
124 for (temp = 0; temp <= 0x3f; temp++) 126 for (temp = 0; temp <= 0x3f; temp++)
125 pci_write_config_dword(nforce2_chipset_dev, NFORCE2_PLLREG, pll); 127 pci_write_config_dword(nforce2_dev, NFORCE2_PLLREG, pll);
126 128
127 return; 129 return;
128} 130}
@@ -139,8 +141,8 @@ static unsigned int nforce2_fsb_read(int bootfsb)
139 u32 fsb, temp = 0; 141 u32 fsb, temp = 0;
140 142
141 /* Get chipset boot FSB from subdevice 5 (FSB at boot-time) */ 143 /* Get chipset boot FSB from subdevice 5 (FSB at boot-time) */
142 nforce2_sub5 = pci_get_subsys(PCI_VENDOR_ID_NVIDIA, 144 nforce2_sub5 = pci_get_subsys(PCI_VENDOR_ID_NVIDIA, 0x01EF,
143 0x01EF, PCI_ANY_ID, PCI_ANY_ID, NULL); 145 PCI_ANY_ID, PCI_ANY_ID, NULL);
144 if (!nforce2_sub5) 146 if (!nforce2_sub5)
145 return 0; 147 return 0;
146 148
@@ -148,13 +150,13 @@ static unsigned int nforce2_fsb_read(int bootfsb)
148 fsb /= 1000000; 150 fsb /= 1000000;
149 151
150 /* Check if PLL register is already set */ 152 /* Check if PLL register is already set */
151 pci_read_config_byte(nforce2_chipset_dev, NFORCE2_PLLENABLE, (u8 *)&temp); 153 pci_read_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8 *)&temp);
152 154
153 if (bootfsb || !temp) 155 if (bootfsb || !temp)
154 return fsb; 156 return fsb;
155 157
156 /* Use PLL register FSB value */ 158 /* Use PLL register FSB value */
157 pci_read_config_dword(nforce2_chipset_dev, NFORCE2_PLLREG, &temp); 159 pci_read_config_dword(nforce2_dev, NFORCE2_PLLREG, &temp);
158 fsb = nforce2_calc_fsb(temp); 160 fsb = nforce2_calc_fsb(temp);
159 161
160 return fsb; 162 return fsb;
@@ -174,18 +176,18 @@ static int nforce2_set_fsb(unsigned int fsb)
174 int pll = 0; 176 int pll = 0;
175 177
176 if ((fsb > max_fsb) || (fsb < NFORCE2_MIN_FSB)) { 178 if ((fsb > max_fsb) || (fsb < NFORCE2_MIN_FSB)) {
177 printk(KERN_ERR "cpufreq: FSB %d is out of range!\n", fsb); 179 printk(KERN_ERR PFX "FSB %d is out of range!\n", fsb);
178 return -EINVAL; 180 return -EINVAL;
179 } 181 }
180 182
181 tfsb = nforce2_fsb_read(0); 183 tfsb = nforce2_fsb_read(0);
182 if (!tfsb) { 184 if (!tfsb) {
183 printk(KERN_ERR "cpufreq: Error while reading the FSB\n"); 185 printk(KERN_ERR PFX "Error while reading the FSB\n");
184 return -EINVAL; 186 return -EINVAL;
185 } 187 }
186 188
187 /* First write? Then set actual value */ 189 /* First write? Then set actual value */
188 pci_read_config_byte(nforce2_chipset_dev, NFORCE2_PLLENABLE, (u8 *)&temp); 190 pci_read_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8 *)&temp);
189 if (!temp) { 191 if (!temp) {
190 pll = nforce2_calc_pll(tfsb); 192 pll = nforce2_calc_pll(tfsb);
191 193
@@ -197,7 +199,7 @@ static int nforce2_set_fsb(unsigned int fsb)
197 199
198 /* Enable write access */ 200 /* Enable write access */
199 temp = 0x01; 201 temp = 0x01;
200 pci_write_config_byte(nforce2_chipset_dev, NFORCE2_PLLENABLE, (u8)temp); 202 pci_write_config_byte(nforce2_dev, NFORCE2_PLLENABLE, (u8)temp);
201 203
202 diff = tfsb - fsb; 204 diff = tfsb - fsb;
203 205
@@ -222,7 +224,7 @@ static int nforce2_set_fsb(unsigned int fsb)
222 } 224 }
223 225
224 temp = 0x40; 226 temp = 0x40;
225 pci_write_config_byte(nforce2_chipset_dev, NFORCE2_PLLADR, (u8)temp); 227 pci_write_config_byte(nforce2_dev, NFORCE2_PLLADR, (u8)temp);
226 228
227 return 0; 229 return 0;
228} 230}
@@ -244,7 +246,8 @@ static unsigned int nforce2_get(unsigned int cpu)
244 * nforce2_target - set a new CPUFreq policy 246 * nforce2_target - set a new CPUFreq policy
245 * @policy: new policy 247 * @policy: new policy
246 * @target_freq: the target frequency 248 * @target_freq: the target frequency
247 * @relation: how that frequency relates to achieved frequency (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) 249 * @relation: how that frequency relates to achieved frequency
250 * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H)
248 * 251 *
249 * Sets a new CPUFreq policy. 252 * Sets a new CPUFreq policy.
250 */ 253 */
@@ -276,7 +279,7 @@ static int nforce2_target(struct cpufreq_policy *policy,
276 /* local_irq_save(flags); */ 279 /* local_irq_save(flags); */
277 280
278 if (nforce2_set_fsb(target_fsb) < 0) 281 if (nforce2_set_fsb(target_fsb) < 0)
279 printk(KERN_ERR "cpufreq: Changing FSB to %d failed\n", 282 printk(KERN_ERR PFX "Changing FSB to %d failed\n",
280 target_fsb); 283 target_fsb);
281 else 284 else
282 dprintk("Changed FSB successfully to %d\n", 285 dprintk("Changed FSB successfully to %d\n",
@@ -327,8 +330,8 @@ static int nforce2_cpu_init(struct cpufreq_policy *policy)
327 /* FIX: Get FID from CPU */ 330 /* FIX: Get FID from CPU */
328 if (!fid) { 331 if (!fid) {
329 if (!cpu_khz) { 332 if (!cpu_khz) {
330 printk(KERN_WARNING 333 printk(KERN_WARNING PFX
331 "cpufreq: cpu_khz not set, can't calculate multiplier!\n"); 334 "cpu_khz not set, can't calculate multiplier!\n");
332 return -ENODEV; 335 return -ENODEV;
333 } 336 }
334 337
@@ -343,7 +346,7 @@ static int nforce2_cpu_init(struct cpufreq_policy *policy)
343 } 346 }
344 } 347 }
345 348
346 printk(KERN_INFO "cpufreq: FSB currently at %i MHz, FID %d.%d\n", fsb, 349 printk(KERN_INFO PFX "FSB currently at %i MHz, FID %d.%d\n", fsb,
347 fid / 10, fid % 10); 350 fid / 10, fid % 10);
348 351
349 /* Set maximum FSB to FSB at boot time */ 352 /* Set maximum FSB to FSB at boot time */
@@ -392,17 +395,18 @@ static struct cpufreq_driver nforce2_driver = {
392 */ 395 */
393static unsigned int nforce2_detect_chipset(void) 396static unsigned int nforce2_detect_chipset(void)
394{ 397{
395 nforce2_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_NVIDIA, 398 nforce2_dev = pci_get_subsys(PCI_VENDOR_ID_NVIDIA,
396 PCI_DEVICE_ID_NVIDIA_NFORCE2, 399 PCI_DEVICE_ID_NVIDIA_NFORCE2,
397 PCI_ANY_ID, PCI_ANY_ID, NULL); 400 PCI_ANY_ID, PCI_ANY_ID, NULL);
398 401
399 if (nforce2_chipset_dev == NULL) 402 if (nforce2_dev == NULL)
400 return -ENODEV; 403 return -ENODEV;
401 404
402 printk(KERN_INFO "cpufreq: Detected nForce2 chipset revision %X\n", 405 printk(KERN_INFO PFX "Detected nForce2 chipset revision %X\n",
403 nforce2_chipset_dev->revision); 406 nforce2_dev->revision);
404 printk(KERN_INFO 407 printk(KERN_INFO PFX
405 "cpufreq: FSB changing is maybe unstable and can lead to crashes and data loss.\n"); 408 "FSB changing is maybe unstable and can lead to "
409 "crashes and data loss.\n");
406 410
407 return 0; 411 return 0;
408} 412}
@@ -420,7 +424,7 @@ static int __init nforce2_init(void)
420 424
421 /* detect chipset */ 425 /* detect chipset */
422 if (nforce2_detect_chipset()) { 426 if (nforce2_detect_chipset()) {
423 printk(KERN_ERR "cpufreq: No nForce2 chipset.\n"); 427 printk(KERN_INFO PFX "No nForce2 chipset.\n");
424 return -ENODEV; 428 return -ENODEV;
425 } 429 }
426 430
diff --git a/arch/x86/kernel/cpu/cpufreq/e_powersaver.c b/arch/x86/kernel/cpu/cpufreq/e_powersaver.c
index c2f930d86640..3f83ea12c47a 100644
--- a/arch/x86/kernel/cpu/cpufreq/e_powersaver.c
+++ b/arch/x86/kernel/cpu/cpufreq/e_powersaver.c
@@ -12,12 +12,12 @@
12#include <linux/cpufreq.h> 12#include <linux/cpufreq.h>
13#include <linux/ioport.h> 13#include <linux/ioport.h>
14#include <linux/slab.h> 14#include <linux/slab.h>
15#include <linux/timex.h>
16#include <linux/io.h>
17#include <linux/delay.h>
15 18
16#include <asm/msr.h> 19#include <asm/msr.h>
17#include <asm/tsc.h> 20#include <asm/tsc.h>
18#include <asm/timex.h>
19#include <asm/io.h>
20#include <asm/delay.h>
21 21
22#define EPS_BRAND_C7M 0 22#define EPS_BRAND_C7M 0
23#define EPS_BRAND_C7 1 23#define EPS_BRAND_C7 1
@@ -184,7 +184,7 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
184 break; 184 break;
185 } 185 }
186 186
187 switch(brand) { 187 switch (brand) {
188 case EPS_BRAND_C7M: 188 case EPS_BRAND_C7M:
189 printk(KERN_CONT "C7-M\n"); 189 printk(KERN_CONT "C7-M\n");
190 break; 190 break;
@@ -218,17 +218,20 @@ static int eps_cpu_init(struct cpufreq_policy *policy)
218 /* Print voltage and multiplier */ 218 /* Print voltage and multiplier */
219 rdmsr(MSR_IA32_PERF_STATUS, lo, hi); 219 rdmsr(MSR_IA32_PERF_STATUS, lo, hi);
220 current_voltage = lo & 0xff; 220 current_voltage = lo & 0xff;
221 printk(KERN_INFO "eps: Current voltage = %dmV\n", current_voltage * 16 + 700); 221 printk(KERN_INFO "eps: Current voltage = %dmV\n",
222 current_voltage * 16 + 700);
222 current_multiplier = (lo >> 8) & 0xff; 223 current_multiplier = (lo >> 8) & 0xff;
223 printk(KERN_INFO "eps: Current multiplier = %d\n", current_multiplier); 224 printk(KERN_INFO "eps: Current multiplier = %d\n", current_multiplier);
224 225
225 /* Print limits */ 226 /* Print limits */
226 max_voltage = hi & 0xff; 227 max_voltage = hi & 0xff;
227 printk(KERN_INFO "eps: Highest voltage = %dmV\n", max_voltage * 16 + 700); 228 printk(KERN_INFO "eps: Highest voltage = %dmV\n",
229 max_voltage * 16 + 700);
228 max_multiplier = (hi >> 8) & 0xff; 230 max_multiplier = (hi >> 8) & 0xff;
229 printk(KERN_INFO "eps: Highest multiplier = %d\n", max_multiplier); 231 printk(KERN_INFO "eps: Highest multiplier = %d\n", max_multiplier);
230 min_voltage = (hi >> 16) & 0xff; 232 min_voltage = (hi >> 16) & 0xff;
231 printk(KERN_INFO "eps: Lowest voltage = %dmV\n", min_voltage * 16 + 700); 233 printk(KERN_INFO "eps: Lowest voltage = %dmV\n",
234 min_voltage * 16 + 700);
232 min_multiplier = (hi >> 24) & 0xff; 235 min_multiplier = (hi >> 24) & 0xff;
233 printk(KERN_INFO "eps: Lowest multiplier = %d\n", min_multiplier); 236 printk(KERN_INFO "eps: Lowest multiplier = %d\n", min_multiplier);
234 237
@@ -318,7 +321,7 @@ static int eps_cpu_exit(struct cpufreq_policy *policy)
318 return 0; 321 return 0;
319} 322}
320 323
321static struct freq_attr* eps_attr[] = { 324static struct freq_attr *eps_attr[] = {
322 &cpufreq_freq_attr_scaling_available_freqs, 325 &cpufreq_freq_attr_scaling_available_freqs,
323 NULL, 326 NULL,
324}; 327};
@@ -356,7 +359,7 @@ static void __exit eps_exit(void)
356 cpufreq_unregister_driver(&eps_driver); 359 cpufreq_unregister_driver(&eps_driver);
357} 360}
358 361
359MODULE_AUTHOR("Rafa³ Bilski <rafalbilski@interia.pl>"); 362MODULE_AUTHOR("Rafal Bilski <rafalbilski@interia.pl>");
360MODULE_DESCRIPTION("Enhanced PowerSaver driver for VIA C7 CPU's."); 363MODULE_DESCRIPTION("Enhanced PowerSaver driver for VIA C7 CPU's.");
361MODULE_LICENSE("GPL"); 364MODULE_LICENSE("GPL");
362 365
diff --git a/arch/x86/kernel/cpu/cpufreq/elanfreq.c b/arch/x86/kernel/cpu/cpufreq/elanfreq.c
index fe613c93b366..006b278b0d5d 100644
--- a/arch/x86/kernel/cpu/cpufreq/elanfreq.c
+++ b/arch/x86/kernel/cpu/cpufreq/elanfreq.c
@@ -184,7 +184,8 @@ static int elanfreq_target(struct cpufreq_policy *policy,
184{ 184{
185 unsigned int newstate = 0; 185 unsigned int newstate = 0;
186 186
187 if (cpufreq_frequency_table_target(policy, &elanfreq_table[0], target_freq, relation, &newstate)) 187 if (cpufreq_frequency_table_target(policy, &elanfreq_table[0],
188 target_freq, relation, &newstate))
188 return -EINVAL; 189 return -EINVAL;
189 190
190 elanfreq_set_cpu_state(newstate); 191 elanfreq_set_cpu_state(newstate);
@@ -301,7 +302,8 @@ static void __exit elanfreq_exit(void)
301module_param(max_freq, int, 0444); 302module_param(max_freq, int, 0444);
302 303
303MODULE_LICENSE("GPL"); 304MODULE_LICENSE("GPL");
304MODULE_AUTHOR("Robert Schwebel <r.schwebel@pengutronix.de>, Sven Geggus <sven@geggus.net>"); 305MODULE_AUTHOR("Robert Schwebel <r.schwebel@pengutronix.de>, "
306 "Sven Geggus <sven@geggus.net>");
305MODULE_DESCRIPTION("cpufreq driver for AMD's Elan CPUs"); 307MODULE_DESCRIPTION("cpufreq driver for AMD's Elan CPUs");
306 308
307module_init(elanfreq_init); 309module_init(elanfreq_init);
diff --git a/arch/x86/kernel/cpu/cpufreq/gx-suspmod.c b/arch/x86/kernel/cpu/cpufreq/gx-suspmod.c
index 9d9eae82e60f..ac27ec2264d5 100644
--- a/arch/x86/kernel/cpu/cpufreq/gx-suspmod.c
+++ b/arch/x86/kernel/cpu/cpufreq/gx-suspmod.c
@@ -79,8 +79,9 @@
79#include <linux/smp.h> 79#include <linux/smp.h>
80#include <linux/cpufreq.h> 80#include <linux/cpufreq.h>
81#include <linux/pci.h> 81#include <linux/pci.h>
82#include <linux/errno.h>
83
82#include <asm/processor-cyrix.h> 84#include <asm/processor-cyrix.h>
83#include <asm/errno.h>
84 85
85/* PCI config registers, all at F0 */ 86/* PCI config registers, all at F0 */
86#define PCI_PMER1 0x80 /* power management enable register 1 */ 87#define PCI_PMER1 0x80 /* power management enable register 1 */
@@ -122,8 +123,8 @@ static struct gxfreq_params *gx_params;
122static int stock_freq; 123static int stock_freq;
123 124
124/* PCI bus clock - defaults to 30.000 if cpu_khz is not available */ 125/* PCI bus clock - defaults to 30.000 if cpu_khz is not available */
125static int pci_busclk = 0; 126static int pci_busclk;
126module_param (pci_busclk, int, 0444); 127module_param(pci_busclk, int, 0444);
127 128
128/* maximum duration for which the cpu may be suspended 129/* maximum duration for which the cpu may be suspended
129 * (32us * MAX_DURATION). If no parameter is given, this defaults 130 * (32us * MAX_DURATION). If no parameter is given, this defaults
@@ -132,7 +133,7 @@ module_param (pci_busclk, int, 0444);
132 * is suspended -- processing power is just 0.39% of what it used to be, 133 * is suspended -- processing power is just 0.39% of what it used to be,
133 * though. 781.25 kHz(!) for a 200 MHz processor -- wow. */ 134 * though. 781.25 kHz(!) for a 200 MHz processor -- wow. */
134static int max_duration = 255; 135static int max_duration = 255;
135module_param (max_duration, int, 0444); 136module_param(max_duration, int, 0444);
136 137
137/* For the default policy, we want at least some processing power 138/* For the default policy, we want at least some processing power
138 * - let's say 5%. (min = maxfreq / POLICY_MIN_DIV) 139 * - let's say 5%. (min = maxfreq / POLICY_MIN_DIV)
@@ -140,7 +141,8 @@ module_param (max_duration, int, 0444);
140#define POLICY_MIN_DIV 20 141#define POLICY_MIN_DIV 20
141 142
142 143
143#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "gx-suspmod", msg) 144#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
145 "gx-suspmod", msg)
144 146
145/** 147/**
146 * we can detect a core multipiler from dir0_lsb 148 * we can detect a core multipiler from dir0_lsb
@@ -166,12 +168,20 @@ static int gx_freq_mult[16] = {
166 * Low Level chipset interface * 168 * Low Level chipset interface *
167 ****************************************************************/ 169 ****************************************************************/
168static struct pci_device_id gx_chipset_tbl[] __initdata = { 170static struct pci_device_id gx_chipset_tbl[] __initdata = {
169 { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_LEGACY, PCI_ANY_ID, PCI_ANY_ID }, 171 { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_LEGACY,
170 { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5520, PCI_ANY_ID, PCI_ANY_ID }, 172 PCI_ANY_ID, PCI_ANY_ID },
171 { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5510, PCI_ANY_ID, PCI_ANY_ID }, 173 { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5520,
174 PCI_ANY_ID, PCI_ANY_ID },
175 { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5510,
176 PCI_ANY_ID, PCI_ANY_ID },
172 { 0, }, 177 { 0, },
173}; 178};
174 179
180static void gx_write_byte(int reg, int value)
181{
182 pci_write_config_byte(gx_params->cs55x0, reg, value);
183}
184
175/** 185/**
176 * gx_detect_chipset: 186 * gx_detect_chipset:
177 * 187 *
@@ -200,7 +210,8 @@ static __init struct pci_dev *gx_detect_chipset(void)
200/** 210/**
201 * gx_get_cpuspeed: 211 * gx_get_cpuspeed:
202 * 212 *
203 * Finds out at which efficient frequency the Cyrix MediaGX/NatSemi Geode CPU runs. 213 * Finds out at which efficient frequency the Cyrix MediaGX/NatSemi
214 * Geode CPU runs.
204 */ 215 */
205static unsigned int gx_get_cpuspeed(unsigned int cpu) 216static unsigned int gx_get_cpuspeed(unsigned int cpu)
206{ 217{
@@ -217,17 +228,18 @@ static unsigned int gx_get_cpuspeed(unsigned int cpu)
217 * 228 *
218 **/ 229 **/
219 230
220static unsigned int gx_validate_speed(unsigned int khz, u8 *on_duration, u8 *off_duration) 231static unsigned int gx_validate_speed(unsigned int khz, u8 *on_duration,
232 u8 *off_duration)
221{ 233{
222 unsigned int i; 234 unsigned int i;
223 u8 tmp_on, tmp_off; 235 u8 tmp_on, tmp_off;
224 int old_tmp_freq = stock_freq; 236 int old_tmp_freq = stock_freq;
225 int tmp_freq; 237 int tmp_freq;
226 238
227 *off_duration=1; 239 *off_duration = 1;
228 *on_duration=0; 240 *on_duration = 0;
229 241
230 for (i=max_duration; i>0; i--) { 242 for (i = max_duration; i > 0; i--) {
231 tmp_off = ((khz * i) / stock_freq) & 0xff; 243 tmp_off = ((khz * i) / stock_freq) & 0xff;
232 tmp_on = i - tmp_off; 244 tmp_on = i - tmp_off;
233 tmp_freq = (stock_freq * tmp_off) / i; 245 tmp_freq = (stock_freq * tmp_off) / i;
@@ -259,26 +271,34 @@ static void gx_set_cpuspeed(unsigned int khz)
259 freqs.cpu = 0; 271 freqs.cpu = 0;
260 freqs.old = gx_get_cpuspeed(0); 272 freqs.old = gx_get_cpuspeed(0);
261 273
262 new_khz = gx_validate_speed(khz, &gx_params->on_duration, &gx_params->off_duration); 274 new_khz = gx_validate_speed(khz, &gx_params->on_duration,
275 &gx_params->off_duration);
263 276
264 freqs.new = new_khz; 277 freqs.new = new_khz;
265 278
266 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); 279 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
267 local_irq_save(flags); 280 local_irq_save(flags);
268 281
269 if (new_khz != stock_freq) { /* if new khz == 100% of CPU speed, it is special case */ 282
283
284 if (new_khz != stock_freq) {
285 /* if new khz == 100% of CPU speed, it is special case */
270 switch (gx_params->cs55x0->device) { 286 switch (gx_params->cs55x0->device) {
271 case PCI_DEVICE_ID_CYRIX_5530_LEGACY: 287 case PCI_DEVICE_ID_CYRIX_5530_LEGACY:
272 pmer1 = gx_params->pci_pmer1 | IRQ_SPDUP | VID_SPDUP; 288 pmer1 = gx_params->pci_pmer1 | IRQ_SPDUP | VID_SPDUP;
273 /* FIXME: need to test other values -- Zwane,Miura */ 289 /* FIXME: need to test other values -- Zwane,Miura */
274 pci_write_config_byte(gx_params->cs55x0, PCI_IRQTC, 4); /* typical 2 to 4ms */ 290 /* typical 2 to 4ms */
275 pci_write_config_byte(gx_params->cs55x0, PCI_VIDTC, 100);/* typical 50 to 100ms */ 291 gx_write_byte(PCI_IRQTC, 4);
276 pci_write_config_byte(gx_params->cs55x0, PCI_PMER1, pmer1); 292 /* typical 50 to 100ms */
277 293 gx_write_byte(PCI_VIDTC, 100);
278 if (gx_params->cs55x0->revision < 0x10) { /* CS5530(rev 1.2, 1.3) */ 294 gx_write_byte(PCI_PMER1, pmer1);
279 suscfg = gx_params->pci_suscfg | SUSMOD; 295
280 } else { /* CS5530A,B.. */ 296 if (gx_params->cs55x0->revision < 0x10) {
281 suscfg = gx_params->pci_suscfg | SUSMOD | PWRSVE; 297 /* CS5530(rev 1.2, 1.3) */
298 suscfg = gx_params->pci_suscfg|SUSMOD;
299 } else {
300 /* CS5530A,B.. */
301 suscfg = gx_params->pci_suscfg|SUSMOD|PWRSVE;
282 } 302 }
283 break; 303 break;
284 case PCI_DEVICE_ID_CYRIX_5520: 304 case PCI_DEVICE_ID_CYRIX_5520:
@@ -294,13 +314,13 @@ static void gx_set_cpuspeed(unsigned int khz)
294 suscfg = gx_params->pci_suscfg & ~(SUSMOD); 314 suscfg = gx_params->pci_suscfg & ~(SUSMOD);
295 gx_params->off_duration = 0; 315 gx_params->off_duration = 0;
296 gx_params->on_duration = 0; 316 gx_params->on_duration = 0;
297 dprintk("suspend modulation disabled: cpu runs 100 percent speed.\n"); 317 dprintk("suspend modulation disabled: cpu runs 100%% speed.\n");
298 } 318 }
299 319
300 pci_write_config_byte(gx_params->cs55x0, PCI_MODOFF, gx_params->off_duration); 320 gx_write_byte(PCI_MODOFF, gx_params->off_duration);
301 pci_write_config_byte(gx_params->cs55x0, PCI_MODON, gx_params->on_duration); 321 gx_write_byte(PCI_MODON, gx_params->on_duration);
302 322
303 pci_write_config_byte(gx_params->cs55x0, PCI_SUSCFG, suscfg); 323 gx_write_byte(PCI_SUSCFG, suscfg);
304 pci_read_config_byte(gx_params->cs55x0, PCI_SUSCFG, &suscfg); 324 pci_read_config_byte(gx_params->cs55x0, PCI_SUSCFG, &suscfg);
305 325
306 local_irq_restore(flags); 326 local_irq_restore(flags);
@@ -334,7 +354,8 @@ static int cpufreq_gx_verify(struct cpufreq_policy *policy)
334 return -EINVAL; 354 return -EINVAL;
335 355
336 policy->cpu = 0; 356 policy->cpu = 0;
337 cpufreq_verify_within_limits(policy, (stock_freq / max_duration), stock_freq); 357 cpufreq_verify_within_limits(policy, (stock_freq / max_duration),
358 stock_freq);
338 359
339 /* it needs to be assured that at least one supported frequency is 360 /* it needs to be assured that at least one supported frequency is
340 * within policy->min and policy->max. If it is not, policy->max 361 * within policy->min and policy->max. If it is not, policy->max
@@ -354,7 +375,8 @@ static int cpufreq_gx_verify(struct cpufreq_policy *policy)
354 policy->max = tmp_freq; 375 policy->max = tmp_freq;
355 if (policy->max < policy->min) 376 if (policy->max < policy->min)
356 policy->max = policy->min; 377 policy->max = policy->min;
357 cpufreq_verify_within_limits(policy, (stock_freq / max_duration), stock_freq); 378 cpufreq_verify_within_limits(policy, (stock_freq / max_duration),
379 stock_freq);
358 380
359 return 0; 381 return 0;
360} 382}
@@ -398,18 +420,18 @@ static int cpufreq_gx_cpu_init(struct cpufreq_policy *policy)
398 return -ENODEV; 420 return -ENODEV;
399 421
400 /* determine maximum frequency */ 422 /* determine maximum frequency */
401 if (pci_busclk) { 423 if (pci_busclk)
402 maxfreq = pci_busclk * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f]; 424 maxfreq = pci_busclk * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f];
403 } else if (cpu_khz) { 425 else if (cpu_khz)
404 maxfreq = cpu_khz; 426 maxfreq = cpu_khz;
405 } else { 427 else
406 maxfreq = 30000 * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f]; 428 maxfreq = 30000 * gx_freq_mult[getCx86(CX86_DIR1) & 0x0f];
407 } 429
408 stock_freq = maxfreq; 430 stock_freq = maxfreq;
409 curfreq = gx_get_cpuspeed(0); 431 curfreq = gx_get_cpuspeed(0);
410 432
411 dprintk("cpu max frequency is %d.\n", maxfreq); 433 dprintk("cpu max frequency is %d.\n", maxfreq);
412 dprintk("cpu current frequency is %dkHz.\n",curfreq); 434 dprintk("cpu current frequency is %dkHz.\n", curfreq);
413 435
414 /* setup basic struct for cpufreq API */ 436 /* setup basic struct for cpufreq API */
415 policy->cpu = 0; 437 policy->cpu = 0;
@@ -447,7 +469,8 @@ static int __init cpufreq_gx_init(void)
447 struct pci_dev *gx_pci; 469 struct pci_dev *gx_pci;
448 470
449 /* Test if we have the right hardware */ 471 /* Test if we have the right hardware */
450 if ((gx_pci = gx_detect_chipset()) == NULL) 472 gx_pci = gx_detect_chipset();
473 if (gx_pci == NULL)
451 return -ENODEV; 474 return -ENODEV;
452 475
453 /* check whether module parameters are sane */ 476 /* check whether module parameters are sane */
@@ -468,9 +491,11 @@ static int __init cpufreq_gx_init(void)
468 pci_read_config_byte(params->cs55x0, PCI_PMER1, &(params->pci_pmer1)); 491 pci_read_config_byte(params->cs55x0, PCI_PMER1, &(params->pci_pmer1));
469 pci_read_config_byte(params->cs55x0, PCI_PMER2, &(params->pci_pmer2)); 492 pci_read_config_byte(params->cs55x0, PCI_PMER2, &(params->pci_pmer2));
470 pci_read_config_byte(params->cs55x0, PCI_MODON, &(params->on_duration)); 493 pci_read_config_byte(params->cs55x0, PCI_MODON, &(params->on_duration));
471 pci_read_config_byte(params->cs55x0, PCI_MODOFF, &(params->off_duration)); 494 pci_read_config_byte(params->cs55x0, PCI_MODOFF,
495 &(params->off_duration));
472 496
473 if ((ret = cpufreq_register_driver(&gx_suspmod_driver))) { 497 ret = cpufreq_register_driver(&gx_suspmod_driver);
498 if (ret) {
474 kfree(params); 499 kfree(params);
475 return ret; /* register error! */ 500 return ret; /* register error! */
476 } 501 }
@@ -485,9 +510,9 @@ static void __exit cpufreq_gx_exit(void)
485 kfree(gx_params); 510 kfree(gx_params);
486} 511}
487 512
488MODULE_AUTHOR ("Hiroshi Miura <miura@da-cha.org>"); 513MODULE_AUTHOR("Hiroshi Miura <miura@da-cha.org>");
489MODULE_DESCRIPTION ("Cpufreq driver for Cyrix MediaGX and NatSemi Geode"); 514MODULE_DESCRIPTION("Cpufreq driver for Cyrix MediaGX and NatSemi Geode");
490MODULE_LICENSE ("GPL"); 515MODULE_LICENSE("GPL");
491 516
492module_init(cpufreq_gx_init); 517module_init(cpufreq_gx_init);
493module_exit(cpufreq_gx_exit); 518module_exit(cpufreq_gx_exit);
diff --git a/arch/x86/kernel/cpu/cpufreq/longhaul.c b/arch/x86/kernel/cpu/cpufreq/longhaul.c
index a4cff5d6e380..f1c51aea064d 100644
--- a/arch/x86/kernel/cpu/cpufreq/longhaul.c
+++ b/arch/x86/kernel/cpu/cpufreq/longhaul.c
@@ -30,12 +30,12 @@
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/string.h> 31#include <linux/string.h>
32#include <linux/delay.h> 32#include <linux/delay.h>
33#include <linux/timex.h>
34#include <linux/io.h>
35#include <linux/acpi.h>
36#include <linux/kernel.h>
33 37
34#include <asm/msr.h> 38#include <asm/msr.h>
35#include <asm/timex.h>
36#include <asm/io.h>
37#include <asm/acpi.h>
38#include <linux/acpi.h>
39#include <acpi/processor.h> 39#include <acpi/processor.h>
40 40
41#include "longhaul.h" 41#include "longhaul.h"
@@ -58,7 +58,7 @@
58#define USE_NORTHBRIDGE (1 << 2) 58#define USE_NORTHBRIDGE (1 << 2)
59 59
60static int cpu_model; 60static int cpu_model;
61static unsigned int numscales=16; 61static unsigned int numscales = 16;
62static unsigned int fsb; 62static unsigned int fsb;
63 63
64static const struct mV_pos *vrm_mV_table; 64static const struct mV_pos *vrm_mV_table;
@@ -67,8 +67,8 @@ static const unsigned char *mV_vrm_table;
67static unsigned int highest_speed, lowest_speed; /* kHz */ 67static unsigned int highest_speed, lowest_speed; /* kHz */
68static unsigned int minmult, maxmult; 68static unsigned int minmult, maxmult;
69static int can_scale_voltage; 69static int can_scale_voltage;
70static struct acpi_processor *pr = NULL; 70static struct acpi_processor *pr;
71static struct acpi_processor_cx *cx = NULL; 71static struct acpi_processor_cx *cx;
72static u32 acpi_regs_addr; 72static u32 acpi_regs_addr;
73static u8 longhaul_flags; 73static u8 longhaul_flags;
74static unsigned int longhaul_index; 74static unsigned int longhaul_index;
@@ -78,12 +78,13 @@ static int scale_voltage;
78static int disable_acpi_c3; 78static int disable_acpi_c3;
79static int revid_errata; 79static int revid_errata;
80 80
81#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "longhaul", msg) 81#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
82 "longhaul", msg)
82 83
83 84
84/* Clock ratios multiplied by 10 */ 85/* Clock ratios multiplied by 10 */
85static int clock_ratio[32]; 86static int mults[32];
86static int eblcr_table[32]; 87static int eblcr[32];
87static int longhaul_version; 88static int longhaul_version;
88static struct cpufreq_frequency_table *longhaul_table; 89static struct cpufreq_frequency_table *longhaul_table;
89 90
@@ -93,7 +94,7 @@ static char speedbuffer[8];
93static char *print_speed(int speed) 94static char *print_speed(int speed)
94{ 95{
95 if (speed < 1000) { 96 if (speed < 1000) {
96 snprintf(speedbuffer, sizeof(speedbuffer),"%dMHz", speed); 97 snprintf(speedbuffer, sizeof(speedbuffer), "%dMHz", speed);
97 return speedbuffer; 98 return speedbuffer;
98 } 99 }
99 100
@@ -122,27 +123,28 @@ static unsigned int calc_speed(int mult)
122 123
123static int longhaul_get_cpu_mult(void) 124static int longhaul_get_cpu_mult(void)
124{ 125{
125 unsigned long invalue=0,lo, hi; 126 unsigned long invalue = 0, lo, hi;
126 127
127 rdmsr (MSR_IA32_EBL_CR_POWERON, lo, hi); 128 rdmsr(MSR_IA32_EBL_CR_POWERON, lo, hi);
128 invalue = (lo & (1<<22|1<<23|1<<24|1<<25)) >>22; 129 invalue = (lo & (1<<22|1<<23|1<<24|1<<25))>>22;
129 if (longhaul_version==TYPE_LONGHAUL_V2 || longhaul_version==TYPE_POWERSAVER) { 130 if (longhaul_version == TYPE_LONGHAUL_V2 ||
131 longhaul_version == TYPE_POWERSAVER) {
130 if (lo & (1<<27)) 132 if (lo & (1<<27))
131 invalue+=16; 133 invalue += 16;
132 } 134 }
133 return eblcr_table[invalue]; 135 return eblcr[invalue];
134} 136}
135 137
136/* For processor with BCR2 MSR */ 138/* For processor with BCR2 MSR */
137 139
138static void do_longhaul1(unsigned int clock_ratio_index) 140static void do_longhaul1(unsigned int mults_index)
139{ 141{
140 union msr_bcr2 bcr2; 142 union msr_bcr2 bcr2;
141 143
142 rdmsrl(MSR_VIA_BCR2, bcr2.val); 144 rdmsrl(MSR_VIA_BCR2, bcr2.val);
143 /* Enable software clock multiplier */ 145 /* Enable software clock multiplier */
144 bcr2.bits.ESOFTBF = 1; 146 bcr2.bits.ESOFTBF = 1;
145 bcr2.bits.CLOCKMUL = clock_ratio_index & 0xff; 147 bcr2.bits.CLOCKMUL = mults_index & 0xff;
146 148
147 /* Sync to timer tick */ 149 /* Sync to timer tick */
148 safe_halt(); 150 safe_halt();
@@ -161,7 +163,7 @@ static void do_longhaul1(unsigned int clock_ratio_index)
161 163
162/* For processor with Longhaul MSR */ 164/* For processor with Longhaul MSR */
163 165
164static void do_powersaver(int cx_address, unsigned int clock_ratio_index, 166static void do_powersaver(int cx_address, unsigned int mults_index,
165 unsigned int dir) 167 unsigned int dir)
166{ 168{
167 union msr_longhaul longhaul; 169 union msr_longhaul longhaul;
@@ -173,11 +175,11 @@ static void do_powersaver(int cx_address, unsigned int clock_ratio_index,
173 longhaul.bits.RevisionKey = longhaul.bits.RevisionID; 175 longhaul.bits.RevisionKey = longhaul.bits.RevisionID;
174 else 176 else
175 longhaul.bits.RevisionKey = 0; 177 longhaul.bits.RevisionKey = 0;
176 longhaul.bits.SoftBusRatio = clock_ratio_index & 0xf; 178 longhaul.bits.SoftBusRatio = mults_index & 0xf;
177 longhaul.bits.SoftBusRatio4 = (clock_ratio_index & 0x10) >> 4; 179 longhaul.bits.SoftBusRatio4 = (mults_index & 0x10) >> 4;
178 /* Setup new voltage */ 180 /* Setup new voltage */
179 if (can_scale_voltage) 181 if (can_scale_voltage)
180 longhaul.bits.SoftVID = (clock_ratio_index >> 8) & 0x1f; 182 longhaul.bits.SoftVID = (mults_index >> 8) & 0x1f;
181 /* Sync to timer tick */ 183 /* Sync to timer tick */
182 safe_halt(); 184 safe_halt();
183 /* Raise voltage if necessary */ 185 /* Raise voltage if necessary */
@@ -240,14 +242,14 @@ static void do_powersaver(int cx_address, unsigned int clock_ratio_index,
240 242
241/** 243/**
242 * longhaul_set_cpu_frequency() 244 * longhaul_set_cpu_frequency()
243 * @clock_ratio_index : bitpattern of the new multiplier. 245 * @mults_index : bitpattern of the new multiplier.
244 * 246 *
245 * Sets a new clock ratio. 247 * Sets a new clock ratio.
246 */ 248 */
247 249
248static void longhaul_setstate(unsigned int table_index) 250static void longhaul_setstate(unsigned int table_index)
249{ 251{
250 unsigned int clock_ratio_index; 252 unsigned int mults_index;
251 int speed, mult; 253 int speed, mult;
252 struct cpufreq_freqs freqs; 254 struct cpufreq_freqs freqs;
253 unsigned long flags; 255 unsigned long flags;
@@ -256,9 +258,9 @@ static void longhaul_setstate(unsigned int table_index)
256 u32 bm_timeout = 1000; 258 u32 bm_timeout = 1000;
257 unsigned int dir = 0; 259 unsigned int dir = 0;
258 260
259 clock_ratio_index = longhaul_table[table_index].index; 261 mults_index = longhaul_table[table_index].index;
260 /* Safety precautions */ 262 /* Safety precautions */
261 mult = clock_ratio[clock_ratio_index & 0x1f]; 263 mult = mults[mults_index & 0x1f];
262 if (mult == -1) 264 if (mult == -1)
263 return; 265 return;
264 speed = calc_speed(mult); 266 speed = calc_speed(mult);
@@ -274,7 +276,7 @@ static void longhaul_setstate(unsigned int table_index)
274 276
275 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); 277 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
276 278
277 dprintk ("Setting to FSB:%dMHz Mult:%d.%dx (%s)\n", 279 dprintk("Setting to FSB:%dMHz Mult:%d.%dx (%s)\n",
278 fsb, mult/10, mult%10, print_speed(speed/1000)); 280 fsb, mult/10, mult%10, print_speed(speed/1000));
279retry_loop: 281retry_loop:
280 preempt_disable(); 282 preempt_disable();
@@ -282,8 +284,8 @@ retry_loop:
282 284
283 pic2_mask = inb(0xA1); 285 pic2_mask = inb(0xA1);
284 pic1_mask = inb(0x21); /* works on C3. save mask. */ 286 pic1_mask = inb(0x21); /* works on C3. save mask. */
285 outb(0xFF,0xA1); /* Overkill */ 287 outb(0xFF, 0xA1); /* Overkill */
286 outb(0xFE,0x21); /* TMR0 only */ 288 outb(0xFE, 0x21); /* TMR0 only */
287 289
288 /* Wait while PCI bus is busy. */ 290 /* Wait while PCI bus is busy. */
289 if (acpi_regs_addr && (longhaul_flags & USE_NORTHBRIDGE 291 if (acpi_regs_addr && (longhaul_flags & USE_NORTHBRIDGE
@@ -312,7 +314,7 @@ retry_loop:
312 * Software controlled multipliers only. 314 * Software controlled multipliers only.
313 */ 315 */
314 case TYPE_LONGHAUL_V1: 316 case TYPE_LONGHAUL_V1:
315 do_longhaul1(clock_ratio_index); 317 do_longhaul1(mults_index);
316 break; 318 break;
317 319
318 /* 320 /*
@@ -327,9 +329,9 @@ retry_loop:
327 if (longhaul_flags & USE_ACPI_C3) { 329 if (longhaul_flags & USE_ACPI_C3) {
328 /* Don't allow wakeup */ 330 /* Don't allow wakeup */
329 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0); 331 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
330 do_powersaver(cx->address, clock_ratio_index, dir); 332 do_powersaver(cx->address, mults_index, dir);
331 } else { 333 } else {
332 do_powersaver(0, clock_ratio_index, dir); 334 do_powersaver(0, mults_index, dir);
333 } 335 }
334 break; 336 break;
335 } 337 }
@@ -341,8 +343,8 @@ retry_loop:
341 /* Enable bus master arbitration */ 343 /* Enable bus master arbitration */
342 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0); 344 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
343 } 345 }
344 outb(pic2_mask,0xA1); /* restore mask */ 346 outb(pic2_mask, 0xA1); /* restore mask */
345 outb(pic1_mask,0x21); 347 outb(pic1_mask, 0x21);
346 348
347 local_irq_restore(flags); 349 local_irq_restore(flags);
348 preempt_enable(); 350 preempt_enable();
@@ -392,7 +394,8 @@ retry_loop:
392 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); 394 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
393 395
394 if (!bm_timeout) 396 if (!bm_timeout)
395 printk(KERN_INFO PFX "Warning: Timeout while waiting for idle PCI bus.\n"); 397 printk(KERN_INFO PFX "Warning: Timeout while waiting for "
398 "idle PCI bus.\n");
396} 399}
397 400
398/* 401/*
@@ -458,31 +461,32 @@ static int __init longhaul_get_ranges(void)
458 break; 461 break;
459 } 462 }
460 463
461 dprintk ("MinMult:%d.%dx MaxMult:%d.%dx\n", 464 dprintk("MinMult:%d.%dx MaxMult:%d.%dx\n",
462 minmult/10, minmult%10, maxmult/10, maxmult%10); 465 minmult/10, minmult%10, maxmult/10, maxmult%10);
463 466
464 highest_speed = calc_speed(maxmult); 467 highest_speed = calc_speed(maxmult);
465 lowest_speed = calc_speed(minmult); 468 lowest_speed = calc_speed(minmult);
466 dprintk ("FSB:%dMHz Lowest speed: %s Highest speed:%s\n", fsb, 469 dprintk("FSB:%dMHz Lowest speed: %s Highest speed:%s\n", fsb,
467 print_speed(lowest_speed/1000), 470 print_speed(lowest_speed/1000),
468 print_speed(highest_speed/1000)); 471 print_speed(highest_speed/1000));
469 472
470 if (lowest_speed == highest_speed) { 473 if (lowest_speed == highest_speed) {
471 printk (KERN_INFO PFX "highestspeed == lowest, aborting.\n"); 474 printk(KERN_INFO PFX "highestspeed == lowest, aborting.\n");
472 return -EINVAL; 475 return -EINVAL;
473 } 476 }
474 if (lowest_speed > highest_speed) { 477 if (lowest_speed > highest_speed) {
475 printk (KERN_INFO PFX "nonsense! lowest (%d > %d) !\n", 478 printk(KERN_INFO PFX "nonsense! lowest (%d > %d) !\n",
476 lowest_speed, highest_speed); 479 lowest_speed, highest_speed);
477 return -EINVAL; 480 return -EINVAL;
478 } 481 }
479 482
480 longhaul_table = kmalloc((numscales + 1) * sizeof(struct cpufreq_frequency_table), GFP_KERNEL); 483 longhaul_table = kmalloc((numscales + 1) * sizeof(*longhaul_table),
481 if(!longhaul_table) 484 GFP_KERNEL);
485 if (!longhaul_table)
482 return -ENOMEM; 486 return -ENOMEM;
483 487
484 for (j = 0; j < numscales; j++) { 488 for (j = 0; j < numscales; j++) {
485 ratio = clock_ratio[j]; 489 ratio = mults[j];
486 if (ratio == -1) 490 if (ratio == -1)
487 continue; 491 continue;
488 if (ratio > maxmult || ratio < minmult) 492 if (ratio > maxmult || ratio < minmult)
@@ -507,13 +511,10 @@ static int __init longhaul_get_ranges(void)
507 } 511 }
508 } 512 }
509 if (min_i != j) { 513 if (min_i != j) {
510 unsigned int temp; 514 swap(longhaul_table[j].frequency,
511 temp = longhaul_table[j].frequency; 515 longhaul_table[min_i].frequency);
512 longhaul_table[j].frequency = longhaul_table[min_i].frequency; 516 swap(longhaul_table[j].index,
513 longhaul_table[min_i].frequency = temp; 517 longhaul_table[min_i].index);
514 temp = longhaul_table[j].index;
515 longhaul_table[j].index = longhaul_table[min_i].index;
516 longhaul_table[min_i].index = temp;
517 } 518 }
518 } 519 }
519 520
@@ -521,7 +522,7 @@ static int __init longhaul_get_ranges(void)
521 522
522 /* Find index we are running on */ 523 /* Find index we are running on */
523 for (j = 0; j < k; j++) { 524 for (j = 0; j < k; j++) {
524 if (clock_ratio[longhaul_table[j].index & 0x1f] == mult) { 525 if (mults[longhaul_table[j].index & 0x1f] == mult) {
525 longhaul_index = j; 526 longhaul_index = j;
526 break; 527 break;
527 } 528 }
@@ -559,20 +560,22 @@ static void __init longhaul_setup_voltagescaling(void)
559 maxvid = vrm_mV_table[longhaul.bits.MaximumVID]; 560 maxvid = vrm_mV_table[longhaul.bits.MaximumVID];
560 561
561 if (minvid.mV == 0 || maxvid.mV == 0 || minvid.mV > maxvid.mV) { 562 if (minvid.mV == 0 || maxvid.mV == 0 || minvid.mV > maxvid.mV) {
562 printk (KERN_INFO PFX "Bogus values Min:%d.%03d Max:%d.%03d. " 563 printk(KERN_INFO PFX "Bogus values Min:%d.%03d Max:%d.%03d. "
563 "Voltage scaling disabled.\n", 564 "Voltage scaling disabled.\n",
564 minvid.mV/1000, minvid.mV%1000, maxvid.mV/1000, maxvid.mV%1000); 565 minvid.mV/1000, minvid.mV%1000,
566 maxvid.mV/1000, maxvid.mV%1000);
565 return; 567 return;
566 } 568 }
567 569
568 if (minvid.mV == maxvid.mV) { 570 if (minvid.mV == maxvid.mV) {
569 printk (KERN_INFO PFX "Claims to support voltage scaling but min & max are " 571 printk(KERN_INFO PFX "Claims to support voltage scaling but "
570 "both %d.%03d. Voltage scaling disabled\n", 572 "min & max are both %d.%03d. "
573 "Voltage scaling disabled\n",
571 maxvid.mV/1000, maxvid.mV%1000); 574 maxvid.mV/1000, maxvid.mV%1000);
572 return; 575 return;
573 } 576 }
574 577
575 /* How many voltage steps */ 578 /* How many voltage steps*/
576 numvscales = maxvid.pos - minvid.pos + 1; 579 numvscales = maxvid.pos - minvid.pos + 1;
577 printk(KERN_INFO PFX 580 printk(KERN_INFO PFX
578 "Max VID=%d.%03d " 581 "Max VID=%d.%03d "
@@ -586,7 +589,7 @@ static void __init longhaul_setup_voltagescaling(void)
586 j = longhaul.bits.MinMHzBR; 589 j = longhaul.bits.MinMHzBR;
587 if (longhaul.bits.MinMHzBR4) 590 if (longhaul.bits.MinMHzBR4)
588 j += 16; 591 j += 16;
589 min_vid_speed = eblcr_table[j]; 592 min_vid_speed = eblcr[j];
590 if (min_vid_speed == -1) 593 if (min_vid_speed == -1)
591 return; 594 return;
592 switch (longhaul.bits.MinMHzFSB) { 595 switch (longhaul.bits.MinMHzFSB) {
@@ -617,7 +620,8 @@ static void __init longhaul_setup_voltagescaling(void)
617 pos = minvid.pos; 620 pos = minvid.pos;
618 longhaul_table[j].index |= mV_vrm_table[pos] << 8; 621 longhaul_table[j].index |= mV_vrm_table[pos] << 8;
619 vid = vrm_mV_table[mV_vrm_table[pos]]; 622 vid = vrm_mV_table[mV_vrm_table[pos]];
620 printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n", speed, j, vid.mV); 623 printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n",
624 speed, j, vid.mV);
621 j++; 625 j++;
622 } 626 }
623 627
@@ -640,7 +644,8 @@ static int longhaul_target(struct cpufreq_policy *policy,
640 unsigned int dir = 0; 644 unsigned int dir = 0;
641 u8 vid, current_vid; 645 u8 vid, current_vid;
642 646
643 if (cpufreq_frequency_table_target(policy, longhaul_table, target_freq, relation, &table_index)) 647 if (cpufreq_frequency_table_target(policy, longhaul_table, target_freq,
648 relation, &table_index))
644 return -EINVAL; 649 return -EINVAL;
645 650
646 /* Don't set same frequency again */ 651 /* Don't set same frequency again */
@@ -656,7 +661,8 @@ static int longhaul_target(struct cpufreq_policy *policy,
656 * this in hardware, C3 is old and we need to do this 661 * this in hardware, C3 is old and we need to do this
657 * in software. */ 662 * in software. */
658 i = longhaul_index; 663 i = longhaul_index;
659 current_vid = (longhaul_table[longhaul_index].index >> 8) & 0x1f; 664 current_vid = (longhaul_table[longhaul_index].index >> 8);
665 current_vid &= 0x1f;
660 if (table_index > longhaul_index) 666 if (table_index > longhaul_index)
661 dir = 1; 667 dir = 1;
662 while (i != table_index) { 668 while (i != table_index) {
@@ -691,9 +697,9 @@ static acpi_status longhaul_walk_callback(acpi_handle obj_handle,
691{ 697{
692 struct acpi_device *d; 698 struct acpi_device *d;
693 699
694 if ( acpi_bus_get_device(obj_handle, &d) ) { 700 if (acpi_bus_get_device(obj_handle, &d))
695 return 0; 701 return 0;
696 } 702
697 *return_value = acpi_driver_data(d); 703 *return_value = acpi_driver_data(d);
698 return 1; 704 return 1;
699} 705}
@@ -750,7 +756,7 @@ static int longhaul_setup_southbridge(void)
750 /* Find VT8235 southbridge */ 756 /* Find VT8235 southbridge */
751 dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, NULL); 757 dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, NULL);
752 if (dev == NULL) 758 if (dev == NULL)
753 /* Find VT8237 southbridge */ 759 /* Find VT8237 southbridge */
754 dev = pci_get_device(PCI_VENDOR_ID_VIA, 760 dev = pci_get_device(PCI_VENDOR_ID_VIA,
755 PCI_DEVICE_ID_VIA_8237, NULL); 761 PCI_DEVICE_ID_VIA_8237, NULL);
756 if (dev != NULL) { 762 if (dev != NULL) {
@@ -769,7 +775,8 @@ static int longhaul_setup_southbridge(void)
769 if (pci_cmd & 1 << 7) { 775 if (pci_cmd & 1 << 7) {
770 pci_read_config_dword(dev, 0x88, &acpi_regs_addr); 776 pci_read_config_dword(dev, 0x88, &acpi_regs_addr);
771 acpi_regs_addr &= 0xff00; 777 acpi_regs_addr &= 0xff00;
772 printk(KERN_INFO PFX "ACPI I/O at 0x%x\n", acpi_regs_addr); 778 printk(KERN_INFO PFX "ACPI I/O at 0x%x\n",
779 acpi_regs_addr);
773 } 780 }
774 781
775 pci_dev_put(dev); 782 pci_dev_put(dev);
@@ -781,7 +788,7 @@ static int longhaul_setup_southbridge(void)
781static int __init longhaul_cpu_init(struct cpufreq_policy *policy) 788static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
782{ 789{
783 struct cpuinfo_x86 *c = &cpu_data(0); 790 struct cpuinfo_x86 *c = &cpu_data(0);
784 char *cpuname=NULL; 791 char *cpuname = NULL;
785 int ret; 792 int ret;
786 u32 lo, hi; 793 u32 lo, hi;
787 794
@@ -791,8 +798,8 @@ static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
791 cpu_model = CPU_SAMUEL; 798 cpu_model = CPU_SAMUEL;
792 cpuname = "C3 'Samuel' [C5A]"; 799 cpuname = "C3 'Samuel' [C5A]";
793 longhaul_version = TYPE_LONGHAUL_V1; 800 longhaul_version = TYPE_LONGHAUL_V1;
794 memcpy (clock_ratio, samuel1_clock_ratio, sizeof(samuel1_clock_ratio)); 801 memcpy(mults, samuel1_mults, sizeof(samuel1_mults));
795 memcpy (eblcr_table, samuel1_eblcr, sizeof(samuel1_eblcr)); 802 memcpy(eblcr, samuel1_eblcr, sizeof(samuel1_eblcr));
796 break; 803 break;
797 804
798 case 7: 805 case 7:
@@ -803,10 +810,8 @@ static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
803 cpuname = "C3 'Samuel 2' [C5B]"; 810 cpuname = "C3 'Samuel 2' [C5B]";
804 /* Note, this is not a typo, early Samuel2's had 811 /* Note, this is not a typo, early Samuel2's had
805 * Samuel1 ratios. */ 812 * Samuel1 ratios. */
806 memcpy(clock_ratio, samuel1_clock_ratio, 813 memcpy(mults, samuel1_mults, sizeof(samuel1_mults));
807 sizeof(samuel1_clock_ratio)); 814 memcpy(eblcr, samuel2_eblcr, sizeof(samuel2_eblcr));
808 memcpy(eblcr_table, samuel2_eblcr,
809 sizeof(samuel2_eblcr));
810 break; 815 break;
811 case 1 ... 15: 816 case 1 ... 15:
812 longhaul_version = TYPE_LONGHAUL_V1; 817 longhaul_version = TYPE_LONGHAUL_V1;
@@ -817,10 +822,8 @@ static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
817 cpu_model = CPU_EZRA; 822 cpu_model = CPU_EZRA;
818 cpuname = "C3 'Ezra' [C5C]"; 823 cpuname = "C3 'Ezra' [C5C]";
819 } 824 }
820 memcpy(clock_ratio, ezra_clock_ratio, 825 memcpy(mults, ezra_mults, sizeof(ezra_mults));
821 sizeof(ezra_clock_ratio)); 826 memcpy(eblcr, ezra_eblcr, sizeof(ezra_eblcr));
822 memcpy(eblcr_table, ezra_eblcr,
823 sizeof(ezra_eblcr));
824 break; 827 break;
825 } 828 }
826 break; 829 break;
@@ -829,18 +832,16 @@ static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
829 cpu_model = CPU_EZRA_T; 832 cpu_model = CPU_EZRA_T;
830 cpuname = "C3 'Ezra-T' [C5M]"; 833 cpuname = "C3 'Ezra-T' [C5M]";
831 longhaul_version = TYPE_POWERSAVER; 834 longhaul_version = TYPE_POWERSAVER;
832 numscales=32; 835 numscales = 32;
833 memcpy (clock_ratio, ezrat_clock_ratio, sizeof(ezrat_clock_ratio)); 836 memcpy(mults, ezrat_mults, sizeof(ezrat_mults));
834 memcpy (eblcr_table, ezrat_eblcr, sizeof(ezrat_eblcr)); 837 memcpy(eblcr, ezrat_eblcr, sizeof(ezrat_eblcr));
835 break; 838 break;
836 839
837 case 9: 840 case 9:
838 longhaul_version = TYPE_POWERSAVER; 841 longhaul_version = TYPE_POWERSAVER;
839 numscales = 32; 842 numscales = 32;
840 memcpy(clock_ratio, 843 memcpy(mults, nehemiah_mults, sizeof(nehemiah_mults));
841 nehemiah_clock_ratio, 844 memcpy(eblcr, nehemiah_eblcr, sizeof(nehemiah_eblcr));
842 sizeof(nehemiah_clock_ratio));
843 memcpy(eblcr_table, nehemiah_eblcr, sizeof(nehemiah_eblcr));
844 switch (c->x86_mask) { 845 switch (c->x86_mask) {
845 case 0 ... 1: 846 case 0 ... 1:
846 cpu_model = CPU_NEHEMIAH; 847 cpu_model = CPU_NEHEMIAH;
@@ -869,14 +870,14 @@ static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
869 longhaul_version = TYPE_LONGHAUL_V1; 870 longhaul_version = TYPE_LONGHAUL_V1;
870 } 871 }
871 872
872 printk (KERN_INFO PFX "VIA %s CPU detected. ", cpuname); 873 printk(KERN_INFO PFX "VIA %s CPU detected. ", cpuname);
873 switch (longhaul_version) { 874 switch (longhaul_version) {
874 case TYPE_LONGHAUL_V1: 875 case TYPE_LONGHAUL_V1:
875 case TYPE_LONGHAUL_V2: 876 case TYPE_LONGHAUL_V2:
876 printk ("Longhaul v%d supported.\n", longhaul_version); 877 printk(KERN_CONT "Longhaul v%d supported.\n", longhaul_version);
877 break; 878 break;
878 case TYPE_POWERSAVER: 879 case TYPE_POWERSAVER:
879 printk ("Powersaver supported.\n"); 880 printk(KERN_CONT "Powersaver supported.\n");
880 break; 881 break;
881 }; 882 };
882 883
@@ -940,7 +941,7 @@ static int __devexit longhaul_cpu_exit(struct cpufreq_policy *policy)
940 return 0; 941 return 0;
941} 942}
942 943
943static struct freq_attr* longhaul_attr[] = { 944static struct freq_attr *longhaul_attr[] = {
944 &cpufreq_freq_attr_scaling_available_freqs, 945 &cpufreq_freq_attr_scaling_available_freqs,
945 NULL, 946 NULL,
946}; 947};
@@ -966,13 +967,15 @@ static int __init longhaul_init(void)
966 967
967#ifdef CONFIG_SMP 968#ifdef CONFIG_SMP
968 if (num_online_cpus() > 1) { 969 if (num_online_cpus() > 1) {
969 printk(KERN_ERR PFX "More than 1 CPU detected, longhaul disabled.\n"); 970 printk(KERN_ERR PFX "More than 1 CPU detected, "
971 "longhaul disabled.\n");
970 return -ENODEV; 972 return -ENODEV;
971 } 973 }
972#endif 974#endif
973#ifdef CONFIG_X86_IO_APIC 975#ifdef CONFIG_X86_IO_APIC
974 if (cpu_has_apic) { 976 if (cpu_has_apic) {
975 printk(KERN_ERR PFX "APIC detected. Longhaul is currently broken in this configuration.\n"); 977 printk(KERN_ERR PFX "APIC detected. Longhaul is currently "
978 "broken in this configuration.\n");
976 return -ENODEV; 979 return -ENODEV;
977 } 980 }
978#endif 981#endif
@@ -993,8 +996,8 @@ static void __exit longhaul_exit(void)
993{ 996{
994 int i; 997 int i;
995 998
996 for (i=0; i < numscales; i++) { 999 for (i = 0; i < numscales; i++) {
997 if (clock_ratio[i] == maxmult) { 1000 if (mults[i] == maxmult) {
998 longhaul_setstate(i); 1001 longhaul_setstate(i);
999 break; 1002 break;
1000 } 1003 }
@@ -1007,11 +1010,11 @@ static void __exit longhaul_exit(void)
1007/* Even if BIOS is exporting ACPI C3 state, and it is used 1010/* Even if BIOS is exporting ACPI C3 state, and it is used
1008 * with success when CPU is idle, this state doesn't 1011 * with success when CPU is idle, this state doesn't
1009 * trigger frequency transition in some cases. */ 1012 * trigger frequency transition in some cases. */
1010module_param (disable_acpi_c3, int, 0644); 1013module_param(disable_acpi_c3, int, 0644);
1011MODULE_PARM_DESC(disable_acpi_c3, "Don't use ACPI C3 support"); 1014MODULE_PARM_DESC(disable_acpi_c3, "Don't use ACPI C3 support");
1012/* Change CPU voltage with frequency. Very usefull to save 1015/* Change CPU voltage with frequency. Very usefull to save
1013 * power, but most VIA C3 processors aren't supporting it. */ 1016 * power, but most VIA C3 processors aren't supporting it. */
1014module_param (scale_voltage, int, 0644); 1017module_param(scale_voltage, int, 0644);
1015MODULE_PARM_DESC(scale_voltage, "Scale voltage of processor"); 1018MODULE_PARM_DESC(scale_voltage, "Scale voltage of processor");
1016/* Force revision key to 0 for processors which doesn't 1019/* Force revision key to 0 for processors which doesn't
1017 * support voltage scaling, but are introducing itself as 1020 * support voltage scaling, but are introducing itself as
@@ -1019,9 +1022,9 @@ MODULE_PARM_DESC(scale_voltage, "Scale voltage of processor");
1019module_param(revid_errata, int, 0644); 1022module_param(revid_errata, int, 0644);
1020MODULE_PARM_DESC(revid_errata, "Ignore CPU Revision ID"); 1023MODULE_PARM_DESC(revid_errata, "Ignore CPU Revision ID");
1021 1024
1022MODULE_AUTHOR ("Dave Jones <davej@redhat.com>"); 1025MODULE_AUTHOR("Dave Jones <davej@redhat.com>");
1023MODULE_DESCRIPTION ("Longhaul driver for VIA Cyrix processors."); 1026MODULE_DESCRIPTION("Longhaul driver for VIA Cyrix processors.");
1024MODULE_LICENSE ("GPL"); 1027MODULE_LICENSE("GPL");
1025 1028
1026late_initcall(longhaul_init); 1029late_initcall(longhaul_init);
1027module_exit(longhaul_exit); 1030module_exit(longhaul_exit);
diff --git a/arch/x86/kernel/cpu/cpufreq/longhaul.h b/arch/x86/kernel/cpu/cpufreq/longhaul.h
index 4fcc320997df..e2360a469f79 100644
--- a/arch/x86/kernel/cpu/cpufreq/longhaul.h
+++ b/arch/x86/kernel/cpu/cpufreq/longhaul.h
@@ -49,14 +49,14 @@ union msr_longhaul {
49 49
50/* 50/*
51 * Clock ratio tables. Div/Mod by 10 to get ratio. 51 * Clock ratio tables. Div/Mod by 10 to get ratio.
52 * The eblcr ones specify the ratio read from the CPU. 52 * The eblcr values specify the ratio read from the CPU.
53 * The clock_ratio ones specify what to write to the CPU. 53 * The mults values specify what to write to the CPU.
54 */ 54 */
55 55
56/* 56/*
57 * VIA C3 Samuel 1 & Samuel 2 (stepping 0) 57 * VIA C3 Samuel 1 & Samuel 2 (stepping 0)
58 */ 58 */
59static const int __initdata samuel1_clock_ratio[16] = { 59static const int __initdata samuel1_mults[16] = {
60 -1, /* 0000 -> RESERVED */ 60 -1, /* 0000 -> RESERVED */
61 30, /* 0001 -> 3.0x */ 61 30, /* 0001 -> 3.0x */
62 40, /* 0010 -> 4.0x */ 62 40, /* 0010 -> 4.0x */
@@ -119,7 +119,7 @@ static const int __initdata samuel2_eblcr[16] = {
119/* 119/*
120 * VIA C3 Ezra 120 * VIA C3 Ezra
121 */ 121 */
122static const int __initdata ezra_clock_ratio[16] = { 122static const int __initdata ezra_mults[16] = {
123 100, /* 0000 -> 10.0x */ 123 100, /* 0000 -> 10.0x */
124 30, /* 0001 -> 3.0x */ 124 30, /* 0001 -> 3.0x */
125 40, /* 0010 -> 4.0x */ 125 40, /* 0010 -> 4.0x */
@@ -160,7 +160,7 @@ static const int __initdata ezra_eblcr[16] = {
160/* 160/*
161 * VIA C3 (Ezra-T) [C5M]. 161 * VIA C3 (Ezra-T) [C5M].
162 */ 162 */
163static const int __initdata ezrat_clock_ratio[32] = { 163static const int __initdata ezrat_mults[32] = {
164 100, /* 0000 -> 10.0x */ 164 100, /* 0000 -> 10.0x */
165 30, /* 0001 -> 3.0x */ 165 30, /* 0001 -> 3.0x */
166 40, /* 0010 -> 4.0x */ 166 40, /* 0010 -> 4.0x */
@@ -235,7 +235,7 @@ static const int __initdata ezrat_eblcr[32] = {
235/* 235/*
236 * VIA C3 Nehemiah */ 236 * VIA C3 Nehemiah */
237 237
238static const int __initdata nehemiah_clock_ratio[32] = { 238static const int __initdata nehemiah_mults[32] = {
239 100, /* 0000 -> 10.0x */ 239 100, /* 0000 -> 10.0x */
240 -1, /* 0001 -> 16.0x */ 240 -1, /* 0001 -> 16.0x */
241 40, /* 0010 -> 4.0x */ 241 40, /* 0010 -> 4.0x */
diff --git a/arch/x86/kernel/cpu/cpufreq/longrun.c b/arch/x86/kernel/cpu/cpufreq/longrun.c
index 777a7ff075de..da5f70fcb766 100644
--- a/arch/x86/kernel/cpu/cpufreq/longrun.c
+++ b/arch/x86/kernel/cpu/cpufreq/longrun.c
@@ -11,12 +11,13 @@
11#include <linux/init.h> 11#include <linux/init.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/cpufreq.h> 13#include <linux/cpufreq.h>
14#include <linux/timex.h>
14 15
15#include <asm/msr.h> 16#include <asm/msr.h>
16#include <asm/processor.h> 17#include <asm/processor.h>
17#include <asm/timex.h>
18 18
19#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "longrun", msg) 19#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
20 "longrun", msg)
20 21
21static struct cpufreq_driver longrun_driver; 22static struct cpufreq_driver longrun_driver;
22 23
@@ -51,7 +52,7 @@ static void __init longrun_get_policy(struct cpufreq_policy *policy)
51 msr_lo &= 0x0000007F; 52 msr_lo &= 0x0000007F;
52 msr_hi &= 0x0000007F; 53 msr_hi &= 0x0000007F;
53 54
54 if ( longrun_high_freq <= longrun_low_freq ) { 55 if (longrun_high_freq <= longrun_low_freq) {
55 /* Assume degenerate Longrun table */ 56 /* Assume degenerate Longrun table */
56 policy->min = policy->max = longrun_high_freq; 57 policy->min = policy->max = longrun_high_freq;
57 } else { 58 } else {
@@ -79,7 +80,7 @@ static int longrun_set_policy(struct cpufreq_policy *policy)
79 if (!policy) 80 if (!policy)
80 return -EINVAL; 81 return -EINVAL;
81 82
82 if ( longrun_high_freq <= longrun_low_freq ) { 83 if (longrun_high_freq <= longrun_low_freq) {
83 /* Assume degenerate Longrun table */ 84 /* Assume degenerate Longrun table */
84 pctg_lo = pctg_hi = 100; 85 pctg_lo = pctg_hi = 100;
85 } else { 86 } else {
@@ -152,7 +153,7 @@ static unsigned int longrun_get(unsigned int cpu)
152 cpuid(0x80860007, &eax, &ebx, &ecx, &edx); 153 cpuid(0x80860007, &eax, &ebx, &ecx, &edx);
153 dprintk("cpuid eax is %u\n", eax); 154 dprintk("cpuid eax is %u\n", eax);
154 155
155 return (eax * 1000); 156 return eax * 1000;
156} 157}
157 158
158/** 159/**
@@ -196,7 +197,8 @@ static unsigned int __init longrun_determine_freqs(unsigned int *low_freq,
196 rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi); 197 rdmsr(MSR_TMTA_LRTI_VOLT_MHZ, msr_lo, msr_hi);
197 *high_freq = msr_lo * 1000; /* to kHz */ 198 *high_freq = msr_lo * 1000; /* to kHz */
198 199
199 dprintk("longrun table interface told %u - %u kHz\n", *low_freq, *high_freq); 200 dprintk("longrun table interface told %u - %u kHz\n",
201 *low_freq, *high_freq);
200 202
201 if (*low_freq > *high_freq) 203 if (*low_freq > *high_freq)
202 *low_freq = *high_freq; 204 *low_freq = *high_freq;
@@ -219,7 +221,7 @@ static unsigned int __init longrun_determine_freqs(unsigned int *low_freq,
219 cpuid(0x80860007, &eax, &ebx, &ecx, &edx); 221 cpuid(0x80860007, &eax, &ebx, &ecx, &edx);
220 /* try decreasing in 10% steps, some processors react only 222 /* try decreasing in 10% steps, some processors react only
221 * on some barrier values */ 223 * on some barrier values */
222 for (try_hi = 80; try_hi > 0 && ecx > 90; try_hi -=10) { 224 for (try_hi = 80; try_hi > 0 && ecx > 90; try_hi -= 10) {
223 /* set to 0 to try_hi perf_pctg */ 225 /* set to 0 to try_hi perf_pctg */
224 msr_lo &= 0xFFFFFF80; 226 msr_lo &= 0xFFFFFF80;
225 msr_hi &= 0xFFFFFF80; 227 msr_hi &= 0xFFFFFF80;
@@ -236,7 +238,7 @@ static unsigned int __init longrun_determine_freqs(unsigned int *low_freq,
236 238
237 /* performance_pctg = (current_freq - low_freq)/(high_freq - low_freq) 239 /* performance_pctg = (current_freq - low_freq)/(high_freq - low_freq)
238 * eqals 240 * eqals
239 * low_freq * ( 1 - perf_pctg) = (cur_freq - high_freq * perf_pctg) 241 * low_freq * (1 - perf_pctg) = (cur_freq - high_freq * perf_pctg)
240 * 242 *
241 * high_freq * perf_pctg is stored tempoarily into "ebx". 243 * high_freq * perf_pctg is stored tempoarily into "ebx".
242 */ 244 */
@@ -317,9 +319,10 @@ static void __exit longrun_exit(void)
317} 319}
318 320
319 321
320MODULE_AUTHOR ("Dominik Brodowski <linux@brodo.de>"); 322MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
321MODULE_DESCRIPTION ("LongRun driver for Transmeta Crusoe and Efficeon processors."); 323MODULE_DESCRIPTION("LongRun driver for Transmeta Crusoe and "
322MODULE_LICENSE ("GPL"); 324 "Efficeon processors.");
325MODULE_LICENSE("GPL");
323 326
324module_init(longrun_init); 327module_init(longrun_init);
325module_exit(longrun_exit); 328module_exit(longrun_exit);
diff --git a/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c b/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c
index 3178c3acd97e..41ed94915f97 100644
--- a/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c
+++ b/arch/x86/kernel/cpu/cpufreq/p4-clockmod.c
@@ -27,15 +27,17 @@
27#include <linux/cpufreq.h> 27#include <linux/cpufreq.h>
28#include <linux/slab.h> 28#include <linux/slab.h>
29#include <linux/cpumask.h> 29#include <linux/cpumask.h>
30#include <linux/timex.h>
30 31
31#include <asm/processor.h> 32#include <asm/processor.h>
32#include <asm/msr.h> 33#include <asm/msr.h>
33#include <asm/timex.h> 34#include <asm/timer.h>
34 35
35#include "speedstep-lib.h" 36#include "speedstep-lib.h"
36 37
37#define PFX "p4-clockmod: " 38#define PFX "p4-clockmod: "
38#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "p4-clockmod", msg) 39#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
40 "p4-clockmod", msg)
39 41
40/* 42/*
41 * Duty Cycle (3bits), note DC_DISABLE is not specified in 43 * Duty Cycle (3bits), note DC_DISABLE is not specified in
@@ -58,7 +60,8 @@ static int cpufreq_p4_setdc(unsigned int cpu, unsigned int newstate)
58{ 60{
59 u32 l, h; 61 u32 l, h;
60 62
61 if (!cpu_online(cpu) || (newstate > DC_DISABLE) || (newstate == DC_RESV)) 63 if (!cpu_online(cpu) ||
64 (newstate > DC_DISABLE) || (newstate == DC_RESV))
62 return -EINVAL; 65 return -EINVAL;
63 66
64 rdmsr_on_cpu(cpu, MSR_IA32_THERM_STATUS, &l, &h); 67 rdmsr_on_cpu(cpu, MSR_IA32_THERM_STATUS, &l, &h);
@@ -66,7 +69,8 @@ static int cpufreq_p4_setdc(unsigned int cpu, unsigned int newstate)
66 if (l & 0x01) 69 if (l & 0x01)
67 dprintk("CPU#%d currently thermal throttled\n", cpu); 70 dprintk("CPU#%d currently thermal throttled\n", cpu);
68 71
69 if (has_N44_O17_errata[cpu] && (newstate == DC_25PT || newstate == DC_DFLT)) 72 if (has_N44_O17_errata[cpu] &&
73 (newstate == DC_25PT || newstate == DC_DFLT))
70 newstate = DC_38PT; 74 newstate = DC_38PT;
71 75
72 rdmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, &l, &h); 76 rdmsr_on_cpu(cpu, MSR_IA32_THERM_CONTROL, &l, &h);
@@ -112,7 +116,8 @@ static int cpufreq_p4_target(struct cpufreq_policy *policy,
112 struct cpufreq_freqs freqs; 116 struct cpufreq_freqs freqs;
113 int i; 117 int i;
114 118
115 if (cpufreq_frequency_table_target(policy, &p4clockmod_table[0], target_freq, relation, &newstate)) 119 if (cpufreq_frequency_table_target(policy, &p4clockmod_table[0],
120 target_freq, relation, &newstate))
116 return -EINVAL; 121 return -EINVAL;
117 122
118 freqs.old = cpufreq_p4_get(policy->cpu); 123 freqs.old = cpufreq_p4_get(policy->cpu);
@@ -127,7 +132,8 @@ static int cpufreq_p4_target(struct cpufreq_policy *policy,
127 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); 132 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
128 } 133 }
129 134
130 /* run on each logical CPU, see section 13.15.3 of IA32 Intel Architecture Software 135 /* run on each logical CPU,
136 * see section 13.15.3 of IA32 Intel Architecture Software
131 * Developer's Manual, Volume 3 137 * Developer's Manual, Volume 3
132 */ 138 */
133 for_each_cpu(i, policy->cpus) 139 for_each_cpu(i, policy->cpus)
@@ -153,28 +159,30 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
153{ 159{
154 if (c->x86 == 0x06) { 160 if (c->x86 == 0x06) {
155 if (cpu_has(c, X86_FEATURE_EST)) 161 if (cpu_has(c, X86_FEATURE_EST))
156 printk(KERN_WARNING PFX "Warning: EST-capable CPU detected. " 162 printk(KERN_WARNING PFX "Warning: EST-capable CPU "
157 "The acpi-cpufreq module offers voltage scaling" 163 "detected. The acpi-cpufreq module offers "
158 " in addition of frequency scaling. You should use " 164 "voltage scaling in addition of frequency "
159 "that instead of p4-clockmod, if possible.\n"); 165 "scaling. You should use that instead of "
166 "p4-clockmod, if possible.\n");
160 switch (c->x86_model) { 167 switch (c->x86_model) {
161 case 0x0E: /* Core */ 168 case 0x0E: /* Core */
162 case 0x0F: /* Core Duo */ 169 case 0x0F: /* Core Duo */
163 case 0x16: /* Celeron Core */ 170 case 0x16: /* Celeron Core */
164 p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; 171 p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
165 return speedstep_get_processor_frequency(SPEEDSTEP_PROCESSOR_PCORE); 172 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
166 case 0x0D: /* Pentium M (Dothan) */ 173 case 0x0D: /* Pentium M (Dothan) */
167 p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; 174 p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
168 /* fall through */ 175 /* fall through */
169 case 0x09: /* Pentium M (Banias) */ 176 case 0x09: /* Pentium M (Banias) */
170 return speedstep_get_processor_frequency(SPEEDSTEP_PROCESSOR_PM); 177 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
171 } 178 }
172 } 179 }
173 180
174 if (c->x86 != 0xF) { 181 if (c->x86 != 0xF) {
175 if (!cpu_has(c, X86_FEATURE_EST)) 182 if (!cpu_has(c, X86_FEATURE_EST))
176 printk(KERN_WARNING PFX "Unknown p4-clockmod-capable CPU. " 183 printk(KERN_WARNING PFX "Unknown CPU. "
177 "Please send an e-mail to <cpufreq@vger.kernel.org>\n"); 184 "Please send an e-mail to "
185 "<cpufreq@vger.kernel.org>\n");
178 return 0; 186 return 0;
179 } 187 }
180 188
@@ -182,16 +190,16 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
182 * throttling is active or not. */ 190 * throttling is active or not. */
183 p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS; 191 p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
184 192
185 if (speedstep_detect_processor() == SPEEDSTEP_PROCESSOR_P4M) { 193 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
186 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. " 194 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
187 "The speedstep-ich or acpi cpufreq modules offer " 195 "The speedstep-ich or acpi cpufreq modules offer "
188 "voltage scaling in addition of frequency scaling. " 196 "voltage scaling in addition of frequency scaling. "
189 "You should use either one instead of p4-clockmod, " 197 "You should use either one instead of p4-clockmod, "
190 "if possible.\n"); 198 "if possible.\n");
191 return speedstep_get_processor_frequency(SPEEDSTEP_PROCESSOR_P4M); 199 return speedstep_get_frequency(SPEEDSTEP_CPU_P4M);
192 } 200 }
193 201
194 return speedstep_get_processor_frequency(SPEEDSTEP_PROCESSOR_P4D); 202 return speedstep_get_frequency(SPEEDSTEP_CPU_P4D);
195} 203}
196 204
197 205
@@ -217,14 +225,20 @@ static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy)
217 dprintk("has errata -- disabling low frequencies\n"); 225 dprintk("has errata -- disabling low frequencies\n");
218 } 226 }
219 227
228 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4D &&
229 c->x86_model < 2) {
230 /* switch to maximum frequency and measure result */
231 cpufreq_p4_setdc(policy->cpu, DC_DISABLE);
232 recalibrate_cpu_khz();
233 }
220 /* get max frequency */ 234 /* get max frequency */
221 stock_freq = cpufreq_p4_get_frequency(c); 235 stock_freq = cpufreq_p4_get_frequency(c);
222 if (!stock_freq) 236 if (!stock_freq)
223 return -EINVAL; 237 return -EINVAL;
224 238
225 /* table init */ 239 /* table init */
226 for (i=1; (p4clockmod_table[i].frequency != CPUFREQ_TABLE_END); i++) { 240 for (i = 1; (p4clockmod_table[i].frequency != CPUFREQ_TABLE_END); i++) {
227 if ((i<2) && (has_N44_O17_errata[policy->cpu])) 241 if ((i < 2) && (has_N44_O17_errata[policy->cpu]))
228 p4clockmod_table[i].frequency = CPUFREQ_ENTRY_INVALID; 242 p4clockmod_table[i].frequency = CPUFREQ_ENTRY_INVALID;
229 else 243 else
230 p4clockmod_table[i].frequency = (stock_freq * i)/8; 244 p4clockmod_table[i].frequency = (stock_freq * i)/8;
@@ -232,7 +246,10 @@ static int cpufreq_p4_cpu_init(struct cpufreq_policy *policy)
232 cpufreq_frequency_table_get_attr(p4clockmod_table, policy->cpu); 246 cpufreq_frequency_table_get_attr(p4clockmod_table, policy->cpu);
233 247
234 /* cpuinfo and default policy values */ 248 /* cpuinfo and default policy values */
235 policy->cpuinfo.transition_latency = 1000000; /* assumed */ 249
250 /* the transition latency is set to be 1 higher than the maximum
251 * transition latency of the ondemand governor */
252 policy->cpuinfo.transition_latency = 10000001;
236 policy->cur = stock_freq; 253 policy->cur = stock_freq;
237 254
238 return cpufreq_frequency_table_cpuinfo(policy, &p4clockmod_table[0]); 255 return cpufreq_frequency_table_cpuinfo(policy, &p4clockmod_table[0]);
@@ -258,12 +275,12 @@ static unsigned int cpufreq_p4_get(unsigned int cpu)
258 l = DC_DISABLE; 275 l = DC_DISABLE;
259 276
260 if (l != DC_DISABLE) 277 if (l != DC_DISABLE)
261 return (stock_freq * l / 8); 278 return stock_freq * l / 8;
262 279
263 return stock_freq; 280 return stock_freq;
264} 281}
265 282
266static struct freq_attr* p4clockmod_attr[] = { 283static struct freq_attr *p4clockmod_attr[] = {
267 &cpufreq_freq_attr_scaling_available_freqs, 284 &cpufreq_freq_attr_scaling_available_freqs,
268 NULL, 285 NULL,
269}; 286};
@@ -298,9 +315,10 @@ static int __init cpufreq_p4_init(void)
298 315
299 ret = cpufreq_register_driver(&p4clockmod_driver); 316 ret = cpufreq_register_driver(&p4clockmod_driver);
300 if (!ret) 317 if (!ret)
301 printk(KERN_INFO PFX "P4/Xeon(TM) CPU On-Demand Clock Modulation available\n"); 318 printk(KERN_INFO PFX "P4/Xeon(TM) CPU On-Demand Clock "
319 "Modulation available\n");
302 320
303 return (ret); 321 return ret;
304} 322}
305 323
306 324
@@ -310,9 +328,9 @@ static void __exit cpufreq_p4_exit(void)
310} 328}
311 329
312 330
313MODULE_AUTHOR ("Zwane Mwaikambo <zwane@commfireservices.com>"); 331MODULE_AUTHOR("Zwane Mwaikambo <zwane@commfireservices.com>");
314MODULE_DESCRIPTION ("cpufreq driver for Pentium(TM) 4/Xeon(TM)"); 332MODULE_DESCRIPTION("cpufreq driver for Pentium(TM) 4/Xeon(TM)");
315MODULE_LICENSE ("GPL"); 333MODULE_LICENSE("GPL");
316 334
317late_initcall(cpufreq_p4_init); 335late_initcall(cpufreq_p4_init);
318module_exit(cpufreq_p4_exit); 336module_exit(cpufreq_p4_exit);
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k6.c b/arch/x86/kernel/cpu/cpufreq/powernow-k6.c
index c1ac5790c63e..f10dea409f40 100644
--- a/arch/x86/kernel/cpu/cpufreq/powernow-k6.c
+++ b/arch/x86/kernel/cpu/cpufreq/powernow-k6.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * This file was based upon code in Powertweak Linux (http://powertweak.sf.net) 2 * This file was based upon code in Powertweak Linux (http://powertweak.sf.net)
3 * (C) 2000-2003 Dave Jones, Arjan van de Ven, Janne Pänkälä, Dominik Brodowski. 3 * (C) 2000-2003 Dave Jones, Arjan van de Ven, Janne Pänkälä,
4 * Dominik Brodowski.
4 * 5 *
5 * Licensed under the terms of the GNU GPL License version 2. 6 * Licensed under the terms of the GNU GPL License version 2.
6 * 7 *
@@ -13,14 +14,15 @@
13#include <linux/cpufreq.h> 14#include <linux/cpufreq.h>
14#include <linux/ioport.h> 15#include <linux/ioport.h>
15#include <linux/slab.h> 16#include <linux/slab.h>
16
17#include <asm/msr.h>
18#include <linux/timex.h> 17#include <linux/timex.h>
19#include <linux/io.h> 18#include <linux/io.h>
20 19
20#include <asm/msr.h>
21
21#define POWERNOW_IOPORT 0xfff0 /* it doesn't matter where, as long 22#define POWERNOW_IOPORT 0xfff0 /* it doesn't matter where, as long
22 as it is unused */ 23 as it is unused */
23 24
25#define PFX "powernow-k6: "
24static unsigned int busfreq; /* FSB, in 10 kHz */ 26static unsigned int busfreq; /* FSB, in 10 kHz */
25static unsigned int max_multiplier; 27static unsigned int max_multiplier;
26 28
@@ -47,8 +49,8 @@ static struct cpufreq_frequency_table clock_ratio[] = {
47 */ 49 */
48static int powernow_k6_get_cpu_multiplier(void) 50static int powernow_k6_get_cpu_multiplier(void)
49{ 51{
50 u64 invalue = 0; 52 u64 invalue = 0;
51 u32 msrval; 53 u32 msrval;
52 54
53 msrval = POWERNOW_IOPORT + 0x1; 55 msrval = POWERNOW_IOPORT + 0x1;
54 wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */ 56 wrmsr(MSR_K6_EPMR, msrval, 0); /* enable the PowerNow port */
@@ -68,12 +70,12 @@ static int powernow_k6_get_cpu_multiplier(void)
68 */ 70 */
69static void powernow_k6_set_state(unsigned int best_i) 71static void powernow_k6_set_state(unsigned int best_i)
70{ 72{
71 unsigned long outvalue = 0, invalue = 0; 73 unsigned long outvalue = 0, invalue = 0;
72 unsigned long msrval; 74 unsigned long msrval;
73 struct cpufreq_freqs freqs; 75 struct cpufreq_freqs freqs;
74 76
75 if (clock_ratio[best_i].index > max_multiplier) { 77 if (clock_ratio[best_i].index > max_multiplier) {
76 printk(KERN_ERR "cpufreq: invalid target frequency\n"); 78 printk(KERN_ERR PFX "invalid target frequency\n");
77 return; 79 return;
78 } 80 }
79 81
@@ -119,7 +121,8 @@ static int powernow_k6_verify(struct cpufreq_policy *policy)
119 * powernow_k6_setpolicy - sets a new CPUFreq policy 121 * powernow_k6_setpolicy - sets a new CPUFreq policy
120 * @policy: new policy 122 * @policy: new policy
121 * @target_freq: the target frequency 123 * @target_freq: the target frequency
122 * @relation: how that frequency relates to achieved frequency (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) 124 * @relation: how that frequency relates to achieved frequency
125 * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H)
123 * 126 *
124 * sets a new CPUFreq policy 127 * sets a new CPUFreq policy
125 */ 128 */
@@ -127,9 +130,10 @@ static int powernow_k6_target(struct cpufreq_policy *policy,
127 unsigned int target_freq, 130 unsigned int target_freq,
128 unsigned int relation) 131 unsigned int relation)
129{ 132{
130 unsigned int newstate = 0; 133 unsigned int newstate = 0;
131 134
132 if (cpufreq_frequency_table_target(policy, &clock_ratio[0], target_freq, relation, &newstate)) 135 if (cpufreq_frequency_table_target(policy, &clock_ratio[0],
136 target_freq, relation, &newstate))
133 return -EINVAL; 137 return -EINVAL;
134 138
135 powernow_k6_set_state(newstate); 139 powernow_k6_set_state(newstate);
@@ -140,7 +144,7 @@ static int powernow_k6_target(struct cpufreq_policy *policy,
140 144
141static int powernow_k6_cpu_init(struct cpufreq_policy *policy) 145static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
142{ 146{
143 unsigned int i; 147 unsigned int i, f;
144 int result; 148 int result;
145 149
146 if (policy->cpu != 0) 150 if (policy->cpu != 0)
@@ -152,10 +156,11 @@ static int powernow_k6_cpu_init(struct cpufreq_policy *policy)
152 156
153 /* table init */ 157 /* table init */
154 for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) { 158 for (i = 0; (clock_ratio[i].frequency != CPUFREQ_TABLE_END); i++) {
155 if (clock_ratio[i].index > max_multiplier) 159 f = clock_ratio[i].index;
160 if (f > max_multiplier)
156 clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID; 161 clock_ratio[i].frequency = CPUFREQ_ENTRY_INVALID;
157 else 162 else
158 clock_ratio[i].frequency = busfreq * clock_ratio[i].index; 163 clock_ratio[i].frequency = busfreq * f;
159 } 164 }
160 165
161 /* cpuinfo and default policy values */ 166 /* cpuinfo and default policy values */
@@ -185,7 +190,9 @@ static int powernow_k6_cpu_exit(struct cpufreq_policy *policy)
185 190
186static unsigned int powernow_k6_get(unsigned int cpu) 191static unsigned int powernow_k6_get(unsigned int cpu)
187{ 192{
188 return busfreq * powernow_k6_get_cpu_multiplier(); 193 unsigned int ret;
194 ret = (busfreq * powernow_k6_get_cpu_multiplier());
195 return ret;
189} 196}
190 197
191static struct freq_attr *powernow_k6_attr[] = { 198static struct freq_attr *powernow_k6_attr[] = {
@@ -221,7 +228,7 @@ static int __init powernow_k6_init(void)
221 return -ENODEV; 228 return -ENODEV;
222 229
223 if (!request_region(POWERNOW_IOPORT, 16, "PowerNow!")) { 230 if (!request_region(POWERNOW_IOPORT, 16, "PowerNow!")) {
224 printk("cpufreq: PowerNow IOPORT region already used.\n"); 231 printk(KERN_INFO PFX "PowerNow IOPORT region already used.\n");
225 return -EIO; 232 return -EIO;
226 } 233 }
227 234
@@ -246,7 +253,8 @@ static void __exit powernow_k6_exit(void)
246} 253}
247 254
248 255
249MODULE_AUTHOR("Arjan van de Ven, Dave Jones <davej@redhat.com>, Dominik Brodowski <linux@brodo.de>"); 256MODULE_AUTHOR("Arjan van de Ven, Dave Jones <davej@redhat.com>, "
257 "Dominik Brodowski <linux@brodo.de>");
250MODULE_DESCRIPTION("PowerNow! driver for AMD K6-2+ / K6-3+ processors."); 258MODULE_DESCRIPTION("PowerNow! driver for AMD K6-2+ / K6-3+ processors.");
251MODULE_LICENSE("GPL"); 259MODULE_LICENSE("GPL");
252 260
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k7.c b/arch/x86/kernel/cpu/cpufreq/powernow-k7.c
index 1b446d79a8fd..3c28ccd49742 100644
--- a/arch/x86/kernel/cpu/cpufreq/powernow-k7.c
+++ b/arch/x86/kernel/cpu/cpufreq/powernow-k7.c
@@ -6,10 +6,12 @@
6 * Licensed under the terms of the GNU GPL License version 2. 6 * Licensed under the terms of the GNU GPL License version 2.
7 * Based upon datasheets & sample CPUs kindly provided by AMD. 7 * Based upon datasheets & sample CPUs kindly provided by AMD.
8 * 8 *
9 * Errata 5: Processor may fail to execute a FID/VID change in presence of interrupt. 9 * Errata 5:
10 * - We cli/sti on stepping A0 CPUs around the FID/VID transition. 10 * CPU may fail to execute a FID/VID change in presence of interrupt.
11 * Errata 15: Processors with half frequency multipliers may hang upon wakeup from disconnect. 11 * - We cli/sti on stepping A0 CPUs around the FID/VID transition.
12 * - We disable half multipliers if ACPI is used on A0 stepping CPUs. 12 * Errata 15:
13 * CPU with half frequency multipliers may hang upon wakeup from disconnect.
14 * - We disable half multipliers if ACPI is used on A0 stepping CPUs.
13 */ 15 */
14 16
15#include <linux/kernel.h> 17#include <linux/kernel.h>
@@ -20,11 +22,11 @@
20#include <linux/slab.h> 22#include <linux/slab.h>
21#include <linux/string.h> 23#include <linux/string.h>
22#include <linux/dmi.h> 24#include <linux/dmi.h>
25#include <linux/timex.h>
26#include <linux/io.h>
23 27
28#include <asm/timer.h> /* Needed for recalibrate_cpu_khz() */
24#include <asm/msr.h> 29#include <asm/msr.h>
25#include <asm/timer.h>
26#include <asm/timex.h>
27#include <asm/io.h>
28#include <asm/system.h> 30#include <asm/system.h>
29 31
30#ifdef CONFIG_X86_POWERNOW_K7_ACPI 32#ifdef CONFIG_X86_POWERNOW_K7_ACPI
@@ -58,9 +60,9 @@ struct pst_s {
58union powernow_acpi_control_t { 60union powernow_acpi_control_t {
59 struct { 61 struct {
60 unsigned long fid:5, 62 unsigned long fid:5,
61 vid:5, 63 vid:5,
62 sgtc:20, 64 sgtc:20,
63 res1:2; 65 res1:2;
64 } bits; 66 } bits;
65 unsigned long val; 67 unsigned long val;
66}; 68};
@@ -94,14 +96,15 @@ static struct cpufreq_frequency_table *powernow_table;
94 96
95static unsigned int can_scale_bus; 97static unsigned int can_scale_bus;
96static unsigned int can_scale_vid; 98static unsigned int can_scale_vid;
97static unsigned int minimum_speed=-1; 99static unsigned int minimum_speed = -1;
98static unsigned int maximum_speed; 100static unsigned int maximum_speed;
99static unsigned int number_scales; 101static unsigned int number_scales;
100static unsigned int fsb; 102static unsigned int fsb;
101static unsigned int latency; 103static unsigned int latency;
102static char have_a0; 104static char have_a0;
103 105
104#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "powernow-k7", msg) 106#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
107 "powernow-k7", msg)
105 108
106static int check_fsb(unsigned int fsbspeed) 109static int check_fsb(unsigned int fsbspeed)
107{ 110{
@@ -109,7 +112,7 @@ static int check_fsb(unsigned int fsbspeed)
109 unsigned int f = fsb / 1000; 112 unsigned int f = fsb / 1000;
110 113
111 delta = (fsbspeed > f) ? fsbspeed - f : f - fsbspeed; 114 delta = (fsbspeed > f) ? fsbspeed - f : f - fsbspeed;
112 return (delta < 5); 115 return delta < 5;
113} 116}
114 117
115static int check_powernow(void) 118static int check_powernow(void)
@@ -117,24 +120,26 @@ static int check_powernow(void)
117 struct cpuinfo_x86 *c = &cpu_data(0); 120 struct cpuinfo_x86 *c = &cpu_data(0);
118 unsigned int maxei, eax, ebx, ecx, edx; 121 unsigned int maxei, eax, ebx, ecx, edx;
119 122
120 if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 !=6)) { 123 if ((c->x86_vendor != X86_VENDOR_AMD) || (c->x86 != 6)) {
121#ifdef MODULE 124#ifdef MODULE
122 printk (KERN_INFO PFX "This module only works with AMD K7 CPUs\n"); 125 printk(KERN_INFO PFX "This module only works with "
126 "AMD K7 CPUs\n");
123#endif 127#endif
124 return 0; 128 return 0;
125 } 129 }
126 130
127 /* Get maximum capabilities */ 131 /* Get maximum capabilities */
128 maxei = cpuid_eax (0x80000000); 132 maxei = cpuid_eax(0x80000000);
129 if (maxei < 0x80000007) { /* Any powernow info ? */ 133 if (maxei < 0x80000007) { /* Any powernow info ? */
130#ifdef MODULE 134#ifdef MODULE
131 printk (KERN_INFO PFX "No powernow capabilities detected\n"); 135 printk(KERN_INFO PFX "No powernow capabilities detected\n");
132#endif 136#endif
133 return 0; 137 return 0;
134 } 138 }
135 139
136 if ((c->x86_model == 6) && (c->x86_mask == 0)) { 140 if ((c->x86_model == 6) && (c->x86_mask == 0)) {
137 printk (KERN_INFO PFX "K7 660[A0] core detected, enabling errata workarounds\n"); 141 printk(KERN_INFO PFX "K7 660[A0] core detected, "
142 "enabling errata workarounds\n");
138 have_a0 = 1; 143 have_a0 = 1;
139 } 144 }
140 145
@@ -144,37 +149,42 @@ static int check_powernow(void)
144 if (!(edx & (1 << 1 | 1 << 2))) 149 if (!(edx & (1 << 1 | 1 << 2)))
145 return 0; 150 return 0;
146 151
147 printk (KERN_INFO PFX "PowerNOW! Technology present. Can scale: "); 152 printk(KERN_INFO PFX "PowerNOW! Technology present. Can scale: ");
148 153
149 if (edx & 1 << 1) { 154 if (edx & 1 << 1) {
150 printk ("frequency"); 155 printk("frequency");
151 can_scale_bus=1; 156 can_scale_bus = 1;
152 } 157 }
153 158
154 if ((edx & (1 << 1 | 1 << 2)) == 0x6) 159 if ((edx & (1 << 1 | 1 << 2)) == 0x6)
155 printk (" and "); 160 printk(" and ");
156 161
157 if (edx & 1 << 2) { 162 if (edx & 1 << 2) {
158 printk ("voltage"); 163 printk("voltage");
159 can_scale_vid=1; 164 can_scale_vid = 1;
160 } 165 }
161 166
162 printk (".\n"); 167 printk(".\n");
163 return 1; 168 return 1;
164} 169}
165 170
171static void invalidate_entry(unsigned int entry)
172{
173 powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID;
174}
166 175
167static int get_ranges (unsigned char *pst) 176static int get_ranges(unsigned char *pst)
168{ 177{
169 unsigned int j; 178 unsigned int j;
170 unsigned int speed; 179 unsigned int speed;
171 u8 fid, vid; 180 u8 fid, vid;
172 181
173 powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) * (number_scales + 1)), GFP_KERNEL); 182 powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) *
183 (number_scales + 1)), GFP_KERNEL);
174 if (!powernow_table) 184 if (!powernow_table)
175 return -ENOMEM; 185 return -ENOMEM;
176 186
177 for (j=0 ; j < number_scales; j++) { 187 for (j = 0 ; j < number_scales; j++) {
178 fid = *pst++; 188 fid = *pst++;
179 189
180 powernow_table[j].frequency = (fsb * fid_codes[fid]) / 10; 190 powernow_table[j].frequency = (fsb * fid_codes[fid]) / 10;
@@ -182,10 +192,10 @@ static int get_ranges (unsigned char *pst)
182 192
183 speed = powernow_table[j].frequency; 193 speed = powernow_table[j].frequency;
184 194
185 if ((fid_codes[fid] % 10)==5) { 195 if ((fid_codes[fid] % 10) == 5) {
186#ifdef CONFIG_X86_POWERNOW_K7_ACPI 196#ifdef CONFIG_X86_POWERNOW_K7_ACPI
187 if (have_a0 == 1) 197 if (have_a0 == 1)
188 powernow_table[j].frequency = CPUFREQ_ENTRY_INVALID; 198 invalidate_entry(j);
189#endif 199#endif
190 } 200 }
191 201
@@ -197,7 +207,7 @@ static int get_ranges (unsigned char *pst)
197 vid = *pst++; 207 vid = *pst++;
198 powernow_table[j].index |= (vid << 8); /* upper 8 bits */ 208 powernow_table[j].index |= (vid << 8); /* upper 8 bits */
199 209
200 dprintk (" FID: 0x%x (%d.%dx [%dMHz]) " 210 dprintk(" FID: 0x%x (%d.%dx [%dMHz]) "
201 "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10, 211 "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10,
202 fid_codes[fid] % 10, speed/1000, vid, 212 fid_codes[fid] % 10, speed/1000, vid,
203 mobile_vid_table[vid]/1000, 213 mobile_vid_table[vid]/1000,
@@ -214,13 +224,13 @@ static void change_FID(int fid)
214{ 224{
215 union msr_fidvidctl fidvidctl; 225 union msr_fidvidctl fidvidctl;
216 226
217 rdmsrl (MSR_K7_FID_VID_CTL, fidvidctl.val); 227 rdmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val);
218 if (fidvidctl.bits.FID != fid) { 228 if (fidvidctl.bits.FID != fid) {
219 fidvidctl.bits.SGTC = latency; 229 fidvidctl.bits.SGTC = latency;
220 fidvidctl.bits.FID = fid; 230 fidvidctl.bits.FID = fid;
221 fidvidctl.bits.VIDC = 0; 231 fidvidctl.bits.VIDC = 0;
222 fidvidctl.bits.FIDC = 1; 232 fidvidctl.bits.FIDC = 1;
223 wrmsrl (MSR_K7_FID_VID_CTL, fidvidctl.val); 233 wrmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val);
224 } 234 }
225} 235}
226 236
@@ -229,18 +239,18 @@ static void change_VID(int vid)
229{ 239{
230 union msr_fidvidctl fidvidctl; 240 union msr_fidvidctl fidvidctl;
231 241
232 rdmsrl (MSR_K7_FID_VID_CTL, fidvidctl.val); 242 rdmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val);
233 if (fidvidctl.bits.VID != vid) { 243 if (fidvidctl.bits.VID != vid) {
234 fidvidctl.bits.SGTC = latency; 244 fidvidctl.bits.SGTC = latency;
235 fidvidctl.bits.VID = vid; 245 fidvidctl.bits.VID = vid;
236 fidvidctl.bits.FIDC = 0; 246 fidvidctl.bits.FIDC = 0;
237 fidvidctl.bits.VIDC = 1; 247 fidvidctl.bits.VIDC = 1;
238 wrmsrl (MSR_K7_FID_VID_CTL, fidvidctl.val); 248 wrmsrl(MSR_K7_FID_VID_CTL, fidvidctl.val);
239 } 249 }
240} 250}
241 251
242 252
243static void change_speed (unsigned int index) 253static void change_speed(unsigned int index)
244{ 254{
245 u8 fid, vid; 255 u8 fid, vid;
246 struct cpufreq_freqs freqs; 256 struct cpufreq_freqs freqs;
@@ -257,7 +267,7 @@ static void change_speed (unsigned int index)
257 267
258 freqs.cpu = 0; 268 freqs.cpu = 0;
259 269
260 rdmsrl (MSR_K7_FID_VID_STATUS, fidvidstatus.val); 270 rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val);
261 cfid = fidvidstatus.bits.CFID; 271 cfid = fidvidstatus.bits.CFID;
262 freqs.old = fsb * fid_codes[cfid] / 10; 272 freqs.old = fsb * fid_codes[cfid] / 10;
263 273
@@ -321,12 +331,14 @@ static int powernow_acpi_init(void)
321 goto err1; 331 goto err1;
322 } 332 }
323 333
324 if (acpi_processor_perf->control_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) { 334 if (acpi_processor_perf->control_register.space_id !=
335 ACPI_ADR_SPACE_FIXED_HARDWARE) {
325 retval = -ENODEV; 336 retval = -ENODEV;
326 goto err2; 337 goto err2;
327 } 338 }
328 339
329 if (acpi_processor_perf->status_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) { 340 if (acpi_processor_perf->status_register.space_id !=
341 ACPI_ADR_SPACE_FIXED_HARDWARE) {
330 retval = -ENODEV; 342 retval = -ENODEV;
331 goto err2; 343 goto err2;
332 } 344 }
@@ -338,7 +350,8 @@ static int powernow_acpi_init(void)
338 goto err2; 350 goto err2;
339 } 351 }
340 352
341 powernow_table = kzalloc((number_scales + 1) * (sizeof(struct cpufreq_frequency_table)), GFP_KERNEL); 353 powernow_table = kzalloc((sizeof(struct cpufreq_frequency_table) *
354 (number_scales + 1)), GFP_KERNEL);
342 if (!powernow_table) { 355 if (!powernow_table) {
343 retval = -ENOMEM; 356 retval = -ENOMEM;
344 goto err2; 357 goto err2;
@@ -352,7 +365,7 @@ static int powernow_acpi_init(void)
352 unsigned int speed, speed_mhz; 365 unsigned int speed, speed_mhz;
353 366
354 pc.val = (unsigned long) state->control; 367 pc.val = (unsigned long) state->control;
355 dprintk ("acpi: P%d: %d MHz %d mW %d uS control %08x SGTC %d\n", 368 dprintk("acpi: P%d: %d MHz %d mW %d uS control %08x SGTC %d\n",
356 i, 369 i,
357 (u32) state->core_frequency, 370 (u32) state->core_frequency,
358 (u32) state->power, 371 (u32) state->power,
@@ -381,12 +394,12 @@ static int powernow_acpi_init(void)
381 if (speed % 1000 > 0) 394 if (speed % 1000 > 0)
382 speed_mhz++; 395 speed_mhz++;
383 396
384 if ((fid_codes[fid] % 10)==5) { 397 if ((fid_codes[fid] % 10) == 5) {
385 if (have_a0 == 1) 398 if (have_a0 == 1)
386 powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID; 399 invalidate_entry(i);
387 } 400 }
388 401
389 dprintk (" FID: 0x%x (%d.%dx [%dMHz]) " 402 dprintk(" FID: 0x%x (%d.%dx [%dMHz]) "
390 "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10, 403 "VID: 0x%x (%d.%03dV)\n", fid, fid_codes[fid] / 10,
391 fid_codes[fid] % 10, speed_mhz, vid, 404 fid_codes[fid] % 10, speed_mhz, vid,
392 mobile_vid_table[vid]/1000, 405 mobile_vid_table[vid]/1000,
@@ -422,7 +435,8 @@ err1:
422err05: 435err05:
423 kfree(acpi_processor_perf); 436 kfree(acpi_processor_perf);
424err0: 437err0:
425 printk(KERN_WARNING PFX "ACPI perflib can not be used in this platform\n"); 438 printk(KERN_WARNING PFX "ACPI perflib can not be used on "
439 "this platform\n");
426 acpi_processor_perf = NULL; 440 acpi_processor_perf = NULL;
427 return retval; 441 return retval;
428} 442}
@@ -435,7 +449,14 @@ static int powernow_acpi_init(void)
435} 449}
436#endif 450#endif
437 451
438static int powernow_decode_bios (int maxfid, int startvid) 452static void print_pst_entry(struct pst_s *pst, unsigned int j)
453{
454 dprintk("PST:%d (@%p)\n", j, pst);
455 dprintk(" cpuid: 0x%x fsb: %d maxFID: 0x%x startvid: 0x%x\n",
456 pst->cpuid, pst->fsbspeed, pst->maxfid, pst->startvid);
457}
458
459static int powernow_decode_bios(int maxfid, int startvid)
439{ 460{
440 struct psb_s *psb; 461 struct psb_s *psb;
441 struct pst_s *pst; 462 struct pst_s *pst;
@@ -446,61 +467,67 @@ static int powernow_decode_bios (int maxfid, int startvid)
446 467
447 etuple = cpuid_eax(0x80000001); 468 etuple = cpuid_eax(0x80000001);
448 469
449 for (i=0xC0000; i < 0xffff0 ; i+=16) { 470 for (i = 0xC0000; i < 0xffff0 ; i += 16) {
450 471
451 p = phys_to_virt(i); 472 p = phys_to_virt(i);
452 473
453 if (memcmp(p, "AMDK7PNOW!", 10) == 0){ 474 if (memcmp(p, "AMDK7PNOW!", 10) == 0) {
454 dprintk ("Found PSB header at %p\n", p); 475 dprintk("Found PSB header at %p\n", p);
455 psb = (struct psb_s *) p; 476 psb = (struct psb_s *) p;
456 dprintk ("Table version: 0x%x\n", psb->tableversion); 477 dprintk("Table version: 0x%x\n", psb->tableversion);
457 if (psb->tableversion != 0x12) { 478 if (psb->tableversion != 0x12) {
458 printk (KERN_INFO PFX "Sorry, only v1.2 tables supported right now\n"); 479 printk(KERN_INFO PFX "Sorry, only v1.2 tables"
480 " supported right now\n");
459 return -ENODEV; 481 return -ENODEV;
460 } 482 }
461 483
462 dprintk ("Flags: 0x%x\n", psb->flags); 484 dprintk("Flags: 0x%x\n", psb->flags);
463 if ((psb->flags & 1)==0) { 485 if ((psb->flags & 1) == 0)
464 dprintk ("Mobile voltage regulator\n"); 486 dprintk("Mobile voltage regulator\n");
465 } else { 487 else
466 dprintk ("Desktop voltage regulator\n"); 488 dprintk("Desktop voltage regulator\n");
467 }
468 489
469 latency = psb->settlingtime; 490 latency = psb->settlingtime;
470 if (latency < 100) { 491 if (latency < 100) {
471 printk(KERN_INFO PFX "BIOS set settling time to %d microseconds. " 492 printk(KERN_INFO PFX "BIOS set settling time "
472 "Should be at least 100. Correcting.\n", latency); 493 "to %d microseconds. "
494 "Should be at least 100. "
495 "Correcting.\n", latency);
473 latency = 100; 496 latency = 100;
474 } 497 }
475 dprintk ("Settling Time: %d microseconds.\n", psb->settlingtime); 498 dprintk("Settling Time: %d microseconds.\n",
476 dprintk ("Has %d PST tables. (Only dumping ones relevant to this CPU).\n", psb->numpst); 499 psb->settlingtime);
500 dprintk("Has %d PST tables. (Only dumping ones "
501 "relevant to this CPU).\n",
502 psb->numpst);
477 503
478 p += sizeof (struct psb_s); 504 p += sizeof(struct psb_s);
479 505
480 pst = (struct pst_s *) p; 506 pst = (struct pst_s *) p;
481 507
482 for (j=0; j<psb->numpst; j++) { 508 for (j = 0; j < psb->numpst; j++) {
483 pst = (struct pst_s *) p; 509 pst = (struct pst_s *) p;
484 number_scales = pst->numpstates; 510 number_scales = pst->numpstates;
485 511
486 if ((etuple == pst->cpuid) && check_fsb(pst->fsbspeed) && 512 if ((etuple == pst->cpuid) &&
487 (maxfid==pst->maxfid) && (startvid==pst->startvid)) 513 check_fsb(pst->fsbspeed) &&
488 { 514 (maxfid == pst->maxfid) &&
489 dprintk ("PST:%d (@%p)\n", j, pst); 515 (startvid == pst->startvid)) {
490 dprintk (" cpuid: 0x%x fsb: %d maxFID: 0x%x startvid: 0x%x\n", 516 print_pst_entry(pst, j);
491 pst->cpuid, pst->fsbspeed, pst->maxfid, pst->startvid); 517 p = (char *)pst + sizeof(struct pst_s);
492 518 ret = get_ranges(p);
493 ret = get_ranges ((char *) pst + sizeof (struct pst_s));
494 return ret; 519 return ret;
495 } else { 520 } else {
496 unsigned int k; 521 unsigned int k;
497 p = (char *) pst + sizeof (struct pst_s); 522 p = (char *)pst + sizeof(struct pst_s);
498 for (k=0; k<number_scales; k++) 523 for (k = 0; k < number_scales; k++)
499 p+=2; 524 p += 2;
500 } 525 }
501 } 526 }
502 printk (KERN_INFO PFX "No PST tables match this cpuid (0x%x)\n", etuple); 527 printk(KERN_INFO PFX "No PST tables match this cpuid "
503 printk (KERN_INFO PFX "This is indicative of a broken BIOS.\n"); 528 "(0x%x)\n", etuple);
529 printk(KERN_INFO PFX "This is indicative of a broken "
530 "BIOS.\n");
504 531
505 return -EINVAL; 532 return -EINVAL;
506 } 533 }
@@ -511,13 +538,14 @@ static int powernow_decode_bios (int maxfid, int startvid)
511} 538}
512 539
513 540
514static int powernow_target (struct cpufreq_policy *policy, 541static int powernow_target(struct cpufreq_policy *policy,
515 unsigned int target_freq, 542 unsigned int target_freq,
516 unsigned int relation) 543 unsigned int relation)
517{ 544{
518 unsigned int newstate; 545 unsigned int newstate;
519 546
520 if (cpufreq_frequency_table_target(policy, powernow_table, target_freq, relation, &newstate)) 547 if (cpufreq_frequency_table_target(policy, powernow_table, target_freq,
548 relation, &newstate))
521 return -EINVAL; 549 return -EINVAL;
522 550
523 change_speed(newstate); 551 change_speed(newstate);
@@ -526,7 +554,7 @@ static int powernow_target (struct cpufreq_policy *policy,
526} 554}
527 555
528 556
529static int powernow_verify (struct cpufreq_policy *policy) 557static int powernow_verify(struct cpufreq_policy *policy)
530{ 558{
531 return cpufreq_frequency_table_verify(policy, powernow_table); 559 return cpufreq_frequency_table_verify(policy, powernow_table);
532} 560}
@@ -566,18 +594,23 @@ static unsigned int powernow_get(unsigned int cpu)
566 594
567 if (cpu) 595 if (cpu)
568 return 0; 596 return 0;
569 rdmsrl (MSR_K7_FID_VID_STATUS, fidvidstatus.val); 597 rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val);
570 cfid = fidvidstatus.bits.CFID; 598 cfid = fidvidstatus.bits.CFID;
571 599
572 return (fsb * fid_codes[cfid] / 10); 600 return fsb * fid_codes[cfid] / 10;
573} 601}
574 602
575 603
576static int __init acer_cpufreq_pst(const struct dmi_system_id *d) 604static int __init acer_cpufreq_pst(const struct dmi_system_id *d)
577{ 605{
578 printk(KERN_WARNING "%s laptop with broken PST tables in BIOS detected.\n", d->ident); 606 printk(KERN_WARNING PFX
579 printk(KERN_WARNING "You need to downgrade to 3A21 (09/09/2002), or try a newer BIOS than 3A71 (01/20/2003)\n"); 607 "%s laptop with broken PST tables in BIOS detected.\n",
580 printk(KERN_WARNING "cpufreq scaling has been disabled as a result of this.\n"); 608 d->ident);
609 printk(KERN_WARNING PFX
610 "You need to downgrade to 3A21 (09/09/2002), or try a newer "
611 "BIOS than 3A71 (01/20/2003)\n");
612 printk(KERN_WARNING PFX
613 "cpufreq scaling has been disabled as a result of this.\n");
581 return 0; 614 return 0;
582} 615}
583 616
@@ -598,7 +631,7 @@ static struct dmi_system_id __initdata powernow_dmi_table[] = {
598 { } 631 { }
599}; 632};
600 633
601static int __init powernow_cpu_init (struct cpufreq_policy *policy) 634static int __init powernow_cpu_init(struct cpufreq_policy *policy)
602{ 635{
603 union msr_fidvidstatus fidvidstatus; 636 union msr_fidvidstatus fidvidstatus;
604 int result; 637 int result;
@@ -606,7 +639,7 @@ static int __init powernow_cpu_init (struct cpufreq_policy *policy)
606 if (policy->cpu != 0) 639 if (policy->cpu != 0)
607 return -ENODEV; 640 return -ENODEV;
608 641
609 rdmsrl (MSR_K7_FID_VID_STATUS, fidvidstatus.val); 642 rdmsrl(MSR_K7_FID_VID_STATUS, fidvidstatus.val);
610 643
611 recalibrate_cpu_khz(); 644 recalibrate_cpu_khz();
612 645
@@ -618,19 +651,21 @@ static int __init powernow_cpu_init (struct cpufreq_policy *policy)
618 dprintk("FSB: %3dMHz\n", fsb/1000); 651 dprintk("FSB: %3dMHz\n", fsb/1000);
619 652
620 if (dmi_check_system(powernow_dmi_table) || acpi_force) { 653 if (dmi_check_system(powernow_dmi_table) || acpi_force) {
621 printk (KERN_INFO PFX "PSB/PST known to be broken. Trying ACPI instead\n"); 654 printk(KERN_INFO PFX "PSB/PST known to be broken. "
655 "Trying ACPI instead\n");
622 result = powernow_acpi_init(); 656 result = powernow_acpi_init();
623 } else { 657 } else {
624 result = powernow_decode_bios(fidvidstatus.bits.MFID, fidvidstatus.bits.SVID); 658 result = powernow_decode_bios(fidvidstatus.bits.MFID,
659 fidvidstatus.bits.SVID);
625 if (result) { 660 if (result) {
626 printk (KERN_INFO PFX "Trying ACPI perflib\n"); 661 printk(KERN_INFO PFX "Trying ACPI perflib\n");
627 maximum_speed = 0; 662 maximum_speed = 0;
628 minimum_speed = -1; 663 minimum_speed = -1;
629 latency = 0; 664 latency = 0;
630 result = powernow_acpi_init(); 665 result = powernow_acpi_init();
631 if (result) { 666 if (result) {
632 printk (KERN_INFO PFX "ACPI and legacy methods failed\n"); 667 printk(KERN_INFO PFX
633 printk (KERN_INFO PFX "See http://www.codemonkey.org.uk/projects/cpufreq/powernow-k7.html\n"); 668 "ACPI and legacy methods failed\n");
634 } 669 }
635 } else { 670 } else {
636 /* SGTC use the bus clock as timer */ 671 /* SGTC use the bus clock as timer */
@@ -642,10 +677,11 @@ static int __init powernow_cpu_init (struct cpufreq_policy *policy)
642 if (result) 677 if (result)
643 return result; 678 return result;
644 679
645 printk (KERN_INFO PFX "Minimum speed %d MHz. Maximum speed %d MHz.\n", 680 printk(KERN_INFO PFX "Minimum speed %d MHz. Maximum speed %d MHz.\n",
646 minimum_speed/1000, maximum_speed/1000); 681 minimum_speed/1000, maximum_speed/1000);
647 682
648 policy->cpuinfo.transition_latency = cpufreq_scale(2000000UL, fsb, latency); 683 policy->cpuinfo.transition_latency =
684 cpufreq_scale(2000000UL, fsb, latency);
649 685
650 policy->cur = powernow_get(0); 686 policy->cur = powernow_get(0);
651 687
@@ -654,7 +690,8 @@ static int __init powernow_cpu_init (struct cpufreq_policy *policy)
654 return cpufreq_frequency_table_cpuinfo(policy, powernow_table); 690 return cpufreq_frequency_table_cpuinfo(policy, powernow_table);
655} 691}
656 692
657static int powernow_cpu_exit (struct cpufreq_policy *policy) { 693static int powernow_cpu_exit(struct cpufreq_policy *policy)
694{
658 cpufreq_frequency_table_put_attr(policy->cpu); 695 cpufreq_frequency_table_put_attr(policy->cpu);
659 696
660#ifdef CONFIG_X86_POWERNOW_K7_ACPI 697#ifdef CONFIG_X86_POWERNOW_K7_ACPI
@@ -669,7 +706,7 @@ static int powernow_cpu_exit (struct cpufreq_policy *policy) {
669 return 0; 706 return 0;
670} 707}
671 708
672static struct freq_attr* powernow_table_attr[] = { 709static struct freq_attr *powernow_table_attr[] = {
673 &cpufreq_freq_attr_scaling_available_freqs, 710 &cpufreq_freq_attr_scaling_available_freqs,
674 NULL, 711 NULL,
675}; 712};
@@ -685,15 +722,15 @@ static struct cpufreq_driver powernow_driver = {
685 .attr = powernow_table_attr, 722 .attr = powernow_table_attr,
686}; 723};
687 724
688static int __init powernow_init (void) 725static int __init powernow_init(void)
689{ 726{
690 if (check_powernow()==0) 727 if (check_powernow() == 0)
691 return -ENODEV; 728 return -ENODEV;
692 return cpufreq_register_driver(&powernow_driver); 729 return cpufreq_register_driver(&powernow_driver);
693} 730}
694 731
695 732
696static void __exit powernow_exit (void) 733static void __exit powernow_exit(void)
697{ 734{
698 cpufreq_unregister_driver(&powernow_driver); 735 cpufreq_unregister_driver(&powernow_driver);
699} 736}
@@ -701,9 +738,9 @@ static void __exit powernow_exit (void)
701module_param(acpi_force, int, 0444); 738module_param(acpi_force, int, 0444);
702MODULE_PARM_DESC(acpi_force, "Force ACPI to be used."); 739MODULE_PARM_DESC(acpi_force, "Force ACPI to be used.");
703 740
704MODULE_AUTHOR ("Dave Jones <davej@redhat.com>"); 741MODULE_AUTHOR("Dave Jones <davej@redhat.com>");
705MODULE_DESCRIPTION ("Powernow driver for AMD K7 processors."); 742MODULE_DESCRIPTION("Powernow driver for AMD K7 processors.");
706MODULE_LICENSE ("GPL"); 743MODULE_LICENSE("GPL");
707 744
708late_initcall(powernow_init); 745late_initcall(powernow_init);
709module_exit(powernow_exit); 746module_exit(powernow_exit);
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
index 6428aa17b40e..a15ac94e0b9b 100644
--- a/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
+++ b/arch/x86/kernel/cpu/cpufreq/powernow-k8.c
@@ -33,16 +33,14 @@
33#include <linux/string.h> 33#include <linux/string.h>
34#include <linux/cpumask.h> 34#include <linux/cpumask.h>
35#include <linux/sched.h> /* for current / set_cpus_allowed() */ 35#include <linux/sched.h> /* for current / set_cpus_allowed() */
36#include <linux/io.h>
37#include <linux/delay.h>
36 38
37#include <asm/msr.h> 39#include <asm/msr.h>
38#include <asm/io.h>
39#include <asm/delay.h>
40 40
41#ifdef CONFIG_X86_POWERNOW_K8_ACPI
42#include <linux/acpi.h> 41#include <linux/acpi.h>
43#include <linux/mutex.h> 42#include <linux/mutex.h>
44#include <acpi/processor.h> 43#include <acpi/processor.h>
45#endif
46 44
47#define PFX "powernow-k8: " 45#define PFX "powernow-k8: "
48#define VERSION "version 2.20.00" 46#define VERSION "version 2.20.00"
@@ -71,7 +69,8 @@ static u32 find_khz_freq_from_fid(u32 fid)
71 return 1000 * find_freq_from_fid(fid); 69 return 1000 * find_freq_from_fid(fid);
72} 70}
73 71
74static u32 find_khz_freq_from_pstate(struct cpufreq_frequency_table *data, u32 pstate) 72static u32 find_khz_freq_from_pstate(struct cpufreq_frequency_table *data,
73 u32 pstate)
75{ 74{
76 return data[pstate].frequency; 75 return data[pstate].frequency;
77} 76}
@@ -186,7 +185,9 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
186 return 1; 185 return 1;
187 } 186 }
188 187
189 lo = fid | (data->currvid << MSR_C_LO_VID_SHIFT) | MSR_C_LO_INIT_FID_VID; 188 lo = fid;
189 lo |= (data->currvid << MSR_C_LO_VID_SHIFT);
190 lo |= MSR_C_LO_INIT_FID_VID;
190 191
191 dprintk("writing fid 0x%x, lo 0x%x, hi 0x%x\n", 192 dprintk("writing fid 0x%x, lo 0x%x, hi 0x%x\n",
192 fid, lo, data->plllock * PLL_LOCK_CONVERSION); 193 fid, lo, data->plllock * PLL_LOCK_CONVERSION);
@@ -194,7 +195,9 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
194 do { 195 do {
195 wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION); 196 wrmsr(MSR_FIDVID_CTL, lo, data->plllock * PLL_LOCK_CONVERSION);
196 if (i++ > 100) { 197 if (i++ > 100) {
197 printk(KERN_ERR PFX "Hardware error - pending bit very stuck - no further pstate changes possible\n"); 198 printk(KERN_ERR PFX
199 "Hardware error - pending bit very stuck - "
200 "no further pstate changes possible\n");
198 return 1; 201 return 1;
199 } 202 }
200 } while (query_current_values_with_pending_wait(data)); 203 } while (query_current_values_with_pending_wait(data));
@@ -202,14 +205,16 @@ static int write_new_fid(struct powernow_k8_data *data, u32 fid)
202 count_off_irt(data); 205 count_off_irt(data);
203 206
204 if (savevid != data->currvid) { 207 if (savevid != data->currvid) {
205 printk(KERN_ERR PFX "vid change on fid trans, old 0x%x, new 0x%x\n", 208 printk(KERN_ERR PFX
206 savevid, data->currvid); 209 "vid change on fid trans, old 0x%x, new 0x%x\n",
210 savevid, data->currvid);
207 return 1; 211 return 1;
208 } 212 }
209 213
210 if (fid != data->currfid) { 214 if (fid != data->currfid) {
211 printk(KERN_ERR PFX "fid trans failed, fid 0x%x, curr 0x%x\n", fid, 215 printk(KERN_ERR PFX
212 data->currfid); 216 "fid trans failed, fid 0x%x, curr 0x%x\n", fid,
217 data->currfid);
213 return 1; 218 return 1;
214 } 219 }
215 220
@@ -228,7 +233,9 @@ static int write_new_vid(struct powernow_k8_data *data, u32 vid)
228 return 1; 233 return 1;
229 } 234 }
230 235
231 lo = data->currfid | (vid << MSR_C_LO_VID_SHIFT) | MSR_C_LO_INIT_FID_VID; 236 lo = data->currfid;
237 lo |= (vid << MSR_C_LO_VID_SHIFT);
238 lo |= MSR_C_LO_INIT_FID_VID;
232 239
233 dprintk("writing vid 0x%x, lo 0x%x, hi 0x%x\n", 240 dprintk("writing vid 0x%x, lo 0x%x, hi 0x%x\n",
234 vid, lo, STOP_GRANT_5NS); 241 vid, lo, STOP_GRANT_5NS);
@@ -236,20 +243,24 @@ static int write_new_vid(struct powernow_k8_data *data, u32 vid)
236 do { 243 do {
237 wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS); 244 wrmsr(MSR_FIDVID_CTL, lo, STOP_GRANT_5NS);
238 if (i++ > 100) { 245 if (i++ > 100) {
239 printk(KERN_ERR PFX "internal error - pending bit very stuck - no further pstate changes possible\n"); 246 printk(KERN_ERR PFX "internal error - pending bit "
247 "very stuck - no further pstate "
248 "changes possible\n");
240 return 1; 249 return 1;
241 } 250 }
242 } while (query_current_values_with_pending_wait(data)); 251 } while (query_current_values_with_pending_wait(data));
243 252
244 if (savefid != data->currfid) { 253 if (savefid != data->currfid) {
245 printk(KERN_ERR PFX "fid changed on vid trans, old 0x%x new 0x%x\n", 254 printk(KERN_ERR PFX "fid changed on vid trans, old "
255 "0x%x new 0x%x\n",
246 savefid, data->currfid); 256 savefid, data->currfid);
247 return 1; 257 return 1;
248 } 258 }
249 259
250 if (vid != data->currvid) { 260 if (vid != data->currvid) {
251 printk(KERN_ERR PFX "vid trans failed, vid 0x%x, curr 0x%x\n", vid, 261 printk(KERN_ERR PFX "vid trans failed, vid 0x%x, "
252 data->currvid); 262 "curr 0x%x\n",
263 vid, data->currvid);
253 return 1; 264 return 1;
254 } 265 }
255 266
@@ -261,7 +272,8 @@ static int write_new_vid(struct powernow_k8_data *data, u32 vid)
261 * Decreasing vid codes represent increasing voltages: 272 * Decreasing vid codes represent increasing voltages:
262 * vid of 0 is 1.550V, vid of 0x1e is 0.800V, vid of VID_OFF is off. 273 * vid of 0 is 1.550V, vid of 0x1e is 0.800V, vid of VID_OFF is off.
263 */ 274 */
264static int decrease_vid_code_by_step(struct powernow_k8_data *data, u32 reqvid, u32 step) 275static int decrease_vid_code_by_step(struct powernow_k8_data *data,
276 u32 reqvid, u32 step)
265{ 277{
266 if ((data->currvid - reqvid) > step) 278 if ((data->currvid - reqvid) > step)
267 reqvid = data->currvid - step; 279 reqvid = data->currvid - step;
@@ -283,7 +295,8 @@ static int transition_pstate(struct powernow_k8_data *data, u32 pstate)
283} 295}
284 296
285/* Change Opteron/Athlon64 fid and vid, by the 3 phases. */ 297/* Change Opteron/Athlon64 fid and vid, by the 3 phases. */
286static int transition_fid_vid(struct powernow_k8_data *data, u32 reqfid, u32 reqvid) 298static int transition_fid_vid(struct powernow_k8_data *data,
299 u32 reqfid, u32 reqvid)
287{ 300{
288 if (core_voltage_pre_transition(data, reqvid)) 301 if (core_voltage_pre_transition(data, reqvid))
289 return 1; 302 return 1;
@@ -298,7 +311,8 @@ static int transition_fid_vid(struct powernow_k8_data *data, u32 reqfid, u32 req
298 return 1; 311 return 1;
299 312
300 if ((reqfid != data->currfid) || (reqvid != data->currvid)) { 313 if ((reqfid != data->currfid) || (reqvid != data->currvid)) {
301 printk(KERN_ERR PFX "failed (cpu%d): req 0x%x 0x%x, curr 0x%x 0x%x\n", 314 printk(KERN_ERR PFX "failed (cpu%d): req 0x%x 0x%x, "
315 "curr 0x%x 0x%x\n",
302 smp_processor_id(), 316 smp_processor_id(),
303 reqfid, reqvid, data->currfid, data->currvid); 317 reqfid, reqvid, data->currfid, data->currvid);
304 return 1; 318 return 1;
@@ -311,13 +325,15 @@ static int transition_fid_vid(struct powernow_k8_data *data, u32 reqfid, u32 req
311} 325}
312 326
313/* Phase 1 - core voltage transition ... setup voltage */ 327/* Phase 1 - core voltage transition ... setup voltage */
314static int core_voltage_pre_transition(struct powernow_k8_data *data, u32 reqvid) 328static int core_voltage_pre_transition(struct powernow_k8_data *data,
329 u32 reqvid)
315{ 330{
316 u32 rvosteps = data->rvo; 331 u32 rvosteps = data->rvo;
317 u32 savefid = data->currfid; 332 u32 savefid = data->currfid;
318 u32 maxvid, lo; 333 u32 maxvid, lo;
319 334
320 dprintk("ph1 (cpu%d): start, currfid 0x%x, currvid 0x%x, reqvid 0x%x, rvo 0x%x\n", 335 dprintk("ph1 (cpu%d): start, currfid 0x%x, currvid 0x%x, "
336 "reqvid 0x%x, rvo 0x%x\n",
321 smp_processor_id(), 337 smp_processor_id(),
322 data->currfid, data->currvid, reqvid, data->rvo); 338 data->currfid, data->currvid, reqvid, data->rvo);
323 339
@@ -340,7 +356,7 @@ static int core_voltage_pre_transition(struct powernow_k8_data *data, u32 reqvid
340 } else { 356 } else {
341 dprintk("ph1: changing vid for rvo, req 0x%x\n", 357 dprintk("ph1: changing vid for rvo, req 0x%x\n",
342 data->currvid - 1); 358 data->currvid - 1);
343 if (decrease_vid_code_by_step(data, data->currvid - 1, 1)) 359 if (decrease_vid_code_by_step(data, data->currvid-1, 1))
344 return 1; 360 return 1;
345 rvosteps--; 361 rvosteps--;
346 } 362 }
@@ -350,7 +366,8 @@ static int core_voltage_pre_transition(struct powernow_k8_data *data, u32 reqvid
350 return 1; 366 return 1;
351 367
352 if (savefid != data->currfid) { 368 if (savefid != data->currfid) {
353 printk(KERN_ERR PFX "ph1 err, currfid changed 0x%x\n", data->currfid); 369 printk(KERN_ERR PFX "ph1 err, currfid changed 0x%x\n",
370 data->currfid);
354 return 1; 371 return 1;
355 } 372 }
356 373
@@ -363,20 +380,24 @@ static int core_voltage_pre_transition(struct powernow_k8_data *data, u32 reqvid
363/* Phase 2 - core frequency transition */ 380/* Phase 2 - core frequency transition */
364static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid) 381static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
365{ 382{
366 u32 vcoreqfid, vcocurrfid, vcofiddiff, fid_interval, savevid = data->currvid; 383 u32 vcoreqfid, vcocurrfid, vcofiddiff;
384 u32 fid_interval, savevid = data->currvid;
367 385
368 if ((reqfid < HI_FID_TABLE_BOTTOM) && (data->currfid < HI_FID_TABLE_BOTTOM)) { 386 if ((reqfid < HI_FID_TABLE_BOTTOM) &&
369 printk(KERN_ERR PFX "ph2: illegal lo-lo transition 0x%x 0x%x\n", 387 (data->currfid < HI_FID_TABLE_BOTTOM)) {
370 reqfid, data->currfid); 388 printk(KERN_ERR PFX "ph2: illegal lo-lo transition "
389 "0x%x 0x%x\n", reqfid, data->currfid);
371 return 1; 390 return 1;
372 } 391 }
373 392
374 if (data->currfid == reqfid) { 393 if (data->currfid == reqfid) {
375 printk(KERN_ERR PFX "ph2 null fid transition 0x%x\n", data->currfid); 394 printk(KERN_ERR PFX "ph2 null fid transition 0x%x\n",
395 data->currfid);
376 return 0; 396 return 0;
377 } 397 }
378 398
379 dprintk("ph2 (cpu%d): starting, currfid 0x%x, currvid 0x%x, reqfid 0x%x\n", 399 dprintk("ph2 (cpu%d): starting, currfid 0x%x, currvid 0x%x, "
400 "reqfid 0x%x\n",
380 smp_processor_id(), 401 smp_processor_id(),
381 data->currfid, data->currvid, reqfid); 402 data->currfid, data->currvid, reqfid);
382 403
@@ -390,14 +411,14 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
390 411
391 if (reqfid > data->currfid) { 412 if (reqfid > data->currfid) {
392 if (data->currfid > LO_FID_TABLE_TOP) { 413 if (data->currfid > LO_FID_TABLE_TOP) {
393 if (write_new_fid(data, data->currfid + fid_interval)) { 414 if (write_new_fid(data,
415 data->currfid + fid_interval))
394 return 1; 416 return 1;
395 }
396 } else { 417 } else {
397 if (write_new_fid 418 if (write_new_fid
398 (data, 2 + convert_fid_to_vco_fid(data->currfid))) { 419 (data,
420 2 + convert_fid_to_vco_fid(data->currfid)))
399 return 1; 421 return 1;
400 }
401 } 422 }
402 } else { 423 } else {
403 if (write_new_fid(data, data->currfid - fid_interval)) 424 if (write_new_fid(data, data->currfid - fid_interval))
@@ -417,7 +438,8 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
417 438
418 if (data->currfid != reqfid) { 439 if (data->currfid != reqfid) {
419 printk(KERN_ERR PFX 440 printk(KERN_ERR PFX
420 "ph2: mismatch, failed fid transition, curr 0x%x, req 0x%x\n", 441 "ph2: mismatch, failed fid transition, "
442 "curr 0x%x, req 0x%x\n",
421 data->currfid, reqfid); 443 data->currfid, reqfid);
422 return 1; 444 return 1;
423 } 445 }
@@ -435,7 +457,8 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid)
435} 457}
436 458
437/* Phase 3 - core voltage transition flow ... jump to the final vid. */ 459/* Phase 3 - core voltage transition flow ... jump to the final vid. */
438static int core_voltage_post_transition(struct powernow_k8_data *data, u32 reqvid) 460static int core_voltage_post_transition(struct powernow_k8_data *data,
461 u32 reqvid)
439{ 462{
440 u32 savefid = data->currfid; 463 u32 savefid = data->currfid;
441 u32 savereqvid = reqvid; 464 u32 savereqvid = reqvid;
@@ -457,7 +480,8 @@ static int core_voltage_post_transition(struct powernow_k8_data *data, u32 reqvi
457 480
458 if (data->currvid != reqvid) { 481 if (data->currvid != reqvid) {
459 printk(KERN_ERR PFX 482 printk(KERN_ERR PFX
460 "ph3: failed vid transition\n, req 0x%x, curr 0x%x", 483 "ph3: failed vid transition\n, "
484 "req 0x%x, curr 0x%x",
461 reqvid, data->currvid); 485 reqvid, data->currvid);
462 return 1; 486 return 1;
463 } 487 }
@@ -508,7 +532,8 @@ static int check_supported_cpu(unsigned int cpu)
508 if ((eax & CPUID_XFAM) == CPUID_XFAM_K8) { 532 if ((eax & CPUID_XFAM) == CPUID_XFAM_K8) {
509 if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) || 533 if (((eax & CPUID_USE_XFAM_XMOD) != CPUID_USE_XFAM_XMOD) ||
510 ((eax & CPUID_XMOD) > CPUID_XMOD_REV_MASK)) { 534 ((eax & CPUID_XMOD) > CPUID_XMOD_REV_MASK)) {
511 printk(KERN_INFO PFX "Processor cpuid %x not supported\n", eax); 535 printk(KERN_INFO PFX
536 "Processor cpuid %x not supported\n", eax);
512 goto out; 537 goto out;
513 } 538 }
514 539
@@ -520,8 +545,10 @@ static int check_supported_cpu(unsigned int cpu)
520 } 545 }
521 546
522 cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx); 547 cpuid(CPUID_FREQ_VOLT_CAPABILITIES, &eax, &ebx, &ecx, &edx);
523 if ((edx & P_STATE_TRANSITION_CAPABLE) != P_STATE_TRANSITION_CAPABLE) { 548 if ((edx & P_STATE_TRANSITION_CAPABLE)
524 printk(KERN_INFO PFX "Power state transitions not supported\n"); 549 != P_STATE_TRANSITION_CAPABLE) {
550 printk(KERN_INFO PFX
551 "Power state transitions not supported\n");
525 goto out; 552 goto out;
526 } 553 }
527 } else { /* must be a HW Pstate capable processor */ 554 } else { /* must be a HW Pstate capable processor */
@@ -539,7 +566,8 @@ out:
539 return rc; 566 return rc;
540} 567}
541 568
542static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, u8 maxvid) 569static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst,
570 u8 maxvid)
543{ 571{
544 unsigned int j; 572 unsigned int j;
545 u8 lastfid = 0xff; 573 u8 lastfid = 0xff;
@@ -550,12 +578,14 @@ static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, u8
550 j, pst[j].vid); 578 j, pst[j].vid);
551 return -EINVAL; 579 return -EINVAL;
552 } 580 }
553 if (pst[j].vid < data->rvo) { /* vid + rvo >= 0 */ 581 if (pst[j].vid < data->rvo) {
582 /* vid + rvo >= 0 */
554 printk(KERN_ERR FW_BUG PFX "0 vid exceeded with pstate" 583 printk(KERN_ERR FW_BUG PFX "0 vid exceeded with pstate"
555 " %d\n", j); 584 " %d\n", j);
556 return -ENODEV; 585 return -ENODEV;
557 } 586 }
558 if (pst[j].vid < maxvid + data->rvo) { /* vid + rvo >= maxvid */ 587 if (pst[j].vid < maxvid + data->rvo) {
588 /* vid + rvo >= maxvid */
559 printk(KERN_ERR FW_BUG PFX "maxvid exceeded with pstate" 589 printk(KERN_ERR FW_BUG PFX "maxvid exceeded with pstate"
560 " %d\n", j); 590 " %d\n", j);
561 return -ENODEV; 591 return -ENODEV;
@@ -579,23 +609,31 @@ static int check_pst_table(struct powernow_k8_data *data, struct pst_s *pst, u8
579 return -EINVAL; 609 return -EINVAL;
580 } 610 }
581 if (lastfid > LO_FID_TABLE_TOP) 611 if (lastfid > LO_FID_TABLE_TOP)
582 printk(KERN_INFO FW_BUG PFX "first fid not from lo freq table\n"); 612 printk(KERN_INFO FW_BUG PFX
613 "first fid not from lo freq table\n");
583 614
584 return 0; 615 return 0;
585} 616}
586 617
618static void invalidate_entry(struct powernow_k8_data *data, unsigned int entry)
619{
620 data->powernow_table[entry].frequency = CPUFREQ_ENTRY_INVALID;
621}
622
587static void print_basics(struct powernow_k8_data *data) 623static void print_basics(struct powernow_k8_data *data)
588{ 624{
589 int j; 625 int j;
590 for (j = 0; j < data->numps; j++) { 626 for (j = 0; j < data->numps; j++) {
591 if (data->powernow_table[j].frequency != CPUFREQ_ENTRY_INVALID) { 627 if (data->powernow_table[j].frequency !=
628 CPUFREQ_ENTRY_INVALID) {
592 if (cpu_family == CPU_HW_PSTATE) { 629 if (cpu_family == CPU_HW_PSTATE) {
593 printk(KERN_INFO PFX " %d : pstate %d (%d MHz)\n", 630 printk(KERN_INFO PFX
594 j, 631 " %d : pstate %d (%d MHz)\n", j,
595 data->powernow_table[j].index, 632 data->powernow_table[j].index,
596 data->powernow_table[j].frequency/1000); 633 data->powernow_table[j].frequency/1000);
597 } else { 634 } else {
598 printk(KERN_INFO PFX " %d : fid 0x%x (%d MHz), vid 0x%x\n", 635 printk(KERN_INFO PFX
636 " %d : fid 0x%x (%d MHz), vid 0x%x\n",
599 j, 637 j,
600 data->powernow_table[j].index & 0xff, 638 data->powernow_table[j].index & 0xff,
601 data->powernow_table[j].frequency/1000, 639 data->powernow_table[j].frequency/1000,
@@ -604,20 +642,25 @@ static void print_basics(struct powernow_k8_data *data)
604 } 642 }
605 } 643 }
606 if (data->batps) 644 if (data->batps)
607 printk(KERN_INFO PFX "Only %d pstates on battery\n", data->batps); 645 printk(KERN_INFO PFX "Only %d pstates on battery\n",
646 data->batps);
608} 647}
609 648
610static int fill_powernow_table(struct powernow_k8_data *data, struct pst_s *pst, u8 maxvid) 649static int fill_powernow_table(struct powernow_k8_data *data,
650 struct pst_s *pst, u8 maxvid)
611{ 651{
612 struct cpufreq_frequency_table *powernow_table; 652 struct cpufreq_frequency_table *powernow_table;
613 unsigned int j; 653 unsigned int j;
614 654
615 if (data->batps) { /* use ACPI support to get full speed on mains power */ 655 if (data->batps) {
616 printk(KERN_WARNING PFX "Only %d pstates usable (use ACPI driver for full range\n", data->batps); 656 /* use ACPI support to get full speed on mains power */
657 printk(KERN_WARNING PFX
658 "Only %d pstates usable (use ACPI driver for full "
659 "range\n", data->batps);
617 data->numps = data->batps; 660 data->numps = data->batps;
618 } 661 }
619 662
620 for ( j=1; j<data->numps; j++ ) { 663 for (j = 1; j < data->numps; j++) {
621 if (pst[j-1].fid >= pst[j].fid) { 664 if (pst[j-1].fid >= pst[j].fid) {
622 printk(KERN_ERR PFX "PST out of sequence\n"); 665 printk(KERN_ERR PFX "PST out of sequence\n");
623 return -EINVAL; 666 return -EINVAL;
@@ -640,9 +683,11 @@ static int fill_powernow_table(struct powernow_k8_data *data, struct pst_s *pst,
640 } 683 }
641 684
642 for (j = 0; j < data->numps; j++) { 685 for (j = 0; j < data->numps; j++) {
686 int freq;
643 powernow_table[j].index = pst[j].fid; /* lower 8 bits */ 687 powernow_table[j].index = pst[j].fid; /* lower 8 bits */
644 powernow_table[j].index |= (pst[j].vid << 8); /* upper 8 bits */ 688 powernow_table[j].index |= (pst[j].vid << 8); /* upper 8 bits */
645 powernow_table[j].frequency = find_khz_freq_from_fid(pst[j].fid); 689 freq = find_khz_freq_from_fid(pst[j].fid);
690 powernow_table[j].frequency = freq;
646 } 691 }
647 powernow_table[data->numps].frequency = CPUFREQ_TABLE_END; 692 powernow_table[data->numps].frequency = CPUFREQ_TABLE_END;
648 powernow_table[data->numps].index = 0; 693 powernow_table[data->numps].index = 0;
@@ -658,7 +703,8 @@ static int fill_powernow_table(struct powernow_k8_data *data, struct pst_s *pst,
658 print_basics(data); 703 print_basics(data);
659 704
660 for (j = 0; j < data->numps; j++) 705 for (j = 0; j < data->numps; j++)
661 if ((pst[j].fid==data->currfid) && (pst[j].vid==data->currvid)) 706 if ((pst[j].fid == data->currfid) &&
707 (pst[j].vid == data->currvid))
662 return 0; 708 return 0;
663 709
664 dprintk("currfid/vid do not match PST, ignoring\n"); 710 dprintk("currfid/vid do not match PST, ignoring\n");
@@ -698,7 +744,8 @@ static int find_psb_table(struct powernow_k8_data *data)
698 } 744 }
699 745
700 data->vstable = psb->vstable; 746 data->vstable = psb->vstable;
701 dprintk("voltage stabilization time: %d(*20us)\n", data->vstable); 747 dprintk("voltage stabilization time: %d(*20us)\n",
748 data->vstable);
702 749
703 dprintk("flags2: 0x%x\n", psb->flags2); 750 dprintk("flags2: 0x%x\n", psb->flags2);
704 data->rvo = psb->flags2 & 3; 751 data->rvo = psb->flags2 & 3;
@@ -713,11 +760,12 @@ static int find_psb_table(struct powernow_k8_data *data)
713 760
714 dprintk("numpst: 0x%x\n", psb->num_tables); 761 dprintk("numpst: 0x%x\n", psb->num_tables);
715 cpst = psb->num_tables; 762 cpst = psb->num_tables;
716 if ((psb->cpuid == 0x00000fc0) || (psb->cpuid == 0x00000fe0) ){ 763 if ((psb->cpuid == 0x00000fc0) ||
764 (psb->cpuid == 0x00000fe0)) {
717 thiscpuid = cpuid_eax(CPUID_PROCESSOR_SIGNATURE); 765 thiscpuid = cpuid_eax(CPUID_PROCESSOR_SIGNATURE);
718 if ((thiscpuid == 0x00000fc0) || (thiscpuid == 0x00000fe0) ) { 766 if ((thiscpuid == 0x00000fc0) ||
767 (thiscpuid == 0x00000fe0))
719 cpst = 1; 768 cpst = 1;
720 }
721 } 769 }
722 if (cpst != 1) { 770 if (cpst != 1) {
723 printk(KERN_ERR FW_BUG PFX "numpst must be 1\n"); 771 printk(KERN_ERR FW_BUG PFX "numpst must be 1\n");
@@ -732,7 +780,8 @@ static int find_psb_table(struct powernow_k8_data *data)
732 780
733 data->numps = psb->numps; 781 data->numps = psb->numps;
734 dprintk("numpstates: 0x%x\n", data->numps); 782 dprintk("numpstates: 0x%x\n", data->numps);
735 return fill_powernow_table(data, (struct pst_s *)(psb+1), maxvid); 783 return fill_powernow_table(data,
784 (struct pst_s *)(psb+1), maxvid);
736 } 785 }
737 /* 786 /*
738 * If you see this message, complain to BIOS manufacturer. If 787 * If you see this message, complain to BIOS manufacturer. If
@@ -745,28 +794,31 @@ static int find_psb_table(struct powernow_k8_data *data)
745 * BIOS and Kernel Developer's Guide, which is available on 794 * BIOS and Kernel Developer's Guide, which is available on
746 * www.amd.com 795 * www.amd.com
747 */ 796 */
748 printk(KERN_ERR PFX "BIOS error - no PSB or ACPI _PSS objects\n"); 797 printk(KERN_ERR FW_BUG PFX "No PSB or ACPI _PSS objects\n");
749 return -ENODEV; 798 return -ENODEV;
750} 799}
751 800
752#ifdef CONFIG_X86_POWERNOW_K8_ACPI 801static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data,
753static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index) 802 unsigned int index)
754{ 803{
804 acpi_integer control;
805
755 if (!data->acpi_data.state_count || (cpu_family == CPU_HW_PSTATE)) 806 if (!data->acpi_data.state_count || (cpu_family == CPU_HW_PSTATE))
756 return; 807 return;
757 808
758 data->irt = (data->acpi_data.states[index].control >> IRT_SHIFT) & IRT_MASK; 809 control = data->acpi_data.states[index].control; data->irt = (control
759 data->rvo = (data->acpi_data.states[index].control >> RVO_SHIFT) & RVO_MASK; 810 >> IRT_SHIFT) & IRT_MASK; data->rvo = (control >>
760 data->exttype = (data->acpi_data.states[index].control >> EXT_TYPE_SHIFT) & EXT_TYPE_MASK; 811 RVO_SHIFT) & RVO_MASK; data->exttype = (control
761 data->plllock = (data->acpi_data.states[index].control >> PLL_L_SHIFT) & PLL_L_MASK; 812 >> EXT_TYPE_SHIFT) & EXT_TYPE_MASK;
762 data->vidmvs = 1 << ((data->acpi_data.states[index].control >> MVS_SHIFT) & MVS_MASK); 813 data->plllock = (control >> PLL_L_SHIFT) & PLL_L_MASK; data->vidmvs = 1
763 data->vstable = (data->acpi_data.states[index].control >> VST_SHIFT) & VST_MASK; 814 << ((control >> MVS_SHIFT) & MVS_MASK); data->vstable =
764} 815 (control >> VST_SHIFT) & VST_MASK; }
765 816
766static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) 817static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
767{ 818{
768 struct cpufreq_frequency_table *powernow_table; 819 struct cpufreq_frequency_table *powernow_table;
769 int ret_val = -ENODEV; 820 int ret_val = -ENODEV;
821 acpi_integer space_id;
770 822
771 if (acpi_processor_register_performance(&data->acpi_data, data->cpu)) { 823 if (acpi_processor_register_performance(&data->acpi_data, data->cpu)) {
772 dprintk("register performance failed: bad ACPI data\n"); 824 dprintk("register performance failed: bad ACPI data\n");
@@ -779,11 +831,12 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
779 goto err_out; 831 goto err_out;
780 } 832 }
781 833
782 if ((data->acpi_data.control_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) || 834 space_id = data->acpi_data.control_register.space_id;
783 (data->acpi_data.status_register.space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) { 835 if ((space_id != ACPI_ADR_SPACE_FIXED_HARDWARE) ||
836 (space_id != ACPI_ADR_SPACE_FIXED_HARDWARE)) {
784 dprintk("Invalid control/status registers (%x - %x)\n", 837 dprintk("Invalid control/status registers (%x - %x)\n",
785 data->acpi_data.control_register.space_id, 838 data->acpi_data.control_register.space_id,
786 data->acpi_data.status_register.space_id); 839 space_id);
787 goto err_out; 840 goto err_out;
788 } 841 }
789 842
@@ -802,7 +855,8 @@ static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data)
802 if (ret_val) 855 if (ret_val)
803 goto err_out_mem; 856 goto err_out_mem;
804 857
805 powernow_table[data->acpi_data.state_count].frequency = CPUFREQ_TABLE_END; 858 powernow_table[data->acpi_data.state_count].frequency =
859 CPUFREQ_TABLE_END;
806 powernow_table[data->acpi_data.state_count].index = 0; 860 powernow_table[data->acpi_data.state_count].index = 0;
807 data->powernow_table = powernow_table; 861 data->powernow_table = powernow_table;
808 862
@@ -830,13 +884,15 @@ err_out_mem:
830err_out: 884err_out:
831 acpi_processor_unregister_performance(&data->acpi_data, data->cpu); 885 acpi_processor_unregister_performance(&data->acpi_data, data->cpu);
832 886
833 /* data->acpi_data.state_count informs us at ->exit() whether ACPI was used */ 887 /* data->acpi_data.state_count informs us at ->exit()
888 * whether ACPI was used */
834 data->acpi_data.state_count = 0; 889 data->acpi_data.state_count = 0;
835 890
836 return ret_val; 891 return ret_val;
837} 892}
838 893
839static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table) 894static int fill_powernow_table_pstate(struct powernow_k8_data *data,
895 struct cpufreq_frequency_table *powernow_table)
840{ 896{
841 int i; 897 int i;
842 u32 hi = 0, lo = 0; 898 u32 hi = 0, lo = 0;
@@ -848,84 +904,101 @@ static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpuf
848 904
849 index = data->acpi_data.states[i].control & HW_PSTATE_MASK; 905 index = data->acpi_data.states[i].control & HW_PSTATE_MASK;
850 if (index > data->max_hw_pstate) { 906 if (index > data->max_hw_pstate) {
851 printk(KERN_ERR PFX "invalid pstate %d - bad value %d.\n", i, index); 907 printk(KERN_ERR PFX "invalid pstate %d - "
852 printk(KERN_ERR PFX "Please report to BIOS manufacturer\n"); 908 "bad value %d.\n", i, index);
853 powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID; 909 printk(KERN_ERR PFX "Please report to BIOS "
910 "manufacturer\n");
911 invalidate_entry(data, i);
854 continue; 912 continue;
855 } 913 }
856 rdmsr(MSR_PSTATE_DEF_BASE + index, lo, hi); 914 rdmsr(MSR_PSTATE_DEF_BASE + index, lo, hi);
857 if (!(hi & HW_PSTATE_VALID_MASK)) { 915 if (!(hi & HW_PSTATE_VALID_MASK)) {
858 dprintk("invalid pstate %d, ignoring\n", index); 916 dprintk("invalid pstate %d, ignoring\n", index);
859 powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID; 917 invalidate_entry(data, i);
860 continue; 918 continue;
861 } 919 }
862 920
863 powernow_table[i].index = index; 921 powernow_table[i].index = index;
864 922
865 powernow_table[i].frequency = data->acpi_data.states[i].core_frequency * 1000; 923 powernow_table[i].frequency =
924 data->acpi_data.states[i].core_frequency * 1000;
866 } 925 }
867 return 0; 926 return 0;
868} 927}
869 928
870static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table) 929static int fill_powernow_table_fidvid(struct powernow_k8_data *data,
930 struct cpufreq_frequency_table *powernow_table)
871{ 931{
872 int i; 932 int i;
873 int cntlofreq = 0; 933 int cntlofreq = 0;
934
874 for (i = 0; i < data->acpi_data.state_count; i++) { 935 for (i = 0; i < data->acpi_data.state_count; i++) {
875 u32 fid; 936 u32 fid;
876 u32 vid; 937 u32 vid;
938 u32 freq, index;
939 acpi_integer status, control;
877 940
878 if (data->exttype) { 941 if (data->exttype) {
879 fid = data->acpi_data.states[i].status & EXT_FID_MASK; 942 status = data->acpi_data.states[i].status;
880 vid = (data->acpi_data.states[i].status >> VID_SHIFT) & EXT_VID_MASK; 943 fid = status & EXT_FID_MASK;
944 vid = (status >> VID_SHIFT) & EXT_VID_MASK;
881 } else { 945 } else {
882 fid = data->acpi_data.states[i].control & FID_MASK; 946 control = data->acpi_data.states[i].control;
883 vid = (data->acpi_data.states[i].control >> VID_SHIFT) & VID_MASK; 947 fid = control & FID_MASK;
948 vid = (control >> VID_SHIFT) & VID_MASK;
884 } 949 }
885 950
886 dprintk(" %d : fid 0x%x, vid 0x%x\n", i, fid, vid); 951 dprintk(" %d : fid 0x%x, vid 0x%x\n", i, fid, vid);
887 952
888 powernow_table[i].index = fid; /* lower 8 bits */ 953 index = fid | (vid<<8);
889 powernow_table[i].index |= (vid << 8); /* upper 8 bits */ 954 powernow_table[i].index = index;
890 powernow_table[i].frequency = find_khz_freq_from_fid(fid); 955
956 freq = find_khz_freq_from_fid(fid);
957 powernow_table[i].frequency = freq;
891 958
892 /* verify frequency is OK */ 959 /* verify frequency is OK */
893 if ((powernow_table[i].frequency > (MAX_FREQ * 1000)) || 960 if ((freq > (MAX_FREQ * 1000)) || (freq < (MIN_FREQ * 1000))) {
894 (powernow_table[i].frequency < (MIN_FREQ * 1000))) { 961 dprintk("invalid freq %u kHz, ignoring\n", freq);
895 dprintk("invalid freq %u kHz, ignoring\n", powernow_table[i].frequency); 962 invalidate_entry(data, i);
896 powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID;
897 continue; 963 continue;
898 } 964 }
899 965
900 /* verify voltage is OK - BIOSs are using "off" to indicate invalid */ 966 /* verify voltage is OK -
967 * BIOSs are using "off" to indicate invalid */
901 if (vid == VID_OFF) { 968 if (vid == VID_OFF) {
902 dprintk("invalid vid %u, ignoring\n", vid); 969 dprintk("invalid vid %u, ignoring\n", vid);
903 powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID; 970 invalidate_entry(data, i);
904 continue; 971 continue;
905 } 972 }
906 973
907 /* verify only 1 entry from the lo frequency table */ 974 /* verify only 1 entry from the lo frequency table */
908 if (fid < HI_FID_TABLE_BOTTOM) { 975 if (fid < HI_FID_TABLE_BOTTOM) {
909 if (cntlofreq) { 976 if (cntlofreq) {
910 /* if both entries are the same, ignore this one ... */ 977 /* if both entries are the same,
911 if ((powernow_table[i].frequency != powernow_table[cntlofreq].frequency) || 978 * ignore this one ... */
912 (powernow_table[i].index != powernow_table[cntlofreq].index)) { 979 if ((freq != powernow_table[cntlofreq].frequency) ||
913 printk(KERN_ERR PFX "Too many lo freq table entries\n"); 980 (index != powernow_table[cntlofreq].index)) {
981 printk(KERN_ERR PFX
982 "Too many lo freq table "
983 "entries\n");
914 return 1; 984 return 1;
915 } 985 }
916 986
917 dprintk("double low frequency table entry, ignoring it.\n"); 987 dprintk("double low frequency table entry, "
918 powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID; 988 "ignoring it.\n");
989 invalidate_entry(data, i);
919 continue; 990 continue;
920 } else 991 } else
921 cntlofreq = i; 992 cntlofreq = i;
922 } 993 }
923 994
924 if (powernow_table[i].frequency != (data->acpi_data.states[i].core_frequency * 1000)) { 995 if (freq != (data->acpi_data.states[i].core_frequency * 1000)) {
925 printk(KERN_INFO PFX "invalid freq entries %u kHz vs. %u kHz\n", 996 printk(KERN_INFO PFX "invalid freq entries "
926 powernow_table[i].frequency, 997 "%u kHz vs. %u kHz\n", freq,
927 (unsigned int) (data->acpi_data.states[i].core_frequency * 1000)); 998 (unsigned int)
928 powernow_table[i].frequency = CPUFREQ_ENTRY_INVALID; 999 (data->acpi_data.states[i].core_frequency
1000 * 1000));
1001 invalidate_entry(data, i);
929 continue; 1002 continue;
930 } 1003 }
931 } 1004 }
@@ -935,7 +1008,8 @@ static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpuf
935static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data) 1008static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data)
936{ 1009{
937 if (data->acpi_data.state_count) 1010 if (data->acpi_data.state_count)
938 acpi_processor_unregister_performance(&data->acpi_data, data->cpu); 1011 acpi_processor_unregister_performance(&data->acpi_data,
1012 data->cpu);
939 free_cpumask_var(data->acpi_data.shared_cpu_map); 1013 free_cpumask_var(data->acpi_data.shared_cpu_map);
940} 1014}
941 1015
@@ -953,15 +1027,9 @@ static int get_transition_latency(struct powernow_k8_data *data)
953 return 1000 * max_latency; 1027 return 1000 * max_latency;
954} 1028}
955 1029
956#else
957static int powernow_k8_cpu_init_acpi(struct powernow_k8_data *data) { return -ENODEV; }
958static void powernow_k8_cpu_exit_acpi(struct powernow_k8_data *data) { return; }
959static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index) { return; }
960static int get_transition_latency(struct powernow_k8_data *data) { return 0; }
961#endif /* CONFIG_X86_POWERNOW_K8_ACPI */
962
963/* Take a frequency, and issue the fid/vid transition command */ 1030/* Take a frequency, and issue the fid/vid transition command */
964static int transition_frequency_fidvid(struct powernow_k8_data *data, unsigned int index) 1031static int transition_frequency_fidvid(struct powernow_k8_data *data,
1032 unsigned int index)
965{ 1033{
966 u32 fid = 0; 1034 u32 fid = 0;
967 u32 vid = 0; 1035 u32 vid = 0;
@@ -989,7 +1057,8 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data, unsigned i
989 return 0; 1057 return 0;
990 } 1058 }
991 1059
992 if ((fid < HI_FID_TABLE_BOTTOM) && (data->currfid < HI_FID_TABLE_BOTTOM)) { 1060 if ((fid < HI_FID_TABLE_BOTTOM) &&
1061 (data->currfid < HI_FID_TABLE_BOTTOM)) {
993 printk(KERN_ERR PFX 1062 printk(KERN_ERR PFX
994 "ignoring illegal change in lo freq table-%x to 0x%x\n", 1063 "ignoring illegal change in lo freq table-%x to 0x%x\n",
995 data->currfid, fid); 1064 data->currfid, fid);
@@ -1017,7 +1086,8 @@ static int transition_frequency_fidvid(struct powernow_k8_data *data, unsigned i
1017} 1086}
1018 1087
1019/* Take a frequency, and issue the hardware pstate transition command */ 1088/* Take a frequency, and issue the hardware pstate transition command */
1020static int transition_frequency_pstate(struct powernow_k8_data *data, unsigned int index) 1089static int transition_frequency_pstate(struct powernow_k8_data *data,
1090 unsigned int index)
1021{ 1091{
1022 u32 pstate = 0; 1092 u32 pstate = 0;
1023 int res, i; 1093 int res, i;
@@ -1029,7 +1099,8 @@ static int transition_frequency_pstate(struct powernow_k8_data *data, unsigned i
1029 pstate = index & HW_PSTATE_MASK; 1099 pstate = index & HW_PSTATE_MASK;
1030 if (pstate > data->max_hw_pstate) 1100 if (pstate > data->max_hw_pstate)
1031 return 0; 1101 return 0;
1032 freqs.old = find_khz_freq_from_pstate(data->powernow_table, data->currpstate); 1102 freqs.old = find_khz_freq_from_pstate(data->powernow_table,
1103 data->currpstate);
1033 freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate); 1104 freqs.new = find_khz_freq_from_pstate(data->powernow_table, pstate);
1034 1105
1035 for_each_cpu_mask_nr(i, *(data->available_cores)) { 1106 for_each_cpu_mask_nr(i, *(data->available_cores)) {
@@ -1048,7 +1119,8 @@ static int transition_frequency_pstate(struct powernow_k8_data *data, unsigned i
1048} 1119}
1049 1120
1050/* Driver entry point to switch to the target frequency */ 1121/* Driver entry point to switch to the target frequency */
1051static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsigned relation) 1122static int powernowk8_target(struct cpufreq_policy *pol,
1123 unsigned targfreq, unsigned relation)
1052{ 1124{
1053 cpumask_t oldmask; 1125 cpumask_t oldmask;
1054 struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); 1126 struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
@@ -1087,14 +1159,18 @@ static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsi
1087 dprintk("targ: curr fid 0x%x, vid 0x%x\n", 1159 dprintk("targ: curr fid 0x%x, vid 0x%x\n",
1088 data->currfid, data->currvid); 1160 data->currfid, data->currvid);
1089 1161
1090 if ((checkvid != data->currvid) || (checkfid != data->currfid)) { 1162 if ((checkvid != data->currvid) ||
1163 (checkfid != data->currfid)) {
1091 printk(KERN_INFO PFX 1164 printk(KERN_INFO PFX
1092 "error - out of sync, fix 0x%x 0x%x, vid 0x%x 0x%x\n", 1165 "error - out of sync, fix 0x%x 0x%x, "
1093 checkfid, data->currfid, checkvid, data->currvid); 1166 "vid 0x%x 0x%x\n",
1167 checkfid, data->currfid,
1168 checkvid, data->currvid);
1094 } 1169 }
1095 } 1170 }
1096 1171
1097 if (cpufreq_frequency_table_target(pol, data->powernow_table, targfreq, relation, &newstate)) 1172 if (cpufreq_frequency_table_target(pol, data->powernow_table,
1173 targfreq, relation, &newstate))
1098 goto err_out; 1174 goto err_out;
1099 1175
1100 mutex_lock(&fidvid_mutex); 1176 mutex_lock(&fidvid_mutex);
@@ -1114,7 +1190,8 @@ static int powernowk8_target(struct cpufreq_policy *pol, unsigned targfreq, unsi
1114 mutex_unlock(&fidvid_mutex); 1190 mutex_unlock(&fidvid_mutex);
1115 1191
1116 if (cpu_family == CPU_HW_PSTATE) 1192 if (cpu_family == CPU_HW_PSTATE)
1117 pol->cur = find_khz_freq_from_pstate(data->powernow_table, newstate); 1193 pol->cur = find_khz_freq_from_pstate(data->powernow_table,
1194 newstate);
1118 else 1195 else
1119 pol->cur = find_khz_freq_from_fid(data->currfid); 1196 pol->cur = find_khz_freq_from_fid(data->currfid);
1120 ret = 0; 1197 ret = 0;
@@ -1141,6 +1218,7 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
1141 struct powernow_k8_data *data; 1218 struct powernow_k8_data *data;
1142 cpumask_t oldmask; 1219 cpumask_t oldmask;
1143 int rc; 1220 int rc;
1221 static int print_once;
1144 1222
1145 if (!cpu_online(pol->cpu)) 1223 if (!cpu_online(pol->cpu))
1146 return -ENODEV; 1224 return -ENODEV;
@@ -1163,33 +1241,31 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
1163 * an UP version, and is deprecated by AMD. 1241 * an UP version, and is deprecated by AMD.
1164 */ 1242 */
1165 if (num_online_cpus() != 1) { 1243 if (num_online_cpus() != 1) {
1166#ifndef CONFIG_ACPI_PROCESSOR 1244 /*
1167 printk(KERN_ERR PFX "ACPI Processor support is required " 1245 * Replace this one with print_once as soon as such a
1168 "for SMP systems but is absent. Please load the " 1246 * thing gets introduced
1169 "ACPI Processor module before starting this " 1247 */
1170 "driver.\n"); 1248 if (!print_once) {
1171#else 1249 WARN_ONCE(1, KERN_ERR FW_BUG PFX "Your BIOS "
1172 printk(KERN_ERR FW_BUG PFX "Your BIOS does not provide" 1250 "does not provide ACPI _PSS objects "
1173 " ACPI _PSS objects in a way that Linux " 1251 "in a way that Linux understands. "
1174 "understands. Please report this to the Linux " 1252 "Please report this to the Linux ACPI"
1175 "ACPI maintainers and complain to your BIOS " 1253 " maintainers and complain to your "
1176 "vendor.\n"); 1254 "BIOS vendor.\n");
1177#endif 1255 print_once++;
1178 kfree(data); 1256 }
1179 return -ENODEV; 1257 goto err_out;
1180 } 1258 }
1181 if (pol->cpu != 0) { 1259 if (pol->cpu != 0) {
1182 printk(KERN_ERR FW_BUG PFX "No ACPI _PSS objects for " 1260 printk(KERN_ERR FW_BUG PFX "No ACPI _PSS objects for "
1183 "CPU other than CPU0. Complain to your BIOS " 1261 "CPU other than CPU0. Complain to your BIOS "
1184 "vendor.\n"); 1262 "vendor.\n");
1185 kfree(data); 1263 goto err_out;
1186 return -ENODEV;
1187 } 1264 }
1188 rc = find_psb_table(data); 1265 rc = find_psb_table(data);
1189 if (rc) { 1266 if (rc)
1190 kfree(data); 1267 goto err_out;
1191 return -ENODEV; 1268
1192 }
1193 /* Take a crude guess here. 1269 /* Take a crude guess here.
1194 * That guess was in microseconds, so multiply with 1000 */ 1270 * That guess was in microseconds, so multiply with 1000 */
1195 pol->cpuinfo.transition_latency = ( 1271 pol->cpuinfo.transition_latency = (
@@ -1204,16 +1280,16 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
1204 1280
1205 if (smp_processor_id() != pol->cpu) { 1281 if (smp_processor_id() != pol->cpu) {
1206 printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu); 1282 printk(KERN_ERR PFX "limiting to cpu %u failed\n", pol->cpu);
1207 goto err_out; 1283 goto err_out_unmask;
1208 } 1284 }
1209 1285
1210 if (pending_bit_stuck()) { 1286 if (pending_bit_stuck()) {
1211 printk(KERN_ERR PFX "failing init, change pending bit set\n"); 1287 printk(KERN_ERR PFX "failing init, change pending bit set\n");
1212 goto err_out; 1288 goto err_out_unmask;
1213 } 1289 }
1214 1290
1215 if (query_current_values_with_pending_wait(data)) 1291 if (query_current_values_with_pending_wait(data))
1216 goto err_out; 1292 goto err_out_unmask;
1217 1293
1218 if (cpu_family == CPU_OPTERON) 1294 if (cpu_family == CPU_OPTERON)
1219 fidvid_msr_init(); 1295 fidvid_msr_init();
@@ -1228,7 +1304,8 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
1228 data->available_cores = pol->cpus; 1304 data->available_cores = pol->cpus;
1229 1305
1230 if (cpu_family == CPU_HW_PSTATE) 1306 if (cpu_family == CPU_HW_PSTATE)
1231 pol->cur = find_khz_freq_from_pstate(data->powernow_table, data->currpstate); 1307 pol->cur = find_khz_freq_from_pstate(data->powernow_table,
1308 data->currpstate);
1232 else 1309 else
1233 pol->cur = find_khz_freq_from_fid(data->currfid); 1310 pol->cur = find_khz_freq_from_fid(data->currfid);
1234 dprintk("policy current frequency %d kHz\n", pol->cur); 1311 dprintk("policy current frequency %d kHz\n", pol->cur);
@@ -1245,7 +1322,8 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
1245 cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu); 1322 cpufreq_frequency_table_get_attr(data->powernow_table, pol->cpu);
1246 1323
1247 if (cpu_family == CPU_HW_PSTATE) 1324 if (cpu_family == CPU_HW_PSTATE)
1248 dprintk("cpu_init done, current pstate 0x%x\n", data->currpstate); 1325 dprintk("cpu_init done, current pstate 0x%x\n",
1326 data->currpstate);
1249 else 1327 else
1250 dprintk("cpu_init done, current fid 0x%x, vid 0x%x\n", 1328 dprintk("cpu_init done, current fid 0x%x, vid 0x%x\n",
1251 data->currfid, data->currvid); 1329 data->currfid, data->currvid);
@@ -1254,15 +1332,16 @@ static int __cpuinit powernowk8_cpu_init(struct cpufreq_policy *pol)
1254 1332
1255 return 0; 1333 return 0;
1256 1334
1257err_out: 1335err_out_unmask:
1258 set_cpus_allowed_ptr(current, &oldmask); 1336 set_cpus_allowed_ptr(current, &oldmask);
1259 powernow_k8_cpu_exit_acpi(data); 1337 powernow_k8_cpu_exit_acpi(data);
1260 1338
1339err_out:
1261 kfree(data); 1340 kfree(data);
1262 return -ENODEV; 1341 return -ENODEV;
1263} 1342}
1264 1343
1265static int __devexit powernowk8_cpu_exit (struct cpufreq_policy *pol) 1344static int __devexit powernowk8_cpu_exit(struct cpufreq_policy *pol)
1266{ 1345{
1267 struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu); 1346 struct powernow_k8_data *data = per_cpu(powernow_data, pol->cpu);
1268 1347
@@ -1279,7 +1358,7 @@ static int __devexit powernowk8_cpu_exit (struct cpufreq_policy *pol)
1279 return 0; 1358 return 0;
1280} 1359}
1281 1360
1282static unsigned int powernowk8_get (unsigned int cpu) 1361static unsigned int powernowk8_get(unsigned int cpu)
1283{ 1362{
1284 struct powernow_k8_data *data; 1363 struct powernow_k8_data *data;
1285 cpumask_t oldmask = current->cpus_allowed; 1364 cpumask_t oldmask = current->cpus_allowed;
@@ -1315,7 +1394,7 @@ out:
1315 return khz; 1394 return khz;
1316} 1395}
1317 1396
1318static struct freq_attr* powernow_k8_attr[] = { 1397static struct freq_attr *powernow_k8_attr[] = {
1319 &cpufreq_freq_attr_scaling_available_freqs, 1398 &cpufreq_freq_attr_scaling_available_freqs,
1320 NULL, 1399 NULL,
1321}; 1400};
@@ -1360,7 +1439,8 @@ static void __exit powernowk8_exit(void)
1360 cpufreq_unregister_driver(&cpufreq_amd64_driver); 1439 cpufreq_unregister_driver(&cpufreq_amd64_driver);
1361} 1440}
1362 1441
1363MODULE_AUTHOR("Paul Devriendt <paul.devriendt@amd.com> and Mark Langsdorf <mark.langsdorf@amd.com>"); 1442MODULE_AUTHOR("Paul Devriendt <paul.devriendt@amd.com> and "
1443 "Mark Langsdorf <mark.langsdorf@amd.com>");
1364MODULE_DESCRIPTION("AMD Athlon 64 and Opteron processor frequency driver."); 1444MODULE_DESCRIPTION("AMD Athlon 64 and Opteron processor frequency driver.");
1365MODULE_LICENSE("GPL"); 1445MODULE_LICENSE("GPL");
1366 1446
diff --git a/arch/x86/kernel/cpu/cpufreq/powernow-k8.h b/arch/x86/kernel/cpu/cpufreq/powernow-k8.h
index 8ecc75b6c7c3..6c6698feade1 100644
--- a/arch/x86/kernel/cpu/cpufreq/powernow-k8.h
+++ b/arch/x86/kernel/cpu/cpufreq/powernow-k8.h
@@ -45,11 +45,10 @@ struct powernow_k8_data {
45 * frequency is in kHz */ 45 * frequency is in kHz */
46 struct cpufreq_frequency_table *powernow_table; 46 struct cpufreq_frequency_table *powernow_table;
47 47
48#ifdef CONFIG_X86_POWERNOW_K8_ACPI
49 /* the acpi table needs to be kept. it's only available if ACPI was 48 /* the acpi table needs to be kept. it's only available if ACPI was
50 * used to determine valid frequency/vid/fid states */ 49 * used to determine valid frequency/vid/fid states */
51 struct acpi_processor_performance acpi_data; 50 struct acpi_processor_performance acpi_data;
52#endif 51
53 /* we need to keep track of associated cores, but let cpufreq 52 /* we need to keep track of associated cores, but let cpufreq
54 * handle hotplug events - so just point at cpufreq pol->cpus 53 * handle hotplug events - so just point at cpufreq pol->cpus
55 * structure */ 54 * structure */
@@ -222,10 +221,8 @@ static int core_frequency_transition(struct powernow_k8_data *data, u32 reqfid);
222 221
223static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index); 222static void powernow_k8_acpi_pst_values(struct powernow_k8_data *data, unsigned int index);
224 223
225#ifdef CONFIG_X86_POWERNOW_K8_ACPI
226static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); 224static int fill_powernow_table_pstate(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table);
227static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table); 225static int fill_powernow_table_fidvid(struct powernow_k8_data *data, struct cpufreq_frequency_table *powernow_table);
228#endif
229 226
230#ifdef CONFIG_SMP 227#ifdef CONFIG_SMP
231static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[]) 228static inline void define_siblings(int cpu, cpumask_t cpu_sharedcore_mask[])
diff --git a/arch/x86/kernel/cpu/cpufreq/sc520_freq.c b/arch/x86/kernel/cpu/cpufreq/sc520_freq.c
index 42da9bd677d6..435a996a613a 100644
--- a/arch/x86/kernel/cpu/cpufreq/sc520_freq.c
+++ b/arch/x86/kernel/cpu/cpufreq/sc520_freq.c
@@ -19,17 +19,19 @@
19 19
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/cpufreq.h> 21#include <linux/cpufreq.h>
22#include <linux/timex.h>
23#include <linux/io.h>
22 24
23#include <asm/msr.h> 25#include <asm/msr.h>
24#include <asm/timex.h>
25#include <asm/io.h>
26 26
27#define MMCR_BASE 0xfffef000 /* The default base address */ 27#define MMCR_BASE 0xfffef000 /* The default base address */
28#define OFFS_CPUCTL 0x2 /* CPU Control Register */ 28#define OFFS_CPUCTL 0x2 /* CPU Control Register */
29 29
30static __u8 __iomem *cpuctl; 30static __u8 __iomem *cpuctl;
31 31
32#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "sc520_freq", msg) 32#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
33 "sc520_freq", msg)
34#define PFX "sc520_freq: "
33 35
34static struct cpufreq_frequency_table sc520_freq_table[] = { 36static struct cpufreq_frequency_table sc520_freq_table[] = {
35 {0x01, 100000}, 37 {0x01, 100000},
@@ -43,7 +45,8 @@ static unsigned int sc520_freq_get_cpu_frequency(unsigned int cpu)
43 45
44 switch (clockspeed_reg & 0x03) { 46 switch (clockspeed_reg & 0x03) {
45 default: 47 default:
46 printk(KERN_ERR "sc520_freq: error: cpuctl register has unexpected value %02x\n", clockspeed_reg); 48 printk(KERN_ERR PFX "error: cpuctl register has unexpected "
49 "value %02x\n", clockspeed_reg);
47 case 0x01: 50 case 0x01:
48 return 100000; 51 return 100000;
49 case 0x02: 52 case 0x02:
@@ -51,7 +54,7 @@ static unsigned int sc520_freq_get_cpu_frequency(unsigned int cpu)
51 } 54 }
52} 55}
53 56
54static void sc520_freq_set_cpu_state (unsigned int state) 57static void sc520_freq_set_cpu_state(unsigned int state)
55{ 58{
56 59
57 struct cpufreq_freqs freqs; 60 struct cpufreq_freqs freqs;
@@ -76,18 +79,19 @@ static void sc520_freq_set_cpu_state (unsigned int state)
76 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); 79 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
77}; 80};
78 81
79static int sc520_freq_verify (struct cpufreq_policy *policy) 82static int sc520_freq_verify(struct cpufreq_policy *policy)
80{ 83{
81 return cpufreq_frequency_table_verify(policy, &sc520_freq_table[0]); 84 return cpufreq_frequency_table_verify(policy, &sc520_freq_table[0]);
82} 85}
83 86
84static int sc520_freq_target (struct cpufreq_policy *policy, 87static int sc520_freq_target(struct cpufreq_policy *policy,
85 unsigned int target_freq, 88 unsigned int target_freq,
86 unsigned int relation) 89 unsigned int relation)
87{ 90{
88 unsigned int newstate = 0; 91 unsigned int newstate = 0;
89 92
90 if (cpufreq_frequency_table_target(policy, sc520_freq_table, target_freq, relation, &newstate)) 93 if (cpufreq_frequency_table_target(policy, sc520_freq_table,
94 target_freq, relation, &newstate))
91 return -EINVAL; 95 return -EINVAL;
92 96
93 sc520_freq_set_cpu_state(newstate); 97 sc520_freq_set_cpu_state(newstate);
@@ -116,7 +120,7 @@ static int sc520_freq_cpu_init(struct cpufreq_policy *policy)
116 120
117 result = cpufreq_frequency_table_cpuinfo(policy, sc520_freq_table); 121 result = cpufreq_frequency_table_cpuinfo(policy, sc520_freq_table);
118 if (result) 122 if (result)
119 return (result); 123 return result;
120 124
121 cpufreq_frequency_table_get_attr(sc520_freq_table, policy->cpu); 125 cpufreq_frequency_table_get_attr(sc520_freq_table, policy->cpu);
122 126
@@ -131,7 +135,7 @@ static int sc520_freq_cpu_exit(struct cpufreq_policy *policy)
131} 135}
132 136
133 137
134static struct freq_attr* sc520_freq_attr[] = { 138static struct freq_attr *sc520_freq_attr[] = {
135 &cpufreq_freq_attr_scaling_available_freqs, 139 &cpufreq_freq_attr_scaling_available_freqs,
136 NULL, 140 NULL,
137}; 141};
@@ -155,13 +159,13 @@ static int __init sc520_freq_init(void)
155 int err; 159 int err;
156 160
157 /* Test if we have the right hardware */ 161 /* Test if we have the right hardware */
158 if(c->x86_vendor != X86_VENDOR_AMD || 162 if (c->x86_vendor != X86_VENDOR_AMD ||
159 c->x86 != 4 || c->x86_model != 9) { 163 c->x86 != 4 || c->x86_model != 9) {
160 dprintk("no Elan SC520 processor found!\n"); 164 dprintk("no Elan SC520 processor found!\n");
161 return -ENODEV; 165 return -ENODEV;
162 } 166 }
163 cpuctl = ioremap((unsigned long)(MMCR_BASE + OFFS_CPUCTL), 1); 167 cpuctl = ioremap((unsigned long)(MMCR_BASE + OFFS_CPUCTL), 1);
164 if(!cpuctl) { 168 if (!cpuctl) {
165 printk(KERN_ERR "sc520_freq: error: failed to remap memory\n"); 169 printk(KERN_ERR "sc520_freq: error: failed to remap memory\n");
166 return -ENOMEM; 170 return -ENOMEM;
167 } 171 }
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-ich.c b/arch/x86/kernel/cpu/cpufreq/speedstep-ich.c
index dedc1e98f168..8bbb11adb315 100644
--- a/arch/x86/kernel/cpu/cpufreq/speedstep-ich.c
+++ b/arch/x86/kernel/cpu/cpufreq/speedstep-ich.c
@@ -39,7 +39,7 @@ static struct pci_dev *speedstep_chipset_dev;
39 39
40/* speedstep_processor 40/* speedstep_processor
41 */ 41 */
42static unsigned int speedstep_processor = 0; 42static unsigned int speedstep_processor;
43 43
44static u32 pmbase; 44static u32 pmbase;
45 45
@@ -54,7 +54,8 @@ static struct cpufreq_frequency_table speedstep_freqs[] = {
54}; 54};
55 55
56 56
57#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "speedstep-ich", msg) 57#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
58 "speedstep-ich", msg)
58 59
59 60
60/** 61/**
@@ -62,7 +63,7 @@ static struct cpufreq_frequency_table speedstep_freqs[] = {
62 * 63 *
63 * Returns: -ENODEV if no register could be found 64 * Returns: -ENODEV if no register could be found
64 */ 65 */
65static int speedstep_find_register (void) 66static int speedstep_find_register(void)
66{ 67{
67 if (!speedstep_chipset_dev) 68 if (!speedstep_chipset_dev)
68 return -ENODEV; 69 return -ENODEV;
@@ -90,7 +91,7 @@ static int speedstep_find_register (void)
90 * 91 *
91 * Tries to change the SpeedStep state. 92 * Tries to change the SpeedStep state.
92 */ 93 */
93static void speedstep_set_state (unsigned int state) 94static void speedstep_set_state(unsigned int state)
94{ 95{
95 u8 pm2_blk; 96 u8 pm2_blk;
96 u8 value; 97 u8 value;
@@ -133,11 +134,11 @@ static void speedstep_set_state (unsigned int state)
133 134
134 dprintk("read at pmbase 0x%x + 0x50 returned 0x%x\n", pmbase, value); 135 dprintk("read at pmbase 0x%x + 0x50 returned 0x%x\n", pmbase, value);
135 136
136 if (state == (value & 0x1)) { 137 if (state == (value & 0x1))
137 dprintk("change to %u MHz succeeded\n", (speedstep_get_processor_frequency(speedstep_processor) / 1000)); 138 dprintk("change to %u MHz succeeded\n",
138 } else { 139 speedstep_get_frequency(speedstep_processor) / 1000);
139 printk (KERN_ERR "cpufreq: change failed - I/O error\n"); 140 else
140 } 141 printk(KERN_ERR "cpufreq: change failed - I/O error\n");
141 142
142 return; 143 return;
143} 144}
@@ -149,7 +150,7 @@ static void speedstep_set_state (unsigned int state)
149 * Tries to activate the SpeedStep status and control registers. 150 * Tries to activate the SpeedStep status and control registers.
150 * Returns -EINVAL on an unsupported chipset, and zero on success. 151 * Returns -EINVAL on an unsupported chipset, and zero on success.
151 */ 152 */
152static int speedstep_activate (void) 153static int speedstep_activate(void)
153{ 154{
154 u16 value = 0; 155 u16 value = 0;
155 156
@@ -175,20 +176,18 @@ static int speedstep_activate (void)
175 * functions. Returns the SPEEDSTEP_CHIPSET_-number for the detected 176 * functions. Returns the SPEEDSTEP_CHIPSET_-number for the detected
176 * chipset, or zero on failure. 177 * chipset, or zero on failure.
177 */ 178 */
178static unsigned int speedstep_detect_chipset (void) 179static unsigned int speedstep_detect_chipset(void)
179{ 180{
180 speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, 181 speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
181 PCI_DEVICE_ID_INTEL_82801DB_12, 182 PCI_DEVICE_ID_INTEL_82801DB_12,
182 PCI_ANY_ID, 183 PCI_ANY_ID, PCI_ANY_ID,
183 PCI_ANY_ID,
184 NULL); 184 NULL);
185 if (speedstep_chipset_dev) 185 if (speedstep_chipset_dev)
186 return 4; /* 4-M */ 186 return 4; /* 4-M */
187 187
188 speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, 188 speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
189 PCI_DEVICE_ID_INTEL_82801CA_12, 189 PCI_DEVICE_ID_INTEL_82801CA_12,
190 PCI_ANY_ID, 190 PCI_ANY_ID, PCI_ANY_ID,
191 PCI_ANY_ID,
192 NULL); 191 NULL);
193 if (speedstep_chipset_dev) 192 if (speedstep_chipset_dev)
194 return 3; /* 3-M */ 193 return 3; /* 3-M */
@@ -196,8 +195,7 @@ static unsigned int speedstep_detect_chipset (void)
196 195
197 speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL, 196 speedstep_chipset_dev = pci_get_subsys(PCI_VENDOR_ID_INTEL,
198 PCI_DEVICE_ID_INTEL_82801BA_10, 197 PCI_DEVICE_ID_INTEL_82801BA_10,
199 PCI_ANY_ID, 198 PCI_ANY_ID, PCI_ANY_ID,
200 PCI_ANY_ID,
201 NULL); 199 NULL);
202 if (speedstep_chipset_dev) { 200 if (speedstep_chipset_dev) {
203 /* speedstep.c causes lockups on Dell Inspirons 8000 and 201 /* speedstep.c causes lockups on Dell Inspirons 8000 and
@@ -208,8 +206,7 @@ static unsigned int speedstep_detect_chipset (void)
208 206
209 hostbridge = pci_get_subsys(PCI_VENDOR_ID_INTEL, 207 hostbridge = pci_get_subsys(PCI_VENDOR_ID_INTEL,
210 PCI_DEVICE_ID_INTEL_82815_MC, 208 PCI_DEVICE_ID_INTEL_82815_MC,
211 PCI_ANY_ID, 209 PCI_ANY_ID, PCI_ANY_ID,
212 PCI_ANY_ID,
213 NULL); 210 NULL);
214 211
215 if (!hostbridge) 212 if (!hostbridge)
@@ -236,7 +233,7 @@ static unsigned int _speedstep_get(const struct cpumask *cpus)
236 233
237 cpus_allowed = current->cpus_allowed; 234 cpus_allowed = current->cpus_allowed;
238 set_cpus_allowed_ptr(current, cpus); 235 set_cpus_allowed_ptr(current, cpus);
239 speed = speedstep_get_processor_frequency(speedstep_processor); 236 speed = speedstep_get_frequency(speedstep_processor);
240 set_cpus_allowed_ptr(current, &cpus_allowed); 237 set_cpus_allowed_ptr(current, &cpus_allowed);
241 dprintk("detected %u kHz as current frequency\n", speed); 238 dprintk("detected %u kHz as current frequency\n", speed);
242 return speed; 239 return speed;
@@ -251,11 +248,12 @@ static unsigned int speedstep_get(unsigned int cpu)
251 * speedstep_target - set a new CPUFreq policy 248 * speedstep_target - set a new CPUFreq policy
252 * @policy: new policy 249 * @policy: new policy
253 * @target_freq: the target frequency 250 * @target_freq: the target frequency
254 * @relation: how that frequency relates to achieved frequency (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H) 251 * @relation: how that frequency relates to achieved frequency
252 * (CPUFREQ_RELATION_L or CPUFREQ_RELATION_H)
255 * 253 *
256 * Sets a new CPUFreq policy. 254 * Sets a new CPUFreq policy.
257 */ 255 */
258static int speedstep_target (struct cpufreq_policy *policy, 256static int speedstep_target(struct cpufreq_policy *policy,
259 unsigned int target_freq, 257 unsigned int target_freq,
260 unsigned int relation) 258 unsigned int relation)
261{ 259{
@@ -264,7 +262,8 @@ static int speedstep_target (struct cpufreq_policy *policy,
264 cpumask_t cpus_allowed; 262 cpumask_t cpus_allowed;
265 int i; 263 int i;
266 264
267 if (cpufreq_frequency_table_target(policy, &speedstep_freqs[0], target_freq, relation, &newstate)) 265 if (cpufreq_frequency_table_target(policy, &speedstep_freqs[0],
266 target_freq, relation, &newstate))
268 return -EINVAL; 267 return -EINVAL;
269 268
270 freqs.old = _speedstep_get(policy->cpus); 269 freqs.old = _speedstep_get(policy->cpus);
@@ -308,7 +307,7 @@ static int speedstep_target (struct cpufreq_policy *policy,
308 * Limit must be within speedstep_low_freq and speedstep_high_freq, with 307 * Limit must be within speedstep_low_freq and speedstep_high_freq, with
309 * at least one border included. 308 * at least one border included.
310 */ 309 */
311static int speedstep_verify (struct cpufreq_policy *policy) 310static int speedstep_verify(struct cpufreq_policy *policy)
312{ 311{
313 return cpufreq_frequency_table_verify(policy, &speedstep_freqs[0]); 312 return cpufreq_frequency_table_verify(policy, &speedstep_freqs[0]);
314} 313}
@@ -344,7 +343,8 @@ static int speedstep_cpu_init(struct cpufreq_policy *policy)
344 return -EIO; 343 return -EIO;
345 344
346 dprintk("currently at %s speed setting - %i MHz\n", 345 dprintk("currently at %s speed setting - %i MHz\n",
347 (speed == speedstep_freqs[SPEEDSTEP_LOW].frequency) ? "low" : "high", 346 (speed == speedstep_freqs[SPEEDSTEP_LOW].frequency)
347 ? "low" : "high",
348 (speed / 1000)); 348 (speed / 1000));
349 349
350 /* cpuinfo and default policy values */ 350 /* cpuinfo and default policy values */
@@ -352,9 +352,9 @@ static int speedstep_cpu_init(struct cpufreq_policy *policy)
352 352
353 result = cpufreq_frequency_table_cpuinfo(policy, speedstep_freqs); 353 result = cpufreq_frequency_table_cpuinfo(policy, speedstep_freqs);
354 if (result) 354 if (result)
355 return (result); 355 return result;
356 356
357 cpufreq_frequency_table_get_attr(speedstep_freqs, policy->cpu); 357 cpufreq_frequency_table_get_attr(speedstep_freqs, policy->cpu);
358 358
359 return 0; 359 return 0;
360} 360}
@@ -366,7 +366,7 @@ static int speedstep_cpu_exit(struct cpufreq_policy *policy)
366 return 0; 366 return 0;
367} 367}
368 368
369static struct freq_attr* speedstep_attr[] = { 369static struct freq_attr *speedstep_attr[] = {
370 &cpufreq_freq_attr_scaling_available_freqs, 370 &cpufreq_freq_attr_scaling_available_freqs,
371 NULL, 371 NULL,
372}; 372};
@@ -396,13 +396,15 @@ static int __init speedstep_init(void)
396 /* detect processor */ 396 /* detect processor */
397 speedstep_processor = speedstep_detect_processor(); 397 speedstep_processor = speedstep_detect_processor();
398 if (!speedstep_processor) { 398 if (!speedstep_processor) {
399 dprintk("Intel(R) SpeedStep(TM) capable processor not found\n"); 399 dprintk("Intel(R) SpeedStep(TM) capable processor "
400 "not found\n");
400 return -ENODEV; 401 return -ENODEV;
401 } 402 }
402 403
403 /* detect chipset */ 404 /* detect chipset */
404 if (!speedstep_detect_chipset()) { 405 if (!speedstep_detect_chipset()) {
405 dprintk("Intel(R) SpeedStep(TM) for this chipset not (yet) available.\n"); 406 dprintk("Intel(R) SpeedStep(TM) for this chipset not "
407 "(yet) available.\n");
406 return -ENODEV; 408 return -ENODEV;
407 } 409 }
408 410
@@ -431,9 +433,11 @@ static void __exit speedstep_exit(void)
431} 433}
432 434
433 435
434MODULE_AUTHOR ("Dave Jones <davej@redhat.com>, Dominik Brodowski <linux@brodo.de>"); 436MODULE_AUTHOR("Dave Jones <davej@redhat.com>, "
435MODULE_DESCRIPTION ("Speedstep driver for Intel mobile processors on chipsets with ICH-M southbridges."); 437 "Dominik Brodowski <linux@brodo.de>");
436MODULE_LICENSE ("GPL"); 438MODULE_DESCRIPTION("Speedstep driver for Intel mobile processors on chipsets "
439 "with ICH-M southbridges.");
440MODULE_LICENSE("GPL");
437 441
438module_init(speedstep_init); 442module_init(speedstep_init);
439module_exit(speedstep_exit); 443module_exit(speedstep_exit);
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c
index cdac7d62369b..2e3c6862657b 100644
--- a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c
+++ b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.c
@@ -16,12 +16,16 @@
16#include <linux/slab.h> 16#include <linux/slab.h>
17 17
18#include <asm/msr.h> 18#include <asm/msr.h>
19#include <asm/tsc.h>
19#include "speedstep-lib.h" 20#include "speedstep-lib.h"
20 21
21#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "speedstep-lib", msg) 22#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
23 "speedstep-lib", msg)
24
25#define PFX "speedstep-lib: "
22 26
23#ifdef CONFIG_X86_SPEEDSTEP_RELAXED_CAP_CHECK 27#ifdef CONFIG_X86_SPEEDSTEP_RELAXED_CAP_CHECK
24static int relaxed_check = 0; 28static int relaxed_check;
25#else 29#else
26#define relaxed_check 0 30#define relaxed_check 0
27#endif 31#endif
@@ -30,14 +34,14 @@ static int relaxed_check = 0;
30 * GET PROCESSOR CORE SPEED IN KHZ * 34 * GET PROCESSOR CORE SPEED IN KHZ *
31 *********************************************************************/ 35 *********************************************************************/
32 36
33static unsigned int pentium3_get_frequency (unsigned int processor) 37static unsigned int pentium3_get_frequency(unsigned int processor)
34{ 38{
35 /* See table 14 of p3_ds.pdf and table 22 of 29834003.pdf */ 39 /* See table 14 of p3_ds.pdf and table 22 of 29834003.pdf */
36 struct { 40 struct {
37 unsigned int ratio; /* Frequency Multiplier (x10) */ 41 unsigned int ratio; /* Frequency Multiplier (x10) */
38 u8 bitmap; /* power on configuration bits 42 u8 bitmap; /* power on configuration bits
39 [27, 25:22] (in MSR 0x2a) */ 43 [27, 25:22] (in MSR 0x2a) */
40 } msr_decode_mult [] = { 44 } msr_decode_mult[] = {
41 { 30, 0x01 }, 45 { 30, 0x01 },
42 { 35, 0x05 }, 46 { 35, 0x05 },
43 { 40, 0x02 }, 47 { 40, 0x02 },
@@ -52,7 +56,7 @@ static unsigned int pentium3_get_frequency (unsigned int processor)
52 { 85, 0x26 }, 56 { 85, 0x26 },
53 { 90, 0x20 }, 57 { 90, 0x20 },
54 { 100, 0x2b }, 58 { 100, 0x2b },
55 { 0, 0xff } /* error or unknown value */ 59 { 0, 0xff } /* error or unknown value */
56 }; 60 };
57 61
58 /* PIII(-M) FSB settings: see table b1-b of 24547206.pdf */ 62 /* PIII(-M) FSB settings: see table b1-b of 24547206.pdf */
@@ -60,7 +64,7 @@ static unsigned int pentium3_get_frequency (unsigned int processor)
60 unsigned int value; /* Front Side Bus speed in MHz */ 64 unsigned int value; /* Front Side Bus speed in MHz */
61 u8 bitmap; /* power on configuration bits [18: 19] 65 u8 bitmap; /* power on configuration bits [18: 19]
62 (in MSR 0x2a) */ 66 (in MSR 0x2a) */
63 } msr_decode_fsb [] = { 67 } msr_decode_fsb[] = {
64 { 66, 0x0 }, 68 { 66, 0x0 },
65 { 100, 0x2 }, 69 { 100, 0x2 },
66 { 133, 0x1 }, 70 { 133, 0x1 },
@@ -85,7 +89,7 @@ static unsigned int pentium3_get_frequency (unsigned int processor)
85 } 89 }
86 90
87 /* decode the multiplier */ 91 /* decode the multiplier */
88 if (processor == SPEEDSTEP_PROCESSOR_PIII_C_EARLY) { 92 if (processor == SPEEDSTEP_CPU_PIII_C_EARLY) {
89 dprintk("workaround for early PIIIs\n"); 93 dprintk("workaround for early PIIIs\n");
90 msr_lo &= 0x03c00000; 94 msr_lo &= 0x03c00000;
91 } else 95 } else
@@ -97,9 +101,10 @@ static unsigned int pentium3_get_frequency (unsigned int processor)
97 j++; 101 j++;
98 } 102 }
99 103
100 dprintk("speed is %u\n", (msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100)); 104 dprintk("speed is %u\n",
105 (msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100));
101 106
102 return (msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100); 107 return msr_decode_mult[j].ratio * msr_decode_fsb[i].value * 100;
103} 108}
104 109
105 110
@@ -112,20 +117,23 @@ static unsigned int pentiumM_get_frequency(void)
112 117
113 /* see table B-2 of 24547212.pdf */ 118 /* see table B-2 of 24547212.pdf */
114 if (msr_lo & 0x00040000) { 119 if (msr_lo & 0x00040000) {
115 printk(KERN_DEBUG "speedstep-lib: PM - invalid FSB: 0x%x 0x%x\n", msr_lo, msr_tmp); 120 printk(KERN_DEBUG PFX "PM - invalid FSB: 0x%x 0x%x\n",
121 msr_lo, msr_tmp);
116 return 0; 122 return 0;
117 } 123 }
118 124
119 msr_tmp = (msr_lo >> 22) & 0x1f; 125 msr_tmp = (msr_lo >> 22) & 0x1f;
120 dprintk("bits 22-26 are 0x%x, speed is %u\n", msr_tmp, (msr_tmp * 100 * 1000)); 126 dprintk("bits 22-26 are 0x%x, speed is %u\n",
127 msr_tmp, (msr_tmp * 100 * 1000));
121 128
122 return (msr_tmp * 100 * 1000); 129 return msr_tmp * 100 * 1000;
123} 130}
124 131
125static unsigned int pentium_core_get_frequency(void) 132static unsigned int pentium_core_get_frequency(void)
126{ 133{
127 u32 fsb = 0; 134 u32 fsb = 0;
128 u32 msr_lo, msr_tmp; 135 u32 msr_lo, msr_tmp;
136 int ret;
129 137
130 rdmsr(MSR_FSB_FREQ, msr_lo, msr_tmp); 138 rdmsr(MSR_FSB_FREQ, msr_lo, msr_tmp);
131 /* see table B-2 of 25366920.pdf */ 139 /* see table B-2 of 25366920.pdf */
@@ -153,12 +161,15 @@ static unsigned int pentium_core_get_frequency(void)
153 } 161 }
154 162
155 rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp); 163 rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_tmp);
156 dprintk("PCORE - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n", msr_lo, msr_tmp); 164 dprintk("PCORE - MSR_IA32_EBL_CR_POWERON: 0x%x 0x%x\n",
165 msr_lo, msr_tmp);
157 166
158 msr_tmp = (msr_lo >> 22) & 0x1f; 167 msr_tmp = (msr_lo >> 22) & 0x1f;
159 dprintk("bits 22-26 are 0x%x, speed is %u\n", msr_tmp, (msr_tmp * fsb)); 168 dprintk("bits 22-26 are 0x%x, speed is %u\n",
169 msr_tmp, (msr_tmp * fsb));
160 170
161 return (msr_tmp * fsb); 171 ret = (msr_tmp * fsb);
172 return ret;
162} 173}
163 174
164 175
@@ -167,6 +178,16 @@ static unsigned int pentium4_get_frequency(void)
167 struct cpuinfo_x86 *c = &boot_cpu_data; 178 struct cpuinfo_x86 *c = &boot_cpu_data;
168 u32 msr_lo, msr_hi, mult; 179 u32 msr_lo, msr_hi, mult;
169 unsigned int fsb = 0; 180 unsigned int fsb = 0;
181 unsigned int ret;
182 u8 fsb_code;
183
184 /* Pentium 4 Model 0 and 1 do not have the Core Clock Frequency
185 * to System Bus Frequency Ratio Field in the Processor Frequency
186 * Configuration Register of the MSR. Therefore the current
187 * frequency cannot be calculated and has to be measured.
188 */
189 if (c->x86_model < 2)
190 return cpu_khz;
170 191
171 rdmsr(0x2c, msr_lo, msr_hi); 192 rdmsr(0x2c, msr_lo, msr_hi);
172 193
@@ -177,62 +198,61 @@ static unsigned int pentium4_get_frequency(void)
177 * revision #12 in Table B-1: MSRs in the Pentium 4 and 198 * revision #12 in Table B-1: MSRs in the Pentium 4 and
178 * Intel Xeon Processors, on page B-4 and B-5. 199 * Intel Xeon Processors, on page B-4 and B-5.
179 */ 200 */
180 if (c->x86_model < 2) 201 fsb_code = (msr_lo >> 16) & 0x7;
202 switch (fsb_code) {
203 case 0:
181 fsb = 100 * 1000; 204 fsb = 100 * 1000;
182 else { 205 break;
183 u8 fsb_code = (msr_lo >> 16) & 0x7; 206 case 1:
184 switch (fsb_code) { 207 fsb = 13333 * 10;
185 case 0: 208 break;
186 fsb = 100 * 1000; 209 case 2:
187 break; 210 fsb = 200 * 1000;
188 case 1: 211 break;
189 fsb = 13333 * 10;
190 break;
191 case 2:
192 fsb = 200 * 1000;
193 break;
194 }
195 } 212 }
196 213
197 if (!fsb) 214 if (!fsb)
198 printk(KERN_DEBUG "speedstep-lib: couldn't detect FSB speed. Please send an e-mail to <linux@brodo.de>\n"); 215 printk(KERN_DEBUG PFX "couldn't detect FSB speed. "
216 "Please send an e-mail to <linux@brodo.de>\n");
199 217
200 /* Multiplier. */ 218 /* Multiplier. */
201 mult = msr_lo >> 24; 219 mult = msr_lo >> 24;
202 220
203 dprintk("P4 - FSB %u kHz; Multiplier %u; Speed %u kHz\n", fsb, mult, (fsb * mult)); 221 dprintk("P4 - FSB %u kHz; Multiplier %u; Speed %u kHz\n",
222 fsb, mult, (fsb * mult));
204 223
205 return (fsb * mult); 224 ret = (fsb * mult);
225 return ret;
206} 226}
207 227
208 228
209unsigned int speedstep_get_processor_frequency(unsigned int processor) 229unsigned int speedstep_get_frequency(unsigned int processor)
210{ 230{
211 switch (processor) { 231 switch (processor) {
212 case SPEEDSTEP_PROCESSOR_PCORE: 232 case SPEEDSTEP_CPU_PCORE:
213 return pentium_core_get_frequency(); 233 return pentium_core_get_frequency();
214 case SPEEDSTEP_PROCESSOR_PM: 234 case SPEEDSTEP_CPU_PM:
215 return pentiumM_get_frequency(); 235 return pentiumM_get_frequency();
216 case SPEEDSTEP_PROCESSOR_P4D: 236 case SPEEDSTEP_CPU_P4D:
217 case SPEEDSTEP_PROCESSOR_P4M: 237 case SPEEDSTEP_CPU_P4M:
218 return pentium4_get_frequency(); 238 return pentium4_get_frequency();
219 case SPEEDSTEP_PROCESSOR_PIII_T: 239 case SPEEDSTEP_CPU_PIII_T:
220 case SPEEDSTEP_PROCESSOR_PIII_C: 240 case SPEEDSTEP_CPU_PIII_C:
221 case SPEEDSTEP_PROCESSOR_PIII_C_EARLY: 241 case SPEEDSTEP_CPU_PIII_C_EARLY:
222 return pentium3_get_frequency(processor); 242 return pentium3_get_frequency(processor);
223 default: 243 default:
224 return 0; 244 return 0;
225 }; 245 };
226 return 0; 246 return 0;
227} 247}
228EXPORT_SYMBOL_GPL(speedstep_get_processor_frequency); 248EXPORT_SYMBOL_GPL(speedstep_get_frequency);
229 249
230 250
231/********************************************************************* 251/*********************************************************************
232 * DETECT SPEEDSTEP-CAPABLE PROCESSOR * 252 * DETECT SPEEDSTEP-CAPABLE PROCESSOR *
233 *********************************************************************/ 253 *********************************************************************/
234 254
235unsigned int speedstep_detect_processor (void) 255unsigned int speedstep_detect_processor(void)
236{ 256{
237 struct cpuinfo_x86 *c = &cpu_data(0); 257 struct cpuinfo_x86 *c = &cpu_data(0);
238 u32 ebx, msr_lo, msr_hi; 258 u32 ebx, msr_lo, msr_hi;
@@ -261,7 +281,7 @@ unsigned int speedstep_detect_processor (void)
261 * sample has ebx = 0x0f, production has 0x0e. 281 * sample has ebx = 0x0f, production has 0x0e.
262 */ 282 */
263 if ((ebx == 0x0e) || (ebx == 0x0f)) 283 if ((ebx == 0x0e) || (ebx == 0x0f))
264 return SPEEDSTEP_PROCESSOR_P4M; 284 return SPEEDSTEP_CPU_P4M;
265 break; 285 break;
266 case 7: 286 case 7:
267 /* 287 /*
@@ -272,7 +292,7 @@ unsigned int speedstep_detect_processor (void)
272 * samples are only of B-stepping... 292 * samples are only of B-stepping...
273 */ 293 */
274 if (ebx == 0x0e) 294 if (ebx == 0x0e)
275 return SPEEDSTEP_PROCESSOR_P4M; 295 return SPEEDSTEP_CPU_P4M;
276 break; 296 break;
277 case 9: 297 case 9:
278 /* 298 /*
@@ -288,10 +308,13 @@ unsigned int speedstep_detect_processor (void)
288 * M-P4-Ms may have either ebx=0xe or 0xf [see above] 308 * M-P4-Ms may have either ebx=0xe or 0xf [see above]
289 * M-P4/533 have either ebx=0xe or 0xf. [25317607.pdf] 309 * M-P4/533 have either ebx=0xe or 0xf. [25317607.pdf]
290 * also, M-P4M HTs have ebx=0x8, too 310 * also, M-P4M HTs have ebx=0x8, too
291 * For now, they are distinguished by the model_id string 311 * For now, they are distinguished by the model_id
312 * string
292 */ 313 */
293 if ((ebx == 0x0e) || (strstr(c->x86_model_id,"Mobile Intel(R) Pentium(R) 4") != NULL)) 314 if ((ebx == 0x0e) ||
294 return SPEEDSTEP_PROCESSOR_P4M; 315 (strstr(c->x86_model_id,
316 "Mobile Intel(R) Pentium(R) 4") != NULL))
317 return SPEEDSTEP_CPU_P4M;
295 break; 318 break;
296 default: 319 default:
297 break; 320 break;
@@ -301,7 +324,8 @@ unsigned int speedstep_detect_processor (void)
301 324
302 switch (c->x86_model) { 325 switch (c->x86_model) {
303 case 0x0B: /* Intel PIII [Tualatin] */ 326 case 0x0B: /* Intel PIII [Tualatin] */
304 /* cpuid_ebx(1) is 0x04 for desktop PIII, 0x06 for mobile PIII-M */ 327 /* cpuid_ebx(1) is 0x04 for desktop PIII,
328 * 0x06 for mobile PIII-M */
305 ebx = cpuid_ebx(0x00000001); 329 ebx = cpuid_ebx(0x00000001);
306 dprintk("ebx is %x\n", ebx); 330 dprintk("ebx is %x\n", ebx);
307 331
@@ -313,14 +337,15 @@ unsigned int speedstep_detect_processor (void)
313 /* So far all PIII-M processors support SpeedStep. See 337 /* So far all PIII-M processors support SpeedStep. See
314 * Intel's 24540640.pdf of June 2003 338 * Intel's 24540640.pdf of June 2003
315 */ 339 */
316 return SPEEDSTEP_PROCESSOR_PIII_T; 340 return SPEEDSTEP_CPU_PIII_T;
317 341
318 case 0x08: /* Intel PIII [Coppermine] */ 342 case 0x08: /* Intel PIII [Coppermine] */
319 343
320 /* all mobile PIII Coppermines have FSB 100 MHz 344 /* all mobile PIII Coppermines have FSB 100 MHz
321 * ==> sort out a few desktop PIIIs. */ 345 * ==> sort out a few desktop PIIIs. */
322 rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_hi); 346 rdmsr(MSR_IA32_EBL_CR_POWERON, msr_lo, msr_hi);
323 dprintk("Coppermine: MSR_IA32_EBL_CR_POWERON is 0x%x, 0x%x\n", msr_lo, msr_hi); 347 dprintk("Coppermine: MSR_IA32_EBL_CR_POWERON is 0x%x, 0x%x\n",
348 msr_lo, msr_hi);
324 msr_lo &= 0x00c0000; 349 msr_lo &= 0x00c0000;
325 if (msr_lo != 0x0080000) 350 if (msr_lo != 0x0080000)
326 return 0; 351 return 0;
@@ -332,13 +357,15 @@ unsigned int speedstep_detect_processor (void)
332 * bit 56 or 57 is set 357 * bit 56 or 57 is set
333 */ 358 */
334 rdmsr(MSR_IA32_PLATFORM_ID, msr_lo, msr_hi); 359 rdmsr(MSR_IA32_PLATFORM_ID, msr_lo, msr_hi);
335 dprintk("Coppermine: MSR_IA32_PLATFORM ID is 0x%x, 0x%x\n", msr_lo, msr_hi); 360 dprintk("Coppermine: MSR_IA32_PLATFORM ID is 0x%x, 0x%x\n",
336 if ((msr_hi & (1<<18)) && (relaxed_check ? 1 : (msr_hi & (3<<24)))) { 361 msr_lo, msr_hi);
362 if ((msr_hi & (1<<18)) &&
363 (relaxed_check ? 1 : (msr_hi & (3<<24)))) {
337 if (c->x86_mask == 0x01) { 364 if (c->x86_mask == 0x01) {
338 dprintk("early PIII version\n"); 365 dprintk("early PIII version\n");
339 return SPEEDSTEP_PROCESSOR_PIII_C_EARLY; 366 return SPEEDSTEP_CPU_PIII_C_EARLY;
340 } else 367 } else
341 return SPEEDSTEP_PROCESSOR_PIII_C; 368 return SPEEDSTEP_CPU_PIII_C;
342 } 369 }
343 370
344 default: 371 default:
@@ -369,7 +396,7 @@ unsigned int speedstep_get_freqs(unsigned int processor,
369 dprintk("trying to determine both speeds\n"); 396 dprintk("trying to determine both speeds\n");
370 397
371 /* get current speed */ 398 /* get current speed */
372 prev_speed = speedstep_get_processor_frequency(processor); 399 prev_speed = speedstep_get_frequency(processor);
373 if (!prev_speed) 400 if (!prev_speed)
374 return -EIO; 401 return -EIO;
375 402
@@ -379,7 +406,7 @@ unsigned int speedstep_get_freqs(unsigned int processor,
379 406
380 /* switch to low state */ 407 /* switch to low state */
381 set_state(SPEEDSTEP_LOW); 408 set_state(SPEEDSTEP_LOW);
382 *low_speed = speedstep_get_processor_frequency(processor); 409 *low_speed = speedstep_get_frequency(processor);
383 if (!*low_speed) { 410 if (!*low_speed) {
384 ret = -EIO; 411 ret = -EIO;
385 goto out; 412 goto out;
@@ -398,7 +425,7 @@ unsigned int speedstep_get_freqs(unsigned int processor,
398 if (transition_latency) 425 if (transition_latency)
399 do_gettimeofday(&tv2); 426 do_gettimeofday(&tv2);
400 427
401 *high_speed = speedstep_get_processor_frequency(processor); 428 *high_speed = speedstep_get_frequency(processor);
402 if (!*high_speed) { 429 if (!*high_speed) {
403 ret = -EIO; 430 ret = -EIO;
404 goto out; 431 goto out;
@@ -426,9 +453,12 @@ unsigned int speedstep_get_freqs(unsigned int processor,
426 /* check if the latency measurement is too high or too low 453 /* check if the latency measurement is too high or too low
427 * and set it to a safe value (500uSec) in that case 454 * and set it to a safe value (500uSec) in that case
428 */ 455 */
429 if (*transition_latency > 10000000 || *transition_latency < 50000) { 456 if (*transition_latency > 10000000 ||
430 printk (KERN_WARNING "speedstep: frequency transition measured seems out of " 457 *transition_latency < 50000) {
431 "range (%u nSec), falling back to a safe one of %u nSec.\n", 458 printk(KERN_WARNING PFX "frequency transition "
459 "measured seems out of range (%u "
460 "nSec), falling back to a safe one of"
461 "%u nSec.\n",
432 *transition_latency, 500000); 462 *transition_latency, 500000);
433 *transition_latency = 500000; 463 *transition_latency = 500000;
434 } 464 }
@@ -436,15 +466,16 @@ unsigned int speedstep_get_freqs(unsigned int processor,
436 466
437out: 467out:
438 local_irq_restore(flags); 468 local_irq_restore(flags);
439 return (ret); 469 return ret;
440} 470}
441EXPORT_SYMBOL_GPL(speedstep_get_freqs); 471EXPORT_SYMBOL_GPL(speedstep_get_freqs);
442 472
443#ifdef CONFIG_X86_SPEEDSTEP_RELAXED_CAP_CHECK 473#ifdef CONFIG_X86_SPEEDSTEP_RELAXED_CAP_CHECK
444module_param(relaxed_check, int, 0444); 474module_param(relaxed_check, int, 0444);
445MODULE_PARM_DESC(relaxed_check, "Don't do all checks for speedstep capability."); 475MODULE_PARM_DESC(relaxed_check,
476 "Don't do all checks for speedstep capability.");
446#endif 477#endif
447 478
448MODULE_AUTHOR ("Dominik Brodowski <linux@brodo.de>"); 479MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
449MODULE_DESCRIPTION ("Library for Intel SpeedStep 1 or 2 cpufreq drivers."); 480MODULE_DESCRIPTION("Library for Intel SpeedStep 1 or 2 cpufreq drivers.");
450MODULE_LICENSE ("GPL"); 481MODULE_LICENSE("GPL");
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.h b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.h
index b11bcc608cac..2b6c04e5a304 100644
--- a/arch/x86/kernel/cpu/cpufreq/speedstep-lib.h
+++ b/arch/x86/kernel/cpu/cpufreq/speedstep-lib.h
@@ -12,17 +12,17 @@
12 12
13/* processors */ 13/* processors */
14 14
15#define SPEEDSTEP_PROCESSOR_PIII_C_EARLY 0x00000001 /* Coppermine core */ 15#define SPEEDSTEP_CPU_PIII_C_EARLY 0x00000001 /* Coppermine core */
16#define SPEEDSTEP_PROCESSOR_PIII_C 0x00000002 /* Coppermine core */ 16#define SPEEDSTEP_CPU_PIII_C 0x00000002 /* Coppermine core */
17#define SPEEDSTEP_PROCESSOR_PIII_T 0x00000003 /* Tualatin core */ 17#define SPEEDSTEP_CPU_PIII_T 0x00000003 /* Tualatin core */
18#define SPEEDSTEP_PROCESSOR_P4M 0x00000004 /* P4-M */ 18#define SPEEDSTEP_CPU_P4M 0x00000004 /* P4-M */
19 19
20/* the following processors are not speedstep-capable and are not auto-detected 20/* the following processors are not speedstep-capable and are not auto-detected
21 * in speedstep_detect_processor(). However, their speed can be detected using 21 * in speedstep_detect_processor(). However, their speed can be detected using
22 * the speedstep_get_processor_frequency() call. */ 22 * the speedstep_get_frequency() call. */
23#define SPEEDSTEP_PROCESSOR_PM 0xFFFFFF03 /* Pentium M */ 23#define SPEEDSTEP_CPU_PM 0xFFFFFF03 /* Pentium M */
24#define SPEEDSTEP_PROCESSOR_P4D 0xFFFFFF04 /* desktop P4 */ 24#define SPEEDSTEP_CPU_P4D 0xFFFFFF04 /* desktop P4 */
25#define SPEEDSTEP_PROCESSOR_PCORE 0xFFFFFF05 /* Core */ 25#define SPEEDSTEP_CPU_PCORE 0xFFFFFF05 /* Core */
26 26
27/* speedstep states -- only two of them */ 27/* speedstep states -- only two of them */
28 28
@@ -34,7 +34,7 @@
34extern unsigned int speedstep_detect_processor (void); 34extern unsigned int speedstep_detect_processor (void);
35 35
36/* detect the current speed (in khz) of the processor */ 36/* detect the current speed (in khz) of the processor */
37extern unsigned int speedstep_get_processor_frequency(unsigned int processor); 37extern unsigned int speedstep_get_frequency(unsigned int processor);
38 38
39 39
40/* detect the low and high speeds of the processor. The callback 40/* detect the low and high speeds of the processor. The callback
diff --git a/arch/x86/kernel/cpu/cpufreq/speedstep-smi.c b/arch/x86/kernel/cpu/cpufreq/speedstep-smi.c
index 8a85c93bd62a..befea088e4f5 100644
--- a/arch/x86/kernel/cpu/cpufreq/speedstep-smi.c
+++ b/arch/x86/kernel/cpu/cpufreq/speedstep-smi.c
@@ -19,8 +19,8 @@
19#include <linux/cpufreq.h> 19#include <linux/cpufreq.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/io.h>
22#include <asm/ist.h> 23#include <asm/ist.h>
23#include <asm/io.h>
24 24
25#include "speedstep-lib.h" 25#include "speedstep-lib.h"
26 26
@@ -30,12 +30,12 @@
30 * If user gives it, these are used. 30 * If user gives it, these are used.
31 * 31 *
32 */ 32 */
33static int smi_port = 0; 33static int smi_port;
34static int smi_cmd = 0; 34static int smi_cmd;
35static unsigned int smi_sig = 0; 35static unsigned int smi_sig;
36 36
37/* info about the processor */ 37/* info about the processor */
38static unsigned int speedstep_processor = 0; 38static unsigned int speedstep_processor;
39 39
40/* 40/*
41 * There are only two frequency states for each processor. Values 41 * There are only two frequency states for each processor. Values
@@ -56,12 +56,13 @@ static struct cpufreq_frequency_table speedstep_freqs[] = {
56 * of DMA activity going on? */ 56 * of DMA activity going on? */
57#define SMI_TRIES 5 57#define SMI_TRIES 5
58 58
59#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "speedstep-smi", msg) 59#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, \
60 "speedstep-smi", msg)
60 61
61/** 62/**
62 * speedstep_smi_ownership 63 * speedstep_smi_ownership
63 */ 64 */
64static int speedstep_smi_ownership (void) 65static int speedstep_smi_ownership(void)
65{ 66{
66 u32 command, result, magic, dummy; 67 u32 command, result, magic, dummy;
67 u32 function = GET_SPEEDSTEP_OWNER; 68 u32 function = GET_SPEEDSTEP_OWNER;
@@ -70,16 +71,18 @@ static int speedstep_smi_ownership (void)
70 command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); 71 command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff);
71 magic = virt_to_phys(magic_data); 72 magic = virt_to_phys(magic_data);
72 73
73 dprintk("trying to obtain ownership with command %x at port %x\n", command, smi_port); 74 dprintk("trying to obtain ownership with command %x at port %x\n",
75 command, smi_port);
74 76
75 __asm__ __volatile__( 77 __asm__ __volatile__(
76 "push %%ebp\n" 78 "push %%ebp\n"
77 "out %%al, (%%dx)\n" 79 "out %%al, (%%dx)\n"
78 "pop %%ebp\n" 80 "pop %%ebp\n"
79 : "=D" (result), "=a" (dummy), "=b" (dummy), "=c" (dummy), "=d" (dummy), 81 : "=D" (result),
80 "=S" (dummy) 82 "=a" (dummy), "=b" (dummy), "=c" (dummy), "=d" (dummy),
83 "=S" (dummy)
81 : "a" (command), "b" (function), "c" (0), "d" (smi_port), 84 : "a" (command), "b" (function), "c" (0), "d" (smi_port),
82 "D" (0), "S" (magic) 85 "D" (0), "S" (magic)
83 : "memory" 86 : "memory"
84 ); 87 );
85 88
@@ -97,10 +100,10 @@ static int speedstep_smi_ownership (void)
97 * even hangs [cf. bugme.osdl.org # 1422] on earlier systems. Empirical testing 100 * even hangs [cf. bugme.osdl.org # 1422] on earlier systems. Empirical testing
98 * shows that the latter occurs if !(ist_info.event & 0xFFFF). 101 * shows that the latter occurs if !(ist_info.event & 0xFFFF).
99 */ 102 */
100static int speedstep_smi_get_freqs (unsigned int *low, unsigned int *high) 103static int speedstep_smi_get_freqs(unsigned int *low, unsigned int *high)
101{ 104{
102 u32 command, result = 0, edi, high_mhz, low_mhz, dummy; 105 u32 command, result = 0, edi, high_mhz, low_mhz, dummy;
103 u32 state=0; 106 u32 state = 0;
104 u32 function = GET_SPEEDSTEP_FREQS; 107 u32 function = GET_SPEEDSTEP_FREQS;
105 108
106 if (!(ist_info.event & 0xFFFF)) { 109 if (!(ist_info.event & 0xFFFF)) {
@@ -110,17 +113,25 @@ static int speedstep_smi_get_freqs (unsigned int *low, unsigned int *high)
110 113
111 command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); 114 command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff);
112 115
113 dprintk("trying to determine frequencies with command %x at port %x\n", command, smi_port); 116 dprintk("trying to determine frequencies with command %x at port %x\n",
117 command, smi_port);
114 118
115 __asm__ __volatile__( 119 __asm__ __volatile__(
116 "push %%ebp\n" 120 "push %%ebp\n"
117 "out %%al, (%%dx)\n" 121 "out %%al, (%%dx)\n"
118 "pop %%ebp" 122 "pop %%ebp"
119 : "=a" (result), "=b" (high_mhz), "=c" (low_mhz), "=d" (state), "=D" (edi), "=S" (dummy) 123 : "=a" (result),
120 : "a" (command), "b" (function), "c" (state), "d" (smi_port), "S" (0), "D" (0) 124 "=b" (high_mhz),
125 "=c" (low_mhz),
126 "=d" (state), "=D" (edi), "=S" (dummy)
127 : "a" (command),
128 "b" (function),
129 "c" (state),
130 "d" (smi_port), "S" (0), "D" (0)
121 ); 131 );
122 132
123 dprintk("result %x, low_freq %u, high_freq %u\n", result, low_mhz, high_mhz); 133 dprintk("result %x, low_freq %u, high_freq %u\n",
134 result, low_mhz, high_mhz);
124 135
125 /* abort if results are obviously incorrect... */ 136 /* abort if results are obviously incorrect... */
126 if ((high_mhz + low_mhz) < 600) 137 if ((high_mhz + low_mhz) < 600)
@@ -137,26 +148,30 @@ static int speedstep_smi_get_freqs (unsigned int *low, unsigned int *high)
137 * @state: processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH) 148 * @state: processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH)
138 * 149 *
139 */ 150 */
140static int speedstep_get_state (void) 151static int speedstep_get_state(void)
141{ 152{
142 u32 function=GET_SPEEDSTEP_STATE; 153 u32 function = GET_SPEEDSTEP_STATE;
143 u32 result, state, edi, command, dummy; 154 u32 result, state, edi, command, dummy;
144 155
145 command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); 156 command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff);
146 157
147 dprintk("trying to determine current setting with command %x at port %x\n", command, smi_port); 158 dprintk("trying to determine current setting with command %x "
159 "at port %x\n", command, smi_port);
148 160
149 __asm__ __volatile__( 161 __asm__ __volatile__(
150 "push %%ebp\n" 162 "push %%ebp\n"
151 "out %%al, (%%dx)\n" 163 "out %%al, (%%dx)\n"
152 "pop %%ebp\n" 164 "pop %%ebp\n"
153 : "=a" (result), "=b" (state), "=D" (edi), "=c" (dummy), "=d" (dummy), "=S" (dummy) 165 : "=a" (result),
154 : "a" (command), "b" (function), "c" (0), "d" (smi_port), "S" (0), "D" (0) 166 "=b" (state), "=D" (edi),
167 "=c" (dummy), "=d" (dummy), "=S" (dummy)
168 : "a" (command), "b" (function), "c" (0),
169 "d" (smi_port), "S" (0), "D" (0)
155 ); 170 );
156 171
157 dprintk("state is %x, result is %x\n", state, result); 172 dprintk("state is %x, result is %x\n", state, result);
158 173
159 return (state & 1); 174 return state & 1;
160} 175}
161 176
162 177
@@ -165,11 +180,11 @@ static int speedstep_get_state (void)
165 * @state: new processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH) 180 * @state: new processor frequency state (SPEEDSTEP_LOW or SPEEDSTEP_HIGH)
166 * 181 *
167 */ 182 */
168static void speedstep_set_state (unsigned int state) 183static void speedstep_set_state(unsigned int state)
169{ 184{
170 unsigned int result = 0, command, new_state, dummy; 185 unsigned int result = 0, command, new_state, dummy;
171 unsigned long flags; 186 unsigned long flags;
172 unsigned int function=SET_SPEEDSTEP_STATE; 187 unsigned int function = SET_SPEEDSTEP_STATE;
173 unsigned int retry = 0; 188 unsigned int retry = 0;
174 189
175 if (state > 0x1) 190 if (state > 0x1)
@@ -180,11 +195,14 @@ static void speedstep_set_state (unsigned int state)
180 195
181 command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff); 196 command = (smi_sig & 0xffffff00) | (smi_cmd & 0xff);
182 197
183 dprintk("trying to set frequency to state %u with command %x at port %x\n", state, command, smi_port); 198 dprintk("trying to set frequency to state %u "
199 "with command %x at port %x\n",
200 state, command, smi_port);
184 201
185 do { 202 do {
186 if (retry) { 203 if (retry) {
187 dprintk("retry %u, previous result %u, waiting...\n", retry, result); 204 dprintk("retry %u, previous result %u, waiting...\n",
205 retry, result);
188 mdelay(retry * 50); 206 mdelay(retry * 50);
189 } 207 }
190 retry++; 208 retry++;
@@ -192,20 +210,26 @@ static void speedstep_set_state (unsigned int state)
192 "push %%ebp\n" 210 "push %%ebp\n"
193 "out %%al, (%%dx)\n" 211 "out %%al, (%%dx)\n"
194 "pop %%ebp" 212 "pop %%ebp"
195 : "=b" (new_state), "=D" (result), "=c" (dummy), "=a" (dummy), 213 : "=b" (new_state), "=D" (result),
196 "=d" (dummy), "=S" (dummy) 214 "=c" (dummy), "=a" (dummy),
197 : "a" (command), "b" (function), "c" (state), "d" (smi_port), "S" (0), "D" (0) 215 "=d" (dummy), "=S" (dummy)
216 : "a" (command), "b" (function), "c" (state),
217 "d" (smi_port), "S" (0), "D" (0)
198 ); 218 );
199 } while ((new_state != state) && (retry <= SMI_TRIES)); 219 } while ((new_state != state) && (retry <= SMI_TRIES));
200 220
201 /* enable IRQs */ 221 /* enable IRQs */
202 local_irq_restore(flags); 222 local_irq_restore(flags);
203 223
204 if (new_state == state) { 224 if (new_state == state)
205 dprintk("change to %u MHz succeeded after %u tries with result %u\n", (speedstep_freqs[new_state].frequency / 1000), retry, result); 225 dprintk("change to %u MHz succeeded after %u tries "
206 } else { 226 "with result %u\n",
207 printk(KERN_ERR "cpufreq: change to state %u failed with new_state %u and result %u\n", state, new_state, result); 227 (speedstep_freqs[new_state].frequency / 1000),
208 } 228 retry, result);
229 else
230 printk(KERN_ERR "cpufreq: change to state %u "
231 "failed with new_state %u and result %u\n",
232 state, new_state, result);
209 233
210 return; 234 return;
211} 235}
@@ -219,13 +243,14 @@ static void speedstep_set_state (unsigned int state)
219 * 243 *
220 * Sets a new CPUFreq policy/freq. 244 * Sets a new CPUFreq policy/freq.
221 */ 245 */
222static int speedstep_target (struct cpufreq_policy *policy, 246static int speedstep_target(struct cpufreq_policy *policy,
223 unsigned int target_freq, unsigned int relation) 247 unsigned int target_freq, unsigned int relation)
224{ 248{
225 unsigned int newstate = 0; 249 unsigned int newstate = 0;
226 struct cpufreq_freqs freqs; 250 struct cpufreq_freqs freqs;
227 251
228 if (cpufreq_frequency_table_target(policy, &speedstep_freqs[0], target_freq, relation, &newstate)) 252 if (cpufreq_frequency_table_target(policy, &speedstep_freqs[0],
253 target_freq, relation, &newstate))
229 return -EINVAL; 254 return -EINVAL;
230 255
231 freqs.old = speedstep_freqs[speedstep_get_state()].frequency; 256 freqs.old = speedstep_freqs[speedstep_get_state()].frequency;
@@ -250,7 +275,7 @@ static int speedstep_target (struct cpufreq_policy *policy,
250 * Limit must be within speedstep_low_freq and speedstep_high_freq, with 275 * Limit must be within speedstep_low_freq and speedstep_high_freq, with
251 * at least one border included. 276 * at least one border included.
252 */ 277 */
253static int speedstep_verify (struct cpufreq_policy *policy) 278static int speedstep_verify(struct cpufreq_policy *policy)
254{ 279{
255 return cpufreq_frequency_table_verify(policy, &speedstep_freqs[0]); 280 return cpufreq_frequency_table_verify(policy, &speedstep_freqs[0]);
256} 281}
@@ -259,7 +284,8 @@ static int speedstep_verify (struct cpufreq_policy *policy)
259static int speedstep_cpu_init(struct cpufreq_policy *policy) 284static int speedstep_cpu_init(struct cpufreq_policy *policy)
260{ 285{
261 int result; 286 int result;
262 unsigned int speed,state; 287 unsigned int speed, state;
288 unsigned int *low, *high;
263 289
264 /* capability check */ 290 /* capability check */
265 if (policy->cpu != 0) 291 if (policy->cpu != 0)
@@ -272,19 +298,23 @@ static int speedstep_cpu_init(struct cpufreq_policy *policy)
272 } 298 }
273 299
274 /* detect low and high frequency */ 300 /* detect low and high frequency */
275 result = speedstep_smi_get_freqs(&speedstep_freqs[SPEEDSTEP_LOW].frequency, 301 low = &speedstep_freqs[SPEEDSTEP_LOW].frequency;
276 &speedstep_freqs[SPEEDSTEP_HIGH].frequency); 302 high = &speedstep_freqs[SPEEDSTEP_HIGH].frequency;
303
304 result = speedstep_smi_get_freqs(low, high);
277 if (result) { 305 if (result) {
278 /* fall back to speedstep_lib.c dection mechanism: try both states out */ 306 /* fall back to speedstep_lib.c dection mechanism:
279 dprintk("could not detect low and high frequencies by SMI call.\n"); 307 * try both states out */
308 dprintk("could not detect low and high frequencies "
309 "by SMI call.\n");
280 result = speedstep_get_freqs(speedstep_processor, 310 result = speedstep_get_freqs(speedstep_processor,
281 &speedstep_freqs[SPEEDSTEP_LOW].frequency, 311 low, high,
282 &speedstep_freqs[SPEEDSTEP_HIGH].frequency,
283 NULL, 312 NULL,
284 &speedstep_set_state); 313 &speedstep_set_state);
285 314
286 if (result) { 315 if (result) {
287 dprintk("could not detect two different speeds -- aborting.\n"); 316 dprintk("could not detect two different speeds"
317 " -- aborting.\n");
288 return result; 318 return result;
289 } else 319 } else
290 dprintk("workaround worked.\n"); 320 dprintk("workaround worked.\n");
@@ -295,7 +325,8 @@ static int speedstep_cpu_init(struct cpufreq_policy *policy)
295 speed = speedstep_freqs[state].frequency; 325 speed = speedstep_freqs[state].frequency;
296 326
297 dprintk("currently at %s speed setting - %i MHz\n", 327 dprintk("currently at %s speed setting - %i MHz\n",
298 (speed == speedstep_freqs[SPEEDSTEP_LOW].frequency) ? "low" : "high", 328 (speed == speedstep_freqs[SPEEDSTEP_LOW].frequency)
329 ? "low" : "high",
299 (speed / 1000)); 330 (speed / 1000));
300 331
301 /* cpuinfo and default policy values */ 332 /* cpuinfo and default policy values */
@@ -304,7 +335,7 @@ static int speedstep_cpu_init(struct cpufreq_policy *policy)
304 335
305 result = cpufreq_frequency_table_cpuinfo(policy, speedstep_freqs); 336 result = cpufreq_frequency_table_cpuinfo(policy, speedstep_freqs);
306 if (result) 337 if (result)
307 return (result); 338 return result;
308 339
309 cpufreq_frequency_table_get_attr(speedstep_freqs, policy->cpu); 340 cpufreq_frequency_table_get_attr(speedstep_freqs, policy->cpu);
310 341
@@ -321,7 +352,7 @@ static unsigned int speedstep_get(unsigned int cpu)
321{ 352{
322 if (cpu) 353 if (cpu)
323 return -ENODEV; 354 return -ENODEV;
324 return speedstep_get_processor_frequency(speedstep_processor); 355 return speedstep_get_frequency(speedstep_processor);
325} 356}
326 357
327 358
@@ -335,7 +366,7 @@ static int speedstep_resume(struct cpufreq_policy *policy)
335 return result; 366 return result;
336} 367}
337 368
338static struct freq_attr* speedstep_attr[] = { 369static struct freq_attr *speedstep_attr[] = {
339 &cpufreq_freq_attr_scaling_available_freqs, 370 &cpufreq_freq_attr_scaling_available_freqs,
340 NULL, 371 NULL,
341}; 372};
@@ -364,21 +395,23 @@ static int __init speedstep_init(void)
364 speedstep_processor = speedstep_detect_processor(); 395 speedstep_processor = speedstep_detect_processor();
365 396
366 switch (speedstep_processor) { 397 switch (speedstep_processor) {
367 case SPEEDSTEP_PROCESSOR_PIII_T: 398 case SPEEDSTEP_CPU_PIII_T:
368 case SPEEDSTEP_PROCESSOR_PIII_C: 399 case SPEEDSTEP_CPU_PIII_C:
369 case SPEEDSTEP_PROCESSOR_PIII_C_EARLY: 400 case SPEEDSTEP_CPU_PIII_C_EARLY:
370 break; 401 break;
371 default: 402 default:
372 speedstep_processor = 0; 403 speedstep_processor = 0;
373 } 404 }
374 405
375 if (!speedstep_processor) { 406 if (!speedstep_processor) {
376 dprintk ("No supported Intel CPU detected.\n"); 407 dprintk("No supported Intel CPU detected.\n");
377 return -ENODEV; 408 return -ENODEV;
378 } 409 }
379 410
380 dprintk("signature:0x%.8lx, command:0x%.8lx, event:0x%.8lx, perf_level:0x%.8lx.\n", 411 dprintk("signature:0x%.8lx, command:0x%.8lx, "
381 ist_info.signature, ist_info.command, ist_info.event, ist_info.perf_level); 412 "event:0x%.8lx, perf_level:0x%.8lx.\n",
413 ist_info.signature, ist_info.command,
414 ist_info.event, ist_info.perf_level);
382 415
383 /* Error if no IST-SMI BIOS or no PARM 416 /* Error if no IST-SMI BIOS or no PARM
384 sig= 'ISGE' aka 'Intel Speedstep Gate E' */ 417 sig= 'ISGE' aka 'Intel Speedstep Gate E' */
@@ -416,17 +449,20 @@ static void __exit speedstep_exit(void)
416 cpufreq_unregister_driver(&speedstep_driver); 449 cpufreq_unregister_driver(&speedstep_driver);
417} 450}
418 451
419module_param(smi_port, int, 0444); 452module_param(smi_port, int, 0444);
420module_param(smi_cmd, int, 0444); 453module_param(smi_cmd, int, 0444);
421module_param(smi_sig, uint, 0444); 454module_param(smi_sig, uint, 0444);
422 455
423MODULE_PARM_DESC(smi_port, "Override the BIOS-given IST port with this value -- Intel's default setting is 0xb2"); 456MODULE_PARM_DESC(smi_port, "Override the BIOS-given IST port with this value "
424MODULE_PARM_DESC(smi_cmd, "Override the BIOS-given IST command with this value -- Intel's default setting is 0x82"); 457 "-- Intel's default setting is 0xb2");
425MODULE_PARM_DESC(smi_sig, "Set to 1 to fake the IST signature when using the SMI interface."); 458MODULE_PARM_DESC(smi_cmd, "Override the BIOS-given IST command with this value "
459 "-- Intel's default setting is 0x82");
460MODULE_PARM_DESC(smi_sig, "Set to 1 to fake the IST signature when using the "
461 "SMI interface.");
426 462
427MODULE_AUTHOR ("Hiroshi Miura"); 463MODULE_AUTHOR("Hiroshi Miura");
428MODULE_DESCRIPTION ("Speedstep driver for IST applet SMI interface."); 464MODULE_DESCRIPTION("Speedstep driver for IST applet SMI interface.");
429MODULE_LICENSE ("GPL"); 465MODULE_LICENSE("GPL");
430 466
431module_init(speedstep_init); 467module_init(speedstep_init);
432module_exit(speedstep_exit); 468module_exit(speedstep_exit);
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index d5cebb52d45b..b8e7aaf7ef75 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -543,8 +543,6 @@ unsigned long native_calibrate_tsc(void)
543 return tsc_pit_min; 543 return tsc_pit_min;
544} 544}
545 545
546#ifdef CONFIG_X86_32
547/* Only called from the Powernow K7 cpu freq driver */
548int recalibrate_cpu_khz(void) 546int recalibrate_cpu_khz(void)
549{ 547{
550#ifndef CONFIG_SMP 548#ifndef CONFIG_SMP
@@ -566,7 +564,6 @@ int recalibrate_cpu_khz(void)
566 564
567EXPORT_SYMBOL(recalibrate_cpu_khz); 565EXPORT_SYMBOL(recalibrate_cpu_khz);
568 566
569#endif /* CONFIG_X86_32 */
570 567
571/* Accelerators for sched_clock() 568/* Accelerators for sched_clock()
572 * convert from cycles(64bits) => nanoseconds (64bits) 569 * convert from cycles(64bits) => nanoseconds (64bits)
diff --git a/crypto/Kconfig b/crypto/Kconfig
index 8dde4fcf99c9..74d0e622a515 100644
--- a/crypto/Kconfig
+++ b/crypto/Kconfig
@@ -56,6 +56,7 @@ config CRYPTO_BLKCIPHER2
56 tristate 56 tristate
57 select CRYPTO_ALGAPI2 57 select CRYPTO_ALGAPI2
58 select CRYPTO_RNG2 58 select CRYPTO_RNG2
59 select CRYPTO_WORKQUEUE
59 60
60config CRYPTO_HASH 61config CRYPTO_HASH
61 tristate 62 tristate
@@ -75,6 +76,10 @@ config CRYPTO_RNG2
75 tristate 76 tristate
76 select CRYPTO_ALGAPI2 77 select CRYPTO_ALGAPI2
77 78
79config CRYPTO_PCOMP
80 tristate
81 select CRYPTO_ALGAPI2
82
78config CRYPTO_MANAGER 83config CRYPTO_MANAGER
79 tristate "Cryptographic algorithm manager" 84 tristate "Cryptographic algorithm manager"
80 select CRYPTO_MANAGER2 85 select CRYPTO_MANAGER2
@@ -87,6 +92,7 @@ config CRYPTO_MANAGER2
87 select CRYPTO_AEAD2 92 select CRYPTO_AEAD2
88 select CRYPTO_HASH2 93 select CRYPTO_HASH2
89 select CRYPTO_BLKCIPHER2 94 select CRYPTO_BLKCIPHER2
95 select CRYPTO_PCOMP
90 96
91config CRYPTO_GF128MUL 97config CRYPTO_GF128MUL
92 tristate "GF(2^128) multiplication functions (EXPERIMENTAL)" 98 tristate "GF(2^128) multiplication functions (EXPERIMENTAL)"
@@ -106,11 +112,15 @@ config CRYPTO_NULL
106 help 112 help
107 These are 'Null' algorithms, used by IPsec, which do nothing. 113 These are 'Null' algorithms, used by IPsec, which do nothing.
108 114
115config CRYPTO_WORKQUEUE
116 tristate
117
109config CRYPTO_CRYPTD 118config CRYPTO_CRYPTD
110 tristate "Software async crypto daemon" 119 tristate "Software async crypto daemon"
111 select CRYPTO_BLKCIPHER 120 select CRYPTO_BLKCIPHER
112 select CRYPTO_HASH 121 select CRYPTO_HASH
113 select CRYPTO_MANAGER 122 select CRYPTO_MANAGER
123 select CRYPTO_WORKQUEUE
114 help 124 help
115 This is a generic software asynchronous crypto daemon that 125 This is a generic software asynchronous crypto daemon that
116 converts an arbitrary synchronous software crypto algorithm 126 converts an arbitrary synchronous software crypto algorithm
@@ -470,6 +480,31 @@ config CRYPTO_AES_X86_64
470 480
471 See <http://csrc.nist.gov/encryption/aes/> for more information. 481 See <http://csrc.nist.gov/encryption/aes/> for more information.
472 482
483config CRYPTO_AES_NI_INTEL
484 tristate "AES cipher algorithms (AES-NI)"
485 depends on (X86 || UML_X86) && 64BIT
486 select CRYPTO_AES_X86_64
487 select CRYPTO_CRYPTD
488 select CRYPTO_ALGAPI
489 help
490 Use Intel AES-NI instructions for AES algorithm.
491
492 AES cipher algorithms (FIPS-197). AES uses the Rijndael
493 algorithm.
494
495 Rijndael appears to be consistently a very good performer in
496 both hardware and software across a wide range of computing
497 environments regardless of its use in feedback or non-feedback
498 modes. Its key setup time is excellent, and its key agility is
499 good. Rijndael's very low memory requirements make it very well
500 suited for restricted-space environments, in which it also
501 demonstrates excellent performance. Rijndael's operations are
502 among the easiest to defend against power and timing attacks.
503
504 The AES specifies three key sizes: 128, 192 and 256 bits
505
506 See <http://csrc.nist.gov/encryption/aes/> for more information.
507
473config CRYPTO_ANUBIS 508config CRYPTO_ANUBIS
474 tristate "Anubis cipher algorithm" 509 tristate "Anubis cipher algorithm"
475 select CRYPTO_ALGAPI 510 select CRYPTO_ALGAPI
@@ -714,6 +749,15 @@ config CRYPTO_DEFLATE
714 749
715 You will most probably want this if using IPSec. 750 You will most probably want this if using IPSec.
716 751
752config CRYPTO_ZLIB
753 tristate "Zlib compression algorithm"
754 select CRYPTO_PCOMP
755 select ZLIB_INFLATE
756 select ZLIB_DEFLATE
757 select NLATTR
758 help
759 This is the zlib algorithm.
760
717config CRYPTO_LZO 761config CRYPTO_LZO
718 tristate "LZO compression algorithm" 762 tristate "LZO compression algorithm"
719 select CRYPTO_ALGAPI 763 select CRYPTO_ALGAPI
diff --git a/crypto/Makefile b/crypto/Makefile
index 46b08bf2035f..673d9f7c1bda 100644
--- a/crypto/Makefile
+++ b/crypto/Makefile
@@ -5,6 +5,8 @@
5obj-$(CONFIG_CRYPTO) += crypto.o 5obj-$(CONFIG_CRYPTO) += crypto.o
6crypto-objs := api.o cipher.o digest.o compress.o 6crypto-objs := api.o cipher.o digest.o compress.o
7 7
8obj-$(CONFIG_CRYPTO_WORKQUEUE) += crypto_wq.o
9
8obj-$(CONFIG_CRYPTO_FIPS) += fips.o 10obj-$(CONFIG_CRYPTO_FIPS) += fips.o
9 11
10crypto_algapi-$(CONFIG_PROC_FS) += proc.o 12crypto_algapi-$(CONFIG_PROC_FS) += proc.o
@@ -25,6 +27,8 @@ crypto_hash-objs += ahash.o
25crypto_hash-objs += shash.o 27crypto_hash-objs += shash.o
26obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o 28obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o
27 29
30obj-$(CONFIG_CRYPTO_PCOMP) += pcompress.o
31
28cryptomgr-objs := algboss.o testmgr.o 32cryptomgr-objs := algboss.o testmgr.o
29 33
30obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o 34obj-$(CONFIG_CRYPTO_MANAGER2) += cryptomgr.o
@@ -70,6 +74,7 @@ obj-$(CONFIG_CRYPTO_ANUBIS) += anubis.o
70obj-$(CONFIG_CRYPTO_SEED) += seed.o 74obj-$(CONFIG_CRYPTO_SEED) += seed.o
71obj-$(CONFIG_CRYPTO_SALSA20) += salsa20_generic.o 75obj-$(CONFIG_CRYPTO_SALSA20) += salsa20_generic.o
72obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o 76obj-$(CONFIG_CRYPTO_DEFLATE) += deflate.o
77obj-$(CONFIG_CRYPTO_ZLIB) += zlib.o
73obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o 78obj-$(CONFIG_CRYPTO_MICHAEL_MIC) += michael_mic.o
74obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o 79obj-$(CONFIG_CRYPTO_CRC32C) += crc32c.o
75obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o 80obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o
diff --git a/crypto/ablkcipher.c b/crypto/ablkcipher.c
index 94140b3756fc..e11ce37c7104 100644
--- a/crypto/ablkcipher.c
+++ b/crypto/ablkcipher.c
@@ -282,6 +282,25 @@ static struct crypto_alg *crypto_lookup_skcipher(const char *name, u32 type,
282 alg->cra_ablkcipher.ivsize)) 282 alg->cra_ablkcipher.ivsize))
283 return alg; 283 return alg;
284 284
285 crypto_mod_put(alg);
286 alg = crypto_alg_mod_lookup(name, type | CRYPTO_ALG_TESTED,
287 mask & ~CRYPTO_ALG_TESTED);
288 if (IS_ERR(alg))
289 return alg;
290
291 if ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
292 CRYPTO_ALG_TYPE_GIVCIPHER) {
293 if ((alg->cra_flags ^ type ^ ~mask) & CRYPTO_ALG_TESTED) {
294 crypto_mod_put(alg);
295 alg = ERR_PTR(-ENOENT);
296 }
297 return alg;
298 }
299
300 BUG_ON(!((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
301 CRYPTO_ALG_TYPE_BLKCIPHER ? alg->cra_blkcipher.ivsize :
302 alg->cra_ablkcipher.ivsize));
303
285 return ERR_PTR(crypto_givcipher_default(alg, type, mask)); 304 return ERR_PTR(crypto_givcipher_default(alg, type, mask));
286} 305}
287 306
diff --git a/crypto/aead.c b/crypto/aead.c
index 3a6f3f52c7c7..d9aa733db164 100644
--- a/crypto/aead.c
+++ b/crypto/aead.c
@@ -422,6 +422,22 @@ static struct crypto_alg *crypto_lookup_aead(const char *name, u32 type,
422 if (!alg->cra_aead.ivsize) 422 if (!alg->cra_aead.ivsize)
423 return alg; 423 return alg;
424 424
425 crypto_mod_put(alg);
426 alg = crypto_alg_mod_lookup(name, type | CRYPTO_ALG_TESTED,
427 mask & ~CRYPTO_ALG_TESTED);
428 if (IS_ERR(alg))
429 return alg;
430
431 if (alg->cra_type == &crypto_aead_type) {
432 if ((alg->cra_flags ^ type ^ ~mask) & CRYPTO_ALG_TESTED) {
433 crypto_mod_put(alg);
434 alg = ERR_PTR(-ENOENT);
435 }
436 return alg;
437 }
438
439 BUG_ON(!alg->cra_aead.ivsize);
440
425 return ERR_PTR(crypto_nivaead_default(alg, type, mask)); 441 return ERR_PTR(crypto_nivaead_default(alg, type, mask));
426} 442}
427 443
diff --git a/crypto/algboss.c b/crypto/algboss.c
index 4601e4267c88..6906f92aeac0 100644
--- a/crypto/algboss.c
+++ b/crypto/algboss.c
@@ -10,7 +10,7 @@
10 * 10 *
11 */ 11 */
12 12
13#include <linux/crypto.h> 13#include <crypto/internal/aead.h>
14#include <linux/ctype.h> 14#include <linux/ctype.h>
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/init.h> 16#include <linux/init.h>
@@ -206,8 +206,7 @@ static int cryptomgr_test(void *data)
206 u32 type = param->type; 206 u32 type = param->type;
207 int err = 0; 207 int err = 0;
208 208
209 if (!((type ^ CRYPTO_ALG_TYPE_BLKCIPHER) & 209 if (type & CRYPTO_ALG_TESTED)
210 CRYPTO_ALG_TYPE_BLKCIPHER_MASK) && !(type & CRYPTO_ALG_GENIV))
211 goto skiptest; 210 goto skiptest;
212 211
213 err = alg_test(param->driver, param->alg, type, CRYPTO_ALG_TESTED); 212 err = alg_test(param->driver, param->alg, type, CRYPTO_ALG_TESTED);
@@ -223,6 +222,7 @@ static int cryptomgr_schedule_test(struct crypto_alg *alg)
223{ 222{
224 struct task_struct *thread; 223 struct task_struct *thread;
225 struct crypto_test_param *param; 224 struct crypto_test_param *param;
225 u32 type;
226 226
227 if (!try_module_get(THIS_MODULE)) 227 if (!try_module_get(THIS_MODULE))
228 goto err; 228 goto err;
@@ -233,7 +233,19 @@ static int cryptomgr_schedule_test(struct crypto_alg *alg)
233 233
234 memcpy(param->driver, alg->cra_driver_name, sizeof(param->driver)); 234 memcpy(param->driver, alg->cra_driver_name, sizeof(param->driver));
235 memcpy(param->alg, alg->cra_name, sizeof(param->alg)); 235 memcpy(param->alg, alg->cra_name, sizeof(param->alg));
236 param->type = alg->cra_flags; 236 type = alg->cra_flags;
237
238 /* This piece of crap needs to disappear into per-type test hooks. */
239 if ((!((type ^ CRYPTO_ALG_TYPE_BLKCIPHER) &
240 CRYPTO_ALG_TYPE_BLKCIPHER_MASK) && !(type & CRYPTO_ALG_GENIV) &&
241 ((alg->cra_flags & CRYPTO_ALG_TYPE_MASK) ==
242 CRYPTO_ALG_TYPE_BLKCIPHER ? alg->cra_blkcipher.ivsize :
243 alg->cra_ablkcipher.ivsize)) ||
244 (!((type ^ CRYPTO_ALG_TYPE_AEAD) & CRYPTO_ALG_TYPE_MASK) &&
245 alg->cra_type == &crypto_nivaead_type && alg->cra_aead.ivsize))
246 type |= CRYPTO_ALG_TESTED;
247
248 param->type = type;
237 249
238 thread = kthread_run(cryptomgr_test, param, "cryptomgr_test"); 250 thread = kthread_run(cryptomgr_test, param, "cryptomgr_test");
239 if (IS_ERR(thread)) 251 if (IS_ERR(thread))
diff --git a/crypto/ansi_cprng.c b/crypto/ansi_cprng.c
index 0fac8ffc2fb7..d80ed4c1e009 100644
--- a/crypto/ansi_cprng.c
+++ b/crypto/ansi_cprng.c
@@ -132,9 +132,15 @@ static int _get_more_prng_bytes(struct prng_context *ctx)
132 */ 132 */
133 if (!memcmp(ctx->rand_data, ctx->last_rand_data, 133 if (!memcmp(ctx->rand_data, ctx->last_rand_data,
134 DEFAULT_BLK_SZ)) { 134 DEFAULT_BLK_SZ)) {
135 if (fips_enabled) {
136 panic("cprng %p Failed repetition check!\n",
137 ctx);
138 }
139
135 printk(KERN_ERR 140 printk(KERN_ERR
136 "ctx %p Failed repetition check!\n", 141 "ctx %p Failed repetition check!\n",
137 ctx); 142 ctx);
143
138 ctx->flags |= PRNG_NEED_RESET; 144 ctx->flags |= PRNG_NEED_RESET;
139 return -EINVAL; 145 return -EINVAL;
140 } 146 }
@@ -338,7 +344,16 @@ static int cprng_init(struct crypto_tfm *tfm)
338 344
339 spin_lock_init(&ctx->prng_lock); 345 spin_lock_init(&ctx->prng_lock);
340 346
341 return reset_prng_context(ctx, NULL, DEFAULT_PRNG_KSZ, NULL, NULL); 347 if (reset_prng_context(ctx, NULL, DEFAULT_PRNG_KSZ, NULL, NULL) < 0)
348 return -EINVAL;
349
350 /*
351 * after allocation, we should always force the user to reset
352 * so they don't inadvertently use the insecure default values
353 * without specifying them intentially
354 */
355 ctx->flags |= PRNG_NEED_RESET;
356 return 0;
342} 357}
343 358
344static void cprng_exit(struct crypto_tfm *tfm) 359static void cprng_exit(struct crypto_tfm *tfm)
diff --git a/crypto/api.c b/crypto/api.c
index 38a2bc02a98c..314dab96840e 100644
--- a/crypto/api.c
+++ b/crypto/api.c
@@ -255,7 +255,7 @@ struct crypto_alg *crypto_alg_mod_lookup(const char *name, u32 type, u32 mask)
255 struct crypto_alg *larval; 255 struct crypto_alg *larval;
256 int ok; 256 int ok;
257 257
258 if (!(mask & CRYPTO_ALG_TESTED)) { 258 if (!((type | mask) & CRYPTO_ALG_TESTED)) {
259 type |= CRYPTO_ALG_TESTED; 259 type |= CRYPTO_ALG_TESTED;
260 mask |= CRYPTO_ALG_TESTED; 260 mask |= CRYPTO_ALG_TESTED;
261 } 261 }
@@ -464,8 +464,8 @@ err:
464} 464}
465EXPORT_SYMBOL_GPL(crypto_alloc_base); 465EXPORT_SYMBOL_GPL(crypto_alloc_base);
466 466
467struct crypto_tfm *crypto_create_tfm(struct crypto_alg *alg, 467void *crypto_create_tfm(struct crypto_alg *alg,
468 const struct crypto_type *frontend) 468 const struct crypto_type *frontend)
469{ 469{
470 char *mem; 470 char *mem;
471 struct crypto_tfm *tfm = NULL; 471 struct crypto_tfm *tfm = NULL;
@@ -499,9 +499,9 @@ out_free_tfm:
499 crypto_shoot_alg(alg); 499 crypto_shoot_alg(alg);
500 kfree(mem); 500 kfree(mem);
501out_err: 501out_err:
502 tfm = ERR_PTR(err); 502 mem = ERR_PTR(err);
503out: 503out:
504 return tfm; 504 return mem;
505} 505}
506EXPORT_SYMBOL_GPL(crypto_create_tfm); 506EXPORT_SYMBOL_GPL(crypto_create_tfm);
507 507
@@ -525,12 +525,11 @@ EXPORT_SYMBOL_GPL(crypto_create_tfm);
525 * 525 *
526 * In case of error the return value is an error pointer. 526 * In case of error the return value is an error pointer.
527 */ 527 */
528struct crypto_tfm *crypto_alloc_tfm(const char *alg_name, 528void *crypto_alloc_tfm(const char *alg_name,
529 const struct crypto_type *frontend, 529 const struct crypto_type *frontend, u32 type, u32 mask)
530 u32 type, u32 mask)
531{ 530{
532 struct crypto_alg *(*lookup)(const char *name, u32 type, u32 mask); 531 struct crypto_alg *(*lookup)(const char *name, u32 type, u32 mask);
533 struct crypto_tfm *tfm; 532 void *tfm;
534 int err; 533 int err;
535 534
536 type &= frontend->maskclear; 535 type &= frontend->maskclear;
diff --git a/crypto/blkcipher.c b/crypto/blkcipher.c
index d70a41c002df..90d26c91f4e9 100644
--- a/crypto/blkcipher.c
+++ b/crypto/blkcipher.c
@@ -521,7 +521,7 @@ static int crypto_grab_nivcipher(struct crypto_skcipher_spawn *spawn,
521 int err; 521 int err;
522 522
523 type = crypto_skcipher_type(type); 523 type = crypto_skcipher_type(type);
524 mask = crypto_skcipher_mask(mask) | CRYPTO_ALG_GENIV; 524 mask = crypto_skcipher_mask(mask)| CRYPTO_ALG_GENIV;
525 525
526 alg = crypto_alg_mod_lookup(name, type, mask); 526 alg = crypto_alg_mod_lookup(name, type, mask);
527 if (IS_ERR(alg)) 527 if (IS_ERR(alg))
diff --git a/crypto/chainiv.c b/crypto/chainiv.c
index 7c37a497b860..ba200b07449d 100644
--- a/crypto/chainiv.c
+++ b/crypto/chainiv.c
@@ -15,6 +15,7 @@
15 15
16#include <crypto/internal/skcipher.h> 16#include <crypto/internal/skcipher.h>
17#include <crypto/rng.h> 17#include <crypto/rng.h>
18#include <crypto/crypto_wq.h>
18#include <linux/err.h> 19#include <linux/err.h>
19#include <linux/init.h> 20#include <linux/init.h>
20#include <linux/kernel.h> 21#include <linux/kernel.h>
@@ -133,7 +134,7 @@ static int async_chainiv_schedule_work(struct async_chainiv_ctx *ctx)
133 goto out; 134 goto out;
134 } 135 }
135 136
136 queued = schedule_work(&ctx->postponed); 137 queued = queue_work(kcrypto_wq, &ctx->postponed);
137 BUG_ON(!queued); 138 BUG_ON(!queued);
138 139
139out: 140out:
diff --git a/crypto/cryptd.c b/crypto/cryptd.c
index d29e06b350ff..d14b22658d7a 100644
--- a/crypto/cryptd.c
+++ b/crypto/cryptd.c
@@ -12,30 +12,31 @@
12 12
13#include <crypto/algapi.h> 13#include <crypto/algapi.h>
14#include <crypto/internal/hash.h> 14#include <crypto/internal/hash.h>
15#include <crypto/cryptd.h>
16#include <crypto/crypto_wq.h>
15#include <linux/err.h> 17#include <linux/err.h>
16#include <linux/init.h> 18#include <linux/init.h>
17#include <linux/kernel.h> 19#include <linux/kernel.h>
18#include <linux/kthread.h>
19#include <linux/list.h> 20#include <linux/list.h>
20#include <linux/module.h> 21#include <linux/module.h>
21#include <linux/mutex.h>
22#include <linux/scatterlist.h> 22#include <linux/scatterlist.h>
23#include <linux/sched.h> 23#include <linux/sched.h>
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/spinlock.h>
26 25
27#define CRYPTD_MAX_QLEN 100 26#define CRYPTD_MAX_CPU_QLEN 100
28 27
29struct cryptd_state { 28struct cryptd_cpu_queue {
30 spinlock_t lock;
31 struct mutex mutex;
32 struct crypto_queue queue; 29 struct crypto_queue queue;
33 struct task_struct *task; 30 struct work_struct work;
31};
32
33struct cryptd_queue {
34 struct cryptd_cpu_queue *cpu_queue;
34}; 35};
35 36
36struct cryptd_instance_ctx { 37struct cryptd_instance_ctx {
37 struct crypto_spawn spawn; 38 struct crypto_spawn spawn;
38 struct cryptd_state *state; 39 struct cryptd_queue *queue;
39}; 40};
40 41
41struct cryptd_blkcipher_ctx { 42struct cryptd_blkcipher_ctx {
@@ -54,11 +55,85 @@ struct cryptd_hash_request_ctx {
54 crypto_completion_t complete; 55 crypto_completion_t complete;
55}; 56};
56 57
57static inline struct cryptd_state *cryptd_get_state(struct crypto_tfm *tfm) 58static void cryptd_queue_worker(struct work_struct *work);
59
60static int cryptd_init_queue(struct cryptd_queue *queue,
61 unsigned int max_cpu_qlen)
62{
63 int cpu;
64 struct cryptd_cpu_queue *cpu_queue;
65
66 queue->cpu_queue = alloc_percpu(struct cryptd_cpu_queue);
67 if (!queue->cpu_queue)
68 return -ENOMEM;
69 for_each_possible_cpu(cpu) {
70 cpu_queue = per_cpu_ptr(queue->cpu_queue, cpu);
71 crypto_init_queue(&cpu_queue->queue, max_cpu_qlen);
72 INIT_WORK(&cpu_queue->work, cryptd_queue_worker);
73 }
74 return 0;
75}
76
77static void cryptd_fini_queue(struct cryptd_queue *queue)
78{
79 int cpu;
80 struct cryptd_cpu_queue *cpu_queue;
81
82 for_each_possible_cpu(cpu) {
83 cpu_queue = per_cpu_ptr(queue->cpu_queue, cpu);
84 BUG_ON(cpu_queue->queue.qlen);
85 }
86 free_percpu(queue->cpu_queue);
87}
88
89static int cryptd_enqueue_request(struct cryptd_queue *queue,
90 struct crypto_async_request *request)
91{
92 int cpu, err;
93 struct cryptd_cpu_queue *cpu_queue;
94
95 cpu = get_cpu();
96 cpu_queue = per_cpu_ptr(queue->cpu_queue, cpu);
97 err = crypto_enqueue_request(&cpu_queue->queue, request);
98 queue_work_on(cpu, kcrypto_wq, &cpu_queue->work);
99 put_cpu();
100
101 return err;
102}
103
104/* Called in workqueue context, do one real cryption work (via
105 * req->complete) and reschedule itself if there are more work to
106 * do. */
107static void cryptd_queue_worker(struct work_struct *work)
108{
109 struct cryptd_cpu_queue *cpu_queue;
110 struct crypto_async_request *req, *backlog;
111
112 cpu_queue = container_of(work, struct cryptd_cpu_queue, work);
113 /* Only handle one request at a time to avoid hogging crypto
114 * workqueue. preempt_disable/enable is used to prevent
115 * being preempted by cryptd_enqueue_request() */
116 preempt_disable();
117 backlog = crypto_get_backlog(&cpu_queue->queue);
118 req = crypto_dequeue_request(&cpu_queue->queue);
119 preempt_enable();
120
121 if (!req)
122 return;
123
124 if (backlog)
125 backlog->complete(backlog, -EINPROGRESS);
126 req->complete(req, 0);
127
128 if (cpu_queue->queue.qlen)
129 queue_work(kcrypto_wq, &cpu_queue->work);
130}
131
132static inline struct cryptd_queue *cryptd_get_queue(struct crypto_tfm *tfm)
58{ 133{
59 struct crypto_instance *inst = crypto_tfm_alg_instance(tfm); 134 struct crypto_instance *inst = crypto_tfm_alg_instance(tfm);
60 struct cryptd_instance_ctx *ictx = crypto_instance_ctx(inst); 135 struct cryptd_instance_ctx *ictx = crypto_instance_ctx(inst);
61 return ictx->state; 136 return ictx->queue;
62} 137}
63 138
64static int cryptd_blkcipher_setkey(struct crypto_ablkcipher *parent, 139static int cryptd_blkcipher_setkey(struct crypto_ablkcipher *parent,
@@ -130,19 +205,13 @@ static int cryptd_blkcipher_enqueue(struct ablkcipher_request *req,
130{ 205{
131 struct cryptd_blkcipher_request_ctx *rctx = ablkcipher_request_ctx(req); 206 struct cryptd_blkcipher_request_ctx *rctx = ablkcipher_request_ctx(req);
132 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req); 207 struct crypto_ablkcipher *tfm = crypto_ablkcipher_reqtfm(req);
133 struct cryptd_state *state = 208 struct cryptd_queue *queue;
134 cryptd_get_state(crypto_ablkcipher_tfm(tfm));
135 int err;
136 209
210 queue = cryptd_get_queue(crypto_ablkcipher_tfm(tfm));
137 rctx->complete = req->base.complete; 211 rctx->complete = req->base.complete;
138 req->base.complete = complete; 212 req->base.complete = complete;
139 213
140 spin_lock_bh(&state->lock); 214 return cryptd_enqueue_request(queue, &req->base);
141 err = ablkcipher_enqueue_request(&state->queue, req);
142 spin_unlock_bh(&state->lock);
143
144 wake_up_process(state->task);
145 return err;
146} 215}
147 216
148static int cryptd_blkcipher_encrypt_enqueue(struct ablkcipher_request *req) 217static int cryptd_blkcipher_encrypt_enqueue(struct ablkcipher_request *req)
@@ -176,21 +245,12 @@ static int cryptd_blkcipher_init_tfm(struct crypto_tfm *tfm)
176static void cryptd_blkcipher_exit_tfm(struct crypto_tfm *tfm) 245static void cryptd_blkcipher_exit_tfm(struct crypto_tfm *tfm)
177{ 246{
178 struct cryptd_blkcipher_ctx *ctx = crypto_tfm_ctx(tfm); 247 struct cryptd_blkcipher_ctx *ctx = crypto_tfm_ctx(tfm);
179 struct cryptd_state *state = cryptd_get_state(tfm);
180 int active;
181
182 mutex_lock(&state->mutex);
183 active = ablkcipher_tfm_in_queue(&state->queue,
184 __crypto_ablkcipher_cast(tfm));
185 mutex_unlock(&state->mutex);
186
187 BUG_ON(active);
188 248
189 crypto_free_blkcipher(ctx->child); 249 crypto_free_blkcipher(ctx->child);
190} 250}
191 251
192static struct crypto_instance *cryptd_alloc_instance(struct crypto_alg *alg, 252static struct crypto_instance *cryptd_alloc_instance(struct crypto_alg *alg,
193 struct cryptd_state *state) 253 struct cryptd_queue *queue)
194{ 254{
195 struct crypto_instance *inst; 255 struct crypto_instance *inst;
196 struct cryptd_instance_ctx *ctx; 256 struct cryptd_instance_ctx *ctx;
@@ -213,7 +273,7 @@ static struct crypto_instance *cryptd_alloc_instance(struct crypto_alg *alg,
213 if (err) 273 if (err)
214 goto out_free_inst; 274 goto out_free_inst;
215 275
216 ctx->state = state; 276 ctx->queue = queue;
217 277
218 memcpy(inst->alg.cra_name, alg->cra_name, CRYPTO_MAX_ALG_NAME); 278 memcpy(inst->alg.cra_name, alg->cra_name, CRYPTO_MAX_ALG_NAME);
219 279
@@ -231,7 +291,7 @@ out_free_inst:
231} 291}
232 292
233static struct crypto_instance *cryptd_alloc_blkcipher( 293static struct crypto_instance *cryptd_alloc_blkcipher(
234 struct rtattr **tb, struct cryptd_state *state) 294 struct rtattr **tb, struct cryptd_queue *queue)
235{ 295{
236 struct crypto_instance *inst; 296 struct crypto_instance *inst;
237 struct crypto_alg *alg; 297 struct crypto_alg *alg;
@@ -241,7 +301,7 @@ static struct crypto_instance *cryptd_alloc_blkcipher(
241 if (IS_ERR(alg)) 301 if (IS_ERR(alg))
242 return ERR_CAST(alg); 302 return ERR_CAST(alg);
243 303
244 inst = cryptd_alloc_instance(alg, state); 304 inst = cryptd_alloc_instance(alg, queue);
245 if (IS_ERR(inst)) 305 if (IS_ERR(inst))
246 goto out_put_alg; 306 goto out_put_alg;
247 307
@@ -289,15 +349,6 @@ static int cryptd_hash_init_tfm(struct crypto_tfm *tfm)
289static void cryptd_hash_exit_tfm(struct crypto_tfm *tfm) 349static void cryptd_hash_exit_tfm(struct crypto_tfm *tfm)
290{ 350{
291 struct cryptd_hash_ctx *ctx = crypto_tfm_ctx(tfm); 351 struct cryptd_hash_ctx *ctx = crypto_tfm_ctx(tfm);
292 struct cryptd_state *state = cryptd_get_state(tfm);
293 int active;
294
295 mutex_lock(&state->mutex);
296 active = ahash_tfm_in_queue(&state->queue,
297 __crypto_ahash_cast(tfm));
298 mutex_unlock(&state->mutex);
299
300 BUG_ON(active);
301 352
302 crypto_free_hash(ctx->child); 353 crypto_free_hash(ctx->child);
303} 354}
@@ -323,19 +374,13 @@ static int cryptd_hash_enqueue(struct ahash_request *req,
323{ 374{
324 struct cryptd_hash_request_ctx *rctx = ahash_request_ctx(req); 375 struct cryptd_hash_request_ctx *rctx = ahash_request_ctx(req);
325 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 376 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
326 struct cryptd_state *state = 377 struct cryptd_queue *queue =
327 cryptd_get_state(crypto_ahash_tfm(tfm)); 378 cryptd_get_queue(crypto_ahash_tfm(tfm));
328 int err;
329 379
330 rctx->complete = req->base.complete; 380 rctx->complete = req->base.complete;
331 req->base.complete = complete; 381 req->base.complete = complete;
332 382
333 spin_lock_bh(&state->lock); 383 return cryptd_enqueue_request(queue, &req->base);
334 err = ahash_enqueue_request(&state->queue, req);
335 spin_unlock_bh(&state->lock);
336
337 wake_up_process(state->task);
338 return err;
339} 384}
340 385
341static void cryptd_hash_init(struct crypto_async_request *req_async, int err) 386static void cryptd_hash_init(struct crypto_async_request *req_async, int err)
@@ -468,7 +513,7 @@ static int cryptd_hash_digest_enqueue(struct ahash_request *req)
468} 513}
469 514
470static struct crypto_instance *cryptd_alloc_hash( 515static struct crypto_instance *cryptd_alloc_hash(
471 struct rtattr **tb, struct cryptd_state *state) 516 struct rtattr **tb, struct cryptd_queue *queue)
472{ 517{
473 struct crypto_instance *inst; 518 struct crypto_instance *inst;
474 struct crypto_alg *alg; 519 struct crypto_alg *alg;
@@ -478,7 +523,7 @@ static struct crypto_instance *cryptd_alloc_hash(
478 if (IS_ERR(alg)) 523 if (IS_ERR(alg))
479 return ERR_PTR(PTR_ERR(alg)); 524 return ERR_PTR(PTR_ERR(alg));
480 525
481 inst = cryptd_alloc_instance(alg, state); 526 inst = cryptd_alloc_instance(alg, queue);
482 if (IS_ERR(inst)) 527 if (IS_ERR(inst))
483 goto out_put_alg; 528 goto out_put_alg;
484 529
@@ -502,7 +547,7 @@ out_put_alg:
502 return inst; 547 return inst;
503} 548}
504 549
505static struct cryptd_state state; 550static struct cryptd_queue queue;
506 551
507static struct crypto_instance *cryptd_alloc(struct rtattr **tb) 552static struct crypto_instance *cryptd_alloc(struct rtattr **tb)
508{ 553{
@@ -514,9 +559,9 @@ static struct crypto_instance *cryptd_alloc(struct rtattr **tb)
514 559
515 switch (algt->type & algt->mask & CRYPTO_ALG_TYPE_MASK) { 560 switch (algt->type & algt->mask & CRYPTO_ALG_TYPE_MASK) {
516 case CRYPTO_ALG_TYPE_BLKCIPHER: 561 case CRYPTO_ALG_TYPE_BLKCIPHER:
517 return cryptd_alloc_blkcipher(tb, &state); 562 return cryptd_alloc_blkcipher(tb, &queue);
518 case CRYPTO_ALG_TYPE_DIGEST: 563 case CRYPTO_ALG_TYPE_DIGEST:
519 return cryptd_alloc_hash(tb, &state); 564 return cryptd_alloc_hash(tb, &queue);
520 } 565 }
521 566
522 return ERR_PTR(-EINVAL); 567 return ERR_PTR(-EINVAL);
@@ -537,82 +582,58 @@ static struct crypto_template cryptd_tmpl = {
537 .module = THIS_MODULE, 582 .module = THIS_MODULE,
538}; 583};
539 584
540static inline int cryptd_create_thread(struct cryptd_state *state, 585struct cryptd_ablkcipher *cryptd_alloc_ablkcipher(const char *alg_name,
541 int (*fn)(void *data), const char *name) 586 u32 type, u32 mask)
542{ 587{
543 spin_lock_init(&state->lock); 588 char cryptd_alg_name[CRYPTO_MAX_ALG_NAME];
544 mutex_init(&state->mutex); 589 struct crypto_ablkcipher *tfm;
545 crypto_init_queue(&state->queue, CRYPTD_MAX_QLEN); 590
546 591 if (snprintf(cryptd_alg_name, CRYPTO_MAX_ALG_NAME,
547 state->task = kthread_run(fn, state, name); 592 "cryptd(%s)", alg_name) >= CRYPTO_MAX_ALG_NAME)
548 if (IS_ERR(state->task)) 593 return ERR_PTR(-EINVAL);
549 return PTR_ERR(state->task); 594 tfm = crypto_alloc_ablkcipher(cryptd_alg_name, type, mask);
595 if (IS_ERR(tfm))
596 return ERR_CAST(tfm);
597 if (crypto_ablkcipher_tfm(tfm)->__crt_alg->cra_module != THIS_MODULE) {
598 crypto_free_ablkcipher(tfm);
599 return ERR_PTR(-EINVAL);
600 }
550 601
551 return 0; 602 return __cryptd_ablkcipher_cast(tfm);
552} 603}
604EXPORT_SYMBOL_GPL(cryptd_alloc_ablkcipher);
553 605
554static inline void cryptd_stop_thread(struct cryptd_state *state) 606struct crypto_blkcipher *cryptd_ablkcipher_child(struct cryptd_ablkcipher *tfm)
555{ 607{
556 BUG_ON(state->queue.qlen); 608 struct cryptd_blkcipher_ctx *ctx = crypto_ablkcipher_ctx(&tfm->base);
557 kthread_stop(state->task); 609 return ctx->child;
558} 610}
611EXPORT_SYMBOL_GPL(cryptd_ablkcipher_child);
559 612
560static int cryptd_thread(void *data) 613void cryptd_free_ablkcipher(struct cryptd_ablkcipher *tfm)
561{ 614{
562 struct cryptd_state *state = data; 615 crypto_free_ablkcipher(&tfm->base);
563 int stop;
564
565 current->flags |= PF_NOFREEZE;
566
567 do {
568 struct crypto_async_request *req, *backlog;
569
570 mutex_lock(&state->mutex);
571 __set_current_state(TASK_INTERRUPTIBLE);
572
573 spin_lock_bh(&state->lock);
574 backlog = crypto_get_backlog(&state->queue);
575 req = crypto_dequeue_request(&state->queue);
576 spin_unlock_bh(&state->lock);
577
578 stop = kthread_should_stop();
579
580 if (stop || req) {
581 __set_current_state(TASK_RUNNING);
582 if (req) {
583 if (backlog)
584 backlog->complete(backlog,
585 -EINPROGRESS);
586 req->complete(req, 0);
587 }
588 }
589
590 mutex_unlock(&state->mutex);
591
592 schedule();
593 } while (!stop);
594
595 return 0;
596} 616}
617EXPORT_SYMBOL_GPL(cryptd_free_ablkcipher);
597 618
598static int __init cryptd_init(void) 619static int __init cryptd_init(void)
599{ 620{
600 int err; 621 int err;
601 622
602 err = cryptd_create_thread(&state, cryptd_thread, "cryptd"); 623 err = cryptd_init_queue(&queue, CRYPTD_MAX_CPU_QLEN);
603 if (err) 624 if (err)
604 return err; 625 return err;
605 626
606 err = crypto_register_template(&cryptd_tmpl); 627 err = crypto_register_template(&cryptd_tmpl);
607 if (err) 628 if (err)
608 kthread_stop(state.task); 629 cryptd_fini_queue(&queue);
609 630
610 return err; 631 return err;
611} 632}
612 633
613static void __exit cryptd_exit(void) 634static void __exit cryptd_exit(void)
614{ 635{
615 cryptd_stop_thread(&state); 636 cryptd_fini_queue(&queue);
616 crypto_unregister_template(&cryptd_tmpl); 637 crypto_unregister_template(&cryptd_tmpl);
617} 638}
618 639
diff --git a/crypto/crypto_wq.c b/crypto/crypto_wq.c
new file mode 100644
index 000000000000..fdcf6248f152
--- /dev/null
+++ b/crypto/crypto_wq.c
@@ -0,0 +1,38 @@
1/*
2 * Workqueue for crypto subsystem
3 *
4 * Copyright (c) 2009 Intel Corp.
5 * Author: Huang Ying <ying.huang@intel.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 */
13
14#include <linux/workqueue.h>
15#include <crypto/algapi.h>
16#include <crypto/crypto_wq.h>
17
18struct workqueue_struct *kcrypto_wq;
19EXPORT_SYMBOL_GPL(kcrypto_wq);
20
21static int __init crypto_wq_init(void)
22{
23 kcrypto_wq = create_workqueue("crypto");
24 if (unlikely(!kcrypto_wq))
25 return -ENOMEM;
26 return 0;
27}
28
29static void __exit crypto_wq_exit(void)
30{
31 destroy_workqueue(kcrypto_wq);
32}
33
34module_init(crypto_wq_init);
35module_exit(crypto_wq_exit);
36
37MODULE_LICENSE("GPL");
38MODULE_DESCRIPTION("Workqueue for crypto subsystem");
diff --git a/crypto/gf128mul.c b/crypto/gf128mul.c
index ecbeaa1f17e1..a90d260528d4 100644
--- a/crypto/gf128mul.c
+++ b/crypto/gf128mul.c
@@ -4,7 +4,7 @@
4 * Copyright (c) 2006, Rik Snel <rsnel@cube.dyndns.org> 4 * Copyright (c) 2006, Rik Snel <rsnel@cube.dyndns.org>
5 * 5 *
6 * Based on Dr Brian Gladman's (GPL'd) work published at 6 * Based on Dr Brian Gladman's (GPL'd) work published at
7 * http://fp.gladman.plus.com/cryptography_technology/index.htm 7 * http://gladman.plushost.co.uk/oldsite/cryptography_technology/index.php
8 * See the original copyright notice below. 8 * See the original copyright notice below.
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify it 10 * This program is free software; you can redistribute it and/or modify it
diff --git a/crypto/internal.h b/crypto/internal.h
index 3c19a27a7563..fc76e1f37fc3 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -109,8 +109,10 @@ void crypto_alg_tested(const char *name, int err);
109void crypto_shoot_alg(struct crypto_alg *alg); 109void crypto_shoot_alg(struct crypto_alg *alg);
110struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type, 110struct crypto_tfm *__crypto_alloc_tfm(struct crypto_alg *alg, u32 type,
111 u32 mask); 111 u32 mask);
112struct crypto_tfm *crypto_create_tfm(struct crypto_alg *alg, 112void *crypto_create_tfm(struct crypto_alg *alg,
113 const struct crypto_type *frontend); 113 const struct crypto_type *frontend);
114void *crypto_alloc_tfm(const char *alg_name,
115 const struct crypto_type *frontend, u32 type, u32 mask);
114 116
115int crypto_register_instance(struct crypto_template *tmpl, 117int crypto_register_instance(struct crypto_template *tmpl,
116 struct crypto_instance *inst); 118 struct crypto_instance *inst);
diff --git a/crypto/pcompress.c b/crypto/pcompress.c
new file mode 100644
index 000000000000..ca9a4af91efe
--- /dev/null
+++ b/crypto/pcompress.c
@@ -0,0 +1,97 @@
1/*
2 * Cryptographic API.
3 *
4 * Partial (de)compression operations.
5 *
6 * Copyright 2008 Sony Corporation
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program.
19 * If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include <linux/crypto.h>
23#include <linux/errno.h>
24#include <linux/module.h>
25#include <linux/seq_file.h>
26#include <linux/string.h>
27
28#include <crypto/compress.h>
29
30#include "internal.h"
31
32
33static int crypto_pcomp_init(struct crypto_tfm *tfm, u32 type, u32 mask)
34{
35 return 0;
36}
37
38static unsigned int crypto_pcomp_extsize(struct crypto_alg *alg,
39 const struct crypto_type *frontend)
40{
41 return alg->cra_ctxsize;
42}
43
44static int crypto_pcomp_init_tfm(struct crypto_tfm *tfm,
45 const struct crypto_type *frontend)
46{
47 return 0;
48}
49
50static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg)
51 __attribute__ ((unused));
52static void crypto_pcomp_show(struct seq_file *m, struct crypto_alg *alg)
53{
54 seq_printf(m, "type : pcomp\n");
55}
56
57static const struct crypto_type crypto_pcomp_type = {
58 .extsize = crypto_pcomp_extsize,
59 .init = crypto_pcomp_init,
60 .init_tfm = crypto_pcomp_init_tfm,
61#ifdef CONFIG_PROC_FS
62 .show = crypto_pcomp_show,
63#endif
64 .maskclear = ~CRYPTO_ALG_TYPE_MASK,
65 .maskset = CRYPTO_ALG_TYPE_MASK,
66 .type = CRYPTO_ALG_TYPE_PCOMPRESS,
67 .tfmsize = offsetof(struct crypto_pcomp, base),
68};
69
70struct crypto_pcomp *crypto_alloc_pcomp(const char *alg_name, u32 type,
71 u32 mask)
72{
73 return crypto_alloc_tfm(alg_name, &crypto_pcomp_type, type, mask);
74}
75EXPORT_SYMBOL_GPL(crypto_alloc_pcomp);
76
77int crypto_register_pcomp(struct pcomp_alg *alg)
78{
79 struct crypto_alg *base = &alg->base;
80
81 base->cra_type = &crypto_pcomp_type;
82 base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
83 base->cra_flags |= CRYPTO_ALG_TYPE_PCOMPRESS;
84
85 return crypto_register_alg(base);
86}
87EXPORT_SYMBOL_GPL(crypto_register_pcomp);
88
89int crypto_unregister_pcomp(struct pcomp_alg *alg)
90{
91 return crypto_unregister_alg(&alg->base);
92}
93EXPORT_SYMBOL_GPL(crypto_unregister_pcomp);
94
95MODULE_LICENSE("GPL");
96MODULE_DESCRIPTION("Partial (de)compression type");
97MODULE_AUTHOR("Sony Corporation");
diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
index caa3542e6ce8..6349d8339d37 100644
--- a/crypto/sha256_generic.c
+++ b/crypto/sha256_generic.c
@@ -2,7 +2,7 @@
2 * Cryptographic API. 2 * Cryptographic API.
3 * 3 *
4 * SHA-256, as specified in 4 * SHA-256, as specified in
5 * http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf 5 * http://csrc.nist.gov/groups/STM/cavp/documents/shs/sha256-384-512.pdf
6 * 6 *
7 * SHA-256 code by Jean-Luc Cooke <jlcooke@certainkey.com>. 7 * SHA-256 code by Jean-Luc Cooke <jlcooke@certainkey.com>.
8 * 8 *
diff --git a/crypto/shash.c b/crypto/shash.c
index d5a2b619c55f..7a659733f94a 100644
--- a/crypto/shash.c
+++ b/crypto/shash.c
@@ -18,15 +18,10 @@
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/seq_file.h> 19#include <linux/seq_file.h>
20 20
21static const struct crypto_type crypto_shash_type;
22
23static inline struct crypto_shash *__crypto_shash_cast(struct crypto_tfm *tfm)
24{
25 return container_of(tfm, struct crypto_shash, base);
26}
27
28#include "internal.h" 21#include "internal.h"
29 22
23static const struct crypto_type crypto_shash_type;
24
30static int shash_setkey_unaligned(struct crypto_shash *tfm, const u8 *key, 25static int shash_setkey_unaligned(struct crypto_shash *tfm, const u8 *key,
31 unsigned int keylen) 26 unsigned int keylen)
32{ 27{
@@ -282,8 +277,7 @@ static int crypto_init_shash_ops_async(struct crypto_tfm *tfm)
282 if (!crypto_mod_get(calg)) 277 if (!crypto_mod_get(calg))
283 return -EAGAIN; 278 return -EAGAIN;
284 279
285 shash = __crypto_shash_cast(crypto_create_tfm( 280 shash = crypto_create_tfm(calg, &crypto_shash_type);
286 calg, &crypto_shash_type));
287 if (IS_ERR(shash)) { 281 if (IS_ERR(shash)) {
288 crypto_mod_put(calg); 282 crypto_mod_put(calg);
289 return PTR_ERR(shash); 283 return PTR_ERR(shash);
@@ -391,8 +385,7 @@ static int crypto_init_shash_ops_compat(struct crypto_tfm *tfm)
391 if (!crypto_mod_get(calg)) 385 if (!crypto_mod_get(calg))
392 return -EAGAIN; 386 return -EAGAIN;
393 387
394 shash = __crypto_shash_cast(crypto_create_tfm( 388 shash = crypto_create_tfm(calg, &crypto_shash_type);
395 calg, &crypto_shash_type));
396 if (IS_ERR(shash)) { 389 if (IS_ERR(shash)) {
397 crypto_mod_put(calg); 390 crypto_mod_put(calg);
398 return PTR_ERR(shash); 391 return PTR_ERR(shash);
@@ -442,8 +435,6 @@ static unsigned int crypto_shash_ctxsize(struct crypto_alg *alg, u32 type,
442static int crypto_shash_init_tfm(struct crypto_tfm *tfm, 435static int crypto_shash_init_tfm(struct crypto_tfm *tfm,
443 const struct crypto_type *frontend) 436 const struct crypto_type *frontend)
444{ 437{
445 if (frontend->type != CRYPTO_ALG_TYPE_SHASH)
446 return -EINVAL;
447 return 0; 438 return 0;
448} 439}
449 440
@@ -482,8 +473,7 @@ static const struct crypto_type crypto_shash_type = {
482struct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type, 473struct crypto_shash *crypto_alloc_shash(const char *alg_name, u32 type,
483 u32 mask) 474 u32 mask)
484{ 475{
485 return __crypto_shash_cast( 476 return crypto_alloc_tfm(alg_name, &crypto_shash_type, type, mask);
486 crypto_alloc_tfm(alg_name, &crypto_shash_type, type, mask));
487} 477}
488EXPORT_SYMBOL_GPL(crypto_alloc_shash); 478EXPORT_SYMBOL_GPL(crypto_alloc_shash);
489 479
diff --git a/crypto/tcrypt.c b/crypto/tcrypt.c
index 28a45a1e6f42..c3c9124209a1 100644
--- a/crypto/tcrypt.c
+++ b/crypto/tcrypt.c
@@ -53,7 +53,7 @@ static char *check[] = {
53 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea", 53 "cast6", "arc4", "michael_mic", "deflate", "crc32c", "tea", "xtea",
54 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt", 54 "khazad", "wp512", "wp384", "wp256", "tnepres", "xeta", "fcrypt",
55 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320", 55 "camellia", "seed", "salsa20", "rmd128", "rmd160", "rmd256", "rmd320",
56 "lzo", "cts", NULL 56 "lzo", "cts", "zlib", NULL
57}; 57};
58 58
59static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc, 59static int test_cipher_jiffies(struct blkcipher_desc *desc, int enc,
@@ -661,6 +661,10 @@ static void do_test(int m)
661 tcrypt_test("ecb(seed)"); 661 tcrypt_test("ecb(seed)");
662 break; 662 break;
663 663
664 case 44:
665 tcrypt_test("zlib");
666 break;
667
664 case 100: 668 case 100:
665 tcrypt_test("hmac(md5)"); 669 tcrypt_test("hmac(md5)");
666 break; 670 break;
diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index a75f11ffb957..b50c3c6b17a2 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -72,6 +72,13 @@ struct comp_test_suite {
72 } comp, decomp; 72 } comp, decomp;
73}; 73};
74 74
75struct pcomp_test_suite {
76 struct {
77 struct pcomp_testvec *vecs;
78 unsigned int count;
79 } comp, decomp;
80};
81
75struct hash_test_suite { 82struct hash_test_suite {
76 struct hash_testvec *vecs; 83 struct hash_testvec *vecs;
77 unsigned int count; 84 unsigned int count;
@@ -86,6 +93,7 @@ struct alg_test_desc {
86 struct aead_test_suite aead; 93 struct aead_test_suite aead;
87 struct cipher_test_suite cipher; 94 struct cipher_test_suite cipher;
88 struct comp_test_suite comp; 95 struct comp_test_suite comp;
96 struct pcomp_test_suite pcomp;
89 struct hash_test_suite hash; 97 struct hash_test_suite hash;
90 } suite; 98 } suite;
91}; 99};
@@ -898,6 +906,159 @@ out:
898 return ret; 906 return ret;
899} 907}
900 908
909static int test_pcomp(struct crypto_pcomp *tfm,
910 struct pcomp_testvec *ctemplate,
911 struct pcomp_testvec *dtemplate, int ctcount,
912 int dtcount)
913{
914 const char *algo = crypto_tfm_alg_driver_name(crypto_pcomp_tfm(tfm));
915 unsigned int i;
916 char result[COMP_BUF_SIZE];
917 int error;
918
919 for (i = 0; i < ctcount; i++) {
920 struct comp_request req;
921
922 error = crypto_compress_setup(tfm, ctemplate[i].params,
923 ctemplate[i].paramsize);
924 if (error) {
925 pr_err("alg: pcomp: compression setup failed on test "
926 "%d for %s: error=%d\n", i + 1, algo, error);
927 return error;
928 }
929
930 error = crypto_compress_init(tfm);
931 if (error) {
932 pr_err("alg: pcomp: compression init failed on test "
933 "%d for %s: error=%d\n", i + 1, algo, error);
934 return error;
935 }
936
937 memset(result, 0, sizeof(result));
938
939 req.next_in = ctemplate[i].input;
940 req.avail_in = ctemplate[i].inlen / 2;
941 req.next_out = result;
942 req.avail_out = ctemplate[i].outlen / 2;
943
944 error = crypto_compress_update(tfm, &req);
945 if (error && (error != -EAGAIN || req.avail_in)) {
946 pr_err("alg: pcomp: compression update failed on test "
947 "%d for %s: error=%d\n", i + 1, algo, error);
948 return error;
949 }
950
951 /* Add remaining input data */
952 req.avail_in += (ctemplate[i].inlen + 1) / 2;
953
954 error = crypto_compress_update(tfm, &req);
955 if (error && (error != -EAGAIN || req.avail_in)) {
956 pr_err("alg: pcomp: compression update failed on test "
957 "%d for %s: error=%d\n", i + 1, algo, error);
958 return error;
959 }
960
961 /* Provide remaining output space */
962 req.avail_out += COMP_BUF_SIZE - ctemplate[i].outlen / 2;
963
964 error = crypto_compress_final(tfm, &req);
965 if (error) {
966 pr_err("alg: pcomp: compression final failed on test "
967 "%d for %s: error=%d\n", i + 1, algo, error);
968 return error;
969 }
970
971 if (COMP_BUF_SIZE - req.avail_out != ctemplate[i].outlen) {
972 pr_err("alg: comp: Compression test %d failed for %s: "
973 "output len = %d (expected %d)\n", i + 1, algo,
974 COMP_BUF_SIZE - req.avail_out,
975 ctemplate[i].outlen);
976 return -EINVAL;
977 }
978
979 if (memcmp(result, ctemplate[i].output, ctemplate[i].outlen)) {
980 pr_err("alg: pcomp: Compression test %d failed for "
981 "%s\n", i + 1, algo);
982 hexdump(result, ctemplate[i].outlen);
983 return -EINVAL;
984 }
985 }
986
987 for (i = 0; i < dtcount; i++) {
988 struct comp_request req;
989
990 error = crypto_decompress_setup(tfm, dtemplate[i].params,
991 dtemplate[i].paramsize);
992 if (error) {
993 pr_err("alg: pcomp: decompression setup failed on "
994 "test %d for %s: error=%d\n", i + 1, algo,
995 error);
996 return error;
997 }
998
999 error = crypto_decompress_init(tfm);
1000 if (error) {
1001 pr_err("alg: pcomp: decompression init failed on test "
1002 "%d for %s: error=%d\n", i + 1, algo, error);
1003 return error;
1004 }
1005
1006 memset(result, 0, sizeof(result));
1007
1008 req.next_in = dtemplate[i].input;
1009 req.avail_in = dtemplate[i].inlen / 2;
1010 req.next_out = result;
1011 req.avail_out = dtemplate[i].outlen / 2;
1012
1013 error = crypto_decompress_update(tfm, &req);
1014 if (error && (error != -EAGAIN || req.avail_in)) {
1015 pr_err("alg: pcomp: decompression update failed on "
1016 "test %d for %s: error=%d\n", i + 1, algo,
1017 error);
1018 return error;
1019 }
1020
1021 /* Add remaining input data */
1022 req.avail_in += (dtemplate[i].inlen + 1) / 2;
1023
1024 error = crypto_decompress_update(tfm, &req);
1025 if (error && (error != -EAGAIN || req.avail_in)) {
1026 pr_err("alg: pcomp: decompression update failed on "
1027 "test %d for %s: error=%d\n", i + 1, algo,
1028 error);
1029 return error;
1030 }
1031
1032 /* Provide remaining output space */
1033 req.avail_out += COMP_BUF_SIZE - dtemplate[i].outlen / 2;
1034
1035 error = crypto_decompress_final(tfm, &req);
1036 if (error && (error != -EAGAIN || req.avail_in)) {
1037 pr_err("alg: pcomp: decompression final failed on "
1038 "test %d for %s: error=%d\n", i + 1, algo,
1039 error);
1040 return error;
1041 }
1042
1043 if (COMP_BUF_SIZE - req.avail_out != dtemplate[i].outlen) {
1044 pr_err("alg: comp: Decompression test %d failed for "
1045 "%s: output len = %d (expected %d)\n", i + 1,
1046 algo, COMP_BUF_SIZE - req.avail_out,
1047 dtemplate[i].outlen);
1048 return -EINVAL;
1049 }
1050
1051 if (memcmp(result, dtemplate[i].output, dtemplate[i].outlen)) {
1052 pr_err("alg: pcomp: Decompression test %d failed for "
1053 "%s\n", i + 1, algo);
1054 hexdump(result, dtemplate[i].outlen);
1055 return -EINVAL;
1056 }
1057 }
1058
1059 return 0;
1060}
1061
901static int alg_test_aead(const struct alg_test_desc *desc, const char *driver, 1062static int alg_test_aead(const struct alg_test_desc *desc, const char *driver,
902 u32 type, u32 mask) 1063 u32 type, u32 mask)
903{ 1064{
@@ -1007,6 +1168,28 @@ static int alg_test_comp(const struct alg_test_desc *desc, const char *driver,
1007 return err; 1168 return err;
1008} 1169}
1009 1170
1171static int alg_test_pcomp(const struct alg_test_desc *desc, const char *driver,
1172 u32 type, u32 mask)
1173{
1174 struct crypto_pcomp *tfm;
1175 int err;
1176
1177 tfm = crypto_alloc_pcomp(driver, type, mask);
1178 if (IS_ERR(tfm)) {
1179 pr_err("alg: pcomp: Failed to load transform for %s: %ld\n",
1180 driver, PTR_ERR(tfm));
1181 return PTR_ERR(tfm);
1182 }
1183
1184 err = test_pcomp(tfm, desc->suite.pcomp.comp.vecs,
1185 desc->suite.pcomp.decomp.vecs,
1186 desc->suite.pcomp.comp.count,
1187 desc->suite.pcomp.decomp.count);
1188
1189 crypto_free_pcomp(tfm);
1190 return err;
1191}
1192
1010static int alg_test_hash(const struct alg_test_desc *desc, const char *driver, 1193static int alg_test_hash(const struct alg_test_desc *desc, const char *driver,
1011 u32 type, u32 mask) 1194 u32 type, u32 mask)
1012{ 1195{
@@ -1835,6 +2018,21 @@ static const struct alg_test_desc alg_test_descs[] = {
1835 } 2018 }
1836 } 2019 }
1837 } 2020 }
2021 }, {
2022 .alg = "zlib",
2023 .test = alg_test_pcomp,
2024 .suite = {
2025 .pcomp = {
2026 .comp = {
2027 .vecs = zlib_comp_tv_template,
2028 .count = ZLIB_COMP_TEST_VECTORS
2029 },
2030 .decomp = {
2031 .vecs = zlib_decomp_tv_template,
2032 .count = ZLIB_DECOMP_TEST_VECTORS
2033 }
2034 }
2035 }
1838 } 2036 }
1839}; 2037};
1840 2038
diff --git a/crypto/testmgr.h b/crypto/testmgr.h
index 132953e144d3..526f00a9c72f 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -15,6 +15,11 @@
15#ifndef _CRYPTO_TESTMGR_H 15#ifndef _CRYPTO_TESTMGR_H
16#define _CRYPTO_TESTMGR_H 16#define _CRYPTO_TESTMGR_H
17 17
18#include <linux/netlink.h>
19#include <linux/zlib.h>
20
21#include <crypto/compress.h>
22
18#define MAX_DIGEST_SIZE 64 23#define MAX_DIGEST_SIZE 64
19#define MAX_TAP 8 24#define MAX_TAP 8
20 25
@@ -8347,10 +8352,19 @@ struct comp_testvec {
8347 char output[COMP_BUF_SIZE]; 8352 char output[COMP_BUF_SIZE];
8348}; 8353};
8349 8354
8355struct pcomp_testvec {
8356 void *params;
8357 unsigned int paramsize;
8358 int inlen, outlen;
8359 char input[COMP_BUF_SIZE];
8360 char output[COMP_BUF_SIZE];
8361};
8362
8350/* 8363/*
8351 * Deflate test vectors (null-terminated strings). 8364 * Deflate test vectors (null-terminated strings).
8352 * Params: winbits=-11, Z_DEFAULT_COMPRESSION, MAX_MEM_LEVEL. 8365 * Params: winbits=-11, Z_DEFAULT_COMPRESSION, MAX_MEM_LEVEL.
8353 */ 8366 */
8367
8354#define DEFLATE_COMP_TEST_VECTORS 2 8368#define DEFLATE_COMP_TEST_VECTORS 2
8355#define DEFLATE_DECOMP_TEST_VECTORS 2 8369#define DEFLATE_DECOMP_TEST_VECTORS 2
8356 8370
@@ -8426,6 +8440,139 @@ static struct comp_testvec deflate_decomp_tv_template[] = {
8426 }, 8440 },
8427}; 8441};
8428 8442
8443#define ZLIB_COMP_TEST_VECTORS 2
8444#define ZLIB_DECOMP_TEST_VECTORS 2
8445
8446static const struct {
8447 struct nlattr nla;
8448 int val;
8449} deflate_comp_params[] = {
8450 {
8451 .nla = {
8452 .nla_len = NLA_HDRLEN + sizeof(int),
8453 .nla_type = ZLIB_COMP_LEVEL,
8454 },
8455 .val = Z_DEFAULT_COMPRESSION,
8456 }, {
8457 .nla = {
8458 .nla_len = NLA_HDRLEN + sizeof(int),
8459 .nla_type = ZLIB_COMP_METHOD,
8460 },
8461 .val = Z_DEFLATED,
8462 }, {
8463 .nla = {
8464 .nla_len = NLA_HDRLEN + sizeof(int),
8465 .nla_type = ZLIB_COMP_WINDOWBITS,
8466 },
8467 .val = -11,
8468 }, {
8469 .nla = {
8470 .nla_len = NLA_HDRLEN + sizeof(int),
8471 .nla_type = ZLIB_COMP_MEMLEVEL,
8472 },
8473 .val = MAX_MEM_LEVEL,
8474 }, {
8475 .nla = {
8476 .nla_len = NLA_HDRLEN + sizeof(int),
8477 .nla_type = ZLIB_COMP_STRATEGY,
8478 },
8479 .val = Z_DEFAULT_STRATEGY,
8480 }
8481};
8482
8483static const struct {
8484 struct nlattr nla;
8485 int val;
8486} deflate_decomp_params[] = {
8487 {
8488 .nla = {
8489 .nla_len = NLA_HDRLEN + sizeof(int),
8490 .nla_type = ZLIB_DECOMP_WINDOWBITS,
8491 },
8492 .val = -11,
8493 }
8494};
8495
8496static struct pcomp_testvec zlib_comp_tv_template[] = {
8497 {
8498 .params = &deflate_comp_params,
8499 .paramsize = sizeof(deflate_comp_params),
8500 .inlen = 70,
8501 .outlen = 38,
8502 .input = "Join us now and share the software "
8503 "Join us now and share the software ",
8504 .output = "\xf3\xca\xcf\xcc\x53\x28\x2d\x56"
8505 "\xc8\xcb\x2f\x57\x48\xcc\x4b\x51"
8506 "\x28\xce\x48\x2c\x4a\x55\x28\xc9"
8507 "\x48\x55\x28\xce\x4f\x2b\x29\x07"
8508 "\x71\xbc\x08\x2b\x01\x00",
8509 }, {
8510 .params = &deflate_comp_params,
8511 .paramsize = sizeof(deflate_comp_params),
8512 .inlen = 191,
8513 .outlen = 122,
8514 .input = "This document describes a compression method based on the DEFLATE"
8515 "compression algorithm. This document defines the application of "
8516 "the DEFLATE algorithm to the IP Payload Compression Protocol.",
8517 .output = "\x5d\x8d\x31\x0e\xc2\x30\x10\x04"
8518 "\xbf\xb2\x2f\xc8\x1f\x10\x04\x09"
8519 "\x89\xc2\x85\x3f\x70\xb1\x2f\xf8"
8520 "\x24\xdb\x67\xd9\x47\xc1\xef\x49"
8521 "\x68\x12\x51\xae\x76\x67\xd6\x27"
8522 "\x19\x88\x1a\xde\x85\xab\x21\xf2"
8523 "\x08\x5d\x16\x1e\x20\x04\x2d\xad"
8524 "\xf3\x18\xa2\x15\x85\x2d\x69\xc4"
8525 "\x42\x83\x23\xb6\x6c\x89\x71\x9b"
8526 "\xef\xcf\x8b\x9f\xcf\x33\xca\x2f"
8527 "\xed\x62\xa9\x4c\x80\xff\x13\xaf"
8528 "\x52\x37\xed\x0e\x52\x6b\x59\x02"
8529 "\xd9\x4e\xe8\x7a\x76\x1d\x02\x98"
8530 "\xfe\x8a\x87\x83\xa3\x4f\x56\x8a"
8531 "\xb8\x9e\x8e\x5c\x57\xd3\xa0\x79"
8532 "\xfa\x02",
8533 },
8534};
8535
8536static struct pcomp_testvec zlib_decomp_tv_template[] = {
8537 {
8538 .params = &deflate_decomp_params,
8539 .paramsize = sizeof(deflate_decomp_params),
8540 .inlen = 122,
8541 .outlen = 191,
8542 .input = "\x5d\x8d\x31\x0e\xc2\x30\x10\x04"
8543 "\xbf\xb2\x2f\xc8\x1f\x10\x04\x09"
8544 "\x89\xc2\x85\x3f\x70\xb1\x2f\xf8"
8545 "\x24\xdb\x67\xd9\x47\xc1\xef\x49"
8546 "\x68\x12\x51\xae\x76\x67\xd6\x27"
8547 "\x19\x88\x1a\xde\x85\xab\x21\xf2"
8548 "\x08\x5d\x16\x1e\x20\x04\x2d\xad"
8549 "\xf3\x18\xa2\x15\x85\x2d\x69\xc4"
8550 "\x42\x83\x23\xb6\x6c\x89\x71\x9b"
8551 "\xef\xcf\x8b\x9f\xcf\x33\xca\x2f"
8552 "\xed\x62\xa9\x4c\x80\xff\x13\xaf"
8553 "\x52\x37\xed\x0e\x52\x6b\x59\x02"
8554 "\xd9\x4e\xe8\x7a\x76\x1d\x02\x98"
8555 "\xfe\x8a\x87\x83\xa3\x4f\x56\x8a"
8556 "\xb8\x9e\x8e\x5c\x57\xd3\xa0\x79"
8557 "\xfa\x02",
8558 .output = "This document describes a compression method based on the DEFLATE"
8559 "compression algorithm. This document defines the application of "
8560 "the DEFLATE algorithm to the IP Payload Compression Protocol.",
8561 }, {
8562 .params = &deflate_decomp_params,
8563 .paramsize = sizeof(deflate_decomp_params),
8564 .inlen = 38,
8565 .outlen = 70,
8566 .input = "\xf3\xca\xcf\xcc\x53\x28\x2d\x56"
8567 "\xc8\xcb\x2f\x57\x48\xcc\x4b\x51"
8568 "\x28\xce\x48\x2c\x4a\x55\x28\xc9"
8569 "\x48\x55\x28\xce\x4f\x2b\x29\x07"
8570 "\x71\xbc\x08\x2b\x01\x00",
8571 .output = "Join us now and share the software "
8572 "Join us now and share the software ",
8573 },
8574};
8575
8429/* 8576/*
8430 * LZO test vectors (null-terminated strings). 8577 * LZO test vectors (null-terminated strings).
8431 */ 8578 */
diff --git a/crypto/zlib.c b/crypto/zlib.c
new file mode 100644
index 000000000000..33609bab614e
--- /dev/null
+++ b/crypto/zlib.c
@@ -0,0 +1,378 @@
1/*
2 * Cryptographic API.
3 *
4 * Zlib algorithm
5 *
6 * Copyright 2008 Sony Corporation
7 *
8 * Based on deflate.c, which is
9 * Copyright (c) 2003 James Morris <jmorris@intercode.com.au>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License, or (at your option)
14 * any later version.
15 *
16 * FIXME: deflate transforms will require up to a total of about 436k of kernel
17 * memory on i386 (390k for compression, the rest for decompression), as the
18 * current zlib kernel code uses a worst case pre-allocation system by default.
19 * This needs to be fixed so that the amount of memory required is properly
20 * related to the winbits and memlevel parameters.
21 */
22
23#define pr_fmt(fmt) "%s: " fmt, __func__
24
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/zlib.h>
28#include <linux/vmalloc.h>
29#include <linux/interrupt.h>
30#include <linux/mm.h>
31#include <linux/net.h>
32#include <linux/slab.h>
33
34#include <crypto/internal/compress.h>
35
36#include <net/netlink.h>
37
38
39struct zlib_ctx {
40 struct z_stream_s comp_stream;
41 struct z_stream_s decomp_stream;
42 int decomp_windowBits;
43};
44
45
46static void zlib_comp_exit(struct zlib_ctx *ctx)
47{
48 struct z_stream_s *stream = &ctx->comp_stream;
49
50 if (stream->workspace) {
51 zlib_deflateEnd(stream);
52 vfree(stream->workspace);
53 stream->workspace = NULL;
54 }
55}
56
57static void zlib_decomp_exit(struct zlib_ctx *ctx)
58{
59 struct z_stream_s *stream = &ctx->decomp_stream;
60
61 if (stream->workspace) {
62 zlib_inflateEnd(stream);
63 kfree(stream->workspace);
64 stream->workspace = NULL;
65 }
66}
67
68static int zlib_init(struct crypto_tfm *tfm)
69{
70 return 0;
71}
72
73static void zlib_exit(struct crypto_tfm *tfm)
74{
75 struct zlib_ctx *ctx = crypto_tfm_ctx(tfm);
76
77 zlib_comp_exit(ctx);
78 zlib_decomp_exit(ctx);
79}
80
81
82static int zlib_compress_setup(struct crypto_pcomp *tfm, void *params,
83 unsigned int len)
84{
85 struct zlib_ctx *ctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
86 struct z_stream_s *stream = &ctx->comp_stream;
87 struct nlattr *tb[ZLIB_COMP_MAX + 1];
88 size_t workspacesize;
89 int ret;
90
91 ret = nla_parse(tb, ZLIB_COMP_MAX, params, len, NULL);
92 if (ret)
93 return ret;
94
95 zlib_comp_exit(ctx);
96
97 workspacesize = zlib_deflate_workspacesize();
98 stream->workspace = vmalloc(workspacesize);
99 if (!stream->workspace)
100 return -ENOMEM;
101
102 memset(stream->workspace, 0, workspacesize);
103 ret = zlib_deflateInit2(stream,
104 tb[ZLIB_COMP_LEVEL]
105 ? nla_get_u32(tb[ZLIB_COMP_LEVEL])
106 : Z_DEFAULT_COMPRESSION,
107 tb[ZLIB_COMP_METHOD]
108 ? nla_get_u32(tb[ZLIB_COMP_METHOD])
109 : Z_DEFLATED,
110 tb[ZLIB_COMP_WINDOWBITS]
111 ? nla_get_u32(tb[ZLIB_COMP_WINDOWBITS])
112 : MAX_WBITS,
113 tb[ZLIB_COMP_MEMLEVEL]
114 ? nla_get_u32(tb[ZLIB_COMP_MEMLEVEL])
115 : DEF_MEM_LEVEL,
116 tb[ZLIB_COMP_STRATEGY]
117 ? nla_get_u32(tb[ZLIB_COMP_STRATEGY])
118 : Z_DEFAULT_STRATEGY);
119 if (ret != Z_OK) {
120 vfree(stream->workspace);
121 stream->workspace = NULL;
122 return -EINVAL;
123 }
124
125 return 0;
126}
127
128static int zlib_compress_init(struct crypto_pcomp *tfm)
129{
130 int ret;
131 struct zlib_ctx *dctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
132 struct z_stream_s *stream = &dctx->comp_stream;
133
134 ret = zlib_deflateReset(stream);
135 if (ret != Z_OK)
136 return -EINVAL;
137
138 return 0;
139}
140
141static int zlib_compress_update(struct crypto_pcomp *tfm,
142 struct comp_request *req)
143{
144 int ret;
145 struct zlib_ctx *dctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
146 struct z_stream_s *stream = &dctx->comp_stream;
147
148 pr_debug("avail_in %u, avail_out %u\n", req->avail_in, req->avail_out);
149 stream->next_in = req->next_in;
150 stream->avail_in = req->avail_in;
151 stream->next_out = req->next_out;
152 stream->avail_out = req->avail_out;
153
154 ret = zlib_deflate(stream, Z_NO_FLUSH);
155 switch (ret) {
156 case Z_OK:
157 break;
158
159 case Z_BUF_ERROR:
160 pr_debug("zlib_deflate could not make progress\n");
161 return -EAGAIN;
162
163 default:
164 pr_debug("zlib_deflate failed %d\n", ret);
165 return -EINVAL;
166 }
167
168 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
169 stream->avail_in, stream->avail_out,
170 req->avail_in - stream->avail_in,
171 req->avail_out - stream->avail_out);
172 req->next_in = stream->next_in;
173 req->avail_in = stream->avail_in;
174 req->next_out = stream->next_out;
175 req->avail_out = stream->avail_out;
176 return 0;
177}
178
179static int zlib_compress_final(struct crypto_pcomp *tfm,
180 struct comp_request *req)
181{
182 int ret;
183 struct zlib_ctx *dctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
184 struct z_stream_s *stream = &dctx->comp_stream;
185
186 pr_debug("avail_in %u, avail_out %u\n", req->avail_in, req->avail_out);
187 stream->next_in = req->next_in;
188 stream->avail_in = req->avail_in;
189 stream->next_out = req->next_out;
190 stream->avail_out = req->avail_out;
191
192 ret = zlib_deflate(stream, Z_FINISH);
193 if (ret != Z_STREAM_END) {
194 pr_debug("zlib_deflate failed %d\n", ret);
195 return -EINVAL;
196 }
197
198 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
199 stream->avail_in, stream->avail_out,
200 req->avail_in - stream->avail_in,
201 req->avail_out - stream->avail_out);
202 req->next_in = stream->next_in;
203 req->avail_in = stream->avail_in;
204 req->next_out = stream->next_out;
205 req->avail_out = stream->avail_out;
206 return 0;
207}
208
209
210static int zlib_decompress_setup(struct crypto_pcomp *tfm, void *params,
211 unsigned int len)
212{
213 struct zlib_ctx *ctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
214 struct z_stream_s *stream = &ctx->decomp_stream;
215 struct nlattr *tb[ZLIB_DECOMP_MAX + 1];
216 int ret = 0;
217
218 ret = nla_parse(tb, ZLIB_DECOMP_MAX, params, len, NULL);
219 if (ret)
220 return ret;
221
222 zlib_decomp_exit(ctx);
223
224 ctx->decomp_windowBits = tb[ZLIB_DECOMP_WINDOWBITS]
225 ? nla_get_u32(tb[ZLIB_DECOMP_WINDOWBITS])
226 : DEF_WBITS;
227
228 stream->workspace = kzalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
229 if (!stream->workspace)
230 return -ENOMEM;
231
232 ret = zlib_inflateInit2(stream, ctx->decomp_windowBits);
233 if (ret != Z_OK) {
234 kfree(stream->workspace);
235 stream->workspace = NULL;
236 return -EINVAL;
237 }
238
239 return 0;
240}
241
242static int zlib_decompress_init(struct crypto_pcomp *tfm)
243{
244 int ret;
245 struct zlib_ctx *dctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
246 struct z_stream_s *stream = &dctx->decomp_stream;
247
248 ret = zlib_inflateReset(stream);
249 if (ret != Z_OK)
250 return -EINVAL;
251
252 return 0;
253}
254
255static int zlib_decompress_update(struct crypto_pcomp *tfm,
256 struct comp_request *req)
257{
258 int ret;
259 struct zlib_ctx *dctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
260 struct z_stream_s *stream = &dctx->decomp_stream;
261
262 pr_debug("avail_in %u, avail_out %u\n", req->avail_in, req->avail_out);
263 stream->next_in = req->next_in;
264 stream->avail_in = req->avail_in;
265 stream->next_out = req->next_out;
266 stream->avail_out = req->avail_out;
267
268 ret = zlib_inflate(stream, Z_SYNC_FLUSH);
269 switch (ret) {
270 case Z_OK:
271 case Z_STREAM_END:
272 break;
273
274 case Z_BUF_ERROR:
275 pr_debug("zlib_inflate could not make progress\n");
276 return -EAGAIN;
277
278 default:
279 pr_debug("zlib_inflate failed %d\n", ret);
280 return -EINVAL;
281 }
282
283 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
284 stream->avail_in, stream->avail_out,
285 req->avail_in - stream->avail_in,
286 req->avail_out - stream->avail_out);
287 req->next_in = stream->next_in;
288 req->avail_in = stream->avail_in;
289 req->next_out = stream->next_out;
290 req->avail_out = stream->avail_out;
291 return 0;
292}
293
294static int zlib_decompress_final(struct crypto_pcomp *tfm,
295 struct comp_request *req)
296{
297 int ret;
298 struct zlib_ctx *dctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
299 struct z_stream_s *stream = &dctx->decomp_stream;
300
301 pr_debug("avail_in %u, avail_out %u\n", req->avail_in, req->avail_out);
302 stream->next_in = req->next_in;
303 stream->avail_in = req->avail_in;
304 stream->next_out = req->next_out;
305 stream->avail_out = req->avail_out;
306
307 if (dctx->decomp_windowBits < 0) {
308 ret = zlib_inflate(stream, Z_SYNC_FLUSH);
309 /*
310 * Work around a bug in zlib, which sometimes wants to taste an
311 * extra byte when being used in the (undocumented) raw deflate
312 * mode. (From USAGI).
313 */
314 if (ret == Z_OK && !stream->avail_in && stream->avail_out) {
315 const void *saved_next_in = stream->next_in;
316 u8 zerostuff = 0;
317
318 stream->next_in = &zerostuff;
319 stream->avail_in = 1;
320 ret = zlib_inflate(stream, Z_FINISH);
321 stream->next_in = saved_next_in;
322 stream->avail_in = 0;
323 }
324 } else
325 ret = zlib_inflate(stream, Z_FINISH);
326 if (ret != Z_STREAM_END) {
327 pr_debug("zlib_inflate failed %d\n", ret);
328 return -EINVAL;
329 }
330
331 pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
332 stream->avail_in, stream->avail_out,
333 req->avail_in - stream->avail_in,
334 req->avail_out - stream->avail_out);
335 req->next_in = stream->next_in;
336 req->avail_in = stream->avail_in;
337 req->next_out = stream->next_out;
338 req->avail_out = stream->avail_out;
339 return 0;
340}
341
342
343static struct pcomp_alg zlib_alg = {
344 .compress_setup = zlib_compress_setup,
345 .compress_init = zlib_compress_init,
346 .compress_update = zlib_compress_update,
347 .compress_final = zlib_compress_final,
348 .decompress_setup = zlib_decompress_setup,
349 .decompress_init = zlib_decompress_init,
350 .decompress_update = zlib_decompress_update,
351 .decompress_final = zlib_decompress_final,
352
353 .base = {
354 .cra_name = "zlib",
355 .cra_flags = CRYPTO_ALG_TYPE_PCOMPRESS,
356 .cra_ctxsize = sizeof(struct zlib_ctx),
357 .cra_module = THIS_MODULE,
358 .cra_init = zlib_init,
359 .cra_exit = zlib_exit,
360 }
361};
362
363static int __init zlib_mod_init(void)
364{
365 return crypto_register_pcomp(&zlib_alg);
366}
367
368static void __exit zlib_mod_fini(void)
369{
370 crypto_unregister_pcomp(&zlib_alg);
371}
372
373module_init(zlib_mod_init);
374module_exit(zlib_mod_fini);
375
376MODULE_LICENSE("GPL");
377MODULE_DESCRIPTION("Zlib Compression Algorithm");
378MODULE_AUTHOR("Sony Corporation");
diff --git a/drivers/acpi/dock.c b/drivers/acpi/dock.c
index 35094f230b1e..7af7db1ba8c4 100644
--- a/drivers/acpi/dock.c
+++ b/drivers/acpi/dock.c
@@ -977,7 +977,7 @@ static int dock_add(acpi_handle handle)
977 sizeof(struct dock_station *)); 977 sizeof(struct dock_station *));
978 978
979 /* we want the dock device to send uevents */ 979 /* we want the dock device to send uevents */
980 dock_device->dev.uevent_suppress = 0; 980 dev_set_uevent_suppress(&dock_device->dev, 0);
981 981
982 if (is_dock(handle)) 982 if (is_dock(handle))
983 dock_station->flags |= DOCK_IS_DOCK; 983 dock_station->flags |= DOCK_IS_DOCK;
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index 00c46e0b40e4..3d763fdf99b7 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -210,7 +210,7 @@ int amba_device_register(struct amba_device *dev, struct resource *parent)
210 dev->dev.release = amba_device_release; 210 dev->dev.release = amba_device_release;
211 dev->dev.bus = &amba_bustype; 211 dev->dev.bus = &amba_bustype;
212 dev->dev.dma_mask = &dev->dma_mask; 212 dev->dev.dma_mask = &dev->dma_mask;
213 dev->res.name = dev->dev.bus_id; 213 dev->res.name = dev_name(&dev->dev);
214 214
215 if (!dev->dev.coherent_dma_mask && dev->dma_mask) 215 if (!dev->dev.coherent_dma_mask && dev->dma_mask)
216 dev_warn(&dev->dev, "coherent dma mask is unset\n"); 216 dev_warn(&dev->dev, "coherent dma mask is unset\n");
@@ -294,7 +294,7 @@ static int amba_find_match(struct device *dev, void *data)
294 if (d->parent) 294 if (d->parent)
295 r &= d->parent == dev->parent; 295 r &= d->parent == dev->parent;
296 if (d->busid) 296 if (d->busid)
297 r &= strcmp(dev->bus_id, d->busid) == 0; 297 r &= strcmp(dev_name(dev), d->busid) == 0;
298 298
299 if (r) { 299 if (r) {
300 get_device(dev); 300 get_device(dev);
diff --git a/drivers/ata/ahci.c b/drivers/ata/ahci.c
index 66e012cd3271..788bba2b1e17 100644
--- a/drivers/ata/ahci.c
+++ b/drivers/ata/ahci.c
@@ -404,7 +404,7 @@ static const struct ata_port_info ahci_port_info[] = {
404 /* board_ahci */ 404 /* board_ahci */
405 { 405 {
406 .flags = AHCI_FLAG_COMMON, 406 .flags = AHCI_FLAG_COMMON,
407 .pio_mask = 0x1f, /* pio0-4 */ 407 .pio_mask = ATA_PIO4,
408 .udma_mask = ATA_UDMA6, 408 .udma_mask = ATA_UDMA6,
409 .port_ops = &ahci_ops, 409 .port_ops = &ahci_ops,
410 }, 410 },
@@ -412,7 +412,7 @@ static const struct ata_port_info ahci_port_info[] = {
412 { 412 {
413 AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_PMP), 413 AHCI_HFLAGS (AHCI_HFLAG_NO_NCQ | AHCI_HFLAG_NO_PMP),
414 .flags = AHCI_FLAG_COMMON, 414 .flags = AHCI_FLAG_COMMON,
415 .pio_mask = 0x1f, /* pio0-4 */ 415 .pio_mask = ATA_PIO4,
416 .udma_mask = ATA_UDMA6, 416 .udma_mask = ATA_UDMA6,
417 .port_ops = &ahci_vt8251_ops, 417 .port_ops = &ahci_vt8251_ops,
418 }, 418 },
@@ -420,7 +420,7 @@ static const struct ata_port_info ahci_port_info[] = {
420 { 420 {
421 AHCI_HFLAGS (AHCI_HFLAG_IGN_IRQ_IF_ERR), 421 AHCI_HFLAGS (AHCI_HFLAG_IGN_IRQ_IF_ERR),
422 .flags = AHCI_FLAG_COMMON, 422 .flags = AHCI_FLAG_COMMON,
423 .pio_mask = 0x1f, /* pio0-4 */ 423 .pio_mask = ATA_PIO4,
424 .udma_mask = ATA_UDMA6, 424 .udma_mask = ATA_UDMA6,
425 .port_ops = &ahci_ops, 425 .port_ops = &ahci_ops,
426 }, 426 },
@@ -430,7 +430,7 @@ static const struct ata_port_info ahci_port_info[] = {
430 AHCI_HFLAG_32BIT_ONLY | AHCI_HFLAG_NO_MSI | 430 AHCI_HFLAG_32BIT_ONLY | AHCI_HFLAG_NO_MSI |
431 AHCI_HFLAG_SECT255), 431 AHCI_HFLAG_SECT255),
432 .flags = AHCI_FLAG_COMMON, 432 .flags = AHCI_FLAG_COMMON,
433 .pio_mask = 0x1f, /* pio0-4 */ 433 .pio_mask = ATA_PIO4,
434 .udma_mask = ATA_UDMA6, 434 .udma_mask = ATA_UDMA6,
435 .port_ops = &ahci_sb600_ops, 435 .port_ops = &ahci_sb600_ops,
436 }, 436 },
@@ -440,7 +440,7 @@ static const struct ata_port_info ahci_port_info[] = {
440 AHCI_HFLAG_MV_PATA | AHCI_HFLAG_NO_PMP), 440 AHCI_HFLAG_MV_PATA | AHCI_HFLAG_NO_PMP),
441 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 441 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
442 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA, 442 ATA_FLAG_MMIO | ATA_FLAG_PIO_DMA,
443 .pio_mask = 0x1f, /* pio0-4 */ 443 .pio_mask = ATA_PIO4,
444 .udma_mask = ATA_UDMA6, 444 .udma_mask = ATA_UDMA6,
445 .port_ops = &ahci_ops, 445 .port_ops = &ahci_ops,
446 }, 446 },
@@ -448,7 +448,7 @@ static const struct ata_port_info ahci_port_info[] = {
448 { 448 {
449 AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL), 449 AHCI_HFLAGS (AHCI_HFLAG_IGN_SERR_INTERNAL),
450 .flags = AHCI_FLAG_COMMON, 450 .flags = AHCI_FLAG_COMMON,
451 .pio_mask = 0x1f, /* pio0-4 */ 451 .pio_mask = ATA_PIO4,
452 .udma_mask = ATA_UDMA6, 452 .udma_mask = ATA_UDMA6,
453 .port_ops = &ahci_sb600_ops, 453 .port_ops = &ahci_sb600_ops,
454 }, 454 },
@@ -456,7 +456,7 @@ static const struct ata_port_info ahci_port_info[] = {
456 { 456 {
457 AHCI_HFLAGS (AHCI_HFLAG_YES_NCQ), 457 AHCI_HFLAGS (AHCI_HFLAG_YES_NCQ),
458 .flags = AHCI_FLAG_COMMON, 458 .flags = AHCI_FLAG_COMMON,
459 .pio_mask = 0x1f, /* pio0-4 */ 459 .pio_mask = ATA_PIO4,
460 .udma_mask = ATA_UDMA6, 460 .udma_mask = ATA_UDMA6,
461 .port_ops = &ahci_ops, 461 .port_ops = &ahci_ops,
462 }, 462 },
@@ -464,7 +464,7 @@ static const struct ata_port_info ahci_port_info[] = {
464 { 464 {
465 AHCI_HFLAGS (AHCI_HFLAG_NO_PMP), 465 AHCI_HFLAGS (AHCI_HFLAG_NO_PMP),
466 .flags = AHCI_FLAG_COMMON, 466 .flags = AHCI_FLAG_COMMON,
467 .pio_mask = 0x1f, /* pio0-4 */ 467 .pio_mask = ATA_PIO4,
468 .udma_mask = ATA_UDMA6, 468 .udma_mask = ATA_UDMA6,
469 .port_ops = &ahci_ops, 469 .port_ops = &ahci_ops,
470 }, 470 },
@@ -1348,7 +1348,7 @@ static ssize_t ahci_transmit_led_message(struct ata_port *ap, u32 state,
1348 writel(message[1], mmio + hpriv->em_loc+4); 1348 writel(message[1], mmio + hpriv->em_loc+4);
1349 1349
1350 /* save off new led state for port/slot */ 1350 /* save off new led state for port/slot */
1351 emp->led_state = message[1]; 1351 emp->led_state = state;
1352 1352
1353 /* 1353 /*
1354 * tell hardware to transmit the message 1354 * tell hardware to transmit the message
@@ -2565,6 +2565,15 @@ static bool ahci_broken_system_poweroff(struct pci_dev *pdev)
2565 /* PCI slot number of the controller */ 2565 /* PCI slot number of the controller */
2566 .driver_data = (void *)0x1FUL, 2566 .driver_data = (void *)0x1FUL,
2567 }, 2567 },
2568 {
2569 .ident = "HP Compaq 6720s",
2570 .matches = {
2571 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
2572 DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6720s"),
2573 },
2574 /* PCI slot number of the controller */
2575 .driver_data = (void *)0x1FUL,
2576 },
2568 2577
2569 { } /* terminate list */ 2578 { } /* terminate list */
2570 }; 2579 };
@@ -2647,8 +2656,8 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2647 if (board_id == board_ahci_sb700 && pdev->revision >= 0x40) 2656 if (board_id == board_ahci_sb700 && pdev->revision >= 0x40)
2648 hpriv->flags &= ~AHCI_HFLAG_IGN_SERR_INTERNAL; 2657 hpriv->flags &= ~AHCI_HFLAG_IGN_SERR_INTERNAL;
2649 2658
2650 if ((hpriv->flags & AHCI_HFLAG_NO_MSI) || pci_enable_msi(pdev)) 2659 if (!(hpriv->flags & AHCI_HFLAG_NO_MSI))
2651 pci_intx(pdev, 1); 2660 pci_enable_msi(pdev);
2652 2661
2653 /* save initial config */ 2662 /* save initial config */
2654 ahci_save_initial_config(pdev, hpriv); 2663 ahci_save_initial_config(pdev, hpriv);
diff --git a/drivers/ata/ata_generic.c b/drivers/ata/ata_generic.c
index dc48a6398abe..ecfd22b4f1ce 100644
--- a/drivers/ata/ata_generic.c
+++ b/drivers/ata/ata_generic.c
@@ -118,8 +118,8 @@ static int ata_generic_init_one(struct pci_dev *dev, const struct pci_device_id
118 u16 command; 118 u16 command;
119 static const struct ata_port_info info = { 119 static const struct ata_port_info info = {
120 .flags = ATA_FLAG_SLAVE_POSS, 120 .flags = ATA_FLAG_SLAVE_POSS,
121 .pio_mask = 0x1f, 121 .pio_mask = ATA_PIO4,
122 .mwdma_mask = 0x07, 122 .mwdma_mask = ATA_MWDMA2,
123 .udma_mask = ATA_UDMA5, 123 .udma_mask = ATA_UDMA5,
124 .port_ops = &generic_port_ops 124 .port_ops = &generic_port_ops
125 }; 125 };
diff --git a/drivers/ata/ata_piix.c b/drivers/ata/ata_piix.c
index ef8b30d577bd..e5cbe80ce172 100644
--- a/drivers/ata/ata_piix.c
+++ b/drivers/ata/ata_piix.c
@@ -446,34 +446,34 @@ static struct ata_port_info piix_port_info[] = {
446 [piix_pata_mwdma] = /* PIIX3 MWDMA only */ 446 [piix_pata_mwdma] = /* PIIX3 MWDMA only */
447 { 447 {
448 .flags = PIIX_PATA_FLAGS, 448 .flags = PIIX_PATA_FLAGS,
449 .pio_mask = 0x1f, /* pio0-4 */ 449 .pio_mask = ATA_PIO4,
450 .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */ 450 .mwdma_mask = ATA_MWDMA12_ONLY, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
451 .port_ops = &piix_pata_ops, 451 .port_ops = &piix_pata_ops,
452 }, 452 },
453 453
454 [piix_pata_33] = /* PIIX4 at 33MHz */ 454 [piix_pata_33] = /* PIIX4 at 33MHz */
455 { 455 {
456 .flags = PIIX_PATA_FLAGS, 456 .flags = PIIX_PATA_FLAGS,
457 .pio_mask = 0x1f, /* pio0-4 */ 457 .pio_mask = ATA_PIO4,
458 .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */ 458 .mwdma_mask = ATA_MWDMA12_ONLY, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
459 .udma_mask = ATA_UDMA_MASK_40C, 459 .udma_mask = ATA_UDMA2,
460 .port_ops = &piix_pata_ops, 460 .port_ops = &piix_pata_ops,
461 }, 461 },
462 462
463 [ich_pata_33] = /* ICH0 - ICH at 33Mhz*/ 463 [ich_pata_33] = /* ICH0 - ICH at 33Mhz*/
464 { 464 {
465 .flags = PIIX_PATA_FLAGS, 465 .flags = PIIX_PATA_FLAGS,
466 .pio_mask = 0x1f, /* pio 0-4 */ 466 .pio_mask = ATA_PIO4,
467 .mwdma_mask = 0x06, /* Check: maybe 0x07 */ 467 .mwdma_mask = ATA_MWDMA12_ONLY, /* Check: maybe MWDMA0 is ok */
468 .udma_mask = ATA_UDMA2, /* UDMA33 */ 468 .udma_mask = ATA_UDMA2,
469 .port_ops = &ich_pata_ops, 469 .port_ops = &ich_pata_ops,
470 }, 470 },
471 471
472 [ich_pata_66] = /* ICH controllers up to 66MHz */ 472 [ich_pata_66] = /* ICH controllers up to 66MHz */
473 { 473 {
474 .flags = PIIX_PATA_FLAGS, 474 .flags = PIIX_PATA_FLAGS,
475 .pio_mask = 0x1f, /* pio 0-4 */ 475 .pio_mask = ATA_PIO4,
476 .mwdma_mask = 0x06, /* MWDMA0 is broken on chip */ 476 .mwdma_mask = ATA_MWDMA12_ONLY, /* MWDMA0 is broken on chip */
477 .udma_mask = ATA_UDMA4, 477 .udma_mask = ATA_UDMA4,
478 .port_ops = &ich_pata_ops, 478 .port_ops = &ich_pata_ops,
479 }, 479 },
@@ -481,17 +481,17 @@ static struct ata_port_info piix_port_info[] = {
481 [ich_pata_100] = 481 [ich_pata_100] =
482 { 482 {
483 .flags = PIIX_PATA_FLAGS | PIIX_FLAG_CHECKINTR, 483 .flags = PIIX_PATA_FLAGS | PIIX_FLAG_CHECKINTR,
484 .pio_mask = 0x1f, /* pio0-4 */ 484 .pio_mask = ATA_PIO4,
485 .mwdma_mask = 0x06, /* mwdma1-2 */ 485 .mwdma_mask = ATA_MWDMA12_ONLY,
486 .udma_mask = ATA_UDMA5, /* udma0-5 */ 486 .udma_mask = ATA_UDMA5,
487 .port_ops = &ich_pata_ops, 487 .port_ops = &ich_pata_ops,
488 }, 488 },
489 489
490 [ich5_sata] = 490 [ich5_sata] =
491 { 491 {
492 .flags = PIIX_SATA_FLAGS, 492 .flags = PIIX_SATA_FLAGS,
493 .pio_mask = 0x1f, /* pio0-4 */ 493 .pio_mask = ATA_PIO4,
494 .mwdma_mask = 0x07, /* mwdma0-2 */ 494 .mwdma_mask = ATA_MWDMA2,
495 .udma_mask = ATA_UDMA6, 495 .udma_mask = ATA_UDMA6,
496 .port_ops = &piix_sata_ops, 496 .port_ops = &piix_sata_ops,
497 }, 497 },
@@ -499,8 +499,8 @@ static struct ata_port_info piix_port_info[] = {
499 [ich6_sata] = 499 [ich6_sata] =
500 { 500 {
501 .flags = PIIX_SATA_FLAGS, 501 .flags = PIIX_SATA_FLAGS,
502 .pio_mask = 0x1f, /* pio0-4 */ 502 .pio_mask = ATA_PIO4,
503 .mwdma_mask = 0x07, /* mwdma0-2 */ 503 .mwdma_mask = ATA_MWDMA2,
504 .udma_mask = ATA_UDMA6, 504 .udma_mask = ATA_UDMA6,
505 .port_ops = &piix_sata_ops, 505 .port_ops = &piix_sata_ops,
506 }, 506 },
@@ -508,8 +508,8 @@ static struct ata_port_info piix_port_info[] = {
508 [ich6m_sata] = 508 [ich6m_sata] =
509 { 509 {
510 .flags = PIIX_SATA_FLAGS, 510 .flags = PIIX_SATA_FLAGS,
511 .pio_mask = 0x1f, /* pio0-4 */ 511 .pio_mask = ATA_PIO4,
512 .mwdma_mask = 0x07, /* mwdma0-2 */ 512 .mwdma_mask = ATA_MWDMA2,
513 .udma_mask = ATA_UDMA6, 513 .udma_mask = ATA_UDMA6,
514 .port_ops = &piix_sata_ops, 514 .port_ops = &piix_sata_ops,
515 }, 515 },
@@ -517,8 +517,8 @@ static struct ata_port_info piix_port_info[] = {
517 [ich8_sata] = 517 [ich8_sata] =
518 { 518 {
519 .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SIDPR, 519 .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SIDPR,
520 .pio_mask = 0x1f, /* pio0-4 */ 520 .pio_mask = ATA_PIO4,
521 .mwdma_mask = 0x07, /* mwdma0-2 */ 521 .mwdma_mask = ATA_MWDMA2,
522 .udma_mask = ATA_UDMA6, 522 .udma_mask = ATA_UDMA6,
523 .port_ops = &piix_sata_ops, 523 .port_ops = &piix_sata_ops,
524 }, 524 },
@@ -526,8 +526,8 @@ static struct ata_port_info piix_port_info[] = {
526 [ich8_2port_sata] = 526 [ich8_2port_sata] =
527 { 527 {
528 .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SIDPR, 528 .flags = PIIX_SATA_FLAGS | PIIX_FLAG_SIDPR,
529 .pio_mask = 0x1f, /* pio0-4 */ 529 .pio_mask = ATA_PIO4,
530 .mwdma_mask = 0x07, /* mwdma0-2 */ 530 .mwdma_mask = ATA_MWDMA2,
531 .udma_mask = ATA_UDMA6, 531 .udma_mask = ATA_UDMA6,
532 .port_ops = &piix_sata_ops, 532 .port_ops = &piix_sata_ops,
533 }, 533 },
@@ -535,8 +535,8 @@ static struct ata_port_info piix_port_info[] = {
535 [tolapai_sata] = 535 [tolapai_sata] =
536 { 536 {
537 .flags = PIIX_SATA_FLAGS, 537 .flags = PIIX_SATA_FLAGS,
538 .pio_mask = 0x1f, /* pio0-4 */ 538 .pio_mask = ATA_PIO4,
539 .mwdma_mask = 0x07, /* mwdma0-2 */ 539 .mwdma_mask = ATA_MWDMA2,
540 .udma_mask = ATA_UDMA6, 540 .udma_mask = ATA_UDMA6,
541 .port_ops = &piix_sata_ops, 541 .port_ops = &piix_sata_ops,
542 }, 542 },
@@ -544,8 +544,8 @@ static struct ata_port_info piix_port_info[] = {
544 [ich8m_apple_sata] = 544 [ich8m_apple_sata] =
545 { 545 {
546 .flags = PIIX_SATA_FLAGS, 546 .flags = PIIX_SATA_FLAGS,
547 .pio_mask = 0x1f, /* pio0-4 */ 547 .pio_mask = ATA_PIO4,
548 .mwdma_mask = 0x07, /* mwdma0-2 */ 548 .mwdma_mask = ATA_MWDMA2,
549 .udma_mask = ATA_UDMA6, 549 .udma_mask = ATA_UDMA6,
550 .port_ops = &piix_sata_ops, 550 .port_ops = &piix_sata_ops,
551 }, 551 },
@@ -553,9 +553,9 @@ static struct ata_port_info piix_port_info[] = {
553 [piix_pata_vmw] = 553 [piix_pata_vmw] =
554 { 554 {
555 .flags = PIIX_PATA_FLAGS, 555 .flags = PIIX_PATA_FLAGS,
556 .pio_mask = 0x1f, /* pio0-4 */ 556 .pio_mask = ATA_PIO4,
557 .mwdma_mask = 0x06, /* mwdma1-2 ?? CHECK 0 should be ok but slow */ 557 .mwdma_mask = ATA_MWDMA12_ONLY, /* mwdma1-2 ?? CHECK 0 should be ok but slow */
558 .udma_mask = ATA_UDMA_MASK_40C, 558 .udma_mask = ATA_UDMA2,
559 .port_ops = &piix_vmw_ops, 559 .port_ops = &piix_vmw_ops,
560 }, 560 },
561 561
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 060bcd601f57..e7ea77cf6069 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -57,6 +57,7 @@
57#include <linux/scatterlist.h> 57#include <linux/scatterlist.h>
58#include <linux/io.h> 58#include <linux/io.h>
59#include <linux/async.h> 59#include <linux/async.h>
60#include <linux/log2.h>
60#include <scsi/scsi.h> 61#include <scsi/scsi.h>
61#include <scsi/scsi_cmnd.h> 62#include <scsi/scsi_cmnd.h>
62#include <scsi/scsi_host.h> 63#include <scsi/scsi_host.h>
@@ -2389,6 +2390,7 @@ int ata_dev_configure(struct ata_device *dev)
2389 dev->cylinders = 0; 2390 dev->cylinders = 0;
2390 dev->heads = 0; 2391 dev->heads = 0;
2391 dev->sectors = 0; 2392 dev->sectors = 0;
2393 dev->multi_count = 0;
2392 2394
2393 /* 2395 /*
2394 * common ATA, ATAPI feature tests 2396 * common ATA, ATAPI feature tests
@@ -2426,8 +2428,15 @@ int ata_dev_configure(struct ata_device *dev)
2426 2428
2427 dev->n_sectors = ata_id_n_sectors(id); 2429 dev->n_sectors = ata_id_n_sectors(id);
2428 2430
2429 if (dev->id[59] & 0x100) 2431 /* get current R/W Multiple count setting */
2430 dev->multi_count = dev->id[59] & 0xff; 2432 if ((dev->id[47] >> 8) == 0x80 && (dev->id[59] & 0x100)) {
2433 unsigned int max = dev->id[47] & 0xff;
2434 unsigned int cnt = dev->id[59] & 0xff;
2435 /* only recognize/allow powers of two here */
2436 if (is_power_of_2(max) && is_power_of_2(cnt))
2437 if (cnt <= max)
2438 dev->multi_count = cnt;
2439 }
2431 2440
2432 if (ata_id_has_lba(id)) { 2441 if (ata_id_has_lba(id)) {
2433 const char *lba_desc; 2442 const char *lba_desc;
@@ -6709,6 +6718,7 @@ EXPORT_SYMBOL_GPL(ata_id_c_string);
6709EXPORT_SYMBOL_GPL(ata_do_dev_read_id); 6718EXPORT_SYMBOL_GPL(ata_do_dev_read_id);
6710EXPORT_SYMBOL_GPL(ata_scsi_simulate); 6719EXPORT_SYMBOL_GPL(ata_scsi_simulate);
6711 6720
6721EXPORT_SYMBOL_GPL(ata_pio_queue_task);
6712EXPORT_SYMBOL_GPL(ata_pio_need_iordy); 6722EXPORT_SYMBOL_GPL(ata_pio_need_iordy);
6713EXPORT_SYMBOL_GPL(ata_timing_find_mode); 6723EXPORT_SYMBOL_GPL(ata_timing_find_mode);
6714EXPORT_SYMBOL_GPL(ata_timing_compute); 6724EXPORT_SYMBOL_GPL(ata_timing_compute);
diff --git a/drivers/ata/libata-eh.c b/drivers/ata/libata-eh.c
index ea890911d4fa..01831312c360 100644
--- a/drivers/ata/libata-eh.c
+++ b/drivers/ata/libata-eh.c
@@ -547,7 +547,7 @@ void ata_scsi_error(struct Scsi_Host *host)
547 547
548 /* For new EH, all qcs are finished in one of three ways - 548 /* For new EH, all qcs are finished in one of three ways -
549 * normal completion, error completion, and SCSI timeout. 549 * normal completion, error completion, and SCSI timeout.
550 * Both cmpletions can race against SCSI timeout. When normal 550 * Both completions can race against SCSI timeout. When normal
551 * completion wins, the qc never reaches EH. When error 551 * completion wins, the qc never reaches EH. When error
552 * completion wins, the qc has ATA_QCFLAG_FAILED set. 552 * completion wins, the qc has ATA_QCFLAG_FAILED set.
553 * 553 *
@@ -562,7 +562,19 @@ void ata_scsi_error(struct Scsi_Host *host)
562 int nr_timedout = 0; 562 int nr_timedout = 0;
563 563
564 spin_lock_irqsave(ap->lock, flags); 564 spin_lock_irqsave(ap->lock, flags);
565 565
566 /* This must occur under the ap->lock as we don't want
567 a polled recovery to race the real interrupt handler
568
569 The lost_interrupt handler checks for any completed but
570 non-notified command and completes much like an IRQ handler.
571
572 We then fall into the error recovery code which will treat
573 this as if normal completion won the race */
574
575 if (ap->ops->lost_interrupt)
576 ap->ops->lost_interrupt(ap);
577
566 list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) { 578 list_for_each_entry_safe(scmd, tmp, &host->eh_cmd_q, eh_entry) {
567 struct ata_queued_cmd *qc; 579 struct ata_queued_cmd *qc;
568 580
@@ -606,6 +618,9 @@ void ata_scsi_error(struct Scsi_Host *host)
606 ap->eh_tries = ATA_EH_MAX_TRIES; 618 ap->eh_tries = ATA_EH_MAX_TRIES;
607 } else 619 } else
608 spin_unlock_wait(ap->lock); 620 spin_unlock_wait(ap->lock);
621
622 /* If we timed raced normal completion and there is nothing to
623 recover nr_timedout == 0 why exactly are we doing error recovery ? */
609 624
610 repeat: 625 repeat:
611 /* invoke error handler */ 626 /* invoke error handler */
diff --git a/drivers/ata/libata-sff.c b/drivers/ata/libata-sff.c
index f93dc029dfde..8332e97a9de3 100644
--- a/drivers/ata/libata-sff.c
+++ b/drivers/ata/libata-sff.c
@@ -52,6 +52,7 @@ const struct ata_port_operations ata_sff_port_ops = {
52 .softreset = ata_sff_softreset, 52 .softreset = ata_sff_softreset,
53 .hardreset = sata_sff_hardreset, 53 .hardreset = sata_sff_hardreset,
54 .postreset = ata_sff_postreset, 54 .postreset = ata_sff_postreset,
55 .drain_fifo = ata_sff_drain_fifo,
55 .error_handler = ata_sff_error_handler, 56 .error_handler = ata_sff_error_handler,
56 .post_internal_cmd = ata_sff_post_internal_cmd, 57 .post_internal_cmd = ata_sff_post_internal_cmd,
57 58
@@ -64,6 +65,8 @@ const struct ata_port_operations ata_sff_port_ops = {
64 .sff_irq_on = ata_sff_irq_on, 65 .sff_irq_on = ata_sff_irq_on,
65 .sff_irq_clear = ata_sff_irq_clear, 66 .sff_irq_clear = ata_sff_irq_clear,
66 67
68 .lost_interrupt = ata_sff_lost_interrupt,
69
67 .port_start = ata_sff_port_start, 70 .port_start = ata_sff_port_start,
68}; 71};
69EXPORT_SYMBOL_GPL(ata_sff_port_ops); 72EXPORT_SYMBOL_GPL(ata_sff_port_ops);
@@ -1646,7 +1649,7 @@ EXPORT_SYMBOL_GPL(ata_sff_qc_fill_rtf);
1646 * RETURNS: 1649 * RETURNS:
1647 * One if interrupt was handled, zero if not (shared irq). 1650 * One if interrupt was handled, zero if not (shared irq).
1648 */ 1651 */
1649inline unsigned int ata_sff_host_intr(struct ata_port *ap, 1652unsigned int ata_sff_host_intr(struct ata_port *ap,
1650 struct ata_queued_cmd *qc) 1653 struct ata_queued_cmd *qc)
1651{ 1654{
1652 struct ata_eh_info *ehi = &ap->link.eh_info; 1655 struct ata_eh_info *ehi = &ap->link.eh_info;
@@ -1775,6 +1778,48 @@ irqreturn_t ata_sff_interrupt(int irq, void *dev_instance)
1775EXPORT_SYMBOL_GPL(ata_sff_interrupt); 1778EXPORT_SYMBOL_GPL(ata_sff_interrupt);
1776 1779
1777/** 1780/**
1781 * ata_sff_lost_interrupt - Check for an apparent lost interrupt
1782 * @ap: port that appears to have timed out
1783 *
1784 * Called from the libata error handlers when the core code suspects
1785 * an interrupt has been lost. If it has complete anything we can and
1786 * then return. Interface must support altstatus for this faster
1787 * recovery to occur.
1788 *
1789 * Locking:
1790 * Caller holds host lock
1791 */
1792
1793void ata_sff_lost_interrupt(struct ata_port *ap)
1794{
1795 u8 status;
1796 struct ata_queued_cmd *qc;
1797
1798 /* Only one outstanding command per SFF channel */
1799 qc = ata_qc_from_tag(ap, ap->link.active_tag);
1800 /* Check we have a live one.. */
1801 if (qc == NULL || !(qc->flags & ATA_QCFLAG_ACTIVE))
1802 return;
1803 /* We cannot lose an interrupt on a polled command */
1804 if (qc->tf.flags & ATA_TFLAG_POLLING)
1805 return;
1806 /* See if the controller thinks it is still busy - if so the command
1807 isn't a lost IRQ but is still in progress */
1808 status = ata_sff_altstatus(ap);
1809 if (status & ATA_BUSY)
1810 return;
1811
1812 /* There was a command running, we are no longer busy and we have
1813 no interrupt. */
1814 ata_port_printk(ap, KERN_WARNING, "lost interrupt (Status 0x%x)\n",
1815 status);
1816 /* Run the host interrupt logic as if the interrupt had not been
1817 lost */
1818 ata_sff_host_intr(ap, qc);
1819}
1820EXPORT_SYMBOL_GPL(ata_sff_lost_interrupt);
1821
1822/**
1778 * ata_sff_freeze - Freeze SFF controller port 1823 * ata_sff_freeze - Freeze SFF controller port
1779 * @ap: port to freeze 1824 * @ap: port to freeze
1780 * 1825 *
@@ -2199,6 +2244,39 @@ void ata_sff_postreset(struct ata_link *link, unsigned int *classes)
2199EXPORT_SYMBOL_GPL(ata_sff_postreset); 2244EXPORT_SYMBOL_GPL(ata_sff_postreset);
2200 2245
2201/** 2246/**
2247 * ata_sff_drain_fifo - Stock FIFO drain logic for SFF controllers
2248 * @qc: command
2249 *
2250 * Drain the FIFO and device of any stuck data following a command
2251 * failing to complete. In some cases this is neccessary before a
2252 * reset will recover the device.
2253 *
2254 */
2255
2256void ata_sff_drain_fifo(struct ata_queued_cmd *qc)
2257{
2258 int count;
2259 struct ata_port *ap;
2260
2261 /* We only need to flush incoming data when a command was running */
2262 if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE)
2263 return;
2264
2265 ap = qc->ap;
2266 /* Drain up to 64K of data before we give up this recovery method */
2267 for (count = 0; (ap->ops->sff_check_status(ap) & ATA_DRQ)
2268 && count < 32768; count++)
2269 ioread16(ap->ioaddr.data_addr);
2270
2271 /* Can become DEBUG later */
2272 if (count)
2273 ata_port_printk(ap, KERN_DEBUG,
2274 "drained %d bytes to clear DRQ.\n", count);
2275
2276}
2277EXPORT_SYMBOL_GPL(ata_sff_drain_fifo);
2278
2279/**
2202 * ata_sff_error_handler - Stock error handler for BMDMA controller 2280 * ata_sff_error_handler - Stock error handler for BMDMA controller
2203 * @ap: port to handle error for 2281 * @ap: port to handle error for
2204 * 2282 *
@@ -2239,7 +2317,8 @@ void ata_sff_error_handler(struct ata_port *ap)
2239 * really a timeout event, adjust error mask and 2317 * really a timeout event, adjust error mask and
2240 * cancel frozen state. 2318 * cancel frozen state.
2241 */ 2319 */
2242 if (qc->err_mask == AC_ERR_TIMEOUT && (host_stat & ATA_DMA_ERR)) { 2320 if (qc->err_mask == AC_ERR_TIMEOUT
2321 && (host_stat & ATA_DMA_ERR)) {
2243 qc->err_mask = AC_ERR_HOST_BUS; 2322 qc->err_mask = AC_ERR_HOST_BUS;
2244 thaw = 1; 2323 thaw = 1;
2245 } 2324 }
@@ -2250,6 +2329,13 @@ void ata_sff_error_handler(struct ata_port *ap)
2250 ata_sff_sync(ap); /* FIXME: We don't need this */ 2329 ata_sff_sync(ap); /* FIXME: We don't need this */
2251 ap->ops->sff_check_status(ap); 2330 ap->ops->sff_check_status(ap);
2252 ap->ops->sff_irq_clear(ap); 2331 ap->ops->sff_irq_clear(ap);
2332 /* We *MUST* do FIFO draining before we issue a reset as several
2333 * devices helpfully clear their internal state and will lock solid
2334 * if we touch the data port post reset. Pass qc in case anyone wants
2335 * to do different PIO/DMA recovery or has per command fixups
2336 */
2337 if (ap->ops->drain_fifo)
2338 ap->ops->drain_fifo(qc);
2253 2339
2254 spin_unlock_irqrestore(ap->lock, flags); 2340 spin_unlock_irqrestore(ap->lock, flags);
2255 2341
@@ -2959,4 +3045,3 @@ out:
2959EXPORT_SYMBOL_GPL(ata_pci_sff_init_one); 3045EXPORT_SYMBOL_GPL(ata_pci_sff_init_one);
2960 3046
2961#endif /* CONFIG_PCI */ 3047#endif /* CONFIG_PCI */
2962
diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
index cea8014cd87e..89a1e0018e71 100644
--- a/drivers/ata/libata.h
+++ b/drivers/ata/libata.h
@@ -79,8 +79,6 @@ extern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
79 u64 block, u32 n_block, unsigned int tf_flags, 79 u64 block, u32 n_block, unsigned int tf_flags,
80 unsigned int tag); 80 unsigned int tag);
81extern u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev); 81extern u64 ata_tf_read_block(struct ata_taskfile *tf, struct ata_device *dev);
82extern void ata_pio_queue_task(struct ata_port *ap, void *data,
83 unsigned long delay);
84extern void ata_port_flush_task(struct ata_port *ap); 82extern void ata_port_flush_task(struct ata_port *ap);
85extern unsigned ata_exec_internal(struct ata_device *dev, 83extern unsigned ata_exec_internal(struct ata_device *dev,
86 struct ata_taskfile *tf, const u8 *cdb, 84 struct ata_taskfile *tf, const u8 *cdb,
diff --git a/drivers/ata/pata_acpi.c b/drivers/ata/pata_acpi.c
index 8b77a9802df1..d8f35fe44421 100644
--- a/drivers/ata/pata_acpi.c
+++ b/drivers/ata/pata_acpi.c
@@ -246,9 +246,9 @@ static int pacpi_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
246 static const struct ata_port_info info = { 246 static const struct ata_port_info info = {
247 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 247 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
248 248
249 .pio_mask = 0x1f, 249 .pio_mask = ATA_PIO4,
250 .mwdma_mask = 0x07, 250 .mwdma_mask = ATA_MWDMA2,
251 .udma_mask = 0x7f, 251 .udma_mask = ATA_UDMA6,
252 252
253 .port_ops = &pacpi_ops, 253 .port_ops = &pacpi_ops,
254 }; 254 };
diff --git a/drivers/ata/pata_ali.c b/drivers/ata/pata_ali.c
index eb99dbe78081..751b7ea4816c 100644
--- a/drivers/ata/pata_ali.c
+++ b/drivers/ata/pata_ali.c
@@ -492,53 +492,53 @@ static int ali_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
492{ 492{
493 static const struct ata_port_info info_early = { 493 static const struct ata_port_info info_early = {
494 .flags = ATA_FLAG_SLAVE_POSS, 494 .flags = ATA_FLAG_SLAVE_POSS,
495 .pio_mask = 0x1f, 495 .pio_mask = ATA_PIO4,
496 .port_ops = &ali_early_port_ops 496 .port_ops = &ali_early_port_ops
497 }; 497 };
498 /* Revision 0x20 added DMA */ 498 /* Revision 0x20 added DMA */
499 static const struct ata_port_info info_20 = { 499 static const struct ata_port_info info_20 = {
500 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48, 500 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
501 .pio_mask = 0x1f, 501 .pio_mask = ATA_PIO4,
502 .mwdma_mask = 0x07, 502 .mwdma_mask = ATA_MWDMA2,
503 .port_ops = &ali_20_port_ops 503 .port_ops = &ali_20_port_ops
504 }; 504 };
505 /* Revision 0x20 with support logic added UDMA */ 505 /* Revision 0x20 with support logic added UDMA */
506 static const struct ata_port_info info_20_udma = { 506 static const struct ata_port_info info_20_udma = {
507 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48, 507 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
508 .pio_mask = 0x1f, 508 .pio_mask = ATA_PIO4,
509 .mwdma_mask = 0x07, 509 .mwdma_mask = ATA_MWDMA2,
510 .udma_mask = 0x07, /* UDMA33 */ 510 .udma_mask = ATA_UDMA2,
511 .port_ops = &ali_20_port_ops 511 .port_ops = &ali_20_port_ops
512 }; 512 };
513 /* Revision 0xC2 adds UDMA66 */ 513 /* Revision 0xC2 adds UDMA66 */
514 static const struct ata_port_info info_c2 = { 514 static const struct ata_port_info info_c2 = {
515 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48, 515 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
516 .pio_mask = 0x1f, 516 .pio_mask = ATA_PIO4,
517 .mwdma_mask = 0x07, 517 .mwdma_mask = ATA_MWDMA2,
518 .udma_mask = ATA_UDMA4, 518 .udma_mask = ATA_UDMA4,
519 .port_ops = &ali_c2_port_ops 519 .port_ops = &ali_c2_port_ops
520 }; 520 };
521 /* Revision 0xC3 is UDMA66 for now */ 521 /* Revision 0xC3 is UDMA66 for now */
522 static const struct ata_port_info info_c3 = { 522 static const struct ata_port_info info_c3 = {
523 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48, 523 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
524 .pio_mask = 0x1f, 524 .pio_mask = ATA_PIO4,
525 .mwdma_mask = 0x07, 525 .mwdma_mask = ATA_MWDMA2,
526 .udma_mask = ATA_UDMA4, 526 .udma_mask = ATA_UDMA4,
527 .port_ops = &ali_c2_port_ops 527 .port_ops = &ali_c2_port_ops
528 }; 528 };
529 /* Revision 0xC4 is UDMA100 */ 529 /* Revision 0xC4 is UDMA100 */
530 static const struct ata_port_info info_c4 = { 530 static const struct ata_port_info info_c4 = {
531 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48, 531 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_PIO_LBA48,
532 .pio_mask = 0x1f, 532 .pio_mask = ATA_PIO4,
533 .mwdma_mask = 0x07, 533 .mwdma_mask = ATA_MWDMA2,
534 .udma_mask = ATA_UDMA5, 534 .udma_mask = ATA_UDMA5,
535 .port_ops = &ali_c4_port_ops 535 .port_ops = &ali_c4_port_ops
536 }; 536 };
537 /* Revision 0xC5 is UDMA133 with LBA48 DMA */ 537 /* Revision 0xC5 is UDMA133 with LBA48 DMA */
538 static const struct ata_port_info info_c5 = { 538 static const struct ata_port_info info_c5 = {
539 .flags = ATA_FLAG_SLAVE_POSS, 539 .flags = ATA_FLAG_SLAVE_POSS,
540 .pio_mask = 0x1f, 540 .pio_mask = ATA_PIO4,
541 .mwdma_mask = 0x07, 541 .mwdma_mask = ATA_MWDMA2,
542 .udma_mask = ATA_UDMA6, 542 .udma_mask = ATA_UDMA6,
543 .port_ops = &ali_c5_port_ops 543 .port_ops = &ali_c5_port_ops
544 }; 544 };
diff --git a/drivers/ata/pata_amd.c b/drivers/ata/pata_amd.c
index 115b1cd6dcf5..33a74f11171c 100644
--- a/drivers/ata/pata_amd.c
+++ b/drivers/ata/pata_amd.c
@@ -455,74 +455,74 @@ static void amd_clear_fifo(struct pci_dev *pdev)
455static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id) 455static int amd_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
456{ 456{
457 static const struct ata_port_info info[10] = { 457 static const struct ata_port_info info[10] = {
458 { /* 0: AMD 7401 */ 458 { /* 0: AMD 7401 - no swdma */
459 .flags = ATA_FLAG_SLAVE_POSS, 459 .flags = ATA_FLAG_SLAVE_POSS,
460 .pio_mask = 0x1f, 460 .pio_mask = ATA_PIO4,
461 .mwdma_mask = 0x07, /* No SWDMA */ 461 .mwdma_mask = ATA_MWDMA2,
462 .udma_mask = 0x07, /* UDMA 33 */ 462 .udma_mask = ATA_UDMA2,
463 .port_ops = &amd33_port_ops 463 .port_ops = &amd33_port_ops
464 }, 464 },
465 { /* 1: Early AMD7409 - no swdma */ 465 { /* 1: Early AMD7409 - no swdma */
466 .flags = ATA_FLAG_SLAVE_POSS, 466 .flags = ATA_FLAG_SLAVE_POSS,
467 .pio_mask = 0x1f, 467 .pio_mask = ATA_PIO4,
468 .mwdma_mask = 0x07, 468 .mwdma_mask = ATA_MWDMA2,
469 .udma_mask = ATA_UDMA4, /* UDMA 66 */ 469 .udma_mask = ATA_UDMA4,
470 .port_ops = &amd66_port_ops 470 .port_ops = &amd66_port_ops
471 }, 471 },
472 { /* 2: AMD 7409, no swdma errata */ 472 { /* 2: AMD 7409 */
473 .flags = ATA_FLAG_SLAVE_POSS, 473 .flags = ATA_FLAG_SLAVE_POSS,
474 .pio_mask = 0x1f, 474 .pio_mask = ATA_PIO4,
475 .mwdma_mask = 0x07, 475 .mwdma_mask = ATA_MWDMA2,
476 .udma_mask = ATA_UDMA4, /* UDMA 66 */ 476 .udma_mask = ATA_UDMA4,
477 .port_ops = &amd66_port_ops 477 .port_ops = &amd66_port_ops
478 }, 478 },
479 { /* 3: AMD 7411 */ 479 { /* 3: AMD 7411 */
480 .flags = ATA_FLAG_SLAVE_POSS, 480 .flags = ATA_FLAG_SLAVE_POSS,
481 .pio_mask = 0x1f, 481 .pio_mask = ATA_PIO4,
482 .mwdma_mask = 0x07, 482 .mwdma_mask = ATA_MWDMA2,
483 .udma_mask = ATA_UDMA5, /* UDMA 100 */ 483 .udma_mask = ATA_UDMA5,
484 .port_ops = &amd100_port_ops 484 .port_ops = &amd100_port_ops
485 }, 485 },
486 { /* 4: AMD 7441 */ 486 { /* 4: AMD 7441 */
487 .flags = ATA_FLAG_SLAVE_POSS, 487 .flags = ATA_FLAG_SLAVE_POSS,
488 .pio_mask = 0x1f, 488 .pio_mask = ATA_PIO4,
489 .mwdma_mask = 0x07, 489 .mwdma_mask = ATA_MWDMA2,
490 .udma_mask = ATA_UDMA5, /* UDMA 100 */ 490 .udma_mask = ATA_UDMA5,
491 .port_ops = &amd100_port_ops 491 .port_ops = &amd100_port_ops
492 }, 492 },
493 { /* 5: AMD 8111*/ 493 { /* 5: AMD 8111 - no swdma */
494 .flags = ATA_FLAG_SLAVE_POSS, 494 .flags = ATA_FLAG_SLAVE_POSS,
495 .pio_mask = 0x1f, 495 .pio_mask = ATA_PIO4,
496 .mwdma_mask = 0x07, 496 .mwdma_mask = ATA_MWDMA2,
497 .udma_mask = ATA_UDMA6, /* UDMA 133, no swdma */ 497 .udma_mask = ATA_UDMA6,
498 .port_ops = &amd133_port_ops 498 .port_ops = &amd133_port_ops
499 }, 499 },
500 { /* 6: AMD 8111 UDMA 100 (Serenade) */ 500 { /* 6: AMD 8111 UDMA 100 (Serenade) - no swdma */
501 .flags = ATA_FLAG_SLAVE_POSS, 501 .flags = ATA_FLAG_SLAVE_POSS,
502 .pio_mask = 0x1f, 502 .pio_mask = ATA_PIO4,
503 .mwdma_mask = 0x07, 503 .mwdma_mask = ATA_MWDMA2,
504 .udma_mask = ATA_UDMA5, /* UDMA 100, no swdma */ 504 .udma_mask = ATA_UDMA5,
505 .port_ops = &amd133_port_ops 505 .port_ops = &amd133_port_ops
506 }, 506 },
507 { /* 7: Nvidia Nforce */ 507 { /* 7: Nvidia Nforce */
508 .flags = ATA_FLAG_SLAVE_POSS, 508 .flags = ATA_FLAG_SLAVE_POSS,
509 .pio_mask = 0x1f, 509 .pio_mask = ATA_PIO4,
510 .mwdma_mask = 0x07, 510 .mwdma_mask = ATA_MWDMA2,
511 .udma_mask = ATA_UDMA5, /* UDMA 100 */ 511 .udma_mask = ATA_UDMA5,
512 .port_ops = &nv100_port_ops 512 .port_ops = &nv100_port_ops
513 }, 513 },
514 { /* 8: Nvidia Nforce2 and later */ 514 { /* 8: Nvidia Nforce2 and later - no swdma */
515 .flags = ATA_FLAG_SLAVE_POSS, 515 .flags = ATA_FLAG_SLAVE_POSS,
516 .pio_mask = 0x1f, 516 .pio_mask = ATA_PIO4,
517 .mwdma_mask = 0x07, 517 .mwdma_mask = ATA_MWDMA2,
518 .udma_mask = ATA_UDMA6, /* UDMA 133, no swdma */ 518 .udma_mask = ATA_UDMA6,
519 .port_ops = &nv133_port_ops 519 .port_ops = &nv133_port_ops
520 }, 520 },
521 { /* 9: AMD CS5536 (Geode companion) */ 521 { /* 9: AMD CS5536 (Geode companion) */
522 .flags = ATA_FLAG_SLAVE_POSS, 522 .flags = ATA_FLAG_SLAVE_POSS,
523 .pio_mask = 0x1f, 523 .pio_mask = ATA_PIO4,
524 .mwdma_mask = 0x07, 524 .mwdma_mask = ATA_MWDMA2,
525 .udma_mask = ATA_UDMA5, /* UDMA 100 */ 525 .udma_mask = ATA_UDMA5,
526 .port_ops = &amd100_port_ops 526 .port_ops = &amd100_port_ops
527 } 527 }
528 }; 528 };
diff --git a/drivers/ata/pata_artop.c b/drivers/ata/pata_artop.c
index 6b3092c75ffe..d332cfdb0f30 100644
--- a/drivers/ata/pata_artop.c
+++ b/drivers/ata/pata_artop.c
@@ -12,7 +12,6 @@
12 * performance Alessandro Zummo <alessandro.zummo@towertech.it> 12 * performance Alessandro Zummo <alessandro.zummo@towertech.it>
13 * 13 *
14 * TODO 14 * TODO
15 * 850 serialization once the core supports it
16 * Investigate no_dsc on 850R 15 * Investigate no_dsc on 850R
17 * Clock detect 16 * Clock detect
18 */ 17 */
@@ -29,7 +28,7 @@
29#include <linux/ata.h> 28#include <linux/ata.h>
30 29
31#define DRV_NAME "pata_artop" 30#define DRV_NAME "pata_artop"
32#define DRV_VERSION "0.4.4" 31#define DRV_VERSION "0.4.5"
33 32
34/* 33/*
35 * The ARTOP has 33 Mhz and "over clocked" timing tables. Until we 34 * The ARTOP has 33 Mhz and "over clocked" timing tables. Until we
@@ -283,6 +282,31 @@ static void artop6260_set_dmamode (struct ata_port *ap, struct ata_device *adev)
283 pci_write_config_byte(pdev, 0x44 + ap->port_no, ultra); 282 pci_write_config_byte(pdev, 0x44 + ap->port_no, ultra);
284} 283}
285 284
285/**
286 * artop_6210_qc_defer - implement serialization
287 * @qc: command
288 *
289 * Issue commands per host on this chip.
290 */
291
292static int artop6210_qc_defer(struct ata_queued_cmd *qc)
293{
294 struct ata_host *host = qc->ap->host;
295 struct ata_port *alt = host->ports[1 ^ qc->ap->port_no];
296 int rc;
297
298 /* First apply the usual rules */
299 rc = ata_std_qc_defer(qc);
300 if (rc != 0)
301 return rc;
302
303 /* Now apply serialization rules. Only allow a command if the
304 other channel state machine is idle */
305 if (alt && alt->qc_active)
306 return ATA_DEFER_PORT;
307 return 0;
308}
309
286static struct scsi_host_template artop_sht = { 310static struct scsi_host_template artop_sht = {
287 ATA_BMDMA_SHT(DRV_NAME), 311 ATA_BMDMA_SHT(DRV_NAME),
288}; 312};
@@ -293,6 +317,7 @@ static struct ata_port_operations artop6210_ops = {
293 .set_piomode = artop6210_set_piomode, 317 .set_piomode = artop6210_set_piomode,
294 .set_dmamode = artop6210_set_dmamode, 318 .set_dmamode = artop6210_set_dmamode,
295 .prereset = artop6210_pre_reset, 319 .prereset = artop6210_pre_reset,
320 .qc_defer = artop6210_qc_defer,
296}; 321};
297 322
298static struct ata_port_operations artop6260_ops = { 323static struct ata_port_operations artop6260_ops = {
@@ -323,29 +348,29 @@ static int artop_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
323 static int printed_version; 348 static int printed_version;
324 static const struct ata_port_info info_6210 = { 349 static const struct ata_port_info info_6210 = {
325 .flags = ATA_FLAG_SLAVE_POSS, 350 .flags = ATA_FLAG_SLAVE_POSS,
326 .pio_mask = 0x1f, /* pio0-4 */ 351 .pio_mask = ATA_PIO4,
327 .mwdma_mask = 0x07, /* mwdma0-2 */ 352 .mwdma_mask = ATA_MWDMA2,
328 .udma_mask = ATA_UDMA2, 353 .udma_mask = ATA_UDMA2,
329 .port_ops = &artop6210_ops, 354 .port_ops = &artop6210_ops,
330 }; 355 };
331 static const struct ata_port_info info_626x = { 356 static const struct ata_port_info info_626x = {
332 .flags = ATA_FLAG_SLAVE_POSS, 357 .flags = ATA_FLAG_SLAVE_POSS,
333 .pio_mask = 0x1f, /* pio0-4 */ 358 .pio_mask = ATA_PIO4,
334 .mwdma_mask = 0x07, /* mwdma0-2 */ 359 .mwdma_mask = ATA_MWDMA2,
335 .udma_mask = ATA_UDMA4, 360 .udma_mask = ATA_UDMA4,
336 .port_ops = &artop6260_ops, 361 .port_ops = &artop6260_ops,
337 }; 362 };
338 static const struct ata_port_info info_628x = { 363 static const struct ata_port_info info_628x = {
339 .flags = ATA_FLAG_SLAVE_POSS, 364 .flags = ATA_FLAG_SLAVE_POSS,
340 .pio_mask = 0x1f, /* pio0-4 */ 365 .pio_mask = ATA_PIO4,
341 .mwdma_mask = 0x07, /* mwdma0-2 */ 366 .mwdma_mask = ATA_MWDMA2,
342 .udma_mask = ATA_UDMA5, 367 .udma_mask = ATA_UDMA5,
343 .port_ops = &artop6260_ops, 368 .port_ops = &artop6260_ops,
344 }; 369 };
345 static const struct ata_port_info info_628x_fast = { 370 static const struct ata_port_info info_628x_fast = {
346 .flags = ATA_FLAG_SLAVE_POSS, 371 .flags = ATA_FLAG_SLAVE_POSS,
347 .pio_mask = 0x1f, /* pio0-4 */ 372 .pio_mask = ATA_PIO4,
348 .mwdma_mask = 0x07, /* mwdma0-2 */ 373 .mwdma_mask = ATA_MWDMA2,
349 .udma_mask = ATA_UDMA6, 374 .udma_mask = ATA_UDMA6,
350 .port_ops = &artop6260_ops, 375 .port_ops = &artop6260_ops,
351 }; 376 };
@@ -362,12 +387,8 @@ static int artop_init_one (struct pci_dev *pdev, const struct pci_device_id *id)
362 387
363 if (id->driver_data == 0) { /* 6210 variant */ 388 if (id->driver_data == 0) { /* 6210 variant */
364 ppi[0] = &info_6210; 389 ppi[0] = &info_6210;
365 ppi[1] = &ata_dummy_port_info;
366 /* BIOS may have left us in UDMA, clear it before libata probe */ 390 /* BIOS may have left us in UDMA, clear it before libata probe */
367 pci_write_config_byte(pdev, 0x54, 0); 391 pci_write_config_byte(pdev, 0x54, 0);
368 /* For the moment (also lacks dsc) */
369 printk(KERN_WARNING "ARTOP 6210 requires serialize functionality not yet supported by libata.\n");
370 printk(KERN_WARNING "Secondary ATA ports will not be activated.\n");
371 } 392 }
372 else if (id->driver_data == 1) /* 6260 */ 393 else if (id->driver_data == 1) /* 6260 */
373 ppi[0] = &info_626x; 394 ppi[0] = &info_626x;
diff --git a/drivers/ata/pata_at32.c b/drivers/ata/pata_at32.c
index ab61095093b9..5c129f99a7e3 100644
--- a/drivers/ata/pata_at32.c
+++ b/drivers/ata/pata_at32.c
@@ -67,7 +67,9 @@
67 * 67 *
68 * Alter PIO_MASK below according to table to set maximal PIO mode. 68 * Alter PIO_MASK below according to table to set maximal PIO mode.
69 */ 69 */
70#define PIO_MASK (0x1f) 70enum {
71 PIO_MASK = ATA_PIO4,
72};
71 73
72/* 74/*
73 * Struct containing private information about device. 75 * Struct containing private information about device.
diff --git a/drivers/ata/pata_atiixp.c b/drivers/ata/pata_atiixp.c
index 506adde8ebb3..bec0b8ade66d 100644
--- a/drivers/ata/pata_atiixp.c
+++ b/drivers/ata/pata_atiixp.c
@@ -220,9 +220,9 @@ static int atiixp_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
220{ 220{
221 static const struct ata_port_info info = { 221 static const struct ata_port_info info = {
222 .flags = ATA_FLAG_SLAVE_POSS, 222 .flags = ATA_FLAG_SLAVE_POSS,
223 .pio_mask = 0x1f, 223 .pio_mask = ATA_PIO4,
224 .mwdma_mask = 0x06, /* No MWDMA0 support */ 224 .mwdma_mask = ATA_MWDMA12_ONLY,
225 .udma_mask = 0x3F, 225 .udma_mask = ATA_UDMA5,
226 .port_ops = &atiixp_port_ops 226 .port_ops = &atiixp_port_ops
227 }; 227 };
228 static const struct pci_bits atiixp_enable_bits[] = { 228 static const struct pci_bits atiixp_enable_bits[] = {
diff --git a/drivers/ata/pata_bf54x.c b/drivers/ata/pata_bf54x.c
index 1050fed96b2b..c4b47a3e5446 100644
--- a/drivers/ata/pata_bf54x.c
+++ b/drivers/ata/pata_bf54x.c
@@ -1502,7 +1502,7 @@ static struct ata_port_info bfin_port_info[] = {
1502 .flags = ATA_FLAG_SLAVE_POSS 1502 .flags = ATA_FLAG_SLAVE_POSS
1503 | ATA_FLAG_MMIO 1503 | ATA_FLAG_MMIO
1504 | ATA_FLAG_NO_LEGACY, 1504 | ATA_FLAG_NO_LEGACY,
1505 .pio_mask = 0x1f, /* pio0-4 */ 1505 .pio_mask = ATA_PIO4,
1506 .mwdma_mask = 0, 1506 .mwdma_mask = 0,
1507 .udma_mask = 0, 1507 .udma_mask = 0,
1508 .port_ops = &bfin_pata_ops, 1508 .port_ops = &bfin_pata_ops,
diff --git a/drivers/ata/pata_cmd640.c b/drivers/ata/pata_cmd640.c
index 34a394264c3d..5acf9fa9b39f 100644
--- a/drivers/ata/pata_cmd640.c
+++ b/drivers/ata/pata_cmd640.c
@@ -211,7 +211,7 @@ static int cmd640_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
211{ 211{
212 static const struct ata_port_info info = { 212 static const struct ata_port_info info = {
213 .flags = ATA_FLAG_SLAVE_POSS, 213 .flags = ATA_FLAG_SLAVE_POSS,
214 .pio_mask = 0x1f, 214 .pio_mask = ATA_PIO4,
215 .port_ops = &cmd640_port_ops 215 .port_ops = &cmd640_port_ops
216 }; 216 };
217 const struct ata_port_info *ppi[] = { &info, NULL }; 217 const struct ata_port_info *ppi[] = { &info, NULL };
diff --git a/drivers/ata/pata_cmd64x.c b/drivers/ata/pata_cmd64x.c
index 3167d8fed2f2..f98dffedf4bc 100644
--- a/drivers/ata/pata_cmd64x.c
+++ b/drivers/ata/pata_cmd64x.c
@@ -299,40 +299,40 @@ static int cmd64x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
299 static const struct ata_port_info cmd_info[6] = { 299 static const struct ata_port_info cmd_info[6] = {
300 { /* CMD 643 - no UDMA */ 300 { /* CMD 643 - no UDMA */
301 .flags = ATA_FLAG_SLAVE_POSS, 301 .flags = ATA_FLAG_SLAVE_POSS,
302 .pio_mask = 0x1f, 302 .pio_mask = ATA_PIO4,
303 .mwdma_mask = 0x07, 303 .mwdma_mask = ATA_MWDMA2,
304 .port_ops = &cmd64x_port_ops 304 .port_ops = &cmd64x_port_ops
305 }, 305 },
306 { /* CMD 646 with broken UDMA */ 306 { /* CMD 646 with broken UDMA */
307 .flags = ATA_FLAG_SLAVE_POSS, 307 .flags = ATA_FLAG_SLAVE_POSS,
308 .pio_mask = 0x1f, 308 .pio_mask = ATA_PIO4,
309 .mwdma_mask = 0x07, 309 .mwdma_mask = ATA_MWDMA2,
310 .port_ops = &cmd64x_port_ops 310 .port_ops = &cmd64x_port_ops
311 }, 311 },
312 { /* CMD 646 with working UDMA */ 312 { /* CMD 646 with working UDMA */
313 .flags = ATA_FLAG_SLAVE_POSS, 313 .flags = ATA_FLAG_SLAVE_POSS,
314 .pio_mask = 0x1f, 314 .pio_mask = ATA_PIO4,
315 .mwdma_mask = 0x07, 315 .mwdma_mask = ATA_MWDMA2,
316 .udma_mask = ATA_UDMA2, 316 .udma_mask = ATA_UDMA2,
317 .port_ops = &cmd64x_port_ops 317 .port_ops = &cmd64x_port_ops
318 }, 318 },
319 { /* CMD 646 rev 1 */ 319 { /* CMD 646 rev 1 */
320 .flags = ATA_FLAG_SLAVE_POSS, 320 .flags = ATA_FLAG_SLAVE_POSS,
321 .pio_mask = 0x1f, 321 .pio_mask = ATA_PIO4,
322 .mwdma_mask = 0x07, 322 .mwdma_mask = ATA_MWDMA2,
323 .port_ops = &cmd646r1_port_ops 323 .port_ops = &cmd646r1_port_ops
324 }, 324 },
325 { /* CMD 648 */ 325 { /* CMD 648 */
326 .flags = ATA_FLAG_SLAVE_POSS, 326 .flags = ATA_FLAG_SLAVE_POSS,
327 .pio_mask = 0x1f, 327 .pio_mask = ATA_PIO4,
328 .mwdma_mask = 0x07, 328 .mwdma_mask = ATA_MWDMA2,
329 .udma_mask = ATA_UDMA4, 329 .udma_mask = ATA_UDMA4,
330 .port_ops = &cmd648_port_ops 330 .port_ops = &cmd648_port_ops
331 }, 331 },
332 { /* CMD 649 */ 332 { /* CMD 649 */
333 .flags = ATA_FLAG_SLAVE_POSS, 333 .flags = ATA_FLAG_SLAVE_POSS,
334 .pio_mask = 0x1f, 334 .pio_mask = ATA_PIO4,
335 .mwdma_mask = 0x07, 335 .mwdma_mask = ATA_MWDMA2,
336 .udma_mask = ATA_UDMA5, 336 .udma_mask = ATA_UDMA5,
337 .port_ops = &cmd648_port_ops 337 .port_ops = &cmd648_port_ops
338 } 338 }
diff --git a/drivers/ata/pata_cs5520.c b/drivers/ata/pata_cs5520.c
index 1186bcd2781c..db6a96984f3f 100644
--- a/drivers/ata/pata_cs5520.c
+++ b/drivers/ata/pata_cs5520.c
@@ -158,7 +158,7 @@ static int __devinit cs5520_init_one(struct pci_dev *pdev, const struct pci_devi
158 static const unsigned int ctl_port[] = { 0x3F6, 0x376 }; 158 static const unsigned int ctl_port[] = { 0x3F6, 0x376 };
159 struct ata_port_info pi = { 159 struct ata_port_info pi = {
160 .flags = ATA_FLAG_SLAVE_POSS, 160 .flags = ATA_FLAG_SLAVE_POSS,
161 .pio_mask = 0x1f, 161 .pio_mask = ATA_PIO4,
162 .port_ops = &cs5520_port_ops, 162 .port_ops = &cs5520_port_ops,
163 }; 163 };
164 const struct ata_port_info *ppi[2]; 164 const struct ata_port_info *ppi[2];
diff --git a/drivers/ata/pata_cs5530.c b/drivers/ata/pata_cs5530.c
index bba453381f44..c974b05e4129 100644
--- a/drivers/ata/pata_cs5530.c
+++ b/drivers/ata/pata_cs5530.c
@@ -298,15 +298,15 @@ static int cs5530_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
298{ 298{
299 static const struct ata_port_info info = { 299 static const struct ata_port_info info = {
300 .flags = ATA_FLAG_SLAVE_POSS, 300 .flags = ATA_FLAG_SLAVE_POSS,
301 .pio_mask = 0x1f, 301 .pio_mask = ATA_PIO4,
302 .mwdma_mask = 0x07, 302 .mwdma_mask = ATA_MWDMA2,
303 .udma_mask = 0x07, 303 .udma_mask = ATA_UDMA2,
304 .port_ops = &cs5530_port_ops 304 .port_ops = &cs5530_port_ops
305 }; 305 };
306 /* The docking connector doesn't do UDMA, and it seems not MWDMA */ 306 /* The docking connector doesn't do UDMA, and it seems not MWDMA */
307 static const struct ata_port_info info_palmax_secondary = { 307 static const struct ata_port_info info_palmax_secondary = {
308 .flags = ATA_FLAG_SLAVE_POSS, 308 .flags = ATA_FLAG_SLAVE_POSS,
309 .pio_mask = 0x1f, 309 .pio_mask = ATA_PIO4,
310 .port_ops = &cs5530_port_ops 310 .port_ops = &cs5530_port_ops
311 }; 311 };
312 const struct ata_port_info *ppi[] = { &info, NULL }; 312 const struct ata_port_info *ppi[] = { &info, NULL };
diff --git a/drivers/ata/pata_cs5535.c b/drivers/ata/pata_cs5535.c
index 8b236af84c2e..d33aa28239a9 100644
--- a/drivers/ata/pata_cs5535.c
+++ b/drivers/ata/pata_cs5535.c
@@ -181,8 +181,8 @@ static int cs5535_init_one(struct pci_dev *dev, const struct pci_device_id *id)
181{ 181{
182 static const struct ata_port_info info = { 182 static const struct ata_port_info info = {
183 .flags = ATA_FLAG_SLAVE_POSS, 183 .flags = ATA_FLAG_SLAVE_POSS,
184 .pio_mask = 0x1f, 184 .pio_mask = ATA_PIO4,
185 .mwdma_mask = 0x07, 185 .mwdma_mask = ATA_MWDMA2,
186 .udma_mask = ATA_UDMA4, 186 .udma_mask = ATA_UDMA4,
187 .port_ops = &cs5535_port_ops 187 .port_ops = &cs5535_port_ops
188 }; 188 };
diff --git a/drivers/ata/pata_cs5536.c b/drivers/ata/pata_cs5536.c
index afed92976198..6da4cb486c8d 100644
--- a/drivers/ata/pata_cs5536.c
+++ b/drivers/ata/pata_cs5536.c
@@ -241,8 +241,8 @@ static int cs5536_init_one(struct pci_dev *dev, const struct pci_device_id *id)
241{ 241{
242 static const struct ata_port_info info = { 242 static const struct ata_port_info info = {
243 .flags = ATA_FLAG_SLAVE_POSS, 243 .flags = ATA_FLAG_SLAVE_POSS,
244 .pio_mask = 0x1f, 244 .pio_mask = ATA_PIO4,
245 .mwdma_mask = 0x07, 245 .mwdma_mask = ATA_MWDMA2,
246 .udma_mask = ATA_UDMA5, 246 .udma_mask = ATA_UDMA5,
247 .port_ops = &cs5536_port_ops, 247 .port_ops = &cs5536_port_ops,
248 }; 248 };
diff --git a/drivers/ata/pata_cypress.c b/drivers/ata/pata_cypress.c
index d546425cd380..8fb040bf7361 100644
--- a/drivers/ata/pata_cypress.c
+++ b/drivers/ata/pata_cypress.c
@@ -124,8 +124,8 @@ static int cy82c693_init_one(struct pci_dev *pdev, const struct pci_device_id *i
124{ 124{
125 static const struct ata_port_info info = { 125 static const struct ata_port_info info = {
126 .flags = ATA_FLAG_SLAVE_POSS, 126 .flags = ATA_FLAG_SLAVE_POSS,
127 .pio_mask = 0x1f, 127 .pio_mask = ATA_PIO4,
128 .mwdma_mask = 0x07, 128 .mwdma_mask = ATA_MWDMA2,
129 .port_ops = &cy82c693_port_ops 129 .port_ops = &cy82c693_port_ops
130 }; 130 };
131 const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info }; 131 const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info };
diff --git a/drivers/ata/pata_efar.c b/drivers/ata/pata_efar.c
index ac6392ea35b0..2085e0a3a05a 100644
--- a/drivers/ata/pata_efar.c
+++ b/drivers/ata/pata_efar.c
@@ -251,9 +251,9 @@ static int efar_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
251 static int printed_version; 251 static int printed_version;
252 static const struct ata_port_info info = { 252 static const struct ata_port_info info = {
253 .flags = ATA_FLAG_SLAVE_POSS, 253 .flags = ATA_FLAG_SLAVE_POSS,
254 .pio_mask = 0x1f, /* pio0-4 */ 254 .pio_mask = ATA_PIO4,
255 .mwdma_mask = 0x07, /* mwdma1-2 */ 255 .mwdma_mask = ATA_MWDMA2,
256 .udma_mask = 0x0f, /* UDMA 66 */ 256 .udma_mask = ATA_UDMA4,
257 .port_ops = &efar_ops, 257 .port_ops = &efar_ops,
258 }; 258 };
259 const struct ata_port_info *ppi[] = { &info, NULL }; 259 const struct ata_port_info *ppi[] = { &info, NULL };
diff --git a/drivers/ata/pata_hpt366.c b/drivers/ata/pata_hpt366.c
index 65c28e5a6cd7..d7f2da127d13 100644
--- a/drivers/ata/pata_hpt366.c
+++ b/drivers/ata/pata_hpt366.c
@@ -336,8 +336,8 @@ static int hpt36x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
336{ 336{
337 static const struct ata_port_info info_hpt366 = { 337 static const struct ata_port_info info_hpt366 = {
338 .flags = ATA_FLAG_SLAVE_POSS, 338 .flags = ATA_FLAG_SLAVE_POSS,
339 .pio_mask = 0x1f, 339 .pio_mask = ATA_PIO4,
340 .mwdma_mask = 0x07, 340 .mwdma_mask = ATA_MWDMA2,
341 .udma_mask = ATA_UDMA4, 341 .udma_mask = ATA_UDMA4,
342 .port_ops = &hpt366_port_ops 342 .port_ops = &hpt366_port_ops
343 }; 343 };
diff --git a/drivers/ata/pata_hpt37x.c b/drivers/ata/pata_hpt37x.c
index 42163998de9a..81ab57003aba 100644
--- a/drivers/ata/pata_hpt37x.c
+++ b/drivers/ata/pata_hpt37x.c
@@ -753,55 +753,55 @@ static int hpt37x_init_one(struct pci_dev *dev, const struct pci_device_id *id)
753 /* HPT370 - UDMA100 */ 753 /* HPT370 - UDMA100 */
754 static const struct ata_port_info info_hpt370 = { 754 static const struct ata_port_info info_hpt370 = {
755 .flags = ATA_FLAG_SLAVE_POSS, 755 .flags = ATA_FLAG_SLAVE_POSS,
756 .pio_mask = 0x1f, 756 .pio_mask = ATA_PIO4,
757 .mwdma_mask = 0x07, 757 .mwdma_mask = ATA_MWDMA2,
758 .udma_mask = ATA_UDMA5, 758 .udma_mask = ATA_UDMA5,
759 .port_ops = &hpt370_port_ops 759 .port_ops = &hpt370_port_ops
760 }; 760 };
761 /* HPT370A - UDMA100 */ 761 /* HPT370A - UDMA100 */
762 static const struct ata_port_info info_hpt370a = { 762 static const struct ata_port_info info_hpt370a = {
763 .flags = ATA_FLAG_SLAVE_POSS, 763 .flags = ATA_FLAG_SLAVE_POSS,
764 .pio_mask = 0x1f, 764 .pio_mask = ATA_PIO4,
765 .mwdma_mask = 0x07, 765 .mwdma_mask = ATA_MWDMA2,
766 .udma_mask = ATA_UDMA5, 766 .udma_mask = ATA_UDMA5,
767 .port_ops = &hpt370a_port_ops 767 .port_ops = &hpt370a_port_ops
768 }; 768 };
769 /* HPT370 - UDMA100 */ 769 /* HPT370 - UDMA100 */
770 static const struct ata_port_info info_hpt370_33 = { 770 static const struct ata_port_info info_hpt370_33 = {
771 .flags = ATA_FLAG_SLAVE_POSS, 771 .flags = ATA_FLAG_SLAVE_POSS,
772 .pio_mask = 0x1f, 772 .pio_mask = ATA_PIO4,
773 .mwdma_mask = 0x07, 773 .mwdma_mask = ATA_MWDMA2,
774 .udma_mask = ATA_UDMA5, 774 .udma_mask = ATA_UDMA5,
775 .port_ops = &hpt370_port_ops 775 .port_ops = &hpt370_port_ops
776 }; 776 };
777 /* HPT370A - UDMA100 */ 777 /* HPT370A - UDMA100 */
778 static const struct ata_port_info info_hpt370a_33 = { 778 static const struct ata_port_info info_hpt370a_33 = {
779 .flags = ATA_FLAG_SLAVE_POSS, 779 .flags = ATA_FLAG_SLAVE_POSS,
780 .pio_mask = 0x1f, 780 .pio_mask = ATA_PIO4,
781 .mwdma_mask = 0x07, 781 .mwdma_mask = ATA_MWDMA2,
782 .udma_mask = ATA_UDMA5, 782 .udma_mask = ATA_UDMA5,
783 .port_ops = &hpt370a_port_ops 783 .port_ops = &hpt370a_port_ops
784 }; 784 };
785 /* HPT371, 372 and friends - UDMA133 */ 785 /* HPT371, 372 and friends - UDMA133 */
786 static const struct ata_port_info info_hpt372 = { 786 static const struct ata_port_info info_hpt372 = {
787 .flags = ATA_FLAG_SLAVE_POSS, 787 .flags = ATA_FLAG_SLAVE_POSS,
788 .pio_mask = 0x1f, 788 .pio_mask = ATA_PIO4,
789 .mwdma_mask = 0x07, 789 .mwdma_mask = ATA_MWDMA2,
790 .udma_mask = ATA_UDMA6, 790 .udma_mask = ATA_UDMA6,
791 .port_ops = &hpt372_port_ops 791 .port_ops = &hpt372_port_ops
792 }; 792 };
793 /* HPT374 - UDMA100, function 1 uses different prereset method */ 793 /* HPT374 - UDMA100, function 1 uses different prereset method */
794 static const struct ata_port_info info_hpt374_fn0 = { 794 static const struct ata_port_info info_hpt374_fn0 = {
795 .flags = ATA_FLAG_SLAVE_POSS, 795 .flags = ATA_FLAG_SLAVE_POSS,
796 .pio_mask = 0x1f, 796 .pio_mask = ATA_PIO4,
797 .mwdma_mask = 0x07, 797 .mwdma_mask = ATA_MWDMA2,
798 .udma_mask = ATA_UDMA5, 798 .udma_mask = ATA_UDMA5,
799 .port_ops = &hpt372_port_ops 799 .port_ops = &hpt372_port_ops
800 }; 800 };
801 static const struct ata_port_info info_hpt374_fn1 = { 801 static const struct ata_port_info info_hpt374_fn1 = {
802 .flags = ATA_FLAG_SLAVE_POSS, 802 .flags = ATA_FLAG_SLAVE_POSS,
803 .pio_mask = 0x1f, 803 .pio_mask = ATA_PIO4,
804 .mwdma_mask = 0x07, 804 .mwdma_mask = ATA_MWDMA2,
805 .udma_mask = ATA_UDMA5, 805 .udma_mask = ATA_UDMA5,
806 .port_ops = &hpt374_fn1_port_ops 806 .port_ops = &hpt374_fn1_port_ops
807 }; 807 };
diff --git a/drivers/ata/pata_hpt3x2n.c b/drivers/ata/pata_hpt3x2n.c
index d5c9fd7b82bb..3d59fe0a408d 100644
--- a/drivers/ata/pata_hpt3x2n.c
+++ b/drivers/ata/pata_hpt3x2n.c
@@ -441,8 +441,8 @@ static int hpt3x2n_init_one(struct pci_dev *dev, const struct pci_device_id *id)
441 /* HPT372N and friends - UDMA133 */ 441 /* HPT372N and friends - UDMA133 */
442 static const struct ata_port_info info = { 442 static const struct ata_port_info info = {
443 .flags = ATA_FLAG_SLAVE_POSS, 443 .flags = ATA_FLAG_SLAVE_POSS,
444 .pio_mask = 0x1f, 444 .pio_mask = ATA_PIO4,
445 .mwdma_mask = 0x07, 445 .mwdma_mask = ATA_MWDMA2,
446 .udma_mask = ATA_UDMA6, 446 .udma_mask = ATA_UDMA6,
447 .port_ops = &hpt3x2n_port_ops 447 .port_ops = &hpt3x2n_port_ops
448 }; 448 };
diff --git a/drivers/ata/pata_hpt3x3.c b/drivers/ata/pata_hpt3x3.c
index f19cc645881a..7e310253b36b 100644
--- a/drivers/ata/pata_hpt3x3.c
+++ b/drivers/ata/pata_hpt3x3.c
@@ -188,11 +188,11 @@ static int hpt3x3_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
188 static int printed_version; 188 static int printed_version;
189 static const struct ata_port_info info = { 189 static const struct ata_port_info info = {
190 .flags = ATA_FLAG_SLAVE_POSS, 190 .flags = ATA_FLAG_SLAVE_POSS,
191 .pio_mask = 0x1f, 191 .pio_mask = ATA_PIO4,
192#if defined(CONFIG_PATA_HPT3X3_DMA) 192#if defined(CONFIG_PATA_HPT3X3_DMA)
193 /* Further debug needed */ 193 /* Further debug needed */
194 .mwdma_mask = 0x07, 194 .mwdma_mask = ATA_MWDMA2,
195 .udma_mask = 0x07, 195 .udma_mask = ATA_UDMA2,
196#endif 196#endif
197 .port_ops = &hpt3x3_port_ops 197 .port_ops = &hpt3x3_port_ops
198 }; 198 };
diff --git a/drivers/ata/pata_icside.c b/drivers/ata/pata_icside.c
index cf9e9848f8b5..e7347db5b6c4 100644
--- a/drivers/ata/pata_icside.c
+++ b/drivers/ata/pata_icside.c
@@ -297,7 +297,7 @@ static int icside_dma_init(struct pata_icside_info *info)
297 297
298 if (ec->dma != NO_DMA && !request_dma(ec->dma, DRV_NAME)) { 298 if (ec->dma != NO_DMA && !request_dma(ec->dma, DRV_NAME)) {
299 state->dma = ec->dma; 299 state->dma = ec->dma;
300 info->mwdma_mask = 0x07; /* MW0..2 */ 300 info->mwdma_mask = ATA_MWDMA2;
301 } 301 }
302 302
303 return 0; 303 return 0;
@@ -473,7 +473,7 @@ static int __devinit pata_icside_add_ports(struct pata_icside_info *info)
473 for (i = 0; i < info->nr_ports; i++) { 473 for (i = 0; i < info->nr_ports; i++) {
474 struct ata_port *ap = host->ports[i]; 474 struct ata_port *ap = host->ports[i];
475 475
476 ap->pio_mask = 0x1f; 476 ap->pio_mask = ATA_PIO4;
477 ap->mwdma_mask = info->mwdma_mask; 477 ap->mwdma_mask = info->mwdma_mask;
478 ap->flags |= ATA_FLAG_SLAVE_POSS; 478 ap->flags |= ATA_FLAG_SLAVE_POSS;
479 ap->ops = &pata_icside_port_ops; 479 ap->ops = &pata_icside_port_ops;
diff --git a/drivers/ata/pata_isapnp.c b/drivers/ata/pata_isapnp.c
index 15cdb9148aab..4bceb8803a10 100644
--- a/drivers/ata/pata_isapnp.c
+++ b/drivers/ata/pata_isapnp.c
@@ -17,7 +17,7 @@
17#include <linux/libata.h> 17#include <linux/libata.h>
18 18
19#define DRV_NAME "pata_isapnp" 19#define DRV_NAME "pata_isapnp"
20#define DRV_VERSION "0.2.2" 20#define DRV_VERSION "0.2.5"
21 21
22static struct scsi_host_template isapnp_sht = { 22static struct scsi_host_template isapnp_sht = {
23 ATA_PIO_SHT(DRV_NAME), 23 ATA_PIO_SHT(DRV_NAME),
@@ -28,6 +28,13 @@ static struct ata_port_operations isapnp_port_ops = {
28 .cable_detect = ata_cable_40wire, 28 .cable_detect = ata_cable_40wire,
29}; 29};
30 30
31static struct ata_port_operations isapnp_noalt_port_ops = {
32 .inherits = &ata_sff_port_ops,
33 .cable_detect = ata_cable_40wire,
34 /* No altstatus so we don't want to use the lost interrupt poll */
35 .lost_interrupt = ATA_OP_NULL,
36};
37
31/** 38/**
32 * isapnp_init_one - attach an isapnp interface 39 * isapnp_init_one - attach an isapnp interface
33 * @idev: PnP device 40 * @idev: PnP device
@@ -65,8 +72,8 @@ static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev
65 72
66 ap = host->ports[0]; 73 ap = host->ports[0];
67 74
68 ap->ops = &isapnp_port_ops; 75 ap->ops = &isapnp_noalt_port_ops;
69 ap->pio_mask = 1; 76 ap->pio_mask = ATA_PIO0;
70 ap->flags |= ATA_FLAG_SLAVE_POSS; 77 ap->flags |= ATA_FLAG_SLAVE_POSS;
71 78
72 ap->ioaddr.cmd_addr = cmd_addr; 79 ap->ioaddr.cmd_addr = cmd_addr;
@@ -76,6 +83,7 @@ static int isapnp_init_one(struct pnp_dev *idev, const struct pnp_device_id *dev
76 pnp_port_start(idev, 1), 1); 83 pnp_port_start(idev, 1), 1);
77 ap->ioaddr.altstatus_addr = ctl_addr; 84 ap->ioaddr.altstatus_addr = ctl_addr;
78 ap->ioaddr.ctl_addr = ctl_addr; 85 ap->ioaddr.ctl_addr = ctl_addr;
86 ap->ops = &isapnp_port_ops;
79 } 87 }
80 88
81 ata_sff_std_ports(&ap->ioaddr); 89 ata_sff_std_ports(&ap->ioaddr);
diff --git a/drivers/ata/pata_it8213.c b/drivers/ata/pata_it8213.c
index c113d7c079c8..f156da8076f7 100644
--- a/drivers/ata/pata_it8213.c
+++ b/drivers/ata/pata_it8213.c
@@ -262,8 +262,8 @@ static int it8213_init_one (struct pci_dev *pdev, const struct pci_device_id *en
262 static int printed_version; 262 static int printed_version;
263 static const struct ata_port_info info = { 263 static const struct ata_port_info info = {
264 .flags = ATA_FLAG_SLAVE_POSS, 264 .flags = ATA_FLAG_SLAVE_POSS,
265 .pio_mask = 0x1f, /* pio0-4 */ 265 .pio_mask = ATA_PIO4,
266 .mwdma_mask = 0x07, /* mwdma0-2 */ 266 .mwdma_mask = ATA_MWDMA2,
267 .udma_mask = ATA_UDMA4, /* FIXME: want UDMA 100? */ 267 .udma_mask = ATA_UDMA4, /* FIXME: want UDMA 100? */
268 .port_ops = &it8213_ops, 268 .port_ops = &it8213_ops,
269 }; 269 };
diff --git a/drivers/ata/pata_it821x.c b/drivers/ata/pata_it821x.c
index b05b86a912c5..188bc2fcd22c 100644
--- a/drivers/ata/pata_it821x.c
+++ b/drivers/ata/pata_it821x.c
@@ -875,29 +875,29 @@ static int it821x_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
875 875
876 static const struct ata_port_info info_smart = { 876 static const struct ata_port_info info_smart = {
877 .flags = ATA_FLAG_SLAVE_POSS, 877 .flags = ATA_FLAG_SLAVE_POSS,
878 .pio_mask = 0x1f, 878 .pio_mask = ATA_PIO4,
879 .mwdma_mask = 0x07, 879 .mwdma_mask = ATA_MWDMA2,
880 .udma_mask = ATA_UDMA6, 880 .udma_mask = ATA_UDMA6,
881 .port_ops = &it821x_smart_port_ops 881 .port_ops = &it821x_smart_port_ops
882 }; 882 };
883 static const struct ata_port_info info_passthru = { 883 static const struct ata_port_info info_passthru = {
884 .flags = ATA_FLAG_SLAVE_POSS, 884 .flags = ATA_FLAG_SLAVE_POSS,
885 .pio_mask = 0x1f, 885 .pio_mask = ATA_PIO4,
886 .mwdma_mask = 0x07, 886 .mwdma_mask = ATA_MWDMA2,
887 .udma_mask = ATA_UDMA6, 887 .udma_mask = ATA_UDMA6,
888 .port_ops = &it821x_passthru_port_ops 888 .port_ops = &it821x_passthru_port_ops
889 }; 889 };
890 static const struct ata_port_info info_rdc = { 890 static const struct ata_port_info info_rdc = {
891 .flags = ATA_FLAG_SLAVE_POSS, 891 .flags = ATA_FLAG_SLAVE_POSS,
892 .pio_mask = 0x1f, 892 .pio_mask = ATA_PIO4,
893 .mwdma_mask = 0x07, 893 .mwdma_mask = ATA_MWDMA2,
894 .udma_mask = ATA_UDMA6, 894 .udma_mask = ATA_UDMA6,
895 .port_ops = &it821x_rdc_port_ops 895 .port_ops = &it821x_rdc_port_ops
896 }; 896 };
897 static const struct ata_port_info info_rdc_11 = { 897 static const struct ata_port_info info_rdc_11 = {
898 .flags = ATA_FLAG_SLAVE_POSS, 898 .flags = ATA_FLAG_SLAVE_POSS,
899 .pio_mask = 0x1f, 899 .pio_mask = ATA_PIO4,
900 .mwdma_mask = 0x07, 900 .mwdma_mask = ATA_MWDMA2,
901 /* No UDMA */ 901 /* No UDMA */
902 .port_ops = &it821x_rdc_port_ops 902 .port_ops = &it821x_rdc_port_ops
903 }; 903 };
diff --git a/drivers/ata/pata_ixp4xx_cf.c b/drivers/ata/pata_ixp4xx_cf.c
index b173c157ab00..19fdecf319a6 100644
--- a/drivers/ata/pata_ixp4xx_cf.c
+++ b/drivers/ata/pata_ixp4xx_cf.c
@@ -176,7 +176,7 @@ static __devinit int ixp4xx_pata_probe(struct platform_device *pdev)
176 ap = host->ports[0]; 176 ap = host->ports[0];
177 177
178 ap->ops = &ixp4xx_port_ops; 178 ap->ops = &ixp4xx_port_ops;
179 ap->pio_mask = 0x1f; /* PIO4 */ 179 ap->pio_mask = ATA_PIO4;
180 ap->flags |= ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY | ATA_FLAG_NO_ATAPI; 180 ap->flags |= ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY | ATA_FLAG_NO_ATAPI;
181 181
182 ixp4xx_setup_port(ap, data, cs0->start, cs1->start); 182 ixp4xx_setup_port(ap, data, cs0->start, cs1->start);
diff --git a/drivers/ata/pata_jmicron.c b/drivers/ata/pata_jmicron.c
index 38cf1ab2d289..3a1474ac8838 100644
--- a/drivers/ata/pata_jmicron.c
+++ b/drivers/ata/pata_jmicron.c
@@ -136,8 +136,8 @@ static int jmicron_init_one (struct pci_dev *pdev, const struct pci_device_id *i
136 static const struct ata_port_info info = { 136 static const struct ata_port_info info = {
137 .flags = ATA_FLAG_SLAVE_POSS, 137 .flags = ATA_FLAG_SLAVE_POSS,
138 138
139 .pio_mask = 0x1f, 139 .pio_mask = ATA_PIO4,
140 .mwdma_mask = 0x07, 140 .mwdma_mask = ATA_MWDMA2,
141 .udma_mask = ATA_UDMA5, 141 .udma_mask = ATA_UDMA5,
142 142
143 .port_ops = &jmicron_ops, 143 .port_ops = &jmicron_ops,
diff --git a/drivers/ata/pata_legacy.c b/drivers/ata/pata_legacy.c
index e3bc1b436284..3f830f0fe2cc 100644
--- a/drivers/ata/pata_legacy.c
+++ b/drivers/ata/pata_legacy.c
@@ -129,7 +129,7 @@ static int qdi; /* Set to probe QDI controllers */
129static int winbond; /* Set to probe Winbond controllers, 129static int winbond; /* Set to probe Winbond controllers,
130 give I/O port if non standard */ 130 give I/O port if non standard */
131static int autospeed; /* Chip present which snoops speed changes */ 131static int autospeed; /* Chip present which snoops speed changes */
132static int pio_mask = 0x1F; /* PIO range for autospeed devices */ 132static int pio_mask = ATA_PIO4; /* PIO range for autospeed devices */
133static int iordy_mask = 0xFFFFFFFF; /* Use iordy if available */ 133static int iordy_mask = 0xFFFFFFFF; /* Use iordy if available */
134 134
135/** 135/**
diff --git a/drivers/ata/pata_marvell.c b/drivers/ata/pata_marvell.c
index 76e399bf8c1b..2096fb737f82 100644
--- a/drivers/ata/pata_marvell.c
+++ b/drivers/ata/pata_marvell.c
@@ -126,8 +126,8 @@ static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *i
126 static const struct ata_port_info info = { 126 static const struct ata_port_info info = {
127 .flags = ATA_FLAG_SLAVE_POSS, 127 .flags = ATA_FLAG_SLAVE_POSS,
128 128
129 .pio_mask = 0x1f, 129 .pio_mask = ATA_PIO4,
130 .mwdma_mask = 0x07, 130 .mwdma_mask = ATA_MWDMA2,
131 .udma_mask = ATA_UDMA5, 131 .udma_mask = ATA_UDMA5,
132 132
133 .port_ops = &marvell_ops, 133 .port_ops = &marvell_ops,
@@ -136,8 +136,8 @@ static int marvell_init_one (struct pci_dev *pdev, const struct pci_device_id *i
136 /* Slave possible as its magically mapped not real */ 136 /* Slave possible as its magically mapped not real */
137 .flags = ATA_FLAG_SLAVE_POSS, 137 .flags = ATA_FLAG_SLAVE_POSS,
138 138
139 .pio_mask = 0x1f, 139 .pio_mask = ATA_PIO4,
140 .mwdma_mask = 0x07, 140 .mwdma_mask = ATA_MWDMA2,
141 .udma_mask = ATA_UDMA6, 141 .udma_mask = ATA_UDMA6,
142 142
143 .port_ops = &marvell_ops, 143 .port_ops = &marvell_ops,
diff --git a/drivers/ata/pata_mpc52xx.c b/drivers/ata/pata_mpc52xx.c
index 50ae6d13078a..68d27bc70d06 100644
--- a/drivers/ata/pata_mpc52xx.c
+++ b/drivers/ata/pata_mpc52xx.c
@@ -737,10 +737,10 @@ mpc52xx_ata_probe(struct of_device *op, const struct of_device_id *match)
737 */ 737 */
738 prop = of_get_property(op->node, "mwdma-mode", &proplen); 738 prop = of_get_property(op->node, "mwdma-mode", &proplen);
739 if ((prop) && (proplen >= 4)) 739 if ((prop) && (proplen >= 4))
740 mwdma_mask = 0x7 & ((1 << (*prop + 1)) - 1); 740 mwdma_mask = ATA_MWDMA2 & ((1 << (*prop + 1)) - 1);
741 prop = of_get_property(op->node, "udma-mode", &proplen); 741 prop = of_get_property(op->node, "udma-mode", &proplen);
742 if ((prop) && (proplen >= 4)) 742 if ((prop) && (proplen >= 4))
743 udma_mask = 0x7 & ((1 << (*prop + 1)) - 1); 743 udma_mask = ATA_UDMA2 & ((1 << (*prop + 1)) - 1);
744 744
745 ata_irq = irq_of_parse_and_map(op->node, 0); 745 ata_irq = irq_of_parse_and_map(op->node, 0);
746 if (ata_irq == NO_IRQ) { 746 if (ata_irq == NO_IRQ) {
diff --git a/drivers/ata/pata_mpiix.c b/drivers/ata/pata_mpiix.c
index aa576cac4d17..b21f0021f54a 100644
--- a/drivers/ata/pata_mpiix.c
+++ b/drivers/ata/pata_mpiix.c
@@ -200,7 +200,7 @@ static int mpiix_init_one(struct pci_dev *dev, const struct pci_device_id *id)
200 the MPIIX your box goes castors up */ 200 the MPIIX your box goes castors up */
201 201
202 ap->ops = &mpiix_port_ops; 202 ap->ops = &mpiix_port_ops;
203 ap->pio_mask = 0x1F; 203 ap->pio_mask = ATA_PIO4;
204 ap->flags |= ATA_FLAG_SLAVE_POSS; 204 ap->flags |= ATA_FLAG_SLAVE_POSS;
205 205
206 ap->ioaddr.cmd_addr = cmd_addr; 206 ap->ioaddr.cmd_addr = cmd_addr;
diff --git a/drivers/ata/pata_netcell.c b/drivers/ata/pata_netcell.c
index 9dc05e1656a8..bdb236957cb9 100644
--- a/drivers/ata/pata_netcell.c
+++ b/drivers/ata/pata_netcell.c
@@ -51,8 +51,8 @@ static int netcell_init_one (struct pci_dev *pdev, const struct pci_device_id *e
51 .flags = ATA_FLAG_SLAVE_POSS, 51 .flags = ATA_FLAG_SLAVE_POSS,
52 /* Actually we don't really care about these as the 52 /* Actually we don't really care about these as the
53 firmware deals with it */ 53 firmware deals with it */
54 .pio_mask = 0x1f, /* pio0-4 */ 54 .pio_mask = ATA_PIO4,
55 .mwdma_mask = 0x07, /* mwdma0-2 */ 55 .mwdma_mask = ATA_MWDMA2,
56 .udma_mask = ATA_UDMA5, /* UDMA 133 */ 56 .udma_mask = ATA_UDMA5, /* UDMA 133 */
57 .port_ops = &netcell_ops, 57 .port_ops = &netcell_ops,
58 }; 58 };
diff --git a/drivers/ata/pata_ninja32.c b/drivers/ata/pata_ninja32.c
index 4dd9a3b031e4..0fb6b1b1e634 100644
--- a/drivers/ata/pata_ninja32.c
+++ b/drivers/ata/pata_ninja32.c
@@ -136,7 +136,7 @@ static int ninja32_init_one(struct pci_dev *dev, const struct pci_device_id *id)
136 if (!base) 136 if (!base)
137 return -ENOMEM; 137 return -ENOMEM;
138 ap->ops = &ninja32_port_ops; 138 ap->ops = &ninja32_port_ops;
139 ap->pio_mask = 0x1F; 139 ap->pio_mask = ATA_PIO4;
140 ap->flags |= ATA_FLAG_SLAVE_POSS; 140 ap->flags |= ATA_FLAG_SLAVE_POSS;
141 141
142 ap->ioaddr.cmd_addr = base + 0x10; 142 ap->ioaddr.cmd_addr = base + 0x10;
diff --git a/drivers/ata/pata_ns87410.c b/drivers/ata/pata_ns87410.c
index 40d411c460de..ca53fac06717 100644
--- a/drivers/ata/pata_ns87410.c
+++ b/drivers/ata/pata_ns87410.c
@@ -144,7 +144,7 @@ static int ns87410_init_one(struct pci_dev *dev, const struct pci_device_id *id)
144{ 144{
145 static const struct ata_port_info info = { 145 static const struct ata_port_info info = {
146 .flags = ATA_FLAG_SLAVE_POSS, 146 .flags = ATA_FLAG_SLAVE_POSS,
147 .pio_mask = 0x0F, 147 .pio_mask = ATA_PIO3,
148 .port_ops = &ns87410_port_ops 148 .port_ops = &ns87410_port_ops
149 }; 149 };
150 const struct ata_port_info *ppi[] = { &info, NULL }; 150 const struct ata_port_info *ppi[] = { &info, NULL };
diff --git a/drivers/ata/pata_ns87415.c b/drivers/ata/pata_ns87415.c
index 89bf5f865d6a..773b1590b492 100644
--- a/drivers/ata/pata_ns87415.c
+++ b/drivers/ata/pata_ns87415.c
@@ -346,8 +346,8 @@ static int ns87415_init_one (struct pci_dev *pdev, const struct pci_device_id *e
346 static int printed_version; 346 static int printed_version;
347 static const struct ata_port_info info = { 347 static const struct ata_port_info info = {
348 .flags = ATA_FLAG_SLAVE_POSS, 348 .flags = ATA_FLAG_SLAVE_POSS,
349 .pio_mask = 0x1f, /* pio0-4 */ 349 .pio_mask = ATA_PIO4,
350 .mwdma_mask = 0x07, /* mwdma0-2 */ 350 .mwdma_mask = ATA_MWDMA2,
351 .port_ops = &ns87415_pata_ops, 351 .port_ops = &ns87415_pata_ops,
352 }; 352 };
353 const struct ata_port_info *ppi[] = { &info, NULL }; 353 const struct ata_port_info *ppi[] = { &info, NULL };
@@ -355,8 +355,8 @@ static int ns87415_init_one (struct pci_dev *pdev, const struct pci_device_id *e
355#if defined(CONFIG_SUPERIO) 355#if defined(CONFIG_SUPERIO)
356 static const struct ata_port_info info87560 = { 356 static const struct ata_port_info info87560 = {
357 .flags = ATA_FLAG_SLAVE_POSS, 357 .flags = ATA_FLAG_SLAVE_POSS,
358 .pio_mask = 0x1f, /* pio0-4 */ 358 .pio_mask = ATA_PIO4,
359 .mwdma_mask = 0x07, /* mwdma0-2 */ 359 .mwdma_mask = ATA_MWDMA2,
360 .port_ops = &ns87560_pata_ops, 360 .port_ops = &ns87560_pata_ops,
361 }; 361 };
362 362
diff --git a/drivers/ata/pata_octeon_cf.c b/drivers/ata/pata_octeon_cf.c
index 0fe4ef309c62..efe2c1985af3 100644
--- a/drivers/ata/pata_octeon_cf.c
+++ b/drivers/ata/pata_octeon_cf.c
@@ -871,7 +871,7 @@ static int __devinit octeon_cf_probe(struct platform_device *pdev)
871 ap->private_data = cf_port; 871 ap->private_data = cf_port;
872 cf_port->ap = ap; 872 cf_port->ap = ap;
873 ap->ops = &octeon_cf_ops; 873 ap->ops = &octeon_cf_ops;
874 ap->pio_mask = 0x7f; /* Support PIO 0-6 */ 874 ap->pio_mask = ATA_PIO6;
875 ap->flags |= ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY 875 ap->flags |= ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY
876 | ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING; 876 | ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING;
877 877
@@ -900,7 +900,7 @@ static int __devinit octeon_cf_probe(struct platform_device *pdev)
900 ap->ioaddr.ctl_addr = cs1 + (6 << 1) + 1; 900 ap->ioaddr.ctl_addr = cs1 + (6 << 1) + 1;
901 octeon_cf_ops.sff_data_xfer = octeon_cf_data_xfer16; 901 octeon_cf_ops.sff_data_xfer = octeon_cf_data_xfer16;
902 902
903 ap->mwdma_mask = 0x1f; /* Support MWDMA 0-4 */ 903 ap->mwdma_mask = ATA_MWDMA4;
904 irq = platform_get_irq(pdev, 0); 904 irq = platform_get_irq(pdev, 0);
905 irq_handler = octeon_cf_interrupt; 905 irq_handler = octeon_cf_interrupt;
906 906
diff --git a/drivers/ata/pata_oldpiix.c b/drivers/ata/pata_oldpiix.c
index 2c1a91c40c1a..84ac5033ac89 100644
--- a/drivers/ata/pata_oldpiix.c
+++ b/drivers/ata/pata_oldpiix.c
@@ -238,8 +238,8 @@ static int oldpiix_init_one (struct pci_dev *pdev, const struct pci_device_id *e
238 static int printed_version; 238 static int printed_version;
239 static const struct ata_port_info info = { 239 static const struct ata_port_info info = {
240 .flags = ATA_FLAG_SLAVE_POSS, 240 .flags = ATA_FLAG_SLAVE_POSS,
241 .pio_mask = 0x1f, /* pio0-4 */ 241 .pio_mask = ATA_PIO4,
242 .mwdma_mask = 0x07, /* mwdma1-2 */ 242 .mwdma_mask = ATA_MWDMA2,
243 .port_ops = &oldpiix_pata_ops, 243 .port_ops = &oldpiix_pata_ops,
244 }; 244 };
245 const struct ata_port_info *ppi[] = { &info, NULL }; 245 const struct ata_port_info *ppi[] = { &info, NULL };
diff --git a/drivers/ata/pata_opti.c b/drivers/ata/pata_opti.c
index e4fa4d565e96..99eddda2d2e5 100644
--- a/drivers/ata/pata_opti.c
+++ b/drivers/ata/pata_opti.c
@@ -163,7 +163,7 @@ static int opti_init_one(struct pci_dev *dev, const struct pci_device_id *id)
163{ 163{
164 static const struct ata_port_info info = { 164 static const struct ata_port_info info = {
165 .flags = ATA_FLAG_SLAVE_POSS, 165 .flags = ATA_FLAG_SLAVE_POSS,
166 .pio_mask = 0x1f, 166 .pio_mask = ATA_PIO4,
167 .port_ops = &opti_port_ops 167 .port_ops = &opti_port_ops
168 }; 168 };
169 const struct ata_port_info *ppi[] = { &info, NULL }; 169 const struct ata_port_info *ppi[] = { &info, NULL };
diff --git a/drivers/ata/pata_optidma.c b/drivers/ata/pata_optidma.c
index 93bb6e91973f..86885a445f97 100644
--- a/drivers/ata/pata_optidma.c
+++ b/drivers/ata/pata_optidma.c
@@ -399,15 +399,15 @@ static int optidma_init_one(struct pci_dev *dev, const struct pci_device_id *id)
399{ 399{
400 static const struct ata_port_info info_82c700 = { 400 static const struct ata_port_info info_82c700 = {
401 .flags = ATA_FLAG_SLAVE_POSS, 401 .flags = ATA_FLAG_SLAVE_POSS,
402 .pio_mask = 0x1f, 402 .pio_mask = ATA_PIO4,
403 .mwdma_mask = 0x07, 403 .mwdma_mask = ATA_MWDMA2,
404 .port_ops = &optidma_port_ops 404 .port_ops = &optidma_port_ops
405 }; 405 };
406 static const struct ata_port_info info_82c700_udma = { 406 static const struct ata_port_info info_82c700_udma = {
407 .flags = ATA_FLAG_SLAVE_POSS, 407 .flags = ATA_FLAG_SLAVE_POSS,
408 .pio_mask = 0x1f, 408 .pio_mask = ATA_PIO4,
409 .mwdma_mask = 0x07, 409 .mwdma_mask = ATA_MWDMA2,
410 .udma_mask = 0x07, 410 .udma_mask = ATA_UDMA2,
411 .port_ops = &optiplus_port_ops 411 .port_ops = &optiplus_port_ops
412 }; 412 };
413 const struct ata_port_info *ppi[] = { &info_82c700, NULL }; 413 const struct ata_port_info *ppi[] = { &info_82c700, NULL };
diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
index 64b2e2281ee7..f4d009ed50ac 100644
--- a/drivers/ata/pata_pcmcia.c
+++ b/drivers/ata/pata_pcmcia.c
@@ -42,7 +42,7 @@
42 42
43 43
44#define DRV_NAME "pata_pcmcia" 44#define DRV_NAME "pata_pcmcia"
45#define DRV_VERSION "0.3.3" 45#define DRV_VERSION "0.3.5"
46 46
47/* 47/*
48 * Private data structure to glue stuff together 48 * Private data structure to glue stuff together
@@ -126,6 +126,37 @@ static unsigned int ata_data_xfer_8bit(struct ata_device *dev,
126 return buflen; 126 return buflen;
127} 127}
128 128
129/**
130 * pcmcia_8bit_drain_fifo - Stock FIFO drain logic for SFF controllers
131 * @qc: command
132 *
133 * Drain the FIFO and device of any stuck data following a command
134 * failing to complete. In some cases this is neccessary before a
135 * reset will recover the device.
136 *
137 */
138
139void pcmcia_8bit_drain_fifo(struct ata_queued_cmd *qc)
140{
141 int count;
142 struct ata_port *ap;
143
144 /* We only need to flush incoming data when a command was running */
145 if (qc == NULL || qc->dma_dir == DMA_TO_DEVICE)
146 return;
147
148 ap = qc->ap;
149
150 /* Drain up to 64K of data before we give up this recovery method */
151 for (count = 0; (ap->ops->sff_check_status(ap) & ATA_DRQ)
152 && count++ < 65536;)
153 ioread8(ap->ioaddr.data_addr);
154
155 if (count)
156 ata_port_printk(ap, KERN_WARNING, "drained %d bytes to clear DRQ.\n",
157 count);
158
159}
129 160
130static struct scsi_host_template pcmcia_sht = { 161static struct scsi_host_template pcmcia_sht = {
131 ATA_PIO_SHT(DRV_NAME), 162 ATA_PIO_SHT(DRV_NAME),
@@ -143,6 +174,7 @@ static struct ata_port_operations pcmcia_8bit_port_ops = {
143 .sff_data_xfer = ata_data_xfer_8bit, 174 .sff_data_xfer = ata_data_xfer_8bit,
144 .cable_detect = ata_cable_40wire, 175 .cable_detect = ata_cable_40wire,
145 .set_mode = pcmcia_set_mode_8bit, 176 .set_mode = pcmcia_set_mode_8bit,
177 .drain_fifo = pcmcia_8bit_drain_fifo,
146}; 178};
147 179
148#define CS_CHECK(fn, ret) \ 180#define CS_CHECK(fn, ret) \
@@ -299,7 +331,7 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
299 ap = host->ports[p]; 331 ap = host->ports[p];
300 332
301 ap->ops = ops; 333 ap->ops = ops;
302 ap->pio_mask = 1; /* ISA so PIO 0 cycles */ 334 ap->pio_mask = ATA_PIO0; /* ISA so PIO 0 cycles */
303 ap->flags |= ATA_FLAG_SLAVE_POSS; 335 ap->flags |= ATA_FLAG_SLAVE_POSS;
304 ap->ioaddr.cmd_addr = io_addr + 0x10 * p; 336 ap->ioaddr.cmd_addr = io_addr + 0x10 * p;
305 ap->ioaddr.altstatus_addr = ctl_addr + 0x10 * p; 337 ap->ioaddr.altstatus_addr = ctl_addr + 0x10 * p;
diff --git a/drivers/ata/pata_pdc2027x.c b/drivers/ata/pata_pdc2027x.c
index e94efccaa482..ca5cad0fd80b 100644
--- a/drivers/ata/pata_pdc2027x.c
+++ b/drivers/ata/pata_pdc2027x.c
@@ -152,18 +152,18 @@ static struct ata_port_info pdc2027x_port_info[] = {
152 { 152 {
153 .flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_SLAVE_POSS | 153 .flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_SLAVE_POSS |
154 ATA_FLAG_MMIO, 154 ATA_FLAG_MMIO,
155 .pio_mask = 0x1f, /* pio0-4 */ 155 .pio_mask = ATA_PIO4,
156 .mwdma_mask = 0x07, /* mwdma0-2 */ 156 .mwdma_mask = ATA_MWDMA2,
157 .udma_mask = ATA_UDMA5, /* udma0-5 */ 157 .udma_mask = ATA_UDMA5,
158 .port_ops = &pdc2027x_pata100_ops, 158 .port_ops = &pdc2027x_pata100_ops,
159 }, 159 },
160 /* PDC_UDMA_133 */ 160 /* PDC_UDMA_133 */
161 { 161 {
162 .flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_SLAVE_POSS | 162 .flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_SLAVE_POSS |
163 ATA_FLAG_MMIO, 163 ATA_FLAG_MMIO,
164 .pio_mask = 0x1f, /* pio0-4 */ 164 .pio_mask = ATA_PIO4,
165 .mwdma_mask = 0x07, /* mwdma0-2 */ 165 .mwdma_mask = ATA_MWDMA2,
166 .udma_mask = ATA_UDMA6, /* udma0-6 */ 166 .udma_mask = ATA_UDMA6,
167 .port_ops = &pdc2027x_pata133_ops, 167 .port_ops = &pdc2027x_pata133_ops,
168 }, 168 },
169}; 169};
diff --git a/drivers/ata/pata_pdc202xx_old.c b/drivers/ata/pata_pdc202xx_old.c
index 799a6a098712..5fedb3d4032b 100644
--- a/drivers/ata/pata_pdc202xx_old.c
+++ b/drivers/ata/pata_pdc202xx_old.c
@@ -291,22 +291,22 @@ static int pdc202xx_init_one(struct pci_dev *dev, const struct pci_device_id *id
291 static const struct ata_port_info info[3] = { 291 static const struct ata_port_info info[3] = {
292 { 292 {
293 .flags = ATA_FLAG_SLAVE_POSS, 293 .flags = ATA_FLAG_SLAVE_POSS,
294 .pio_mask = 0x1f, 294 .pio_mask = ATA_PIO4,
295 .mwdma_mask = 0x07, 295 .mwdma_mask = ATA_MWDMA2,
296 .udma_mask = ATA_UDMA2, 296 .udma_mask = ATA_UDMA2,
297 .port_ops = &pdc2024x_port_ops 297 .port_ops = &pdc2024x_port_ops
298 }, 298 },
299 { 299 {
300 .flags = ATA_FLAG_SLAVE_POSS, 300 .flags = ATA_FLAG_SLAVE_POSS,
301 .pio_mask = 0x1f, 301 .pio_mask = ATA_PIO4,
302 .mwdma_mask = 0x07, 302 .mwdma_mask = ATA_MWDMA2,
303 .udma_mask = ATA_UDMA4, 303 .udma_mask = ATA_UDMA4,
304 .port_ops = &pdc2026x_port_ops 304 .port_ops = &pdc2026x_port_ops
305 }, 305 },
306 { 306 {
307 .flags = ATA_FLAG_SLAVE_POSS, 307 .flags = ATA_FLAG_SLAVE_POSS,
308 .pio_mask = 0x1f, 308 .pio_mask = ATA_PIO4,
309 .mwdma_mask = 0x07, 309 .mwdma_mask = ATA_MWDMA2,
310 .udma_mask = ATA_UDMA5, 310 .udma_mask = ATA_UDMA5,
311 .port_ops = &pdc2026x_port_ops 311 .port_ops = &pdc2026x_port_ops
312 } 312 }
diff --git a/drivers/ata/pata_qdi.c b/drivers/ata/pata_qdi.c
index f1b26f7c8e4d..45879dc6fa41 100644
--- a/drivers/ata/pata_qdi.c
+++ b/drivers/ata/pata_qdi.c
@@ -212,11 +212,11 @@ static __init int qdi_init_one(unsigned long port, int type, unsigned long io, i
212 212
213 if (type == 6580) { 213 if (type == 6580) {
214 ap->ops = &qdi6580_port_ops; 214 ap->ops = &qdi6580_port_ops;
215 ap->pio_mask = 0x1F; 215 ap->pio_mask = ATA_PIO4;
216 ap->flags |= ATA_FLAG_SLAVE_POSS; 216 ap->flags |= ATA_FLAG_SLAVE_POSS;
217 } else { 217 } else {
218 ap->ops = &qdi6500_port_ops; 218 ap->ops = &qdi6500_port_ops;
219 ap->pio_mask = 0x07; /* Actually PIO3 !IORDY is possible */ 219 ap->pio_mask = ATA_PIO2; /* Actually PIO3 !IORDY is possible */
220 ap->flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY; 220 ap->flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
221 } 221 }
222 222
diff --git a/drivers/ata/pata_radisys.c b/drivers/ata/pata_radisys.c
index 695d44ae52c6..4401b332eaab 100644
--- a/drivers/ata/pata_radisys.c
+++ b/drivers/ata/pata_radisys.c
@@ -216,9 +216,9 @@ static int radisys_init_one (struct pci_dev *pdev, const struct pci_device_id *e
216 static int printed_version; 216 static int printed_version;
217 static const struct ata_port_info info = { 217 static const struct ata_port_info info = {
218 .flags = ATA_FLAG_SLAVE_POSS, 218 .flags = ATA_FLAG_SLAVE_POSS,
219 .pio_mask = 0x1f, /* pio0-4 */ 219 .pio_mask = ATA_PIO4,
220 .mwdma_mask = 0x07, /* mwdma1-2 */ 220 .mwdma_mask = ATA_MWDMA12_ONLY,
221 .udma_mask = 0x14, /* UDMA33/66 only */ 221 .udma_mask = ATA_UDMA24_ONLY,
222 .port_ops = &radisys_pata_ops, 222 .port_ops = &radisys_pata_ops,
223 }; 223 };
224 const struct ata_port_info *ppi[] = { &info, NULL }; 224 const struct ata_port_info *ppi[] = { &info, NULL };
diff --git a/drivers/ata/pata_rb532_cf.c b/drivers/ata/pata_rb532_cf.c
index ebfcda26d639..8e3cdef8a25f 100644
--- a/drivers/ata/pata_rb532_cf.c
+++ b/drivers/ata/pata_rb532_cf.c
@@ -48,63 +48,11 @@
48struct rb532_cf_info { 48struct rb532_cf_info {
49 void __iomem *iobase; 49 void __iomem *iobase;
50 unsigned int gpio_line; 50 unsigned int gpio_line;
51 int frozen;
52 unsigned int irq; 51 unsigned int irq;
53}; 52};
54 53
55/* ------------------------------------------------------------------------ */ 54/* ------------------------------------------------------------------------ */
56 55
57static inline void rb532_pata_finish_io(struct ata_port *ap)
58{
59 struct ata_host *ah = ap->host;
60 struct rb532_cf_info *info = ah->private_data;
61
62 /* FIXME: Keep previous delay. If this is merely a fence then
63 ata_sff_sync might be sufficient. */
64 ata_sff_dma_pause(ap);
65 ndelay(RB500_CF_IO_DELAY);
66}
67
68static void rb532_pata_exec_command(struct ata_port *ap,
69 const struct ata_taskfile *tf)
70{
71 writeb(tf->command, ap->ioaddr.command_addr);
72 rb532_pata_finish_io(ap);
73}
74
75static unsigned int rb532_pata_data_xfer(struct ata_device *adev, unsigned char *buf,
76 unsigned int buflen, int write_data)
77{
78 struct ata_port *ap = adev->link->ap;
79 void __iomem *ioaddr = ap->ioaddr.data_addr;
80 int retlen = buflen;
81
82 if (write_data) {
83 for (; buflen > 0; buflen--, buf++)
84 writeb(*buf, ioaddr);
85 } else {
86 for (; buflen > 0; buflen--, buf++)
87 *buf = readb(ioaddr);
88 }
89
90 rb532_pata_finish_io(adev->link->ap);
91 return retlen;
92}
93
94static void rb532_pata_freeze(struct ata_port *ap)
95{
96 struct rb532_cf_info *info = ap->host->private_data;
97
98 info->frozen = 1;
99}
100
101static void rb532_pata_thaw(struct ata_port *ap)
102{
103 struct rb532_cf_info *info = ap->host->private_data;
104
105 info->frozen = 0;
106}
107
108static irqreturn_t rb532_pata_irq_handler(int irq, void *dev_instance) 56static irqreturn_t rb532_pata_irq_handler(int irq, void *dev_instance)
109{ 57{
110 struct ata_host *ah = dev_instance; 58 struct ata_host *ah = dev_instance;
@@ -112,8 +60,7 @@ static irqreturn_t rb532_pata_irq_handler(int irq, void *dev_instance)
112 60
113 if (gpio_get_value(info->gpio_line)) { 61 if (gpio_get_value(info->gpio_line)) {
114 set_irq_type(info->irq, IRQ_TYPE_LEVEL_LOW); 62 set_irq_type(info->irq, IRQ_TYPE_LEVEL_LOW);
115 if (!info->frozen) 63 ata_sff_interrupt(info->irq, dev_instance);
116 ata_sff_interrupt(info->irq, dev_instance);
117 } else { 64 } else {
118 set_irq_type(info->irq, IRQ_TYPE_LEVEL_HIGH); 65 set_irq_type(info->irq, IRQ_TYPE_LEVEL_HIGH);
119 } 66 }
@@ -123,10 +70,7 @@ static irqreturn_t rb532_pata_irq_handler(int irq, void *dev_instance)
123 70
124static struct ata_port_operations rb532_pata_port_ops = { 71static struct ata_port_operations rb532_pata_port_ops = {
125 .inherits = &ata_sff_port_ops, 72 .inherits = &ata_sff_port_ops,
126 .sff_exec_command = rb532_pata_exec_command, 73 .sff_data_xfer = ata_sff_data_xfer32,
127 .sff_data_xfer = rb532_pata_data_xfer,
128 .freeze = rb532_pata_freeze,
129 .thaw = rb532_pata_thaw,
130}; 74};
131 75
132/* ------------------------------------------------------------------------ */ 76/* ------------------------------------------------------------------------ */
@@ -145,7 +89,7 @@ static void rb532_pata_setup_ports(struct ata_host *ah)
145 ap = ah->ports[0]; 89 ap = ah->ports[0];
146 90
147 ap->ops = &rb532_pata_port_ops; 91 ap->ops = &rb532_pata_port_ops;
148 ap->pio_mask = 0x1f; /* PIO4 */ 92 ap->pio_mask = ATA_PIO4;
149 ap->flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO; 93 ap->flags = ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO;
150 94
151 ap->ioaddr.cmd_addr = info->iobase + RB500_CF_REG_BASE; 95 ap->ioaddr.cmd_addr = info->iobase + RB500_CF_REG_BASE;
@@ -160,7 +104,7 @@ static void rb532_pata_setup_ports(struct ata_host *ah)
160 104
161static __devinit int rb532_pata_driver_probe(struct platform_device *pdev) 105static __devinit int rb532_pata_driver_probe(struct platform_device *pdev)
162{ 106{
163 unsigned int irq; 107 int irq;
164 int gpio; 108 int gpio;
165 struct resource *res; 109 struct resource *res;
166 struct ata_host *ah; 110 struct ata_host *ah;
diff --git a/drivers/ata/pata_rz1000.c b/drivers/ata/pata_rz1000.c
index 46d6bc1bf1e9..0c574c065c62 100644
--- a/drivers/ata/pata_rz1000.c
+++ b/drivers/ata/pata_rz1000.c
@@ -88,7 +88,7 @@ static int rz1000_init_one (struct pci_dev *pdev, const struct pci_device_id *en
88 static int printed_version; 88 static int printed_version;
89 static const struct ata_port_info info = { 89 static const struct ata_port_info info = {
90 .flags = ATA_FLAG_SLAVE_POSS, 90 .flags = ATA_FLAG_SLAVE_POSS,
91 .pio_mask = 0x1f, 91 .pio_mask = ATA_PIO4,
92 .port_ops = &rz1000_port_ops 92 .port_ops = &rz1000_port_ops
93 }; 93 };
94 const struct ata_port_info *ppi[] = { &info, NULL }; 94 const struct ata_port_info *ppi[] = { &info, NULL };
diff --git a/drivers/ata/pata_sc1200.c b/drivers/ata/pata_sc1200.c
index 9a4bdca54616..f49814d6fd2e 100644
--- a/drivers/ata/pata_sc1200.c
+++ b/drivers/ata/pata_sc1200.c
@@ -2,7 +2,6 @@
2 * New ATA layer SC1200 driver Alan Cox <alan@lxorguk.ukuu.org.uk> 2 * New ATA layer SC1200 driver Alan Cox <alan@lxorguk.ukuu.org.uk>
3 * 3 *
4 * TODO: Mode selection filtering 4 * TODO: Mode selection filtering
5 * TODO: Can't enable second channel until ATA core has serialize
6 * TODO: Needs custom DMA cleanup code 5 * TODO: Needs custom DMA cleanup code
7 * 6 *
8 * Based very heavily on 7 * Based very heavily on
@@ -178,6 +177,31 @@ static unsigned int sc1200_qc_issue(struct ata_queued_cmd *qc)
178 return ata_sff_qc_issue(qc); 177 return ata_sff_qc_issue(qc);
179} 178}
180 179
180/**
181 * sc1200_qc_defer - implement serialization
182 * @qc: command
183 *
184 * Serialize command issue on this controller.
185 */
186
187static int sc1200_qc_defer(struct ata_queued_cmd *qc)
188{
189 struct ata_host *host = qc->ap->host;
190 struct ata_port *alt = host->ports[1 ^ qc->ap->port_no];
191 int rc;
192
193 /* First apply the usual rules */
194 rc = ata_std_qc_defer(qc);
195 if (rc != 0)
196 return rc;
197
198 /* Now apply serialization rules. Only allow a command if the
199 other channel state machine is idle */
200 if (alt && alt->qc_active)
201 return ATA_DEFER_PORT;
202 return 0;
203}
204
181static struct scsi_host_template sc1200_sht = { 205static struct scsi_host_template sc1200_sht = {
182 ATA_BMDMA_SHT(DRV_NAME), 206 ATA_BMDMA_SHT(DRV_NAME),
183 .sg_tablesize = LIBATA_DUMB_MAX_PRD, 207 .sg_tablesize = LIBATA_DUMB_MAX_PRD,
@@ -187,6 +211,7 @@ static struct ata_port_operations sc1200_port_ops = {
187 .inherits = &ata_bmdma_port_ops, 211 .inherits = &ata_bmdma_port_ops,
188 .qc_prep = ata_sff_dumb_qc_prep, 212 .qc_prep = ata_sff_dumb_qc_prep,
189 .qc_issue = sc1200_qc_issue, 213 .qc_issue = sc1200_qc_issue,
214 .qc_defer = sc1200_qc_defer,
190 .cable_detect = ata_cable_40wire, 215 .cable_detect = ata_cable_40wire,
191 .set_piomode = sc1200_set_piomode, 216 .set_piomode = sc1200_set_piomode,
192 .set_dmamode = sc1200_set_dmamode, 217 .set_dmamode = sc1200_set_dmamode,
@@ -205,13 +230,13 @@ static int sc1200_init_one(struct pci_dev *dev, const struct pci_device_id *id)
205{ 230{
206 static const struct ata_port_info info = { 231 static const struct ata_port_info info = {
207 .flags = ATA_FLAG_SLAVE_POSS, 232 .flags = ATA_FLAG_SLAVE_POSS,
208 .pio_mask = 0x1f, 233 .pio_mask = ATA_PIO4,
209 .mwdma_mask = 0x07, 234 .mwdma_mask = ATA_MWDMA2,
210 .udma_mask = 0x07, 235 .udma_mask = ATA_UDMA2,
211 .port_ops = &sc1200_port_ops 236 .port_ops = &sc1200_port_ops
212 }; 237 };
213 /* Can't enable port 2 yet, see top comments */ 238 /* Can't enable port 2 yet, see top comments */
214 const struct ata_port_info *ppi[] = { &info, &ata_dummy_port_info }; 239 const struct ata_port_info *ppi[] = { &info, };
215 240
216 return ata_pci_sff_init_one(dev, ppi, &sc1200_sht, NULL); 241 return ata_pci_sff_init_one(dev, ppi, &sc1200_sht, NULL);
217} 242}
diff --git a/drivers/ata/pata_scc.c b/drivers/ata/pata_scc.c
index d447f1cb46ec..4257d6b40af4 100644
--- a/drivers/ata/pata_scc.c
+++ b/drivers/ata/pata_scc.c
@@ -1001,8 +1001,8 @@ static struct ata_port_operations scc_pata_ops = {
1001static struct ata_port_info scc_port_info[] = { 1001static struct ata_port_info scc_port_info[] = {
1002 { 1002 {
1003 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY, 1003 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_MMIO | ATA_FLAG_NO_LEGACY,
1004 .pio_mask = 0x1f, /* pio0-4 */ 1004 .pio_mask = ATA_PIO4,
1005 .mwdma_mask = 0x00, 1005 /* No MWDMA */
1006 .udma_mask = ATA_UDMA6, 1006 .udma_mask = ATA_UDMA6,
1007 .port_ops = &scc_pata_ops, 1007 .port_ops = &scc_pata_ops,
1008 }, 1008 },
diff --git a/drivers/ata/pata_sch.c b/drivers/ata/pata_sch.c
index 6aeeeeb34124..99cceb458e2a 100644
--- a/drivers/ata/pata_sch.c
+++ b/drivers/ata/pata_sch.c
@@ -84,9 +84,9 @@ static struct ata_port_operations sch_pata_ops = {
84 84
85static struct ata_port_info sch_port_info = { 85static struct ata_port_info sch_port_info = {
86 .flags = ATA_FLAG_SLAVE_POSS, 86 .flags = ATA_FLAG_SLAVE_POSS,
87 .pio_mask = ATA_PIO4, /* pio0-4 */ 87 .pio_mask = ATA_PIO4,
88 .mwdma_mask = ATA_MWDMA2, /* mwdma0-2 */ 88 .mwdma_mask = ATA_MWDMA2,
89 .udma_mask = ATA_UDMA5, /* udma0-5 */ 89 .udma_mask = ATA_UDMA5,
90 .port_ops = &sch_pata_ops, 90 .port_ops = &sch_pata_ops,
91}; 91};
92 92
diff --git a/drivers/ata/pata_serverworks.c b/drivers/ata/pata_serverworks.c
index 8d2fd9dd40c7..beaed12d50e4 100644
--- a/drivers/ata/pata_serverworks.c
+++ b/drivers/ata/pata_serverworks.c
@@ -398,26 +398,26 @@ static int serverworks_init_one(struct pci_dev *pdev, const struct pci_device_id
398 static const struct ata_port_info info[4] = { 398 static const struct ata_port_info info[4] = {
399 { /* OSB4 */ 399 { /* OSB4 */
400 .flags = ATA_FLAG_SLAVE_POSS, 400 .flags = ATA_FLAG_SLAVE_POSS,
401 .pio_mask = 0x1f, 401 .pio_mask = ATA_PIO4,
402 .mwdma_mask = 0x07, 402 .mwdma_mask = ATA_MWDMA2,
403 .udma_mask = 0x07, 403 .udma_mask = ATA_UDMA2,
404 .port_ops = &serverworks_osb4_port_ops 404 .port_ops = &serverworks_osb4_port_ops
405 }, { /* OSB4 no UDMA */ 405 }, { /* OSB4 no UDMA */
406 .flags = ATA_FLAG_SLAVE_POSS, 406 .flags = ATA_FLAG_SLAVE_POSS,
407 .pio_mask = 0x1f, 407 .pio_mask = ATA_PIO4,
408 .mwdma_mask = 0x07, 408 .mwdma_mask = ATA_MWDMA2,
409 .udma_mask = 0x00, 409 /* No UDMA */
410 .port_ops = &serverworks_osb4_port_ops 410 .port_ops = &serverworks_osb4_port_ops
411 }, { /* CSB5 */ 411 }, { /* CSB5 */
412 .flags = ATA_FLAG_SLAVE_POSS, 412 .flags = ATA_FLAG_SLAVE_POSS,
413 .pio_mask = 0x1f, 413 .pio_mask = ATA_PIO4,
414 .mwdma_mask = 0x07, 414 .mwdma_mask = ATA_MWDMA2,
415 .udma_mask = ATA_UDMA4, 415 .udma_mask = ATA_UDMA4,
416 .port_ops = &serverworks_csb_port_ops 416 .port_ops = &serverworks_csb_port_ops
417 }, { /* CSB5 - later revisions*/ 417 }, { /* CSB5 - later revisions*/
418 .flags = ATA_FLAG_SLAVE_POSS, 418 .flags = ATA_FLAG_SLAVE_POSS,
419 .pio_mask = 0x1f, 419 .pio_mask = ATA_PIO4,
420 .mwdma_mask = 0x07, 420 .mwdma_mask = ATA_MWDMA2,
421 .udma_mask = ATA_UDMA5, 421 .udma_mask = ATA_UDMA5,
422 .port_ops = &serverworks_csb_port_ops 422 .port_ops = &serverworks_csb_port_ops
423 } 423 }
diff --git a/drivers/ata/pata_sil680.c b/drivers/ata/pata_sil680.c
index 9e764e5747e6..4cb649d8d38c 100644
--- a/drivers/ata/pata_sil680.c
+++ b/drivers/ata/pata_sil680.c
@@ -282,15 +282,15 @@ static int __devinit sil680_init_one(struct pci_dev *pdev,
282{ 282{
283 static const struct ata_port_info info = { 283 static const struct ata_port_info info = {
284 .flags = ATA_FLAG_SLAVE_POSS, 284 .flags = ATA_FLAG_SLAVE_POSS,
285 .pio_mask = 0x1f, 285 .pio_mask = ATA_PIO4,
286 .mwdma_mask = 0x07, 286 .mwdma_mask = ATA_MWDMA2,
287 .udma_mask = ATA_UDMA6, 287 .udma_mask = ATA_UDMA6,
288 .port_ops = &sil680_port_ops 288 .port_ops = &sil680_port_ops
289 }; 289 };
290 static const struct ata_port_info info_slow = { 290 static const struct ata_port_info info_slow = {
291 .flags = ATA_FLAG_SLAVE_POSS, 291 .flags = ATA_FLAG_SLAVE_POSS,
292 .pio_mask = 0x1f, 292 .pio_mask = ATA_PIO4,
293 .mwdma_mask = 0x07, 293 .mwdma_mask = ATA_MWDMA2,
294 .udma_mask = ATA_UDMA5, 294 .udma_mask = ATA_UDMA5,
295 .port_ops = &sil680_port_ops 295 .port_ops = &sil680_port_ops
296 }; 296 };
diff --git a/drivers/ata/pata_sis.c b/drivers/ata/pata_sis.c
index 27ceb42a774b..488e77bcd22b 100644
--- a/drivers/ata/pata_sis.c
+++ b/drivers/ata/pata_sis.c
@@ -552,51 +552,57 @@ static struct ata_port_operations sis_old_ops = {
552 552
553static const struct ata_port_info sis_info = { 553static const struct ata_port_info sis_info = {
554 .flags = ATA_FLAG_SLAVE_POSS, 554 .flags = ATA_FLAG_SLAVE_POSS,
555 .pio_mask = 0x1f, /* pio0-4 */ 555 .pio_mask = ATA_PIO4,
556 .mwdma_mask = 0x07, 556 .mwdma_mask = ATA_MWDMA2,
557 .udma_mask = 0, 557 /* No UDMA */
558 .port_ops = &sis_old_ops, 558 .port_ops = &sis_old_ops,
559}; 559};
560static const struct ata_port_info sis_info33 = { 560static const struct ata_port_info sis_info33 = {
561 .flags = ATA_FLAG_SLAVE_POSS, 561 .flags = ATA_FLAG_SLAVE_POSS,
562 .pio_mask = 0x1f, /* pio0-4 */ 562 .pio_mask = ATA_PIO4,
563 .mwdma_mask = 0x07, 563 .mwdma_mask = ATA_MWDMA2,
564 .udma_mask = ATA_UDMA2, /* UDMA 33 */ 564 .udma_mask = ATA_UDMA2,
565 .port_ops = &sis_old_ops, 565 .port_ops = &sis_old_ops,
566}; 566};
567static const struct ata_port_info sis_info66 = { 567static const struct ata_port_info sis_info66 = {
568 .flags = ATA_FLAG_SLAVE_POSS, 568 .flags = ATA_FLAG_SLAVE_POSS,
569 .pio_mask = 0x1f, /* pio0-4 */ 569 .pio_mask = ATA_PIO4,
570 .udma_mask = ATA_UDMA4, /* UDMA 66 */ 570 /* No MWDMA */
571 .udma_mask = ATA_UDMA4,
571 .port_ops = &sis_66_ops, 572 .port_ops = &sis_66_ops,
572}; 573};
573static const struct ata_port_info sis_info100 = { 574static const struct ata_port_info sis_info100 = {
574 .flags = ATA_FLAG_SLAVE_POSS, 575 .flags = ATA_FLAG_SLAVE_POSS,
575 .pio_mask = 0x1f, /* pio0-4 */ 576 .pio_mask = ATA_PIO4,
577 /* No MWDMA */
576 .udma_mask = ATA_UDMA5, 578 .udma_mask = ATA_UDMA5,
577 .port_ops = &sis_100_ops, 579 .port_ops = &sis_100_ops,
578}; 580};
579static const struct ata_port_info sis_info100_early = { 581static const struct ata_port_info sis_info100_early = {
580 .flags = ATA_FLAG_SLAVE_POSS, 582 .flags = ATA_FLAG_SLAVE_POSS,
583 .pio_mask = ATA_PIO4,
584 /* No MWDMA */
581 .udma_mask = ATA_UDMA5, 585 .udma_mask = ATA_UDMA5,
582 .pio_mask = 0x1f, /* pio0-4 */
583 .port_ops = &sis_66_ops, 586 .port_ops = &sis_66_ops,
584}; 587};
585static const struct ata_port_info sis_info133 = { 588static const struct ata_port_info sis_info133 = {
586 .flags = ATA_FLAG_SLAVE_POSS, 589 .flags = ATA_FLAG_SLAVE_POSS,
587 .pio_mask = 0x1f, /* pio0-4 */ 590 .pio_mask = ATA_PIO4,
591 /* No MWDMA */
588 .udma_mask = ATA_UDMA6, 592 .udma_mask = ATA_UDMA6,
589 .port_ops = &sis_133_ops, 593 .port_ops = &sis_133_ops,
590}; 594};
591const struct ata_port_info sis_info133_for_sata = { 595const struct ata_port_info sis_info133_for_sata = {
592 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST, 596 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_SRST,
593 .pio_mask = 0x1f, /* pio0-4 */ 597 .pio_mask = ATA_PIO4,
598 /* No MWDMA */
594 .udma_mask = ATA_UDMA6, 599 .udma_mask = ATA_UDMA6,
595 .port_ops = &sis_133_for_sata_ops, 600 .port_ops = &sis_133_for_sata_ops,
596}; 601};
597static const struct ata_port_info sis_info133_early = { 602static const struct ata_port_info sis_info133_early = {
598 .flags = ATA_FLAG_SLAVE_POSS, 603 .flags = ATA_FLAG_SLAVE_POSS,
599 .pio_mask = 0x1f, /* pio0-4 */ 604 .pio_mask = ATA_PIO4,
605 /* No MWDMA */
600 .udma_mask = ATA_UDMA6, 606 .udma_mask = ATA_UDMA6,
601 .port_ops = &sis_133_early_ops, 607 .port_ops = &sis_133_early_ops,
602}; 608};
diff --git a/drivers/ata/pata_sl82c105.c b/drivers/ata/pata_sl82c105.c
index 1b0e7b6d8ef5..29f733c32066 100644
--- a/drivers/ata/pata_sl82c105.c
+++ b/drivers/ata/pata_sl82c105.c
@@ -283,13 +283,13 @@ static int sl82c105_init_one(struct pci_dev *dev, const struct pci_device_id *id
283{ 283{
284 static const struct ata_port_info info_dma = { 284 static const struct ata_port_info info_dma = {
285 .flags = ATA_FLAG_SLAVE_POSS, 285 .flags = ATA_FLAG_SLAVE_POSS,
286 .pio_mask = 0x1f, 286 .pio_mask = ATA_PIO4,
287 .mwdma_mask = 0x07, 287 .mwdma_mask = ATA_MWDMA2,
288 .port_ops = &sl82c105_port_ops 288 .port_ops = &sl82c105_port_ops
289 }; 289 };
290 static const struct ata_port_info info_early = { 290 static const struct ata_port_info info_early = {
291 .flags = ATA_FLAG_SLAVE_POSS, 291 .flags = ATA_FLAG_SLAVE_POSS,
292 .pio_mask = 0x1f, 292 .pio_mask = ATA_PIO4,
293 .port_ops = &sl82c105_port_ops 293 .port_ops = &sl82c105_port_ops
294 }; 294 };
295 /* for now use only the first port */ 295 /* for now use only the first port */
diff --git a/drivers/ata/pata_triflex.c b/drivers/ata/pata_triflex.c
index ef9597517cdd..f1f13ff222fd 100644
--- a/drivers/ata/pata_triflex.c
+++ b/drivers/ata/pata_triflex.c
@@ -191,8 +191,8 @@ static int triflex_init_one(struct pci_dev *dev, const struct pci_device_id *id)
191{ 191{
192 static const struct ata_port_info info = { 192 static const struct ata_port_info info = {
193 .flags = ATA_FLAG_SLAVE_POSS, 193 .flags = ATA_FLAG_SLAVE_POSS,
194 .pio_mask = 0x1f, 194 .pio_mask = ATA_PIO4,
195 .mwdma_mask = 0x07, 195 .mwdma_mask = ATA_MWDMA2,
196 .port_ops = &triflex_port_ops 196 .port_ops = &triflex_port_ops
197 }; 197 };
198 const struct ata_port_info *ppi[] = { &info, NULL }; 198 const struct ata_port_info *ppi[] = { &info, NULL };
diff --git a/drivers/ata/pata_via.c b/drivers/ata/pata_via.c
index ba556d3e6963..b08e6e0f82b6 100644
--- a/drivers/ata/pata_via.c
+++ b/drivers/ata/pata_via.c
@@ -422,46 +422,46 @@ static int via_init_one(struct pci_dev *pdev, const struct pci_device_id *id)
422 /* Early VIA without UDMA support */ 422 /* Early VIA without UDMA support */
423 static const struct ata_port_info via_mwdma_info = { 423 static const struct ata_port_info via_mwdma_info = {
424 .flags = ATA_FLAG_SLAVE_POSS, 424 .flags = ATA_FLAG_SLAVE_POSS,
425 .pio_mask = 0x1f, 425 .pio_mask = ATA_PIO4,
426 .mwdma_mask = 0x07, 426 .mwdma_mask = ATA_MWDMA2,
427 .port_ops = &via_port_ops 427 .port_ops = &via_port_ops
428 }; 428 };
429 /* Ditto with IRQ masking required */ 429 /* Ditto with IRQ masking required */
430 static const struct ata_port_info via_mwdma_info_borked = { 430 static const struct ata_port_info via_mwdma_info_borked = {
431 .flags = ATA_FLAG_SLAVE_POSS, 431 .flags = ATA_FLAG_SLAVE_POSS,
432 .pio_mask = 0x1f, 432 .pio_mask = ATA_PIO4,
433 .mwdma_mask = 0x07, 433 .mwdma_mask = ATA_MWDMA2,
434 .port_ops = &via_port_ops_noirq, 434 .port_ops = &via_port_ops_noirq,
435 }; 435 };
436 /* VIA UDMA 33 devices (and borked 66) */ 436 /* VIA UDMA 33 devices (and borked 66) */
437 static const struct ata_port_info via_udma33_info = { 437 static const struct ata_port_info via_udma33_info = {
438 .flags = ATA_FLAG_SLAVE_POSS, 438 .flags = ATA_FLAG_SLAVE_POSS,
439 .pio_mask = 0x1f, 439 .pio_mask = ATA_PIO4,
440 .mwdma_mask = 0x07, 440 .mwdma_mask = ATA_MWDMA2,
441 .udma_mask = ATA_UDMA2, 441 .udma_mask = ATA_UDMA2,
442 .port_ops = &via_port_ops 442 .port_ops = &via_port_ops
443 }; 443 };
444 /* VIA UDMA 66 devices */ 444 /* VIA UDMA 66 devices */
445 static const struct ata_port_info via_udma66_info = { 445 static const struct ata_port_info via_udma66_info = {
446 .flags = ATA_FLAG_SLAVE_POSS, 446 .flags = ATA_FLAG_SLAVE_POSS,
447 .pio_mask = 0x1f, 447 .pio_mask = ATA_PIO4,
448 .mwdma_mask = 0x07, 448 .mwdma_mask = ATA_MWDMA2,
449 .udma_mask = ATA_UDMA4, 449 .udma_mask = ATA_UDMA4,
450 .port_ops = &via_port_ops 450 .port_ops = &via_port_ops
451 }; 451 };
452 /* VIA UDMA 100 devices */ 452 /* VIA UDMA 100 devices */
453 static const struct ata_port_info via_udma100_info = { 453 static const struct ata_port_info via_udma100_info = {
454 .flags = ATA_FLAG_SLAVE_POSS, 454 .flags = ATA_FLAG_SLAVE_POSS,
455 .pio_mask = 0x1f, 455 .pio_mask = ATA_PIO4,
456 .mwdma_mask = 0x07, 456 .mwdma_mask = ATA_MWDMA2,
457 .udma_mask = ATA_UDMA5, 457 .udma_mask = ATA_UDMA5,
458 .port_ops = &via_port_ops 458 .port_ops = &via_port_ops
459 }; 459 };
460 /* UDMA133 with bad AST (All current 133) */ 460 /* UDMA133 with bad AST (All current 133) */
461 static const struct ata_port_info via_udma133_info = { 461 static const struct ata_port_info via_udma133_info = {
462 .flags = ATA_FLAG_SLAVE_POSS, 462 .flags = ATA_FLAG_SLAVE_POSS,
463 .pio_mask = 0x1f, 463 .pio_mask = ATA_PIO4,
464 .mwdma_mask = 0x07, 464 .mwdma_mask = ATA_MWDMA2,
465 .udma_mask = ATA_UDMA6, /* FIXME: should check north bridge */ 465 .udma_mask = ATA_UDMA6, /* FIXME: should check north bridge */
466 .port_ops = &via_port_ops 466 .port_ops = &via_port_ops
467 }; 467 };
diff --git a/drivers/ata/pata_winbond.c b/drivers/ata/pata_winbond.c
index 319e164a3d74..6d8619b6f670 100644
--- a/drivers/ata/pata_winbond.c
+++ b/drivers/ata/pata_winbond.c
@@ -193,7 +193,7 @@ static __init int winbond_init_one(unsigned long port)
193 ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", cmd_port, ctl_port); 193 ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", cmd_port, ctl_port);
194 194
195 ap->ops = &winbond_port_ops; 195 ap->ops = &winbond_port_ops;
196 ap->pio_mask = 0x1F; 196 ap->pio_mask = ATA_PIO4;
197 ap->flags |= ATA_FLAG_SLAVE_POSS; 197 ap->flags |= ATA_FLAG_SLAVE_POSS;
198 ap->ioaddr.cmd_addr = cmd_addr; 198 ap->ioaddr.cmd_addr = cmd_addr;
199 ap->ioaddr.altstatus_addr = ctl_addr; 199 ap->ioaddr.altstatus_addr = ctl_addr;
diff --git a/drivers/ata/pdc_adma.c b/drivers/ata/pdc_adma.c
index be53545c9f64..39588178d028 100644
--- a/drivers/ata/pdc_adma.c
+++ b/drivers/ata/pdc_adma.c
@@ -148,6 +148,8 @@ static struct scsi_host_template adma_ata_sht = {
148static struct ata_port_operations adma_ata_ops = { 148static struct ata_port_operations adma_ata_ops = {
149 .inherits = &ata_sff_port_ops, 149 .inherits = &ata_sff_port_ops,
150 150
151 .lost_interrupt = ATA_OP_NULL,
152
151 .check_atapi_dma = adma_check_atapi_dma, 153 .check_atapi_dma = adma_check_atapi_dma,
152 .qc_prep = adma_qc_prep, 154 .qc_prep = adma_qc_prep,
153 .qc_issue = adma_qc_issue, 155 .qc_issue = adma_qc_issue,
@@ -166,7 +168,7 @@ static struct ata_port_info adma_port_info[] = {
166 .flags = ATA_FLAG_SLAVE_POSS | 168 .flags = ATA_FLAG_SLAVE_POSS |
167 ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO | 169 ATA_FLAG_NO_LEGACY | ATA_FLAG_MMIO |
168 ATA_FLAG_PIO_POLLING, 170 ATA_FLAG_PIO_POLLING,
169 .pio_mask = 0x10, /* pio4 */ 171 .pio_mask = ATA_PIO4_ONLY,
170 .udma_mask = ATA_UDMA4, 172 .udma_mask = ATA_UDMA4,
171 .port_ops = &adma_ata_ops, 173 .port_ops = &adma_ata_ops,
172 }, 174 },
diff --git a/drivers/ata/sata_fsl.c b/drivers/ata/sata_fsl.c
index 55bc88c1707b..c2e90e1fece0 100644
--- a/drivers/ata/sata_fsl.c
+++ b/drivers/ata/sata_fsl.c
@@ -1279,8 +1279,8 @@ static struct ata_port_operations sata_fsl_ops = {
1279static const struct ata_port_info sata_fsl_port_info[] = { 1279static const struct ata_port_info sata_fsl_port_info[] = {
1280 { 1280 {
1281 .flags = SATA_FSL_HOST_FLAGS, 1281 .flags = SATA_FSL_HOST_FLAGS,
1282 .pio_mask = 0x1f, /* pio 0-4 */ 1282 .pio_mask = ATA_PIO4,
1283 .udma_mask = 0x7f, /* udma 0-6 */ 1283 .udma_mask = ATA_UDMA6,
1284 .port_ops = &sata_fsl_ops, 1284 .port_ops = &sata_fsl_ops,
1285 }, 1285 },
1286}; 1286};
diff --git a/drivers/ata/sata_inic162x.c b/drivers/ata/sata_inic162x.c
index fbbd87c96f10..305a4f825f53 100644
--- a/drivers/ata/sata_inic162x.c
+++ b/drivers/ata/sata_inic162x.c
@@ -744,8 +744,8 @@ static struct ata_port_operations inic_port_ops = {
744 744
745static struct ata_port_info inic_port_info = { 745static struct ata_port_info inic_port_info = {
746 .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA, 746 .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA,
747 .pio_mask = 0x1f, /* pio0-4 */ 747 .pio_mask = ATA_PIO4,
748 .mwdma_mask = 0x07, /* mwdma0-2 */ 748 .mwdma_mask = ATA_MWDMA2,
749 .udma_mask = ATA_UDMA6, 749 .udma_mask = ATA_UDMA6,
750 .port_ops = &inic_port_ops 750 .port_ops = &inic_port_ops
751}; 751};
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index 74b1080d116d..a377226b81c8 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -1,10 +1,13 @@
1/* 1/*
2 * sata_mv.c - Marvell SATA support 2 * sata_mv.c - Marvell SATA support
3 * 3 *
4 * Copyright 2008: Marvell Corporation, all rights reserved. 4 * Copyright 2008-2009: Marvell Corporation, all rights reserved.
5 * Copyright 2005: EMC Corporation, all rights reserved. 5 * Copyright 2005: EMC Corporation, all rights reserved.
6 * Copyright 2005 Red Hat, Inc. All rights reserved. 6 * Copyright 2005 Red Hat, Inc. All rights reserved.
7 * 7 *
8 * Originally written by Brett Russ.
9 * Extensive overhaul and enhancement by Mark Lord <mlord@pobox.com>.
10 *
8 * Please ALWAYS copy linux-ide@vger.kernel.org on emails. 11 * Please ALWAYS copy linux-ide@vger.kernel.org on emails.
9 * 12 *
10 * This program is free software; you can redistribute it and/or modify 13 * This program is free software; you can redistribute it and/or modify
@@ -25,20 +28,13 @@
25/* 28/*
26 * sata_mv TODO list: 29 * sata_mv TODO list:
27 * 30 *
28 * --> Errata workaround for NCQ device errors.
29 *
30 * --> More errata workarounds for PCI-X. 31 * --> More errata workarounds for PCI-X.
31 * 32 *
32 * --> Complete a full errata audit for all chipsets to identify others. 33 * --> Complete a full errata audit for all chipsets to identify others.
33 * 34 *
34 * --> ATAPI support (Marvell claims the 60xx/70xx chips can do it).
35 *
36 * --> Develop a low-power-consumption strategy, and implement it. 35 * --> Develop a low-power-consumption strategy, and implement it.
37 * 36 *
38 * --> [Experiment, low priority] Investigate interrupt coalescing. 37 * --> Add sysfs attributes for per-chip / per-HC IRQ coalescing thresholds.
39 * Quite often, especially with PCI Message Signalled Interrupts (MSI),
40 * the overhead reduced by interrupt mitigation is quite often not
41 * worth the latency cost.
42 * 38 *
43 * --> [Experiment, Marvell value added] Is it possible to use target 39 * --> [Experiment, Marvell value added] Is it possible to use target
44 * mode to cross-connect two Linux boxes with Marvell cards? If so, 40 * mode to cross-connect two Linux boxes with Marvell cards? If so,
@@ -68,7 +64,27 @@
68#include <linux/libata.h> 64#include <linux/libata.h>
69 65
70#define DRV_NAME "sata_mv" 66#define DRV_NAME "sata_mv"
71#define DRV_VERSION "1.25" 67#define DRV_VERSION "1.27"
68
69/*
70 * module options
71 */
72
73static int msi;
74#ifdef CONFIG_PCI
75module_param(msi, int, S_IRUGO);
76MODULE_PARM_DESC(msi, "Enable use of PCI MSI (0=off, 1=on)");
77#endif
78
79static int irq_coalescing_io_count;
80module_param(irq_coalescing_io_count, int, S_IRUGO);
81MODULE_PARM_DESC(irq_coalescing_io_count,
82 "IRQ coalescing I/O count threshold (0..255)");
83
84static int irq_coalescing_usecs;
85module_param(irq_coalescing_usecs, int, S_IRUGO);
86MODULE_PARM_DESC(irq_coalescing_usecs,
87 "IRQ coalescing time threshold in usecs");
72 88
73enum { 89enum {
74 /* BAR's are enumerated in terms of pci_resource_start() terms */ 90 /* BAR's are enumerated in terms of pci_resource_start() terms */
@@ -79,13 +95,32 @@ enum {
79 MV_MAJOR_REG_AREA_SZ = 0x10000, /* 64KB */ 95 MV_MAJOR_REG_AREA_SZ = 0x10000, /* 64KB */
80 MV_MINOR_REG_AREA_SZ = 0x2000, /* 8KB */ 96 MV_MINOR_REG_AREA_SZ = 0x2000, /* 8KB */
81 97
98 /* For use with both IRQ coalescing methods ("all ports" or "per-HC" */
99 COAL_CLOCKS_PER_USEC = 150, /* for calculating COAL_TIMEs */
100 MAX_COAL_TIME_THRESHOLD = ((1 << 24) - 1), /* internal clocks count */
101 MAX_COAL_IO_COUNT = 255, /* completed I/O count */
102
82 MV_PCI_REG_BASE = 0, 103 MV_PCI_REG_BASE = 0,
83 MV_IRQ_COAL_REG_BASE = 0x18000, /* 6xxx part only */ 104
84 MV_IRQ_COAL_CAUSE = (MV_IRQ_COAL_REG_BASE + 0x08), 105 /*
85 MV_IRQ_COAL_CAUSE_LO = (MV_IRQ_COAL_REG_BASE + 0x88), 106 * Per-chip ("all ports") interrupt coalescing feature.
86 MV_IRQ_COAL_CAUSE_HI = (MV_IRQ_COAL_REG_BASE + 0x8c), 107 * This is only for GEN_II / GEN_IIE hardware.
87 MV_IRQ_COAL_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xcc), 108 *
88 MV_IRQ_COAL_TIME_THRESHOLD = (MV_IRQ_COAL_REG_BASE + 0xd0), 109 * Coalescing defers the interrupt until either the IO_THRESHOLD
110 * (count of completed I/Os) is met, or the TIME_THRESHOLD is met.
111 */
112 MV_COAL_REG_BASE = 0x18000,
113 MV_IRQ_COAL_CAUSE = (MV_COAL_REG_BASE + 0x08),
114 ALL_PORTS_COAL_IRQ = (1 << 4), /* all ports irq event */
115
116 MV_IRQ_COAL_IO_THRESHOLD = (MV_COAL_REG_BASE + 0xcc),
117 MV_IRQ_COAL_TIME_THRESHOLD = (MV_COAL_REG_BASE + 0xd0),
118
119 /*
120 * Registers for the (unused here) transaction coalescing feature:
121 */
122 MV_TRAN_COAL_CAUSE_LO = (MV_COAL_REG_BASE + 0x88),
123 MV_TRAN_COAL_CAUSE_HI = (MV_COAL_REG_BASE + 0x8c),
89 124
90 MV_SATAHC0_REG_BASE = 0x20000, 125 MV_SATAHC0_REG_BASE = 0x20000,
91 MV_FLASH_CTL_OFS = 0x1046c, 126 MV_FLASH_CTL_OFS = 0x1046c,
@@ -117,17 +152,16 @@ enum {
117 152
118 /* Host Flags */ 153 /* Host Flags */
119 MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */ 154 MV_FLAG_DUAL_HC = (1 << 30), /* two SATA Host Controllers */
120 MV_FLAG_IRQ_COALESCE = (1 << 29), /* IRQ coalescing capability */
121 155
122 MV_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 156 MV_COMMON_FLAGS = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
123 ATA_FLAG_MMIO | ATA_FLAG_NO_ATAPI | 157 ATA_FLAG_MMIO | ATA_FLAG_PIO_POLLING,
124 ATA_FLAG_PIO_POLLING, 158
159 MV_GEN_I_FLAGS = MV_COMMON_FLAGS | ATA_FLAG_NO_ATAPI,
125 160
126 MV_6XXX_FLAGS = MV_FLAG_IRQ_COALESCE, 161 MV_GEN_II_FLAGS = MV_COMMON_FLAGS | ATA_FLAG_NCQ |
162 ATA_FLAG_PMP | ATA_FLAG_ACPI_SATA,
127 163
128 MV_GENIIE_FLAGS = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 164 MV_GEN_IIE_FLAGS = MV_GEN_II_FLAGS | ATA_FLAG_AN,
129 ATA_FLAG_PMP | ATA_FLAG_ACPI_SATA |
130 ATA_FLAG_NCQ | ATA_FLAG_AN,
131 165
132 CRQB_FLAG_READ = (1 << 0), 166 CRQB_FLAG_READ = (1 << 0),
133 CRQB_TAG_SHIFT = 1, 167 CRQB_TAG_SHIFT = 1,
@@ -180,16 +214,18 @@ enum {
180 PCI_HC_MAIN_IRQ_MASK_OFS = 0x1d64, 214 PCI_HC_MAIN_IRQ_MASK_OFS = 0x1d64,
181 SOC_HC_MAIN_IRQ_CAUSE_OFS = 0x20020, 215 SOC_HC_MAIN_IRQ_CAUSE_OFS = 0x20020,
182 SOC_HC_MAIN_IRQ_MASK_OFS = 0x20024, 216 SOC_HC_MAIN_IRQ_MASK_OFS = 0x20024,
183 ERR_IRQ = (1 << 0), /* shift by port # */ 217 ERR_IRQ = (1 << 0), /* shift by (2 * port #) */
184 DONE_IRQ = (1 << 1), /* shift by port # */ 218 DONE_IRQ = (1 << 1), /* shift by (2 * port #) */
185 HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */ 219 HC0_IRQ_PEND = 0x1ff, /* bits 0-8 = HC0's ports */
186 HC_SHIFT = 9, /* bits 9-17 = HC1's ports */ 220 HC_SHIFT = 9, /* bits 9-17 = HC1's ports */
221 DONE_IRQ_0_3 = 0x000000aa, /* DONE_IRQ ports 0,1,2,3 */
222 DONE_IRQ_4_7 = (DONE_IRQ_0_3 << HC_SHIFT), /* 4,5,6,7 */
187 PCI_ERR = (1 << 18), 223 PCI_ERR = (1 << 18),
188 TRAN_LO_DONE = (1 << 19), /* 6xxx: IRQ coalescing */ 224 TRAN_COAL_LO_DONE = (1 << 19), /* transaction coalescing */
189 TRAN_HI_DONE = (1 << 20), /* 6xxx: IRQ coalescing */ 225 TRAN_COAL_HI_DONE = (1 << 20), /* transaction coalescing */
190 PORTS_0_3_COAL_DONE = (1 << 8), 226 PORTS_0_3_COAL_DONE = (1 << 8), /* HC0 IRQ coalescing */
191 PORTS_4_7_COAL_DONE = (1 << 17), 227 PORTS_4_7_COAL_DONE = (1 << 17), /* HC1 IRQ coalescing */
192 PORTS_0_7_COAL_DONE = (1 << 21), /* 6xxx: IRQ coalescing */ 228 ALL_PORTS_COAL_DONE = (1 << 21), /* GEN_II(E) IRQ coalescing */
193 GPIO_INT = (1 << 22), 229 GPIO_INT = (1 << 22),
194 SELF_INT = (1 << 23), 230 SELF_INT = (1 << 23),
195 TWSI_INT = (1 << 24), 231 TWSI_INT = (1 << 24),
@@ -205,6 +241,21 @@ enum {
205 HC_COAL_IRQ = (1 << 4), /* IRQ coalescing */ 241 HC_COAL_IRQ = (1 << 4), /* IRQ coalescing */
206 DEV_IRQ = (1 << 8), /* shift by port # */ 242 DEV_IRQ = (1 << 8), /* shift by port # */
207 243
244 /*
245 * Per-HC (Host-Controller) interrupt coalescing feature.
246 * This is present on all chip generations.
247 *
248 * Coalescing defers the interrupt until either the IO_THRESHOLD
249 * (count of completed I/Os) is met, or the TIME_THRESHOLD is met.
250 */
251 HC_IRQ_COAL_IO_THRESHOLD_OFS = 0x000c,
252 HC_IRQ_COAL_TIME_THRESHOLD_OFS = 0x0010,
253
254 SOC_LED_CTRL_OFS = 0x2c,
255 SOC_LED_CTRL_BLINK = (1 << 0), /* Active LED blink */
256 SOC_LED_CTRL_ACT_PRESENCE = (1 << 2), /* Multiplex dev presence */
257 /* with dev activity LED */
258
208 /* Shadow block registers */ 259 /* Shadow block registers */
209 SHD_BLK_OFS = 0x100, 260 SHD_BLK_OFS = 0x100,
210 SHD_CTL_AST_OFS = 0x20, /* ofs from SHD_BLK_OFS */ 261 SHD_CTL_AST_OFS = 0x20, /* ofs from SHD_BLK_OFS */
@@ -346,6 +397,12 @@ enum {
346 EDMA_ARB_CFG_OFS = 0x38, 397 EDMA_ARB_CFG_OFS = 0x38,
347 398
348 EDMA_HALTCOND_OFS = 0x60, /* GenIIe halt conditions */ 399 EDMA_HALTCOND_OFS = 0x60, /* GenIIe halt conditions */
400 EDMA_UNKNOWN_RSVD_OFS = 0x6C, /* GenIIe unknown/reserved */
401
402 BMDMA_CMD_OFS = 0x224, /* bmdma command register */
403 BMDMA_STATUS_OFS = 0x228, /* bmdma status register */
404 BMDMA_PRD_LOW_OFS = 0x22c, /* bmdma PRD addr 31:0 */
405 BMDMA_PRD_HIGH_OFS = 0x230, /* bmdma PRD addr 63:32 */
349 406
350 /* Host private flags (hp_flags) */ 407 /* Host private flags (hp_flags) */
351 MV_HP_FLAG_MSI = (1 << 0), 408 MV_HP_FLAG_MSI = (1 << 0),
@@ -359,12 +416,14 @@ enum {
359 MV_HP_PCIE = (1 << 9), /* PCIe bus/regs: 7042 */ 416 MV_HP_PCIE = (1 << 9), /* PCIe bus/regs: 7042 */
360 MV_HP_CUT_THROUGH = (1 << 10), /* can use EDMA cut-through */ 417 MV_HP_CUT_THROUGH = (1 << 10), /* can use EDMA cut-through */
361 MV_HP_FLAG_SOC = (1 << 11), /* SystemOnChip, no PCI */ 418 MV_HP_FLAG_SOC = (1 << 11), /* SystemOnChip, no PCI */
419 MV_HP_QUIRK_LED_BLINK_EN = (1 << 12), /* is led blinking enabled? */
362 420
363 /* Port private flags (pp_flags) */ 421 /* Port private flags (pp_flags) */
364 MV_PP_FLAG_EDMA_EN = (1 << 0), /* is EDMA engine enabled? */ 422 MV_PP_FLAG_EDMA_EN = (1 << 0), /* is EDMA engine enabled? */
365 MV_PP_FLAG_NCQ_EN = (1 << 1), /* is EDMA set up for NCQ? */ 423 MV_PP_FLAG_NCQ_EN = (1 << 1), /* is EDMA set up for NCQ? */
366 MV_PP_FLAG_FBS_EN = (1 << 2), /* is EDMA set up for FBS? */ 424 MV_PP_FLAG_FBS_EN = (1 << 2), /* is EDMA set up for FBS? */
367 MV_PP_FLAG_DELAYED_EH = (1 << 3), /* delayed dev err handling */ 425 MV_PP_FLAG_DELAYED_EH = (1 << 3), /* delayed dev err handling */
426 MV_PP_FLAG_FAKE_ATA_BUSY = (1 << 4), /* ignore initial ATA_DRDY */
368}; 427};
369 428
370#define IS_GEN_I(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_I) 429#define IS_GEN_I(hpriv) ((hpriv)->hp_flags & MV_HP_GEN_I)
@@ -433,6 +492,18 @@ struct mv_sg {
433 __le32 reserved; 492 __le32 reserved;
434}; 493};
435 494
495/*
496 * We keep a local cache of a few frequently accessed port
497 * registers here, to avoid having to read them (very slow)
498 * when switching between EDMA and non-EDMA modes.
499 */
500struct mv_cached_regs {
501 u32 fiscfg;
502 u32 ltmode;
503 u32 haltcond;
504 u32 unknown_rsvd;
505};
506
436struct mv_port_priv { 507struct mv_port_priv {
437 struct mv_crqb *crqb; 508 struct mv_crqb *crqb;
438 dma_addr_t crqb_dma; 509 dma_addr_t crqb_dma;
@@ -445,6 +516,7 @@ struct mv_port_priv {
445 unsigned int resp_idx; 516 unsigned int resp_idx;
446 517
447 u32 pp_flags; 518 u32 pp_flags;
519 struct mv_cached_regs cached;
448 unsigned int delayed_eh_pmp_map; 520 unsigned int delayed_eh_pmp_map;
449}; 521};
450 522
@@ -535,7 +607,7 @@ static void mv_reset_channel(struct mv_host_priv *hpriv, void __iomem *mmio,
535 unsigned int port_no); 607 unsigned int port_no);
536static int mv_stop_edma(struct ata_port *ap); 608static int mv_stop_edma(struct ata_port *ap);
537static int mv_stop_edma_engine(void __iomem *port_mmio); 609static int mv_stop_edma_engine(void __iomem *port_mmio);
538static void mv_edma_cfg(struct ata_port *ap, int want_ncq); 610static void mv_edma_cfg(struct ata_port *ap, int want_ncq, int want_edma);
539 611
540static void mv_pmp_select(struct ata_port *ap, int pmp); 612static void mv_pmp_select(struct ata_port *ap, int pmp);
541static int mv_pmp_hardreset(struct ata_link *link, unsigned int *class, 613static int mv_pmp_hardreset(struct ata_link *link, unsigned int *class,
@@ -546,6 +618,14 @@ static void mv_pmp_error_handler(struct ata_port *ap);
546static void mv_process_crpb_entries(struct ata_port *ap, 618static void mv_process_crpb_entries(struct ata_port *ap,
547 struct mv_port_priv *pp); 619 struct mv_port_priv *pp);
548 620
621static void mv_sff_irq_clear(struct ata_port *ap);
622static int mv_check_atapi_dma(struct ata_queued_cmd *qc);
623static void mv_bmdma_setup(struct ata_queued_cmd *qc);
624static void mv_bmdma_start(struct ata_queued_cmd *qc);
625static void mv_bmdma_stop(struct ata_queued_cmd *qc);
626static u8 mv_bmdma_status(struct ata_port *ap);
627static u8 mv_sff_check_status(struct ata_port *ap);
628
549/* .sg_tablesize is (MV_MAX_SG_CT / 2) in the structures below 629/* .sg_tablesize is (MV_MAX_SG_CT / 2) in the structures below
550 * because we have to allow room for worst case splitting of 630 * because we have to allow room for worst case splitting of
551 * PRDs for 64K boundaries in mv_fill_sg(). 631 * PRDs for 64K boundaries in mv_fill_sg().
@@ -566,6 +646,8 @@ static struct scsi_host_template mv6_sht = {
566static struct ata_port_operations mv5_ops = { 646static struct ata_port_operations mv5_ops = {
567 .inherits = &ata_sff_port_ops, 647 .inherits = &ata_sff_port_ops,
568 648
649 .lost_interrupt = ATA_OP_NULL,
650
569 .qc_defer = mv_qc_defer, 651 .qc_defer = mv_qc_defer,
570 .qc_prep = mv_qc_prep, 652 .qc_prep = mv_qc_prep,
571 .qc_issue = mv_qc_issue, 653 .qc_issue = mv_qc_issue,
@@ -593,6 +675,14 @@ static struct ata_port_operations mv6_ops = {
593 .pmp_softreset = mv_softreset, 675 .pmp_softreset = mv_softreset,
594 .softreset = mv_softreset, 676 .softreset = mv_softreset,
595 .error_handler = mv_pmp_error_handler, 677 .error_handler = mv_pmp_error_handler,
678
679 .sff_check_status = mv_sff_check_status,
680 .sff_irq_clear = mv_sff_irq_clear,
681 .check_atapi_dma = mv_check_atapi_dma,
682 .bmdma_setup = mv_bmdma_setup,
683 .bmdma_start = mv_bmdma_start,
684 .bmdma_stop = mv_bmdma_stop,
685 .bmdma_status = mv_bmdma_status,
596}; 686};
597 687
598static struct ata_port_operations mv_iie_ops = { 688static struct ata_port_operations mv_iie_ops = {
@@ -603,53 +693,49 @@ static struct ata_port_operations mv_iie_ops = {
603 693
604static const struct ata_port_info mv_port_info[] = { 694static const struct ata_port_info mv_port_info[] = {
605 { /* chip_504x */ 695 { /* chip_504x */
606 .flags = MV_COMMON_FLAGS, 696 .flags = MV_GEN_I_FLAGS,
607 .pio_mask = 0x1f, /* pio0-4 */ 697 .pio_mask = 0x1f, /* pio0-4 */
608 .udma_mask = ATA_UDMA6, 698 .udma_mask = ATA_UDMA6,
609 .port_ops = &mv5_ops, 699 .port_ops = &mv5_ops,
610 }, 700 },
611 { /* chip_508x */ 701 { /* chip_508x */
612 .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC, 702 .flags = MV_GEN_I_FLAGS | MV_FLAG_DUAL_HC,
613 .pio_mask = 0x1f, /* pio0-4 */ 703 .pio_mask = 0x1f, /* pio0-4 */
614 .udma_mask = ATA_UDMA6, 704 .udma_mask = ATA_UDMA6,
615 .port_ops = &mv5_ops, 705 .port_ops = &mv5_ops,
616 }, 706 },
617 { /* chip_5080 */ 707 { /* chip_5080 */
618 .flags = MV_COMMON_FLAGS | MV_FLAG_DUAL_HC, 708 .flags = MV_GEN_I_FLAGS | MV_FLAG_DUAL_HC,
619 .pio_mask = 0x1f, /* pio0-4 */ 709 .pio_mask = 0x1f, /* pio0-4 */
620 .udma_mask = ATA_UDMA6, 710 .udma_mask = ATA_UDMA6,
621 .port_ops = &mv5_ops, 711 .port_ops = &mv5_ops,
622 }, 712 },
623 { /* chip_604x */ 713 { /* chip_604x */
624 .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 714 .flags = MV_GEN_II_FLAGS,
625 ATA_FLAG_PMP | ATA_FLAG_ACPI_SATA |
626 ATA_FLAG_NCQ,
627 .pio_mask = 0x1f, /* pio0-4 */ 715 .pio_mask = 0x1f, /* pio0-4 */
628 .udma_mask = ATA_UDMA6, 716 .udma_mask = ATA_UDMA6,
629 .port_ops = &mv6_ops, 717 .port_ops = &mv6_ops,
630 }, 718 },
631 { /* chip_608x */ 719 { /* chip_608x */
632 .flags = MV_COMMON_FLAGS | MV_6XXX_FLAGS | 720 .flags = MV_GEN_II_FLAGS | MV_FLAG_DUAL_HC,
633 ATA_FLAG_PMP | ATA_FLAG_ACPI_SATA |
634 ATA_FLAG_NCQ | MV_FLAG_DUAL_HC,
635 .pio_mask = 0x1f, /* pio0-4 */ 721 .pio_mask = 0x1f, /* pio0-4 */
636 .udma_mask = ATA_UDMA6, 722 .udma_mask = ATA_UDMA6,
637 .port_ops = &mv6_ops, 723 .port_ops = &mv6_ops,
638 }, 724 },
639 { /* chip_6042 */ 725 { /* chip_6042 */
640 .flags = MV_GENIIE_FLAGS, 726 .flags = MV_GEN_IIE_FLAGS,
641 .pio_mask = 0x1f, /* pio0-4 */ 727 .pio_mask = 0x1f, /* pio0-4 */
642 .udma_mask = ATA_UDMA6, 728 .udma_mask = ATA_UDMA6,
643 .port_ops = &mv_iie_ops, 729 .port_ops = &mv_iie_ops,
644 }, 730 },
645 { /* chip_7042 */ 731 { /* chip_7042 */
646 .flags = MV_GENIIE_FLAGS, 732 .flags = MV_GEN_IIE_FLAGS,
647 .pio_mask = 0x1f, /* pio0-4 */ 733 .pio_mask = 0x1f, /* pio0-4 */
648 .udma_mask = ATA_UDMA6, 734 .udma_mask = ATA_UDMA6,
649 .port_ops = &mv_iie_ops, 735 .port_ops = &mv_iie_ops,
650 }, 736 },
651 { /* chip_soc */ 737 { /* chip_soc */
652 .flags = MV_GENIIE_FLAGS, 738 .flags = MV_GEN_IIE_FLAGS,
653 .pio_mask = 0x1f, /* pio0-4 */ 739 .pio_mask = 0x1f, /* pio0-4 */
654 .udma_mask = ATA_UDMA6, 740 .udma_mask = ATA_UDMA6,
655 .port_ops = &mv_iie_ops, 741 .port_ops = &mv_iie_ops,
@@ -794,6 +880,44 @@ static inline int mv_get_hc_count(unsigned long port_flags)
794 return ((port_flags & MV_FLAG_DUAL_HC) ? 2 : 1); 880 return ((port_flags & MV_FLAG_DUAL_HC) ? 2 : 1);
795} 881}
796 882
883/**
884 * mv_save_cached_regs - (re-)initialize cached port registers
885 * @ap: the port whose registers we are caching
886 *
887 * Initialize the local cache of port registers,
888 * so that reading them over and over again can
889 * be avoided on the hotter paths of this driver.
890 * This saves a few microseconds each time we switch
891 * to/from EDMA mode to perform (eg.) a drive cache flush.
892 */
893static void mv_save_cached_regs(struct ata_port *ap)
894{
895 void __iomem *port_mmio = mv_ap_base(ap);
896 struct mv_port_priv *pp = ap->private_data;
897
898 pp->cached.fiscfg = readl(port_mmio + FISCFG_OFS);
899 pp->cached.ltmode = readl(port_mmio + LTMODE_OFS);
900 pp->cached.haltcond = readl(port_mmio + EDMA_HALTCOND_OFS);
901 pp->cached.unknown_rsvd = readl(port_mmio + EDMA_UNKNOWN_RSVD_OFS);
902}
903
904/**
905 * mv_write_cached_reg - write to a cached port register
906 * @addr: hardware address of the register
907 * @old: pointer to cached value of the register
908 * @new: new value for the register
909 *
910 * Write a new value to a cached register,
911 * but only if the value is different from before.
912 */
913static inline void mv_write_cached_reg(void __iomem *addr, u32 *old, u32 new)
914{
915 if (new != *old) {
916 *old = new;
917 writel(new, addr);
918 }
919}
920
797static void mv_set_edma_ptrs(void __iomem *port_mmio, 921static void mv_set_edma_ptrs(void __iomem *port_mmio,
798 struct mv_host_priv *hpriv, 922 struct mv_host_priv *hpriv,
799 struct mv_port_priv *pp) 923 struct mv_port_priv *pp)
@@ -825,6 +949,23 @@ static void mv_set_edma_ptrs(void __iomem *port_mmio,
825 port_mmio + EDMA_RSP_Q_OUT_PTR_OFS); 949 port_mmio + EDMA_RSP_Q_OUT_PTR_OFS);
826} 950}
827 951
952static void mv_write_main_irq_mask(u32 mask, struct mv_host_priv *hpriv)
953{
954 /*
955 * When writing to the main_irq_mask in hardware,
956 * we must ensure exclusivity between the interrupt coalescing bits
957 * and the corresponding individual port DONE_IRQ bits.
958 *
959 * Note that this register is really an "IRQ enable" register,
960 * not an "IRQ mask" register as Marvell's naming might suggest.
961 */
962 if (mask & (ALL_PORTS_COAL_DONE | PORTS_0_3_COAL_DONE))
963 mask &= ~DONE_IRQ_0_3;
964 if (mask & (ALL_PORTS_COAL_DONE | PORTS_4_7_COAL_DONE))
965 mask &= ~DONE_IRQ_4_7;
966 writelfl(mask, hpriv->main_irq_mask_addr);
967}
968
828static void mv_set_main_irq_mask(struct ata_host *host, 969static void mv_set_main_irq_mask(struct ata_host *host,
829 u32 disable_bits, u32 enable_bits) 970 u32 disable_bits, u32 enable_bits)
830{ 971{
@@ -835,7 +976,7 @@ static void mv_set_main_irq_mask(struct ata_host *host,
835 new_mask = (old_mask & ~disable_bits) | enable_bits; 976 new_mask = (old_mask & ~disable_bits) | enable_bits;
836 if (new_mask != old_mask) { 977 if (new_mask != old_mask) {
837 hpriv->main_irq_mask = new_mask; 978 hpriv->main_irq_mask = new_mask;
838 writelfl(new_mask, hpriv->main_irq_mask_addr); 979 mv_write_main_irq_mask(new_mask, hpriv);
839 } 980 }
840} 981}
841 982
@@ -852,8 +993,94 @@ static void mv_enable_port_irqs(struct ata_port *ap,
852 mv_set_main_irq_mask(ap->host, disable_bits, enable_bits); 993 mv_set_main_irq_mask(ap->host, disable_bits, enable_bits);
853} 994}
854 995
996static void mv_clear_and_enable_port_irqs(struct ata_port *ap,
997 void __iomem *port_mmio,
998 unsigned int port_irqs)
999{
1000 struct mv_host_priv *hpriv = ap->host->private_data;
1001 int hardport = mv_hardport_from_port(ap->port_no);
1002 void __iomem *hc_mmio = mv_hc_base_from_port(
1003 mv_host_base(ap->host), ap->port_no);
1004 u32 hc_irq_cause;
1005
1006 /* clear EDMA event indicators, if any */
1007 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
1008
1009 /* clear pending irq events */
1010 hc_irq_cause = ~((DEV_IRQ | DMA_IRQ) << hardport);
1011 writelfl(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
1012
1013 /* clear FIS IRQ Cause */
1014 if (IS_GEN_IIE(hpriv))
1015 writelfl(0, port_mmio + SATA_FIS_IRQ_CAUSE_OFS);
1016
1017 mv_enable_port_irqs(ap, port_irqs);
1018}
1019
1020static void mv_set_irq_coalescing(struct ata_host *host,
1021 unsigned int count, unsigned int usecs)
1022{
1023 struct mv_host_priv *hpriv = host->private_data;
1024 void __iomem *mmio = hpriv->base, *hc_mmio;
1025 u32 coal_enable = 0;
1026 unsigned long flags;
1027 unsigned int clks, is_dual_hc = hpriv->n_ports > MV_PORTS_PER_HC;
1028 const u32 coal_disable = PORTS_0_3_COAL_DONE | PORTS_4_7_COAL_DONE |
1029 ALL_PORTS_COAL_DONE;
1030
1031 /* Disable IRQ coalescing if either threshold is zero */
1032 if (!usecs || !count) {
1033 clks = count = 0;
1034 } else {
1035 /* Respect maximum limits of the hardware */
1036 clks = usecs * COAL_CLOCKS_PER_USEC;
1037 if (clks > MAX_COAL_TIME_THRESHOLD)
1038 clks = MAX_COAL_TIME_THRESHOLD;
1039 if (count > MAX_COAL_IO_COUNT)
1040 count = MAX_COAL_IO_COUNT;
1041 }
1042
1043 spin_lock_irqsave(&host->lock, flags);
1044 mv_set_main_irq_mask(host, coal_disable, 0);
1045
1046 if (is_dual_hc && !IS_GEN_I(hpriv)) {
1047 /*
1048 * GEN_II/GEN_IIE with dual host controllers:
1049 * one set of global thresholds for the entire chip.
1050 */
1051 writel(clks, mmio + MV_IRQ_COAL_TIME_THRESHOLD);
1052 writel(count, mmio + MV_IRQ_COAL_IO_THRESHOLD);
1053 /* clear leftover coal IRQ bit */
1054 writel(~ALL_PORTS_COAL_IRQ, mmio + MV_IRQ_COAL_CAUSE);
1055 if (count)
1056 coal_enable = ALL_PORTS_COAL_DONE;
1057 clks = count = 0; /* force clearing of regular regs below */
1058 }
1059
1060 /*
1061 * All chips: independent thresholds for each HC on the chip.
1062 */
1063 hc_mmio = mv_hc_base_from_port(mmio, 0);
1064 writel(clks, hc_mmio + HC_IRQ_COAL_TIME_THRESHOLD_OFS);
1065 writel(count, hc_mmio + HC_IRQ_COAL_IO_THRESHOLD_OFS);
1066 writel(~HC_COAL_IRQ, hc_mmio + HC_IRQ_CAUSE_OFS);
1067 if (count)
1068 coal_enable |= PORTS_0_3_COAL_DONE;
1069 if (is_dual_hc) {
1070 hc_mmio = mv_hc_base_from_port(mmio, MV_PORTS_PER_HC);
1071 writel(clks, hc_mmio + HC_IRQ_COAL_TIME_THRESHOLD_OFS);
1072 writel(count, hc_mmio + HC_IRQ_COAL_IO_THRESHOLD_OFS);
1073 writel(~HC_COAL_IRQ, hc_mmio + HC_IRQ_CAUSE_OFS);
1074 if (count)
1075 coal_enable |= PORTS_4_7_COAL_DONE;
1076 }
1077
1078 mv_set_main_irq_mask(host, 0, coal_enable);
1079 spin_unlock_irqrestore(&host->lock, flags);
1080}
1081
855/** 1082/**
856 * mv_start_dma - Enable eDMA engine 1083 * mv_start_edma - Enable eDMA engine
857 * @base: port base address 1084 * @base: port base address
858 * @pp: port private data 1085 * @pp: port private data
859 * 1086 *
@@ -863,7 +1090,7 @@ static void mv_enable_port_irqs(struct ata_port *ap,
863 * LOCKING: 1090 * LOCKING:
864 * Inherited from caller. 1091 * Inherited from caller.
865 */ 1092 */
866static void mv_start_dma(struct ata_port *ap, void __iomem *port_mmio, 1093static void mv_start_edma(struct ata_port *ap, void __iomem *port_mmio,
867 struct mv_port_priv *pp, u8 protocol) 1094 struct mv_port_priv *pp, u8 protocol)
868{ 1095{
869 int want_ncq = (protocol == ATA_PROT_NCQ); 1096 int want_ncq = (protocol == ATA_PROT_NCQ);
@@ -875,26 +1102,11 @@ static void mv_start_dma(struct ata_port *ap, void __iomem *port_mmio,
875 } 1102 }
876 if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) { 1103 if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) {
877 struct mv_host_priv *hpriv = ap->host->private_data; 1104 struct mv_host_priv *hpriv = ap->host->private_data;
878 int hardport = mv_hardport_from_port(ap->port_no);
879 void __iomem *hc_mmio = mv_hc_base_from_port(
880 mv_host_base(ap->host), ap->port_no);
881 u32 hc_irq_cause;
882
883 /* clear EDMA event indicators, if any */
884 writelfl(0, port_mmio + EDMA_ERR_IRQ_CAUSE_OFS);
885 1105
886 /* clear pending irq events */ 1106 mv_edma_cfg(ap, want_ncq, 1);
887 hc_irq_cause = ~((DEV_IRQ | DMA_IRQ) << hardport);
888 writelfl(hc_irq_cause, hc_mmio + HC_IRQ_CAUSE_OFS);
889
890 mv_edma_cfg(ap, want_ncq);
891
892 /* clear FIS IRQ Cause */
893 if (IS_GEN_IIE(hpriv))
894 writelfl(0, port_mmio + SATA_FIS_IRQ_CAUSE_OFS);
895 1107
896 mv_set_edma_ptrs(port_mmio, hpriv, pp); 1108 mv_set_edma_ptrs(port_mmio, hpriv, pp);
897 mv_enable_port_irqs(ap, DONE_IRQ|ERR_IRQ); 1109 mv_clear_and_enable_port_irqs(ap, port_mmio, DONE_IRQ|ERR_IRQ);
898 1110
899 writelfl(EDMA_EN, port_mmio + EDMA_CMD_OFS); 1111 writelfl(EDMA_EN, port_mmio + EDMA_CMD_OFS);
900 pp->pp_flags |= MV_PP_FLAG_EDMA_EN; 1112 pp->pp_flags |= MV_PP_FLAG_EDMA_EN;
@@ -952,6 +1164,7 @@ static int mv_stop_edma(struct ata_port *ap)
952{ 1164{
953 void __iomem *port_mmio = mv_ap_base(ap); 1165 void __iomem *port_mmio = mv_ap_base(ap);
954 struct mv_port_priv *pp = ap->private_data; 1166 struct mv_port_priv *pp = ap->private_data;
1167 int err = 0;
955 1168
956 if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN)) 1169 if (!(pp->pp_flags & MV_PP_FLAG_EDMA_EN))
957 return 0; 1170 return 0;
@@ -959,9 +1172,10 @@ static int mv_stop_edma(struct ata_port *ap)
959 mv_wait_for_edma_empty_idle(ap); 1172 mv_wait_for_edma_empty_idle(ap);
960 if (mv_stop_edma_engine(port_mmio)) { 1173 if (mv_stop_edma_engine(port_mmio)) {
961 ata_port_printk(ap, KERN_ERR, "Unable to stop eDMA\n"); 1174 ata_port_printk(ap, KERN_ERR, "Unable to stop eDMA\n");
962 return -EIO; 1175 err = -EIO;
963 } 1176 }
964 return 0; 1177 mv_edma_cfg(ap, 0, 0);
1178 return err;
965} 1179}
966 1180
967#ifdef ATA_DEBUG 1181#ifdef ATA_DEBUG
@@ -1130,35 +1344,33 @@ static int mv_qc_defer(struct ata_queued_cmd *qc)
1130 return ATA_DEFER_PORT; 1344 return ATA_DEFER_PORT;
1131} 1345}
1132 1346
1133static void mv_config_fbs(void __iomem *port_mmio, int want_ncq, int want_fbs) 1347static void mv_config_fbs(struct ata_port *ap, int want_ncq, int want_fbs)
1134{ 1348{
1135 u32 new_fiscfg, old_fiscfg; 1349 struct mv_port_priv *pp = ap->private_data;
1136 u32 new_ltmode, old_ltmode; 1350 void __iomem *port_mmio;
1137 u32 new_haltcond, old_haltcond;
1138 1351
1139 old_fiscfg = readl(port_mmio + FISCFG_OFS); 1352 u32 fiscfg, *old_fiscfg = &pp->cached.fiscfg;
1140 old_ltmode = readl(port_mmio + LTMODE_OFS); 1353 u32 ltmode, *old_ltmode = &pp->cached.ltmode;
1141 old_haltcond = readl(port_mmio + EDMA_HALTCOND_OFS); 1354 u32 haltcond, *old_haltcond = &pp->cached.haltcond;
1142 1355
1143 new_fiscfg = old_fiscfg & ~(FISCFG_SINGLE_SYNC | FISCFG_WAIT_DEV_ERR); 1356 ltmode = *old_ltmode & ~LTMODE_BIT8;
1144 new_ltmode = old_ltmode & ~LTMODE_BIT8; 1357 haltcond = *old_haltcond | EDMA_ERR_DEV;
1145 new_haltcond = old_haltcond | EDMA_ERR_DEV;
1146 1358
1147 if (want_fbs) { 1359 if (want_fbs) {
1148 new_fiscfg = old_fiscfg | FISCFG_SINGLE_SYNC; 1360 fiscfg = *old_fiscfg | FISCFG_SINGLE_SYNC;
1149 new_ltmode = old_ltmode | LTMODE_BIT8; 1361 ltmode = *old_ltmode | LTMODE_BIT8;
1150 if (want_ncq) 1362 if (want_ncq)
1151 new_haltcond &= ~EDMA_ERR_DEV; 1363 haltcond &= ~EDMA_ERR_DEV;
1152 else 1364 else
1153 new_fiscfg |= FISCFG_WAIT_DEV_ERR; 1365 fiscfg |= FISCFG_WAIT_DEV_ERR;
1366 } else {
1367 fiscfg = *old_fiscfg & ~(FISCFG_SINGLE_SYNC | FISCFG_WAIT_DEV_ERR);
1154 } 1368 }
1155 1369
1156 if (new_fiscfg != old_fiscfg) 1370 port_mmio = mv_ap_base(ap);
1157 writelfl(new_fiscfg, port_mmio + FISCFG_OFS); 1371 mv_write_cached_reg(port_mmio + FISCFG_OFS, old_fiscfg, fiscfg);
1158 if (new_ltmode != old_ltmode) 1372 mv_write_cached_reg(port_mmio + LTMODE_OFS, old_ltmode, ltmode);
1159 writelfl(new_ltmode, port_mmio + LTMODE_OFS); 1373 mv_write_cached_reg(port_mmio + EDMA_HALTCOND_OFS, old_haltcond, haltcond);
1160 if (new_haltcond != old_haltcond)
1161 writelfl(new_haltcond, port_mmio + EDMA_HALTCOND_OFS);
1162} 1374}
1163 1375
1164static void mv_60x1_errata_sata25(struct ata_port *ap, int want_ncq) 1376static void mv_60x1_errata_sata25(struct ata_port *ap, int want_ncq)
@@ -1176,7 +1388,86 @@ static void mv_60x1_errata_sata25(struct ata_port *ap, int want_ncq)
1176 writel(new, hpriv->base + MV_GPIO_PORT_CTL_OFS); 1388 writel(new, hpriv->base + MV_GPIO_PORT_CTL_OFS);
1177} 1389}
1178 1390
1179static void mv_edma_cfg(struct ata_port *ap, int want_ncq) 1391/**
1392 * mv_bmdma_enable - set a magic bit on GEN_IIE to allow bmdma
1393 * @ap: Port being initialized
1394 *
1395 * There are two DMA modes on these chips: basic DMA, and EDMA.
1396 *
1397 * Bit-0 of the "EDMA RESERVED" register enables/disables use
1398 * of basic DMA on the GEN_IIE versions of the chips.
1399 *
1400 * This bit survives EDMA resets, and must be set for basic DMA
1401 * to function, and should be cleared when EDMA is active.
1402 */
1403static void mv_bmdma_enable_iie(struct ata_port *ap, int enable_bmdma)
1404{
1405 struct mv_port_priv *pp = ap->private_data;
1406 u32 new, *old = &pp->cached.unknown_rsvd;
1407
1408 if (enable_bmdma)
1409 new = *old | 1;
1410 else
1411 new = *old & ~1;
1412 mv_write_cached_reg(mv_ap_base(ap) + EDMA_UNKNOWN_RSVD_OFS, old, new);
1413}
1414
1415/*
1416 * SOC chips have an issue whereby the HDD LEDs don't always blink
1417 * during I/O when NCQ is enabled. Enabling a special "LED blink" mode
1418 * of the SOC takes care of it, generating a steady blink rate when
1419 * any drive on the chip is active.
1420 *
1421 * Unfortunately, the blink mode is a global hardware setting for the SOC,
1422 * so we must use it whenever at least one port on the SOC has NCQ enabled.
1423 *
1424 * We turn "LED blink" off when NCQ is not in use anywhere, because the normal
1425 * LED operation works then, and provides better (more accurate) feedback.
1426 *
1427 * Note that this code assumes that an SOC never has more than one HC onboard.
1428 */
1429static void mv_soc_led_blink_enable(struct ata_port *ap)
1430{
1431 struct ata_host *host = ap->host;
1432 struct mv_host_priv *hpriv = host->private_data;
1433 void __iomem *hc_mmio;
1434 u32 led_ctrl;
1435
1436 if (hpriv->hp_flags & MV_HP_QUIRK_LED_BLINK_EN)
1437 return;
1438 hpriv->hp_flags |= MV_HP_QUIRK_LED_BLINK_EN;
1439 hc_mmio = mv_hc_base_from_port(mv_host_base(host), ap->port_no);
1440 led_ctrl = readl(hc_mmio + SOC_LED_CTRL_OFS);
1441 writel(led_ctrl | SOC_LED_CTRL_BLINK, hc_mmio + SOC_LED_CTRL_OFS);
1442}
1443
1444static void mv_soc_led_blink_disable(struct ata_port *ap)
1445{
1446 struct ata_host *host = ap->host;
1447 struct mv_host_priv *hpriv = host->private_data;
1448 void __iomem *hc_mmio;
1449 u32 led_ctrl;
1450 unsigned int port;
1451
1452 if (!(hpriv->hp_flags & MV_HP_QUIRK_LED_BLINK_EN))
1453 return;
1454
1455 /* disable led-blink only if no ports are using NCQ */
1456 for (port = 0; port < hpriv->n_ports; port++) {
1457 struct ata_port *this_ap = host->ports[port];
1458 struct mv_port_priv *pp = this_ap->private_data;
1459
1460 if (pp->pp_flags & MV_PP_FLAG_NCQ_EN)
1461 return;
1462 }
1463
1464 hpriv->hp_flags &= ~MV_HP_QUIRK_LED_BLINK_EN;
1465 hc_mmio = mv_hc_base_from_port(mv_host_base(host), ap->port_no);
1466 led_ctrl = readl(hc_mmio + SOC_LED_CTRL_OFS);
1467 writel(led_ctrl & ~SOC_LED_CTRL_BLINK, hc_mmio + SOC_LED_CTRL_OFS);
1468}
1469
1470static void mv_edma_cfg(struct ata_port *ap, int want_ncq, int want_edma)
1180{ 1471{
1181 u32 cfg; 1472 u32 cfg;
1182 struct mv_port_priv *pp = ap->private_data; 1473 struct mv_port_priv *pp = ap->private_data;
@@ -1185,7 +1476,8 @@ static void mv_edma_cfg(struct ata_port *ap, int want_ncq)
1185 1476
1186 /* set up non-NCQ EDMA configuration */ 1477 /* set up non-NCQ EDMA configuration */
1187 cfg = EDMA_CFG_Q_DEPTH; /* always 0x1f for *all* chips */ 1478 cfg = EDMA_CFG_Q_DEPTH; /* always 0x1f for *all* chips */
1188 pp->pp_flags &= ~MV_PP_FLAG_FBS_EN; 1479 pp->pp_flags &=
1480 ~(MV_PP_FLAG_FBS_EN | MV_PP_FLAG_NCQ_EN | MV_PP_FLAG_FAKE_ATA_BUSY);
1189 1481
1190 if (IS_GEN_I(hpriv)) 1482 if (IS_GEN_I(hpriv))
1191 cfg |= (1 << 8); /* enab config burst size mask */ 1483 cfg |= (1 << 8); /* enab config burst size mask */
@@ -1206,7 +1498,7 @@ static void mv_edma_cfg(struct ata_port *ap, int want_ncq)
1206 */ 1498 */
1207 want_fbs &= want_ncq; 1499 want_fbs &= want_ncq;
1208 1500
1209 mv_config_fbs(port_mmio, want_ncq, want_fbs); 1501 mv_config_fbs(ap, want_ncq, want_fbs);
1210 1502
1211 if (want_fbs) { 1503 if (want_fbs) {
1212 pp->pp_flags |= MV_PP_FLAG_FBS_EN; 1504 pp->pp_flags |= MV_PP_FLAG_FBS_EN;
@@ -1214,18 +1506,27 @@ static void mv_edma_cfg(struct ata_port *ap, int want_ncq)
1214 } 1506 }
1215 1507
1216 cfg |= (1 << 23); /* do not mask PM field in rx'd FIS */ 1508 cfg |= (1 << 23); /* do not mask PM field in rx'd FIS */
1217 cfg |= (1 << 22); /* enab 4-entry host queue cache */ 1509 if (want_edma) {
1218 if (!IS_SOC(hpriv)) 1510 cfg |= (1 << 22); /* enab 4-entry host queue cache */
1219 cfg |= (1 << 18); /* enab early completion */ 1511 if (!IS_SOC(hpriv))
1512 cfg |= (1 << 18); /* enab early completion */
1513 }
1220 if (hpriv->hp_flags & MV_HP_CUT_THROUGH) 1514 if (hpriv->hp_flags & MV_HP_CUT_THROUGH)
1221 cfg |= (1 << 17); /* enab cut-thru (dis stor&forwrd) */ 1515 cfg |= (1 << 17); /* enab cut-thru (dis stor&forwrd) */
1516 mv_bmdma_enable_iie(ap, !want_edma);
1517
1518 if (IS_SOC(hpriv)) {
1519 if (want_ncq)
1520 mv_soc_led_blink_enable(ap);
1521 else
1522 mv_soc_led_blink_disable(ap);
1523 }
1222 } 1524 }
1223 1525
1224 if (want_ncq) { 1526 if (want_ncq) {
1225 cfg |= EDMA_CFG_NCQ; 1527 cfg |= EDMA_CFG_NCQ;
1226 pp->pp_flags |= MV_PP_FLAG_NCQ_EN; 1528 pp->pp_flags |= MV_PP_FLAG_NCQ_EN;
1227 } else 1529 }
1228 pp->pp_flags &= ~MV_PP_FLAG_NCQ_EN;
1229 1530
1230 writelfl(cfg, port_mmio + EDMA_CFG_OFS); 1531 writelfl(cfg, port_mmio + EDMA_CFG_OFS);
1231} 1532}
@@ -1309,6 +1610,8 @@ static int mv_port_start(struct ata_port *ap)
1309 pp->sg_tbl_dma[tag] = pp->sg_tbl_dma[0]; 1610 pp->sg_tbl_dma[tag] = pp->sg_tbl_dma[0];
1310 } 1611 }
1311 } 1612 }
1613 mv_save_cached_regs(ap);
1614 mv_edma_cfg(ap, 0, 0);
1312 return 0; 1615 return 0;
1313 1616
1314out_port_free_dma_mem: 1617out_port_free_dma_mem:
@@ -1357,12 +1660,13 @@ static void mv_fill_sg(struct ata_queued_cmd *qc)
1357 u32 offset = addr & 0xffff; 1660 u32 offset = addr & 0xffff;
1358 u32 len = sg_len; 1661 u32 len = sg_len;
1359 1662
1360 if ((offset + sg_len > 0x10000)) 1663 if (offset + len > 0x10000)
1361 len = 0x10000 - offset; 1664 len = 0x10000 - offset;
1362 1665
1363 mv_sg->addr = cpu_to_le32(addr & 0xffffffff); 1666 mv_sg->addr = cpu_to_le32(addr & 0xffffffff);
1364 mv_sg->addr_hi = cpu_to_le32((addr >> 16) >> 16); 1667 mv_sg->addr_hi = cpu_to_le32((addr >> 16) >> 16);
1365 mv_sg->flags_size = cpu_to_le32(len & 0xffff); 1668 mv_sg->flags_size = cpu_to_le32(len & 0xffff);
1669 mv_sg->reserved = 0;
1366 1670
1367 sg_len -= len; 1671 sg_len -= len;
1368 addr += len; 1672 addr += len;
@@ -1374,6 +1678,7 @@ static void mv_fill_sg(struct ata_queued_cmd *qc)
1374 1678
1375 if (likely(last_sg)) 1679 if (likely(last_sg))
1376 last_sg->flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL); 1680 last_sg->flags_size |= cpu_to_le32(EPRD_FLAG_END_OF_TBL);
1681 mb(); /* ensure data structure is visible to the chipset */
1377} 1682}
1378 1683
1379static void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last) 1684static void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last)
@@ -1384,6 +1689,147 @@ static void mv_crqb_pack_cmd(__le16 *cmdw, u8 data, u8 addr, unsigned last)
1384} 1689}
1385 1690
1386/** 1691/**
1692 * mv_sff_irq_clear - Clear hardware interrupt after DMA.
1693 * @ap: Port associated with this ATA transaction.
1694 *
1695 * We need this only for ATAPI bmdma transactions,
1696 * as otherwise we experience spurious interrupts
1697 * after libata-sff handles the bmdma interrupts.
1698 */
1699static void mv_sff_irq_clear(struct ata_port *ap)
1700{
1701 mv_clear_and_enable_port_irqs(ap, mv_ap_base(ap), ERR_IRQ);
1702}
1703
1704/**
1705 * mv_check_atapi_dma - Filter ATAPI cmds which are unsuitable for DMA.
1706 * @qc: queued command to check for chipset/DMA compatibility.
1707 *
1708 * The bmdma engines cannot handle speculative data sizes
1709 * (bytecount under/over flow). So only allow DMA for
1710 * data transfer commands with known data sizes.
1711 *
1712 * LOCKING:
1713 * Inherited from caller.
1714 */
1715static int mv_check_atapi_dma(struct ata_queued_cmd *qc)
1716{
1717 struct scsi_cmnd *scmd = qc->scsicmd;
1718
1719 if (scmd) {
1720 switch (scmd->cmnd[0]) {
1721 case READ_6:
1722 case READ_10:
1723 case READ_12:
1724 case WRITE_6:
1725 case WRITE_10:
1726 case WRITE_12:
1727 case GPCMD_READ_CD:
1728 case GPCMD_SEND_DVD_STRUCTURE:
1729 case GPCMD_SEND_CUE_SHEET:
1730 return 0; /* DMA is safe */
1731 }
1732 }
1733 return -EOPNOTSUPP; /* use PIO instead */
1734}
1735
1736/**
1737 * mv_bmdma_setup - Set up BMDMA transaction
1738 * @qc: queued command to prepare DMA for.
1739 *
1740 * LOCKING:
1741 * Inherited from caller.
1742 */
1743static void mv_bmdma_setup(struct ata_queued_cmd *qc)
1744{
1745 struct ata_port *ap = qc->ap;
1746 void __iomem *port_mmio = mv_ap_base(ap);
1747 struct mv_port_priv *pp = ap->private_data;
1748
1749 mv_fill_sg(qc);
1750
1751 /* clear all DMA cmd bits */
1752 writel(0, port_mmio + BMDMA_CMD_OFS);
1753
1754 /* load PRD table addr. */
1755 writel((pp->sg_tbl_dma[qc->tag] >> 16) >> 16,
1756 port_mmio + BMDMA_PRD_HIGH_OFS);
1757 writelfl(pp->sg_tbl_dma[qc->tag],
1758 port_mmio + BMDMA_PRD_LOW_OFS);
1759
1760 /* issue r/w command */
1761 ap->ops->sff_exec_command(ap, &qc->tf);
1762}
1763
1764/**
1765 * mv_bmdma_start - Start a BMDMA transaction
1766 * @qc: queued command to start DMA on.
1767 *
1768 * LOCKING:
1769 * Inherited from caller.
1770 */
1771static void mv_bmdma_start(struct ata_queued_cmd *qc)
1772{
1773 struct ata_port *ap = qc->ap;
1774 void __iomem *port_mmio = mv_ap_base(ap);
1775 unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);
1776 u32 cmd = (rw ? 0 : ATA_DMA_WR) | ATA_DMA_START;
1777
1778 /* start host DMA transaction */
1779 writelfl(cmd, port_mmio + BMDMA_CMD_OFS);
1780}
1781
1782/**
1783 * mv_bmdma_stop - Stop BMDMA transfer
1784 * @qc: queued command to stop DMA on.
1785 *
1786 * Clears the ATA_DMA_START flag in the bmdma control register
1787 *
1788 * LOCKING:
1789 * Inherited from caller.
1790 */
1791static void mv_bmdma_stop(struct ata_queued_cmd *qc)
1792{
1793 struct ata_port *ap = qc->ap;
1794 void __iomem *port_mmio = mv_ap_base(ap);
1795 u32 cmd;
1796
1797 /* clear start/stop bit */
1798 cmd = readl(port_mmio + BMDMA_CMD_OFS);
1799 cmd &= ~ATA_DMA_START;
1800 writelfl(cmd, port_mmio + BMDMA_CMD_OFS);
1801
1802 /* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */
1803 ata_sff_dma_pause(ap);
1804}
1805
1806/**
1807 * mv_bmdma_status - Read BMDMA status
1808 * @ap: port for which to retrieve DMA status.
1809 *
1810 * Read and return equivalent of the sff BMDMA status register.
1811 *
1812 * LOCKING:
1813 * Inherited from caller.
1814 */
1815static u8 mv_bmdma_status(struct ata_port *ap)
1816{
1817 void __iomem *port_mmio = mv_ap_base(ap);
1818 u32 reg, status;
1819
1820 /*
1821 * Other bits are valid only if ATA_DMA_ACTIVE==0,
1822 * and the ATA_DMA_INTR bit doesn't exist.
1823 */
1824 reg = readl(port_mmio + BMDMA_STATUS_OFS);
1825 if (reg & ATA_DMA_ACTIVE)
1826 status = ATA_DMA_ACTIVE;
1827 else
1828 status = (reg & ATA_DMA_ERR) | ATA_DMA_INTR;
1829 return status;
1830}
1831
1832/**
1387 * mv_qc_prep - Host specific command preparation. 1833 * mv_qc_prep - Host specific command preparation.
1388 * @qc: queued command to prepare 1834 * @qc: queued command to prepare
1389 * 1835 *
@@ -1545,6 +1991,132 @@ static void mv_qc_prep_iie(struct ata_queued_cmd *qc)
1545} 1991}
1546 1992
1547/** 1993/**
1994 * mv_sff_check_status - fetch device status, if valid
1995 * @ap: ATA port to fetch status from
1996 *
1997 * When using command issue via mv_qc_issue_fis(),
1998 * the initial ATA_BUSY state does not show up in the
1999 * ATA status (shadow) register. This can confuse libata!
2000 *
2001 * So we have a hook here to fake ATA_BUSY for that situation,
2002 * until the first time a BUSY, DRQ, or ERR bit is seen.
2003 *
2004 * The rest of the time, it simply returns the ATA status register.
2005 */
2006static u8 mv_sff_check_status(struct ata_port *ap)
2007{
2008 u8 stat = ioread8(ap->ioaddr.status_addr);
2009 struct mv_port_priv *pp = ap->private_data;
2010
2011 if (pp->pp_flags & MV_PP_FLAG_FAKE_ATA_BUSY) {
2012 if (stat & (ATA_BUSY | ATA_DRQ | ATA_ERR))
2013 pp->pp_flags &= ~MV_PP_FLAG_FAKE_ATA_BUSY;
2014 else
2015 stat = ATA_BUSY;
2016 }
2017 return stat;
2018}
2019
2020/**
2021 * mv_send_fis - Send a FIS, using the "Vendor-Unique FIS" register
2022 * @fis: fis to be sent
2023 * @nwords: number of 32-bit words in the fis
2024 */
2025static unsigned int mv_send_fis(struct ata_port *ap, u32 *fis, int nwords)
2026{
2027 void __iomem *port_mmio = mv_ap_base(ap);
2028 u32 ifctl, old_ifctl, ifstat;
2029 int i, timeout = 200, final_word = nwords - 1;
2030
2031 /* Initiate FIS transmission mode */
2032 old_ifctl = readl(port_mmio + SATA_IFCTL_OFS);
2033 ifctl = 0x100 | (old_ifctl & 0xf);
2034 writelfl(ifctl, port_mmio + SATA_IFCTL_OFS);
2035
2036 /* Send all words of the FIS except for the final word */
2037 for (i = 0; i < final_word; ++i)
2038 writel(fis[i], port_mmio + VENDOR_UNIQUE_FIS_OFS);
2039
2040 /* Flag end-of-transmission, and then send the final word */
2041 writelfl(ifctl | 0x200, port_mmio + SATA_IFCTL_OFS);
2042 writelfl(fis[final_word], port_mmio + VENDOR_UNIQUE_FIS_OFS);
2043
2044 /*
2045 * Wait for FIS transmission to complete.
2046 * This typically takes just a single iteration.
2047 */
2048 do {
2049 ifstat = readl(port_mmio + SATA_IFSTAT_OFS);
2050 } while (!(ifstat & 0x1000) && --timeout);
2051
2052 /* Restore original port configuration */
2053 writelfl(old_ifctl, port_mmio + SATA_IFCTL_OFS);
2054
2055 /* See if it worked */
2056 if ((ifstat & 0x3000) != 0x1000) {
2057 ata_port_printk(ap, KERN_WARNING,
2058 "%s transmission error, ifstat=%08x\n",
2059 __func__, ifstat);
2060 return AC_ERR_OTHER;
2061 }
2062 return 0;
2063}
2064
2065/**
2066 * mv_qc_issue_fis - Issue a command directly as a FIS
2067 * @qc: queued command to start
2068 *
2069 * Note that the ATA shadow registers are not updated
2070 * after command issue, so the device will appear "READY"
2071 * if polled, even while it is BUSY processing the command.
2072 *
2073 * So we use a status hook to fake ATA_BUSY until the drive changes state.
2074 *
2075 * Note: we don't get updated shadow regs on *completion*
2076 * of non-data commands. So avoid sending them via this function,
2077 * as they will appear to have completed immediately.
2078 *
2079 * GEN_IIE has special registers that we could get the result tf from,
2080 * but earlier chipsets do not. For now, we ignore those registers.
2081 */
2082static unsigned int mv_qc_issue_fis(struct ata_queued_cmd *qc)
2083{
2084 struct ata_port *ap = qc->ap;
2085 struct mv_port_priv *pp = ap->private_data;
2086 struct ata_link *link = qc->dev->link;
2087 u32 fis[5];
2088 int err = 0;
2089
2090 ata_tf_to_fis(&qc->tf, link->pmp, 1, (void *)fis);
2091 err = mv_send_fis(ap, fis, sizeof(fis) / sizeof(fis[0]));
2092 if (err)
2093 return err;
2094
2095 switch (qc->tf.protocol) {
2096 case ATAPI_PROT_PIO:
2097 pp->pp_flags |= MV_PP_FLAG_FAKE_ATA_BUSY;
2098 /* fall through */
2099 case ATAPI_PROT_NODATA:
2100 ap->hsm_task_state = HSM_ST_FIRST;
2101 break;
2102 case ATA_PROT_PIO:
2103 pp->pp_flags |= MV_PP_FLAG_FAKE_ATA_BUSY;
2104 if (qc->tf.flags & ATA_TFLAG_WRITE)
2105 ap->hsm_task_state = HSM_ST_FIRST;
2106 else
2107 ap->hsm_task_state = HSM_ST;
2108 break;
2109 default:
2110 ap->hsm_task_state = HSM_ST_LAST;
2111 break;
2112 }
2113
2114 if (qc->tf.flags & ATA_TFLAG_POLLING)
2115 ata_pio_queue_task(ap, qc, 0);
2116 return 0;
2117}
2118
2119/**
1548 * mv_qc_issue - Initiate a command to the host 2120 * mv_qc_issue - Initiate a command to the host
1549 * @qc: queued command to start 2121 * @qc: queued command to start
1550 * 2122 *
@@ -1558,14 +2130,28 @@ static void mv_qc_prep_iie(struct ata_queued_cmd *qc)
1558 */ 2130 */
1559static unsigned int mv_qc_issue(struct ata_queued_cmd *qc) 2131static unsigned int mv_qc_issue(struct ata_queued_cmd *qc)
1560{ 2132{
2133 static int limit_warnings = 10;
1561 struct ata_port *ap = qc->ap; 2134 struct ata_port *ap = qc->ap;
1562 void __iomem *port_mmio = mv_ap_base(ap); 2135 void __iomem *port_mmio = mv_ap_base(ap);
1563 struct mv_port_priv *pp = ap->private_data; 2136 struct mv_port_priv *pp = ap->private_data;
1564 u32 in_index; 2137 u32 in_index;
2138 unsigned int port_irqs;
1565 2139
1566 if ((qc->tf.protocol != ATA_PROT_DMA) && 2140 pp->pp_flags &= ~MV_PP_FLAG_FAKE_ATA_BUSY; /* paranoia */
1567 (qc->tf.protocol != ATA_PROT_NCQ)) { 2141
1568 static int limit_warnings = 10; 2142 switch (qc->tf.protocol) {
2143 case ATA_PROT_DMA:
2144 case ATA_PROT_NCQ:
2145 mv_start_edma(ap, port_mmio, pp, qc->tf.protocol);
2146 pp->req_idx = (pp->req_idx + 1) & MV_MAX_Q_DEPTH_MASK;
2147 in_index = pp->req_idx << EDMA_REQ_Q_PTR_SHIFT;
2148
2149 /* Write the request in pointer to kick the EDMA to life */
2150 writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | in_index,
2151 port_mmio + EDMA_REQ_Q_IN_PTR_OFS);
2152 return 0;
2153
2154 case ATA_PROT_PIO:
1569 /* 2155 /*
1570 * Errata SATA#16, SATA#24: warn if multiple DRQs expected. 2156 * Errata SATA#16, SATA#24: warn if multiple DRQs expected.
1571 * 2157 *
@@ -1583,27 +2169,46 @@ static unsigned int mv_qc_issue(struct ata_queued_cmd *qc)
1583 ": attempting PIO w/multiple DRQ: " 2169 ": attempting PIO w/multiple DRQ: "
1584 "this may fail due to h/w errata\n"); 2170 "this may fail due to h/w errata\n");
1585 } 2171 }
1586 /* 2172 /* drop through */
1587 * We're about to send a non-EDMA capable command to the 2173 case ATA_PROT_NODATA:
1588 * port. Turn off EDMA so there won't be problems accessing 2174 case ATAPI_PROT_PIO:
1589 * shadow block, etc registers. 2175 case ATAPI_PROT_NODATA:
1590 */ 2176 if (ap->flags & ATA_FLAG_PIO_POLLING)
1591 mv_stop_edma(ap); 2177 qc->tf.flags |= ATA_TFLAG_POLLING;
1592 mv_enable_port_irqs(ap, ERR_IRQ); 2178 break;
1593 mv_pmp_select(ap, qc->dev->link->pmp);
1594 return ata_sff_qc_issue(qc);
1595 } 2179 }
1596 2180
1597 mv_start_dma(ap, port_mmio, pp, qc->tf.protocol); 2181 if (qc->tf.flags & ATA_TFLAG_POLLING)
1598 2182 port_irqs = ERR_IRQ; /* mask device interrupt when polling */
1599 pp->req_idx = (pp->req_idx + 1) & MV_MAX_Q_DEPTH_MASK; 2183 else
1600 in_index = pp->req_idx << EDMA_REQ_Q_PTR_SHIFT; 2184 port_irqs = ERR_IRQ | DONE_IRQ; /* unmask all interrupts */
1601 2185
1602 /* and write the request in pointer to kick the EDMA to life */ 2186 /*
1603 writelfl((pp->crqb_dma & EDMA_REQ_Q_BASE_LO_MASK) | in_index, 2187 * We're about to send a non-EDMA capable command to the
1604 port_mmio + EDMA_REQ_Q_IN_PTR_OFS); 2188 * port. Turn off EDMA so there won't be problems accessing
2189 * shadow block, etc registers.
2190 */
2191 mv_stop_edma(ap);
2192 mv_clear_and_enable_port_irqs(ap, mv_ap_base(ap), port_irqs);
2193 mv_pmp_select(ap, qc->dev->link->pmp);
1605 2194
1606 return 0; 2195 if (qc->tf.command == ATA_CMD_READ_LOG_EXT) {
2196 struct mv_host_priv *hpriv = ap->host->private_data;
2197 /*
2198 * Workaround for 88SX60x1 FEr SATA#25 (part 2).
2199 *
2200 * After any NCQ error, the READ_LOG_EXT command
2201 * from libata-eh *must* use mv_qc_issue_fis().
2202 * Otherwise it might fail, due to chip errata.
2203 *
2204 * Rather than special-case it, we'll just *always*
2205 * use this method here for READ_LOG_EXT, making for
2206 * easier testing.
2207 */
2208 if (IS_GEN_II(hpriv))
2209 return mv_qc_issue_fis(qc);
2210 }
2211 return ata_sff_qc_issue(qc);
1607} 2212}
1608 2213
1609static struct ata_queued_cmd *mv_get_active_qc(struct ata_port *ap) 2214static struct ata_queued_cmd *mv_get_active_qc(struct ata_port *ap)
@@ -1614,8 +2219,12 @@ static struct ata_queued_cmd *mv_get_active_qc(struct ata_port *ap)
1614 if (pp->pp_flags & MV_PP_FLAG_NCQ_EN) 2219 if (pp->pp_flags & MV_PP_FLAG_NCQ_EN)
1615 return NULL; 2220 return NULL;
1616 qc = ata_qc_from_tag(ap, ap->link.active_tag); 2221 qc = ata_qc_from_tag(ap, ap->link.active_tag);
1617 if (qc && (qc->tf.flags & ATA_TFLAG_POLLING)) 2222 if (qc) {
1618 qc = NULL; 2223 if (qc->tf.flags & ATA_TFLAG_POLLING)
2224 qc = NULL;
2225 else if (!(qc->flags & ATA_QCFLAG_ACTIVE))
2226 qc = NULL;
2227 }
1619 return qc; 2228 return qc;
1620} 2229}
1621 2230
@@ -2084,6 +2693,10 @@ static int mv_host_intr(struct ata_host *host, u32 main_irq_cause)
2084 void __iomem *mmio = hpriv->base, *hc_mmio; 2693 void __iomem *mmio = hpriv->base, *hc_mmio;
2085 unsigned int handled = 0, port; 2694 unsigned int handled = 0, port;
2086 2695
2696 /* If asserted, clear the "all ports" IRQ coalescing bit */
2697 if (main_irq_cause & ALL_PORTS_COAL_DONE)
2698 writel(~ALL_PORTS_COAL_IRQ, mmio + MV_IRQ_COAL_CAUSE);
2699
2087 for (port = 0; port < hpriv->n_ports; port++) { 2700 for (port = 0; port < hpriv->n_ports; port++) {
2088 struct ata_port *ap = host->ports[port]; 2701 struct ata_port *ap = host->ports[port];
2089 unsigned int p, shift, hardport, port_cause; 2702 unsigned int p, shift, hardport, port_cause;
@@ -2116,6 +2729,8 @@ static int mv_host_intr(struct ata_host *host, u32 main_irq_cause)
2116 * to ack (only) those ports via hc_irq_cause. 2729 * to ack (only) those ports via hc_irq_cause.
2117 */ 2730 */
2118 ack_irqs = 0; 2731 ack_irqs = 0;
2732 if (hc_cause & PORTS_0_3_COAL_DONE)
2733 ack_irqs = HC_COAL_IRQ;
2119 for (p = 0; p < MV_PORTS_PER_HC; ++p) { 2734 for (p = 0; p < MV_PORTS_PER_HC; ++p) {
2120 if ((port + p) >= hpriv->n_ports) 2735 if ((port + p) >= hpriv->n_ports)
2121 break; 2736 break;
@@ -2204,7 +2819,7 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance)
2204 2819
2205 /* for MSI: block new interrupts while in here */ 2820 /* for MSI: block new interrupts while in here */
2206 if (using_msi) 2821 if (using_msi)
2207 writel(0, hpriv->main_irq_mask_addr); 2822 mv_write_main_irq_mask(0, hpriv);
2208 2823
2209 main_irq_cause = readl(hpriv->main_irq_cause_addr); 2824 main_irq_cause = readl(hpriv->main_irq_cause_addr);
2210 pending_irqs = main_irq_cause & hpriv->main_irq_mask; 2825 pending_irqs = main_irq_cause & hpriv->main_irq_mask;
@@ -2221,7 +2836,7 @@ static irqreturn_t mv_interrupt(int irq, void *dev_instance)
2221 2836
2222 /* for MSI: unmask; interrupt cause bits will retrigger now */ 2837 /* for MSI: unmask; interrupt cause bits will retrigger now */
2223 if (using_msi) 2838 if (using_msi)
2224 writel(hpriv->main_irq_mask, hpriv->main_irq_mask_addr); 2839 mv_write_main_irq_mask(hpriv->main_irq_mask, hpriv);
2225 2840
2226 spin_unlock(&host->lock); 2841 spin_unlock(&host->lock);
2227 2842
@@ -2774,6 +3389,8 @@ static int mv_hardreset(struct ata_link *link, unsigned int *class,
2774 3389
2775 mv_reset_channel(hpriv, mmio, ap->port_no); 3390 mv_reset_channel(hpriv, mmio, ap->port_no);
2776 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN; 3391 pp->pp_flags &= ~MV_PP_FLAG_EDMA_EN;
3392 pp->pp_flags &=
3393 ~(MV_PP_FLAG_FBS_EN | MV_PP_FLAG_NCQ_EN | MV_PP_FLAG_FAKE_ATA_BUSY);
2777 3394
2778 /* Workaround for errata FEr SATA#10 (part 2) */ 3395 /* Workaround for errata FEr SATA#10 (part 2) */
2779 do { 3396 do {
@@ -2793,6 +3410,8 @@ static int mv_hardreset(struct ata_link *link, unsigned int *class,
2793 extra = HZ; /* only extend it once, max */ 3410 extra = HZ; /* only extend it once, max */
2794 } 3411 }
2795 } while (sstatus != 0x0 && sstatus != 0x113 && sstatus != 0x123); 3412 } while (sstatus != 0x0 && sstatus != 0x113 && sstatus != 0x123);
3413 mv_save_cached_regs(ap);
3414 mv_edma_cfg(ap, 0, 0);
2796 3415
2797 return rc; 3416 return rc;
2798} 3417}
@@ -3126,6 +3745,8 @@ static int mv_init_host(struct ata_host *host, unsigned int board_idx)
3126 * The per-port interrupts get done later as ports are set up. 3745 * The per-port interrupts get done later as ports are set up.
3127 */ 3746 */
3128 mv_set_main_irq_mask(host, 0, PCI_ERR); 3747 mv_set_main_irq_mask(host, 0, PCI_ERR);
3748 mv_set_irq_coalescing(host, irq_coalescing_io_count,
3749 irq_coalescing_usecs);
3129done: 3750done:
3130 return rc; 3751 return rc;
3131} 3752}
@@ -3287,12 +3908,6 @@ static struct pci_driver mv_pci_driver = {
3287 .remove = ata_pci_remove_one, 3908 .remove = ata_pci_remove_one,
3288}; 3909};
3289 3910
3290/*
3291 * module options
3292 */
3293static int msi; /* Use PCI msi; either zero (off, default) or non-zero */
3294
3295
3296/* move to PCI layer or libata core? */ 3911/* move to PCI layer or libata core? */
3297static int pci_go_64(struct pci_dev *pdev) 3912static int pci_go_64(struct pci_dev *pdev)
3298{ 3913{
@@ -3474,10 +4089,5 @@ MODULE_DEVICE_TABLE(pci, mv_pci_tbl);
3474MODULE_VERSION(DRV_VERSION); 4089MODULE_VERSION(DRV_VERSION);
3475MODULE_ALIAS("platform:" DRV_NAME); 4090MODULE_ALIAS("platform:" DRV_NAME);
3476 4091
3477#ifdef CONFIG_PCI
3478module_param(msi, int, 0444);
3479MODULE_PARM_DESC(msi, "Enable use of PCI MSI (0=off, 1=on)");
3480#endif
3481
3482module_init(mv_init); 4092module_init(mv_init);
3483module_exit(mv_exit); 4093module_exit(mv_exit);
diff --git a/drivers/ata/sata_nv.c b/drivers/ata/sata_nv.c
index f65b53785a8f..6cda12ba8122 100644
--- a/drivers/ata/sata_nv.c
+++ b/drivers/ata/sata_nv.c
@@ -57,9 +57,9 @@ enum {
57 NV_MMIO_BAR = 5, 57 NV_MMIO_BAR = 5,
58 58
59 NV_PORTS = 2, 59 NV_PORTS = 2,
60 NV_PIO_MASK = 0x1f, 60 NV_PIO_MASK = ATA_PIO4,
61 NV_MWDMA_MASK = 0x07, 61 NV_MWDMA_MASK = ATA_MWDMA2,
62 NV_UDMA_MASK = 0x7f, 62 NV_UDMA_MASK = ATA_UDMA6,
63 NV_PORT0_SCR_REG_OFFSET = 0x00, 63 NV_PORT0_SCR_REG_OFFSET = 0x00,
64 NV_PORT1_SCR_REG_OFFSET = 0x40, 64 NV_PORT1_SCR_REG_OFFSET = 0x40,
65 65
@@ -408,6 +408,7 @@ static struct scsi_host_template nv_swncq_sht = {
408 408
409static struct ata_port_operations nv_common_ops = { 409static struct ata_port_operations nv_common_ops = {
410 .inherits = &ata_bmdma_port_ops, 410 .inherits = &ata_bmdma_port_ops,
411 .lost_interrupt = ATA_OP_NULL,
411 .scr_read = nv_scr_read, 412 .scr_read = nv_scr_read,
412 .scr_write = nv_scr_write, 413 .scr_write = nv_scr_write,
413}; 414};
diff --git a/drivers/ata/sata_promise.c b/drivers/ata/sata_promise.c
index ba9a2570a742..b1fd7d62071a 100644
--- a/drivers/ata/sata_promise.c
+++ b/drivers/ata/sata_promise.c
@@ -176,7 +176,9 @@ static const struct ata_port_operations pdc_common_ops = {
176 .check_atapi_dma = pdc_check_atapi_dma, 176 .check_atapi_dma = pdc_check_atapi_dma,
177 .qc_prep = pdc_qc_prep, 177 .qc_prep = pdc_qc_prep,
178 .qc_issue = pdc_qc_issue, 178 .qc_issue = pdc_qc_issue,
179
179 .sff_irq_clear = pdc_irq_clear, 180 .sff_irq_clear = pdc_irq_clear,
181 .lost_interrupt = ATA_OP_NULL,
180 182
181 .post_internal_cmd = pdc_post_internal_cmd, 183 .post_internal_cmd = pdc_post_internal_cmd,
182 .error_handler = pdc_error_handler, 184 .error_handler = pdc_error_handler,
@@ -213,8 +215,8 @@ static const struct ata_port_info pdc_port_info[] = {
213 { 215 {
214 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA | 216 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
215 PDC_FLAG_SATA_PATA, 217 PDC_FLAG_SATA_PATA,
216 .pio_mask = 0x1f, /* pio0-4 */ 218 .pio_mask = ATA_PIO4,
217 .mwdma_mask = 0x07, /* mwdma0-2 */ 219 .mwdma_mask = ATA_MWDMA2,
218 .udma_mask = ATA_UDMA6, 220 .udma_mask = ATA_UDMA6,
219 .port_ops = &pdc_old_sata_ops, 221 .port_ops = &pdc_old_sata_ops,
220 }, 222 },
@@ -222,8 +224,8 @@ static const struct ata_port_info pdc_port_info[] = {
222 [board_2037x_pata] = 224 [board_2037x_pata] =
223 { 225 {
224 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS, 226 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS,
225 .pio_mask = 0x1f, /* pio0-4 */ 227 .pio_mask = ATA_PIO4,
226 .mwdma_mask = 0x07, /* mwdma0-2 */ 228 .mwdma_mask = ATA_MWDMA2,
227 .udma_mask = ATA_UDMA6, 229 .udma_mask = ATA_UDMA6,
228 .port_ops = &pdc_pata_ops, 230 .port_ops = &pdc_pata_ops,
229 }, 231 },
@@ -232,8 +234,8 @@ static const struct ata_port_info pdc_port_info[] = {
232 { 234 {
233 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA | 235 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
234 PDC_FLAG_4_PORTS, 236 PDC_FLAG_4_PORTS,
235 .pio_mask = 0x1f, /* pio0-4 */ 237 .pio_mask = ATA_PIO4,
236 .mwdma_mask = 0x07, /* mwdma0-2 */ 238 .mwdma_mask = ATA_MWDMA2,
237 .udma_mask = ATA_UDMA6, 239 .udma_mask = ATA_UDMA6,
238 .port_ops = &pdc_old_sata_ops, 240 .port_ops = &pdc_old_sata_ops,
239 }, 241 },
@@ -242,8 +244,8 @@ static const struct ata_port_info pdc_port_info[] = {
242 { 244 {
243 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS | 245 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS |
244 PDC_FLAG_4_PORTS, 246 PDC_FLAG_4_PORTS,
245 .pio_mask = 0x1f, /* pio0-4 */ 247 .pio_mask = ATA_PIO4,
246 .mwdma_mask = 0x07, /* mwdma0-2 */ 248 .mwdma_mask = ATA_MWDMA2,
247 .udma_mask = ATA_UDMA6, 249 .udma_mask = ATA_UDMA6,
248 .port_ops = &pdc_pata_ops, 250 .port_ops = &pdc_pata_ops,
249 }, 251 },
@@ -252,8 +254,8 @@ static const struct ata_port_info pdc_port_info[] = {
252 { 254 {
253 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA | 255 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
254 PDC_FLAG_GEN_II | PDC_FLAG_SATA_PATA, 256 PDC_FLAG_GEN_II | PDC_FLAG_SATA_PATA,
255 .pio_mask = 0x1f, /* pio0-4 */ 257 .pio_mask = ATA_PIO4,
256 .mwdma_mask = 0x07, /* mwdma0-2 */ 258 .mwdma_mask = ATA_MWDMA2,
257 .udma_mask = ATA_UDMA6, 259 .udma_mask = ATA_UDMA6,
258 .port_ops = &pdc_sata_ops, 260 .port_ops = &pdc_sata_ops,
259 }, 261 },
@@ -262,8 +264,8 @@ static const struct ata_port_info pdc_port_info[] = {
262 { 264 {
263 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS | 265 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SLAVE_POSS |
264 PDC_FLAG_GEN_II, 266 PDC_FLAG_GEN_II,
265 .pio_mask = 0x1f, /* pio0-4 */ 267 .pio_mask = ATA_PIO4,
266 .mwdma_mask = 0x07, /* mwdma0-2 */ 268 .mwdma_mask = ATA_MWDMA2,
267 .udma_mask = ATA_UDMA6, 269 .udma_mask = ATA_UDMA6,
268 .port_ops = &pdc_pata_ops, 270 .port_ops = &pdc_pata_ops,
269 }, 271 },
@@ -272,8 +274,8 @@ static const struct ata_port_info pdc_port_info[] = {
272 { 274 {
273 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA | 275 .flags = PDC_COMMON_FLAGS | ATA_FLAG_SATA |
274 PDC_FLAG_GEN_II | PDC_FLAG_4_PORTS, 276 PDC_FLAG_GEN_II | PDC_FLAG_4_PORTS,
275 .pio_mask = 0x1f, /* pio0-4 */ 277 .pio_mask = ATA_PIO4,
276 .mwdma_mask = 0x07, /* mwdma0-2 */ 278 .mwdma_mask = ATA_MWDMA2,
277 .udma_mask = ATA_UDMA6, 279 .udma_mask = ATA_UDMA6,
278 .port_ops = &pdc_sata_ops, 280 .port_ops = &pdc_sata_ops,
279 }, 281 },
diff --git a/drivers/ata/sata_qstor.c b/drivers/ata/sata_qstor.c
index a000c86ac859..c3936d35cdac 100644
--- a/drivers/ata/sata_qstor.c
+++ b/drivers/ata/sata_qstor.c
@@ -147,6 +147,7 @@ static struct ata_port_operations qs_ata_ops = {
147 .softreset = ATA_OP_NULL, 147 .softreset = ATA_OP_NULL,
148 .error_handler = qs_error_handler, 148 .error_handler = qs_error_handler,
149 .post_internal_cmd = ATA_OP_NULL, 149 .post_internal_cmd = ATA_OP_NULL,
150 .lost_interrupt = ATA_OP_NULL,
150 151
151 .scr_read = qs_scr_read, 152 .scr_read = qs_scr_read,
152 .scr_write = qs_scr_write, 153 .scr_write = qs_scr_write,
@@ -160,7 +161,7 @@ static const struct ata_port_info qs_port_info[] = {
160 { 161 {
161 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 162 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
162 ATA_FLAG_MMIO | ATA_FLAG_PIO_POLLING, 163 ATA_FLAG_MMIO | ATA_FLAG_PIO_POLLING,
163 .pio_mask = 0x10, /* pio4 */ 164 .pio_mask = ATA_PIO4_ONLY,
164 .udma_mask = ATA_UDMA6, 165 .udma_mask = ATA_UDMA6,
165 .port_ops = &qs_ata_ops, 166 .port_ops = &qs_ata_ops,
166 }, 167 },
diff --git a/drivers/ata/sata_sil.c b/drivers/ata/sata_sil.c
index d0091609e210..e67ce8e5caa5 100644
--- a/drivers/ata/sata_sil.c
+++ b/drivers/ata/sata_sil.c
@@ -200,8 +200,8 @@ static const struct ata_port_info sil_port_info[] = {
200 /* sil_3112 */ 200 /* sil_3112 */
201 { 201 {
202 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_MOD15WRITE, 202 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_MOD15WRITE,
203 .pio_mask = 0x1f, /* pio0-4 */ 203 .pio_mask = ATA_PIO4,
204 .mwdma_mask = 0x07, /* mwdma0-2 */ 204 .mwdma_mask = ATA_MWDMA2,
205 .udma_mask = ATA_UDMA5, 205 .udma_mask = ATA_UDMA5,
206 .port_ops = &sil_ops, 206 .port_ops = &sil_ops,
207 }, 207 },
@@ -209,24 +209,24 @@ static const struct ata_port_info sil_port_info[] = {
209 { 209 {
210 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_MOD15WRITE | 210 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_MOD15WRITE |
211 SIL_FLAG_NO_SATA_IRQ, 211 SIL_FLAG_NO_SATA_IRQ,
212 .pio_mask = 0x1f, /* pio0-4 */ 212 .pio_mask = ATA_PIO4,
213 .mwdma_mask = 0x07, /* mwdma0-2 */ 213 .mwdma_mask = ATA_MWDMA2,
214 .udma_mask = ATA_UDMA5, 214 .udma_mask = ATA_UDMA5,
215 .port_ops = &sil_ops, 215 .port_ops = &sil_ops,
216 }, 216 },
217 /* sil_3512 */ 217 /* sil_3512 */
218 { 218 {
219 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT, 219 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT,
220 .pio_mask = 0x1f, /* pio0-4 */ 220 .pio_mask = ATA_PIO4,
221 .mwdma_mask = 0x07, /* mwdma0-2 */ 221 .mwdma_mask = ATA_MWDMA2,
222 .udma_mask = ATA_UDMA5, 222 .udma_mask = ATA_UDMA5,
223 .port_ops = &sil_ops, 223 .port_ops = &sil_ops,
224 }, 224 },
225 /* sil_3114 */ 225 /* sil_3114 */
226 { 226 {
227 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT, 227 .flags = SIL_DFL_PORT_FLAGS | SIL_FLAG_RERR_ON_DMA_ACT,
228 .pio_mask = 0x1f, /* pio0-4 */ 228 .pio_mask = ATA_PIO4,
229 .mwdma_mask = 0x07, /* mwdma0-2 */ 229 .mwdma_mask = ATA_MWDMA2,
230 .udma_mask = ATA_UDMA5, 230 .udma_mask = ATA_UDMA5,
231 .port_ops = &sil_ops, 231 .port_ops = &sil_ops,
232 }, 232 },
diff --git a/drivers/ata/sata_sil24.c b/drivers/ata/sata_sil24.c
index 2590c2279fa7..0d8990dcdfcd 100644
--- a/drivers/ata/sata_sil24.c
+++ b/drivers/ata/sata_sil24.c
@@ -429,25 +429,25 @@ static const struct ata_port_info sil24_port_info[] = {
429 { 429 {
430 .flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(4) | 430 .flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(4) |
431 SIL24_FLAG_PCIX_IRQ_WOC, 431 SIL24_FLAG_PCIX_IRQ_WOC,
432 .pio_mask = 0x1f, /* pio0-4 */ 432 .pio_mask = ATA_PIO4,
433 .mwdma_mask = 0x07, /* mwdma0-2 */ 433 .mwdma_mask = ATA_MWDMA2,
434 .udma_mask = ATA_UDMA5, /* udma0-5 */ 434 .udma_mask = ATA_UDMA5,
435 .port_ops = &sil24_ops, 435 .port_ops = &sil24_ops,
436 }, 436 },
437 /* sil_3132 */ 437 /* sil_3132 */
438 { 438 {
439 .flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(2), 439 .flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(2),
440 .pio_mask = 0x1f, /* pio0-4 */ 440 .pio_mask = ATA_PIO4,
441 .mwdma_mask = 0x07, /* mwdma0-2 */ 441 .mwdma_mask = ATA_MWDMA2,
442 .udma_mask = ATA_UDMA5, /* udma0-5 */ 442 .udma_mask = ATA_UDMA5,
443 .port_ops = &sil24_ops, 443 .port_ops = &sil24_ops,
444 }, 444 },
445 /* sil_3131/sil_3531 */ 445 /* sil_3131/sil_3531 */
446 { 446 {
447 .flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(1), 447 .flags = SIL24_COMMON_FLAGS | SIL24_NPORTS2FLAG(1),
448 .pio_mask = 0x1f, /* pio0-4 */ 448 .pio_mask = ATA_PIO4,
449 .mwdma_mask = 0x07, /* mwdma0-2 */ 449 .mwdma_mask = ATA_MWDMA2,
450 .udma_mask = ATA_UDMA5, /* udma0-5 */ 450 .udma_mask = ATA_UDMA5,
451 .port_ops = &sil24_ops, 451 .port_ops = &sil24_ops,
452 }, 452 },
453}; 453};
diff --git a/drivers/ata/sata_sis.c b/drivers/ata/sata_sis.c
index 9c43b4e7c4a6..8f9833228619 100644
--- a/drivers/ata/sata_sis.c
+++ b/drivers/ata/sata_sis.c
@@ -97,8 +97,8 @@ static struct ata_port_operations sis_ops = {
97 97
98static const struct ata_port_info sis_port_info = { 98static const struct ata_port_info sis_port_info = {
99 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, 99 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
100 .pio_mask = 0x1f, 100 .pio_mask = ATA_PIO4,
101 .mwdma_mask = 0x7, 101 .mwdma_mask = ATA_MWDMA2,
102 .udma_mask = ATA_UDMA6, 102 .udma_mask = ATA_UDMA6,
103 .port_ops = &sis_ops, 103 .port_ops = &sis_ops,
104}; 104};
diff --git a/drivers/ata/sata_svw.c b/drivers/ata/sata_svw.c
index 609d147813ae..7257f2d5c52c 100644
--- a/drivers/ata/sata_svw.c
+++ b/drivers/ata/sata_svw.c
@@ -361,8 +361,8 @@ static const struct ata_port_info k2_port_info[] = {
361 { 361 {
362 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 362 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
363 ATA_FLAG_MMIO | K2_FLAG_NO_ATAPI_DMA, 363 ATA_FLAG_MMIO | K2_FLAG_NO_ATAPI_DMA,
364 .pio_mask = 0x1f, 364 .pio_mask = ATA_PIO4,
365 .mwdma_mask = 0x07, 365 .mwdma_mask = ATA_MWDMA2,
366 .udma_mask = ATA_UDMA6, 366 .udma_mask = ATA_UDMA6,
367 .port_ops = &k2_sata_ops, 367 .port_ops = &k2_sata_ops,
368 }, 368 },
@@ -371,8 +371,8 @@ static const struct ata_port_info k2_port_info[] = {
371 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 371 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
372 ATA_FLAG_MMIO | K2_FLAG_NO_ATAPI_DMA | 372 ATA_FLAG_MMIO | K2_FLAG_NO_ATAPI_DMA |
373 K2_FLAG_SATA_8_PORTS, 373 K2_FLAG_SATA_8_PORTS,
374 .pio_mask = 0x1f, 374 .pio_mask = ATA_PIO4,
375 .mwdma_mask = 0x07, 375 .mwdma_mask = ATA_MWDMA2,
376 .udma_mask = ATA_UDMA6, 376 .udma_mask = ATA_UDMA6,
377 .port_ops = &k2_sata_ops, 377 .port_ops = &k2_sata_ops,
378 }, 378 },
@@ -380,8 +380,8 @@ static const struct ata_port_info k2_port_info[] = {
380 { 380 {
381 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 381 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
382 ATA_FLAG_MMIO | K2_FLAG_BAR_POS_3, 382 ATA_FLAG_MMIO | K2_FLAG_BAR_POS_3,
383 .pio_mask = 0x1f, 383 .pio_mask = ATA_PIO4,
384 .mwdma_mask = 0x07, 384 .mwdma_mask = ATA_MWDMA2,
385 .udma_mask = ATA_UDMA6, 385 .udma_mask = ATA_UDMA6,
386 .port_ops = &k2_sata_ops, 386 .port_ops = &k2_sata_ops,
387 }, 387 },
@@ -389,8 +389,8 @@ static const struct ata_port_info k2_port_info[] = {
389 { 389 {
390 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 390 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
391 ATA_FLAG_MMIO, 391 ATA_FLAG_MMIO,
392 .pio_mask = 0x1f, 392 .pio_mask = ATA_PIO4,
393 .mwdma_mask = 0x07, 393 .mwdma_mask = ATA_MWDMA2,
394 .udma_mask = ATA_UDMA6, 394 .udma_mask = ATA_UDMA6,
395 .port_ops = &k2_sata_ops, 395 .port_ops = &k2_sata_ops,
396 }, 396 },
diff --git a/drivers/ata/sata_sx4.c b/drivers/ata/sata_sx4.c
index ec04b8d3c791..dce3dccced3f 100644
--- a/drivers/ata/sata_sx4.c
+++ b/drivers/ata/sata_sx4.c
@@ -265,8 +265,8 @@ static const struct ata_port_info pdc_port_info[] = {
265 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 265 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
266 ATA_FLAG_SRST | ATA_FLAG_MMIO | 266 ATA_FLAG_SRST | ATA_FLAG_MMIO |
267 ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING, 267 ATA_FLAG_NO_ATAPI | ATA_FLAG_PIO_POLLING,
268 .pio_mask = 0x1f, /* pio0-4 */ 268 .pio_mask = ATA_PIO4,
269 .mwdma_mask = 0x07, /* mwdma0-2 */ 269 .mwdma_mask = ATA_MWDMA2,
270 .udma_mask = ATA_UDMA6, 270 .udma_mask = ATA_UDMA6,
271 .port_ops = &pdc_20621_ops, 271 .port_ops = &pdc_20621_ops,
272 }, 272 },
diff --git a/drivers/ata/sata_uli.c b/drivers/ata/sata_uli.c
index 019575bb3e08..e5bff47e8aa1 100644
--- a/drivers/ata/sata_uli.c
+++ b/drivers/ata/sata_uli.c
@@ -89,7 +89,7 @@ static struct ata_port_operations uli_ops = {
89static const struct ata_port_info uli_port_info = { 89static const struct ata_port_info uli_port_info = {
90 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 90 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
91 ATA_FLAG_IGN_SIMPLEX, 91 ATA_FLAG_IGN_SIMPLEX,
92 .pio_mask = 0x1f, /* pio0-4 */ 92 .pio_mask = ATA_PIO4,
93 .udma_mask = ATA_UDMA6, 93 .udma_mask = ATA_UDMA6,
94 .port_ops = &uli_ops, 94 .port_ops = &uli_ops,
95}; 95};
diff --git a/drivers/ata/sata_via.c b/drivers/ata/sata_via.c
index 5c62da9cd491..98e8c50703b3 100644
--- a/drivers/ata/sata_via.c
+++ b/drivers/ata/sata_via.c
@@ -146,24 +146,24 @@ static struct ata_port_operations vt8251_ops = {
146 146
147static const struct ata_port_info vt6420_port_info = { 147static const struct ata_port_info vt6420_port_info = {
148 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, 148 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
149 .pio_mask = 0x1f, 149 .pio_mask = ATA_PIO4,
150 .mwdma_mask = 0x07, 150 .mwdma_mask = ATA_MWDMA2,
151 .udma_mask = ATA_UDMA6, 151 .udma_mask = ATA_UDMA6,
152 .port_ops = &vt6420_sata_ops, 152 .port_ops = &vt6420_sata_ops,
153}; 153};
154 154
155static struct ata_port_info vt6421_sport_info = { 155static struct ata_port_info vt6421_sport_info = {
156 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY, 156 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY,
157 .pio_mask = 0x1f, 157 .pio_mask = ATA_PIO4,
158 .mwdma_mask = 0x07, 158 .mwdma_mask = ATA_MWDMA2,
159 .udma_mask = ATA_UDMA6, 159 .udma_mask = ATA_UDMA6,
160 .port_ops = &vt6421_sata_ops, 160 .port_ops = &vt6421_sata_ops,
161}; 161};
162 162
163static struct ata_port_info vt6421_pport_info = { 163static struct ata_port_info vt6421_pport_info = {
164 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_LEGACY, 164 .flags = ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_LEGACY,
165 .pio_mask = 0x1f, 165 .pio_mask = ATA_PIO4,
166 .mwdma_mask = 0, 166 /* No MWDMA */
167 .udma_mask = ATA_UDMA6, 167 .udma_mask = ATA_UDMA6,
168 .port_ops = &vt6421_pata_ops, 168 .port_ops = &vt6421_pata_ops,
169}; 169};
@@ -171,8 +171,8 @@ static struct ata_port_info vt6421_pport_info = {
171static struct ata_port_info vt8251_port_info = { 171static struct ata_port_info vt8251_port_info = {
172 .flags = ATA_FLAG_SATA | ATA_FLAG_SLAVE_POSS | 172 .flags = ATA_FLAG_SATA | ATA_FLAG_SLAVE_POSS |
173 ATA_FLAG_NO_LEGACY, 173 ATA_FLAG_NO_LEGACY,
174 .pio_mask = 0x1f, 174 .pio_mask = ATA_PIO4,
175 .mwdma_mask = 0x07, 175 .mwdma_mask = ATA_MWDMA2,
176 .udma_mask = ATA_UDMA6, 176 .udma_mask = ATA_UDMA6,
177 .port_ops = &vt8251_ops, 177 .port_ops = &vt8251_ops,
178}; 178};
diff --git a/drivers/ata/sata_vsc.c b/drivers/ata/sata_vsc.c
index c57cdff9e6bd..ed70bd28fa2c 100644
--- a/drivers/ata/sata_vsc.c
+++ b/drivers/ata/sata_vsc.c
@@ -308,6 +308,9 @@ static struct scsi_host_template vsc_sata_sht = {
308 308
309static struct ata_port_operations vsc_sata_ops = { 309static struct ata_port_operations vsc_sata_ops = {
310 .inherits = &ata_bmdma_port_ops, 310 .inherits = &ata_bmdma_port_ops,
311 /* The IRQ handling is not quite standard SFF behaviour so we
312 cannot use the default lost interrupt handler */
313 .lost_interrupt = ATA_OP_NULL,
311 .sff_tf_load = vsc_sata_tf_load, 314 .sff_tf_load = vsc_sata_tf_load,
312 .sff_tf_read = vsc_sata_tf_read, 315 .sff_tf_read = vsc_sata_tf_read,
313 .freeze = vsc_freeze, 316 .freeze = vsc_freeze,
@@ -345,8 +348,8 @@ static int __devinit vsc_sata_init_one(struct pci_dev *pdev,
345 static const struct ata_port_info pi = { 348 static const struct ata_port_info pi = {
346 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY | 349 .flags = ATA_FLAG_SATA | ATA_FLAG_NO_LEGACY |
347 ATA_FLAG_MMIO, 350 ATA_FLAG_MMIO,
348 .pio_mask = 0x1f, 351 .pio_mask = ATA_PIO4,
349 .mwdma_mask = 0x07, 352 .mwdma_mask = ATA_MWDMA2,
350 .udma_mask = ATA_UDMA6, 353 .udma_mask = ATA_UDMA6,
351 .port_ops = &vsc_sata_ops, 354 .port_ops = &vsc_sata_ops,
352 }; 355 };
diff --git a/drivers/base/base.h b/drivers/base/base.h
index 9f50f1b545dc..ddc97496db4a 100644
--- a/drivers/base/base.h
+++ b/drivers/base/base.h
@@ -63,6 +63,32 @@ struct class_private {
63#define to_class(obj) \ 63#define to_class(obj) \
64 container_of(obj, struct class_private, class_subsys.kobj) 64 container_of(obj, struct class_private, class_subsys.kobj)
65 65
66/**
67 * struct device_private - structure to hold the private to the driver core portions of the device structure.
68 *
69 * @klist_children - klist containing all children of this device
70 * @knode_parent - node in sibling list
71 * @knode_driver - node in driver list
72 * @knode_bus - node in bus list
73 * @device - pointer back to the struct class that this structure is
74 * associated with.
75 *
76 * Nothing outside of the driver core should ever touch these fields.
77 */
78struct device_private {
79 struct klist klist_children;
80 struct klist_node knode_parent;
81 struct klist_node knode_driver;
82 struct klist_node knode_bus;
83 struct device *device;
84};
85#define to_device_private_parent(obj) \
86 container_of(obj, struct device_private, knode_parent)
87#define to_device_private_driver(obj) \
88 container_of(obj, struct device_private, knode_driver)
89#define to_device_private_bus(obj) \
90 container_of(obj, struct device_private, knode_bus)
91
66/* initialisation functions */ 92/* initialisation functions */
67extern int devices_init(void); 93extern int devices_init(void);
68extern int buses_init(void); 94extern int buses_init(void);
@@ -86,6 +112,11 @@ extern void bus_remove_driver(struct device_driver *drv);
86 112
87extern void driver_detach(struct device_driver *drv); 113extern void driver_detach(struct device_driver *drv);
88extern int driver_probe_device(struct device_driver *drv, struct device *dev); 114extern int driver_probe_device(struct device_driver *drv, struct device *dev);
115static inline int driver_match_device(struct device_driver *drv,
116 struct device *dev)
117{
118 return drv->bus->match && drv->bus->match(dev, drv);
119}
89 120
90extern void sysdev_shutdown(void); 121extern void sysdev_shutdown(void);
91 122
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 83f32b891fa9..dc030f1f00f1 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -198,7 +198,7 @@ static ssize_t driver_bind(struct device_driver *drv,
198 int err = -ENODEV; 198 int err = -ENODEV;
199 199
200 dev = bus_find_device_by_name(bus, NULL, buf); 200 dev = bus_find_device_by_name(bus, NULL, buf);
201 if (dev && dev->driver == NULL) { 201 if (dev && dev->driver == NULL && driver_match_device(drv, dev)) {
202 if (dev->parent) /* Needed for USB */ 202 if (dev->parent) /* Needed for USB */
203 down(&dev->parent->sem); 203 down(&dev->parent->sem);
204 down(&dev->sem); 204 down(&dev->sem);
@@ -253,7 +253,14 @@ static ssize_t store_drivers_probe(struct bus_type *bus,
253static struct device *next_device(struct klist_iter *i) 253static struct device *next_device(struct klist_iter *i)
254{ 254{
255 struct klist_node *n = klist_next(i); 255 struct klist_node *n = klist_next(i);
256 return n ? container_of(n, struct device, knode_bus) : NULL; 256 struct device *dev = NULL;
257 struct device_private *dev_prv;
258
259 if (n) {
260 dev_prv = to_device_private_bus(n);
261 dev = dev_prv->device;
262 }
263 return dev;
257} 264}
258 265
259/** 266/**
@@ -286,7 +293,7 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start,
286 return -EINVAL; 293 return -EINVAL;
287 294
288 klist_iter_init_node(&bus->p->klist_devices, &i, 295 klist_iter_init_node(&bus->p->klist_devices, &i,
289 (start ? &start->knode_bus : NULL)); 296 (start ? &start->p->knode_bus : NULL));
290 while ((dev = next_device(&i)) && !error) 297 while ((dev = next_device(&i)) && !error)
291 error = fn(dev, data); 298 error = fn(dev, data);
292 klist_iter_exit(&i); 299 klist_iter_exit(&i);
@@ -320,7 +327,7 @@ struct device *bus_find_device(struct bus_type *bus,
320 return NULL; 327 return NULL;
321 328
322 klist_iter_init_node(&bus->p->klist_devices, &i, 329 klist_iter_init_node(&bus->p->klist_devices, &i,
323 (start ? &start->knode_bus : NULL)); 330 (start ? &start->p->knode_bus : NULL));
324 while ((dev = next_device(&i))) 331 while ((dev = next_device(&i)))
325 if (match(dev, data) && get_device(dev)) 332 if (match(dev, data) && get_device(dev))
326 break; 333 break;
@@ -507,7 +514,8 @@ void bus_attach_device(struct device *dev)
507 ret = device_attach(dev); 514 ret = device_attach(dev);
508 WARN_ON(ret < 0); 515 WARN_ON(ret < 0);
509 if (ret >= 0) 516 if (ret >= 0)
510 klist_add_tail(&dev->knode_bus, &bus->p->klist_devices); 517 klist_add_tail(&dev->p->knode_bus,
518 &bus->p->klist_devices);
511 } 519 }
512} 520}
513 521
@@ -528,8 +536,8 @@ void bus_remove_device(struct device *dev)
528 sysfs_remove_link(&dev->bus->p->devices_kset->kobj, 536 sysfs_remove_link(&dev->bus->p->devices_kset->kobj,
529 dev_name(dev)); 537 dev_name(dev));
530 device_remove_attrs(dev->bus, dev); 538 device_remove_attrs(dev->bus, dev);
531 if (klist_node_attached(&dev->knode_bus)) 539 if (klist_node_attached(&dev->p->knode_bus))
532 klist_del(&dev->knode_bus); 540 klist_del(&dev->p->knode_bus);
533 541
534 pr_debug("bus: '%s': remove device %s\n", 542 pr_debug("bus: '%s': remove device %s\n",
535 dev->bus->name, dev_name(dev)); 543 dev->bus->name, dev_name(dev));
@@ -831,14 +839,16 @@ static void bus_remove_attrs(struct bus_type *bus)
831 839
832static void klist_devices_get(struct klist_node *n) 840static void klist_devices_get(struct klist_node *n)
833{ 841{
834 struct device *dev = container_of(n, struct device, knode_bus); 842 struct device_private *dev_prv = to_device_private_bus(n);
843 struct device *dev = dev_prv->device;
835 844
836 get_device(dev); 845 get_device(dev);
837} 846}
838 847
839static void klist_devices_put(struct klist_node *n) 848static void klist_devices_put(struct klist_node *n)
840{ 849{
841 struct device *dev = container_of(n, struct device, knode_bus); 850 struct device_private *dev_prv = to_device_private_bus(n);
851 struct device *dev = dev_prv->device;
842 852
843 put_device(dev); 853 put_device(dev);
844} 854}
@@ -932,6 +942,7 @@ bus_uevent_fail:
932 kset_unregister(&bus->p->subsys); 942 kset_unregister(&bus->p->subsys);
933 kfree(bus->p); 943 kfree(bus->p);
934out: 944out:
945 bus->p = NULL;
935 return retval; 946 return retval;
936} 947}
937EXPORT_SYMBOL_GPL(bus_register); 948EXPORT_SYMBOL_GPL(bus_register);
@@ -953,6 +964,7 @@ void bus_unregister(struct bus_type *bus)
953 bus_remove_file(bus, &bus_attr_uevent); 964 bus_remove_file(bus, &bus_attr_uevent);
954 kset_unregister(&bus->p->subsys); 965 kset_unregister(&bus->p->subsys);
955 kfree(bus->p); 966 kfree(bus->p);
967 bus->p = NULL;
956} 968}
957EXPORT_SYMBOL_GPL(bus_unregister); 969EXPORT_SYMBOL_GPL(bus_unregister);
958 970
@@ -993,18 +1005,20 @@ static void device_insertion_sort_klist(struct device *a, struct list_head *list
993{ 1005{
994 struct list_head *pos; 1006 struct list_head *pos;
995 struct klist_node *n; 1007 struct klist_node *n;
1008 struct device_private *dev_prv;
996 struct device *b; 1009 struct device *b;
997 1010
998 list_for_each(pos, list) { 1011 list_for_each(pos, list) {
999 n = container_of(pos, struct klist_node, n_node); 1012 n = container_of(pos, struct klist_node, n_node);
1000 b = container_of(n, struct device, knode_bus); 1013 dev_prv = to_device_private_bus(n);
1014 b = dev_prv->device;
1001 if (compare(a, b) <= 0) { 1015 if (compare(a, b) <= 0) {
1002 list_move_tail(&a->knode_bus.n_node, 1016 list_move_tail(&a->p->knode_bus.n_node,
1003 &b->knode_bus.n_node); 1017 &b->p->knode_bus.n_node);
1004 return; 1018 return;
1005 } 1019 }
1006 } 1020 }
1007 list_move_tail(&a->knode_bus.n_node, list); 1021 list_move_tail(&a->p->knode_bus.n_node, list);
1008} 1022}
1009 1023
1010void bus_sort_breadthfirst(struct bus_type *bus, 1024void bus_sort_breadthfirst(struct bus_type *bus,
@@ -1014,6 +1028,7 @@ void bus_sort_breadthfirst(struct bus_type *bus,
1014 LIST_HEAD(sorted_devices); 1028 LIST_HEAD(sorted_devices);
1015 struct list_head *pos, *tmp; 1029 struct list_head *pos, *tmp;
1016 struct klist_node *n; 1030 struct klist_node *n;
1031 struct device_private *dev_prv;
1017 struct device *dev; 1032 struct device *dev;
1018 struct klist *device_klist; 1033 struct klist *device_klist;
1019 1034
@@ -1022,7 +1037,8 @@ void bus_sort_breadthfirst(struct bus_type *bus,
1022 spin_lock(&device_klist->k_lock); 1037 spin_lock(&device_klist->k_lock);
1023 list_for_each_safe(pos, tmp, &device_klist->k_list) { 1038 list_for_each_safe(pos, tmp, &device_klist->k_list) {
1024 n = container_of(pos, struct klist_node, n_node); 1039 n = container_of(pos, struct klist_node, n_node);
1025 dev = container_of(n, struct device, knode_bus); 1040 dev_prv = to_device_private_bus(n);
1041 dev = dev_prv->device;
1026 device_insertion_sort_klist(dev, &sorted_devices, compare); 1042 device_insertion_sort_klist(dev, &sorted_devices, compare);
1027 } 1043 }
1028 list_splice(&sorted_devices, &device_klist->k_list); 1044 list_splice(&sorted_devices, &device_klist->k_list);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index f3eae630e589..e73c92d13a23 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -109,6 +109,7 @@ static struct sysfs_ops dev_sysfs_ops = {
109static void device_release(struct kobject *kobj) 109static void device_release(struct kobject *kobj)
110{ 110{
111 struct device *dev = to_dev(kobj); 111 struct device *dev = to_dev(kobj);
112 struct device_private *p = dev->p;
112 113
113 if (dev->release) 114 if (dev->release)
114 dev->release(dev); 115 dev->release(dev);
@@ -120,6 +121,7 @@ static void device_release(struct kobject *kobj)
120 WARN(1, KERN_ERR "Device '%s' does not have a release() " 121 WARN(1, KERN_ERR "Device '%s' does not have a release() "
121 "function, it is broken and must be fixed.\n", 122 "function, it is broken and must be fixed.\n",
122 dev_name(dev)); 123 dev_name(dev));
124 kfree(p);
123} 125}
124 126
125static struct kobj_type device_ktype = { 127static struct kobj_type device_ktype = {
@@ -134,8 +136,6 @@ static int dev_uevent_filter(struct kset *kset, struct kobject *kobj)
134 136
135 if (ktype == &device_ktype) { 137 if (ktype == &device_ktype) {
136 struct device *dev = to_dev(kobj); 138 struct device *dev = to_dev(kobj);
137 if (dev->uevent_suppress)
138 return 0;
139 if (dev->bus) 139 if (dev->bus)
140 return 1; 140 return 1;
141 if (dev->class) 141 if (dev->class)
@@ -507,14 +507,16 @@ EXPORT_SYMBOL_GPL(device_schedule_callback_owner);
507 507
508static void klist_children_get(struct klist_node *n) 508static void klist_children_get(struct klist_node *n)
509{ 509{
510 struct device *dev = container_of(n, struct device, knode_parent); 510 struct device_private *p = to_device_private_parent(n);
511 struct device *dev = p->device;
511 512
512 get_device(dev); 513 get_device(dev);
513} 514}
514 515
515static void klist_children_put(struct klist_node *n) 516static void klist_children_put(struct klist_node *n)
516{ 517{
517 struct device *dev = container_of(n, struct device, knode_parent); 518 struct device_private *p = to_device_private_parent(n);
519 struct device *dev = p->device;
518 520
519 put_device(dev); 521 put_device(dev);
520} 522}
@@ -538,8 +540,6 @@ void device_initialize(struct device *dev)
538{ 540{
539 dev->kobj.kset = devices_kset; 541 dev->kobj.kset = devices_kset;
540 kobject_init(&dev->kobj, &device_ktype); 542 kobject_init(&dev->kobj, &device_ktype);
541 klist_init(&dev->klist_children, klist_children_get,
542 klist_children_put);
543 INIT_LIST_HEAD(&dev->dma_pools); 543 INIT_LIST_HEAD(&dev->dma_pools);
544 init_MUTEX(&dev->sem); 544 init_MUTEX(&dev->sem);
545 spin_lock_init(&dev->devres_lock); 545 spin_lock_init(&dev->devres_lock);
@@ -777,17 +777,12 @@ static void device_remove_class_symlinks(struct device *dev)
777int dev_set_name(struct device *dev, const char *fmt, ...) 777int dev_set_name(struct device *dev, const char *fmt, ...)
778{ 778{
779 va_list vargs; 779 va_list vargs;
780 char *s; 780 int err;
781 781
782 va_start(vargs, fmt); 782 va_start(vargs, fmt);
783 vsnprintf(dev->bus_id, sizeof(dev->bus_id), fmt, vargs); 783 err = kobject_set_name_vargs(&dev->kobj, fmt, vargs);
784 va_end(vargs); 784 va_end(vargs);
785 785 return err;
786 /* ewww... some of these buggers have / in the name... */
787 while ((s = strchr(dev->bus_id, '/')))
788 *s = '!';
789
790 return 0;
791} 786}
792EXPORT_SYMBOL_GPL(dev_set_name); 787EXPORT_SYMBOL_GPL(dev_set_name);
793 788
@@ -864,12 +859,26 @@ int device_add(struct device *dev)
864 if (!dev) 859 if (!dev)
865 goto done; 860 goto done;
866 861
867 /* Temporarily support init_name if it is set. 862 dev->p = kzalloc(sizeof(*dev->p), GFP_KERNEL);
868 * It will override bus_id for now */ 863 if (!dev->p) {
869 if (dev->init_name) 864 error = -ENOMEM;
870 dev_set_name(dev, "%s", dev->init_name); 865 goto done;
866 }
867 dev->p->device = dev;
868 klist_init(&dev->p->klist_children, klist_children_get,
869 klist_children_put);
870
871 /*
872 * for statically allocated devices, which should all be converted
873 * some day, we need to initialize the name. We prevent reading back
874 * the name, and force the use of dev_name()
875 */
876 if (dev->init_name) {
877 dev_set_name(dev, dev->init_name);
878 dev->init_name = NULL;
879 }
871 880
872 if (!strlen(dev->bus_id)) 881 if (!dev_name(dev))
873 goto done; 882 goto done;
874 883
875 pr_debug("device: '%s': %s\n", dev_name(dev), __func__); 884 pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
@@ -928,7 +937,8 @@ int device_add(struct device *dev)
928 kobject_uevent(&dev->kobj, KOBJ_ADD); 937 kobject_uevent(&dev->kobj, KOBJ_ADD);
929 bus_attach_device(dev); 938 bus_attach_device(dev);
930 if (parent) 939 if (parent)
931 klist_add_tail(&dev->knode_parent, &parent->klist_children); 940 klist_add_tail(&dev->p->knode_parent,
941 &parent->p->klist_children);
932 942
933 if (dev->class) { 943 if (dev->class) {
934 mutex_lock(&dev->class->p->class_mutex); 944 mutex_lock(&dev->class->p->class_mutex);
@@ -1042,7 +1052,7 @@ void device_del(struct device *dev)
1042 device_pm_remove(dev); 1052 device_pm_remove(dev);
1043 dpm_sysfs_remove(dev); 1053 dpm_sysfs_remove(dev);
1044 if (parent) 1054 if (parent)
1045 klist_del(&dev->knode_parent); 1055 klist_del(&dev->p->knode_parent);
1046 if (MAJOR(dev->devt)) { 1056 if (MAJOR(dev->devt)) {
1047 device_remove_sys_dev_entry(dev); 1057 device_remove_sys_dev_entry(dev);
1048 device_remove_file(dev, &devt_attr); 1058 device_remove_file(dev, &devt_attr);
@@ -1103,7 +1113,14 @@ void device_unregister(struct device *dev)
1103static struct device *next_device(struct klist_iter *i) 1113static struct device *next_device(struct klist_iter *i)
1104{ 1114{
1105 struct klist_node *n = klist_next(i); 1115 struct klist_node *n = klist_next(i);
1106 return n ? container_of(n, struct device, knode_parent) : NULL; 1116 struct device *dev = NULL;
1117 struct device_private *p;
1118
1119 if (n) {
1120 p = to_device_private_parent(n);
1121 dev = p->device;
1122 }
1123 return dev;
1107} 1124}
1108 1125
1109/** 1126/**
@@ -1125,7 +1142,7 @@ int device_for_each_child(struct device *parent, void *data,
1125 struct device *child; 1142 struct device *child;
1126 int error = 0; 1143 int error = 0;
1127 1144
1128 klist_iter_init(&parent->klist_children, &i); 1145 klist_iter_init(&parent->p->klist_children, &i);
1129 while ((child = next_device(&i)) && !error) 1146 while ((child = next_device(&i)) && !error)
1130 error = fn(child, data); 1147 error = fn(child, data);
1131 klist_iter_exit(&i); 1148 klist_iter_exit(&i);
@@ -1156,7 +1173,7 @@ struct device *device_find_child(struct device *parent, void *data,
1156 if (!parent) 1173 if (!parent)
1157 return NULL; 1174 return NULL;
1158 1175
1159 klist_iter_init(&parent->klist_children, &i); 1176 klist_iter_init(&parent->p->klist_children, &i);
1160 while ((child = next_device(&i))) 1177 while ((child = next_device(&i)))
1161 if (match(child, data) && get_device(child)) 1178 if (match(child, data) && get_device(child))
1162 break; 1179 break;
@@ -1348,7 +1365,10 @@ struct device *device_create_vargs(struct class *class, struct device *parent,
1348 dev->release = device_create_release; 1365 dev->release = device_create_release;
1349 dev_set_drvdata(dev, drvdata); 1366 dev_set_drvdata(dev, drvdata);
1350 1367
1351 vsnprintf(dev->bus_id, BUS_ID_SIZE, fmt, args); 1368 retval = kobject_set_name_vargs(&dev->kobj, fmt, args);
1369 if (retval)
1370 goto error;
1371
1352 retval = device_register(dev); 1372 retval = device_register(dev);
1353 if (retval) 1373 if (retval)
1354 goto error; 1374 goto error;
@@ -1452,19 +1472,15 @@ int device_rename(struct device *dev, char *new_name)
1452 old_class_name = make_class_name(dev->class->name, &dev->kobj); 1472 old_class_name = make_class_name(dev->class->name, &dev->kobj);
1453#endif 1473#endif
1454 1474
1455 old_device_name = kmalloc(BUS_ID_SIZE, GFP_KERNEL); 1475 old_device_name = kstrdup(dev_name(dev), GFP_KERNEL);
1456 if (!old_device_name) { 1476 if (!old_device_name) {
1457 error = -ENOMEM; 1477 error = -ENOMEM;
1458 goto out; 1478 goto out;
1459 } 1479 }
1460 strlcpy(old_device_name, dev->bus_id, BUS_ID_SIZE);
1461 strlcpy(dev->bus_id, new_name, BUS_ID_SIZE);
1462 1480
1463 error = kobject_rename(&dev->kobj, new_name); 1481 error = kobject_rename(&dev->kobj, new_name);
1464 if (error) { 1482 if (error)
1465 strlcpy(dev->bus_id, old_device_name, BUS_ID_SIZE);
1466 goto out; 1483 goto out;
1467 }
1468 1484
1469#ifdef CONFIG_SYSFS_DEPRECATED 1485#ifdef CONFIG_SYSFS_DEPRECATED
1470 if (old_class_name) { 1486 if (old_class_name) {
@@ -1545,8 +1561,10 @@ out:
1545 * device_move - moves a device to a new parent 1561 * device_move - moves a device to a new parent
1546 * @dev: the pointer to the struct device to be moved 1562 * @dev: the pointer to the struct device to be moved
1547 * @new_parent: the new parent of the device (can by NULL) 1563 * @new_parent: the new parent of the device (can by NULL)
1564 * @dpm_order: how to reorder the dpm_list
1548 */ 1565 */
1549int device_move(struct device *dev, struct device *new_parent) 1566int device_move(struct device *dev, struct device *new_parent,
1567 enum dpm_order dpm_order)
1550{ 1568{
1551 int error; 1569 int error;
1552 struct device *old_parent; 1570 struct device *old_parent;
@@ -1556,6 +1574,7 @@ int device_move(struct device *dev, struct device *new_parent)
1556 if (!dev) 1574 if (!dev)
1557 return -EINVAL; 1575 return -EINVAL;
1558 1576
1577 device_pm_lock();
1559 new_parent = get_device(new_parent); 1578 new_parent = get_device(new_parent);
1560 new_parent_kobj = get_device_parent(dev, new_parent); 1579 new_parent_kobj = get_device_parent(dev, new_parent);
1561 1580
@@ -1570,9 +1589,10 @@ int device_move(struct device *dev, struct device *new_parent)
1570 old_parent = dev->parent; 1589 old_parent = dev->parent;
1571 dev->parent = new_parent; 1590 dev->parent = new_parent;
1572 if (old_parent) 1591 if (old_parent)
1573 klist_remove(&dev->knode_parent); 1592 klist_remove(&dev->p->knode_parent);
1574 if (new_parent) { 1593 if (new_parent) {
1575 klist_add_tail(&dev->knode_parent, &new_parent->klist_children); 1594 klist_add_tail(&dev->p->knode_parent,
1595 &new_parent->p->klist_children);
1576 set_dev_node(dev, dev_to_node(new_parent)); 1596 set_dev_node(dev, dev_to_node(new_parent));
1577 } 1597 }
1578 1598
@@ -1584,11 +1604,11 @@ int device_move(struct device *dev, struct device *new_parent)
1584 device_move_class_links(dev, new_parent, old_parent); 1604 device_move_class_links(dev, new_parent, old_parent);
1585 if (!kobject_move(&dev->kobj, &old_parent->kobj)) { 1605 if (!kobject_move(&dev->kobj, &old_parent->kobj)) {
1586 if (new_parent) 1606 if (new_parent)
1587 klist_remove(&dev->knode_parent); 1607 klist_remove(&dev->p->knode_parent);
1588 dev->parent = old_parent; 1608 dev->parent = old_parent;
1589 if (old_parent) { 1609 if (old_parent) {
1590 klist_add_tail(&dev->knode_parent, 1610 klist_add_tail(&dev->p->knode_parent,
1591 &old_parent->klist_children); 1611 &old_parent->p->klist_children);
1592 set_dev_node(dev, dev_to_node(old_parent)); 1612 set_dev_node(dev, dev_to_node(old_parent));
1593 } 1613 }
1594 } 1614 }
@@ -1596,9 +1616,23 @@ int device_move(struct device *dev, struct device *new_parent)
1596 put_device(new_parent); 1616 put_device(new_parent);
1597 goto out; 1617 goto out;
1598 } 1618 }
1619 switch (dpm_order) {
1620 case DPM_ORDER_NONE:
1621 break;
1622 case DPM_ORDER_DEV_AFTER_PARENT:
1623 device_pm_move_after(dev, new_parent);
1624 break;
1625 case DPM_ORDER_PARENT_BEFORE_DEV:
1626 device_pm_move_before(new_parent, dev);
1627 break;
1628 case DPM_ORDER_DEV_LAST:
1629 device_pm_move_last(dev);
1630 break;
1631 }
1599out_put: 1632out_put:
1600 put_device(old_parent); 1633 put_device(old_parent);
1601out: 1634out:
1635 device_pm_unlock();
1602 put_device(dev); 1636 put_device(dev);
1603 return error; 1637 return error;
1604} 1638}
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 135231239103..f17c3266a0e0 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -30,7 +30,7 @@
30 30
31static void driver_bound(struct device *dev) 31static void driver_bound(struct device *dev)
32{ 32{
33 if (klist_node_attached(&dev->knode_driver)) { 33 if (klist_node_attached(&dev->p->knode_driver)) {
34 printk(KERN_WARNING "%s: device %s already bound\n", 34 printk(KERN_WARNING "%s: device %s already bound\n",
35 __func__, kobject_name(&dev->kobj)); 35 __func__, kobject_name(&dev->kobj));
36 return; 36 return;
@@ -43,7 +43,7 @@ static void driver_bound(struct device *dev)
43 blocking_notifier_call_chain(&dev->bus->p->bus_notifier, 43 blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
44 BUS_NOTIFY_BOUND_DRIVER, dev); 44 BUS_NOTIFY_BOUND_DRIVER, dev);
45 45
46 klist_add_tail(&dev->knode_driver, &dev->driver->p->klist_devices); 46 klist_add_tail(&dev->p->knode_driver, &dev->driver->p->klist_devices);
47} 47}
48 48
49static int driver_sysfs_add(struct device *dev) 49static int driver_sysfs_add(struct device *dev)
@@ -172,16 +172,12 @@ int driver_probe_done(void)
172/** 172/**
173 * wait_for_device_probe 173 * wait_for_device_probe
174 * Wait for device probing to be completed. 174 * Wait for device probing to be completed.
175 *
176 * Note: this function polls at 100 msec intervals.
177 */ 175 */
178int wait_for_device_probe(void) 176void wait_for_device_probe(void)
179{ 177{
180 /* wait for the known devices to complete their probing */ 178 /* wait for the known devices to complete their probing */
181 while (driver_probe_done() != 0) 179 wait_event(probe_waitqueue, atomic_read(&probe_count) == 0);
182 msleep(100);
183 async_synchronize_full(); 180 async_synchronize_full();
184 return 0;
185} 181}
186 182
187/** 183/**
@@ -189,14 +185,8 @@ int wait_for_device_probe(void)
189 * @drv: driver to bind a device to 185 * @drv: driver to bind a device to
190 * @dev: device to try to bind to the driver 186 * @dev: device to try to bind to the driver
191 * 187 *
192 * First, we call the bus's match function, if one present, which should 188 * This function returns -ENODEV if the device is not registered,
193 * compare the device IDs the driver supports with the device IDs of the 189 * 1 if the device is bound sucessfully and 0 otherwise.
194 * device. Note we don't do this ourselves because we don't know the
195 * format of the ID structures, nor what is to be considered a match and
196 * what is not.
197 *
198 * This function returns 1 if a match is found, -ENODEV if the device is
199 * not registered, and 0 otherwise.
200 * 190 *
201 * This function must be called with @dev->sem held. When called for a 191 * This function must be called with @dev->sem held. When called for a
202 * USB interface, @dev->parent->sem must be held as well. 192 * USB interface, @dev->parent->sem must be held as well.
@@ -207,21 +197,22 @@ int driver_probe_device(struct device_driver *drv, struct device *dev)
207 197
208 if (!device_is_registered(dev)) 198 if (!device_is_registered(dev))
209 return -ENODEV; 199 return -ENODEV;
210 if (drv->bus->match && !drv->bus->match(dev, drv))
211 goto done;
212 200
213 pr_debug("bus: '%s': %s: matched device %s with driver %s\n", 201 pr_debug("bus: '%s': %s: matched device %s with driver %s\n",
214 drv->bus->name, __func__, dev_name(dev), drv->name); 202 drv->bus->name, __func__, dev_name(dev), drv->name);
215 203
216 ret = really_probe(dev, drv); 204 ret = really_probe(dev, drv);
217 205
218done:
219 return ret; 206 return ret;
220} 207}
221 208
222static int __device_attach(struct device_driver *drv, void *data) 209static int __device_attach(struct device_driver *drv, void *data)
223{ 210{
224 struct device *dev = data; 211 struct device *dev = data;
212
213 if (!driver_match_device(drv, dev))
214 return 0;
215
225 return driver_probe_device(drv, dev); 216 return driver_probe_device(drv, dev);
226} 217}
227 218
@@ -274,7 +265,7 @@ static int __driver_attach(struct device *dev, void *data)
274 * is an error. 265 * is an error.
275 */ 266 */
276 267
277 if (drv->bus->match && !drv->bus->match(dev, drv)) 268 if (!driver_match_device(drv, dev))
278 return 0; 269 return 0;
279 270
280 if (dev->parent) /* Needed for USB */ 271 if (dev->parent) /* Needed for USB */
@@ -327,7 +318,7 @@ static void __device_release_driver(struct device *dev)
327 drv->remove(dev); 318 drv->remove(dev);
328 devres_release_all(dev); 319 devres_release_all(dev);
329 dev->driver = NULL; 320 dev->driver = NULL;
330 klist_remove(&dev->knode_driver); 321 klist_remove(&dev->p->knode_driver);
331 } 322 }
332} 323}
333 324
@@ -357,6 +348,7 @@ EXPORT_SYMBOL_GPL(device_release_driver);
357 */ 348 */
358void driver_detach(struct device_driver *drv) 349void driver_detach(struct device_driver *drv)
359{ 350{
351 struct device_private *dev_prv;
360 struct device *dev; 352 struct device *dev;
361 353
362 for (;;) { 354 for (;;) {
@@ -365,8 +357,10 @@ void driver_detach(struct device_driver *drv)
365 spin_unlock(&drv->p->klist_devices.k_lock); 357 spin_unlock(&drv->p->klist_devices.k_lock);
366 break; 358 break;
367 } 359 }
368 dev = list_entry(drv->p->klist_devices.k_list.prev, 360 dev_prv = list_entry(drv->p->klist_devices.k_list.prev,
369 struct device, knode_driver.n_node); 361 struct device_private,
362 knode_driver.n_node);
363 dev = dev_prv->device;
370 get_device(dev); 364 get_device(dev);
371 spin_unlock(&drv->p->klist_devices.k_lock); 365 spin_unlock(&drv->p->klist_devices.k_lock);
372 366
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 1e2bda780e48..c51f11bb29ae 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -19,7 +19,14 @@
19static struct device *next_device(struct klist_iter *i) 19static struct device *next_device(struct klist_iter *i)
20{ 20{
21 struct klist_node *n = klist_next(i); 21 struct klist_node *n = klist_next(i);
22 return n ? container_of(n, struct device, knode_driver) : NULL; 22 struct device *dev = NULL;
23 struct device_private *dev_prv;
24
25 if (n) {
26 dev_prv = to_device_private_driver(n);
27 dev = dev_prv->device;
28 }
29 return dev;
23} 30}
24 31
25/** 32/**
@@ -42,7 +49,7 @@ int driver_for_each_device(struct device_driver *drv, struct device *start,
42 return -EINVAL; 49 return -EINVAL;
43 50
44 klist_iter_init_node(&drv->p->klist_devices, &i, 51 klist_iter_init_node(&drv->p->klist_devices, &i,
45 start ? &start->knode_driver : NULL); 52 start ? &start->p->knode_driver : NULL);
46 while ((dev = next_device(&i)) && !error) 53 while ((dev = next_device(&i)) && !error)
47 error = fn(dev, data); 54 error = fn(dev, data);
48 klist_iter_exit(&i); 55 klist_iter_exit(&i);
@@ -76,7 +83,7 @@ struct device *driver_find_device(struct device_driver *drv,
76 return NULL; 83 return NULL;
77 84
78 klist_iter_init_node(&drv->p->klist_devices, &i, 85 klist_iter_init_node(&drv->p->klist_devices, &i,
79 (start ? &start->knode_driver : NULL)); 86 (start ? &start->p->knode_driver : NULL));
80 while ((dev = next_device(&i))) 87 while ((dev = next_device(&i)))
81 if (match(dev, data) && get_device(dev)) 88 if (match(dev, data) && get_device(dev))
82 break; 89 break;
@@ -216,6 +223,8 @@ int driver_register(struct device_driver *drv)
216 int ret; 223 int ret;
217 struct device_driver *other; 224 struct device_driver *other;
218 225
226 BUG_ON(!drv->bus->p);
227
219 if ((drv->bus->probe && drv->probe) || 228 if ((drv->bus->probe && drv->probe) ||
220 (drv->bus->remove && drv->remove) || 229 (drv->bus->remove && drv->remove) ||
221 (drv->bus->shutdown && drv->shutdown)) 230 (drv->bus->shutdown && drv->shutdown))
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 44699d9dd85c..d3a59c688fe4 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -319,7 +319,7 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
319 f_dev->parent = device; 319 f_dev->parent = device;
320 f_dev->class = &firmware_class; 320 f_dev->class = &firmware_class;
321 dev_set_drvdata(f_dev, fw_priv); 321 dev_set_drvdata(f_dev, fw_priv);
322 f_dev->uevent_suppress = 1; 322 dev_set_uevent_suppress(f_dev, 1);
323 retval = device_register(f_dev); 323 retval = device_register(f_dev);
324 if (retval) { 324 if (retval) {
325 dev_err(device, "%s: device_register failed\n", __func__); 325 dev_err(device, "%s: device_register failed\n", __func__);
@@ -366,7 +366,7 @@ static int fw_setup_device(struct firmware *fw, struct device **dev_p,
366 } 366 }
367 367
368 if (uevent) 368 if (uevent)
369 f_dev->uevent_suppress = 0; 369 dev_set_uevent_suppress(f_dev, 0);
370 *dev_p = f_dev; 370 *dev_p = f_dev;
371 goto out; 371 goto out;
372 372
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 349a1013603f..d2198f64ad4e 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -217,6 +217,7 @@ int platform_device_add_data(struct platform_device *pdev, const void *data,
217 if (d) { 217 if (d) {
218 memcpy(d, data, size); 218 memcpy(d, data, size);
219 pdev->dev.platform_data = d; 219 pdev->dev.platform_data = d;
220 pdev->platform_data = d;
220 } 221 }
221 return d ? 0 : -ENOMEM; 222 return d ? 0 : -ENOMEM;
222} 223}
@@ -246,6 +247,21 @@ int platform_device_add(struct platform_device *pdev)
246 else 247 else
247 dev_set_name(&pdev->dev, pdev->name); 248 dev_set_name(&pdev->dev, pdev->name);
248 249
250 /* We will remove platform_data field from struct device
251 * if all platform devices pass its platform specific data
252 * from platform_device. The conversion is going to be a
253 * long time, so we allow the two cases coexist to make
254 * this kind of fix more easily*/
255 if (pdev->platform_data && pdev->dev.platform_data) {
256 printk(KERN_ERR
257 "%s: use which platform_data?\n",
258 dev_name(&pdev->dev));
259 } else if (pdev->platform_data) {
260 pdev->dev.platform_data = pdev->platform_data;
261 } else if (pdev->dev.platform_data) {
262 pdev->platform_data = pdev->dev.platform_data;
263 }
264
249 for (i = 0; i < pdev->num_resources; i++) { 265 for (i = 0; i < pdev->num_resources; i++) {
250 struct resource *p, *r = &pdev->resource[i]; 266 struct resource *p, *r = &pdev->resource[i];
251 267
@@ -584,10 +600,25 @@ static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
584{ 600{
585 struct platform_device *pdev = to_platform_device(dev); 601 struct platform_device *pdev = to_platform_device(dev);
586 602
587 add_uevent_var(env, "MODALIAS=platform:%s", pdev->name); 603 add_uevent_var(env, "MODALIAS=%s%s", PLATFORM_MODULE_PREFIX,
604 (pdev->id_entry) ? pdev->id_entry->name : pdev->name);
588 return 0; 605 return 0;
589} 606}
590 607
608static const struct platform_device_id *platform_match_id(
609 struct platform_device_id *id,
610 struct platform_device *pdev)
611{
612 while (id->name[0]) {
613 if (strcmp(pdev->name, id->name) == 0) {
614 pdev->id_entry = id;
615 return id;
616 }
617 id++;
618 }
619 return NULL;
620}
621
591/** 622/**
592 * platform_match - bind platform device to platform driver. 623 * platform_match - bind platform device to platform driver.
593 * @dev: device. 624 * @dev: device.
@@ -603,9 +634,14 @@ static int platform_uevent(struct device *dev, struct kobj_uevent_env *env)
603 */ 634 */
604static int platform_match(struct device *dev, struct device_driver *drv) 635static int platform_match(struct device *dev, struct device_driver *drv)
605{ 636{
606 struct platform_device *pdev; 637 struct platform_device *pdev = to_platform_device(dev);
638 struct platform_driver *pdrv = to_platform_driver(drv);
607 639
608 pdev = container_of(dev, struct platform_device, dev); 640 /* match against the id table first */
641 if (pdrv->id_table)
642 return platform_match_id(pdrv->id_table, pdev) != NULL;
643
644 /* fall-back to driver name match */
609 return (strcmp(pdev->name, drv->name) == 0); 645 return (strcmp(pdev->name, drv->name) == 0);
610} 646}
611 647
@@ -623,26 +659,24 @@ static int platform_legacy_suspend(struct device *dev, pm_message_t mesg)
623 659
624static int platform_legacy_suspend_late(struct device *dev, pm_message_t mesg) 660static int platform_legacy_suspend_late(struct device *dev, pm_message_t mesg)
625{ 661{
626 struct platform_driver *drv = to_platform_driver(dev->driver); 662 struct platform_driver *pdrv = to_platform_driver(dev->driver);
627 struct platform_device *pdev; 663 struct platform_device *pdev = to_platform_device(dev);
628 int ret = 0; 664 int ret = 0;
629 665
630 pdev = container_of(dev, struct platform_device, dev); 666 if (dev->driver && pdrv->suspend_late)
631 if (dev->driver && drv->suspend_late) 667 ret = pdrv->suspend_late(pdev, mesg);
632 ret = drv->suspend_late(pdev, mesg);
633 668
634 return ret; 669 return ret;
635} 670}
636 671
637static int platform_legacy_resume_early(struct device *dev) 672static int platform_legacy_resume_early(struct device *dev)
638{ 673{
639 struct platform_driver *drv = to_platform_driver(dev->driver); 674 struct platform_driver *pdrv = to_platform_driver(dev->driver);
640 struct platform_device *pdev; 675 struct platform_device *pdev = to_platform_device(dev);
641 int ret = 0; 676 int ret = 0;
642 677
643 pdev = container_of(dev, struct platform_device, dev); 678 if (dev->driver && pdrv->resume_early)
644 if (dev->driver && drv->resume_early) 679 ret = pdrv->resume_early(pdev);
645 ret = drv->resume_early(pdev);
646 680
647 return ret; 681 return ret;
648} 682}
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 2d14f4ae6c01..e255341682c8 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -107,6 +107,50 @@ void device_pm_remove(struct device *dev)
107} 107}
108 108
109/** 109/**
110 * device_pm_move_before - move device in dpm_list
111 * @deva: Device to move in dpm_list
112 * @devb: Device @deva should come before
113 */
114void device_pm_move_before(struct device *deva, struct device *devb)
115{
116 pr_debug("PM: Moving %s:%s before %s:%s\n",
117 deva->bus ? deva->bus->name : "No Bus",
118 kobject_name(&deva->kobj),
119 devb->bus ? devb->bus->name : "No Bus",
120 kobject_name(&devb->kobj));
121 /* Delete deva from dpm_list and reinsert before devb. */
122 list_move_tail(&deva->power.entry, &devb->power.entry);
123}
124
125/**
126 * device_pm_move_after - move device in dpm_list
127 * @deva: Device to move in dpm_list
128 * @devb: Device @deva should come after
129 */
130void device_pm_move_after(struct device *deva, struct device *devb)
131{
132 pr_debug("PM: Moving %s:%s after %s:%s\n",
133 deva->bus ? deva->bus->name : "No Bus",
134 kobject_name(&deva->kobj),
135 devb->bus ? devb->bus->name : "No Bus",
136 kobject_name(&devb->kobj));
137 /* Delete deva from dpm_list and reinsert after devb. */
138 list_move(&deva->power.entry, &devb->power.entry);
139}
140
141/**
142 * device_pm_move_last - move device to end of dpm_list
143 * @dev: Device to move in dpm_list
144 */
145void device_pm_move_last(struct device *dev)
146{
147 pr_debug("PM: Moving %s:%s to end of list\n",
148 dev->bus ? dev->bus->name : "No Bus",
149 kobject_name(&dev->kobj));
150 list_move_tail(&dev->power.entry, &dpm_list);
151}
152
153/**
110 * pm_op - execute the PM operation appropiate for given PM event 154 * pm_op - execute the PM operation appropiate for given PM event
111 * @dev: Device. 155 * @dev: Device.
112 * @ops: PM operations to choose from. 156 * @ops: PM operations to choose from.
diff --git a/drivers/base/power/power.h b/drivers/base/power/power.h
index 41f51fae042f..c7cb4fc3735c 100644
--- a/drivers/base/power/power.h
+++ b/drivers/base/power/power.h
@@ -18,11 +18,19 @@ static inline struct device *to_device(struct list_head *entry)
18 18
19extern void device_pm_add(struct device *); 19extern void device_pm_add(struct device *);
20extern void device_pm_remove(struct device *); 20extern void device_pm_remove(struct device *);
21extern void device_pm_move_before(struct device *, struct device *);
22extern void device_pm_move_after(struct device *, struct device *);
23extern void device_pm_move_last(struct device *);
21 24
22#else /* CONFIG_PM_SLEEP */ 25#else /* CONFIG_PM_SLEEP */
23 26
24static inline void device_pm_add(struct device *dev) {} 27static inline void device_pm_add(struct device *dev) {}
25static inline void device_pm_remove(struct device *dev) {} 28static inline void device_pm_remove(struct device *dev) {}
29static inline void device_pm_move_before(struct device *deva,
30 struct device *devb) {}
31static inline void device_pm_move_after(struct device *deva,
32 struct device *devb) {}
33static inline void device_pm_move_last(struct device *dev) {}
26 34
27#endif 35#endif
28 36
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index b428c8c4bc64..cbd36cf59a0f 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -30,10 +30,10 @@
30 30
31 31
32static ssize_t 32static ssize_t
33sysdev_show(struct kobject * kobj, struct attribute * attr, char * buffer) 33sysdev_show(struct kobject *kobj, struct attribute *attr, char *buffer)
34{ 34{
35 struct sys_device * sysdev = to_sysdev(kobj); 35 struct sys_device *sysdev = to_sysdev(kobj);
36 struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr); 36 struct sysdev_attribute *sysdev_attr = to_sysdev_attr(attr);
37 37
38 if (sysdev_attr->show) 38 if (sysdev_attr->show)
39 return sysdev_attr->show(sysdev, sysdev_attr, buffer); 39 return sysdev_attr->show(sysdev, sysdev_attr, buffer);
@@ -42,11 +42,11 @@ sysdev_show(struct kobject * kobj, struct attribute * attr, char * buffer)
42 42
43 43
44static ssize_t 44static ssize_t
45sysdev_store(struct kobject * kobj, struct attribute * attr, 45sysdev_store(struct kobject *kobj, struct attribute *attr,
46 const char * buffer, size_t count) 46 const char *buffer, size_t count)
47{ 47{
48 struct sys_device * sysdev = to_sysdev(kobj); 48 struct sys_device *sysdev = to_sysdev(kobj);
49 struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr); 49 struct sysdev_attribute *sysdev_attr = to_sysdev_attr(attr);
50 50
51 if (sysdev_attr->store) 51 if (sysdev_attr->store)
52 return sysdev_attr->store(sysdev, sysdev_attr, buffer, count); 52 return sysdev_attr->store(sysdev, sysdev_attr, buffer, count);
@@ -63,13 +63,13 @@ static struct kobj_type ktype_sysdev = {
63}; 63};
64 64
65 65
66int sysdev_create_file(struct sys_device * s, struct sysdev_attribute * a) 66int sysdev_create_file(struct sys_device *s, struct sysdev_attribute *a)
67{ 67{
68 return sysfs_create_file(&s->kobj, &a->attr); 68 return sysfs_create_file(&s->kobj, &a->attr);
69} 69}
70 70
71 71
72void sysdev_remove_file(struct sys_device * s, struct sysdev_attribute * a) 72void sysdev_remove_file(struct sys_device *s, struct sysdev_attribute *a)
73{ 73{
74 sysfs_remove_file(&s->kobj, &a->attr); 74 sysfs_remove_file(&s->kobj, &a->attr);
75} 75}
@@ -84,7 +84,7 @@ EXPORT_SYMBOL_GPL(sysdev_remove_file);
84static ssize_t sysdev_class_show(struct kobject *kobj, struct attribute *attr, 84static ssize_t sysdev_class_show(struct kobject *kobj, struct attribute *attr,
85 char *buffer) 85 char *buffer)
86{ 86{
87 struct sysdev_class * class = to_sysdev_class(kobj); 87 struct sysdev_class *class = to_sysdev_class(kobj);
88 struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr); 88 struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr);
89 89
90 if (class_attr->show) 90 if (class_attr->show)
@@ -95,8 +95,8 @@ static ssize_t sysdev_class_show(struct kobject *kobj, struct attribute *attr,
95static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr, 95static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr,
96 const char *buffer, size_t count) 96 const char *buffer, size_t count)
97{ 97{
98 struct sysdev_class * class = to_sysdev_class(kobj); 98 struct sysdev_class *class = to_sysdev_class(kobj);
99 struct sysdev_class_attribute * class_attr = to_sysdev_class_attr(attr); 99 struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr);
100 100
101 if (class_attr->store) 101 if (class_attr->store)
102 return class_attr->store(class, buffer, count); 102 return class_attr->store(class, buffer, count);
@@ -128,7 +128,7 @@ EXPORT_SYMBOL_GPL(sysdev_class_remove_file);
128 128
129static struct kset *system_kset; 129static struct kset *system_kset;
130 130
131int sysdev_class_register(struct sysdev_class * cls) 131int sysdev_class_register(struct sysdev_class *cls)
132{ 132{
133 pr_debug("Registering sysdev class '%s'\n", cls->name); 133 pr_debug("Registering sysdev class '%s'\n", cls->name);
134 134
@@ -141,7 +141,7 @@ int sysdev_class_register(struct sysdev_class * cls)
141 return kset_register(&cls->kset); 141 return kset_register(&cls->kset);
142} 142}
143 143
144void sysdev_class_unregister(struct sysdev_class * cls) 144void sysdev_class_unregister(struct sysdev_class *cls)
145{ 145{
146 pr_debug("Unregistering sysdev class '%s'\n", 146 pr_debug("Unregistering sysdev class '%s'\n",
147 kobject_name(&cls->kset.kobj)); 147 kobject_name(&cls->kset.kobj));
@@ -203,8 +203,8 @@ int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv)
203 * @cls: Class driver belongs to. 203 * @cls: Class driver belongs to.
204 * @drv: Driver. 204 * @drv: Driver.
205 */ 205 */
206void sysdev_driver_unregister(struct sysdev_class * cls, 206void sysdev_driver_unregister(struct sysdev_class *cls,
207 struct sysdev_driver * drv) 207 struct sysdev_driver *drv)
208{ 208{
209 mutex_lock(&sysdev_drivers_lock); 209 mutex_lock(&sysdev_drivers_lock);
210 list_del_init(&drv->entry); 210 list_del_init(&drv->entry);
@@ -229,10 +229,10 @@ EXPORT_SYMBOL_GPL(sysdev_driver_unregister);
229 * @sysdev: device in question 229 * @sysdev: device in question
230 * 230 *
231 */ 231 */
232int sysdev_register(struct sys_device * sysdev) 232int sysdev_register(struct sys_device *sysdev)
233{ 233{
234 int error; 234 int error;
235 struct sysdev_class * cls = sysdev->cls; 235 struct sysdev_class *cls = sysdev->cls;
236 236
237 if (!cls) 237 if (!cls)
238 return -EINVAL; 238 return -EINVAL;
@@ -252,7 +252,7 @@ int sysdev_register(struct sys_device * sysdev)
252 sysdev->id); 252 sysdev->id);
253 253
254 if (!error) { 254 if (!error) {
255 struct sysdev_driver * drv; 255 struct sysdev_driver *drv;
256 256
257 pr_debug("Registering sys device '%s'\n", 257 pr_debug("Registering sys device '%s'\n",
258 kobject_name(&sysdev->kobj)); 258 kobject_name(&sysdev->kobj));
@@ -274,9 +274,9 @@ int sysdev_register(struct sys_device * sysdev)
274 return error; 274 return error;
275} 275}
276 276
277void sysdev_unregister(struct sys_device * sysdev) 277void sysdev_unregister(struct sys_device *sysdev)
278{ 278{
279 struct sysdev_driver * drv; 279 struct sysdev_driver *drv;
280 280
281 mutex_lock(&sysdev_drivers_lock); 281 mutex_lock(&sysdev_drivers_lock);
282 list_for_each_entry(drv, &sysdev->cls->drivers, entry) { 282 list_for_each_entry(drv, &sysdev->cls->drivers, entry) {
@@ -305,19 +305,19 @@ void sysdev_unregister(struct sys_device * sysdev)
305 */ 305 */
306void sysdev_shutdown(void) 306void sysdev_shutdown(void)
307{ 307{
308 struct sysdev_class * cls; 308 struct sysdev_class *cls;
309 309
310 pr_debug("Shutting Down System Devices\n"); 310 pr_debug("Shutting Down System Devices\n");
311 311
312 mutex_lock(&sysdev_drivers_lock); 312 mutex_lock(&sysdev_drivers_lock);
313 list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) { 313 list_for_each_entry_reverse(cls, &system_kset->list, kset.kobj.entry) {
314 struct sys_device * sysdev; 314 struct sys_device *sysdev;
315 315
316 pr_debug("Shutting down type '%s':\n", 316 pr_debug("Shutting down type '%s':\n",
317 kobject_name(&cls->kset.kobj)); 317 kobject_name(&cls->kset.kobj));
318 318
319 list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) { 319 list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) {
320 struct sysdev_driver * drv; 320 struct sysdev_driver *drv;
321 pr_debug(" %s\n", kobject_name(&sysdev->kobj)); 321 pr_debug(" %s\n", kobject_name(&sysdev->kobj));
322 322
323 /* Call auxillary drivers first */ 323 /* Call auxillary drivers first */
@@ -364,7 +364,7 @@ static void __sysdev_resume(struct sys_device *dev)
364 */ 364 */
365int sysdev_suspend(pm_message_t state) 365int sysdev_suspend(pm_message_t state)
366{ 366{
367 struct sysdev_class * cls; 367 struct sysdev_class *cls;
368 struct sys_device *sysdev, *err_dev; 368 struct sys_device *sysdev, *err_dev;
369 struct sysdev_driver *drv, *err_drv; 369 struct sysdev_driver *drv, *err_drv;
370 int ret; 370 int ret;
@@ -442,12 +442,12 @@ EXPORT_SYMBOL_GPL(sysdev_suspend);
442 */ 442 */
443int sysdev_resume(void) 443int sysdev_resume(void)
444{ 444{
445 struct sysdev_class * cls; 445 struct sysdev_class *cls;
446 446
447 pr_debug("Resuming System Devices\n"); 447 pr_debug("Resuming System Devices\n");
448 448
449 list_for_each_entry(cls, &system_kset->list, kset.kobj.entry) { 449 list_for_each_entry(cls, &system_kset->list, kset.kobj.entry) {
450 struct sys_device * sysdev; 450 struct sys_device *sysdev;
451 451
452 pr_debug("Resuming type '%s':\n", 452 pr_debug("Resuming type '%s':\n",
453 kobject_name(&cls->kset.kobj)); 453 kobject_name(&cls->kset.kobj));
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 83d8ed39433d..c2c95e614506 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -4135,10 +4135,9 @@ static int have_no_fdc = -ENODEV;
4135static ssize_t floppy_cmos_show(struct device *dev, 4135static ssize_t floppy_cmos_show(struct device *dev,
4136 struct device_attribute *attr, char *buf) 4136 struct device_attribute *attr, char *buf)
4137{ 4137{
4138 struct platform_device *p; 4138 struct platform_device *p = to_platform_device(dev);
4139 int drive; 4139 int drive;
4140 4140
4141 p = container_of(dev, struct platform_device,dev);
4142 drive = p->id; 4141 drive = p->id;
4143 return sprintf(buf, "%X\n", UDP->cmos); 4142 return sprintf(buf, "%X\n", UDP->cmos);
4144} 4143}
diff --git a/drivers/block/ub.c b/drivers/block/ub.c
index 12fb816db7b0..69b7f8e77596 100644
--- a/drivers/block/ub.c
+++ b/drivers/block/ub.c
@@ -391,7 +391,7 @@ static int ub_probe_lun(struct ub_dev *sc, int lnum);
391 */ 391 */
392#ifdef CONFIG_USB_LIBUSUAL 392#ifdef CONFIG_USB_LIBUSUAL
393 393
394#define ub_usb_ids storage_usb_ids 394#define ub_usb_ids usb_storage_usb_ids
395#else 395#else
396 396
397static struct usb_device_id ub_usb_ids[] = { 397static struct usb_device_id ub_usb_ids[] = {
@@ -2146,10 +2146,9 @@ static int ub_get_pipes(struct ub_dev *sc, struct usb_device *dev,
2146 ep = &altsetting->endpoint[i].desc; 2146 ep = &altsetting->endpoint[i].desc;
2147 2147
2148 /* Is it a BULK endpoint? */ 2148 /* Is it a BULK endpoint? */
2149 if ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) 2149 if (usb_endpoint_xfer_bulk(ep)) {
2150 == USB_ENDPOINT_XFER_BULK) {
2151 /* BULK in or out? */ 2150 /* BULK in or out? */
2152 if (ep->bEndpointAddress & USB_DIR_IN) { 2151 if (usb_endpoint_dir_in(ep)) {
2153 if (ep_in == NULL) 2152 if (ep_in == NULL)
2154 ep_in = ep; 2153 ep_in = ep;
2155 } else { 2154 } else {
@@ -2168,9 +2167,9 @@ static int ub_get_pipes(struct ub_dev *sc, struct usb_device *dev,
2168 sc->send_ctrl_pipe = usb_sndctrlpipe(dev, 0); 2167 sc->send_ctrl_pipe = usb_sndctrlpipe(dev, 0);
2169 sc->recv_ctrl_pipe = usb_rcvctrlpipe(dev, 0); 2168 sc->recv_ctrl_pipe = usb_rcvctrlpipe(dev, 0);
2170 sc->send_bulk_pipe = usb_sndbulkpipe(dev, 2169 sc->send_bulk_pipe = usb_sndbulkpipe(dev,
2171 ep_out->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 2170 usb_endpoint_num(ep_out));
2172 sc->recv_bulk_pipe = usb_rcvbulkpipe(dev, 2171 sc->recv_bulk_pipe = usb_rcvbulkpipe(dev,
2173 ep_in->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 2172 usb_endpoint_num(ep_in));
2174 2173
2175 return 0; 2174 return 0;
2176} 2175}
diff --git a/drivers/char/hw_random/Kconfig b/drivers/char/hw_random/Kconfig
index 8822eca58ffa..5fab6470f4b2 100644
--- a/drivers/char/hw_random/Kconfig
+++ b/drivers/char/hw_random/Kconfig
@@ -20,6 +20,20 @@ config HW_RANDOM
20 20
21 If unsure, say Y. 21 If unsure, say Y.
22 22
23config HW_RANDOM_TIMERIOMEM
24 tristate "Timer IOMEM HW Random Number Generator support"
25 depends on HW_RANDOM && HAS_IOMEM
26 ---help---
27 This driver provides kernel-side support for a generic Random
28 Number Generator used by reading a 'dumb' iomem address that
29 is to be read no faster than, for example, once a second;
30 the default FPGA bitstream on the TS-7800 has such functionality.
31
32 To compile this driver as a module, choose M here: the
33 module will be called timeriomem-rng.
34
35 If unsure, say Y.
36
23config HW_RANDOM_INTEL 37config HW_RANDOM_INTEL
24 tristate "Intel HW Random Number Generator support" 38 tristate "Intel HW Random Number Generator support"
25 depends on HW_RANDOM && (X86 || IA64) && PCI 39 depends on HW_RANDOM && (X86 || IA64) && PCI
diff --git a/drivers/char/hw_random/Makefile b/drivers/char/hw_random/Makefile
index b6effb7522c2..e81d21a5f28f 100644
--- a/drivers/char/hw_random/Makefile
+++ b/drivers/char/hw_random/Makefile
@@ -4,6 +4,7 @@
4 4
5obj-$(CONFIG_HW_RANDOM) += rng-core.o 5obj-$(CONFIG_HW_RANDOM) += rng-core.o
6rng-core-y := core.o 6rng-core-y := core.o
7obj-$(CONFIG_HW_RANDOM_TIMERIOMEM) += timeriomem-rng.o
7obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o 8obj-$(CONFIG_HW_RANDOM_INTEL) += intel-rng.o
8obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o 9obj-$(CONFIG_HW_RANDOM_AMD) += amd-rng.o
9obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o 10obj-$(CONFIG_HW_RANDOM_GEODE) += geode-rng.o
diff --git a/drivers/char/hw_random/timeriomem-rng.c b/drivers/char/hw_random/timeriomem-rng.c
new file mode 100644
index 000000000000..10ad41be5897
--- /dev/null
+++ b/drivers/char/hw_random/timeriomem-rng.c
@@ -0,0 +1,151 @@
1/*
2 * drivers/char/hw_random/timeriomem-rng.c
3 *
4 * Copyright (C) 2009 Alexander Clouter <alex@digriz.org.uk>
5 *
6 * Derived from drivers/char/hw_random/omap-rng.c
7 * Copyright 2005 (c) MontaVista Software, Inc.
8 * Author: Deepak Saxena <dsaxena@plexity.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * Overview:
15 * This driver is useful for platforms that have an IO range that provides
16 * periodic random data from a single IO memory address. All the platform
17 * has to do is provide the address and 'wait time' that new data becomes
18 * available.
19 *
20 * TODO: add support for reading sizes other than 32bits and masking
21 */
22
23#include <linux/module.h>
24#include <linux/kernel.h>
25#include <linux/platform_device.h>
26#include <linux/hw_random.h>
27#include <linux/io.h>
28#include <linux/timeriomem-rng.h>
29#include <linux/jiffies.h>
30#include <linux/sched.h>
31#include <linux/timer.h>
32#include <linux/completion.h>
33
34static struct timeriomem_rng_data *timeriomem_rng_data;
35
36static void timeriomem_rng_trigger(unsigned long);
37static DEFINE_TIMER(timeriomem_rng_timer, timeriomem_rng_trigger, 0, 0);
38
39/*
40 * have data return 1, however return 0 if we have nothing
41 */
42static int timeriomem_rng_data_present(struct hwrng *rng, int wait)
43{
44 if (rng->priv == 0)
45 return 1;
46
47 if (!wait || timeriomem_rng_data->present)
48 return timeriomem_rng_data->present;
49
50 wait_for_completion(&timeriomem_rng_data->completion);
51
52 return 1;
53}
54
55static int timeriomem_rng_data_read(struct hwrng *rng, u32 *data)
56{
57 unsigned long cur;
58 s32 delay;
59
60 *data = readl(timeriomem_rng_data->address);
61
62 if (rng->priv != 0) {
63 cur = jiffies;
64
65 delay = cur - timeriomem_rng_timer.expires;
66 delay = rng->priv - (delay % rng->priv);
67
68 timeriomem_rng_timer.expires = cur + delay;
69 timeriomem_rng_data->present = 0;
70
71 init_completion(&timeriomem_rng_data->completion);
72 add_timer(&timeriomem_rng_timer);
73 }
74
75 return 4;
76}
77
78static void timeriomem_rng_trigger(unsigned long dummy)
79{
80 timeriomem_rng_data->present = 1;
81 complete(&timeriomem_rng_data->completion);
82}
83
84static struct hwrng timeriomem_rng_ops = {
85 .name = "timeriomem",
86 .data_present = timeriomem_rng_data_present,
87 .data_read = timeriomem_rng_data_read,
88 .priv = 0,
89};
90
91static int __init timeriomem_rng_probe(struct platform_device *pdev)
92{
93 int ret;
94
95 timeriomem_rng_data = pdev->dev.platform_data;
96
97 if (timeriomem_rng_data->period != 0
98 && usecs_to_jiffies(timeriomem_rng_data->period) > 0) {
99 timeriomem_rng_timer.expires = jiffies;
100
101 timeriomem_rng_ops.priv = usecs_to_jiffies(
102 timeriomem_rng_data->period);
103 }
104 timeriomem_rng_data->present = 1;
105
106 ret = hwrng_register(&timeriomem_rng_ops);
107 if (ret) {
108 dev_err(&pdev->dev, "problem registering\n");
109 return ret;
110 }
111
112 dev_info(&pdev->dev, "32bits from 0x%p @ %dus\n",
113 timeriomem_rng_data->address,
114 timeriomem_rng_data->period);
115
116 return 0;
117}
118
119static int __devexit timeriomem_rng_remove(struct platform_device *pdev)
120{
121 del_timer_sync(&timeriomem_rng_timer);
122 hwrng_unregister(&timeriomem_rng_ops);
123
124 return 0;
125}
126
127static struct platform_driver timeriomem_rng_driver = {
128 .driver = {
129 .name = "timeriomem_rng",
130 .owner = THIS_MODULE,
131 },
132 .probe = timeriomem_rng_probe,
133 .remove = __devexit_p(timeriomem_rng_remove),
134};
135
136static int __init timeriomem_rng_init(void)
137{
138 return platform_driver_register(&timeriomem_rng_driver);
139}
140
141static void __exit timeriomem_rng_exit(void)
142{
143 platform_driver_unregister(&timeriomem_rng_driver);
144}
145
146module_init(timeriomem_rng_init);
147module_exit(timeriomem_rng_exit);
148
149MODULE_LICENSE("GPL");
150MODULE_AUTHOR("Alexander Clouter <alex@digriz.org.uk>");
151MODULE_DESCRIPTION("Timer IOMEM H/W RNG driver");
diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
index d0e7926eb486..c64a1bc65349 100644
--- a/drivers/char/tpm/tpm_atmel.c
+++ b/drivers/char/tpm/tpm_atmel.c
@@ -168,12 +168,22 @@ static void atml_plat_remove(void)
168 } 168 }
169} 169}
170 170
171static struct device_driver atml_drv = { 171static int tpm_atml_suspend(struct platform_device *dev, pm_message_t msg)
172 .name = "tpm_atmel", 172{
173 .bus = &platform_bus_type, 173 return tpm_pm_suspend(&dev->dev, msg);
174 .owner = THIS_MODULE, 174}
175 .suspend = tpm_pm_suspend, 175
176 .resume = tpm_pm_resume, 176static int tpm_atml_resume(struct platform_device *dev)
177{
178 return tpm_pm_resume(&dev->dev);
179}
180static struct platform_driver atml_drv = {
181 .driver = {
182 .name = "tpm_atmel",
183 .owner = THIS_MODULE,
184 },
185 .suspend = tpm_atml_suspend,
186 .resume = tpm_atml_resume,
177}; 187};
178 188
179static int __init init_atmel(void) 189static int __init init_atmel(void)
@@ -184,7 +194,7 @@ static int __init init_atmel(void)
184 unsigned long base; 194 unsigned long base;
185 struct tpm_chip *chip; 195 struct tpm_chip *chip;
186 196
187 rc = driver_register(&atml_drv); 197 rc = platform_driver_register(&atml_drv);
188 if (rc) 198 if (rc)
189 return rc; 199 return rc;
190 200
@@ -223,13 +233,13 @@ err_rel_reg:
223 atmel_release_region(base, 233 atmel_release_region(base,
224 region_size); 234 region_size);
225err_unreg_drv: 235err_unreg_drv:
226 driver_unregister(&atml_drv); 236 platform_driver_unregister(&atml_drv);
227 return rc; 237 return rc;
228} 238}
229 239
230static void __exit cleanup_atmel(void) 240static void __exit cleanup_atmel(void)
231{ 241{
232 driver_unregister(&atml_drv); 242 platform_driver_unregister(&atml_drv);
233 atml_plat_remove(); 243 atml_plat_remove();
234} 244}
235 245
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index 717af7ad1bdf..aec1931608aa 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -654,12 +654,22 @@ module_param_string(hid, tpm_pnp_tbl[TIS_HID_USR_IDX].id,
654 sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444); 654 sizeof(tpm_pnp_tbl[TIS_HID_USR_IDX].id), 0444);
655MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe"); 655MODULE_PARM_DESC(hid, "Set additional specific HID for this driver to probe");
656 656
657static struct device_driver tis_drv = { 657static int tpm_tis_suspend(struct platform_device *dev, pm_message_t msg)
658 .name = "tpm_tis", 658{
659 .bus = &platform_bus_type, 659 return tpm_pm_suspend(&dev->dev, msg);
660 .owner = THIS_MODULE, 660}
661 .suspend = tpm_pm_suspend, 661
662 .resume = tpm_pm_resume, 662static int tpm_tis_resume(struct platform_device *dev)
663{
664 return tpm_pm_resume(&dev->dev);
665}
666static struct platform_driver tis_drv = {
667 .driver = {
668 .name = "tpm_tis",
669 .owner = THIS_MODULE,
670 },
671 .suspend = tpm_tis_suspend,
672 .resume = tpm_tis_resume,
663}; 673};
664 674
665static struct platform_device *pdev; 675static struct platform_device *pdev;
@@ -672,14 +682,14 @@ static int __init init_tis(void)
672 int rc; 682 int rc;
673 683
674 if (force) { 684 if (force) {
675 rc = driver_register(&tis_drv); 685 rc = platform_driver_register(&tis_drv);
676 if (rc < 0) 686 if (rc < 0)
677 return rc; 687 return rc;
678 if (IS_ERR(pdev=platform_device_register_simple("tpm_tis", -1, NULL, 0))) 688 if (IS_ERR(pdev=platform_device_register_simple("tpm_tis", -1, NULL, 0)))
679 return PTR_ERR(pdev); 689 return PTR_ERR(pdev);
680 if((rc=tpm_tis_init(&pdev->dev, TIS_MEM_BASE, TIS_MEM_LEN, 0)) != 0) { 690 if((rc=tpm_tis_init(&pdev->dev, TIS_MEM_BASE, TIS_MEM_LEN, 0)) != 0) {
681 platform_device_unregister(pdev); 691 platform_device_unregister(pdev);
682 driver_unregister(&tis_drv); 692 platform_driver_unregister(&tis_drv);
683 } 693 }
684 return rc; 694 return rc;
685 } 695 }
@@ -711,7 +721,7 @@ static void __exit cleanup_tis(void)
711 721
712 if (force) { 722 if (force) {
713 platform_device_unregister(pdev); 723 platform_device_unregister(pdev);
714 driver_unregister(&tis_drv); 724 platform_driver_unregister(&tis_drv);
715 } else 725 } else
716 pnp_unregister_driver(&tis_pnp_driver); 726 pnp_unregister_driver(&tis_pnp_driver);
717} 727}
diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
index 4f3b3f95fc42..d94d25c12aa8 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/char/vc_screen.c
@@ -479,18 +479,18 @@ static const struct file_operations vcs_fops = {
479 479
480static struct class *vc_class; 480static struct class *vc_class;
481 481
482void vcs_make_sysfs(struct tty_struct *tty) 482void vcs_make_sysfs(int index)
483{ 483{
484 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 1), NULL, 484 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, index + 1), NULL,
485 "vcs%u", tty->index + 1); 485 "vcs%u", index + 1);
486 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 129), NULL, 486 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, index + 129), NULL,
487 "vcsa%u", tty->index + 1); 487 "vcsa%u", index + 1);
488} 488}
489 489
490void vcs_remove_sysfs(struct tty_struct *tty) 490void vcs_remove_sysfs(int index)
491{ 491{
492 device_destroy(vc_class, MKDEV(VCS_MAJOR, tty->index + 1)); 492 device_destroy(vc_class, MKDEV(VCS_MAJOR, index + 1));
493 device_destroy(vc_class, MKDEV(VCS_MAJOR, tty->index + 129)); 493 device_destroy(vc_class, MKDEV(VCS_MAJOR, index + 129));
494} 494}
495 495
496int __init vcs_init(void) 496int __init vcs_init(void)
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 7900bd63b36d..2c1d133819b5 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -778,6 +778,7 @@ int vc_allocate(unsigned int currcons) /* return 0 on success */
778 } 778 }
779 vc->vc_kmalloced = 1; 779 vc->vc_kmalloced = 1;
780 vc_init(vc, vc->vc_rows, vc->vc_cols, 1); 780 vc_init(vc, vc->vc_rows, vc->vc_cols, 1);
781 vcs_make_sysfs(currcons);
781 atomic_notifier_call_chain(&vt_notifier_list, VT_ALLOCATE, &param); 782 atomic_notifier_call_chain(&vt_notifier_list, VT_ALLOCATE, &param);
782 } 783 }
783 return 0; 784 return 0;
@@ -987,7 +988,9 @@ void vc_deallocate(unsigned int currcons)
987 if (vc_cons_allocated(currcons)) { 988 if (vc_cons_allocated(currcons)) {
988 struct vc_data *vc = vc_cons[currcons].d; 989 struct vc_data *vc = vc_cons[currcons].d;
989 struct vt_notifier_param param = { .vc = vc }; 990 struct vt_notifier_param param = { .vc = vc };
991
990 atomic_notifier_call_chain(&vt_notifier_list, VT_DEALLOCATE, &param); 992 atomic_notifier_call_chain(&vt_notifier_list, VT_DEALLOCATE, &param);
993 vcs_remove_sysfs(currcons);
991 vc->vc_sw->con_deinit(vc); 994 vc->vc_sw->con_deinit(vc);
992 put_pid(vc->vt_pid); 995 put_pid(vc->vt_pid);
993 module_put(vc->vc_sw->owner); 996 module_put(vc->vc_sw->owner);
@@ -2775,7 +2778,6 @@ static int con_open(struct tty_struct *tty, struct file *filp)
2775 tty->termios->c_iflag |= IUTF8; 2778 tty->termios->c_iflag |= IUTF8;
2776 else 2779 else
2777 tty->termios->c_iflag &= ~IUTF8; 2780 tty->termios->c_iflag &= ~IUTF8;
2778 vcs_make_sysfs(tty);
2779 release_console_sem(); 2781 release_console_sem();
2780 return ret; 2782 return ret;
2781 } 2783 }
@@ -2795,7 +2797,6 @@ static void con_shutdown(struct tty_struct *tty)
2795 BUG_ON(vc == NULL); 2797 BUG_ON(vc == NULL);
2796 acquire_console_sem(); 2798 acquire_console_sem();
2797 vc->vc_tty = NULL; 2799 vc->vc_tty = NULL;
2798 vcs_remove_sysfs(tty);
2799 release_console_sem(); 2800 release_console_sem();
2800 tty_shutdown(tty); 2801 tty_shutdown(tty);
2801} 2802}
diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile
index 1525882190fd..1efb2879a94f 100644
--- a/drivers/clocksource/Makefile
+++ b/drivers/clocksource/Makefile
@@ -2,3 +2,4 @@ obj-$(CONFIG_ATMEL_TCB_CLKSRC) += tcb_clksrc.o
2obj-$(CONFIG_X86_CYCLONE_TIMER) += cyclone.o 2obj-$(CONFIG_X86_CYCLONE_TIMER) += cyclone.o
3obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o 3obj-$(CONFIG_X86_PM_TIMER) += acpi_pm.o
4obj-$(CONFIG_SCx200HR_TIMER) += scx200_hrt.o 4obj-$(CONFIG_SCx200HR_TIMER) += scx200_hrt.o
5obj-$(CONFIG_SH_TIMER_CMT) += sh_cmt.o
diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c
new file mode 100644
index 000000000000..7783b42f6914
--- /dev/null
+++ b/drivers/clocksource/sh_cmt.c
@@ -0,0 +1,615 @@
1/*
2 * SuperH Timer Support - CMT
3 *
4 * Copyright (C) 2008 Magnus Damm
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include <linux/init.h>
21#include <linux/bootmem.h>
22#include <linux/platform_device.h>
23#include <linux/spinlock.h>
24#include <linux/interrupt.h>
25#include <linux/ioport.h>
26#include <linux/io.h>
27#include <linux/clk.h>
28#include <linux/irq.h>
29#include <linux/err.h>
30#include <linux/clocksource.h>
31#include <linux/clockchips.h>
32#include <linux/sh_cmt.h>
33
34struct sh_cmt_priv {
35 void __iomem *mapbase;
36 struct clk *clk;
37 unsigned long width; /* 16 or 32 bit version of hardware block */
38 unsigned long overflow_bit;
39 unsigned long clear_bits;
40 struct irqaction irqaction;
41 struct platform_device *pdev;
42
43 unsigned long flags;
44 unsigned long match_value;
45 unsigned long next_match_value;
46 unsigned long max_match_value;
47 unsigned long rate;
48 spinlock_t lock;
49 struct clock_event_device ced;
50 unsigned long total_cycles;
51};
52
53static DEFINE_SPINLOCK(sh_cmt_lock);
54
55#define CMSTR -1 /* shared register */
56#define CMCSR 0 /* channel register */
57#define CMCNT 1 /* channel register */
58#define CMCOR 2 /* channel register */
59
60static inline unsigned long sh_cmt_read(struct sh_cmt_priv *p, int reg_nr)
61{
62 struct sh_cmt_config *cfg = p->pdev->dev.platform_data;
63 void __iomem *base = p->mapbase;
64 unsigned long offs;
65
66 if (reg_nr == CMSTR) {
67 offs = 0;
68 base -= cfg->channel_offset;
69 } else
70 offs = reg_nr;
71
72 if (p->width == 16)
73 offs <<= 1;
74 else {
75 offs <<= 2;
76 if ((reg_nr == CMCNT) || (reg_nr == CMCOR))
77 return ioread32(base + offs);
78 }
79
80 return ioread16(base + offs);
81}
82
83static inline void sh_cmt_write(struct sh_cmt_priv *p, int reg_nr,
84 unsigned long value)
85{
86 struct sh_cmt_config *cfg = p->pdev->dev.platform_data;
87 void __iomem *base = p->mapbase;
88 unsigned long offs;
89
90 if (reg_nr == CMSTR) {
91 offs = 0;
92 base -= cfg->channel_offset;
93 } else
94 offs = reg_nr;
95
96 if (p->width == 16)
97 offs <<= 1;
98 else {
99 offs <<= 2;
100 if ((reg_nr == CMCNT) || (reg_nr == CMCOR)) {
101 iowrite32(value, base + offs);
102 return;
103 }
104 }
105
106 iowrite16(value, base + offs);
107}
108
109static unsigned long sh_cmt_get_counter(struct sh_cmt_priv *p,
110 int *has_wrapped)
111{
112 unsigned long v1, v2, v3;
113
114 /* Make sure the timer value is stable. Stolen from acpi_pm.c */
115 do {
116 v1 = sh_cmt_read(p, CMCNT);
117 v2 = sh_cmt_read(p, CMCNT);
118 v3 = sh_cmt_read(p, CMCNT);
119 } while (unlikely((v1 > v2 && v1 < v3) || (v2 > v3 && v2 < v1)
120 || (v3 > v1 && v3 < v2)));
121
122 *has_wrapped = sh_cmt_read(p, CMCSR) & p->overflow_bit;
123 return v2;
124}
125
126
127static void sh_cmt_start_stop_ch(struct sh_cmt_priv *p, int start)
128{
129 struct sh_cmt_config *cfg = p->pdev->dev.platform_data;
130 unsigned long flags, value;
131
132 /* start stop register shared by multiple timer channels */
133 spin_lock_irqsave(&sh_cmt_lock, flags);
134 value = sh_cmt_read(p, CMSTR);
135
136 if (start)
137 value |= 1 << cfg->timer_bit;
138 else
139 value &= ~(1 << cfg->timer_bit);
140
141 sh_cmt_write(p, CMSTR, value);
142 spin_unlock_irqrestore(&sh_cmt_lock, flags);
143}
144
145static int sh_cmt_enable(struct sh_cmt_priv *p, unsigned long *rate)
146{
147 struct sh_cmt_config *cfg = p->pdev->dev.platform_data;
148 int ret;
149
150 /* enable clock */
151 ret = clk_enable(p->clk);
152 if (ret) {
153 pr_err("sh_cmt: cannot enable clock \"%s\"\n", cfg->clk);
154 return ret;
155 }
156 *rate = clk_get_rate(p->clk) / 8;
157
158 /* make sure channel is disabled */
159 sh_cmt_start_stop_ch(p, 0);
160
161 /* configure channel, periodic mode and maximum timeout */
162 if (p->width == 16)
163 sh_cmt_write(p, CMCSR, 0);
164 else
165 sh_cmt_write(p, CMCSR, 0x01a4);
166
167 sh_cmt_write(p, CMCOR, 0xffffffff);
168 sh_cmt_write(p, CMCNT, 0);
169
170 /* enable channel */
171 sh_cmt_start_stop_ch(p, 1);
172 return 0;
173}
174
175static void sh_cmt_disable(struct sh_cmt_priv *p)
176{
177 /* disable channel */
178 sh_cmt_start_stop_ch(p, 0);
179
180 /* stop clock */
181 clk_disable(p->clk);
182}
183
184/* private flags */
185#define FLAG_CLOCKEVENT (1 << 0)
186#define FLAG_CLOCKSOURCE (1 << 1)
187#define FLAG_REPROGRAM (1 << 2)
188#define FLAG_SKIPEVENT (1 << 3)
189#define FLAG_IRQCONTEXT (1 << 4)
190
191static void sh_cmt_clock_event_program_verify(struct sh_cmt_priv *p,
192 int absolute)
193{
194 unsigned long new_match;
195 unsigned long value = p->next_match_value;
196 unsigned long delay = 0;
197 unsigned long now = 0;
198 int has_wrapped;
199
200 now = sh_cmt_get_counter(p, &has_wrapped);
201 p->flags |= FLAG_REPROGRAM; /* force reprogram */
202
203 if (has_wrapped) {
204 /* we're competing with the interrupt handler.
205 * -> let the interrupt handler reprogram the timer.
206 * -> interrupt number two handles the event.
207 */
208 p->flags |= FLAG_SKIPEVENT;
209 return;
210 }
211
212 if (absolute)
213 now = 0;
214
215 do {
216 /* reprogram the timer hardware,
217 * but don't save the new match value yet.
218 */
219 new_match = now + value + delay;
220 if (new_match > p->max_match_value)
221 new_match = p->max_match_value;
222
223 sh_cmt_write(p, CMCOR, new_match);
224
225 now = sh_cmt_get_counter(p, &has_wrapped);
226 if (has_wrapped && (new_match > p->match_value)) {
227 /* we are changing to a greater match value,
228 * so this wrap must be caused by the counter
229 * matching the old value.
230 * -> first interrupt reprograms the timer.
231 * -> interrupt number two handles the event.
232 */
233 p->flags |= FLAG_SKIPEVENT;
234 break;
235 }
236
237 if (has_wrapped) {
238 /* we are changing to a smaller match value,
239 * so the wrap must be caused by the counter
240 * matching the new value.
241 * -> save programmed match value.
242 * -> let isr handle the event.
243 */
244 p->match_value = new_match;
245 break;
246 }
247
248 /* be safe: verify hardware settings */
249 if (now < new_match) {
250 /* timer value is below match value, all good.
251 * this makes sure we won't miss any match events.
252 * -> save programmed match value.
253 * -> let isr handle the event.
254 */
255 p->match_value = new_match;
256 break;
257 }
258
259 /* the counter has reached a value greater
260 * than our new match value. and since the
261 * has_wrapped flag isn't set we must have
262 * programmed a too close event.
263 * -> increase delay and retry.
264 */
265 if (delay)
266 delay <<= 1;
267 else
268 delay = 1;
269
270 if (!delay)
271 pr_warning("sh_cmt: too long delay\n");
272
273 } while (delay);
274}
275
276static void sh_cmt_set_next(struct sh_cmt_priv *p, unsigned long delta)
277{
278 unsigned long flags;
279
280 if (delta > p->max_match_value)
281 pr_warning("sh_cmt: delta out of range\n");
282
283 spin_lock_irqsave(&p->lock, flags);
284 p->next_match_value = delta;
285 sh_cmt_clock_event_program_verify(p, 0);
286 spin_unlock_irqrestore(&p->lock, flags);
287}
288
289static irqreturn_t sh_cmt_interrupt(int irq, void *dev_id)
290{
291 struct sh_cmt_priv *p = dev_id;
292
293 /* clear flags */
294 sh_cmt_write(p, CMCSR, sh_cmt_read(p, CMCSR) & p->clear_bits);
295
296 /* update clock source counter to begin with if enabled
297 * the wrap flag should be cleared by the timer specific
298 * isr before we end up here.
299 */
300 if (p->flags & FLAG_CLOCKSOURCE)
301 p->total_cycles += p->match_value;
302
303 if (!(p->flags & FLAG_REPROGRAM))
304 p->next_match_value = p->max_match_value;
305
306 p->flags |= FLAG_IRQCONTEXT;
307
308 if (p->flags & FLAG_CLOCKEVENT) {
309 if (!(p->flags & FLAG_SKIPEVENT)) {
310 if (p->ced.mode == CLOCK_EVT_MODE_ONESHOT) {
311 p->next_match_value = p->max_match_value;
312 p->flags |= FLAG_REPROGRAM;
313 }
314
315 p->ced.event_handler(&p->ced);
316 }
317 }
318
319 p->flags &= ~FLAG_SKIPEVENT;
320
321 if (p->flags & FLAG_REPROGRAM) {
322 p->flags &= ~FLAG_REPROGRAM;
323 sh_cmt_clock_event_program_verify(p, 1);
324
325 if (p->flags & FLAG_CLOCKEVENT)
326 if ((p->ced.mode == CLOCK_EVT_MODE_SHUTDOWN)
327 || (p->match_value == p->next_match_value))
328 p->flags &= ~FLAG_REPROGRAM;
329 }
330
331 p->flags &= ~FLAG_IRQCONTEXT;
332
333 return IRQ_HANDLED;
334}
335
336static int sh_cmt_start(struct sh_cmt_priv *p, unsigned long flag)
337{
338 int ret = 0;
339 unsigned long flags;
340
341 spin_lock_irqsave(&p->lock, flags);
342
343 if (!(p->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE)))
344 ret = sh_cmt_enable(p, &p->rate);
345
346 if (ret)
347 goto out;
348 p->flags |= flag;
349
350 /* setup timeout if no clockevent */
351 if ((flag == FLAG_CLOCKSOURCE) && (!(p->flags & FLAG_CLOCKEVENT)))
352 sh_cmt_set_next(p, p->max_match_value);
353 out:
354 spin_unlock_irqrestore(&p->lock, flags);
355
356 return ret;
357}
358
359static void sh_cmt_stop(struct sh_cmt_priv *p, unsigned long flag)
360{
361 unsigned long flags;
362 unsigned long f;
363
364 spin_lock_irqsave(&p->lock, flags);
365
366 f = p->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE);
367 p->flags &= ~flag;
368
369 if (f && !(p->flags & (FLAG_CLOCKEVENT | FLAG_CLOCKSOURCE)))
370 sh_cmt_disable(p);
371
372 /* adjust the timeout to maximum if only clocksource left */
373 if ((flag == FLAG_CLOCKEVENT) && (p->flags & FLAG_CLOCKSOURCE))
374 sh_cmt_set_next(p, p->max_match_value);
375
376 spin_unlock_irqrestore(&p->lock, flags);
377}
378
379static struct sh_cmt_priv *ced_to_sh_cmt(struct clock_event_device *ced)
380{
381 return container_of(ced, struct sh_cmt_priv, ced);
382}
383
384static void sh_cmt_clock_event_start(struct sh_cmt_priv *p, int periodic)
385{
386 struct clock_event_device *ced = &p->ced;
387
388 sh_cmt_start(p, FLAG_CLOCKEVENT);
389
390 /* TODO: calculate good shift from rate and counter bit width */
391
392 ced->shift = 32;
393 ced->mult = div_sc(p->rate, NSEC_PER_SEC, ced->shift);
394 ced->max_delta_ns = clockevent_delta2ns(p->max_match_value, ced);
395 ced->min_delta_ns = clockevent_delta2ns(0x1f, ced);
396
397 if (periodic)
398 sh_cmt_set_next(p, (p->rate + HZ/2) / HZ);
399 else
400 sh_cmt_set_next(p, p->max_match_value);
401}
402
403static void sh_cmt_clock_event_mode(enum clock_event_mode mode,
404 struct clock_event_device *ced)
405{
406 struct sh_cmt_priv *p = ced_to_sh_cmt(ced);
407
408 /* deal with old setting first */
409 switch (ced->mode) {
410 case CLOCK_EVT_MODE_PERIODIC:
411 case CLOCK_EVT_MODE_ONESHOT:
412 sh_cmt_stop(p, FLAG_CLOCKEVENT);
413 break;
414 default:
415 break;
416 }
417
418 switch (mode) {
419 case CLOCK_EVT_MODE_PERIODIC:
420 pr_info("sh_cmt: %s used for periodic clock events\n",
421 ced->name);
422 sh_cmt_clock_event_start(p, 1);
423 break;
424 case CLOCK_EVT_MODE_ONESHOT:
425 pr_info("sh_cmt: %s used for oneshot clock events\n",
426 ced->name);
427 sh_cmt_clock_event_start(p, 0);
428 break;
429 case CLOCK_EVT_MODE_SHUTDOWN:
430 case CLOCK_EVT_MODE_UNUSED:
431 sh_cmt_stop(p, FLAG_CLOCKEVENT);
432 break;
433 default:
434 break;
435 }
436}
437
438static int sh_cmt_clock_event_next(unsigned long delta,
439 struct clock_event_device *ced)
440{
441 struct sh_cmt_priv *p = ced_to_sh_cmt(ced);
442
443 BUG_ON(ced->mode != CLOCK_EVT_MODE_ONESHOT);
444 if (likely(p->flags & FLAG_IRQCONTEXT))
445 p->next_match_value = delta;
446 else
447 sh_cmt_set_next(p, delta);
448
449 return 0;
450}
451
452static void sh_cmt_register_clockevent(struct sh_cmt_priv *p,
453 char *name, unsigned long rating)
454{
455 struct clock_event_device *ced = &p->ced;
456
457 memset(ced, 0, sizeof(*ced));
458
459 ced->name = name;
460 ced->features = CLOCK_EVT_FEAT_PERIODIC;
461 ced->features |= CLOCK_EVT_FEAT_ONESHOT;
462 ced->rating = rating;
463 ced->cpumask = cpumask_of(0);
464 ced->set_next_event = sh_cmt_clock_event_next;
465 ced->set_mode = sh_cmt_clock_event_mode;
466
467 pr_info("sh_cmt: %s used for clock events\n", ced->name);
468 ced->mult = 1; /* work around misplaced WARN_ON() in clockevents.c */
469 clockevents_register_device(ced);
470}
471
472int sh_cmt_register(struct sh_cmt_priv *p, char *name,
473 unsigned long clockevent_rating,
474 unsigned long clocksource_rating)
475{
476 if (p->width == (sizeof(p->max_match_value) * 8))
477 p->max_match_value = ~0;
478 else
479 p->max_match_value = (1 << p->width) - 1;
480
481 p->match_value = p->max_match_value;
482 spin_lock_init(&p->lock);
483
484 if (clockevent_rating)
485 sh_cmt_register_clockevent(p, name, clockevent_rating);
486
487 return 0;
488}
489
490static int sh_cmt_setup(struct sh_cmt_priv *p, struct platform_device *pdev)
491{
492 struct sh_cmt_config *cfg = pdev->dev.platform_data;
493 struct resource *res;
494 int irq, ret;
495 ret = -ENXIO;
496
497 memset(p, 0, sizeof(*p));
498 p->pdev = pdev;
499
500 if (!cfg) {
501 dev_err(&p->pdev->dev, "missing platform data\n");
502 goto err0;
503 }
504
505 platform_set_drvdata(pdev, p);
506
507 res = platform_get_resource(p->pdev, IORESOURCE_MEM, 0);
508 if (!res) {
509 dev_err(&p->pdev->dev, "failed to get I/O memory\n");
510 goto err0;
511 }
512
513 irq = platform_get_irq(p->pdev, 0);
514 if (irq < 0) {
515 dev_err(&p->pdev->dev, "failed to get irq\n");
516 goto err0;
517 }
518
519 /* map memory, let mapbase point to our channel */
520 p->mapbase = ioremap_nocache(res->start, resource_size(res));
521 if (p->mapbase == NULL) {
522 pr_err("sh_cmt: failed to remap I/O memory\n");
523 goto err0;
524 }
525
526 /* request irq using setup_irq() (too early for request_irq()) */
527 p->irqaction.name = cfg->name;
528 p->irqaction.handler = sh_cmt_interrupt;
529 p->irqaction.dev_id = p;
530 p->irqaction.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL;
531 p->irqaction.mask = CPU_MASK_NONE;
532 ret = setup_irq(irq, &p->irqaction);
533 if (ret) {
534 pr_err("sh_cmt: failed to request irq %d\n", irq);
535 goto err1;
536 }
537
538 /* get hold of clock */
539 p->clk = clk_get(&p->pdev->dev, cfg->clk);
540 if (IS_ERR(p->clk)) {
541 pr_err("sh_cmt: cannot get clock \"%s\"\n", cfg->clk);
542 ret = PTR_ERR(p->clk);
543 goto err2;
544 }
545
546 if (resource_size(res) == 6) {
547 p->width = 16;
548 p->overflow_bit = 0x80;
549 p->clear_bits = ~0xc0;
550 } else {
551 p->width = 32;
552 p->overflow_bit = 0x8000;
553 p->clear_bits = ~0xc000;
554 }
555
556 return sh_cmt_register(p, cfg->name,
557 cfg->clockevent_rating,
558 cfg->clocksource_rating);
559 err2:
560 free_irq(irq, p);
561 err1:
562 iounmap(p->mapbase);
563 err0:
564 return ret;
565}
566
567static int __devinit sh_cmt_probe(struct platform_device *pdev)
568{
569 struct sh_cmt_priv *p = platform_get_drvdata(pdev);
570 int ret;
571
572 p = kmalloc(sizeof(*p), GFP_KERNEL);
573 if (p == NULL) {
574 dev_err(&pdev->dev, "failed to allocate driver data\n");
575 return -ENOMEM;
576 }
577
578 ret = sh_cmt_setup(p, pdev);
579 if (ret) {
580 kfree(p);
581
582 platform_set_drvdata(pdev, NULL);
583 }
584 return ret;
585}
586
587static int __devexit sh_cmt_remove(struct platform_device *pdev)
588{
589 return -EBUSY; /* cannot unregister clockevent and clocksource */
590}
591
592static struct platform_driver sh_cmt_device_driver = {
593 .probe = sh_cmt_probe,
594 .remove = __devexit_p(sh_cmt_remove),
595 .driver = {
596 .name = "sh_cmt",
597 }
598};
599
600static int __init sh_cmt_init(void)
601{
602 return platform_driver_register(&sh_cmt_device_driver);
603}
604
605static void __exit sh_cmt_exit(void)
606{
607 platform_driver_unregister(&sh_cmt_device_driver);
608}
609
610module_init(sh_cmt_init);
611module_exit(sh_cmt_exit);
612
613MODULE_AUTHOR("Magnus Damm");
614MODULE_DESCRIPTION("SuperH CMT Timer Driver");
615MODULE_LICENSE("GPL v2");
diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index d6daf3c507d3..d270e8eb3e67 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -104,7 +104,8 @@ EXPORT_SYMBOL_GPL(unlock_policy_rwsem_write);
104 104
105 105
106/* internal prototypes */ 106/* internal prototypes */
107static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event); 107static int __cpufreq_governor(struct cpufreq_policy *policy,
108 unsigned int event);
108static unsigned int __cpufreq_get(unsigned int cpu); 109static unsigned int __cpufreq_get(unsigned int cpu);
109static void handle_update(struct work_struct *work); 110static void handle_update(struct work_struct *work);
110 111
@@ -128,7 +129,7 @@ static int __init init_cpufreq_transition_notifier_list(void)
128pure_initcall(init_cpufreq_transition_notifier_list); 129pure_initcall(init_cpufreq_transition_notifier_list);
129 130
130static LIST_HEAD(cpufreq_governor_list); 131static LIST_HEAD(cpufreq_governor_list);
131static DEFINE_MUTEX (cpufreq_governor_mutex); 132static DEFINE_MUTEX(cpufreq_governor_mutex);
132 133
133struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) 134struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
134{ 135{
@@ -371,7 +372,7 @@ static struct cpufreq_governor *__find_governor(const char *str_governor)
371 struct cpufreq_governor *t; 372 struct cpufreq_governor *t;
372 373
373 list_for_each_entry(t, &cpufreq_governor_list, governor_list) 374 list_for_each_entry(t, &cpufreq_governor_list, governor_list)
374 if (!strnicmp(str_governor,t->name,CPUFREQ_NAME_LEN)) 375 if (!strnicmp(str_governor, t->name, CPUFREQ_NAME_LEN))
375 return t; 376 return t;
376 377
377 return NULL; 378 return NULL;
@@ -429,15 +430,11 @@ static int cpufreq_parse_governor(char *str_governor, unsigned int *policy,
429 430
430 mutex_unlock(&cpufreq_governor_mutex); 431 mutex_unlock(&cpufreq_governor_mutex);
431 } 432 }
432 out: 433out:
433 return err; 434 return err;
434} 435}
435 436
436 437
437/* drivers/base/cpu.c */
438extern struct sysdev_class cpu_sysdev_class;
439
440
441/** 438/**
442 * cpufreq_per_cpu_attr_read() / show_##file_name() - 439 * cpufreq_per_cpu_attr_read() / show_##file_name() -
443 * print out cpufreq information 440 * print out cpufreq information
@@ -450,11 +447,12 @@ extern struct sysdev_class cpu_sysdev_class;
450static ssize_t show_##file_name \ 447static ssize_t show_##file_name \
451(struct cpufreq_policy *policy, char *buf) \ 448(struct cpufreq_policy *policy, char *buf) \
452{ \ 449{ \
453 return sprintf (buf, "%u\n", policy->object); \ 450 return sprintf(buf, "%u\n", policy->object); \
454} 451}
455 452
456show_one(cpuinfo_min_freq, cpuinfo.min_freq); 453show_one(cpuinfo_min_freq, cpuinfo.min_freq);
457show_one(cpuinfo_max_freq, cpuinfo.max_freq); 454show_one(cpuinfo_max_freq, cpuinfo.max_freq);
455show_one(cpuinfo_transition_latency, cpuinfo.transition_latency);
458show_one(scaling_min_freq, min); 456show_one(scaling_min_freq, min);
459show_one(scaling_max_freq, max); 457show_one(scaling_max_freq, max);
460show_one(scaling_cur_freq, cur); 458show_one(scaling_cur_freq, cur);
@@ -476,7 +474,7 @@ static ssize_t store_##file_name \
476 if (ret) \ 474 if (ret) \
477 return -EINVAL; \ 475 return -EINVAL; \
478 \ 476 \
479 ret = sscanf (buf, "%u", &new_policy.object); \ 477 ret = sscanf(buf, "%u", &new_policy.object); \
480 if (ret != 1) \ 478 if (ret != 1) \
481 return -EINVAL; \ 479 return -EINVAL; \
482 \ 480 \
@@ -486,8 +484,8 @@ static ssize_t store_##file_name \
486 return ret ? ret : count; \ 484 return ret ? ret : count; \
487} 485}
488 486
489store_one(scaling_min_freq,min); 487store_one(scaling_min_freq, min);
490store_one(scaling_max_freq,max); 488store_one(scaling_max_freq, max);
491 489
492/** 490/**
493 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware 491 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
@@ -507,12 +505,13 @@ static ssize_t show_cpuinfo_cur_freq(struct cpufreq_policy *policy,
507 */ 505 */
508static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf) 506static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
509{ 507{
510 if(policy->policy == CPUFREQ_POLICY_POWERSAVE) 508 if (policy->policy == CPUFREQ_POLICY_POWERSAVE)
511 return sprintf(buf, "powersave\n"); 509 return sprintf(buf, "powersave\n");
512 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) 510 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
513 return sprintf(buf, "performance\n"); 511 return sprintf(buf, "performance\n");
514 else if (policy->governor) 512 else if (policy->governor)
515 return scnprintf(buf, CPUFREQ_NAME_LEN, "%s\n", policy->governor->name); 513 return scnprintf(buf, CPUFREQ_NAME_LEN, "%s\n",
514 policy->governor->name);
516 return -EINVAL; 515 return -EINVAL;
517} 516}
518 517
@@ -531,7 +530,7 @@ static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
531 if (ret) 530 if (ret)
532 return ret; 531 return ret;
533 532
534 ret = sscanf (buf, "%15s", str_governor); 533 ret = sscanf(buf, "%15s", str_governor);
535 if (ret != 1) 534 if (ret != 1)
536 return -EINVAL; 535 return -EINVAL;
537 536
@@ -575,7 +574,8 @@ static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
575 } 574 }
576 575
577 list_for_each_entry(t, &cpufreq_governor_list, governor_list) { 576 list_for_each_entry(t, &cpufreq_governor_list, governor_list) {
578 if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) - (CPUFREQ_NAME_LEN + 2))) 577 if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char))
578 - (CPUFREQ_NAME_LEN + 2)))
579 goto out; 579 goto out;
580 i += scnprintf(&buf[i], CPUFREQ_NAME_LEN, "%s ", t->name); 580 i += scnprintf(&buf[i], CPUFREQ_NAME_LEN, "%s ", t->name);
581 } 581 }
@@ -594,7 +594,7 @@ static ssize_t show_cpus(const struct cpumask *mask, char *buf)
594 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " "); 594 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " ");
595 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu); 595 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu);
596 if (i >= (PAGE_SIZE - 5)) 596 if (i >= (PAGE_SIZE - 5))
597 break; 597 break;
598 } 598 }
599 i += sprintf(&buf[i], "\n"); 599 i += sprintf(&buf[i], "\n");
600 return i; 600 return i;
@@ -660,6 +660,7 @@ __ATTR(_name, 0644, show_##_name, store_##_name)
660define_one_ro0400(cpuinfo_cur_freq); 660define_one_ro0400(cpuinfo_cur_freq);
661define_one_ro(cpuinfo_min_freq); 661define_one_ro(cpuinfo_min_freq);
662define_one_ro(cpuinfo_max_freq); 662define_one_ro(cpuinfo_max_freq);
663define_one_ro(cpuinfo_transition_latency);
663define_one_ro(scaling_available_governors); 664define_one_ro(scaling_available_governors);
664define_one_ro(scaling_driver); 665define_one_ro(scaling_driver);
665define_one_ro(scaling_cur_freq); 666define_one_ro(scaling_cur_freq);
@@ -673,6 +674,7 @@ define_one_rw(scaling_setspeed);
673static struct attribute *default_attrs[] = { 674static struct attribute *default_attrs[] = {
674 &cpuinfo_min_freq.attr, 675 &cpuinfo_min_freq.attr,
675 &cpuinfo_max_freq.attr, 676 &cpuinfo_max_freq.attr,
677 &cpuinfo_transition_latency.attr,
676 &scaling_min_freq.attr, 678 &scaling_min_freq.attr,
677 &scaling_max_freq.attr, 679 &scaling_max_freq.attr,
678 &affected_cpus.attr, 680 &affected_cpus.attr,
@@ -684,10 +686,10 @@ static struct attribute *default_attrs[] = {
684 NULL 686 NULL
685}; 687};
686 688
687#define to_policy(k) container_of(k,struct cpufreq_policy,kobj) 689#define to_policy(k) container_of(k, struct cpufreq_policy, kobj)
688#define to_attr(a) container_of(a,struct freq_attr,attr) 690#define to_attr(a) container_of(a, struct freq_attr, attr)
689 691
690static ssize_t show(struct kobject *kobj, struct attribute *attr ,char *buf) 692static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
691{ 693{
692 struct cpufreq_policy *policy = to_policy(kobj); 694 struct cpufreq_policy *policy = to_policy(kobj);
693 struct freq_attr *fattr = to_attr(attr); 695 struct freq_attr *fattr = to_attr(attr);
@@ -853,10 +855,10 @@ static int cpufreq_add_dev(struct sys_device *sys_dev)
853 if (cpu == j) 855 if (cpu == j)
854 continue; 856 continue;
855 857
856 /* check for existing affected CPUs. They may not be aware 858 /* Check for existing affected CPUs.
857 * of it due to CPU Hotplug. 859 * They may not be aware of it due to CPU Hotplug.
858 */ 860 */
859 managed_policy = cpufreq_cpu_get(j); // FIXME: Where is this released? What about error paths? 861 managed_policy = cpufreq_cpu_get(j); /* FIXME: Where is this released? What about error paths? */
860 if (unlikely(managed_policy)) { 862 if (unlikely(managed_policy)) {
861 863
862 /* Set proper policy_cpu */ 864 /* Set proper policy_cpu */
@@ -1127,8 +1129,8 @@ static void handle_update(struct work_struct *work)
1127 * @old_freq: CPU frequency the kernel thinks the CPU runs at 1129 * @old_freq: CPU frequency the kernel thinks the CPU runs at
1128 * @new_freq: CPU frequency the CPU actually runs at 1130 * @new_freq: CPU frequency the CPU actually runs at
1129 * 1131 *
1130 * We adjust to current frequency first, and need to clean up later. So either call 1132 * We adjust to current frequency first, and need to clean up later.
1131 * to cpufreq_update_policy() or schedule handle_update()). 1133 * So either call to cpufreq_update_policy() or schedule handle_update()).
1132 */ 1134 */
1133static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq, 1135static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq,
1134 unsigned int new_freq) 1136 unsigned int new_freq)
@@ -1610,7 +1612,8 @@ EXPORT_SYMBOL_GPL(cpufreq_unregister_governor);
1610 1612
1611/** 1613/**
1612 * cpufreq_get_policy - get the current cpufreq_policy 1614 * cpufreq_get_policy - get the current cpufreq_policy
1613 * @policy: struct cpufreq_policy into which the current cpufreq_policy is written 1615 * @policy: struct cpufreq_policy into which the current cpufreq_policy
1616 * is written
1614 * 1617 *
1615 * Reads the current cpufreq policy. 1618 * Reads the current cpufreq policy.
1616 */ 1619 */
diff --git a/drivers/cpufreq/cpufreq_conservative.c b/drivers/cpufreq/cpufreq_conservative.c
index 0320962c4ec5..2ecd95e4ab1a 100644
--- a/drivers/cpufreq/cpufreq_conservative.c
+++ b/drivers/cpufreq/cpufreq_conservative.c
@@ -4,7 +4,7 @@
4 * Copyright (C) 2001 Russell King 4 * Copyright (C) 2001 Russell King
5 * (C) 2003 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>. 5 * (C) 2003 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>.
6 * Jun Nakajima <jun.nakajima@intel.com> 6 * Jun Nakajima <jun.nakajima@intel.com>
7 * (C) 2004 Alexander Clouter <alex-kernel@digriz.org.uk> 7 * (C) 2009 Alexander Clouter <alex@digriz.org.uk>
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as 10 * it under the terms of the GNU General Public License version 2 as
@@ -13,22 +13,17 @@
13 13
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/smp.h>
17#include <linux/init.h> 16#include <linux/init.h>
18#include <linux/interrupt.h>
19#include <linux/ctype.h>
20#include <linux/cpufreq.h> 17#include <linux/cpufreq.h>
21#include <linux/sysctl.h>
22#include <linux/types.h>
23#include <linux/fs.h>
24#include <linux/sysfs.h>
25#include <linux/cpu.h> 18#include <linux/cpu.h>
26#include <linux/kmod.h>
27#include <linux/workqueue.h>
28#include <linux/jiffies.h> 19#include <linux/jiffies.h>
29#include <linux/kernel_stat.h> 20#include <linux/kernel_stat.h>
30#include <linux/percpu.h>
31#include <linux/mutex.h> 21#include <linux/mutex.h>
22#include <linux/hrtimer.h>
23#include <linux/tick.h>
24#include <linux/ktime.h>
25#include <linux/sched.h>
26
32/* 27/*
33 * dbs is used in this file as a shortform for demandbased switching 28 * dbs is used in this file as a shortform for demandbased switching
34 * It helps to keep variable names smaller, simpler 29 * It helps to keep variable names smaller, simpler
@@ -43,19 +38,31 @@
43 * latency of the processor. The governor will work on any processor with 38 * latency of the processor. The governor will work on any processor with
44 * transition latency <= 10mS, using appropriate sampling 39 * transition latency <= 10mS, using appropriate sampling
45 * rate. 40 * rate.
46 * For CPUs with transition latency > 10mS (mostly drivers 41 * For CPUs with transition latency > 10mS (mostly drivers with CPUFREQ_ETERNAL)
47 * with CPUFREQ_ETERNAL), this governor will not work. 42 * this governor will not work.
48 * All times here are in uS. 43 * All times here are in uS.
49 */ 44 */
50static unsigned int def_sampling_rate; 45static unsigned int def_sampling_rate;
51#define MIN_SAMPLING_RATE_RATIO (2) 46#define MIN_SAMPLING_RATE_RATIO (2)
52/* for correct statistics, we need at least 10 ticks between each measure */ 47/* for correct statistics, we need at least 10 ticks between each measure */
53#define MIN_STAT_SAMPLING_RATE \ 48#define MIN_STAT_SAMPLING_RATE \
54 (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10)) 49 (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10))
55#define MIN_SAMPLING_RATE \ 50#define MIN_SAMPLING_RATE \
56 (def_sampling_rate / MIN_SAMPLING_RATE_RATIO) 51 (def_sampling_rate / MIN_SAMPLING_RATE_RATIO)
52/* Above MIN_SAMPLING_RATE will vanish with its sysfs file soon
53 * Define the minimal settable sampling rate to the greater of:
54 * - "HW transition latency" * 100 (same as default sampling / 10)
55 * - MIN_STAT_SAMPLING_RATE
56 * To avoid that userspace shoots itself.
57*/
58static unsigned int minimum_sampling_rate(void)
59{
60 return max(def_sampling_rate / 10, MIN_STAT_SAMPLING_RATE);
61}
62
63/* This will also vanish soon with removing sampling_rate_max */
57#define MAX_SAMPLING_RATE (500 * def_sampling_rate) 64#define MAX_SAMPLING_RATE (500 * def_sampling_rate)
58#define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) 65#define LATENCY_MULTIPLIER (1000)
59#define DEF_SAMPLING_DOWN_FACTOR (1) 66#define DEF_SAMPLING_DOWN_FACTOR (1)
60#define MAX_SAMPLING_DOWN_FACTOR (10) 67#define MAX_SAMPLING_DOWN_FACTOR (10)
61#define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000) 68#define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000)
@@ -63,12 +70,15 @@ static unsigned int def_sampling_rate;
63static void do_dbs_timer(struct work_struct *work); 70static void do_dbs_timer(struct work_struct *work);
64 71
65struct cpu_dbs_info_s { 72struct cpu_dbs_info_s {
73 cputime64_t prev_cpu_idle;
74 cputime64_t prev_cpu_wall;
75 cputime64_t prev_cpu_nice;
66 struct cpufreq_policy *cur_policy; 76 struct cpufreq_policy *cur_policy;
67 unsigned int prev_cpu_idle_up; 77 struct delayed_work work;
68 unsigned int prev_cpu_idle_down;
69 unsigned int enable;
70 unsigned int down_skip; 78 unsigned int down_skip;
71 unsigned int requested_freq; 79 unsigned int requested_freq;
80 int cpu;
81 unsigned int enable:1;
72}; 82};
73static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info); 83static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info);
74 84
@@ -82,19 +92,18 @@ static unsigned int dbs_enable; /* number of CPUs using this policy */
82 * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock 92 * cpu_hotplug lock should be taken before that. Note that cpu_hotplug lock
83 * is recursive for the same process. -Venki 93 * is recursive for the same process. -Venki
84 */ 94 */
85static DEFINE_MUTEX (dbs_mutex); 95static DEFINE_MUTEX(dbs_mutex);
86static DECLARE_DELAYED_WORK(dbs_work, do_dbs_timer);
87 96
88struct dbs_tuners { 97static struct workqueue_struct *kconservative_wq;
98
99static struct dbs_tuners {
89 unsigned int sampling_rate; 100 unsigned int sampling_rate;
90 unsigned int sampling_down_factor; 101 unsigned int sampling_down_factor;
91 unsigned int up_threshold; 102 unsigned int up_threshold;
92 unsigned int down_threshold; 103 unsigned int down_threshold;
93 unsigned int ignore_nice; 104 unsigned int ignore_nice;
94 unsigned int freq_step; 105 unsigned int freq_step;
95}; 106} dbs_tuners_ins = {
96
97static struct dbs_tuners dbs_tuners_ins = {
98 .up_threshold = DEF_FREQUENCY_UP_THRESHOLD, 107 .up_threshold = DEF_FREQUENCY_UP_THRESHOLD,
99 .down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD, 108 .down_threshold = DEF_FREQUENCY_DOWN_THRESHOLD,
100 .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR, 109 .sampling_down_factor = DEF_SAMPLING_DOWN_FACTOR,
@@ -102,18 +111,37 @@ static struct dbs_tuners dbs_tuners_ins = {
102 .freq_step = 5, 111 .freq_step = 5,
103}; 112};
104 113
105static inline unsigned int get_cpu_idle_time(unsigned int cpu) 114static inline cputime64_t get_cpu_idle_time_jiffy(unsigned int cpu,
115 cputime64_t *wall)
106{ 116{
107 unsigned int add_nice = 0, ret; 117 cputime64_t idle_time;
118 cputime64_t cur_wall_time;
119 cputime64_t busy_time;
108 120
109 if (dbs_tuners_ins.ignore_nice) 121 cur_wall_time = jiffies64_to_cputime64(get_jiffies_64());
110 add_nice = kstat_cpu(cpu).cpustat.nice; 122 busy_time = cputime64_add(kstat_cpu(cpu).cpustat.user,
123 kstat_cpu(cpu).cpustat.system);
124
125 busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.irq);
126 busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.softirq);
127 busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.steal);
128 busy_time = cputime64_add(busy_time, kstat_cpu(cpu).cpustat.nice);
129
130 idle_time = cputime64_sub(cur_wall_time, busy_time);
131 if (wall)
132 *wall = cur_wall_time;
133
134 return idle_time;
135}
136
137static inline cputime64_t get_cpu_idle_time(unsigned int cpu, cputime64_t *wall)
138{
139 u64 idle_time = get_cpu_idle_time_us(cpu, wall);
111 140
112 ret = kstat_cpu(cpu).cpustat.idle + 141 if (idle_time == -1ULL)
113 kstat_cpu(cpu).cpustat.iowait + 142 return get_cpu_idle_time_jiffy(cpu, wall);
114 add_nice;
115 143
116 return ret; 144 return idle_time;
117} 145}
118 146
119/* keep track of frequency transitions */ 147/* keep track of frequency transitions */
@@ -125,10 +153,21 @@ dbs_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
125 struct cpu_dbs_info_s *this_dbs_info = &per_cpu(cpu_dbs_info, 153 struct cpu_dbs_info_s *this_dbs_info = &per_cpu(cpu_dbs_info,
126 freq->cpu); 154 freq->cpu);
127 155
156 struct cpufreq_policy *policy;
157
128 if (!this_dbs_info->enable) 158 if (!this_dbs_info->enable)
129 return 0; 159 return 0;
130 160
131 this_dbs_info->requested_freq = freq->new; 161 policy = this_dbs_info->cur_policy;
162
163 /*
164 * we only care if our internally tracked freq moves outside
165 * the 'valid' ranges of freqency available to us otherwise
166 * we do not change it
167 */
168 if (this_dbs_info->requested_freq > policy->max
169 || this_dbs_info->requested_freq < policy->min)
170 this_dbs_info->requested_freq = freq->new;
132 171
133 return 0; 172 return 0;
134} 173}
@@ -140,16 +179,31 @@ static struct notifier_block dbs_cpufreq_notifier_block = {
140/************************** sysfs interface ************************/ 179/************************** sysfs interface ************************/
141static ssize_t show_sampling_rate_max(struct cpufreq_policy *policy, char *buf) 180static ssize_t show_sampling_rate_max(struct cpufreq_policy *policy, char *buf)
142{ 181{
143 return sprintf (buf, "%u\n", MAX_SAMPLING_RATE); 182 static int print_once;
183
184 if (!print_once) {
185 printk(KERN_INFO "CPUFREQ: conservative sampling_rate_max "
186 "sysfs file is deprecated - used by: %s\n",
187 current->comm);
188 print_once = 1;
189 }
190 return sprintf(buf, "%u\n", MAX_SAMPLING_RATE);
144} 191}
145 192
146static ssize_t show_sampling_rate_min(struct cpufreq_policy *policy, char *buf) 193static ssize_t show_sampling_rate_min(struct cpufreq_policy *policy, char *buf)
147{ 194{
148 return sprintf (buf, "%u\n", MIN_SAMPLING_RATE); 195 static int print_once;
196
197 if (!print_once) {
198 printk(KERN_INFO "CPUFREQ: conservative sampling_rate_max "
199 "sysfs file is deprecated - used by: %s\n", current->comm);
200 print_once = 1;
201 }
202 return sprintf(buf, "%u\n", MIN_SAMPLING_RATE);
149} 203}
150 204
151#define define_one_ro(_name) \ 205#define define_one_ro(_name) \
152static struct freq_attr _name = \ 206static struct freq_attr _name = \
153__ATTR(_name, 0444, show_##_name, NULL) 207__ATTR(_name, 0444, show_##_name, NULL)
154 208
155define_one_ro(sampling_rate_max); 209define_one_ro(sampling_rate_max);
@@ -174,7 +228,8 @@ static ssize_t store_sampling_down_factor(struct cpufreq_policy *unused,
174{ 228{
175 unsigned int input; 229 unsigned int input;
176 int ret; 230 int ret;
177 ret = sscanf (buf, "%u", &input); 231 ret = sscanf(buf, "%u", &input);
232
178 if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1) 233 if (ret != 1 || input > MAX_SAMPLING_DOWN_FACTOR || input < 1)
179 return -EINVAL; 234 return -EINVAL;
180 235
@@ -190,15 +245,13 @@ static ssize_t store_sampling_rate(struct cpufreq_policy *unused,
190{ 245{
191 unsigned int input; 246 unsigned int input;
192 int ret; 247 int ret;
193 ret = sscanf (buf, "%u", &input); 248 ret = sscanf(buf, "%u", &input);
194 249
195 mutex_lock(&dbs_mutex); 250 if (ret != 1)
196 if (ret != 1 || input > MAX_SAMPLING_RATE || input < MIN_SAMPLING_RATE) {
197 mutex_unlock(&dbs_mutex);
198 return -EINVAL; 251 return -EINVAL;
199 }
200 252
201 dbs_tuners_ins.sampling_rate = input; 253 mutex_lock(&dbs_mutex);
254 dbs_tuners_ins.sampling_rate = max(input, minimum_sampling_rate());
202 mutex_unlock(&dbs_mutex); 255 mutex_unlock(&dbs_mutex);
203 256
204 return count; 257 return count;
@@ -209,10 +262,11 @@ static ssize_t store_up_threshold(struct cpufreq_policy *unused,
209{ 262{
210 unsigned int input; 263 unsigned int input;
211 int ret; 264 int ret;
212 ret = sscanf (buf, "%u", &input); 265 ret = sscanf(buf, "%u", &input);
213 266
214 mutex_lock(&dbs_mutex); 267 mutex_lock(&dbs_mutex);
215 if (ret != 1 || input > 100 || input <= dbs_tuners_ins.down_threshold) { 268 if (ret != 1 || input > 100 ||
269 input <= dbs_tuners_ins.down_threshold) {
216 mutex_unlock(&dbs_mutex); 270 mutex_unlock(&dbs_mutex);
217 return -EINVAL; 271 return -EINVAL;
218 } 272 }
@@ -228,10 +282,12 @@ static ssize_t store_down_threshold(struct cpufreq_policy *unused,
228{ 282{
229 unsigned int input; 283 unsigned int input;
230 int ret; 284 int ret;
231 ret = sscanf (buf, "%u", &input); 285 ret = sscanf(buf, "%u", &input);
232 286
233 mutex_lock(&dbs_mutex); 287 mutex_lock(&dbs_mutex);
234 if (ret != 1 || input > 100 || input >= dbs_tuners_ins.up_threshold) { 288 /* cannot be lower than 11 otherwise freq will not fall */
289 if (ret != 1 || input < 11 || input > 100 ||
290 input >= dbs_tuners_ins.up_threshold) {
235 mutex_unlock(&dbs_mutex); 291 mutex_unlock(&dbs_mutex);
236 return -EINVAL; 292 return -EINVAL;
237 } 293 }
@@ -264,12 +320,14 @@ static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy,
264 } 320 }
265 dbs_tuners_ins.ignore_nice = input; 321 dbs_tuners_ins.ignore_nice = input;
266 322
267 /* we need to re-evaluate prev_cpu_idle_up and prev_cpu_idle_down */ 323 /* we need to re-evaluate prev_cpu_idle */
268 for_each_online_cpu(j) { 324 for_each_online_cpu(j) {
269 struct cpu_dbs_info_s *j_dbs_info; 325 struct cpu_dbs_info_s *dbs_info;
270 j_dbs_info = &per_cpu(cpu_dbs_info, j); 326 dbs_info = &per_cpu(cpu_dbs_info, j);
271 j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(j); 327 dbs_info->prev_cpu_idle = get_cpu_idle_time(j,
272 j_dbs_info->prev_cpu_idle_down = j_dbs_info->prev_cpu_idle_up; 328 &dbs_info->prev_cpu_wall);
329 if (dbs_tuners_ins.ignore_nice)
330 dbs_info->prev_cpu_nice = kstat_cpu(j).cpustat.nice;
273 } 331 }
274 mutex_unlock(&dbs_mutex); 332 mutex_unlock(&dbs_mutex);
275 333
@@ -281,7 +339,6 @@ static ssize_t store_freq_step(struct cpufreq_policy *policy,
281{ 339{
282 unsigned int input; 340 unsigned int input;
283 int ret; 341 int ret;
284
285 ret = sscanf(buf, "%u", &input); 342 ret = sscanf(buf, "%u", &input);
286 343
287 if (ret != 1) 344 if (ret != 1)
@@ -310,7 +367,7 @@ define_one_rw(down_threshold);
310define_one_rw(ignore_nice_load); 367define_one_rw(ignore_nice_load);
311define_one_rw(freq_step); 368define_one_rw(freq_step);
312 369
313static struct attribute * dbs_attributes[] = { 370static struct attribute *dbs_attributes[] = {
314 &sampling_rate_max.attr, 371 &sampling_rate_max.attr,
315 &sampling_rate_min.attr, 372 &sampling_rate_min.attr,
316 &sampling_rate.attr, 373 &sampling_rate.attr,
@@ -329,55 +386,78 @@ static struct attribute_group dbs_attr_group = {
329 386
330/************************** sysfs end ************************/ 387/************************** sysfs end ************************/
331 388
332static void dbs_check_cpu(int cpu) 389static void dbs_check_cpu(struct cpu_dbs_info_s *this_dbs_info)
333{ 390{
334 unsigned int idle_ticks, up_idle_ticks, down_idle_ticks; 391 unsigned int load = 0;
335 unsigned int tmp_idle_ticks, total_idle_ticks;
336 unsigned int freq_target; 392 unsigned int freq_target;
337 unsigned int freq_down_sampling_rate;
338 struct cpu_dbs_info_s *this_dbs_info = &per_cpu(cpu_dbs_info, cpu);
339 struct cpufreq_policy *policy;
340 393
341 if (!this_dbs_info->enable) 394 struct cpufreq_policy *policy;
342 return; 395 unsigned int j;
343 396
344 policy = this_dbs_info->cur_policy; 397 policy = this_dbs_info->cur_policy;
345 398
346 /* 399 /*
347 * The default safe range is 20% to 80% 400 * Every sampling_rate, we check, if current idle time is less
348 * Every sampling_rate, we check 401 * than 20% (default), then we try to increase frequency
349 * - If current idle time is less than 20%, then we try to 402 * Every sampling_rate*sampling_down_factor, we check, if current
350 * increase frequency 403 * idle time is more than 80%, then we try to decrease frequency
351 * Every sampling_rate*sampling_down_factor, we check
352 * - If current idle time is more than 80%, then we try to
353 * decrease frequency
354 * 404 *
355 * Any frequency increase takes it to the maximum frequency. 405 * Any frequency increase takes it to the maximum frequency.
356 * Frequency reduction happens at minimum steps of 406 * Frequency reduction happens at minimum steps of
357 * 5% (default) of max_frequency 407 * 5% (default) of maximum frequency
358 */ 408 */
359 409
360 /* Check for frequency increase */ 410 /* Get Absolute Load */
361 idle_ticks = UINT_MAX; 411 for_each_cpu(j, policy->cpus) {
412 struct cpu_dbs_info_s *j_dbs_info;
413 cputime64_t cur_wall_time, cur_idle_time;
414 unsigned int idle_time, wall_time;
362 415
363 /* Check for frequency increase */ 416 j_dbs_info = &per_cpu(cpu_dbs_info, j);
364 total_idle_ticks = get_cpu_idle_time(cpu); 417
365 tmp_idle_ticks = total_idle_ticks - 418 cur_idle_time = get_cpu_idle_time(j, &cur_wall_time);
366 this_dbs_info->prev_cpu_idle_up; 419
367 this_dbs_info->prev_cpu_idle_up = total_idle_ticks; 420 wall_time = (unsigned int) cputime64_sub(cur_wall_time,
421 j_dbs_info->prev_cpu_wall);
422 j_dbs_info->prev_cpu_wall = cur_wall_time;
423
424 idle_time = (unsigned int) cputime64_sub(cur_idle_time,
425 j_dbs_info->prev_cpu_idle);
426 j_dbs_info->prev_cpu_idle = cur_idle_time;
427
428 if (dbs_tuners_ins.ignore_nice) {
429 cputime64_t cur_nice;
430 unsigned long cur_nice_jiffies;
431
432 cur_nice = cputime64_sub(kstat_cpu(j).cpustat.nice,
433 j_dbs_info->prev_cpu_nice);
434 /*
435 * Assumption: nice time between sampling periods will
436 * be less than 2^32 jiffies for 32 bit sys
437 */
438 cur_nice_jiffies = (unsigned long)
439 cputime64_to_jiffies64(cur_nice);
368 440
369 if (tmp_idle_ticks < idle_ticks) 441 j_dbs_info->prev_cpu_nice = kstat_cpu(j).cpustat.nice;
370 idle_ticks = tmp_idle_ticks; 442 idle_time += jiffies_to_usecs(cur_nice_jiffies);
443 }
444
445 if (unlikely(!wall_time || wall_time < idle_time))
446 continue;
447
448 load = 100 * (wall_time - idle_time) / wall_time;
449 }
371 450
372 /* Scale idle ticks by 100 and compare with up and down ticks */ 451 /*
373 idle_ticks *= 100; 452 * break out if we 'cannot' reduce the speed as the user might
374 up_idle_ticks = (100 - dbs_tuners_ins.up_threshold) * 453 * want freq_step to be zero
375 usecs_to_jiffies(dbs_tuners_ins.sampling_rate); 454 */
455 if (dbs_tuners_ins.freq_step == 0)
456 return;
376 457
377 if (idle_ticks < up_idle_ticks) { 458 /* Check for frequency increase */
459 if (load > dbs_tuners_ins.up_threshold) {
378 this_dbs_info->down_skip = 0; 460 this_dbs_info->down_skip = 0;
379 this_dbs_info->prev_cpu_idle_down =
380 this_dbs_info->prev_cpu_idle_up;
381 461
382 /* if we are already at full speed then break out early */ 462 /* if we are already at full speed then break out early */
383 if (this_dbs_info->requested_freq == policy->max) 463 if (this_dbs_info->requested_freq == policy->max)
@@ -398,49 +478,24 @@ static void dbs_check_cpu(int cpu)
398 return; 478 return;
399 } 479 }
400 480
401 /* Check for frequency decrease */ 481 /*
402 this_dbs_info->down_skip++; 482 * The optimal frequency is the frequency that is the lowest that
403 if (this_dbs_info->down_skip < dbs_tuners_ins.sampling_down_factor) 483 * can support the current CPU usage without triggering the up
404 return; 484 * policy. To be safe, we focus 10 points under the threshold.
405 485 */
406 /* Check for frequency decrease */ 486 if (load < (dbs_tuners_ins.down_threshold - 10)) {
407 total_idle_ticks = this_dbs_info->prev_cpu_idle_up;
408 tmp_idle_ticks = total_idle_ticks -
409 this_dbs_info->prev_cpu_idle_down;
410 this_dbs_info->prev_cpu_idle_down = total_idle_ticks;
411
412 if (tmp_idle_ticks < idle_ticks)
413 idle_ticks = tmp_idle_ticks;
414
415 /* Scale idle ticks by 100 and compare with up and down ticks */
416 idle_ticks *= 100;
417 this_dbs_info->down_skip = 0;
418
419 freq_down_sampling_rate = dbs_tuners_ins.sampling_rate *
420 dbs_tuners_ins.sampling_down_factor;
421 down_idle_ticks = (100 - dbs_tuners_ins.down_threshold) *
422 usecs_to_jiffies(freq_down_sampling_rate);
423
424 if (idle_ticks > down_idle_ticks) {
425 /*
426 * if we are already at the lowest speed then break out early
427 * or if we 'cannot' reduce the speed as the user might want
428 * freq_target to be zero
429 */
430 if (this_dbs_info->requested_freq == policy->min
431 || dbs_tuners_ins.freq_step == 0)
432 return;
433
434 freq_target = (dbs_tuners_ins.freq_step * policy->max) / 100; 487 freq_target = (dbs_tuners_ins.freq_step * policy->max) / 100;
435 488
436 /* max freq cannot be less than 100. But who knows.... */
437 if (unlikely(freq_target == 0))
438 freq_target = 5;
439
440 this_dbs_info->requested_freq -= freq_target; 489 this_dbs_info->requested_freq -= freq_target;
441 if (this_dbs_info->requested_freq < policy->min) 490 if (this_dbs_info->requested_freq < policy->min)
442 this_dbs_info->requested_freq = policy->min; 491 this_dbs_info->requested_freq = policy->min;
443 492
493 /*
494 * if we cannot reduce the frequency anymore, break out early
495 */
496 if (policy->cur == policy->min)
497 return;
498
444 __cpufreq_driver_target(policy, this_dbs_info->requested_freq, 499 __cpufreq_driver_target(policy, this_dbs_info->requested_freq,
445 CPUFREQ_RELATION_H); 500 CPUFREQ_RELATION_H);
446 return; 501 return;
@@ -449,27 +504,45 @@ static void dbs_check_cpu(int cpu)
449 504
450static void do_dbs_timer(struct work_struct *work) 505static void do_dbs_timer(struct work_struct *work)
451{ 506{
452 int i; 507 struct cpu_dbs_info_s *dbs_info =
453 mutex_lock(&dbs_mutex); 508 container_of(work, struct cpu_dbs_info_s, work.work);
454 for_each_online_cpu(i) 509 unsigned int cpu = dbs_info->cpu;
455 dbs_check_cpu(i); 510
456 schedule_delayed_work(&dbs_work, 511 /* We want all CPUs to do sampling nearly on same jiffy */
457 usecs_to_jiffies(dbs_tuners_ins.sampling_rate)); 512 int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
458 mutex_unlock(&dbs_mutex); 513
514 delay -= jiffies % delay;
515
516 if (lock_policy_rwsem_write(cpu) < 0)
517 return;
518
519 if (!dbs_info->enable) {
520 unlock_policy_rwsem_write(cpu);
521 return;
522 }
523
524 dbs_check_cpu(dbs_info);
525
526 queue_delayed_work_on(cpu, kconservative_wq, &dbs_info->work, delay);
527 unlock_policy_rwsem_write(cpu);
459} 528}
460 529
461static inline void dbs_timer_init(void) 530static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info)
462{ 531{
463 init_timer_deferrable(&dbs_work.timer); 532 /* We want all CPUs to do sampling nearly on same jiffy */
464 schedule_delayed_work(&dbs_work, 533 int delay = usecs_to_jiffies(dbs_tuners_ins.sampling_rate);
465 usecs_to_jiffies(dbs_tuners_ins.sampling_rate)); 534 delay -= jiffies % delay;
466 return; 535
536 dbs_info->enable = 1;
537 INIT_DELAYED_WORK_DEFERRABLE(&dbs_info->work, do_dbs_timer);
538 queue_delayed_work_on(dbs_info->cpu, kconservative_wq, &dbs_info->work,
539 delay);
467} 540}
468 541
469static inline void dbs_timer_exit(void) 542static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info)
470{ 543{
471 cancel_delayed_work(&dbs_work); 544 dbs_info->enable = 0;
472 return; 545 cancel_delayed_work(&dbs_info->work);
473} 546}
474 547
475static int cpufreq_governor_dbs(struct cpufreq_policy *policy, 548static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
@@ -503,11 +576,13 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
503 j_dbs_info = &per_cpu(cpu_dbs_info, j); 576 j_dbs_info = &per_cpu(cpu_dbs_info, j);
504 j_dbs_info->cur_policy = policy; 577 j_dbs_info->cur_policy = policy;
505 578
506 j_dbs_info->prev_cpu_idle_up = get_cpu_idle_time(cpu); 579 j_dbs_info->prev_cpu_idle = get_cpu_idle_time(j,
507 j_dbs_info->prev_cpu_idle_down 580 &j_dbs_info->prev_cpu_wall);
508 = j_dbs_info->prev_cpu_idle_up; 581 if (dbs_tuners_ins.ignore_nice) {
582 j_dbs_info->prev_cpu_nice =
583 kstat_cpu(j).cpustat.nice;
584 }
509 } 585 }
510 this_dbs_info->enable = 1;
511 this_dbs_info->down_skip = 0; 586 this_dbs_info->down_skip = 0;
512 this_dbs_info->requested_freq = policy->cur; 587 this_dbs_info->requested_freq = policy->cur;
513 588
@@ -523,38 +598,36 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
523 if (latency == 0) 598 if (latency == 0)
524 latency = 1; 599 latency = 1;
525 600
526 def_sampling_rate = 10 * latency * 601 def_sampling_rate =
527 DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; 602 max(latency * LATENCY_MULTIPLIER,
528 603 MIN_STAT_SAMPLING_RATE);
529 if (def_sampling_rate < MIN_STAT_SAMPLING_RATE)
530 def_sampling_rate = MIN_STAT_SAMPLING_RATE;
531 604
532 dbs_tuners_ins.sampling_rate = def_sampling_rate; 605 dbs_tuners_ins.sampling_rate = def_sampling_rate;
533 606
534 dbs_timer_init();
535 cpufreq_register_notifier( 607 cpufreq_register_notifier(
536 &dbs_cpufreq_notifier_block, 608 &dbs_cpufreq_notifier_block,
537 CPUFREQ_TRANSITION_NOTIFIER); 609 CPUFREQ_TRANSITION_NOTIFIER);
538 } 610 }
611 dbs_timer_init(this_dbs_info);
539 612
540 mutex_unlock(&dbs_mutex); 613 mutex_unlock(&dbs_mutex);
614
541 break; 615 break;
542 616
543 case CPUFREQ_GOV_STOP: 617 case CPUFREQ_GOV_STOP:
544 mutex_lock(&dbs_mutex); 618 mutex_lock(&dbs_mutex);
545 this_dbs_info->enable = 0; 619 dbs_timer_exit(this_dbs_info);
546 sysfs_remove_group(&policy->kobj, &dbs_attr_group); 620 sysfs_remove_group(&policy->kobj, &dbs_attr_group);
547 dbs_enable--; 621 dbs_enable--;
622
548 /* 623 /*
549 * Stop the timerschedule work, when this governor 624 * Stop the timerschedule work, when this governor
550 * is used for first time 625 * is used for first time
551 */ 626 */
552 if (dbs_enable == 0) { 627 if (dbs_enable == 0)
553 dbs_timer_exit();
554 cpufreq_unregister_notifier( 628 cpufreq_unregister_notifier(
555 &dbs_cpufreq_notifier_block, 629 &dbs_cpufreq_notifier_block,
556 CPUFREQ_TRANSITION_NOTIFIER); 630 CPUFREQ_TRANSITION_NOTIFIER);
557 }
558 631
559 mutex_unlock(&dbs_mutex); 632 mutex_unlock(&dbs_mutex);
560 633
@@ -571,6 +644,7 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
571 this_dbs_info->cur_policy, 644 this_dbs_info->cur_policy,
572 policy->min, CPUFREQ_RELATION_L); 645 policy->min, CPUFREQ_RELATION_L);
573 mutex_unlock(&dbs_mutex); 646 mutex_unlock(&dbs_mutex);
647
574 break; 648 break;
575 } 649 }
576 return 0; 650 return 0;
@@ -588,23 +662,33 @@ struct cpufreq_governor cpufreq_gov_conservative = {
588 662
589static int __init cpufreq_gov_dbs_init(void) 663static int __init cpufreq_gov_dbs_init(void)
590{ 664{
591 return cpufreq_register_governor(&cpufreq_gov_conservative); 665 int err;
666
667 kconservative_wq = create_workqueue("kconservative");
668 if (!kconservative_wq) {
669 printk(KERN_ERR "Creation of kconservative failed\n");
670 return -EFAULT;
671 }
672
673 err = cpufreq_register_governor(&cpufreq_gov_conservative);
674 if (err)
675 destroy_workqueue(kconservative_wq);
676
677 return err;
592} 678}
593 679
594static void __exit cpufreq_gov_dbs_exit(void) 680static void __exit cpufreq_gov_dbs_exit(void)
595{ 681{
596 /* Make sure that the scheduled work is indeed not running */
597 flush_scheduled_work();
598
599 cpufreq_unregister_governor(&cpufreq_gov_conservative); 682 cpufreq_unregister_governor(&cpufreq_gov_conservative);
683 destroy_workqueue(kconservative_wq);
600} 684}
601 685
602 686
603MODULE_AUTHOR ("Alexander Clouter <alex-kernel@digriz.org.uk>"); 687MODULE_AUTHOR("Alexander Clouter <alex@digriz.org.uk>");
604MODULE_DESCRIPTION ("'cpufreq_conservative' - A dynamic cpufreq governor for " 688MODULE_DESCRIPTION("'cpufreq_conservative' - A dynamic cpufreq governor for "
605 "Low Latency Frequency Transition capable processors " 689 "Low Latency Frequency Transition capable processors "
606 "optimised for use in a battery environment"); 690 "optimised for use in a battery environment");
607MODULE_LICENSE ("GPL"); 691MODULE_LICENSE("GPL");
608 692
609#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE 693#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE
610fs_initcall(cpufreq_gov_dbs_init); 694fs_initcall(cpufreq_gov_dbs_init);
diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
index 6f45b1658a67..338f428a15b7 100644
--- a/drivers/cpufreq/cpufreq_ondemand.c
+++ b/drivers/cpufreq/cpufreq_ondemand.c
@@ -21,6 +21,7 @@
21#include <linux/hrtimer.h> 21#include <linux/hrtimer.h>
22#include <linux/tick.h> 22#include <linux/tick.h>
23#include <linux/ktime.h> 23#include <linux/ktime.h>
24#include <linux/sched.h>
24 25
25/* 26/*
26 * dbs is used in this file as a shortform for demandbased switching 27 * dbs is used in this file as a shortform for demandbased switching
@@ -51,8 +52,20 @@ static unsigned int def_sampling_rate;
51 (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10)) 52 (MIN_SAMPLING_RATE_RATIO * jiffies_to_usecs(10))
52#define MIN_SAMPLING_RATE \ 53#define MIN_SAMPLING_RATE \
53 (def_sampling_rate / MIN_SAMPLING_RATE_RATIO) 54 (def_sampling_rate / MIN_SAMPLING_RATE_RATIO)
55/* Above MIN_SAMPLING_RATE will vanish with its sysfs file soon
56 * Define the minimal settable sampling rate to the greater of:
57 * - "HW transition latency" * 100 (same as default sampling / 10)
58 * - MIN_STAT_SAMPLING_RATE
59 * To avoid that userspace shoots itself.
60*/
61static unsigned int minimum_sampling_rate(void)
62{
63 return max(def_sampling_rate / 10, MIN_STAT_SAMPLING_RATE);
64}
65
66/* This will also vanish soon with removing sampling_rate_max */
54#define MAX_SAMPLING_RATE (500 * def_sampling_rate) 67#define MAX_SAMPLING_RATE (500 * def_sampling_rate)
55#define DEF_SAMPLING_RATE_LATENCY_MULTIPLIER (1000) 68#define LATENCY_MULTIPLIER (1000)
56#define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000) 69#define TRANSITION_LATENCY_LIMIT (10 * 1000 * 1000)
57 70
58static void do_dbs_timer(struct work_struct *work); 71static void do_dbs_timer(struct work_struct *work);
@@ -65,14 +78,14 @@ struct cpu_dbs_info_s {
65 cputime64_t prev_cpu_wall; 78 cputime64_t prev_cpu_wall;
66 cputime64_t prev_cpu_nice; 79 cputime64_t prev_cpu_nice;
67 struct cpufreq_policy *cur_policy; 80 struct cpufreq_policy *cur_policy;
68 struct delayed_work work; 81 struct delayed_work work;
69 struct cpufreq_frequency_table *freq_table; 82 struct cpufreq_frequency_table *freq_table;
70 unsigned int freq_lo; 83 unsigned int freq_lo;
71 unsigned int freq_lo_jiffies; 84 unsigned int freq_lo_jiffies;
72 unsigned int freq_hi_jiffies; 85 unsigned int freq_hi_jiffies;
73 int cpu; 86 int cpu;
74 unsigned int enable:1, 87 unsigned int enable:1,
75 sample_type:1; 88 sample_type:1;
76}; 89};
77static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info); 90static DEFINE_PER_CPU(struct cpu_dbs_info_s, cpu_dbs_info);
78 91
@@ -203,12 +216,28 @@ static void ondemand_powersave_bias_init(void)
203/************************** sysfs interface ************************/ 216/************************** sysfs interface ************************/
204static ssize_t show_sampling_rate_max(struct cpufreq_policy *policy, char *buf) 217static ssize_t show_sampling_rate_max(struct cpufreq_policy *policy, char *buf)
205{ 218{
206 return sprintf (buf, "%u\n", MAX_SAMPLING_RATE); 219 static int print_once;
220
221 if (!print_once) {
222 printk(KERN_INFO "CPUFREQ: ondemand sampling_rate_max "
223 "sysfs file is deprecated - used by: %s\n",
224 current->comm);
225 print_once = 1;
226 }
227 return sprintf(buf, "%u\n", MAX_SAMPLING_RATE);
207} 228}
208 229
209static ssize_t show_sampling_rate_min(struct cpufreq_policy *policy, char *buf) 230static ssize_t show_sampling_rate_min(struct cpufreq_policy *policy, char *buf)
210{ 231{
211 return sprintf (buf, "%u\n", MIN_SAMPLING_RATE); 232 static int print_once;
233
234 if (!print_once) {
235 printk(KERN_INFO "CPUFREQ: ondemand sampling_rate_min "
236 "sysfs file is deprecated - used by: %s\n",
237 current->comm);
238 print_once = 1;
239 }
240 return sprintf(buf, "%u\n", MIN_SAMPLING_RATE);
212} 241}
213 242
214#define define_one_ro(_name) \ 243#define define_one_ro(_name) \
@@ -238,13 +267,11 @@ static ssize_t store_sampling_rate(struct cpufreq_policy *unused,
238 ret = sscanf(buf, "%u", &input); 267 ret = sscanf(buf, "%u", &input);
239 268
240 mutex_lock(&dbs_mutex); 269 mutex_lock(&dbs_mutex);
241 if (ret != 1 || input > MAX_SAMPLING_RATE 270 if (ret != 1) {
242 || input < MIN_SAMPLING_RATE) {
243 mutex_unlock(&dbs_mutex); 271 mutex_unlock(&dbs_mutex);
244 return -EINVAL; 272 return -EINVAL;
245 } 273 }
246 274 dbs_tuners_ins.sampling_rate = max(input, minimum_sampling_rate());
247 dbs_tuners_ins.sampling_rate = input;
248 mutex_unlock(&dbs_mutex); 275 mutex_unlock(&dbs_mutex);
249 276
250 return count; 277 return count;
@@ -279,14 +306,14 @@ static ssize_t store_ignore_nice_load(struct cpufreq_policy *policy,
279 unsigned int j; 306 unsigned int j;
280 307
281 ret = sscanf(buf, "%u", &input); 308 ret = sscanf(buf, "%u", &input);
282 if ( ret != 1 ) 309 if (ret != 1)
283 return -EINVAL; 310 return -EINVAL;
284 311
285 if ( input > 1 ) 312 if (input > 1)
286 input = 1; 313 input = 1;
287 314
288 mutex_lock(&dbs_mutex); 315 mutex_lock(&dbs_mutex);
289 if ( input == dbs_tuners_ins.ignore_nice ) { /* nothing to do */ 316 if (input == dbs_tuners_ins.ignore_nice) { /* nothing to do */
290 mutex_unlock(&dbs_mutex); 317 mutex_unlock(&dbs_mutex);
291 return count; 318 return count;
292 } 319 }
@@ -337,7 +364,7 @@ define_one_rw(up_threshold);
337define_one_rw(ignore_nice_load); 364define_one_rw(ignore_nice_load);
338define_one_rw(powersave_bias); 365define_one_rw(powersave_bias);
339 366
340static struct attribute * dbs_attributes[] = { 367static struct attribute *dbs_attributes[] = {
341 &sampling_rate_max.attr, 368 &sampling_rate_max.attr,
342 &sampling_rate_min.attr, 369 &sampling_rate_min.attr,
343 &sampling_rate.attr, 370 &sampling_rate.attr,
@@ -512,8 +539,7 @@ static void do_dbs_timer(struct work_struct *work)
512 } 539 }
513 } else { 540 } else {
514 __cpufreq_driver_target(dbs_info->cur_policy, 541 __cpufreq_driver_target(dbs_info->cur_policy,
515 dbs_info->freq_lo, 542 dbs_info->freq_lo, CPUFREQ_RELATION_H);
516 CPUFREQ_RELATION_H);
517 } 543 }
518 queue_delayed_work_on(cpu, kondemand_wq, &dbs_info->work, delay); 544 queue_delayed_work_on(cpu, kondemand_wq, &dbs_info->work, delay);
519 unlock_policy_rwsem_write(cpu); 545 unlock_policy_rwsem_write(cpu);
@@ -530,7 +556,7 @@ static inline void dbs_timer_init(struct cpu_dbs_info_s *dbs_info)
530 dbs_info->sample_type = DBS_NORMAL_SAMPLE; 556 dbs_info->sample_type = DBS_NORMAL_SAMPLE;
531 INIT_DELAYED_WORK_DEFERRABLE(&dbs_info->work, do_dbs_timer); 557 INIT_DELAYED_WORK_DEFERRABLE(&dbs_info->work, do_dbs_timer);
532 queue_delayed_work_on(dbs_info->cpu, kondemand_wq, &dbs_info->work, 558 queue_delayed_work_on(dbs_info->cpu, kondemand_wq, &dbs_info->work,
533 delay); 559 delay);
534} 560}
535 561
536static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info) 562static inline void dbs_timer_exit(struct cpu_dbs_info_s *dbs_info)
@@ -591,11 +617,9 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
591 if (latency == 0) 617 if (latency == 0)
592 latency = 1; 618 latency = 1;
593 619
594 def_sampling_rate = latency * 620 def_sampling_rate =
595 DEF_SAMPLING_RATE_LATENCY_MULTIPLIER; 621 max(latency * LATENCY_MULTIPLIER,
596 622 MIN_STAT_SAMPLING_RATE);
597 if (def_sampling_rate < MIN_STAT_SAMPLING_RATE)
598 def_sampling_rate = MIN_STAT_SAMPLING_RATE;
599 623
600 dbs_tuners_ins.sampling_rate = def_sampling_rate; 624 dbs_tuners_ins.sampling_rate = def_sampling_rate;
601 } 625 }
@@ -617,12 +641,10 @@ static int cpufreq_governor_dbs(struct cpufreq_policy *policy,
617 mutex_lock(&dbs_mutex); 641 mutex_lock(&dbs_mutex);
618 if (policy->max < this_dbs_info->cur_policy->cur) 642 if (policy->max < this_dbs_info->cur_policy->cur)
619 __cpufreq_driver_target(this_dbs_info->cur_policy, 643 __cpufreq_driver_target(this_dbs_info->cur_policy,
620 policy->max, 644 policy->max, CPUFREQ_RELATION_H);
621 CPUFREQ_RELATION_H);
622 else if (policy->min > this_dbs_info->cur_policy->cur) 645 else if (policy->min > this_dbs_info->cur_policy->cur)
623 __cpufreq_driver_target(this_dbs_info->cur_policy, 646 __cpufreq_driver_target(this_dbs_info->cur_policy,
624 policy->min, 647 policy->min, CPUFREQ_RELATION_L);
625 CPUFREQ_RELATION_L);
626 mutex_unlock(&dbs_mutex); 648 mutex_unlock(&dbs_mutex);
627 break; 649 break;
628 } 650 }
@@ -677,7 +699,7 @@ static void __exit cpufreq_gov_dbs_exit(void)
677MODULE_AUTHOR("Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>"); 699MODULE_AUTHOR("Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>");
678MODULE_AUTHOR("Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>"); 700MODULE_AUTHOR("Alexey Starikovskiy <alexey.y.starikovskiy@intel.com>");
679MODULE_DESCRIPTION("'cpufreq_ondemand' - A dynamic cpufreq governor for " 701MODULE_DESCRIPTION("'cpufreq_ondemand' - A dynamic cpufreq governor for "
680 "Low Latency Frequency Transition capable processors"); 702 "Low Latency Frequency Transition capable processors");
681MODULE_LICENSE("GPL"); 703MODULE_LICENSE("GPL");
682 704
683#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND 705#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND
diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
index c0ff97d375d7..5a62d678dd19 100644
--- a/drivers/cpufreq/cpufreq_stats.c
+++ b/drivers/cpufreq/cpufreq_stats.c
@@ -2,7 +2,7 @@
2 * drivers/cpufreq/cpufreq_stats.c 2 * drivers/cpufreq/cpufreq_stats.c
3 * 3 *
4 * Copyright (C) 2003-2004 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>. 4 * Copyright (C) 2003-2004 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>.
5 * (C) 2004 Zou Nan hai <nanhai.zou@intel.com>. 5 * (C) 2004 Zou Nan hai <nanhai.zou@intel.com>.
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 8 * it under the terms of the GNU General Public License version 2 as
@@ -23,7 +23,7 @@
23 23
24static spinlock_t cpufreq_stats_lock; 24static spinlock_t cpufreq_stats_lock;
25 25
26#define CPUFREQ_STATDEVICE_ATTR(_name,_mode,_show) \ 26#define CPUFREQ_STATDEVICE_ATTR(_name, _mode, _show) \
27static struct freq_attr _attr_##_name = {\ 27static struct freq_attr _attr_##_name = {\
28 .attr = {.name = __stringify(_name), .mode = _mode, }, \ 28 .attr = {.name = __stringify(_name), .mode = _mode, }, \
29 .show = _show,\ 29 .show = _show,\
@@ -50,8 +50,7 @@ struct cpufreq_stats_attribute {
50 ssize_t(*show) (struct cpufreq_stats *, char *); 50 ssize_t(*show) (struct cpufreq_stats *, char *);
51}; 51};
52 52
53static int 53static int cpufreq_stats_update(unsigned int cpu)
54cpufreq_stats_update (unsigned int cpu)
55{ 54{
56 struct cpufreq_stats *stat; 55 struct cpufreq_stats *stat;
57 unsigned long long cur_time; 56 unsigned long long cur_time;
@@ -68,8 +67,7 @@ cpufreq_stats_update (unsigned int cpu)
68 return 0; 67 return 0;
69} 68}
70 69
71static ssize_t 70static ssize_t show_total_trans(struct cpufreq_policy *policy, char *buf)
72show_total_trans(struct cpufreq_policy *policy, char *buf)
73{ 71{
74 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu); 72 struct cpufreq_stats *stat = per_cpu(cpufreq_stats_table, policy->cpu);
75 if (!stat) 73 if (!stat)
@@ -78,8 +76,7 @@ show_total_trans(struct cpufreq_policy *policy, char *buf)
78 per_cpu(cpufreq_stats_table, stat->cpu)->total_trans); 76 per_cpu(cpufreq_stats_table, stat->cpu)->total_trans);
79} 77}
80 78
81static ssize_t 79static ssize_t show_time_in_state(struct cpufreq_policy *policy, char *buf)
82show_time_in_state(struct cpufreq_policy *policy, char *buf)
83{ 80{
84 ssize_t len = 0; 81 ssize_t len = 0;
85 int i; 82 int i;
@@ -89,14 +86,14 @@ show_time_in_state(struct cpufreq_policy *policy, char *buf)
89 cpufreq_stats_update(stat->cpu); 86 cpufreq_stats_update(stat->cpu);
90 for (i = 0; i < stat->state_num; i++) { 87 for (i = 0; i < stat->state_num; i++) {
91 len += sprintf(buf + len, "%u %llu\n", stat->freq_table[i], 88 len += sprintf(buf + len, "%u %llu\n", stat->freq_table[i],
92 (unsigned long long)cputime64_to_clock_t(stat->time_in_state[i])); 89 (unsigned long long)
90 cputime64_to_clock_t(stat->time_in_state[i]));
93 } 91 }
94 return len; 92 return len;
95} 93}
96 94
97#ifdef CONFIG_CPU_FREQ_STAT_DETAILS 95#ifdef CONFIG_CPU_FREQ_STAT_DETAILS
98static ssize_t 96static ssize_t show_trans_table(struct cpufreq_policy *policy, char *buf)
99show_trans_table(struct cpufreq_policy *policy, char *buf)
100{ 97{
101 ssize_t len = 0; 98 ssize_t len = 0;
102 int i, j; 99 int i, j;
@@ -139,11 +136,11 @@ show_trans_table(struct cpufreq_policy *policy, char *buf)
139 return PAGE_SIZE; 136 return PAGE_SIZE;
140 return len; 137 return len;
141} 138}
142CPUFREQ_STATDEVICE_ATTR(trans_table,0444,show_trans_table); 139CPUFREQ_STATDEVICE_ATTR(trans_table, 0444, show_trans_table);
143#endif 140#endif
144 141
145CPUFREQ_STATDEVICE_ATTR(total_trans,0444,show_total_trans); 142CPUFREQ_STATDEVICE_ATTR(total_trans, 0444, show_total_trans);
146CPUFREQ_STATDEVICE_ATTR(time_in_state,0444,show_time_in_state); 143CPUFREQ_STATDEVICE_ATTR(time_in_state, 0444, show_time_in_state);
147 144
148static struct attribute *default_attrs[] = { 145static struct attribute *default_attrs[] = {
149 &_attr_total_trans.attr, 146 &_attr_total_trans.attr,
@@ -158,8 +155,7 @@ static struct attribute_group stats_attr_group = {
158 .name = "stats" 155 .name = "stats"
159}; 156};
160 157
161static int 158static int freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq)
162freq_table_get_index(struct cpufreq_stats *stat, unsigned int freq)
163{ 159{
164 int index; 160 int index;
165 for (index = 0; index < stat->max_state; index++) 161 for (index = 0; index < stat->max_state; index++)
@@ -183,8 +179,7 @@ static void cpufreq_stats_free_table(unsigned int cpu)
183 cpufreq_cpu_put(policy); 179 cpufreq_cpu_put(policy);
184} 180}
185 181
186static int 182static int cpufreq_stats_create_table(struct cpufreq_policy *policy,
187cpufreq_stats_create_table (struct cpufreq_policy *policy,
188 struct cpufreq_frequency_table *table) 183 struct cpufreq_frequency_table *table)
189{ 184{
190 unsigned int i, j, count = 0, ret = 0; 185 unsigned int i, j, count = 0, ret = 0;
@@ -194,7 +189,8 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy,
194 unsigned int cpu = policy->cpu; 189 unsigned int cpu = policy->cpu;
195 if (per_cpu(cpufreq_stats_table, cpu)) 190 if (per_cpu(cpufreq_stats_table, cpu))
196 return -EBUSY; 191 return -EBUSY;
197 if ((stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL)) == NULL) 192 stat = kzalloc(sizeof(struct cpufreq_stats), GFP_KERNEL);
193 if ((stat) == NULL)
198 return -ENOMEM; 194 return -ENOMEM;
199 195
200 data = cpufreq_cpu_get(cpu); 196 data = cpufreq_cpu_get(cpu);
@@ -203,13 +199,14 @@ cpufreq_stats_create_table (struct cpufreq_policy *policy,
203 goto error_get_fail; 199 goto error_get_fail;
204 } 200 }
205 201
206 if ((ret = sysfs_create_group(&data->kobj, &stats_attr_group))) 202 ret = sysfs_create_group(&data->kobj, &stats_attr_group);
203 if (ret)
207 goto error_out; 204 goto error_out;
208 205
209 stat->cpu = cpu; 206 stat->cpu = cpu;
210 per_cpu(cpufreq_stats_table, cpu) = stat; 207 per_cpu(cpufreq_stats_table, cpu) = stat;
211 208
212 for (i=0; table[i].frequency != CPUFREQ_TABLE_END; i++) { 209 for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {
213 unsigned int freq = table[i].frequency; 210 unsigned int freq = table[i].frequency;
214 if (freq == CPUFREQ_ENTRY_INVALID) 211 if (freq == CPUFREQ_ENTRY_INVALID)
215 continue; 212 continue;
@@ -255,9 +252,8 @@ error_get_fail:
255 return ret; 252 return ret;
256} 253}
257 254
258static int 255static int cpufreq_stat_notifier_policy(struct notifier_block *nb,
259cpufreq_stat_notifier_policy (struct notifier_block *nb, unsigned long val, 256 unsigned long val, void *data)
260 void *data)
261{ 257{
262 int ret; 258 int ret;
263 struct cpufreq_policy *policy = data; 259 struct cpufreq_policy *policy = data;
@@ -268,14 +264,14 @@ cpufreq_stat_notifier_policy (struct notifier_block *nb, unsigned long val,
268 table = cpufreq_frequency_get_table(cpu); 264 table = cpufreq_frequency_get_table(cpu);
269 if (!table) 265 if (!table)
270 return 0; 266 return 0;
271 if ((ret = cpufreq_stats_create_table(policy, table))) 267 ret = cpufreq_stats_create_table(policy, table);
268 if (ret)
272 return ret; 269 return ret;
273 return 0; 270 return 0;
274} 271}
275 272
276static int 273static int cpufreq_stat_notifier_trans(struct notifier_block *nb,
277cpufreq_stat_notifier_trans (struct notifier_block *nb, unsigned long val, 274 unsigned long val, void *data)
278 void *data)
279{ 275{
280 struct cpufreq_freqs *freq = data; 276 struct cpufreq_freqs *freq = data;
281 struct cpufreq_stats *stat; 277 struct cpufreq_stats *stat;
@@ -340,19 +336,20 @@ static struct notifier_block notifier_trans_block = {
340 .notifier_call = cpufreq_stat_notifier_trans 336 .notifier_call = cpufreq_stat_notifier_trans
341}; 337};
342 338
343static int 339static int __init cpufreq_stats_init(void)
344__init cpufreq_stats_init(void)
345{ 340{
346 int ret; 341 int ret;
347 unsigned int cpu; 342 unsigned int cpu;
348 343
349 spin_lock_init(&cpufreq_stats_lock); 344 spin_lock_init(&cpufreq_stats_lock);
350 if ((ret = cpufreq_register_notifier(&notifier_policy_block, 345 ret = cpufreq_register_notifier(&notifier_policy_block,
351 CPUFREQ_POLICY_NOTIFIER))) 346 CPUFREQ_POLICY_NOTIFIER);
347 if (ret)
352 return ret; 348 return ret;
353 349
354 if ((ret = cpufreq_register_notifier(&notifier_trans_block, 350 ret = cpufreq_register_notifier(&notifier_trans_block,
355 CPUFREQ_TRANSITION_NOTIFIER))) { 351 CPUFREQ_TRANSITION_NOTIFIER);
352 if (ret) {
356 cpufreq_unregister_notifier(&notifier_policy_block, 353 cpufreq_unregister_notifier(&notifier_policy_block,
357 CPUFREQ_POLICY_NOTIFIER); 354 CPUFREQ_POLICY_NOTIFIER);
358 return ret; 355 return ret;
@@ -364,8 +361,7 @@ __init cpufreq_stats_init(void)
364 } 361 }
365 return 0; 362 return 0;
366} 363}
367static void 364static void __exit cpufreq_stats_exit(void)
368__exit cpufreq_stats_exit(void)
369{ 365{
370 unsigned int cpu; 366 unsigned int cpu;
371 367
@@ -379,10 +375,10 @@ __exit cpufreq_stats_exit(void)
379 } 375 }
380} 376}
381 377
382MODULE_AUTHOR ("Zou Nan hai <nanhai.zou@intel.com>"); 378MODULE_AUTHOR("Zou Nan hai <nanhai.zou@intel.com>");
383MODULE_DESCRIPTION ("'cpufreq_stats' - A driver to export cpufreq stats " 379MODULE_DESCRIPTION("'cpufreq_stats' - A driver to export cpufreq stats "
384 "through sysfs filesystem"); 380 "through sysfs filesystem");
385MODULE_LICENSE ("GPL"); 381MODULE_LICENSE("GPL");
386 382
387module_init(cpufreq_stats_init); 383module_init(cpufreq_stats_init);
388module_exit(cpufreq_stats_exit); 384module_exit(cpufreq_stats_exit);
diff --git a/drivers/cpufreq/cpufreq_userspace.c b/drivers/cpufreq/cpufreq_userspace.c
index 1442bbada053..66d2d1d6c80f 100644
--- a/drivers/cpufreq/cpufreq_userspace.c
+++ b/drivers/cpufreq/cpufreq_userspace.c
@@ -24,9 +24,6 @@
24#include <linux/sysfs.h> 24#include <linux/sysfs.h>
25#include <linux/mutex.h> 25#include <linux/mutex.h>
26 26
27#include <asm/uaccess.h>
28
29
30/** 27/**
31 * A few values needed by the userspace governor 28 * A few values needed by the userspace governor
32 */ 29 */
@@ -37,7 +34,7 @@ static DEFINE_PER_CPU(unsigned int, cpu_set_freq); /* CPU freq desired by
37 userspace */ 34 userspace */
38static DEFINE_PER_CPU(unsigned int, cpu_is_managed); 35static DEFINE_PER_CPU(unsigned int, cpu_is_managed);
39 36
40static DEFINE_MUTEX (userspace_mutex); 37static DEFINE_MUTEX(userspace_mutex);
41static int cpus_using_userspace_governor; 38static int cpus_using_userspace_governor;
42 39
43#define dprintk(msg...) \ 40#define dprintk(msg...) \
@@ -46,9 +43,9 @@ static int cpus_using_userspace_governor;
46/* keep track of frequency transitions */ 43/* keep track of frequency transitions */
47static int 44static int
48userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val, 45userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
49 void *data) 46 void *data)
50{ 47{
51 struct cpufreq_freqs *freq = data; 48 struct cpufreq_freqs *freq = data;
52 49
53 if (!per_cpu(cpu_is_managed, freq->cpu)) 50 if (!per_cpu(cpu_is_managed, freq->cpu))
54 return 0; 51 return 0;
@@ -57,11 +54,11 @@ userspace_cpufreq_notifier(struct notifier_block *nb, unsigned long val,
57 freq->cpu, freq->new); 54 freq->cpu, freq->new);
58 per_cpu(cpu_cur_freq, freq->cpu) = freq->new; 55 per_cpu(cpu_cur_freq, freq->cpu) = freq->new;
59 56
60 return 0; 57 return 0;
61} 58}
62 59
63static struct notifier_block userspace_cpufreq_notifier_block = { 60static struct notifier_block userspace_cpufreq_notifier_block = {
64 .notifier_call = userspace_cpufreq_notifier 61 .notifier_call = userspace_cpufreq_notifier
65}; 62};
66 63
67 64
@@ -93,8 +90,11 @@ static int cpufreq_set(struct cpufreq_policy *policy, unsigned int freq)
93 * We're safe from concurrent calls to ->target() here 90 * We're safe from concurrent calls to ->target() here
94 * as we hold the userspace_mutex lock. If we were calling 91 * as we hold the userspace_mutex lock. If we were calling
95 * cpufreq_driver_target, a deadlock situation might occur: 92 * cpufreq_driver_target, a deadlock situation might occur:
96 * A: cpufreq_set (lock userspace_mutex) -> cpufreq_driver_target(lock policy->lock) 93 * A: cpufreq_set (lock userspace_mutex) ->
97 * B: cpufreq_set_policy(lock policy->lock) -> __cpufreq_governor -> cpufreq_governor_userspace (lock userspace_mutex) 94 * cpufreq_driver_target(lock policy->lock)
95 * B: cpufreq_set_policy(lock policy->lock) ->
96 * __cpufreq_governor ->
97 * cpufreq_governor_userspace (lock userspace_mutex)
98 */ 98 */
99 ret = __cpufreq_driver_target(policy, freq, CPUFREQ_RELATION_L); 99 ret = __cpufreq_driver_target(policy, freq, CPUFREQ_RELATION_L);
100 100
@@ -210,9 +210,10 @@ static void __exit cpufreq_gov_userspace_exit(void)
210} 210}
211 211
212 212
213MODULE_AUTHOR ("Dominik Brodowski <linux@brodo.de>, Russell King <rmk@arm.linux.org.uk>"); 213MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>, "
214MODULE_DESCRIPTION ("CPUfreq policy governor 'userspace'"); 214 "Russell King <rmk@arm.linux.org.uk>");
215MODULE_LICENSE ("GPL"); 215MODULE_DESCRIPTION("CPUfreq policy governor 'userspace'");
216MODULE_LICENSE("GPL");
216 217
217#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE 218#ifdef CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE
218fs_initcall(cpufreq_gov_userspace_init); 219fs_initcall(cpufreq_gov_userspace_init);
diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index 9071d80fbba2..a9bd3a05a684 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -28,7 +28,7 @@ int cpufreq_frequency_table_cpuinfo(struct cpufreq_policy *policy,
28 unsigned int max_freq = 0; 28 unsigned int max_freq = 0;
29 unsigned int i; 29 unsigned int i;
30 30
31 for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 31 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
32 unsigned int freq = table[i].frequency; 32 unsigned int freq = table[i].frequency;
33 if (freq == CPUFREQ_ENTRY_INVALID) { 33 if (freq == CPUFREQ_ENTRY_INVALID) {
34 dprintk("table entry %u is invalid, skipping\n", i); 34 dprintk("table entry %u is invalid, skipping\n", i);
@@ -70,7 +70,7 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy *policy,
70 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq, 70 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
71 policy->cpuinfo.max_freq); 71 policy->cpuinfo.max_freq);
72 72
73 for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 73 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
74 unsigned int freq = table[i].frequency; 74 unsigned int freq = table[i].frequency;
75 if (freq == CPUFREQ_ENTRY_INVALID) 75 if (freq == CPUFREQ_ENTRY_INVALID)
76 continue; 76 continue;
@@ -125,13 +125,13 @@ int cpufreq_frequency_table_target(struct cpufreq_policy *policy,
125 if (!cpu_online(policy->cpu)) 125 if (!cpu_online(policy->cpu))
126 return -EINVAL; 126 return -EINVAL;
127 127
128 for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 128 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
129 unsigned int freq = table[i].frequency; 129 unsigned int freq = table[i].frequency;
130 if (freq == CPUFREQ_ENTRY_INVALID) 130 if (freq == CPUFREQ_ENTRY_INVALID)
131 continue; 131 continue;
132 if ((freq < policy->min) || (freq > policy->max)) 132 if ((freq < policy->min) || (freq > policy->max))
133 continue; 133 continue;
134 switch(relation) { 134 switch (relation) {
135 case CPUFREQ_RELATION_H: 135 case CPUFREQ_RELATION_H:
136 if (freq <= target_freq) { 136 if (freq <= target_freq) {
137 if (freq >= optimal.frequency) { 137 if (freq >= optimal.frequency) {
@@ -178,7 +178,7 @@ static DEFINE_PER_CPU(struct cpufreq_frequency_table *, show_table);
178/** 178/**
179 * show_available_freqs - show available frequencies for the specified CPU 179 * show_available_freqs - show available frequencies for the specified CPU
180 */ 180 */
181static ssize_t show_available_freqs (struct cpufreq_policy *policy, char *buf) 181static ssize_t show_available_freqs(struct cpufreq_policy *policy, char *buf)
182{ 182{
183 unsigned int i = 0; 183 unsigned int i = 0;
184 unsigned int cpu = policy->cpu; 184 unsigned int cpu = policy->cpu;
@@ -190,7 +190,7 @@ static ssize_t show_available_freqs (struct cpufreq_policy *policy, char *buf)
190 190
191 table = per_cpu(show_table, cpu); 191 table = per_cpu(show_table, cpu);
192 192
193 for (i=0; (table[i].frequency != CPUFREQ_TABLE_END); i++) { 193 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
194 if (table[i].frequency == CPUFREQ_ENTRY_INVALID) 194 if (table[i].frequency == CPUFREQ_ENTRY_INVALID)
195 continue; 195 continue;
196 count += sprintf(&buf[count], "%d ", table[i].frequency); 196 count += sprintf(&buf[count], "%d ", table[i].frequency);
@@ -234,6 +234,6 @@ struct cpufreq_frequency_table *cpufreq_frequency_get_table(unsigned int cpu)
234} 234}
235EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table); 235EXPORT_SYMBOL_GPL(cpufreq_frequency_get_table);
236 236
237MODULE_AUTHOR ("Dominik Brodowski <linux@brodo.de>"); 237MODULE_AUTHOR("Dominik Brodowski <linux@brodo.de>");
238MODULE_DESCRIPTION ("CPUfreq frequency table helpers"); 238MODULE_DESCRIPTION("CPUfreq frequency table helpers");
239MODULE_LICENSE ("GPL"); 239MODULE_LICENSE("GPL");
diff --git a/drivers/crypto/Kconfig b/drivers/crypto/Kconfig
index e522144cba3a..01afd758072f 100644
--- a/drivers/crypto/Kconfig
+++ b/drivers/crypto/Kconfig
@@ -86,7 +86,7 @@ config ZCRYPT_MONOLITHIC
86config CRYPTO_SHA1_S390 86config CRYPTO_SHA1_S390
87 tristate "SHA1 digest algorithm" 87 tristate "SHA1 digest algorithm"
88 depends on S390 88 depends on S390
89 select CRYPTO_ALGAPI 89 select CRYPTO_HASH
90 help 90 help
91 This is the s390 hardware accelerated implementation of the 91 This is the s390 hardware accelerated implementation of the
92 SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2). 92 SHA-1 secure hash standard (FIPS 180-1/DFIPS 180-2).
@@ -94,7 +94,7 @@ config CRYPTO_SHA1_S390
94config CRYPTO_SHA256_S390 94config CRYPTO_SHA256_S390
95 tristate "SHA256 digest algorithm" 95 tristate "SHA256 digest algorithm"
96 depends on S390 96 depends on S390
97 select CRYPTO_ALGAPI 97 select CRYPTO_HASH
98 help 98 help
99 This is the s390 hardware accelerated implementation of the 99 This is the s390 hardware accelerated implementation of the
100 SHA256 secure hash standard (DFIPS 180-2). 100 SHA256 secure hash standard (DFIPS 180-2).
@@ -105,7 +105,7 @@ config CRYPTO_SHA256_S390
105config CRYPTO_SHA512_S390 105config CRYPTO_SHA512_S390
106 tristate "SHA384 and SHA512 digest algorithm" 106 tristate "SHA384 and SHA512 digest algorithm"
107 depends on S390 107 depends on S390
108 select CRYPTO_ALGAPI 108 select CRYPTO_HASH
109 help 109 help
110 This is the s390 hardware accelerated implementation of the 110 This is the s390 hardware accelerated implementation of the
111 SHA512 secure hash standard. 111 SHA512 secure hash standard.
@@ -200,4 +200,13 @@ config CRYPTO_DEV_IXP4XX
200 help 200 help
201 Driver for the IXP4xx NPE crypto engine. 201 Driver for the IXP4xx NPE crypto engine.
202 202
203config CRYPTO_DEV_PPC4XX
204 tristate "Driver AMCC PPC4xx crypto accelerator"
205 depends on PPC && 4xx
206 select CRYPTO_HASH
207 select CRYPTO_ALGAPI
208 select CRYPTO_BLKCIPHER
209 help
210 This option allows you to have support for AMCC crypto acceleration.
211
203endif # CRYPTO_HW 212endif # CRYPTO_HW
diff --git a/drivers/crypto/Makefile b/drivers/crypto/Makefile
index 73557b2968d3..9bf4a2bc8846 100644
--- a/drivers/crypto/Makefile
+++ b/drivers/crypto/Makefile
@@ -4,3 +4,4 @@ obj-$(CONFIG_CRYPTO_DEV_GEODE) += geode-aes.o
4obj-$(CONFIG_CRYPTO_DEV_HIFN_795X) += hifn_795x.o 4obj-$(CONFIG_CRYPTO_DEV_HIFN_795X) += hifn_795x.o
5obj-$(CONFIG_CRYPTO_DEV_TALITOS) += talitos.o 5obj-$(CONFIG_CRYPTO_DEV_TALITOS) += talitos.o
6obj-$(CONFIG_CRYPTO_DEV_IXP4XX) += ixp4xx_crypto.o 6obj-$(CONFIG_CRYPTO_DEV_IXP4XX) += ixp4xx_crypto.o
7obj-$(CONFIG_CRYPTO_DEV_PPC4XX) += amcc/
diff --git a/drivers/crypto/amcc/Makefile b/drivers/crypto/amcc/Makefile
new file mode 100644
index 000000000000..aa376e8d5ed5
--- /dev/null
+++ b/drivers/crypto/amcc/Makefile
@@ -0,0 +1,2 @@
1obj-$(CONFIG_CRYPTO_DEV_PPC4XX) += crypto4xx.o
2crypto4xx-objs := crypto4xx_core.o crypto4xx_alg.o crypto4xx_sa.o
diff --git a/drivers/crypto/amcc/crypto4xx_alg.c b/drivers/crypto/amcc/crypto4xx_alg.c
new file mode 100644
index 000000000000..61b6e1bec8c6
--- /dev/null
+++ b/drivers/crypto/amcc/crypto4xx_alg.c
@@ -0,0 +1,293 @@
1/**
2 * AMCC SoC PPC4xx Crypto Driver
3 *
4 * Copyright (c) 2008 Applied Micro Circuits Corporation.
5 * All rights reserved. James Hsiao <jhsiao@amcc.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * This file implements the Linux crypto algorithms.
18 */
19
20#include <linux/kernel.h>
21#include <linux/interrupt.h>
22#include <linux/spinlock_types.h>
23#include <linux/scatterlist.h>
24#include <linux/crypto.h>
25#include <linux/hash.h>
26#include <crypto/internal/hash.h>
27#include <linux/dma-mapping.h>
28#include <crypto/algapi.h>
29#include <crypto/aes.h>
30#include <crypto/sha.h>
31#include "crypto4xx_reg_def.h"
32#include "crypto4xx_sa.h"
33#include "crypto4xx_core.h"
34
35void set_dynamic_sa_command_0(struct dynamic_sa_ctl *sa, u32 save_h,
36 u32 save_iv, u32 ld_h, u32 ld_iv, u32 hdr_proc,
37 u32 h, u32 c, u32 pad_type, u32 op_grp, u32 op,
38 u32 dir)
39{
40 sa->sa_command_0.w = 0;
41 sa->sa_command_0.bf.save_hash_state = save_h;
42 sa->sa_command_0.bf.save_iv = save_iv;
43 sa->sa_command_0.bf.load_hash_state = ld_h;
44 sa->sa_command_0.bf.load_iv = ld_iv;
45 sa->sa_command_0.bf.hdr_proc = hdr_proc;
46 sa->sa_command_0.bf.hash_alg = h;
47 sa->sa_command_0.bf.cipher_alg = c;
48 sa->sa_command_0.bf.pad_type = pad_type & 3;
49 sa->sa_command_0.bf.extend_pad = pad_type >> 2;
50 sa->sa_command_0.bf.op_group = op_grp;
51 sa->sa_command_0.bf.opcode = op;
52 sa->sa_command_0.bf.dir = dir;
53}
54
55void set_dynamic_sa_command_1(struct dynamic_sa_ctl *sa, u32 cm, u32 hmac_mc,
56 u32 cfb, u32 esn, u32 sn_mask, u32 mute,
57 u32 cp_pad, u32 cp_pay, u32 cp_hdr)
58{
59 sa->sa_command_1.w = 0;
60 sa->sa_command_1.bf.crypto_mode31 = (cm & 4) >> 2;
61 sa->sa_command_1.bf.crypto_mode9_8 = cm & 3;
62 sa->sa_command_1.bf.feedback_mode = cfb,
63 sa->sa_command_1.bf.sa_rev = 1;
64 sa->sa_command_1.bf.extended_seq_num = esn;
65 sa->sa_command_1.bf.seq_num_mask = sn_mask;
66 sa->sa_command_1.bf.mutable_bit_proc = mute;
67 sa->sa_command_1.bf.copy_pad = cp_pad;
68 sa->sa_command_1.bf.copy_payload = cp_pay;
69 sa->sa_command_1.bf.copy_hdr = cp_hdr;
70}
71
72int crypto4xx_encrypt(struct ablkcipher_request *req)
73{
74 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
75
76 ctx->direction = DIR_OUTBOUND;
77 ctx->hash_final = 0;
78 ctx->is_hash = 0;
79 ctx->pd_ctl = 0x1;
80
81 return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
82 req->nbytes, req->info,
83 get_dynamic_sa_iv_size(ctx));
84}
85
86int crypto4xx_decrypt(struct ablkcipher_request *req)
87{
88 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
89
90 ctx->direction = DIR_INBOUND;
91 ctx->hash_final = 0;
92 ctx->is_hash = 0;
93 ctx->pd_ctl = 1;
94
95 return crypto4xx_build_pd(&req->base, ctx, req->src, req->dst,
96 req->nbytes, req->info,
97 get_dynamic_sa_iv_size(ctx));
98}
99
100/**
101 * AES Functions
102 */
103static int crypto4xx_setkey_aes(struct crypto_ablkcipher *cipher,
104 const u8 *key,
105 unsigned int keylen,
106 unsigned char cm,
107 u8 fb)
108{
109 struct crypto_tfm *tfm = crypto_ablkcipher_tfm(cipher);
110 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm);
111 struct dynamic_sa_ctl *sa;
112 int rc;
113
114 if (keylen != AES_KEYSIZE_256 &&
115 keylen != AES_KEYSIZE_192 && keylen != AES_KEYSIZE_128) {
116 crypto_ablkcipher_set_flags(cipher,
117 CRYPTO_TFM_RES_BAD_KEY_LEN);
118 return -EINVAL;
119 }
120
121 /* Create SA */
122 if (ctx->sa_in_dma_addr || ctx->sa_out_dma_addr)
123 crypto4xx_free_sa(ctx);
124
125 rc = crypto4xx_alloc_sa(ctx, SA_AES128_LEN + (keylen-16) / 4);
126 if (rc)
127 return rc;
128
129 if (ctx->state_record_dma_addr == 0) {
130 rc = crypto4xx_alloc_state_record(ctx);
131 if (rc) {
132 crypto4xx_free_sa(ctx);
133 return rc;
134 }
135 }
136 /* Setup SA */
137 sa = (struct dynamic_sa_ctl *) ctx->sa_in;
138 ctx->hash_final = 0;
139
140 set_dynamic_sa_command_0(sa, SA_NOT_SAVE_HASH, SA_NOT_SAVE_IV,
141 SA_LOAD_HASH_FROM_SA, SA_LOAD_IV_FROM_STATE,
142 SA_NO_HEADER_PROC, SA_HASH_ALG_NULL,
143 SA_CIPHER_ALG_AES, SA_PAD_TYPE_ZERO,
144 SA_OP_GROUP_BASIC, SA_OPCODE_DECRYPT,
145 DIR_INBOUND);
146
147 set_dynamic_sa_command_1(sa, cm, SA_HASH_MODE_HASH,
148 fb, SA_EXTENDED_SN_OFF,
149 SA_SEQ_MASK_OFF, SA_MC_ENABLE,
150 SA_NOT_COPY_PAD, SA_NOT_COPY_PAYLOAD,
151 SA_NOT_COPY_HDR);
152 crypto4xx_memcpy_le(ctx->sa_in + get_dynamic_sa_offset_key_field(ctx),
153 key, keylen);
154 sa->sa_contents = SA_AES_CONTENTS | (keylen << 2);
155 sa->sa_command_1.bf.key_len = keylen >> 3;
156 ctx->is_hash = 0;
157 ctx->direction = DIR_INBOUND;
158 memcpy(ctx->sa_in + get_dynamic_sa_offset_state_ptr_field(ctx),
159 (void *)&ctx->state_record_dma_addr, 4);
160 ctx->offset_to_sr_ptr = get_dynamic_sa_offset_state_ptr_field(ctx);
161
162 memcpy(ctx->sa_out, ctx->sa_in, ctx->sa_len * 4);
163 sa = (struct dynamic_sa_ctl *) ctx->sa_out;
164 sa->sa_command_0.bf.dir = DIR_OUTBOUND;
165
166 return 0;
167}
168
169int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher,
170 const u8 *key, unsigned int keylen)
171{
172 return crypto4xx_setkey_aes(cipher, key, keylen, CRYPTO_MODE_CBC,
173 CRYPTO_FEEDBACK_MODE_NO_FB);
174}
175
176/**
177 * HASH SHA1 Functions
178 */
179static int crypto4xx_hash_alg_init(struct crypto_tfm *tfm,
180 unsigned int sa_len,
181 unsigned char ha,
182 unsigned char hm)
183{
184 struct crypto_alg *alg = tfm->__crt_alg;
185 struct crypto4xx_alg *my_alg = crypto_alg_to_crypto4xx_alg(alg);
186 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm);
187 struct dynamic_sa_ctl *sa;
188 struct dynamic_sa_hash160 *sa_in;
189 int rc;
190
191 ctx->dev = my_alg->dev;
192 ctx->is_hash = 1;
193 ctx->hash_final = 0;
194
195 /* Create SA */
196 if (ctx->sa_in_dma_addr || ctx->sa_out_dma_addr)
197 crypto4xx_free_sa(ctx);
198
199 rc = crypto4xx_alloc_sa(ctx, sa_len);
200 if (rc)
201 return rc;
202
203 if (ctx->state_record_dma_addr == 0) {
204 crypto4xx_alloc_state_record(ctx);
205 if (!ctx->state_record_dma_addr) {
206 crypto4xx_free_sa(ctx);
207 return -ENOMEM;
208 }
209 }
210
211 tfm->crt_ahash.reqsize = sizeof(struct crypto4xx_ctx);
212 sa = (struct dynamic_sa_ctl *) ctx->sa_in;
213 set_dynamic_sa_command_0(sa, SA_SAVE_HASH, SA_NOT_SAVE_IV,
214 SA_NOT_LOAD_HASH, SA_LOAD_IV_FROM_SA,
215 SA_NO_HEADER_PROC, ha, SA_CIPHER_ALG_NULL,
216 SA_PAD_TYPE_ZERO, SA_OP_GROUP_BASIC,
217 SA_OPCODE_HASH, DIR_INBOUND);
218 set_dynamic_sa_command_1(sa, 0, SA_HASH_MODE_HASH,
219 CRYPTO_FEEDBACK_MODE_NO_FB, SA_EXTENDED_SN_OFF,
220 SA_SEQ_MASK_OFF, SA_MC_ENABLE,
221 SA_NOT_COPY_PAD, SA_NOT_COPY_PAYLOAD,
222 SA_NOT_COPY_HDR);
223 ctx->direction = DIR_INBOUND;
224 sa->sa_contents = SA_HASH160_CONTENTS;
225 sa_in = (struct dynamic_sa_hash160 *) ctx->sa_in;
226 /* Need to zero hash digest in SA */
227 memset(sa_in->inner_digest, 0, sizeof(sa_in->inner_digest));
228 memset(sa_in->outer_digest, 0, sizeof(sa_in->outer_digest));
229 sa_in->state_ptr = ctx->state_record_dma_addr;
230 ctx->offset_to_sr_ptr = get_dynamic_sa_offset_state_ptr_field(ctx);
231
232 return 0;
233}
234
235int crypto4xx_hash_init(struct ahash_request *req)
236{
237 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
238 int ds;
239 struct dynamic_sa_ctl *sa;
240
241 sa = (struct dynamic_sa_ctl *) ctx->sa_in;
242 ds = crypto_ahash_digestsize(
243 __crypto_ahash_cast(req->base.tfm));
244 sa->sa_command_0.bf.digest_len = ds >> 2;
245 sa->sa_command_0.bf.load_hash_state = SA_LOAD_HASH_FROM_SA;
246 ctx->is_hash = 1;
247 ctx->direction = DIR_INBOUND;
248
249 return 0;
250}
251
252int crypto4xx_hash_update(struct ahash_request *req)
253{
254 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
255
256 ctx->is_hash = 1;
257 ctx->hash_final = 0;
258 ctx->pd_ctl = 0x11;
259 ctx->direction = DIR_INBOUND;
260
261 return crypto4xx_build_pd(&req->base, ctx, req->src,
262 (struct scatterlist *) req->result,
263 req->nbytes, NULL, 0);
264}
265
266int crypto4xx_hash_final(struct ahash_request *req)
267{
268 return 0;
269}
270
271int crypto4xx_hash_digest(struct ahash_request *req)
272{
273 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
274
275 ctx->hash_final = 1;
276 ctx->pd_ctl = 0x11;
277 ctx->direction = DIR_INBOUND;
278
279 return crypto4xx_build_pd(&req->base, ctx, req->src,
280 (struct scatterlist *) req->result,
281 req->nbytes, NULL, 0);
282}
283
284/**
285 * SHA1 Algorithm
286 */
287int crypto4xx_sha1_alg_init(struct crypto_tfm *tfm)
288{
289 return crypto4xx_hash_alg_init(tfm, SA_HASH160_LEN, SA_HASH_ALG_SHA1,
290 SA_HASH_MODE_HASH);
291}
292
293
diff --git a/drivers/crypto/amcc/crypto4xx_core.c b/drivers/crypto/amcc/crypto4xx_core.c
new file mode 100644
index 000000000000..4c0dfb2b872e
--- /dev/null
+++ b/drivers/crypto/amcc/crypto4xx_core.c
@@ -0,0 +1,1310 @@
1/**
2 * AMCC SoC PPC4xx Crypto Driver
3 *
4 * Copyright (c) 2008 Applied Micro Circuits Corporation.
5 * All rights reserved. James Hsiao <jhsiao@amcc.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * This file implements AMCC crypto offload Linux device driver for use with
18 * Linux CryptoAPI.
19 */
20
21#include <linux/kernel.h>
22#include <linux/interrupt.h>
23#include <linux/spinlock_types.h>
24#include <linux/random.h>
25#include <linux/scatterlist.h>
26#include <linux/crypto.h>
27#include <linux/dma-mapping.h>
28#include <linux/platform_device.h>
29#include <linux/init.h>
30#include <linux/of_platform.h>
31#include <asm/dcr.h>
32#include <asm/dcr-regs.h>
33#include <asm/cacheflush.h>
34#include <crypto/internal/hash.h>
35#include <crypto/algapi.h>
36#include <crypto/aes.h>
37#include <crypto/sha.h>
38#include "crypto4xx_reg_def.h"
39#include "crypto4xx_core.h"
40#include "crypto4xx_sa.h"
41
42#define PPC4XX_SEC_VERSION_STR "0.5"
43
44/**
45 * PPC4xx Crypto Engine Initialization Routine
46 */
47static void crypto4xx_hw_init(struct crypto4xx_device *dev)
48{
49 union ce_ring_size ring_size;
50 union ce_ring_contol ring_ctrl;
51 union ce_part_ring_size part_ring_size;
52 union ce_io_threshold io_threshold;
53 u32 rand_num;
54 union ce_pe_dma_cfg pe_dma_cfg;
55
56 writel(PPC4XX_BYTE_ORDER, dev->ce_base + CRYPTO4XX_BYTE_ORDER_CFG);
57 /* setup pe dma, include reset sg, pdr and pe, then release reset */
58 pe_dma_cfg.w = 0;
59 pe_dma_cfg.bf.bo_sgpd_en = 1;
60 pe_dma_cfg.bf.bo_data_en = 0;
61 pe_dma_cfg.bf.bo_sa_en = 1;
62 pe_dma_cfg.bf.bo_pd_en = 1;
63 pe_dma_cfg.bf.dynamic_sa_en = 1;
64 pe_dma_cfg.bf.reset_sg = 1;
65 pe_dma_cfg.bf.reset_pdr = 1;
66 pe_dma_cfg.bf.reset_pe = 1;
67 writel(pe_dma_cfg.w, dev->ce_base + CRYPTO4XX_PE_DMA_CFG);
68 /* un reset pe,sg and pdr */
69 pe_dma_cfg.bf.pe_mode = 0;
70 pe_dma_cfg.bf.reset_sg = 0;
71 pe_dma_cfg.bf.reset_pdr = 0;
72 pe_dma_cfg.bf.reset_pe = 0;
73 pe_dma_cfg.bf.bo_td_en = 0;
74 writel(pe_dma_cfg.w, dev->ce_base + CRYPTO4XX_PE_DMA_CFG);
75 writel(dev->pdr_pa, dev->ce_base + CRYPTO4XX_PDR_BASE);
76 writel(dev->pdr_pa, dev->ce_base + CRYPTO4XX_RDR_BASE);
77 writel(PPC4XX_PRNG_CTRL_AUTO_EN, dev->ce_base + CRYPTO4XX_PRNG_CTRL);
78 get_random_bytes(&rand_num, sizeof(rand_num));
79 writel(rand_num, dev->ce_base + CRYPTO4XX_PRNG_SEED_L);
80 get_random_bytes(&rand_num, sizeof(rand_num));
81 writel(rand_num, dev->ce_base + CRYPTO4XX_PRNG_SEED_H);
82 ring_size.w = 0;
83 ring_size.bf.ring_offset = PPC4XX_PD_SIZE;
84 ring_size.bf.ring_size = PPC4XX_NUM_PD;
85 writel(ring_size.w, dev->ce_base + CRYPTO4XX_RING_SIZE);
86 ring_ctrl.w = 0;
87 writel(ring_ctrl.w, dev->ce_base + CRYPTO4XX_RING_CTRL);
88 writel(PPC4XX_DC_3DES_EN, dev->ce_base + CRYPTO4XX_DEVICE_CTRL);
89 writel(dev->gdr_pa, dev->ce_base + CRYPTO4XX_GATH_RING_BASE);
90 writel(dev->sdr_pa, dev->ce_base + CRYPTO4XX_SCAT_RING_BASE);
91 part_ring_size.w = 0;
92 part_ring_size.bf.sdr_size = PPC4XX_SDR_SIZE;
93 part_ring_size.bf.gdr_size = PPC4XX_GDR_SIZE;
94 writel(part_ring_size.w, dev->ce_base + CRYPTO4XX_PART_RING_SIZE);
95 writel(PPC4XX_SD_BUFFER_SIZE, dev->ce_base + CRYPTO4XX_PART_RING_CFG);
96 io_threshold.w = 0;
97 io_threshold.bf.output_threshold = PPC4XX_OUTPUT_THRESHOLD;
98 io_threshold.bf.input_threshold = PPC4XX_INPUT_THRESHOLD;
99 writel(io_threshold.w, dev->ce_base + CRYPTO4XX_IO_THRESHOLD);
100 writel(0, dev->ce_base + CRYPTO4XX_PDR_BASE_UADDR);
101 writel(0, dev->ce_base + CRYPTO4XX_RDR_BASE_UADDR);
102 writel(0, dev->ce_base + CRYPTO4XX_PKT_SRC_UADDR);
103 writel(0, dev->ce_base + CRYPTO4XX_PKT_DEST_UADDR);
104 writel(0, dev->ce_base + CRYPTO4XX_SA_UADDR);
105 writel(0, dev->ce_base + CRYPTO4XX_GATH_RING_BASE_UADDR);
106 writel(0, dev->ce_base + CRYPTO4XX_SCAT_RING_BASE_UADDR);
107 /* un reset pe,sg and pdr */
108 pe_dma_cfg.bf.pe_mode = 1;
109 pe_dma_cfg.bf.reset_sg = 0;
110 pe_dma_cfg.bf.reset_pdr = 0;
111 pe_dma_cfg.bf.reset_pe = 0;
112 pe_dma_cfg.bf.bo_td_en = 0;
113 writel(pe_dma_cfg.w, dev->ce_base + CRYPTO4XX_PE_DMA_CFG);
114 /*clear all pending interrupt*/
115 writel(PPC4XX_INTERRUPT_CLR, dev->ce_base + CRYPTO4XX_INT_CLR);
116 writel(PPC4XX_INT_DESCR_CNT, dev->ce_base + CRYPTO4XX_INT_DESCR_CNT);
117 writel(PPC4XX_INT_DESCR_CNT, dev->ce_base + CRYPTO4XX_INT_DESCR_CNT);
118 writel(PPC4XX_INT_CFG, dev->ce_base + CRYPTO4XX_INT_CFG);
119 writel(PPC4XX_PD_DONE_INT, dev->ce_base + CRYPTO4XX_INT_EN);
120}
121
122int crypto4xx_alloc_sa(struct crypto4xx_ctx *ctx, u32 size)
123{
124 ctx->sa_in = dma_alloc_coherent(ctx->dev->core_dev->device, size * 4,
125 &ctx->sa_in_dma_addr, GFP_ATOMIC);
126 if (ctx->sa_in == NULL)
127 return -ENOMEM;
128
129 ctx->sa_out = dma_alloc_coherent(ctx->dev->core_dev->device, size * 4,
130 &ctx->sa_out_dma_addr, GFP_ATOMIC);
131 if (ctx->sa_out == NULL) {
132 dma_free_coherent(ctx->dev->core_dev->device,
133 ctx->sa_len * 4,
134 ctx->sa_in, ctx->sa_in_dma_addr);
135 return -ENOMEM;
136 }
137
138 memset(ctx->sa_in, 0, size * 4);
139 memset(ctx->sa_out, 0, size * 4);
140 ctx->sa_len = size;
141
142 return 0;
143}
144
145void crypto4xx_free_sa(struct crypto4xx_ctx *ctx)
146{
147 if (ctx->sa_in != NULL)
148 dma_free_coherent(ctx->dev->core_dev->device, ctx->sa_len * 4,
149 ctx->sa_in, ctx->sa_in_dma_addr);
150 if (ctx->sa_out != NULL)
151 dma_free_coherent(ctx->dev->core_dev->device, ctx->sa_len * 4,
152 ctx->sa_out, ctx->sa_out_dma_addr);
153
154 ctx->sa_in_dma_addr = 0;
155 ctx->sa_out_dma_addr = 0;
156 ctx->sa_len = 0;
157}
158
159u32 crypto4xx_alloc_state_record(struct crypto4xx_ctx *ctx)
160{
161 ctx->state_record = dma_alloc_coherent(ctx->dev->core_dev->device,
162 sizeof(struct sa_state_record),
163 &ctx->state_record_dma_addr, GFP_ATOMIC);
164 if (!ctx->state_record_dma_addr)
165 return -ENOMEM;
166 memset(ctx->state_record, 0, sizeof(struct sa_state_record));
167
168 return 0;
169}
170
171void crypto4xx_free_state_record(struct crypto4xx_ctx *ctx)
172{
173 if (ctx->state_record != NULL)
174 dma_free_coherent(ctx->dev->core_dev->device,
175 sizeof(struct sa_state_record),
176 ctx->state_record,
177 ctx->state_record_dma_addr);
178 ctx->state_record_dma_addr = 0;
179}
180
181/**
182 * alloc memory for the gather ring
183 * no need to alloc buf for the ring
184 * gdr_tail, gdr_head and gdr_count are initialized by this function
185 */
186static u32 crypto4xx_build_pdr(struct crypto4xx_device *dev)
187{
188 int i;
189 struct pd_uinfo *pd_uinfo;
190 dev->pdr = dma_alloc_coherent(dev->core_dev->device,
191 sizeof(struct ce_pd) * PPC4XX_NUM_PD,
192 &dev->pdr_pa, GFP_ATOMIC);
193 if (!dev->pdr)
194 return -ENOMEM;
195
196 dev->pdr_uinfo = kzalloc(sizeof(struct pd_uinfo) * PPC4XX_NUM_PD,
197 GFP_KERNEL);
198 if (!dev->pdr_uinfo) {
199 dma_free_coherent(dev->core_dev->device,
200 sizeof(struct ce_pd) * PPC4XX_NUM_PD,
201 dev->pdr,
202 dev->pdr_pa);
203 return -ENOMEM;
204 }
205 memset(dev->pdr, 0, sizeof(struct ce_pd) * PPC4XX_NUM_PD);
206 dev->shadow_sa_pool = dma_alloc_coherent(dev->core_dev->device,
207 256 * PPC4XX_NUM_PD,
208 &dev->shadow_sa_pool_pa,
209 GFP_ATOMIC);
210 if (!dev->shadow_sa_pool)
211 return -ENOMEM;
212
213 dev->shadow_sr_pool = dma_alloc_coherent(dev->core_dev->device,
214 sizeof(struct sa_state_record) * PPC4XX_NUM_PD,
215 &dev->shadow_sr_pool_pa, GFP_ATOMIC);
216 if (!dev->shadow_sr_pool)
217 return -ENOMEM;
218 for (i = 0; i < PPC4XX_NUM_PD; i++) {
219 pd_uinfo = (struct pd_uinfo *) (dev->pdr_uinfo +
220 sizeof(struct pd_uinfo) * i);
221
222 /* alloc 256 bytes which is enough for any kind of dynamic sa */
223 pd_uinfo->sa_va = dev->shadow_sa_pool + 256 * i;
224 pd_uinfo->sa_pa = dev->shadow_sa_pool_pa + 256 * i;
225
226 /* alloc state record */
227 pd_uinfo->sr_va = dev->shadow_sr_pool +
228 sizeof(struct sa_state_record) * i;
229 pd_uinfo->sr_pa = dev->shadow_sr_pool_pa +
230 sizeof(struct sa_state_record) * i;
231 }
232
233 return 0;
234}
235
236static void crypto4xx_destroy_pdr(struct crypto4xx_device *dev)
237{
238 if (dev->pdr != NULL)
239 dma_free_coherent(dev->core_dev->device,
240 sizeof(struct ce_pd) * PPC4XX_NUM_PD,
241 dev->pdr, dev->pdr_pa);
242 if (dev->shadow_sa_pool)
243 dma_free_coherent(dev->core_dev->device, 256 * PPC4XX_NUM_PD,
244 dev->shadow_sa_pool, dev->shadow_sa_pool_pa);
245 if (dev->shadow_sr_pool)
246 dma_free_coherent(dev->core_dev->device,
247 sizeof(struct sa_state_record) * PPC4XX_NUM_PD,
248 dev->shadow_sr_pool, dev->shadow_sr_pool_pa);
249
250 kfree(dev->pdr_uinfo);
251}
252
253static u32 crypto4xx_get_pd_from_pdr_nolock(struct crypto4xx_device *dev)
254{
255 u32 retval;
256 u32 tmp;
257
258 retval = dev->pdr_head;
259 tmp = (dev->pdr_head + 1) % PPC4XX_NUM_PD;
260
261 if (tmp == dev->pdr_tail)
262 return ERING_WAS_FULL;
263
264 dev->pdr_head = tmp;
265
266 return retval;
267}
268
269static u32 crypto4xx_put_pd_to_pdr(struct crypto4xx_device *dev, u32 idx)
270{
271 struct pd_uinfo *pd_uinfo;
272 unsigned long flags;
273
274 pd_uinfo = (struct pd_uinfo *)(dev->pdr_uinfo +
275 sizeof(struct pd_uinfo) * idx);
276 spin_lock_irqsave(&dev->core_dev->lock, flags);
277 if (dev->pdr_tail != PPC4XX_LAST_PD)
278 dev->pdr_tail++;
279 else
280 dev->pdr_tail = 0;
281 pd_uinfo->state = PD_ENTRY_FREE;
282 spin_unlock_irqrestore(&dev->core_dev->lock, flags);
283
284 return 0;
285}
286
287static struct ce_pd *crypto4xx_get_pdp(struct crypto4xx_device *dev,
288 dma_addr_t *pd_dma, u32 idx)
289{
290 *pd_dma = dev->pdr_pa + sizeof(struct ce_pd) * idx;
291
292 return dev->pdr + sizeof(struct ce_pd) * idx;
293}
294
295/**
296 * alloc memory for the gather ring
297 * no need to alloc buf for the ring
298 * gdr_tail, gdr_head and gdr_count are initialized by this function
299 */
300static u32 crypto4xx_build_gdr(struct crypto4xx_device *dev)
301{
302 dev->gdr = dma_alloc_coherent(dev->core_dev->device,
303 sizeof(struct ce_gd) * PPC4XX_NUM_GD,
304 &dev->gdr_pa, GFP_ATOMIC);
305 if (!dev->gdr)
306 return -ENOMEM;
307
308 memset(dev->gdr, 0, sizeof(struct ce_gd) * PPC4XX_NUM_GD);
309
310 return 0;
311}
312
313static inline void crypto4xx_destroy_gdr(struct crypto4xx_device *dev)
314{
315 dma_free_coherent(dev->core_dev->device,
316 sizeof(struct ce_gd) * PPC4XX_NUM_GD,
317 dev->gdr, dev->gdr_pa);
318}
319
320/*
321 * when this function is called.
322 * preemption or interrupt must be disabled
323 */
324u32 crypto4xx_get_n_gd(struct crypto4xx_device *dev, int n)
325{
326 u32 retval;
327 u32 tmp;
328 if (n >= PPC4XX_NUM_GD)
329 return ERING_WAS_FULL;
330
331 retval = dev->gdr_head;
332 tmp = (dev->gdr_head + n) % PPC4XX_NUM_GD;
333 if (dev->gdr_head > dev->gdr_tail) {
334 if (tmp < dev->gdr_head && tmp >= dev->gdr_tail)
335 return ERING_WAS_FULL;
336 } else if (dev->gdr_head < dev->gdr_tail) {
337 if (tmp < dev->gdr_head || tmp >= dev->gdr_tail)
338 return ERING_WAS_FULL;
339 }
340 dev->gdr_head = tmp;
341
342 return retval;
343}
344
345static u32 crypto4xx_put_gd_to_gdr(struct crypto4xx_device *dev)
346{
347 unsigned long flags;
348
349 spin_lock_irqsave(&dev->core_dev->lock, flags);
350 if (dev->gdr_tail == dev->gdr_head) {
351 spin_unlock_irqrestore(&dev->core_dev->lock, flags);
352 return 0;
353 }
354
355 if (dev->gdr_tail != PPC4XX_LAST_GD)
356 dev->gdr_tail++;
357 else
358 dev->gdr_tail = 0;
359
360 spin_unlock_irqrestore(&dev->core_dev->lock, flags);
361
362 return 0;
363}
364
365static inline struct ce_gd *crypto4xx_get_gdp(struct crypto4xx_device *dev,
366 dma_addr_t *gd_dma, u32 idx)
367{
368 *gd_dma = dev->gdr_pa + sizeof(struct ce_gd) * idx;
369
370 return (struct ce_gd *) (dev->gdr + sizeof(struct ce_gd) * idx);
371}
372
373/**
374 * alloc memory for the scatter ring
375 * need to alloc buf for the ring
376 * sdr_tail, sdr_head and sdr_count are initialized by this function
377 */
378static u32 crypto4xx_build_sdr(struct crypto4xx_device *dev)
379{
380 int i;
381 struct ce_sd *sd_array;
382
383 /* alloc memory for scatter descriptor ring */
384 dev->sdr = dma_alloc_coherent(dev->core_dev->device,
385 sizeof(struct ce_sd) * PPC4XX_NUM_SD,
386 &dev->sdr_pa, GFP_ATOMIC);
387 if (!dev->sdr)
388 return -ENOMEM;
389
390 dev->scatter_buffer_size = PPC4XX_SD_BUFFER_SIZE;
391 dev->scatter_buffer_va =
392 dma_alloc_coherent(dev->core_dev->device,
393 dev->scatter_buffer_size * PPC4XX_NUM_SD,
394 &dev->scatter_buffer_pa, GFP_ATOMIC);
395 if (!dev->scatter_buffer_va) {
396 dma_free_coherent(dev->core_dev->device,
397 sizeof(struct ce_sd) * PPC4XX_NUM_SD,
398 dev->sdr, dev->sdr_pa);
399 return -ENOMEM;
400 }
401
402 sd_array = dev->sdr;
403
404 for (i = 0; i < PPC4XX_NUM_SD; i++) {
405 sd_array[i].ptr = dev->scatter_buffer_pa +
406 dev->scatter_buffer_size * i;
407 }
408
409 return 0;
410}
411
412static void crypto4xx_destroy_sdr(struct crypto4xx_device *dev)
413{
414 if (dev->sdr != NULL)
415 dma_free_coherent(dev->core_dev->device,
416 sizeof(struct ce_sd) * PPC4XX_NUM_SD,
417 dev->sdr, dev->sdr_pa);
418
419 if (dev->scatter_buffer_va != NULL)
420 dma_free_coherent(dev->core_dev->device,
421 dev->scatter_buffer_size * PPC4XX_NUM_SD,
422 dev->scatter_buffer_va,
423 dev->scatter_buffer_pa);
424}
425
426/*
427 * when this function is called.
428 * preemption or interrupt must be disabled
429 */
430static u32 crypto4xx_get_n_sd(struct crypto4xx_device *dev, int n)
431{
432 u32 retval;
433 u32 tmp;
434
435 if (n >= PPC4XX_NUM_SD)
436 return ERING_WAS_FULL;
437
438 retval = dev->sdr_head;
439 tmp = (dev->sdr_head + n) % PPC4XX_NUM_SD;
440 if (dev->sdr_head > dev->gdr_tail) {
441 if (tmp < dev->sdr_head && tmp >= dev->sdr_tail)
442 return ERING_WAS_FULL;
443 } else if (dev->sdr_head < dev->sdr_tail) {
444 if (tmp < dev->sdr_head || tmp >= dev->sdr_tail)
445 return ERING_WAS_FULL;
446 } /* the head = tail, or empty case is already take cared */
447 dev->sdr_head = tmp;
448
449 return retval;
450}
451
452static u32 crypto4xx_put_sd_to_sdr(struct crypto4xx_device *dev)
453{
454 unsigned long flags;
455
456 spin_lock_irqsave(&dev->core_dev->lock, flags);
457 if (dev->sdr_tail == dev->sdr_head) {
458 spin_unlock_irqrestore(&dev->core_dev->lock, flags);
459 return 0;
460 }
461 if (dev->sdr_tail != PPC4XX_LAST_SD)
462 dev->sdr_tail++;
463 else
464 dev->sdr_tail = 0;
465 spin_unlock_irqrestore(&dev->core_dev->lock, flags);
466
467 return 0;
468}
469
470static inline struct ce_sd *crypto4xx_get_sdp(struct crypto4xx_device *dev,
471 dma_addr_t *sd_dma, u32 idx)
472{
473 *sd_dma = dev->sdr_pa + sizeof(struct ce_sd) * idx;
474
475 return (struct ce_sd *)(dev->sdr + sizeof(struct ce_sd) * idx);
476}
477
478static u32 crypto4xx_fill_one_page(struct crypto4xx_device *dev,
479 dma_addr_t *addr, u32 *length,
480 u32 *idx, u32 *offset, u32 *nbytes)
481{
482 u32 len;
483
484 if (*length > dev->scatter_buffer_size) {
485 memcpy(phys_to_virt(*addr),
486 dev->scatter_buffer_va +
487 *idx * dev->scatter_buffer_size + *offset,
488 dev->scatter_buffer_size);
489 *offset = 0;
490 *length -= dev->scatter_buffer_size;
491 *nbytes -= dev->scatter_buffer_size;
492 if (*idx == PPC4XX_LAST_SD)
493 *idx = 0;
494 else
495 (*idx)++;
496 *addr = *addr + dev->scatter_buffer_size;
497 return 1;
498 } else if (*length < dev->scatter_buffer_size) {
499 memcpy(phys_to_virt(*addr),
500 dev->scatter_buffer_va +
501 *idx * dev->scatter_buffer_size + *offset, *length);
502 if ((*offset + *length) == dev->scatter_buffer_size) {
503 if (*idx == PPC4XX_LAST_SD)
504 *idx = 0;
505 else
506 (*idx)++;
507 *nbytes -= *length;
508 *offset = 0;
509 } else {
510 *nbytes -= *length;
511 *offset += *length;
512 }
513
514 return 0;
515 } else {
516 len = (*nbytes <= dev->scatter_buffer_size) ?
517 (*nbytes) : dev->scatter_buffer_size;
518 memcpy(phys_to_virt(*addr),
519 dev->scatter_buffer_va +
520 *idx * dev->scatter_buffer_size + *offset,
521 len);
522 *offset = 0;
523 *nbytes -= len;
524
525 if (*idx == PPC4XX_LAST_SD)
526 *idx = 0;
527 else
528 (*idx)++;
529
530 return 0;
531 }
532}
533
534static void crypto4xx_copy_pkt_to_dst(struct crypto4xx_device *dev,
535 struct ce_pd *pd,
536 struct pd_uinfo *pd_uinfo,
537 u32 nbytes,
538 struct scatterlist *dst)
539{
540 dma_addr_t addr;
541 u32 this_sd;
542 u32 offset;
543 u32 len;
544 u32 i;
545 u32 sg_len;
546 struct scatterlist *sg;
547
548 this_sd = pd_uinfo->first_sd;
549 offset = 0;
550 i = 0;
551
552 while (nbytes) {
553 sg = &dst[i];
554 sg_len = sg->length;
555 addr = dma_map_page(dev->core_dev->device, sg_page(sg),
556 sg->offset, sg->length, DMA_TO_DEVICE);
557
558 if (offset == 0) {
559 len = (nbytes <= sg->length) ? nbytes : sg->length;
560 while (crypto4xx_fill_one_page(dev, &addr, &len,
561 &this_sd, &offset, &nbytes))
562 ;
563 if (!nbytes)
564 return;
565 i++;
566 } else {
567 len = (nbytes <= (dev->scatter_buffer_size - offset)) ?
568 nbytes : (dev->scatter_buffer_size - offset);
569 len = (sg->length < len) ? sg->length : len;
570 while (crypto4xx_fill_one_page(dev, &addr, &len,
571 &this_sd, &offset, &nbytes))
572 ;
573 if (!nbytes)
574 return;
575 sg_len -= len;
576 if (sg_len) {
577 addr += len;
578 while (crypto4xx_fill_one_page(dev, &addr,
579 &sg_len, &this_sd, &offset, &nbytes))
580 ;
581 }
582 i++;
583 }
584 }
585}
586
587static u32 crypto4xx_copy_digest_to_dst(struct pd_uinfo *pd_uinfo,
588 struct crypto4xx_ctx *ctx)
589{
590 struct dynamic_sa_ctl *sa = (struct dynamic_sa_ctl *) ctx->sa_in;
591 struct sa_state_record *state_record =
592 (struct sa_state_record *) pd_uinfo->sr_va;
593
594 if (sa->sa_command_0.bf.hash_alg == SA_HASH_ALG_SHA1) {
595 memcpy((void *) pd_uinfo->dest_va, state_record->save_digest,
596 SA_HASH_ALG_SHA1_DIGEST_SIZE);
597 }
598
599 return 0;
600}
601
602static void crypto4xx_ret_sg_desc(struct crypto4xx_device *dev,
603 struct pd_uinfo *pd_uinfo)
604{
605 int i;
606 if (pd_uinfo->num_gd) {
607 for (i = 0; i < pd_uinfo->num_gd; i++)
608 crypto4xx_put_gd_to_gdr(dev);
609 pd_uinfo->first_gd = 0xffffffff;
610 pd_uinfo->num_gd = 0;
611 }
612 if (pd_uinfo->num_sd) {
613 for (i = 0; i < pd_uinfo->num_sd; i++)
614 crypto4xx_put_sd_to_sdr(dev);
615
616 pd_uinfo->first_sd = 0xffffffff;
617 pd_uinfo->num_sd = 0;
618 }
619}
620
621static u32 crypto4xx_ablkcipher_done(struct crypto4xx_device *dev,
622 struct pd_uinfo *pd_uinfo,
623 struct ce_pd *pd)
624{
625 struct crypto4xx_ctx *ctx;
626 struct ablkcipher_request *ablk_req;
627 struct scatterlist *dst;
628 dma_addr_t addr;
629
630 ablk_req = ablkcipher_request_cast(pd_uinfo->async_req);
631 ctx = crypto_tfm_ctx(ablk_req->base.tfm);
632
633 if (pd_uinfo->using_sd) {
634 crypto4xx_copy_pkt_to_dst(dev, pd, pd_uinfo, ablk_req->nbytes,
635 ablk_req->dst);
636 } else {
637 dst = pd_uinfo->dest_va;
638 addr = dma_map_page(dev->core_dev->device, sg_page(dst),
639 dst->offset, dst->length, DMA_FROM_DEVICE);
640 }
641 crypto4xx_ret_sg_desc(dev, pd_uinfo);
642 if (ablk_req->base.complete != NULL)
643 ablk_req->base.complete(&ablk_req->base, 0);
644
645 return 0;
646}
647
648static u32 crypto4xx_ahash_done(struct crypto4xx_device *dev,
649 struct pd_uinfo *pd_uinfo)
650{
651 struct crypto4xx_ctx *ctx;
652 struct ahash_request *ahash_req;
653
654 ahash_req = ahash_request_cast(pd_uinfo->async_req);
655 ctx = crypto_tfm_ctx(ahash_req->base.tfm);
656
657 crypto4xx_copy_digest_to_dst(pd_uinfo,
658 crypto_tfm_ctx(ahash_req->base.tfm));
659 crypto4xx_ret_sg_desc(dev, pd_uinfo);
660 /* call user provided callback function x */
661 if (ahash_req->base.complete != NULL)
662 ahash_req->base.complete(&ahash_req->base, 0);
663
664 return 0;
665}
666
667static u32 crypto4xx_pd_done(struct crypto4xx_device *dev, u32 idx)
668{
669 struct ce_pd *pd;
670 struct pd_uinfo *pd_uinfo;
671
672 pd = dev->pdr + sizeof(struct ce_pd)*idx;
673 pd_uinfo = dev->pdr_uinfo + sizeof(struct pd_uinfo)*idx;
674 if (crypto_tfm_alg_type(pd_uinfo->async_req->tfm) ==
675 CRYPTO_ALG_TYPE_ABLKCIPHER)
676 return crypto4xx_ablkcipher_done(dev, pd_uinfo, pd);
677 else
678 return crypto4xx_ahash_done(dev, pd_uinfo);
679}
680
681/**
682 * Note: Only use this function to copy items that is word aligned.
683 */
684void crypto4xx_memcpy_le(unsigned int *dst,
685 const unsigned char *buf,
686 int len)
687{
688 u8 *tmp;
689 for (; len >= 4; buf += 4, len -= 4)
690 *dst++ = cpu_to_le32(*(unsigned int *) buf);
691
692 tmp = (u8 *)dst;
693 switch (len) {
694 case 3:
695 *tmp++ = 0;
696 *tmp++ = *(buf+2);
697 *tmp++ = *(buf+1);
698 *tmp++ = *buf;
699 break;
700 case 2:
701 *tmp++ = 0;
702 *tmp++ = 0;
703 *tmp++ = *(buf+1);
704 *tmp++ = *buf;
705 break;
706 case 1:
707 *tmp++ = 0;
708 *tmp++ = 0;
709 *tmp++ = 0;
710 *tmp++ = *buf;
711 break;
712 default:
713 break;
714 }
715}
716
717static void crypto4xx_stop_all(struct crypto4xx_core_device *core_dev)
718{
719 crypto4xx_destroy_pdr(core_dev->dev);
720 crypto4xx_destroy_gdr(core_dev->dev);
721 crypto4xx_destroy_sdr(core_dev->dev);
722 dev_set_drvdata(core_dev->device, NULL);
723 iounmap(core_dev->dev->ce_base);
724 kfree(core_dev->dev);
725 kfree(core_dev);
726}
727
728void crypto4xx_return_pd(struct crypto4xx_device *dev,
729 u32 pd_entry, struct ce_pd *pd,
730 struct pd_uinfo *pd_uinfo)
731{
732 /* irq should be already disabled */
733 dev->pdr_head = pd_entry;
734 pd->pd_ctl.w = 0;
735 pd->pd_ctl_len.w = 0;
736 pd_uinfo->state = PD_ENTRY_FREE;
737}
738
739/*
740 * derive number of elements in scatterlist
741 * Shamlessly copy from talitos.c
742 */
743static int get_sg_count(struct scatterlist *sg_list, int nbytes)
744{
745 struct scatterlist *sg = sg_list;
746 int sg_nents = 0;
747
748 while (nbytes) {
749 sg_nents++;
750 if (sg->length > nbytes)
751 break;
752 nbytes -= sg->length;
753 sg = sg_next(sg);
754 }
755
756 return sg_nents;
757}
758
759static u32 get_next_gd(u32 current)
760{
761 if (current != PPC4XX_LAST_GD)
762 return current + 1;
763 else
764 return 0;
765}
766
767static u32 get_next_sd(u32 current)
768{
769 if (current != PPC4XX_LAST_SD)
770 return current + 1;
771 else
772 return 0;
773}
774
775u32 crypto4xx_build_pd(struct crypto_async_request *req,
776 struct crypto4xx_ctx *ctx,
777 struct scatterlist *src,
778 struct scatterlist *dst,
779 unsigned int datalen,
780 void *iv, u32 iv_len)
781{
782 struct crypto4xx_device *dev = ctx->dev;
783 dma_addr_t addr, pd_dma, sd_dma, gd_dma;
784 struct dynamic_sa_ctl *sa;
785 struct scatterlist *sg;
786 struct ce_gd *gd;
787 struct ce_pd *pd;
788 u32 num_gd, num_sd;
789 u32 fst_gd = 0xffffffff;
790 u32 fst_sd = 0xffffffff;
791 u32 pd_entry;
792 unsigned long flags;
793 struct pd_uinfo *pd_uinfo = NULL;
794 unsigned int nbytes = datalen, idx;
795 unsigned int ivlen = 0;
796 u32 gd_idx = 0;
797
798 /* figure how many gd is needed */
799 num_gd = get_sg_count(src, datalen);
800 if (num_gd == 1)
801 num_gd = 0;
802
803 /* figure how many sd is needed */
804 if (sg_is_last(dst) || ctx->is_hash) {
805 num_sd = 0;
806 } else {
807 if (datalen > PPC4XX_SD_BUFFER_SIZE) {
808 num_sd = datalen / PPC4XX_SD_BUFFER_SIZE;
809 if (datalen % PPC4XX_SD_BUFFER_SIZE)
810 num_sd++;
811 } else {
812 num_sd = 1;
813 }
814 }
815
816 /*
817 * The follow section of code needs to be protected
818 * The gather ring and scatter ring needs to be consecutive
819 * In case of run out of any kind of descriptor, the descriptor
820 * already got must be return the original place.
821 */
822 spin_lock_irqsave(&dev->core_dev->lock, flags);
823 if (num_gd) {
824 fst_gd = crypto4xx_get_n_gd(dev, num_gd);
825 if (fst_gd == ERING_WAS_FULL) {
826 spin_unlock_irqrestore(&dev->core_dev->lock, flags);
827 return -EAGAIN;
828 }
829 }
830 if (num_sd) {
831 fst_sd = crypto4xx_get_n_sd(dev, num_sd);
832 if (fst_sd == ERING_WAS_FULL) {
833 if (num_gd)
834 dev->gdr_head = fst_gd;
835 spin_unlock_irqrestore(&dev->core_dev->lock, flags);
836 return -EAGAIN;
837 }
838 }
839 pd_entry = crypto4xx_get_pd_from_pdr_nolock(dev);
840 if (pd_entry == ERING_WAS_FULL) {
841 if (num_gd)
842 dev->gdr_head = fst_gd;
843 if (num_sd)
844 dev->sdr_head = fst_sd;
845 spin_unlock_irqrestore(&dev->core_dev->lock, flags);
846 return -EAGAIN;
847 }
848 spin_unlock_irqrestore(&dev->core_dev->lock, flags);
849
850 pd_uinfo = (struct pd_uinfo *)(dev->pdr_uinfo +
851 sizeof(struct pd_uinfo) * pd_entry);
852 pd = crypto4xx_get_pdp(dev, &pd_dma, pd_entry);
853 pd_uinfo->async_req = req;
854 pd_uinfo->num_gd = num_gd;
855 pd_uinfo->num_sd = num_sd;
856
857 if (iv_len || ctx->is_hash) {
858 ivlen = iv_len;
859 pd->sa = pd_uinfo->sa_pa;
860 sa = (struct dynamic_sa_ctl *) pd_uinfo->sa_va;
861 if (ctx->direction == DIR_INBOUND)
862 memcpy(sa, ctx->sa_in, ctx->sa_len * 4);
863 else
864 memcpy(sa, ctx->sa_out, ctx->sa_len * 4);
865
866 memcpy((void *) sa + ctx->offset_to_sr_ptr,
867 &pd_uinfo->sr_pa, 4);
868
869 if (iv_len)
870 crypto4xx_memcpy_le(pd_uinfo->sr_va, iv, iv_len);
871 } else {
872 if (ctx->direction == DIR_INBOUND) {
873 pd->sa = ctx->sa_in_dma_addr;
874 sa = (struct dynamic_sa_ctl *) ctx->sa_in;
875 } else {
876 pd->sa = ctx->sa_out_dma_addr;
877 sa = (struct dynamic_sa_ctl *) ctx->sa_out;
878 }
879 }
880 pd->sa_len = ctx->sa_len;
881 if (num_gd) {
882 /* get first gd we are going to use */
883 gd_idx = fst_gd;
884 pd_uinfo->first_gd = fst_gd;
885 pd_uinfo->num_gd = num_gd;
886 gd = crypto4xx_get_gdp(dev, &gd_dma, gd_idx);
887 pd->src = gd_dma;
888 /* enable gather */
889 sa->sa_command_0.bf.gather = 1;
890 idx = 0;
891 src = &src[0];
892 /* walk the sg, and setup gather array */
893 while (nbytes) {
894 sg = &src[idx];
895 addr = dma_map_page(dev->core_dev->device, sg_page(sg),
896 sg->offset, sg->length, DMA_TO_DEVICE);
897 gd->ptr = addr;
898 gd->ctl_len.len = sg->length;
899 gd->ctl_len.done = 0;
900 gd->ctl_len.ready = 1;
901 if (sg->length >= nbytes)
902 break;
903 nbytes -= sg->length;
904 gd_idx = get_next_gd(gd_idx);
905 gd = crypto4xx_get_gdp(dev, &gd_dma, gd_idx);
906 idx++;
907 }
908 } else {
909 pd->src = (u32)dma_map_page(dev->core_dev->device, sg_page(src),
910 src->offset, src->length, DMA_TO_DEVICE);
911 /*
912 * Disable gather in sa command
913 */
914 sa->sa_command_0.bf.gather = 0;
915 /*
916 * Indicate gather array is not used
917 */
918 pd_uinfo->first_gd = 0xffffffff;
919 pd_uinfo->num_gd = 0;
920 }
921 if (ctx->is_hash || sg_is_last(dst)) {
922 /*
923 * we know application give us dst a whole piece of memory
924 * no need to use scatter ring.
925 * In case of is_hash, the icv is always at end of src data.
926 */
927 pd_uinfo->using_sd = 0;
928 pd_uinfo->first_sd = 0xffffffff;
929 pd_uinfo->num_sd = 0;
930 pd_uinfo->dest_va = dst;
931 sa->sa_command_0.bf.scatter = 0;
932 if (ctx->is_hash)
933 pd->dest = virt_to_phys((void *)dst);
934 else
935 pd->dest = (u32)dma_map_page(dev->core_dev->device,
936 sg_page(dst), dst->offset,
937 dst->length, DMA_TO_DEVICE);
938 } else {
939 struct ce_sd *sd = NULL;
940 u32 sd_idx = fst_sd;
941 nbytes = datalen;
942 sa->sa_command_0.bf.scatter = 1;
943 pd_uinfo->using_sd = 1;
944 pd_uinfo->dest_va = dst;
945 pd_uinfo->first_sd = fst_sd;
946 pd_uinfo->num_sd = num_sd;
947 sd = crypto4xx_get_sdp(dev, &sd_dma, sd_idx);
948 pd->dest = sd_dma;
949 /* setup scatter descriptor */
950 sd->ctl.done = 0;
951 sd->ctl.rdy = 1;
952 /* sd->ptr should be setup by sd_init routine*/
953 idx = 0;
954 if (nbytes >= PPC4XX_SD_BUFFER_SIZE)
955 nbytes -= PPC4XX_SD_BUFFER_SIZE;
956 else
957 nbytes = 0;
958 while (nbytes) {
959 sd_idx = get_next_sd(sd_idx);
960 sd = crypto4xx_get_sdp(dev, &sd_dma, sd_idx);
961 /* setup scatter descriptor */
962 sd->ctl.done = 0;
963 sd->ctl.rdy = 1;
964 if (nbytes >= PPC4XX_SD_BUFFER_SIZE)
965 nbytes -= PPC4XX_SD_BUFFER_SIZE;
966 else
967 /*
968 * SD entry can hold PPC4XX_SD_BUFFER_SIZE,
969 * which is more than nbytes, so done.
970 */
971 nbytes = 0;
972 }
973 }
974
975 sa->sa_command_1.bf.hash_crypto_offset = 0;
976 pd->pd_ctl.w = ctx->pd_ctl;
977 pd->pd_ctl_len.w = 0x00400000 | (ctx->bypass << 24) | datalen;
978 pd_uinfo->state = PD_ENTRY_INUSE;
979 wmb();
980 /* write any value to push engine to read a pd */
981 writel(1, dev->ce_base + CRYPTO4XX_INT_DESCR_RD);
982 return -EINPROGRESS;
983}
984
985/**
986 * Algorithm Registration Functions
987 */
988static int crypto4xx_alg_init(struct crypto_tfm *tfm)
989{
990 struct crypto_alg *alg = tfm->__crt_alg;
991 struct crypto4xx_alg *amcc_alg = crypto_alg_to_crypto4xx_alg(alg);
992 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm);
993
994 ctx->dev = amcc_alg->dev;
995 ctx->sa_in = NULL;
996 ctx->sa_out = NULL;
997 ctx->sa_in_dma_addr = 0;
998 ctx->sa_out_dma_addr = 0;
999 ctx->sa_len = 0;
1000
1001 if (alg->cra_type == &crypto_ablkcipher_type)
1002 tfm->crt_ablkcipher.reqsize = sizeof(struct crypto4xx_ctx);
1003 else if (alg->cra_type == &crypto_ahash_type)
1004 tfm->crt_ahash.reqsize = sizeof(struct crypto4xx_ctx);
1005
1006 return 0;
1007}
1008
1009static void crypto4xx_alg_exit(struct crypto_tfm *tfm)
1010{
1011 struct crypto4xx_ctx *ctx = crypto_tfm_ctx(tfm);
1012
1013 crypto4xx_free_sa(ctx);
1014 crypto4xx_free_state_record(ctx);
1015}
1016
1017int crypto4xx_register_alg(struct crypto4xx_device *sec_dev,
1018 struct crypto_alg *crypto_alg, int array_size)
1019{
1020 struct crypto4xx_alg *alg;
1021 int i;
1022 int rc = 0;
1023
1024 for (i = 0; i < array_size; i++) {
1025 alg = kzalloc(sizeof(struct crypto4xx_alg), GFP_KERNEL);
1026 if (!alg)
1027 return -ENOMEM;
1028
1029 alg->alg = crypto_alg[i];
1030 INIT_LIST_HEAD(&alg->alg.cra_list);
1031 if (alg->alg.cra_init == NULL)
1032 alg->alg.cra_init = crypto4xx_alg_init;
1033 if (alg->alg.cra_exit == NULL)
1034 alg->alg.cra_exit = crypto4xx_alg_exit;
1035 alg->dev = sec_dev;
1036 rc = crypto_register_alg(&alg->alg);
1037 if (rc) {
1038 list_del(&alg->entry);
1039 kfree(alg);
1040 } else {
1041 list_add_tail(&alg->entry, &sec_dev->alg_list);
1042 }
1043 }
1044
1045 return 0;
1046}
1047
1048static void crypto4xx_unregister_alg(struct crypto4xx_device *sec_dev)
1049{
1050 struct crypto4xx_alg *alg, *tmp;
1051
1052 list_for_each_entry_safe(alg, tmp, &sec_dev->alg_list, entry) {
1053 list_del(&alg->entry);
1054 crypto_unregister_alg(&alg->alg);
1055 kfree(alg);
1056 }
1057}
1058
1059static void crypto4xx_bh_tasklet_cb(unsigned long data)
1060{
1061 struct device *dev = (struct device *)data;
1062 struct crypto4xx_core_device *core_dev = dev_get_drvdata(dev);
1063 struct pd_uinfo *pd_uinfo;
1064 struct ce_pd *pd;
1065 u32 tail;
1066
1067 while (core_dev->dev->pdr_head != core_dev->dev->pdr_tail) {
1068 tail = core_dev->dev->pdr_tail;
1069 pd_uinfo = core_dev->dev->pdr_uinfo +
1070 sizeof(struct pd_uinfo)*tail;
1071 pd = core_dev->dev->pdr + sizeof(struct ce_pd) * tail;
1072 if ((pd_uinfo->state == PD_ENTRY_INUSE) &&
1073 pd->pd_ctl.bf.pe_done &&
1074 !pd->pd_ctl.bf.host_ready) {
1075 pd->pd_ctl.bf.pe_done = 0;
1076 crypto4xx_pd_done(core_dev->dev, tail);
1077 crypto4xx_put_pd_to_pdr(core_dev->dev, tail);
1078 pd_uinfo->state = PD_ENTRY_FREE;
1079 } else {
1080 /* if tail not done, break */
1081 break;
1082 }
1083 }
1084}
1085
1086/**
1087 * Top Half of isr.
1088 */
1089static irqreturn_t crypto4xx_ce_interrupt_handler(int irq, void *data)
1090{
1091 struct device *dev = (struct device *)data;
1092 struct crypto4xx_core_device *core_dev = dev_get_drvdata(dev);
1093
1094 if (core_dev->dev->ce_base == 0)
1095 return 0;
1096
1097 writel(PPC4XX_INTERRUPT_CLR,
1098 core_dev->dev->ce_base + CRYPTO4XX_INT_CLR);
1099 tasklet_schedule(&core_dev->tasklet);
1100
1101 return IRQ_HANDLED;
1102}
1103
1104/**
1105 * Supported Crypto Algorithms
1106 */
1107struct crypto_alg crypto4xx_alg[] = {
1108 /* Crypto AES modes */
1109 {
1110 .cra_name = "cbc(aes)",
1111 .cra_driver_name = "cbc-aes-ppc4xx",
1112 .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
1113 .cra_flags = CRYPTO_ALG_TYPE_ABLKCIPHER | CRYPTO_ALG_ASYNC,
1114 .cra_blocksize = AES_BLOCK_SIZE,
1115 .cra_ctxsize = sizeof(struct crypto4xx_ctx),
1116 .cra_alignmask = 0,
1117 .cra_type = &crypto_ablkcipher_type,
1118 .cra_module = THIS_MODULE,
1119 .cra_u = {
1120 .ablkcipher = {
1121 .min_keysize = AES_MIN_KEY_SIZE,
1122 .max_keysize = AES_MAX_KEY_SIZE,
1123 .ivsize = AES_IV_SIZE,
1124 .setkey = crypto4xx_setkey_aes_cbc,
1125 .encrypt = crypto4xx_encrypt,
1126 .decrypt = crypto4xx_decrypt,
1127 }
1128 }
1129 },
1130 /* Hash SHA1 */
1131 {
1132 .cra_name = "sha1",
1133 .cra_driver_name = "sha1-ppc4xx",
1134 .cra_priority = CRYPTO4XX_CRYPTO_PRIORITY,
1135 .cra_flags = CRYPTO_ALG_TYPE_AHASH | CRYPTO_ALG_ASYNC,
1136 .cra_blocksize = SHA1_BLOCK_SIZE,
1137 .cra_ctxsize = sizeof(struct crypto4xx_ctx),
1138 .cra_alignmask = 0,
1139 .cra_type = &crypto_ahash_type,
1140 .cra_init = crypto4xx_sha1_alg_init,
1141 .cra_module = THIS_MODULE,
1142 .cra_u = {
1143 .ahash = {
1144 .digestsize = SHA1_DIGEST_SIZE,
1145 .init = crypto4xx_hash_init,
1146 .update = crypto4xx_hash_update,
1147 .final = crypto4xx_hash_final,
1148 .digest = crypto4xx_hash_digest,
1149 }
1150 }
1151 },
1152};
1153
1154/**
1155 * Module Initialization Routine
1156 */
1157static int __init crypto4xx_probe(struct of_device *ofdev,
1158 const struct of_device_id *match)
1159{
1160 int rc;
1161 struct resource res;
1162 struct device *dev = &ofdev->dev;
1163 struct crypto4xx_core_device *core_dev;
1164
1165 rc = of_address_to_resource(ofdev->node, 0, &res);
1166 if (rc)
1167 return -ENODEV;
1168
1169 if (of_find_compatible_node(NULL, NULL, "amcc,ppc460ex-crypto")) {
1170 mtdcri(SDR0, PPC460EX_SDR0_SRST,
1171 mfdcri(SDR0, PPC460EX_SDR0_SRST) | PPC460EX_CE_RESET);
1172 mtdcri(SDR0, PPC460EX_SDR0_SRST,
1173 mfdcri(SDR0, PPC460EX_SDR0_SRST) & ~PPC460EX_CE_RESET);
1174 } else if (of_find_compatible_node(NULL, NULL,
1175 "amcc,ppc405ex-crypto")) {
1176 mtdcri(SDR0, PPC405EX_SDR0_SRST,
1177 mfdcri(SDR0, PPC405EX_SDR0_SRST) | PPC405EX_CE_RESET);
1178 mtdcri(SDR0, PPC405EX_SDR0_SRST,
1179 mfdcri(SDR0, PPC405EX_SDR0_SRST) & ~PPC405EX_CE_RESET);
1180 } else if (of_find_compatible_node(NULL, NULL,
1181 "amcc,ppc460sx-crypto")) {
1182 mtdcri(SDR0, PPC460SX_SDR0_SRST,
1183 mfdcri(SDR0, PPC460SX_SDR0_SRST) | PPC460SX_CE_RESET);
1184 mtdcri(SDR0, PPC460SX_SDR0_SRST,
1185 mfdcri(SDR0, PPC460SX_SDR0_SRST) & ~PPC460SX_CE_RESET);
1186 } else {
1187 printk(KERN_ERR "Crypto Function Not supported!\n");
1188 return -EINVAL;
1189 }
1190
1191 core_dev = kzalloc(sizeof(struct crypto4xx_core_device), GFP_KERNEL);
1192 if (!core_dev)
1193 return -ENOMEM;
1194
1195 dev_set_drvdata(dev, core_dev);
1196 core_dev->ofdev = ofdev;
1197 core_dev->dev = kzalloc(sizeof(struct crypto4xx_device), GFP_KERNEL);
1198 if (!core_dev->dev)
1199 goto err_alloc_dev;
1200
1201 core_dev->dev->core_dev = core_dev;
1202 core_dev->device = dev;
1203 spin_lock_init(&core_dev->lock);
1204 INIT_LIST_HEAD(&core_dev->dev->alg_list);
1205 rc = crypto4xx_build_pdr(core_dev->dev);
1206 if (rc)
1207 goto err_build_pdr;
1208
1209 rc = crypto4xx_build_gdr(core_dev->dev);
1210 if (rc)
1211 goto err_build_gdr;
1212
1213 rc = crypto4xx_build_sdr(core_dev->dev);
1214 if (rc)
1215 goto err_build_sdr;
1216
1217 /* Init tasklet for bottom half processing */
1218 tasklet_init(&core_dev->tasklet, crypto4xx_bh_tasklet_cb,
1219 (unsigned long) dev);
1220
1221 /* Register for Crypto isr, Crypto Engine IRQ */
1222 core_dev->irq = irq_of_parse_and_map(ofdev->node, 0);
1223 rc = request_irq(core_dev->irq, crypto4xx_ce_interrupt_handler, 0,
1224 core_dev->dev->name, dev);
1225 if (rc)
1226 goto err_request_irq;
1227
1228 core_dev->dev->ce_base = of_iomap(ofdev->node, 0);
1229 if (!core_dev->dev->ce_base) {
1230 dev_err(dev, "failed to of_iomap\n");
1231 goto err_iomap;
1232 }
1233
1234 /* need to setup pdr, rdr, gdr and sdr before this */
1235 crypto4xx_hw_init(core_dev->dev);
1236
1237 /* Register security algorithms with Linux CryptoAPI */
1238 rc = crypto4xx_register_alg(core_dev->dev, crypto4xx_alg,
1239 ARRAY_SIZE(crypto4xx_alg));
1240 if (rc)
1241 goto err_start_dev;
1242
1243 return 0;
1244
1245err_start_dev:
1246 iounmap(core_dev->dev->ce_base);
1247err_iomap:
1248 free_irq(core_dev->irq, dev);
1249 irq_dispose_mapping(core_dev->irq);
1250 tasklet_kill(&core_dev->tasklet);
1251err_request_irq:
1252 crypto4xx_destroy_sdr(core_dev->dev);
1253err_build_sdr:
1254 crypto4xx_destroy_gdr(core_dev->dev);
1255err_build_gdr:
1256 crypto4xx_destroy_pdr(core_dev->dev);
1257err_build_pdr:
1258 kfree(core_dev->dev);
1259err_alloc_dev:
1260 kfree(core_dev);
1261
1262 return rc;
1263}
1264
1265static int __exit crypto4xx_remove(struct of_device *ofdev)
1266{
1267 struct device *dev = &ofdev->dev;
1268 struct crypto4xx_core_device *core_dev = dev_get_drvdata(dev);
1269
1270 free_irq(core_dev->irq, dev);
1271 irq_dispose_mapping(core_dev->irq);
1272
1273 tasklet_kill(&core_dev->tasklet);
1274 /* Un-register with Linux CryptoAPI */
1275 crypto4xx_unregister_alg(core_dev->dev);
1276 /* Free all allocated memory */
1277 crypto4xx_stop_all(core_dev);
1278
1279 return 0;
1280}
1281
1282static struct of_device_id crypto4xx_match[] = {
1283 { .compatible = "amcc,ppc4xx-crypto",},
1284 { },
1285};
1286
1287static struct of_platform_driver crypto4xx_driver = {
1288 .name = "crypto4xx",
1289 .match_table = crypto4xx_match,
1290 .probe = crypto4xx_probe,
1291 .remove = crypto4xx_remove,
1292};
1293
1294static int __init crypto4xx_init(void)
1295{
1296 return of_register_platform_driver(&crypto4xx_driver);
1297}
1298
1299static void __exit crypto4xx_exit(void)
1300{
1301 of_unregister_platform_driver(&crypto4xx_driver);
1302}
1303
1304module_init(crypto4xx_init);
1305module_exit(crypto4xx_exit);
1306
1307MODULE_LICENSE("GPL");
1308MODULE_AUTHOR("James Hsiao <jhsiao@amcc.com>");
1309MODULE_DESCRIPTION("Driver for AMCC PPC4xx crypto accelerator");
1310
diff --git a/drivers/crypto/amcc/crypto4xx_core.h b/drivers/crypto/amcc/crypto4xx_core.h
new file mode 100644
index 000000000000..1ef103449364
--- /dev/null
+++ b/drivers/crypto/amcc/crypto4xx_core.h
@@ -0,0 +1,177 @@
1/**
2 * AMCC SoC PPC4xx Crypto Driver
3 *
4 * Copyright (c) 2008 Applied Micro Circuits Corporation.
5 * All rights reserved. James Hsiao <jhsiao@amcc.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * This is the header file for AMCC Crypto offload Linux device driver for
18 * use with Linux CryptoAPI.
19
20 */
21
22#ifndef __CRYPTO4XX_CORE_H__
23#define __CRYPTO4XX_CORE_H__
24
25#define PPC460SX_SDR0_SRST 0x201
26#define PPC405EX_SDR0_SRST 0x200
27#define PPC460EX_SDR0_SRST 0x201
28#define PPC460EX_CE_RESET 0x08000000
29#define PPC460SX_CE_RESET 0x20000000
30#define PPC405EX_CE_RESET 0x00000008
31
32#define CRYPTO4XX_CRYPTO_PRIORITY 300
33#define PPC4XX_LAST_PD 63
34#define PPC4XX_NUM_PD 64
35#define PPC4XX_LAST_GD 1023
36#define PPC4XX_NUM_GD 1024
37#define PPC4XX_LAST_SD 63
38#define PPC4XX_NUM_SD 64
39#define PPC4XX_SD_BUFFER_SIZE 2048
40
41#define PD_ENTRY_INUSE 1
42#define PD_ENTRY_FREE 0
43#define ERING_WAS_FULL 0xffffffff
44
45struct crypto4xx_device;
46
47struct pd_uinfo {
48 struct crypto4xx_device *dev;
49 u32 state;
50 u32 using_sd;
51 u32 first_gd; /* first gather discriptor
52 used by this packet */
53 u32 num_gd; /* number of gather discriptor
54 used by this packet */
55 u32 first_sd; /* first scatter discriptor
56 used by this packet */
57 u32 num_sd; /* number of scatter discriptors
58 used by this packet */
59 void *sa_va; /* shadow sa, when using cp from ctx->sa */
60 u32 sa_pa;
61 void *sr_va; /* state record for shadow sa */
62 u32 sr_pa;
63 struct scatterlist *dest_va;
64 struct crypto_async_request *async_req; /* base crypto request
65 for this packet */
66};
67
68struct crypto4xx_device {
69 struct crypto4xx_core_device *core_dev;
70 char *name;
71 u64 ce_phy_address;
72 void __iomem *ce_base;
73
74 void *pdr; /* base address of packet
75 descriptor ring */
76 dma_addr_t pdr_pa; /* physical address used to
77 program ce pdr_base_register */
78 void *gdr; /* gather descriptor ring */
79 dma_addr_t gdr_pa; /* physical address used to
80 program ce gdr_base_register */
81 void *sdr; /* scatter descriptor ring */
82 dma_addr_t sdr_pa; /* physical address used to
83 program ce sdr_base_register */
84 void *scatter_buffer_va;
85 dma_addr_t scatter_buffer_pa;
86 u32 scatter_buffer_size;
87
88 void *shadow_sa_pool; /* pool of memory for sa in pd_uinfo */
89 dma_addr_t shadow_sa_pool_pa;
90 void *shadow_sr_pool; /* pool of memory for sr in pd_uinfo */
91 dma_addr_t shadow_sr_pool_pa;
92 u32 pdr_tail;
93 u32 pdr_head;
94 u32 gdr_tail;
95 u32 gdr_head;
96 u32 sdr_tail;
97 u32 sdr_head;
98 void *pdr_uinfo;
99 struct list_head alg_list; /* List of algorithm supported
100 by this device */
101};
102
103struct crypto4xx_core_device {
104 struct device *device;
105 struct of_device *ofdev;
106 struct crypto4xx_device *dev;
107 u32 int_status;
108 u32 irq;
109 struct tasklet_struct tasklet;
110 spinlock_t lock;
111};
112
113struct crypto4xx_ctx {
114 struct crypto4xx_device *dev;
115 void *sa_in;
116 dma_addr_t sa_in_dma_addr;
117 void *sa_out;
118 dma_addr_t sa_out_dma_addr;
119 void *state_record;
120 dma_addr_t state_record_dma_addr;
121 u32 sa_len;
122 u32 offset_to_sr_ptr; /* offset to state ptr, in dynamic sa */
123 u32 direction;
124 u32 next_hdr;
125 u32 save_iv;
126 u32 pd_ctl_len;
127 u32 pd_ctl;
128 u32 bypass;
129 u32 is_hash;
130 u32 hash_final;
131};
132
133struct crypto4xx_req_ctx {
134 struct crypto4xx_device *dev; /* Device in which
135 operation to send to */
136 void *sa;
137 u32 sa_dma_addr;
138 u16 sa_len;
139};
140
141struct crypto4xx_alg {
142 struct list_head entry;
143 struct crypto_alg alg;
144 struct crypto4xx_device *dev;
145};
146
147#define crypto_alg_to_crypto4xx_alg(x) \
148 container_of(x, struct crypto4xx_alg, alg)
149
150extern int crypto4xx_alloc_sa(struct crypto4xx_ctx *ctx, u32 size);
151extern void crypto4xx_free_sa(struct crypto4xx_ctx *ctx);
152extern u32 crypto4xx_alloc_sa_rctx(struct crypto4xx_ctx *ctx,
153 struct crypto4xx_ctx *rctx);
154extern void crypto4xx_free_sa_rctx(struct crypto4xx_ctx *rctx);
155extern void crypto4xx_free_ctx(struct crypto4xx_ctx *ctx);
156extern u32 crypto4xx_alloc_state_record(struct crypto4xx_ctx *ctx);
157extern u32 get_dynamic_sa_offset_state_ptr_field(struct crypto4xx_ctx *ctx);
158extern u32 get_dynamic_sa_offset_key_field(struct crypto4xx_ctx *ctx);
159extern u32 get_dynamic_sa_iv_size(struct crypto4xx_ctx *ctx);
160extern void crypto4xx_memcpy_le(unsigned int *dst,
161 const unsigned char *buf, int len);
162extern u32 crypto4xx_build_pd(struct crypto_async_request *req,
163 struct crypto4xx_ctx *ctx,
164 struct scatterlist *src,
165 struct scatterlist *dst,
166 unsigned int datalen,
167 void *iv, u32 iv_len);
168extern int crypto4xx_setkey_aes_cbc(struct crypto_ablkcipher *cipher,
169 const u8 *key, unsigned int keylen);
170extern int crypto4xx_encrypt(struct ablkcipher_request *req);
171extern int crypto4xx_decrypt(struct ablkcipher_request *req);
172extern int crypto4xx_sha1_alg_init(struct crypto_tfm *tfm);
173extern int crypto4xx_hash_digest(struct ahash_request *req);
174extern int crypto4xx_hash_final(struct ahash_request *req);
175extern int crypto4xx_hash_update(struct ahash_request *req);
176extern int crypto4xx_hash_init(struct ahash_request *req);
177#endif
diff --git a/drivers/crypto/amcc/crypto4xx_reg_def.h b/drivers/crypto/amcc/crypto4xx_reg_def.h
new file mode 100644
index 000000000000..7d4edb002619
--- /dev/null
+++ b/drivers/crypto/amcc/crypto4xx_reg_def.h
@@ -0,0 +1,284 @@
1/**
2 * AMCC SoC PPC4xx Crypto Driver
3 *
4 * Copyright (c) 2008 Applied Micro Circuits Corporation.
5 * All rights reserved. James Hsiao <jhsiao@amcc.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * This filr defines the register set for Security Subsystem
18 */
19
20#ifndef __CRYPTO4XX_REG_DEF_H__
21#define __CRYPTO4XX_REG_DEF_H__
22
23/* CRYPTO4XX Register offset */
24#define CRYPTO4XX_DESCRIPTOR 0x00000000
25#define CRYPTO4XX_CTRL_STAT 0x00000000
26#define CRYPTO4XX_SOURCE 0x00000004
27#define CRYPTO4XX_DEST 0x00000008
28#define CRYPTO4XX_SA 0x0000000C
29#define CRYPTO4XX_SA_LENGTH 0x00000010
30#define CRYPTO4XX_LENGTH 0x00000014
31
32#define CRYPTO4XX_PE_DMA_CFG 0x00000040
33#define CRYPTO4XX_PE_DMA_STAT 0x00000044
34#define CRYPTO4XX_PDR_BASE 0x00000048
35#define CRYPTO4XX_RDR_BASE 0x0000004c
36#define CRYPTO4XX_RING_SIZE 0x00000050
37#define CRYPTO4XX_RING_CTRL 0x00000054
38#define CRYPTO4XX_INT_RING_STAT 0x00000058
39#define CRYPTO4XX_EXT_RING_STAT 0x0000005c
40#define CRYPTO4XX_IO_THRESHOLD 0x00000060
41#define CRYPTO4XX_GATH_RING_BASE 0x00000064
42#define CRYPTO4XX_SCAT_RING_BASE 0x00000068
43#define CRYPTO4XX_PART_RING_SIZE 0x0000006c
44#define CRYPTO4XX_PART_RING_CFG 0x00000070
45
46#define CRYPTO4XX_PDR_BASE_UADDR 0x00000080
47#define CRYPTO4XX_RDR_BASE_UADDR 0x00000084
48#define CRYPTO4XX_PKT_SRC_UADDR 0x00000088
49#define CRYPTO4XX_PKT_DEST_UADDR 0x0000008c
50#define CRYPTO4XX_SA_UADDR 0x00000090
51#define CRYPTO4XX_GATH_RING_BASE_UADDR 0x000000A0
52#define CRYPTO4XX_SCAT_RING_BASE_UADDR 0x000000A4
53
54#define CRYPTO4XX_SEQ_RD 0x00000408
55#define CRYPTO4XX_SEQ_MASK_RD 0x0000040C
56
57#define CRYPTO4XX_SA_CMD_0 0x00010600
58#define CRYPTO4XX_SA_CMD_1 0x00010604
59
60#define CRYPTO4XX_STATE_PTR 0x000106dc
61#define CRYPTO4XX_STATE_IV 0x00010700
62#define CRYPTO4XX_STATE_HASH_BYTE_CNT_0 0x00010710
63#define CRYPTO4XX_STATE_HASH_BYTE_CNT_1 0x00010714
64
65#define CRYPTO4XX_STATE_IDIGEST_0 0x00010718
66#define CRYPTO4XX_STATE_IDIGEST_1 0x0001071c
67
68#define CRYPTO4XX_DATA_IN 0x00018000
69#define CRYPTO4XX_DATA_OUT 0x0001c000
70
71#define CRYPTO4XX_INT_UNMASK_STAT 0x000500a0
72#define CRYPTO4XX_INT_MASK_STAT 0x000500a4
73#define CRYPTO4XX_INT_CLR 0x000500a4
74#define CRYPTO4XX_INT_EN 0x000500a8
75
76#define CRYPTO4XX_INT_PKA 0x00000002
77#define CRYPTO4XX_INT_PDR_DONE 0x00008000
78#define CRYPTO4XX_INT_MA_WR_ERR 0x00020000
79#define CRYPTO4XX_INT_MA_RD_ERR 0x00010000
80#define CRYPTO4XX_INT_PE_ERR 0x00000200
81#define CRYPTO4XX_INT_USER_DMA_ERR 0x00000040
82#define CRYPTO4XX_INT_SLAVE_ERR 0x00000010
83#define CRYPTO4XX_INT_MASTER_ERR 0x00000008
84#define CRYPTO4XX_INT_ERROR 0x00030258
85
86#define CRYPTO4XX_INT_CFG 0x000500ac
87#define CRYPTO4XX_INT_DESCR_RD 0x000500b0
88#define CRYPTO4XX_INT_DESCR_CNT 0x000500b4
89#define CRYPTO4XX_INT_TIMEOUT_CNT 0x000500b8
90
91#define CRYPTO4XX_DEVICE_CTRL 0x00060080
92#define CRYPTO4XX_DEVICE_ID 0x00060084
93#define CRYPTO4XX_DEVICE_INFO 0x00060088
94#define CRYPTO4XX_DMA_USER_SRC 0x00060094
95#define CRYPTO4XX_DMA_USER_DEST 0x00060098
96#define CRYPTO4XX_DMA_USER_CMD 0x0006009C
97
98#define CRYPTO4XX_DMA_CFG 0x000600d4
99#define CRYPTO4XX_BYTE_ORDER_CFG 0x000600d8
100#define CRYPTO4XX_ENDIAN_CFG 0x000600d8
101
102#define CRYPTO4XX_PRNG_STAT 0x00070000
103#define CRYPTO4XX_PRNG_CTRL 0x00070004
104#define CRYPTO4XX_PRNG_SEED_L 0x00070008
105#define CRYPTO4XX_PRNG_SEED_H 0x0007000c
106
107#define CRYPTO4XX_PRNG_RES_0 0x00070020
108#define CRYPTO4XX_PRNG_RES_1 0x00070024
109#define CRYPTO4XX_PRNG_RES_2 0x00070028
110#define CRYPTO4XX_PRNG_RES_3 0x0007002C
111
112#define CRYPTO4XX_PRNG_LFSR_L 0x00070030
113#define CRYPTO4XX_PRNG_LFSR_H 0x00070034
114
115/**
116 * Initilize CRYPTO ENGINE registers, and memory bases.
117 */
118#define PPC4XX_PDR_POLL 0x3ff
119#define PPC4XX_OUTPUT_THRESHOLD 2
120#define PPC4XX_INPUT_THRESHOLD 2
121#define PPC4XX_PD_SIZE 6
122#define PPC4XX_CTX_DONE_INT 0x2000
123#define PPC4XX_PD_DONE_INT 0x8000
124#define PPC4XX_BYTE_ORDER 0x22222
125#define PPC4XX_INTERRUPT_CLR 0x3ffff
126#define PPC4XX_PRNG_CTRL_AUTO_EN 0x3
127#define PPC4XX_DC_3DES_EN 1
128#define PPC4XX_INT_DESCR_CNT 4
129#define PPC4XX_INT_TIMEOUT_CNT 0
130#define PPC4XX_INT_CFG 1
131/**
132 * all follow define are ad hoc
133 */
134#define PPC4XX_RING_RETRY 100
135#define PPC4XX_RING_POLL 100
136#define PPC4XX_SDR_SIZE PPC4XX_NUM_SD
137#define PPC4XX_GDR_SIZE PPC4XX_NUM_GD
138
139/**
140 * Generic Security Association (SA) with all possible fields. These will
141 * never likely used except for reference purpose. These structure format
142 * can be not changed as the hardware expects them to be layout as defined.
143 * Field can be removed or reduced but ordering can not be changed.
144 */
145#define CRYPTO4XX_DMA_CFG_OFFSET 0x40
146union ce_pe_dma_cfg {
147 struct {
148 u32 rsv:7;
149 u32 dir_host:1;
150 u32 rsv1:2;
151 u32 bo_td_en:1;
152 u32 dis_pdr_upd:1;
153 u32 bo_sgpd_en:1;
154 u32 bo_data_en:1;
155 u32 bo_sa_en:1;
156 u32 bo_pd_en:1;
157 u32 rsv2:4;
158 u32 dynamic_sa_en:1;
159 u32 pdr_mode:2;
160 u32 pe_mode:1;
161 u32 rsv3:5;
162 u32 reset_sg:1;
163 u32 reset_pdr:1;
164 u32 reset_pe:1;
165 } bf;
166 u32 w;
167} __attribute__((packed));
168
169#define CRYPTO4XX_PDR_BASE_OFFSET 0x48
170#define CRYPTO4XX_RDR_BASE_OFFSET 0x4c
171#define CRYPTO4XX_RING_SIZE_OFFSET 0x50
172union ce_ring_size {
173 struct {
174 u32 ring_offset:16;
175 u32 rsv:6;
176 u32 ring_size:10;
177 } bf;
178 u32 w;
179} __attribute__((packed));
180
181#define CRYPTO4XX_RING_CONTROL_OFFSET 0x54
182union ce_ring_contol {
183 struct {
184 u32 continuous:1;
185 u32 rsv:5;
186 u32 ring_retry_divisor:10;
187 u32 rsv1:4;
188 u32 ring_poll_divisor:10;
189 } bf;
190 u32 w;
191} __attribute__((packed));
192
193#define CRYPTO4XX_IO_THRESHOLD_OFFSET 0x60
194union ce_io_threshold {
195 struct {
196 u32 rsv:6;
197 u32 output_threshold:10;
198 u32 rsv1:6;
199 u32 input_threshold:10;
200 } bf;
201 u32 w;
202} __attribute__((packed));
203
204#define CRYPTO4XX_GATHER_RING_BASE_OFFSET 0x64
205#define CRYPTO4XX_SCATTER_RING_BASE_OFFSET 0x68
206
207union ce_part_ring_size {
208 struct {
209 u32 sdr_size:16;
210 u32 gdr_size:16;
211 } bf;
212 u32 w;
213} __attribute__((packed));
214
215#define MAX_BURST_SIZE_32 0
216#define MAX_BURST_SIZE_64 1
217#define MAX_BURST_SIZE_128 2
218#define MAX_BURST_SIZE_256 3
219
220/* gather descriptor control length */
221struct gd_ctl_len {
222 u32 len:16;
223 u32 rsv:14;
224 u32 done:1;
225 u32 ready:1;
226} __attribute__((packed));
227
228struct ce_gd {
229 u32 ptr;
230 struct gd_ctl_len ctl_len;
231} __attribute__((packed));
232
233struct sd_ctl {
234 u32 ctl:30;
235 u32 done:1;
236 u32 rdy:1;
237} __attribute__((packed));
238
239struct ce_sd {
240 u32 ptr;
241 struct sd_ctl ctl;
242} __attribute__((packed));
243
244#define PD_PAD_CTL_32 0x10
245#define PD_PAD_CTL_64 0x20
246#define PD_PAD_CTL_128 0x40
247#define PD_PAD_CTL_256 0x80
248union ce_pd_ctl {
249 struct {
250 u32 pd_pad_ctl:8;
251 u32 status:8;
252 u32 next_hdr:8;
253 u32 rsv:2;
254 u32 cached_sa:1;
255 u32 hash_final:1;
256 u32 init_arc4:1;
257 u32 rsv1:1;
258 u32 pe_done:1;
259 u32 host_ready:1;
260 } bf;
261 u32 w;
262} __attribute__((packed));
263
264union ce_pd_ctl_len {
265 struct {
266 u32 bypass:8;
267 u32 pe_done:1;
268 u32 host_ready:1;
269 u32 rsv:2;
270 u32 pkt_len:20;
271 } bf;
272 u32 w;
273} __attribute__((packed));
274
275struct ce_pd {
276 union ce_pd_ctl pd_ctl;
277 u32 src;
278 u32 dest;
279 u32 sa; /* get from ctx->sa_dma_addr */
280 u32 sa_len; /* only if dynamic sa is used */
281 union ce_pd_ctl_len pd_ctl_len;
282
283} __attribute__((packed));
284#endif
diff --git a/drivers/crypto/amcc/crypto4xx_sa.c b/drivers/crypto/amcc/crypto4xx_sa.c
new file mode 100644
index 000000000000..466fd94cd4a3
--- /dev/null
+++ b/drivers/crypto/amcc/crypto4xx_sa.c
@@ -0,0 +1,108 @@
1/**
2 * AMCC SoC PPC4xx Crypto Driver
3 *
4 * Copyright (c) 2008 Applied Micro Circuits Corporation.
5 * All rights reserved. James Hsiao <jhsiao@amcc.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * @file crypto4xx_sa.c
18 *
19 * This file implements the security context
20 * assoicate format.
21 */
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/moduleparam.h>
25#include <linux/mod_devicetable.h>
26#include <linux/interrupt.h>
27#include <linux/spinlock_types.h>
28#include <linux/highmem.h>
29#include <linux/scatterlist.h>
30#include <linux/crypto.h>
31#include <crypto/algapi.h>
32#include <crypto/des.h>
33#include "crypto4xx_reg_def.h"
34#include "crypto4xx_sa.h"
35#include "crypto4xx_core.h"
36
37u32 get_dynamic_sa_offset_iv_field(struct crypto4xx_ctx *ctx)
38{
39 u32 offset;
40 union dynamic_sa_contents cts;
41
42 if (ctx->direction == DIR_INBOUND)
43 cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_in))->sa_contents;
44 else
45 cts.w = ((struct dynamic_sa_ctl *)(ctx->sa_out))->sa_contents;
46 offset = cts.bf.key_size
47 + cts.bf.inner_size
48 + cts.bf.outer_size
49 + cts.bf.spi
50 + cts.bf.seq_num0
51 + cts.bf.seq_num1
52 + cts.bf.seq_num_mask0
53 + cts.bf.seq_num_mask1
54 + cts.bf.seq_num_mask2
55 + cts.bf.seq_num_mask3;
56
57 return sizeof(struct dynamic_sa_ctl) + offset * 4;
58}
59
60u32 get_dynamic_sa_offset_state_ptr_field(struct crypto4xx_ctx *ctx)
61{
62 u32 offset;
63 union dynamic_sa_contents cts;
64
65 if (ctx->direction == DIR_INBOUND)
66 cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
67 else
68 cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;
69 offset = cts.bf.key_size
70 + cts.bf.inner_size
71 + cts.bf.outer_size
72 + cts.bf.spi
73 + cts.bf.seq_num0
74 + cts.bf.seq_num1
75 + cts.bf.seq_num_mask0
76 + cts.bf.seq_num_mask1
77 + cts.bf.seq_num_mask2
78 + cts.bf.seq_num_mask3
79 + cts.bf.iv0
80 + cts.bf.iv1
81 + cts.bf.iv2
82 + cts.bf.iv3;
83
84 return sizeof(struct dynamic_sa_ctl) + offset * 4;
85}
86
87u32 get_dynamic_sa_iv_size(struct crypto4xx_ctx *ctx)
88{
89 union dynamic_sa_contents cts;
90
91 if (ctx->direction == DIR_INBOUND)
92 cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
93 else
94 cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;
95 return (cts.bf.iv0 + cts.bf.iv1 + cts.bf.iv2 + cts.bf.iv3) * 4;
96}
97
98u32 get_dynamic_sa_offset_key_field(struct crypto4xx_ctx *ctx)
99{
100 union dynamic_sa_contents cts;
101
102 if (ctx->direction == DIR_INBOUND)
103 cts.w = ((struct dynamic_sa_ctl *) ctx->sa_in)->sa_contents;
104 else
105 cts.w = ((struct dynamic_sa_ctl *) ctx->sa_out)->sa_contents;
106
107 return sizeof(struct dynamic_sa_ctl);
108}
diff --git a/drivers/crypto/amcc/crypto4xx_sa.h b/drivers/crypto/amcc/crypto4xx_sa.h
new file mode 100644
index 000000000000..4b83ed7e5570
--- /dev/null
+++ b/drivers/crypto/amcc/crypto4xx_sa.h
@@ -0,0 +1,243 @@
1/**
2 * AMCC SoC PPC4xx Crypto Driver
3 *
4 * Copyright (c) 2008 Applied Micro Circuits Corporation.
5 * All rights reserved. James Hsiao <jhsiao@amcc.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * This file defines the security context
18 * assoicate format.
19 */
20
21#ifndef __CRYPTO4XX_SA_H__
22#define __CRYPTO4XX_SA_H__
23
24#define AES_IV_SIZE 16
25
26/**
27 * Contents of Dynamic Security Association (SA) with all possible fields
28 */
29union dynamic_sa_contents {
30 struct {
31 u32 arc4_state_ptr:1;
32 u32 arc4_ij_ptr:1;
33 u32 state_ptr:1;
34 u32 iv3:1;
35 u32 iv2:1;
36 u32 iv1:1;
37 u32 iv0:1;
38 u32 seq_num_mask3:1;
39 u32 seq_num_mask2:1;
40 u32 seq_num_mask1:1;
41 u32 seq_num_mask0:1;
42 u32 seq_num1:1;
43 u32 seq_num0:1;
44 u32 spi:1;
45 u32 outer_size:5;
46 u32 inner_size:5;
47 u32 key_size:4;
48 u32 cmd_size:4;
49 } bf;
50 u32 w;
51} __attribute__((packed));
52
53#define DIR_OUTBOUND 0
54#define DIR_INBOUND 1
55#define SA_OP_GROUP_BASIC 0
56#define SA_OPCODE_ENCRYPT 0
57#define SA_OPCODE_DECRYPT 0
58#define SA_OPCODE_HASH 3
59#define SA_CIPHER_ALG_DES 0
60#define SA_CIPHER_ALG_3DES 1
61#define SA_CIPHER_ALG_ARC4 2
62#define SA_CIPHER_ALG_AES 3
63#define SA_CIPHER_ALG_KASUMI 4
64#define SA_CIPHER_ALG_NULL 15
65
66#define SA_HASH_ALG_MD5 0
67#define SA_HASH_ALG_SHA1 1
68#define SA_HASH_ALG_NULL 15
69#define SA_HASH_ALG_SHA1_DIGEST_SIZE 20
70
71#define SA_LOAD_HASH_FROM_SA 0
72#define SA_LOAD_HASH_FROM_STATE 2
73#define SA_NOT_LOAD_HASH 3
74#define SA_LOAD_IV_FROM_SA 0
75#define SA_LOAD_IV_FROM_INPUT 1
76#define SA_LOAD_IV_FROM_STATE 2
77#define SA_LOAD_IV_GEN_IV 3
78
79#define SA_PAD_TYPE_CONSTANT 2
80#define SA_PAD_TYPE_ZERO 3
81#define SA_PAD_TYPE_TLS 5
82#define SA_PAD_TYPE_DTLS 5
83#define SA_NOT_SAVE_HASH 0
84#define SA_SAVE_HASH 1
85#define SA_NOT_SAVE_IV 0
86#define SA_SAVE_IV 1
87#define SA_HEADER_PROC 1
88#define SA_NO_HEADER_PROC 0
89
90union sa_command_0 {
91 struct {
92 u32 scatter:1;
93 u32 gather:1;
94 u32 save_hash_state:1;
95 u32 save_iv:1;
96 u32 load_hash_state:2;
97 u32 load_iv:2;
98 u32 digest_len:4;
99 u32 hdr_proc:1;
100 u32 extend_pad:1;
101 u32 stream_cipher_pad:1;
102 u32 rsv:1;
103 u32 hash_alg:4;
104 u32 cipher_alg:4;
105 u32 pad_type:2;
106 u32 op_group:2;
107 u32 dir:1;
108 u32 opcode:3;
109 } bf;
110 u32 w;
111} __attribute__((packed));
112
113#define CRYPTO_MODE_ECB 0
114#define CRYPTO_MODE_CBC 1
115
116#define CRYPTO_FEEDBACK_MODE_NO_FB 0
117#define CRYPTO_FEEDBACK_MODE_64BIT_OFB 0
118#define CRYPTO_FEEDBACK_MODE_8BIT_CFB 1
119#define CRYPTO_FEEDBACK_MODE_1BIT_CFB 2
120#define CRYPTO_FEEDBACK_MODE_128BIT_CFB 3
121
122#define SA_AES_KEY_LEN_128 2
123#define SA_AES_KEY_LEN_192 3
124#define SA_AES_KEY_LEN_256 4
125
126#define SA_REV2 1
127/**
128 * The follow defines bits sa_command_1
129 * In Basic hash mode this bit define simple hash or hmac.
130 * In IPsec mode, this bit define muting control.
131 */
132#define SA_HASH_MODE_HASH 0
133#define SA_HASH_MODE_HMAC 1
134#define SA_MC_ENABLE 0
135#define SA_MC_DISABLE 1
136#define SA_NOT_COPY_HDR 0
137#define SA_COPY_HDR 1
138#define SA_NOT_COPY_PAD 0
139#define SA_COPY_PAD 1
140#define SA_NOT_COPY_PAYLOAD 0
141#define SA_COPY_PAYLOAD 1
142#define SA_EXTENDED_SN_OFF 0
143#define SA_EXTENDED_SN_ON 1
144#define SA_SEQ_MASK_OFF 0
145#define SA_SEQ_MASK_ON 1
146
147union sa_command_1 {
148 struct {
149 u32 crypto_mode31:1;
150 u32 save_arc4_state:1;
151 u32 arc4_stateful:1;
152 u32 key_len:5;
153 u32 hash_crypto_offset:8;
154 u32 sa_rev:2;
155 u32 byte_offset:1;
156 u32 hmac_muting:1;
157 u32 feedback_mode:2;
158 u32 crypto_mode9_8:2;
159 u32 extended_seq_num:1;
160 u32 seq_num_mask:1;
161 u32 mutable_bit_proc:1;
162 u32 ip_version:1;
163 u32 copy_pad:1;
164 u32 copy_payload:1;
165 u32 copy_hdr:1;
166 u32 rsv1:1;
167 } bf;
168 u32 w;
169} __attribute__((packed));
170
171struct dynamic_sa_ctl {
172 u32 sa_contents;
173 union sa_command_0 sa_command_0;
174 union sa_command_1 sa_command_1;
175} __attribute__((packed));
176
177/**
178 * State Record for Security Association (SA)
179 */
180struct sa_state_record {
181 u32 save_iv[4];
182 u32 save_hash_byte_cnt[2];
183 u32 save_digest[16];
184} __attribute__((packed));
185
186/**
187 * Security Association (SA) for AES128
188 *
189 */
190struct dynamic_sa_aes128 {
191 struct dynamic_sa_ctl ctrl;
192 u32 key[4];
193 u32 iv[4]; /* for CBC, OFC, and CFB mode */
194 u32 state_ptr;
195 u32 reserved;
196} __attribute__((packed));
197
198#define SA_AES128_LEN (sizeof(struct dynamic_sa_aes128)/4)
199#define SA_AES128_CONTENTS 0x3e000042
200
201/*
202 * Security Association (SA) for AES192
203 */
204struct dynamic_sa_aes192 {
205 struct dynamic_sa_ctl ctrl;
206 u32 key[6];
207 u32 iv[4]; /* for CBC, OFC, and CFB mode */
208 u32 state_ptr;
209 u32 reserved;
210} __attribute__((packed));
211
212#define SA_AES192_LEN (sizeof(struct dynamic_sa_aes192)/4)
213#define SA_AES192_CONTENTS 0x3e000062
214
215/**
216 * Security Association (SA) for AES256
217 */
218struct dynamic_sa_aes256 {
219 struct dynamic_sa_ctl ctrl;
220 u32 key[8];
221 u32 iv[4]; /* for CBC, OFC, and CFB mode */
222 u32 state_ptr;
223 u32 reserved;
224} __attribute__((packed));
225
226#define SA_AES256_LEN (sizeof(struct dynamic_sa_aes256)/4)
227#define SA_AES256_CONTENTS 0x3e000082
228#define SA_AES_CONTENTS 0x3e000002
229
230/**
231 * Security Association (SA) for HASH160: HMAC-SHA1
232 */
233struct dynamic_sa_hash160 {
234 struct dynamic_sa_ctl ctrl;
235 u32 inner_digest[5];
236 u32 outer_digest[5];
237 u32 state_ptr;
238 u32 reserved;
239} __attribute__((packed));
240#define SA_HASH160_LEN (sizeof(struct dynamic_sa_hash160)/4)
241#define SA_HASH160_CONTENTS 0x2000a502
242
243#endif
diff --git a/drivers/dio/dio.c b/drivers/dio/dio.c
index 10c3c498358c..55dd88d82d6d 100644
--- a/drivers/dio/dio.c
+++ b/drivers/dio/dio.c
@@ -182,7 +182,7 @@ static int __init dio_init(void)
182 182
183 /* Initialize the DIO bus */ 183 /* Initialize the DIO bus */
184 INIT_LIST_HEAD(&dio_bus.devices); 184 INIT_LIST_HEAD(&dio_bus.devices);
185 strcpy(dio_bus.dev.bus_id, "dio"); 185 dev_set_name(&dio_bus.dev, "dio");
186 error = device_register(&dio_bus.dev); 186 error = device_register(&dio_bus.dev);
187 if (error) { 187 if (error) {
188 pr_err("DIO: Error registering dio_bus\n"); 188 pr_err("DIO: Error registering dio_bus\n");
@@ -237,7 +237,7 @@ static int __init dio_init(void)
237 dev->scode = scode; 237 dev->scode = scode;
238 dev->resource.start = pa; 238 dev->resource.start = pa;
239 dev->resource.end = pa + DIO_SIZE(scode, va); 239 dev->resource.end = pa + DIO_SIZE(scode, va);
240 sprintf(dev->dev.bus_id,"%02x", scode); 240 dev_set_name(&dev->dev, "%02x", scode);
241 241
242 /* read the ID byte(s) and encode if necessary. */ 242 /* read the ID byte(s) and encode if necessary. */
243 prid = DIO_ID(va); 243 prid = DIO_ID(va);
diff --git a/drivers/dma/dw_dmac.c b/drivers/dma/dw_dmac.c
index a97c07eef7ec..20ad3d26bec2 100644
--- a/drivers/dma/dw_dmac.c
+++ b/drivers/dma/dw_dmac.c
@@ -1011,7 +1011,7 @@ static int __init dw_probe(struct platform_device *pdev)
1011 dma_writel(dw, CFG, DW_CFG_DMA_EN); 1011 dma_writel(dw, CFG, DW_CFG_DMA_EN);
1012 1012
1013 printk(KERN_INFO "%s: DesignWare DMA Controller, %d channels\n", 1013 printk(KERN_INFO "%s: DesignWare DMA Controller, %d channels\n",
1014 pdev->dev.bus_id, dw->dma.chancnt); 1014 dev_name(&pdev->dev), dw->dma.chancnt);
1015 1015
1016 dma_async_device_register(&dw->dma); 1016 dma_async_device_register(&dw->dma);
1017 1017
diff --git a/drivers/edac/cell_edac.c b/drivers/edac/cell_edac.c
index 24f3ca851523..cb0f639f049d 100644
--- a/drivers/edac/cell_edac.c
+++ b/drivers/edac/cell_edac.c
@@ -198,7 +198,7 @@ static int __devinit cell_edac_probe(struct platform_device *pdev)
198 mci->edac_cap = EDAC_FLAG_EC | EDAC_FLAG_SECDED; 198 mci->edac_cap = EDAC_FLAG_EC | EDAC_FLAG_SECDED;
199 mci->mod_name = "cell_edac"; 199 mci->mod_name = "cell_edac";
200 mci->ctl_name = "MIC"; 200 mci->ctl_name = "MIC";
201 mci->dev_name = pdev->dev.bus_id; 201 mci->dev_name = dev_name(&pdev->dev);
202 mci->edac_check = cell_edac_check; 202 mci->edac_check = cell_edac_check;
203 cell_edac_init_csrows(mci); 203 cell_edac_init_csrows(mci);
204 204
diff --git a/drivers/edac/mpc85xx_edac.c b/drivers/edac/mpc85xx_edac.c
index 853ef37ec006..4637a4a757df 100644
--- a/drivers/edac/mpc85xx_edac.c
+++ b/drivers/edac/mpc85xx_edac.c
@@ -218,7 +218,7 @@ static int __devinit mpc85xx_pci_err_probe(struct of_device *op,
218 pci->dev = &op->dev; 218 pci->dev = &op->dev;
219 pci->mod_name = EDAC_MOD_STR; 219 pci->mod_name = EDAC_MOD_STR;
220 pci->ctl_name = pdata->name; 220 pci->ctl_name = pdata->name;
221 pci->dev_name = op->dev.bus_id; 221 pci->dev_name = dev_name(&op->dev);
222 222
223 if (edac_op_state == EDAC_OPSTATE_POLL) 223 if (edac_op_state == EDAC_OPSTATE_POLL)
224 pci->edac_check = mpc85xx_pci_check; 224 pci->edac_check = mpc85xx_pci_check;
diff --git a/drivers/edac/mv64x60_edac.c b/drivers/edac/mv64x60_edac.c
index 083ce8d0c63d..5131aaae8e03 100644
--- a/drivers/edac/mv64x60_edac.c
+++ b/drivers/edac/mv64x60_edac.c
@@ -121,7 +121,7 @@ static int __devinit mv64x60_pci_err_probe(struct platform_device *pdev)
121 pdata->irq = NO_IRQ; 121 pdata->irq = NO_IRQ;
122 platform_set_drvdata(pdev, pci); 122 platform_set_drvdata(pdev, pci);
123 pci->dev = &pdev->dev; 123 pci->dev = &pdev->dev;
124 pci->dev_name = pdev->dev.bus_id; 124 pci->dev_name = dev_name(&pdev->dev);
125 pci->mod_name = EDAC_MOD_STR; 125 pci->mod_name = EDAC_MOD_STR;
126 pci->ctl_name = pdata->name; 126 pci->ctl_name = pdata->name;
127 127
@@ -294,7 +294,7 @@ static int __devinit mv64x60_sram_err_probe(struct platform_device *pdev)
294 pdata->irq = NO_IRQ; 294 pdata->irq = NO_IRQ;
295 edac_dev->dev = &pdev->dev; 295 edac_dev->dev = &pdev->dev;
296 platform_set_drvdata(pdev, edac_dev); 296 platform_set_drvdata(pdev, edac_dev);
297 edac_dev->dev_name = pdev->dev.bus_id; 297 edac_dev->dev_name = dev_name(&pdev->dev);
298 298
299 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 299 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
300 if (!r) { 300 if (!r) {
@@ -462,7 +462,7 @@ static int __devinit mv64x60_cpu_err_probe(struct platform_device *pdev)
462 pdata->irq = NO_IRQ; 462 pdata->irq = NO_IRQ;
463 edac_dev->dev = &pdev->dev; 463 edac_dev->dev = &pdev->dev;
464 platform_set_drvdata(pdev, edac_dev); 464 platform_set_drvdata(pdev, edac_dev);
465 edac_dev->dev_name = pdev->dev.bus_id; 465 edac_dev->dev_name = dev_name(&pdev->dev);
466 466
467 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 467 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
468 if (!r) { 468 if (!r) {
@@ -713,7 +713,7 @@ static int __devinit mv64x60_mc_err_probe(struct platform_device *pdev)
713 platform_set_drvdata(pdev, mci); 713 platform_set_drvdata(pdev, mci);
714 pdata->name = "mv64x60_mc_err"; 714 pdata->name = "mv64x60_mc_err";
715 pdata->irq = NO_IRQ; 715 pdata->irq = NO_IRQ;
716 mci->dev_name = pdev->dev.bus_id; 716 mci->dev_name = dev_name(&pdev->dev);
717 pdata->edac_idx = edac_mc_idx++; 717 pdata->edac_idx = edac_mc_idx++;
718 718
719 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 719 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
diff --git a/drivers/eisa/eisa-bus.c b/drivers/eisa/eisa-bus.c
index c950bf8606d9..66958b3f10b4 100644
--- a/drivers/eisa/eisa-bus.c
+++ b/drivers/eisa/eisa-bus.c
@@ -200,7 +200,7 @@ static int __init eisa_init_device (struct eisa_root_device *root,
200 edev->dev.bus = &eisa_bus_type; 200 edev->dev.bus = &eisa_bus_type;
201 edev->dev.dma_mask = &edev->dma_mask; 201 edev->dev.dma_mask = &edev->dma_mask;
202 edev->dev.coherent_dma_mask = edev->dma_mask; 202 edev->dev.coherent_dma_mask = edev->dma_mask;
203 sprintf (edev->dev.bus_id, "%02X:%02X", root->bus_nr, slot); 203 dev_set_name(&edev->dev, "%02X:%02X", root->bus_nr, slot);
204 204
205 for (i = 0; i < EISA_MAX_RESOURCES; i++) { 205 for (i = 0; i < EISA_MAX_RESOURCES; i++) {
206#ifdef CONFIG_EISA_NAMES 206#ifdef CONFIG_EISA_NAMES
@@ -301,7 +301,7 @@ static int __init eisa_probe (struct eisa_root_device *root)
301 struct eisa_device *edev; 301 struct eisa_device *edev;
302 302
303 printk (KERN_INFO "EISA: Probing bus %d at %s\n", 303 printk (KERN_INFO "EISA: Probing bus %d at %s\n",
304 root->bus_nr, root->dev->bus_id); 304 root->bus_nr, dev_name(root->dev));
305 305
306 /* First try to get hold of slot 0. If there is no device 306 /* First try to get hold of slot 0. If there is no device
307 * here, simply fail, unless root->force_probe is set. */ 307 * here, simply fail, unless root->force_probe is set. */
diff --git a/drivers/gpio/bt8xxgpio.c b/drivers/gpio/bt8xxgpio.c
index 7a1168249dd5..984b587f0f96 100644
--- a/drivers/gpio/bt8xxgpio.c
+++ b/drivers/gpio/bt8xxgpio.c
@@ -160,7 +160,7 @@ static void bt8xxgpio_gpio_setup(struct bt8xxgpio *bg)
160{ 160{
161 struct gpio_chip *c = &bg->gpio; 161 struct gpio_chip *c = &bg->gpio;
162 162
163 c->label = bg->pdev->dev.bus_id; 163 c->label = dev_name(&bg->pdev->dev);
164 c->owner = THIS_MODULE; 164 c->owner = THIS_MODULE;
165 c->direction_input = bt8xxgpio_gpio_direction_input; 165 c->direction_input = bt8xxgpio_gpio_direction_input;
166 c->get = bt8xxgpio_gpio_get; 166 c->get = bt8xxgpio_gpio_get;
diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
index 5aa6780652aa..186d08159d48 100644
--- a/drivers/gpu/drm/drm_sysfs.c
+++ b/drivers/gpu/drm/drm_sysfs.c
@@ -359,8 +359,8 @@ int drm_sysfs_connector_add(struct drm_connector *connector)
359 DRM_DEBUG("adding \"%s\" to sysfs\n", 359 DRM_DEBUG("adding \"%s\" to sysfs\n",
360 drm_get_connector_name(connector)); 360 drm_get_connector_name(connector));
361 361
362 snprintf(connector->kdev.bus_id, BUS_ID_SIZE, "card%d-%s", 362 dev_set_name(&connector->kdev, "card%d-%s",
363 dev->primary->index, drm_get_connector_name(connector)); 363 dev->primary->index, drm_get_connector_name(connector));
364 ret = device_register(&connector->kdev); 364 ret = device_register(&connector->kdev);
365 365
366 if (ret) { 366 if (ret) {
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index e7d984866de0..fbb9030b68a5 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -841,7 +841,7 @@ int i2c_attach_client(struct i2c_client *client)
841 841
842 if (client->driver && !is_newstyle_driver(client->driver)) { 842 if (client->driver && !is_newstyle_driver(client->driver)) {
843 client->dev.release = i2c_client_release; 843 client->dev.release = i2c_client_release;
844 client->dev.uevent_suppress = 1; 844 dev_set_uevent_suppress(&client->dev, 1);
845 } else 845 } else
846 client->dev.release = i2c_client_dev_release; 846 client->dev.release = i2c_client_dev_release;
847 847
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index 5ea3bfad172a..640c99207242 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -56,8 +56,12 @@ if IDE
56 56
57comment "Please see Documentation/ide/ide.txt for help/info on IDE drives" 57comment "Please see Documentation/ide/ide.txt for help/info on IDE drives"
58 58
59config IDE_XFER_MODE
60 bool
61
59config IDE_TIMINGS 62config IDE_TIMINGS
60 bool 63 bool
64 select IDE_XFER_MODE
61 65
62config IDE_ATAPI 66config IDE_ATAPI
63 bool 67 bool
@@ -698,6 +702,7 @@ config BLK_DEV_IDE_PMAC_ATA100FIRST
698config BLK_DEV_IDE_AU1XXX 702config BLK_DEV_IDE_AU1XXX
699 bool "IDE for AMD Alchemy Au1200" 703 bool "IDE for AMD Alchemy Au1200"
700 depends on SOC_AU1200 704 depends on SOC_AU1200
705 select IDE_XFER_MODE
701choice 706choice
702 prompt "IDE Mode for AMD Alchemy Au1200" 707 prompt "IDE Mode for AMD Alchemy Au1200"
703 default CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA 708 default CONFIG_BLK_DEV_IDE_AU1XXX_PIO_DBDMA
@@ -871,6 +876,7 @@ config BLK_DEV_ALI14XX
871 876
872config BLK_DEV_DTC2278 877config BLK_DEV_DTC2278
873 tristate "DTC-2278 support" 878 tristate "DTC-2278 support"
879 select IDE_XFER_MODE
874 select IDE_LEGACY 880 select IDE_LEGACY
875 help 881 help
876 This driver is enabled at runtime using the "dtc2278.probe" kernel 882 This driver is enabled at runtime using the "dtc2278.probe" kernel
@@ -902,6 +908,7 @@ config BLK_DEV_QD65XX
902 908
903config BLK_DEV_UMC8672 909config BLK_DEV_UMC8672
904 tristate "UMC-8672 support" 910 tristate "UMC-8672 support"
911 select IDE_XFER_MODE
905 select IDE_LEGACY 912 select IDE_LEGACY
906 help 913 help
907 This driver is enabled at runtime using the "umc8672.probe" kernel 914 This driver is enabled at runtime using the "umc8672.probe" kernel
@@ -915,5 +922,6 @@ endif
915config BLK_DEV_IDEDMA 922config BLK_DEV_IDEDMA
916 def_bool BLK_DEV_IDEDMA_SFF || \ 923 def_bool BLK_DEV_IDEDMA_SFF || \
917 BLK_DEV_IDEDMA_ICS || BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 924 BLK_DEV_IDEDMA_ICS || BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
925 select IDE_XFER_MODE
918 926
919endif # IDE 927endif # IDE
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index 1c326d94aa6d..9b4bbe1cdc1a 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -5,9 +5,11 @@
5EXTRA_CFLAGS += -Idrivers/ide 5EXTRA_CFLAGS += -Idrivers/ide
6 6
7ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \ 7ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \
8 ide-taskfile.o ide-pm.o ide-park.o ide-pio-blacklist.o ide-sysfs.o 8 ide-taskfile.o ide-pm.o ide-park.o ide-sysfs.o ide-devsets.o \
9 ide-io-std.o ide-eh.o
9 10
10# core IDE code 11# core IDE code
12ide-core-$(CONFIG_IDE_XFER_MODE) += ide-pio-blacklist.o ide-xfer-mode.o
11ide-core-$(CONFIG_IDE_TIMINGS) += ide-timings.o 13ide-core-$(CONFIG_IDE_TIMINGS) += ide-timings.o
12ide-core-$(CONFIG_IDE_ATAPI) += ide-atapi.o 14ide-core-$(CONFIG_IDE_ATAPI) += ide-atapi.o
13ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o 15ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o
diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
index 4485b9c6f0e6..878f8ec6dbe1 100644
--- a/drivers/ide/aec62xx.c
+++ b/drivers/ide/aec62xx.c
@@ -139,7 +139,7 @@ static void aec_set_pio_mode(ide_drive_t *drive, const u8 pio)
139 drive->hwif->port_ops->set_dma_mode(drive, pio + XFER_PIO_0); 139 drive->hwif->port_ops->set_dma_mode(drive, pio + XFER_PIO_0);
140} 140}
141 141
142static unsigned int init_chipset_aec62xx(struct pci_dev *dev) 142static int init_chipset_aec62xx(struct pci_dev *dev)
143{ 143{
144 /* These are necessary to get AEC6280 Macintosh cards to work */ 144 /* These are necessary to get AEC6280 Macintosh cards to work */
145 if ((dev->device == PCI_DEVICE_ID_ARTOP_ATP865) || 145 if ((dev->device == PCI_DEVICE_ID_ARTOP_ATP865) ||
@@ -156,7 +156,7 @@ static unsigned int init_chipset_aec62xx(struct pci_dev *dev)
156 pci_write_config_byte(dev, 0x4a, reg4ah | 0x80); 156 pci_write_config_byte(dev, 0x4a, reg4ah | 0x80);
157 } 157 }
158 158
159 return dev->irq; 159 return 0;
160} 160}
161 161
162static u8 atp86x_cable_detect(ide_hwif_t *hwif) 162static u8 atp86x_cable_detect(ide_hwif_t *hwif)
diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
index 66f43083408b..d3513b6b8530 100644
--- a/drivers/ide/alim15x3.c
+++ b/drivers/ide/alim15x3.c
@@ -212,7 +212,7 @@ static int ali15x3_dma_setup(ide_drive_t *drive)
212 * appropriate also sets up the 1533 southbridge. 212 * appropriate also sets up the 1533 southbridge.
213 */ 213 */
214 214
215static unsigned int init_chipset_ali15x3(struct pci_dev *dev) 215static int init_chipset_ali15x3(struct pci_dev *dev)
216{ 216{
217 unsigned long flags; 217 unsigned long flags;
218 u8 tmpbyte; 218 u8 tmpbyte;
diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
index 77267c859965..628cd2e5fed8 100644
--- a/drivers/ide/amd74xx.c
+++ b/drivers/ide/amd74xx.c
@@ -140,7 +140,7 @@ static void amd7411_cable_detect(struct pci_dev *dev)
140 * The initialization callback. Initialize drive independent registers. 140 * The initialization callback. Initialize drive independent registers.
141 */ 141 */
142 142
143static unsigned int init_chipset_amd74xx(struct pci_dev *dev) 143static int init_chipset_amd74xx(struct pci_dev *dev)
144{ 144{
145 u8 t = 0, offset = amd_offset(dev); 145 u8 t = 0, offset = amd_offset(dev);
146 146
@@ -172,7 +172,7 @@ static unsigned int init_chipset_amd74xx(struct pci_dev *dev)
172 t |= 0xf0; 172 t |= 0xf0;
173 pci_write_config_byte(dev, AMD_IDE_CONFIG + offset, t); 173 pci_write_config_byte(dev, AMD_IDE_CONFIG + offset, t);
174 174
175 return dev->irq; 175 return 0;
176} 176}
177 177
178static u8 amd_cable_detect(ide_hwif_t *hwif) 178static u8 amd_cable_detect(ide_hwif_t *hwif)
@@ -183,14 +183,6 @@ static u8 amd_cable_detect(ide_hwif_t *hwif)
183 return ATA_CBL_PATA40; 183 return ATA_CBL_PATA40;
184} 184}
185 185
186static void __devinit init_hwif_amd74xx(ide_hwif_t *hwif)
187{
188 struct pci_dev *dev = to_pci_dev(hwif->dev);
189
190 if (hwif->irq == 0) /* 0 is bogus but will do for now */
191 hwif->irq = pci_get_legacy_ide_irq(dev, hwif->channel);
192}
193
194static const struct ide_port_ops amd_port_ops = { 186static const struct ide_port_ops amd_port_ops = {
195 .set_pio_mode = amd_set_pio_mode, 187 .set_pio_mode = amd_set_pio_mode,
196 .set_dma_mode = amd_set_drive, 188 .set_dma_mode = amd_set_drive,
@@ -207,7 +199,6 @@ static const struct ide_port_ops amd_port_ops = {
207 { \ 199 { \
208 .name = DRV_NAME, \ 200 .name = DRV_NAME, \
209 .init_chipset = init_chipset_amd74xx, \ 201 .init_chipset = init_chipset_amd74xx, \
210 .init_hwif = init_hwif_amd74xx, \
211 .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, \ 202 .enablebits = {{0x40,0x02,0x02}, {0x40,0x01,0x01}}, \
212 .port_ops = &amd_port_ops, \ 203 .port_ops = &amd_port_ops, \
213 .host_flags = IDE_HFLAGS_AMD, \ 204 .host_flags = IDE_HFLAGS_AMD, \
@@ -221,7 +212,6 @@ static const struct ide_port_ops amd_port_ops = {
221 { \ 212 { \
222 .name = DRV_NAME, \ 213 .name = DRV_NAME, \
223 .init_chipset = init_chipset_amd74xx, \ 214 .init_chipset = init_chipset_amd74xx, \
224 .init_hwif = init_hwif_amd74xx, \
225 .enablebits = {{0x50,0x02,0x02}, {0x50,0x01,0x01}}, \ 215 .enablebits = {{0x50,0x02,0x02}, {0x50,0x01,0x01}}, \
226 .port_ops = &amd_port_ops, \ 216 .port_ops = &amd_port_ops, \
227 .host_flags = IDE_HFLAGS_AMD, \ 217 .host_flags = IDE_HFLAGS_AMD, \
diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
index ecd1e62ca91a..923cbfe259d3 100644
--- a/drivers/ide/atiixp.c
+++ b/drivers/ide/atiixp.c
@@ -142,7 +142,6 @@ static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
142 .name = DRV_NAME, 142 .name = DRV_NAME,
143 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}}, 143 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
144 .port_ops = &atiixp_port_ops, 144 .port_ops = &atiixp_port_ops,
145 .host_flags = IDE_HFLAG_LEGACY_IRQS,
146 .pio_mask = ATA_PIO4, 145 .pio_mask = ATA_PIO4,
147 .mwdma_mask = ATA_MWDMA2, 146 .mwdma_mask = ATA_MWDMA2,
148 .udma_mask = ATA_UDMA5, 147 .udma_mask = ATA_UDMA5,
@@ -151,7 +150,7 @@ static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
151 .name = DRV_NAME, 150 .name = DRV_NAME,
152 .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}}, 151 .enablebits = {{0x48,0x01,0x00}, {0x00,0x00,0x00}},
153 .port_ops = &atiixp_port_ops, 152 .port_ops = &atiixp_port_ops,
154 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_LEGACY_IRQS, 153 .host_flags = IDE_HFLAG_SINGLE,
155 .pio_mask = ATA_PIO4, 154 .pio_mask = ATA_PIO4,
156 .mwdma_mask = ATA_MWDMA2, 155 .mwdma_mask = ATA_MWDMA2,
157 .udma_mask = ATA_UDMA5, 156 .udma_mask = ATA_UDMA5,
diff --git a/drivers/ide/au1xxx-ide.c b/drivers/ide/au1xxx-ide.c
index 79a2dfed8eb7..154ec2cf734f 100644
--- a/drivers/ide/au1xxx-ide.c
+++ b/drivers/ide/au1xxx-ide.c
@@ -536,9 +536,8 @@ static const struct ide_port_info au1xxx_port_info = {
536#endif 536#endif
537}; 537};
538 538
539static int au_ide_probe(struct device *dev) 539static int au_ide_probe(struct platform_device *dev)
540{ 540{
541 struct platform_device *pdev = to_platform_device(dev);
542 _auide_hwif *ahwif = &auide_hwif; 541 _auide_hwif *ahwif = &auide_hwif;
543 struct resource *res; 542 struct resource *res;
544 struct ide_host *host; 543 struct ide_host *host;
@@ -552,23 +551,23 @@ static int au_ide_probe(struct device *dev)
552#endif 551#endif
553 552
554 memset(&auide_hwif, 0, sizeof(_auide_hwif)); 553 memset(&auide_hwif, 0, sizeof(_auide_hwif));
555 ahwif->irq = platform_get_irq(pdev, 0); 554 ahwif->irq = platform_get_irq(dev, 0);
556 555
557 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 556 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
558 557
559 if (res == NULL) { 558 if (res == NULL) {
560 pr_debug("%s %d: no base address\n", DRV_NAME, pdev->id); 559 pr_debug("%s %d: no base address\n", DRV_NAME, dev->id);
561 ret = -ENODEV; 560 ret = -ENODEV;
562 goto out; 561 goto out;
563 } 562 }
564 if (ahwif->irq < 0) { 563 if (ahwif->irq < 0) {
565 pr_debug("%s %d: no IRQ\n", DRV_NAME, pdev->id); 564 pr_debug("%s %d: no IRQ\n", DRV_NAME, dev->id);
566 ret = -ENODEV; 565 ret = -ENODEV;
567 goto out; 566 goto out;
568 } 567 }
569 568
570 if (!request_mem_region(res->start, res->end - res->start + 1, 569 if (!request_mem_region(res->start, res->end - res->start + 1,
571 pdev->name)) { 570 dev->name)) {
572 pr_debug("%s: request_mem_region failed\n", DRV_NAME); 571 pr_debug("%s: request_mem_region failed\n", DRV_NAME);
573 ret = -EBUSY; 572 ret = -EBUSY;
574 goto out; 573 goto out;
@@ -583,7 +582,7 @@ static int au_ide_probe(struct device *dev)
583 memset(&hw, 0, sizeof(hw)); 582 memset(&hw, 0, sizeof(hw));
584 auide_setup_ports(&hw, ahwif); 583 auide_setup_ports(&hw, ahwif);
585 hw.irq = ahwif->irq; 584 hw.irq = ahwif->irq;
586 hw.dev = dev; 585 hw.dev = &dev->dev;
587 hw.chipset = ide_au1xxx; 586 hw.chipset = ide_au1xxx;
588 587
589 ret = ide_host_add(&au1xxx_port_info, hws, &host); 588 ret = ide_host_add(&au1xxx_port_info, hws, &host);
@@ -592,7 +591,7 @@ static int au_ide_probe(struct device *dev)
592 591
593 auide_hwif.hwif = host->ports[0]; 592 auide_hwif.hwif = host->ports[0];
594 593
595 dev_set_drvdata(dev, host); 594 platform_set_drvdata(dev, host);
596 595
597 printk(KERN_INFO "Au1xxx IDE(builtin) configured for %s\n", mode ); 596 printk(KERN_INFO "Au1xxx IDE(builtin) configured for %s\n", mode );
598 597
@@ -600,38 +599,39 @@ static int au_ide_probe(struct device *dev)
600 return ret; 599 return ret;
601} 600}
602 601
603static int au_ide_remove(struct device *dev) 602static int au_ide_remove(struct platform_device *dev)
604{ 603{
605 struct platform_device *pdev = to_platform_device(dev);
606 struct resource *res; 604 struct resource *res;
607 struct ide_host *host = dev_get_drvdata(dev); 605 struct ide_host *host = platform_get_drvdata(dev);
608 _auide_hwif *ahwif = &auide_hwif; 606 _auide_hwif *ahwif = &auide_hwif;
609 607
610 ide_host_remove(host); 608 ide_host_remove(host);
611 609
612 iounmap((void *)ahwif->regbase); 610 iounmap((void *)ahwif->regbase);
613 611
614 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 612 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
615 release_mem_region(res->start, res->end - res->start + 1); 613 release_mem_region(res->start, res->end - res->start + 1);
616 614
617 return 0; 615 return 0;
618} 616}
619 617
620static struct device_driver au1200_ide_driver = { 618static struct platform_driver au1200_ide_driver = {
621 .name = "au1200-ide", 619 .driver = {
622 .bus = &platform_bus_type, 620 .name = "au1200-ide",
621 .owner = THIS_MODULE,
622 },
623 .probe = au_ide_probe, 623 .probe = au_ide_probe,
624 .remove = au_ide_remove, 624 .remove = au_ide_remove,
625}; 625};
626 626
627static int __init au_ide_init(void) 627static int __init au_ide_init(void)
628{ 628{
629 return driver_register(&au1200_ide_driver); 629 return platform_driver_register(&au1200_ide_driver);
630} 630}
631 631
632static void __exit au_ide_exit(void) 632static void __exit au_ide_exit(void)
633{ 633{
634 driver_unregister(&au1200_ide_driver); 634 platform_driver_unregister(&au1200_ide_driver);
635} 635}
636 636
637MODULE_LICENSE("GPL"); 637MODULE_LICENSE("GPL");
diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
index 2f9688d87ecd..aeee036b1503 100644
--- a/drivers/ide/cmd64x.c
+++ b/drivers/ide/cmd64x.c
@@ -333,7 +333,7 @@ static int cmd646_1_dma_end(ide_drive_t *drive)
333 return (dma_stat & 7) != 4; 333 return (dma_stat & 7) != 4;
334} 334}
335 335
336static unsigned int init_chipset_cmd64x(struct pci_dev *dev) 336static int init_chipset_cmd64x(struct pci_dev *dev)
337{ 337{
338 u8 mrdmode = 0; 338 u8 mrdmode = 0;
339 339
diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
index d003bec56ff9..58fb90e5b763 100644
--- a/drivers/ide/cs5520.c
+++ b/drivers/ide/cs5520.c
@@ -133,7 +133,8 @@ static int __devinit cs5520_init_one(struct pci_dev *dev, const struct pci_devic
133 * do all the device setup for us 133 * do all the device setup for us
134 */ 134 */
135 135
136 ide_pci_setup_ports(dev, d, 14, &hw[0], &hws[0]); 136 ide_pci_setup_ports(dev, d, &hw[0], &hws[0]);
137 hw[0].irq = 14;
137 138
138 return ide_host_add(d, hws, NULL); 139 return ide_host_add(d, hws, NULL);
139} 140}
diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
index d8ede85fe17f..8e8b35a89901 100644
--- a/drivers/ide/cs5530.c
+++ b/drivers/ide/cs5530.c
@@ -135,7 +135,7 @@ static void cs5530_set_dma_mode(ide_drive_t *drive, const u8 mode)
135 * Initialize the cs5530 bridge for reliable IDE DMA operation. 135 * Initialize the cs5530 bridge for reliable IDE DMA operation.
136 */ 136 */
137 137
138static unsigned int init_chipset_cs5530(struct pci_dev *dev) 138static int init_chipset_cs5530(struct pci_dev *dev)
139{ 139{
140 struct pci_dev *master_0 = NULL, *cs5530_0 = NULL; 140 struct pci_dev *master_0 = NULL, *cs5530_0 = NULL;
141 141
diff --git a/drivers/ide/delkin_cb.c b/drivers/ide/delkin_cb.c
index 8f1b2d9f0513..bacb1194c9c9 100644
--- a/drivers/ide/delkin_cb.c
+++ b/drivers/ide/delkin_cb.c
@@ -46,7 +46,7 @@ static const struct ide_port_ops delkin_cb_port_ops = {
46 .quirkproc = ide_undecoded_slave, 46 .quirkproc = ide_undecoded_slave,
47}; 47};
48 48
49static unsigned int delkin_cb_init_chipset(struct pci_dev *dev) 49static int delkin_cb_init_chipset(struct pci_dev *dev)
50{ 50{
51 unsigned long base = pci_resource_start(dev, 0); 51 unsigned long base = pci_resource_start(dev, 0);
52 int i; 52 int i;
diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
index 3eb9b5c63a0f..d3b3e824f445 100644
--- a/drivers/ide/hpt366.c
+++ b/drivers/ide/hpt366.c
@@ -995,7 +995,7 @@ static void hpt3xx_disable_fast_irq(struct pci_dev *dev, u8 mcr_addr)
995 pci_write_config_byte(dev, mcr_addr + 1, new_mcr); 995 pci_write_config_byte(dev, mcr_addr + 1, new_mcr);
996} 996}
997 997
998static unsigned int init_chipset_hpt366(struct pci_dev *dev) 998static int init_chipset_hpt366(struct pci_dev *dev)
999{ 999{
1000 unsigned long io_base = pci_resource_start(dev, 4); 1000 unsigned long io_base = pci_resource_start(dev, 4);
1001 struct hpt_info *info = hpt3xx_get_info(&dev->dev); 1001 struct hpt_info *info = hpt3xx_get_info(&dev->dev);
@@ -1237,7 +1237,7 @@ static unsigned int init_chipset_hpt366(struct pci_dev *dev)
1237 hpt3xx_disable_fast_irq(dev, 0x50); 1237 hpt3xx_disable_fast_irq(dev, 0x50);
1238 hpt3xx_disable_fast_irq(dev, 0x54); 1238 hpt3xx_disable_fast_irq(dev, 0x54);
1239 1239
1240 return dev->irq; 1240 return 0;
1241} 1241}
1242 1242
1243static u8 hpt3xx_cable_detect(ide_hwif_t *hwif) 1243static u8 hpt3xx_cable_detect(ide_hwif_t *hwif)
diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index ec7d07fa570a..5b704f1ea90c 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -20,9 +20,6 @@
20#include <acpi/acpi_bus.h> 20#include <acpi/acpi_bus.h>
21 21
22#define REGS_PER_GTF 7 22#define REGS_PER_GTF 7
23struct taskfile_array {
24 u8 tfa[REGS_PER_GTF]; /* regs. 0x1f1 - 0x1f7 */
25};
26 23
27struct GTM_buffer { 24struct GTM_buffer {
28 u32 PIO_speed0; 25 u32 PIO_speed0;
@@ -89,12 +86,8 @@ static const struct dmi_system_id ide_acpi_dmi_table[] = {
89 { } /* terminate list */ 86 { } /* terminate list */
90}; 87};
91 88
92static int ide_acpi_blacklist(void) 89int ide_acpi_init(void)
93{ 90{
94 static int done;
95 if (done)
96 return 0;
97 done = 1;
98 dmi_check_system(ide_acpi_dmi_table); 91 dmi_check_system(ide_acpi_dmi_table);
99 return 0; 92 return 0;
100} 93}
@@ -202,40 +195,6 @@ static acpi_handle ide_acpi_hwif_get_handle(ide_hwif_t *hwif)
202} 195}
203 196
204/** 197/**
205 * ide_acpi_drive_get_handle - Get ACPI object handle for a given drive
206 * @drive: device to locate
207 *
208 * Retrieves the object handle of a given drive. According to the ACPI
209 * spec the drive is a child of the hwif.
210 *
211 * Returns handle on success, 0 on error.
212 */
213static acpi_handle ide_acpi_drive_get_handle(ide_drive_t *drive)
214{
215 ide_hwif_t *hwif = drive->hwif;
216 int port;
217 acpi_handle drive_handle;
218
219 if (!hwif->acpidata)
220 return NULL;
221
222 if (!hwif->acpidata->obj_handle)
223 return NULL;
224
225 port = hwif->channel ? drive->dn - 2: drive->dn;
226
227 DEBPRINT("ENTER: %s at channel#: %d port#: %d\n",
228 drive->name, hwif->channel, port);
229
230
231 /* TBD: could also check ACPI object VALID bits */
232 drive_handle = acpi_get_child(hwif->acpidata->obj_handle, port);
233 DEBPRINT("drive %s handle 0x%p\n", drive->name, drive_handle);
234
235 return drive_handle;
236}
237
238/**
239 * do_drive_get_GTF - get the drive bootup default taskfile settings 198 * do_drive_get_GTF - get the drive bootup default taskfile settings
240 * @drive: the drive for which the taskfile settings should be retrieved 199 * @drive: the drive for which the taskfile settings should be retrieved
241 * @gtf_length: number of bytes of _GTF data returned at @gtf_address 200 * @gtf_length: number of bytes of _GTF data returned at @gtf_address
@@ -257,47 +216,15 @@ static int do_drive_get_GTF(ide_drive_t *drive,
257 acpi_status status; 216 acpi_status status;
258 struct acpi_buffer output; 217 struct acpi_buffer output;
259 union acpi_object *out_obj; 218 union acpi_object *out_obj;
260 ide_hwif_t *hwif = drive->hwif;
261 struct device *dev = hwif->gendev.parent;
262 int err = -ENODEV; 219 int err = -ENODEV;
263 int port;
264 220
265 *gtf_length = 0; 221 *gtf_length = 0;
266 *gtf_address = 0UL; 222 *gtf_address = 0UL;
267 *obj_loc = 0UL; 223 *obj_loc = 0UL;
268 224
269 if (ide_noacpi)
270 return 0;
271
272 if (!dev) {
273 DEBPRINT("no PCI device for %s\n", hwif->name);
274 goto out;
275 }
276
277 if (!hwif->acpidata) {
278 DEBPRINT("no ACPI data for %s\n", hwif->name);
279 goto out;
280 }
281
282 port = hwif->channel ? drive->dn - 2: drive->dn;
283
284 DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n",
285 hwif->name, dev_name(dev), port, hwif->channel);
286
287 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) {
288 DEBPRINT("%s drive %d:%d not present\n",
289 hwif->name, hwif->channel, port);
290 goto out;
291 }
292
293 /* Get this drive's _ADR info. if not already known. */
294 if (!drive->acpidata->obj_handle) { 225 if (!drive->acpidata->obj_handle) {
295 drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive); 226 DEBPRINT("No ACPI object found for %s\n", drive->name);
296 if (!drive->acpidata->obj_handle) { 227 goto out;
297 DEBPRINT("No ACPI object found for %s\n",
298 drive->name);
299 goto out;
300 }
301 } 228 }
302 229
303 /* Setting up output buffer */ 230 /* Setting up output buffer */
@@ -355,43 +282,6 @@ out:
355} 282}
356 283
357/** 284/**
358 * taskfile_load_raw - send taskfile registers to drive
359 * @drive: drive to which output is sent
360 * @gtf: raw ATA taskfile register set (0x1f1 - 0x1f7)
361 *
362 * Outputs IDE taskfile to the drive.
363 */
364static int taskfile_load_raw(ide_drive_t *drive,
365 const struct taskfile_array *gtf)
366{
367 ide_task_t args;
368 int err = 0;
369
370 DEBPRINT("(0x1f1-1f7): hex: "
371 "%02x %02x %02x %02x %02x %02x %02x\n",
372 gtf->tfa[0], gtf->tfa[1], gtf->tfa[2],
373 gtf->tfa[3], gtf->tfa[4], gtf->tfa[5], gtf->tfa[6]);
374
375 memset(&args, 0, sizeof(ide_task_t));
376
377 /* convert gtf to IDE Taskfile */
378 memcpy(&args.tf_array[7], &gtf->tfa, 7);
379 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
380
381 if (!ide_acpigtf) {
382 DEBPRINT("_GTF execution disabled\n");
383 return err;
384 }
385
386 err = ide_no_data_taskfile(drive, &args);
387 if (err)
388 printk(KERN_ERR "%s: ide_no_data_taskfile failed: %u\n",
389 __func__, err);
390
391 return err;
392}
393
394/**
395 * do_drive_set_taskfiles - write the drive taskfile settings from _GTF 285 * do_drive_set_taskfiles - write the drive taskfile settings from _GTF
396 * @drive: the drive to which the taskfile command should be sent 286 * @drive: the drive to which the taskfile command should be sent
397 * @gtf_length: total number of bytes of _GTF taskfiles 287 * @gtf_length: total number of bytes of _GTF taskfiles
@@ -404,43 +294,41 @@ static int do_drive_set_taskfiles(ide_drive_t *drive,
404 unsigned int gtf_length, 294 unsigned int gtf_length,
405 unsigned long gtf_address) 295 unsigned long gtf_address)
406{ 296{
407 int rc = -ENODEV, err; 297 int rc = 0, err;
408 int gtf_count = gtf_length / REGS_PER_GTF; 298 int gtf_count = gtf_length / REGS_PER_GTF;
409 int ix; 299 int ix;
410 struct taskfile_array *gtf;
411
412 if (ide_noacpi)
413 return 0;
414
415 DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn);
416
417 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
418 goto out;
419
420 if (!gtf_count) /* shouldn't be here */
421 goto out;
422 300
423 DEBPRINT("total GTF bytes=%u (0x%x), gtf_count=%d, addr=0x%lx\n", 301 DEBPRINT("total GTF bytes=%u (0x%x), gtf_count=%d, addr=0x%lx\n",
424 gtf_length, gtf_length, gtf_count, gtf_address); 302 gtf_length, gtf_length, gtf_count, gtf_address);
425 303
426 if (gtf_length % REGS_PER_GTF) { 304 /* send all taskfile registers (0x1f1-0x1f7) *in*that*order* */
427 printk(KERN_ERR "%s: unexpected GTF length (%d)\n",
428 __func__, gtf_length);
429 goto out;
430 }
431
432 rc = 0;
433 for (ix = 0; ix < gtf_count; ix++) { 305 for (ix = 0; ix < gtf_count; ix++) {
434 gtf = (struct taskfile_array *) 306 u8 *gtf = (u8 *)(gtf_address + ix * REGS_PER_GTF);
435 (gtf_address + ix * REGS_PER_GTF); 307 ide_task_t task;
436 308
437 /* send all TaskFile registers (0x1f1-0x1f7) *in*that*order* */ 309 DEBPRINT("(0x1f1-1f7): "
438 err = taskfile_load_raw(drive, gtf); 310 "hex: %02x %02x %02x %02x %02x %02x %02x\n",
439 if (err) 311 gtf[0], gtf[1], gtf[2],
312 gtf[3], gtf[4], gtf[5], gtf[6]);
313
314 if (!ide_acpigtf) {
315 DEBPRINT("_GTF execution disabled\n");
316 continue;
317 }
318
319 /* convert GTF to taskfile */
320 memset(&task, 0, sizeof(ide_task_t));
321 memcpy(&task.tf_array[7], gtf, REGS_PER_GTF);
322 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
323
324 err = ide_no_data_taskfile(drive, &task);
325 if (err) {
326 printk(KERN_ERR "%s: ide_no_data_taskfile failed: %u\n",
327 __func__, err);
440 rc = err; 328 rc = err;
329 }
441 } 330 }
442 331
443out:
444 return rc; 332 return rc;
445} 333}
446 334
@@ -647,26 +535,23 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on)
647 DEBPRINT("no ACPI data for %s\n", hwif->name); 535 DEBPRINT("no ACPI data for %s\n", hwif->name);
648 return; 536 return;
649 } 537 }
538
650 /* channel first and then drives for power on and verse versa for power off */ 539 /* channel first and then drives for power on and verse versa for power off */
651 if (on) 540 if (on)
652 acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0); 541 acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D0);
653 542
654 ide_port_for_each_dev(i, drive, hwif) { 543 ide_port_for_each_present_dev(i, drive, hwif) {
655 if (!drive->acpidata->obj_handle) 544 if (drive->acpidata->obj_handle)
656 drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
657
658 if (drive->acpidata->obj_handle &&
659 (drive->dev_flags & IDE_DFLAG_PRESENT)) {
660 acpi_bus_set_power(drive->acpidata->obj_handle, 545 acpi_bus_set_power(drive->acpidata->obj_handle,
661 on? ACPI_STATE_D0: ACPI_STATE_D3); 546 on ? ACPI_STATE_D0 : ACPI_STATE_D3);
662 }
663 } 547 }
548
664 if (!on) 549 if (!on)
665 acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D3); 550 acpi_bus_set_power(hwif->acpidata->obj_handle, ACPI_STATE_D3);
666} 551}
667 552
668/** 553/**
669 * ide_acpi_init - initialize the ACPI link for an IDE interface 554 * ide_acpi_init_port - initialize the ACPI link for an IDE interface
670 * @hwif: target IDE interface (channel) 555 * @hwif: target IDE interface (channel)
671 * 556 *
672 * The ACPI spec is not quite clear when the drive identify buffer 557 * The ACPI spec is not quite clear when the drive identify buffer
@@ -676,10 +561,8 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on)
676 * So we get the information during startup; but this means that 561 * So we get the information during startup; but this means that
677 * any changes during run-time will be lost after resume. 562 * any changes during run-time will be lost after resume.
678 */ 563 */
679void ide_acpi_init(ide_hwif_t *hwif) 564void ide_acpi_init_port(ide_hwif_t *hwif)
680{ 565{
681 ide_acpi_blacklist();
682
683 hwif->acpidata = kzalloc(sizeof(struct ide_acpi_hwif_link), GFP_KERNEL); 566 hwif->acpidata = kzalloc(sizeof(struct ide_acpi_hwif_link), GFP_KERNEL);
684 if (!hwif->acpidata) 567 if (!hwif->acpidata)
685 return; 568 return;
@@ -708,15 +591,24 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
708 hwif->devices[0]->acpidata = &hwif->acpidata->master; 591 hwif->devices[0]->acpidata = &hwif->acpidata->master;
709 hwif->devices[1]->acpidata = &hwif->acpidata->slave; 592 hwif->devices[1]->acpidata = &hwif->acpidata->slave;
710 593
711 /* 594 /* get _ADR info for each device */
712 * Send IDENTIFY for each drive 595 ide_port_for_each_present_dev(i, drive, hwif) {
713 */ 596 acpi_handle dev_handle;
714 ide_port_for_each_dev(i, drive, hwif) {
715 memset(drive->acpidata, 0, sizeof(*drive->acpidata));
716 597
717 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) 598 DEBPRINT("ENTER: %s at channel#: %d port#: %d\n",
718 continue; 599 drive->name, hwif->channel, drive->dn & 1);
600
601 /* TBD: could also check ACPI object VALID bits */
602 dev_handle = acpi_get_child(hwif->acpidata->obj_handle,
603 drive->dn & 1);
604
605 DEBPRINT("drive %s handle 0x%p\n", drive->name, dev_handle);
606
607 drive->acpidata->obj_handle = dev_handle;
608 }
719 609
610 /* send IDENTIFY for each device */
611 ide_port_for_each_present_dev(i, drive, hwif) {
720 err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff); 612 err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff);
721 if (err) 613 if (err)
722 DEBPRINT("identify device %s failed (%d)\n", 614 DEBPRINT("identify device %s failed (%d)\n",
@@ -736,9 +628,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
736 ide_acpi_get_timing(hwif); 628 ide_acpi_get_timing(hwif);
737 ide_acpi_push_timing(hwif); 629 ide_acpi_push_timing(hwif);
738 630
739 ide_port_for_each_dev(i, drive, hwif) { 631 ide_port_for_each_present_dev(i, drive, hwif) {
740 if (drive->dev_flags & IDE_DFLAG_PRESENT) 632 ide_acpi_exec_tfs(drive);
741 /* Execute ACPI startup code */
742 ide_acpi_exec_tfs(drive);
743 } 633 }
744} 634}
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index e9d042dba0e0..6adc5b4a4406 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -149,7 +149,10 @@ static void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
149 memcpy(rq->cmd, pc->c, 12); 149 memcpy(rq->cmd, pc->c, 12);
150 if (drive->media == ide_tape) 150 if (drive->media == ide_tape)
151 rq->cmd[13] = REQ_IDETAPE_PC1; 151 rq->cmd[13] = REQ_IDETAPE_PC1;
152 ide_do_drive_cmd(drive, rq); 152
153 drive->hwif->rq = NULL;
154
155 elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0);
153} 156}
154 157
155/* 158/*
@@ -297,6 +300,21 @@ int ide_cd_get_xferlen(struct request *rq)
297} 300}
298EXPORT_SYMBOL_GPL(ide_cd_get_xferlen); 301EXPORT_SYMBOL_GPL(ide_cd_get_xferlen);
299 302
303void ide_read_bcount_and_ireason(ide_drive_t *drive, u16 *bcount, u8 *ireason)
304{
305 ide_task_t task;
306
307 memset(&task, 0, sizeof(task));
308 task.tf_flags = IDE_TFLAG_IN_LBAH | IDE_TFLAG_IN_LBAM |
309 IDE_TFLAG_IN_NSECT;
310
311 drive->hwif->tp_ops->tf_read(drive, &task);
312
313 *bcount = (task.tf.lbah << 8) | task.tf.lbam;
314 *ireason = task.tf.nsect & 3;
315}
316EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason);
317
300/* 318/*
301 * This is the usual interrupt handler which will be called during a packet 319 * This is the usual interrupt handler which will be called during a packet
302 * command. We will transfer some of the data (as requested by the drive) 320 * command. We will transfer some of the data (as requested by the drive)
@@ -456,6 +474,25 @@ next_irq:
456 return ide_started; 474 return ide_started;
457} 475}
458 476
477static void ide_pktcmd_tf_load(ide_drive_t *drive, u32 tf_flags, u16 bcount)
478{
479 ide_hwif_t *hwif = drive->hwif;
480 ide_task_t task;
481 u8 dma = drive->dma;
482
483 memset(&task, 0, sizeof(task));
484 task.tf_flags = IDE_TFLAG_OUT_LBAH | IDE_TFLAG_OUT_LBAM |
485 IDE_TFLAG_OUT_FEATURE | tf_flags;
486 task.tf.feature = dma; /* Use PIO/DMA */
487 task.tf.lbam = bcount & 0xff;
488 task.tf.lbah = (bcount >> 8) & 0xff;
489
490 ide_tf_dump(drive->name, &task.tf);
491 hwif->tp_ops->set_irq(hwif, 1);
492 SELECT_MASK(drive, 0);
493 hwif->tp_ops->tf_load(drive, &task);
494}
495
459static u8 ide_read_ireason(ide_drive_t *drive) 496static u8 ide_read_ireason(ide_drive_t *drive)
460{ 497{
461 ide_task_t task; 498 ide_task_t task;
@@ -629,7 +666,7 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive)
629 : WAIT_TAPE_CMD; 666 : WAIT_TAPE_CMD;
630 } 667 }
631 668
632 ide_pktcmd_tf_load(drive, tf_flags, bcount, drive->dma); 669 ide_pktcmd_tf_load(drive, tf_flags, bcount);
633 670
634 /* Issue the packet command */ 671 /* Issue the packet command */
635 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { 672 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index ddfbea41d296..2177cd11664c 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -242,7 +242,9 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
242 ide_debug_log(IDE_DBG_SENSE, "failed_cmd: 0x%x\n", 242 ide_debug_log(IDE_DBG_SENSE, "failed_cmd: 0x%x\n",
243 failed_command->cmd[0]); 243 failed_command->cmd[0]);
244 244
245 ide_do_drive_cmd(drive, rq); 245 drive->hwif->rq = NULL;
246
247 elv_add_request(drive->queue, rq, ELEVATOR_INSERT_FRONT, 0);
246} 248}
247 249
248static void cdrom_end_request(ide_drive_t *drive, int uptodate) 250static void cdrom_end_request(ide_drive_t *drive, int uptodate)
diff --git a/drivers/ide/ide-devsets.c b/drivers/ide/ide-devsets.c
new file mode 100644
index 000000000000..7c3953414d47
--- /dev/null
+++ b/drivers/ide/ide-devsets.c
@@ -0,0 +1,190 @@
1
2#include <linux/kernel.h>
3#include <linux/ide.h>
4
5DEFINE_MUTEX(ide_setting_mtx);
6
7ide_devset_get(io_32bit, io_32bit);
8
9static int set_io_32bit(ide_drive_t *drive, int arg)
10{
11 if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT)
12 return -EPERM;
13
14 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
15 return -EINVAL;
16
17 drive->io_32bit = arg;
18
19 return 0;
20}
21
22ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS);
23
24static int set_ksettings(ide_drive_t *drive, int arg)
25{
26 if (arg < 0 || arg > 1)
27 return -EINVAL;
28
29 if (arg)
30 drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS;
31 else
32 drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS;
33
34 return 0;
35}
36
37ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA);
38
39static int set_using_dma(ide_drive_t *drive, int arg)
40{
41#ifdef CONFIG_BLK_DEV_IDEDMA
42 int err = -EPERM;
43
44 if (arg < 0 || arg > 1)
45 return -EINVAL;
46
47 if (ata_id_has_dma(drive->id) == 0)
48 goto out;
49
50 if (drive->hwif->dma_ops == NULL)
51 goto out;
52
53 err = 0;
54
55 if (arg) {
56 if (ide_set_dma(drive))
57 err = -EIO;
58 } else
59 ide_dma_off(drive);
60
61out:
62 return err;
63#else
64 if (arg < 0 || arg > 1)
65 return -EINVAL;
66
67 return -EPERM;
68#endif
69}
70
71/*
72 * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
73 */
74static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
75{
76 switch (req_pio) {
77 case 202:
78 case 201:
79 case 200:
80 case 102:
81 case 101:
82 case 100:
83 return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
84 case 9:
85 case 8:
86 return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
87 case 7:
88 case 6:
89 return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
90 default:
91 return 0;
92 }
93}
94
95static int set_pio_mode(ide_drive_t *drive, int arg)
96{
97 ide_hwif_t *hwif = drive->hwif;
98 const struct ide_port_ops *port_ops = hwif->port_ops;
99
100 if (arg < 0 || arg > 255)
101 return -EINVAL;
102
103 if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
104 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
105 return -ENOSYS;
106
107 if (set_pio_mode_abuse(drive->hwif, arg)) {
108 if (arg == 8 || arg == 9) {
109 unsigned long flags;
110
111 /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
112 spin_lock_irqsave(&hwif->lock, flags);
113 port_ops->set_pio_mode(drive, arg);
114 spin_unlock_irqrestore(&hwif->lock, flags);
115 } else
116 port_ops->set_pio_mode(drive, arg);
117 } else {
118 int keep_dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
119
120 ide_set_pio(drive, arg);
121
122 if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
123 if (keep_dma)
124 ide_dma_on(drive);
125 }
126 }
127
128 return 0;
129}
130
131ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK);
132
133static int set_unmaskirq(ide_drive_t *drive, int arg)
134{
135 if (drive->dev_flags & IDE_DFLAG_NO_UNMASK)
136 return -EPERM;
137
138 if (arg < 0 || arg > 1)
139 return -EINVAL;
140
141 if (arg)
142 drive->dev_flags |= IDE_DFLAG_UNMASK;
143 else
144 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
145
146 return 0;
147}
148
149ide_ext_devset_rw_sync(io_32bit, io_32bit);
150ide_ext_devset_rw_sync(keepsettings, ksettings);
151ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
152ide_ext_devset_rw_sync(using_dma, using_dma);
153__IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
154
155int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting,
156 int arg)
157{
158 struct request_queue *q = drive->queue;
159 struct request *rq;
160 int ret = 0;
161
162 if (!(setting->flags & DS_SYNC))
163 return setting->set(drive, arg);
164
165 rq = blk_get_request(q, READ, __GFP_WAIT);
166 rq->cmd_type = REQ_TYPE_SPECIAL;
167 rq->cmd_len = 5;
168 rq->cmd[0] = REQ_DEVSET_EXEC;
169 *(int *)&rq->cmd[1] = arg;
170 rq->special = setting->set;
171
172 if (blk_execute_rq(q, NULL, rq, 0))
173 ret = rq->errors;
174 blk_put_request(rq);
175
176 return ret;
177}
178
179ide_startstop_t ide_do_devset(ide_drive_t *drive, struct request *rq)
180{
181 int err, (*setfunc)(ide_drive_t *, int) = rq->special;
182
183 err = setfunc(drive, *(int *)&rq->cmd[1]);
184 if (err)
185 rq->errors = err;
186 else
187 err = 1;
188 ide_end_request(drive, err, 0);
189 return ide_stopped;
190}
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index 059c90bb5ad2..a878f4734f81 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -470,6 +470,63 @@ void ide_dma_timeout(ide_drive_t *drive)
470} 470}
471EXPORT_SYMBOL_GPL(ide_dma_timeout); 471EXPORT_SYMBOL_GPL(ide_dma_timeout);
472 472
473/*
474 * un-busy the port etc, and clear any pending DMA status. we want to
475 * retry the current request in pio mode instead of risking tossing it
476 * all away
477 */
478ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
479{
480 ide_hwif_t *hwif = drive->hwif;
481 struct request *rq;
482 ide_startstop_t ret = ide_stopped;
483
484 /*
485 * end current dma transaction
486 */
487
488 if (error < 0) {
489 printk(KERN_WARNING "%s: DMA timeout error\n", drive->name);
490 (void)hwif->dma_ops->dma_end(drive);
491 ret = ide_error(drive, "dma timeout error",
492 hwif->tp_ops->read_status(hwif));
493 } else {
494 printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name);
495 hwif->dma_ops->dma_timeout(drive);
496 }
497
498 /*
499 * disable dma for now, but remember that we did so because of
500 * a timeout -- we'll reenable after we finish this next request
501 * (or rather the first chunk of it) in pio.
502 */
503 drive->dev_flags |= IDE_DFLAG_DMA_PIO_RETRY;
504 drive->retry_pio++;
505 ide_dma_off_quietly(drive);
506
507 /*
508 * un-busy drive etc and make sure request is sane
509 */
510
511 rq = hwif->rq;
512 if (!rq)
513 goto out;
514
515 hwif->rq = NULL;
516
517 rq->errors = 0;
518
519 if (!rq->bio)
520 goto out;
521
522 rq->sector = rq->bio->bi_sector;
523 rq->current_nr_sectors = bio_iovec(rq->bio)->bv_len >> 9;
524 rq->hard_cur_sectors = rq->current_nr_sectors;
525 rq->buffer = bio_data(rq->bio);
526out:
527 return ret;
528}
529
473void ide_release_dma_engine(ide_hwif_t *hwif) 530void ide_release_dma_engine(ide_hwif_t *hwif)
474{ 531{
475 if (hwif->dmatable_cpu) { 532 if (hwif->dmatable_cpu) {
diff --git a/drivers/ide/ide-eh.c b/drivers/ide/ide-eh.c
new file mode 100644
index 000000000000..1231b5e486f2
--- /dev/null
+++ b/drivers/ide/ide-eh.c
@@ -0,0 +1,428 @@
1
2#include <linux/kernel.h>
3#include <linux/ide.h>
4#include <linux/delay.h>
5
6static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq,
7 u8 stat, u8 err)
8{
9 ide_hwif_t *hwif = drive->hwif;
10
11 if ((stat & ATA_BUSY) ||
12 ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
13 /* other bits are useless when BUSY */
14 rq->errors |= ERROR_RESET;
15 } else if (stat & ATA_ERR) {
16 /* err has different meaning on cdrom and tape */
17 if (err == ATA_ABORTED) {
18 if ((drive->dev_flags & IDE_DFLAG_LBA) &&
19 /* some newer drives don't support ATA_CMD_INIT_DEV_PARAMS */
20 hwif->tp_ops->read_status(hwif) == ATA_CMD_INIT_DEV_PARAMS)
21 return ide_stopped;
22 } else if ((err & BAD_CRC) == BAD_CRC) {
23 /* UDMA crc error, just retry the operation */
24 drive->crc_count++;
25 } else if (err & (ATA_BBK | ATA_UNC)) {
26 /* retries won't help these */
27 rq->errors = ERROR_MAX;
28 } else if (err & ATA_TRK0NF) {
29 /* help it find track zero */
30 rq->errors |= ERROR_RECAL;
31 }
32 }
33
34 if ((stat & ATA_DRQ) && rq_data_dir(rq) == READ &&
35 (hwif->host_flags & IDE_HFLAG_ERROR_STOPS_FIFO) == 0) {
36 int nsect = drive->mult_count ? drive->mult_count : 1;
37
38 ide_pad_transfer(drive, READ, nsect * SECTOR_SIZE);
39 }
40
41 if (rq->errors >= ERROR_MAX || blk_noretry_request(rq)) {
42 ide_kill_rq(drive, rq);
43 return ide_stopped;
44 }
45
46 if (hwif->tp_ops->read_status(hwif) & (ATA_BUSY | ATA_DRQ))
47 rq->errors |= ERROR_RESET;
48
49 if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
50 ++rq->errors;
51 return ide_do_reset(drive);
52 }
53
54 if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
55 drive->special.b.recalibrate = 1;
56
57 ++rq->errors;
58
59 return ide_stopped;
60}
61
62static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq,
63 u8 stat, u8 err)
64{
65 ide_hwif_t *hwif = drive->hwif;
66
67 if ((stat & ATA_BUSY) ||
68 ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
69 /* other bits are useless when BUSY */
70 rq->errors |= ERROR_RESET;
71 } else {
72 /* add decoding error stuff */
73 }
74
75 if (hwif->tp_ops->read_status(hwif) & (ATA_BUSY | ATA_DRQ))
76 /* force an abort */
77 hwif->tp_ops->exec_command(hwif, ATA_CMD_IDLEIMMEDIATE);
78
79 if (rq->errors >= ERROR_MAX) {
80 ide_kill_rq(drive, rq);
81 } else {
82 if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
83 ++rq->errors;
84 return ide_do_reset(drive);
85 }
86 ++rq->errors;
87 }
88
89 return ide_stopped;
90}
91
92static ide_startstop_t __ide_error(ide_drive_t *drive, struct request *rq,
93 u8 stat, u8 err)
94{
95 if (drive->media == ide_disk)
96 return ide_ata_error(drive, rq, stat, err);
97 return ide_atapi_error(drive, rq, stat, err);
98}
99
100/**
101 * ide_error - handle an error on the IDE
102 * @drive: drive the error occurred on
103 * @msg: message to report
104 * @stat: status bits
105 *
106 * ide_error() takes action based on the error returned by the drive.
107 * For normal I/O that may well include retries. We deal with
108 * both new-style (taskfile) and old style command handling here.
109 * In the case of taskfile command handling there is work left to
110 * do
111 */
112
113ide_startstop_t ide_error(ide_drive_t *drive, const char *msg, u8 stat)
114{
115 struct request *rq;
116 u8 err;
117
118 err = ide_dump_status(drive, msg, stat);
119
120 rq = drive->hwif->rq;
121 if (rq == NULL)
122 return ide_stopped;
123
124 /* retry only "normal" I/O: */
125 if (!blk_fs_request(rq)) {
126 rq->errors = 1;
127 ide_end_drive_cmd(drive, stat, err);
128 return ide_stopped;
129 }
130
131 return __ide_error(drive, rq, stat, err);
132}
133EXPORT_SYMBOL_GPL(ide_error);
134
135static inline void ide_complete_drive_reset(ide_drive_t *drive, int err)
136{
137 struct request *rq = drive->hwif->rq;
138
139 if (rq && blk_special_request(rq) && rq->cmd[0] == REQ_DRIVE_RESET)
140 ide_end_request(drive, err ? err : 1, 0);
141}
142
143/* needed below */
144static ide_startstop_t do_reset1(ide_drive_t *, int);
145
146/*
147 * atapi_reset_pollfunc() gets invoked to poll the interface for completion
148 * every 50ms during an atapi drive reset operation. If the drive has not yet
149 * responded, and we have not yet hit our maximum waiting time, then the timer
150 * is restarted for another 50ms.
151 */
152static ide_startstop_t atapi_reset_pollfunc(ide_drive_t *drive)
153{
154 ide_hwif_t *hwif = drive->hwif;
155 u8 stat;
156
157 SELECT_DRIVE(drive);
158 udelay(10);
159 stat = hwif->tp_ops->read_status(hwif);
160
161 if (OK_STAT(stat, 0, ATA_BUSY))
162 printk(KERN_INFO "%s: ATAPI reset complete\n", drive->name);
163 else {
164 if (time_before(jiffies, hwif->poll_timeout)) {
165 ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20,
166 NULL);
167 /* continue polling */
168 return ide_started;
169 }
170 /* end of polling */
171 hwif->polling = 0;
172 printk(KERN_ERR "%s: ATAPI reset timed-out, status=0x%02x\n",
173 drive->name, stat);
174 /* do it the old fashioned way */
175 return do_reset1(drive, 1);
176 }
177 /* done polling */
178 hwif->polling = 0;
179 ide_complete_drive_reset(drive, 0);
180 return ide_stopped;
181}
182
183static void ide_reset_report_error(ide_hwif_t *hwif, u8 err)
184{
185 static const char *err_master_vals[] =
186 { NULL, "passed", "formatter device error",
187 "sector buffer error", "ECC circuitry error",
188 "controlling MPU error" };
189
190 u8 err_master = err & 0x7f;
191
192 printk(KERN_ERR "%s: reset: master: ", hwif->name);
193 if (err_master && err_master < 6)
194 printk(KERN_CONT "%s", err_master_vals[err_master]);
195 else
196 printk(KERN_CONT "error (0x%02x?)", err);
197 if (err & 0x80)
198 printk(KERN_CONT "; slave: failed");
199 printk(KERN_CONT "\n");
200}
201
202/*
203 * reset_pollfunc() gets invoked to poll the interface for completion every 50ms
204 * during an ide reset operation. If the drives have not yet responded,
205 * and we have not yet hit our maximum waiting time, then the timer is restarted
206 * for another 50ms.
207 */
208static ide_startstop_t reset_pollfunc(ide_drive_t *drive)
209{
210 ide_hwif_t *hwif = drive->hwif;
211 const struct ide_port_ops *port_ops = hwif->port_ops;
212 u8 tmp;
213 int err = 0;
214
215 if (port_ops && port_ops->reset_poll) {
216 err = port_ops->reset_poll(drive);
217 if (err) {
218 printk(KERN_ERR "%s: host reset_poll failure for %s.\n",
219 hwif->name, drive->name);
220 goto out;
221 }
222 }
223
224 tmp = hwif->tp_ops->read_status(hwif);
225
226 if (!OK_STAT(tmp, 0, ATA_BUSY)) {
227 if (time_before(jiffies, hwif->poll_timeout)) {
228 ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL);
229 /* continue polling */
230 return ide_started;
231 }
232 printk(KERN_ERR "%s: reset timed-out, status=0x%02x\n",
233 hwif->name, tmp);
234 drive->failures++;
235 err = -EIO;
236 } else {
237 tmp = ide_read_error(drive);
238
239 if (tmp == 1) {
240 printk(KERN_INFO "%s: reset: success\n", hwif->name);
241 drive->failures = 0;
242 } else {
243 ide_reset_report_error(hwif, tmp);
244 drive->failures++;
245 err = -EIO;
246 }
247 }
248out:
249 hwif->polling = 0; /* done polling */
250 ide_complete_drive_reset(drive, err);
251 return ide_stopped;
252}
253
254static void ide_disk_pre_reset(ide_drive_t *drive)
255{
256 int legacy = (drive->id[ATA_ID_CFS_ENABLE_2] & 0x0400) ? 0 : 1;
257
258 drive->special.all = 0;
259 drive->special.b.set_geometry = legacy;
260 drive->special.b.recalibrate = legacy;
261
262 drive->mult_count = 0;
263 drive->dev_flags &= ~IDE_DFLAG_PARKED;
264
265 if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0 &&
266 (drive->dev_flags & IDE_DFLAG_USING_DMA) == 0)
267 drive->mult_req = 0;
268
269 if (drive->mult_req != drive->mult_count)
270 drive->special.b.set_multmode = 1;
271}
272
273static void pre_reset(ide_drive_t *drive)
274{
275 const struct ide_port_ops *port_ops = drive->hwif->port_ops;
276
277 if (drive->media == ide_disk)
278 ide_disk_pre_reset(drive);
279 else
280 drive->dev_flags |= IDE_DFLAG_POST_RESET;
281
282 if (drive->dev_flags & IDE_DFLAG_USING_DMA) {
283 if (drive->crc_count)
284 ide_check_dma_crc(drive);
285 else
286 ide_dma_off(drive);
287 }
288
289 if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0) {
290 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0) {
291 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
292 drive->io_32bit = 0;
293 }
294 return;
295 }
296
297 if (port_ops && port_ops->pre_reset)
298 port_ops->pre_reset(drive);
299
300 if (drive->current_speed != 0xff)
301 drive->desired_speed = drive->current_speed;
302 drive->current_speed = 0xff;
303}
304
305/*
306 * do_reset1() attempts to recover a confused drive by resetting it.
307 * Unfortunately, resetting a disk drive actually resets all devices on
308 * the same interface, so it can really be thought of as resetting the
309 * interface rather than resetting the drive.
310 *
311 * ATAPI devices have their own reset mechanism which allows them to be
312 * individually reset without clobbering other devices on the same interface.
313 *
314 * Unfortunately, the IDE interface does not generate an interrupt to let
315 * us know when the reset operation has finished, so we must poll for this.
316 * Equally poor, though, is the fact that this may a very long time to complete,
317 * (up to 30 seconds worstcase). So, instead of busy-waiting here for it,
318 * we set a timer to poll at 50ms intervals.
319 */
320static ide_startstop_t do_reset1(ide_drive_t *drive, int do_not_try_atapi)
321{
322 ide_hwif_t *hwif = drive->hwif;
323 struct ide_io_ports *io_ports = &hwif->io_ports;
324 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
325 const struct ide_port_ops *port_ops;
326 ide_drive_t *tdrive;
327 unsigned long flags, timeout;
328 int i;
329 DEFINE_WAIT(wait);
330
331 spin_lock_irqsave(&hwif->lock, flags);
332
333 /* We must not reset with running handlers */
334 BUG_ON(hwif->handler != NULL);
335
336 /* For an ATAPI device, first try an ATAPI SRST. */
337 if (drive->media != ide_disk && !do_not_try_atapi) {
338 pre_reset(drive);
339 SELECT_DRIVE(drive);
340 udelay(20);
341 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
342 ndelay(400);
343 hwif->poll_timeout = jiffies + WAIT_WORSTCASE;
344 hwif->polling = 1;
345 __ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL);
346 spin_unlock_irqrestore(&hwif->lock, flags);
347 return ide_started;
348 }
349
350 /* We must not disturb devices in the IDE_DFLAG_PARKED state. */
351 do {
352 unsigned long now;
353
354 prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE);
355 timeout = jiffies;
356 ide_port_for_each_present_dev(i, tdrive, hwif) {
357 if ((tdrive->dev_flags & IDE_DFLAG_PARKED) &&
358 time_after(tdrive->sleep, timeout))
359 timeout = tdrive->sleep;
360 }
361
362 now = jiffies;
363 if (time_before_eq(timeout, now))
364 break;
365
366 spin_unlock_irqrestore(&hwif->lock, flags);
367 timeout = schedule_timeout_uninterruptible(timeout - now);
368 spin_lock_irqsave(&hwif->lock, flags);
369 } while (timeout);
370 finish_wait(&ide_park_wq, &wait);
371
372 /*
373 * First, reset any device state data we were maintaining
374 * for any of the drives on this interface.
375 */
376 ide_port_for_each_dev(i, tdrive, hwif)
377 pre_reset(tdrive);
378
379 if (io_ports->ctl_addr == 0) {
380 spin_unlock_irqrestore(&hwif->lock, flags);
381 ide_complete_drive_reset(drive, -ENXIO);
382 return ide_stopped;
383 }
384
385 /*
386 * Note that we also set nIEN while resetting the device,
387 * to mask unwanted interrupts from the interface during the reset.
388 * However, due to the design of PC hardware, this will cause an
389 * immediate interrupt due to the edge transition it produces.
390 * This single interrupt gives us a "fast poll" for drives that
391 * recover from reset very quickly, saving us the first 50ms wait time.
392 *
393 * TODO: add ->softreset method and stop abusing ->set_irq
394 */
395 /* set SRST and nIEN */
396 tp_ops->set_irq(hwif, 4);
397 /* more than enough time */
398 udelay(10);
399 /* clear SRST, leave nIEN (unless device is on the quirk list) */
400 tp_ops->set_irq(hwif, drive->quirk_list == 2);
401 /* more than enough time */
402 udelay(10);
403 hwif->poll_timeout = jiffies + WAIT_WORSTCASE;
404 hwif->polling = 1;
405 __ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL);
406
407 /*
408 * Some weird controller like resetting themselves to a strange
409 * state when the disks are reset this way. At least, the Winbond
410 * 553 documentation says that
411 */
412 port_ops = hwif->port_ops;
413 if (port_ops && port_ops->resetproc)
414 port_ops->resetproc(drive);
415
416 spin_unlock_irqrestore(&hwif->lock, flags);
417 return ide_started;
418}
419
420/*
421 * ide_do_reset() is the entry point to the drive/interface reset code.
422 */
423
424ide_startstop_t ide_do_reset(ide_drive_t *drive)
425{
426 return do_reset1(drive, 0);
427}
428EXPORT_SYMBOL(ide_do_reset);
diff --git a/drivers/ide/ide-io-std.c b/drivers/ide/ide-io-std.c
new file mode 100644
index 000000000000..45b43dd49cda
--- /dev/null
+++ b/drivers/ide/ide-io-std.c
@@ -0,0 +1,316 @@
1
2#include <linux/kernel.h>
3#include <linux/ide.h>
4
5/*
6 * Conventional PIO operations for ATA devices
7 */
8
9static u8 ide_inb(unsigned long port)
10{
11 return (u8) inb(port);
12}
13
14static void ide_outb(u8 val, unsigned long port)
15{
16 outb(val, port);
17}
18
19/*
20 * MMIO operations, typically used for SATA controllers
21 */
22
23static u8 ide_mm_inb(unsigned long port)
24{
25 return (u8) readb((void __iomem *) port);
26}
27
28static void ide_mm_outb(u8 value, unsigned long port)
29{
30 writeb(value, (void __iomem *) port);
31}
32
33void ide_exec_command(ide_hwif_t *hwif, u8 cmd)
34{
35 if (hwif->host_flags & IDE_HFLAG_MMIO)
36 writeb(cmd, (void __iomem *)hwif->io_ports.command_addr);
37 else
38 outb(cmd, hwif->io_ports.command_addr);
39}
40EXPORT_SYMBOL_GPL(ide_exec_command);
41
42u8 ide_read_status(ide_hwif_t *hwif)
43{
44 if (hwif->host_flags & IDE_HFLAG_MMIO)
45 return readb((void __iomem *)hwif->io_ports.status_addr);
46 else
47 return inb(hwif->io_ports.status_addr);
48}
49EXPORT_SYMBOL_GPL(ide_read_status);
50
51u8 ide_read_altstatus(ide_hwif_t *hwif)
52{
53 if (hwif->host_flags & IDE_HFLAG_MMIO)
54 return readb((void __iomem *)hwif->io_ports.ctl_addr);
55 else
56 return inb(hwif->io_ports.ctl_addr);
57}
58EXPORT_SYMBOL_GPL(ide_read_altstatus);
59
60void ide_set_irq(ide_hwif_t *hwif, int on)
61{
62 u8 ctl = ATA_DEVCTL_OBS;
63
64 if (on == 4) { /* hack for SRST */
65 ctl |= 4;
66 on &= ~4;
67 }
68
69 ctl |= on ? 0 : 2;
70
71 if (hwif->host_flags & IDE_HFLAG_MMIO)
72 writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr);
73 else
74 outb(ctl, hwif->io_ports.ctl_addr);
75}
76EXPORT_SYMBOL_GPL(ide_set_irq);
77
78void ide_tf_load(ide_drive_t *drive, ide_task_t *task)
79{
80 ide_hwif_t *hwif = drive->hwif;
81 struct ide_io_ports *io_ports = &hwif->io_ports;
82 struct ide_taskfile *tf = &task->tf;
83 void (*tf_outb)(u8 addr, unsigned long port);
84 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
85 u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
86
87 if (mmio)
88 tf_outb = ide_mm_outb;
89 else
90 tf_outb = ide_outb;
91
92 if (task->tf_flags & IDE_TFLAG_FLAGGED)
93 HIHI = 0xFF;
94
95 if (task->tf_flags & IDE_TFLAG_OUT_DATA) {
96 u16 data = (tf->hob_data << 8) | tf->data;
97
98 if (mmio)
99 writew(data, (void __iomem *)io_ports->data_addr);
100 else
101 outw(data, io_ports->data_addr);
102 }
103
104 if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
105 tf_outb(tf->hob_feature, io_ports->feature_addr);
106 if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
107 tf_outb(tf->hob_nsect, io_ports->nsect_addr);
108 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
109 tf_outb(tf->hob_lbal, io_ports->lbal_addr);
110 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
111 tf_outb(tf->hob_lbam, io_ports->lbam_addr);
112 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
113 tf_outb(tf->hob_lbah, io_ports->lbah_addr);
114
115 if (task->tf_flags & IDE_TFLAG_OUT_FEATURE)
116 tf_outb(tf->feature, io_ports->feature_addr);
117 if (task->tf_flags & IDE_TFLAG_OUT_NSECT)
118 tf_outb(tf->nsect, io_ports->nsect_addr);
119 if (task->tf_flags & IDE_TFLAG_OUT_LBAL)
120 tf_outb(tf->lbal, io_ports->lbal_addr);
121 if (task->tf_flags & IDE_TFLAG_OUT_LBAM)
122 tf_outb(tf->lbam, io_ports->lbam_addr);
123 if (task->tf_flags & IDE_TFLAG_OUT_LBAH)
124 tf_outb(tf->lbah, io_ports->lbah_addr);
125
126 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
127 tf_outb((tf->device & HIHI) | drive->select,
128 io_ports->device_addr);
129}
130EXPORT_SYMBOL_GPL(ide_tf_load);
131
132void ide_tf_read(ide_drive_t *drive, ide_task_t *task)
133{
134 ide_hwif_t *hwif = drive->hwif;
135 struct ide_io_ports *io_ports = &hwif->io_ports;
136 struct ide_taskfile *tf = &task->tf;
137 void (*tf_outb)(u8 addr, unsigned long port);
138 u8 (*tf_inb)(unsigned long port);
139 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
140
141 if (mmio) {
142 tf_outb = ide_mm_outb;
143 tf_inb = ide_mm_inb;
144 } else {
145 tf_outb = ide_outb;
146 tf_inb = ide_inb;
147 }
148
149 if (task->tf_flags & IDE_TFLAG_IN_DATA) {
150 u16 data;
151
152 if (mmio)
153 data = readw((void __iomem *)io_ports->data_addr);
154 else
155 data = inw(io_ports->data_addr);
156
157 tf->data = data & 0xff;
158 tf->hob_data = (data >> 8) & 0xff;
159 }
160
161 /* be sure we're looking at the low order bits */
162 tf_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
163
164 if (task->tf_flags & IDE_TFLAG_IN_FEATURE)
165 tf->feature = tf_inb(io_ports->feature_addr);
166 if (task->tf_flags & IDE_TFLAG_IN_NSECT)
167 tf->nsect = tf_inb(io_ports->nsect_addr);
168 if (task->tf_flags & IDE_TFLAG_IN_LBAL)
169 tf->lbal = tf_inb(io_ports->lbal_addr);
170 if (task->tf_flags & IDE_TFLAG_IN_LBAM)
171 tf->lbam = tf_inb(io_ports->lbam_addr);
172 if (task->tf_flags & IDE_TFLAG_IN_LBAH)
173 tf->lbah = tf_inb(io_ports->lbah_addr);
174 if (task->tf_flags & IDE_TFLAG_IN_DEVICE)
175 tf->device = tf_inb(io_ports->device_addr);
176
177 if (task->tf_flags & IDE_TFLAG_LBA48) {
178 tf_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
179
180 if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
181 tf->hob_feature = tf_inb(io_ports->feature_addr);
182 if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
183 tf->hob_nsect = tf_inb(io_ports->nsect_addr);
184 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
185 tf->hob_lbal = tf_inb(io_ports->lbal_addr);
186 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
187 tf->hob_lbam = tf_inb(io_ports->lbam_addr);
188 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
189 tf->hob_lbah = tf_inb(io_ports->lbah_addr);
190 }
191}
192EXPORT_SYMBOL_GPL(ide_tf_read);
193
194/*
195 * Some localbus EIDE interfaces require a special access sequence
196 * when using 32-bit I/O instructions to transfer data. We call this
197 * the "vlb_sync" sequence, which consists of three successive reads
198 * of the sector count register location, with interrupts disabled
199 * to ensure that the reads all happen together.
200 */
201static void ata_vlb_sync(unsigned long port)
202{
203 (void)inb(port);
204 (void)inb(port);
205 (void)inb(port);
206}
207
208/*
209 * This is used for most PIO data transfers *from* the IDE interface
210 *
211 * These routines will round up any request for an odd number of bytes,
212 * so if an odd len is specified, be sure that there's at least one
213 * extra byte allocated for the buffer.
214 */
215void ide_input_data(ide_drive_t *drive, struct request *rq, void *buf,
216 unsigned int len)
217{
218 ide_hwif_t *hwif = drive->hwif;
219 struct ide_io_ports *io_ports = &hwif->io_ports;
220 unsigned long data_addr = io_ports->data_addr;
221 u8 io_32bit = drive->io_32bit;
222 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
223
224 len++;
225
226 if (io_32bit) {
227 unsigned long uninitialized_var(flags);
228
229 if ((io_32bit & 2) && !mmio) {
230 local_irq_save(flags);
231 ata_vlb_sync(io_ports->nsect_addr);
232 }
233
234 if (mmio)
235 __ide_mm_insl((void __iomem *)data_addr, buf, len / 4);
236 else
237 insl(data_addr, buf, len / 4);
238
239 if ((io_32bit & 2) && !mmio)
240 local_irq_restore(flags);
241
242 if ((len & 3) >= 2) {
243 if (mmio)
244 __ide_mm_insw((void __iomem *)data_addr,
245 (u8 *)buf + (len & ~3), 1);
246 else
247 insw(data_addr, (u8 *)buf + (len & ~3), 1);
248 }
249 } else {
250 if (mmio)
251 __ide_mm_insw((void __iomem *)data_addr, buf, len / 2);
252 else
253 insw(data_addr, buf, len / 2);
254 }
255}
256EXPORT_SYMBOL_GPL(ide_input_data);
257
258/*
259 * This is used for most PIO data transfers *to* the IDE interface
260 */
261void ide_output_data(ide_drive_t *drive, struct request *rq, void *buf,
262 unsigned int len)
263{
264 ide_hwif_t *hwif = drive->hwif;
265 struct ide_io_ports *io_ports = &hwif->io_ports;
266 unsigned long data_addr = io_ports->data_addr;
267 u8 io_32bit = drive->io_32bit;
268 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
269
270 len++;
271
272 if (io_32bit) {
273 unsigned long uninitialized_var(flags);
274
275 if ((io_32bit & 2) && !mmio) {
276 local_irq_save(flags);
277 ata_vlb_sync(io_ports->nsect_addr);
278 }
279
280 if (mmio)
281 __ide_mm_outsl((void __iomem *)data_addr, buf, len / 4);
282 else
283 outsl(data_addr, buf, len / 4);
284
285 if ((io_32bit & 2) && !mmio)
286 local_irq_restore(flags);
287
288 if ((len & 3) >= 2) {
289 if (mmio)
290 __ide_mm_outsw((void __iomem *)data_addr,
291 (u8 *)buf + (len & ~3), 1);
292 else
293 outsw(data_addr, (u8 *)buf + (len & ~3), 1);
294 }
295 } else {
296 if (mmio)
297 __ide_mm_outsw((void __iomem *)data_addr, buf, len / 2);
298 else
299 outsw(data_addr, buf, len / 2);
300 }
301}
302EXPORT_SYMBOL_GPL(ide_output_data);
303
304const struct ide_tp_ops default_tp_ops = {
305 .exec_command = ide_exec_command,
306 .read_status = ide_read_status,
307 .read_altstatus = ide_read_altstatus,
308
309 .set_irq = ide_set_irq,
310
311 .tf_load = ide_tf_load,
312 .tf_read = ide_tf_read,
313
314 .input_data = ide_input_data,
315 .output_data = ide_output_data,
316};
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index a9a6c208288a..2e92497b58aa 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -196,7 +196,7 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
196} 196}
197EXPORT_SYMBOL(ide_end_drive_cmd); 197EXPORT_SYMBOL(ide_end_drive_cmd);
198 198
199static void ide_kill_rq(ide_drive_t *drive, struct request *rq) 199void ide_kill_rq(ide_drive_t *drive, struct request *rq)
200{ 200{
201 if (rq->rq_disk) { 201 if (rq->rq_disk) {
202 struct ide_driver *drv; 202 struct ide_driver *drv;
@@ -207,133 +207,6 @@ static void ide_kill_rq(ide_drive_t *drive, struct request *rq)
207 ide_end_request(drive, 0, 0); 207 ide_end_request(drive, 0, 0);
208} 208}
209 209
210static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
211{
212 ide_hwif_t *hwif = drive->hwif;
213
214 if ((stat & ATA_BUSY) ||
215 ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
216 /* other bits are useless when BUSY */
217 rq->errors |= ERROR_RESET;
218 } else if (stat & ATA_ERR) {
219 /* err has different meaning on cdrom and tape */
220 if (err == ATA_ABORTED) {
221 if ((drive->dev_flags & IDE_DFLAG_LBA) &&
222 /* some newer drives don't support ATA_CMD_INIT_DEV_PARAMS */
223 hwif->tp_ops->read_status(hwif) == ATA_CMD_INIT_DEV_PARAMS)
224 return ide_stopped;
225 } else if ((err & BAD_CRC) == BAD_CRC) {
226 /* UDMA crc error, just retry the operation */
227 drive->crc_count++;
228 } else if (err & (ATA_BBK | ATA_UNC)) {
229 /* retries won't help these */
230 rq->errors = ERROR_MAX;
231 } else if (err & ATA_TRK0NF) {
232 /* help it find track zero */
233 rq->errors |= ERROR_RECAL;
234 }
235 }
236
237 if ((stat & ATA_DRQ) && rq_data_dir(rq) == READ &&
238 (hwif->host_flags & IDE_HFLAG_ERROR_STOPS_FIFO) == 0) {
239 int nsect = drive->mult_count ? drive->mult_count : 1;
240
241 ide_pad_transfer(drive, READ, nsect * SECTOR_SIZE);
242 }
243
244 if (rq->errors >= ERROR_MAX || blk_noretry_request(rq)) {
245 ide_kill_rq(drive, rq);
246 return ide_stopped;
247 }
248
249 if (hwif->tp_ops->read_status(hwif) & (ATA_BUSY | ATA_DRQ))
250 rq->errors |= ERROR_RESET;
251
252 if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
253 ++rq->errors;
254 return ide_do_reset(drive);
255 }
256
257 if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
258 drive->special.b.recalibrate = 1;
259
260 ++rq->errors;
261
262 return ide_stopped;
263}
264
265static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
266{
267 ide_hwif_t *hwif = drive->hwif;
268
269 if ((stat & ATA_BUSY) ||
270 ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
271 /* other bits are useless when BUSY */
272 rq->errors |= ERROR_RESET;
273 } else {
274 /* add decoding error stuff */
275 }
276
277 if (hwif->tp_ops->read_status(hwif) & (ATA_BUSY | ATA_DRQ))
278 /* force an abort */
279 hwif->tp_ops->exec_command(hwif, ATA_CMD_IDLEIMMEDIATE);
280
281 if (rq->errors >= ERROR_MAX) {
282 ide_kill_rq(drive, rq);
283 } else {
284 if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
285 ++rq->errors;
286 return ide_do_reset(drive);
287 }
288 ++rq->errors;
289 }
290
291 return ide_stopped;
292}
293
294static ide_startstop_t
295__ide_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
296{
297 if (drive->media == ide_disk)
298 return ide_ata_error(drive, rq, stat, err);
299 return ide_atapi_error(drive, rq, stat, err);
300}
301
302/**
303 * ide_error - handle an error on the IDE
304 * @drive: drive the error occurred on
305 * @msg: message to report
306 * @stat: status bits
307 *
308 * ide_error() takes action based on the error returned by the drive.
309 * For normal I/O that may well include retries. We deal with
310 * both new-style (taskfile) and old style command handling here.
311 * In the case of taskfile command handling there is work left to
312 * do
313 */
314
315ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, u8 stat)
316{
317 struct request *rq;
318 u8 err;
319
320 err = ide_dump_status(drive, msg, stat);
321
322 rq = drive->hwif->rq;
323 if (rq == NULL)
324 return ide_stopped;
325
326 /* retry only "normal" I/O: */
327 if (!blk_fs_request(rq)) {
328 rq->errors = 1;
329 ide_end_drive_cmd(drive, stat, err);
330 return ide_stopped;
331 }
332
333 return __ide_error(drive, rq, stat, err);
334}
335EXPORT_SYMBOL_GPL(ide_error);
336
337static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf) 210static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
338{ 211{
339 tf->nsect = drive->sect; 212 tf->nsect = drive->sect;
@@ -490,71 +363,16 @@ static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
490 return ide_stopped; 363 return ide_stopped;
491} 364}
492 365
493int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting,
494 int arg)
495{
496 struct request_queue *q = drive->queue;
497 struct request *rq;
498 int ret = 0;
499
500 if (!(setting->flags & DS_SYNC))
501 return setting->set(drive, arg);
502
503 rq = blk_get_request(q, READ, __GFP_WAIT);
504 rq->cmd_type = REQ_TYPE_SPECIAL;
505 rq->cmd_len = 5;
506 rq->cmd[0] = REQ_DEVSET_EXEC;
507 *(int *)&rq->cmd[1] = arg;
508 rq->special = setting->set;
509
510 if (blk_execute_rq(q, NULL, rq, 0))
511 ret = rq->errors;
512 blk_put_request(rq);
513
514 return ret;
515}
516EXPORT_SYMBOL_GPL(ide_devset_execute);
517
518static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq) 366static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq)
519{ 367{
520 u8 cmd = rq->cmd[0]; 368 u8 cmd = rq->cmd[0];
521 369
522 if (cmd == REQ_PARK_HEADS || cmd == REQ_UNPARK_HEADS) {
523 ide_task_t task;
524 struct ide_taskfile *tf = &task.tf;
525
526 memset(&task, 0, sizeof(task));
527 if (cmd == REQ_PARK_HEADS) {
528 drive->sleep = *(unsigned long *)rq->special;
529 drive->dev_flags |= IDE_DFLAG_SLEEPING;
530 tf->command = ATA_CMD_IDLEIMMEDIATE;
531 tf->feature = 0x44;
532 tf->lbal = 0x4c;
533 tf->lbam = 0x4e;
534 tf->lbah = 0x55;
535 task.tf_flags |= IDE_TFLAG_CUSTOM_HANDLER;
536 } else /* cmd == REQ_UNPARK_HEADS */
537 tf->command = ATA_CMD_CHK_POWER;
538
539 task.tf_flags |= IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
540 task.rq = rq;
541 drive->hwif->data_phase = task.data_phase = TASKFILE_NO_DATA;
542 return do_rw_taskfile(drive, &task);
543 }
544
545 switch (cmd) { 370 switch (cmd) {
371 case REQ_PARK_HEADS:
372 case REQ_UNPARK_HEADS:
373 return ide_do_park_unpark(drive, rq);
546 case REQ_DEVSET_EXEC: 374 case REQ_DEVSET_EXEC:
547 { 375 return ide_do_devset(drive, rq);
548 int err, (*setfunc)(ide_drive_t *, int) = rq->special;
549
550 err = setfunc(drive, *(int *)&rq->cmd[1]);
551 if (err)
552 rq->errors = err;
553 else
554 err = 1;
555 ide_end_request(drive, err, 0);
556 return ide_stopped;
557 }
558 case REQ_DRIVE_RESET: 376 case REQ_DRIVE_RESET:
559 return ide_do_reset(drive); 377 return ide_do_reset(drive);
560 default: 378 default:
@@ -820,63 +638,6 @@ plug_device_2:
820 blk_plug_device(q); 638 blk_plug_device(q);
821} 639}
822 640
823/*
824 * un-busy the port etc, and clear any pending DMA status. we want to
825 * retry the current request in pio mode instead of risking tossing it
826 * all away
827 */
828static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
829{
830 ide_hwif_t *hwif = drive->hwif;
831 struct request *rq;
832 ide_startstop_t ret = ide_stopped;
833
834 /*
835 * end current dma transaction
836 */
837
838 if (error < 0) {
839 printk(KERN_WARNING "%s: DMA timeout error\n", drive->name);
840 (void)hwif->dma_ops->dma_end(drive);
841 ret = ide_error(drive, "dma timeout error",
842 hwif->tp_ops->read_status(hwif));
843 } else {
844 printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name);
845 hwif->dma_ops->dma_timeout(drive);
846 }
847
848 /*
849 * disable dma for now, but remember that we did so because of
850 * a timeout -- we'll reenable after we finish this next request
851 * (or rather the first chunk of it) in pio.
852 */
853 drive->dev_flags |= IDE_DFLAG_DMA_PIO_RETRY;
854 drive->retry_pio++;
855 ide_dma_off_quietly(drive);
856
857 /*
858 * un-busy drive etc and make sure request is sane
859 */
860
861 rq = hwif->rq;
862 if (!rq)
863 goto out;
864
865 hwif->rq = NULL;
866
867 rq->errors = 0;
868
869 if (!rq->bio)
870 goto out;
871
872 rq->sector = rq->bio->bi_sector;
873 rq->current_nr_sectors = bio_iovec(rq->bio)->bv_len >> 9;
874 rq->hard_cur_sectors = rq->current_nr_sectors;
875 rq->buffer = bio_data(rq->bio);
876out:
877 return ret;
878}
879
880static void ide_plug_device(ide_drive_t *drive) 641static void ide_plug_device(ide_drive_t *drive)
881{ 642{
882 struct request_queue *q = drive->queue; 643 struct request_queue *q = drive->queue;
@@ -888,6 +649,29 @@ static void ide_plug_device(ide_drive_t *drive)
888 spin_unlock_irqrestore(q->queue_lock, flags); 649 spin_unlock_irqrestore(q->queue_lock, flags);
889} 650}
890 651
652static int drive_is_ready(ide_drive_t *drive)
653{
654 ide_hwif_t *hwif = drive->hwif;
655 u8 stat = 0;
656
657 if (drive->waiting_for_dma)
658 return hwif->dma_ops->dma_test_irq(drive);
659
660 if (hwif->io_ports.ctl_addr &&
661 (hwif->host_flags & IDE_HFLAG_BROKEN_ALTSTATUS) == 0)
662 stat = hwif->tp_ops->read_altstatus(hwif);
663 else
664 /* Note: this may clear a pending IRQ!! */
665 stat = hwif->tp_ops->read_status(hwif);
666
667 if (stat & ATA_BUSY)
668 /* drive busy: definitely not interrupting */
669 return 0;
670
671 /* drive ready: *might* be interrupting */
672 return 1;
673}
674
891/** 675/**
892 * ide_timer_expiry - handle lack of an IDE interrupt 676 * ide_timer_expiry - handle lack of an IDE interrupt
893 * @data: timer callback magic (hwif) 677 * @data: timer callback magic (hwif)
@@ -1164,54 +948,6 @@ out_early:
1164} 948}
1165EXPORT_SYMBOL_GPL(ide_intr); 949EXPORT_SYMBOL_GPL(ide_intr);
1166 950
1167/**
1168 * ide_do_drive_cmd - issue IDE special command
1169 * @drive: device to issue command
1170 * @rq: request to issue
1171 *
1172 * This function issues a special IDE device request
1173 * onto the request queue.
1174 *
1175 * the rq is queued at the head of the request queue, displacing
1176 * the currently-being-processed request and this function
1177 * returns immediately without waiting for the new rq to be
1178 * completed. This is VERY DANGEROUS, and is intended for
1179 * careful use by the ATAPI tape/cdrom driver code.
1180 */
1181
1182void ide_do_drive_cmd(ide_drive_t *drive, struct request *rq)
1183{
1184 struct request_queue *q = drive->queue;
1185 unsigned long flags;
1186
1187 drive->hwif->rq = NULL;
1188
1189 spin_lock_irqsave(q->queue_lock, flags);
1190 __elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 0);
1191 spin_unlock_irqrestore(q->queue_lock, flags);
1192}
1193EXPORT_SYMBOL(ide_do_drive_cmd);
1194
1195void ide_pktcmd_tf_load(ide_drive_t *drive, u32 tf_flags, u16 bcount, u8 dma)
1196{
1197 ide_hwif_t *hwif = drive->hwif;
1198 ide_task_t task;
1199
1200 memset(&task, 0, sizeof(task));
1201 task.tf_flags = IDE_TFLAG_OUT_LBAH | IDE_TFLAG_OUT_LBAM |
1202 IDE_TFLAG_OUT_FEATURE | tf_flags;
1203 task.tf.feature = dma; /* Use PIO/DMA */
1204 task.tf.lbam = bcount & 0xff;
1205 task.tf.lbah = (bcount >> 8) & 0xff;
1206
1207 ide_tf_dump(drive->name, &task.tf);
1208 hwif->tp_ops->set_irq(hwif, 1);
1209 SELECT_MASK(drive, 0);
1210 hwif->tp_ops->tf_load(drive, &task);
1211}
1212
1213EXPORT_SYMBOL_GPL(ide_pktcmd_tf_load);
1214
1215void ide_pad_transfer(ide_drive_t *drive, int write, int len) 951void ide_pad_transfer(ide_drive_t *drive, int write, int len)
1216{ 952{
1217 ide_hwif_t *hwif = drive->hwif; 953 ide_hwif_t *hwif = drive->hwif;
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index b1892bd95c6f..317c5dadd7c0 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -27,35 +27,7 @@
27#include <asm/uaccess.h> 27#include <asm/uaccess.h>
28#include <asm/io.h> 28#include <asm/io.h>
29 29
30/* 30void SELECT_DRIVE(ide_drive_t *drive)
31 * Conventional PIO operations for ATA devices
32 */
33
34static u8 ide_inb (unsigned long port)
35{
36 return (u8) inb(port);
37}
38
39static void ide_outb (u8 val, unsigned long port)
40{
41 outb(val, port);
42}
43
44/*
45 * MMIO operations, typically used for SATA controllers
46 */
47
48static u8 ide_mm_inb (unsigned long port)
49{
50 return (u8) readb((void __iomem *) port);
51}
52
53static void ide_mm_outb (u8 value, unsigned long port)
54{
55 writeb(value, (void __iomem *) port);
56}
57
58void SELECT_DRIVE (ide_drive_t *drive)
59{ 31{
60 ide_hwif_t *hwif = drive->hwif; 32 ide_hwif_t *hwif = drive->hwif;
61 const struct ide_port_ops *port_ops = hwif->port_ops; 33 const struct ide_port_ops *port_ops = hwif->port_ops;
@@ -78,277 +50,6 @@ void SELECT_MASK(ide_drive_t *drive, int mask)
78 port_ops->maskproc(drive, mask); 50 port_ops->maskproc(drive, mask);
79} 51}
80 52
81void ide_exec_command(ide_hwif_t *hwif, u8 cmd)
82{
83 if (hwif->host_flags & IDE_HFLAG_MMIO)
84 writeb(cmd, (void __iomem *)hwif->io_ports.command_addr);
85 else
86 outb(cmd, hwif->io_ports.command_addr);
87}
88EXPORT_SYMBOL_GPL(ide_exec_command);
89
90u8 ide_read_status(ide_hwif_t *hwif)
91{
92 if (hwif->host_flags & IDE_HFLAG_MMIO)
93 return readb((void __iomem *)hwif->io_ports.status_addr);
94 else
95 return inb(hwif->io_ports.status_addr);
96}
97EXPORT_SYMBOL_GPL(ide_read_status);
98
99u8 ide_read_altstatus(ide_hwif_t *hwif)
100{
101 if (hwif->host_flags & IDE_HFLAG_MMIO)
102 return readb((void __iomem *)hwif->io_ports.ctl_addr);
103 else
104 return inb(hwif->io_ports.ctl_addr);
105}
106EXPORT_SYMBOL_GPL(ide_read_altstatus);
107
108void ide_set_irq(ide_hwif_t *hwif, int on)
109{
110 u8 ctl = ATA_DEVCTL_OBS;
111
112 if (on == 4) { /* hack for SRST */
113 ctl |= 4;
114 on &= ~4;
115 }
116
117 ctl |= on ? 0 : 2;
118
119 if (hwif->host_flags & IDE_HFLAG_MMIO)
120 writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr);
121 else
122 outb(ctl, hwif->io_ports.ctl_addr);
123}
124EXPORT_SYMBOL_GPL(ide_set_irq);
125
126void ide_tf_load(ide_drive_t *drive, ide_task_t *task)
127{
128 ide_hwif_t *hwif = drive->hwif;
129 struct ide_io_ports *io_ports = &hwif->io_ports;
130 struct ide_taskfile *tf = &task->tf;
131 void (*tf_outb)(u8 addr, unsigned long port);
132 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
133 u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
134
135 if (mmio)
136 tf_outb = ide_mm_outb;
137 else
138 tf_outb = ide_outb;
139
140 if (task->tf_flags & IDE_TFLAG_FLAGGED)
141 HIHI = 0xFF;
142
143 if (task->tf_flags & IDE_TFLAG_OUT_DATA) {
144 u16 data = (tf->hob_data << 8) | tf->data;
145
146 if (mmio)
147 writew(data, (void __iomem *)io_ports->data_addr);
148 else
149 outw(data, io_ports->data_addr);
150 }
151
152 if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
153 tf_outb(tf->hob_feature, io_ports->feature_addr);
154 if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
155 tf_outb(tf->hob_nsect, io_ports->nsect_addr);
156 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
157 tf_outb(tf->hob_lbal, io_ports->lbal_addr);
158 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
159 tf_outb(tf->hob_lbam, io_ports->lbam_addr);
160 if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
161 tf_outb(tf->hob_lbah, io_ports->lbah_addr);
162
163 if (task->tf_flags & IDE_TFLAG_OUT_FEATURE)
164 tf_outb(tf->feature, io_ports->feature_addr);
165 if (task->tf_flags & IDE_TFLAG_OUT_NSECT)
166 tf_outb(tf->nsect, io_ports->nsect_addr);
167 if (task->tf_flags & IDE_TFLAG_OUT_LBAL)
168 tf_outb(tf->lbal, io_ports->lbal_addr);
169 if (task->tf_flags & IDE_TFLAG_OUT_LBAM)
170 tf_outb(tf->lbam, io_ports->lbam_addr);
171 if (task->tf_flags & IDE_TFLAG_OUT_LBAH)
172 tf_outb(tf->lbah, io_ports->lbah_addr);
173
174 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
175 tf_outb((tf->device & HIHI) | drive->select,
176 io_ports->device_addr);
177}
178EXPORT_SYMBOL_GPL(ide_tf_load);
179
180void ide_tf_read(ide_drive_t *drive, ide_task_t *task)
181{
182 ide_hwif_t *hwif = drive->hwif;
183 struct ide_io_ports *io_ports = &hwif->io_ports;
184 struct ide_taskfile *tf = &task->tf;
185 void (*tf_outb)(u8 addr, unsigned long port);
186 u8 (*tf_inb)(unsigned long port);
187 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
188
189 if (mmio) {
190 tf_outb = ide_mm_outb;
191 tf_inb = ide_mm_inb;
192 } else {
193 tf_outb = ide_outb;
194 tf_inb = ide_inb;
195 }
196
197 if (task->tf_flags & IDE_TFLAG_IN_DATA) {
198 u16 data;
199
200 if (mmio)
201 data = readw((void __iomem *)io_ports->data_addr);
202 else
203 data = inw(io_ports->data_addr);
204
205 tf->data = data & 0xff;
206 tf->hob_data = (data >> 8) & 0xff;
207 }
208
209 /* be sure we're looking at the low order bits */
210 tf_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
211
212 if (task->tf_flags & IDE_TFLAG_IN_FEATURE)
213 tf->feature = tf_inb(io_ports->feature_addr);
214 if (task->tf_flags & IDE_TFLAG_IN_NSECT)
215 tf->nsect = tf_inb(io_ports->nsect_addr);
216 if (task->tf_flags & IDE_TFLAG_IN_LBAL)
217 tf->lbal = tf_inb(io_ports->lbal_addr);
218 if (task->tf_flags & IDE_TFLAG_IN_LBAM)
219 tf->lbam = tf_inb(io_ports->lbam_addr);
220 if (task->tf_flags & IDE_TFLAG_IN_LBAH)
221 tf->lbah = tf_inb(io_ports->lbah_addr);
222 if (task->tf_flags & IDE_TFLAG_IN_DEVICE)
223 tf->device = tf_inb(io_ports->device_addr);
224
225 if (task->tf_flags & IDE_TFLAG_LBA48) {
226 tf_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
227
228 if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
229 tf->hob_feature = tf_inb(io_ports->feature_addr);
230 if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
231 tf->hob_nsect = tf_inb(io_ports->nsect_addr);
232 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
233 tf->hob_lbal = tf_inb(io_ports->lbal_addr);
234 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
235 tf->hob_lbam = tf_inb(io_ports->lbam_addr);
236 if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
237 tf->hob_lbah = tf_inb(io_ports->lbah_addr);
238 }
239}
240EXPORT_SYMBOL_GPL(ide_tf_read);
241
242/*
243 * Some localbus EIDE interfaces require a special access sequence
244 * when using 32-bit I/O instructions to transfer data. We call this
245 * the "vlb_sync" sequence, which consists of three successive reads
246 * of the sector count register location, with interrupts disabled
247 * to ensure that the reads all happen together.
248 */
249static void ata_vlb_sync(unsigned long port)
250{
251 (void)inb(port);
252 (void)inb(port);
253 (void)inb(port);
254}
255
256/*
257 * This is used for most PIO data transfers *from* the IDE interface
258 *
259 * These routines will round up any request for an odd number of bytes,
260 * so if an odd len is specified, be sure that there's at least one
261 * extra byte allocated for the buffer.
262 */
263void ide_input_data(ide_drive_t *drive, struct request *rq, void *buf,
264 unsigned int len)
265{
266 ide_hwif_t *hwif = drive->hwif;
267 struct ide_io_ports *io_ports = &hwif->io_ports;
268 unsigned long data_addr = io_ports->data_addr;
269 u8 io_32bit = drive->io_32bit;
270 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
271
272 len++;
273
274 if (io_32bit) {
275 unsigned long uninitialized_var(flags);
276
277 if ((io_32bit & 2) && !mmio) {
278 local_irq_save(flags);
279 ata_vlb_sync(io_ports->nsect_addr);
280 }
281
282 if (mmio)
283 __ide_mm_insl((void __iomem *)data_addr, buf, len / 4);
284 else
285 insl(data_addr, buf, len / 4);
286
287 if ((io_32bit & 2) && !mmio)
288 local_irq_restore(flags);
289
290 if ((len & 3) >= 2) {
291 if (mmio)
292 __ide_mm_insw((void __iomem *)data_addr,
293 (u8 *)buf + (len & ~3), 1);
294 else
295 insw(data_addr, (u8 *)buf + (len & ~3), 1);
296 }
297 } else {
298 if (mmio)
299 __ide_mm_insw((void __iomem *)data_addr, buf, len / 2);
300 else
301 insw(data_addr, buf, len / 2);
302 }
303}
304EXPORT_SYMBOL_GPL(ide_input_data);
305
306/*
307 * This is used for most PIO data transfers *to* the IDE interface
308 */
309void ide_output_data(ide_drive_t *drive, struct request *rq, void *buf,
310 unsigned int len)
311{
312 ide_hwif_t *hwif = drive->hwif;
313 struct ide_io_ports *io_ports = &hwif->io_ports;
314 unsigned long data_addr = io_ports->data_addr;
315 u8 io_32bit = drive->io_32bit;
316 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
317
318 len++;
319
320 if (io_32bit) {
321 unsigned long uninitialized_var(flags);
322
323 if ((io_32bit & 2) && !mmio) {
324 local_irq_save(flags);
325 ata_vlb_sync(io_ports->nsect_addr);
326 }
327
328 if (mmio)
329 __ide_mm_outsl((void __iomem *)data_addr, buf, len / 4);
330 else
331 outsl(data_addr, buf, len / 4);
332
333 if ((io_32bit & 2) && !mmio)
334 local_irq_restore(flags);
335
336 if ((len & 3) >= 2) {
337 if (mmio)
338 __ide_mm_outsw((void __iomem *)data_addr,
339 (u8 *)buf + (len & ~3), 1);
340 else
341 outsw(data_addr, (u8 *)buf + (len & ~3), 1);
342 }
343 } else {
344 if (mmio)
345 __ide_mm_outsw((void __iomem *)data_addr, buf, len / 2);
346 else
347 outsw(data_addr, buf, len / 2);
348 }
349}
350EXPORT_SYMBOL_GPL(ide_output_data);
351
352u8 ide_read_error(ide_drive_t *drive) 53u8 ide_read_error(ide_drive_t *drive)
353{ 54{
354 ide_task_t task; 55 ide_task_t task;
@@ -362,35 +63,6 @@ u8 ide_read_error(ide_drive_t *drive)
362} 63}
363EXPORT_SYMBOL_GPL(ide_read_error); 64EXPORT_SYMBOL_GPL(ide_read_error);
364 65
365void ide_read_bcount_and_ireason(ide_drive_t *drive, u16 *bcount, u8 *ireason)
366{
367 ide_task_t task;
368
369 memset(&task, 0, sizeof(task));
370 task.tf_flags = IDE_TFLAG_IN_LBAH | IDE_TFLAG_IN_LBAM |
371 IDE_TFLAG_IN_NSECT;
372
373 drive->hwif->tp_ops->tf_read(drive, &task);
374
375 *bcount = (task.tf.lbah << 8) | task.tf.lbam;
376 *ireason = task.tf.nsect & 3;
377}
378EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason);
379
380const struct ide_tp_ops default_tp_ops = {
381 .exec_command = ide_exec_command,
382 .read_status = ide_read_status,
383 .read_altstatus = ide_read_altstatus,
384
385 .set_irq = ide_set_irq,
386
387 .tf_load = ide_tf_load,
388 .tf_read = ide_tf_read,
389
390 .input_data = ide_input_data,
391 .output_data = ide_output_data,
392};
393
394void ide_fix_driveid(u16 *id) 66void ide_fix_driveid(u16 *id)
395{ 67{
396#ifndef __LITTLE_ENDIAN 68#ifndef __LITTLE_ENDIAN
@@ -412,7 +84,7 @@ void ide_fix_driveid(u16 *id)
412 * returned by the ATA_CMD_ID_ATA[PI] commands. 84 * returned by the ATA_CMD_ID_ATA[PI] commands.
413 */ 85 */
414 86
415void ide_fixstring (u8 *s, const int bytecount, const int byteswap) 87void ide_fixstring(u8 *s, const int bytecount, const int byteswap)
416{ 88{
417 u8 *p, *end = &s[bytecount & ~1]; /* bytecount must be even */ 89 u8 *p, *end = &s[bytecount & ~1]; /* bytecount must be even */
418 90
@@ -435,44 +107,9 @@ void ide_fixstring (u8 *s, const int bytecount, const int byteswap)
435 while (p != end) 107 while (p != end)
436 *p++ = '\0'; 108 *p++ = '\0';
437} 109}
438
439EXPORT_SYMBOL(ide_fixstring); 110EXPORT_SYMBOL(ide_fixstring);
440 111
441/* 112/*
442 * Needed for PCI irq sharing
443 */
444int drive_is_ready (ide_drive_t *drive)
445{
446 ide_hwif_t *hwif = drive->hwif;
447 u8 stat = 0;
448
449 if (drive->waiting_for_dma)
450 return hwif->dma_ops->dma_test_irq(drive);
451
452 /*
453 * We do a passive status test under shared PCI interrupts on
454 * cards that truly share the ATA side interrupt, but may also share
455 * an interrupt with another pci card/device. We make no assumptions
456 * about possible isa-pnp and pci-pnp issues yet.
457 */
458 if (hwif->io_ports.ctl_addr &&
459 (hwif->host_flags & IDE_HFLAG_BROKEN_ALTSTATUS) == 0)
460 stat = hwif->tp_ops->read_altstatus(hwif);
461 else
462 /* Note: this may clear a pending IRQ!! */
463 stat = hwif->tp_ops->read_status(hwif);
464
465 if (stat & ATA_BUSY)
466 /* drive busy: definitely not interrupting */
467 return 0;
468
469 /* drive ready: *might* be interrupting */
470 return 1;
471}
472
473EXPORT_SYMBOL(drive_is_ready);
474
475/*
476 * This routine busy-waits for the drive status to be not "busy". 113 * This routine busy-waits for the drive status to be not "busy".
477 * It then checks the status for all of the "good" bits and none 114 * It then checks the status for all of the "good" bits and none
478 * of the "bad" bits, and if all is okay it returns 0. All other 115 * of the "bad" bits, and if all is okay it returns 0. All other
@@ -483,7 +120,8 @@ EXPORT_SYMBOL(drive_is_ready);
483 * setting a timer to wake up at half second intervals thereafter, 120 * setting a timer to wake up at half second intervals thereafter,
484 * until timeout is achieved, before timing out. 121 * until timeout is achieved, before timing out.
485 */ 122 */
486static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, unsigned long timeout, u8 *rstat) 123static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad,
124 unsigned long timeout, u8 *rstat)
487{ 125{
488 ide_hwif_t *hwif = drive->hwif; 126 ide_hwif_t *hwif = drive->hwif;
489 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 127 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
@@ -541,7 +179,8 @@ static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, unsigned long ti
541 * The caller should return the updated value of "startstop" in this case, 179 * The caller should return the updated value of "startstop" in this case,
542 * "startstop" is unchanged when the function returns 0. 180 * "startstop" is unchanged when the function returns 0.
543 */ 181 */
544int ide_wait_stat(ide_startstop_t *startstop, ide_drive_t *drive, u8 good, u8 bad, unsigned long timeout) 182int ide_wait_stat(ide_startstop_t *startstop, ide_drive_t *drive, u8 good,
183 u8 bad, unsigned long timeout)
545{ 184{
546 int err; 185 int err;
547 u8 stat; 186 u8 stat;
@@ -561,7 +200,6 @@ int ide_wait_stat(ide_startstop_t *startstop, ide_drive_t *drive, u8 good, u8 ba
561 200
562 return err; 201 return err;
563} 202}
564
565EXPORT_SYMBOL(ide_wait_stat); 203EXPORT_SYMBOL(ide_wait_stat);
566 204
567/** 205/**
@@ -582,7 +220,6 @@ int ide_in_drive_list(u16 *id, const struct drive_list_entry *table)
582 return 1; 220 return 1;
583 return 0; 221 return 0;
584} 222}
585
586EXPORT_SYMBOL_GPL(ide_in_drive_list); 223EXPORT_SYMBOL_GPL(ide_in_drive_list);
587 224
588/* 225/*
@@ -607,7 +244,7 @@ static const struct drive_list_entry ivb_list[] = {
607 * All hosts that use the 80c ribbon must use! 244 * All hosts that use the 80c ribbon must use!
608 * The name is derived from upper byte of word 93 and the 80c ribbon. 245 * The name is derived from upper byte of word 93 and the 80c ribbon.
609 */ 246 */
610u8 eighty_ninty_three (ide_drive_t *drive) 247u8 eighty_ninty_three(ide_drive_t *drive)
611{ 248{
612 ide_hwif_t *hwif = drive->hwif; 249 ide_hwif_t *hwif = drive->hwif;
613 u16 *id = drive->id; 250 u16 *id = drive->id;
@@ -652,47 +289,19 @@ no_80w:
652 289
653int ide_driveid_update(ide_drive_t *drive) 290int ide_driveid_update(ide_drive_t *drive)
654{ 291{
655 ide_hwif_t *hwif = drive->hwif;
656 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
657 u16 *id; 292 u16 *id;
658 unsigned long flags; 293 int rc;
659 u8 stat;
660
661 /*
662 * Re-read drive->id for possible DMA mode
663 * change (copied from ide-probe.c)
664 */
665
666 SELECT_MASK(drive, 1);
667 tp_ops->set_irq(hwif, 0);
668 msleep(50);
669 tp_ops->exec_command(hwif, ATA_CMD_ID_ATA);
670 294
671 if (ide_busy_sleep(hwif, WAIT_WORSTCASE, 1)) { 295 id = kmalloc(SECTOR_SIZE, GFP_ATOMIC);
672 SELECT_MASK(drive, 0); 296 if (id == NULL)
673 return 0; 297 return 0;
674 }
675
676 msleep(50); /* wait for IRQ and ATA_DRQ */
677 stat = tp_ops->read_status(hwif);
678 298
679 if (!OK_STAT(stat, ATA_DRQ, BAD_R_STAT)) { 299 SELECT_MASK(drive, 1);
680 SELECT_MASK(drive, 0); 300 rc = ide_dev_read_id(drive, ATA_CMD_ID_ATA, id);
681 printk("%s: CHECK for good STATUS\n", drive->name);
682 return 0;
683 }
684 local_irq_save(flags);
685 SELECT_MASK(drive, 0); 301 SELECT_MASK(drive, 0);
686 id = kmalloc(SECTOR_SIZE, GFP_ATOMIC); 302
687 if (!id) { 303 if (rc)
688 local_irq_restore(flags); 304 goto out_err;
689 return 0;
690 }
691 tp_ops->input_data(drive, NULL, id, SECTOR_SIZE);
692 (void)tp_ops->read_status(hwif); /* clear drive IRQ */
693 local_irq_enable();
694 local_irq_restore(flags);
695 ide_fix_driveid(id);
696 305
697 drive->id[ATA_ID_UDMA_MODES] = id[ATA_ID_UDMA_MODES]; 306 drive->id[ATA_ID_UDMA_MODES] = id[ATA_ID_UDMA_MODES];
698 drive->id[ATA_ID_MWDMA_MODES] = id[ATA_ID_MWDMA_MODES]; 307 drive->id[ATA_ID_MWDMA_MODES] = id[ATA_ID_MWDMA_MODES];
@@ -705,6 +314,12 @@ int ide_driveid_update(ide_drive_t *drive)
705 ide_dma_off(drive); 314 ide_dma_off(drive);
706 315
707 return 1; 316 return 1;
317out_err:
318 SELECT_MASK(drive, 0);
319 if (rc == 2)
320 printk(KERN_ERR "%s: %s: bad status\n", drive->name, __func__);
321 kfree(id);
322 return 0;
708} 323}
709 324
710int ide_config_drive_speed(ide_drive_t *drive, u8 speed) 325int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
@@ -731,18 +346,15 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
731 * but for some reason these don't work at 346 * but for some reason these don't work at
732 * this point (lost interrupt). 347 * this point (lost interrupt).
733 */ 348 */
734 /* 349
735 * Select the drive, and issue the SETFEATURES command
736 */
737 disable_irq_nosync(hwif->irq);
738
739 /* 350 /*
740 * FIXME: we race against the running IRQ here if 351 * FIXME: we race against the running IRQ here if
741 * this is called from non IRQ context. If we use 352 * this is called from non IRQ context. If we use
742 * disable_irq() we hang on the error path. Work 353 * disable_irq() we hang on the error path. Work
743 * is needed. 354 * is needed.
744 */ 355 */
745 356 disable_irq_nosync(hwif->irq);
357
746 udelay(1); 358 udelay(1);
747 SELECT_DRIVE(drive); 359 SELECT_DRIVE(drive);
748 SELECT_MASK(drive, 1); 360 SELECT_MASK(drive, 1);
@@ -812,8 +424,8 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
812 * 424 *
813 * See also ide_execute_command 425 * See also ide_execute_command
814 */ 426 */
815static void __ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, 427void __ide_set_handler(ide_drive_t *drive, ide_handler_t *handler,
816 unsigned int timeout, ide_expiry_t *expiry) 428 unsigned int timeout, ide_expiry_t *expiry)
817{ 429{
818 ide_hwif_t *hwif = drive->hwif; 430 ide_hwif_t *hwif = drive->hwif;
819 431
@@ -835,9 +447,8 @@ void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler,
835 __ide_set_handler(drive, handler, timeout, expiry); 447 __ide_set_handler(drive, handler, timeout, expiry);
836 spin_unlock_irqrestore(&hwif->lock, flags); 448 spin_unlock_irqrestore(&hwif->lock, flags);
837} 449}
838
839EXPORT_SYMBOL(ide_set_handler); 450EXPORT_SYMBOL(ide_set_handler);
840 451
841/** 452/**
842 * ide_execute_command - execute an IDE command 453 * ide_execute_command - execute an IDE command
843 * @drive: IDE drive to issue the command against 454 * @drive: IDE drive to issue the command against
@@ -847,7 +458,7 @@ EXPORT_SYMBOL(ide_set_handler);
847 * @expiry: handler to run on timeout 458 * @expiry: handler to run on timeout
848 * 459 *
849 * Helper function to issue an IDE command. This handles the 460 * Helper function to issue an IDE command. This handles the
850 * atomicity requirements, command timing and ensures that the 461 * atomicity requirements, command timing and ensures that the
851 * handler and IRQ setup do not race. All IDE command kick off 462 * handler and IRQ setup do not race. All IDE command kick off
852 * should go via this function or do equivalent locking. 463 * should go via this function or do equivalent locking.
853 */ 464 */
@@ -884,301 +495,6 @@ void ide_execute_pkt_cmd(ide_drive_t *drive)
884} 495}
885EXPORT_SYMBOL_GPL(ide_execute_pkt_cmd); 496EXPORT_SYMBOL_GPL(ide_execute_pkt_cmd);
886 497
887static inline void ide_complete_drive_reset(ide_drive_t *drive, int err)
888{
889 struct request *rq = drive->hwif->rq;
890
891 if (rq && blk_special_request(rq) && rq->cmd[0] == REQ_DRIVE_RESET)
892 ide_end_request(drive, err ? err : 1, 0);
893}
894
895/* needed below */
896static ide_startstop_t do_reset1 (ide_drive_t *, int);
897
898/*
899 * atapi_reset_pollfunc() gets invoked to poll the interface for completion every 50ms
900 * during an atapi drive reset operation. If the drive has not yet responded,
901 * and we have not yet hit our maximum waiting time, then the timer is restarted
902 * for another 50ms.
903 */
904static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive)
905{
906 ide_hwif_t *hwif = drive->hwif;
907 u8 stat;
908
909 SELECT_DRIVE(drive);
910 udelay (10);
911 stat = hwif->tp_ops->read_status(hwif);
912
913 if (OK_STAT(stat, 0, ATA_BUSY))
914 printk("%s: ATAPI reset complete\n", drive->name);
915 else {
916 if (time_before(jiffies, hwif->poll_timeout)) {
917 ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL);
918 /* continue polling */
919 return ide_started;
920 }
921 /* end of polling */
922 hwif->polling = 0;
923 printk("%s: ATAPI reset timed-out, status=0x%02x\n",
924 drive->name, stat);
925 /* do it the old fashioned way */
926 return do_reset1(drive, 1);
927 }
928 /* done polling */
929 hwif->polling = 0;
930 ide_complete_drive_reset(drive, 0);
931 return ide_stopped;
932}
933
934static void ide_reset_report_error(ide_hwif_t *hwif, u8 err)
935{
936 static const char *err_master_vals[] =
937 { NULL, "passed", "formatter device error",
938 "sector buffer error", "ECC circuitry error",
939 "controlling MPU error" };
940
941 u8 err_master = err & 0x7f;
942
943 printk(KERN_ERR "%s: reset: master: ", hwif->name);
944 if (err_master && err_master < 6)
945 printk(KERN_CONT "%s", err_master_vals[err_master]);
946 else
947 printk(KERN_CONT "error (0x%02x?)", err);
948 if (err & 0x80)
949 printk(KERN_CONT "; slave: failed");
950 printk(KERN_CONT "\n");
951}
952
953/*
954 * reset_pollfunc() gets invoked to poll the interface for completion every 50ms
955 * during an ide reset operation. If the drives have not yet responded,
956 * and we have not yet hit our maximum waiting time, then the timer is restarted
957 * for another 50ms.
958 */
959static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
960{
961 ide_hwif_t *hwif = drive->hwif;
962 const struct ide_port_ops *port_ops = hwif->port_ops;
963 u8 tmp;
964 int err = 0;
965
966 if (port_ops && port_ops->reset_poll) {
967 err = port_ops->reset_poll(drive);
968 if (err) {
969 printk(KERN_ERR "%s: host reset_poll failure for %s.\n",
970 hwif->name, drive->name);
971 goto out;
972 }
973 }
974
975 tmp = hwif->tp_ops->read_status(hwif);
976
977 if (!OK_STAT(tmp, 0, ATA_BUSY)) {
978 if (time_before(jiffies, hwif->poll_timeout)) {
979 ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL);
980 /* continue polling */
981 return ide_started;
982 }
983 printk("%s: reset timed-out, status=0x%02x\n", hwif->name, tmp);
984 drive->failures++;
985 err = -EIO;
986 } else {
987 tmp = ide_read_error(drive);
988
989 if (tmp == 1) {
990 printk(KERN_INFO "%s: reset: success\n", hwif->name);
991 drive->failures = 0;
992 } else {
993 ide_reset_report_error(hwif, tmp);
994 drive->failures++;
995 err = -EIO;
996 }
997 }
998out:
999 hwif->polling = 0; /* done polling */
1000 ide_complete_drive_reset(drive, err);
1001 return ide_stopped;
1002}
1003
1004static void ide_disk_pre_reset(ide_drive_t *drive)
1005{
1006 int legacy = (drive->id[ATA_ID_CFS_ENABLE_2] & 0x0400) ? 0 : 1;
1007
1008 drive->special.all = 0;
1009 drive->special.b.set_geometry = legacy;
1010 drive->special.b.recalibrate = legacy;
1011
1012 drive->mult_count = 0;
1013 drive->dev_flags &= ~IDE_DFLAG_PARKED;
1014
1015 if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0 &&
1016 (drive->dev_flags & IDE_DFLAG_USING_DMA) == 0)
1017 drive->mult_req = 0;
1018
1019 if (drive->mult_req != drive->mult_count)
1020 drive->special.b.set_multmode = 1;
1021}
1022
1023static void pre_reset(ide_drive_t *drive)
1024{
1025 const struct ide_port_ops *port_ops = drive->hwif->port_ops;
1026
1027 if (drive->media == ide_disk)
1028 ide_disk_pre_reset(drive);
1029 else
1030 drive->dev_flags |= IDE_DFLAG_POST_RESET;
1031
1032 if (drive->dev_flags & IDE_DFLAG_USING_DMA) {
1033 if (drive->crc_count)
1034 ide_check_dma_crc(drive);
1035 else
1036 ide_dma_off(drive);
1037 }
1038
1039 if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0) {
1040 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0) {
1041 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
1042 drive->io_32bit = 0;
1043 }
1044 return;
1045 }
1046
1047 if (port_ops && port_ops->pre_reset)
1048 port_ops->pre_reset(drive);
1049
1050 if (drive->current_speed != 0xff)
1051 drive->desired_speed = drive->current_speed;
1052 drive->current_speed = 0xff;
1053}
1054
1055/*
1056 * do_reset1() attempts to recover a confused drive by resetting it.
1057 * Unfortunately, resetting a disk drive actually resets all devices on
1058 * the same interface, so it can really be thought of as resetting the
1059 * interface rather than resetting the drive.
1060 *
1061 * ATAPI devices have their own reset mechanism which allows them to be
1062 * individually reset without clobbering other devices on the same interface.
1063 *
1064 * Unfortunately, the IDE interface does not generate an interrupt to let
1065 * us know when the reset operation has finished, so we must poll for this.
1066 * Equally poor, though, is the fact that this may a very long time to complete,
1067 * (up to 30 seconds worstcase). So, instead of busy-waiting here for it,
1068 * we set a timer to poll at 50ms intervals.
1069 */
1070static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1071{
1072 ide_hwif_t *hwif = drive->hwif;
1073 struct ide_io_ports *io_ports = &hwif->io_ports;
1074 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
1075 const struct ide_port_ops *port_ops;
1076 ide_drive_t *tdrive;
1077 unsigned long flags, timeout;
1078 int i;
1079 DEFINE_WAIT(wait);
1080
1081 spin_lock_irqsave(&hwif->lock, flags);
1082
1083 /* We must not reset with running handlers */
1084 BUG_ON(hwif->handler != NULL);
1085
1086 /* For an ATAPI device, first try an ATAPI SRST. */
1087 if (drive->media != ide_disk && !do_not_try_atapi) {
1088 pre_reset(drive);
1089 SELECT_DRIVE(drive);
1090 udelay (20);
1091 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
1092 ndelay(400);
1093 hwif->poll_timeout = jiffies + WAIT_WORSTCASE;
1094 hwif->polling = 1;
1095 __ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL);
1096 spin_unlock_irqrestore(&hwif->lock, flags);
1097 return ide_started;
1098 }
1099
1100 /* We must not disturb devices in the IDE_DFLAG_PARKED state. */
1101 do {
1102 unsigned long now;
1103
1104 prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE);
1105 timeout = jiffies;
1106 ide_port_for_each_dev(i, tdrive, hwif) {
1107 if (tdrive->dev_flags & IDE_DFLAG_PRESENT &&
1108 tdrive->dev_flags & IDE_DFLAG_PARKED &&
1109 time_after(tdrive->sleep, timeout))
1110 timeout = tdrive->sleep;
1111 }
1112
1113 now = jiffies;
1114 if (time_before_eq(timeout, now))
1115 break;
1116
1117 spin_unlock_irqrestore(&hwif->lock, flags);
1118 timeout = schedule_timeout_uninterruptible(timeout - now);
1119 spin_lock_irqsave(&hwif->lock, flags);
1120 } while (timeout);
1121 finish_wait(&ide_park_wq, &wait);
1122
1123 /*
1124 * First, reset any device state data we were maintaining
1125 * for any of the drives on this interface.
1126 */
1127 ide_port_for_each_dev(i, tdrive, hwif)
1128 pre_reset(tdrive);
1129
1130 if (io_ports->ctl_addr == 0) {
1131 spin_unlock_irqrestore(&hwif->lock, flags);
1132 ide_complete_drive_reset(drive, -ENXIO);
1133 return ide_stopped;
1134 }
1135
1136 /*
1137 * Note that we also set nIEN while resetting the device,
1138 * to mask unwanted interrupts from the interface during the reset.
1139 * However, due to the design of PC hardware, this will cause an
1140 * immediate interrupt due to the edge transition it produces.
1141 * This single interrupt gives us a "fast poll" for drives that
1142 * recover from reset very quickly, saving us the first 50ms wait time.
1143 *
1144 * TODO: add ->softreset method and stop abusing ->set_irq
1145 */
1146 /* set SRST and nIEN */
1147 tp_ops->set_irq(hwif, 4);
1148 /* more than enough time */
1149 udelay(10);
1150 /* clear SRST, leave nIEN (unless device is on the quirk list) */
1151 tp_ops->set_irq(hwif, drive->quirk_list == 2);
1152 /* more than enough time */
1153 udelay(10);
1154 hwif->poll_timeout = jiffies + WAIT_WORSTCASE;
1155 hwif->polling = 1;
1156 __ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL);
1157
1158 /*
1159 * Some weird controller like resetting themselves to a strange
1160 * state when the disks are reset this way. At least, the Winbond
1161 * 553 documentation says that
1162 */
1163 port_ops = hwif->port_ops;
1164 if (port_ops && port_ops->resetproc)
1165 port_ops->resetproc(drive);
1166
1167 spin_unlock_irqrestore(&hwif->lock, flags);
1168 return ide_started;
1169}
1170
1171/*
1172 * ide_do_reset() is the entry point to the drive/interface reset code.
1173 */
1174
1175ide_startstop_t ide_do_reset (ide_drive_t *drive)
1176{
1177 return do_reset1(drive, 0);
1178}
1179
1180EXPORT_SYMBOL(ide_do_reset);
1181
1182/* 498/*
1183 * ide_wait_not_busy() waits for the currently selected device on the hwif 499 * ide_wait_not_busy() waits for the currently selected device on the hwif
1184 * to report a non-busy status, see comments in ide_probe_port(). 500 * to report a non-busy status, see comments in ide_probe_port().
@@ -1187,7 +503,7 @@ int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout)
1187{ 503{
1188 u8 stat = 0; 504 u8 stat = 0;
1189 505
1190 while(timeout--) { 506 while (timeout--) {
1191 /* 507 /*
1192 * Turn this into a schedule() sleep once I'm sure 508 * Turn this into a schedule() sleep once I'm sure
1193 * about locking issues (2.5 work ?). 509 * about locking issues (2.5 work ?).
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index 09526a0de734..f6c683dd2987 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -5,163 +5,6 @@
5#include <linux/ide.h> 5#include <linux/ide.h>
6#include <linux/bitops.h> 6#include <linux/bitops.h>
7 7
8static const char *udma_str[] =
9 { "UDMA/16", "UDMA/25", "UDMA/33", "UDMA/44",
10 "UDMA/66", "UDMA/100", "UDMA/133", "UDMA7" };
11static const char *mwdma_str[] =
12 { "MWDMA0", "MWDMA1", "MWDMA2" };
13static const char *swdma_str[] =
14 { "SWDMA0", "SWDMA1", "SWDMA2" };
15static const char *pio_str[] =
16 { "PIO0", "PIO1", "PIO2", "PIO3", "PIO4", "PIO5" };
17
18/**
19 * ide_xfer_verbose - return IDE mode names
20 * @mode: transfer mode
21 *
22 * Returns a constant string giving the name of the mode
23 * requested.
24 */
25
26const char *ide_xfer_verbose(u8 mode)
27{
28 const char *s;
29 u8 i = mode & 0xf;
30
31 if (mode >= XFER_UDMA_0 && mode <= XFER_UDMA_7)
32 s = udma_str[i];
33 else if (mode >= XFER_MW_DMA_0 && mode <= XFER_MW_DMA_2)
34 s = mwdma_str[i];
35 else if (mode >= XFER_SW_DMA_0 && mode <= XFER_SW_DMA_2)
36 s = swdma_str[i];
37 else if (mode >= XFER_PIO_0 && mode <= XFER_PIO_5)
38 s = pio_str[i & 0x7];
39 else if (mode == XFER_PIO_SLOW)
40 s = "PIO SLOW";
41 else
42 s = "XFER ERROR";
43
44 return s;
45}
46EXPORT_SYMBOL(ide_xfer_verbose);
47
48/**
49 * ide_rate_filter - filter transfer mode
50 * @drive: IDE device
51 * @speed: desired speed
52 *
53 * Given the available transfer modes this function returns
54 * the best available speed at or below the speed requested.
55 *
56 * TODO: check device PIO capabilities
57 */
58
59static u8 ide_rate_filter(ide_drive_t *drive, u8 speed)
60{
61 ide_hwif_t *hwif = drive->hwif;
62 u8 mode = ide_find_dma_mode(drive, speed);
63
64 if (mode == 0) {
65 if (hwif->pio_mask)
66 mode = fls(hwif->pio_mask) - 1 + XFER_PIO_0;
67 else
68 mode = XFER_PIO_4;
69 }
70
71/* printk("%s: mode 0x%02x, speed 0x%02x\n", __func__, mode, speed); */
72
73 return min(speed, mode);
74}
75
76/**
77 * ide_get_best_pio_mode - get PIO mode from drive
78 * @drive: drive to consider
79 * @mode_wanted: preferred mode
80 * @max_mode: highest allowed mode
81 *
82 * This routine returns the recommended PIO settings for a given drive,
83 * based on the drive->id information and the ide_pio_blacklist[].
84 *
85 * Drive PIO mode is auto-selected if 255 is passed as mode_wanted.
86 * This is used by most chipset support modules when "auto-tuning".
87 */
88
89u8 ide_get_best_pio_mode(ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
90{
91 u16 *id = drive->id;
92 int pio_mode = -1, overridden = 0;
93
94 if (mode_wanted != 255)
95 return min_t(u8, mode_wanted, max_mode);
96
97 if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_BLACKLIST) == 0)
98 pio_mode = ide_scan_pio_blacklist((char *)&id[ATA_ID_PROD]);
99
100 if (pio_mode != -1) {
101 printk(KERN_INFO "%s: is on PIO blacklist\n", drive->name);
102 } else {
103 pio_mode = id[ATA_ID_OLD_PIO_MODES] >> 8;
104 if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */
105 pio_mode = 2;
106 overridden = 1;
107 }
108
109 if (id[ATA_ID_FIELD_VALID] & 2) { /* ATA2? */
110 if (ata_id_has_iordy(id)) {
111 if (id[ATA_ID_PIO_MODES] & 7) {
112 overridden = 0;
113 if (id[ATA_ID_PIO_MODES] & 4)
114 pio_mode = 5;
115 else if (id[ATA_ID_PIO_MODES] & 2)
116 pio_mode = 4;
117 else
118 pio_mode = 3;
119 }
120 }
121 }
122
123 if (overridden)
124 printk(KERN_INFO "%s: tPIO > 2, assuming tPIO = 2\n",
125 drive->name);
126 }
127
128 if (pio_mode > max_mode)
129 pio_mode = max_mode;
130
131 return pio_mode;
132}
133EXPORT_SYMBOL_GPL(ide_get_best_pio_mode);
134
135/* req_pio == "255" for auto-tune */
136void ide_set_pio(ide_drive_t *drive, u8 req_pio)
137{
138 ide_hwif_t *hwif = drive->hwif;
139 const struct ide_port_ops *port_ops = hwif->port_ops;
140 u8 host_pio, pio;
141
142 if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
143 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
144 return;
145
146 BUG_ON(hwif->pio_mask == 0x00);
147
148 host_pio = fls(hwif->pio_mask) - 1;
149
150 pio = ide_get_best_pio_mode(drive, req_pio, host_pio);
151
152 /*
153 * TODO:
154 * - report device max PIO mode
155 * - check req_pio != 255 against device max PIO mode
156 */
157 printk(KERN_DEBUG "%s: host max PIO%d wanted PIO%d%s selected PIO%d\n",
158 drive->name, host_pio, req_pio,
159 req_pio == 255 ? "(auto-tune)" : "", pio);
160
161 (void)ide_set_pio_mode(drive, XFER_PIO_0 + pio);
162}
163EXPORT_SYMBOL_GPL(ide_set_pio);
164
165/** 8/**
166 * ide_toggle_bounce - handle bounce buffering 9 * ide_toggle_bounce - handle bounce buffering
167 * @drive: drive to update 10 * @drive: drive to update
@@ -188,89 +31,6 @@ void ide_toggle_bounce(ide_drive_t *drive, int on)
188 blk_queue_bounce_limit(drive->queue, addr); 31 blk_queue_bounce_limit(drive->queue, addr);
189} 32}
190 33
191int ide_set_pio_mode(ide_drive_t *drive, const u8 mode)
192{
193 ide_hwif_t *hwif = drive->hwif;
194 const struct ide_port_ops *port_ops = hwif->port_ops;
195
196 if (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)
197 return 0;
198
199 if (port_ops == NULL || port_ops->set_pio_mode == NULL)
200 return -1;
201
202 /*
203 * TODO: temporary hack for some legacy host drivers that didn't
204 * set transfer mode on the device in ->set_pio_mode method...
205 */
206 if (port_ops->set_dma_mode == NULL) {
207 port_ops->set_pio_mode(drive, mode - XFER_PIO_0);
208 return 0;
209 }
210
211 if (hwif->host_flags & IDE_HFLAG_POST_SET_MODE) {
212 if (ide_config_drive_speed(drive, mode))
213 return -1;
214 port_ops->set_pio_mode(drive, mode - XFER_PIO_0);
215 return 0;
216 } else {
217 port_ops->set_pio_mode(drive, mode - XFER_PIO_0);
218 return ide_config_drive_speed(drive, mode);
219 }
220}
221
222int ide_set_dma_mode(ide_drive_t *drive, const u8 mode)
223{
224 ide_hwif_t *hwif = drive->hwif;
225 const struct ide_port_ops *port_ops = hwif->port_ops;
226
227 if (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)
228 return 0;
229
230 if (port_ops == NULL || port_ops->set_dma_mode == NULL)
231 return -1;
232
233 if (hwif->host_flags & IDE_HFLAG_POST_SET_MODE) {
234 if (ide_config_drive_speed(drive, mode))
235 return -1;
236 port_ops->set_dma_mode(drive, mode);
237 return 0;
238 } else {
239 port_ops->set_dma_mode(drive, mode);
240 return ide_config_drive_speed(drive, mode);
241 }
242}
243EXPORT_SYMBOL_GPL(ide_set_dma_mode);
244
245/**
246 * ide_set_xfer_rate - set transfer rate
247 * @drive: drive to set
248 * @rate: speed to attempt to set
249 *
250 * General helper for setting the speed of an IDE device. This
251 * function knows about user enforced limits from the configuration
252 * which ->set_pio_mode/->set_dma_mode does not.
253 */
254
255int ide_set_xfer_rate(ide_drive_t *drive, u8 rate)
256{
257 ide_hwif_t *hwif = drive->hwif;
258 const struct ide_port_ops *port_ops = hwif->port_ops;
259
260 if (port_ops == NULL || port_ops->set_dma_mode == NULL ||
261 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
262 return -1;
263
264 rate = ide_rate_filter(drive, rate);
265
266 BUG_ON(rate < XFER_PIO_0);
267
268 if (rate >= XFER_PIO_0 && rate <= XFER_PIO_5)
269 return ide_set_pio_mode(drive, rate);
270
271 return ide_set_dma_mode(drive, rate);
272}
273
274static void ide_dump_opcode(ide_drive_t *drive) 34static void ide_dump_opcode(ide_drive_t *drive)
275{ 35{
276 struct request *rq = drive->hwif->rq; 36 struct request *rq = drive->hwif->rq;
diff --git a/drivers/ide/ide-park.c b/drivers/ide/ide-park.c
index c875a957596c..f30e52152fcb 100644
--- a/drivers/ide/ide-park.c
+++ b/drivers/ide/ide-park.c
@@ -1,5 +1,6 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/ide.h> 2#include <linux/ide.h>
3#include <linux/hdreg.h>
3#include <linux/jiffies.h> 4#include <linux/jiffies.h>
4#include <linux/blkdev.h> 5#include <linux/blkdev.h>
5 6
@@ -60,6 +61,30 @@ out:
60 return; 61 return;
61} 62}
62 63
64ide_startstop_t ide_do_park_unpark(ide_drive_t *drive, struct request *rq)
65{
66 ide_task_t task;
67 struct ide_taskfile *tf = &task.tf;
68
69 memset(&task, 0, sizeof(task));
70 if (rq->cmd[0] == REQ_PARK_HEADS) {
71 drive->sleep = *(unsigned long *)rq->special;
72 drive->dev_flags |= IDE_DFLAG_SLEEPING;
73 tf->command = ATA_CMD_IDLEIMMEDIATE;
74 tf->feature = 0x44;
75 tf->lbal = 0x4c;
76 tf->lbam = 0x4e;
77 tf->lbah = 0x55;
78 task.tf_flags |= IDE_TFLAG_CUSTOM_HANDLER;
79 } else /* cmd == REQ_UNPARK_HEADS */
80 tf->command = ATA_CMD_CHK_POWER;
81
82 task.tf_flags |= IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
83 task.rq = rq;
84 drive->hwif->data_phase = task.data_phase = TASKFILE_NO_DATA;
85 return do_rw_taskfile(drive, &task);
86}
87
63ssize_t ide_park_show(struct device *dev, struct device_attribute *attr, 88ssize_t ide_park_show(struct device *dev, struct device_attribute *attr,
64 char *buf) 89 char *buf)
65{ 90{
diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
index bddae2b329a0..61111fd27130 100644
--- a/drivers/ide/ide-pci-generic.c
+++ b/drivers/ide/ide-pci-generic.c
@@ -33,8 +33,6 @@ static int ide_generic_all; /* Set to claim all devices */
33module_param_named(all_generic_ide, ide_generic_all, bool, 0444); 33module_param_named(all_generic_ide, ide_generic_all, bool, 0444);
34MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE storage controllers."); 34MODULE_PARM_DESC(all_generic_ide, "IDE generic will claim all unknown PCI IDE storage controllers.");
35 35
36#define IDE_HFLAGS_UMC (IDE_HFLAG_NO_DMA | IDE_HFLAG_FORCE_LEGACY_IRQS)
37
38#define DECLARE_GENERIC_PCI_DEV(extra_flags) \ 36#define DECLARE_GENERIC_PCI_DEV(extra_flags) \
39 { \ 37 { \
40 .name = DRV_NAME, \ 38 .name = DRV_NAME, \
@@ -61,7 +59,7 @@ static const struct ide_port_info generic_chipsets[] __devinitdata = {
61 /* 2: SAMURAI / HT6565 / HINT_IDE */ 59 /* 2: SAMURAI / HT6565 / HINT_IDE */
62 DECLARE_GENERIC_PCI_DEV(0), 60 DECLARE_GENERIC_PCI_DEV(0),
63 /* 3: UM8673F / UM8886A / UM8886BF */ 61 /* 3: UM8673F / UM8886A / UM8886BF */
64 DECLARE_GENERIC_PCI_DEV(IDE_HFLAGS_UMC), 62 DECLARE_GENERIC_PCI_DEV(IDE_HFLAG_NO_DMA),
65 /* 4: VIA_IDE / OPTI621V / Piccolo010{2,3,5} */ 63 /* 4: VIA_IDE / OPTI621V / Piccolo010{2,3,5} */
66 DECLARE_GENERIC_PCI_DEV(IDE_HFLAG_NO_AUTODMA), 64 DECLARE_GENERIC_PCI_DEV(IDE_HFLAG_NO_AUTODMA),
67 65
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index ee8e3e7cad51..974067043fba 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -181,16 +181,16 @@ static void ide_classify_atapi_dev(ide_drive_t *drive)
181 * do_identify - identify a drive 181 * do_identify - identify a drive
182 * @drive: drive to identify 182 * @drive: drive to identify
183 * @cmd: command used 183 * @cmd: command used
184 * @id: buffer for IDENTIFY data
184 * 185 *
185 * Called when we have issued a drive identify command to 186 * Called when we have issued a drive identify command to
186 * read and parse the results. This function is run with 187 * read and parse the results. This function is run with
187 * interrupts disabled. 188 * interrupts disabled.
188 */ 189 */
189 190
190static void do_identify(ide_drive_t *drive, u8 cmd) 191static void do_identify(ide_drive_t *drive, u8 cmd, u16 *id)
191{ 192{
192 ide_hwif_t *hwif = drive->hwif; 193 ide_hwif_t *hwif = drive->hwif;
193 u16 *id = drive->id;
194 char *m = (char *)&id[ATA_ID_PROD]; 194 char *m = (char *)&id[ATA_ID_PROD];
195 unsigned long flags; 195 unsigned long flags;
196 int bswap = 1; 196 int bswap = 1;
@@ -233,16 +233,6 @@ static void do_identify(ide_drive_t *drive, u8 cmd)
233 drive->dev_flags |= IDE_DFLAG_PRESENT; 233 drive->dev_flags |= IDE_DFLAG_PRESENT;
234 drive->dev_flags &= ~IDE_DFLAG_DEAD; 234 drive->dev_flags &= ~IDE_DFLAG_DEAD;
235 235
236 /*
237 * Check for an ATAPI device
238 */
239 if (cmd == ATA_CMD_ID_ATAPI)
240 ide_classify_atapi_dev(drive);
241 else
242 /*
243 * Not an ATAPI device: looks like a "regular" hard disk
244 */
245 ide_classify_ata_dev(drive);
246 return; 236 return;
247err_misc: 237err_misc:
248 kfree(id); 238 kfree(id);
@@ -250,21 +240,19 @@ err_misc:
250} 240}
251 241
252/** 242/**
253 * actual_try_to_identify - send ata/atapi identify 243 * ide_dev_read_id - send ATA/ATAPI IDENTIFY command
254 * @drive: drive to identify 244 * @drive: drive to identify
255 * @cmd: command to use 245 * @cmd: command to use
246 * @id: buffer for IDENTIFY data
256 * 247 *
257 * try_to_identify() sends an ATA(PI) IDENTIFY request to a drive 248 * Sends an ATA(PI) IDENTIFY request to a drive and waits for a response.
258 * and waits for a response. It also monitors irqs while this is
259 * happening, in hope of automatically determining which one is
260 * being used by the interface.
261 * 249 *
262 * Returns: 0 device was identified 250 * Returns: 0 device was identified
263 * 1 device timed-out (no response to identify request) 251 * 1 device timed-out (no response to identify request)
264 * 2 device aborted the command (refused to identify itself) 252 * 2 device aborted the command (refused to identify itself)
265 */ 253 */
266 254
267static int actual_try_to_identify (ide_drive_t *drive, u8 cmd) 255int ide_dev_read_id(ide_drive_t *drive, u8 cmd, u16 *id)
268{ 256{
269 ide_hwif_t *hwif = drive->hwif; 257 ide_hwif_t *hwif = drive->hwif;
270 struct ide_io_ports *io_ports = &hwif->io_ports; 258 struct ide_io_ports *io_ports = &hwif->io_ports;
@@ -273,6 +261,13 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
273 unsigned long timeout; 261 unsigned long timeout;
274 u8 s = 0, a = 0; 262 u8 s = 0, a = 0;
275 263
264 /*
265 * Disable device IRQ. Otherwise we'll get spurious interrupts
266 * during the identify phase that the IRQ handler isn't expecting.
267 */
268 if (io_ports->ctl_addr)
269 tp_ops->set_irq(hwif, 0);
270
276 /* take a deep breath */ 271 /* take a deep breath */
277 msleep(50); 272 msleep(50);
278 273
@@ -317,7 +312,7 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
317 312
318 if (OK_STAT(s, ATA_DRQ, BAD_R_STAT)) { 313 if (OK_STAT(s, ATA_DRQ, BAD_R_STAT)) {
319 /* drive returned ID */ 314 /* drive returned ID */
320 do_identify(drive, cmd); 315 do_identify(drive, cmd, id);
321 /* drive responded with ID */ 316 /* drive responded with ID */
322 rc = 0; 317 rc = 0;
323 /* clear drive IRQ */ 318 /* clear drive IRQ */
@@ -329,63 +324,6 @@ static int actual_try_to_identify (ide_drive_t *drive, u8 cmd)
329 return rc; 324 return rc;
330} 325}
331 326
332/**
333 * try_to_identify - try to identify a drive
334 * @drive: drive to probe
335 * @cmd: command to use
336 *
337 * Issue the identify command and then do IRQ probing to
338 * complete the identification when needed by finding the
339 * IRQ the drive is attached to
340 */
341
342static int try_to_identify (ide_drive_t *drive, u8 cmd)
343{
344 ide_hwif_t *hwif = drive->hwif;
345 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
346 int retval;
347 int autoprobe = 0;
348 unsigned long cookie = 0;
349
350 /*
351 * Disable device irq unless we need to
352 * probe for it. Otherwise we'll get spurious
353 * interrupts during the identify-phase that
354 * the irq handler isn't expecting.
355 */
356 if (hwif->io_ports.ctl_addr) {
357 if (!hwif->irq) {
358 autoprobe = 1;
359 cookie = probe_irq_on();
360 }
361 tp_ops->set_irq(hwif, autoprobe);
362 }
363
364 retval = actual_try_to_identify(drive, cmd);
365
366 if (autoprobe) {
367 int irq;
368
369 tp_ops->set_irq(hwif, 0);
370 /* clear drive IRQ */
371 (void)tp_ops->read_status(hwif);
372 udelay(5);
373 irq = probe_irq_off(cookie);
374 if (!hwif->irq) {
375 if (irq > 0) {
376 hwif->irq = irq;
377 } else {
378 /* Mmmm.. multiple IRQs..
379 * don't know which was ours
380 */
381 printk(KERN_ERR "%s: IRQ probe failed (0x%lx)\n",
382 drive->name, cookie);
383 }
384 }
385 }
386 return retval;
387}
388
389int ide_busy_sleep(ide_hwif_t *hwif, unsigned long timeout, int altstatus) 327int ide_busy_sleep(ide_hwif_t *hwif, unsigned long timeout, int altstatus)
390{ 328{
391 u8 stat; 329 u8 stat;
@@ -440,6 +378,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
440{ 378{
441 ide_hwif_t *hwif = drive->hwif; 379 ide_hwif_t *hwif = drive->hwif;
442 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 380 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
381 u16 *id = drive->id;
443 int rc; 382 int rc;
444 u8 present = !!(drive->dev_flags & IDE_DFLAG_PRESENT), stat; 383 u8 present = !!(drive->dev_flags & IDE_DFLAG_PRESENT), stat;
445 384
@@ -475,11 +414,10 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
475 414
476 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY) || 415 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY) ||
477 present || cmd == ATA_CMD_ID_ATAPI) { 416 present || cmd == ATA_CMD_ID_ATAPI) {
478 /* send cmd and wait */ 417 rc = ide_dev_read_id(drive, cmd, id);
479 if ((rc = try_to_identify(drive, cmd))) { 418 if (rc)
480 /* failed: try again */ 419 /* failed: try again */
481 rc = try_to_identify(drive,cmd); 420 rc = ide_dev_read_id(drive, cmd, id);
482 }
483 421
484 stat = tp_ops->read_status(hwif); 422 stat = tp_ops->read_status(hwif);
485 423
@@ -494,7 +432,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
494 msleep(50); 432 msleep(50);
495 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET); 433 tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
496 (void)ide_busy_sleep(hwif, WAIT_WORSTCASE, 0); 434 (void)ide_busy_sleep(hwif, WAIT_WORSTCASE, 0);
497 rc = try_to_identify(drive, cmd); 435 rc = ide_dev_read_id(drive, cmd, id);
498 } 436 }
499 437
500 /* ensure drive IRQ is clear */ 438 /* ensure drive IRQ is clear */
@@ -517,37 +455,6 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
517 return rc; 455 return rc;
518} 456}
519 457
520/*
521 *
522 */
523static void enable_nest (ide_drive_t *drive)
524{
525 ide_hwif_t *hwif = drive->hwif;
526 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
527 u8 stat;
528
529 printk(KERN_INFO "%s: enabling %s -- ",
530 hwif->name, (char *)&drive->id[ATA_ID_PROD]);
531
532 SELECT_DRIVE(drive);
533 msleep(50);
534 tp_ops->exec_command(hwif, ATA_EXABYTE_ENABLE_NEST);
535
536 if (ide_busy_sleep(hwif, WAIT_WORSTCASE, 0)) {
537 printk(KERN_CONT "failed (timeout)\n");
538 return;
539 }
540
541 msleep(50);
542
543 stat = tp_ops->read_status(hwif);
544
545 if (!OK_STAT(stat, 0, BAD_STAT))
546 printk(KERN_CONT "failed (status = 0x%02x)\n", stat);
547 else
548 printk(KERN_CONT "success\n");
549}
550
551/** 458/**
552 * probe_for_drives - upper level drive probe 459 * probe_for_drives - upper level drive probe
553 * @drive: drive to probe for 460 * @drive: drive to probe for
@@ -563,6 +470,8 @@ static void enable_nest (ide_drive_t *drive)
563static u8 probe_for_drive(ide_drive_t *drive) 470static u8 probe_for_drive(ide_drive_t *drive)
564{ 471{
565 char *m; 472 char *m;
473 int rc;
474 u8 cmd;
566 475
567 /* 476 /*
568 * In order to keep things simple we have an id 477 * In order to keep things simple we have an id
@@ -586,21 +495,19 @@ static u8 probe_for_drive(ide_drive_t *drive)
586 495
587 /* skip probing? */ 496 /* skip probing? */
588 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0) { 497 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0) {
589retry:
590 /* if !(success||timed-out) */ 498 /* if !(success||timed-out) */
591 if (do_probe(drive, ATA_CMD_ID_ATA) >= 2) 499 cmd = ATA_CMD_ID_ATA;
500 rc = do_probe(drive, cmd);
501 if (rc >= 2) {
592 /* look for ATAPI device */ 502 /* look for ATAPI device */
593 (void)do_probe(drive, ATA_CMD_ID_ATAPI); 503 cmd = ATA_CMD_ID_ATAPI;
504 rc = do_probe(drive, cmd);
505 }
594 506
595 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) 507 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
596 /* drive not found */ 508 /* drive not found */
597 return 0; 509 return 0;
598 510
599 if (strstr(m, "E X A B Y T E N E S T")) {
600 enable_nest(drive);
601 goto retry;
602 }
603
604 /* identification failed? */ 511 /* identification failed? */
605 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) { 512 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
606 if (drive->media == ide_disk) { 513 if (drive->media == ide_disk) {
@@ -614,8 +521,12 @@ retry:
614 printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name); 521 printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name);
615 drive->dev_flags &= ~IDE_DFLAG_PRESENT; 522 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
616 } 523 }
524 } else {
525 if (cmd == ATA_CMD_ID_ATAPI)
526 ide_classify_atapi_dev(drive);
527 else
528 ide_classify_ata_dev(drive);
617 } 529 }
618 /* drive was found */
619 } 530 }
620 531
621 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) 532 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
@@ -779,7 +690,6 @@ EXPORT_SYMBOL_GPL(ide_undecoded_slave);
779static int ide_probe_port(ide_hwif_t *hwif) 690static int ide_probe_port(ide_hwif_t *hwif)
780{ 691{
781 ide_drive_t *drive; 692 ide_drive_t *drive;
782 unsigned long flags;
783 unsigned int irqd; 693 unsigned int irqd;
784 int i, rc = -ENODEV; 694 int i, rc = -ENODEV;
785 695
@@ -797,9 +707,6 @@ static int ide_probe_port(ide_hwif_t *hwif)
797 if (irqd) 707 if (irqd)
798 disable_irq(hwif->irq); 708 disable_irq(hwif->irq);
799 709
800 local_save_flags(flags);
801 local_irq_enable_in_hardirq();
802
803 if (ide_port_wait_ready(hwif) == -EBUSY) 710 if (ide_port_wait_ready(hwif) == -EBUSY)
804 printk(KERN_DEBUG "%s: Wait for ready failed before probe !\n", hwif->name); 711 printk(KERN_DEBUG "%s: Wait for ready failed before probe !\n", hwif->name);
805 712
@@ -813,8 +720,6 @@ static int ide_probe_port(ide_hwif_t *hwif)
813 rc = 0; 720 rc = 0;
814 } 721 }
815 722
816 local_irq_restore(flags);
817
818 /* 723 /*
819 * Use cached IRQ number. It might be (and is...) changed by probe 724 * Use cached IRQ number. It might be (and is...) changed by probe
820 * code above 725 * code above
@@ -831,29 +736,18 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
831 ide_drive_t *drive; 736 ide_drive_t *drive;
832 int i; 737 int i;
833 738
834 ide_port_for_each_dev(i, drive, hwif) { 739 ide_port_for_each_present_dev(i, drive, hwif) {
835 if (drive->dev_flags & IDE_DFLAG_PRESENT) { 740 if (port_ops && port_ops->quirkproc)
836 if (port_ops && port_ops->quirkproc) 741 port_ops->quirkproc(drive);
837 port_ops->quirkproc(drive);
838 }
839 } 742 }
840 743
841 ide_port_for_each_dev(i, drive, hwif) { 744 ide_port_for_each_present_dev(i, drive, hwif) {
842 if (drive->dev_flags & IDE_DFLAG_PRESENT) { 745 ide_set_max_pio(drive);
843 ide_set_max_pio(drive);
844 746
845 drive->dev_flags |= IDE_DFLAG_NICE1; 747 drive->dev_flags |= IDE_DFLAG_NICE1;
846
847 if (hwif->dma_ops)
848 ide_set_dma(drive);
849 }
850 }
851 748
852 ide_port_for_each_dev(i, drive, hwif) { 749 if (hwif->dma_ops)
853 if (hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) 750 ide_set_dma(drive);
854 drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT;
855 else
856 drive->dev_flags &= ~IDE_DFLAG_NO_IO_32BIT;
857 } 751 }
858} 752}
859 753
@@ -924,10 +818,7 @@ static int ide_port_setup_devices(ide_hwif_t *hwif)
924 int i, j = 0; 818 int i, j = 0;
925 819
926 mutex_lock(&ide_cfg_mtx); 820 mutex_lock(&ide_cfg_mtx);
927 ide_port_for_each_dev(i, drive, hwif) { 821 ide_port_for_each_present_dev(i, drive, hwif) {
928 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
929 continue;
930
931 if (ide_init_queue(drive)) { 822 if (ide_init_queue(drive)) {
932 printk(KERN_ERR "ide: failed to init %s\n", 823 printk(KERN_ERR "ide: failed to init %s\n",
933 drive->name); 824 drive->name);
@@ -953,13 +844,6 @@ static int init_irq (ide_hwif_t *hwif)
953 irq_handler_t irq_handler; 844 irq_handler_t irq_handler;
954 int sa = 0; 845 int sa = 0;
955 846
956 mutex_lock(&ide_cfg_mtx);
957 spin_lock_init(&hwif->lock);
958
959 init_timer(&hwif->timer);
960 hwif->timer.function = &ide_timer_expiry;
961 hwif->timer.data = (unsigned long)hwif;
962
963 irq_handler = hwif->host->irq_handler; 847 irq_handler = hwif->host->irq_handler;
964 if (irq_handler == NULL) 848 if (irq_handler == NULL)
965 irq_handler = ide_intr; 849 irq_handler = ide_intr;
@@ -997,10 +881,8 @@ static int init_irq (ide_hwif_t *hwif)
997 printk(KERN_CONT " (serialized)"); 881 printk(KERN_CONT " (serialized)");
998 printk(KERN_CONT "\n"); 882 printk(KERN_CONT "\n");
999 883
1000 mutex_unlock(&ide_cfg_mtx);
1001 return 0; 884 return 0;
1002out_up: 885out_up:
1003 mutex_unlock(&ide_cfg_mtx);
1004 return 1; 886 return 1;
1005} 887}
1006 888
@@ -1099,14 +981,9 @@ static void drive_release_dev (struct device *dev)
1099 981
1100static int hwif_init(ide_hwif_t *hwif) 982static int hwif_init(ide_hwif_t *hwif)
1101{ 983{
1102 int old_irq;
1103
1104 if (!hwif->irq) { 984 if (!hwif->irq) {
1105 hwif->irq = __ide_default_irq(hwif->io_ports.data_addr); 985 printk(KERN_ERR "%s: disabled, no IRQ\n", hwif->name);
1106 if (!hwif->irq) { 986 return 0;
1107 printk(KERN_ERR "%s: disabled, no IRQ\n", hwif->name);
1108 return 0;
1109 }
1110 } 987 }
1111 988
1112 if (register_blkdev(hwif->major, hwif->name)) 989 if (register_blkdev(hwif->major, hwif->name))
@@ -1124,29 +1001,12 @@ static int hwif_init(ide_hwif_t *hwif)
1124 1001
1125 sg_init_table(hwif->sg_table, hwif->sg_max_nents); 1002 sg_init_table(hwif->sg_table, hwif->sg_max_nents);
1126 1003
1127 if (init_irq(hwif) == 0)
1128 goto done;
1129
1130 old_irq = hwif->irq;
1131 /*
1132 * It failed to initialise. Find the default IRQ for
1133 * this port and try that.
1134 */
1135 hwif->irq = __ide_default_irq(hwif->io_ports.data_addr);
1136 if (!hwif->irq) {
1137 printk(KERN_ERR "%s: disabled, unable to get IRQ %d\n",
1138 hwif->name, old_irq);
1139 goto out;
1140 }
1141 if (init_irq(hwif)) { 1004 if (init_irq(hwif)) {
1142 printk(KERN_ERR "%s: probed IRQ %d and default IRQ %d failed\n", 1005 printk(KERN_ERR "%s: disabled, unable to get IRQ %d\n",
1143 hwif->name, old_irq, hwif->irq); 1006 hwif->name, hwif->irq);
1144 goto out; 1007 goto out;
1145 } 1008 }
1146 printk(KERN_WARNING "%s: probed IRQ %d failed, using default\n",
1147 hwif->name, hwif->irq);
1148 1009
1149done:
1150 blk_register_region(MKDEV(hwif->major, 0), MAX_DRIVES << PARTN_BITS, 1010 blk_register_region(MKDEV(hwif->major, 0), MAX_DRIVES << PARTN_BITS,
1151 THIS_MODULE, ata_probe, ata_lock, hwif); 1011 THIS_MODULE, ata_probe, ata_lock, hwif);
1152 return 1; 1012 return 1;
@@ -1161,13 +1021,10 @@ static void hwif_register_devices(ide_hwif_t *hwif)
1161 ide_drive_t *drive; 1021 ide_drive_t *drive;
1162 unsigned int i; 1022 unsigned int i;
1163 1023
1164 ide_port_for_each_dev(i, drive, hwif) { 1024 ide_port_for_each_present_dev(i, drive, hwif) {
1165 struct device *dev = &drive->gendev; 1025 struct device *dev = &drive->gendev;
1166 int ret; 1026 int ret;
1167 1027
1168 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
1169 continue;
1170
1171 dev_set_name(dev, "%u.%u", hwif->index, i); 1028 dev_set_name(dev, "%u.%u", hwif->index, i);
1172 dev->parent = &hwif->gendev; 1029 dev->parent = &hwif->gendev;
1173 dev->bus = &ide_bus_type; 1030 dev->bus = &ide_bus_type;
@@ -1192,6 +1049,8 @@ static void ide_port_init_devices(ide_hwif_t *hwif)
1192 1049
1193 if (hwif->host_flags & IDE_HFLAG_IO_32BIT) 1050 if (hwif->host_flags & IDE_HFLAG_IO_32BIT)
1194 drive->io_32bit = 1; 1051 drive->io_32bit = 1;
1052 if (hwif->host_flags & IDE_HFLAG_NO_IO_32BIT)
1053 drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT;
1195 if (hwif->host_flags & IDE_HFLAG_UNMASK_IRQS) 1054 if (hwif->host_flags & IDE_HFLAG_UNMASK_IRQS)
1196 drive->dev_flags |= IDE_DFLAG_UNMASK; 1055 drive->dev_flags |= IDE_DFLAG_UNMASK;
1197 if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS) 1056 if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS)
@@ -1213,10 +1072,6 @@ static void ide_init_port(ide_hwif_t *hwif, unsigned int port,
1213 if (d->init_iops) 1072 if (d->init_iops)
1214 d->init_iops(hwif); 1073 d->init_iops(hwif);
1215 1074
1216 if ((!hwif->irq && (d->host_flags & IDE_HFLAG_LEGACY_IRQS)) ||
1217 (d->host_flags & IDE_HFLAG_FORCE_LEGACY_IRQS))
1218 hwif->irq = port ? 15 : 14;
1219
1220 /* ->host_flags may be set by ->init_iops (or even earlier...) */ 1075 /* ->host_flags may be set by ->init_iops (or even earlier...) */
1221 hwif->host_flags |= d->host_flags; 1076 hwif->host_flags |= d->host_flags;
1222 hwif->pio_mask = d->pio_mask; 1077 hwif->pio_mask = d->pio_mask;
@@ -1317,6 +1172,12 @@ static void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
1317 hwif->name[2] = 'e'; 1172 hwif->name[2] = 'e';
1318 hwif->name[3] = '0' + index; 1173 hwif->name[3] = '0' + index;
1319 1174
1175 spin_lock_init(&hwif->lock);
1176
1177 init_timer(&hwif->timer);
1178 hwif->timer.function = &ide_timer_expiry;
1179 hwif->timer.data = (unsigned long)hwif;
1180
1320 init_completion(&hwif->gendev_rel_comp); 1181 init_completion(&hwif->gendev_rel_comp);
1321 1182
1322 hwif->tp_ops = &default_tp_ops; 1183 hwif->tp_ops = &default_tp_ops;
@@ -1567,7 +1428,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1567 1428
1568 j++; 1429 j++;
1569 1430
1570 ide_acpi_init(hwif); 1431 ide_acpi_init_port(hwif);
1571 1432
1572 if (hwif->present) 1433 if (hwif->present)
1573 ide_acpi_port_init_devices(hwif); 1434 ide_acpi_port_init_devices(hwif);
@@ -1624,11 +1485,9 @@ static void __ide_port_unregister_devices(ide_hwif_t *hwif)
1624 ide_drive_t *drive; 1485 ide_drive_t *drive;
1625 int i; 1486 int i;
1626 1487
1627 ide_port_for_each_dev(i, drive, hwif) { 1488 ide_port_for_each_present_dev(i, drive, hwif) {
1628 if (drive->dev_flags & IDE_DFLAG_PRESENT) { 1489 device_unregister(&drive->gendev);
1629 device_unregister(&drive->gendev); 1490 wait_for_completion(&drive->gendev_rel_comp);
1630 wait_for_completion(&drive->gendev_rel_comp);
1631 }
1632 } 1491 }
1633} 1492}
1634 1493
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index a7b9287ee0d4..417cde56eafd 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -600,7 +600,7 @@ void ide_proc_port_register_devices(ide_hwif_t *hwif)
600 int i; 600 int i;
601 601
602 ide_port_for_each_dev(i, drive, hwif) { 602 ide_port_for_each_dev(i, drive, hwif) {
603 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0 || drive->proc) 603 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
604 continue; 604 continue;
605 605
606 drive->proc = proc_mkdir(drive->name, parent); 606 drive->proc = proc_mkdir(drive->name, parent);
diff --git a/drivers/ide/ide-xfer-mode.c b/drivers/ide/ide-xfer-mode.c
new file mode 100644
index 000000000000..6910f6a257e8
--- /dev/null
+++ b/drivers/ide/ide-xfer-mode.c
@@ -0,0 +1,246 @@
1#include <linux/types.h>
2#include <linux/string.h>
3#include <linux/kernel.h>
4#include <linux/interrupt.h>
5#include <linux/ide.h>
6#include <linux/bitops.h>
7
8static const char *udma_str[] =
9 { "UDMA/16", "UDMA/25", "UDMA/33", "UDMA/44",
10 "UDMA/66", "UDMA/100", "UDMA/133", "UDMA7" };
11static const char *mwdma_str[] =
12 { "MWDMA0", "MWDMA1", "MWDMA2" };
13static const char *swdma_str[] =
14 { "SWDMA0", "SWDMA1", "SWDMA2" };
15static const char *pio_str[] =
16 { "PIO0", "PIO1", "PIO2", "PIO3", "PIO4", "PIO5" };
17
18/**
19 * ide_xfer_verbose - return IDE mode names
20 * @mode: transfer mode
21 *
22 * Returns a constant string giving the name of the mode
23 * requested.
24 */
25
26const char *ide_xfer_verbose(u8 mode)
27{
28 const char *s;
29 u8 i = mode & 0xf;
30
31 if (mode >= XFER_UDMA_0 && mode <= XFER_UDMA_7)
32 s = udma_str[i];
33 else if (mode >= XFER_MW_DMA_0 && mode <= XFER_MW_DMA_2)
34 s = mwdma_str[i];
35 else if (mode >= XFER_SW_DMA_0 && mode <= XFER_SW_DMA_2)
36 s = swdma_str[i];
37 else if (mode >= XFER_PIO_0 && mode <= XFER_PIO_5)
38 s = pio_str[i & 0x7];
39 else if (mode == XFER_PIO_SLOW)
40 s = "PIO SLOW";
41 else
42 s = "XFER ERROR";
43
44 return s;
45}
46EXPORT_SYMBOL(ide_xfer_verbose);
47
48/**
49 * ide_get_best_pio_mode - get PIO mode from drive
50 * @drive: drive to consider
51 * @mode_wanted: preferred mode
52 * @max_mode: highest allowed mode
53 *
54 * This routine returns the recommended PIO settings for a given drive,
55 * based on the drive->id information and the ide_pio_blacklist[].
56 *
57 * Drive PIO mode is auto-selected if 255 is passed as mode_wanted.
58 * This is used by most chipset support modules when "auto-tuning".
59 */
60
61u8 ide_get_best_pio_mode(ide_drive_t *drive, u8 mode_wanted, u8 max_mode)
62{
63 u16 *id = drive->id;
64 int pio_mode = -1, overridden = 0;
65
66 if (mode_wanted != 255)
67 return min_t(u8, mode_wanted, max_mode);
68
69 if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_BLACKLIST) == 0)
70 pio_mode = ide_scan_pio_blacklist((char *)&id[ATA_ID_PROD]);
71
72 if (pio_mode != -1) {
73 printk(KERN_INFO "%s: is on PIO blacklist\n", drive->name);
74 } else {
75 pio_mode = id[ATA_ID_OLD_PIO_MODES] >> 8;
76 if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */
77 pio_mode = 2;
78 overridden = 1;
79 }
80
81 if (id[ATA_ID_FIELD_VALID] & 2) { /* ATA2? */
82 if (ata_id_has_iordy(id)) {
83 if (id[ATA_ID_PIO_MODES] & 7) {
84 overridden = 0;
85 if (id[ATA_ID_PIO_MODES] & 4)
86 pio_mode = 5;
87 else if (id[ATA_ID_PIO_MODES] & 2)
88 pio_mode = 4;
89 else
90 pio_mode = 3;
91 }
92 }
93 }
94
95 if (overridden)
96 printk(KERN_INFO "%s: tPIO > 2, assuming tPIO = 2\n",
97 drive->name);
98 }
99
100 if (pio_mode > max_mode)
101 pio_mode = max_mode;
102
103 return pio_mode;
104}
105EXPORT_SYMBOL_GPL(ide_get_best_pio_mode);
106
107int ide_set_pio_mode(ide_drive_t *drive, const u8 mode)
108{
109 ide_hwif_t *hwif = drive->hwif;
110 const struct ide_port_ops *port_ops = hwif->port_ops;
111
112 if (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)
113 return 0;
114
115 if (port_ops == NULL || port_ops->set_pio_mode == NULL)
116 return -1;
117
118 /*
119 * TODO: temporary hack for some legacy host drivers that didn't
120 * set transfer mode on the device in ->set_pio_mode method...
121 */
122 if (port_ops->set_dma_mode == NULL) {
123 port_ops->set_pio_mode(drive, mode - XFER_PIO_0);
124 return 0;
125 }
126
127 if (hwif->host_flags & IDE_HFLAG_POST_SET_MODE) {
128 if (ide_config_drive_speed(drive, mode))
129 return -1;
130 port_ops->set_pio_mode(drive, mode - XFER_PIO_0);
131 return 0;
132 } else {
133 port_ops->set_pio_mode(drive, mode - XFER_PIO_0);
134 return ide_config_drive_speed(drive, mode);
135 }
136}
137
138int ide_set_dma_mode(ide_drive_t *drive, const u8 mode)
139{
140 ide_hwif_t *hwif = drive->hwif;
141 const struct ide_port_ops *port_ops = hwif->port_ops;
142
143 if (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)
144 return 0;
145
146 if (port_ops == NULL || port_ops->set_dma_mode == NULL)
147 return -1;
148
149 if (hwif->host_flags & IDE_HFLAG_POST_SET_MODE) {
150 if (ide_config_drive_speed(drive, mode))
151 return -1;
152 port_ops->set_dma_mode(drive, mode);
153 return 0;
154 } else {
155 port_ops->set_dma_mode(drive, mode);
156 return ide_config_drive_speed(drive, mode);
157 }
158}
159EXPORT_SYMBOL_GPL(ide_set_dma_mode);
160
161/* req_pio == "255" for auto-tune */
162void ide_set_pio(ide_drive_t *drive, u8 req_pio)
163{
164 ide_hwif_t *hwif = drive->hwif;
165 const struct ide_port_ops *port_ops = hwif->port_ops;
166 u8 host_pio, pio;
167
168 if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
169 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
170 return;
171
172 BUG_ON(hwif->pio_mask == 0x00);
173
174 host_pio = fls(hwif->pio_mask) - 1;
175
176 pio = ide_get_best_pio_mode(drive, req_pio, host_pio);
177
178 /*
179 * TODO:
180 * - report device max PIO mode
181 * - check req_pio != 255 against device max PIO mode
182 */
183 printk(KERN_DEBUG "%s: host max PIO%d wanted PIO%d%s selected PIO%d\n",
184 drive->name, host_pio, req_pio,
185 req_pio == 255 ? "(auto-tune)" : "", pio);
186
187 (void)ide_set_pio_mode(drive, XFER_PIO_0 + pio);
188}
189EXPORT_SYMBOL_GPL(ide_set_pio);
190
191/**
192 * ide_rate_filter - filter transfer mode
193 * @drive: IDE device
194 * @speed: desired speed
195 *
196 * Given the available transfer modes this function returns
197 * the best available speed at or below the speed requested.
198 *
199 * TODO: check device PIO capabilities
200 */
201
202static u8 ide_rate_filter(ide_drive_t *drive, u8 speed)
203{
204 ide_hwif_t *hwif = drive->hwif;
205 u8 mode = ide_find_dma_mode(drive, speed);
206
207 if (mode == 0) {
208 if (hwif->pio_mask)
209 mode = fls(hwif->pio_mask) - 1 + XFER_PIO_0;
210 else
211 mode = XFER_PIO_4;
212 }
213
214/* printk("%s: mode 0x%02x, speed 0x%02x\n", __func__, mode, speed); */
215
216 return min(speed, mode);
217}
218
219/**
220 * ide_set_xfer_rate - set transfer rate
221 * @drive: drive to set
222 * @rate: speed to attempt to set
223 *
224 * General helper for setting the speed of an IDE device. This
225 * function knows about user enforced limits from the configuration
226 * which ->set_pio_mode/->set_dma_mode does not.
227 */
228
229int ide_set_xfer_rate(ide_drive_t *drive, u8 rate)
230{
231 ide_hwif_t *hwif = drive->hwif;
232 const struct ide_port_ops *port_ops = hwif->port_ops;
233
234 if (port_ops == NULL || port_ops->set_dma_mode == NULL ||
235 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
236 return -1;
237
238 rate = ide_rate_filter(drive, rate);
239
240 BUG_ON(rate < XFER_PIO_0);
241
242 if (rate >= XFER_PIO_0 && rate <= XFER_PIO_5)
243 return ide_set_pio_mode(drive, rate);
244
245 return ide_set_dma_mode(drive, rate);
246}
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 0920e3b0c962..92c9b90931e7 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -62,160 +62,6 @@
62 62
63struct class *ide_port_class; 63struct class *ide_port_class;
64 64
65/*
66 * Locks for IDE setting functionality
67 */
68
69DEFINE_MUTEX(ide_setting_mtx);
70
71ide_devset_get(io_32bit, io_32bit);
72
73static int set_io_32bit(ide_drive_t *drive, int arg)
74{
75 if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT)
76 return -EPERM;
77
78 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
79 return -EINVAL;
80
81 drive->io_32bit = arg;
82
83 return 0;
84}
85
86ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS);
87
88static int set_ksettings(ide_drive_t *drive, int arg)
89{
90 if (arg < 0 || arg > 1)
91 return -EINVAL;
92
93 if (arg)
94 drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS;
95 else
96 drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS;
97
98 return 0;
99}
100
101ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA);
102
103static int set_using_dma(ide_drive_t *drive, int arg)
104{
105#ifdef CONFIG_BLK_DEV_IDEDMA
106 int err = -EPERM;
107
108 if (arg < 0 || arg > 1)
109 return -EINVAL;
110
111 if (ata_id_has_dma(drive->id) == 0)
112 goto out;
113
114 if (drive->hwif->dma_ops == NULL)
115 goto out;
116
117 err = 0;
118
119 if (arg) {
120 if (ide_set_dma(drive))
121 err = -EIO;
122 } else
123 ide_dma_off(drive);
124
125out:
126 return err;
127#else
128 if (arg < 0 || arg > 1)
129 return -EINVAL;
130
131 return -EPERM;
132#endif
133}
134
135/*
136 * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
137 */
138static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
139{
140 switch (req_pio) {
141 case 202:
142 case 201:
143 case 200:
144 case 102:
145 case 101:
146 case 100:
147 return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
148 case 9:
149 case 8:
150 return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
151 case 7:
152 case 6:
153 return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
154 default:
155 return 0;
156 }
157}
158
159static int set_pio_mode(ide_drive_t *drive, int arg)
160{
161 ide_hwif_t *hwif = drive->hwif;
162 const struct ide_port_ops *port_ops = hwif->port_ops;
163
164 if (arg < 0 || arg > 255)
165 return -EINVAL;
166
167 if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
168 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
169 return -ENOSYS;
170
171 if (set_pio_mode_abuse(drive->hwif, arg)) {
172 if (arg == 8 || arg == 9) {
173 unsigned long flags;
174
175 /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
176 spin_lock_irqsave(&hwif->lock, flags);
177 port_ops->set_pio_mode(drive, arg);
178 spin_unlock_irqrestore(&hwif->lock, flags);
179 } else
180 port_ops->set_pio_mode(drive, arg);
181 } else {
182 int keep_dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
183
184 ide_set_pio(drive, arg);
185
186 if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
187 if (keep_dma)
188 ide_dma_on(drive);
189 }
190 }
191
192 return 0;
193}
194
195ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK);
196
197static int set_unmaskirq(ide_drive_t *drive, int arg)
198{
199 if (drive->dev_flags & IDE_DFLAG_NO_UNMASK)
200 return -EPERM;
201
202 if (arg < 0 || arg > 1)
203 return -EINVAL;
204
205 if (arg)
206 drive->dev_flags |= IDE_DFLAG_UNMASK;
207 else
208 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
209
210 return 0;
211}
212
213ide_ext_devset_rw_sync(io_32bit, io_32bit);
214ide_ext_devset_rw_sync(keepsettings, ksettings);
215ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
216ide_ext_devset_rw_sync(using_dma, using_dma);
217__IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
218
219/** 65/**
220 * ide_device_get - get an additional reference to a ide_drive_t 66 * ide_device_get - get an additional reference to a ide_drive_t
221 * @drive: device to get a reference to 67 * @drive: device to get a reference to
@@ -527,6 +373,8 @@ static int __init ide_init(void)
527 goto out_port_class; 373 goto out_port_class;
528 } 374 }
529 375
376 ide_acpi_init();
377
530 proc_ide_create(); 378 proc_ide_create();
531 379
532 return 0; 380 return 0;
diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
index 13b8153112ed..6b9fc950b4af 100644
--- a/drivers/ide/it821x.c
+++ b/drivers/ide/it821x.c
@@ -603,7 +603,7 @@ static void it8212_disable_raid(struct pci_dev *dev)
603 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20); 603 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x20);
604} 604}
605 605
606static unsigned int init_chipset_it821x(struct pci_dev *dev) 606static int init_chipset_it821x(struct pci_dev *dev)
607{ 607{
608 u8 conf; 608 u8 conf;
609 static char *mode[2] = { "pass through", "smart" }; 609 static char *mode[2] = { "pass through", "smart" };
diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
index 83643ed9a426..ea48a3ee8063 100644
--- a/drivers/ide/ns87415.c
+++ b/drivers/ide/ns87415.c
@@ -286,9 +286,7 @@ static void __devinit init_hwif_ns87415 (ide_hwif_t *hwif)
286 } 286 }
287 287
288 if (!using_inta) 288 if (!using_inta)
289 hwif->irq = __ide_default_irq(hwif->io_ports.data_addr); 289 hwif->irq = pci_get_legacy_ide_irq(dev, hwif->channel);
290 else if (!hwif->irq && hwif->mate && hwif->mate->irq)
291 hwif->irq = hwif->mate->irq; /* share IRQ with mate */
292 290
293 if (!hwif->dma_base) 291 if (!hwif->dma_base)
294 return; 292 return;
diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
index f21290c4b447..b68906c3c17e 100644
--- a/drivers/ide/pdc202xx_new.c
+++ b/drivers/ide/pdc202xx_new.c
@@ -325,7 +325,7 @@ static void apple_kiwi_init(struct pci_dev *pdev)
325} 325}
326#endif /* CONFIG_PPC_PMAC */ 326#endif /* CONFIG_PPC_PMAC */
327 327
328static unsigned int init_chipset_pdcnew(struct pci_dev *dev) 328static int init_chipset_pdcnew(struct pci_dev *dev)
329{ 329{
330 const char *name = DRV_NAME; 330 const char *name = DRV_NAME;
331 unsigned long dma_base = pci_resource_start(dev, 4); 331 unsigned long dma_base = pci_resource_start(dev, 4);
@@ -444,7 +444,7 @@ static unsigned int init_chipset_pdcnew(struct pci_dev *dev)
444#endif 444#endif
445 445
446 out: 446 out:
447 return dev->irq; 447 return 0;
448} 448}
449 449
450static struct pci_dev * __devinit pdc20270_get_dev2(struct pci_dev *dev) 450static struct pci_dev * __devinit pdc20270_get_dev2(struct pci_dev *dev)
diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
index 97193323aebf..cba66ebce4e3 100644
--- a/drivers/ide/pdc202xx_old.c
+++ b/drivers/ide/pdc202xx_old.c
@@ -264,7 +264,7 @@ static void pdc202xx_dma_timeout(ide_drive_t *drive)
264 ide_dma_timeout(drive); 264 ide_dma_timeout(drive);
265} 265}
266 266
267static unsigned int init_chipset_pdc202xx(struct pci_dev *dev) 267static int init_chipset_pdc202xx(struct pci_dev *dev)
268{ 268{
269 unsigned long dmabase = pci_resource_start(dev, 4); 269 unsigned long dmabase = pci_resource_start(dev, 4);
270 u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0; 270 u8 udma_speed_flag = 0, primary_mode = 0, secondary_mode = 0;
@@ -290,7 +290,7 @@ static unsigned int init_chipset_pdc202xx(struct pci_dev *dev)
290 printk("%sACTIVE\n", (inb(dmabase | 0x1f) & 1) ? "" : "IN"); 290 printk("%sACTIVE\n", (inb(dmabase | 0x1f) & 1) ? "" : "IN");
291 } 291 }
292out: 292out:
293 return dev->irq; 293 return 0;
294} 294}
295 295
296static void __devinit pdc202ata4_fixup_irq(struct pci_dev *dev, 296static void __devinit pdc202ata4_fixup_irq(struct pci_dev *dev,
diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
index f1e2e4ef0d71..2aa699933064 100644
--- a/drivers/ide/piix.c
+++ b/drivers/ide/piix.c
@@ -204,7 +204,7 @@ static void piix_set_dma_mode(ide_drive_t *drive, const u8 speed)
204 * out to be nice and simple. 204 * out to be nice and simple.
205 */ 205 */
206 206
207static unsigned int init_chipset_ich(struct pci_dev *dev) 207static int init_chipset_ich(struct pci_dev *dev)
208{ 208{
209 u32 extra = 0; 209 u32 extra = 0;
210 210
@@ -318,19 +318,12 @@ static const struct ide_port_ops ich_port_ops = {
318 .cable_detect = piix_cable_detect, 318 .cable_detect = piix_cable_detect,
319}; 319};
320 320
321#ifndef CONFIG_IA64
322 #define IDE_HFLAGS_PIIX IDE_HFLAG_LEGACY_IRQS
323#else
324 #define IDE_HFLAGS_PIIX 0
325#endif
326
327#define DECLARE_PIIX_DEV(udma) \ 321#define DECLARE_PIIX_DEV(udma) \
328 { \ 322 { \
329 .name = DRV_NAME, \ 323 .name = DRV_NAME, \
330 .init_hwif = init_hwif_piix, \ 324 .init_hwif = init_hwif_piix, \
331 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ 325 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \
332 .port_ops = &piix_port_ops, \ 326 .port_ops = &piix_port_ops, \
333 .host_flags = IDE_HFLAGS_PIIX, \
334 .pio_mask = ATA_PIO4, \ 327 .pio_mask = ATA_PIO4, \
335 .swdma_mask = ATA_SWDMA2_ONLY, \ 328 .swdma_mask = ATA_SWDMA2_ONLY, \
336 .mwdma_mask = ATA_MWDMA12_ONLY, \ 329 .mwdma_mask = ATA_MWDMA12_ONLY, \
@@ -344,7 +337,6 @@ static const struct ide_port_ops ich_port_ops = {
344 .init_hwif = init_hwif_piix, \ 337 .init_hwif = init_hwif_piix, \
345 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ 338 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \
346 .port_ops = &ich_port_ops, \ 339 .port_ops = &ich_port_ops, \
347 .host_flags = IDE_HFLAGS_PIIX, \
348 .pio_mask = ATA_PIO4, \ 340 .pio_mask = ATA_PIO4, \
349 .swdma_mask = ATA_SWDMA2_ONLY, \ 341 .swdma_mask = ATA_SWDMA2_ONLY, \
350 .mwdma_mask = ATA_MWDMA12_ONLY, \ 342 .mwdma_mask = ATA_MWDMA12_ONLY, \
@@ -360,8 +352,7 @@ static const struct ide_port_info piix_pci_info[] __devinitdata = {
360 */ 352 */
361 .name = DRV_NAME, 353 .name = DRV_NAME,
362 .enablebits = {{0x6d,0xc0,0x80}, {0x6d,0xc0,0xc0}}, 354 .enablebits = {{0x6d,0xc0,0x80}, {0x6d,0xc0,0xc0}},
363 .host_flags = IDE_HFLAG_ISA_PORTS | IDE_HFLAG_NO_DMA | 355 .host_flags = IDE_HFLAG_ISA_PORTS | IDE_HFLAG_NO_DMA,
364 IDE_HFLAGS_PIIX,
365 .pio_mask = ATA_PIO4, 356 .pio_mask = ATA_PIO4,
366 /* This is a painful system best to let it self tune for now */ 357 /* This is a painful system best to let it self tune for now */
367 }, 358 },
diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
index 382102ba467b..b6554ef92716 100644
--- a/drivers/ide/serverworks.c
+++ b/drivers/ide/serverworks.c
@@ -175,7 +175,7 @@ static void svwks_set_dma_mode(ide_drive_t *drive, const u8 speed)
175 pci_write_config_byte(dev, 0x54, ultra_enable); 175 pci_write_config_byte(dev, 0x54, ultra_enable);
176} 176}
177 177
178static unsigned int init_chipset_svwks(struct pci_dev *dev) 178static int init_chipset_svwks(struct pci_dev *dev)
179{ 179{
180 unsigned int reg; 180 unsigned int reg;
181 u8 btr; 181 u8 btr;
@@ -270,7 +270,7 @@ static unsigned int init_chipset_svwks(struct pci_dev *dev)
270 pci_write_config_byte(dev, 0x5A, btr); 270 pci_write_config_byte(dev, 0x5A, btr);
271 } 271 }
272 272
273 return dev->irq; 273 return 0;
274} 274}
275 275
276static u8 ata66_svwks_svwks(ide_hwif_t *hwif) 276static u8 ata66_svwks_svwks(ide_hwif_t *hwif)
@@ -353,14 +353,11 @@ static const struct ide_port_ops svwks_port_ops = {
353 .cable_detect = svwks_cable_detect, 353 .cable_detect = svwks_cable_detect,
354}; 354};
355 355
356#define IDE_HFLAGS_SVWKS IDE_HFLAG_LEGACY_IRQS
357
358static const struct ide_port_info serverworks_chipsets[] __devinitdata = { 356static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
359 { /* 0: OSB4 */ 357 { /* 0: OSB4 */
360 .name = DRV_NAME, 358 .name = DRV_NAME,
361 .init_chipset = init_chipset_svwks, 359 .init_chipset = init_chipset_svwks,
362 .port_ops = &osb4_port_ops, 360 .port_ops = &osb4_port_ops,
363 .host_flags = IDE_HFLAGS_SVWKS,
364 .pio_mask = ATA_PIO4, 361 .pio_mask = ATA_PIO4,
365 .mwdma_mask = ATA_MWDMA2, 362 .mwdma_mask = ATA_MWDMA2,
366 .udma_mask = 0x00, /* UDMA is problematic on OSB4 */ 363 .udma_mask = 0x00, /* UDMA is problematic on OSB4 */
@@ -369,7 +366,6 @@ static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
369 .name = DRV_NAME, 366 .name = DRV_NAME,
370 .init_chipset = init_chipset_svwks, 367 .init_chipset = init_chipset_svwks,
371 .port_ops = &svwks_port_ops, 368 .port_ops = &svwks_port_ops,
372 .host_flags = IDE_HFLAGS_SVWKS,
373 .pio_mask = ATA_PIO4, 369 .pio_mask = ATA_PIO4,
374 .mwdma_mask = ATA_MWDMA2, 370 .mwdma_mask = ATA_MWDMA2,
375 .udma_mask = ATA_UDMA5, 371 .udma_mask = ATA_UDMA5,
@@ -378,7 +374,6 @@ static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
378 .name = DRV_NAME, 374 .name = DRV_NAME,
379 .init_chipset = init_chipset_svwks, 375 .init_chipset = init_chipset_svwks,
380 .port_ops = &svwks_port_ops, 376 .port_ops = &svwks_port_ops,
381 .host_flags = IDE_HFLAGS_SVWKS,
382 .pio_mask = ATA_PIO4, 377 .pio_mask = ATA_PIO4,
383 .mwdma_mask = ATA_MWDMA2, 378 .mwdma_mask = ATA_MWDMA2,
384 .udma_mask = ATA_UDMA5, 379 .udma_mask = ATA_UDMA5,
@@ -387,7 +382,7 @@ static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
387 .name = DRV_NAME, 382 .name = DRV_NAME,
388 .init_chipset = init_chipset_svwks, 383 .init_chipset = init_chipset_svwks,
389 .port_ops = &svwks_port_ops, 384 .port_ops = &svwks_port_ops,
390 .host_flags = IDE_HFLAGS_SVWKS | IDE_HFLAG_SINGLE, 385 .host_flags = IDE_HFLAG_SINGLE,
391 .pio_mask = ATA_PIO4, 386 .pio_mask = ATA_PIO4,
392 .mwdma_mask = ATA_MWDMA2, 387 .mwdma_mask = ATA_MWDMA2,
393 .udma_mask = ATA_UDMA5, 388 .udma_mask = ATA_UDMA5,
@@ -396,7 +391,7 @@ static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
396 .name = DRV_NAME, 391 .name = DRV_NAME,
397 .init_chipset = init_chipset_svwks, 392 .init_chipset = init_chipset_svwks,
398 .port_ops = &svwks_port_ops, 393 .port_ops = &svwks_port_ops,
399 .host_flags = IDE_HFLAGS_SVWKS | IDE_HFLAG_SINGLE, 394 .host_flags = IDE_HFLAG_SINGLE,
400 .pio_mask = ATA_PIO4, 395 .pio_mask = ATA_PIO4,
401 .mwdma_mask = ATA_MWDMA2, 396 .mwdma_mask = ATA_MWDMA2,
402 .udma_mask = ATA_UDMA5, 397 .udma_mask = ATA_UDMA5,
diff --git a/drivers/ide/setup-pci.c b/drivers/ide/setup-pci.c
index e85d1ed29c2a..24bc884826fc 100644
--- a/drivers/ide/setup-pci.c
+++ b/drivers/ide/setup-pci.c
@@ -305,7 +305,6 @@ static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *
305 * @dev: PCI device holding interface 305 * @dev: PCI device holding interface
306 * @d: IDE port info 306 * @d: IDE port info
307 * @port: port number 307 * @port: port number
308 * @irq: PCI IRQ
309 * @hw: hw_regs_t instance corresponding to this port 308 * @hw: hw_regs_t instance corresponding to this port
310 * 309 *
311 * Perform the initial set up for the hardware interface structure. This 310 * Perform the initial set up for the hardware interface structure. This
@@ -316,7 +315,7 @@ static int ide_pci_check_iomem(struct pci_dev *dev, const struct ide_port_info *
316 */ 315 */
317 316
318static int ide_hw_configure(struct pci_dev *dev, const struct ide_port_info *d, 317static int ide_hw_configure(struct pci_dev *dev, const struct ide_port_info *d,
319 unsigned int port, int irq, hw_regs_t *hw) 318 unsigned int port, hw_regs_t *hw)
320{ 319{
321 unsigned long ctl = 0, base = 0; 320 unsigned long ctl = 0, base = 0;
322 321
@@ -344,7 +343,6 @@ static int ide_hw_configure(struct pci_dev *dev, const struct ide_port_info *d,
344 } 343 }
345 344
346 memset(hw, 0, sizeof(*hw)); 345 memset(hw, 0, sizeof(*hw));
347 hw->irq = irq;
348 hw->dev = &dev->dev; 346 hw->dev = &dev->dev;
349 hw->chipset = d->chipset ? d->chipset : ide_pci; 347 hw->chipset = d->chipset ? d->chipset : ide_pci;
350 ide_std_init_ports(hw, base, ctl | 2); 348 ide_std_init_ports(hw, base, ctl | 2);
@@ -448,7 +446,6 @@ out:
448 * ide_pci_setup_ports - configure ports/devices on PCI IDE 446 * ide_pci_setup_ports - configure ports/devices on PCI IDE
449 * @dev: PCI device 447 * @dev: PCI device
450 * @d: IDE port info 448 * @d: IDE port info
451 * @pciirq: IRQ line
452 * @hw: hw_regs_t instances corresponding to this PCI IDE device 449 * @hw: hw_regs_t instances corresponding to this PCI IDE device
453 * @hws: hw_regs_t pointers table to update 450 * @hws: hw_regs_t pointers table to update
454 * 451 *
@@ -462,7 +459,7 @@ out:
462 */ 459 */
463 460
464void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d, 461void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d,
465 int pciirq, hw_regs_t *hw, hw_regs_t **hws) 462 hw_regs_t *hw, hw_regs_t **hws)
466{ 463{
467 int channels = (d->host_flags & IDE_HFLAG_SINGLE) ? 1 : 2, port; 464 int channels = (d->host_flags & IDE_HFLAG_SINGLE) ? 1 : 2, port;
468 u8 tmp; 465 u8 tmp;
@@ -481,7 +478,7 @@ void ide_pci_setup_ports(struct pci_dev *dev, const struct ide_port_info *d,
481 continue; /* port not enabled */ 478 continue; /* port not enabled */
482 } 479 }
483 480
484 if (ide_hw_configure(dev, d, port, pciirq, hw + port)) 481 if (ide_hw_configure(dev, d, port, hw + port))
485 continue; 482 continue;
486 483
487 *(hws + port) = hw + port; 484 *(hws + port) = hw + port;
@@ -524,7 +521,7 @@ static int do_ide_setup_pci_device(struct pci_dev *dev,
524 if (noisy) 521 if (noisy)
525 printk(KERN_INFO "%s %s: not 100%% native mode: will " 522 printk(KERN_INFO "%s %s: not 100%% native mode: will "
526 "probe irqs later\n", d->name, pci_name(dev)); 523 "probe irqs later\n", d->name, pci_name(dev));
527 pciirq = ret; 524 pciirq = 0;
528 } else if (!pciirq && noisy) { 525 } else if (!pciirq && noisy) {
529 printk(KERN_WARNING "%s %s: bad irq (%d): will probe later\n", 526 printk(KERN_WARNING "%s %s: bad irq (%d): will probe later\n",
530 d->name, pci_name(dev), pciirq); 527 d->name, pci_name(dev), pciirq);
@@ -549,7 +546,7 @@ int ide_pci_init_one(struct pci_dev *dev, const struct ide_port_info *d,
549 if (ret < 0) 546 if (ret < 0)
550 goto out; 547 goto out;
551 548
552 ide_pci_setup_ports(dev, d, 0, &hw[0], &hws[0]); 549 ide_pci_setup_ports(dev, d, &hw[0], &hws[0]);
553 550
554 host = ide_host_alloc(d, hws); 551 host = ide_host_alloc(d, hws);
555 if (host == NULL) { 552 if (host == NULL) {
@@ -568,7 +565,11 @@ int ide_pci_init_one(struct pci_dev *dev, const struct ide_port_info *d,
568 goto out; 565 goto out;
569 566
570 /* fixup IRQ */ 567 /* fixup IRQ */
571 hw[1].irq = hw[0].irq = ret; 568 if (ide_pci_is_in_compatibility_mode(dev)) {
569 hw[0].irq = pci_get_legacy_ide_irq(dev, 0);
570 hw[1].irq = pci_get_legacy_ide_irq(dev, 1);
571 } else
572 hw[1].irq = hw[0].irq = ret;
572 573
573 ret = ide_host_register(host, d, hws); 574 ret = ide_host_register(host, d, hws);
574 if (ret) 575 if (ret)
@@ -591,7 +592,7 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
591 if (ret < 0) 592 if (ret < 0)
592 goto out; 593 goto out;
593 594
594 ide_pci_setup_ports(pdev[i], d, 0, &hw[i*2], &hws[i*2]); 595 ide_pci_setup_ports(pdev[i], d, &hw[i*2], &hws[i*2]);
595 } 596 }
596 597
597 host = ide_host_alloc(d, hws); 598 host = ide_host_alloc(d, hws);
@@ -619,7 +620,11 @@ int ide_pci_init_two(struct pci_dev *dev1, struct pci_dev *dev2,
619 goto out; 620 goto out;
620 621
621 /* fixup IRQ */ 622 /* fixup IRQ */
622 hw[i*2 + 1].irq = hw[i*2].irq = ret; 623 if (ide_pci_is_in_compatibility_mode(pdev[i])) {
624 hw[i*2].irq = pci_get_legacy_ide_irq(pdev[i], 0);
625 hw[i*2 + 1].irq = pci_get_legacy_ide_irq(pdev[i], 1);
626 } else
627 hw[i*2 + 1].irq = hw[i*2].irq = ret;
623 } 628 }
624 629
625 ret = ide_host_register(host, d, hws); 630 ret = ide_host_register(host, d, hws);
diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
index cb2b352b876b..1811ae9cd843 100644
--- a/drivers/ide/siimage.c
+++ b/drivers/ide/siimage.c
@@ -464,7 +464,7 @@ static void sil_sata_pre_reset(ide_drive_t *drive)
464 * to 133 MHz clocking if the system isn't already set up to do it. 464 * to 133 MHz clocking if the system isn't already set up to do it.
465 */ 465 */
466 466
467static unsigned int init_chipset_siimage(struct pci_dev *dev) 467static int init_chipset_siimage(struct pci_dev *dev)
468{ 468{
469 struct ide_host *host = pci_get_drvdata(dev); 469 struct ide_host *host = pci_get_drvdata(dev);
470 void __iomem *ioaddr = host->host_priv; 470 void __iomem *ioaddr = host->host_priv;
diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
index 9ec1a4a4432c..afca22beaadf 100644
--- a/drivers/ide/sis5513.c
+++ b/drivers/ide/sis5513.c
@@ -447,7 +447,7 @@ static int __devinit sis_find_family(struct pci_dev *dev)
447 return chipset_family; 447 return chipset_family;
448} 448}
449 449
450static unsigned int init_chipset_sis5513(struct pci_dev *dev) 450static int init_chipset_sis5513(struct pci_dev *dev)
451{ 451{
452 /* Make general config ops here 452 /* Make general config ops here
453 1/ tell IDE channels to operate in Compatibility mode only 453 1/ tell IDE channels to operate in Compatibility mode only
@@ -563,7 +563,7 @@ static const struct ide_port_info sis5513_chipset __devinitdata = {
563 .name = DRV_NAME, 563 .name = DRV_NAME,
564 .init_chipset = init_chipset_sis5513, 564 .init_chipset = init_chipset_sis5513,
565 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} }, 565 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
566 .host_flags = IDE_HFLAG_LEGACY_IRQS | IDE_HFLAG_NO_AUTODMA, 566 .host_flags = IDE_HFLAG_NO_AUTODMA,
567 .pio_mask = ATA_PIO4, 567 .pio_mask = ATA_PIO4,
568 .mwdma_mask = ATA_MWDMA2, 568 .mwdma_mask = ATA_MWDMA2,
569}; 569};
diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
index 6297956507c0..dba213c51baa 100644
--- a/drivers/ide/sl82c105.c
+++ b/drivers/ide/sl82c105.c
@@ -271,7 +271,7 @@ static u8 sl82c105_bridge_revision(struct pci_dev *dev)
271 * channel 0 here at least, but channel 1 has to be enabled by 271 * channel 0 here at least, but channel 1 has to be enabled by
272 * firmware or arch code. We still set both to 16 bits mode. 272 * firmware or arch code. We still set both to 16 bits mode.
273 */ 273 */
274static unsigned int init_chipset_sl82c105(struct pci_dev *dev) 274static int init_chipset_sl82c105(struct pci_dev *dev)
275{ 275{
276 u32 val; 276 u32 val;
277 277
@@ -281,7 +281,7 @@ static unsigned int init_chipset_sl82c105(struct pci_dev *dev)
281 val |= CTRL_P0EN | CTRL_P0F16 | CTRL_P1F16; 281 val |= CTRL_P0EN | CTRL_P0F16 | CTRL_P1F16;
282 pci_write_config_dword(dev, 0x40, val); 282 pci_write_config_dword(dev, 0x40, val);
283 283
284 return dev->irq; 284 return 0;
285} 285}
286 286
287static const struct ide_port_ops sl82c105_port_ops = { 287static const struct ide_port_ops sl82c105_port_ops = {
diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
index 40b4b94a4288..f55d7d6313e8 100644
--- a/drivers/ide/slc90e66.c
+++ b/drivers/ide/slc90e66.c
@@ -136,7 +136,6 @@ static const struct ide_port_info slc90e66_chipset __devinitdata = {
136 .name = DRV_NAME, 136 .name = DRV_NAME,
137 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} }, 137 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
138 .port_ops = &slc90e66_port_ops, 138 .port_ops = &slc90e66_port_ops,
139 .host_flags = IDE_HFLAG_LEGACY_IRQS,
140 .pio_mask = ATA_PIO4, 139 .pio_mask = ATA_PIO4,
141 .swdma_mask = ATA_SWDMA2_ONLY, 140 .swdma_mask = ATA_SWDMA2_ONLY,
142 .mwdma_mask = ATA_MWDMA12_ONLY, 141 .mwdma_mask = ATA_MWDMA12_ONLY,
diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
index b6a1285a4021..1c09e549c423 100644
--- a/drivers/ide/trm290.c
+++ b/drivers/ide/trm290.c
@@ -277,9 +277,6 @@ static void __devinit init_hwif_trm290(ide_hwif_t *hwif)
277 if (reg & 0x10) 277 if (reg & 0x10)
278 /* legacy mode */ 278 /* legacy mode */
279 hwif->irq = hwif->channel ? 15 : 14; 279 hwif->irq = hwif->channel ? 15 : 14;
280 else if (!hwif->irq && hwif->mate && hwif->mate->irq)
281 /* sharing IRQ with mate */
282 hwif->irq = hwif->mate->irq;
283 280
284#if 1 281#if 1
285 { 282 {
diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
index 6092fe3f409d..3ff7231e4858 100644
--- a/drivers/ide/via82cxxx.c
+++ b/drivers/ide/via82cxxx.c
@@ -267,7 +267,7 @@ static void via_cable_detect(struct via82cxxx_dev *vdev, u32 u)
267 * and initialize its drive independent registers. 267 * and initialize its drive independent registers.
268 */ 268 */
269 269
270static unsigned int init_chipset_via82cxxx(struct pci_dev *dev) 270static int init_chipset_via82cxxx(struct pci_dev *dev)
271{ 271{
272 struct ide_host *host = pci_get_drvdata(dev); 272 struct ide_host *host = pci_get_drvdata(dev);
273 struct via82cxxx_dev *vdev = host->host_priv; 273 struct via82cxxx_dev *vdev = host->host_priv;
@@ -443,16 +443,6 @@ static int __devinit via_init_one(struct pci_dev *dev, const struct pci_device_i
443 if ((via_config->flags & VIA_NO_UNMASK) == 0) 443 if ((via_config->flags & VIA_NO_UNMASK) == 0)
444 d.host_flags |= IDE_HFLAG_UNMASK_IRQS; 444 d.host_flags |= IDE_HFLAG_UNMASK_IRQS;
445 445
446#ifdef CONFIG_PPC_CHRP
447 if (machine_is(chrp) && _chrp_type == _CHRP_Pegasos)
448 d.host_flags |= IDE_HFLAG_FORCE_LEGACY_IRQS;
449#endif
450
451#ifdef CONFIG_AMIGAONE
452 if (machine_is(amigaone))
453 d.host_flags |= IDE_HFLAG_FORCE_LEGACY_IRQS;
454#endif
455
456 d.udma_mask = via_config->udma_mask; 446 d.udma_mask = via_config->udma_mask;
457 447
458 vdev = kzalloc(sizeof(*vdev), GFP_KERNEL); 448 vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
diff --git a/drivers/input/joystick/maplecontrol.c b/drivers/input/joystick/maplecontrol.c
index e50047bfe938..77cfde571bd9 100644
--- a/drivers/input/joystick/maplecontrol.c
+++ b/drivers/input/joystick/maplecontrol.c
@@ -3,7 +3,7 @@
3 * Based on drivers/usb/iforce.c 3 * Based on drivers/usb/iforce.c
4 * 4 *
5 * Copyright Yaegashi Takeshi, 2001 5 * Copyright Yaegashi Takeshi, 2001
6 * Adrian McMenamin, 2008 6 * Adrian McMenamin, 2008 - 2009
7 */ 7 */
8 8
9#include <linux/kernel.h> 9#include <linux/kernel.h>
@@ -29,7 +29,7 @@ static void dc_pad_callback(struct mapleq *mq)
29 struct maple_device *mapledev = mq->dev; 29 struct maple_device *mapledev = mq->dev;
30 struct dc_pad *pad = maple_get_drvdata(mapledev); 30 struct dc_pad *pad = maple_get_drvdata(mapledev);
31 struct input_dev *dev = pad->dev; 31 struct input_dev *dev = pad->dev;
32 unsigned char *res = mq->recvbuf; 32 unsigned char *res = mq->recvbuf->buf;
33 33
34 buttons = ~le16_to_cpup((__le16 *)(res + 8)); 34 buttons = ~le16_to_cpup((__le16 *)(res + 8));
35 35
diff --git a/drivers/input/keyboard/maple_keyb.c b/drivers/input/keyboard/maple_keyb.c
index 22f17a593be7..5aa2361aef95 100644
--- a/drivers/input/keyboard/maple_keyb.c
+++ b/drivers/input/keyboard/maple_keyb.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * SEGA Dreamcast keyboard driver 2 * SEGA Dreamcast keyboard driver
3 * Based on drivers/usb/usbkbd.c 3 * Based on drivers/usb/usbkbd.c
4 * Copyright YAEGASHI Takeshi, 2001 4 * Copyright (c) YAEGASHI Takeshi, 2001
5 * Porting to 2.6 Copyright Adrian McMenamin, 2007, 2008 5 * Porting to 2.6 Copyright (c) Adrian McMenamin, 2007 - 2009
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -33,7 +33,7 @@ static DEFINE_MUTEX(maple_keyb_mutex);
33 33
34#define NR_SCANCODES 256 34#define NR_SCANCODES 256
35 35
36MODULE_AUTHOR("YAEGASHI Takeshi, Adrian McMenamin"); 36MODULE_AUTHOR("Adrian McMenamin <adrian@mcmen.demon.co.uk");
37MODULE_DESCRIPTION("SEGA Dreamcast keyboard driver"); 37MODULE_DESCRIPTION("SEGA Dreamcast keyboard driver");
38MODULE_LICENSE("GPL"); 38MODULE_LICENSE("GPL");
39 39
@@ -115,7 +115,7 @@ static void dc_scan_kbd(struct dc_kbd *kbd)
115 input_event(dev, EV_MSC, MSC_SCAN, code); 115 input_event(dev, EV_MSC, MSC_SCAN, code);
116 input_report_key(dev, keycode, 0); 116 input_report_key(dev, keycode, 0);
117 } else 117 } else
118 printk(KERN_DEBUG "maple_keyb: " 118 dev_dbg(&dev->dev,
119 "Unknown key (scancode %#x) released.", 119 "Unknown key (scancode %#x) released.",
120 code); 120 code);
121 } 121 }
@@ -127,7 +127,7 @@ static void dc_scan_kbd(struct dc_kbd *kbd)
127 input_event(dev, EV_MSC, MSC_SCAN, code); 127 input_event(dev, EV_MSC, MSC_SCAN, code);
128 input_report_key(dev, keycode, 1); 128 input_report_key(dev, keycode, 1);
129 } else 129 } else
130 printk(KERN_DEBUG "maple_keyb: " 130 dev_dbg(&dev->dev,
131 "Unknown key (scancode %#x) pressed.", 131 "Unknown key (scancode %#x) pressed.",
132 code); 132 code);
133 } 133 }
@@ -140,7 +140,7 @@ static void dc_kbd_callback(struct mapleq *mq)
140{ 140{
141 struct maple_device *mapledev = mq->dev; 141 struct maple_device *mapledev = mq->dev;
142 struct dc_kbd *kbd = maple_get_drvdata(mapledev); 142 struct dc_kbd *kbd = maple_get_drvdata(mapledev);
143 unsigned long *buf = mq->recvbuf; 143 unsigned long *buf = (unsigned long *)(mq->recvbuf->buf);
144 144
145 /* 145 /*
146 * We should always get the lock because the only 146 * We should always get the lock because the only
@@ -159,22 +159,27 @@ static void dc_kbd_callback(struct mapleq *mq)
159 159
160static int probe_maple_kbd(struct device *dev) 160static int probe_maple_kbd(struct device *dev)
161{ 161{
162 struct maple_device *mdev = to_maple_dev(dev); 162 struct maple_device *mdev;
163 struct maple_driver *mdrv = to_maple_driver(dev->driver); 163 struct maple_driver *mdrv;
164 int i, error; 164 int i, error;
165 struct dc_kbd *kbd; 165 struct dc_kbd *kbd;
166 struct input_dev *idev; 166 struct input_dev *idev;
167 167
168 if (!(mdev->function & MAPLE_FUNC_KEYBOARD)) 168 mdev = to_maple_dev(dev);
169 return -EINVAL; 169 mdrv = to_maple_driver(dev->driver);
170 170
171 kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL); 171 kbd = kzalloc(sizeof(struct dc_kbd), GFP_KERNEL);
172 idev = input_allocate_device(); 172 if (!kbd) {
173 if (!kbd || !idev) {
174 error = -ENOMEM; 173 error = -ENOMEM;
175 goto fail; 174 goto fail;
176 } 175 }
177 176
177 idev = input_allocate_device();
178 if (!idev) {
179 error = -ENOMEM;
180 goto fail_idev_alloc;
181 }
182
178 kbd->dev = idev; 183 kbd->dev = idev;
179 memcpy(kbd->keycode, dc_kbd_keycode, sizeof(kbd->keycode)); 184 memcpy(kbd->keycode, dc_kbd_keycode, sizeof(kbd->keycode));
180 185
@@ -195,7 +200,7 @@ static int probe_maple_kbd(struct device *dev)
195 200
196 error = input_register_device(idev); 201 error = input_register_device(idev);
197 if (error) 202 if (error)
198 goto fail; 203 goto fail_register;
199 204
200 /* Maple polling is locked to VBLANK - which may be just 50/s */ 205 /* Maple polling is locked to VBLANK - which may be just 50/s */
201 maple_getcond_callback(mdev, dc_kbd_callback, HZ/50, 206 maple_getcond_callback(mdev, dc_kbd_callback, HZ/50,
@@ -207,10 +212,12 @@ static int probe_maple_kbd(struct device *dev)
207 212
208 return error; 213 return error;
209 214
210fail: 215fail_register:
216 maple_set_drvdata(mdev, NULL);
211 input_free_device(idev); 217 input_free_device(idev);
218fail_idev_alloc:
212 kfree(kbd); 219 kfree(kbd);
213 maple_set_drvdata(mdev, NULL); 220fail:
214 return error; 221 return error;
215} 222}
216 223
diff --git a/drivers/input/keyboard/sh_keysc.c b/drivers/input/keyboard/sh_keysc.c
index 5c8a1bcf7ca7..e1480fb11de3 100644
--- a/drivers/input/keyboard/sh_keysc.c
+++ b/drivers/input/keyboard/sh_keysc.c
@@ -219,6 +219,8 @@ static int __devinit sh_keysc_probe(struct platform_device *pdev)
219 pdata->scan_timing, priv->iomem_base + KYCR1_OFFS); 219 pdata->scan_timing, priv->iomem_base + KYCR1_OFFS);
220 iowrite16(0, priv->iomem_base + KYOUTDR_OFFS); 220 iowrite16(0, priv->iomem_base + KYOUTDR_OFFS);
221 iowrite16(KYCR2_IRQ_LEVEL, priv->iomem_base + KYCR2_OFFS); 221 iowrite16(KYCR2_IRQ_LEVEL, priv->iomem_base + KYCR2_OFFS);
222
223 device_init_wakeup(&pdev->dev, 1);
222 return 0; 224 return 0;
223 err5: 225 err5:
224 free_irq(irq, pdev); 226 free_irq(irq, pdev);
@@ -253,17 +255,33 @@ static int __devexit sh_keysc_remove(struct platform_device *pdev)
253 return 0; 255 return 0;
254} 256}
255 257
258static int sh_keysc_suspend(struct device *dev)
259{
260 struct platform_device *pdev = to_platform_device(dev);
261 struct sh_keysc_priv *priv = platform_get_drvdata(pdev);
262 unsigned short value;
263
264 value = ioread16(priv->iomem_base + KYCR1_OFFS);
265
266 if (device_may_wakeup(dev))
267 value |= 0x80;
268 else
269 value &= ~0x80;
256 270
257#define sh_keysc_suspend NULL 271 iowrite16(value, priv->iomem_base + KYCR1_OFFS);
258#define sh_keysc_resume NULL 272 return 0;
273}
274
275static struct dev_pm_ops sh_keysc_dev_pm_ops = {
276 .suspend = sh_keysc_suspend,
277};
259 278
260struct platform_driver sh_keysc_device_driver = { 279struct platform_driver sh_keysc_device_driver = {
261 .probe = sh_keysc_probe, 280 .probe = sh_keysc_probe,
262 .remove = __devexit_p(sh_keysc_remove), 281 .remove = __devexit_p(sh_keysc_remove),
263 .suspend = sh_keysc_suspend,
264 .resume = sh_keysc_resume,
265 .driver = { 282 .driver = {
266 .name = "sh_keysc", 283 .name = "sh_keysc",
284 .pm = &sh_keysc_dev_pm_ops,
267 } 285 }
268}; 286};
269 287
diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
index ac245e7e96a5..3071a52467ed 100644
--- a/drivers/isdn/gigaset/ser-gigaset.c
+++ b/drivers/isdn/gigaset/ser-gigaset.c
@@ -389,8 +389,7 @@ static void gigaset_freecshw(struct cardstate *cs)
389 389
390static void gigaset_device_release(struct device *dev) 390static void gigaset_device_release(struct device *dev)
391{ 391{
392 struct platform_device *pdev = 392 struct platform_device *pdev = to_platform_device(dev);
393 container_of(dev, struct platform_device, dev);
394 393
395 /* adapted from platform_device_release() in drivers/base/platform.c */ 394 /* adapted from platform_device_release() in drivers/base/platform.c */
396 //FIXME is this actually necessary? 395 //FIXME is this actually necessary?
diff --git a/drivers/mca/mca-bus.c b/drivers/mca/mca-bus.c
index ef2dbfe74714..ada5ebbaa255 100644
--- a/drivers/mca/mca-bus.c
+++ b/drivers/mca/mca-bus.c
@@ -110,7 +110,7 @@ int __init mca_register_device(int bus, struct mca_device *mca_dev)
110 110
111 mca_dev->dev.parent = &mca_bus->dev; 111 mca_dev->dev.parent = &mca_bus->dev;
112 mca_dev->dev.bus = &mca_bus_type; 112 mca_dev->dev.bus = &mca_bus_type;
113 sprintf (mca_dev->dev.bus_id, "%02d:%02X", bus, mca_dev->slot); 113 dev_set_name(&mca_dev->dev, "%02d:%02X", bus, mca_dev->slot);
114 mca_dev->dma_mask = mca_bus->default_dma_mask; 114 mca_dev->dma_mask = mca_bus->default_dma_mask;
115 mca_dev->dev.dma_mask = &mca_dev->dma_mask; 115 mca_dev->dev.dma_mask = &mca_dev->dma_mask;
116 mca_dev->dev.coherent_dma_mask = mca_dev->dma_mask; 116 mca_dev->dev.coherent_dma_mask = mca_dev->dma_mask;
@@ -151,7 +151,7 @@ struct mca_bus * __devinit mca_attach_bus(int bus)
151 if (!mca_bus) 151 if (!mca_bus)
152 return NULL; 152 return NULL;
153 153
154 sprintf(mca_bus->dev.bus_id,"mca%d",bus); 154 dev_set_name(&mca_bus->dev, "mca%d", bus);
155 sprintf(mca_bus->name,"Host %s MCA Bridge", bus ? "Secondary" : "Primary"); 155 sprintf(mca_bus->name,"Host %s MCA Bridge", bus ? "Secondary" : "Primary");
156 if (device_register(&mca_bus->dev)) { 156 if (device_register(&mca_bus->dev)) {
157 kfree(mca_bus); 157 kfree(mca_bus);
diff --git a/drivers/media/radio/radio-tea5764.c b/drivers/media/radio/radio-tea5764.c
index 4d35308fc1ff..393623818ade 100644
--- a/drivers/media/radio/radio-tea5764.c
+++ b/drivers/media/radio/radio-tea5764.c
@@ -298,7 +298,8 @@ static int vidioc_querycap(struct file *file, void *priv,
298 298
299 strlcpy(v->driver, dev->dev.driver->name, sizeof(v->driver)); 299 strlcpy(v->driver, dev->dev.driver->name, sizeof(v->driver));
300 strlcpy(v->card, dev->name, sizeof(v->card)); 300 strlcpy(v->card, dev->name, sizeof(v->card));
301 snprintf(v->bus_info, sizeof(v->bus_info), "I2C:%s", dev->dev.bus_id); 301 snprintf(v->bus_info, sizeof(v->bus_info),
302 "I2C:%s", dev_name(&dev->dev));
302 v->version = RADIO_VERSION; 303 v->version = RADIO_VERSION;
303 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO; 304 v->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
304 return 0; 305 return 0;
diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
index 66c755c116dc..ce98d955231a 100644
--- a/drivers/media/video/cx88/cx88-alsa.c
+++ b/drivers/media/video/cx88/cx88-alsa.c
@@ -803,9 +803,10 @@ static int __devinit cx88_audio_initdev(struct pci_dev *pci,
803 return (-ENOENT); 803 return (-ENOENT);
804 } 804 }
805 805
806 card = snd_card_new(index[devno], id[devno], THIS_MODULE, sizeof(snd_cx88_card_t)); 806 err = snd_card_create(index[devno], id[devno], THIS_MODULE,
807 if (!card) 807 sizeof(snd_cx88_card_t), &card);
808 return (-ENOMEM); 808 if (err < 0)
809 return err;
809 810
810 card->private_free = snd_cx88_dev_free; 811 card->private_free = snd_cx88_dev_free;
811 812
diff --git a/drivers/media/video/em28xx/em28xx-audio.c b/drivers/media/video/em28xx/em28xx-audio.c
index 2ac738fa6a07..f132e31f6edd 100644
--- a/drivers/media/video/em28xx/em28xx-audio.c
+++ b/drivers/media/video/em28xx/em28xx-audio.c
@@ -448,9 +448,10 @@ static int em28xx_audio_init(struct em28xx *dev)
448 printk(KERN_INFO "em28xx-audio.c: Copyright (C) 2006 Markus " 448 printk(KERN_INFO "em28xx-audio.c: Copyright (C) 2006 Markus "
449 "Rechberger\n"); 449 "Rechberger\n");
450 450
451 card = snd_card_new(index[devnr], "Em28xx Audio", THIS_MODULE, 0); 451 err = snd_card_create(index[devnr], "Em28xx Audio", THIS_MODULE, 0,
452 if (card == NULL) 452 &card);
453 return -ENOMEM; 453 if (err < 0)
454 return err;
454 455
455 spin_lock_init(&adev->slock); 456 spin_lock_init(&adev->slock);
456 err = snd_pcm_new(card, "Em28xx Audio", 0, 0, 1, &pcm); 457 err = snd_pcm_new(card, "Em28xx Audio", 0, 0, 1, &pcm);
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index c750d3dd57d2..8b0b64a89874 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -990,10 +990,10 @@ static int alsa_card_saa7134_create(struct saa7134_dev *dev, int devnum)
990 if (!enable[devnum]) 990 if (!enable[devnum])
991 return -ENODEV; 991 return -ENODEV;
992 992
993 card = snd_card_new(index[devnum], id[devnum], THIS_MODULE, sizeof(snd_card_saa7134_t)); 993 err = snd_card_create(index[devnum], id[devnum], THIS_MODULE,
994 994 sizeof(snd_card_saa7134_t), &card);
995 if (card == NULL) 995 if (err < 0)
996 return -ENOMEM; 996 return err;
997 997
998 strcpy(card->driver, "SAA7134"); 998 strcpy(card->driver, "SAA7134");
999 999
diff --git a/drivers/media/video/v4l2-device.c b/drivers/media/video/v4l2-device.c
index cf9d4c7f571a..8a4b74f3129f 100644
--- a/drivers/media/video/v4l2-device.c
+++ b/drivers/media/video/v4l2-device.c
@@ -34,7 +34,7 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
34 spin_lock_init(&v4l2_dev->lock); 34 spin_lock_init(&v4l2_dev->lock);
35 v4l2_dev->dev = dev; 35 v4l2_dev->dev = dev;
36 snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s %s", 36 snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s %s",
37 dev->driver->name, dev->bus_id); 37 dev->driver->name, dev_name(dev));
38 dev_set_drvdata(dev, v4l2_dev); 38 dev_set_drvdata(dev, v4l2_dev);
39 return 0; 39 return 0;
40} 40}
diff --git a/drivers/mfd/mcp-core.c b/drivers/mfd/mcp-core.c
index 6063dc2b52e8..57271cb3b316 100644
--- a/drivers/mfd/mcp-core.c
+++ b/drivers/mfd/mcp-core.c
@@ -214,7 +214,7 @@ EXPORT_SYMBOL(mcp_host_alloc);
214 214
215int mcp_host_register(struct mcp *mcp) 215int mcp_host_register(struct mcp *mcp)
216{ 216{
217 strcpy(mcp->attached_device.bus_id, "mcp0"); 217 dev_set_name(&mcp->attached_device, "mcp0");
218 return device_register(&mcp->attached_device); 218 return device_register(&mcp->attached_device);
219} 219}
220EXPORT_SYMBOL(mcp_host_register); 220EXPORT_SYMBOL(mcp_host_register);
diff --git a/drivers/mfd/ucb1x00-core.c b/drivers/mfd/ucb1x00-core.c
index 6860c924f364..fea9085fe52c 100644
--- a/drivers/mfd/ucb1x00-core.c
+++ b/drivers/mfd/ucb1x00-core.c
@@ -492,7 +492,7 @@ static int ucb1x00_probe(struct mcp *mcp)
492 492
493 ucb->dev.class = &ucb1x00_class; 493 ucb->dev.class = &ucb1x00_class;
494 ucb->dev.parent = &mcp->attached_device; 494 ucb->dev.parent = &mcp->attached_device;
495 strlcpy(ucb->dev.bus_id, "ucb1x00", sizeof(ucb->dev.bus_id)); 495 dev_set_name(&ucb->dev, "ucb1x00");
496 496
497 spin_lock_init(&ucb->lock); 497 spin_lock_init(&ucb->lock);
498 spin_lock_init(&ucb->io_lock); 498 spin_lock_init(&ucb->io_lock);
diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index 2b1196e6142c..e94e92001e7c 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -1603,7 +1603,7 @@ static int __init atmci_probe(struct platform_device *pdev)
1603 1603
1604 tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)host); 1604 tasklet_init(&host->tasklet, atmci_tasklet_func, (unsigned long)host);
1605 1605
1606 ret = request_irq(irq, atmci_interrupt, 0, pdev->dev.bus_id, host); 1606 ret = request_irq(irq, atmci_interrupt, 0, dev_name(&pdev->dev), host);
1607 if (ret) 1607 if (ret)
1608 goto err_request_irq; 1608 goto err_request_irq;
1609 1609
diff --git a/drivers/mmc/host/of_mmc_spi.c b/drivers/mmc/host/of_mmc_spi.c
index fb2921f8099d..0c44d560bf1a 100644
--- a/drivers/mmc/host/of_mmc_spi.c
+++ b/drivers/mmc/host/of_mmc_spi.c
@@ -103,7 +103,7 @@ struct mmc_spi_platform_data *mmc_spi_get_pdata(struct spi_device *spi)
103 if (!gpio_is_valid(oms->gpios[i])) 103 if (!gpio_is_valid(oms->gpios[i]))
104 continue; 104 continue;
105 105
106 ret = gpio_request(oms->gpios[i], dev->bus_id); 106 ret = gpio_request(oms->gpios[i], dev_name(dev));
107 if (ret < 0) { 107 if (ret < 0) {
108 oms->gpios[i] = -EINVAL; 108 oms->gpios[i] = -EINVAL;
109 continue; 109 continue;
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 043d50fb6ef6..729f899a5cd5 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -551,5 +551,15 @@ config MTD_PLATRAM
551 551
552 This selection automatically selects the map_ram driver. 552 This selection automatically selects the map_ram driver.
553 553
554endmenu 554config MTD_VMU
555 tristate "Map driver for Dreamcast VMU"
556 depends on MAPLE
557 help
558 This driver enables access to the Dreamcast Visual Memory Unit (VMU).
559
560 Most Dreamcast users will want to say Y here.
555 561
562 To build this as a module select M here, the module will be called
563 vmu-flash.
564
565endmenu
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile
index 6d9ba35caf11..26b28a7a90b5 100644
--- a/drivers/mtd/maps/Makefile
+++ b/drivers/mtd/maps/Makefile
@@ -61,3 +61,4 @@ obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o
61obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o 61obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o
62obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o 62obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o
63obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o 63obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o
64obj-$(CONFIG_MTD_VMU) += vmu-flash.o
diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c
index 771139c5bf87..e9026cb1c5b2 100644
--- a/drivers/mtd/maps/pxa2xx-flash.c
+++ b/drivers/mtd/maps/pxa2xx-flash.c
@@ -41,9 +41,8 @@ struct pxa2xx_flash_info {
41static const char *probes[] = { "RedBoot", "cmdlinepart", NULL }; 41static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
42 42
43 43
44static int __init pxa2xx_flash_probe(struct device *dev) 44static int __init pxa2xx_flash_probe(struct platform_device *pdev)
45{ 45{
46 struct platform_device *pdev = to_platform_device(dev);
47 struct flash_platform_data *flash = pdev->dev.platform_data; 46 struct flash_platform_data *flash = pdev->dev.platform_data;
48 struct pxa2xx_flash_info *info; 47 struct pxa2xx_flash_info *info;
49 struct mtd_partition *parts; 48 struct mtd_partition *parts;
@@ -114,15 +113,15 @@ static int __init pxa2xx_flash_probe(struct device *dev)
114 add_mtd_device(info->mtd); 113 add_mtd_device(info->mtd);
115 } 114 }
116 115
117 dev_set_drvdata(dev, info); 116 platform_set_drvdata(pdev, info);
118 return 0; 117 return 0;
119} 118}
120 119
121static int __exit pxa2xx_flash_remove(struct device *dev) 120static int __exit pxa2xx_flash_remove(struct platform_device *dev)
122{ 121{
123 struct pxa2xx_flash_info *info = dev_get_drvdata(dev); 122 struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
124 123
125 dev_set_drvdata(dev, NULL); 124 platform_set_drvdata(dev, NULL);
126 125
127#ifdef CONFIG_MTD_PARTITIONS 126#ifdef CONFIG_MTD_PARTITIONS
128 if (info->nr_parts) 127 if (info->nr_parts)
@@ -141,9 +140,9 @@ static int __exit pxa2xx_flash_remove(struct device *dev)
141} 140}
142 141
143#ifdef CONFIG_PM 142#ifdef CONFIG_PM
144static int pxa2xx_flash_suspend(struct device *dev, pm_message_t state) 143static int pxa2xx_flash_suspend(struct platform_device *dev, pm_message_t state)
145{ 144{
146 struct pxa2xx_flash_info *info = dev_get_drvdata(dev); 145 struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
147 int ret = 0; 146 int ret = 0;
148 147
149 if (info->mtd && info->mtd->suspend) 148 if (info->mtd && info->mtd->suspend)
@@ -151,17 +150,17 @@ static int pxa2xx_flash_suspend(struct device *dev, pm_message_t state)
151 return ret; 150 return ret;
152} 151}
153 152
154static int pxa2xx_flash_resume(struct device *dev) 153static int pxa2xx_flash_resume(struct platform_device *dev)
155{ 154{
156 struct pxa2xx_flash_info *info = dev_get_drvdata(dev); 155 struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
157 156
158 if (info->mtd && info->mtd->resume) 157 if (info->mtd && info->mtd->resume)
159 info->mtd->resume(info->mtd); 158 info->mtd->resume(info->mtd);
160 return 0; 159 return 0;
161} 160}
162static void pxa2xx_flash_shutdown(struct device *dev) 161static void pxa2xx_flash_shutdown(struct platform_device *dev)
163{ 162{
164 struct pxa2xx_flash_info *info = dev_get_drvdata(dev); 163 struct pxa2xx_flash_info *info = platform_get_drvdata(dev);
165 164
166 if (info && info->mtd->suspend(info->mtd) == 0) 165 if (info && info->mtd->suspend(info->mtd) == 0)
167 info->mtd->resume(info->mtd); 166 info->mtd->resume(info->mtd);
@@ -172,11 +171,13 @@ static void pxa2xx_flash_shutdown(struct device *dev)
172#define pxa2xx_flash_shutdown NULL 171#define pxa2xx_flash_shutdown NULL
173#endif 172#endif
174 173
175static struct device_driver pxa2xx_flash_driver = { 174static struct platform_driver pxa2xx_flash_driver = {
176 .name = "pxa2xx-flash", 175 .driver = {
177 .bus = &platform_bus_type, 176 .name = "pxa2xx-flash",
177 .owner = THIS_MODULE,
178 },
178 .probe = pxa2xx_flash_probe, 179 .probe = pxa2xx_flash_probe,
179 .remove = __exit_p(pxa2xx_flash_remove), 180 .remove = __devexit_p(pxa2xx_flash_remove),
180 .suspend = pxa2xx_flash_suspend, 181 .suspend = pxa2xx_flash_suspend,
181 .resume = pxa2xx_flash_resume, 182 .resume = pxa2xx_flash_resume,
182 .shutdown = pxa2xx_flash_shutdown, 183 .shutdown = pxa2xx_flash_shutdown,
@@ -184,12 +185,12 @@ static struct device_driver pxa2xx_flash_driver = {
184 185
185static int __init init_pxa2xx_flash(void) 186static int __init init_pxa2xx_flash(void)
186{ 187{
187 return driver_register(&pxa2xx_flash_driver); 188 return platform_driver_register(&pxa2xx_flash_driver);
188} 189}
189 190
190static void __exit cleanup_pxa2xx_flash(void) 191static void __exit cleanup_pxa2xx_flash(void)
191{ 192{
192 driver_unregister(&pxa2xx_flash_driver); 193 platform_driver_unregister(&pxa2xx_flash_driver);
193} 194}
194 195
195module_init(init_pxa2xx_flash); 196module_init(init_pxa2xx_flash);
diff --git a/drivers/mtd/maps/vmu-flash.c b/drivers/mtd/maps/vmu-flash.c
new file mode 100644
index 000000000000..1f73297e7776
--- /dev/null
+++ b/drivers/mtd/maps/vmu-flash.c
@@ -0,0 +1,832 @@
1/* vmu-flash.c
2 * Driver for SEGA Dreamcast Visual Memory Unit
3 *
4 * Copyright (c) Adrian McMenamin 2002 - 2009
5 * Copyright (c) Paul Mundt 2001
6 *
7 * Licensed under version 2 of the
8 * GNU General Public Licence
9 */
10#include <linux/init.h>
11#include <linux/sched.h>
12#include <linux/delay.h>
13#include <linux/maple.h>
14#include <linux/mtd/mtd.h>
15#include <linux/mtd/map.h>
16
17struct vmu_cache {
18 unsigned char *buffer; /* Cache */
19 unsigned int block; /* Which block was cached */
20 unsigned long jiffies_atc; /* When was it cached? */
21 int valid;
22};
23
24struct mdev_part {
25 struct maple_device *mdev;
26 int partition;
27};
28
29struct vmupart {
30 u16 user_blocks;
31 u16 root_block;
32 u16 numblocks;
33 char *name;
34 struct vmu_cache *pcache;
35};
36
37struct memcard {
38 u16 tempA;
39 u16 tempB;
40 u32 partitions;
41 u32 blocklen;
42 u32 writecnt;
43 u32 readcnt;
44 u32 removeable;
45 int partition;
46 int read;
47 unsigned char *blockread;
48 struct vmupart *parts;
49 struct mtd_info *mtd;
50};
51
52struct vmu_block {
53 unsigned int num; /* block number */
54 unsigned int ofs; /* block offset */
55};
56
57static struct vmu_block *ofs_to_block(unsigned long src_ofs,
58 struct mtd_info *mtd, int partition)
59{
60 struct vmu_block *vblock;
61 struct maple_device *mdev;
62 struct memcard *card;
63 struct mdev_part *mpart;
64 int num;
65
66 mpart = mtd->priv;
67 mdev = mpart->mdev;
68 card = maple_get_drvdata(mdev);
69
70 if (src_ofs >= card->parts[partition].numblocks * card->blocklen)
71 goto failed;
72
73 num = src_ofs / card->blocklen;
74 if (num > card->parts[partition].numblocks)
75 goto failed;
76
77 vblock = kmalloc(sizeof(struct vmu_block), GFP_KERNEL);
78 if (!vblock)
79 goto failed;
80
81 vblock->num = num;
82 vblock->ofs = src_ofs % card->blocklen;
83 return vblock;
84
85failed:
86 return NULL;
87}
88
89/* Maple bus callback function for reads */
90static void vmu_blockread(struct mapleq *mq)
91{
92 struct maple_device *mdev;
93 struct memcard *card;
94
95 mdev = mq->dev;
96 card = maple_get_drvdata(mdev);
97 /* copy the read in data */
98
99 if (unlikely(!card->blockread))
100 return;
101
102 memcpy(card->blockread, mq->recvbuf->buf + 12,
103 card->blocklen/card->readcnt);
104
105}
106
107/* Interface with maple bus to read blocks
108 * caching the results so that other parts
109 * of the driver can access block reads */
110static int maple_vmu_read_block(unsigned int num, unsigned char *buf,
111 struct mtd_info *mtd)
112{
113 struct memcard *card;
114 struct mdev_part *mpart;
115 struct maple_device *mdev;
116 int partition, error = 0, x, wait;
117 unsigned char *blockread = NULL;
118 struct vmu_cache *pcache;
119 __be32 sendbuf;
120
121 mpart = mtd->priv;
122 mdev = mpart->mdev;
123 partition = mpart->partition;
124 card = maple_get_drvdata(mdev);
125 pcache = card->parts[partition].pcache;
126 pcache->valid = 0;
127
128 /* prepare the cache for this block */
129 if (!pcache->buffer) {
130 pcache->buffer = kmalloc(card->blocklen, GFP_KERNEL);
131 if (!pcache->buffer) {
132 dev_err(&mdev->dev, "VMU at (%d, %d) - read fails due"
133 " to lack of memory\n", mdev->port,
134 mdev->unit);
135 error = -ENOMEM;
136 goto outB;
137 }
138 }
139
140 /*
141 * Reads may be phased - again the hardware spec
142 * supports this - though may not be any devices in
143 * the wild that implement it, but we will here
144 */
145 for (x = 0; x < card->readcnt; x++) {
146 sendbuf = cpu_to_be32(partition << 24 | x << 16 | num);
147
148 if (atomic_read(&mdev->busy) == 1) {
149 wait_event_interruptible_timeout(mdev->maple_wait,
150 atomic_read(&mdev->busy) == 0, HZ);
151 if (atomic_read(&mdev->busy) == 1) {
152 dev_notice(&mdev->dev, "VMU at (%d, %d)"
153 " is busy\n", mdev->port, mdev->unit);
154 error = -EAGAIN;
155 goto outB;
156 }
157 }
158
159 atomic_set(&mdev->busy, 1);
160 blockread = kmalloc(card->blocklen/card->readcnt, GFP_KERNEL);
161 if (!blockread) {
162 error = -ENOMEM;
163 atomic_set(&mdev->busy, 0);
164 goto outB;
165 }
166 card->blockread = blockread;
167
168 maple_getcond_callback(mdev, vmu_blockread, 0,
169 MAPLE_FUNC_MEMCARD);
170 error = maple_add_packet(mdev, MAPLE_FUNC_MEMCARD,
171 MAPLE_COMMAND_BREAD, 2, &sendbuf);
172 /* Very long timeouts seem to be needed when box is stressed */
173 wait = wait_event_interruptible_timeout(mdev->maple_wait,
174 (atomic_read(&mdev->busy) == 0 ||
175 atomic_read(&mdev->busy) == 2), HZ * 3);
176 /*
177 * MTD layer does not handle hotplugging well
178 * so have to return errors when VMU is unplugged
179 * in the middle of a read (busy == 2)
180 */
181 if (error || atomic_read(&mdev->busy) == 2) {
182 if (atomic_read(&mdev->busy) == 2)
183 error = -ENXIO;
184 atomic_set(&mdev->busy, 0);
185 card->blockread = NULL;
186 goto outA;
187 }
188 if (wait == 0 || wait == -ERESTARTSYS) {
189 card->blockread = NULL;
190 atomic_set(&mdev->busy, 0);
191 error = -EIO;
192 list_del_init(&(mdev->mq->list));
193 kfree(mdev->mq->sendbuf);
194 mdev->mq->sendbuf = NULL;
195 if (wait == -ERESTARTSYS) {
196 dev_warn(&mdev->dev, "VMU read on (%d, %d)"
197 " interrupted on block 0x%X\n",
198 mdev->port, mdev->unit, num);
199 } else
200 dev_notice(&mdev->dev, "VMU read on (%d, %d)"
201 " timed out on block 0x%X\n",
202 mdev->port, mdev->unit, num);
203 goto outA;
204 }
205
206 memcpy(buf + (card->blocklen/card->readcnt) * x, blockread,
207 card->blocklen/card->readcnt);
208
209 memcpy(pcache->buffer + (card->blocklen/card->readcnt) * x,
210 card->blockread, card->blocklen/card->readcnt);
211 card->blockread = NULL;
212 pcache->block = num;
213 pcache->jiffies_atc = jiffies;
214 pcache->valid = 1;
215 kfree(blockread);
216 }
217
218 return error;
219
220outA:
221 kfree(blockread);
222outB:
223 return error;
224}
225
226/* communicate with maple bus for phased writing */
227static int maple_vmu_write_block(unsigned int num, const unsigned char *buf,
228 struct mtd_info *mtd)
229{
230 struct memcard *card;
231 struct mdev_part *mpart;
232 struct maple_device *mdev;
233 int partition, error, locking, x, phaselen, wait;
234 __be32 *sendbuf;
235
236 mpart = mtd->priv;
237 mdev = mpart->mdev;
238 partition = mpart->partition;
239 card = maple_get_drvdata(mdev);
240
241 phaselen = card->blocklen/card->writecnt;
242
243 sendbuf = kmalloc(phaselen + 4, GFP_KERNEL);
244 if (!sendbuf) {
245 error = -ENOMEM;
246 goto fail_nosendbuf;
247 }
248 for (x = 0; x < card->writecnt; x++) {
249 sendbuf[0] = cpu_to_be32(partition << 24 | x << 16 | num);
250 memcpy(&sendbuf[1], buf + phaselen * x, phaselen);
251 /* wait until the device is not busy doing something else
252 * or 1 second - which ever is longer */
253 if (atomic_read(&mdev->busy) == 1) {
254 wait_event_interruptible_timeout(mdev->maple_wait,
255 atomic_read(&mdev->busy) == 0, HZ);
256 if (atomic_read(&mdev->busy) == 1) {
257 error = -EBUSY;
258 dev_notice(&mdev->dev, "VMU write at (%d, %d)"
259 "failed - device is busy\n",
260 mdev->port, mdev->unit);
261 goto fail_nolock;
262 }
263 }
264 atomic_set(&mdev->busy, 1);
265
266 locking = maple_add_packet(mdev, MAPLE_FUNC_MEMCARD,
267 MAPLE_COMMAND_BWRITE, phaselen / 4 + 2, sendbuf);
268 wait = wait_event_interruptible_timeout(mdev->maple_wait,
269 atomic_read(&mdev->busy) == 0, HZ/10);
270 if (locking) {
271 error = -EIO;
272 atomic_set(&mdev->busy, 0);
273 goto fail_nolock;
274 }
275 if (atomic_read(&mdev->busy) == 2) {
276 atomic_set(&mdev->busy, 0);
277 } else if (wait == 0 || wait == -ERESTARTSYS) {
278 error = -EIO;
279 dev_warn(&mdev->dev, "Write at (%d, %d) of block"
280 " 0x%X at phase %d failed: could not"
281 " communicate with VMU", mdev->port,
282 mdev->unit, num, x);
283 atomic_set(&mdev->busy, 0);
284 kfree(mdev->mq->sendbuf);
285 mdev->mq->sendbuf = NULL;
286 list_del_init(&(mdev->mq->list));
287 goto fail_nolock;
288 }
289 }
290 kfree(sendbuf);
291
292 return card->blocklen;
293
294fail_nolock:
295 kfree(sendbuf);
296fail_nosendbuf:
297 dev_err(&mdev->dev, "VMU (%d, %d): write failed\n", mdev->port,
298 mdev->unit);
299 return error;
300}
301
302/* mtd function to simulate reading byte by byte */
303static unsigned char vmu_flash_read_char(unsigned long ofs, int *retval,
304 struct mtd_info *mtd)
305{
306 struct vmu_block *vblock;
307 struct memcard *card;
308 struct mdev_part *mpart;
309 struct maple_device *mdev;
310 unsigned char *buf, ret;
311 int partition, error;
312
313 mpart = mtd->priv;
314 mdev = mpart->mdev;
315 partition = mpart->partition;
316 card = maple_get_drvdata(mdev);
317 *retval = 0;
318
319 buf = kmalloc(card->blocklen, GFP_KERNEL);
320 if (!buf) {
321 *retval = 1;
322 ret = -ENOMEM;
323 goto finish;
324 }
325
326 vblock = ofs_to_block(ofs, mtd, partition);
327 if (!vblock) {
328 *retval = 3;
329 ret = -ENOMEM;
330 goto out_buf;
331 }
332
333 error = maple_vmu_read_block(vblock->num, buf, mtd);
334 if (error) {
335 ret = error;
336 *retval = 2;
337 goto out_vblock;
338 }
339
340 ret = buf[vblock->ofs];
341
342out_vblock:
343 kfree(vblock);
344out_buf:
345 kfree(buf);
346finish:
347 return ret;
348}
349
350/* mtd higher order function to read flash */
351static int vmu_flash_read(struct mtd_info *mtd, loff_t from, size_t len,
352 size_t *retlen, u_char *buf)
353{
354 struct maple_device *mdev;
355 struct memcard *card;
356 struct mdev_part *mpart;
357 struct vmu_cache *pcache;
358 struct vmu_block *vblock;
359 int index = 0, retval, partition, leftover, numblocks;
360 unsigned char cx;
361
362 if (len < 1)
363 return -EIO;
364
365 mpart = mtd->priv;
366 mdev = mpart->mdev;
367 partition = mpart->partition;
368 card = maple_get_drvdata(mdev);
369
370 numblocks = card->parts[partition].numblocks;
371 if (from + len > numblocks * card->blocklen)
372 len = numblocks * card->blocklen - from;
373 if (len == 0)
374 return -EIO;
375 /* Have we cached this bit already? */
376 pcache = card->parts[partition].pcache;
377 do {
378 vblock = ofs_to_block(from + index, mtd, partition);
379 if (!vblock)
380 return -ENOMEM;
381 /* Have we cached this and is the cache valid and timely? */
382 if (pcache->valid &&
383 time_before(jiffies, pcache->jiffies_atc + HZ) &&
384 (pcache->block == vblock->num)) {
385 /* we have cached it, so do necessary copying */
386 leftover = card->blocklen - vblock->ofs;
387 if (vblock->ofs + len - index < card->blocklen) {
388 /* only a bit of this block to copy */
389 memcpy(buf + index,
390 pcache->buffer + vblock->ofs,
391 len - index);
392 index = len;
393 } else {
394 /* otherwise copy remainder of whole block */
395 memcpy(buf + index, pcache->buffer +
396 vblock->ofs, leftover);
397 index += leftover;
398 }
399 } else {
400 /*
401 * Not cached so read one byte -
402 * but cache the rest of the block
403 */
404 cx = vmu_flash_read_char(from + index, &retval, mtd);
405 if (retval) {
406 *retlen = index;
407 kfree(vblock);
408 return cx;
409 }
410 memset(buf + index, cx, 1);
411 index++;
412 }
413 kfree(vblock);
414 } while (len > index);
415 *retlen = index;
416
417 return 0;
418}
419
420static int vmu_flash_write(struct mtd_info *mtd, loff_t to, size_t len,
421 size_t *retlen, const u_char *buf)
422{
423 struct maple_device *mdev;
424 struct memcard *card;
425 struct mdev_part *mpart;
426 int index = 0, partition, error = 0, numblocks;
427 struct vmu_cache *pcache;
428 struct vmu_block *vblock;
429 unsigned char *buffer;
430
431 mpart = mtd->priv;
432 mdev = mpart->mdev;
433 partition = mpart->partition;
434 card = maple_get_drvdata(mdev);
435
436 /* simple sanity checks */
437 if (len < 1) {
438 error = -EIO;
439 goto failed;
440 }
441 numblocks = card->parts[partition].numblocks;
442 if (to + len > numblocks * card->blocklen)
443 len = numblocks * card->blocklen - to;
444 if (len == 0) {
445 error = -EIO;
446 goto failed;
447 }
448
449 vblock = ofs_to_block(to, mtd, partition);
450 if (!vblock) {
451 error = -ENOMEM;
452 goto failed;
453 }
454
455 buffer = kmalloc(card->blocklen, GFP_KERNEL);
456 if (!buffer) {
457 error = -ENOMEM;
458 goto fail_buffer;
459 }
460
461 do {
462 /* Read in the block we are to write to */
463 error = maple_vmu_read_block(vblock->num, buffer, mtd);
464 if (error)
465 goto fail_io;
466
467 do {
468 buffer[vblock->ofs] = buf[index];
469 vblock->ofs++;
470 index++;
471 if (index >= len)
472 break;
473 } while (vblock->ofs < card->blocklen);
474
475 /* write out new buffer */
476 error = maple_vmu_write_block(vblock->num, buffer, mtd);
477 /* invalidate the cache */
478 pcache = card->parts[partition].pcache;
479 pcache->valid = 0;
480
481 if (error != card->blocklen)
482 goto fail_io;
483
484 vblock->num++;
485 vblock->ofs = 0;
486 } while (len > index);
487
488 kfree(buffer);
489 *retlen = index;
490 kfree(vblock);
491 return 0;
492
493fail_io:
494 kfree(buffer);
495fail_buffer:
496 kfree(vblock);
497failed:
498 dev_err(&mdev->dev, "VMU write failing with error %d\n", error);
499 return error;
500}
501
502static void vmu_flash_sync(struct mtd_info *mtd)
503{
504 /* Do nothing here */
505}
506
507/* Maple bus callback function to recursively query hardware details */
508static void vmu_queryblocks(struct mapleq *mq)
509{
510 struct maple_device *mdev;
511 unsigned short *res;
512 struct memcard *card;
513 __be32 partnum;
514 struct vmu_cache *pcache;
515 struct mdev_part *mpart;
516 struct mtd_info *mtd_cur;
517 struct vmupart *part_cur;
518 int error;
519
520 mdev = mq->dev;
521 card = maple_get_drvdata(mdev);
522 res = (unsigned short *) (mq->recvbuf->buf);
523 card->tempA = res[12];
524 card->tempB = res[6];
525
526 dev_info(&mdev->dev, "VMU device at partition %d has %d user "
527 "blocks with a root block at %d\n", card->partition,
528 card->tempA, card->tempB);
529
530 part_cur = &card->parts[card->partition];
531 part_cur->user_blocks = card->tempA;
532 part_cur->root_block = card->tempB;
533 part_cur->numblocks = card->tempB + 1;
534 part_cur->name = kmalloc(12, GFP_KERNEL);
535 if (!part_cur->name)
536 goto fail_name;
537
538 sprintf(part_cur->name, "vmu%d.%d.%d",
539 mdev->port, mdev->unit, card->partition);
540 mtd_cur = &card->mtd[card->partition];
541 mtd_cur->name = part_cur->name;
542 mtd_cur->type = 8;
543 mtd_cur->flags = MTD_WRITEABLE|MTD_NO_ERASE;
544 mtd_cur->size = part_cur->numblocks * card->blocklen;
545 mtd_cur->erasesize = card->blocklen;
546 mtd_cur->write = vmu_flash_write;
547 mtd_cur->read = vmu_flash_read;
548 mtd_cur->sync = vmu_flash_sync;
549 mtd_cur->writesize = card->blocklen;
550
551 mpart = kmalloc(sizeof(struct mdev_part), GFP_KERNEL);
552 if (!mpart)
553 goto fail_mpart;
554
555 mpart->mdev = mdev;
556 mpart->partition = card->partition;
557 mtd_cur->priv = mpart;
558 mtd_cur->owner = THIS_MODULE;
559
560 pcache = kzalloc(sizeof(struct vmu_cache), GFP_KERNEL);
561 if (!pcache)
562 goto fail_cache_create;
563 part_cur->pcache = pcache;
564
565 error = add_mtd_device(mtd_cur);
566 if (error)
567 goto fail_mtd_register;
568
569 maple_getcond_callback(mdev, NULL, 0,
570 MAPLE_FUNC_MEMCARD);
571
572 /*
573 * Set up a recursive call to the (probably theoretical)
574 * second or more partition
575 */
576 if (++card->partition < card->partitions) {
577 partnum = cpu_to_be32(card->partition << 24);
578 maple_getcond_callback(mdev, vmu_queryblocks, 0,
579 MAPLE_FUNC_MEMCARD);
580 maple_add_packet(mdev, MAPLE_FUNC_MEMCARD,
581 MAPLE_COMMAND_GETMINFO, 2, &partnum);
582 }
583 return;
584
585fail_mtd_register:
586 dev_err(&mdev->dev, "Could not register maple device at (%d, %d)"
587 "error is 0x%X\n", mdev->port, mdev->unit, error);
588 for (error = 0; error <= card->partition; error++) {
589 kfree(((card->parts)[error]).pcache);
590 ((card->parts)[error]).pcache = NULL;
591 }
592fail_cache_create:
593fail_mpart:
594 for (error = 0; error <= card->partition; error++) {
595 kfree(((card->mtd)[error]).priv);
596 ((card->mtd)[error]).priv = NULL;
597 }
598 maple_getcond_callback(mdev, NULL, 0,
599 MAPLE_FUNC_MEMCARD);
600 kfree(part_cur->name);
601fail_name:
602 return;
603}
604
605/* Handles very basic info about the flash, queries for details */
606static int __devinit vmu_connect(struct maple_device *mdev)
607{
608 unsigned long test_flash_data, basic_flash_data;
609 int c, error;
610 struct memcard *card;
611 u32 partnum = 0;
612
613 test_flash_data = be32_to_cpu(mdev->devinfo.function);
614 /* Need to count how many bits are set - to find out which
615 * function_data element has details of the memory card:
616 * using Brian Kernighan's/Peter Wegner's method */
617 for (c = 0; test_flash_data; c++)
618 test_flash_data &= test_flash_data - 1;
619
620 basic_flash_data = be32_to_cpu(mdev->devinfo.function_data[c - 1]);
621
622 card = kmalloc(sizeof(struct memcard), GFP_KERNEL);
623 if (!card) {
624 error = ENOMEM;
625 goto fail_nomem;
626 }
627
628 card->partitions = (basic_flash_data >> 24 & 0xFF) + 1;
629 card->blocklen = ((basic_flash_data >> 16 & 0xFF) + 1) << 5;
630 card->writecnt = basic_flash_data >> 12 & 0xF;
631 card->readcnt = basic_flash_data >> 8 & 0xF;
632 card->removeable = basic_flash_data >> 7 & 1;
633
634 card->partition = 0;
635
636 /*
637 * Not sure there are actually any multi-partition devices in the
638 * real world, but the hardware supports them, so, so will we
639 */
640 card->parts = kmalloc(sizeof(struct vmupart) * card->partitions,
641 GFP_KERNEL);
642 if (!card->parts) {
643 error = -ENOMEM;
644 goto fail_partitions;
645 }
646
647 card->mtd = kmalloc(sizeof(struct mtd_info) * card->partitions,
648 GFP_KERNEL);
649 if (!card->mtd) {
650 error = -ENOMEM;
651 goto fail_mtd_info;
652 }
653
654 maple_set_drvdata(mdev, card);
655
656 /*
657 * We want to trap meminfo not get cond
658 * so set interval to zero, but rely on maple bus
659 * driver to pass back the results of the meminfo
660 */
661 maple_getcond_callback(mdev, vmu_queryblocks, 0,
662 MAPLE_FUNC_MEMCARD);
663
664 /* Make sure we are clear to go */
665 if (atomic_read(&mdev->busy) == 1) {
666 wait_event_interruptible_timeout(mdev->maple_wait,
667 atomic_read(&mdev->busy) == 0, HZ);
668 if (atomic_read(&mdev->busy) == 1) {
669 dev_notice(&mdev->dev, "VMU at (%d, %d) is busy\n",
670 mdev->port, mdev->unit);
671 error = -EAGAIN;
672 goto fail_device_busy;
673 }
674 }
675
676 atomic_set(&mdev->busy, 1);
677
678 /*
679 * Set up the minfo call: vmu_queryblocks will handle
680 * the information passed back
681 */
682 error = maple_add_packet(mdev, MAPLE_FUNC_MEMCARD,
683 MAPLE_COMMAND_GETMINFO, 2, &partnum);
684 if (error) {
685 dev_err(&mdev->dev, "Could not lock VMU at (%d, %d)"
686 " error is 0x%X\n", mdev->port, mdev->unit, error);
687 goto fail_mtd_info;
688 }
689 return 0;
690
691fail_device_busy:
692 kfree(card->mtd);
693fail_mtd_info:
694 kfree(card->parts);
695fail_partitions:
696 kfree(card);
697fail_nomem:
698 return error;
699}
700
701static void __devexit vmu_disconnect(struct maple_device *mdev)
702{
703 struct memcard *card;
704 struct mdev_part *mpart;
705 int x;
706
707 mdev->callback = NULL;
708 card = maple_get_drvdata(mdev);
709 for (x = 0; x < card->partitions; x++) {
710 mpart = ((card->mtd)[x]).priv;
711 mpart->mdev = NULL;
712 del_mtd_device(&((card->mtd)[x]));
713 kfree(((card->parts)[x]).name);
714 }
715 kfree(card->parts);
716 kfree(card->mtd);
717 kfree(card);
718}
719
720/* Callback to handle eccentricities of both mtd subsystem
721 * and general flakyness of Dreamcast VMUs
722 */
723static int vmu_can_unload(struct maple_device *mdev)
724{
725 struct memcard *card;
726 int x;
727 struct mtd_info *mtd;
728
729 card = maple_get_drvdata(mdev);
730 for (x = 0; x < card->partitions; x++) {
731 mtd = &((card->mtd)[x]);
732 if (mtd->usecount > 0)
733 return 0;
734 }
735 return 1;
736}
737
738#define ERRSTR "VMU at (%d, %d) file error -"
739
740static void vmu_file_error(struct maple_device *mdev, void *recvbuf)
741{
742 enum maple_file_errors error = ((int *)recvbuf)[1];
743
744 switch (error) {
745
746 case MAPLE_FILEERR_INVALID_PARTITION:
747 dev_notice(&mdev->dev, ERRSTR " invalid partition number\n",
748 mdev->port, mdev->unit);
749 break;
750
751 case MAPLE_FILEERR_PHASE_ERROR:
752 dev_notice(&mdev->dev, ERRSTR " phase error\n",
753 mdev->port, mdev->unit);
754 break;
755
756 case MAPLE_FILEERR_INVALID_BLOCK:
757 dev_notice(&mdev->dev, ERRSTR " invalid block number\n",
758 mdev->port, mdev->unit);
759 break;
760
761 case MAPLE_FILEERR_WRITE_ERROR:
762 dev_notice(&mdev->dev, ERRSTR " write error\n",
763 mdev->port, mdev->unit);
764 break;
765
766 case MAPLE_FILEERR_INVALID_WRITE_LENGTH:
767 dev_notice(&mdev->dev, ERRSTR " invalid write length\n",
768 mdev->port, mdev->unit);
769 break;
770
771 case MAPLE_FILEERR_BAD_CRC:
772 dev_notice(&mdev->dev, ERRSTR " bad CRC\n",
773 mdev->port, mdev->unit);
774 break;
775
776 default:
777 dev_notice(&mdev->dev, ERRSTR " 0x%X\n",
778 mdev->port, mdev->unit, error);
779 }
780}
781
782
783static int __devinit probe_maple_vmu(struct device *dev)
784{
785 int error;
786 struct maple_device *mdev = to_maple_dev(dev);
787 struct maple_driver *mdrv = to_maple_driver(dev->driver);
788
789 mdev->can_unload = vmu_can_unload;
790 mdev->fileerr_handler = vmu_file_error;
791 mdev->driver = mdrv;
792
793 error = vmu_connect(mdev);
794 if (error)
795 return error;
796
797 return 0;
798}
799
800static int __devexit remove_maple_vmu(struct device *dev)
801{
802 struct maple_device *mdev = to_maple_dev(dev);
803
804 vmu_disconnect(mdev);
805 return 0;
806}
807
808static struct maple_driver vmu_flash_driver = {
809 .function = MAPLE_FUNC_MEMCARD,
810 .drv = {
811 .name = "Dreamcast_visual_memory",
812 .probe = probe_maple_vmu,
813 .remove = __devexit_p(remove_maple_vmu),
814 },
815};
816
817static int __init vmu_flash_map_init(void)
818{
819 return maple_driver_register(&vmu_flash_driver);
820}
821
822static void __exit vmu_flash_map_exit(void)
823{
824 maple_driver_unregister(&vmu_flash_driver);
825}
826
827module_init(vmu_flash_map_init);
828module_exit(vmu_flash_map_exit);
829
830MODULE_LICENSE("GPL");
831MODULE_AUTHOR("Adrian McMenamin");
832MODULE_DESCRIPTION("Flash mapping for Sega Dreamcast visual memory");
diff --git a/drivers/mtd/nand/excite_nandflash.c b/drivers/mtd/nand/excite_nandflash.c
index ced14b5294d5..72446fb48d4b 100644
--- a/drivers/mtd/nand/excite_nandflash.c
+++ b/drivers/mtd/nand/excite_nandflash.c
@@ -128,11 +128,11 @@ static int excite_nand_devready(struct mtd_info *mtd)
128 * The binding to the mtd and all allocated 128 * The binding to the mtd and all allocated
129 * resources are released. 129 * resources are released.
130 */ 130 */
131static int __exit excite_nand_remove(struct device *dev) 131static int __exit excite_nand_remove(struct platform_device *dev)
132{ 132{
133 struct excite_nand_drvdata * const this = dev_get_drvdata(dev); 133 struct excite_nand_drvdata * const this = platform_get_drvdata(dev);
134 134
135 dev_set_drvdata(dev, NULL); 135 platform_set_drvdata(dev, NULL);
136 136
137 if (unlikely(!this)) { 137 if (unlikely(!this)) {
138 printk(KERN_ERR "%s: called %s without private data!!", 138 printk(KERN_ERR "%s: called %s without private data!!",
@@ -159,9 +159,8 @@ static int __exit excite_nand_remove(struct device *dev)
159 * it can allocate all necessary resources then calls the 159 * it can allocate all necessary resources then calls the
160 * nand layer to look for devices. 160 * nand layer to look for devices.
161*/ 161*/
162static int __init excite_nand_probe(struct device *dev) 162static int __init excite_nand_probe(struct platform_device *pdev)
163{ 163{
164 struct platform_device * const pdev = to_platform_device(dev);
165 struct excite_nand_drvdata *drvdata; /* private driver data */ 164 struct excite_nand_drvdata *drvdata; /* private driver data */
166 struct nand_chip *board_chip; /* private flash chip data */ 165 struct nand_chip *board_chip; /* private flash chip data */
167 struct mtd_info *board_mtd; /* mtd info for this board */ 166 struct mtd_info *board_mtd; /* mtd info for this board */
@@ -175,7 +174,7 @@ static int __init excite_nand_probe(struct device *dev)
175 } 174 }
176 175
177 /* bind private data into driver */ 176 /* bind private data into driver */
178 dev_set_drvdata(dev, drvdata); 177 platform_set_drvdata(pdev, drvdata);
179 178
180 /* allocate and map the resource */ 179 /* allocate and map the resource */
181 drvdata->regs = 180 drvdata->regs =
@@ -219,23 +218,25 @@ static int __init excite_nand_probe(struct device *dev)
219 return 0; 218 return 0;
220} 219}
221 220
222static struct device_driver excite_nand_driver = { 221static struct platform_driver excite_nand_driver = {
223 .name = "excite_nand", 222 .driver = {
224 .bus = &platform_bus_type, 223 .name = "excite_nand",
224 .owner = THIS_MODULE,
225 },
225 .probe = excite_nand_probe, 226 .probe = excite_nand_probe,
226 .remove = __exit_p(excite_nand_remove) 227 .remove = __devexit_p(excite_nand_remove)
227}; 228};
228 229
229static int __init excite_nand_init(void) 230static int __init excite_nand_init(void)
230{ 231{
231 pr_info("Basler eXcite nand flash driver Version " 232 pr_info("Basler eXcite nand flash driver Version "
232 EXCITE_NANDFLASH_VERSION "\n"); 233 EXCITE_NANDFLASH_VERSION "\n");
233 return driver_register(&excite_nand_driver); 234 return platform_driver_register(&excite_nand_driver);
234} 235}
235 236
236static void __exit excite_nand_exit(void) 237static void __exit excite_nand_exit(void)
237{ 238{
238 driver_unregister(&excite_nand_driver); 239 platform_driver_unregister(&excite_nand_driver);
239} 240}
240 241
241module_init(excite_nand_init); 242module_init(excite_nand_init);
diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
index 582cf80f555a..89bf85af642c 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -187,7 +187,7 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
187 return -ENODEV; 187 return -ENODEV;
188 188
189 ndfc->mtd.name = kasprintf(GFP_KERNEL, "%s.%s", 189 ndfc->mtd.name = kasprintf(GFP_KERNEL, "%s.%s",
190 ndfc->ofdev->dev.bus_id, flash_np->name); 190 dev_name(&ndfc->ofdev->dev), flash_np->name);
191 if (!ndfc->mtd.name) { 191 if (!ndfc->mtd.name) {
192 ret = -ENOMEM; 192 ret = -ENOMEM;
193 goto err; 193 goto err;
diff --git a/drivers/mtd/onenand/generic.c b/drivers/mtd/onenand/generic.c
index 5b69e7773c6c..3a496c33fb52 100644
--- a/drivers/mtd/onenand/generic.c
+++ b/drivers/mtd/onenand/generic.c
@@ -36,10 +36,9 @@ struct onenand_info {
36 struct onenand_chip onenand; 36 struct onenand_chip onenand;
37}; 37};
38 38
39static int __devinit generic_onenand_probe(struct device *dev) 39static int __devinit generic_onenand_probe(struct platform_device *pdev)
40{ 40{
41 struct onenand_info *info; 41 struct onenand_info *info;
42 struct platform_device *pdev = to_platform_device(dev);
43 struct flash_platform_data *pdata = pdev->dev.platform_data; 42 struct flash_platform_data *pdata = pdev->dev.platform_data;
44 struct resource *res = pdev->resource; 43 struct resource *res = pdev->resource;
45 unsigned long size = res->end - res->start + 1; 44 unsigned long size = res->end - res->start + 1;
@@ -49,7 +48,7 @@ static int __devinit generic_onenand_probe(struct device *dev)
49 if (!info) 48 if (!info)
50 return -ENOMEM; 49 return -ENOMEM;
51 50
52 if (!request_mem_region(res->start, size, dev->driver->name)) { 51 if (!request_mem_region(res->start, size, pdev->dev.driver->name)) {
53 err = -EBUSY; 52 err = -EBUSY;
54 goto out_free_info; 53 goto out_free_info;
55 } 54 }
@@ -82,7 +81,7 @@ static int __devinit generic_onenand_probe(struct device *dev)
82#endif 81#endif
83 err = add_mtd_device(&info->mtd); 82 err = add_mtd_device(&info->mtd);
84 83
85 dev_set_drvdata(&pdev->dev, info); 84 platform_set_drvdata(pdev, info);
86 85
87 return 0; 86 return 0;
88 87
@@ -96,14 +95,13 @@ out_free_info:
96 return err; 95 return err;
97} 96}
98 97
99static int __devexit generic_onenand_remove(struct device *dev) 98static int __devexit generic_onenand_remove(struct platform_device *pdev)
100{ 99{
101 struct platform_device *pdev = to_platform_device(dev); 100 struct onenand_info *info = platform_get_drvdata(pdev);
102 struct onenand_info *info = dev_get_drvdata(&pdev->dev);
103 struct resource *res = pdev->resource; 101 struct resource *res = pdev->resource;
104 unsigned long size = res->end - res->start + 1; 102 unsigned long size = res->end - res->start + 1;
105 103
106 dev_set_drvdata(&pdev->dev, NULL); 104 platform_set_drvdata(pdev, NULL);
107 105
108 if (info) { 106 if (info) {
109 if (info->parts) 107 if (info->parts)
@@ -120,9 +118,11 @@ static int __devexit generic_onenand_remove(struct device *dev)
120 return 0; 118 return 0;
121} 119}
122 120
123static struct device_driver generic_onenand_driver = { 121static struct platform_driver generic_onenand_driver = {
124 .name = DRIVER_NAME, 122 .driver = {
125 .bus = &platform_bus_type, 123 .name = DRIVER_NAME,
124 .owner = THIS_MODULE,
125 },
126 .probe = generic_onenand_probe, 126 .probe = generic_onenand_probe,
127 .remove = __devexit_p(generic_onenand_remove), 127 .remove = __devexit_p(generic_onenand_remove),
128}; 128};
@@ -131,12 +131,12 @@ MODULE_ALIAS(DRIVER_NAME);
131 131
132static int __init generic_onenand_init(void) 132static int __init generic_onenand_init(void)
133{ 133{
134 return driver_register(&generic_onenand_driver); 134 return platform_driver_register(&generic_onenand_driver);
135} 135}
136 136
137static void __exit generic_onenand_exit(void) 137static void __exit generic_onenand_exit(void)
138{ 138{
139 driver_unregister(&generic_onenand_driver); 139 platform_driver_unregister(&generic_onenand_driver);
140} 140}
141 141
142module_init(generic_onenand_init); 142module_init(generic_onenand_init);
diff --git a/drivers/net/arm/ks8695net.c b/drivers/net/arm/ks8695net.c
index f3a127434897..35cd264abae7 100644
--- a/drivers/net/arm/ks8695net.c
+++ b/drivers/net/arm/ks8695net.c
@@ -1059,7 +1059,7 @@ ks8695_get_drvinfo(struct net_device *ndev, struct ethtool_drvinfo *info)
1059{ 1059{
1060 strlcpy(info->driver, MODULENAME, sizeof(info->driver)); 1060 strlcpy(info->driver, MODULENAME, sizeof(info->driver));
1061 strlcpy(info->version, MODULEVERSION, sizeof(info->version)); 1061 strlcpy(info->version, MODULEVERSION, sizeof(info->version));
1062 strlcpy(info->bus_info, ndev->dev.parent->bus_id, 1062 strlcpy(info->bus_info, dev_name(ndev->dev.parent),
1063 sizeof(info->bus_info)); 1063 sizeof(info->bus_info));
1064} 1064}
1065 1065
diff --git a/drivers/net/au1000_eth.c b/drivers/net/au1000_eth.c
index 9c875bb3f76c..79aec32c6add 100644
--- a/drivers/net/au1000_eth.c
+++ b/drivers/net/au1000_eth.c
@@ -355,8 +355,8 @@ static int mii_probe (struct net_device *dev)
355 /* now we are supposed to have a proper phydev, to attach to... */ 355 /* now we are supposed to have a proper phydev, to attach to... */
356 BUG_ON(phydev->attached_dev); 356 BUG_ON(phydev->attached_dev);
357 357
358 phydev = phy_connect(dev, phydev->dev.bus_id, &au1000_adjust_link, 0, 358 phydev = phy_connect(dev, dev_name(&phydev->dev), &au1000_adjust_link,
359 PHY_INTERFACE_MODE_MII); 359 0, PHY_INTERFACE_MODE_MII);
360 360
361 if (IS_ERR(phydev)) { 361 if (IS_ERR(phydev)) {
362 printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name); 362 printk(KERN_ERR "%s: Could not attach to PHY\n", dev->name);
@@ -381,8 +381,8 @@ static int mii_probe (struct net_device *dev)
381 aup->phy_dev = phydev; 381 aup->phy_dev = phydev;
382 382
383 printk(KERN_INFO "%s: attached PHY driver [%s] " 383 printk(KERN_INFO "%s: attached PHY driver [%s] "
384 "(mii_bus:phy_addr=%s, irq=%d)\n", 384 "(mii_bus:phy_addr=%s, irq=%d)\n", dev->name,
385 dev->name, phydev->drv->name, phydev->dev.bus_id, phydev->irq); 385 phydev->drv->name, dev_name(&phydev->dev), phydev->irq);
386 386
387 return 0; 387 return 0;
388} 388}
diff --git a/drivers/net/bfin_mac.c b/drivers/net/bfin_mac.c
index 78e31aa861e0..9afe8092dfc4 100644
--- a/drivers/net/bfin_mac.c
+++ b/drivers/net/bfin_mac.c
@@ -415,11 +415,11 @@ static int mii_probe(struct net_device *dev)
415 } 415 }
416 416
417#if defined(CONFIG_BFIN_MAC_RMII) 417#if defined(CONFIG_BFIN_MAC_RMII)
418 phydev = phy_connect(dev, phydev->dev.bus_id, &bfin_mac_adjust_link, 0, 418 phydev = phy_connect(dev, dev_name(&phydev->dev), &bfin_mac_adjust_link,
419 PHY_INTERFACE_MODE_RMII); 419 0, PHY_INTERFACE_MODE_RMII);
420#else 420#else
421 phydev = phy_connect(dev, phydev->dev.bus_id, &bfin_mac_adjust_link, 0, 421 phydev = phy_connect(dev, dev_name(&phydev->dev), &bfin_mac_adjust_link,
422 PHY_INTERFACE_MODE_MII); 422 0, PHY_INTERFACE_MODE_MII);
423#endif 423#endif
424 424
425 if (IS_ERR(phydev)) { 425 if (IS_ERR(phydev)) {
@@ -447,7 +447,7 @@ static int mii_probe(struct net_device *dev)
447 printk(KERN_INFO "%s: attached PHY driver [%s] " 447 printk(KERN_INFO "%s: attached PHY driver [%s] "
448 "(mii_bus:phy_addr=%s, irq=%d, mdc_clk=%dHz(mdc_div=%d)" 448 "(mii_bus:phy_addr=%s, irq=%d, mdc_clk=%dHz(mdc_div=%d)"
449 "@sclk=%dMHz)\n", 449 "@sclk=%dMHz)\n",
450 DRV_NAME, phydev->drv->name, phydev->dev.bus_id, phydev->irq, 450 DRV_NAME, phydev->drv->name, dev_name(&phydev->dev), phydev->irq,
451 MDC_CLK, mdc_div, sclk/1000000); 451 MDC_CLK, mdc_div, sclk/1000000);
452 452
453 return 0; 453 return 0;
@@ -488,7 +488,7 @@ static void bfin_mac_ethtool_getdrvinfo(struct net_device *dev,
488 strcpy(info->driver, DRV_NAME); 488 strcpy(info->driver, DRV_NAME);
489 strcpy(info->version, DRV_VERSION); 489 strcpy(info->version, DRV_VERSION);
490 strcpy(info->fw_version, "N/A"); 490 strcpy(info->fw_version, "N/A");
491 strcpy(info->bus_info, dev->dev.bus_id); 491 strcpy(info->bus_info, dev_name(&dev->dev));
492} 492}
493 493
494static struct ethtool_ops bfin_mac_ethtool_ops = { 494static struct ethtool_ops bfin_mac_ethtool_ops = {
diff --git a/drivers/net/bmac.c b/drivers/net/bmac.c
index 8a546a33d581..1ab58375d061 100644
--- a/drivers/net/bmac.c
+++ b/drivers/net/bmac.c
@@ -1240,7 +1240,7 @@ static void bmac_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *inf
1240{ 1240{
1241 struct bmac_data *bp = netdev_priv(dev); 1241 struct bmac_data *bp = netdev_priv(dev);
1242 strcpy(info->driver, "bmac"); 1242 strcpy(info->driver, "bmac");
1243 strcpy(info->bus_info, bp->mdev->ofdev.dev.bus_id); 1243 strcpy(info->bus_info, dev_name(&bp->mdev->ofdev.dev));
1244} 1244}
1245 1245
1246static const struct ethtool_ops bmac_ethtool_ops = { 1246static const struct ethtool_ops bmac_ethtool_ops = {
diff --git a/drivers/net/cpmac.c b/drivers/net/cpmac.c
index f66548751c38..79741c5f9fe7 100644
--- a/drivers/net/cpmac.c
+++ b/drivers/net/cpmac.c
@@ -1161,7 +1161,7 @@ static int __devinit cpmac_probe(struct platform_device *pdev)
1161 priv->msg_enable = netif_msg_init(debug_level, 0xff); 1161 priv->msg_enable = netif_msg_init(debug_level, 0xff);
1162 memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr)); 1162 memcpy(dev->dev_addr, pdata->dev_addr, sizeof(dev->dev_addr));
1163 1163
1164 priv->phy = phy_connect(dev, cpmac_mii->phy_map[phy_id]->dev.bus_id, 1164 priv->phy = phy_connect(dev, dev_name(&cpmac_mii->phy_map[phy_id]->dev),
1165 &cpmac_adjust_link, 0, PHY_INTERFACE_MODE_MII); 1165 &cpmac_adjust_link, 0, PHY_INTERFACE_MODE_MII);
1166 if (IS_ERR(priv->phy)) { 1166 if (IS_ERR(priv->phy)) {
1167 if (netif_msg_drv(priv)) 1167 if (netif_msg_drv(priv))
diff --git a/drivers/net/declance.c b/drivers/net/declance.c
index 7ce3053530f9..861c867fca87 100644
--- a/drivers/net/declance.c
+++ b/drivers/net/declance.c
@@ -1027,7 +1027,7 @@ static int __init dec_lance_probe(struct device *bdev, const int type)
1027 printk(version); 1027 printk(version);
1028 1028
1029 if (bdev) 1029 if (bdev)
1030 snprintf(name, sizeof(name), "%s", bdev->bus_id); 1030 snprintf(name, sizeof(name), "%s", dev_name(bdev));
1031 else { 1031 else {
1032 i = 0; 1032 i = 0;
1033 dev = root_lance_dev; 1033 dev = root_lance_dev;
@@ -1105,10 +1105,10 @@ static int __init dec_lance_probe(struct device *bdev, const int type)
1105 1105
1106 start = to_tc_dev(bdev)->resource.start; 1106 start = to_tc_dev(bdev)->resource.start;
1107 len = to_tc_dev(bdev)->resource.end - start + 1; 1107 len = to_tc_dev(bdev)->resource.end - start + 1;
1108 if (!request_mem_region(start, len, bdev->bus_id)) { 1108 if (!request_mem_region(start, len, dev_name(bdev))) {
1109 printk(KERN_ERR 1109 printk(KERN_ERR
1110 "%s: Unable to reserve MMIO resource\n", 1110 "%s: Unable to reserve MMIO resource\n",
1111 bdev->bus_id); 1111 dev_name(bdev));
1112 ret = -EBUSY; 1112 ret = -EBUSY;
1113 goto err_out_dev; 1113 goto err_out_dev;
1114 } 1114 }
diff --git a/drivers/net/depca.c b/drivers/net/depca.c
index e4cef491dc73..55625dbbae5a 100644
--- a/drivers/net/depca.c
+++ b/drivers/net/depca.c
@@ -606,8 +606,8 @@ static int __init depca_hw_init (struct net_device *dev, struct device *device)
606 if (!mem_start || lp->adapter < DEPCA || lp->adapter >=unknown) 606 if (!mem_start || lp->adapter < DEPCA || lp->adapter >=unknown)
607 return -ENXIO; 607 return -ENXIO;
608 608
609 printk ("%s: %s at 0x%04lx", 609 printk("%s: %s at 0x%04lx",
610 device->bus_id, depca_signature[lp->adapter], ioaddr); 610 dev_name(device), depca_signature[lp->adapter], ioaddr);
611 611
612 switch (lp->depca_bus) { 612 switch (lp->depca_bus) {
613#ifdef CONFIG_MCA 613#ifdef CONFIG_MCA
@@ -669,7 +669,7 @@ static int __init depca_hw_init (struct net_device *dev, struct device *device)
669 669
670 spin_lock_init(&lp->lock); 670 spin_lock_init(&lp->lock);
671 sprintf(lp->adapter_name, "%s (%s)", 671 sprintf(lp->adapter_name, "%s (%s)",
672 depca_signature[lp->adapter], device->bus_id); 672 depca_signature[lp->adapter], dev_name(device));
673 status = -EBUSY; 673 status = -EBUSY;
674 674
675 /* Initialisation Block */ 675 /* Initialisation Block */
diff --git a/drivers/net/ehea/ehea_main.c b/drivers/net/ehea/ehea_main.c
index dfe92264e825..8e7c16535ad7 100644
--- a/drivers/net/ehea/ehea_main.c
+++ b/drivers/net/ehea/ehea_main.c
@@ -3040,7 +3040,7 @@ static struct device *ehea_register_port(struct ehea_port *port,
3040 port->ofdev.dev.parent = &port->adapter->ofdev->dev; 3040 port->ofdev.dev.parent = &port->adapter->ofdev->dev;
3041 port->ofdev.dev.bus = &ibmebus_bus_type; 3041 port->ofdev.dev.bus = &ibmebus_bus_type;
3042 3042
3043 sprintf(port->ofdev.dev.bus_id, "port%d", port_name_cnt++); 3043 dev_set_name(&port->ofdev.dev, "port%d", port_name_cnt++);
3044 port->ofdev.dev.release = logical_port_release; 3044 port->ofdev.dev.release = logical_port_release;
3045 3045
3046 ret = of_device_register(&port->ofdev); 3046 ret = of_device_register(&port->ofdev);
diff --git a/drivers/net/jazzsonic.c b/drivers/net/jazzsonic.c
index 334ff9e12cdd..14248cfc3dfd 100644
--- a/drivers/net/jazzsonic.c
+++ b/drivers/net/jazzsonic.c
@@ -131,7 +131,8 @@ static int __init sonic_probe1(struct net_device *dev)
131 if (sonic_debug && version_printed++ == 0) 131 if (sonic_debug && version_printed++ == 0)
132 printk(version); 132 printk(version);
133 133
134 printk(KERN_INFO "%s: Sonic ethernet found at 0x%08lx, ", lp->device->bus_id, dev->base_addr); 134 printk(KERN_INFO "%s: Sonic ethernet found at 0x%08lx, ",
135 dev_name(lp->device), dev->base_addr);
135 136
136 /* 137 /*
137 * Put the sonic into software reset, then 138 * Put the sonic into software reset, then
@@ -156,7 +157,8 @@ static int __init sonic_probe1(struct net_device *dev)
156 if ((lp->descriptors = dma_alloc_coherent(lp->device, 157 if ((lp->descriptors = dma_alloc_coherent(lp->device,
157 SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), 158 SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
158 &lp->descriptors_laddr, GFP_KERNEL)) == NULL) { 159 &lp->descriptors_laddr, GFP_KERNEL)) == NULL) {
159 printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n", lp->device->bus_id); 160 printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n",
161 dev_name(lp->device));
160 goto out; 162 goto out;
161 } 163 }
162 164
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index f6c4936e2fa8..f4086542c358 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -211,10 +211,10 @@ static int macb_mii_probe(struct net_device *dev)
211 211
212 /* attach the mac to the phy */ 212 /* attach the mac to the phy */
213 if (pdata && pdata->is_rmii) { 213 if (pdata && pdata->is_rmii) {
214 phydev = phy_connect(dev, phydev->dev.bus_id, 214 phydev = phy_connect(dev, dev_name(&phydev->dev),
215 &macb_handle_link_change, 0, PHY_INTERFACE_MODE_RMII); 215 &macb_handle_link_change, 0, PHY_INTERFACE_MODE_RMII);
216 } else { 216 } else {
217 phydev = phy_connect(dev, phydev->dev.bus_id, 217 phydev = phy_connect(dev, dev_name(&phydev->dev),
218 &macb_handle_link_change, 0, PHY_INTERFACE_MODE_MII); 218 &macb_handle_link_change, 0, PHY_INTERFACE_MODE_MII);
219 } 219 }
220 220
@@ -1077,7 +1077,7 @@ static void macb_get_drvinfo(struct net_device *dev,
1077 1077
1078 strcpy(info->driver, bp->pdev->dev.driver->name); 1078 strcpy(info->driver, bp->pdev->dev.driver->name);
1079 strcpy(info->version, "$Revision: 1.14 $"); 1079 strcpy(info->version, "$Revision: 1.14 $");
1080 strcpy(info->bus_info, bp->pdev->dev.bus_id); 1080 strcpy(info->bus_info, dev_name(&bp->pdev->dev));
1081} 1081}
1082 1082
1083static struct ethtool_ops macb_ethtool_ops = { 1083static struct ethtool_ops macb_ethtool_ops = {
@@ -1234,8 +1234,8 @@ static int __init macb_probe(struct platform_device *pdev)
1234 1234
1235 phydev = bp->phy_dev; 1235 phydev = bp->phy_dev;
1236 printk(KERN_INFO "%s: attached PHY driver [%s] " 1236 printk(KERN_INFO "%s: attached PHY driver [%s] "
1237 "(mii_bus:phy_addr=%s, irq=%d)\n", 1237 "(mii_bus:phy_addr=%s, irq=%d)\n", dev->name,
1238 dev->name, phydev->drv->name, phydev->dev.bus_id, phydev->irq); 1238 phydev->drv->name, dev_name(&phydev->dev), phydev->irq);
1239 1239
1240 return 0; 1240 return 0;
1241 1241
diff --git a/drivers/net/macsonic.c b/drivers/net/macsonic.c
index 205bb05c25d6..527166e35d56 100644
--- a/drivers/net/macsonic.c
+++ b/drivers/net/macsonic.c
@@ -176,7 +176,8 @@ static int __init macsonic_init(struct net_device *dev)
176 if ((lp->descriptors = dma_alloc_coherent(lp->device, 176 if ((lp->descriptors = dma_alloc_coherent(lp->device,
177 SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode), 177 SIZEOF_SONIC_DESC * SONIC_BUS_SCALE(lp->dma_bitmode),
178 &lp->descriptors_laddr, GFP_KERNEL)) == NULL) { 178 &lp->descriptors_laddr, GFP_KERNEL)) == NULL) {
179 printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n", lp->device->bus_id); 179 printk(KERN_ERR "%s: couldn't alloc DMA memory for descriptors.\n",
180 dev_name(lp->device));
180 return -ENOMEM; 181 return -ENOMEM;
181 } 182 }
182 183
@@ -337,7 +338,7 @@ static int __init mac_onboard_sonic_probe(struct net_device *dev)
337 sonic_version_printed = 1; 338 sonic_version_printed = 1;
338 } 339 }
339 printk(KERN_INFO "%s: onboard / comm-slot SONIC at 0x%08lx\n", 340 printk(KERN_INFO "%s: onboard / comm-slot SONIC at 0x%08lx\n",
340 lp->device->bus_id, dev->base_addr); 341 dev_name(lp->device), dev->base_addr);
341 342
342 /* The PowerBook's SONIC is 16 bit always. */ 343 /* The PowerBook's SONIC is 16 bit always. */
343 if (macintosh_config->ident == MAC_MODEL_PB520) { 344 if (macintosh_config->ident == MAC_MODEL_PB520) {
@@ -370,10 +371,10 @@ static int __init mac_onboard_sonic_probe(struct net_device *dev)
370 } 371 }
371 printk(KERN_INFO 372 printk(KERN_INFO
372 "%s: revision 0x%04x, using %d bit DMA and register offset %d\n", 373 "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
373 lp->device->bus_id, sr, lp->dma_bitmode?32:16, lp->reg_offset); 374 dev_name(lp->device), sr, lp->dma_bitmode?32:16, lp->reg_offset);
374 375
375#if 0 /* This is sometimes useful to find out how MacOS configured the card. */ 376#if 0 /* This is sometimes useful to find out how MacOS configured the card. */
376 printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", lp->device->bus_id, 377 printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", dev_name(lp->device),
377 SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff); 378 SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff);
378#endif 379#endif
379 380
@@ -525,12 +526,12 @@ static int __init mac_nubus_sonic_probe(struct net_device *dev)
525 sonic_version_printed = 1; 526 sonic_version_printed = 1;
526 } 527 }
527 printk(KERN_INFO "%s: %s in slot %X\n", 528 printk(KERN_INFO "%s: %s in slot %X\n",
528 lp->device->bus_id, ndev->board->name, ndev->board->slot); 529 dev_name(lp->device), ndev->board->name, ndev->board->slot);
529 printk(KERN_INFO "%s: revision 0x%04x, using %d bit DMA and register offset %d\n", 530 printk(KERN_INFO "%s: revision 0x%04x, using %d bit DMA and register offset %d\n",
530 lp->device->bus_id, SONIC_READ(SONIC_SR), dma_bitmode?32:16, reg_offset); 531 dev_name(lp->device), SONIC_READ(SONIC_SR), dma_bitmode?32:16, reg_offset);
531 532
532#if 0 /* This is sometimes useful to find out how MacOS configured the card. */ 533#if 0 /* This is sometimes useful to find out how MacOS configured the card. */
533 printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", lp->device->bus_id, 534 printk(KERN_INFO "%s: DCR: 0x%04x, DCR2: 0x%04x\n", dev_name(lp->device),
534 SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff); 535 SONIC_READ(SONIC_DCR) & 0xffff, SONIC_READ(SONIC_DCR2) & 0xffff);
535#endif 536#endif
536 537
diff --git a/drivers/net/mipsnet.c b/drivers/net/mipsnet.c
index 4e7a5faf0351..664835b822fb 100644
--- a/drivers/net/mipsnet.c
+++ b/drivers/net/mipsnet.c
@@ -237,7 +237,7 @@ static void mipsnet_set_mclist(struct net_device *dev)
237{ 237{
238} 238}
239 239
240static int __init mipsnet_probe(struct device *dev) 240static int __init mipsnet_probe(struct platform_device *dev)
241{ 241{
242 struct net_device *netdev; 242 struct net_device *netdev;
243 int err; 243 int err;
@@ -248,7 +248,7 @@ static int __init mipsnet_probe(struct device *dev)
248 goto out; 248 goto out;
249 } 249 }
250 250
251 dev_set_drvdata(dev, netdev); 251 platform_set_drvdata(dev, netdev);
252 252
253 netdev->open = mipsnet_open; 253 netdev->open = mipsnet_open;
254 netdev->stop = mipsnet_close; 254 netdev->stop = mipsnet_close;
@@ -293,23 +293,25 @@ out:
293 return err; 293 return err;
294} 294}
295 295
296static int __devexit mipsnet_device_remove(struct device *device) 296static int __devexit mipsnet_device_remove(struct platform_device *device)
297{ 297{
298 struct net_device *dev = dev_get_drvdata(device); 298 struct net_device *dev = platform_get_drvdata(device);
299 299
300 unregister_netdev(dev); 300 unregister_netdev(dev);
301 release_region(dev->base_addr, sizeof(struct mipsnet_regs)); 301 release_region(dev->base_addr, sizeof(struct mipsnet_regs));
302 free_netdev(dev); 302 free_netdev(dev);
303 dev_set_drvdata(device, NULL); 303 platform_set_drvdata(device, NULL);
304 304
305 return 0; 305 return 0;
306} 306}
307 307
308static struct device_driver mipsnet_driver = { 308static struct platform_driver mipsnet_driver = {
309 .name = mipsnet_string, 309 .driver = {
310 .bus = &platform_bus_type, 310 .name = mipsnet_string,
311 .probe = mipsnet_probe, 311 .owner = THIS_MODULE,
312 .remove = __devexit_p(mipsnet_device_remove), 312 },
313 .probe = mipsnet_probe,
314 .remove = __devexit_p(mipsnet_device_remove),
313}; 315};
314 316
315static int __init mipsnet_init_module(void) 317static int __init mipsnet_init_module(void)
@@ -319,7 +321,7 @@ static int __init mipsnet_init_module(void)
319 printk(KERN_INFO "MIPSNet Ethernet driver. Version: %s. " 321 printk(KERN_INFO "MIPSNet Ethernet driver. Version: %s. "
320 "(c)2005 MIPS Technologies, Inc.\n", MIPSNET_VERSION); 322 "(c)2005 MIPS Technologies, Inc.\n", MIPSNET_VERSION);
321 323
322 err = driver_register(&mipsnet_driver); 324 err = platform_driver_register(&mipsnet_driver);
323 if (err) 325 if (err)
324 printk(KERN_ERR "Driver registration failed\n"); 326 printk(KERN_ERR "Driver registration failed\n");
325 327
@@ -328,7 +330,7 @@ static int __init mipsnet_init_module(void)
328 330
329static void __exit mipsnet_exit_module(void) 331static void __exit mipsnet_exit_module(void)
330{ 332{
331 driver_unregister(&mipsnet_driver); 333 platform_driver_unregister(&mipsnet_driver);
332} 334}
333 335
334module_init(mipsnet_init_module); 336module_init(mipsnet_init_module);
diff --git a/drivers/net/mv643xx_eth.c b/drivers/net/mv643xx_eth.c
index b0bc3bc18e9c..fe4e158c893d 100644
--- a/drivers/net/mv643xx_eth.c
+++ b/drivers/net/mv643xx_eth.c
@@ -2588,7 +2588,7 @@ static void phy_init(struct mv643xx_eth_private *mp, int speed, int duplex)
2588 2588
2589 phy_reset(mp); 2589 phy_reset(mp);
2590 2590
2591 phy_attach(mp->dev, phy->dev.bus_id, 0, PHY_INTERFACE_MODE_GMII); 2591 phy_attach(mp->dev, dev_name(&phy->dev), 0, PHY_INTERFACE_MODE_GMII);
2592 2592
2593 if (speed == 0) { 2593 if (speed == 0) {
2594 phy->autoneg = AUTONEG_ENABLE; 2594 phy->autoneg = AUTONEG_ENABLE;
diff --git a/drivers/net/sb1250-mac.c b/drivers/net/sb1250-mac.c
index 31e38fae017f..845431c186ac 100644
--- a/drivers/net/sb1250-mac.c
+++ b/drivers/net/sb1250-mac.c
@@ -2478,7 +2478,7 @@ static int sbmac_mii_probe(struct net_device *dev)
2478 return -ENXIO; 2478 return -ENXIO;
2479 } 2479 }
2480 2480
2481 phy_dev = phy_connect(dev, phy_dev->dev.bus_id, &sbmac_mii_poll, 0, 2481 phy_dev = phy_connect(dev, dev_name(&phy_dev->dev), &sbmac_mii_poll, 0,
2482 PHY_INTERFACE_MODE_GMII); 2482 PHY_INTERFACE_MODE_GMII);
2483 if (IS_ERR(phy_dev)) { 2483 if (IS_ERR(phy_dev)) {
2484 printk(KERN_ERR "%s: could not attach to PHY\n", dev->name); 2484 printk(KERN_ERR "%s: could not attach to PHY\n", dev->name);
@@ -2500,7 +2500,7 @@ static int sbmac_mii_probe(struct net_device *dev)
2500 2500
2501 pr_info("%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n", 2501 pr_info("%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
2502 dev->name, phy_dev->drv->name, 2502 dev->name, phy_dev->drv->name,
2503 phy_dev->dev.bus_id, phy_dev->irq); 2503 dev_name(&phy_dev->dev), phy_dev->irq);
2504 2504
2505 sc->phy_dev = phy_dev; 2505 sc->phy_dev = phy_dev;
2506 2506
@@ -2697,7 +2697,7 @@ static int __init sbmac_probe(struct platform_device *pldev)
2697 sbm_base = ioremap_nocache(res->start, res->end - res->start + 1); 2697 sbm_base = ioremap_nocache(res->start, res->end - res->start + 1);
2698 if (!sbm_base) { 2698 if (!sbm_base) {
2699 printk(KERN_ERR "%s: unable to map device registers\n", 2699 printk(KERN_ERR "%s: unable to map device registers\n",
2700 pldev->dev.bus_id); 2700 dev_name(&pldev->dev));
2701 err = -ENOMEM; 2701 err = -ENOMEM;
2702 goto out_out; 2702 goto out_out;
2703 } 2703 }
@@ -2708,7 +2708,7 @@ static int __init sbmac_probe(struct platform_device *pldev)
2708 * If we find a zero, skip this MAC. 2708 * If we find a zero, skip this MAC.
2709 */ 2709 */
2710 sbmac_orig_hwaddr = __raw_readq(sbm_base + R_MAC_ETHERNET_ADDR); 2710 sbmac_orig_hwaddr = __raw_readq(sbm_base + R_MAC_ETHERNET_ADDR);
2711 pr_debug("%s: %sconfiguring MAC at 0x%08Lx\n", pldev->dev.bus_id, 2711 pr_debug("%s: %sconfiguring MAC at 0x%08Lx\n", dev_name(&pldev->dev),
2712 sbmac_orig_hwaddr ? "" : "not ", (long long)res->start); 2712 sbmac_orig_hwaddr ? "" : "not ", (long long)res->start);
2713 if (sbmac_orig_hwaddr == 0) { 2713 if (sbmac_orig_hwaddr == 0) {
2714 err = 0; 2714 err = 0;
@@ -2721,7 +2721,7 @@ static int __init sbmac_probe(struct platform_device *pldev)
2721 dev = alloc_etherdev(sizeof(struct sbmac_softc)); 2721 dev = alloc_etherdev(sizeof(struct sbmac_softc));
2722 if (!dev) { 2722 if (!dev) {
2723 printk(KERN_ERR "%s: unable to allocate etherdev\n", 2723 printk(KERN_ERR "%s: unable to allocate etherdev\n",
2724 pldev->dev.bus_id); 2724 dev_name(&pldev->dev));
2725 err = -ENOMEM; 2725 err = -ENOMEM;
2726 goto out_unmap; 2726 goto out_unmap;
2727 } 2727 }
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 223cde0d43be..293610334a77 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -1545,7 +1545,7 @@ smc911x_ethtool_getdrvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1545{ 1545{
1546 strncpy(info->driver, CARDNAME, sizeof(info->driver)); 1546 strncpy(info->driver, CARDNAME, sizeof(info->driver));
1547 strncpy(info->version, version, sizeof(info->version)); 1547 strncpy(info->version, version, sizeof(info->version));
1548 strncpy(info->bus_info, dev->dev.parent->bus_id, sizeof(info->bus_info)); 1548 strncpy(info->bus_info, dev_name(dev->dev.parent), sizeof(info->bus_info));
1549} 1549}
1550 1550
1551static int smc911x_ethtool_nwayreset(struct net_device *dev) 1551static int smc911x_ethtool_nwayreset(struct net_device *dev)
diff --git a/drivers/net/smc91x.c b/drivers/net/smc91x.c
index b215a8d85e62..0b6da9501444 100644
--- a/drivers/net/smc91x.c
+++ b/drivers/net/smc91x.c
@@ -1614,7 +1614,7 @@ smc_ethtool_getdrvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
1614{ 1614{
1615 strncpy(info->driver, CARDNAME, sizeof(info->driver)); 1615 strncpy(info->driver, CARDNAME, sizeof(info->driver));
1616 strncpy(info->version, version, sizeof(info->version)); 1616 strncpy(info->version, version, sizeof(info->version));
1617 strncpy(info->bus_info, dev->dev.parent->bus_id, sizeof(info->bus_info)); 1617 strncpy(info->bus_info, dev_name(dev->dev.parent), sizeof(info->bus_info));
1618} 1618}
1619 1619
1620static int smc_ethtool_nwayreset(struct net_device *dev) 1620static int smc_ethtool_nwayreset(struct net_device *dev)
diff --git a/drivers/net/smsc911x.c b/drivers/net/smsc911x.c
index d1590ac55e4b..ab18ee0f60f3 100644
--- a/drivers/net/smsc911x.c
+++ b/drivers/net/smsc911x.c
@@ -769,7 +769,7 @@ static int smsc911x_mii_probe(struct net_device *dev)
769 return -ENODEV; 769 return -ENODEV;
770 } 770 }
771 771
772 phydev = phy_connect(dev, phydev->dev.bus_id, 772 phydev = phy_connect(dev, dev_name(&phydev->dev),
773 &smsc911x_phy_adjust_link, 0, pdata->config.phy_interface); 773 &smsc911x_phy_adjust_link, 0, pdata->config.phy_interface);
774 774
775 if (IS_ERR(phydev)) { 775 if (IS_ERR(phydev)) {
@@ -778,7 +778,8 @@ static int smsc911x_mii_probe(struct net_device *dev)
778 } 778 }
779 779
780 pr_info("%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n", 780 pr_info("%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
781 dev->name, phydev->drv->name, phydev->dev.bus_id, phydev->irq); 781 dev->name, phydev->drv->name,
782 dev_name(&phydev->dev), phydev->irq);
782 783
783 /* mask with MAC supported features */ 784 /* mask with MAC supported features */
784 phydev->supported &= (PHY_BASIC_FEATURES | SUPPORTED_Pause | 785 phydev->supported &= (PHY_BASIC_FEATURES | SUPPORTED_Pause |
@@ -1549,7 +1550,7 @@ static void smsc911x_ethtool_getdrvinfo(struct net_device *dev,
1549{ 1550{
1550 strlcpy(info->driver, SMSC_CHIPNAME, sizeof(info->driver)); 1551 strlcpy(info->driver, SMSC_CHIPNAME, sizeof(info->driver));
1551 strlcpy(info->version, SMSC_DRV_VERSION, sizeof(info->version)); 1552 strlcpy(info->version, SMSC_DRV_VERSION, sizeof(info->version));
1552 strlcpy(info->bus_info, dev->dev.parent->bus_id, 1553 strlcpy(info->bus_info, dev_name(dev->dev.parent),
1553 sizeof(info->bus_info)); 1554 sizeof(info->bus_info));
1554} 1555}
1555 1556
diff --git a/drivers/net/smsc9420.c b/drivers/net/smsc9420.c
index 4e15ae068b3f..72f1348eb809 100644
--- a/drivers/net/smsc9420.c
+++ b/drivers/net/smsc9420.c
@@ -1160,7 +1160,7 @@ static int smsc9420_mii_probe(struct net_device *dev)
1160 smsc_info(PROBE, "PHY addr %d, phy_id 0x%08X", phydev->addr, 1160 smsc_info(PROBE, "PHY addr %d, phy_id 0x%08X", phydev->addr,
1161 phydev->phy_id); 1161 phydev->phy_id);
1162 1162
1163 phydev = phy_connect(dev, phydev->dev.bus_id, 1163 phydev = phy_connect(dev, dev_name(&phydev->dev),
1164 &smsc9420_phy_adjust_link, 0, PHY_INTERFACE_MODE_MII); 1164 &smsc9420_phy_adjust_link, 0, PHY_INTERFACE_MODE_MII);
1165 1165
1166 if (IS_ERR(phydev)) { 1166 if (IS_ERR(phydev)) {
@@ -1169,7 +1169,7 @@ static int smsc9420_mii_probe(struct net_device *dev)
1169 } 1169 }
1170 1170
1171 pr_info("%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n", 1171 pr_info("%s: attached PHY driver [%s] (mii_bus:phy_addr=%s, irq=%d)\n",
1172 dev->name, phydev->drv->name, phydev->dev.bus_id, phydev->irq); 1172 dev->name, phydev->drv->name, dev_name(&phydev->dev), phydev->irq);
1173 1173
1174 /* mask with MAC supported features */ 1174 /* mask with MAC supported features */
1175 phydev->supported &= (PHY_BASIC_FEATURES | SUPPORTED_Pause | 1175 phydev->supported &= (PHY_BASIC_FEATURES | SUPPORTED_Pause |
diff --git a/drivers/net/tc35815.c b/drivers/net/tc35815.c
index bcd0e60cbda9..e1f8eb96a45c 100644
--- a/drivers/net/tc35815.c
+++ b/drivers/net/tc35815.c
@@ -725,7 +725,7 @@ static int tc_mii_probe(struct net_device *dev)
725 } 725 }
726 726
727 /* attach the mac to the phy */ 727 /* attach the mac to the phy */
728 phydev = phy_connect(dev, phydev->dev.bus_id, 728 phydev = phy_connect(dev, dev_name(&phydev->dev),
729 &tc_handle_link_change, 0, 729 &tc_handle_link_change, 0,
730 lp->chiptype == TC35815_TX4939 ? 730 lp->chiptype == TC35815_TX4939 ?
731 PHY_INTERFACE_MODE_RMII : PHY_INTERFACE_MODE_MII); 731 PHY_INTERFACE_MODE_RMII : PHY_INTERFACE_MODE_MII);
@@ -735,7 +735,7 @@ static int tc_mii_probe(struct net_device *dev)
735 } 735 }
736 printk(KERN_INFO "%s: attached PHY driver [%s] " 736 printk(KERN_INFO "%s: attached PHY driver [%s] "
737 "(mii_bus:phy_addr=%s, id=%x)\n", 737 "(mii_bus:phy_addr=%s, id=%x)\n",
738 dev->name, phydev->drv->name, phydev->dev.bus_id, 738 dev->name, phydev->drv->name, dev_name(&phydev->dev),
739 phydev->phy_id); 739 phydev->phy_id);
740 740
741 /* mask with MAC supported features */ 741 /* mask with MAC supported features */
diff --git a/drivers/net/wimax/i2400m/driver.c b/drivers/net/wimax/i2400m/driver.c
index e80a0b65a754..d58b971faa64 100644
--- a/drivers/net/wimax/i2400m/driver.c
+++ b/drivers/net/wimax/i2400m/driver.c
@@ -613,7 +613,7 @@ int i2400m_setup(struct i2400m *i2400m, enum i2400m_bri bm_flags)
613 d_fnstart(3, dev, "(i2400m %p)\n", i2400m); 613 d_fnstart(3, dev, "(i2400m %p)\n", i2400m);
614 614
615 snprintf(wimax_dev->name, sizeof(wimax_dev->name), 615 snprintf(wimax_dev->name, sizeof(wimax_dev->name),
616 "i2400m-%s:%s", dev->bus->name, dev->bus_id); 616 "i2400m-%s:%s", dev->bus->name, dev_name(dev));
617 617
618 i2400m->bm_cmd_buf = kzalloc(I2400M_BM_CMD_BUF_SIZE, GFP_KERNEL); 618 i2400m->bm_cmd_buf = kzalloc(I2400M_BM_CMD_BUF_SIZE, GFP_KERNEL);
619 if (i2400m->bm_cmd_buf == NULL) { 619 if (i2400m->bm_cmd_buf == NULL) {
diff --git a/drivers/net/wimax/i2400m/usb-notif.c b/drivers/net/wimax/i2400m/usb-notif.c
index 9702c22b2497..0528879f6d39 100644
--- a/drivers/net/wimax/i2400m/usb-notif.c
+++ b/drivers/net/wimax/i2400m/usb-notif.c
@@ -102,7 +102,7 @@ int i2400mu_notification_grok(struct i2400mu *i2400mu, const void *buf,
102 dev_err(dev, "HW BUG? Unknown/unexpected data in notification " 102 dev_err(dev, "HW BUG? Unknown/unexpected data in notification "
103 "message (%zu bytes)\n", buf_len); 103 "message (%zu bytes)\n", buf_len);
104 snprintf(prefix, sizeof(prefix), "%s %s: ", 104 snprintf(prefix, sizeof(prefix), "%s %s: ",
105 dev_driver_string(dev) , dev->bus_id); 105 dev_driver_string(dev) , dev_name(dev));
106 if (buf_len > 64) { 106 if (buf_len > 64) {
107 print_hex_dump(KERN_ERR, prefix, DUMP_PREFIX_OFFSET, 107 print_hex_dump(KERN_ERR, prefix, DUMP_PREFIX_OFFSET,
108 8, 4, buf, 64, 0); 108 8, 4, buf, 64, 0);
diff --git a/drivers/net/xtsonic.c b/drivers/net/xtsonic.c
index 03a3f34e9039..a12a7211c982 100644
--- a/drivers/net/xtsonic.c
+++ b/drivers/net/xtsonic.c
@@ -183,7 +183,7 @@ static int __init sonic_probe1(struct net_device *dev)
183 183
184 if (lp->descriptors == NULL) { 184 if (lp->descriptors == NULL) {
185 printk(KERN_ERR "%s: couldn't alloc DMA memory for " 185 printk(KERN_ERR "%s: couldn't alloc DMA memory for "
186 " descriptors.\n", lp->device->bus_id); 186 " descriptors.\n", dev_name(lp->device));
187 goto out; 187 goto out;
188 } 188 }
189 189
diff --git a/drivers/pci/hotplug/cpqphp_sysfs.c b/drivers/pci/hotplug/cpqphp_sysfs.c
index a13abf55d784..8450f4a6568a 100644
--- a/drivers/pci/hotplug/cpqphp_sysfs.c
+++ b/drivers/pci/hotplug/cpqphp_sysfs.c
@@ -225,7 +225,8 @@ void cpqhp_shutdown_debugfs(void)
225 225
226void cpqhp_create_debugfs_files(struct controller *ctrl) 226void cpqhp_create_debugfs_files(struct controller *ctrl)
227{ 227{
228 ctrl->dentry = debugfs_create_file(ctrl->pci_dev->dev.bus_id, S_IRUGO, root, ctrl, &debug_ops); 228 ctrl->dentry = debugfs_create_file(dev_name(&ctrl->pci_dev->dev),
229 S_IRUGO, root, ctrl, &debug_ops);
229} 230}
230 231
231void cpqhp_remove_debugfs_files(struct controller *ctrl) 232void cpqhp_remove_debugfs_files(struct controller *ctrl)
diff --git a/drivers/pcmcia/au1000_generic.c b/drivers/pcmcia/au1000_generic.c
index fc1de46fd20a..90013341cd5f 100644
--- a/drivers/pcmcia/au1000_generic.c
+++ b/drivers/pcmcia/au1000_generic.c
@@ -468,13 +468,13 @@ out:
468 return ret; 468 return ret;
469} 469}
470 470
471int au1x00_drv_pcmcia_remove(struct device *dev) 471int au1x00_drv_pcmcia_remove(struct platform_device *dev)
472{ 472{
473 struct skt_dev_info *sinfo = dev_get_drvdata(dev); 473 struct skt_dev_info *sinfo = platform_get_drvdata(dev);
474 int i; 474 int i;
475 475
476 mutex_lock(&pcmcia_sockets_lock); 476 mutex_lock(&pcmcia_sockets_lock);
477 dev_set_drvdata(dev, NULL); 477 platform_set_drvdata(dev, NULL);
478 478
479 for (i = 0; i < sinfo->nskt; i++) { 479 for (i = 0; i < sinfo->nskt; i++) {
480 struct au1000_pcmcia_socket *skt = PCMCIA_SOCKET(i); 480 struct au1000_pcmcia_socket *skt = PCMCIA_SOCKET(i);
@@ -498,13 +498,13 @@ int au1x00_drv_pcmcia_remove(struct device *dev)
498 * PCMCIA "Driver" API 498 * PCMCIA "Driver" API
499 */ 499 */
500 500
501static int au1x00_drv_pcmcia_probe(struct device *dev) 501static int au1x00_drv_pcmcia_probe(struct platform_device *dev)
502{ 502{
503 int i, ret = -ENODEV; 503 int i, ret = -ENODEV;
504 504
505 mutex_lock(&pcmcia_sockets_lock); 505 mutex_lock(&pcmcia_sockets_lock);
506 for (i=0; i < ARRAY_SIZE(au1x00_pcmcia_hw_init); i++) { 506 for (i=0; i < ARRAY_SIZE(au1x00_pcmcia_hw_init); i++) {
507 ret = au1x00_pcmcia_hw_init[i](dev); 507 ret = au1x00_pcmcia_hw_init[i](&dev->dev);
508 if (ret == 0) 508 if (ret == 0)
509 break; 509 break;
510 } 510 }
@@ -512,14 +512,26 @@ static int au1x00_drv_pcmcia_probe(struct device *dev)
512 return ret; 512 return ret;
513} 513}
514 514
515static int au1x00_drv_pcmcia_suspend(struct platform_device *dev,
516 pm_message_t state)
517{
518 return pcmcia_socket_dev_suspend(&dev->dev, state);
519}
520
521static int au1x00_drv_pcmcia_resume(struct platform_device *dev)
522{
523 return pcmcia_socket_dev_resume(&dev->dev);
524}
515 525
516static struct device_driver au1x00_pcmcia_driver = { 526static struct platform_driver au1x00_pcmcia_driver = {
527 .driver = {
528 .name = "au1x00-pcmcia",
529 .owner = THIS_MODULE,
530 },
517 .probe = au1x00_drv_pcmcia_probe, 531 .probe = au1x00_drv_pcmcia_probe,
518 .remove = au1x00_drv_pcmcia_remove, 532 .remove = au1x00_drv_pcmcia_remove,
519 .name = "au1x00-pcmcia", 533 .suspend = au1x00_drv_pcmcia_suspend,
520 .bus = &platform_bus_type, 534 .resume = au1x00_drv_pcmcia_resume,
521 .suspend = pcmcia_socket_dev_suspend,
522 .resume = pcmcia_socket_dev_resume,
523}; 535};
524 536
525 537
@@ -533,8 +545,7 @@ static struct device_driver au1x00_pcmcia_driver = {
533static int __init au1x00_pcmcia_init(void) 545static int __init au1x00_pcmcia_init(void)
534{ 546{
535 int error = 0; 547 int error = 0;
536 if ((error = driver_register(&au1x00_pcmcia_driver))) 548 error = platform_driver_register(&au1x00_pcmcia_driver);
537 return error;
538 return error; 549 return error;
539} 550}
540 551
@@ -544,7 +555,7 @@ static int __init au1x00_pcmcia_init(void)
544 */ 555 */
545static void __exit au1x00_pcmcia_exit(void) 556static void __exit au1x00_pcmcia_exit(void)
546{ 557{
547 driver_unregister(&au1x00_pcmcia_driver); 558 platform_driver_unregister(&au1x00_pcmcia_driver);
548} 559}
549 560
550module_init(au1x00_pcmcia_init); 561module_init(au1x00_pcmcia_init);
diff --git a/drivers/pcmcia/i82365.c b/drivers/pcmcia/i82365.c
index 71653ab84890..40d4953e4b12 100644
--- a/drivers/pcmcia/i82365.c
+++ b/drivers/pcmcia/i82365.c
@@ -1238,6 +1238,16 @@ static int pcic_init(struct pcmcia_socket *s)
1238 return 0; 1238 return 0;
1239} 1239}
1240 1240
1241static int i82365_drv_pcmcia_suspend(struct platform_device *dev,
1242 pm_message_t state)
1243{
1244 return pcmcia_socket_dev_suspend(&dev->dev, state);
1245}
1246
1247static int i82365_drv_pcmcia_resume(struct platform_device *dev)
1248{
1249 return pcmcia_socket_dev_resume(&dev->dev);
1250}
1241static struct pccard_operations pcic_operations = { 1251static struct pccard_operations pcic_operations = {
1242 .init = pcic_init, 1252 .init = pcic_init,
1243 .get_status = pcic_get_status, 1253 .get_status = pcic_get_status,
@@ -1248,11 +1258,13 @@ static struct pccard_operations pcic_operations = {
1248 1258
1249/*====================================================================*/ 1259/*====================================================================*/
1250 1260
1251static struct device_driver i82365_driver = { 1261static struct platform_driver i82365_driver = {
1252 .name = "i82365", 1262 .driver = {
1253 .bus = &platform_bus_type, 1263 .name = "i82365",
1254 .suspend = pcmcia_socket_dev_suspend, 1264 .owner = THIS_MODULE,
1255 .resume = pcmcia_socket_dev_resume, 1265 },
1266 .suspend = i82365_drv_pcmcia_suspend,
1267 .resume = i82365_drv_pcmcia_resume,
1256}; 1268};
1257 1269
1258static struct platform_device *i82365_device; 1270static struct platform_device *i82365_device;
@@ -1261,7 +1273,7 @@ static int __init init_i82365(void)
1261{ 1273{
1262 int i, ret; 1274 int i, ret;
1263 1275
1264 ret = driver_register(&i82365_driver); 1276 ret = platform_driver_register(&i82365_driver);
1265 if (ret) 1277 if (ret)
1266 goto err_out; 1278 goto err_out;
1267 1279
@@ -1337,7 +1349,7 @@ err_dev_unregister:
1337 pnp_disable_dev(i82365_pnpdev); 1349 pnp_disable_dev(i82365_pnpdev);
1338#endif 1350#endif
1339err_driver_unregister: 1351err_driver_unregister:
1340 driver_unregister(&i82365_driver); 1352 platform_driver_unregister(&i82365_driver);
1341err_out: 1353err_out:
1342 return ret; 1354 return ret;
1343} /* init_i82365 */ 1355} /* init_i82365 */
@@ -1365,7 +1377,7 @@ static void __exit exit_i82365(void)
1365 if (i82365_pnpdev) 1377 if (i82365_pnpdev)
1366 pnp_disable_dev(i82365_pnpdev); 1378 pnp_disable_dev(i82365_pnpdev);
1367#endif 1379#endif
1368 driver_unregister(&i82365_driver); 1380 platform_driver_unregister(&i82365_driver);
1369} /* exit_i82365 */ 1381} /* exit_i82365 */
1370 1382
1371module_init(init_i82365); 1383module_init(init_i82365);
diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c
index 2ab4f22c21de..62b4ecc97c46 100644
--- a/drivers/pcmcia/m32r_cfc.c
+++ b/drivers/pcmcia/m32r_cfc.c
@@ -696,13 +696,25 @@ static struct pccard_operations pcc_operations = {
696 .set_mem_map = pcc_set_mem_map, 696 .set_mem_map = pcc_set_mem_map,
697}; 697};
698 698
699static int cfc_drv_pcmcia_suspend(struct platform_device *dev,
700 pm_message_t state)
701{
702 return pcmcia_socket_dev_suspend(&dev->dev, state);
703}
704
705static int cfc_drv_pcmcia_resume(struct platform_device *dev)
706{
707 return pcmcia_socket_dev_resume(&dev->dev);
708}
699/*====================================================================*/ 709/*====================================================================*/
700 710
701static struct device_driver pcc_driver = { 711static struct platform_driver pcc_driver = {
702 .name = "cfc", 712 .driver = {
703 .bus = &platform_bus_type, 713 .name = "cfc",
704 .suspend = pcmcia_socket_dev_suspend, 714 .owner = THIS_MODULE,
705 .resume = pcmcia_socket_dev_resume, 715 },
716 .suspend = cfc_drv_pcmcia_suspend,
717 .resume = cfc_drv_pcmcia_resume,
706}; 718};
707 719
708static struct platform_device pcc_device = { 720static struct platform_device pcc_device = {
@@ -716,13 +728,13 @@ static int __init init_m32r_pcc(void)
716{ 728{
717 int i, ret; 729 int i, ret;
718 730
719 ret = driver_register(&pcc_driver); 731 ret = platform_driver_register(&pcc_driver);
720 if (ret) 732 if (ret)
721 return ret; 733 return ret;
722 734
723 ret = platform_device_register(&pcc_device); 735 ret = platform_device_register(&pcc_device);
724 if (ret){ 736 if (ret){
725 driver_unregister(&pcc_driver); 737 platform_driver_unregister(&pcc_driver);
726 return ret; 738 return ret;
727 } 739 }
728 740
@@ -754,7 +766,7 @@ static int __init init_m32r_pcc(void)
754 if (pcc_sockets == 0) { 766 if (pcc_sockets == 0) {
755 printk("socket is not found.\n"); 767 printk("socket is not found.\n");
756 platform_device_unregister(&pcc_device); 768 platform_device_unregister(&pcc_device);
757 driver_unregister(&pcc_driver); 769 platform_driver_unregister(&pcc_driver);
758 return -ENODEV; 770 return -ENODEV;
759 } 771 }
760 772
@@ -802,7 +814,7 @@ static void __exit exit_m32r_pcc(void)
802 if (poll_interval != 0) 814 if (poll_interval != 0)
803 del_timer_sync(&poll_timer); 815 del_timer_sync(&poll_timer);
804 816
805 driver_unregister(&pcc_driver); 817 platform_driver_unregister(&pcc_driver);
806} /* exit_m32r_pcc */ 818} /* exit_m32r_pcc */
807 819
808module_init(init_m32r_pcc); 820module_init(init_m32r_pcc);
diff --git a/drivers/pcmcia/m32r_pcc.c b/drivers/pcmcia/m32r_pcc.c
index 2f108c23dbd9..12034b41d196 100644
--- a/drivers/pcmcia/m32r_pcc.c
+++ b/drivers/pcmcia/m32r_pcc.c
@@ -672,13 +672,25 @@ static struct pccard_operations pcc_operations = {
672 .set_mem_map = pcc_set_mem_map, 672 .set_mem_map = pcc_set_mem_map,
673}; 673};
674 674
675static int pcc_drv_pcmcia_suspend(struct platform_device *dev,
676 pm_message_t state)
677{
678 return pcmcia_socket_dev_suspend(&dev->dev, state);
679}
680
681static int pcc_drv_pcmcia_resume(struct platform_device *dev)
682{
683 return pcmcia_socket_dev_resume(&dev->dev);
684}
675/*====================================================================*/ 685/*====================================================================*/
676 686
677static struct device_driver pcc_driver = { 687static struct platform_driver pcc_driver = {
678 .name = "pcc", 688 .driver = {
679 .bus = &platform_bus_type, 689 .name = "pcc",
680 .suspend = pcmcia_socket_dev_suspend, 690 .owner = THIS_MODULE,
681 .resume = pcmcia_socket_dev_resume, 691 },
692 .suspend = pcc_drv_pcmcia_suspend,
693 .resume = pcc_drv_pcmcia_resume,
682}; 694};
683 695
684static struct platform_device pcc_device = { 696static struct platform_device pcc_device = {
@@ -692,13 +704,13 @@ static int __init init_m32r_pcc(void)
692{ 704{
693 int i, ret; 705 int i, ret;
694 706
695 ret = driver_register(&pcc_driver); 707 ret = platform_driver_register(&pcc_driver);
696 if (ret) 708 if (ret)
697 return ret; 709 return ret;
698 710
699 ret = platform_device_register(&pcc_device); 711 ret = platform_device_register(&pcc_device);
700 if (ret){ 712 if (ret){
701 driver_unregister(&pcc_driver); 713 platform_driver_unregister(&pcc_driver);
702 return ret; 714 return ret;
703 } 715 }
704 716
@@ -715,7 +727,7 @@ static int __init init_m32r_pcc(void)
715 if (pcc_sockets == 0) { 727 if (pcc_sockets == 0) {
716 printk("socket is not found.\n"); 728 printk("socket is not found.\n");
717 platform_device_unregister(&pcc_device); 729 platform_device_unregister(&pcc_device);
718 driver_unregister(&pcc_driver); 730 platform_driver_unregister(&pcc_driver);
719 return -ENODEV; 731 return -ENODEV;
720 } 732 }
721 733
@@ -763,7 +775,7 @@ static void __exit exit_m32r_pcc(void)
763 if (poll_interval != 0) 775 if (poll_interval != 0)
764 del_timer_sync(&poll_timer); 776 del_timer_sync(&poll_timer);
765 777
766 driver_unregister(&pcc_driver); 778 platform_driver_unregister(&pcc_driver);
767} /* exit_m32r_pcc */ 779} /* exit_m32r_pcc */
768 780
769module_init(init_m32r_pcc); 781module_init(init_m32r_pcc);
diff --git a/drivers/pcmcia/rsrc_mgr.c b/drivers/pcmcia/rsrc_mgr.c
index c0e2afc79e3e..e592e0e0d7ed 100644
--- a/drivers/pcmcia/rsrc_mgr.c
+++ b/drivers/pcmcia/rsrc_mgr.c
@@ -153,7 +153,7 @@ static struct resource *iodyn_find_io_region(unsigned long base, int num,
153 unsigned long align, struct pcmcia_socket *s) 153 unsigned long align, struct pcmcia_socket *s)
154{ 154{
155 struct resource *res = make_resource(0, num, IORESOURCE_IO, 155 struct resource *res = make_resource(0, num, IORESOURCE_IO,
156 s->dev.bus_id); 156 dev_name(&s->dev));
157 struct pcmcia_align_data data; 157 struct pcmcia_align_data data;
158 unsigned long min = base; 158 unsigned long min = base;
159 int ret; 159 int ret;
diff --git a/drivers/pcmcia/sa1100_generic.c b/drivers/pcmcia/sa1100_generic.c
index c5b2a44b4c37..d8da5ac844e9 100644
--- a/drivers/pcmcia/sa1100_generic.c
+++ b/drivers/pcmcia/sa1100_generic.c
@@ -65,7 +65,7 @@ static int (*sa11x0_pcmcia_hw_init[])(struct device *dev) = {
65#endif 65#endif
66}; 66};
67 67
68static int sa11x0_drv_pcmcia_probe(struct device *dev) 68static int sa11x0_drv_pcmcia_probe(struct platform_device *dev)
69{ 69{
70 int i, ret = -ENODEV; 70 int i, ret = -ENODEV;
71 71
@@ -73,7 +73,7 @@ static int sa11x0_drv_pcmcia_probe(struct device *dev)
73 * Initialise any "on-board" PCMCIA sockets. 73 * Initialise any "on-board" PCMCIA sockets.
74 */ 74 */
75 for (i = 0; i < ARRAY_SIZE(sa11x0_pcmcia_hw_init); i++) { 75 for (i = 0; i < ARRAY_SIZE(sa11x0_pcmcia_hw_init); i++) {
76 ret = sa11x0_pcmcia_hw_init[i](dev); 76 ret = sa11x0_pcmcia_hw_init[i](&dev->dev);
77 if (ret == 0) 77 if (ret == 0)
78 break; 78 break;
79 } 79 }
@@ -81,13 +81,31 @@ static int sa11x0_drv_pcmcia_probe(struct device *dev)
81 return ret; 81 return ret;
82} 82}
83 83
84static struct device_driver sa11x0_pcmcia_driver = { 84static int sa11x0_drv_pcmcia_remove(struct platform_device *dev)
85{
86 return soc_common_drv_pcmcia_remove(&dev->dev);
87}
88
89static int sa11x0_drv_pcmcia_suspend(struct platform_device *dev,
90 pm_message_t state)
91{
92 return pcmcia_socket_dev_suspend(&dev->dev, state);
93}
94
95static int sa11x0_drv_pcmcia_resume(struct platform_device *dev)
96{
97 return pcmcia_socket_dev_resume(&dev->dev);
98}
99
100static struct platform_driver sa11x0_pcmcia_driver = {
101 .driver = {
102 .name = "sa11x0-pcmcia",
103 .owner = THIS_MODULE,
104 },
85 .probe = sa11x0_drv_pcmcia_probe, 105 .probe = sa11x0_drv_pcmcia_probe,
86 .remove = soc_common_drv_pcmcia_remove, 106 .remove = sa11x0_drv_pcmcia_remove,
87 .name = "sa11x0-pcmcia", 107 .suspend = sa11x0_drv_pcmcia_suspend,
88 .bus = &platform_bus_type, 108 .resume = sa11x0_drv_pcmcia_resume,
89 .suspend = pcmcia_socket_dev_suspend,
90 .resume = pcmcia_socket_dev_resume,
91}; 109};
92 110
93/* sa11x0_pcmcia_init() 111/* sa11x0_pcmcia_init()
@@ -100,7 +118,7 @@ static struct device_driver sa11x0_pcmcia_driver = {
100 */ 118 */
101static int __init sa11x0_pcmcia_init(void) 119static int __init sa11x0_pcmcia_init(void)
102{ 120{
103 return driver_register(&sa11x0_pcmcia_driver); 121 return platform_driver_register(&sa11x0_pcmcia_driver);
104} 122}
105 123
106/* sa11x0_pcmcia_exit() 124/* sa11x0_pcmcia_exit()
@@ -110,7 +128,7 @@ static int __init sa11x0_pcmcia_init(void)
110 */ 128 */
111static void __exit sa11x0_pcmcia_exit(void) 129static void __exit sa11x0_pcmcia_exit(void)
112{ 130{
113 driver_unregister(&sa11x0_pcmcia_driver); 131 platform_driver_unregister(&sa11x0_pcmcia_driver);
114} 132}
115 133
116MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>"); 134MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");
diff --git a/drivers/pcmcia/tcic.c b/drivers/pcmcia/tcic.c
index 2a613e920fd4..9ad97ea836e8 100644
--- a/drivers/pcmcia/tcic.c
+++ b/drivers/pcmcia/tcic.c
@@ -363,13 +363,25 @@ static int __init get_tcic_id(void)
363 return id; 363 return id;
364} 364}
365 365
366static int tcic_drv_pcmcia_suspend(struct platform_device *dev,
367 pm_message_t state)
368{
369 return pcmcia_socket_dev_suspend(&dev->dev, state);
370}
371
372static int tcic_drv_pcmcia_resume(struct platform_device *dev)
373{
374 return pcmcia_socket_dev_resume(&dev->dev);
375}
366/*====================================================================*/ 376/*====================================================================*/
367 377
368static struct device_driver tcic_driver = { 378static struct platform_driver tcic_driver = {
369 .name = "tcic-pcmcia", 379 .driver = {
370 .bus = &platform_bus_type, 380 .name = "tcic-pcmcia",
371 .suspend = pcmcia_socket_dev_suspend, 381 .owner = THIS_MODULE,
372 .resume = pcmcia_socket_dev_resume, 382 },
383 .suspend = tcic_drv_pcmcia_suspend,
384 .resume = tcic_drv_pcmcia_resume,
373}; 385};
374 386
375static struct platform_device tcic_device = { 387static struct platform_device tcic_device = {
@@ -383,7 +395,7 @@ static int __init init_tcic(void)
383 int i, sock, ret = 0; 395 int i, sock, ret = 0;
384 u_int mask, scan; 396 u_int mask, scan;
385 397
386 if (driver_register(&tcic_driver)) 398 if (platform_driver_register(&tcic_driver))
387 return -1; 399 return -1;
388 400
389 printk(KERN_INFO "Databook TCIC-2 PCMCIA probe: "); 401 printk(KERN_INFO "Databook TCIC-2 PCMCIA probe: ");
@@ -391,7 +403,7 @@ static int __init init_tcic(void)
391 403
392 if (!request_region(tcic_base, 16, "tcic-2")) { 404 if (!request_region(tcic_base, 16, "tcic-2")) {
393 printk("could not allocate ports,\n "); 405 printk("could not allocate ports,\n ");
394 driver_unregister(&tcic_driver); 406 platform_driver_unregister(&tcic_driver);
395 return -ENODEV; 407 return -ENODEV;
396 } 408 }
397 else { 409 else {
@@ -414,7 +426,7 @@ static int __init init_tcic(void)
414 if (sock == 0) { 426 if (sock == 0) {
415 printk("not found.\n"); 427 printk("not found.\n");
416 release_region(tcic_base, 16); 428 release_region(tcic_base, 16);
417 driver_unregister(&tcic_driver); 429 platform_driver_unregister(&tcic_driver);
418 return -ENODEV; 430 return -ENODEV;
419 } 431 }
420 432
@@ -542,7 +554,7 @@ static void __exit exit_tcic(void)
542 } 554 }
543 555
544 platform_device_unregister(&tcic_device); 556 platform_device_unregister(&tcic_device);
545 driver_unregister(&tcic_driver); 557 platform_driver_unregister(&tcic_driver);
546} /* exit_tcic */ 558} /* exit_tcic */
547 559
548/*====================================================================*/ 560/*====================================================================*/
diff --git a/drivers/pcmcia/vrc4171_card.c b/drivers/pcmcia/vrc4171_card.c
index b2c412419059..659421d0ca46 100644
--- a/drivers/pcmcia/vrc4171_card.c
+++ b/drivers/pcmcia/vrc4171_card.c
@@ -704,24 +704,37 @@ static int __devinit vrc4171_card_setup(char *options)
704 704
705__setup("vrc4171_card=", vrc4171_card_setup); 705__setup("vrc4171_card=", vrc4171_card_setup);
706 706
707static struct device_driver vrc4171_card_driver = { 707static int vrc4171_card_suspend(struct platform_device *dev,
708 .name = vrc4171_card_name, 708 pm_message_t state)
709 .bus = &platform_bus_type, 709{
710 .suspend = pcmcia_socket_dev_suspend, 710 return pcmcia_socket_dev_suspend(&dev->dev, state);
711 .resume = pcmcia_socket_dev_resume, 711}
712
713static int vrc4171_card_resume(struct platform_device *dev)
714{
715 return pcmcia_socket_dev_resume(&dev->dev);
716}
717
718static struct platform_driver vrc4171_card_driver = {
719 .driver = {
720 .name = vrc4171_card_name,
721 .owner = THIS_MODULE,
722 },
723 .suspend = vrc4171_card_suspend,
724 .resume = vrc4171_card_resume,
712}; 725};
713 726
714static int __devinit vrc4171_card_init(void) 727static int __devinit vrc4171_card_init(void)
715{ 728{
716 int retval; 729 int retval;
717 730
718 retval = driver_register(&vrc4171_card_driver); 731 retval = platform_driver_register(&vrc4171_card_driver);
719 if (retval < 0) 732 if (retval < 0)
720 return retval; 733 return retval;
721 734
722 retval = platform_device_register(&vrc4171_card_device); 735 retval = platform_device_register(&vrc4171_card_device);
723 if (retval < 0) { 736 if (retval < 0) {
724 driver_unregister(&vrc4171_card_driver); 737 platform_driver_unregister(&vrc4171_card_driver);
725 return retval; 738 return retval;
726 } 739 }
727 740
@@ -735,11 +748,12 @@ static int __devinit vrc4171_card_init(void)
735 if (retval < 0) { 748 if (retval < 0) {
736 vrc4171_remove_sockets(); 749 vrc4171_remove_sockets();
737 platform_device_unregister(&vrc4171_card_device); 750 platform_device_unregister(&vrc4171_card_device);
738 driver_unregister(&vrc4171_card_driver); 751 platform_driver_unregister(&vrc4171_card_driver);
739 return retval; 752 return retval;
740 } 753 }
741 754
742 printk(KERN_INFO "%s, connected to IRQ %d\n", vrc4171_card_driver.name, vrc4171_irq); 755 printk(KERN_INFO "%s, connected to IRQ %d\n",
756 vrc4171_card_driver.driver.name, vrc4171_irq);
743 757
744 return 0; 758 return 0;
745} 759}
@@ -749,7 +763,7 @@ static void __devexit vrc4171_card_exit(void)
749 free_irq(vrc4171_irq, vrc4171_sockets); 763 free_irq(vrc4171_irq, vrc4171_sockets);
750 vrc4171_remove_sockets(); 764 vrc4171_remove_sockets();
751 platform_device_unregister(&vrc4171_card_device); 765 platform_device_unregister(&vrc4171_card_device);
752 driver_unregister(&vrc4171_card_driver); 766 platform_driver_unregister(&vrc4171_card_driver);
753} 767}
754 768
755module_init(vrc4171_card_init); 769module_init(vrc4171_card_init);
diff --git a/drivers/rapidio/rio-driver.c b/drivers/rapidio/rio-driver.c
index addb87cf44d9..3222fa3c808c 100644
--- a/drivers/rapidio/rio-driver.c
+++ b/drivers/rapidio/rio-driver.c
@@ -193,7 +193,7 @@ static int rio_match_bus(struct device *dev, struct device_driver *drv)
193} 193}
194 194
195static struct device rio_bus = { 195static struct device rio_bus = {
196 .bus_id = "rapidio", 196 .init_name = "rapidio",
197}; 197};
198 198
199struct bus_type rio_bus_type = { 199struct bus_type rio_bus_type = {
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index d5e4e637ddec..86c61f143515 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -351,7 +351,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
351 /* register irq handler after we know what name we'll use */ 351 /* register irq handler after we know what name we'll use */
352 ret = request_irq(AT91_ID_SYS, at91_rtc_interrupt, 352 ret = request_irq(AT91_ID_SYS, at91_rtc_interrupt,
353 IRQF_DISABLED | IRQF_SHARED, 353 IRQF_DISABLED | IRQF_SHARED,
354 rtc->rtcdev->dev.bus_id, rtc); 354 dev_name(&rtc->rtcdev->dev), rtc);
355 if (ret) { 355 if (ret) {
356 dev_dbg(&pdev->dev, "can't share IRQ %d?\n", AT91_ID_SYS); 356 dev_dbg(&pdev->dev, "can't share IRQ %d?\n", AT91_ID_SYS);
357 rtc_device_unregister(rtc->rtcdev); 357 rtc_device_unregister(rtc->rtcdev);
@@ -366,7 +366,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
366 366
367 if (gpbr_readl(rtc) == 0) 367 if (gpbr_readl(rtc) == 0)
368 dev_warn(&pdev->dev, "%s: SET TIME!\n", 368 dev_warn(&pdev->dev, "%s: SET TIME!\n",
369 rtc->rtcdev->dev.bus_id); 369 dev_name(&rtc->rtcdev->dev));
370 370
371 return 0; 371 return 0;
372 372
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 2cbeb0794f14..bd1ce8e2bc18 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -377,13 +377,13 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
377 377
378 /* handle periodic and alarm irqs */ 378 /* handle periodic and alarm irqs */
379 if (request_irq(omap_rtc_timer, rtc_irq, IRQF_DISABLED, 379 if (request_irq(omap_rtc_timer, rtc_irq, IRQF_DISABLED,
380 rtc->dev.bus_id, rtc)) { 380 dev_name(&rtc->dev), rtc)) {
381 pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n", 381 pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n",
382 pdev->name, omap_rtc_timer); 382 pdev->name, omap_rtc_timer);
383 goto fail0; 383 goto fail0;
384 } 384 }
385 if (request_irq(omap_rtc_alarm, rtc_irq, IRQF_DISABLED, 385 if (request_irq(omap_rtc_alarm, rtc_irq, IRQF_DISABLED,
386 rtc->dev.bus_id, rtc)) { 386 dev_name(&rtc->dev), rtc)) {
387 pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n", 387 pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n",
388 pdev->name, omap_rtc_alarm); 388 pdev->name, omap_rtc_alarm);
389 goto fail1; 389 goto fail1;
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 1c3fc6b428e9..4898f7fe8518 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -28,7 +28,7 @@
28#include <asm/rtc.h> 28#include <asm/rtc.h>
29 29
30#define DRV_NAME "sh-rtc" 30#define DRV_NAME "sh-rtc"
31#define DRV_VERSION "0.2.0" 31#define DRV_VERSION "0.2.1"
32 32
33#define RTC_REG(r) ((r) * rtc_reg_size) 33#define RTC_REG(r) ((r) * rtc_reg_size)
34 34
@@ -99,56 +99,51 @@ struct sh_rtc {
99 unsigned short periodic_freq; 99 unsigned short periodic_freq;
100}; 100};
101 101
102static irqreturn_t sh_rtc_interrupt(int irq, void *dev_id) 102static int __sh_rtc_interrupt(struct sh_rtc *rtc)
103{ 103{
104 struct sh_rtc *rtc = dev_id; 104 unsigned int tmp, pending;
105 unsigned int tmp;
106
107 spin_lock(&rtc->lock);
108 105
109 tmp = readb(rtc->regbase + RCR1); 106 tmp = readb(rtc->regbase + RCR1);
107 pending = tmp & RCR1_CF;
110 tmp &= ~RCR1_CF; 108 tmp &= ~RCR1_CF;
111 writeb(tmp, rtc->regbase + RCR1); 109 writeb(tmp, rtc->regbase + RCR1);
112 110
113 /* Users have requested One x Second IRQ */ 111 /* Users have requested One x Second IRQ */
114 if (rtc->periodic_freq & PF_OXS) 112 if (pending && rtc->periodic_freq & PF_OXS)
115 rtc_update_irq(rtc->rtc_dev, 1, RTC_UF | RTC_IRQF); 113 rtc_update_irq(rtc->rtc_dev, 1, RTC_UF | RTC_IRQF);
116 114
117 spin_unlock(&rtc->lock); 115 return pending;
118
119 return IRQ_HANDLED;
120} 116}
121 117
122static irqreturn_t sh_rtc_alarm(int irq, void *dev_id) 118static int __sh_rtc_alarm(struct sh_rtc *rtc)
123{ 119{
124 struct sh_rtc *rtc = dev_id; 120 unsigned int tmp, pending;
125 unsigned int tmp;
126
127 spin_lock(&rtc->lock);
128 121
129 tmp = readb(rtc->regbase + RCR1); 122 tmp = readb(rtc->regbase + RCR1);
123 pending = tmp & RCR1_AF;
130 tmp &= ~(RCR1_AF | RCR1_AIE); 124 tmp &= ~(RCR1_AF | RCR1_AIE);
131 writeb(tmp, rtc->regbase + RCR1); 125 writeb(tmp, rtc->regbase + RCR1);
132
133 rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF);
134 126
135 spin_unlock(&rtc->lock); 127 if (pending)
128 rtc_update_irq(rtc->rtc_dev, 1, RTC_AF | RTC_IRQF);
136 129
137 return IRQ_HANDLED; 130 return pending;
138} 131}
139 132
140static irqreturn_t sh_rtc_periodic(int irq, void *dev_id) 133static int __sh_rtc_periodic(struct sh_rtc *rtc)
141{ 134{
142 struct sh_rtc *rtc = dev_id;
143 struct rtc_device *rtc_dev = rtc->rtc_dev; 135 struct rtc_device *rtc_dev = rtc->rtc_dev;
144 unsigned int tmp; 136 struct rtc_task *irq_task;
145 137 unsigned int tmp, pending;
146 spin_lock(&rtc->lock);
147 138
148 tmp = readb(rtc->regbase + RCR2); 139 tmp = readb(rtc->regbase + RCR2);
140 pending = tmp & RCR2_PEF;
149 tmp &= ~RCR2_PEF; 141 tmp &= ~RCR2_PEF;
150 writeb(tmp, rtc->regbase + RCR2); 142 writeb(tmp, rtc->regbase + RCR2);
151 143
144 if (!pending)
145 return 0;
146
152 /* Half period enabled than one skipped and the next notified */ 147 /* Half period enabled than one skipped and the next notified */
153 if ((rtc->periodic_freq & PF_HP) && (rtc->periodic_freq & PF_COUNT)) 148 if ((rtc->periodic_freq & PF_HP) && (rtc->periodic_freq & PF_COUNT))
154 rtc->periodic_freq &= ~PF_COUNT; 149 rtc->periodic_freq &= ~PF_COUNT;
@@ -157,16 +152,65 @@ static irqreturn_t sh_rtc_periodic(int irq, void *dev_id)
157 rtc->periodic_freq |= PF_COUNT; 152 rtc->periodic_freq |= PF_COUNT;
158 if (rtc->periodic_freq & PF_KOU) { 153 if (rtc->periodic_freq & PF_KOU) {
159 spin_lock(&rtc_dev->irq_task_lock); 154 spin_lock(&rtc_dev->irq_task_lock);
160 if (rtc_dev->irq_task) 155 irq_task = rtc_dev->irq_task;
161 rtc_dev->irq_task->func(rtc_dev->irq_task->private_data); 156 if (irq_task)
157 irq_task->func(irq_task->private_data);
162 spin_unlock(&rtc_dev->irq_task_lock); 158 spin_unlock(&rtc_dev->irq_task_lock);
163 } else 159 } else
164 rtc_update_irq(rtc->rtc_dev, 1, RTC_PF | RTC_IRQF); 160 rtc_update_irq(rtc->rtc_dev, 1, RTC_PF | RTC_IRQF);
165 } 161 }
166 162
163 return pending;
164}
165
166static irqreturn_t sh_rtc_interrupt(int irq, void *dev_id)
167{
168 struct sh_rtc *rtc = dev_id;
169 int ret;
170
171 spin_lock(&rtc->lock);
172 ret = __sh_rtc_interrupt(rtc);
173 spin_unlock(&rtc->lock);
174
175 return IRQ_RETVAL(ret);
176}
177
178static irqreturn_t sh_rtc_alarm(int irq, void *dev_id)
179{
180 struct sh_rtc *rtc = dev_id;
181 int ret;
182
183 spin_lock(&rtc->lock);
184 ret = __sh_rtc_alarm(rtc);
185 spin_unlock(&rtc->lock);
186
187 return IRQ_RETVAL(ret);
188}
189
190static irqreturn_t sh_rtc_periodic(int irq, void *dev_id)
191{
192 struct sh_rtc *rtc = dev_id;
193 int ret;
194
195 spin_lock(&rtc->lock);
196 ret = __sh_rtc_periodic(rtc);
167 spin_unlock(&rtc->lock); 197 spin_unlock(&rtc->lock);
168 198
169 return IRQ_HANDLED; 199 return IRQ_RETVAL(ret);
200}
201
202static irqreturn_t sh_rtc_shared(int irq, void *dev_id)
203{
204 struct sh_rtc *rtc = dev_id;
205 int ret;
206
207 spin_lock(&rtc->lock);
208 ret = __sh_rtc_interrupt(rtc);
209 ret |= __sh_rtc_alarm(rtc);
210 ret |= __sh_rtc_periodic(rtc);
211 spin_unlock(&rtc->lock);
212
213 return IRQ_RETVAL(ret);
170} 214}
171 215
172static inline void sh_rtc_setpie(struct device *dev, unsigned int enable) 216static inline void sh_rtc_setpie(struct device *dev, unsigned int enable)
@@ -275,6 +319,25 @@ static int sh_rtc_proc(struct device *dev, struct seq_file *seq)
275 return 0; 319 return 0;
276} 320}
277 321
322static inline void sh_rtc_setcie(struct device *dev, unsigned int enable)
323{
324 struct sh_rtc *rtc = dev_get_drvdata(dev);
325 unsigned int tmp;
326
327 spin_lock_irq(&rtc->lock);
328
329 tmp = readb(rtc->regbase + RCR1);
330
331 if (!enable)
332 tmp &= ~RCR1_CIE;
333 else
334 tmp |= RCR1_CIE;
335
336 writeb(tmp, rtc->regbase + RCR1);
337
338 spin_unlock_irq(&rtc->lock);
339}
340
278static int sh_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 341static int sh_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
279{ 342{
280 struct sh_rtc *rtc = dev_get_drvdata(dev); 343 struct sh_rtc *rtc = dev_get_drvdata(dev);
@@ -291,9 +354,11 @@ static int sh_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
291 break; 354 break;
292 case RTC_UIE_OFF: 355 case RTC_UIE_OFF:
293 rtc->periodic_freq &= ~PF_OXS; 356 rtc->periodic_freq &= ~PF_OXS;
357 sh_rtc_setcie(dev, 0);
294 break; 358 break;
295 case RTC_UIE_ON: 359 case RTC_UIE_ON:
296 rtc->periodic_freq |= PF_OXS; 360 rtc->periodic_freq |= PF_OXS;
361 sh_rtc_setcie(dev, 1);
297 break; 362 break;
298 case RTC_IRQP_READ: 363 case RTC_IRQP_READ:
299 ret = put_user(rtc->rtc_dev->irq_freq, 364 ret = put_user(rtc->rtc_dev->irq_freq,
@@ -356,18 +421,17 @@ static int sh_rtc_read_time(struct device *dev, struct rtc_time *tm)
356 tm->tm_sec--; 421 tm->tm_sec--;
357#endif 422#endif
358 423
424 /* only keep the carry interrupt enabled if UIE is on */
425 if (!(rtc->periodic_freq & PF_OXS))
426 sh_rtc_setcie(dev, 0);
427
359 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, " 428 dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
360 "mday=%d, mon=%d, year=%d, wday=%d\n", 429 "mday=%d, mon=%d, year=%d, wday=%d\n",
361 __func__, 430 __func__,
362 tm->tm_sec, tm->tm_min, tm->tm_hour, 431 tm->tm_sec, tm->tm_min, tm->tm_hour,
363 tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday); 432 tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday);
364 433
365 if (rtc_valid_tm(tm) < 0) { 434 return rtc_valid_tm(tm);
366 dev_err(dev, "invalid date\n");
367 rtc_time_to_tm(0, tm);
368 }
369
370 return 0;
371} 435}
372 436
373static int sh_rtc_set_time(struct device *dev, struct rtc_time *tm) 437static int sh_rtc_set_time(struct device *dev, struct rtc_time *tm)
@@ -572,7 +636,7 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev)
572{ 636{
573 struct sh_rtc *rtc; 637 struct sh_rtc *rtc;
574 struct resource *res; 638 struct resource *res;
575 unsigned int tmp; 639 struct rtc_time r;
576 int ret; 640 int ret;
577 641
578 rtc = kzalloc(sizeof(struct sh_rtc), GFP_KERNEL); 642 rtc = kzalloc(sizeof(struct sh_rtc), GFP_KERNEL);
@@ -585,26 +649,12 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev)
585 ret = platform_get_irq(pdev, 0); 649 ret = platform_get_irq(pdev, 0);
586 if (unlikely(ret <= 0)) { 650 if (unlikely(ret <= 0)) {
587 ret = -ENOENT; 651 ret = -ENOENT;
588 dev_err(&pdev->dev, "No IRQ for period\n"); 652 dev_err(&pdev->dev, "No IRQ resource\n");
589 goto err_badres; 653 goto err_badres;
590 } 654 }
591 rtc->periodic_irq = ret; 655 rtc->periodic_irq = ret;
592 656 rtc->carry_irq = platform_get_irq(pdev, 1);
593 ret = platform_get_irq(pdev, 1); 657 rtc->alarm_irq = platform_get_irq(pdev, 2);
594 if (unlikely(ret <= 0)) {
595 ret = -ENOENT;
596 dev_err(&pdev->dev, "No IRQ for carry\n");
597 goto err_badres;
598 }
599 rtc->carry_irq = ret;
600
601 ret = platform_get_irq(pdev, 2);
602 if (unlikely(ret <= 0)) {
603 ret = -ENOENT;
604 dev_err(&pdev->dev, "No IRQ for alarm\n");
605 goto err_badres;
606 }
607 rtc->alarm_irq = ret;
608 658
609 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 659 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
610 if (unlikely(res == NULL)) { 660 if (unlikely(res == NULL)) {
@@ -646,47 +696,66 @@ static int __devinit sh_rtc_probe(struct platform_device *pdev)
646 } 696 }
647 697
648 rtc->rtc_dev->max_user_freq = 256; 698 rtc->rtc_dev->max_user_freq = 256;
649 rtc->rtc_dev->irq_freq = 1;
650 rtc->periodic_freq = 0x60;
651 699
652 platform_set_drvdata(pdev, rtc); 700 platform_set_drvdata(pdev, rtc);
653 701
654 /* register periodic/carry/alarm irqs */ 702 if (rtc->carry_irq <= 0) {
655 ret = request_irq(rtc->periodic_irq, sh_rtc_periodic, IRQF_DISABLED, 703 /* register shared periodic/carry/alarm irq */
656 "sh-rtc period", rtc); 704 ret = request_irq(rtc->periodic_irq, sh_rtc_shared,
657 if (unlikely(ret)) { 705 IRQF_DISABLED, "sh-rtc", rtc);
658 dev_err(&pdev->dev, 706 if (unlikely(ret)) {
659 "request period IRQ failed with %d, IRQ %d\n", ret, 707 dev_err(&pdev->dev,
660 rtc->periodic_irq); 708 "request IRQ failed with %d, IRQ %d\n", ret,
661 goto err_unmap; 709 rtc->periodic_irq);
662 } 710 goto err_unmap;
711 }
712 } else {
713 /* register periodic/carry/alarm irqs */
714 ret = request_irq(rtc->periodic_irq, sh_rtc_periodic,
715 IRQF_DISABLED, "sh-rtc period", rtc);
716 if (unlikely(ret)) {
717 dev_err(&pdev->dev,
718 "request period IRQ failed with %d, IRQ %d\n",
719 ret, rtc->periodic_irq);
720 goto err_unmap;
721 }
663 722
664 ret = request_irq(rtc->carry_irq, sh_rtc_interrupt, IRQF_DISABLED, 723 ret = request_irq(rtc->carry_irq, sh_rtc_interrupt,
665 "sh-rtc carry", rtc); 724 IRQF_DISABLED, "sh-rtc carry", rtc);
666 if (unlikely(ret)) { 725 if (unlikely(ret)) {
667 dev_err(&pdev->dev, 726 dev_err(&pdev->dev,
668 "request carry IRQ failed with %d, IRQ %d\n", ret, 727 "request carry IRQ failed with %d, IRQ %d\n",
669 rtc->carry_irq); 728 ret, rtc->carry_irq);
670 free_irq(rtc->periodic_irq, rtc); 729 free_irq(rtc->periodic_irq, rtc);
671 goto err_unmap; 730 goto err_unmap;
672 } 731 }
673 732
674 ret = request_irq(rtc->alarm_irq, sh_rtc_alarm, IRQF_DISABLED, 733 ret = request_irq(rtc->alarm_irq, sh_rtc_alarm,
675 "sh-rtc alarm", rtc); 734 IRQF_DISABLED, "sh-rtc alarm", rtc);
676 if (unlikely(ret)) { 735 if (unlikely(ret)) {
677 dev_err(&pdev->dev, 736 dev_err(&pdev->dev,
678 "request alarm IRQ failed with %d, IRQ %d\n", ret, 737 "request alarm IRQ failed with %d, IRQ %d\n",
679 rtc->alarm_irq); 738 ret, rtc->alarm_irq);
680 free_irq(rtc->carry_irq, rtc); 739 free_irq(rtc->carry_irq, rtc);
681 free_irq(rtc->periodic_irq, rtc); 740 free_irq(rtc->periodic_irq, rtc);
682 goto err_unmap; 741 goto err_unmap;
742 }
683 } 743 }
684 744
685 tmp = readb(rtc->regbase + RCR1); 745 /* everything disabled by default */
686 tmp &= ~RCR1_CF; 746 rtc->periodic_freq = 0;
687 tmp |= RCR1_CIE; 747 rtc->rtc_dev->irq_freq = 0;
688 writeb(tmp, rtc->regbase + RCR1); 748 sh_rtc_setpie(&pdev->dev, 0);
749 sh_rtc_setaie(&pdev->dev, 0);
750 sh_rtc_setcie(&pdev->dev, 0);
751
752 /* reset rtc to epoch 0 if time is invalid */
753 if (rtc_read_time(rtc->rtc_dev, &r) < 0) {
754 rtc_time_to_tm(0, &r);
755 rtc_set_time(rtc->rtc_dev, &r);
756 }
689 757
758 device_init_wakeup(&pdev->dev, 1);
690 return 0; 759 return 0;
691 760
692err_unmap: 761err_unmap:
@@ -708,10 +777,13 @@ static int __devexit sh_rtc_remove(struct platform_device *pdev)
708 777
709 sh_rtc_setpie(&pdev->dev, 0); 778 sh_rtc_setpie(&pdev->dev, 0);
710 sh_rtc_setaie(&pdev->dev, 0); 779 sh_rtc_setaie(&pdev->dev, 0);
780 sh_rtc_setcie(&pdev->dev, 0);
711 781
712 free_irq(rtc->carry_irq, rtc);
713 free_irq(rtc->periodic_irq, rtc); 782 free_irq(rtc->periodic_irq, rtc);
714 free_irq(rtc->alarm_irq, rtc); 783 if (rtc->carry_irq > 0) {
784 free_irq(rtc->carry_irq, rtc);
785 free_irq(rtc->alarm_irq, rtc);
786 }
715 787
716 release_resource(rtc->res); 788 release_resource(rtc->res);
717 789
diff --git a/drivers/rtc/rtc-twl4030.c b/drivers/rtc/rtc-twl4030.c
index ad35f76c46b7..a6341e4f9a0f 100644
--- a/drivers/rtc/rtc-twl4030.c
+++ b/drivers/rtc/rtc-twl4030.c
@@ -426,7 +426,7 @@ static int __devinit twl4030_rtc_probe(struct platform_device *pdev)
426 426
427 ret = request_irq(irq, twl4030_rtc_interrupt, 427 ret = request_irq(irq, twl4030_rtc_interrupt,
428 IRQF_TRIGGER_RISING, 428 IRQF_TRIGGER_RISING,
429 rtc->dev.bus_id, rtc); 429 dev_name(&rtc->dev), rtc);
430 if (ret < 0) { 430 if (ret < 0) {
431 dev_err(&pdev->dev, "IRQ is not free.\n"); 431 dev_err(&pdev->dev, "IRQ is not free.\n");
432 goto out1; 432 goto out1;
diff --git a/drivers/s390/cio/ccwgroup.c b/drivers/s390/cio/ccwgroup.c
index 918e6fce2573..b91c1719b075 100644
--- a/drivers/s390/cio/ccwgroup.c
+++ b/drivers/s390/cio/ccwgroup.c
@@ -104,8 +104,9 @@ ccwgroup_ungroup_store(struct device *dev, struct device_attribute *attr, const
104 rc = device_schedule_callback(dev, ccwgroup_ungroup_callback); 104 rc = device_schedule_callback(dev, ccwgroup_ungroup_callback);
105out: 105out:
106 if (rc) { 106 if (rc) {
107 /* Release onoff "lock" when ungrouping failed. */ 107 if (rc != -EAGAIN)
108 atomic_set(&gdev->onoff, 0); 108 /* Release onoff "lock" when ungrouping failed. */
109 atomic_set(&gdev->onoff, 0);
109 return rc; 110 return rc;
110 } 111 }
111 return count; 112 return count;
diff --git a/drivers/s390/cio/chsc_sch.c b/drivers/s390/cio/chsc_sch.c
index 0a2f2edafc03..93eca1731b81 100644
--- a/drivers/s390/cio/chsc_sch.c
+++ b/drivers/s390/cio/chsc_sch.c
@@ -84,8 +84,8 @@ static int chsc_subchannel_probe(struct subchannel *sch)
84 kfree(private); 84 kfree(private);
85 } else { 85 } else {
86 sch->private = private; 86 sch->private = private;
87 if (sch->dev.uevent_suppress) { 87 if (dev_get_uevent_suppress(&sch->dev)) {
88 sch->dev.uevent_suppress = 0; 88 dev_set_uevent_suppress(&sch->dev, 0);
89 kobject_uevent(&sch->dev.kobj, KOBJ_ADD); 89 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
90 } 90 }
91 } 91 }
diff --git a/drivers/s390/cio/css.c b/drivers/s390/cio/css.c
index 8019288bc6de..427d11d88069 100644
--- a/drivers/s390/cio/css.c
+++ b/drivers/s390/cio/css.c
@@ -272,7 +272,7 @@ static int css_register_subchannel(struct subchannel *sch)
272 * the subchannel driver can decide itself when it wants to inform 272 * the subchannel driver can decide itself when it wants to inform
273 * userspace of its existence. 273 * userspace of its existence.
274 */ 274 */
275 sch->dev.uevent_suppress = 1; 275 dev_set_uevent_suppress(&sch->dev, 1);
276 css_update_ssd_info(sch); 276 css_update_ssd_info(sch);
277 /* make it known to the system */ 277 /* make it known to the system */
278 ret = css_sch_device_register(sch); 278 ret = css_sch_device_register(sch);
@@ -287,7 +287,7 @@ static int css_register_subchannel(struct subchannel *sch)
287 * a fitting driver module may be loaded based on the 287 * a fitting driver module may be loaded based on the
288 * modalias. 288 * modalias.
289 */ 289 */
290 sch->dev.uevent_suppress = 0; 290 dev_set_uevent_suppress(&sch->dev, 0);
291 kobject_uevent(&sch->dev.kobj, KOBJ_ADD); 291 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
292 } 292 }
293 return ret; 293 return ret;
diff --git a/drivers/s390/cio/device.c b/drivers/s390/cio/device.c
index 23d5752349b5..e28f8ae53453 100644
--- a/drivers/s390/cio/device.c
+++ b/drivers/s390/cio/device.c
@@ -799,7 +799,7 @@ static void sch_attach_disconnected_device(struct subchannel *sch,
799 return; 799 return;
800 other_sch = to_subchannel(cdev->dev.parent); 800 other_sch = to_subchannel(cdev->dev.parent);
801 /* Note: device_move() changes cdev->dev.parent */ 801 /* Note: device_move() changes cdev->dev.parent */
802 ret = device_move(&cdev->dev, &sch->dev); 802 ret = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV);
803 if (ret) { 803 if (ret) {
804 CIO_MSG_EVENT(0, "Moving disconnected device 0.%x.%04x failed " 804 CIO_MSG_EVENT(0, "Moving disconnected device 0.%x.%04x failed "
805 "(ret=%d)!\n", cdev->private->dev_id.ssid, 805 "(ret=%d)!\n", cdev->private->dev_id.ssid,
@@ -830,7 +830,7 @@ static void sch_attach_orphaned_device(struct subchannel *sch,
830 * Try to move the ccw device to its new subchannel. 830 * Try to move the ccw device to its new subchannel.
831 * Note: device_move() changes cdev->dev.parent 831 * Note: device_move() changes cdev->dev.parent
832 */ 832 */
833 ret = device_move(&cdev->dev, &sch->dev); 833 ret = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV);
834 if (ret) { 834 if (ret) {
835 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage " 835 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x from orphanage "
836 "failed (ret=%d)!\n", 836 "failed (ret=%d)!\n",
@@ -897,7 +897,8 @@ void ccw_device_move_to_orphanage(struct work_struct *work)
897 * ccw device can take its place on the subchannel. 897 * ccw device can take its place on the subchannel.
898 * Note: device_move() changes cdev->dev.parent 898 * Note: device_move() changes cdev->dev.parent
899 */ 899 */
900 ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev); 900 ret = device_move(&cdev->dev, &css->pseudo_subchannel->dev,
901 DPM_ORDER_NONE);
901 if (ret) { 902 if (ret) {
902 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed " 903 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to orphanage failed "
903 "(ret=%d)!\n", cdev->private->dev_id.ssid, 904 "(ret=%d)!\n", cdev->private->dev_id.ssid,
@@ -981,7 +982,7 @@ io_subchannel_register(struct work_struct *work)
981 * Now we know this subchannel will stay, we can throw 982 * Now we know this subchannel will stay, we can throw
982 * our delayed uevent. 983 * our delayed uevent.
983 */ 984 */
984 sch->dev.uevent_suppress = 0; 985 dev_set_uevent_suppress(&sch->dev, 0);
985 kobject_uevent(&sch->dev.kobj, KOBJ_ADD); 986 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
986 /* make it known to the system */ 987 /* make it known to the system */
987 ret = ccw_device_register(cdev); 988 ret = ccw_device_register(cdev);
@@ -1129,7 +1130,7 @@ static void ccw_device_move_to_sch(struct work_struct *work)
1129 * Try to move the ccw device to its new subchannel. 1130 * Try to move the ccw device to its new subchannel.
1130 * Note: device_move() changes cdev->dev.parent 1131 * Note: device_move() changes cdev->dev.parent
1131 */ 1132 */
1132 rc = device_move(&cdev->dev, &sch->dev); 1133 rc = device_move(&cdev->dev, &sch->dev, DPM_ORDER_PARENT_BEFORE_DEV);
1133 mutex_unlock(&sch->reg_mutex); 1134 mutex_unlock(&sch->reg_mutex);
1134 if (rc) { 1135 if (rc) {
1135 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel " 1136 CIO_MSG_EVENT(0, "Moving device 0.%x.%04x to subchannel "
@@ -1243,7 +1244,7 @@ static int io_subchannel_probe(struct subchannel *sch)
1243 * the ccw_device and exit. This happens for all early 1244 * the ccw_device and exit. This happens for all early
1244 * devices, e.g. the console. 1245 * devices, e.g. the console.
1245 */ 1246 */
1246 sch->dev.uevent_suppress = 0; 1247 dev_set_uevent_suppress(&sch->dev, 0);
1247 kobject_uevent(&sch->dev.kobj, KOBJ_ADD); 1248 kobject_uevent(&sch->dev.kobj, KOBJ_ADD);
1248 cdev->dev.groups = ccwdev_attr_groups; 1249 cdev->dev.groups = ccwdev_attr_groups;
1249 device_initialize(&cdev->dev); 1250 device_initialize(&cdev->dev);
diff --git a/drivers/s390/net/qeth_l3_main.c b/drivers/s390/net/qeth_l3_main.c
index 3d04920b9bb9..0dcc036d34aa 100644
--- a/drivers/s390/net/qeth_l3_main.c
+++ b/drivers/s390/net/qeth_l3_main.c
@@ -1038,7 +1038,7 @@ static int qeth_l3_setadapter_parms(struct qeth_card *card)
1038 rc = qeth_query_setadapterparms(card); 1038 rc = qeth_query_setadapterparms(card);
1039 if (rc) { 1039 if (rc) {
1040 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: " 1040 QETH_DBF_MESSAGE(2, "%s couldn't set adapter parameters: "
1041 "0x%x\n", card->gdev->dev.bus_id, rc); 1041 "0x%x\n", dev_name(&card->gdev->dev), rc);
1042 return rc; 1042 return rc;
1043 } 1043 }
1044 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) { 1044 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
diff --git a/drivers/scsi/a4000t.c b/drivers/scsi/a4000t.c
index d4bda2017746..61af3d91ac8a 100644
--- a/drivers/scsi/a4000t.c
+++ b/drivers/scsi/a4000t.c
@@ -35,7 +35,7 @@ static struct platform_device *a4000t_scsi_device;
35 35
36#define A4000T_SCSI_ADDR 0xdd0040 36#define A4000T_SCSI_ADDR 0xdd0040
37 37
38static int __devinit a4000t_probe(struct device *dev) 38static int __devinit a4000t_probe(struct platform_device *dev)
39{ 39{
40 struct Scsi_Host *host; 40 struct Scsi_Host *host;
41 struct NCR_700_Host_Parameters *hostdata; 41 struct NCR_700_Host_Parameters *hostdata;
@@ -61,7 +61,8 @@ static int __devinit a4000t_probe(struct device *dev)
61 hostdata->dcntl_extra = EA_710; 61 hostdata->dcntl_extra = EA_710;
62 62
63 /* and register the chip */ 63 /* and register the chip */
64 host = NCR_700_detect(&a4000t_scsi_driver_template, hostdata, dev); 64 host = NCR_700_detect(&a4000t_scsi_driver_template, hostdata,
65 &dev->dev);
65 if (!host) { 66 if (!host) {
66 printk(KERN_ERR "a4000t-scsi: No host detected; " 67 printk(KERN_ERR "a4000t-scsi: No host detected; "
67 "board configuration problem?\n"); 68 "board configuration problem?\n");
@@ -78,7 +79,7 @@ static int __devinit a4000t_probe(struct device *dev)
78 goto out_put_host; 79 goto out_put_host;
79 } 80 }
80 81
81 dev_set_drvdata(dev, host); 82 platform_set_drvdata(dev, host);
82 scsi_scan_host(host); 83 scsi_scan_host(host);
83 84
84 return 0; 85 return 0;
@@ -93,9 +94,9 @@ static int __devinit a4000t_probe(struct device *dev)
93 return -ENODEV; 94 return -ENODEV;
94} 95}
95 96
96static __devexit int a4000t_device_remove(struct device *dev) 97static __devexit int a4000t_device_remove(struct platform_device *dev)
97{ 98{
98 struct Scsi_Host *host = dev_get_drvdata(dev); 99 struct Scsi_Host *host = platform_get_drvdata(dev);
99 struct NCR_700_Host_Parameters *hostdata = shost_priv(host); 100 struct NCR_700_Host_Parameters *hostdata = shost_priv(host);
100 101
101 scsi_remove_host(host); 102 scsi_remove_host(host);
@@ -108,25 +109,27 @@ static __devexit int a4000t_device_remove(struct device *dev)
108 return 0; 109 return 0;
109} 110}
110 111
111static struct device_driver a4000t_scsi_driver = { 112static struct platform_driver a4000t_scsi_driver = {
112 .name = "a4000t-scsi", 113 .driver = {
113 .bus = &platform_bus_type, 114 .name = "a4000t-scsi",
114 .probe = a4000t_probe, 115 .owner = THIS_MODULE,
115 .remove = __devexit_p(a4000t_device_remove), 116 },
117 .probe = a4000t_probe,
118 .remove = __devexit_p(a4000t_device_remove),
116}; 119};
117 120
118static int __init a4000t_scsi_init(void) 121static int __init a4000t_scsi_init(void)
119{ 122{
120 int err; 123 int err;
121 124
122 err = driver_register(&a4000t_scsi_driver); 125 err = platform_driver_register(&a4000t_scsi_driver);
123 if (err) 126 if (err)
124 return err; 127 return err;
125 128
126 a4000t_scsi_device = platform_device_register_simple("a4000t-scsi", 129 a4000t_scsi_device = platform_device_register_simple("a4000t-scsi",
127 -1, NULL, 0); 130 -1, NULL, 0);
128 if (IS_ERR(a4000t_scsi_device)) { 131 if (IS_ERR(a4000t_scsi_device)) {
129 driver_unregister(&a4000t_scsi_driver); 132 platform_driver_register(&a4000t_scsi_driver);
130 return PTR_ERR(a4000t_scsi_device); 133 return PTR_ERR(a4000t_scsi_device);
131 } 134 }
132 135
@@ -136,7 +139,7 @@ static int __init a4000t_scsi_init(void)
136static void __exit a4000t_scsi_exit(void) 139static void __exit a4000t_scsi_exit(void)
137{ 140{
138 platform_device_unregister(a4000t_scsi_device); 141 platform_device_unregister(a4000t_scsi_device);
139 driver_unregister(&a4000t_scsi_driver); 142 platform_driver_unregister(&a4000t_scsi_driver);
140} 143}
141 144
142module_init(a4000t_scsi_init); 145module_init(a4000t_scsi_init);
diff --git a/drivers/scsi/bvme6000_scsi.c b/drivers/scsi/bvme6000_scsi.c
index d858f3d41274..5799cb5cba6b 100644
--- a/drivers/scsi/bvme6000_scsi.c
+++ b/drivers/scsi/bvme6000_scsi.c
@@ -34,7 +34,7 @@ static struct scsi_host_template bvme6000_scsi_driver_template = {
34static struct platform_device *bvme6000_scsi_device; 34static struct platform_device *bvme6000_scsi_device;
35 35
36static __devinit int 36static __devinit int
37bvme6000_probe(struct device *dev) 37bvme6000_probe(struct platform_device *dev)
38{ 38{
39 struct Scsi_Host *host; 39 struct Scsi_Host *host;
40 struct NCR_700_Host_Parameters *hostdata; 40 struct NCR_700_Host_Parameters *hostdata;
@@ -58,7 +58,8 @@ bvme6000_probe(struct device *dev)
58 hostdata->ctest7_extra = CTEST7_TT1; 58 hostdata->ctest7_extra = CTEST7_TT1;
59 59
60 /* and register the chip */ 60 /* and register the chip */
61 host = NCR_700_detect(&bvme6000_scsi_driver_template, hostdata, dev); 61 host = NCR_700_detect(&bvme6000_scsi_driver_template, hostdata,
62 &dev->dev);
62 if (!host) { 63 if (!host) {
63 printk(KERN_ERR "bvme6000-scsi: No host detected; " 64 printk(KERN_ERR "bvme6000-scsi: No host detected; "
64 "board configuration problem?\n"); 65 "board configuration problem?\n");
@@ -73,7 +74,7 @@ bvme6000_probe(struct device *dev)
73 goto out_put_host; 74 goto out_put_host;
74 } 75 }
75 76
76 dev_set_drvdata(dev, host); 77 platform_set_drvdata(dev, host);
77 scsi_scan_host(host); 78 scsi_scan_host(host);
78 79
79 return 0; 80 return 0;
@@ -87,9 +88,9 @@ bvme6000_probe(struct device *dev)
87} 88}
88 89
89static __devexit int 90static __devexit int
90bvme6000_device_remove(struct device *dev) 91bvme6000_device_remove(struct platform_device *dev)
91{ 92{
92 struct Scsi_Host *host = dev_get_drvdata(dev); 93 struct Scsi_Host *host = platform_get_drvdata(dev);
93 struct NCR_700_Host_Parameters *hostdata = shost_priv(host); 94 struct NCR_700_Host_Parameters *hostdata = shost_priv(host);
94 95
95 scsi_remove_host(host); 96 scsi_remove_host(host);
@@ -100,25 +101,27 @@ bvme6000_device_remove(struct device *dev)
100 return 0; 101 return 0;
101} 102}
102 103
103static struct device_driver bvme6000_scsi_driver = { 104static struct platform_driver bvme6000_scsi_driver = {
104 .name = "bvme6000-scsi", 105 .driver = {
105 .bus = &platform_bus_type, 106 .name = "bvme6000-scsi",
106 .probe = bvme6000_probe, 107 .owner = THIS_MODULE,
107 .remove = __devexit_p(bvme6000_device_remove), 108 },
109 .probe = bvme6000_probe,
110 .remove = __devexit_p(bvme6000_device_remove),
108}; 111};
109 112
110static int __init bvme6000_scsi_init(void) 113static int __init bvme6000_scsi_init(void)
111{ 114{
112 int err; 115 int err;
113 116
114 err = driver_register(&bvme6000_scsi_driver); 117 err = platform_driver_register(&bvme6000_scsi_driver);
115 if (err) 118 if (err)
116 return err; 119 return err;
117 120
118 bvme6000_scsi_device = platform_device_register_simple("bvme6000-scsi", 121 bvme6000_scsi_device = platform_device_register_simple("bvme6000-scsi",
119 -1, NULL, 0); 122 -1, NULL, 0);
120 if (IS_ERR(bvme6000_scsi_device)) { 123 if (IS_ERR(bvme6000_scsi_device)) {
121 driver_unregister(&bvme6000_scsi_driver); 124 platform_driver_unregister(&bvme6000_scsi_driver);
122 return PTR_ERR(bvme6000_scsi_device); 125 return PTR_ERR(bvme6000_scsi_device);
123 } 126 }
124 127
@@ -128,7 +131,7 @@ static int __init bvme6000_scsi_init(void)
128static void __exit bvme6000_scsi_exit(void) 131static void __exit bvme6000_scsi_exit(void)
129{ 132{
130 platform_device_unregister(bvme6000_scsi_device); 133 platform_device_unregister(bvme6000_scsi_device);
131 driver_unregister(&bvme6000_scsi_driver); 134 platform_driver_unregister(&bvme6000_scsi_driver);
132} 135}
133 136
134module_init(bvme6000_scsi_init); 137module_init(bvme6000_scsi_init);
diff --git a/drivers/scsi/mvme16x_scsi.c b/drivers/scsi/mvme16x_scsi.c
index b264b499d982..b5fbfd6ce870 100644
--- a/drivers/scsi/mvme16x_scsi.c
+++ b/drivers/scsi/mvme16x_scsi.c
@@ -34,7 +34,7 @@ static struct scsi_host_template mvme16x_scsi_driver_template = {
34static struct platform_device *mvme16x_scsi_device; 34static struct platform_device *mvme16x_scsi_device;
35 35
36static __devinit int 36static __devinit int
37mvme16x_probe(struct device *dev) 37mvme16x_probe(struct platform_device *dev)
38{ 38{
39 struct Scsi_Host * host = NULL; 39 struct Scsi_Host * host = NULL;
40 struct NCR_700_Host_Parameters *hostdata; 40 struct NCR_700_Host_Parameters *hostdata;
@@ -64,7 +64,8 @@ mvme16x_probe(struct device *dev)
64 hostdata->ctest7_extra = CTEST7_TT1; 64 hostdata->ctest7_extra = CTEST7_TT1;
65 65
66 /* and register the chip */ 66 /* and register the chip */
67 host = NCR_700_detect(&mvme16x_scsi_driver_template, hostdata, dev); 67 host = NCR_700_detect(&mvme16x_scsi_driver_template, hostdata,
68 &dev->dev);
68 if (!host) { 69 if (!host) {
69 printk(KERN_ERR "mvme16x-scsi: No host detected; " 70 printk(KERN_ERR "mvme16x-scsi: No host detected; "
70 "board configuration problem?\n"); 71 "board configuration problem?\n");
@@ -88,7 +89,7 @@ mvme16x_probe(struct device *dev)
88 out_be32(0xfff4202c, v); 89 out_be32(0xfff4202c, v);
89 } 90 }
90 91
91 dev_set_drvdata(dev, host); 92 platform_set_drvdata(dev, host);
92 scsi_scan_host(host); 93 scsi_scan_host(host);
93 94
94 return 0; 95 return 0;
@@ -102,9 +103,9 @@ mvme16x_probe(struct device *dev)
102} 103}
103 104
104static __devexit int 105static __devexit int
105mvme16x_device_remove(struct device *dev) 106mvme16x_device_remove(struct platform_device *dev)
106{ 107{
107 struct Scsi_Host *host = dev_get_drvdata(dev); 108 struct Scsi_Host *host = platform_get_drvdata(dev);
108 struct NCR_700_Host_Parameters *hostdata = shost_priv(host); 109 struct NCR_700_Host_Parameters *hostdata = shost_priv(host);
109 110
110 /* Disable scsi chip ints */ 111 /* Disable scsi chip ints */
@@ -123,25 +124,27 @@ mvme16x_device_remove(struct device *dev)
123 return 0; 124 return 0;
124} 125}
125 126
126static struct device_driver mvme16x_scsi_driver = { 127static struct platform_driver mvme16x_scsi_driver = {
127 .name = "mvme16x-scsi", 128 .driver = {
128 .bus = &platform_bus_type, 129 .name = "mvme16x-scsi",
129 .probe = mvme16x_probe, 130 .owner = THIS_MODULE,
130 .remove = __devexit_p(mvme16x_device_remove), 131 },
132 .probe = mvme16x_probe,
133 .remove = __devexit_p(mvme16x_device_remove),
131}; 134};
132 135
133static int __init mvme16x_scsi_init(void) 136static int __init mvme16x_scsi_init(void)
134{ 137{
135 int err; 138 int err;
136 139
137 err = driver_register(&mvme16x_scsi_driver); 140 err = platform_driver_register(&mvme16x_scsi_driver);
138 if (err) 141 if (err)
139 return err; 142 return err;
140 143
141 mvme16x_scsi_device = platform_device_register_simple("mvme16x-scsi", 144 mvme16x_scsi_device = platform_device_register_simple("mvme16x-scsi",
142 -1, NULL, 0); 145 -1, NULL, 0);
143 if (IS_ERR(mvme16x_scsi_device)) { 146 if (IS_ERR(mvme16x_scsi_device)) {
144 driver_unregister(&mvme16x_scsi_driver); 147 platform_driver_unregister(&mvme16x_scsi_driver);
145 return PTR_ERR(mvme16x_scsi_device); 148 return PTR_ERR(mvme16x_scsi_device);
146 } 149 }
147 150
@@ -151,7 +154,7 @@ static int __init mvme16x_scsi_init(void)
151static void __exit mvme16x_scsi_exit(void) 154static void __exit mvme16x_scsi_exit(void)
152{ 155{
153 platform_device_unregister(mvme16x_scsi_device); 156 platform_device_unregister(mvme16x_scsi_device);
154 driver_unregister(&mvme16x_scsi_driver); 157 platform_driver_unregister(&mvme16x_scsi_driver);
155} 158}
156 159
157module_init(mvme16x_scsi_init); 160module_init(mvme16x_scsi_init);
diff --git a/drivers/serial/sh-sci.c b/drivers/serial/sh-sci.c
index 557b54ab2f25..dbf5357a77b3 100644
--- a/drivers/serial/sh-sci.c
+++ b/drivers/serial/sh-sci.c
@@ -139,7 +139,7 @@ static void sci_poll_put_char(struct uart_port *port, unsigned char c)
139 } while (!(status & SCxSR_TDxE(port))); 139 } while (!(status & SCxSR_TDxE(port)));
140 140
141 sci_in(port, SCxSR); /* Dummy read */ 141 sci_in(port, SCxSR); /* Dummy read */
142 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port)); 142 sci_out(port, SCxSR, SCxSR_TDxE_CLEAR(port) & ~SCxSR_TEND(port));
143 sci_out(port, SCxTDR, c); 143 sci_out(port, SCxTDR, c);
144} 144}
145#endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */ 145#endif /* CONFIG_CONSOLE_POLL || CONFIG_SERIAL_SH_SCI_CONSOLE */
@@ -263,6 +263,7 @@ static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
263#elif defined(CONFIG_CPU_SUBTYPE_SH7763) || \ 263#elif defined(CONFIG_CPU_SUBTYPE_SH7763) || \
264 defined(CONFIG_CPU_SUBTYPE_SH7780) || \ 264 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
265 defined(CONFIG_CPU_SUBTYPE_SH7785) || \ 265 defined(CONFIG_CPU_SUBTYPE_SH7785) || \
266 defined(CONFIG_CPU_SUBTYPE_SH7786) || \
266 defined(CONFIG_CPU_SUBTYPE_SHX3) 267 defined(CONFIG_CPU_SUBTYPE_SHX3)
267static inline void sci_init_pins(struct uart_port *port, unsigned int cflag) 268static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
268{ 269{
@@ -284,7 +285,8 @@ static inline void sci_init_pins(struct uart_port *port, unsigned int cflag)
284 285
285#if defined(CONFIG_CPU_SUBTYPE_SH7760) || \ 286#if defined(CONFIG_CPU_SUBTYPE_SH7760) || \
286 defined(CONFIG_CPU_SUBTYPE_SH7780) || \ 287 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
287 defined(CONFIG_CPU_SUBTYPE_SH7785) 288 defined(CONFIG_CPU_SUBTYPE_SH7785) || \
289 defined(CONFIG_CPU_SUBTYPE_SH7786)
288static inline int scif_txroom(struct uart_port *port) 290static inline int scif_txroom(struct uart_port *port)
289{ 291{
290 return SCIF_TXROOM_MAX - (sci_in(port, SCTFDR) & 0xff); 292 return SCIF_TXROOM_MAX - (sci_in(port, SCTFDR) & 0xff);
@@ -1095,6 +1097,7 @@ static void serial_console_write(struct console *co, const char *s,
1095 unsigned count) 1097 unsigned count)
1096{ 1098{
1097 struct uart_port *port = &serial_console_port->port; 1099 struct uart_port *port = &serial_console_port->port;
1100 unsigned short bits;
1098 int i; 1101 int i;
1099 1102
1100 for (i = 0; i < count; i++) { 1103 for (i = 0; i < count; i++) {
@@ -1103,6 +1106,11 @@ static void serial_console_write(struct console *co, const char *s,
1103 1106
1104 sci_poll_put_char(port, *s++); 1107 sci_poll_put_char(port, *s++);
1105 } 1108 }
1109
1110 /* wait until fifo is empty and last bit has been transmitted */
1111 bits = SCxSR_TDxE(port) | SCxSR_TEND(port);
1112 while ((sci_in(port, SCxSR) & bits) != bits)
1113 cpu_relax();
1106} 1114}
1107 1115
1108static int __init serial_console_setup(struct console *co, char *options) 1116static int __init serial_console_setup(struct console *co, char *options)
diff --git a/drivers/serial/sh-sci.h b/drivers/serial/sh-sci.h
index 022e89ffec1d..d0aa82d7fce0 100644
--- a/drivers/serial/sh-sci.h
+++ b/drivers/serial/sh-sci.h
@@ -1,6 +1,6 @@
1#include <linux/serial_core.h> 1#include <linux/serial_core.h>
2#include <asm/io.h> 2#include <asm/io.h>
3#include <asm/gpio.h> 3#include <linux/gpio.h>
4 4
5#if defined(CONFIG_H83007) || defined(CONFIG_H83068) 5#if defined(CONFIG_H83007) || defined(CONFIG_H83068)
6#include <asm/regs306x.h> 6#include <asm/regs306x.h>
@@ -126,7 +126,8 @@
126# define SCSPTR1 0xffe10024 /* 16 bit SCIF */ 126# define SCSPTR1 0xffe10024 /* 16 bit SCIF */
127# define SCIF_ORER 0x0001 /* Overrun error bit */ 127# define SCIF_ORER 0x0001 /* Overrun error bit */
128# define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */ 128# define SCSCR_INIT(port) 0x3a /* TIE=0,RIE=0,TE=1,RE=1,REIE=1 */
129#elif defined(CONFIG_CPU_SUBTYPE_SH7785) 129#elif defined(CONFIG_CPU_SUBTYPE_SH7785) || \
130 defined(CONFIG_CPU_SUBTYPE_SH7786)
130# define SCSPTR0 0xffea0024 /* 16 bit SCIF */ 131# define SCSPTR0 0xffea0024 /* 16 bit SCIF */
131# define SCSPTR1 0xffeb0024 /* 16 bit SCIF */ 132# define SCSPTR1 0xffeb0024 /* 16 bit SCIF */
132# define SCSPTR2 0xffec0024 /* 16 bit SCIF */ 133# define SCSPTR2 0xffec0024 /* 16 bit SCIF */
@@ -182,6 +183,7 @@
182 defined(CONFIG_CPU_SUBTYPE_SH7763) || \ 183 defined(CONFIG_CPU_SUBTYPE_SH7763) || \
183 defined(CONFIG_CPU_SUBTYPE_SH7780) || \ 184 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
184 defined(CONFIG_CPU_SUBTYPE_SH7785) || \ 185 defined(CONFIG_CPU_SUBTYPE_SH7785) || \
186 defined(CONFIG_CPU_SUBTYPE_SH7786) || \
185 defined(CONFIG_CPU_SUBTYPE_SHX3) 187 defined(CONFIG_CPU_SUBTYPE_SHX3)
186#define SCI_CTRL_FLAGS_REIE 0x08 /* 7750 SCIF */ 188#define SCI_CTRL_FLAGS_REIE 0x08 /* 7750 SCIF */
187#else 189#else
@@ -413,7 +415,8 @@ SCIx_FNS(SCxRDR, 0x0a, 8, 0x14, 8, 0x0A, 8, 0x14, 8, 0x05, 8)
413SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16) 415SCIF_FNS(SCFCR, 0x0c, 8, 0x18, 16)
414#if defined(CONFIG_CPU_SUBTYPE_SH7760) || \ 416#if defined(CONFIG_CPU_SUBTYPE_SH7760) || \
415 defined(CONFIG_CPU_SUBTYPE_SH7780) || \ 417 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
416 defined(CONFIG_CPU_SUBTYPE_SH7785) 418 defined(CONFIG_CPU_SUBTYPE_SH7785) || \
419 defined(CONFIG_CPU_SUBTYPE_SH7786)
417SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16) 420SCIF_FNS(SCFDR, 0x0e, 16, 0x1C, 16)
418SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16) 421SCIF_FNS(SCTFDR, 0x0e, 16, 0x1C, 16)
419SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16) 422SCIF_FNS(SCRFDR, 0x0e, 16, 0x20, 16)
@@ -644,7 +647,8 @@ static inline int sci_rxd_in(struct uart_port *port)
644 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */ 647 return ctrl_inw(SCSPTR1) & 0x0001 ? 1 : 0; /* SCIF */
645 return 1; 648 return 1;
646} 649}
647#elif defined(CONFIG_CPU_SUBTYPE_SH7785) 650#elif defined(CONFIG_CPU_SUBTYPE_SH7785) || \
651 defined(CONFIG_CPU_SUBTYPE_SH7786)
648static inline int sci_rxd_in(struct uart_port *port) 652static inline int sci_rxd_in(struct uart_port *port)
649{ 653{
650 if (port->mapbase == 0xffea0000) 654 if (port->mapbase == 0xffea0000)
@@ -746,7 +750,8 @@ static inline int sci_rxd_in(struct uart_port *port)
746 */ 750 */
747 751
748#if defined(CONFIG_CPU_SUBTYPE_SH7780) || \ 752#if defined(CONFIG_CPU_SUBTYPE_SH7780) || \
749 defined(CONFIG_CPU_SUBTYPE_SH7785) 753 defined(CONFIG_CPU_SUBTYPE_SH7785) || \
754 defined(CONFIG_CPU_SUBTYPE_SH7786)
750#define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(16*bps)-1) 755#define SCBRR_VALUE(bps, clk) ((clk+16*bps)/(16*bps)-1)
751#elif defined(CONFIG_CPU_SUBTYPE_SH7705) || \ 756#elif defined(CONFIG_CPU_SUBTYPE_SH7705) || \
752 defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 757 defined(CONFIG_CPU_SUBTYPE_SH7720) || \
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index 45a299f35617..e09d3cebb4fb 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -1438,12 +1438,12 @@ static int __devinit zs_probe(struct of_device *op, const struct of_device_id *m
1438 } else { 1438 } else {
1439 printk(KERN_INFO "%s: Keyboard at MMIO 0x%llx (irq = %d) " 1439 printk(KERN_INFO "%s: Keyboard at MMIO 0x%llx (irq = %d) "
1440 "is a %s\n", 1440 "is a %s\n",
1441 op->dev.bus_id, 1441 dev_name(&op->dev),
1442 (unsigned long long) up[0].port.mapbase, 1442 (unsigned long long) up[0].port.mapbase,
1443 op->irqs[0], sunzilog_type(&up[0].port)); 1443 op->irqs[0], sunzilog_type(&up[0].port));
1444 printk(KERN_INFO "%s: Mouse at MMIO 0x%llx (irq = %d) " 1444 printk(KERN_INFO "%s: Mouse at MMIO 0x%llx (irq = %d) "
1445 "is a %s\n", 1445 "is a %s\n",
1446 op->dev.bus_id, 1446 dev_name(&op->dev),
1447 (unsigned long long) up[1].port.mapbase, 1447 (unsigned long long) up[1].port.mapbase,
1448 op->irqs[0], sunzilog_type(&up[1].port)); 1448 op->irqs[0], sunzilog_type(&up[1].port));
1449 kbm_inst++; 1449 kbm_inst++;
diff --git a/drivers/sh/intc.c b/drivers/sh/intc.c
index 58d24c5a76ce..2269fbcaa182 100644
--- a/drivers/sh/intc.c
+++ b/drivers/sh/intc.c
@@ -568,6 +568,10 @@ static void __init intc_register_irq(struct intc_desc *desc,
568 if (!data[0] && data[1]) 568 if (!data[0] && data[1])
569 primary = 1; 569 primary = 1;
570 570
571 if (!data[0] && !data[1])
572 pr_warning("intc: missing unique irq mask for "
573 "irq %d (vect 0x%04x)\n", irq, irq2evt(irq));
574
571 data[0] = data[0] ? data[0] : intc_mask_data(desc, d, enum_id, 1); 575 data[0] = data[0] ? data[0] : intc_mask_data(desc, d, enum_id, 1);
572 data[1] = data[1] ? data[1] : intc_prio_data(desc, d, enum_id, 1); 576 data[1] = data[1] ? data[1] : intc_prio_data(desc, d, enum_id, 1);
573 577
@@ -641,6 +645,17 @@ static unsigned int __init save_reg(struct intc_desc_int *d,
641 return 0; 645 return 0;
642} 646}
643 647
648static unsigned char *intc_evt2irq_table;
649
650unsigned int intc_evt2irq(unsigned int vector)
651{
652 unsigned int irq = evt2irq(vector);
653
654 if (intc_evt2irq_table && intc_evt2irq_table[irq])
655 irq = intc_evt2irq_table[irq];
656
657 return irq;
658}
644 659
645void __init register_intc_controller(struct intc_desc *desc) 660void __init register_intc_controller(struct intc_desc *desc)
646{ 661{
@@ -705,9 +720,41 @@ void __init register_intc_controller(struct intc_desc *desc)
705 720
706 BUG_ON(k > 256); /* _INTC_ADDR_E() and _INTC_ADDR_D() are 8 bits */ 721 BUG_ON(k > 256); /* _INTC_ADDR_E() and _INTC_ADDR_D() are 8 bits */
707 722
723 /* keep the first vector only if same enum is used multiple times */
724 for (i = 0; i < desc->nr_vectors; i++) {
725 struct intc_vect *vect = desc->vectors + i;
726 int first_irq = evt2irq(vect->vect);
727
728 if (!vect->enum_id)
729 continue;
730
731 for (k = i + 1; k < desc->nr_vectors; k++) {
732 struct intc_vect *vect2 = desc->vectors + k;
733
734 if (vect->enum_id != vect2->enum_id)
735 continue;
736
737 vect2->enum_id = 0;
738
739 if (!intc_evt2irq_table)
740 intc_evt2irq_table = alloc_bootmem(NR_IRQS);
741
742 if (!intc_evt2irq_table) {
743 pr_warning("intc: cannot allocate evt2irq!\n");
744 continue;
745 }
746
747 intc_evt2irq_table[evt2irq(vect2->vect)] = first_irq;
748 }
749 }
750
751 /* register the vectors one by one */
708 for (i = 0; i < desc->nr_vectors; i++) { 752 for (i = 0; i < desc->nr_vectors; i++) {
709 struct intc_vect *vect = desc->vectors + i; 753 struct intc_vect *vect = desc->vectors + i;
710 754
755 if (!vect->enum_id)
756 continue;
757
711 intc_register_irq(desc, d, vect->enum_id, evt2irq(vect->vect)); 758 intc_register_irq(desc, d, vect->enum_id, evt2irq(vect->vect));
712 } 759 }
713} 760}
diff --git a/drivers/sh/maple/maple.c b/drivers/sh/maple/maple.c
index 63f0de29aa14..cab1ab7cfb78 100644
--- a/drivers/sh/maple/maple.c
+++ b/drivers/sh/maple/maple.c
@@ -1,16 +1,10 @@
1/* 1/*
2 * Core maple bus functionality 2 * Core maple bus functionality
3 * 3 *
4 * Copyright (C) 2007, 2008 Adrian McMenamin 4 * Copyright (C) 2007 - 2009 Adrian McMenamin
5 * Copyright (C) 2001 - 2008 Paul Mundt 5 * Copyright (C) 2001 - 2008 Paul Mundt
6 * 6 * Copyright (C) 2000 - 2001 YAEGASHI Takeshi
7 * Based on 2.4 code by:
8 *
9 * Copyright (C) 2000-2001 YAEGASHI Takeshi
10 * Copyright (C) 2001 M. R. Brown 7 * Copyright (C) 2001 M. R. Brown
11 * Copyright (C) 2001 Paul Mundt
12 *
13 * and others.
14 * 8 *
15 * This file is subject to the terms and conditions of the GNU General Public 9 * This file is subject to the terms and conditions of the GNU General Public
16 * License. See the file "COPYING" in the main directory of this archive 10 * License. See the file "COPYING" in the main directory of this archive
@@ -32,7 +26,7 @@
32#include <mach/dma.h> 26#include <mach/dma.h>
33#include <mach/sysasic.h> 27#include <mach/sysasic.h>
34 28
35MODULE_AUTHOR("Yaegashi Takeshi, Paul Mundt, M. R. Brown, Adrian McMenamin"); 29MODULE_AUTHOR("Adrian McMenamin <adrian@mcmen.demon.co.uk>");
36MODULE_DESCRIPTION("Maple bus driver for Dreamcast"); 30MODULE_DESCRIPTION("Maple bus driver for Dreamcast");
37MODULE_LICENSE("GPL v2"); 31MODULE_LICENSE("GPL v2");
38MODULE_SUPPORTED_DEVICE("{{SEGA, Dreamcast/Maple}}"); 32MODULE_SUPPORTED_DEVICE("{{SEGA, Dreamcast/Maple}}");
@@ -49,7 +43,7 @@ static LIST_HEAD(maple_sentq);
49/* mutex to protect queue of waiting packets */ 43/* mutex to protect queue of waiting packets */
50static DEFINE_MUTEX(maple_wlist_lock); 44static DEFINE_MUTEX(maple_wlist_lock);
51 45
52static struct maple_driver maple_dummy_driver; 46static struct maple_driver maple_unsupported_device;
53static struct device maple_bus; 47static struct device maple_bus;
54static int subdevice_map[MAPLE_PORTS]; 48static int subdevice_map[MAPLE_PORTS];
55static unsigned long *maple_sendbuf, *maple_sendptr, *maple_lastptr; 49static unsigned long *maple_sendbuf, *maple_sendptr, *maple_lastptr;
@@ -62,8 +56,9 @@ struct maple_device_specify {
62 int unit; 56 int unit;
63}; 57};
64 58
65static bool checked[4]; 59static bool checked[MAPLE_PORTS];
66static struct maple_device *baseunits[4]; 60static bool empty[MAPLE_PORTS];
61static struct maple_device *baseunits[MAPLE_PORTS];
67 62
68/** 63/**
69 * maple_driver_register - register a maple driver 64 * maple_driver_register - register a maple driver
@@ -97,12 +92,20 @@ void maple_driver_unregister(struct maple_driver *drv)
97EXPORT_SYMBOL_GPL(maple_driver_unregister); 92EXPORT_SYMBOL_GPL(maple_driver_unregister);
98 93
99/* set hardware registers to enable next round of dma */ 94/* set hardware registers to enable next round of dma */
100static void maplebus_dma_reset(void) 95static void maple_dma_reset(void)
101{ 96{
102 ctrl_outl(MAPLE_MAGIC, MAPLE_RESET); 97 ctrl_outl(MAPLE_MAGIC, MAPLE_RESET);
103 /* set trig type to 0 for software trigger, 1 for hardware (VBLANK) */ 98 /* set trig type to 0 for software trigger, 1 for hardware (VBLANK) */
104 ctrl_outl(1, MAPLE_TRIGTYPE); 99 ctrl_outl(1, MAPLE_TRIGTYPE);
105 ctrl_outl(MAPLE_2MBPS | MAPLE_TIMEOUT(50000), MAPLE_SPEED); 100 /*
101 * Maple system register
102 * bits 31 - 16 timeout in units of 20nsec
103 * bit 12 hard trigger - set 0 to keep responding to VBLANK
104 * bits 9 - 8 set 00 for 2 Mbps, 01 for 1 Mbps
105 * bits 3 - 0 delay (in 1.3ms) between VBLANK and start of DMA
106 * max delay is 11
107 */
108 ctrl_outl(MAPLE_2MBPS | MAPLE_TIMEOUT(0xFFFF), MAPLE_SPEED);
106 ctrl_outl(PHYSADDR(maple_sendbuf), MAPLE_DMAADDR); 109 ctrl_outl(PHYSADDR(maple_sendbuf), MAPLE_DMAADDR);
107 ctrl_outl(1, MAPLE_ENABLE); 110 ctrl_outl(1, MAPLE_ENABLE);
108} 111}
@@ -134,21 +137,16 @@ static void maple_release_device(struct device *dev)
134{ 137{
135 struct maple_device *mdev; 138 struct maple_device *mdev;
136 struct mapleq *mq; 139 struct mapleq *mq;
137 if (!dev) 140
138 return;
139 mdev = to_maple_dev(dev); 141 mdev = to_maple_dev(dev);
140 mq = mdev->mq; 142 mq = mdev->mq;
141 if (mq) { 143 kmem_cache_free(maple_queue_cache, mq->recvbuf);
142 if (mq->recvbufdcsp) 144 kfree(mq);
143 kmem_cache_free(maple_queue_cache, mq->recvbufdcsp);
144 kfree(mq);
145 mq = NULL;
146 }
147 kfree(mdev); 145 kfree(mdev);
148} 146}
149 147
150/** 148/**
151 * maple_add_packet - add a single instruction to the queue 149 * maple_add_packet - add a single instruction to the maple bus queue
152 * @mdev: maple device 150 * @mdev: maple device
153 * @function: function on device being queried 151 * @function: function on device being queried
154 * @command: maple command to add 152 * @command: maple command to add
@@ -158,68 +156,12 @@ static void maple_release_device(struct device *dev)
158int maple_add_packet(struct maple_device *mdev, u32 function, u32 command, 156int maple_add_packet(struct maple_device *mdev, u32 function, u32 command,
159 size_t length, void *data) 157 size_t length, void *data)
160{ 158{
161 int locking, ret = 0; 159 int ret = 0;
162 void *sendbuf = NULL; 160 void *sendbuf = NULL;
163 161
164 mutex_lock(&maple_wlist_lock);
165 /* bounce if device already locked */
166 locking = mutex_is_locked(&mdev->mq->mutex);
167 if (locking) {
168 ret = -EBUSY;
169 goto out;
170 }
171
172 mutex_lock(&mdev->mq->mutex);
173
174 if (length) { 162 if (length) {
175 sendbuf = kmalloc(length * 4, GFP_KERNEL); 163 sendbuf = kzalloc(length * 4, GFP_KERNEL);
176 if (!sendbuf) { 164 if (!sendbuf) {
177 mutex_unlock(&mdev->mq->mutex);
178 ret = -ENOMEM;
179 goto out;
180 }
181 ((__be32 *)sendbuf)[0] = cpu_to_be32(function);
182 }
183
184 mdev->mq->command = command;
185 mdev->mq->length = length;
186 if (length > 1)
187 memcpy(sendbuf + 4, data, (length - 1) * 4);
188 mdev->mq->sendbuf = sendbuf;
189
190 list_add(&mdev->mq->list, &maple_waitq);
191out:
192 mutex_unlock(&maple_wlist_lock);
193 return ret;
194}
195EXPORT_SYMBOL_GPL(maple_add_packet);
196
197/**
198 * maple_add_packet_sleeps - add a single instruction to the queue
199 * @mdev: maple device
200 * @function: function on device being queried
201 * @command: maple command to add
202 * @length: length of command string (in 32 bit words)
203 * @data: remainder of command string
204 *
205 * Same as maple_add_packet(), but waits for the lock to become free.
206 */
207int maple_add_packet_sleeps(struct maple_device *mdev, u32 function,
208 u32 command, size_t length, void *data)
209{
210 int locking, ret = 0;
211 void *sendbuf = NULL;
212
213 locking = mutex_lock_interruptible(&mdev->mq->mutex);
214 if (locking) {
215 ret = -EIO;
216 goto out;
217 }
218
219 if (length) {
220 sendbuf = kmalloc(length * 4, GFP_KERNEL);
221 if (!sendbuf) {
222 mutex_unlock(&mdev->mq->mutex);
223 ret = -ENOMEM; 165 ret = -ENOMEM;
224 goto out; 166 goto out;
225 } 167 }
@@ -233,38 +175,35 @@ int maple_add_packet_sleeps(struct maple_device *mdev, u32 function,
233 mdev->mq->sendbuf = sendbuf; 175 mdev->mq->sendbuf = sendbuf;
234 176
235 mutex_lock(&maple_wlist_lock); 177 mutex_lock(&maple_wlist_lock);
236 list_add(&mdev->mq->list, &maple_waitq); 178 list_add_tail(&mdev->mq->list, &maple_waitq);
237 mutex_unlock(&maple_wlist_lock); 179 mutex_unlock(&maple_wlist_lock);
238out: 180out:
239 return ret; 181 return ret;
240} 182}
241EXPORT_SYMBOL_GPL(maple_add_packet_sleeps); 183EXPORT_SYMBOL_GPL(maple_add_packet);
242 184
243static struct mapleq *maple_allocq(struct maple_device *mdev) 185static struct mapleq *maple_allocq(struct maple_device *mdev)
244{ 186{
245 struct mapleq *mq; 187 struct mapleq *mq;
246 188
247 mq = kmalloc(sizeof(*mq), GFP_KERNEL); 189 mq = kzalloc(sizeof(*mq), GFP_KERNEL);
248 if (!mq) 190 if (!mq)
249 goto failed_nomem; 191 goto failed_nomem;
250 192
193 INIT_LIST_HEAD(&mq->list);
251 mq->dev = mdev; 194 mq->dev = mdev;
252 mq->recvbufdcsp = kmem_cache_zalloc(maple_queue_cache, GFP_KERNEL); 195 mq->recvbuf = kmem_cache_zalloc(maple_queue_cache, GFP_KERNEL);
253 mq->recvbuf = (void *) P2SEGADDR(mq->recvbufdcsp);
254 if (!mq->recvbuf) 196 if (!mq->recvbuf)
255 goto failed_p2; 197 goto failed_p2;
256 /* 198 mq->recvbuf->buf = &((mq->recvbuf->bufx)[0]);
257 * most devices do not need the mutex - but
258 * anything that injects block reads or writes
259 * will rely on it
260 */
261 mutex_init(&mq->mutex);
262 199
263 return mq; 200 return mq;
264 201
265failed_p2: 202failed_p2:
266 kfree(mq); 203 kfree(mq);
267failed_nomem: 204failed_nomem:
205 dev_err(&mdev->dev, "could not allocate memory for device (%d, %d)\n",
206 mdev->port, mdev->unit);
268 return NULL; 207 return NULL;
269} 208}
270 209
@@ -272,12 +211,16 @@ static struct maple_device *maple_alloc_dev(int port, int unit)
272{ 211{
273 struct maple_device *mdev; 212 struct maple_device *mdev;
274 213
214 /* zero this out to avoid kobj subsystem
215 * thinking it has already been registered */
216
275 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL); 217 mdev = kzalloc(sizeof(*mdev), GFP_KERNEL);
276 if (!mdev) 218 if (!mdev)
277 return NULL; 219 return NULL;
278 220
279 mdev->port = port; 221 mdev->port = port;
280 mdev->unit = unit; 222 mdev->unit = unit;
223
281 mdev->mq = maple_allocq(mdev); 224 mdev->mq = maple_allocq(mdev);
282 225
283 if (!mdev->mq) { 226 if (!mdev->mq) {
@@ -286,19 +229,14 @@ static struct maple_device *maple_alloc_dev(int port, int unit)
286 } 229 }
287 mdev->dev.bus = &maple_bus_type; 230 mdev->dev.bus = &maple_bus_type;
288 mdev->dev.parent = &maple_bus; 231 mdev->dev.parent = &maple_bus;
232 init_waitqueue_head(&mdev->maple_wait);
289 return mdev; 233 return mdev;
290} 234}
291 235
292static void maple_free_dev(struct maple_device *mdev) 236static void maple_free_dev(struct maple_device *mdev)
293{ 237{
294 if (!mdev) 238 kmem_cache_free(maple_queue_cache, mdev->mq->recvbuf);
295 return; 239 kfree(mdev->mq);
296 if (mdev->mq) {
297 if (mdev->mq->recvbufdcsp)
298 kmem_cache_free(maple_queue_cache,
299 mdev->mq->recvbufdcsp);
300 kfree(mdev->mq);
301 }
302 kfree(mdev); 240 kfree(mdev);
303} 241}
304 242
@@ -320,7 +258,7 @@ static void maple_build_block(struct mapleq *mq)
320 maple_lastptr = maple_sendptr; 258 maple_lastptr = maple_sendptr;
321 259
322 *maple_sendptr++ = (port << 16) | len | 0x80000000; 260 *maple_sendptr++ = (port << 16) | len | 0x80000000;
323 *maple_sendptr++ = PHYSADDR(mq->recvbuf); 261 *maple_sendptr++ = PHYSADDR(mq->recvbuf->buf);
324 *maple_sendptr++ = 262 *maple_sendptr++ =
325 mq->command | (to << 8) | (from << 16) | (len << 24); 263 mq->command | (to << 8) | (from << 16) | (len << 24);
326 while (len-- > 0) 264 while (len-- > 0)
@@ -333,20 +271,28 @@ static void maple_send(void)
333 int i, maple_packets = 0; 271 int i, maple_packets = 0;
334 struct mapleq *mq, *nmq; 272 struct mapleq *mq, *nmq;
335 273
336 if (!list_empty(&maple_sentq)) 274 if (!maple_dma_done())
337 return; 275 return;
276
277 /* disable DMA */
278 ctrl_outl(0, MAPLE_ENABLE);
279
280 if (!list_empty(&maple_sentq))
281 goto finish;
282
338 mutex_lock(&maple_wlist_lock); 283 mutex_lock(&maple_wlist_lock);
339 if (list_empty(&maple_waitq) || !maple_dma_done()) { 284 if (list_empty(&maple_waitq)) {
340 mutex_unlock(&maple_wlist_lock); 285 mutex_unlock(&maple_wlist_lock);
341 return; 286 goto finish;
342 } 287 }
343 mutex_unlock(&maple_wlist_lock); 288
344 maple_lastptr = maple_sendbuf; 289 maple_lastptr = maple_sendbuf;
345 maple_sendptr = maple_sendbuf; 290 maple_sendptr = maple_sendbuf;
346 mutex_lock(&maple_wlist_lock); 291
347 list_for_each_entry_safe(mq, nmq, &maple_waitq, list) { 292 list_for_each_entry_safe(mq, nmq, &maple_waitq, list) {
348 maple_build_block(mq); 293 maple_build_block(mq);
349 list_move(&mq->list, &maple_sentq); 294 list_del_init(&mq->list);
295 list_add_tail(&mq->list, &maple_sentq);
350 if (maple_packets++ > MAPLE_MAXPACKETS) 296 if (maple_packets++ > MAPLE_MAXPACKETS)
351 break; 297 break;
352 } 298 }
@@ -356,10 +302,13 @@ static void maple_send(void)
356 dma_cache_sync(0, maple_sendbuf + i * PAGE_SIZE, 302 dma_cache_sync(0, maple_sendbuf + i * PAGE_SIZE,
357 PAGE_SIZE, DMA_BIDIRECTIONAL); 303 PAGE_SIZE, DMA_BIDIRECTIONAL);
358 } 304 }
305
306finish:
307 maple_dma_reset();
359} 308}
360 309
361/* check if there is a driver registered likely to match this device */ 310/* check if there is a driver registered likely to match this device */
362static int check_matching_maple_driver(struct device_driver *driver, 311static int maple_check_matching_driver(struct device_driver *driver,
363 void *devptr) 312 void *devptr)
364{ 313{
365 struct maple_driver *maple_drv; 314 struct maple_driver *maple_drv;
@@ -374,10 +323,7 @@ static int check_matching_maple_driver(struct device_driver *driver,
374 323
375static void maple_detach_driver(struct maple_device *mdev) 324static void maple_detach_driver(struct maple_device *mdev)
376{ 325{
377 if (!mdev)
378 return;
379 device_unregister(&mdev->dev); 326 device_unregister(&mdev->dev);
380 mdev = NULL;
381} 327}
382 328
383/* process initial MAPLE_COMMAND_DEVINFO for each device or port */ 329/* process initial MAPLE_COMMAND_DEVINFO for each device or port */
@@ -385,9 +331,9 @@ static void maple_attach_driver(struct maple_device *mdev)
385{ 331{
386 char *p, *recvbuf; 332 char *p, *recvbuf;
387 unsigned long function; 333 unsigned long function;
388 int matched, retval; 334 int matched, error;
389 335
390 recvbuf = mdev->mq->recvbuf; 336 recvbuf = mdev->mq->recvbuf->buf;
391 /* copy the data as individual elements in 337 /* copy the data as individual elements in
392 * case of memory optimisation */ 338 * case of memory optimisation */
393 memcpy(&mdev->devinfo.function, recvbuf + 4, 4); 339 memcpy(&mdev->devinfo.function, recvbuf + 4, 4);
@@ -395,7 +341,6 @@ static void maple_attach_driver(struct maple_device *mdev)
395 memcpy(&mdev->devinfo.area_code, recvbuf + 20, 1); 341 memcpy(&mdev->devinfo.area_code, recvbuf + 20, 1);
396 memcpy(&mdev->devinfo.connector_direction, recvbuf + 21, 1); 342 memcpy(&mdev->devinfo.connector_direction, recvbuf + 21, 1);
397 memcpy(&mdev->devinfo.product_name[0], recvbuf + 22, 30); 343 memcpy(&mdev->devinfo.product_name[0], recvbuf + 22, 30);
398 memcpy(&mdev->devinfo.product_licence[0], recvbuf + 52, 60);
399 memcpy(&mdev->devinfo.standby_power, recvbuf + 112, 2); 344 memcpy(&mdev->devinfo.standby_power, recvbuf + 112, 2);
400 memcpy(&mdev->devinfo.max_power, recvbuf + 114, 2); 345 memcpy(&mdev->devinfo.max_power, recvbuf + 114, 2);
401 memcpy(mdev->product_name, mdev->devinfo.product_name, 30); 346 memcpy(mdev->product_name, mdev->devinfo.product_name, 30);
@@ -414,43 +359,39 @@ static void maple_attach_driver(struct maple_device *mdev)
414 else 359 else
415 break; 360 break;
416 361
417 printk(KERN_INFO "Maple device detected: %s\n",
418 mdev->product_name);
419 printk(KERN_INFO "Maple device: %s\n", mdev->product_licence);
420
421 function = be32_to_cpu(mdev->devinfo.function); 362 function = be32_to_cpu(mdev->devinfo.function);
422 363
364 dev_info(&mdev->dev, "detected %s: function 0x%lX: at (%d, %d)\n",
365 mdev->product_name, function, mdev->port, mdev->unit);
366
423 if (function > 0x200) { 367 if (function > 0x200) {
424 /* Do this silently - as not a real device */ 368 /* Do this silently - as not a real device */
425 function = 0; 369 function = 0;
426 mdev->driver = &maple_dummy_driver; 370 mdev->driver = &maple_unsupported_device;
427 sprintf(mdev->dev.bus_id, "%d:0.port", mdev->port); 371 dev_set_name(&mdev->dev, "%d:0.port", mdev->port);
428 } else { 372 } else {
429 printk(KERN_INFO
430 "Maple bus at (%d, %d): Function 0x%lX\n",
431 mdev->port, mdev->unit, function);
432
433 matched = 373 matched =
434 bus_for_each_drv(&maple_bus_type, NULL, mdev, 374 bus_for_each_drv(&maple_bus_type, NULL, mdev,
435 check_matching_maple_driver); 375 maple_check_matching_driver);
436 376
437 if (matched == 0) { 377 if (matched == 0) {
438 /* Driver does not exist yet */ 378 /* Driver does not exist yet */
439 printk(KERN_INFO 379 dev_info(&mdev->dev, "no driver found\n");
440 "No maple driver found.\n"); 380 mdev->driver = &maple_unsupported_device;
441 mdev->driver = &maple_dummy_driver;
442 } 381 }
443 sprintf(mdev->dev.bus_id, "%d:0%d.%lX", mdev->port, 382 dev_set_name(&mdev->dev, "%d:0%d.%lX", mdev->port,
444 mdev->unit, function); 383 mdev->unit, function);
445 } 384 }
385
446 mdev->function = function; 386 mdev->function = function;
447 mdev->dev.release = &maple_release_device; 387 mdev->dev.release = &maple_release_device;
448 retval = device_register(&mdev->dev); 388
449 if (retval) { 389 atomic_set(&mdev->busy, 0);
450 printk(KERN_INFO 390 error = device_register(&mdev->dev);
451 "Maple bus: Attempt to register device" 391 if (error) {
452 " (%x, %x) failed.\n", 392 dev_warn(&mdev->dev, "could not register device at"
453 mdev->port, mdev->unit); 393 " (%d, %d), with error 0x%X\n", mdev->unit,
394 mdev->port, error);
454 maple_free_dev(mdev); 395 maple_free_dev(mdev);
455 mdev = NULL; 396 mdev = NULL;
456 return; 397 return;
@@ -462,7 +403,7 @@ static void maple_attach_driver(struct maple_device *mdev)
462 * port and unit then return 1 - allows identification 403 * port and unit then return 1 - allows identification
463 * of which devices need to be attached or detached 404 * of which devices need to be attached or detached
464 */ 405 */
465static int detach_maple_device(struct device *device, void *portptr) 406static int check_maple_device(struct device *device, void *portptr)
466{ 407{
467 struct maple_device_specify *ds; 408 struct maple_device_specify *ds;
468 struct maple_device *mdev; 409 struct maple_device *mdev;
@@ -477,21 +418,25 @@ static int detach_maple_device(struct device *device, void *portptr)
477static int setup_maple_commands(struct device *device, void *ignored) 418static int setup_maple_commands(struct device *device, void *ignored)
478{ 419{
479 int add; 420 int add;
480 struct maple_device *maple_dev = to_maple_dev(device); 421 struct maple_device *mdev = to_maple_dev(device);
481 422 if (mdev->interval > 0 && atomic_read(&mdev->busy) == 0 &&
482 if ((maple_dev->interval > 0) 423 time_after(jiffies, mdev->when)) {
483 && time_after(jiffies, maple_dev->when)) { 424 /* bounce if we cannot add */
484 /* bounce if we cannot lock */ 425 add = maple_add_packet(mdev,
485 add = maple_add_packet(maple_dev, 426 be32_to_cpu(mdev->devinfo.function),
486 be32_to_cpu(maple_dev->devinfo.function),
487 MAPLE_COMMAND_GETCOND, 1, NULL); 427 MAPLE_COMMAND_GETCOND, 1, NULL);
488 if (!add) 428 if (!add)
489 maple_dev->when = jiffies + maple_dev->interval; 429 mdev->when = jiffies + mdev->interval;
490 } else { 430 } else {
491 if (time_after(jiffies, maple_pnp_time)) 431 if (time_after(jiffies, maple_pnp_time))
492 /* This will also bounce */ 432 /* Ensure we don't have block reads and devinfo
493 maple_add_packet(maple_dev, 0, 433 * calls interfering with one another - so flag the
494 MAPLE_COMMAND_DEVINFO, 0, NULL); 434 * device as busy */
435 if (atomic_read(&mdev->busy) == 0) {
436 atomic_set(&mdev->busy, 1);
437 maple_add_packet(mdev, 0,
438 MAPLE_COMMAND_DEVINFO, 0, NULL);
439 }
495 } 440 }
496 return 0; 441 return 0;
497} 442}
@@ -499,29 +444,50 @@ static int setup_maple_commands(struct device *device, void *ignored)
499/* VBLANK bottom half - implemented via workqueue */ 444/* VBLANK bottom half - implemented via workqueue */
500static void maple_vblank_handler(struct work_struct *work) 445static void maple_vblank_handler(struct work_struct *work)
501{ 446{
502 if (!list_empty(&maple_sentq) || !maple_dma_done()) 447 int x, locking;
448 struct maple_device *mdev;
449
450 if (!maple_dma_done())
503 return; 451 return;
504 452
505 ctrl_outl(0, MAPLE_ENABLE); 453 ctrl_outl(0, MAPLE_ENABLE);
506 454
455 if (!list_empty(&maple_sentq))
456 goto finish;
457
458 /*
459 * Set up essential commands - to fetch data and
460 * check devices are still present
461 */
507 bus_for_each_dev(&maple_bus_type, NULL, NULL, 462 bus_for_each_dev(&maple_bus_type, NULL, NULL,
508 setup_maple_commands); 463 setup_maple_commands);
464
465 if (time_after(jiffies, maple_pnp_time)) {
466 /*
467 * Scan the empty ports - bus is flakey and may have
468 * mis-reported emptyness
469 */
470 for (x = 0; x < MAPLE_PORTS; x++) {
471 if (checked[x] && empty[x]) {
472 mdev = baseunits[x];
473 if (!mdev)
474 break;
475 atomic_set(&mdev->busy, 1);
476 locking = maple_add_packet(mdev, 0,
477 MAPLE_COMMAND_DEVINFO, 0, NULL);
478 if (!locking)
479 break;
480 }
481 }
509 482
510 if (time_after(jiffies, maple_pnp_time))
511 maple_pnp_time = jiffies + MAPLE_PNP_INTERVAL; 483 maple_pnp_time = jiffies + MAPLE_PNP_INTERVAL;
512
513 mutex_lock(&maple_wlist_lock);
514 if (!list_empty(&maple_waitq) && list_empty(&maple_sentq)) {
515 mutex_unlock(&maple_wlist_lock);
516 maple_send();
517 } else {
518 mutex_unlock(&maple_wlist_lock);
519 } 484 }
520 485
521 maplebus_dma_reset(); 486finish:
487 maple_send();
522} 488}
523 489
524/* handle devices added via hotplugs - placing them on queue for DEVINFO*/ 490/* handle devices added via hotplugs - placing them on queue for DEVINFO */
525static void maple_map_subunits(struct maple_device *mdev, int submask) 491static void maple_map_subunits(struct maple_device *mdev, int submask)
526{ 492{
527 int retval, k, devcheck; 493 int retval, k, devcheck;
@@ -533,7 +499,7 @@ static void maple_map_subunits(struct maple_device *mdev, int submask)
533 ds.unit = k + 1; 499 ds.unit = k + 1;
534 retval = 500 retval =
535 bus_for_each_dev(&maple_bus_type, NULL, &ds, 501 bus_for_each_dev(&maple_bus_type, NULL, &ds,
536 detach_maple_device); 502 check_maple_device);
537 if (retval) { 503 if (retval) {
538 submask = submask >> 1; 504 submask = submask >> 1;
539 continue; 505 continue;
@@ -543,6 +509,7 @@ static void maple_map_subunits(struct maple_device *mdev, int submask)
543 mdev_add = maple_alloc_dev(mdev->port, k + 1); 509 mdev_add = maple_alloc_dev(mdev->port, k + 1);
544 if (!mdev_add) 510 if (!mdev_add)
545 return; 511 return;
512 atomic_set(&mdev_add->busy, 1);
546 maple_add_packet(mdev_add, 0, MAPLE_COMMAND_DEVINFO, 513 maple_add_packet(mdev_add, 0, MAPLE_COMMAND_DEVINFO,
547 0, NULL); 514 0, NULL);
548 /* mark that we are checking sub devices */ 515 /* mark that we are checking sub devices */
@@ -564,27 +531,45 @@ static void maple_clean_submap(struct maple_device *mdev)
564} 531}
565 532
566/* handle empty port or hotplug removal */ 533/* handle empty port or hotplug removal */
567static void maple_response_none(struct maple_device *mdev, 534static void maple_response_none(struct maple_device *mdev)
568 struct mapleq *mq) 535{
569{ 536 maple_clean_submap(mdev);
570 if (mdev->unit != 0) { 537
571 list_del(&mq->list); 538 if (likely(mdev->unit != 0)) {
572 maple_clean_submap(mdev); 539 /*
573 printk(KERN_INFO 540 * Block devices play up
574 "Maple bus device detaching at (%d, %d)\n", 541 * and give the impression they have
575 mdev->port, mdev->unit); 542 * been removed even when still in place or
543 * trip the mtd layer when they have
544 * really gone - this code traps that eventuality
545 * and ensures we aren't overloaded with useless
546 * error messages
547 */
548 if (mdev->can_unload) {
549 if (!mdev->can_unload(mdev)) {
550 atomic_set(&mdev->busy, 2);
551 wake_up(&mdev->maple_wait);
552 return;
553 }
554 }
555
556 dev_info(&mdev->dev, "detaching device at (%d, %d)\n",
557 mdev->port, mdev->unit);
576 maple_detach_driver(mdev); 558 maple_detach_driver(mdev);
577 return; 559 return;
578 } 560 } else {
579 if (!started || !fullscan) { 561 if (!started || !fullscan) {
580 if (checked[mdev->port] == false) { 562 if (checked[mdev->port] == false) {
581 checked[mdev->port] = true; 563 checked[mdev->port] = true;
582 printk(KERN_INFO "No maple devices attached" 564 empty[mdev->port] = true;
583 " to port %d\n", mdev->port); 565 dev_info(&mdev->dev, "no devices"
566 " to port %d\n", mdev->port);
567 }
568 return;
584 } 569 }
585 return;
586 } 570 }
587 maple_clean_submap(mdev); 571 /* Some hardware devices generate false detach messages on unit 0 */
572 atomic_set(&mdev->busy, 0);
588} 573}
589 574
590/* preprocess hotplugs or scans */ 575/* preprocess hotplugs or scans */
@@ -599,8 +584,11 @@ static void maple_response_devinfo(struct maple_device *mdev,
599 } else { 584 } else {
600 if (mdev->unit != 0) 585 if (mdev->unit != 0)
601 maple_attach_driver(mdev); 586 maple_attach_driver(mdev);
587 if (mdev->unit == 0) {
588 empty[mdev->port] = false;
589 maple_attach_driver(mdev);
590 }
602 } 591 }
603 return;
604 } 592 }
605 if (mdev->unit == 0) { 593 if (mdev->unit == 0) {
606 submask = recvbuf[2] & 0x1F; 594 submask = recvbuf[2] & 0x1F;
@@ -611,6 +599,17 @@ static void maple_response_devinfo(struct maple_device *mdev,
611 } 599 }
612} 600}
613 601
602static void maple_response_fileerr(struct maple_device *mdev, void *recvbuf)
603{
604 if (mdev->fileerr_handler) {
605 mdev->fileerr_handler(mdev, recvbuf);
606 return;
607 } else
608 dev_warn(&mdev->dev, "device at (%d, %d) reports"
609 "file error 0x%X\n", mdev->port, mdev->unit,
610 ((int *)recvbuf)[1]);
611}
612
614static void maple_port_rescan(void) 613static void maple_port_rescan(void)
615{ 614{
616 int i; 615 int i;
@@ -621,12 +620,6 @@ static void maple_port_rescan(void)
621 if (checked[i] == false) { 620 if (checked[i] == false) {
622 fullscan = 0; 621 fullscan = 0;
623 mdev = baseunits[i]; 622 mdev = baseunits[i];
624 /*
625 * test lock in case scan has failed
626 * but device is still locked
627 */
628 if (mutex_is_locked(&mdev->mq->mutex))
629 mutex_unlock(&mdev->mq->mutex);
630 maple_add_packet(mdev, 0, MAPLE_COMMAND_DEVINFO, 623 maple_add_packet(mdev, 0, MAPLE_COMMAND_DEVINFO,
631 0, NULL); 624 0, NULL);
632 } 625 }
@@ -637,7 +630,7 @@ static void maple_port_rescan(void)
637static void maple_dma_handler(struct work_struct *work) 630static void maple_dma_handler(struct work_struct *work)
638{ 631{
639 struct mapleq *mq, *nmq; 632 struct mapleq *mq, *nmq;
640 struct maple_device *dev; 633 struct maple_device *mdev;
641 char *recvbuf; 634 char *recvbuf;
642 enum maple_code code; 635 enum maple_code code;
643 636
@@ -646,43 +639,56 @@ static void maple_dma_handler(struct work_struct *work)
646 ctrl_outl(0, MAPLE_ENABLE); 639 ctrl_outl(0, MAPLE_ENABLE);
647 if (!list_empty(&maple_sentq)) { 640 if (!list_empty(&maple_sentq)) {
648 list_for_each_entry_safe(mq, nmq, &maple_sentq, list) { 641 list_for_each_entry_safe(mq, nmq, &maple_sentq, list) {
649 recvbuf = mq->recvbuf; 642 mdev = mq->dev;
643 recvbuf = mq->recvbuf->buf;
644 dma_cache_sync(&mdev->dev, recvbuf, 0x400,
645 DMA_FROM_DEVICE);
650 code = recvbuf[0]; 646 code = recvbuf[0];
651 dev = mq->dev;
652 kfree(mq->sendbuf); 647 kfree(mq->sendbuf);
653 mutex_unlock(&mq->mutex);
654 list_del_init(&mq->list); 648 list_del_init(&mq->list);
655
656 switch (code) { 649 switch (code) {
657 case MAPLE_RESPONSE_NONE: 650 case MAPLE_RESPONSE_NONE:
658 maple_response_none(dev, mq); 651 maple_response_none(mdev);
659 break; 652 break;
660 653
661 case MAPLE_RESPONSE_DEVINFO: 654 case MAPLE_RESPONSE_DEVINFO:
662 maple_response_devinfo(dev, recvbuf); 655 maple_response_devinfo(mdev, recvbuf);
656 atomic_set(&mdev->busy, 0);
663 break; 657 break;
664 658
665 case MAPLE_RESPONSE_DATATRF: 659 case MAPLE_RESPONSE_DATATRF:
666 if (dev->callback) 660 if (mdev->callback)
667 dev->callback(mq); 661 mdev->callback(mq);
662 atomic_set(&mdev->busy, 0);
663 wake_up(&mdev->maple_wait);
668 break; 664 break;
669 665
670 case MAPLE_RESPONSE_FILEERR: 666 case MAPLE_RESPONSE_FILEERR:
667 maple_response_fileerr(mdev, recvbuf);
668 atomic_set(&mdev->busy, 0);
669 wake_up(&mdev->maple_wait);
670 break;
671
671 case MAPLE_RESPONSE_AGAIN: 672 case MAPLE_RESPONSE_AGAIN:
672 case MAPLE_RESPONSE_BADCMD: 673 case MAPLE_RESPONSE_BADCMD:
673 case MAPLE_RESPONSE_BADFUNC: 674 case MAPLE_RESPONSE_BADFUNC:
674 printk(KERN_DEBUG 675 dev_warn(&mdev->dev, "non-fatal error"
675 "Maple non-fatal error 0x%X\n", 676 " 0x%X at (%d, %d)\n", code,
676 code); 677 mdev->port, mdev->unit);
678 atomic_set(&mdev->busy, 0);
677 break; 679 break;
678 680
679 case MAPLE_RESPONSE_ALLINFO: 681 case MAPLE_RESPONSE_ALLINFO:
680 printk(KERN_DEBUG 682 dev_notice(&mdev->dev, "extended"
681 "Maple - extended device information" 683 " device information request for (%d, %d)"
682 " not supported\n"); 684 " but call is not supported\n", mdev->port,
685 mdev->unit);
686 atomic_set(&mdev->busy, 0);
683 break; 687 break;
684 688
685 case MAPLE_RESPONSE_OK: 689 case MAPLE_RESPONSE_OK:
690 atomic_set(&mdev->busy, 0);
691 wake_up(&mdev->maple_wait);
686 break; 692 break;
687 693
688 default: 694 default:
@@ -699,20 +705,19 @@ static void maple_dma_handler(struct work_struct *work)
699 if (!fullscan) 705 if (!fullscan)
700 maple_port_rescan(); 706 maple_port_rescan();
701 /* mark that we have been through the first scan */ 707 /* mark that we have been through the first scan */
702 if (started == 0) 708 started = 1;
703 started = 1;
704 } 709 }
705 maplebus_dma_reset(); 710 maple_send();
706} 711}
707 712
708static irqreturn_t maplebus_dma_interrupt(int irq, void *dev_id) 713static irqreturn_t maple_dma_interrupt(int irq, void *dev_id)
709{ 714{
710 /* Load everything into the bottom half */ 715 /* Load everything into the bottom half */
711 schedule_work(&maple_dma_process); 716 schedule_work(&maple_dma_process);
712 return IRQ_HANDLED; 717 return IRQ_HANDLED;
713} 718}
714 719
715static irqreturn_t maplebus_vblank_interrupt(int irq, void *dev_id) 720static irqreturn_t maple_vblank_interrupt(int irq, void *dev_id)
716{ 721{
717 schedule_work(&maple_vblank_process); 722 schedule_work(&maple_vblank_process);
718 return IRQ_HANDLED; 723 return IRQ_HANDLED;
@@ -720,14 +725,14 @@ static irqreturn_t maplebus_vblank_interrupt(int irq, void *dev_id)
720 725
721static int maple_set_dma_interrupt_handler(void) 726static int maple_set_dma_interrupt_handler(void)
722{ 727{
723 return request_irq(HW_EVENT_MAPLE_DMA, maplebus_dma_interrupt, 728 return request_irq(HW_EVENT_MAPLE_DMA, maple_dma_interrupt,
724 IRQF_SHARED, "maple bus DMA", &maple_dummy_driver); 729 IRQF_SHARED, "maple bus DMA", &maple_unsupported_device);
725} 730}
726 731
727static int maple_set_vblank_interrupt_handler(void) 732static int maple_set_vblank_interrupt_handler(void)
728{ 733{
729 return request_irq(HW_EVENT_VSYNC, maplebus_vblank_interrupt, 734 return request_irq(HW_EVENT_VSYNC, maple_vblank_interrupt,
730 IRQF_SHARED, "maple bus VBLANK", &maple_dummy_driver); 735 IRQF_SHARED, "maple bus VBLANK", &maple_unsupported_device);
731} 736}
732 737
733static int maple_get_dma_buffer(void) 738static int maple_get_dma_buffer(void)
@@ -740,7 +745,7 @@ static int maple_get_dma_buffer(void)
740 return 0; 745 return 0;
741} 746}
742 747
743static int match_maple_bus_driver(struct device *devptr, 748static int maple_match_bus_driver(struct device *devptr,
744 struct device_driver *drvptr) 749 struct device_driver *drvptr)
745{ 750{
746 struct maple_driver *maple_drv = to_maple_driver(drvptr); 751 struct maple_driver *maple_drv = to_maple_driver(drvptr);
@@ -765,22 +770,24 @@ static void maple_bus_release(struct device *dev)
765{ 770{
766} 771}
767 772
768static struct maple_driver maple_dummy_driver = { 773static struct maple_driver maple_unsupported_device = {
769 .drv = { 774 .drv = {
770 .name = "maple_dummy_driver", 775 .name = "maple_unsupported_device",
771 .bus = &maple_bus_type, 776 .bus = &maple_bus_type,
772 }, 777 },
773}; 778};
774 779/**
780 * maple_bus_type - core maple bus structure
781 */
775struct bus_type maple_bus_type = { 782struct bus_type maple_bus_type = {
776 .name = "maple", 783 .name = "maple",
777 .match = match_maple_bus_driver, 784 .match = maple_match_bus_driver,
778 .uevent = maple_bus_uevent, 785 .uevent = maple_bus_uevent,
779}; 786};
780EXPORT_SYMBOL_GPL(maple_bus_type); 787EXPORT_SYMBOL_GPL(maple_bus_type);
781 788
782static struct device maple_bus = { 789static struct device maple_bus = {
783 .bus_id = "maple", 790 .init_name = "maple",
784 .release = maple_bus_release, 791 .release = maple_bus_release,
785}; 792};
786 793
@@ -788,7 +795,8 @@ static int __init maple_bus_init(void)
788{ 795{
789 int retval, i; 796 int retval, i;
790 struct maple_device *mdev[MAPLE_PORTS]; 797 struct maple_device *mdev[MAPLE_PORTS];
791 ctrl_outl(0, MAPLE_STATE); 798
799 ctrl_outl(0, MAPLE_ENABLE);
792 800
793 retval = device_register(&maple_bus); 801 retval = device_register(&maple_bus);
794 if (retval) 802 if (retval)
@@ -798,36 +806,33 @@ static int __init maple_bus_init(void)
798 if (retval) 806 if (retval)
799 goto cleanup_device; 807 goto cleanup_device;
800 808
801 retval = driver_register(&maple_dummy_driver.drv); 809 retval = driver_register(&maple_unsupported_device.drv);
802 if (retval) 810 if (retval)
803 goto cleanup_bus; 811 goto cleanup_bus;
804 812
805 /* allocate memory for maple bus dma */ 813 /* allocate memory for maple bus dma */
806 retval = maple_get_dma_buffer(); 814 retval = maple_get_dma_buffer();
807 if (retval) { 815 if (retval) {
808 printk(KERN_INFO 816 dev_err(&maple_bus, "failed to allocate DMA buffers\n");
809 "Maple bus: Failed to allocate Maple DMA buffers\n");
810 goto cleanup_basic; 817 goto cleanup_basic;
811 } 818 }
812 819
813 /* set up DMA interrupt handler */ 820 /* set up DMA interrupt handler */
814 retval = maple_set_dma_interrupt_handler(); 821 retval = maple_set_dma_interrupt_handler();
815 if (retval) { 822 if (retval) {
816 printk(KERN_INFO 823 dev_err(&maple_bus, "bus failed to grab maple "
817 "Maple bus: Failed to grab maple DMA IRQ\n"); 824 "DMA IRQ\n");
818 goto cleanup_dma; 825 goto cleanup_dma;
819 } 826 }
820 827
821 /* set up VBLANK interrupt handler */ 828 /* set up VBLANK interrupt handler */
822 retval = maple_set_vblank_interrupt_handler(); 829 retval = maple_set_vblank_interrupt_handler();
823 if (retval) { 830 if (retval) {
824 printk(KERN_INFO "Maple bus: Failed to grab VBLANK IRQ\n"); 831 dev_err(&maple_bus, "bus failed to grab VBLANK IRQ\n");
825 goto cleanup_irq; 832 goto cleanup_irq;
826 } 833 }
827 834
828 maple_queue_cache = 835 maple_queue_cache = KMEM_CACHE(maple_buffer, SLAB_HWCACHE_ALIGN);
829 kmem_cache_create("maple_queue_cache", 0x400, 0,
830 SLAB_HWCACHE_ALIGN, NULL);
831 836
832 if (!maple_queue_cache) 837 if (!maple_queue_cache)
833 goto cleanup_bothirqs; 838 goto cleanup_bothirqs;
@@ -838,23 +843,23 @@ static int __init maple_bus_init(void)
838 /* setup maple ports */ 843 /* setup maple ports */
839 for (i = 0; i < MAPLE_PORTS; i++) { 844 for (i = 0; i < MAPLE_PORTS; i++) {
840 checked[i] = false; 845 checked[i] = false;
846 empty[i] = false;
841 mdev[i] = maple_alloc_dev(i, 0); 847 mdev[i] = maple_alloc_dev(i, 0);
842 baseunits[i] = mdev[i];
843 if (!mdev[i]) { 848 if (!mdev[i]) {
844 while (i-- > 0) 849 while (i-- > 0)
845 maple_free_dev(mdev[i]); 850 maple_free_dev(mdev[i]);
846 goto cleanup_cache; 851 goto cleanup_cache;
847 } 852 }
853 baseunits[i] = mdev[i];
854 atomic_set(&mdev[i]->busy, 1);
848 maple_add_packet(mdev[i], 0, MAPLE_COMMAND_DEVINFO, 0, NULL); 855 maple_add_packet(mdev[i], 0, MAPLE_COMMAND_DEVINFO, 0, NULL);
849 subdevice_map[i] = 0; 856 subdevice_map[i] = 0;
850 } 857 }
851 858
852 /* setup maplebus hardware */ 859 maple_pnp_time = jiffies + HZ;
853 maplebus_dma_reset(); 860 /* prepare initial queue */
854 /* initial detection */
855 maple_send(); 861 maple_send();
856 maple_pnp_time = jiffies; 862 dev_info(&maple_bus, "bus core now registered\n");
857 printk(KERN_INFO "Maple bus core now registered.\n");
858 863
859 return 0; 864 return 0;
860 865
@@ -871,7 +876,7 @@ cleanup_dma:
871 free_pages((unsigned long) maple_sendbuf, MAPLE_DMA_PAGES); 876 free_pages((unsigned long) maple_sendbuf, MAPLE_DMA_PAGES);
872 877
873cleanup_basic: 878cleanup_basic:
874 driver_unregister(&maple_dummy_driver.drv); 879 driver_unregister(&maple_unsupported_device.drv);
875 880
876cleanup_bus: 881cleanup_bus:
877 bus_unregister(&maple_bus_type); 882 bus_unregister(&maple_bus_type);
@@ -880,7 +885,7 @@ cleanup_device:
880 device_unregister(&maple_bus); 885 device_unregister(&maple_bus);
881 886
882cleanup: 887cleanup:
883 printk(KERN_INFO "Maple bus registration failed\n"); 888 printk(KERN_ERR "Maple bus registration failed\n");
884 return retval; 889 return retval;
885} 890}
886/* Push init to later to ensure hardware gets detected */ 891/* Push init to later to ensure hardware gets detected */
diff --git a/drivers/sh/superhyway/superhyway.c b/drivers/sh/superhyway/superhyway.c
index 4d0282b821b5..2d9e7f3d5611 100644
--- a/drivers/sh/superhyway/superhyway.c
+++ b/drivers/sh/superhyway/superhyway.c
@@ -22,7 +22,7 @@
22static int superhyway_devices; 22static int superhyway_devices;
23 23
24static struct device superhyway_bus_device = { 24static struct device superhyway_bus_device = {
25 .bus_id = "superhyway", 25 .init_name = "superhyway",
26}; 26};
27 27
28static void superhyway_device_release(struct device *dev) 28static void superhyway_device_release(struct device *dev)
@@ -83,7 +83,7 @@ int superhyway_add_device(unsigned long base, struct superhyway_device *sdev,
83 dev->id.id = dev->vcr.mod_id; 83 dev->id.id = dev->vcr.mod_id;
84 84
85 sprintf(dev->name, "SuperHyway device %04x", dev->id.id); 85 sprintf(dev->name, "SuperHyway device %04x", dev->id.id);
86 sprintf(dev->dev.bus_id, "%02x", superhyway_devices); 86 dev_set_name(&dev->dev, "%02x", superhyway_devices);
87 87
88 superhyway_devices++; 88 superhyway_devices++;
89 89
diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index 56ff3e6864ea..12e443cc4ac9 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -322,7 +322,7 @@ static void atmel_spi_next_message(struct spi_master *master)
322 spi = msg->spi; 322 spi = msg->spi;
323 323
324 dev_dbg(master->dev.parent, "start message %p for %s\n", 324 dev_dbg(master->dev.parent, "start message %p for %s\n",
325 msg, spi->dev.bus_id); 325 msg, dev_name(&spi->dev));
326 326
327 /* select chip if it's not still active */ 327 /* select chip if it's not still active */
328 if (as->stay) { 328 if (as->stay) {
@@ -627,7 +627,7 @@ static int atmel_spi_setup(struct spi_device *spi)
627 if (!asd) 627 if (!asd)
628 return -ENOMEM; 628 return -ENOMEM;
629 629
630 ret = gpio_request(npcs_pin, spi->dev.bus_id); 630 ret = gpio_request(npcs_pin, dev_name(&spi->dev));
631 if (ret) { 631 if (ret) {
632 kfree(asd); 632 kfree(asd);
633 return ret; 633 return ret;
@@ -668,7 +668,7 @@ static int atmel_spi_transfer(struct spi_device *spi, struct spi_message *msg)
668 as = spi_master_get_devdata(spi->master); 668 as = spi_master_get_devdata(spi->master);
669 669
670 dev_dbg(controller, "new message %p submitted for %s\n", 670 dev_dbg(controller, "new message %p submitted for %s\n",
671 msg, spi->dev.bus_id); 671 msg, dev_name(&spi->dev));
672 672
673 if (unlikely(list_empty(&msg->transfers))) 673 if (unlikely(list_empty(&msg->transfers)))
674 return -EINVAL; 674 return -EINVAL;
@@ -803,7 +803,7 @@ static int __init atmel_spi_probe(struct platform_device *pdev)
803 as->clk = clk; 803 as->clk = clk;
804 804
805 ret = request_irq(irq, atmel_spi_interrupt, 0, 805 ret = request_irq(irq, atmel_spi_interrupt, 0,
806 pdev->dev.bus_id, master); 806 dev_name(&pdev->dev), master);
807 if (ret) 807 if (ret)
808 goto out_unmap_regs; 808 goto out_unmap_regs;
809 809
diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c
index 3b97803e1d11..68c77a911595 100644
--- a/drivers/spi/mpc52xx_psc_spi.c
+++ b/drivers/spi/mpc52xx_psc_spi.c
@@ -429,7 +429,7 @@ static int __init mpc52xx_psc_spi_do_probe(struct device *dev, u32 regaddr,
429 INIT_LIST_HEAD(&mps->queue); 429 INIT_LIST_HEAD(&mps->queue);
430 430
431 mps->workqueue = create_singlethread_workqueue( 431 mps->workqueue = create_singlethread_workqueue(
432 master->dev.parent->bus_id); 432 dev_name(master->dev.parent));
433 if (mps->workqueue == NULL) { 433 if (mps->workqueue == NULL) {
434 ret = -EBUSY; 434 ret = -EBUSY;
435 goto free_irq; 435 goto free_irq;
diff --git a/drivers/spi/omap2_mcspi.c b/drivers/spi/omap2_mcspi.c
index 454a2712e629..1c65e380c845 100644
--- a/drivers/spi/omap2_mcspi.c
+++ b/drivers/spi/omap2_mcspi.c
@@ -1003,7 +1003,7 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev)
1003 goto err1; 1003 goto err1;
1004 } 1004 }
1005 if (!request_mem_region(r->start, (r->end - r->start) + 1, 1005 if (!request_mem_region(r->start, (r->end - r->start) + 1,
1006 pdev->dev.bus_id)) { 1006 dev_name(&pdev->dev))) {
1007 status = -EBUSY; 1007 status = -EBUSY;
1008 goto err1; 1008 goto err1;
1009 } 1009 }
diff --git a/drivers/spi/omap_uwire.c b/drivers/spi/omap_uwire.c
index bab6ff061e91..60b5381c65c4 100644
--- a/drivers/spi/omap_uwire.c
+++ b/drivers/spi/omap_uwire.c
@@ -245,7 +245,7 @@ static int uwire_txrx(struct spi_device *spi, struct spi_transfer *t)
245 245
246#ifdef VERBOSE 246#ifdef VERBOSE
247 pr_debug("%s: write-%d =%04x\n", 247 pr_debug("%s: write-%d =%04x\n",
248 spi->dev.bus_id, bits, val); 248 dev_name(&spi->dev), bits, val);
249#endif 249#endif
250 if (wait_uwire_csr_flag(CSRB, 0, 0)) 250 if (wait_uwire_csr_flag(CSRB, 0, 0))
251 goto eio; 251 goto eio;
@@ -305,7 +305,7 @@ static int uwire_txrx(struct spi_device *spi, struct spi_transfer *t)
305 status += bytes; 305 status += bytes;
306#ifdef VERBOSE 306#ifdef VERBOSE
307 pr_debug("%s: read-%d =%04x\n", 307 pr_debug("%s: read-%d =%04x\n",
308 spi->dev.bus_id, bits, val); 308 dev_name(&spi->dev), bits, val);
309#endif 309#endif
310 310
311 } 311 }
@@ -331,7 +331,7 @@ static int uwire_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
331 uwire = spi_master_get_devdata(spi->master); 331 uwire = spi_master_get_devdata(spi->master);
332 332
333 if (spi->chip_select > 3) { 333 if (spi->chip_select > 3) {
334 pr_debug("%s: cs%d?\n", spi->dev.bus_id, spi->chip_select); 334 pr_debug("%s: cs%d?\n", dev_name(&spi->dev), spi->chip_select);
335 status = -ENODEV; 335 status = -ENODEV;
336 goto done; 336 goto done;
337 } 337 }
@@ -343,7 +343,7 @@ static int uwire_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
343 bits = 8; 343 bits = 8;
344 344
345 if (bits > 16) { 345 if (bits > 16) {
346 pr_debug("%s: wordsize %d?\n", spi->dev.bus_id, bits); 346 pr_debug("%s: wordsize %d?\n", dev_name(&spi->dev), bits);
347 status = -ENODEV; 347 status = -ENODEV;
348 goto done; 348 goto done;
349 } 349 }
@@ -378,7 +378,7 @@ static int uwire_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
378 hz = t->speed_hz; 378 hz = t->speed_hz;
379 379
380 if (!hz) { 380 if (!hz) {
381 pr_debug("%s: zero speed?\n", spi->dev.bus_id); 381 pr_debug("%s: zero speed?\n", dev_name(&spi->dev));
382 status = -EINVAL; 382 status = -EINVAL;
383 goto done; 383 goto done;
384 } 384 }
@@ -406,7 +406,7 @@ static int uwire_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
406 } 406 }
407 if (div1_idx == 4) { 407 if (div1_idx == 4) {
408 pr_debug("%s: lowest clock %ld, need %d\n", 408 pr_debug("%s: lowest clock %ld, need %d\n",
409 spi->dev.bus_id, rate / 10 / 8, hz); 409 dev_name(&spi->dev), rate / 10 / 8, hz);
410 status = -EDOM; 410 status = -EDOM;
411 goto done; 411 goto done;
412 } 412 }
diff --git a/drivers/spi/orion_spi.c b/drivers/spi/orion_spi.c
index 014becb7d530..c8b0babdc2a6 100644
--- a/drivers/spi/orion_spi.c
+++ b/drivers/spi/orion_spi.c
@@ -496,7 +496,7 @@ static int __init orion_spi_probe(struct platform_device *pdev)
496 } 496 }
497 497
498 if (!request_mem_region(r->start, (r->end - r->start) + 1, 498 if (!request_mem_region(r->start, (r->end - r->start) + 1,
499 pdev->dev.bus_id)) { 499 dev_name(&pdev->dev))) {
500 status = -EBUSY; 500 status = -EBUSY;
501 goto out; 501 goto out;
502 } 502 }
diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c
index d0fc4ca2f656..ec24f2d16f3c 100644
--- a/drivers/spi/pxa2xx_spi.c
+++ b/drivers/spi/pxa2xx_spi.c
@@ -1333,7 +1333,7 @@ static int __init init_queue(struct driver_data *drv_data)
1333 1333
1334 INIT_WORK(&drv_data->pump_messages, pump_messages); 1334 INIT_WORK(&drv_data->pump_messages, pump_messages);
1335 drv_data->workqueue = create_singlethread_workqueue( 1335 drv_data->workqueue = create_singlethread_workqueue(
1336 drv_data->master->dev.parent->bus_id); 1336 dev_name(drv_data->master->dev.parent));
1337 if (drv_data->workqueue == NULL) 1337 if (drv_data->workqueue == NULL)
1338 return -EBUSY; 1338 return -EBUSY;
1339 1339
@@ -1462,7 +1462,7 @@ static int __init pxa2xx_spi_probe(struct platform_device *pdev)
1462 drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR; 1462 drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR;
1463 } 1463 }
1464 1464
1465 status = request_irq(ssp->irq, ssp_int, 0, dev->bus_id, drv_data); 1465 status = request_irq(ssp->irq, ssp_int, 0, dev_name(dev), drv_data);
1466 if (status < 0) { 1466 if (status < 0) {
1467 dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq); 1467 dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq);
1468 goto out_error_master_alloc; 1468 goto out_error_master_alloc;
diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c
index 7fea3cf4588a..3410b0c55ed2 100644
--- a/drivers/spi/spi_bfin5xx.c
+++ b/drivers/spi/spi_bfin5xx.c
@@ -1160,8 +1160,8 @@ static inline int init_queue(struct driver_data *drv_data)
1160 1160
1161 /* init messages workqueue */ 1161 /* init messages workqueue */
1162 INIT_WORK(&drv_data->pump_messages, pump_messages); 1162 INIT_WORK(&drv_data->pump_messages, pump_messages);
1163 drv_data->workqueue = 1163 drv_data->workqueue = create_singlethread_workqueue(
1164 create_singlethread_workqueue(drv_data->master->dev.parent->bus_id); 1164 dev_name(drv_data->master->dev.parent));
1165 if (drv_data->workqueue == NULL) 1165 if (drv_data->workqueue == NULL)
1166 return -EBUSY; 1166 return -EBUSY;
1167 1167
diff --git a/drivers/spi/spi_gpio.c b/drivers/spi/spi_gpio.c
index f5ed9721aabb..d2866c293dee 100644
--- a/drivers/spi/spi_gpio.c
+++ b/drivers/spi/spi_gpio.c
@@ -191,7 +191,7 @@ static int spi_gpio_setup(struct spi_device *spi)
191 return -EINVAL; 191 return -EINVAL;
192 192
193 if (!spi->controller_state) { 193 if (!spi->controller_state) {
194 status = gpio_request(cs, spi->dev.bus_id); 194 status = gpio_request(cs, dev_name(&spi->dev));
195 if (status) 195 if (status)
196 return status; 196 return status;
197 status = gpio_direction_output(cs, spi->mode & SPI_CS_HIGH); 197 status = gpio_direction_output(cs, spi->mode & SPI_CS_HIGH);
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c
index 269a55ec52ef..0480d8bb19d3 100644
--- a/drivers/spi/spi_imx.c
+++ b/drivers/spi/spi_imx.c
@@ -1381,7 +1381,7 @@ static int __init init_queue(struct driver_data *drv_data)
1381 1381
1382 INIT_WORK(&drv_data->work, pump_messages); 1382 INIT_WORK(&drv_data->work, pump_messages);
1383 drv_data->workqueue = create_singlethread_workqueue( 1383 drv_data->workqueue = create_singlethread_workqueue(
1384 drv_data->master->dev.parent->bus_id); 1384 dev_name(drv_data->master->dev.parent));
1385 if (drv_data->workqueue == NULL) 1385 if (drv_data->workqueue == NULL)
1386 return -EBUSY; 1386 return -EBUSY;
1387 1387
@@ -1525,7 +1525,8 @@ static int __init spi_imx_probe(struct platform_device *pdev)
1525 status = -ENODEV; 1525 status = -ENODEV;
1526 goto err_no_irqres; 1526 goto err_no_irqres;
1527 } 1527 }
1528 status = request_irq(irq, spi_int, IRQF_DISABLED, dev->bus_id, drv_data); 1528 status = request_irq(irq, spi_int, IRQF_DISABLED,
1529 dev_name(dev), drv_data);
1529 if (status < 0) { 1530 if (status < 0) {
1530 dev_err(&pdev->dev, "probe - cannot get IRQ (%d)\n", status); 1531 dev_err(&pdev->dev, "probe - cannot get IRQ (%d)\n", status);
1531 goto err_no_irqres; 1532 goto err_no_irqres;
diff --git a/drivers/spi/spi_mpc83xx.c b/drivers/spi/spi_mpc83xx.c
index ac0e3e4b3c54..44a2b46ccb79 100644
--- a/drivers/spi/spi_mpc83xx.c
+++ b/drivers/spi/spi_mpc83xx.c
@@ -637,7 +637,7 @@ static int __init mpc83xx_spi_probe(struct platform_device *dev)
637 INIT_LIST_HEAD(&mpc83xx_spi->queue); 637 INIT_LIST_HEAD(&mpc83xx_spi->queue);
638 638
639 mpc83xx_spi->workqueue = create_singlethread_workqueue( 639 mpc83xx_spi->workqueue = create_singlethread_workqueue(
640 master->dev.parent->bus_id); 640 dev_name(master->dev.parent));
641 if (mpc83xx_spi->workqueue == NULL) { 641 if (mpc83xx_spi->workqueue == NULL) {
642 ret = -EBUSY; 642 ret = -EBUSY;
643 goto free_irq; 643 goto free_irq;
@@ -649,7 +649,7 @@ static int __init mpc83xx_spi_probe(struct platform_device *dev)
649 649
650 printk(KERN_INFO 650 printk(KERN_INFO
651 "%s: MPC83xx SPI Controller driver at 0x%p (irq = %d)\n", 651 "%s: MPC83xx SPI Controller driver at 0x%p (irq = %d)\n",
652 dev->dev.bus_id, mpc83xx_spi->base, mpc83xx_spi->irq); 652 dev_name(&dev->dev), mpc83xx_spi->base, mpc83xx_spi->irq);
653 653
654 return ret; 654 return ret;
655 655
diff --git a/drivers/spi/spi_txx9.c b/drivers/spi/spi_txx9.c
index 2296f37ea3c6..29cbb065618a 100644
--- a/drivers/spi/spi_txx9.c
+++ b/drivers/spi/spi_txx9.c
@@ -404,7 +404,8 @@ static int __init txx9spi_probe(struct platform_device *dev)
404 if (ret) 404 if (ret)
405 goto exit; 405 goto exit;
406 406
407 c->workqueue = create_singlethread_workqueue(master->dev.parent->bus_id); 407 c->workqueue = create_singlethread_workqueue(
408 dev_name(master->dev.parent));
408 if (!c->workqueue) 409 if (!c->workqueue)
409 goto exit_busy; 410 goto exit_busy;
410 c->last_chipselect = -1; 411 c->last_chipselect = -1;
diff --git a/drivers/staging/go7007/snd-go7007.c b/drivers/staging/go7007/snd-go7007.c
index a7de401f61ab..cd19be6c00e0 100644
--- a/drivers/staging/go7007/snd-go7007.c
+++ b/drivers/staging/go7007/snd-go7007.c
@@ -248,10 +248,11 @@ int go7007_snd_init(struct go7007 *go)
248 spin_lock_init(&gosnd->lock); 248 spin_lock_init(&gosnd->lock);
249 gosnd->hw_ptr = gosnd->w_idx = gosnd->avail = 0; 249 gosnd->hw_ptr = gosnd->w_idx = gosnd->avail = 0;
250 gosnd->capturing = 0; 250 gosnd->capturing = 0;
251 gosnd->card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 251 ret = snd_card_create(index[dev], id[dev], THIS_MODULE, 0,
252 if (gosnd->card == NULL) { 252 &gosnd->card);
253 if (ret < 0) {
253 kfree(gosnd); 254 kfree(gosnd);
254 return -ENOMEM; 255 return ret;
255 } 256 }
256 ret = snd_device_new(gosnd->card, SNDRV_DEV_LOWLEVEL, go, 257 ret = snd_device_new(gosnd->card, SNDRV_DEV_LOWLEVEL, go,
257 &go7007_snd_device_ops); 258 &go7007_snd_device_ops);
diff --git a/drivers/tc/tc.c b/drivers/tc/tc.c
index f77f62a4b325..e5bd4470a570 100644
--- a/drivers/tc/tc.c
+++ b/drivers/tc/tc.c
@@ -86,7 +86,7 @@ static void __init tc_bus_add_devices(struct tc_bus *tbus)
86 slot); 86 slot);
87 goto out_err; 87 goto out_err;
88 } 88 }
89 sprintf(tdev->dev.bus_id, "tc%x", slot); 89 dev_set_name(&tdev->dev, "tc%x", slot);
90 tdev->bus = tbus; 90 tdev->bus = tbus;
91 tdev->dev.parent = &tbus->dev; 91 tdev->dev.parent = &tbus->dev;
92 tdev->dev.bus = &tc_bus_type; 92 tdev->dev.bus = &tc_bus_type;
@@ -104,7 +104,7 @@ static void __init tc_bus_add_devices(struct tc_bus *tbus)
104 tdev->vendor[8] = 0; 104 tdev->vendor[8] = 0;
105 tdev->name[8] = 0; 105 tdev->name[8] = 0;
106 106
107 pr_info("%s: %s %s %s\n", tdev->dev.bus_id, tdev->vendor, 107 pr_info("%s: %s %s %s\n", dev_name(&tdev->dev), tdev->vendor,
108 tdev->name, tdev->firmware); 108 tdev->name, tdev->firmware);
109 109
110 devsize = readb(module + offset + TC_SLOT_SIZE); 110 devsize = readb(module + offset + TC_SLOT_SIZE);
@@ -118,7 +118,7 @@ static void __init tc_bus_add_devices(struct tc_bus *tbus)
118 } else { 118 } else {
119 printk(KERN_ERR "%s: Cannot provide slot space " 119 printk(KERN_ERR "%s: Cannot provide slot space "
120 "(%dMiB required, up to %dMiB supported)\n", 120 "(%dMiB required, up to %dMiB supported)\n",
121 tdev->dev.bus_id, devsize >> 20, 121 dev_name(&tdev->dev), devsize >> 20,
122 max(slotsize, extslotsize) >> 20); 122 max(slotsize, extslotsize) >> 20);
123 kfree(tdev); 123 kfree(tdev);
124 goto out_err; 124 goto out_err;
@@ -146,7 +146,7 @@ static int __init tc_init(void)
146 return 0; 146 return 0;
147 147
148 INIT_LIST_HEAD(&tc_bus.devices); 148 INIT_LIST_HEAD(&tc_bus.devices);
149 strcpy(tc_bus.dev.bus_id, "tc"); 149 dev_set_name(&tc_bus.dev, "tc");
150 device_register(&tc_bus.dev); 150 device_register(&tc_bus.dev);
151 151
152 if (tc_bus.info.slot_size) { 152 if (tc_bus.info.slot_size) {
diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig
index 04b954cfce76..7f86534de269 100644
--- a/drivers/uio/Kconfig
+++ b/drivers/uio/Kconfig
@@ -58,6 +58,24 @@ config UIO_SMX
58 58
59 If you compile this as a module, it will be called uio_smx. 59 If you compile this as a module, it will be called uio_smx.
60 60
61config UIO_AEC
62 tristate "AEC video timestamp device"
63 depends on PCI
64 default n
65 help
66
67 UIO driver for the Adrienne Electronics Corporation PCI time
68 code device.
69
70 This device differs from other UIO devices since it uses I/O
71 ports instead of memory mapped I/O. In order to make it
72 possible for UIO to work with this device a utility, uioport,
73 can be used to read and write the ports:
74
75 git clone git://ifup.org/philips/uioport.git
76
77 If you compile this as a module, it will be called uio_aec.
78
61config UIO_SERCOS3 79config UIO_SERCOS3
62 tristate "Automata Sercos III PCI card driver" 80 tristate "Automata Sercos III PCI card driver"
63 default n 81 default n
diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile
index e69558149859..5c2586d75797 100644
--- a/drivers/uio/Makefile
+++ b/drivers/uio/Makefile
@@ -3,4 +3,5 @@ obj-$(CONFIG_UIO_CIF) += uio_cif.o
3obj-$(CONFIG_UIO_PDRV) += uio_pdrv.o 3obj-$(CONFIG_UIO_PDRV) += uio_pdrv.o
4obj-$(CONFIG_UIO_PDRV_GENIRQ) += uio_pdrv_genirq.o 4obj-$(CONFIG_UIO_PDRV_GENIRQ) += uio_pdrv_genirq.o
5obj-$(CONFIG_UIO_SMX) += uio_smx.o 5obj-$(CONFIG_UIO_SMX) += uio_smx.o
6obj-$(CONFIG_UIO_AEC) += uio_aec.o
6obj-$(CONFIG_UIO_SERCOS3) += uio_sercos3.o 7obj-$(CONFIG_UIO_SERCOS3) += uio_sercos3.o
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 4ca85a113aa2..03efb065455f 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -61,6 +61,14 @@ struct uio_map {
61}; 61};
62#define to_map(map) container_of(map, struct uio_map, kobj) 62#define to_map(map) container_of(map, struct uio_map, kobj)
63 63
64static ssize_t map_name_show(struct uio_mem *mem, char *buf)
65{
66 if (unlikely(!mem->name))
67 mem->name = "";
68
69 return sprintf(buf, "%s\n", mem->name);
70}
71
64static ssize_t map_addr_show(struct uio_mem *mem, char *buf) 72static ssize_t map_addr_show(struct uio_mem *mem, char *buf)
65{ 73{
66 return sprintf(buf, "0x%lx\n", mem->addr); 74 return sprintf(buf, "0x%lx\n", mem->addr);
@@ -82,6 +90,8 @@ struct map_sysfs_entry {
82 ssize_t (*store)(struct uio_mem *, const char *, size_t); 90 ssize_t (*store)(struct uio_mem *, const char *, size_t);
83}; 91};
84 92
93static struct map_sysfs_entry name_attribute =
94 __ATTR(name, S_IRUGO, map_name_show, NULL);
85static struct map_sysfs_entry addr_attribute = 95static struct map_sysfs_entry addr_attribute =
86 __ATTR(addr, S_IRUGO, map_addr_show, NULL); 96 __ATTR(addr, S_IRUGO, map_addr_show, NULL);
87static struct map_sysfs_entry size_attribute = 97static struct map_sysfs_entry size_attribute =
@@ -90,6 +100,7 @@ static struct map_sysfs_entry offset_attribute =
90 __ATTR(offset, S_IRUGO, map_offset_show, NULL); 100 __ATTR(offset, S_IRUGO, map_offset_show, NULL);
91 101
92static struct attribute *attrs[] = { 102static struct attribute *attrs[] = {
103 &name_attribute.attr,
93 &addr_attribute.attr, 104 &addr_attribute.attr,
94 &size_attribute.attr, 105 &size_attribute.attr,
95 &offset_attribute.attr, 106 &offset_attribute.attr,
@@ -133,6 +144,14 @@ struct uio_portio {
133}; 144};
134#define to_portio(portio) container_of(portio, struct uio_portio, kobj) 145#define to_portio(portio) container_of(portio, struct uio_portio, kobj)
135 146
147static ssize_t portio_name_show(struct uio_port *port, char *buf)
148{
149 if (unlikely(!port->name))
150 port->name = "";
151
152 return sprintf(buf, "%s\n", port->name);
153}
154
136static ssize_t portio_start_show(struct uio_port *port, char *buf) 155static ssize_t portio_start_show(struct uio_port *port, char *buf)
137{ 156{
138 return sprintf(buf, "0x%lx\n", port->start); 157 return sprintf(buf, "0x%lx\n", port->start);
@@ -159,6 +178,8 @@ struct portio_sysfs_entry {
159 ssize_t (*store)(struct uio_port *, const char *, size_t); 178 ssize_t (*store)(struct uio_port *, const char *, size_t);
160}; 179};
161 180
181static struct portio_sysfs_entry portio_name_attribute =
182 __ATTR(name, S_IRUGO, portio_name_show, NULL);
162static struct portio_sysfs_entry portio_start_attribute = 183static struct portio_sysfs_entry portio_start_attribute =
163 __ATTR(start, S_IRUGO, portio_start_show, NULL); 184 __ATTR(start, S_IRUGO, portio_start_show, NULL);
164static struct portio_sysfs_entry portio_size_attribute = 185static struct portio_sysfs_entry portio_size_attribute =
@@ -167,6 +188,7 @@ static struct portio_sysfs_entry portio_porttype_attribute =
167 __ATTR(porttype, S_IRUGO, portio_porttype_show, NULL); 188 __ATTR(porttype, S_IRUGO, portio_porttype_show, NULL);
168 189
169static struct attribute *portio_attrs[] = { 190static struct attribute *portio_attrs[] = {
191 &portio_name_attribute.attr,
170 &portio_start_attribute.attr, 192 &portio_start_attribute.attr,
171 &portio_size_attribute.attr, 193 &portio_size_attribute.attr,
172 &portio_porttype_attribute.attr, 194 &portio_porttype_attribute.attr,
@@ -686,7 +708,8 @@ static int uio_mmap(struct file *filep, struct vm_area_struct *vma)
686 return -EINVAL; 708 return -EINVAL;
687 709
688 requested_pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; 710 requested_pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
689 actual_pages = (idev->info->mem[mi].size + PAGE_SIZE -1) >> PAGE_SHIFT; 711 actual_pages = ((idev->info->mem[mi].addr & ~PAGE_MASK)
712 + idev->info->mem[mi].size + PAGE_SIZE -1) >> PAGE_SHIFT;
690 if (requested_pages > actual_pages) 713 if (requested_pages > actual_pages)
691 return -EINVAL; 714 return -EINVAL;
692 715
diff --git a/drivers/uio/uio_aec.c b/drivers/uio/uio_aec.c
new file mode 100644
index 000000000000..b7830e9a3baa
--- /dev/null
+++ b/drivers/uio/uio_aec.c
@@ -0,0 +1,175 @@
1/*
2 * uio_aec.c -- simple driver for Adrienne Electronics Corp time code PCI device
3 *
4 * Copyright (C) 2008 Brandon Philips <brandon@ifup.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc., 59
17 * Temple Place, Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20#include <linux/kernel.h>
21#include <linux/module.h>
22#include <linux/pci.h>
23#include <linux/init.h>
24#include <linux/interrupt.h>
25#include <linux/cdev.h>
26#include <linux/fs.h>
27#include <linux/io.h>
28#include <linux/uaccess.h>
29#include <linux/uio_driver.h>
30
31#define PCI_VENDOR_ID_AEC 0xaecb
32#define PCI_DEVICE_ID_AEC_VITCLTC 0x6250
33
34#define INT_ENABLE_ADDR 0xFC
35#define INT_ENABLE 0x10
36#define INT_DISABLE 0x0
37
38#define INT_MASK_ADDR 0x2E
39#define INT_MASK_ALL 0x3F
40
41#define INTA_DRVR_ADDR 0xFE
42#define INTA_ENABLED_FLAG 0x08
43#define INTA_FLAG 0x01
44
45#define MAILBOX 0x0F
46
47static struct pci_device_id ids[] = {
48 { PCI_DEVICE(PCI_VENDOR_ID_AEC, PCI_DEVICE_ID_AEC_VITCLTC), },
49 { 0, }
50};
51MODULE_DEVICE_TABLE(pci, ids);
52
53static irqreturn_t aectc_irq(int irq, struct uio_info *dev_info)
54{
55 void __iomem *int_flag = dev_info->priv + INTA_DRVR_ADDR;
56 unsigned char status = ioread8(int_flag);
57
58
59 if ((status & INTA_ENABLED_FLAG) && (status & INTA_FLAG)) {
60 /* application writes 0x00 to 0x2F to get next interrupt */
61 status = ioread8(dev_info->priv + MAILBOX);
62 return IRQ_HANDLED;
63 }
64
65 return IRQ_NONE;
66}
67
68static void print_board_data(struct pci_dev *pdev, struct uio_info *i)
69{
70 dev_info(&pdev->dev, "PCI-TC board vendor: %x%x number: %x%x"
71 " revision: %c%c\n",
72 ioread8(i->priv + 0x01),
73 ioread8(i->priv + 0x00),
74 ioread8(i->priv + 0x03),
75 ioread8(i->priv + 0x02),
76 ioread8(i->priv + 0x06),
77 ioread8(i->priv + 0x07));
78}
79
80static int __devinit probe(struct pci_dev *pdev, const struct pci_device_id *id)
81{
82 struct uio_info *info;
83 int ret;
84
85 info = kzalloc(sizeof(struct uio_info), GFP_KERNEL);
86 if (!info)
87 return -ENOMEM;
88
89 if (pci_enable_device(pdev))
90 goto out_free;
91
92 if (pci_request_regions(pdev, "aectc"))
93 goto out_disable;
94
95 info->name = "aectc";
96 info->port[0].start = pci_resource_start(pdev, 0);
97 if (!info->port[0].start)
98 goto out_release;
99 info->priv = pci_iomap(pdev, 0, 0);
100 if (!info->priv)
101 goto out_release;
102 info->port[0].size = pci_resource_len(pdev, 0);
103 info->port[0].porttype = UIO_PORT_GPIO;
104
105 info->version = "0.0.1";
106 info->irq = pdev->irq;
107 info->irq_flags = IRQF_SHARED;
108 info->handler = aectc_irq;
109
110 print_board_data(pdev, info);
111 ret = uio_register_device(&pdev->dev, info);
112 if (ret)
113 goto out_unmap;
114
115 iowrite32(INT_ENABLE, info->priv + INT_ENABLE_ADDR);
116 iowrite8(INT_MASK_ALL, info->priv + INT_MASK_ADDR);
117 if (!(ioread8(info->priv + INTA_DRVR_ADDR)
118 & INTA_ENABLED_FLAG))
119 dev_err(&pdev->dev, "aectc: interrupts not enabled\n");
120
121 pci_set_drvdata(pdev, info);
122
123 return 0;
124
125out_unmap:
126 pci_iounmap(pdev, info->priv);
127out_release:
128 pci_release_regions(pdev);
129out_disable:
130 pci_disable_device(pdev);
131out_free:
132 kfree(info);
133 return -ENODEV;
134}
135
136static void remove(struct pci_dev *pdev)
137{
138 struct uio_info *info = pci_get_drvdata(pdev);
139
140 /* disable interrupts */
141 iowrite8(INT_DISABLE, info->priv + INT_MASK_ADDR);
142 iowrite32(INT_DISABLE, info->priv + INT_ENABLE_ADDR);
143 /* read mailbox to ensure board drops irq */
144 ioread8(info->priv + MAILBOX);
145
146 uio_unregister_device(info);
147 pci_release_regions(pdev);
148 pci_disable_device(pdev);
149 pci_set_drvdata(pdev, NULL);
150 iounmap(info->priv);
151
152 kfree(info);
153}
154
155static struct pci_driver pci_driver = {
156 .name = "aectc",
157 .id_table = ids,
158 .probe = probe,
159 .remove = remove,
160};
161
162static int __init aectc_init(void)
163{
164 return pci_register_driver(&pci_driver);
165}
166
167static void __exit aectc_exit(void)
168{
169 pci_unregister_driver(&pci_driver);
170}
171
172MODULE_LICENSE("GPL");
173
174module_init(aectc_init);
175module_exit(aectc_exit);
diff --git a/drivers/usb/Kconfig b/drivers/usb/Kconfig
index 83babb0a1df7..c6c816b7ecb5 100644
--- a/drivers/usb/Kconfig
+++ b/drivers/usb/Kconfig
@@ -47,6 +47,7 @@ config USB_ARCH_HAS_OHCI
47 default y if CPU_SUBTYPE_SH7720 47 default y if CPU_SUBTYPE_SH7720
48 default y if CPU_SUBTYPE_SH7721 48 default y if CPU_SUBTYPE_SH7721
49 default y if CPU_SUBTYPE_SH7763 49 default y if CPU_SUBTYPE_SH7763
50 default y if CPU_SUBTYPE_SH7786
50 # more: 51 # more:
51 default PCI 52 default PCI
52 53
diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index b2ceb4aff233..89299a5ce168 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_USB_SL811_HCD) += host/
19obj-$(CONFIG_USB_U132_HCD) += host/ 19obj-$(CONFIG_USB_U132_HCD) += host/
20obj-$(CONFIG_USB_R8A66597_HCD) += host/ 20obj-$(CONFIG_USB_R8A66597_HCD) += host/
21obj-$(CONFIG_USB_HWA_HCD) += host/ 21obj-$(CONFIG_USB_HWA_HCD) += host/
22obj-$(CONFIG_USB_ISP1760_HCD) += host/
22 23
23obj-$(CONFIG_USB_C67X00_HCD) += c67x00/ 24obj-$(CONFIG_USB_C67X00_HCD) += c67x00/
24 25
diff --git a/drivers/usb/class/usblp.c b/drivers/usb/class/usblp.c
index 3f3ee1351930..d2747a49b974 100644
--- a/drivers/usb/class/usblp.c
+++ b/drivers/usb/class/usblp.c
@@ -880,16 +880,19 @@ static int usblp_wwait(struct usblp *usblp, int nonblock)
880 if (rc <= 0) 880 if (rc <= 0)
881 break; 881 break;
882 882
883 if (usblp->flags & LP_ABORT) { 883 if (schedule_timeout(msecs_to_jiffies(1500)) == 0) {
884 if (schedule_timeout(msecs_to_jiffies(5000)) == 0) { 884 if (usblp->flags & LP_ABORT) {
885 err = usblp_check_status(usblp, err); 885 err = usblp_check_status(usblp, err);
886 if (err == 1) { /* Paper out */ 886 if (err == 1) { /* Paper out */
887 rc = -ENOSPC; 887 rc = -ENOSPC;
888 break; 888 break;
889 } 889 }
890 } else {
891 /* Prod the printer, Gentoo#251237. */
892 mutex_lock(&usblp->mut);
893 usblp_read_status(usblp, usblp->statusbuf);
894 mutex_unlock(&usblp->mut);
890 } 895 }
891 } else {
892 schedule();
893 } 896 }
894 } 897 }
895 set_current_state(TASK_RUNNING); 898 set_current_state(TASK_RUNNING);
diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
index 6ec38175a817..73c108d117b4 100644
--- a/drivers/usb/core/devices.c
+++ b/drivers/usb/core/devices.c
@@ -187,7 +187,7 @@ static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end,
187 } 187 }
188 188
189 /* this isn't checking for illegal values */ 189 /* this isn't checking for illegal values */
190 switch (desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 190 switch (usb_endpoint_type(desc)) {
191 case USB_ENDPOINT_XFER_CONTROL: 191 case USB_ENDPOINT_XFER_CONTROL:
192 type = "Ctrl"; 192 type = "Ctrl";
193 if (speed == USB_SPEED_HIGH) /* uframes per NAK */ 193 if (speed == USB_SPEED_HIGH) /* uframes per NAK */
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 6585f527e381..df3c539f652a 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -104,7 +104,7 @@ MODULE_PARM_DESC(usbfs_snoop, "true to log all usbfs traffic");
104 104
105#define MAX_USBFS_BUFFER_SIZE 16384 105#define MAX_USBFS_BUFFER_SIZE 16384
106 106
107static inline int connected(struct dev_state *ps) 107static int connected(struct dev_state *ps)
108{ 108{
109 return (!list_empty(&ps->list) && 109 return (!list_empty(&ps->list) &&
110 ps->dev->state != USB_STATE_NOTATTACHED); 110 ps->dev->state != USB_STATE_NOTATTACHED);
@@ -248,7 +248,7 @@ static void free_async(struct async *as)
248 kfree(as); 248 kfree(as);
249} 249}
250 250
251static inline void async_newpending(struct async *as) 251static void async_newpending(struct async *as)
252{ 252{
253 struct dev_state *ps = as->ps; 253 struct dev_state *ps = as->ps;
254 unsigned long flags; 254 unsigned long flags;
@@ -258,7 +258,7 @@ static inline void async_newpending(struct async *as)
258 spin_unlock_irqrestore(&ps->lock, flags); 258 spin_unlock_irqrestore(&ps->lock, flags);
259} 259}
260 260
261static inline void async_removepending(struct async *as) 261static void async_removepending(struct async *as)
262{ 262{
263 struct dev_state *ps = as->ps; 263 struct dev_state *ps = as->ps;
264 unsigned long flags; 264 unsigned long flags;
@@ -268,7 +268,7 @@ static inline void async_removepending(struct async *as)
268 spin_unlock_irqrestore(&ps->lock, flags); 268 spin_unlock_irqrestore(&ps->lock, flags);
269} 269}
270 270
271static inline struct async *async_getcompleted(struct dev_state *ps) 271static struct async *async_getcompleted(struct dev_state *ps)
272{ 272{
273 unsigned long flags; 273 unsigned long flags;
274 struct async *as = NULL; 274 struct async *as = NULL;
@@ -283,7 +283,7 @@ static inline struct async *async_getcompleted(struct dev_state *ps)
283 return as; 283 return as;
284} 284}
285 285
286static inline struct async *async_getpending(struct dev_state *ps, 286static struct async *async_getpending(struct dev_state *ps,
287 void __user *userurb) 287 void __user *userurb)
288{ 288{
289 unsigned long flags; 289 unsigned long flags;
@@ -302,7 +302,7 @@ static inline struct async *async_getpending(struct dev_state *ps,
302 302
303static void snoop_urb(struct urb *urb, void __user *userurb) 303static void snoop_urb(struct urb *urb, void __user *userurb)
304{ 304{
305 int j; 305 unsigned j;
306 unsigned char *data = urb->transfer_buffer; 306 unsigned char *data = urb->transfer_buffer;
307 307
308 if (!usbfs_snoop) 308 if (!usbfs_snoop)
@@ -311,9 +311,9 @@ static void snoop_urb(struct urb *urb, void __user *userurb)
311 dev_info(&urb->dev->dev, "direction=%s\n", 311 dev_info(&urb->dev->dev, "direction=%s\n",
312 usb_urb_dir_in(urb) ? "IN" : "OUT"); 312 usb_urb_dir_in(urb) ? "IN" : "OUT");
313 dev_info(&urb->dev->dev, "userurb=%p\n", userurb); 313 dev_info(&urb->dev->dev, "userurb=%p\n", userurb);
314 dev_info(&urb->dev->dev, "transfer_buffer_length=%d\n", 314 dev_info(&urb->dev->dev, "transfer_buffer_length=%u\n",
315 urb->transfer_buffer_length); 315 urb->transfer_buffer_length);
316 dev_info(&urb->dev->dev, "actual_length=%d\n", urb->actual_length); 316 dev_info(&urb->dev->dev, "actual_length=%u\n", urb->actual_length);
317 dev_info(&urb->dev->dev, "data: "); 317 dev_info(&urb->dev->dev, "data: ");
318 for (j = 0; j < urb->transfer_buffer_length; ++j) 318 for (j = 0; j < urb->transfer_buffer_length; ++j)
319 printk("%02x ", data[j]); 319 printk("%02x ", data[j]);
@@ -376,7 +376,7 @@ static void destroy_async_on_interface(struct dev_state *ps,
376 destroy_async(ps, &hitlist); 376 destroy_async(ps, &hitlist);
377} 377}
378 378
379static inline void destroy_all_async(struct dev_state *ps) 379static void destroy_all_async(struct dev_state *ps)
380{ 380{
381 destroy_async(ps, &ps->async_pending); 381 destroy_async(ps, &ps->async_pending);
382} 382}
@@ -525,7 +525,8 @@ static int check_ctrlrecip(struct dev_state *ps, unsigned int requesttype,
525{ 525{
526 int ret = 0; 526 int ret = 0;
527 527
528 if (ps->dev->state != USB_STATE_ADDRESS 528 if (ps->dev->state != USB_STATE_UNAUTHENTICATED
529 && ps->dev->state != USB_STATE_ADDRESS
529 && ps->dev->state != USB_STATE_CONFIGURED) 530 && ps->dev->state != USB_STATE_CONFIGURED)
530 return -EHOSTUNREACH; 531 return -EHOSTUNREACH;
531 if (USB_TYPE_VENDOR == (USB_TYPE_MASK & requesttype)) 532 if (USB_TYPE_VENDOR == (USB_TYPE_MASK & requesttype))
diff --git a/drivers/usb/core/endpoint.c b/drivers/usb/core/endpoint.c
index e1710f260b4f..40dee2ac0133 100644
--- a/drivers/usb/core/endpoint.c
+++ b/drivers/usb/core/endpoint.c
@@ -66,7 +66,7 @@ static ssize_t show_ep_type(struct device *dev, struct device_attribute *attr,
66 struct ep_device *ep = to_ep_device(dev); 66 struct ep_device *ep = to_ep_device(dev);
67 char *type = "unknown"; 67 char *type = "unknown";
68 68
69 switch (ep->desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 69 switch (usb_endpoint_type(ep->desc)) {
70 case USB_ENDPOINT_XFER_CONTROL: 70 case USB_ENDPOINT_XFER_CONTROL:
71 type = "Control"; 71 type = "Control";
72 break; 72 break;
@@ -94,7 +94,7 @@ static ssize_t show_ep_interval(struct device *dev,
94 94
95 in = (ep->desc->bEndpointAddress & USB_DIR_IN); 95 in = (ep->desc->bEndpointAddress & USB_DIR_IN);
96 96
97 switch (ep->desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 97 switch (usb_endpoint_type(ep->desc)) {
98 case USB_ENDPOINT_XFER_CONTROL: 98 case USB_ENDPOINT_XFER_CONTROL:
99 if (ep->udev->speed == USB_SPEED_HIGH) /* uframes per NAK */ 99 if (ep->udev->speed == USB_SPEED_HIGH) /* uframes per NAK */
100 interval = ep->desc->bInterval; 100 interval = ep->desc->bInterval;
@@ -131,10 +131,9 @@ static ssize_t show_ep_direction(struct device *dev,
131 struct ep_device *ep = to_ep_device(dev); 131 struct ep_device *ep = to_ep_device(dev);
132 char *direction; 132 char *direction;
133 133
134 if ((ep->desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == 134 if (usb_endpoint_xfer_control(ep->desc))
135 USB_ENDPOINT_XFER_CONTROL)
136 direction = "both"; 135 direction = "both";
137 else if (ep->desc->bEndpointAddress & USB_DIR_IN) 136 else if (usb_endpoint_dir_in(ep->desc))
138 direction = "in"; 137 direction = "in";
139 else 138 else
140 direction = "out"; 139 direction = "out";
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 3c711db55d86..81fa8506825d 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -279,9 +279,9 @@ static const u8 hs_rh_config_descriptor [] = {
279 * helper routine for returning string descriptors in UTF-16LE 279 * helper routine for returning string descriptors in UTF-16LE
280 * input can actually be ISO-8859-1; ASCII is its 7-bit subset 280 * input can actually be ISO-8859-1; ASCII is its 7-bit subset
281 */ 281 */
282static int ascii2utf (char *s, u8 *utf, int utfmax) 282static unsigned ascii2utf(char *s, u8 *utf, int utfmax)
283{ 283{
284 int retval; 284 unsigned retval;
285 285
286 for (retval = 0; *s && utfmax > 1; utfmax -= 2, retval += 2) { 286 for (retval = 0; *s && utfmax > 1; utfmax -= 2, retval += 2) {
287 *utf++ = *s++; 287 *utf++ = *s++;
@@ -304,19 +304,15 @@ static int ascii2utf (char *s, u8 *utf, int utfmax)
304 * Produces either a manufacturer, product or serial number string for the 304 * Produces either a manufacturer, product or serial number string for the
305 * virtual root hub device. 305 * virtual root hub device.
306 */ 306 */
307static int rh_string ( 307static unsigned rh_string(int id, struct usb_hcd *hcd, u8 *data, unsigned len)
308 int id, 308{
309 struct usb_hcd *hcd,
310 u8 *data,
311 int len
312) {
313 char buf [100]; 309 char buf [100];
314 310
315 // language ids 311 // language ids
316 if (id == 0) { 312 if (id == 0) {
317 buf[0] = 4; buf[1] = 3; /* 4 bytes string data */ 313 buf[0] = 4; buf[1] = 3; /* 4 bytes string data */
318 buf[2] = 0x09; buf[3] = 0x04; /* MSFT-speak for "en-us" */ 314 buf[2] = 0x09; buf[3] = 0x04; /* MSFT-speak for "en-us" */
319 len = min (len, 4); 315 len = min_t(unsigned, len, 4);
320 memcpy (data, buf, len); 316 memcpy (data, buf, len);
321 return len; 317 return len;
322 318
@@ -332,10 +328,7 @@ static int rh_string (
332 } else if (id == 3) { 328 } else if (id == 3) {
333 snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname, 329 snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname,
334 init_utsname()->release, hcd->driver->description); 330 init_utsname()->release, hcd->driver->description);
335 331 }
336 // unsupported IDs --> "protocol stall"
337 } else
338 return -EPIPE;
339 332
340 switch (len) { /* All cases fall through */ 333 switch (len) { /* All cases fall through */
341 default: 334 default:
@@ -360,9 +353,8 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
360 u8 tbuf [sizeof (struct usb_hub_descriptor)] 353 u8 tbuf [sizeof (struct usb_hub_descriptor)]
361 __attribute__((aligned(4))); 354 __attribute__((aligned(4)));
362 const u8 *bufp = tbuf; 355 const u8 *bufp = tbuf;
363 int len = 0; 356 unsigned len = 0;
364 int status; 357 int status;
365 int n;
366 u8 patch_wakeup = 0; 358 u8 patch_wakeup = 0;
367 u8 patch_protocol = 0; 359 u8 patch_protocol = 0;
368 360
@@ -456,10 +448,11 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
456 patch_wakeup = 1; 448 patch_wakeup = 1;
457 break; 449 break;
458 case USB_DT_STRING << 8: 450 case USB_DT_STRING << 8:
459 n = rh_string (wValue & 0xff, hcd, ubuf, wLength); 451 if ((wValue & 0xff) < 4)
460 if (n < 0) 452 urb->actual_length = rh_string(wValue & 0xff,
453 hcd, ubuf, wLength);
454 else /* unsupported IDs --> "protocol stall" */
461 goto error; 455 goto error;
462 urb->actual_length = n;
463 break; 456 break;
464 default: 457 default:
465 goto error; 458 goto error;
@@ -629,7 +622,7 @@ static int rh_queue_status (struct usb_hcd *hcd, struct urb *urb)
629{ 622{
630 int retval; 623 int retval;
631 unsigned long flags; 624 unsigned long flags;
632 int len = 1 + (urb->dev->maxchild / 8); 625 unsigned len = 1 + (urb->dev->maxchild / 8);
633 626
634 spin_lock_irqsave (&hcd_root_hub_lock, flags); 627 spin_lock_irqsave (&hcd_root_hub_lock, flags);
635 if (hcd->status_urb || urb->transfer_buffer_length < len) { 628 if (hcd->status_urb || urb->transfer_buffer_length < len) {
@@ -901,7 +894,7 @@ static int register_root_hub(struct usb_hcd *hcd)
901 894
902 mutex_lock(&usb_bus_list_lock); 895 mutex_lock(&usb_bus_list_lock);
903 896
904 usb_dev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64); 897 usb_dev->ep0.desc.wMaxPacketSize = cpu_to_le16(64);
905 retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE); 898 retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE);
906 if (retval != sizeof usb_dev->descriptor) { 899 if (retval != sizeof usb_dev->descriptor) {
907 mutex_unlock(&usb_bus_list_lock); 900 mutex_unlock(&usb_bus_list_lock);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index cd50d86029e7..be86ae3f4088 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -392,7 +392,7 @@ static void hub_irq(struct urb *urb)
392{ 392{
393 struct usb_hub *hub = urb->context; 393 struct usb_hub *hub = urb->context;
394 int status = urb->status; 394 int status = urb->status;
395 int i; 395 unsigned i;
396 unsigned long bits; 396 unsigned long bits;
397 397
398 switch (status) { 398 switch (status) {
@@ -1305,6 +1305,7 @@ void usb_set_device_state(struct usb_device *udev,
1305 recursively_mark_NOTATTACHED(udev); 1305 recursively_mark_NOTATTACHED(udev);
1306 spin_unlock_irqrestore(&device_state_lock, flags); 1306 spin_unlock_irqrestore(&device_state_lock, flags);
1307} 1307}
1308EXPORT_SYMBOL_GPL(usb_set_device_state);
1308 1309
1309/* 1310/*
1310 * WUSB devices are simple: they have no hubs behind, so the mapping 1311 * WUSB devices are simple: they have no hubs behind, so the mapping
@@ -2471,20 +2472,20 @@ hub_port_init (struct usb_hub *hub, struct usb_device *udev, int port1,
2471 */ 2472 */
2472 switch (udev->speed) { 2473 switch (udev->speed) {
2473 case USB_SPEED_VARIABLE: /* fixed at 512 */ 2474 case USB_SPEED_VARIABLE: /* fixed at 512 */
2474 udev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(512); 2475 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512);
2475 break; 2476 break;
2476 case USB_SPEED_HIGH: /* fixed at 64 */ 2477 case USB_SPEED_HIGH: /* fixed at 64 */
2477 udev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64); 2478 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64);
2478 break; 2479 break;
2479 case USB_SPEED_FULL: /* 8, 16, 32, or 64 */ 2480 case USB_SPEED_FULL: /* 8, 16, 32, or 64 */
2480 /* to determine the ep0 maxpacket size, try to read 2481 /* to determine the ep0 maxpacket size, try to read
2481 * the device descriptor to get bMaxPacketSize0 and 2482 * the device descriptor to get bMaxPacketSize0 and
2482 * then correct our initial guess. 2483 * then correct our initial guess.
2483 */ 2484 */
2484 udev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(64); 2485 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(64);
2485 break; 2486 break;
2486 case USB_SPEED_LOW: /* fixed at 8 */ 2487 case USB_SPEED_LOW: /* fixed at 8 */
2487 udev->ep0.desc.wMaxPacketSize = __constant_cpu_to_le16(8); 2488 udev->ep0.desc.wMaxPacketSize = cpu_to_le16(8);
2488 break; 2489 break;
2489 default: 2490 default:
2490 goto fail; 2491 goto fail;
@@ -3392,10 +3393,10 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3392 udev->descriptor = descriptor; /* for disconnect() calls */ 3393 udev->descriptor = descriptor; /* for disconnect() calls */
3393 goto re_enumerate; 3394 goto re_enumerate;
3394 } 3395 }
3395 3396
3397 /* Restore the device's previous configuration */
3396 if (!udev->actconfig) 3398 if (!udev->actconfig)
3397 goto done; 3399 goto done;
3398
3399 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 3400 ret = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
3400 USB_REQ_SET_CONFIGURATION, 0, 3401 USB_REQ_SET_CONFIGURATION, 0,
3401 udev->actconfig->desc.bConfigurationValue, 0, 3402 udev->actconfig->desc.bConfigurationValue, 0,
@@ -3408,16 +3409,25 @@ static int usb_reset_and_verify_device(struct usb_device *udev)
3408 } 3409 }
3409 usb_set_device_state(udev, USB_STATE_CONFIGURED); 3410 usb_set_device_state(udev, USB_STATE_CONFIGURED);
3410 3411
3412 /* Put interfaces back into the same altsettings as before.
3413 * Don't bother to send the Set-Interface request for interfaces
3414 * that were already in altsetting 0; besides being unnecessary,
3415 * many devices can't handle it. Instead just reset the host-side
3416 * endpoint state.
3417 */
3411 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) { 3418 for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
3412 struct usb_interface *intf = udev->actconfig->interface[i]; 3419 struct usb_interface *intf = udev->actconfig->interface[i];
3413 struct usb_interface_descriptor *desc; 3420 struct usb_interface_descriptor *desc;
3414 3421
3415 /* set_interface resets host side toggle even
3416 * for altsetting zero. the interface may have no driver.
3417 */
3418 desc = &intf->cur_altsetting->desc; 3422 desc = &intf->cur_altsetting->desc;
3419 ret = usb_set_interface(udev, desc->bInterfaceNumber, 3423 if (desc->bAlternateSetting == 0) {
3420 desc->bAlternateSetting); 3424 usb_disable_interface(udev, intf, true);
3425 usb_enable_interface(udev, intf, true);
3426 ret = 0;
3427 } else {
3428 ret = usb_set_interface(udev, desc->bInterfaceNumber,
3429 desc->bAlternateSetting);
3430 }
3421 if (ret < 0) { 3431 if (ret < 0) {
3422 dev_err(&udev->dev, "failed to restore interface %d " 3432 dev_err(&udev->dev, "failed to restore interface %d "
3423 "altsetting %d (error=%d)\n", 3433 "altsetting %d (error=%d)\n",
diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index 49e7f56e0d7f..30a0690f3683 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -59,7 +59,7 @@ static int usb_start_wait_urb(struct urb *urb, int timeout, int *actual_length)
59 retval = (ctx.status == -ENOENT ? -ETIMEDOUT : ctx.status); 59 retval = (ctx.status == -ENOENT ? -ETIMEDOUT : ctx.status);
60 60
61 dev_dbg(&urb->dev->dev, 61 dev_dbg(&urb->dev->dev,
62 "%s timed out on ep%d%s len=%d/%d\n", 62 "%s timed out on ep%d%s len=%u/%u\n",
63 current->comm, 63 current->comm,
64 usb_endpoint_num(&urb->ep->desc), 64 usb_endpoint_num(&urb->ep->desc),
65 usb_urb_dir_in(urb) ? "in" : "out", 65 usb_urb_dir_in(urb) ? "in" : "out",
@@ -804,18 +804,16 @@ int usb_string(struct usb_device *dev, int index, char *buf, size_t size)
804 dev_err(&dev->dev, 804 dev_err(&dev->dev,
805 "string descriptor 0 read error: %d\n", 805 "string descriptor 0 read error: %d\n",
806 err); 806 err);
807 goto errout;
808 } else if (err < 4) { 807 } else if (err < 4) {
809 dev_err(&dev->dev, "string descriptor 0 too short\n"); 808 dev_err(&dev->dev, "string descriptor 0 too short\n");
810 err = -EINVAL;
811 goto errout;
812 } else { 809 } else {
813 dev->have_langid = 1;
814 dev->string_langid = tbuf[2] | (tbuf[3] << 8); 810 dev->string_langid = tbuf[2] | (tbuf[3] << 8);
815 /* always use the first langid listed */ 811 /* always use the first langid listed */
816 dev_dbg(&dev->dev, "default language 0x%04x\n", 812 dev_dbg(&dev->dev, "default language 0x%04x\n",
817 dev->string_langid); 813 dev->string_langid);
818 } 814 }
815
816 dev->have_langid = 1;
819 } 817 }
820 818
821 err = usb_string_sub(dev, dev->string_langid, index, tbuf); 819 err = usb_string_sub(dev, dev->string_langid, index, tbuf);
@@ -1719,7 +1717,8 @@ free_interfaces:
1719 } 1717 }
1720 kfree(new_interfaces); 1718 kfree(new_interfaces);
1721 1719
1722 if (cp->string == NULL) 1720 if (cp->string == NULL &&
1721 !(dev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
1723 cp->string = usb_cache_string(dev, cp->desc.iConfiguration); 1722 cp->string = usb_cache_string(dev, cp->desc.iConfiguration);
1724 1723
1725 /* Now that all the interfaces are set up, register them 1724 /* Now that all the interfaces are set up, register them
diff --git a/drivers/usb/core/quirks.c b/drivers/usb/core/quirks.c
index c070b34b669d..ab93918d9207 100644
--- a/drivers/usb/core/quirks.c
+++ b/drivers/usb/core/quirks.c
@@ -54,6 +54,10 @@ static const struct usb_device_id usb_quirk_list[] = {
54 { USB_DEVICE(0x0638, 0x0a13), .driver_info = 54 { USB_DEVICE(0x0638, 0x0a13), .driver_info =
55 USB_QUIRK_STRING_FETCH_255 }, 55 USB_QUIRK_STRING_FETCH_255 },
56 56
57 /* Saitek Cyborg Gold Joystick */
58 { USB_DEVICE(0x06a3, 0x0006), .driver_info =
59 USB_QUIRK_CONFIG_INTF_STRINGS },
60
57 /* M-Systems Flash Disk Pioneers */ 61 /* M-Systems Flash Disk Pioneers */
58 { USB_DEVICE(0x08ec, 0x1000), .driver_info = USB_QUIRK_RESET_RESUME }, 62 { USB_DEVICE(0x08ec, 0x1000), .driver_info = USB_QUIRK_RESET_RESUME },
59 63
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 4cc2456ef3be..c66789197927 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -13,6 +13,7 @@
13#include <linux/kernel.h> 13#include <linux/kernel.h>
14#include <linux/string.h> 14#include <linux/string.h>
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include <linux/usb/quirks.h>
16#include "usb.h" 17#include "usb.h"
17 18
18/* Active configuration fields */ 19/* Active configuration fields */
@@ -813,7 +814,8 @@ int usb_create_sysfs_intf_files(struct usb_interface *intf)
813 if (intf->sysfs_files_created || intf->unregistering) 814 if (intf->sysfs_files_created || intf->unregistering)
814 return 0; 815 return 0;
815 816
816 if (alt->string == NULL) 817 if (alt->string == NULL &&
818 !(udev->quirks & USB_QUIRK_CONFIG_INTF_STRINGS))
817 alt->string = usb_cache_string(udev, alt->desc.iInterface); 819 alt->string = usb_cache_string(udev, alt->desc.iInterface);
818 if (alt->string) 820 if (alt->string)
819 retval = device_create_file(&intf->dev, &dev_attr_interface); 821 retval = device_create_file(&intf->dev, &dev_attr_interface);
diff --git a/drivers/usb/core/urb.c b/drivers/usb/core/urb.c
index 58bc5e3c2560..3376055f36e7 100644
--- a/drivers/usb/core/urb.c
+++ b/drivers/usb/core/urb.c
@@ -295,7 +295,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
295 if (!urb || urb->hcpriv || !urb->complete) 295 if (!urb || urb->hcpriv || !urb->complete)
296 return -EINVAL; 296 return -EINVAL;
297 dev = urb->dev; 297 dev = urb->dev;
298 if ((!dev) || (dev->state < USB_STATE_DEFAULT)) 298 if ((!dev) || (dev->state < USB_STATE_UNAUTHENTICATED))
299 return -ENODEV; 299 return -ENODEV;
300 300
301 /* For now, get the endpoint from the pipe. Eventually drivers 301 /* For now, get the endpoint from the pipe. Eventually drivers
@@ -370,7 +370,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
370 } 370 }
371 371
372 /* the I/O buffer must be mapped/unmapped, except when length=0 */ 372 /* the I/O buffer must be mapped/unmapped, except when length=0 */
373 if (urb->transfer_buffer_length < 0) 373 if (urb->transfer_buffer_length > INT_MAX)
374 return -EMSGSIZE; 374 return -EMSGSIZE;
375 375
376#ifdef DEBUG 376#ifdef DEBUG
diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
index e55fef52a5dc..770b3eaa9184 100644
--- a/drivers/usb/gadget/Kconfig
+++ b/drivers/usb/gadget/Kconfig
@@ -254,6 +254,7 @@ config USB_PXA25X_SMALL
254config USB_GADGET_PXA27X 254config USB_GADGET_PXA27X
255 boolean "PXA 27x" 255 boolean "PXA 27x"
256 depends on ARCH_PXA && PXA27x 256 depends on ARCH_PXA && PXA27x
257 select USB_OTG_UTILS
257 help 258 help
258 Intel's PXA 27x series XScale ARM v5TE processors include 259 Intel's PXA 27x series XScale ARM v5TE processors include
259 an integrated full speed USB 1.1 device controller. 260 an integrated full speed USB 1.1 device controller.
diff --git a/drivers/usb/gadget/amd5536udc.c b/drivers/usb/gadget/amd5536udc.c
index abf8192f89e8..826f3adde5d8 100644
--- a/drivers/usb/gadget/amd5536udc.c
+++ b/drivers/usb/gadget/amd5536udc.c
@@ -551,7 +551,7 @@ udc_alloc_request(struct usb_ep *usbep, gfp_t gfp)
551 dma_desc->status = AMD_ADDBITS(dma_desc->status, 551 dma_desc->status = AMD_ADDBITS(dma_desc->status,
552 UDC_DMA_STP_STS_BS_HOST_BUSY, 552 UDC_DMA_STP_STS_BS_HOST_BUSY,
553 UDC_DMA_STP_STS_BS); 553 UDC_DMA_STP_STS_BS);
554 dma_desc->bufptr = __constant_cpu_to_le32(DMA_DONT_USE); 554 dma_desc->bufptr = cpu_to_le32(DMA_DONT_USE);
555 req->td_data = dma_desc; 555 req->td_data = dma_desc;
556 req->td_data_last = NULL; 556 req->td_data_last = NULL;
557 req->chain_len = 1; 557 req->chain_len = 1;
diff --git a/drivers/usb/gadget/atmel_usba_udc.c b/drivers/usb/gadget/atmel_usba_udc.c
index 65b03e3445a1..c22fab164113 100644
--- a/drivers/usb/gadget/atmel_usba_udc.c
+++ b/drivers/usb/gadget/atmel_usba_udc.c
@@ -1017,7 +1017,7 @@ static struct usb_endpoint_descriptor usba_ep0_desc = {
1017 .bDescriptorType = USB_DT_ENDPOINT, 1017 .bDescriptorType = USB_DT_ENDPOINT,
1018 .bEndpointAddress = 0, 1018 .bEndpointAddress = 0,
1019 .bmAttributes = USB_ENDPOINT_XFER_CONTROL, 1019 .bmAttributes = USB_ENDPOINT_XFER_CONTROL,
1020 .wMaxPacketSize = __constant_cpu_to_le16(64), 1020 .wMaxPacketSize = cpu_to_le16(64),
1021 /* FIXME: I have no idea what to put here */ 1021 /* FIXME: I have no idea what to put here */
1022 .bInterval = 1, 1022 .bInterval = 1,
1023}; 1023};
@@ -1207,21 +1207,21 @@ static int do_test_mode(struct usba_udc *udc)
1207/* Avoid overly long expressions */ 1207/* Avoid overly long expressions */
1208static inline bool feature_is_dev_remote_wakeup(struct usb_ctrlrequest *crq) 1208static inline bool feature_is_dev_remote_wakeup(struct usb_ctrlrequest *crq)
1209{ 1209{
1210 if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_REMOTE_WAKEUP)) 1210 if (crq->wValue == cpu_to_le16(USB_DEVICE_REMOTE_WAKEUP))
1211 return true; 1211 return true;
1212 return false; 1212 return false;
1213} 1213}
1214 1214
1215static inline bool feature_is_dev_test_mode(struct usb_ctrlrequest *crq) 1215static inline bool feature_is_dev_test_mode(struct usb_ctrlrequest *crq)
1216{ 1216{
1217 if (crq->wValue == __constant_cpu_to_le16(USB_DEVICE_TEST_MODE)) 1217 if (crq->wValue == cpu_to_le16(USB_DEVICE_TEST_MODE))
1218 return true; 1218 return true;
1219 return false; 1219 return false;
1220} 1220}
1221 1221
1222static inline bool feature_is_ep_halt(struct usb_ctrlrequest *crq) 1222static inline bool feature_is_ep_halt(struct usb_ctrlrequest *crq)
1223{ 1223{
1224 if (crq->wValue == __constant_cpu_to_le16(USB_ENDPOINT_HALT)) 1224 if (crq->wValue == cpu_to_le16(USB_ENDPOINT_HALT))
1225 return true; 1225 return true;
1226 return false; 1226 return false;
1227} 1227}
@@ -1239,7 +1239,7 @@ static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
1239 status = cpu_to_le16(udc->devstatus); 1239 status = cpu_to_le16(udc->devstatus);
1240 } else if (crq->bRequestType 1240 } else if (crq->bRequestType
1241 == (USB_DIR_IN | USB_RECIP_INTERFACE)) { 1241 == (USB_DIR_IN | USB_RECIP_INTERFACE)) {
1242 status = __constant_cpu_to_le16(0); 1242 status = cpu_to_le16(0);
1243 } else if (crq->bRequestType 1243 } else if (crq->bRequestType
1244 == (USB_DIR_IN | USB_RECIP_ENDPOINT)) { 1244 == (USB_DIR_IN | USB_RECIP_ENDPOINT)) {
1245 struct usba_ep *target; 1245 struct usba_ep *target;
@@ -1250,12 +1250,12 @@ static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
1250 1250
1251 status = 0; 1251 status = 0;
1252 if (is_stalled(udc, target)) 1252 if (is_stalled(udc, target))
1253 status |= __constant_cpu_to_le16(1); 1253 status |= cpu_to_le16(1);
1254 } else 1254 } else
1255 goto delegate; 1255 goto delegate;
1256 1256
1257 /* Write directly to the FIFO. No queueing is done. */ 1257 /* Write directly to the FIFO. No queueing is done. */
1258 if (crq->wLength != __constant_cpu_to_le16(sizeof(status))) 1258 if (crq->wLength != cpu_to_le16(sizeof(status)))
1259 goto stall; 1259 goto stall;
1260 ep->state = DATA_STAGE_IN; 1260 ep->state = DATA_STAGE_IN;
1261 __raw_writew(status, ep->fifo); 1261 __raw_writew(status, ep->fifo);
@@ -1274,7 +1274,7 @@ static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
1274 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) { 1274 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
1275 struct usba_ep *target; 1275 struct usba_ep *target;
1276 1276
1277 if (crq->wLength != __constant_cpu_to_le16(0) 1277 if (crq->wLength != cpu_to_le16(0)
1278 || !feature_is_ep_halt(crq)) 1278 || !feature_is_ep_halt(crq))
1279 goto stall; 1279 goto stall;
1280 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex)); 1280 target = get_ep_by_addr(udc, le16_to_cpu(crq->wIndex));
@@ -1308,7 +1308,7 @@ static int handle_ep0_setup(struct usba_udc *udc, struct usba_ep *ep,
1308 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) { 1308 } else if (crq->bRequestType == USB_RECIP_ENDPOINT) {
1309 struct usba_ep *target; 1309 struct usba_ep *target;
1310 1310
1311 if (crq->wLength != __constant_cpu_to_le16(0) 1311 if (crq->wLength != cpu_to_le16(0)
1312 || !feature_is_ep_halt(crq)) 1312 || !feature_is_ep_halt(crq))
1313 goto stall; 1313 goto stall;
1314 1314
@@ -1514,7 +1514,7 @@ restart:
1514 */ 1514 */
1515 ep->state = DATA_STAGE_IN; 1515 ep->state = DATA_STAGE_IN;
1516 } else { 1516 } else {
1517 if (crq.crq.wLength != __constant_cpu_to_le16(0)) 1517 if (crq.crq.wLength != cpu_to_le16(0))
1518 ep->state = DATA_STAGE_OUT; 1518 ep->state = DATA_STAGE_OUT;
1519 else 1519 else
1520 ep->state = STATUS_STAGE_IN; 1520 ep->state = STATUS_STAGE_IN;
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index 5495b171cf29..928137d3dbdc 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -66,7 +66,7 @@ static struct usb_device_descriptor device_desc = {
66 .bLength = sizeof device_desc, 66 .bLength = sizeof device_desc,
67 .bDescriptorType = USB_DT_DEVICE, 67 .bDescriptorType = USB_DT_DEVICE,
68 68
69 .bcdUSB = __constant_cpu_to_le16(0x0200), 69 .bcdUSB = cpu_to_le16(0x0200),
70 70
71 .bDeviceClass = USB_CLASS_COMM, 71 .bDeviceClass = USB_CLASS_COMM,
72 .bDeviceSubClass = 0, 72 .bDeviceSubClass = 0,
@@ -74,8 +74,8 @@ static struct usb_device_descriptor device_desc = {
74 /* .bMaxPacketSize0 = f(hardware) */ 74 /* .bMaxPacketSize0 = f(hardware) */
75 75
76 /* Vendor and product id can be overridden by module parameters. */ 76 /* Vendor and product id can be overridden by module parameters. */
77 .idVendor = __constant_cpu_to_le16(CDC_VENDOR_NUM), 77 .idVendor = cpu_to_le16(CDC_VENDOR_NUM),
78 .idProduct = __constant_cpu_to_le16(CDC_PRODUCT_NUM), 78 .idProduct = cpu_to_le16(CDC_PRODUCT_NUM),
79 /* .bcdDevice = f(hardware) */ 79 /* .bcdDevice = f(hardware) */
80 /* .iManufacturer = DYNAMIC */ 80 /* .iManufacturer = DYNAMIC */
81 /* .iProduct = DYNAMIC */ 81 /* .iProduct = DYNAMIC */
@@ -193,7 +193,7 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
193 gadget->name, 193 gadget->name,
194 cdc_config_driver.label); 194 cdc_config_driver.label);
195 device_desc.bcdDevice = 195 device_desc.bcdDevice =
196 __constant_cpu_to_le16(0x0300 | 0x0099); 196 cpu_to_le16(0x0300 | 0x0099);
197 } 197 }
198 198
199 199
diff --git a/drivers/usb/gadget/ci13xxx_udc.c b/drivers/usb/gadget/ci13xxx_udc.c
index bebf911c7e5f..22c65960c429 100644
--- a/drivers/usb/gadget/ci13xxx_udc.c
+++ b/drivers/usb/gadget/ci13xxx_udc.c
@@ -56,7 +56,6 @@
56#include <linux/dma-mapping.h> 56#include <linux/dma-mapping.h>
57#include <linux/init.h> 57#include <linux/init.h>
58#include <linux/interrupt.h> 58#include <linux/interrupt.h>
59#include <linux/interrupt.h>
60#include <linux/io.h> 59#include <linux/io.h>
61#include <linux/irq.h> 60#include <linux/irq.h>
62#include <linux/kernel.h> 61#include <linux/kernel.h>
@@ -2626,7 +2625,7 @@ static int udc_probe(struct device *dev, void __iomem *regs, const char *name)
2626 INIT_LIST_HEAD(&udc->gadget.ep_list); 2625 INIT_LIST_HEAD(&udc->gadget.ep_list);
2627 udc->gadget.ep0 = NULL; 2626 udc->gadget.ep0 = NULL;
2628 2627
2629 strcpy(udc->gadget.dev.bus_id, "gadget"); 2628 dev_set_name(&udc->gadget.dev, "gadget");
2630 udc->gadget.dev.dma_mask = dev->dma_mask; 2629 udc->gadget.dev.dma_mask = dev->dma_mask;
2631 udc->gadget.dev.parent = dev; 2630 udc->gadget.dev.parent = dev;
2632 udc->gadget.dev.release = udc_release; 2631 udc->gadget.dev.release = udc_release;
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 5d11c291f1ad..59e85234fa0a 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -149,16 +149,17 @@ done:
149int usb_function_deactivate(struct usb_function *function) 149int usb_function_deactivate(struct usb_function *function)
150{ 150{
151 struct usb_composite_dev *cdev = function->config->cdev; 151 struct usb_composite_dev *cdev = function->config->cdev;
152 unsigned long flags;
152 int status = 0; 153 int status = 0;
153 154
154 spin_lock(&cdev->lock); 155 spin_lock_irqsave(&cdev->lock, flags);
155 156
156 if (cdev->deactivations == 0) 157 if (cdev->deactivations == 0)
157 status = usb_gadget_disconnect(cdev->gadget); 158 status = usb_gadget_disconnect(cdev->gadget);
158 if (status == 0) 159 if (status == 0)
159 cdev->deactivations++; 160 cdev->deactivations++;
160 161
161 spin_unlock(&cdev->lock); 162 spin_unlock_irqrestore(&cdev->lock, flags);
162 return status; 163 return status;
163} 164}
164 165
@@ -1013,7 +1014,7 @@ composite_suspend(struct usb_gadget *gadget)
1013 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1014 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1014 struct usb_function *f; 1015 struct usb_function *f;
1015 1016
1016 /* REVISIT: should we have config and device level 1017 /* REVISIT: should we have config level
1017 * suspend/resume callbacks? 1018 * suspend/resume callbacks?
1018 */ 1019 */
1019 DBG(cdev, "suspend\n"); 1020 DBG(cdev, "suspend\n");
@@ -1023,6 +1024,8 @@ composite_suspend(struct usb_gadget *gadget)
1023 f->suspend(f); 1024 f->suspend(f);
1024 } 1025 }
1025 } 1026 }
1027 if (composite->suspend)
1028 composite->suspend(cdev);
1026} 1029}
1027 1030
1028static void 1031static void
@@ -1031,10 +1034,12 @@ composite_resume(struct usb_gadget *gadget)
1031 struct usb_composite_dev *cdev = get_gadget_data(gadget); 1034 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1032 struct usb_function *f; 1035 struct usb_function *f;
1033 1036
1034 /* REVISIT: should we have config and device level 1037 /* REVISIT: should we have config level
1035 * suspend/resume callbacks? 1038 * suspend/resume callbacks?
1036 */ 1039 */
1037 DBG(cdev, "resume\n"); 1040 DBG(cdev, "resume\n");
1041 if (composite->resume)
1042 composite->resume(cdev);
1038 if (cdev->config) { 1043 if (cdev->config) {
1039 list_for_each_entry(f, &cdev->config->functions, list) { 1044 list_for_each_entry(f, &cdev->config->functions, list) {
1040 if (f->resume) 1045 if (f->resume)
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 9064696636ac..a56b24d305f8 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -1437,7 +1437,7 @@ restart:
1437 } 1437 }
1438 if (urb->transfer_buffer_length > 1) 1438 if (urb->transfer_buffer_length > 1)
1439 buf [1] = 0; 1439 buf [1] = 0;
1440 urb->actual_length = min (2, 1440 urb->actual_length = min_t(u32, 2,
1441 urb->transfer_buffer_length); 1441 urb->transfer_buffer_length);
1442 value = 0; 1442 value = 0;
1443 status = 0; 1443 status = 0;
@@ -1626,7 +1626,7 @@ static int dummy_hub_control (
1626 hub_descriptor ((struct usb_hub_descriptor *) buf); 1626 hub_descriptor ((struct usb_hub_descriptor *) buf);
1627 break; 1627 break;
1628 case GetHubStatus: 1628 case GetHubStatus:
1629 *(__le32 *) buf = __constant_cpu_to_le32 (0); 1629 *(__le32 *) buf = cpu_to_le32 (0);
1630 break; 1630 break;
1631 case GetPortStatus: 1631 case GetPortStatus:
1632 if (wIndex != 1) 1632 if (wIndex != 1)
diff --git a/drivers/usb/gadget/epautoconf.c b/drivers/usb/gadget/epautoconf.c
index a36b1175b18d..cd0914ec898e 100644
--- a/drivers/usb/gadget/epautoconf.c
+++ b/drivers/usb/gadget/epautoconf.c
@@ -148,7 +148,7 @@ ep_matches (
148 return 0; 148 return 0;
149 149
150 /* BOTH: "high bandwidth" works only at high speed */ 150 /* BOTH: "high bandwidth" works only at high speed */
151 if ((desc->wMaxPacketSize & __constant_cpu_to_le16(3<<11))) { 151 if ((desc->wMaxPacketSize & cpu_to_le16(3<<11))) {
152 if (!gadget->is_dualspeed) 152 if (!gadget->is_dualspeed)
153 return 0; 153 return 0;
154 /* configure your hardware with enough buffering!! */ 154 /* configure your hardware with enough buffering!! */
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 37252d0012a7..d006dc652e02 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -156,7 +156,7 @@ static struct usb_device_descriptor device_desc = {
156 .bLength = sizeof device_desc, 156 .bLength = sizeof device_desc,
157 .bDescriptorType = USB_DT_DEVICE, 157 .bDescriptorType = USB_DT_DEVICE,
158 158
159 .bcdUSB = __constant_cpu_to_le16 (0x0200), 159 .bcdUSB = cpu_to_le16 (0x0200),
160 160
161 .bDeviceClass = USB_CLASS_COMM, 161 .bDeviceClass = USB_CLASS_COMM,
162 .bDeviceSubClass = 0, 162 .bDeviceSubClass = 0,
@@ -167,8 +167,8 @@ static struct usb_device_descriptor device_desc = {
167 * we support. (As does bNumConfigurations.) These values can 167 * we support. (As does bNumConfigurations.) These values can
168 * also be overridden by module parameters. 168 * also be overridden by module parameters.
169 */ 169 */
170 .idVendor = __constant_cpu_to_le16 (CDC_VENDOR_NUM), 170 .idVendor = cpu_to_le16 (CDC_VENDOR_NUM),
171 .idProduct = __constant_cpu_to_le16 (CDC_PRODUCT_NUM), 171 .idProduct = cpu_to_le16 (CDC_PRODUCT_NUM),
172 /* .bcdDevice = f(hardware) */ 172 /* .bcdDevice = f(hardware) */
173 /* .iManufacturer = DYNAMIC */ 173 /* .iManufacturer = DYNAMIC */
174 /* .iProduct = DYNAMIC */ 174 /* .iProduct = DYNAMIC */
@@ -318,7 +318,7 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
318 gadget->name, 318 gadget->name,
319 eth_config_driver.label); 319 eth_config_driver.label);
320 device_desc.bcdDevice = 320 device_desc.bcdDevice =
321 __constant_cpu_to_le16(0x0300 | 0x0099); 321 cpu_to_le16(0x0300 | 0x0099);
322 } 322 }
323 323
324 324
diff --git a/drivers/usb/gadget/f_acm.c b/drivers/usb/gadget/f_acm.c
index c1d34df0b157..7953948bfe4a 100644
--- a/drivers/usb/gadget/f_acm.c
+++ b/drivers/usb/gadget/f_acm.c
@@ -125,7 +125,7 @@ static struct usb_cdc_header_desc acm_header_desc __initdata = {
125 .bLength = sizeof(acm_header_desc), 125 .bLength = sizeof(acm_header_desc),
126 .bDescriptorType = USB_DT_CS_INTERFACE, 126 .bDescriptorType = USB_DT_CS_INTERFACE,
127 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 127 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
128 .bcdCDC = __constant_cpu_to_le16(0x0110), 128 .bcdCDC = cpu_to_le16(0x0110),
129}; 129};
130 130
131static struct usb_cdc_call_mgmt_descriptor 131static struct usb_cdc_call_mgmt_descriptor
@@ -159,7 +159,7 @@ static struct usb_endpoint_descriptor acm_fs_notify_desc __initdata = {
159 .bDescriptorType = USB_DT_ENDPOINT, 159 .bDescriptorType = USB_DT_ENDPOINT,
160 .bEndpointAddress = USB_DIR_IN, 160 .bEndpointAddress = USB_DIR_IN,
161 .bmAttributes = USB_ENDPOINT_XFER_INT, 161 .bmAttributes = USB_ENDPOINT_XFER_INT,
162 .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET), 162 .wMaxPacketSize = cpu_to_le16(GS_NOTIFY_MAXPACKET),
163 .bInterval = 1 << GS_LOG2_NOTIFY_INTERVAL, 163 .bInterval = 1 << GS_LOG2_NOTIFY_INTERVAL,
164}; 164};
165 165
@@ -197,7 +197,7 @@ static struct usb_endpoint_descriptor acm_hs_notify_desc __initdata = {
197 .bDescriptorType = USB_DT_ENDPOINT, 197 .bDescriptorType = USB_DT_ENDPOINT,
198 .bEndpointAddress = USB_DIR_IN, 198 .bEndpointAddress = USB_DIR_IN,
199 .bmAttributes = USB_ENDPOINT_XFER_INT, 199 .bmAttributes = USB_ENDPOINT_XFER_INT,
200 .wMaxPacketSize = __constant_cpu_to_le16(GS_NOTIFY_MAXPACKET), 200 .wMaxPacketSize = cpu_to_le16(GS_NOTIFY_MAXPACKET),
201 .bInterval = GS_LOG2_NOTIFY_INTERVAL+4, 201 .bInterval = GS_LOG2_NOTIFY_INTERVAL+4,
202}; 202};
203 203
@@ -205,14 +205,14 @@ static struct usb_endpoint_descriptor acm_hs_in_desc __initdata = {
205 .bLength = USB_DT_ENDPOINT_SIZE, 205 .bLength = USB_DT_ENDPOINT_SIZE,
206 .bDescriptorType = USB_DT_ENDPOINT, 206 .bDescriptorType = USB_DT_ENDPOINT,
207 .bmAttributes = USB_ENDPOINT_XFER_BULK, 207 .bmAttributes = USB_ENDPOINT_XFER_BULK,
208 .wMaxPacketSize = __constant_cpu_to_le16(512), 208 .wMaxPacketSize = cpu_to_le16(512),
209}; 209};
210 210
211static struct usb_endpoint_descriptor acm_hs_out_desc __initdata = { 211static struct usb_endpoint_descriptor acm_hs_out_desc __initdata = {
212 .bLength = USB_DT_ENDPOINT_SIZE, 212 .bLength = USB_DT_ENDPOINT_SIZE,
213 .bDescriptorType = USB_DT_ENDPOINT, 213 .bDescriptorType = USB_DT_ENDPOINT,
214 .bmAttributes = USB_ENDPOINT_XFER_BULK, 214 .bmAttributes = USB_ENDPOINT_XFER_BULK,
215 .wMaxPacketSize = __constant_cpu_to_le16(512), 215 .wMaxPacketSize = cpu_to_le16(512),
216}; 216};
217 217
218static struct usb_descriptor_header *acm_hs_function[] __initdata = { 218static struct usb_descriptor_header *acm_hs_function[] __initdata = {
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
index 4ae579948e54..ecf5bdd0ae06 100644
--- a/drivers/usb/gadget/f_ecm.c
+++ b/drivers/usb/gadget/f_ecm.c
@@ -130,7 +130,7 @@ static struct usb_cdc_header_desc ecm_header_desc __initdata = {
130 .bDescriptorType = USB_DT_CS_INTERFACE, 130 .bDescriptorType = USB_DT_CS_INTERFACE,
131 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 131 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
132 132
133 .bcdCDC = __constant_cpu_to_le16(0x0110), 133 .bcdCDC = cpu_to_le16(0x0110),
134}; 134};
135 135
136static struct usb_cdc_union_desc ecm_union_desc __initdata = { 136static struct usb_cdc_union_desc ecm_union_desc __initdata = {
@@ -148,9 +148,9 @@ static struct usb_cdc_ether_desc ecm_desc __initdata = {
148 148
149 /* this descriptor actually adds value, surprise! */ 149 /* this descriptor actually adds value, surprise! */
150 /* .iMACAddress = DYNAMIC */ 150 /* .iMACAddress = DYNAMIC */
151 .bmEthernetStatistics = __constant_cpu_to_le32(0), /* no statistics */ 151 .bmEthernetStatistics = cpu_to_le32(0), /* no statistics */
152 .wMaxSegmentSize = __constant_cpu_to_le16(ETH_FRAME_LEN), 152 .wMaxSegmentSize = cpu_to_le16(ETH_FRAME_LEN),
153 .wNumberMCFilters = __constant_cpu_to_le16(0), 153 .wNumberMCFilters = cpu_to_le16(0),
154 .bNumberPowerFilters = 0, 154 .bNumberPowerFilters = 0,
155}; 155};
156 156
@@ -192,7 +192,7 @@ static struct usb_endpoint_descriptor fs_ecm_notify_desc __initdata = {
192 192
193 .bEndpointAddress = USB_DIR_IN, 193 .bEndpointAddress = USB_DIR_IN,
194 .bmAttributes = USB_ENDPOINT_XFER_INT, 194 .bmAttributes = USB_ENDPOINT_XFER_INT,
195 .wMaxPacketSize = __constant_cpu_to_le16(ECM_STATUS_BYTECOUNT), 195 .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT),
196 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, 196 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
197}; 197};
198 198
@@ -236,7 +236,7 @@ static struct usb_endpoint_descriptor hs_ecm_notify_desc __initdata = {
236 236
237 .bEndpointAddress = USB_DIR_IN, 237 .bEndpointAddress = USB_DIR_IN,
238 .bmAttributes = USB_ENDPOINT_XFER_INT, 238 .bmAttributes = USB_ENDPOINT_XFER_INT,
239 .wMaxPacketSize = __constant_cpu_to_le16(ECM_STATUS_BYTECOUNT), 239 .wMaxPacketSize = cpu_to_le16(ECM_STATUS_BYTECOUNT),
240 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, 240 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
241}; 241};
242static struct usb_endpoint_descriptor hs_ecm_in_desc __initdata = { 242static struct usb_endpoint_descriptor hs_ecm_in_desc __initdata = {
@@ -245,7 +245,7 @@ static struct usb_endpoint_descriptor hs_ecm_in_desc __initdata = {
245 245
246 .bEndpointAddress = USB_DIR_IN, 246 .bEndpointAddress = USB_DIR_IN,
247 .bmAttributes = USB_ENDPOINT_XFER_BULK, 247 .bmAttributes = USB_ENDPOINT_XFER_BULK,
248 .wMaxPacketSize = __constant_cpu_to_le16(512), 248 .wMaxPacketSize = cpu_to_le16(512),
249}; 249};
250 250
251static struct usb_endpoint_descriptor hs_ecm_out_desc __initdata = { 251static struct usb_endpoint_descriptor hs_ecm_out_desc __initdata = {
@@ -254,7 +254,7 @@ static struct usb_endpoint_descriptor hs_ecm_out_desc __initdata = {
254 254
255 .bEndpointAddress = USB_DIR_OUT, 255 .bEndpointAddress = USB_DIR_OUT,
256 .bmAttributes = USB_ENDPOINT_XFER_BULK, 256 .bmAttributes = USB_ENDPOINT_XFER_BULK,
257 .wMaxPacketSize = __constant_cpu_to_le16(512), 257 .wMaxPacketSize = cpu_to_le16(512),
258}; 258};
259 259
260static struct usb_descriptor_header *ecm_hs_function[] __initdata = { 260static struct usb_descriptor_header *ecm_hs_function[] __initdata = {
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c
index 8affe1dfc2c1..eb6ddfc20857 100644
--- a/drivers/usb/gadget/f_loopback.c
+++ b/drivers/usb/gadget/f_loopback.c
@@ -100,7 +100,7 @@ static struct usb_endpoint_descriptor hs_loop_source_desc = {
100 .bDescriptorType = USB_DT_ENDPOINT, 100 .bDescriptorType = USB_DT_ENDPOINT,
101 101
102 .bmAttributes = USB_ENDPOINT_XFER_BULK, 102 .bmAttributes = USB_ENDPOINT_XFER_BULK,
103 .wMaxPacketSize = __constant_cpu_to_le16(512), 103 .wMaxPacketSize = cpu_to_le16(512),
104}; 104};
105 105
106static struct usb_endpoint_descriptor hs_loop_sink_desc = { 106static struct usb_endpoint_descriptor hs_loop_sink_desc = {
@@ -108,7 +108,7 @@ static struct usb_endpoint_descriptor hs_loop_sink_desc = {
108 .bDescriptorType = USB_DT_ENDPOINT, 108 .bDescriptorType = USB_DT_ENDPOINT,
109 109
110 .bmAttributes = USB_ENDPOINT_XFER_BULK, 110 .bmAttributes = USB_ENDPOINT_XFER_BULK,
111 .wMaxPacketSize = __constant_cpu_to_le16(512), 111 .wMaxPacketSize = cpu_to_le16(512),
112}; 112};
113 113
114static struct usb_descriptor_header *hs_loopback_descs[] = { 114static struct usb_descriptor_header *hs_loopback_descs[] = {
@@ -359,7 +359,7 @@ static struct usb_configuration loopback_driver = {
359 * loopback_add - add a loopback testing configuration to a device 359 * loopback_add - add a loopback testing configuration to a device
360 * @cdev: the device to support the loopback configuration 360 * @cdev: the device to support the loopback configuration
361 */ 361 */
362int __init loopback_add(struct usb_composite_dev *cdev) 362int __init loopback_add(struct usb_composite_dev *cdev, bool autoresume)
363{ 363{
364 int id; 364 int id;
365 365
@@ -372,6 +372,10 @@ int __init loopback_add(struct usb_composite_dev *cdev)
372 loopback_intf.iInterface = id; 372 loopback_intf.iInterface = id;
373 loopback_driver.iConfiguration = id; 373 loopback_driver.iConfiguration = id;
374 374
375 /* support autoresume for remote wakeup testing */
376 if (autoresume)
377 sourcesink_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
378
375 /* support OTG systems */ 379 /* support OTG systems */
376 if (gadget_is_otg(cdev->gadget)) { 380 if (gadget_is_otg(cdev->gadget)) {
377 loopback_driver.descriptors = otg_desc; 381 loopback_driver.descriptors = otg_desc;
diff --git a/drivers/usb/gadget/f_obex.c b/drivers/usb/gadget/f_obex.c
index 38aa896cc5db..46d6266f30ec 100644
--- a/drivers/usb/gadget/f_obex.c
+++ b/drivers/usb/gadget/f_obex.c
@@ -123,7 +123,7 @@ static struct usb_cdc_header_desc obex_cdc_header_desc __initdata = {
123 .bLength = sizeof(obex_cdc_header_desc), 123 .bLength = sizeof(obex_cdc_header_desc),
124 .bDescriptorType = USB_DT_CS_INTERFACE, 124 .bDescriptorType = USB_DT_CS_INTERFACE,
125 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 125 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
126 .bcdCDC = __constant_cpu_to_le16(0x0120), 126 .bcdCDC = cpu_to_le16(0x0120),
127}; 127};
128 128
129static struct usb_cdc_union_desc obex_cdc_union_desc __initdata = { 129static struct usb_cdc_union_desc obex_cdc_union_desc __initdata = {
@@ -138,7 +138,7 @@ static struct usb_cdc_obex_desc obex_desc __initdata = {
138 .bLength = sizeof(obex_desc), 138 .bLength = sizeof(obex_desc),
139 .bDescriptorType = USB_DT_CS_INTERFACE, 139 .bDescriptorType = USB_DT_CS_INTERFACE,
140 .bDescriptorSubType = USB_CDC_OBEX_TYPE, 140 .bDescriptorSubType = USB_CDC_OBEX_TYPE,
141 .bcdVersion = __constant_cpu_to_le16(0x0100), 141 .bcdVersion = cpu_to_le16(0x0100),
142}; 142};
143 143
144/* High-Speed Support */ 144/* High-Speed Support */
@@ -149,7 +149,7 @@ static struct usb_endpoint_descriptor obex_hs_ep_out_desc __initdata = {
149 149
150 .bEndpointAddress = USB_DIR_OUT, 150 .bEndpointAddress = USB_DIR_OUT,
151 .bmAttributes = USB_ENDPOINT_XFER_BULK, 151 .bmAttributes = USB_ENDPOINT_XFER_BULK,
152 .wMaxPacketSize = __constant_cpu_to_le16(512), 152 .wMaxPacketSize = cpu_to_le16(512),
153}; 153};
154 154
155static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = { 155static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = {
@@ -158,7 +158,7 @@ static struct usb_endpoint_descriptor obex_hs_ep_in_desc __initdata = {
158 158
159 .bEndpointAddress = USB_DIR_IN, 159 .bEndpointAddress = USB_DIR_IN,
160 .bmAttributes = USB_ENDPOINT_XFER_BULK, 160 .bmAttributes = USB_ENDPOINT_XFER_BULK,
161 .wMaxPacketSize = __constant_cpu_to_le16(512), 161 .wMaxPacketSize = cpu_to_le16(512),
162}; 162};
163 163
164static struct usb_descriptor_header *hs_function[] __initdata = { 164static struct usb_descriptor_header *hs_function[] __initdata = {
diff --git a/drivers/usb/gadget/f_phonet.c b/drivers/usb/gadget/f_phonet.c
index c0916c7b217e..c1abeb89b413 100644
--- a/drivers/usb/gadget/f_phonet.c
+++ b/drivers/usb/gadget/f_phonet.c
@@ -79,7 +79,7 @@ pn_header_desc = {
79 .bLength = sizeof pn_header_desc, 79 .bLength = sizeof pn_header_desc,
80 .bDescriptorType = USB_DT_CS_INTERFACE, 80 .bDescriptorType = USB_DT_CS_INTERFACE,
81 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 81 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
82 .bcdCDC = __constant_cpu_to_le16(0x0110), 82 .bcdCDC = cpu_to_le16(0x0110),
83}; 83};
84 84
85static const struct usb_cdc_header_desc 85static const struct usb_cdc_header_desc
@@ -87,7 +87,7 @@ pn_phonet_desc = {
87 .bLength = sizeof pn_phonet_desc, 87 .bLength = sizeof pn_phonet_desc,
88 .bDescriptorType = USB_DT_CS_INTERFACE, 88 .bDescriptorType = USB_DT_CS_INTERFACE,
89 .bDescriptorSubType = USB_CDC_PHONET_TYPE, 89 .bDescriptorSubType = USB_CDC_PHONET_TYPE,
90 .bcdCDC = __constant_cpu_to_le16(0x1505), /* ??? */ 90 .bcdCDC = cpu_to_le16(0x1505), /* ??? */
91}; 91};
92 92
93static struct usb_cdc_union_desc 93static struct usb_cdc_union_desc
@@ -138,7 +138,7 @@ pn_hs_sink_desc = {
138 138
139 .bEndpointAddress = USB_DIR_OUT, 139 .bEndpointAddress = USB_DIR_OUT,
140 .bmAttributes = USB_ENDPOINT_XFER_BULK, 140 .bmAttributes = USB_ENDPOINT_XFER_BULK,
141 .wMaxPacketSize = __constant_cpu_to_le16(512), 141 .wMaxPacketSize = cpu_to_le16(512),
142}; 142};
143 143
144static struct usb_endpoint_descriptor 144static struct usb_endpoint_descriptor
@@ -157,7 +157,7 @@ pn_hs_source_desc = {
157 157
158 .bEndpointAddress = USB_DIR_IN, 158 .bEndpointAddress = USB_DIR_IN,
159 .bmAttributes = USB_ENDPOINT_XFER_BULK, 159 .bmAttributes = USB_ENDPOINT_XFER_BULK,
160 .wMaxPacketSize = __constant_cpu_to_le16(512), 160 .wMaxPacketSize = cpu_to_le16(512),
161}; 161};
162 162
163static struct usb_descriptor_header *fs_pn_function[] = { 163static struct usb_descriptor_header *fs_pn_function[] = {
diff --git a/drivers/usb/gadget/f_rndis.c b/drivers/usb/gadget/f_rndis.c
index 3a8bb53fc473..3279a4726042 100644
--- a/drivers/usb/gadget/f_rndis.c
+++ b/drivers/usb/gadget/f_rndis.c
@@ -137,7 +137,7 @@ static struct usb_cdc_header_desc header_desc __initdata = {
137 .bDescriptorType = USB_DT_CS_INTERFACE, 137 .bDescriptorType = USB_DT_CS_INTERFACE,
138 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 138 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
139 139
140 .bcdCDC = __constant_cpu_to_le16(0x0110), 140 .bcdCDC = cpu_to_le16(0x0110),
141}; 141};
142 142
143static struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor __initdata = { 143static struct usb_cdc_call_mgmt_descriptor call_mgmt_descriptor __initdata = {
@@ -187,7 +187,7 @@ static struct usb_endpoint_descriptor fs_notify_desc __initdata = {
187 187
188 .bEndpointAddress = USB_DIR_IN, 188 .bEndpointAddress = USB_DIR_IN,
189 .bmAttributes = USB_ENDPOINT_XFER_INT, 189 .bmAttributes = USB_ENDPOINT_XFER_INT,
190 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT), 190 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
191 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, 191 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
192}; 192};
193 193
@@ -230,7 +230,7 @@ static struct usb_endpoint_descriptor hs_notify_desc __initdata = {
230 230
231 .bEndpointAddress = USB_DIR_IN, 231 .bEndpointAddress = USB_DIR_IN,
232 .bmAttributes = USB_ENDPOINT_XFER_INT, 232 .bmAttributes = USB_ENDPOINT_XFER_INT,
233 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT), 233 .wMaxPacketSize = cpu_to_le16(STATUS_BYTECOUNT),
234 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, 234 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
235}; 235};
236static struct usb_endpoint_descriptor hs_in_desc __initdata = { 236static struct usb_endpoint_descriptor hs_in_desc __initdata = {
@@ -239,7 +239,7 @@ static struct usb_endpoint_descriptor hs_in_desc __initdata = {
239 239
240 .bEndpointAddress = USB_DIR_IN, 240 .bEndpointAddress = USB_DIR_IN,
241 .bmAttributes = USB_ENDPOINT_XFER_BULK, 241 .bmAttributes = USB_ENDPOINT_XFER_BULK,
242 .wMaxPacketSize = __constant_cpu_to_le16(512), 242 .wMaxPacketSize = cpu_to_le16(512),
243}; 243};
244 244
245static struct usb_endpoint_descriptor hs_out_desc __initdata = { 245static struct usb_endpoint_descriptor hs_out_desc __initdata = {
@@ -248,7 +248,7 @@ static struct usb_endpoint_descriptor hs_out_desc __initdata = {
248 248
249 .bEndpointAddress = USB_DIR_OUT, 249 .bEndpointAddress = USB_DIR_OUT,
250 .bmAttributes = USB_ENDPOINT_XFER_BULK, 250 .bmAttributes = USB_ENDPOINT_XFER_BULK,
251 .wMaxPacketSize = __constant_cpu_to_le16(512), 251 .wMaxPacketSize = cpu_to_le16(512),
252}; 252};
253 253
254static struct usb_descriptor_header *eth_hs_function[] __initdata = { 254static struct usb_descriptor_header *eth_hs_function[] __initdata = {
@@ -437,7 +437,7 @@ invalid:
437 DBG(cdev, "rndis req%02x.%02x v%04x i%04x l%d\n", 437 DBG(cdev, "rndis req%02x.%02x v%04x i%04x l%d\n",
438 ctrl->bRequestType, ctrl->bRequest, 438 ctrl->bRequestType, ctrl->bRequest,
439 w_value, w_index, w_length); 439 w_value, w_index, w_length);
440 req->zero = 0; 440 req->zero = (value < w_length);
441 req->length = value; 441 req->length = value;
442 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC); 442 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
443 if (value < 0) 443 if (value < 0)
diff --git a/drivers/usb/gadget/f_serial.c b/drivers/usb/gadget/f_serial.c
index fe5674db344b..db0aa93606ef 100644
--- a/drivers/usb/gadget/f_serial.c
+++ b/drivers/usb/gadget/f_serial.c
@@ -89,14 +89,14 @@ static struct usb_endpoint_descriptor gser_hs_in_desc __initdata = {
89 .bLength = USB_DT_ENDPOINT_SIZE, 89 .bLength = USB_DT_ENDPOINT_SIZE,
90 .bDescriptorType = USB_DT_ENDPOINT, 90 .bDescriptorType = USB_DT_ENDPOINT,
91 .bmAttributes = USB_ENDPOINT_XFER_BULK, 91 .bmAttributes = USB_ENDPOINT_XFER_BULK,
92 .wMaxPacketSize = __constant_cpu_to_le16(512), 92 .wMaxPacketSize = cpu_to_le16(512),
93}; 93};
94 94
95static struct usb_endpoint_descriptor gser_hs_out_desc __initdata = { 95static struct usb_endpoint_descriptor gser_hs_out_desc __initdata = {
96 .bLength = USB_DT_ENDPOINT_SIZE, 96 .bLength = USB_DT_ENDPOINT_SIZE,
97 .bDescriptorType = USB_DT_ENDPOINT, 97 .bDescriptorType = USB_DT_ENDPOINT,
98 .bmAttributes = USB_ENDPOINT_XFER_BULK, 98 .bmAttributes = USB_ENDPOINT_XFER_BULK,
99 .wMaxPacketSize = __constant_cpu_to_le16(512), 99 .wMaxPacketSize = cpu_to_le16(512),
100}; 100};
101 101
102static struct usb_descriptor_header *gser_hs_function[] __initdata = { 102static struct usb_descriptor_header *gser_hs_function[] __initdata = {
diff --git a/drivers/usb/gadget/f_sourcesink.c b/drivers/usb/gadget/f_sourcesink.c
index dc84d26d2835..bffe91d525f9 100644
--- a/drivers/usb/gadget/f_sourcesink.c
+++ b/drivers/usb/gadget/f_sourcesink.c
@@ -59,7 +59,6 @@ struct f_sourcesink {
59 59
60 struct usb_ep *in_ep; 60 struct usb_ep *in_ep;
61 struct usb_ep *out_ep; 61 struct usb_ep *out_ep;
62 struct timer_list resume;
63}; 62};
64 63
65static inline struct f_sourcesink *func_to_ss(struct usb_function *f) 64static inline struct f_sourcesink *func_to_ss(struct usb_function *f)
@@ -67,10 +66,6 @@ static inline struct f_sourcesink *func_to_ss(struct usb_function *f)
67 return container_of(f, struct f_sourcesink, function); 66 return container_of(f, struct f_sourcesink, function);
68} 67}
69 68
70static unsigned autoresume;
71module_param(autoresume, uint, 0);
72MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup");
73
74static unsigned pattern; 69static unsigned pattern;
75module_param(pattern, uint, 0); 70module_param(pattern, uint, 0);
76MODULE_PARM_DESC(pattern, "0 = all zeroes, 1 = mod63 "); 71MODULE_PARM_DESC(pattern, "0 = all zeroes, 1 = mod63 ");
@@ -118,7 +113,7 @@ static struct usb_endpoint_descriptor hs_source_desc = {
118 .bDescriptorType = USB_DT_ENDPOINT, 113 .bDescriptorType = USB_DT_ENDPOINT,
119 114
120 .bmAttributes = USB_ENDPOINT_XFER_BULK, 115 .bmAttributes = USB_ENDPOINT_XFER_BULK,
121 .wMaxPacketSize = __constant_cpu_to_le16(512), 116 .wMaxPacketSize = cpu_to_le16(512),
122}; 117};
123 118
124static struct usb_endpoint_descriptor hs_sink_desc = { 119static struct usb_endpoint_descriptor hs_sink_desc = {
@@ -126,7 +121,7 @@ static struct usb_endpoint_descriptor hs_sink_desc = {
126 .bDescriptorType = USB_DT_ENDPOINT, 121 .bDescriptorType = USB_DT_ENDPOINT,
127 122
128 .bmAttributes = USB_ENDPOINT_XFER_BULK, 123 .bmAttributes = USB_ENDPOINT_XFER_BULK,
129 .wMaxPacketSize = __constant_cpu_to_le16(512), 124 .wMaxPacketSize = cpu_to_le16(512),
130}; 125};
131 126
132static struct usb_descriptor_header *hs_source_sink_descs[] = { 127static struct usb_descriptor_header *hs_source_sink_descs[] = {
@@ -155,21 +150,6 @@ static struct usb_gadget_strings *sourcesink_strings[] = {
155 150
156/*-------------------------------------------------------------------------*/ 151/*-------------------------------------------------------------------------*/
157 152
158static void sourcesink_autoresume(unsigned long _c)
159{
160 struct usb_composite_dev *cdev = (void *)_c;
161 struct usb_gadget *g = cdev->gadget;
162
163 /* Normally the host would be woken up for something
164 * more significant than just a timer firing; likely
165 * because of some direct user request.
166 */
167 if (g->speed != USB_SPEED_UNKNOWN) {
168 int status = usb_gadget_wakeup(g);
169 DBG(cdev, "%s --> %d\n", __func__, status);
170 }
171}
172
173static int __init 153static int __init
174sourcesink_bind(struct usb_configuration *c, struct usb_function *f) 154sourcesink_bind(struct usb_configuration *c, struct usb_function *f)
175{ 155{
@@ -198,9 +178,6 @@ autoconf_fail:
198 goto autoconf_fail; 178 goto autoconf_fail;
199 ss->out_ep->driver_data = cdev; /* claim */ 179 ss->out_ep->driver_data = cdev; /* claim */
200 180
201 setup_timer(&ss->resume, sourcesink_autoresume,
202 (unsigned long) c->cdev);
203
204 /* support high speed hardware */ 181 /* support high speed hardware */
205 if (gadget_is_dualspeed(c->cdev->gadget)) { 182 if (gadget_is_dualspeed(c->cdev->gadget)) {
206 hs_source_desc.bEndpointAddress = 183 hs_source_desc.bEndpointAddress =
@@ -359,7 +336,6 @@ static void disable_source_sink(struct f_sourcesink *ss)
359 336
360 cdev = ss->function.config->cdev; 337 cdev = ss->function.config->cdev;
361 disable_endpoints(cdev, ss->in_ep, ss->out_ep); 338 disable_endpoints(cdev, ss->in_ep, ss->out_ep);
362 del_timer(&ss->resume);
363 VDBG(cdev, "%s disabled\n", ss->function.name); 339 VDBG(cdev, "%s disabled\n", ss->function.name);
364} 340}
365 341
@@ -426,30 +402,6 @@ static void sourcesink_disable(struct usb_function *f)
426 disable_source_sink(ss); 402 disable_source_sink(ss);
427} 403}
428 404
429static void sourcesink_suspend(struct usb_function *f)
430{
431 struct f_sourcesink *ss = func_to_ss(f);
432 struct usb_composite_dev *cdev = f->config->cdev;
433
434 if (cdev->gadget->speed == USB_SPEED_UNKNOWN)
435 return;
436
437 if (autoresume) {
438 mod_timer(&ss->resume, jiffies + (HZ * autoresume));
439 DBG(cdev, "suspend, wakeup in %d seconds\n", autoresume);
440 } else
441 DBG(cdev, "%s\n", __func__);
442}
443
444static void sourcesink_resume(struct usb_function *f)
445{
446 struct f_sourcesink *ss = func_to_ss(f);
447 struct usb_composite_dev *cdev = f->config->cdev;
448
449 DBG(cdev, "%s\n", __func__);
450 del_timer(&ss->resume);
451}
452
453/*-------------------------------------------------------------------------*/ 405/*-------------------------------------------------------------------------*/
454 406
455static int __init sourcesink_bind_config(struct usb_configuration *c) 407static int __init sourcesink_bind_config(struct usb_configuration *c)
@@ -467,8 +419,6 @@ static int __init sourcesink_bind_config(struct usb_configuration *c)
467 ss->function.unbind = sourcesink_unbind; 419 ss->function.unbind = sourcesink_unbind;
468 ss->function.set_alt = sourcesink_set_alt; 420 ss->function.set_alt = sourcesink_set_alt;
469 ss->function.disable = sourcesink_disable; 421 ss->function.disable = sourcesink_disable;
470 ss->function.suspend = sourcesink_suspend;
471 ss->function.resume = sourcesink_resume;
472 422
473 status = usb_add_function(c, &ss->function); 423 status = usb_add_function(c, &ss->function);
474 if (status) 424 if (status)
@@ -559,7 +509,7 @@ static struct usb_configuration sourcesink_driver = {
559 * sourcesink_add - add a source/sink testing configuration to a device 509 * sourcesink_add - add a source/sink testing configuration to a device
560 * @cdev: the device to support the configuration 510 * @cdev: the device to support the configuration
561 */ 511 */
562int __init sourcesink_add(struct usb_composite_dev *cdev) 512int __init sourcesink_add(struct usb_composite_dev *cdev, bool autoresume)
563{ 513{
564 int id; 514 int id;
565 515
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index fe1832875771..a9c98fdb626d 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -108,7 +108,7 @@ static struct usb_cdc_header_desc mdlm_header_desc __initdata = {
108 .bDescriptorType = USB_DT_CS_INTERFACE, 108 .bDescriptorType = USB_DT_CS_INTERFACE,
109 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 109 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
110 110
111 .bcdCDC = __constant_cpu_to_le16(0x0110), 111 .bcdCDC = cpu_to_le16(0x0110),
112}; 112};
113 113
114static struct usb_cdc_mdlm_desc mdlm_desc __initdata = { 114static struct usb_cdc_mdlm_desc mdlm_desc __initdata = {
@@ -116,7 +116,7 @@ static struct usb_cdc_mdlm_desc mdlm_desc __initdata = {
116 .bDescriptorType = USB_DT_CS_INTERFACE, 116 .bDescriptorType = USB_DT_CS_INTERFACE,
117 .bDescriptorSubType = USB_CDC_MDLM_TYPE, 117 .bDescriptorSubType = USB_CDC_MDLM_TYPE,
118 118
119 .bcdVersion = __constant_cpu_to_le16(0x0100), 119 .bcdVersion = cpu_to_le16(0x0100),
120 .bGUID = { 120 .bGUID = {
121 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6, 121 0x5d, 0x34, 0xcf, 0x66, 0x11, 0x18, 0x11, 0xd6,
122 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f, 122 0xa2, 0x1a, 0x00, 0x01, 0x02, 0xca, 0x9a, 0x7f,
@@ -144,9 +144,9 @@ static struct usb_cdc_ether_desc ether_desc __initdata = {
144 144
145 /* this descriptor actually adds value, surprise! */ 145 /* this descriptor actually adds value, surprise! */
146 /* .iMACAddress = DYNAMIC */ 146 /* .iMACAddress = DYNAMIC */
147 .bmEthernetStatistics = __constant_cpu_to_le32(0), /* no statistics */ 147 .bmEthernetStatistics = cpu_to_le32(0), /* no statistics */
148 .wMaxSegmentSize = __constant_cpu_to_le16(ETH_FRAME_LEN), 148 .wMaxSegmentSize = cpu_to_le16(ETH_FRAME_LEN),
149 .wNumberMCFilters = __constant_cpu_to_le16(0), 149 .wNumberMCFilters = cpu_to_le16(0),
150 .bNumberPowerFilters = 0, 150 .bNumberPowerFilters = 0,
151}; 151};
152 152
@@ -186,7 +186,7 @@ static struct usb_endpoint_descriptor hs_subset_in_desc __initdata = {
186 .bDescriptorType = USB_DT_ENDPOINT, 186 .bDescriptorType = USB_DT_ENDPOINT,
187 187
188 .bmAttributes = USB_ENDPOINT_XFER_BULK, 188 .bmAttributes = USB_ENDPOINT_XFER_BULK,
189 .wMaxPacketSize = __constant_cpu_to_le16(512), 189 .wMaxPacketSize = cpu_to_le16(512),
190}; 190};
191 191
192static struct usb_endpoint_descriptor hs_subset_out_desc __initdata = { 192static struct usb_endpoint_descriptor hs_subset_out_desc __initdata = {
@@ -194,7 +194,7 @@ static struct usb_endpoint_descriptor hs_subset_out_desc __initdata = {
194 .bDescriptorType = USB_DT_ENDPOINT, 194 .bDescriptorType = USB_DT_ENDPOINT,
195 195
196 .bmAttributes = USB_ENDPOINT_XFER_BULK, 196 .bmAttributes = USB_ENDPOINT_XFER_BULK,
197 .wMaxPacketSize = __constant_cpu_to_le16(512), 197 .wMaxPacketSize = cpu_to_le16(512),
198}; 198};
199 199
200static struct usb_descriptor_header *hs_eth_function[] __initdata = { 200static struct usb_descriptor_header *hs_eth_function[] __initdata = {
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index 1ab9dac7e12d..d3c2464dee82 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -847,13 +847,13 @@ device_desc = {
847 .bLength = sizeof device_desc, 847 .bLength = sizeof device_desc,
848 .bDescriptorType = USB_DT_DEVICE, 848 .bDescriptorType = USB_DT_DEVICE,
849 849
850 .bcdUSB = __constant_cpu_to_le16(0x0200), 850 .bcdUSB = cpu_to_le16(0x0200),
851 .bDeviceClass = USB_CLASS_PER_INTERFACE, 851 .bDeviceClass = USB_CLASS_PER_INTERFACE,
852 852
853 /* The next three values can be overridden by module parameters */ 853 /* The next three values can be overridden by module parameters */
854 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_ID), 854 .idVendor = cpu_to_le16(DRIVER_VENDOR_ID),
855 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_ID), 855 .idProduct = cpu_to_le16(DRIVER_PRODUCT_ID),
856 .bcdDevice = __constant_cpu_to_le16(0xffff), 856 .bcdDevice = cpu_to_le16(0xffff),
857 857
858 .iManufacturer = STRING_MANUFACTURER, 858 .iManufacturer = STRING_MANUFACTURER,
859 .iProduct = STRING_PRODUCT, 859 .iProduct = STRING_PRODUCT,
@@ -926,7 +926,7 @@ fs_intr_in_desc = {
926 926
927 .bEndpointAddress = USB_DIR_IN, 927 .bEndpointAddress = USB_DIR_IN,
928 .bmAttributes = USB_ENDPOINT_XFER_INT, 928 .bmAttributes = USB_ENDPOINT_XFER_INT,
929 .wMaxPacketSize = __constant_cpu_to_le16(2), 929 .wMaxPacketSize = cpu_to_le16(2),
930 .bInterval = 32, // frames -> 32 ms 930 .bInterval = 32, // frames -> 32 ms
931}; 931};
932 932
@@ -954,7 +954,7 @@ dev_qualifier = {
954 .bLength = sizeof dev_qualifier, 954 .bLength = sizeof dev_qualifier,
955 .bDescriptorType = USB_DT_DEVICE_QUALIFIER, 955 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
956 956
957 .bcdUSB = __constant_cpu_to_le16(0x0200), 957 .bcdUSB = cpu_to_le16(0x0200),
958 .bDeviceClass = USB_CLASS_PER_INTERFACE, 958 .bDeviceClass = USB_CLASS_PER_INTERFACE,
959 959
960 .bNumConfigurations = 1, 960 .bNumConfigurations = 1,
@@ -967,7 +967,7 @@ hs_bulk_in_desc = {
967 967
968 /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */ 968 /* bEndpointAddress copied from fs_bulk_in_desc during fsg_bind() */
969 .bmAttributes = USB_ENDPOINT_XFER_BULK, 969 .bmAttributes = USB_ENDPOINT_XFER_BULK,
970 .wMaxPacketSize = __constant_cpu_to_le16(512), 970 .wMaxPacketSize = cpu_to_le16(512),
971}; 971};
972 972
973static struct usb_endpoint_descriptor 973static struct usb_endpoint_descriptor
@@ -977,7 +977,7 @@ hs_bulk_out_desc = {
977 977
978 /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */ 978 /* bEndpointAddress copied from fs_bulk_out_desc during fsg_bind() */
979 .bmAttributes = USB_ENDPOINT_XFER_BULK, 979 .bmAttributes = USB_ENDPOINT_XFER_BULK,
980 .wMaxPacketSize = __constant_cpu_to_le16(512), 980 .wMaxPacketSize = cpu_to_le16(512),
981 .bInterval = 1, // NAK every 1 uframe 981 .bInterval = 1, // NAK every 1 uframe
982}; 982};
983 983
@@ -988,7 +988,7 @@ hs_intr_in_desc = {
988 988
989 /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */ 989 /* bEndpointAddress copied from fs_intr_in_desc during fsg_bind() */
990 .bmAttributes = USB_ENDPOINT_XFER_INT, 990 .bmAttributes = USB_ENDPOINT_XFER_INT,
991 .wMaxPacketSize = __constant_cpu_to_le16(2), 991 .wMaxPacketSize = cpu_to_le16(2),
992 .bInterval = 9, // 2**(9-1) = 256 uframes -> 32 ms 992 .bInterval = 9, // 2**(9-1) = 256 uframes -> 32 ms
993}; 993};
994 994
@@ -2646,7 +2646,7 @@ static int send_status(struct fsg_dev *fsg)
2646 struct bulk_cs_wrap *csw = bh->buf; 2646 struct bulk_cs_wrap *csw = bh->buf;
2647 2647
2648 /* Store and send the Bulk-only CSW */ 2648 /* Store and send the Bulk-only CSW */
2649 csw->Signature = __constant_cpu_to_le32(USB_BULK_CS_SIG); 2649 csw->Signature = cpu_to_le32(USB_BULK_CS_SIG);
2650 csw->Tag = fsg->tag; 2650 csw->Tag = fsg->tag;
2651 csw->Residue = cpu_to_le32(fsg->residue); 2651 csw->Residue = cpu_to_le32(fsg->residue);
2652 csw->Status = status; 2652 csw->Status = status;
@@ -3089,7 +3089,7 @@ static int received_cbw(struct fsg_dev *fsg, struct fsg_buffhd *bh)
3089 3089
3090 /* Is the CBW valid? */ 3090 /* Is the CBW valid? */
3091 if (req->actual != USB_BULK_CB_WRAP_LEN || 3091 if (req->actual != USB_BULK_CB_WRAP_LEN ||
3092 cbw->Signature != __constant_cpu_to_le32( 3092 cbw->Signature != cpu_to_le32(
3093 USB_BULK_CB_SIG)) { 3093 USB_BULK_CB_SIG)) {
3094 DBG(fsg, "invalid CBW: len %u sig 0x%x\n", 3094 DBG(fsg, "invalid CBW: len %u sig 0x%x\n",
3095 req->actual, 3095 req->actual,
diff --git a/drivers/usb/gadget/fsl_usb2_udc.c b/drivers/usb/gadget/fsl_usb2_udc.c
index d8d9a52a44b3..9d7b95d4e3d2 100644
--- a/drivers/usb/gadget/fsl_usb2_udc.c
+++ b/drivers/usb/gadget/fsl_usb2_udc.c
@@ -1802,7 +1802,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1802 1802
1803out: 1803out:
1804 if (retval) 1804 if (retval)
1805 printk("gadget driver register failed %d\n", retval); 1805 printk(KERN_WARNING "gadget driver register failed %d\n",
1806 retval);
1806 return retval; 1807 return retval;
1807} 1808}
1808EXPORT_SYMBOL(usb_gadget_register_driver); 1809EXPORT_SYMBOL(usb_gadget_register_driver);
@@ -1847,7 +1848,8 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1847 udc_controller->gadget.dev.driver = NULL; 1848 udc_controller->gadget.dev.driver = NULL;
1848 udc_controller->driver = NULL; 1849 udc_controller->driver = NULL;
1849 1850
1850 printk("unregistered gadget driver '%s'\n", driver->driver.name); 1851 printk(KERN_WARNING "unregistered gadget driver '%s'\n",
1852 driver->driver.name);
1851 return 0; 1853 return 0;
1852} 1854}
1853EXPORT_SYMBOL(usb_gadget_unregister_driver); 1855EXPORT_SYMBOL(usb_gadget_unregister_driver);
@@ -2455,7 +2457,7 @@ module_init(udc_init);
2455static void __exit udc_exit(void) 2457static void __exit udc_exit(void)
2456{ 2458{
2457 platform_driver_unregister(&udc_driver); 2459 platform_driver_unregister(&udc_driver);
2458 printk("%s unregistered\n", driver_desc); 2460 printk(KERN_WARNING "%s unregistered\n", driver_desc);
2459} 2461}
2460 2462
2461module_exit(udc_exit); 2463module_exit(udc_exit);
diff --git a/drivers/usb/gadget/g_zero.h b/drivers/usb/gadget/g_zero.h
index dd2f16ad5a88..e84b3c47ed3c 100644
--- a/drivers/usb/gadget/g_zero.h
+++ b/drivers/usb/gadget/g_zero.h
@@ -19,7 +19,7 @@ void disable_endpoints(struct usb_composite_dev *cdev,
19 struct usb_ep *in, struct usb_ep *out); 19 struct usb_ep *in, struct usb_ep *out);
20 20
21/* configuration-specific linkup */ 21/* configuration-specific linkup */
22int sourcesink_add(struct usb_composite_dev *cdev); 22int sourcesink_add(struct usb_composite_dev *cdev, bool autoresume);
23int loopback_add(struct usb_composite_dev *cdev); 23int loopback_add(struct usb_composite_dev *cdev, bool autoresume);
24 24
25#endif /* __G_ZERO_H */ 25#endif /* __G_ZERO_H */
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index 60d3f9e9b51f..b9312dc6e041 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -199,10 +199,10 @@ DECLARE_USB_MS_ENDPOINT_DESCRIPTOR(1);
199static struct usb_device_descriptor device_desc = { 199static struct usb_device_descriptor device_desc = {
200 .bLength = USB_DT_DEVICE_SIZE, 200 .bLength = USB_DT_DEVICE_SIZE,
201 .bDescriptorType = USB_DT_DEVICE, 201 .bDescriptorType = USB_DT_DEVICE,
202 .bcdUSB = __constant_cpu_to_le16(0x0200), 202 .bcdUSB = cpu_to_le16(0x0200),
203 .bDeviceClass = USB_CLASS_PER_INTERFACE, 203 .bDeviceClass = USB_CLASS_PER_INTERFACE,
204 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM), 204 .idVendor = cpu_to_le16(DRIVER_VENDOR_NUM),
205 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM), 205 .idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM),
206 .iManufacturer = STRING_MANUFACTURER, 206 .iManufacturer = STRING_MANUFACTURER,
207 .iProduct = STRING_PRODUCT, 207 .iProduct = STRING_PRODUCT,
208 .bNumConfigurations = 1, 208 .bNumConfigurations = 1,
@@ -241,8 +241,8 @@ static const struct usb_ac_header_descriptor_1 ac_header_desc = {
241 .bLength = USB_DT_AC_HEADER_SIZE(1), 241 .bLength = USB_DT_AC_HEADER_SIZE(1),
242 .bDescriptorType = USB_DT_CS_INTERFACE, 242 .bDescriptorType = USB_DT_CS_INTERFACE,
243 .bDescriptorSubtype = USB_MS_HEADER, 243 .bDescriptorSubtype = USB_MS_HEADER,
244 .bcdADC = __constant_cpu_to_le16(0x0100), 244 .bcdADC = cpu_to_le16(0x0100),
245 .wTotalLength = __constant_cpu_to_le16(USB_DT_AC_HEADER_SIZE(1)), 245 .wTotalLength = cpu_to_le16(USB_DT_AC_HEADER_SIZE(1)),
246 .bInCollection = 1, 246 .bInCollection = 1,
247 .baInterfaceNr = { 247 .baInterfaceNr = {
248 [0] = GMIDI_MS_INTERFACE, 248 [0] = GMIDI_MS_INTERFACE,
@@ -265,8 +265,8 @@ static const struct usb_ms_header_descriptor ms_header_desc = {
265 .bLength = USB_DT_MS_HEADER_SIZE, 265 .bLength = USB_DT_MS_HEADER_SIZE,
266 .bDescriptorType = USB_DT_CS_INTERFACE, 266 .bDescriptorType = USB_DT_CS_INTERFACE,
267 .bDescriptorSubtype = USB_MS_HEADER, 267 .bDescriptorSubtype = USB_MS_HEADER,
268 .bcdMSC = __constant_cpu_to_le16(0x0100), 268 .bcdMSC = cpu_to_le16(0x0100),
269 .wTotalLength = __constant_cpu_to_le16(USB_DT_MS_HEADER_SIZE 269 .wTotalLength = cpu_to_le16(USB_DT_MS_HEADER_SIZE
270 + 2*USB_DT_MIDI_IN_SIZE 270 + 2*USB_DT_MIDI_IN_SIZE
271 + 2*USB_DT_MIDI_OUT_SIZE(1)), 271 + 2*USB_DT_MIDI_OUT_SIZE(1)),
272}; 272};
@@ -1099,10 +1099,9 @@ static int gmidi_register_card(struct gmidi_device *dev)
1099 .dev_free = gmidi_snd_free, 1099 .dev_free = gmidi_snd_free,
1100 }; 1100 };
1101 1101
1102 card = snd_card_new(index, id, THIS_MODULE, 0); 1102 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
1103 if (!card) { 1103 if (err < 0) {
1104 ERROR(dev, "snd_card_new failed\n"); 1104 ERROR(dev, "snd_card_create failed\n");
1105 err = -ENOMEM;
1106 goto fail; 1105 goto fail;
1107 } 1106 }
1108 dev->card = card; 1107 dev->card = card;
@@ -1227,7 +1226,7 @@ autoconf_fail:
1227 */ 1226 */
1228 pr_warning("%s: controller '%s' not recognized\n", 1227 pr_warning("%s: controller '%s' not recognized\n",
1229 shortname, gadget->name); 1228 shortname, gadget->name);
1230 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); 1229 device_desc.bcdDevice = cpu_to_le16(0x9999);
1231 } 1230 }
1232 1231
1233 1232
diff --git a/drivers/usb/gadget/goku_udc.c b/drivers/usb/gadget/goku_udc.c
index 63419c4d503c..de010c939dbb 100644
--- a/drivers/usb/gadget/goku_udc.c
+++ b/drivers/usb/gadget/goku_udc.c
@@ -1472,7 +1472,7 @@ static void ep0_setup(struct goku_udc *dev)
1472 /* active endpoint */ 1472 /* active endpoint */
1473 if (tmp > 3 || (!dev->ep[tmp].desc && tmp != 0)) 1473 if (tmp > 3 || (!dev->ep[tmp].desc && tmp != 0))
1474 goto stall; 1474 goto stall;
1475 if (ctrl.wIndex & __constant_cpu_to_le16( 1475 if (ctrl.wIndex & cpu_to_le16(
1476 USB_DIR_IN)) { 1476 USB_DIR_IN)) {
1477 if (!dev->ep[tmp].is_in) 1477 if (!dev->ep[tmp].is_in)
1478 goto stall; 1478 goto stall;
@@ -1480,7 +1480,7 @@ static void ep0_setup(struct goku_udc *dev)
1480 if (dev->ep[tmp].is_in) 1480 if (dev->ep[tmp].is_in)
1481 goto stall; 1481 goto stall;
1482 } 1482 }
1483 if (ctrl.wValue != __constant_cpu_to_le16( 1483 if (ctrl.wValue != cpu_to_le16(
1484 USB_ENDPOINT_HALT)) 1484 USB_ENDPOINT_HALT))
1485 goto stall; 1485 goto stall;
1486 if (tmp) 1486 if (tmp)
@@ -1493,7 +1493,7 @@ succeed:
1493 return; 1493 return;
1494 case USB_RECIP_DEVICE: 1494 case USB_RECIP_DEVICE:
1495 /* device remote wakeup: always clear */ 1495 /* device remote wakeup: always clear */
1496 if (ctrl.wValue != __constant_cpu_to_le16(1)) 1496 if (ctrl.wValue != cpu_to_le16(1))
1497 goto stall; 1497 goto stall;
1498 VDBG(dev, "clear dev remote wakeup\n"); 1498 VDBG(dev, "clear dev remote wakeup\n");
1499 goto succeed; 1499 goto succeed;
@@ -1519,7 +1519,7 @@ succeed:
1519 dev->req_config = (ctrl.bRequest == USB_REQ_SET_CONFIGURATION 1519 dev->req_config = (ctrl.bRequest == USB_REQ_SET_CONFIGURATION
1520 && ctrl.bRequestType == USB_RECIP_DEVICE); 1520 && ctrl.bRequestType == USB_RECIP_DEVICE);
1521 if (unlikely(dev->req_config)) 1521 if (unlikely(dev->req_config))
1522 dev->configured = (ctrl.wValue != __constant_cpu_to_le16(0)); 1522 dev->configured = (ctrl.wValue != cpu_to_le16(0));
1523 1523
1524 /* delegate everything to the gadget driver. 1524 /* delegate everything to the gadget driver.
1525 * it may respond after this irq handler returns. 1525 * it may respond after this irq handler returns.
diff --git a/drivers/usb/gadget/imx_udc.c b/drivers/usb/gadget/imx_udc.c
index 77c5d0a8a06e..168658b4b4e2 100644
--- a/drivers/usb/gadget/imx_udc.c
+++ b/drivers/usb/gadget/imx_udc.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * driver/usb/gadget/imx_udc.c 2 * driver/usb/gadget/imx_udc.c
3 * 3 *
4 * Copyright (C) 2005 Mike Lee(eemike@gmail.com) 4 * Copyright (C) 2005 Mike Lee <eemike@gmail.com>
5 * Copyright (C) 2008 Darius Augulis <augulis.darius@gmail.com> 5 * Copyright (C) 2008 Darius Augulis <augulis.darius@gmail.com>
6 * 6 *
7 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
@@ -28,6 +28,7 @@
28#include <linux/dma-mapping.h> 28#include <linux/dma-mapping.h>
29#include <linux/clk.h> 29#include <linux/clk.h>
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/timer.h>
31 32
32#include <linux/usb/ch9.h> 33#include <linux/usb/ch9.h>
33#include <linux/usb/gadget.h> 34#include <linux/usb/gadget.h>
@@ -51,7 +52,8 @@ void ep0_chg_stat(const char *label, struct imx_udc_struct *imx_usb,
51void imx_udc_enable(struct imx_udc_struct *imx_usb) 52void imx_udc_enable(struct imx_udc_struct *imx_usb)
52{ 53{
53 int temp = __raw_readl(imx_usb->base + USB_CTRL); 54 int temp = __raw_readl(imx_usb->base + USB_CTRL);
54 __raw_writel(temp | CTRL_FE_ENA | CTRL_AFE_ENA, imx_usb->base + USB_CTRL); 55 __raw_writel(temp | CTRL_FE_ENA | CTRL_AFE_ENA,
56 imx_usb->base + USB_CTRL);
55 imx_usb->gadget.speed = USB_SPEED_FULL; 57 imx_usb->gadget.speed = USB_SPEED_FULL;
56} 58}
57 59
@@ -126,7 +128,8 @@ void imx_udc_config(struct imx_udc_struct *imx_usb)
126 for (j = 0; j < 5; j++) { 128 for (j = 0; j < 5; j++) {
127 __raw_writeb(ep_conf[j], 129 __raw_writeb(ep_conf[j],
128 imx_usb->base + USB_DDAT); 130 imx_usb->base + USB_DDAT);
129 do {} while (__raw_readl(imx_usb->base + USB_DADR) 131 do {} while (__raw_readl(imx_usb->base
132 + USB_DADR)
130 & DADR_BSY); 133 & DADR_BSY);
131 } 134 }
132 } 135 }
@@ -183,7 +186,8 @@ void imx_udc_init_ep(struct imx_udc_struct *imx_usb)
183 temp = (EP_DIR(imx_ep) << 7) | (max << 5) 186 temp = (EP_DIR(imx_ep) << 7) | (max << 5)
184 | (imx_ep->bmAttributes << 3); 187 | (imx_ep->bmAttributes << 3);
185 __raw_writel(temp, imx_usb->base + USB_EP_STAT(i)); 188 __raw_writel(temp, imx_usb->base + USB_EP_STAT(i));
186 __raw_writel(temp | EPSTAT_FLUSH, imx_usb->base + USB_EP_STAT(i)); 189 __raw_writel(temp | EPSTAT_FLUSH,
190 imx_usb->base + USB_EP_STAT(i));
187 D_INI(imx_usb->dev, "<%s> ep%d_stat %08x\n", __func__, i, 191 D_INI(imx_usb->dev, "<%s> ep%d_stat %08x\n", __func__, i,
188 __raw_readl(imx_usb->base + USB_EP_STAT(i))); 192 __raw_readl(imx_usb->base + USB_EP_STAT(i)));
189 } 193 }
@@ -278,15 +282,18 @@ void imx_ep_stall(struct imx_ep_struct *imx_ep)
278 struct imx_udc_struct *imx_usb = imx_ep->imx_usb; 282 struct imx_udc_struct *imx_usb = imx_ep->imx_usb;
279 int temp, i; 283 int temp, i;
280 284
281 D_ERR(imx_usb->dev, "<%s> Forced stall on %s\n", __func__, imx_ep->ep.name); 285 D_ERR(imx_usb->dev,
286 "<%s> Forced stall on %s\n", __func__, imx_ep->ep.name);
282 287
283 imx_flush(imx_ep); 288 imx_flush(imx_ep);
284 289
285 /* Special care for ep0 */ 290 /* Special care for ep0 */
286 if (EP_NO(imx_ep)) { 291 if (!EP_NO(imx_ep)) {
287 temp = __raw_readl(imx_usb->base + USB_CTRL); 292 temp = __raw_readl(imx_usb->base + USB_CTRL);
288 __raw_writel(temp | CTRL_CMDOVER | CTRL_CMDERROR, imx_usb->base + USB_CTRL); 293 __raw_writel(temp | CTRL_CMDOVER | CTRL_CMDERROR,
289 do { } while (__raw_readl(imx_usb->base + USB_CTRL) & CTRL_CMDOVER); 294 imx_usb->base + USB_CTRL);
295 do { } while (__raw_readl(imx_usb->base + USB_CTRL)
296 & CTRL_CMDOVER);
290 temp = __raw_readl(imx_usb->base + USB_CTRL); 297 temp = __raw_readl(imx_usb->base + USB_CTRL);
291 __raw_writel(temp & ~CTRL_CMDERROR, imx_usb->base + USB_CTRL); 298 __raw_writel(temp & ~CTRL_CMDERROR, imx_usb->base + USB_CTRL);
292 } 299 }
@@ -296,12 +303,13 @@ void imx_ep_stall(struct imx_ep_struct *imx_ep)
296 imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); 303 imx_usb->base + USB_EP_STAT(EP_NO(imx_ep)));
297 304
298 for (i = 0; i < 100; i ++) { 305 for (i = 0; i < 100; i ++) {
299 temp = __raw_readl(imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); 306 temp = __raw_readl(imx_usb->base
307 + USB_EP_STAT(EP_NO(imx_ep)));
300 if (!(temp & EPSTAT_STALL)) 308 if (!(temp & EPSTAT_STALL))
301 break; 309 break;
302 udelay(20); 310 udelay(20);
303 } 311 }
304 if (i == 50) 312 if (i == 100)
305 D_ERR(imx_usb->dev, "<%s> Non finished stall on %s\n", 313 D_ERR(imx_usb->dev, "<%s> Non finished stall on %s\n",
306 __func__, imx_ep->ep.name); 314 __func__, imx_ep->ep.name);
307 } 315 }
@@ -325,7 +333,8 @@ static int imx_udc_wakeup(struct usb_gadget *_gadget)
325 ******************************************************************************* 333 *******************************************************************************
326 */ 334 */
327 335
328static void ep_add_request(struct imx_ep_struct *imx_ep, struct imx_request *req) 336static void ep_add_request(struct imx_ep_struct *imx_ep,
337 struct imx_request *req)
329{ 338{
330 if (unlikely(!req)) 339 if (unlikely(!req))
331 return; 340 return;
@@ -334,7 +343,8 @@ static void ep_add_request(struct imx_ep_struct *imx_ep, struct imx_request *req
334 list_add_tail(&req->queue, &imx_ep->queue); 343 list_add_tail(&req->queue, &imx_ep->queue);
335} 344}
336 345
337static void ep_del_request(struct imx_ep_struct *imx_ep, struct imx_request *req) 346static void ep_del_request(struct imx_ep_struct *imx_ep,
347 struct imx_request *req)
338{ 348{
339 if (unlikely(!req)) 349 if (unlikely(!req))
340 return; 350 return;
@@ -343,7 +353,8 @@ static void ep_del_request(struct imx_ep_struct *imx_ep, struct imx_request *req
343 req->in_use = 0; 353 req->in_use = 0;
344} 354}
345 355
346static void done(struct imx_ep_struct *imx_ep, struct imx_request *req, int status) 356static void done(struct imx_ep_struct *imx_ep,
357 struct imx_request *req, int status)
347{ 358{
348 ep_del_request(imx_ep, req); 359 ep_del_request(imx_ep, req);
349 360
@@ -494,7 +505,8 @@ static int write_fifo(struct imx_ep_struct *imx_ep, struct imx_request *req)
494 __func__, imx_ep->ep.name, req, 505 __func__, imx_ep->ep.name, req,
495 completed ? "completed" : "not completed"); 506 completed ? "completed" : "not completed");
496 if (!EP_NO(imx_ep)) 507 if (!EP_NO(imx_ep))
497 ep0_chg_stat(__func__, imx_ep->imx_usb, EP0_IDLE); 508 ep0_chg_stat(__func__,
509 imx_ep->imx_usb, EP0_IDLE);
498 } 510 }
499 } 511 }
500 512
@@ -539,10 +551,9 @@ static int handle_ep0(struct imx_ep_struct *imx_ep)
539 struct imx_request *req = NULL; 551 struct imx_request *req = NULL;
540 int ret = 0; 552 int ret = 0;
541 553
542 if (!list_empty(&imx_ep->queue)) 554 if (!list_empty(&imx_ep->queue)) {
543 req = list_entry(imx_ep->queue.next, struct imx_request, queue); 555 req = list_entry(imx_ep->queue.next, struct imx_request, queue);
544 556
545 if (req) {
546 switch (imx_ep->imx_usb->ep0state) { 557 switch (imx_ep->imx_usb->ep0state) {
547 558
548 case EP0_IN_DATA_PHASE: /* GET_DESCRIPTOR */ 559 case EP0_IN_DATA_PHASE: /* GET_DESCRIPTOR */
@@ -561,6 +572,10 @@ static int handle_ep0(struct imx_ep_struct *imx_ep)
561 } 572 }
562 } 573 }
563 574
575 else
576 D_ERR(imx_ep->imx_usb->dev, "<%s> no request on %s\n",
577 __func__, imx_ep->ep.name);
578
564 return ret; 579 return ret;
565} 580}
566 581
@@ -583,7 +598,8 @@ static void handle_ep0_devreq(struct imx_udc_struct *imx_usb)
583 "<%s> no setup packet received\n", __func__); 598 "<%s> no setup packet received\n", __func__);
584 goto stall; 599 goto stall;
585 } 600 }
586 u.word[i] = __raw_readl(imx_usb->base + USB_EP_FDAT(EP_NO(imx_ep))); 601 u.word[i] = __raw_readl(imx_usb->base
602 + USB_EP_FDAT(EP_NO(imx_ep)));
587 } 603 }
588 604
589 temp = imx_ep_empty(imx_ep); 605 temp = imx_ep_empty(imx_ep);
@@ -759,7 +775,7 @@ static int imx_ep_queue
759 */ 775 */
760 if (imx_usb->set_config && !EP_NO(imx_ep)) { 776 if (imx_usb->set_config && !EP_NO(imx_ep)) {
761 imx_usb->set_config = 0; 777 imx_usb->set_config = 0;
762 D_EPX(imx_usb->dev, 778 D_ERR(imx_usb->dev,
763 "<%s> gadget reply set config\n", __func__); 779 "<%s> gadget reply set config\n", __func__);
764 return 0; 780 return 0;
765 } 781 }
@@ -779,28 +795,29 @@ static int imx_ep_queue
779 return -ESHUTDOWN; 795 return -ESHUTDOWN;
780 } 796 }
781 797
782 local_irq_save(flags);
783
784 /* Debug */ 798 /* Debug */
785 D_REQ(imx_usb->dev, "<%s> ep%d %s request for [%d] bytes\n", 799 D_REQ(imx_usb->dev, "<%s> ep%d %s request for [%d] bytes\n",
786 __func__, EP_NO(imx_ep), 800 __func__, EP_NO(imx_ep),
787 ((!EP_NO(imx_ep) && imx_ep->imx_usb->ep0state == EP0_IN_DATA_PHASE) 801 ((!EP_NO(imx_ep) && imx_ep->imx_usb->ep0state
788 || (EP_NO(imx_ep) && EP_DIR(imx_ep))) ? "IN" : "OUT", usb_req->length); 802 == EP0_IN_DATA_PHASE)
803 || (EP_NO(imx_ep) && EP_DIR(imx_ep)))
804 ? "IN" : "OUT", usb_req->length);
789 dump_req(__func__, imx_ep, usb_req); 805 dump_req(__func__, imx_ep, usb_req);
790 806
791 if (imx_ep->stopped) { 807 if (imx_ep->stopped) {
792 usb_req->status = -ESHUTDOWN; 808 usb_req->status = -ESHUTDOWN;
793 ret = -ESHUTDOWN; 809 return -ESHUTDOWN;
794 goto out;
795 } 810 }
796 811
797 if (req->in_use) { 812 if (req->in_use) {
798 D_ERR(imx_usb->dev, 813 D_ERR(imx_usb->dev,
799 "<%s> refusing to queue req %p (already queued)\n", 814 "<%s> refusing to queue req %p (already queued)\n",
800 __func__, req); 815 __func__, req);
801 goto out; 816 return 0;
802 } 817 }
803 818
819 local_irq_save(flags);
820
804 usb_req->status = -EINPROGRESS; 821 usb_req->status = -EINPROGRESS;
805 usb_req->actual = 0; 822 usb_req->actual = 0;
806 823
@@ -810,7 +827,7 @@ static int imx_ep_queue
810 ret = handle_ep0(imx_ep); 827 ret = handle_ep0(imx_ep);
811 else 828 else
812 ret = handle_ep(imx_ep); 829 ret = handle_ep(imx_ep);
813out: 830
814 local_irq_restore(flags); 831 local_irq_restore(flags);
815 return ret; 832 return ret;
816} 833}
@@ -997,71 +1014,32 @@ static void udc_stop_activity(struct imx_udc_struct *imx_usb,
997 ******************************************************************************* 1014 *******************************************************************************
998 */ 1015 */
999 1016
1000static irqreturn_t imx_udc_irq(int irq, void *dev) 1017/*
1018 * Called when timer expires.
1019 * Timer is started when CFG_CHG is received.
1020 */
1021static void handle_config(unsigned long data)
1001{ 1022{
1002 struct imx_udc_struct *imx_usb = dev; 1023 struct imx_udc_struct *imx_usb = (void *)data;
1003 struct usb_ctrlrequest u; 1024 struct usb_ctrlrequest u;
1004 int temp, cfg, intf, alt; 1025 int temp, cfg, intf, alt;
1005 int intr = __raw_readl(imx_usb->base + USB_INTR);
1006 1026
1007 if (intr & (INTR_WAKEUP | INTR_SUSPEND | INTR_RESUME | INTR_RESET_START 1027 local_irq_disable();
1008 | INTR_RESET_STOP | INTR_CFG_CHG)) {
1009 dump_intr(__func__, intr, imx_usb->dev);
1010 dump_usb_stat(__func__, imx_usb);
1011 }
1012 1028
1013 if (!imx_usb->driver) { 1029 temp = __raw_readl(imx_usb->base + USB_STAT);
1014 /*imx_udc_disable(imx_usb);*/ 1030 cfg = (temp & STAT_CFG) >> 5;
1015 goto end_irq; 1031 intf = (temp & STAT_INTF) >> 3;
1016 } 1032 alt = temp & STAT_ALTSET;
1017 1033
1018 if (intr & INTR_WAKEUP) { 1034 D_REQ(imx_usb->dev,
1019 if (imx_usb->gadget.speed == USB_SPEED_UNKNOWN 1035 "<%s> orig config C=%d, I=%d, A=%d / "
1020 && imx_usb->driver && imx_usb->driver->resume) 1036 "req config C=%d, I=%d, A=%d\n",
1021 imx_usb->driver->resume(&imx_usb->gadget); 1037 __func__, imx_usb->cfg, imx_usb->intf, imx_usb->alt,
1022 imx_usb->set_config = 0; 1038 cfg, intf, alt);
1023 imx_usb->gadget.speed = USB_SPEED_FULL;
1024 }
1025
1026 if (intr & INTR_SUSPEND) {
1027 if (imx_usb->gadget.speed != USB_SPEED_UNKNOWN
1028 && imx_usb->driver && imx_usb->driver->suspend)
1029 imx_usb->driver->suspend(&imx_usb->gadget);
1030 imx_usb->set_config = 0;
1031 imx_usb->gadget.speed = USB_SPEED_UNKNOWN;
1032 }
1033
1034 if (intr & INTR_RESET_START) {
1035 __raw_writel(intr, imx_usb->base + USB_INTR);
1036 udc_stop_activity(imx_usb, imx_usb->driver);
1037 imx_usb->set_config = 0;
1038 imx_usb->gadget.speed = USB_SPEED_UNKNOWN;
1039 }
1040 1039
1041 if (intr & INTR_RESET_STOP) 1040 if (cfg == 1 || cfg == 2) {
1042 imx_usb->gadget.speed = USB_SPEED_FULL;
1043 1041
1044 if (intr & INTR_CFG_CHG) {
1045 __raw_writel(INTR_CFG_CHG, imx_usb->base + USB_INTR);
1046 temp = __raw_readl(imx_usb->base + USB_STAT);
1047 cfg = (temp & STAT_CFG) >> 5;
1048 intf = (temp & STAT_INTF) >> 3;
1049 alt = temp & STAT_ALTSET;
1050
1051 D_REQ(imx_usb->dev,
1052 "<%s> orig config C=%d, I=%d, A=%d / "
1053 "req config C=%d, I=%d, A=%d\n",
1054 __func__, imx_usb->cfg, imx_usb->intf, imx_usb->alt,
1055 cfg, intf, alt);
1056
1057 if (cfg != 1 && cfg != 2)
1058 goto end_irq;
1059
1060 imx_usb->set_config = 0;
1061
1062 /* Config setup */
1063 if (imx_usb->cfg != cfg) { 1042 if (imx_usb->cfg != cfg) {
1064 D_REQ(imx_usb->dev, "<%s> Change config start\n",__func__);
1065 u.bRequest = USB_REQ_SET_CONFIGURATION; 1043 u.bRequest = USB_REQ_SET_CONFIGURATION;
1066 u.bRequestType = USB_DIR_OUT | 1044 u.bRequestType = USB_DIR_OUT |
1067 USB_TYPE_STANDARD | 1045 USB_TYPE_STANDARD |
@@ -1070,14 +1048,10 @@ static irqreturn_t imx_udc_irq(int irq, void *dev)
1070 u.wIndex = 0; 1048 u.wIndex = 0;
1071 u.wLength = 0; 1049 u.wLength = 0;
1072 imx_usb->cfg = cfg; 1050 imx_usb->cfg = cfg;
1073 imx_usb->set_config = 1;
1074 imx_usb->driver->setup(&imx_usb->gadget, &u); 1051 imx_usb->driver->setup(&imx_usb->gadget, &u);
1075 imx_usb->set_config = 0;
1076 D_REQ(imx_usb->dev, "<%s> Change config done\n",__func__);
1077 1052
1078 } 1053 }
1079 if (imx_usb->intf != intf || imx_usb->alt != alt) { 1054 if (imx_usb->intf != intf || imx_usb->alt != alt) {
1080 D_REQ(imx_usb->dev, "<%s> Change interface start\n",__func__);
1081 u.bRequest = USB_REQ_SET_INTERFACE; 1055 u.bRequest = USB_REQ_SET_INTERFACE;
1082 u.bRequestType = USB_DIR_OUT | 1056 u.bRequestType = USB_DIR_OUT |
1083 USB_TYPE_STANDARD | 1057 USB_TYPE_STANDARD |
@@ -1087,20 +1061,92 @@ static irqreturn_t imx_udc_irq(int irq, void *dev)
1087 u.wLength = 0; 1061 u.wLength = 0;
1088 imx_usb->intf = intf; 1062 imx_usb->intf = intf;
1089 imx_usb->alt = alt; 1063 imx_usb->alt = alt;
1090 imx_usb->set_config = 1;
1091 imx_usb->driver->setup(&imx_usb->gadget, &u); 1064 imx_usb->driver->setup(&imx_usb->gadget, &u);
1092 imx_usb->set_config = 0;
1093 D_REQ(imx_usb->dev, "<%s> Change interface done\n",__func__);
1094 } 1065 }
1095 } 1066 }
1096 1067
1068 imx_usb->set_config = 0;
1069
1070 local_irq_enable();
1071}
1072
1073static irqreturn_t imx_udc_irq(int irq, void *dev)
1074{
1075 struct imx_udc_struct *imx_usb = dev;
1076 int intr = __raw_readl(imx_usb->base + USB_INTR);
1077 int temp;
1078
1079 if (intr & (INTR_WAKEUP | INTR_SUSPEND | INTR_RESUME | INTR_RESET_START
1080 | INTR_RESET_STOP | INTR_CFG_CHG)) {
1081 dump_intr(__func__, intr, imx_usb->dev);
1082 dump_usb_stat(__func__, imx_usb);
1083 }
1084
1085 if (!imx_usb->driver)
1086 goto end_irq;
1087
1097 if (intr & INTR_SOF) { 1088 if (intr & INTR_SOF) {
1089 /* Copy from Freescale BSP.
1090 We must enable SOF intr and set CMDOVER.
1091 Datasheet don't specifiy this action, but it
1092 is done in Freescale BSP, so just copy it.
1093 */
1098 if (imx_usb->ep0state == EP0_IDLE) { 1094 if (imx_usb->ep0state == EP0_IDLE) {
1099 temp = __raw_readl(imx_usb->base + USB_CTRL); 1095 temp = __raw_readl(imx_usb->base + USB_CTRL);
1100 __raw_writel(temp | CTRL_CMDOVER, imx_usb->base + USB_CTRL); 1096 __raw_writel(temp | CTRL_CMDOVER,
1097 imx_usb->base + USB_CTRL);
1101 } 1098 }
1102 } 1099 }
1103 1100
1101 if (intr & INTR_CFG_CHG) {
1102 /* A workaround of serious IMX UDC bug.
1103 Handling of CFG_CHG should be delayed for some time, because
1104 IMX does not NACK the host when CFG_CHG interrupt is pending.
1105 There is no time to handle current CFG_CHG
1106 if next CFG_CHG or SETUP packed is send immediately.
1107 We have to clear CFG_CHG, start the timer and
1108 NACK the host by setting CTRL_CMDOVER
1109 if it sends any SETUP packet.
1110 When timer expires, handler is called to handle configuration
1111 changes. While CFG_CHG is not handled (set_config=1),
1112 we must NACK the host to every SETUP packed.
1113 This delay prevents from going out of sync with host.
1114 */
1115 __raw_writel(INTR_CFG_CHG, imx_usb->base + USB_INTR);
1116 imx_usb->set_config = 1;
1117 mod_timer(&imx_usb->timer, jiffies + 5);
1118 goto end_irq;
1119 }
1120
1121 if (intr & INTR_WAKEUP) {
1122 if (imx_usb->gadget.speed == USB_SPEED_UNKNOWN
1123 && imx_usb->driver && imx_usb->driver->resume)
1124 imx_usb->driver->resume(&imx_usb->gadget);
1125 imx_usb->set_config = 0;
1126 del_timer(&imx_usb->timer);
1127 imx_usb->gadget.speed = USB_SPEED_FULL;
1128 }
1129
1130 if (intr & INTR_SUSPEND) {
1131 if (imx_usb->gadget.speed != USB_SPEED_UNKNOWN
1132 && imx_usb->driver && imx_usb->driver->suspend)
1133 imx_usb->driver->suspend(&imx_usb->gadget);
1134 imx_usb->set_config = 0;
1135 del_timer(&imx_usb->timer);
1136 imx_usb->gadget.speed = USB_SPEED_UNKNOWN;
1137 }
1138
1139 if (intr & INTR_RESET_START) {
1140 __raw_writel(intr, imx_usb->base + USB_INTR);
1141 udc_stop_activity(imx_usb, imx_usb->driver);
1142 imx_usb->set_config = 0;
1143 del_timer(&imx_usb->timer);
1144 imx_usb->gadget.speed = USB_SPEED_UNKNOWN;
1145 }
1146
1147 if (intr & INTR_RESET_STOP)
1148 imx_usb->gadget.speed = USB_SPEED_FULL;
1149
1104end_irq: 1150end_irq:
1105 __raw_writel(intr, imx_usb->base + USB_INTR); 1151 __raw_writel(intr, imx_usb->base + USB_INTR);
1106 return IRQ_HANDLED; 1152 return IRQ_HANDLED;
@@ -1109,6 +1155,7 @@ end_irq:
1109static irqreturn_t imx_udc_ctrl_irq(int irq, void *dev) 1155static irqreturn_t imx_udc_ctrl_irq(int irq, void *dev)
1110{ 1156{
1111 struct imx_udc_struct *imx_usb = dev; 1157 struct imx_udc_struct *imx_usb = dev;
1158 struct imx_ep_struct *imx_ep = &imx_usb->imx_ep[0];
1112 int intr = __raw_readl(imx_usb->base + USB_EP_INTR(0)); 1159 int intr = __raw_readl(imx_usb->base + USB_EP_INTR(0));
1113 1160
1114 dump_ep_intr(__func__, 0, intr, imx_usb->dev); 1161 dump_ep_intr(__func__, 0, intr, imx_usb->dev);
@@ -1118,16 +1165,15 @@ static irqreturn_t imx_udc_ctrl_irq(int irq, void *dev)
1118 return IRQ_HANDLED; 1165 return IRQ_HANDLED;
1119 } 1166 }
1120 1167
1121 /* DEVREQ IRQ has highest priority */ 1168 /* DEVREQ has highest priority */
1122 if (intr & (EPINTR_DEVREQ | EPINTR_MDEVREQ)) 1169 if (intr & (EPINTR_DEVREQ | EPINTR_MDEVREQ))
1123 handle_ep0_devreq(imx_usb); 1170 handle_ep0_devreq(imx_usb);
1124 /* Seem i.MX is missing EOF interrupt sometimes. 1171 /* Seem i.MX is missing EOF interrupt sometimes.
1125 * Therefore we monitor both EOF and FIFO_EMPTY interrups 1172 * Therefore we don't monitor EOF.
1126 * when transmiting, and both EOF and FIFO_FULL when 1173 * We call handle_ep0() only if a request is queued for ep0.
1127 * receiving data.
1128 */ 1174 */
1129 else if (intr & (EPINTR_EOF | EPINTR_FIFO_EMPTY | EPINTR_FIFO_FULL)) 1175 else if (!list_empty(&imx_ep->queue))
1130 handle_ep0(&imx_usb->imx_ep[0]); 1176 handle_ep0(imx_ep);
1131 1177
1132 __raw_writel(intr, imx_usb->base + USB_EP_INTR(0)); 1178 __raw_writel(intr, imx_usb->base + USB_EP_INTR(0));
1133 1179
@@ -1186,8 +1232,8 @@ static struct imx_udc_struct controller = {
1186 .ep0 = &controller.imx_ep[0].ep, 1232 .ep0 = &controller.imx_ep[0].ep,
1187 .name = driver_name, 1233 .name = driver_name,
1188 .dev = { 1234 .dev = {
1189 .bus_id = "gadget", 1235 .init_name = "gadget",
1190 }, 1236 },
1191 }, 1237 },
1192 1238
1193 .imx_ep[0] = { 1239 .imx_ep[0] = {
@@ -1318,6 +1364,7 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1318 1364
1319 udc_stop_activity(imx_usb, driver); 1365 udc_stop_activity(imx_usb, driver);
1320 imx_udc_disable(imx_usb); 1366 imx_udc_disable(imx_usb);
1367 del_timer(&imx_usb->timer);
1321 1368
1322 driver->unbind(&imx_usb->gadget); 1369 driver->unbind(&imx_usb->gadget);
1323 imx_usb->gadget.dev.driver = NULL; 1370 imx_usb->gadget.dev.driver = NULL;
@@ -1435,6 +1482,10 @@ static int __init imx_udc_probe(struct platform_device *pdev)
1435 usb_init_data(imx_usb); 1482 usb_init_data(imx_usb);
1436 imx_udc_init(imx_usb); 1483 imx_udc_init(imx_usb);
1437 1484
1485 init_timer(&imx_usb->timer);
1486 imx_usb->timer.function = handle_config;
1487 imx_usb->timer.data = (unsigned long)imx_usb;
1488
1438 return 0; 1489 return 0;
1439 1490
1440fail3: 1491fail3:
@@ -1457,6 +1508,7 @@ static int __exit imx_udc_remove(struct platform_device *pdev)
1457 int i; 1508 int i;
1458 1509
1459 imx_udc_disable(imx_usb); 1510 imx_udc_disable(imx_usb);
1511 del_timer(&imx_usb->timer);
1460 1512
1461 for (i = 0; i < IMX_USB_NB_EP + 1; i++) 1513 for (i = 0; i < IMX_USB_NB_EP + 1; i++)
1462 free_irq(imx_usb->usbd_int[i], imx_usb); 1514 free_irq(imx_usb->usbd_int[i], imx_usb);
diff --git a/drivers/usb/gadget/imx_udc.h b/drivers/usb/gadget/imx_udc.h
index 850076937d8d..b48ad59603d1 100644
--- a/drivers/usb/gadget/imx_udc.h
+++ b/drivers/usb/gadget/imx_udc.h
@@ -23,7 +23,8 @@
23/* Helper macros */ 23/* Helper macros */
24#define EP_NO(ep) ((ep->bEndpointAddress) & ~USB_DIR_IN) /* IN:1, OUT:0 */ 24#define EP_NO(ep) ((ep->bEndpointAddress) & ~USB_DIR_IN) /* IN:1, OUT:0 */
25#define EP_DIR(ep) ((ep->bEndpointAddress) & USB_DIR_IN ? 1 : 0) 25#define EP_DIR(ep) ((ep->bEndpointAddress) & USB_DIR_IN ? 1 : 0)
26#define irq_to_ep(irq) (((irq) >= USBD_INT0) || ((irq) <= USBD_INT6) ? ((irq) - USBD_INT0) : (USBD_INT6)) /*should not happen*/ 26#define irq_to_ep(irq) (((irq) >= USBD_INT0) || ((irq) <= USBD_INT6) \
27 ? ((irq) - USBD_INT0) : (USBD_INT6)) /*should not happen*/
27#define ep_to_irq(ep) (EP_NO((ep)) + USBD_INT0) 28#define ep_to_irq(ep) (EP_NO((ep)) + USBD_INT0)
28#define IMX_USB_NB_EP 6 29#define IMX_USB_NB_EP 6
29 30
@@ -58,6 +59,7 @@ struct imx_udc_struct {
58 struct device *dev; 59 struct device *dev;
59 struct imx_ep_struct imx_ep[IMX_USB_NB_EP]; 60 struct imx_ep_struct imx_ep[IMX_USB_NB_EP];
60 struct clk *clk; 61 struct clk *clk;
62 struct timer_list timer;
61 enum ep0_state ep0state; 63 enum ep0_state ep0state;
62 struct resource *res; 64 struct resource *res;
63 void __iomem *base; 65 void __iomem *base;
@@ -88,8 +90,8 @@ struct imx_udc_struct {
88#define USB_EP_FDAT3(x) (0x3F + (x*0x30)) /* USB FIFO data */ 90#define USB_EP_FDAT3(x) (0x3F + (x*0x30)) /* USB FIFO data */
89#define USB_EP_FSTAT(x) (0x40 + (x*0x30)) /* USB FIFO status */ 91#define USB_EP_FSTAT(x) (0x40 + (x*0x30)) /* USB FIFO status */
90#define USB_EP_FCTRL(x) (0x44 + (x*0x30)) /* USB FIFO control */ 92#define USB_EP_FCTRL(x) (0x44 + (x*0x30)) /* USB FIFO control */
91#define USB_EP_LRFP(x) (0x48 + (x*0x30)) /* USB last read frame pointer */ 93#define USB_EP_LRFP(x) (0x48 + (x*0x30)) /* USB last rd f. pointer */
92#define USB_EP_LWFP(x) (0x4C + (x*0x30)) /* USB last write frame pointer */ 94#define USB_EP_LWFP(x) (0x4C + (x*0x30)) /* USB last wr f. pointer */
93#define USB_EP_FALRM(x) (0x50 + (x*0x30)) /* USB FIFO alarm */ 95#define USB_EP_FALRM(x) (0x50 + (x*0x30)) /* USB FIFO alarm */
94#define USB_EP_FRDP(x) (0x54 + (x*0x30)) /* USB FIFO read pointer */ 96#define USB_EP_FRDP(x) (0x54 + (x*0x30)) /* USB FIFO read pointer */
95#define USB_EP_FWRP(x) (0x58 + (x*0x30)) /* USB FIFO write pointer */ 97#define USB_EP_FWRP(x) (0x58 + (x*0x30)) /* USB FIFO write pointer */
@@ -170,7 +172,7 @@ struct imx_udc_struct {
170/* #define DEBUG_IRQ */ 172/* #define DEBUG_IRQ */
171/* #define DEBUG_EPIRQ */ 173/* #define DEBUG_EPIRQ */
172/* #define DEBUG_DUMP */ 174/* #define DEBUG_DUMP */
173#define DEBUG_ERR 175/* #define DEBUG_ERR */
174 176
175#ifdef DEBUG_REQ 177#ifdef DEBUG_REQ
176 #define D_REQ(dev, args...) dev_dbg(dev, ## args) 178 #define D_REQ(dev, args...) dev_dbg(dev, ## args)
@@ -228,7 +230,8 @@ struct imx_udc_struct {
228#endif /* DEBUG_IRQ */ 230#endif /* DEBUG_IRQ */
229 231
230#ifdef DEBUG_EPIRQ 232#ifdef DEBUG_EPIRQ
231 static void dump_ep_intr(const char *label, int nr, int irqreg, struct device *dev) 233 static void dump_ep_intr(const char *label, int nr, int irqreg,
234 struct device *dev)
232 { 235 {
233 dev_dbg(dev, "<%s> EP%d_INTR=[%s%s%s%s%s%s%s%s%s]\n", label, nr, 236 dev_dbg(dev, "<%s> EP%d_INTR=[%s%s%s%s%s%s%s%s%s]\n", label, nr,
234 (irqreg & EPINTR_FIFO_FULL) ? " full" : "", 237 (irqreg & EPINTR_FIFO_FULL) ? " full" : "",
@@ -246,7 +249,8 @@ struct imx_udc_struct {
246#endif /* DEBUG_IRQ */ 249#endif /* DEBUG_IRQ */
247 250
248#ifdef DEBUG_DUMP 251#ifdef DEBUG_DUMP
249 static void dump_usb_stat(const char *label, struct imx_udc_struct *imx_usb) 252 static void dump_usb_stat(const char *label,
253 struct imx_udc_struct *imx_usb)
250 { 254 {
251 int temp = __raw_readl(imx_usb->base + USB_STAT); 255 int temp = __raw_readl(imx_usb->base + USB_STAT);
252 256
@@ -259,12 +263,15 @@ struct imx_udc_struct {
259 (temp & STAT_ALTSET)); 263 (temp & STAT_ALTSET));
260 } 264 }
261 265
262 static void dump_ep_stat(const char *label, struct imx_ep_struct *imx_ep) 266 static void dump_ep_stat(const char *label,
267 struct imx_ep_struct *imx_ep)
263 { 268 {
264 int temp = __raw_readl(imx_ep->imx_usb->base + USB_EP_INTR(EP_NO(imx_ep))); 269 int temp = __raw_readl(imx_ep->imx_usb->base
270 + USB_EP_INTR(EP_NO(imx_ep)));
265 271
266 dev_dbg(imx_ep->imx_usb->dev, 272 dev_dbg(imx_ep->imx_usb->dev,
267 "<%s> EP%d_INTR=[%s%s%s%s%s%s%s%s%s]\n", label, EP_NO(imx_ep), 273 "<%s> EP%d_INTR=[%s%s%s%s%s%s%s%s%s]\n",
274 label, EP_NO(imx_ep),
268 (temp & EPINTR_FIFO_FULL) ? " full" : "", 275 (temp & EPINTR_FIFO_FULL) ? " full" : "",
269 (temp & EPINTR_FIFO_EMPTY) ? " fempty" : "", 276 (temp & EPINTR_FIFO_EMPTY) ? " fempty" : "",
270 (temp & EPINTR_FIFO_ERROR) ? " ferr" : "", 277 (temp & EPINTR_FIFO_ERROR) ? " ferr" : "",
@@ -275,18 +282,22 @@ struct imx_udc_struct {
275 (temp & EPINTR_DEVREQ) ? " devreq" : "", 282 (temp & EPINTR_DEVREQ) ? " devreq" : "",
276 (temp & EPINTR_EOT) ? " eot" : ""); 283 (temp & EPINTR_EOT) ? " eot" : "");
277 284
278 temp = __raw_readl(imx_ep->imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); 285 temp = __raw_readl(imx_ep->imx_usb->base
286 + USB_EP_STAT(EP_NO(imx_ep)));
279 287
280 dev_dbg(imx_ep->imx_usb->dev, 288 dev_dbg(imx_ep->imx_usb->dev,
281 "<%s> EP%d_STAT=[%s%s bcount=%d]\n", label, EP_NO(imx_ep), 289 "<%s> EP%d_STAT=[%s%s bcount=%d]\n",
290 label, EP_NO(imx_ep),
282 (temp & EPSTAT_SIP) ? " sip" : "", 291 (temp & EPSTAT_SIP) ? " sip" : "",
283 (temp & EPSTAT_STALL) ? " stall" : "", 292 (temp & EPSTAT_STALL) ? " stall" : "",
284 (temp & EPSTAT_BCOUNT) >> 16); 293 (temp & EPSTAT_BCOUNT) >> 16);
285 294
286 temp = __raw_readl(imx_ep->imx_usb->base + USB_EP_FSTAT(EP_NO(imx_ep))); 295 temp = __raw_readl(imx_ep->imx_usb->base
296 + USB_EP_FSTAT(EP_NO(imx_ep)));
287 297
288 dev_dbg(imx_ep->imx_usb->dev, 298 dev_dbg(imx_ep->imx_usb->dev,
289 "<%s> EP%d_FSTAT=[%s%s%s%s%s%s%s]\n", label, EP_NO(imx_ep), 299 "<%s> EP%d_FSTAT=[%s%s%s%s%s%s%s]\n",
300 label, EP_NO(imx_ep),
290 (temp & FSTAT_ERR) ? " ferr" : "", 301 (temp & FSTAT_ERR) ? " ferr" : "",
291 (temp & FSTAT_UF) ? " funder" : "", 302 (temp & FSTAT_UF) ? " funder" : "",
292 (temp & FSTAT_OF) ? " fover" : "", 303 (temp & FSTAT_OF) ? " fover" : "",
@@ -296,19 +307,23 @@ struct imx_udc_struct {
296 (temp & FSTAT_EMPTY) ? " fempty" : ""); 307 (temp & FSTAT_EMPTY) ? " fempty" : "");
297 } 308 }
298 309
299 static void dump_req(const char *label, struct imx_ep_struct *imx_ep, struct usb_request *req) 310 static void dump_req(const char *label, struct imx_ep_struct *imx_ep,
311 struct usb_request *req)
300 { 312 {
301 int i; 313 int i;
302 314
303 if (!req || !req->buf) { 315 if (!req || !req->buf) {
304 dev_dbg(imx_ep->imx_usb->dev, "<%s> req or req buf is free\n", label); 316 dev_dbg(imx_ep->imx_usb->dev,
317 "<%s> req or req buf is free\n", label);
305 return; 318 return;
306 } 319 }
307 320
308 if ((!EP_NO(imx_ep) && imx_ep->imx_usb->ep0state == EP0_IN_DATA_PHASE) 321 if ((!EP_NO(imx_ep) && imx_ep->imx_usb->ep0state
322 == EP0_IN_DATA_PHASE)
309 || (EP_NO(imx_ep) && EP_DIR(imx_ep))) { 323 || (EP_NO(imx_ep) && EP_DIR(imx_ep))) {
310 324
311 dev_dbg(imx_ep->imx_usb->dev, "<%s> request dump <", label); 325 dev_dbg(imx_ep->imx_usb->dev,
326 "<%s> request dump <", label);
312 for (i = 0; i < req->length; i++) 327 for (i = 0; i < req->length; i++)
313 printk("%02x-", *((u8 *)req->buf + i)); 328 printk("%02x-", *((u8 *)req->buf + i));
314 printk(">\n"); 329 printk(">\n");
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 317b48fdbf01..d20937f28a19 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -1334,7 +1334,7 @@ static void make_qualifier (struct dev_data *dev)
1334 1334
1335 qual.bLength = sizeof qual; 1335 qual.bLength = sizeof qual;
1336 qual.bDescriptorType = USB_DT_DEVICE_QUALIFIER; 1336 qual.bDescriptorType = USB_DT_DEVICE_QUALIFIER;
1337 qual.bcdUSB = __constant_cpu_to_le16 (0x0200); 1337 qual.bcdUSB = cpu_to_le16 (0x0200);
1338 1338
1339 desc = dev->dev; 1339 desc = dev->dev;
1340 qual.bDeviceClass = desc->bDeviceClass; 1340 qual.bDeviceClass = desc->bDeviceClass;
@@ -1908,7 +1908,7 @@ dev_config (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
1908 || dev->dev->bNumConfigurations != 1) 1908 || dev->dev->bNumConfigurations != 1)
1909 goto fail; 1909 goto fail;
1910 dev->dev->bNumConfigurations = 1; 1910 dev->dev->bNumConfigurations = 1;
1911 dev->dev->bcdUSB = __constant_cpu_to_le16 (0x0200); 1911 dev->dev->bcdUSB = cpu_to_le16 (0x0200);
1912 1912
1913 /* triggers gadgetfs_bind(); then we can enumerate. */ 1913 /* triggers gadgetfs_bind(); then we can enumerate. */
1914 spin_unlock_irq (&dev->lock); 1914 spin_unlock_irq (&dev->lock);
diff --git a/drivers/usb/gadget/lh7a40x_udc.c b/drivers/usb/gadget/lh7a40x_udc.c
index d554b0895603..6cd3d54f5640 100644
--- a/drivers/usb/gadget/lh7a40x_udc.c
+++ b/drivers/usb/gadget/lh7a40x_udc.c
@@ -432,8 +432,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
432 device_add(&dev->gadget.dev); 432 device_add(&dev->gadget.dev);
433 retval = driver->bind(&dev->gadget); 433 retval = driver->bind(&dev->gadget);
434 if (retval) { 434 if (retval) {
435 printk("%s: bind to driver %s --> error %d\n", dev->gadget.name, 435 printk(KERN_WARNING "%s: bind to driver %s --> error %d\n",
436 driver->driver.name, retval); 436 dev->gadget.name, driver->driver.name, retval);
437 device_del(&dev->gadget.dev); 437 device_del(&dev->gadget.dev);
438 438
439 dev->driver = 0; 439 dev->driver = 0;
@@ -445,8 +445,8 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
445 * for set_configuration as well as eventual disconnect. 445 * for set_configuration as well as eventual disconnect.
446 * NOTE: this shouldn't power up until later. 446 * NOTE: this shouldn't power up until later.
447 */ 447 */
448 printk("%s: registered gadget driver '%s'\n", dev->gadget.name, 448 printk(KERN_WARNING "%s: registered gadget driver '%s'\n",
449 driver->driver.name); 449 dev->gadget.name, driver->driver.name);
450 450
451 udc_enable(dev); 451 udc_enable(dev);
452 452
@@ -581,7 +581,8 @@ static int read_fifo(struct lh7a40x_ep *ep, struct lh7a40x_request *req)
581 * discard the extra data. 581 * discard the extra data.
582 */ 582 */
583 if (req->req.status != -EOVERFLOW) 583 if (req->req.status != -EOVERFLOW)
584 printk("%s overflow %d\n", ep->ep.name, count); 584 printk(KERN_WARNING "%s overflow %d\n",
585 ep->ep.name, count);
585 req->req.status = -EOVERFLOW; 586 req->req.status = -EOVERFLOW;
586 } else { 587 } else {
587 *buf++ = byte; 588 *buf++ = byte;
@@ -831,7 +832,8 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
831 queue); 832 queue);
832 833
833 if (!req) { 834 if (!req) {
834 printk("%s: NULL REQ %d\n", 835 printk(KERN_WARNING
836 "%s: NULL REQ %d\n",
835 __func__, ep_idx); 837 __func__, ep_idx);
836 flush(ep); 838 flush(ep);
837 break; 839 break;
@@ -844,7 +846,7 @@ static void lh7a40x_out_epn(struct lh7a40x_udc *dev, u32 ep_idx, u32 intr)
844 846
845 } else { 847 } else {
846 /* Throw packet away.. */ 848 /* Throw packet away.. */
847 printk("%s: No descriptor?!?\n", __func__); 849 printk(KERN_WARNING "%s: No descriptor?!?\n", __func__);
848 flush(ep); 850 flush(ep);
849 } 851 }
850} 852}
diff --git a/drivers/usb/gadget/net2280.c b/drivers/usb/gadget/net2280.c
index 12c6d83b218c..9498be87a724 100644
--- a/drivers/usb/gadget/net2280.c
+++ b/drivers/usb/gadget/net2280.c
@@ -142,8 +142,8 @@ static char *type_string (u8 bmAttributes)
142 142
143#include "net2280.h" 143#include "net2280.h"
144 144
145#define valid_bit __constant_cpu_to_le32 (1 << VALID_BIT) 145#define valid_bit cpu_to_le32 (1 << VALID_BIT)
146#define dma_done_ie __constant_cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE) 146#define dma_done_ie cpu_to_le32 (1 << DMA_DONE_INTERRUPT_ENABLE)
147 147
148/*-------------------------------------------------------------------------*/ 148/*-------------------------------------------------------------------------*/
149 149
@@ -425,7 +425,7 @@ net2280_alloc_request (struct usb_ep *_ep, gfp_t gfp_flags)
425 return NULL; 425 return NULL;
426 } 426 }
427 td->dmacount = 0; /* not VALID */ 427 td->dmacount = 0; /* not VALID */
428 td->dmaaddr = __constant_cpu_to_le32 (DMA_ADDR_INVALID); 428 td->dmaaddr = cpu_to_le32 (DMA_ADDR_INVALID);
429 td->dmadesc = td->dmaaddr; 429 td->dmadesc = td->dmaaddr;
430 req->td = td; 430 req->td = td;
431 } 431 }
@@ -775,7 +775,7 @@ static void start_dma (struct net2280_ep *ep, struct net2280_request *req)
775 fill_dma_desc (ep, req, 1); 775 fill_dma_desc (ep, req, 1);
776 776
777 if (!use_dma_chaining) 777 if (!use_dma_chaining)
778 req->td->dmacount |= __constant_cpu_to_le32 (1 << END_OF_CHAIN); 778 req->td->dmacount |= cpu_to_le32 (1 << END_OF_CHAIN);
779 779
780 start_queue (ep, tmp, req->td_dma); 780 start_queue (ep, tmp, req->td_dma);
781} 781}
@@ -2407,9 +2407,9 @@ static void handle_stat0_irqs (struct net2280 *dev, u32 stat)
2407 2407
2408 if (readl (&e->regs->ep_rsp) 2408 if (readl (&e->regs->ep_rsp)
2409 & (1 << SET_ENDPOINT_HALT)) 2409 & (1 << SET_ENDPOINT_HALT))
2410 status = __constant_cpu_to_le32 (1); 2410 status = cpu_to_le32 (1);
2411 else 2411 else
2412 status = __constant_cpu_to_le32 (0); 2412 status = cpu_to_le32 (0);
2413 2413
2414 /* don't bother with a request object! */ 2414 /* don't bother with a request object! */
2415 writel (0, &dev->epregs [0].ep_irqenb); 2415 writel (0, &dev->epregs [0].ep_irqenb);
@@ -2667,7 +2667,7 @@ static void handle_stat1_irqs (struct net2280 *dev, u32 stat)
2667 req = list_entry (ep->queue.next, 2667 req = list_entry (ep->queue.next,
2668 struct net2280_request, queue); 2668 struct net2280_request, queue);
2669 dmacount = req->td->dmacount; 2669 dmacount = req->td->dmacount;
2670 dmacount &= __constant_cpu_to_le32 ( 2670 dmacount &= cpu_to_le32 (
2671 (1 << VALID_BIT) 2671 (1 << VALID_BIT)
2672 | DMA_BYTE_COUNT_MASK); 2672 | DMA_BYTE_COUNT_MASK);
2673 if (dmacount && (dmacount & valid_bit) == 0) 2673 if (dmacount && (dmacount & valid_bit) == 0)
@@ -2881,7 +2881,7 @@ static int net2280_probe (struct pci_dev *pdev, const struct pci_device_id *id)
2881 goto done; 2881 goto done;
2882 } 2882 }
2883 td->dmacount = 0; /* not VALID */ 2883 td->dmacount = 0; /* not VALID */
2884 td->dmaaddr = __constant_cpu_to_le32 (DMA_ADDR_INVALID); 2884 td->dmaaddr = cpu_to_le32 (DMA_ADDR_INVALID);
2885 td->dmadesc = td->dmaaddr; 2885 td->dmadesc = td->dmaaddr;
2886 dev->ep [i].dummy = td; 2886 dev->ep [i].dummy = td;
2887 } 2887 }
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index 5a3034fdfe47..29500154d00c 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -225,12 +225,12 @@ module_param(qlen, uint, S_IRUGO|S_IWUSR);
225static struct usb_device_descriptor device_desc = { 225static struct usb_device_descriptor device_desc = {
226 .bLength = sizeof device_desc, 226 .bLength = sizeof device_desc,
227 .bDescriptorType = USB_DT_DEVICE, 227 .bDescriptorType = USB_DT_DEVICE,
228 .bcdUSB = __constant_cpu_to_le16(0x0200), 228 .bcdUSB = cpu_to_le16(0x0200),
229 .bDeviceClass = USB_CLASS_PER_INTERFACE, 229 .bDeviceClass = USB_CLASS_PER_INTERFACE,
230 .bDeviceSubClass = 0, 230 .bDeviceSubClass = 0,
231 .bDeviceProtocol = 0, 231 .bDeviceProtocol = 0,
232 .idVendor = __constant_cpu_to_le16(PRINTER_VENDOR_NUM), 232 .idVendor = cpu_to_le16(PRINTER_VENDOR_NUM),
233 .idProduct = __constant_cpu_to_le16(PRINTER_PRODUCT_NUM), 233 .idProduct = cpu_to_le16(PRINTER_PRODUCT_NUM),
234 .iManufacturer = STRING_MANUFACTURER, 234 .iManufacturer = STRING_MANUFACTURER,
235 .iProduct = STRING_PRODUCT, 235 .iProduct = STRING_PRODUCT,
236 .iSerialNumber = STRING_SERIALNUM, 236 .iSerialNumber = STRING_SERIALNUM,
@@ -299,20 +299,20 @@ static struct usb_endpoint_descriptor hs_ep_in_desc = {
299 .bLength = USB_DT_ENDPOINT_SIZE, 299 .bLength = USB_DT_ENDPOINT_SIZE,
300 .bDescriptorType = USB_DT_ENDPOINT, 300 .bDescriptorType = USB_DT_ENDPOINT,
301 .bmAttributes = USB_ENDPOINT_XFER_BULK, 301 .bmAttributes = USB_ENDPOINT_XFER_BULK,
302 .wMaxPacketSize = __constant_cpu_to_le16(512) 302 .wMaxPacketSize = cpu_to_le16(512)
303}; 303};
304 304
305static struct usb_endpoint_descriptor hs_ep_out_desc = { 305static struct usb_endpoint_descriptor hs_ep_out_desc = {
306 .bLength = USB_DT_ENDPOINT_SIZE, 306 .bLength = USB_DT_ENDPOINT_SIZE,
307 .bDescriptorType = USB_DT_ENDPOINT, 307 .bDescriptorType = USB_DT_ENDPOINT,
308 .bmAttributes = USB_ENDPOINT_XFER_BULK, 308 .bmAttributes = USB_ENDPOINT_XFER_BULK,
309 .wMaxPacketSize = __constant_cpu_to_le16(512) 309 .wMaxPacketSize = cpu_to_le16(512)
310}; 310};
311 311
312static struct usb_qualifier_descriptor dev_qualifier = { 312static struct usb_qualifier_descriptor dev_qualifier = {
313 .bLength = sizeof dev_qualifier, 313 .bLength = sizeof dev_qualifier,
314 .bDescriptorType = USB_DT_DEVICE_QUALIFIER, 314 .bDescriptorType = USB_DT_DEVICE_QUALIFIER,
315 .bcdUSB = __constant_cpu_to_le16(0x0200), 315 .bcdUSB = cpu_to_le16(0x0200),
316 .bDeviceClass = USB_CLASS_PRINTER, 316 .bDeviceClass = USB_CLASS_PRINTER,
317 .bNumConfigurations = 1 317 .bNumConfigurations = 1
318}; 318};
@@ -1406,16 +1406,16 @@ printer_bind(struct usb_gadget *gadget)
1406 gadget->name); 1406 gadget->name);
1407 /* unrecognized, but safe unless bulk is REALLY quirky */ 1407 /* unrecognized, but safe unless bulk is REALLY quirky */
1408 device_desc.bcdDevice = 1408 device_desc.bcdDevice =
1409 __constant_cpu_to_le16(0xFFFF); 1409 cpu_to_le16(0xFFFF);
1410 } 1410 }
1411 snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s", 1411 snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s",
1412 init_utsname()->sysname, init_utsname()->release, 1412 init_utsname()->sysname, init_utsname()->release,
1413 gadget->name); 1413 gadget->name);
1414 1414
1415 device_desc.idVendor = 1415 device_desc.idVendor =
1416 __constant_cpu_to_le16(PRINTER_VENDOR_NUM); 1416 cpu_to_le16(PRINTER_VENDOR_NUM);
1417 device_desc.idProduct = 1417 device_desc.idProduct =
1418 __constant_cpu_to_le16(PRINTER_PRODUCT_NUM); 1418 cpu_to_le16(PRINTER_PRODUCT_NUM);
1419 1419
1420 /* support optional vendor/distro customization */ 1420 /* support optional vendor/distro customization */
1421 if (idVendor) { 1421 if (idVendor) {
diff --git a/drivers/usb/gadget/pxa27x_udc.c b/drivers/usb/gadget/pxa27x_udc.c
index 990f40f988d4..8cc676ecbb23 100644
--- a/drivers/usb/gadget/pxa27x_udc.c
+++ b/drivers/usb/gadget/pxa27x_udc.c
@@ -30,6 +30,7 @@
30#include <linux/proc_fs.h> 30#include <linux/proc_fs.h>
31#include <linux/clk.h> 31#include <linux/clk.h>
32#include <linux/irq.h> 32#include <linux/irq.h>
33#include <linux/gpio.h>
33 34
34#include <asm/byteorder.h> 35#include <asm/byteorder.h>
35#include <mach/hardware.h> 36#include <mach/hardware.h>
@@ -278,7 +279,7 @@ static void pxa_init_debugfs(struct pxa_udc *udc)
278 goto err_queues; 279 goto err_queues;
279 eps = debugfs_create_file("epstate", 0400, root, udc, 280 eps = debugfs_create_file("epstate", 0400, root, udc,
280 &eps_dbg_fops); 281 &eps_dbg_fops);
281 if (!queues) 282 if (!eps)
282 goto err_eps; 283 goto err_eps;
283 284
284 udc->debugfs_root = root; 285 udc->debugfs_root = root;
@@ -747,13 +748,13 @@ static void req_done(struct pxa_ep *ep, struct pxa27x_request *req, int status)
747} 748}
748 749
749/** 750/**
750 * ep_end_out_req - Ends control endpoint in request 751 * ep_end_out_req - Ends endpoint OUT request
751 * @ep: physical endpoint 752 * @ep: physical endpoint
752 * @req: pxa request 753 * @req: pxa request
753 * 754 *
754 * Context: ep->lock held 755 * Context: ep->lock held
755 * 756 *
756 * Ends endpoint in request (completes usb request). 757 * Ends endpoint OUT request (completes usb request).
757 */ 758 */
758static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req) 759static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
759{ 760{
@@ -762,13 +763,13 @@ static void ep_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
762} 763}
763 764
764/** 765/**
765 * ep0_end_out_req - Ends control endpoint in request (ends data stage) 766 * ep0_end_out_req - Ends control endpoint OUT request (ends data stage)
766 * @ep: physical endpoint 767 * @ep: physical endpoint
767 * @req: pxa request 768 * @req: pxa request
768 * 769 *
769 * Context: ep->lock held 770 * Context: ep->lock held
770 * 771 *
771 * Ends control endpoint in request (completes usb request), and puts 772 * Ends control endpoint OUT request (completes usb request), and puts
772 * control endpoint into idle state 773 * control endpoint into idle state
773 */ 774 */
774static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req) 775static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
@@ -779,13 +780,13 @@ static void ep0_end_out_req(struct pxa_ep *ep, struct pxa27x_request *req)
779} 780}
780 781
781/** 782/**
782 * ep_end_in_req - Ends endpoint out request 783 * ep_end_in_req - Ends endpoint IN request
783 * @ep: physical endpoint 784 * @ep: physical endpoint
784 * @req: pxa request 785 * @req: pxa request
785 * 786 *
786 * Context: ep->lock held 787 * Context: ep->lock held
787 * 788 *
788 * Ends endpoint out request (completes usb request). 789 * Ends endpoint IN request (completes usb request).
789 */ 790 */
790static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req) 791static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req)
791{ 792{
@@ -794,20 +795,18 @@ static void ep_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req)
794} 795}
795 796
796/** 797/**
797 * ep0_end_in_req - Ends control endpoint out request (ends data stage) 798 * ep0_end_in_req - Ends control endpoint IN request (ends data stage)
798 * @ep: physical endpoint 799 * @ep: physical endpoint
799 * @req: pxa request 800 * @req: pxa request
800 * 801 *
801 * Context: ep->lock held 802 * Context: ep->lock held
802 * 803 *
803 * Ends control endpoint out request (completes usb request), and puts 804 * Ends control endpoint IN request (completes usb request), and puts
804 * control endpoint into status state 805 * control endpoint into status state
805 */ 806 */
806static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req) 807static void ep0_end_in_req(struct pxa_ep *ep, struct pxa27x_request *req)
807{ 808{
808 struct pxa_udc *udc = ep->dev; 809 set_ep0state(ep->dev, IN_STATUS_STAGE);
809
810 set_ep0state(udc, IN_STATUS_STAGE);
811 ep_end_in_req(ep, req); 810 ep_end_in_req(ep, req);
812} 811}
813 812
@@ -1167,7 +1166,7 @@ static int pxa_ep_queue(struct usb_ep *_ep, struct usb_request *_req,
1167 ep_end_in_req(ep, req); 1166 ep_end_in_req(ep, req);
1168 } else { 1167 } else {
1169 ep_err(ep, "got a request of %d bytes while" 1168 ep_err(ep, "got a request of %d bytes while"
1170 "in state WATI_ACK_SET_CONF_INTERF\n", 1169 "in state WAIT_ACK_SET_CONF_INTERF\n",
1171 length); 1170 length);
1172 ep_del_request(ep, req); 1171 ep_del_request(ep, req);
1173 rc = -EL2HLT; 1172 rc = -EL2HLT;
@@ -1213,30 +1212,26 @@ static int pxa_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
1213 struct udc_usb_ep *udc_usb_ep; 1212 struct udc_usb_ep *udc_usb_ep;
1214 struct pxa27x_request *req; 1213 struct pxa27x_request *req;
1215 unsigned long flags; 1214 unsigned long flags;
1216 int rc; 1215 int rc = -EINVAL;
1217 1216
1218 if (!_ep) 1217 if (!_ep)
1219 return -EINVAL; 1218 return rc;
1220 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep); 1219 udc_usb_ep = container_of(_ep, struct udc_usb_ep, usb_ep);
1221 ep = udc_usb_ep->pxa_ep; 1220 ep = udc_usb_ep->pxa_ep;
1222 if (!ep || is_ep0(ep)) 1221 if (!ep || is_ep0(ep))
1223 return -EINVAL; 1222 return rc;
1224 1223
1225 spin_lock_irqsave(&ep->lock, flags); 1224 spin_lock_irqsave(&ep->lock, flags);
1226 1225
1227 /* make sure it's actually queued on this endpoint */ 1226 /* make sure it's actually queued on this endpoint */
1228 list_for_each_entry(req, &ep->queue, queue) { 1227 list_for_each_entry(req, &ep->queue, queue) {
1229 if (&req->req == _req) 1228 if (&req->req == _req) {
1229 req_done(ep, req, -ECONNRESET);
1230 rc = 0;
1230 break; 1231 break;
1232 }
1231 } 1233 }
1232 1234
1233 rc = -EINVAL;
1234 if (&req->req != _req)
1235 goto out;
1236
1237 rc = 0;
1238 req_done(ep, req, -ECONNRESET);
1239out:
1240 spin_unlock_irqrestore(&ep->lock, flags); 1235 spin_unlock_irqrestore(&ep->lock, flags);
1241 return rc; 1236 return rc;
1242} 1237}
@@ -1471,6 +1466,32 @@ static struct usb_ep_ops pxa_ep_ops = {
1471 .fifo_flush = pxa_ep_fifo_flush, 1466 .fifo_flush = pxa_ep_fifo_flush,
1472}; 1467};
1473 1468
1469/**
1470 * dplus_pullup - Connect or disconnect pullup resistor to D+ pin
1471 * @udc: udc device
1472 * @on: 0 if disconnect pullup resistor, 1 otherwise
1473 * Context: any
1474 *
1475 * Handle D+ pullup resistor, make the device visible to the usb bus, and
1476 * declare it as a full speed usb device
1477 */
1478static void dplus_pullup(struct pxa_udc *udc, int on)
1479{
1480 if (on) {
1481 if (gpio_is_valid(udc->mach->gpio_pullup))
1482 gpio_set_value(udc->mach->gpio_pullup,
1483 !udc->mach->gpio_pullup_inverted);
1484 if (udc->mach->udc_command)
1485 udc->mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
1486 } else {
1487 if (gpio_is_valid(udc->mach->gpio_pullup))
1488 gpio_set_value(udc->mach->gpio_pullup,
1489 udc->mach->gpio_pullup_inverted);
1490 if (udc->mach->udc_command)
1491 udc->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT);
1492 }
1493 udc->pullup_on = on;
1494}
1474 1495
1475/** 1496/**
1476 * pxa_udc_get_frame - Returns usb frame number 1497 * pxa_udc_get_frame - Returns usb frame number
@@ -1500,21 +1521,145 @@ static int pxa_udc_wakeup(struct usb_gadget *_gadget)
1500 return 0; 1521 return 0;
1501} 1522}
1502 1523
1524static void udc_enable(struct pxa_udc *udc);
1525static void udc_disable(struct pxa_udc *udc);
1526
1527/**
1528 * should_enable_udc - Tells if UDC should be enabled
1529 * @udc: udc device
1530 * Context: any
1531 *
1532 * The UDC should be enabled if :
1533
1534 * - the pullup resistor is connected
1535 * - and a gadget driver is bound
1536 * - and vbus is sensed (or no vbus sense is available)
1537 *
1538 * Returns 1 if UDC should be enabled, 0 otherwise
1539 */
1540static int should_enable_udc(struct pxa_udc *udc)
1541{
1542 int put_on;
1543
1544 put_on = ((udc->pullup_on) && (udc->driver));
1545 put_on &= ((udc->vbus_sensed) || (!udc->transceiver));
1546 return put_on;
1547}
1548
1549/**
1550 * should_disable_udc - Tells if UDC should be disabled
1551 * @udc: udc device
1552 * Context: any
1553 *
1554 * The UDC should be disabled if :
1555 * - the pullup resistor is not connected
1556 * - or no gadget driver is bound
1557 * - or no vbus is sensed (when vbus sesing is available)
1558 *
1559 * Returns 1 if UDC should be disabled
1560 */
1561static int should_disable_udc(struct pxa_udc *udc)
1562{
1563 int put_off;
1564
1565 put_off = ((!udc->pullup_on) || (!udc->driver));
1566 put_off |= ((!udc->vbus_sensed) && (udc->transceiver));
1567 return put_off;
1568}
1569
1570/**
1571 * pxa_udc_pullup - Offer manual D+ pullup control
1572 * @_gadget: usb gadget using the control
1573 * @is_active: 0 if disconnect, else connect D+ pullup resistor
1574 * Context: !in_interrupt()
1575 *
1576 * Returns 0 if OK, -EOPNOTSUPP if udc driver doesn't handle D+ pullup
1577 */
1578static int pxa_udc_pullup(struct usb_gadget *_gadget, int is_active)
1579{
1580 struct pxa_udc *udc = to_gadget_udc(_gadget);
1581
1582 if (!gpio_is_valid(udc->mach->gpio_pullup) && !udc->mach->udc_command)
1583 return -EOPNOTSUPP;
1584
1585 dplus_pullup(udc, is_active);
1586
1587 if (should_enable_udc(udc))
1588 udc_enable(udc);
1589 if (should_disable_udc(udc))
1590 udc_disable(udc);
1591 return 0;
1592}
1593
1594static void udc_enable(struct pxa_udc *udc);
1595static void udc_disable(struct pxa_udc *udc);
1596
1597/**
1598 * pxa_udc_vbus_session - Called by external transceiver to enable/disable udc
1599 * @_gadget: usb gadget
1600 * @is_active: 0 if should disable the udc, 1 if should enable
1601 *
1602 * Enables the udc, and optionnaly activates D+ pullup resistor. Or disables the
1603 * udc, and deactivates D+ pullup resistor.
1604 *
1605 * Returns 0
1606 */
1607static int pxa_udc_vbus_session(struct usb_gadget *_gadget, int is_active)
1608{
1609 struct pxa_udc *udc = to_gadget_udc(_gadget);
1610
1611 udc->vbus_sensed = is_active;
1612 if (should_enable_udc(udc))
1613 udc_enable(udc);
1614 if (should_disable_udc(udc))
1615 udc_disable(udc);
1616
1617 return 0;
1618}
1619
1620/**
1621 * pxa_udc_vbus_draw - Called by gadget driver after SET_CONFIGURATION completed
1622 * @_gadget: usb gadget
1623 * @mA: current drawn
1624 *
1625 * Context: !in_interrupt()
1626 *
1627 * Called after a configuration was chosen by a USB host, to inform how much
1628 * current can be drawn by the device from VBus line.
1629 *
1630 * Returns 0 or -EOPNOTSUPP if no transceiver is handling the udc
1631 */
1632static int pxa_udc_vbus_draw(struct usb_gadget *_gadget, unsigned mA)
1633{
1634 struct pxa_udc *udc;
1635
1636 udc = to_gadget_udc(_gadget);
1637 if (udc->transceiver)
1638 return otg_set_power(udc->transceiver, mA);
1639 return -EOPNOTSUPP;
1640}
1641
1503static const struct usb_gadget_ops pxa_udc_ops = { 1642static const struct usb_gadget_ops pxa_udc_ops = {
1504 .get_frame = pxa_udc_get_frame, 1643 .get_frame = pxa_udc_get_frame,
1505 .wakeup = pxa_udc_wakeup, 1644 .wakeup = pxa_udc_wakeup,
1506 /* current versions must always be self-powered */ 1645 .pullup = pxa_udc_pullup,
1646 .vbus_session = pxa_udc_vbus_session,
1647 .vbus_draw = pxa_udc_vbus_draw,
1507}; 1648};
1508 1649
1509/** 1650/**
1510 * udc_disable - disable udc device controller 1651 * udc_disable - disable udc device controller
1511 * @udc: udc device 1652 * @udc: udc device
1653 * Context: any
1512 * 1654 *
1513 * Disables the udc device : disables clocks, udc interrupts, control endpoint 1655 * Disables the udc device : disables clocks, udc interrupts, control endpoint
1514 * interrupts. 1656 * interrupts.
1515 */ 1657 */
1516static void udc_disable(struct pxa_udc *udc) 1658static void udc_disable(struct pxa_udc *udc)
1517{ 1659{
1660 if (!udc->enabled)
1661 return;
1662
1518 udc_writel(udc, UDCICR0, 0); 1663 udc_writel(udc, UDCICR0, 0);
1519 udc_writel(udc, UDCICR1, 0); 1664 udc_writel(udc, UDCICR1, 0);
1520 1665
@@ -1523,8 +1668,8 @@ static void udc_disable(struct pxa_udc *udc)
1523 1668
1524 ep0_idle(udc); 1669 ep0_idle(udc);
1525 udc->gadget.speed = USB_SPEED_UNKNOWN; 1670 udc->gadget.speed = USB_SPEED_UNKNOWN;
1526 if (udc->mach->udc_command) 1671
1527 udc->mach->udc_command(PXA2XX_UDC_CMD_DISCONNECT); 1672 udc->enabled = 0;
1528} 1673}
1529 1674
1530/** 1675/**
@@ -1555,10 +1700,9 @@ static __init void udc_init_data(struct pxa_udc *dev)
1555 } 1700 }
1556 1701
1557 /* USB endpoints init */ 1702 /* USB endpoints init */
1558 for (i = 0; i < NR_USB_ENDPOINTS; i++) 1703 for (i = 1; i < NR_USB_ENDPOINTS; i++)
1559 if (i != 0) 1704 list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list,
1560 list_add_tail(&dev->udc_usb_ep[i].usb_ep.ep_list, 1705 &dev->gadget.ep_list);
1561 &dev->gadget.ep_list);
1562} 1706}
1563 1707
1564/** 1708/**
@@ -1570,6 +1714,9 @@ static __init void udc_init_data(struct pxa_udc *dev)
1570 */ 1714 */
1571static void udc_enable(struct pxa_udc *udc) 1715static void udc_enable(struct pxa_udc *udc)
1572{ 1716{
1717 if (udc->enabled)
1718 return;
1719
1573 udc_writel(udc, UDCICR0, 0); 1720 udc_writel(udc, UDCICR0, 0);
1574 udc_writel(udc, UDCICR1, 0); 1721 udc_writel(udc, UDCICR1, 0);
1575 udc_clear_mask_UDCCR(udc, UDCCR_UDE); 1722 udc_clear_mask_UDCCR(udc, UDCCR_UDE);
@@ -1598,9 +1745,7 @@ static void udc_enable(struct pxa_udc *udc)
1598 /* enable ep0 irqs */ 1745 /* enable ep0 irqs */
1599 pio_irq_enable(&udc->pxa_ep[0]); 1746 pio_irq_enable(&udc->pxa_ep[0]);
1600 1747
1601 dev_info(udc->dev, "UDC connecting\n"); 1748 udc->enabled = 1;
1602 if (udc->mach->udc_command)
1603 udc->mach->udc_command(PXA2XX_UDC_CMD_CONNECT);
1604} 1749}
1605 1750
1606/** 1751/**
@@ -1612,6 +1757,9 @@ static void udc_enable(struct pxa_udc *udc)
1612 * usb traffic follows until a disconnect is reported. Then a host may connect 1757 * usb traffic follows until a disconnect is reported. Then a host may connect
1613 * again, or the driver might get unbound. 1758 * again, or the driver might get unbound.
1614 * 1759 *
1760 * Note that the udc is not automatically enabled. Check function
1761 * should_enable_udc().
1762 *
1615 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise 1763 * Returns 0 if no error, -EINVAL, -ENODEV, -EBUSY otherwise
1616 */ 1764 */
1617int usb_gadget_register_driver(struct usb_gadget_driver *driver) 1765int usb_gadget_register_driver(struct usb_gadget_driver *driver)
@@ -1630,6 +1778,7 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1630 /* first hook up the driver ... */ 1778 /* first hook up the driver ... */
1631 udc->driver = driver; 1779 udc->driver = driver;
1632 udc->gadget.dev.driver = &driver->driver; 1780 udc->gadget.dev.driver = &driver->driver;
1781 dplus_pullup(udc, 1);
1633 1782
1634 retval = device_add(&udc->gadget.dev); 1783 retval = device_add(&udc->gadget.dev);
1635 if (retval) { 1784 if (retval) {
@@ -1645,9 +1794,21 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver)
1645 dev_dbg(udc->dev, "registered gadget driver '%s'\n", 1794 dev_dbg(udc->dev, "registered gadget driver '%s'\n",
1646 driver->driver.name); 1795 driver->driver.name);
1647 1796
1648 udc_enable(udc); 1797 if (udc->transceiver) {
1798 retval = otg_set_peripheral(udc->transceiver, &udc->gadget);
1799 if (retval) {
1800 dev_err(udc->dev, "can't bind to transceiver\n");
1801 goto transceiver_fail;
1802 }
1803 }
1804
1805 if (should_enable_udc(udc))
1806 udc_enable(udc);
1649 return 0; 1807 return 0;
1650 1808
1809transceiver_fail:
1810 if (driver->unbind)
1811 driver->unbind(&udc->gadget);
1651bind_fail: 1812bind_fail:
1652 device_del(&udc->gadget.dev); 1813 device_del(&udc->gadget.dev);
1653add_fail: 1814add_fail:
@@ -1699,14 +1860,17 @@ int usb_gadget_unregister_driver(struct usb_gadget_driver *driver)
1699 1860
1700 stop_activity(udc, driver); 1861 stop_activity(udc, driver);
1701 udc_disable(udc); 1862 udc_disable(udc);
1863 dplus_pullup(udc, 0);
1702 1864
1703 driver->unbind(&udc->gadget); 1865 driver->unbind(&udc->gadget);
1704 udc->driver = NULL; 1866 udc->driver = NULL;
1705 1867
1706 device_del(&udc->gadget.dev); 1868 device_del(&udc->gadget.dev);
1707
1708 dev_info(udc->dev, "unregistered gadget driver '%s'\n", 1869 dev_info(udc->dev, "unregistered gadget driver '%s'\n",
1709 driver->driver.name); 1870 driver->driver.name);
1871
1872 if (udc->transceiver)
1873 return otg_set_peripheral(udc->transceiver, NULL);
1710 return 0; 1874 return 0;
1711} 1875}
1712EXPORT_SYMBOL(usb_gadget_unregister_driver); 1876EXPORT_SYMBOL(usb_gadget_unregister_driver);
@@ -1823,14 +1987,14 @@ static void handle_ep0(struct pxa_udc *udc, int fifo_irq, int opc_irq)
1823 struct pxa27x_request *req = NULL; 1987 struct pxa27x_request *req = NULL;
1824 int completed = 0; 1988 int completed = 0;
1825 1989
1990 if (!list_empty(&ep->queue))
1991 req = list_entry(ep->queue.next, struct pxa27x_request, queue);
1992
1826 udccsr0 = udc_ep_readl(ep, UDCCSR); 1993 udccsr0 = udc_ep_readl(ep, UDCCSR);
1827 ep_dbg(ep, "state=%s, req=%p, udccsr0=0x%03x, udcbcr=%d, irq_msk=%x\n", 1994 ep_dbg(ep, "state=%s, req=%p, udccsr0=0x%03x, udcbcr=%d, irq_msk=%x\n",
1828 EP0_STNAME(udc), req, udccsr0, udc_ep_readl(ep, UDCBCR), 1995 EP0_STNAME(udc), req, udccsr0, udc_ep_readl(ep, UDCBCR),
1829 (fifo_irq << 1 | opc_irq)); 1996 (fifo_irq << 1 | opc_irq));
1830 1997
1831 if (!list_empty(&ep->queue))
1832 req = list_entry(ep->queue.next, struct pxa27x_request, queue);
1833
1834 if (udccsr0 & UDCCSR0_SST) { 1998 if (udccsr0 & UDCCSR0_SST) {
1835 ep_dbg(ep, "clearing stall status\n"); 1999 ep_dbg(ep, "clearing stall status\n");
1836 nuke(ep, -EPIPE); 2000 nuke(ep, -EPIPE);
@@ -2212,7 +2376,7 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2212{ 2376{
2213 struct resource *regs; 2377 struct resource *regs;
2214 struct pxa_udc *udc = &memory; 2378 struct pxa_udc *udc = &memory;
2215 int retval; 2379 int retval = 0, gpio;
2216 2380
2217 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 2381 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2218 if (!regs) 2382 if (!regs)
@@ -2223,6 +2387,20 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2223 2387
2224 udc->dev = &pdev->dev; 2388 udc->dev = &pdev->dev;
2225 udc->mach = pdev->dev.platform_data; 2389 udc->mach = pdev->dev.platform_data;
2390 udc->transceiver = otg_get_transceiver();
2391
2392 gpio = udc->mach->gpio_pullup;
2393 if (gpio_is_valid(gpio)) {
2394 retval = gpio_request(gpio, "USB D+ pullup");
2395 if (retval == 0)
2396 gpio_direction_output(gpio,
2397 udc->mach->gpio_pullup_inverted);
2398 }
2399 if (retval) {
2400 dev_err(&pdev->dev, "Couldn't request gpio %d : %d\n",
2401 gpio, retval);
2402 return retval;
2403 }
2226 2404
2227 udc->clk = clk_get(&pdev->dev, NULL); 2405 udc->clk = clk_get(&pdev->dev, NULL);
2228 if (IS_ERR(udc->clk)) { 2406 if (IS_ERR(udc->clk)) {
@@ -2240,6 +2418,7 @@ static int __init pxa_udc_probe(struct platform_device *pdev)
2240 device_initialize(&udc->gadget.dev); 2418 device_initialize(&udc->gadget.dev);
2241 udc->gadget.dev.parent = &pdev->dev; 2419 udc->gadget.dev.parent = &pdev->dev;
2242 udc->gadget.dev.dma_mask = NULL; 2420 udc->gadget.dev.dma_mask = NULL;
2421 udc->vbus_sensed = 0;
2243 2422
2244 the_controller = udc; 2423 the_controller = udc;
2245 platform_set_drvdata(pdev, udc); 2424 platform_set_drvdata(pdev, udc);
@@ -2273,14 +2452,21 @@ err_clk:
2273static int __exit pxa_udc_remove(struct platform_device *_dev) 2452static int __exit pxa_udc_remove(struct platform_device *_dev)
2274{ 2453{
2275 struct pxa_udc *udc = platform_get_drvdata(_dev); 2454 struct pxa_udc *udc = platform_get_drvdata(_dev);
2455 int gpio = udc->mach->gpio_pullup;
2276 2456
2277 usb_gadget_unregister_driver(udc->driver); 2457 usb_gadget_unregister_driver(udc->driver);
2278 free_irq(udc->irq, udc); 2458 free_irq(udc->irq, udc);
2279 pxa_cleanup_debugfs(udc); 2459 pxa_cleanup_debugfs(udc);
2460 if (gpio_is_valid(gpio))
2461 gpio_free(gpio);
2462
2463 otg_put_transceiver(udc->transceiver);
2280 2464
2465 udc->transceiver = NULL;
2281 platform_set_drvdata(_dev, NULL); 2466 platform_set_drvdata(_dev, NULL);
2282 the_controller = NULL; 2467 the_controller = NULL;
2283 clk_put(udc->clk); 2468 clk_put(udc->clk);
2469 iounmap(udc->regs);
2284 2470
2285 return 0; 2471 return 0;
2286} 2472}
@@ -2319,6 +2505,8 @@ static int pxa_udc_suspend(struct platform_device *_dev, pm_message_t state)
2319 } 2505 }
2320 2506
2321 udc_disable(udc); 2507 udc_disable(udc);
2508 udc->pullup_resume = udc->pullup_on;
2509 dplus_pullup(udc, 0);
2322 2510
2323 return 0; 2511 return 0;
2324} 2512}
@@ -2346,7 +2534,9 @@ static int pxa_udc_resume(struct platform_device *_dev)
2346 ep->udccsr_value, ep->udccr_value); 2534 ep->udccsr_value, ep->udccr_value);
2347 } 2535 }
2348 2536
2349 udc_enable(udc); 2537 dplus_pullup(udc, udc->pullup_resume);
2538 if (should_enable_udc(udc))
2539 udc_enable(udc);
2350 /* 2540 /*
2351 * We do not handle OTG yet. 2541 * We do not handle OTG yet.
2352 * 2542 *
diff --git a/drivers/usb/gadget/pxa27x_udc.h b/drivers/usb/gadget/pxa27x_udc.h
index 1d1b7936ee11..db58125331da 100644
--- a/drivers/usb/gadget/pxa27x_udc.h
+++ b/drivers/usb/gadget/pxa27x_udc.h
@@ -26,6 +26,7 @@
26#include <linux/types.h> 26#include <linux/types.h>
27#include <linux/spinlock.h> 27#include <linux/spinlock.h>
28#include <linux/io.h> 28#include <linux/io.h>
29#include <linux/usb/otg.h>
29 30
30/* 31/*
31 * Register definitions 32 * Register definitions
@@ -421,10 +422,14 @@ struct udc_stats {
421 * @driver: bound gadget (zero, g_ether, g_file_storage, ...) 422 * @driver: bound gadget (zero, g_ether, g_file_storage, ...)
422 * @dev: device 423 * @dev: device
423 * @mach: machine info, used to activate specific GPIO 424 * @mach: machine info, used to activate specific GPIO
425 * @transceiver: external transceiver to handle vbus sense and D+ pullup
424 * @ep0state: control endpoint state machine state 426 * @ep0state: control endpoint state machine state
425 * @stats: statistics on udc usage 427 * @stats: statistics on udc usage
426 * @udc_usb_ep: array of usb endpoints offered by the gadget 428 * @udc_usb_ep: array of usb endpoints offered by the gadget
427 * @pxa_ep: array of pxa available endpoints 429 * @pxa_ep: array of pxa available endpoints
430 * @enabled: UDC was enabled by a previous udc_enable()
431 * @pullup_on: if pullup resistor connected to D+ pin
432 * @pullup_resume: if pullup resistor should be connected to D+ pin on resume
428 * @config: UDC active configuration 433 * @config: UDC active configuration
429 * @last_interface: UDC interface of the last SET_INTERFACE host request 434 * @last_interface: UDC interface of the last SET_INTERFACE host request
430 * @last_alternate: UDC altsetting of the last SET_INTERFACE host request 435 * @last_alternate: UDC altsetting of the last SET_INTERFACE host request
@@ -443,6 +448,7 @@ struct pxa_udc {
443 struct usb_gadget_driver *driver; 448 struct usb_gadget_driver *driver;
444 struct device *dev; 449 struct device *dev;
445 struct pxa2xx_udc_mach_info *mach; 450 struct pxa2xx_udc_mach_info *mach;
451 struct otg_transceiver *transceiver;
446 452
447 enum ep0_state ep0state; 453 enum ep0_state ep0state;
448 struct udc_stats stats; 454 struct udc_stats stats;
@@ -450,6 +456,10 @@ struct pxa_udc {
450 struct udc_usb_ep udc_usb_ep[NR_USB_ENDPOINTS]; 456 struct udc_usb_ep udc_usb_ep[NR_USB_ENDPOINTS];
451 struct pxa_ep pxa_ep[NR_PXA_ENDPOINTS]; 457 struct pxa_ep pxa_ep[NR_PXA_ENDPOINTS];
452 458
459 unsigned enabled:1;
460 unsigned pullup_on:1;
461 unsigned pullup_resume:1;
462 unsigned vbus_sensed:1;
453 unsigned config:2; 463 unsigned config:2;
454 unsigned last_interface:3; 464 unsigned last_interface:3;
455 unsigned last_alternate:3; 465 unsigned last_alternate:3;
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 37879af1c433..f46a60962dab 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -87,12 +87,12 @@ static struct usb_gadget_strings *dev_strings[] = {
87static struct usb_device_descriptor device_desc = { 87static struct usb_device_descriptor device_desc = {
88 .bLength = USB_DT_DEVICE_SIZE, 88 .bLength = USB_DT_DEVICE_SIZE,
89 .bDescriptorType = USB_DT_DEVICE, 89 .bDescriptorType = USB_DT_DEVICE,
90 .bcdUSB = __constant_cpu_to_le16(0x0200), 90 .bcdUSB = cpu_to_le16(0x0200),
91 /* .bDeviceClass = f(use_acm) */ 91 /* .bDeviceClass = f(use_acm) */
92 .bDeviceSubClass = 0, 92 .bDeviceSubClass = 0,
93 .bDeviceProtocol = 0, 93 .bDeviceProtocol = 0,
94 /* .bMaxPacketSize0 = f(hardware) */ 94 /* .bMaxPacketSize0 = f(hardware) */
95 .idVendor = __constant_cpu_to_le16(GS_VENDOR_ID), 95 .idVendor = cpu_to_le16(GS_VENDOR_ID),
96 /* .idProduct = f(use_acm) */ 96 /* .idProduct = f(use_acm) */
97 /* .bcdDevice = f(hardware) */ 97 /* .bcdDevice = f(hardware) */
98 /* .iManufacturer = DYNAMIC */ 98 /* .iManufacturer = DYNAMIC */
@@ -216,7 +216,7 @@ static int __init gs_bind(struct usb_composite_dev *cdev)
216 pr_warning("gs_bind: controller '%s' not recognized\n", 216 pr_warning("gs_bind: controller '%s' not recognized\n",
217 gadget->name); 217 gadget->name);
218 device_desc.bcdDevice = 218 device_desc.bcdDevice =
219 __constant_cpu_to_le16(GS_VERSION_NUM | 0x0099); 219 cpu_to_le16(GS_VERSION_NUM | 0x0099);
220 } 220 }
221 221
222 if (gadget_is_otg(cdev->gadget)) { 222 if (gadget_is_otg(cdev->gadget)) {
@@ -255,19 +255,19 @@ static int __init init(void)
255 serial_config_driver.bConfigurationValue = 2; 255 serial_config_driver.bConfigurationValue = 2;
256 device_desc.bDeviceClass = USB_CLASS_COMM; 256 device_desc.bDeviceClass = USB_CLASS_COMM;
257 device_desc.idProduct = 257 device_desc.idProduct =
258 __constant_cpu_to_le16(GS_CDC_PRODUCT_ID); 258 cpu_to_le16(GS_CDC_PRODUCT_ID);
259 } else if (use_obex) { 259 } else if (use_obex) {
260 serial_config_driver.label = "CDC OBEX config"; 260 serial_config_driver.label = "CDC OBEX config";
261 serial_config_driver.bConfigurationValue = 3; 261 serial_config_driver.bConfigurationValue = 3;
262 device_desc.bDeviceClass = USB_CLASS_COMM; 262 device_desc.bDeviceClass = USB_CLASS_COMM;
263 device_desc.idProduct = 263 device_desc.idProduct =
264 __constant_cpu_to_le16(GS_CDC_OBEX_PRODUCT_ID); 264 cpu_to_le16(GS_CDC_OBEX_PRODUCT_ID);
265 } else { 265 } else {
266 serial_config_driver.label = "Generic Serial config"; 266 serial_config_driver.label = "Generic Serial config";
267 serial_config_driver.bConfigurationValue = 1; 267 serial_config_driver.bConfigurationValue = 1;
268 device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC; 268 device_desc.bDeviceClass = USB_CLASS_VENDOR_SPEC;
269 device_desc.idProduct = 269 device_desc.idProduct =
270 __constant_cpu_to_le16(GS_PRODUCT_ID); 270 cpu_to_le16(GS_PRODUCT_ID);
271 } 271 }
272 strings_dev[STRING_DESCRIPTION_IDX].s = serial_config_driver.label; 272 strings_dev[STRING_DESCRIPTION_IDX].s = serial_config_driver.label;
273 273
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index 53d59287f2bc..0a4d99ab40d8 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -1092,7 +1092,7 @@ int __init gserial_setup(struct usb_gadget *g, unsigned count)
1092 gs_tty_driver->init_termios.c_ispeed = 9600; 1092 gs_tty_driver->init_termios.c_ispeed = 9600;
1093 gs_tty_driver->init_termios.c_ospeed = 9600; 1093 gs_tty_driver->init_termios.c_ospeed = 9600;
1094 1094
1095 coding.dwDTERate = __constant_cpu_to_le32(9600); 1095 coding.dwDTERate = cpu_to_le32(9600);
1096 coding.bCharFormat = 8; 1096 coding.bCharFormat = 8;
1097 coding.bParityType = USB_CDC_NO_PARITY; 1097 coding.bParityType = USB_CDC_NO_PARITY;
1098 coding.bDataBits = USB_CDC_1_STOP_BITS; 1098 coding.bDataBits = USB_CDC_1_STOP_BITS;
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 361d9659ac48..2d772401b7ad 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -102,22 +102,32 @@ module_param(loopdefault, bool, S_IRUGO|S_IWUSR);
102#ifndef CONFIG_USB_ZERO_HNPTEST 102#ifndef CONFIG_USB_ZERO_HNPTEST
103#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */ 103#define DRIVER_VENDOR_NUM 0x0525 /* NetChip */
104#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */ 104#define DRIVER_PRODUCT_NUM 0xa4a0 /* Linux-USB "Gadget Zero" */
105#define DEFAULT_AUTORESUME 0
105#else 106#else
106#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */ 107#define DRIVER_VENDOR_NUM 0x1a0a /* OTG test device IDs */
107#define DRIVER_PRODUCT_NUM 0xbadd 108#define DRIVER_PRODUCT_NUM 0xbadd
109#define DEFAULT_AUTORESUME 5
108#endif 110#endif
109 111
112/* If the optional "autoresume" mode is enabled, it provides good
113 * functional coverage for the "USBCV" test harness from USB-IF.
114 * It's always set if OTG mode is enabled.
115 */
116unsigned autoresume = DEFAULT_AUTORESUME;
117module_param(autoresume, uint, S_IRUGO);
118MODULE_PARM_DESC(autoresume, "zero, or seconds before remote wakeup");
119
110/*-------------------------------------------------------------------------*/ 120/*-------------------------------------------------------------------------*/
111 121
112static struct usb_device_descriptor device_desc = { 122static struct usb_device_descriptor device_desc = {
113 .bLength = sizeof device_desc, 123 .bLength = sizeof device_desc,
114 .bDescriptorType = USB_DT_DEVICE, 124 .bDescriptorType = USB_DT_DEVICE,
115 125
116 .bcdUSB = __constant_cpu_to_le16(0x0200), 126 .bcdUSB = cpu_to_le16(0x0200),
117 .bDeviceClass = USB_CLASS_VENDOR_SPEC, 127 .bDeviceClass = USB_CLASS_VENDOR_SPEC,
118 128
119 .idVendor = __constant_cpu_to_le16(DRIVER_VENDOR_NUM), 129 .idVendor = cpu_to_le16(DRIVER_VENDOR_NUM),
120 .idProduct = __constant_cpu_to_le16(DRIVER_PRODUCT_NUM), 130 .idProduct = cpu_to_le16(DRIVER_PRODUCT_NUM),
121 .bNumConfigurations = 2, 131 .bNumConfigurations = 2,
122}; 132};
123 133
@@ -212,6 +222,47 @@ void disable_endpoints(struct usb_composite_dev *cdev,
212 222
213/*-------------------------------------------------------------------------*/ 223/*-------------------------------------------------------------------------*/
214 224
225static struct timer_list autoresume_timer;
226
227static void zero_autoresume(unsigned long _c)
228{
229 struct usb_composite_dev *cdev = (void *)_c;
230 struct usb_gadget *g = cdev->gadget;
231
232 /* unconfigured devices can't issue wakeups */
233 if (!cdev->config)
234 return;
235
236 /* Normally the host would be woken up for something
237 * more significant than just a timer firing; likely
238 * because of some direct user request.
239 */
240 if (g->speed != USB_SPEED_UNKNOWN) {
241 int status = usb_gadget_wakeup(g);
242 INFO(cdev, "%s --> %d\n", __func__, status);
243 }
244}
245
246static void zero_suspend(struct usb_composite_dev *cdev)
247{
248 if (cdev->gadget->speed == USB_SPEED_UNKNOWN)
249 return;
250
251 if (autoresume) {
252 mod_timer(&autoresume_timer, jiffies + (HZ * autoresume));
253 DBG(cdev, "suspend, wakeup in %d seconds\n", autoresume);
254 } else
255 DBG(cdev, "%s\n", __func__);
256}
257
258static void zero_resume(struct usb_composite_dev *cdev)
259{
260 DBG(cdev, "%s\n", __func__);
261 del_timer(&autoresume_timer);
262}
263
264/*-------------------------------------------------------------------------*/
265
215static int __init zero_bind(struct usb_composite_dev *cdev) 266static int __init zero_bind(struct usb_composite_dev *cdev)
216{ 267{
217 int gcnum; 268 int gcnum;
@@ -239,17 +290,19 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
239 strings_dev[STRING_SERIAL_IDX].id = id; 290 strings_dev[STRING_SERIAL_IDX].id = id;
240 device_desc.iSerialNumber = id; 291 device_desc.iSerialNumber = id;
241 292
293 setup_timer(&autoresume_timer, zero_autoresume, (unsigned long) cdev);
294
242 /* Register primary, then secondary configuration. Note that 295 /* Register primary, then secondary configuration. Note that
243 * SH3 only allows one config... 296 * SH3 only allows one config...
244 */ 297 */
245 if (loopdefault) { 298 if (loopdefault) {
246 loopback_add(cdev); 299 loopback_add(cdev, autoresume != 0);
247 if (!gadget_is_sh(gadget)) 300 if (!gadget_is_sh(gadget))
248 sourcesink_add(cdev); 301 sourcesink_add(cdev, autoresume != 0);
249 } else { 302 } else {
250 sourcesink_add(cdev); 303 sourcesink_add(cdev, autoresume != 0);
251 if (!gadget_is_sh(gadget)) 304 if (!gadget_is_sh(gadget))
252 loopback_add(cdev); 305 loopback_add(cdev, autoresume != 0);
253 } 306 }
254 307
255 gcnum = usb_gadget_controller_number(gadget); 308 gcnum = usb_gadget_controller_number(gadget);
@@ -265,7 +318,7 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
265 */ 318 */
266 pr_warning("%s: controller '%s' not recognized\n", 319 pr_warning("%s: controller '%s' not recognized\n",
267 longname, gadget->name); 320 longname, gadget->name);
268 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999); 321 device_desc.bcdDevice = cpu_to_le16(0x9999);
269 } 322 }
270 323
271 324
@@ -278,11 +331,20 @@ static int __init zero_bind(struct usb_composite_dev *cdev)
278 return 0; 331 return 0;
279} 332}
280 333
334static int zero_unbind(struct usb_composite_dev *cdev)
335{
336 del_timer_sync(&autoresume_timer);
337 return 0;
338}
339
281static struct usb_composite_driver zero_driver = { 340static struct usb_composite_driver zero_driver = {
282 .name = "zero", 341 .name = "zero",
283 .dev = &device_desc, 342 .dev = &device_desc,
284 .strings = dev_strings, 343 .strings = dev_strings,
285 .bind = zero_bind, 344 .bind = zero_bind,
345 .unbind = zero_unbind,
346 .suspend = zero_suspend,
347 .resume = zero_resume,
286}; 348};
287 349
288MODULE_AUTHOR("David Brownell"); 350MODULE_AUTHOR("David Brownell");
diff --git a/drivers/usb/host/Kconfig b/drivers/usb/host/Kconfig
index 2c63bfb1f8d9..845479f7c707 100644
--- a/drivers/usb/host/Kconfig
+++ b/drivers/usb/host/Kconfig
@@ -24,10 +24,7 @@ config USB_EHCI_HCD
24 The Enhanced Host Controller Interface (EHCI) is standard for USB 2.0 24 The Enhanced Host Controller Interface (EHCI) is standard for USB 2.0
25 "high speed" (480 Mbit/sec, 60 Mbyte/sec) host controller hardware. 25 "high speed" (480 Mbit/sec, 60 Mbyte/sec) host controller hardware.
26 If your USB host controller supports USB 2.0, you will likely want to 26 If your USB host controller supports USB 2.0, you will likely want to
27 configure this Host Controller Driver. At the time of this writing, 27 configure this Host Controller Driver.
28 the primary implementation of EHCI is a chip from NEC, widely available
29 in add-on PCI cards, but implementations are in the works from other
30 vendors including Intel and Philips. Motherboard support is appearing.
31 28
32 EHCI controllers are packaged with "companion" host controllers (OHCI 29 EHCI controllers are packaged with "companion" host controllers (OHCI
33 or UHCI) to handle USB 1.1 devices connected to root hub ports. Ports 30 or UHCI) to handle USB 1.1 devices connected to root hub ports. Ports
@@ -123,7 +120,7 @@ config USB_ISP116X_HCD
123 120
124config USB_ISP1760_HCD 121config USB_ISP1760_HCD
125 tristate "ISP 1760 HCD support" 122 tristate "ISP 1760 HCD support"
126 depends on USB && EXPERIMENTAL && (PCI || PPC_OF) 123 depends on USB && EXPERIMENTAL
127 ---help--- 124 ---help---
128 The ISP1760 chip is a USB 2.0 host controller. 125 The ISP1760 chip is a USB 2.0 host controller.
129 126
diff --git a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c
index e551bb38852b..f2618d17710d 100644
--- a/drivers/usb/host/ehci-hcd.c
+++ b/drivers/usb/host/ehci-hcd.c
@@ -110,6 +110,42 @@ MODULE_PARM_DESC (ignore_oc, "ignore bogus hardware overcurrent indications");
110 110
111/*-------------------------------------------------------------------------*/ 111/*-------------------------------------------------------------------------*/
112 112
113static void
114timer_action(struct ehci_hcd *ehci, enum ehci_timer_action action)
115{
116 /* Don't override timeouts which shrink or (later) disable
117 * the async ring; just the I/O watchdog. Note that if a
118 * SHRINK were pending, OFF would never be requested.
119 */
120 if (timer_pending(&ehci->watchdog)
121 && ((BIT(TIMER_ASYNC_SHRINK) | BIT(TIMER_ASYNC_OFF))
122 & ehci->actions))
123 return;
124
125 if (!test_and_set_bit(action, &ehci->actions)) {
126 unsigned long t;
127
128 switch (action) {
129 case TIMER_IO_WATCHDOG:
130 t = EHCI_IO_JIFFIES;
131 break;
132 case TIMER_ASYNC_OFF:
133 t = EHCI_ASYNC_JIFFIES;
134 break;
135 /* case TIMER_ASYNC_SHRINK: */
136 default:
137 /* add a jiffie since we synch against the
138 * 8 KHz uframe counter.
139 */
140 t = DIV_ROUND_UP(EHCI_SHRINK_FRAMES * HZ, 1000) + 1;
141 break;
142 }
143 mod_timer(&ehci->watchdog, t + jiffies);
144 }
145}
146
147/*-------------------------------------------------------------------------*/
148
113/* 149/*
114 * handshake - spin reading hc until handshake completes or fails 150 * handshake - spin reading hc until handshake completes or fails
115 * @ptr: address of hc register to be read 151 * @ptr: address of hc register to be read
diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index ecc9b66c03cd..1976b1b3778c 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -333,12 +333,40 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
333 token = hc32_to_cpu(ehci, qtd->hw_token); 333 token = hc32_to_cpu(ehci, qtd->hw_token);
334 334
335 /* always clean up qtds the hc de-activated */ 335 /* always clean up qtds the hc de-activated */
336 retry_xacterr:
336 if ((token & QTD_STS_ACTIVE) == 0) { 337 if ((token & QTD_STS_ACTIVE) == 0) {
337 338
338 /* on STALL, error, and short reads this urb must 339 /* on STALL, error, and short reads this urb must
339 * complete and all its qtds must be recycled. 340 * complete and all its qtds must be recycled.
340 */ 341 */
341 if ((token & QTD_STS_HALT) != 0) { 342 if ((token & QTD_STS_HALT) != 0) {
343
344 /* retry transaction errors until we
345 * reach the software xacterr limit
346 */
347 if ((token & QTD_STS_XACT) &&
348 QTD_CERR(token) == 0 &&
349 --qh->xacterrs > 0 &&
350 !urb->unlinked) {
351 ehci_dbg(ehci,
352 "detected XactErr len %zu/%zu retry %d\n",
353 qtd->length - QTD_LENGTH(token), qtd->length,
354 QH_XACTERR_MAX - qh->xacterrs);
355
356 /* reset the token in the qtd and the
357 * qh overlay (which still contains
358 * the qtd) so that we pick up from
359 * where we left off
360 */
361 token &= ~QTD_STS_HALT;
362 token |= QTD_STS_ACTIVE |
363 (EHCI_TUNE_CERR << 10);
364 qtd->hw_token = cpu_to_hc32(ehci,
365 token);
366 wmb();
367 qh->hw_token = cpu_to_hc32(ehci, token);
368 goto retry_xacterr;
369 }
342 stopped = 1; 370 stopped = 1;
343 371
344 /* magic dummy for some short reads; qh won't advance. 372 /* magic dummy for some short reads; qh won't advance.
@@ -421,6 +449,9 @@ halt:
421 /* remove qtd; it's recycled after possible urb completion */ 449 /* remove qtd; it's recycled after possible urb completion */
422 list_del (&qtd->qtd_list); 450 list_del (&qtd->qtd_list);
423 last = qtd; 451 last = qtd;
452
453 /* reinit the xacterr counter for the next qtd */
454 qh->xacterrs = QH_XACTERR_MAX;
424 } 455 }
425 456
426 /* last urb's completion might still need calling */ 457 /* last urb's completion might still need calling */
@@ -862,6 +893,7 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
862 head->qh_next.qh = qh; 893 head->qh_next.qh = qh;
863 head->hw_next = dma; 894 head->hw_next = dma;
864 895
896 qh->xacterrs = QH_XACTERR_MAX;
865 qh->qh_state = QH_STATE_LINKED; 897 qh->qh_state = QH_STATE_LINKED;
866 /* qtd completions reported later by interrupt */ 898 /* qtd completions reported later by interrupt */
867} 899}
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 1d0b49e3f192..ada5d2ba297b 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -563,7 +563,7 @@ static int qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
563 // and this qh is active in the current uframe 563 // and this qh is active in the current uframe
564 // (and overlay token SplitXstate is false?) 564 // (and overlay token SplitXstate is false?)
565 // THEN 565 // THEN
566 // qh->hw_info1 |= __constant_cpu_to_hc32(1 << 7 /* "ignore" */); 566 // qh->hw_info1 |= cpu_to_hc32(1 << 7 /* "ignore" */);
567 567
568 /* high bandwidth, or otherwise part of every microframe */ 568 /* high bandwidth, or otherwise part of every microframe */
569 if ((period = qh->period) == 0) 569 if ((period = qh->period) == 0)
diff --git a/drivers/usb/host/ehci.h b/drivers/usb/host/ehci.h
index 262b00c9b334..6cff195e1a36 100644
--- a/drivers/usb/host/ehci.h
+++ b/drivers/usb/host/ehci.h
@@ -190,40 +190,6 @@ timer_action_done (struct ehci_hcd *ehci, enum ehci_timer_action action)
190 clear_bit (action, &ehci->actions); 190 clear_bit (action, &ehci->actions);
191} 191}
192 192
193static inline void
194timer_action (struct ehci_hcd *ehci, enum ehci_timer_action action)
195{
196 /* Don't override timeouts which shrink or (later) disable
197 * the async ring; just the I/O watchdog. Note that if a
198 * SHRINK were pending, OFF would never be requested.
199 */
200 if (timer_pending(&ehci->watchdog)
201 && ((BIT(TIMER_ASYNC_SHRINK) | BIT(TIMER_ASYNC_OFF))
202 & ehci->actions))
203 return;
204
205 if (!test_and_set_bit (action, &ehci->actions)) {
206 unsigned long t;
207
208 switch (action) {
209 case TIMER_IO_WATCHDOG:
210 t = EHCI_IO_JIFFIES;
211 break;
212 case TIMER_ASYNC_OFF:
213 t = EHCI_ASYNC_JIFFIES;
214 break;
215 // case TIMER_ASYNC_SHRINK:
216 default:
217 /* add a jiffie since we synch against the
218 * 8 KHz uframe counter.
219 */
220 t = DIV_ROUND_UP(EHCI_SHRINK_FRAMES * HZ, 1000) + 1;
221 break;
222 }
223 mod_timer(&ehci->watchdog, t + jiffies);
224 }
225}
226
227static void free_cached_itd_list(struct ehci_hcd *ehci); 193static void free_cached_itd_list(struct ehci_hcd *ehci);
228 194
229/*-------------------------------------------------------------------------*/ 195/*-------------------------------------------------------------------------*/
@@ -287,7 +253,7 @@ struct ehci_qtd {
287 253
288/* 254/*
289 * Now the following defines are not converted using the 255 * Now the following defines are not converted using the
290 * __constant_cpu_to_le32() macro anymore, since we have to support 256 * cpu_to_le32() macro anymore, since we have to support
291 * "dynamic" switching between be and le support, so that the driver 257 * "dynamic" switching between be and le support, so that the driver
292 * can be used on one system with SoC EHCI controller using big-endian 258 * can be used on one system with SoC EHCI controller using big-endian
293 * descriptors as well as a normal little-endian PCI EHCI controller. 259 * descriptors as well as a normal little-endian PCI EHCI controller.
@@ -376,6 +342,9 @@ struct ehci_qh {
376#define QH_STATE_UNLINK_WAIT 4 /* LINKED and on reclaim q */ 342#define QH_STATE_UNLINK_WAIT 4 /* LINKED and on reclaim q */
377#define QH_STATE_COMPLETING 5 /* don't touch token.HALT */ 343#define QH_STATE_COMPLETING 5 /* don't touch token.HALT */
378 344
345 u8 xacterrs; /* XactErr retry counter */
346#define QH_XACTERR_MAX 32 /* XactErr retry limit */
347
379 /* periodic schedule info */ 348 /* periodic schedule info */
380 u8 usecs; /* intr bandwidth */ 349 u8 usecs; /* intr bandwidth */
381 u8 gap_uf; /* uframes split/csplit gap */ 350 u8 gap_uf; /* uframes split/csplit gap */
diff --git a/drivers/usb/host/fhci-dbg.c b/drivers/usb/host/fhci-dbg.c
index 34e14edf390b..ea8a4255c5da 100644
--- a/drivers/usb/host/fhci-dbg.c
+++ b/drivers/usb/host/fhci-dbg.c
@@ -108,7 +108,7 @@ void fhci_dfs_create(struct fhci_hcd *fhci)
108{ 108{
109 struct device *dev = fhci_to_hcd(fhci)->self.controller; 109 struct device *dev = fhci_to_hcd(fhci)->self.controller;
110 110
111 fhci->dfs_root = debugfs_create_dir(dev->bus_id, NULL); 111 fhci->dfs_root = debugfs_create_dir(dev_name(dev), NULL);
112 if (!fhci->dfs_root) { 112 if (!fhci->dfs_root) {
113 WARN_ON(1); 113 WARN_ON(1);
114 return; 114 return;
diff --git a/drivers/usb/host/fhci-hcd.c b/drivers/usb/host/fhci-hcd.c
index ba622cc8a9ba..0951818ef93b 100644
--- a/drivers/usb/host/fhci-hcd.c
+++ b/drivers/usb/host/fhci-hcd.c
@@ -583,7 +583,7 @@ static int __devinit of_fhci_probe(struct of_device *ofdev,
583 if (sprop && strcmp(sprop, "host")) 583 if (sprop && strcmp(sprop, "host"))
584 return -ENODEV; 584 return -ENODEV;
585 585
586 hcd = usb_create_hcd(&fhci_driver, dev, dev->bus_id); 586 hcd = usb_create_hcd(&fhci_driver, dev, dev_name(dev));
587 if (!hcd) { 587 if (!hcd) {
588 dev_err(dev, "could not create hcd\n"); 588 dev_err(dev, "could not create hcd\n");
589 return -ENOMEM; 589 return -ENOMEM;
@@ -650,7 +650,7 @@ static int __devinit of_fhci_probe(struct of_device *ofdev,
650 } 650 }
651 } 651 }
652 652
653 ret = gpio_request(gpio, dev->bus_id); 653 ret = gpio_request(gpio, dev_name(dev));
654 if (ret) { 654 if (ret) {
655 dev_err(dev, "failed to request gpio %d", i); 655 dev_err(dev, "failed to request gpio %d", i);
656 goto err_gpios; 656 goto err_gpios;
diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
index 8582236e4cad..cbf30e515f29 100644
--- a/drivers/usb/host/hwa-hc.c
+++ b/drivers/usb/host/hwa-hc.c
@@ -464,8 +464,7 @@ static int __hwahc_dev_set_key(struct wusbhc *wusbhc, u8 port_idx, u32 tkid,
464 port_idx << 8 | iface_no, 464 port_idx << 8 | iface_no,
465 keyd, keyd_len, 1000 /* FIXME: arbitrary */); 465 keyd, keyd_len, 1000 /* FIXME: arbitrary */);
466 466
467 memset(keyd, 0, sizeof(*keyd)); /* clear keys etc. */ 467 kzfree(keyd); /* clear keys etc. */
468 kfree(keyd);
469 return result; 468 return result;
470} 469}
471 470
diff --git a/drivers/usb/host/isp116x-hcd.c b/drivers/usb/host/isp116x-hcd.c
index 4dda31b26892..a2b305477afe 100644
--- a/drivers/usb/host/isp116x-hcd.c
+++ b/drivers/usb/host/isp116x-hcd.c
@@ -772,7 +772,7 @@ static int isp116x_urb_enqueue(struct usb_hcd *hcd,
772 break; 772 break;
773 case PIPE_INTERRUPT: 773 case PIPE_INTERRUPT:
774 urb->interval = ep->period; 774 urb->interval = ep->period;
775 ep->length = min((int)ep->maxpacket, 775 ep->length = min_t(u32, ep->maxpacket,
776 urb->transfer_buffer_length); 776 urb->transfer_buffer_length);
777 777
778 /* urb submitted for already existing endpoint */ 778 /* urb submitted for already existing endpoint */
diff --git a/drivers/usb/host/isp116x.h b/drivers/usb/host/isp116x.h
index aa211bafcff9..12db961acdfb 100644
--- a/drivers/usb/host/isp116x.h
+++ b/drivers/usb/host/isp116x.h
@@ -563,7 +563,7 @@ static void urb_dbg(struct urb *urb, char *msg)
563*/ 563*/
564static inline void dump_ptd(struct ptd *ptd) 564static inline void dump_ptd(struct ptd *ptd)
565{ 565{
566 printk("td: %x %d%c%d %d,%d,%d %x %x%x%x\n", 566 printk(KERN_WARNING "td: %x %d%c%d %d,%d,%d %x %x%x%x\n",
567 PTD_GET_CC(ptd), PTD_GET_FA(ptd), 567 PTD_GET_CC(ptd), PTD_GET_FA(ptd),
568 PTD_DIR_STR(ptd), PTD_GET_EP(ptd), 568 PTD_DIR_STR(ptd), PTD_GET_EP(ptd),
569 PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd), 569 PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd),
@@ -576,7 +576,7 @@ static inline void dump_ptd_out_data(struct ptd *ptd, u8 * buf)
576 int k; 576 int k;
577 577
578 if (PTD_GET_DIR(ptd) != PTD_DIR_IN && PTD_GET_LEN(ptd)) { 578 if (PTD_GET_DIR(ptd) != PTD_DIR_IN && PTD_GET_LEN(ptd)) {
579 printk("-> "); 579 printk(KERN_WARNING "-> ");
580 for (k = 0; k < PTD_GET_LEN(ptd); ++k) 580 for (k = 0; k < PTD_GET_LEN(ptd); ++k)
581 printk("%02x ", ((u8 *) buf)[k]); 581 printk("%02x ", ((u8 *) buf)[k]);
582 printk("\n"); 582 printk("\n");
@@ -588,13 +588,13 @@ static inline void dump_ptd_in_data(struct ptd *ptd, u8 * buf)
588 int k; 588 int k;
589 589
590 if (PTD_GET_DIR(ptd) == PTD_DIR_IN && PTD_GET_COUNT(ptd)) { 590 if (PTD_GET_DIR(ptd) == PTD_DIR_IN && PTD_GET_COUNT(ptd)) {
591 printk("<- "); 591 printk(KERN_WARNING "<- ");
592 for (k = 0; k < PTD_GET_COUNT(ptd); ++k) 592 for (k = 0; k < PTD_GET_COUNT(ptd); ++k)
593 printk("%02x ", ((u8 *) buf)[k]); 593 printk("%02x ", ((u8 *) buf)[k]);
594 printk("\n"); 594 printk("\n");
595 } 595 }
596 if (PTD_GET_LAST(ptd)) 596 if (PTD_GET_LAST(ptd))
597 printk("-\n"); 597 printk(KERN_WARNING "-\n");
598} 598}
599 599
600#else 600#else
diff --git a/drivers/usb/host/isp1760-hcd.c b/drivers/usb/host/isp1760-hcd.c
index b899f1a59c26..cd07ea3f0c63 100644
--- a/drivers/usb/host/isp1760-hcd.c
+++ b/drivers/usb/host/isp1760-hcd.c
@@ -644,7 +644,7 @@ static void transform_add_int(struct isp1760_hcd *priv, struct isp1760_qh *qh,
644 644
645 if (urb->dev->speed != USB_SPEED_HIGH) { 645 if (urb->dev->speed != USB_SPEED_HIGH) {
646 /* split */ 646 /* split */
647 ptd->dw5 = __constant_cpu_to_le32(0x1c); 647 ptd->dw5 = cpu_to_le32(0x1c);
648 648
649 if (qh->period >= 32) 649 if (qh->period >= 32)
650 period = qh->period / 2; 650 period = qh->period / 2;
@@ -819,6 +819,13 @@ static void enqueue_an_ATL_packet(struct usb_hcd *hcd, struct isp1760_qh *qh,
819 u32 atl_regs, payload; 819 u32 atl_regs, payload;
820 u32 buffstatus; 820 u32 buffstatus;
821 821
822 /*
823 * When this function is called from the interrupt handler to enqueue
824 * a follow-up packet, the SKIP register gets written and read back
825 * almost immediately. With ISP1761, this register requires a delay of
826 * 195ns between a write and subsequent read (see section 15.1.1.3).
827 */
828 ndelay(195);
822 skip_map = isp1760_readl(hcd->regs + HC_ATL_PTD_SKIPMAP_REG); 829 skip_map = isp1760_readl(hcd->regs + HC_ATL_PTD_SKIPMAP_REG);
823 830
824 BUG_ON(!skip_map); 831 BUG_ON(!skip_map);
@@ -853,6 +860,13 @@ static void enqueue_an_INT_packet(struct usb_hcd *hcd, struct isp1760_qh *qh,
853 u32 int_regs, payload; 860 u32 int_regs, payload;
854 u32 buffstatus; 861 u32 buffstatus;
855 862
863 /*
864 * When this function is called from the interrupt handler to enqueue
865 * a follow-up packet, the SKIP register gets written and read back
866 * almost immediately. With ISP1761, this register requires a delay of
867 * 195ns between a write and subsequent read (see section 15.1.1.3).
868 */
869 ndelay(195);
856 skip_map = isp1760_readl(hcd->regs + HC_INT_PTD_SKIPMAP_REG); 870 skip_map = isp1760_readl(hcd->regs + HC_INT_PTD_SKIPMAP_REG);
857 871
858 BUG_ON(!skip_map); 872 BUG_ON(!skip_map);
@@ -1054,7 +1068,7 @@ static void do_atl_int(struct usb_hcd *usb_hcd)
1054 priv_write_copy(priv, (u32 *)&ptd, usb_hcd->regs + 1068 priv_write_copy(priv, (u32 *)&ptd, usb_hcd->regs +
1055 atl_regs, sizeof(ptd)); 1069 atl_regs, sizeof(ptd));
1056 1070
1057 ptd.dw0 |= __constant_cpu_to_le32(PTD_VALID); 1071 ptd.dw0 |= cpu_to_le32(PTD_VALID);
1058 priv_write_copy(priv, (u32 *)&ptd, usb_hcd->regs + 1072 priv_write_copy(priv, (u32 *)&ptd, usb_hcd->regs +
1059 atl_regs, sizeof(ptd)); 1073 atl_regs, sizeof(ptd));
1060 1074
@@ -2235,9 +2249,10 @@ void deinit_kmem_cache(void)
2235 kmem_cache_destroy(qh_cachep); 2249 kmem_cache_destroy(qh_cachep);
2236} 2250}
2237 2251
2238struct usb_hcd *isp1760_register(u64 res_start, u64 res_len, int irq, 2252struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len,
2239 u64 irqflags, struct device *dev, const char *busname, 2253 int irq, unsigned long irqflags,
2240 unsigned int devflags) 2254 struct device *dev, const char *busname,
2255 unsigned int devflags)
2241{ 2256{
2242 struct usb_hcd *hcd; 2257 struct usb_hcd *hcd;
2243 struct isp1760_hcd *priv; 2258 struct isp1760_hcd *priv;
diff --git a/drivers/usb/host/isp1760-hcd.h b/drivers/usb/host/isp1760-hcd.h
index a9daea587962..462f4943cb1b 100644
--- a/drivers/usb/host/isp1760-hcd.h
+++ b/drivers/usb/host/isp1760-hcd.h
@@ -2,9 +2,10 @@
2#define _ISP1760_HCD_H_ 2#define _ISP1760_HCD_H_
3 3
4/* exports for if */ 4/* exports for if */
5struct usb_hcd *isp1760_register(u64 res_start, u64 res_len, int irq, 5struct usb_hcd *isp1760_register(phys_addr_t res_start, resource_size_t res_len,
6 u64 irqflags, struct device *dev, const char *busname, 6 int irq, unsigned long irqflags,
7 unsigned int devflags); 7 struct device *dev, const char *busname,
8 unsigned int devflags);
8int init_kmem_once(void); 9int init_kmem_once(void);
9void deinit_kmem_cache(void); 10void deinit_kmem_cache(void);
10 11
diff --git a/drivers/usb/host/isp1760-if.c b/drivers/usb/host/isp1760-if.c
index 4cf7ca428b33..3fa3a1702796 100644
--- a/drivers/usb/host/isp1760-if.c
+++ b/drivers/usb/host/isp1760-if.c
@@ -10,6 +10,7 @@
10 10
11#include <linux/usb.h> 11#include <linux/usb.h>
12#include <linux/io.h> 12#include <linux/io.h>
13#include <linux/platform_device.h>
13 14
14#include "../core/hcd.h" 15#include "../core/hcd.h"
15#include "isp1760-hcd.h" 16#include "isp1760-hcd.h"
@@ -300,39 +301,101 @@ static struct pci_driver isp1761_pci_driver = {
300}; 301};
301#endif 302#endif
302 303
304static int __devinit isp1760_plat_probe(struct platform_device *pdev)
305{
306 int ret = 0;
307 struct usb_hcd *hcd;
308 struct resource *mem_res;
309 struct resource *irq_res;
310 resource_size_t mem_size;
311 unsigned long irqflags = IRQF_SHARED | IRQF_DISABLED;
312
313 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
314 if (!mem_res) {
315 pr_warning("isp1760: Memory resource not available\n");
316 ret = -ENODEV;
317 goto out;
318 }
319 mem_size = resource_size(mem_res);
320 if (!request_mem_region(mem_res->start, mem_size, "isp1760")) {
321 pr_warning("isp1760: Cannot reserve the memory resource\n");
322 ret = -EBUSY;
323 goto out;
324 }
325
326 irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
327 if (!irq_res) {
328 pr_warning("isp1760: IRQ resource not available\n");
329 return -ENODEV;
330 }
331 irqflags |= irq_res->flags & IRQF_TRIGGER_MASK;
332
333 hcd = isp1760_register(mem_res->start, mem_size, irq_res->start,
334 irqflags, &pdev->dev, dev_name(&pdev->dev), 0);
335 if (IS_ERR(hcd)) {
336 pr_warning("isp1760: Failed to register the HCD device\n");
337 ret = -ENODEV;
338 goto cleanup;
339 }
340
341 pr_info("ISP1760 USB device initialised\n");
342 return ret;
343
344cleanup:
345 release_mem_region(mem_res->start, mem_size);
346out:
347 return ret;
348}
349
350static int __devexit isp1760_plat_remove(struct platform_device *pdev)
351{
352 struct resource *mem_res;
353 resource_size_t mem_size;
354
355 mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
356 mem_size = resource_size(mem_res);
357 release_mem_region(mem_res->start, mem_size);
358
359 return 0;
360}
361
362static struct platform_driver isp1760_plat_driver = {
363 .probe = isp1760_plat_probe,
364 .remove = isp1760_plat_remove,
365 .driver = {
366 .name = "isp1760",
367 },
368};
369
303static int __init isp1760_init(void) 370static int __init isp1760_init(void)
304{ 371{
305 int ret; 372 int ret, any_ret = -ENODEV;
306 373
307 init_kmem_once(); 374 init_kmem_once();
308 375
376 ret = platform_driver_register(&isp1760_plat_driver);
377 if (!ret)
378 any_ret = 0;
309#ifdef CONFIG_PPC_OF 379#ifdef CONFIG_PPC_OF
310 ret = of_register_platform_driver(&isp1760_of_driver); 380 ret = of_register_platform_driver(&isp1760_of_driver);
311 if (ret) { 381 if (!ret)
312 deinit_kmem_cache(); 382 any_ret = 0;
313 return ret;
314 }
315#endif 383#endif
316#ifdef CONFIG_PCI 384#ifdef CONFIG_PCI
317 ret = pci_register_driver(&isp1761_pci_driver); 385 ret = pci_register_driver(&isp1761_pci_driver);
318 if (ret) 386 if (!ret)
319 goto unreg_of; 387 any_ret = 0;
320#endif 388#endif
321 return ret;
322 389
323#ifdef CONFIG_PCI 390 if (any_ret)
324unreg_of: 391 deinit_kmem_cache();
325#endif 392 return any_ret;
326#ifdef CONFIG_PPC_OF
327 of_unregister_platform_driver(&isp1760_of_driver);
328#endif
329 deinit_kmem_cache();
330 return ret;
331} 393}
332module_init(isp1760_init); 394module_init(isp1760_init);
333 395
334static void __exit isp1760_exit(void) 396static void __exit isp1760_exit(void)
335{ 397{
398 platform_driver_unregister(&isp1760_plat_driver);
336#ifdef CONFIG_PPC_OF 399#ifdef CONFIG_PPC_OF
337 of_unregister_platform_driver(&isp1760_of_driver); 400 of_unregister_platform_driver(&isp1760_of_driver);
338#endif 401#endif
diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index 5cf5f1eca4f4..25db704f3a2a 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -997,7 +997,7 @@ MODULE_LICENSE ("GPL");
997#define SA1111_DRIVER ohci_hcd_sa1111_driver 997#define SA1111_DRIVER ohci_hcd_sa1111_driver
998#endif 998#endif
999 999
1000#ifdef CONFIG_ARCH_S3C2410 1000#if defined(CONFIG_ARCH_S3C2410) || defined(CONFIG_ARCH_S3C64XX)
1001#include "ohci-s3c2410.c" 1001#include "ohci-s3c2410.c"
1002#define PLATFORM_DRIVER ohci_hcd_s3c2410_driver 1002#define PLATFORM_DRIVER ohci_hcd_s3c2410_driver
1003#endif 1003#endif
@@ -1049,7 +1049,8 @@ MODULE_LICENSE ("GPL");
1049 1049
1050#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \ 1050#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
1051 defined(CONFIG_CPU_SUBTYPE_SH7721) || \ 1051 defined(CONFIG_CPU_SUBTYPE_SH7721) || \
1052 defined(CONFIG_CPU_SUBTYPE_SH7763) 1052 defined(CONFIG_CPU_SUBTYPE_SH7763) || \
1053 defined(CONFIG_CPU_SUBTYPE_SH7786)
1053#include "ohci-sh.c" 1054#include "ohci-sh.c"
1054#define PLATFORM_DRIVER ohci_hcd_sh_driver 1055#define PLATFORM_DRIVER ohci_hcd_sh_driver
1055#endif 1056#endif
diff --git a/drivers/usb/host/ohci-s3c2410.c b/drivers/usb/host/ohci-s3c2410.c
index f46af7a718d4..a68af2dd55ca 100644
--- a/drivers/usb/host/ohci-s3c2410.c
+++ b/drivers/usb/host/ohci-s3c2410.c
@@ -21,9 +21,7 @@
21 21
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
23#include <linux/clk.h> 23#include <linux/clk.h>
24 24#include <plat/usb-control.h>
25#include <mach/hardware.h>
26#include <mach/usb-control.h>
27 25
28#define valid_port(idx) ((idx) == 1 || (idx) == 2) 26#define valid_port(idx) ((idx) == 1 || (idx) == 2)
29 27
@@ -372,7 +370,7 @@ static int usb_hcd_s3c2410_probe (const struct hc_driver *driver,
372 370
373 usb_clk = clk_get(&dev->dev, "usb-bus-host"); 371 usb_clk = clk_get(&dev->dev, "usb-bus-host");
374 if (IS_ERR(usb_clk)) { 372 if (IS_ERR(usb_clk)) {
375 dev_err(&dev->dev, "cannot get usb-host clock\n"); 373 dev_err(&dev->dev, "cannot get usb-bus-host clock\n");
376 retval = -ENOENT; 374 retval = -ENOENT;
377 goto err_clk; 375 goto err_clk;
378 } 376 }
diff --git a/drivers/usb/host/oxu210hp-hcd.c b/drivers/usb/host/oxu210hp-hcd.c
index 75548f7c716b..5ac489ee3dab 100644
--- a/drivers/usb/host/oxu210hp-hcd.c
+++ b/drivers/usb/host/oxu210hp-hcd.c
@@ -845,14 +845,14 @@ static inline void qh_update(struct oxu_hcd *oxu,
845 is_out = !(qtd->hw_token & cpu_to_le32(1 << 8)); 845 is_out = !(qtd->hw_token & cpu_to_le32(1 << 8));
846 epnum = (le32_to_cpup(&qh->hw_info1) >> 8) & 0x0f; 846 epnum = (le32_to_cpup(&qh->hw_info1) >> 8) & 0x0f;
847 if (unlikely(!usb_gettoggle(qh->dev, epnum, is_out))) { 847 if (unlikely(!usb_gettoggle(qh->dev, epnum, is_out))) {
848 qh->hw_token &= ~__constant_cpu_to_le32(QTD_TOGGLE); 848 qh->hw_token &= ~cpu_to_le32(QTD_TOGGLE);
849 usb_settoggle(qh->dev, epnum, is_out, 1); 849 usb_settoggle(qh->dev, epnum, is_out, 1);
850 } 850 }
851 } 851 }
852 852
853 /* HC must see latest qtd and qh data before we clear ACTIVE+HALT */ 853 /* HC must see latest qtd and qh data before we clear ACTIVE+HALT */
854 wmb(); 854 wmb();
855 qh->hw_token &= __constant_cpu_to_le32(QTD_TOGGLE | QTD_STS_PING); 855 qh->hw_token &= cpu_to_le32(QTD_TOGGLE | QTD_STS_PING);
856} 856}
857 857
858/* If it weren't for a common silicon quirk (writing the dummy into the qh 858/* If it weren't for a common silicon quirk (writing the dummy into the qh
@@ -937,7 +937,7 @@ __acquires(oxu->lock)
937 struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv; 937 struct ehci_qh *qh = (struct ehci_qh *) urb->hcpriv;
938 938
939 /* S-mask in a QH means it's an interrupt urb */ 939 /* S-mask in a QH means it's an interrupt urb */
940 if ((qh->hw_info2 & __constant_cpu_to_le32(QH_SMASK)) != 0) { 940 if ((qh->hw_info2 & cpu_to_le32(QH_SMASK)) != 0) {
941 941
942 /* ... update hc-wide periodic stats (for usbfs) */ 942 /* ... update hc-wide periodic stats (for usbfs) */
943 oxu_to_hcd(oxu)->self.bandwidth_int_reqs--; 943 oxu_to_hcd(oxu)->self.bandwidth_int_reqs--;
@@ -981,7 +981,7 @@ static void unlink_async(struct oxu_hcd *oxu, struct ehci_qh *qh);
981static void intr_deschedule(struct oxu_hcd *oxu, struct ehci_qh *qh); 981static void intr_deschedule(struct oxu_hcd *oxu, struct ehci_qh *qh);
982static int qh_schedule(struct oxu_hcd *oxu, struct ehci_qh *qh); 982static int qh_schedule(struct oxu_hcd *oxu, struct ehci_qh *qh);
983 983
984#define HALT_BIT __constant_cpu_to_le32(QTD_STS_HALT) 984#define HALT_BIT cpu_to_le32(QTD_STS_HALT)
985 985
986/* Process and free completed qtds for a qh, returning URBs to drivers. 986/* Process and free completed qtds for a qh, returning URBs to drivers.
987 * Chases up to qh->hw_current. Returns number of completions called, 987 * Chases up to qh->hw_current. Returns number of completions called,
@@ -1160,7 +1160,7 @@ halt:
1160 /* should be rare for periodic transfers, 1160 /* should be rare for periodic transfers,
1161 * except maybe high bandwidth ... 1161 * except maybe high bandwidth ...
1162 */ 1162 */
1163 if ((__constant_cpu_to_le32(QH_SMASK) 1163 if ((cpu_to_le32(QH_SMASK)
1164 & qh->hw_info2) != 0) { 1164 & qh->hw_info2) != 0) {
1165 intr_deschedule(oxu, qh); 1165 intr_deschedule(oxu, qh);
1166 (void) qh_schedule(oxu, qh); 1166 (void) qh_schedule(oxu, qh);
@@ -1350,7 +1350,7 @@ static struct list_head *qh_urb_transaction(struct oxu_hcd *oxu,
1350 } 1350 }
1351 1351
1352 /* by default, enable interrupt on urb completion */ 1352 /* by default, enable interrupt on urb completion */
1353 qtd->hw_token |= __constant_cpu_to_le32(QTD_IOC); 1353 qtd->hw_token |= cpu_to_le32(QTD_IOC);
1354 return head; 1354 return head;
1355 1355
1356cleanup: 1356cleanup:
@@ -1539,7 +1539,7 @@ static void qh_link_async(struct oxu_hcd *oxu, struct ehci_qh *qh)
1539 /* qtd completions reported later by interrupt */ 1539 /* qtd completions reported later by interrupt */
1540} 1540}
1541 1541
1542#define QH_ADDR_MASK __constant_cpu_to_le32(0x7f) 1542#define QH_ADDR_MASK cpu_to_le32(0x7f)
1543 1543
1544/* 1544/*
1545 * For control/bulk/interrupt, return QH with these TDs appended. 1545 * For control/bulk/interrupt, return QH with these TDs appended.
@@ -2012,7 +2012,7 @@ static void qh_unlink_periodic(struct oxu_hcd *oxu, struct ehci_qh *qh)
2012 * and this qh is active in the current uframe 2012 * and this qh is active in the current uframe
2013 * (and overlay token SplitXstate is false?) 2013 * (and overlay token SplitXstate is false?)
2014 * THEN 2014 * THEN
2015 * qh->hw_info1 |= __constant_cpu_to_le32(1 << 7 "ignore"); 2015 * qh->hw_info1 |= cpu_to_le32(1 << 7 "ignore");
2016 */ 2016 */
2017 2017
2018 /* high bandwidth, or otherwise part of every microframe */ 2018 /* high bandwidth, or otherwise part of every microframe */
@@ -2057,7 +2057,7 @@ static void intr_deschedule(struct oxu_hcd *oxu, struct ehci_qh *qh)
2057 * active high speed queues may need bigger delays... 2057 * active high speed queues may need bigger delays...
2058 */ 2058 */
2059 if (list_empty(&qh->qtd_list) 2059 if (list_empty(&qh->qtd_list)
2060 || (__constant_cpu_to_le32(QH_CMASK) & qh->hw_info2) != 0) 2060 || (cpu_to_le32(QH_CMASK) & qh->hw_info2) != 0)
2061 wait = 2; 2061 wait = 2;
2062 else 2062 else
2063 wait = 55; /* worst case: 3 * 1024 */ 2063 wait = 55; /* worst case: 3 * 1024 */
@@ -2183,10 +2183,10 @@ static int qh_schedule(struct oxu_hcd *oxu, struct ehci_qh *qh)
2183 qh->start = frame; 2183 qh->start = frame;
2184 2184
2185 /* reset S-frame and (maybe) C-frame masks */ 2185 /* reset S-frame and (maybe) C-frame masks */
2186 qh->hw_info2 &= __constant_cpu_to_le32(~(QH_CMASK | QH_SMASK)); 2186 qh->hw_info2 &= cpu_to_le32(~(QH_CMASK | QH_SMASK));
2187 qh->hw_info2 |= qh->period 2187 qh->hw_info2 |= qh->period
2188 ? cpu_to_le32(1 << uframe) 2188 ? cpu_to_le32(1 << uframe)
2189 : __constant_cpu_to_le32(QH_SMASK); 2189 : cpu_to_le32(QH_SMASK);
2190 qh->hw_info2 |= c_mask; 2190 qh->hw_info2 |= c_mask;
2191 } else 2191 } else
2192 oxu_dbg(oxu, "reused qh %p schedule\n", qh); 2192 oxu_dbg(oxu, "reused qh %p schedule\n", qh);
@@ -2684,7 +2684,7 @@ static int oxu_reset(struct usb_hcd *hcd)
2684 oxu->urb_len = 0; 2684 oxu->urb_len = 0;
2685 2685
2686 /* FIMXE */ 2686 /* FIMXE */
2687 hcd->self.controller->dma_mask = 0UL; 2687 hcd->self.controller->dma_mask = NULL;
2688 2688
2689 if (oxu->is_otg) { 2689 if (oxu->is_otg) {
2690 oxu->caps = hcd->regs + OXU_OTG_CAP_OFFSET; 2690 oxu->caps = hcd->regs + OXU_OTG_CAP_OFFSET;
diff --git a/drivers/usb/host/oxu210hp.h b/drivers/usb/host/oxu210hp.h
index 8910e271cc7d..1c216ad9aad2 100644
--- a/drivers/usb/host/oxu210hp.h
+++ b/drivers/usb/host/oxu210hp.h
@@ -235,21 +235,21 @@ struct ehci_qtd {
235} __attribute__ ((aligned(32))); 235} __attribute__ ((aligned(32)));
236 236
237/* mask NakCnt+T in qh->hw_alt_next */ 237/* mask NakCnt+T in qh->hw_alt_next */
238#define QTD_MASK __constant_cpu_to_le32 (~0x1f) 238#define QTD_MASK cpu_to_le32 (~0x1f)
239 239
240#define IS_SHORT_READ(token) (QTD_LENGTH(token) != 0 && QTD_PID(token) == 1) 240#define IS_SHORT_READ(token) (QTD_LENGTH(token) != 0 && QTD_PID(token) == 1)
241 241
242/* Type tag from {qh, itd, sitd, fstn}->hw_next */ 242/* Type tag from {qh, itd, sitd, fstn}->hw_next */
243#define Q_NEXT_TYPE(dma) ((dma) & __constant_cpu_to_le32 (3 << 1)) 243#define Q_NEXT_TYPE(dma) ((dma) & cpu_to_le32 (3 << 1))
244 244
245/* values for that type tag */ 245/* values for that type tag */
246#define Q_TYPE_QH __constant_cpu_to_le32 (1 << 1) 246#define Q_TYPE_QH cpu_to_le32 (1 << 1)
247 247
248/* next async queue entry, or pointer to interrupt/periodic QH */ 248/* next async queue entry, or pointer to interrupt/periodic QH */
249#define QH_NEXT(dma) (cpu_to_le32(((u32)dma)&~0x01f)|Q_TYPE_QH) 249#define QH_NEXT(dma) (cpu_to_le32(((u32)dma)&~0x01f)|Q_TYPE_QH)
250 250
251/* for periodic/async schedules and qtd lists, mark end of list */ 251/* for periodic/async schedules and qtd lists, mark end of list */
252#define EHCI_LIST_END __constant_cpu_to_le32(1) /* "null pointer" to hw */ 252#define EHCI_LIST_END cpu_to_le32(1) /* "null pointer" to hw */
253 253
254/* 254/*
255 * Entries in periodic shadow table are pointers to one of four kinds 255 * Entries in periodic shadow table are pointers to one of four kinds
diff --git a/drivers/usb/host/pci-quirks.c b/drivers/usb/host/pci-quirks.c
index 75b69847918e..033c2846ce59 100644
--- a/drivers/usb/host/pci-quirks.c
+++ b/drivers/usb/host/pci-quirks.c
@@ -234,7 +234,7 @@ static void __devinit quirk_usb_disable_ehci(struct pci_dev *pdev)
234 */ 234 */
235 hcc_params = readl(base + EHCI_HCC_PARAMS); 235 hcc_params = readl(base + EHCI_HCC_PARAMS);
236 offset = (hcc_params >> 8) & 0xff; 236 offset = (hcc_params >> 8) & 0xff;
237 while (offset && count--) { 237 while (offset && --count) {
238 u32 cap; 238 u32 cap;
239 int msec; 239 int msec;
240 240
diff --git a/drivers/usb/host/r8a66597-hcd.c b/drivers/usb/host/r8a66597-hcd.c
index 319041205b57..f1626e58c141 100644
--- a/drivers/usb/host/r8a66597-hcd.c
+++ b/drivers/usb/host/r8a66597-hcd.c
@@ -660,9 +660,9 @@ static u16 get_empty_pipenum(struct r8a66597 *r8a66597,
660 u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min; 660 u16 array[R8A66597_MAX_NUM_PIPE], i = 0, min;
661 661
662 memset(array, 0, sizeof(array)); 662 memset(array, 0, sizeof(array));
663 switch (ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { 663 switch (usb_endpoint_type(ep)) {
664 case USB_ENDPOINT_XFER_BULK: 664 case USB_ENDPOINT_XFER_BULK:
665 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 665 if (usb_endpoint_dir_in(ep))
666 array[i++] = 4; 666 array[i++] = 4;
667 else { 667 else {
668 array[i++] = 3; 668 array[i++] = 3;
@@ -670,7 +670,7 @@ static u16 get_empty_pipenum(struct r8a66597 *r8a66597,
670 } 670 }
671 break; 671 break;
672 case USB_ENDPOINT_XFER_INT: 672 case USB_ENDPOINT_XFER_INT:
673 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) { 673 if (usb_endpoint_dir_in(ep)) {
674 array[i++] = 6; 674 array[i++] = 6;
675 array[i++] = 7; 675 array[i++] = 7;
676 array[i++] = 8; 676 array[i++] = 8;
@@ -678,7 +678,7 @@ static u16 get_empty_pipenum(struct r8a66597 *r8a66597,
678 array[i++] = 9; 678 array[i++] = 9;
679 break; 679 break;
680 case USB_ENDPOINT_XFER_ISOC: 680 case USB_ENDPOINT_XFER_ISOC:
681 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 681 if (usb_endpoint_dir_in(ep))
682 array[i++] = 2; 682 array[i++] = 2;
683 else 683 else
684 array[i++] = 1; 684 array[i++] = 1;
@@ -928,10 +928,9 @@ static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb,
928 928
929 info.pipenum = get_empty_pipenum(r8a66597, ep); 929 info.pipenum = get_empty_pipenum(r8a66597, ep);
930 info.address = get_urb_to_r8a66597_addr(r8a66597, urb); 930 info.address = get_urb_to_r8a66597_addr(r8a66597, urb);
931 info.epnum = ep->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK; 931 info.epnum = usb_endpoint_num(ep);
932 info.maxpacket = le16_to_cpu(ep->wMaxPacketSize); 932 info.maxpacket = le16_to_cpu(ep->wMaxPacketSize);
933 info.type = get_r8a66597_type(ep->bmAttributes 933 info.type = get_r8a66597_type(usb_endpoint_type(ep));
934 & USB_ENDPOINT_XFERTYPE_MASK);
935 info.bufnum = get_bufnum(info.pipenum); 934 info.bufnum = get_bufnum(info.pipenum);
936 info.buf_bsize = get_buf_bsize(info.pipenum); 935 info.buf_bsize = get_buf_bsize(info.pipenum);
937 if (info.type == R8A66597_BULK) { 936 if (info.type == R8A66597_BULK) {
@@ -941,7 +940,7 @@ static void init_pipe_info(struct r8a66597 *r8a66597, struct urb *urb,
941 info.interval = get_interval(urb, ep->bInterval); 940 info.interval = get_interval(urb, ep->bInterval);
942 info.timer_interval = get_timer_interval(urb, ep->bInterval); 941 info.timer_interval = get_timer_interval(urb, ep->bInterval);
943 } 942 }
944 if (ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) 943 if (usb_endpoint_dir_in(ep))
945 info.dir_in = 1; 944 info.dir_in = 1;
946 else 945 else
947 info.dir_in = 0; 946 info.dir_in = 0;
@@ -1014,6 +1013,9 @@ static void r8a66597_check_syssts(struct r8a66597 *r8a66597, int port,
1014 1013
1015 r8a66597_write(r8a66597, ~DTCH, get_intsts_reg(port)); 1014 r8a66597_write(r8a66597, ~DTCH, get_intsts_reg(port));
1016 r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port)); 1015 r8a66597_bset(r8a66597, DTCHE, get_intenb_reg(port));
1016
1017 if (r8a66597->bus_suspended)
1018 usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597));
1017} 1019}
1018 1020
1019/* this function must be called with interrupt disabled */ 1021/* this function must be called with interrupt disabled */
@@ -1395,7 +1397,7 @@ static void packet_write(struct r8a66597 *r8a66597, u16 pipenum)
1395 (int)urb->iso_frame_desc[td->iso_cnt].length); 1397 (int)urb->iso_frame_desc[td->iso_cnt].length);
1396 } else { 1398 } else {
1397 buf = (u16 *)(urb->transfer_buffer + urb->actual_length); 1399 buf = (u16 *)(urb->transfer_buffer + urb->actual_length);
1398 size = min((int)bufsize, 1400 size = min_t(u32, bufsize,
1399 urb->transfer_buffer_length - urb->actual_length); 1401 urb->transfer_buffer_length - urb->actual_length);
1400 } 1402 }
1401 1403
@@ -1615,6 +1617,11 @@ static irqreturn_t r8a66597_irq(struct usb_hcd *hcd)
1615 r8a66597_bclr(r8a66597, DTCHE, INTENB2); 1617 r8a66597_bclr(r8a66597, DTCHE, INTENB2);
1616 r8a66597_usb_disconnect(r8a66597, 1); 1618 r8a66597_usb_disconnect(r8a66597, 1);
1617 } 1619 }
1620 if (mask2 & BCHG) {
1621 r8a66597_write(r8a66597, ~BCHG, INTSTS2);
1622 r8a66597_bclr(r8a66597, BCHGE, INTENB2);
1623 usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597));
1624 }
1618 } 1625 }
1619 1626
1620 if (mask1) { 1627 if (mask1) {
@@ -1630,6 +1637,12 @@ static irqreturn_t r8a66597_irq(struct usb_hcd *hcd)
1630 r8a66597_bclr(r8a66597, DTCHE, INTENB1); 1637 r8a66597_bclr(r8a66597, DTCHE, INTENB1);
1631 r8a66597_usb_disconnect(r8a66597, 0); 1638 r8a66597_usb_disconnect(r8a66597, 0);
1632 } 1639 }
1640 if (mask1 & BCHG) {
1641 r8a66597_write(r8a66597, ~BCHG, INTSTS1);
1642 r8a66597_bclr(r8a66597, BCHGE, INTENB1);
1643 usb_hcd_resume_root_hub(r8a66597_to_hcd(r8a66597));
1644 }
1645
1633 if (mask1 & SIGN) { 1646 if (mask1 & SIGN) {
1634 r8a66597_write(r8a66597, ~SIGN, INTSTS1); 1647 r8a66597_write(r8a66597, ~SIGN, INTSTS1);
1635 status = get_urb_error(r8a66597, 0); 1648 status = get_urb_error(r8a66597, 0);
@@ -2141,7 +2154,7 @@ static int r8a66597_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
2141 2154
2142 switch (wValue) { 2155 switch (wValue) {
2143 case USB_PORT_FEAT_ENABLE: 2156 case USB_PORT_FEAT_ENABLE:
2144 rh->port &= (1 << USB_PORT_FEAT_POWER); 2157 rh->port &= ~(1 << USB_PORT_FEAT_POWER);
2145 break; 2158 break;
2146 case USB_PORT_FEAT_SUSPEND: 2159 case USB_PORT_FEAT_SUSPEND:
2147 break; 2160 break;
@@ -2213,6 +2226,68 @@ error:
2213 return ret; 2226 return ret;
2214} 2227}
2215 2228
2229#if defined(CONFIG_PM)
2230static int r8a66597_bus_suspend(struct usb_hcd *hcd)
2231{
2232 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
2233 int port;
2234
2235 dbg("%s", __func__);
2236
2237 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) {
2238 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
2239 unsigned long dvstctr_reg = get_dvstctr_reg(port);
2240
2241 if (!(rh->port & (1 << USB_PORT_FEAT_ENABLE)))
2242 continue;
2243
2244 dbg("suspend port = %d", port);
2245 r8a66597_bclr(r8a66597, UACT, dvstctr_reg); /* suspend */
2246 rh->port |= 1 << USB_PORT_FEAT_SUSPEND;
2247
2248 if (rh->dev->udev->do_remote_wakeup) {
2249 msleep(3); /* waiting last SOF */
2250 r8a66597_bset(r8a66597, RWUPE, dvstctr_reg);
2251 r8a66597_write(r8a66597, ~BCHG, get_intsts_reg(port));
2252 r8a66597_bset(r8a66597, BCHGE, get_intenb_reg(port));
2253 }
2254 }
2255
2256 r8a66597->bus_suspended = 1;
2257
2258 return 0;
2259}
2260
2261static int r8a66597_bus_resume(struct usb_hcd *hcd)
2262{
2263 struct r8a66597 *r8a66597 = hcd_to_r8a66597(hcd);
2264 int port;
2265
2266 dbg("%s", __func__);
2267
2268 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) {
2269 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
2270 unsigned long dvstctr_reg = get_dvstctr_reg(port);
2271
2272 if (!(rh->port & (1 << USB_PORT_FEAT_SUSPEND)))
2273 continue;
2274
2275 dbg("resume port = %d", port);
2276 rh->port &= ~(1 << USB_PORT_FEAT_SUSPEND);
2277 rh->port |= 1 << USB_PORT_FEAT_C_SUSPEND;
2278 r8a66597_mdfy(r8a66597, RESUME, RESUME | UACT, dvstctr_reg);
2279 msleep(50);
2280 r8a66597_mdfy(r8a66597, UACT, RESUME | UACT, dvstctr_reg);
2281 }
2282
2283 return 0;
2284
2285}
2286#else
2287#define r8a66597_bus_suspend NULL
2288#define r8a66597_bus_resume NULL
2289#endif
2290
2216static struct hc_driver r8a66597_hc_driver = { 2291static struct hc_driver r8a66597_hc_driver = {
2217 .description = hcd_name, 2292 .description = hcd_name,
2218 .hcd_priv_size = sizeof(struct r8a66597), 2293 .hcd_priv_size = sizeof(struct r8a66597),
@@ -2243,16 +2318,39 @@ static struct hc_driver r8a66597_hc_driver = {
2243 */ 2318 */
2244 .hub_status_data = r8a66597_hub_status_data, 2319 .hub_status_data = r8a66597_hub_status_data,
2245 .hub_control = r8a66597_hub_control, 2320 .hub_control = r8a66597_hub_control,
2321 .bus_suspend = r8a66597_bus_suspend,
2322 .bus_resume = r8a66597_bus_resume,
2246}; 2323};
2247 2324
2248#if defined(CONFIG_PM) 2325#if defined(CONFIG_PM)
2249static int r8a66597_suspend(struct platform_device *pdev, pm_message_t state) 2326static int r8a66597_suspend(struct platform_device *pdev, pm_message_t state)
2250{ 2327{
2328 struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev);
2329 int port;
2330
2331 dbg("%s", __func__);
2332
2333 disable_controller(r8a66597);
2334
2335 for (port = 0; port < R8A66597_MAX_ROOT_HUB; port++) {
2336 struct r8a66597_root_hub *rh = &r8a66597->root_hub[port];
2337
2338 rh->port = 0x00000000;
2339 }
2340
2251 return 0; 2341 return 0;
2252} 2342}
2253 2343
2254static int r8a66597_resume(struct platform_device *pdev) 2344static int r8a66597_resume(struct platform_device *pdev)
2255{ 2345{
2346 struct r8a66597 *r8a66597 = dev_get_drvdata(&pdev->dev);
2347 struct usb_hcd *hcd = r8a66597_to_hcd(r8a66597);
2348
2349 dbg("%s", __func__);
2350
2351 enable_controller(r8a66597);
2352 usb_root_hub_lost_power(hcd->self.root_hub);
2353
2256 return 0; 2354 return 0;
2257} 2355}
2258#else /* if defined(CONFIG_PM) */ 2356#else /* if defined(CONFIG_PM) */
diff --git a/drivers/usb/host/r8a66597.h b/drivers/usb/host/r8a66597.h
index ecacde4d69b0..f49208f1bb74 100644
--- a/drivers/usb/host/r8a66597.h
+++ b/drivers/usb/host/r8a66597.h
@@ -504,6 +504,8 @@ struct r8a66597 {
504 504
505 struct list_head child_device; 505 struct list_head child_device;
506 unsigned long child_connect_map[4]; 506 unsigned long child_connect_map[4];
507
508 unsigned bus_suspended:1;
507}; 509};
508 510
509static inline struct r8a66597 *hcd_to_r8a66597(struct usb_hcd *hcd) 511static inline struct r8a66597 *hcd_to_r8a66597(struct usb_hcd *hcd)
diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c
index e106e9d48d4a..a949259f18b9 100644
--- a/drivers/usb/host/sl811-hcd.c
+++ b/drivers/usb/host/sl811-hcd.c
@@ -230,7 +230,7 @@ static void in_packet(
230 writeb(usb_pipedevice(urb->pipe), data_reg); 230 writeb(usb_pipedevice(urb->pipe), data_reg);
231 231
232 sl811_write(sl811, bank + SL11H_HOSTCTLREG, control); 232 sl811_write(sl811, bank + SL11H_HOSTCTLREG, control);
233 ep->length = min((int)len, 233 ep->length = min_t(u32, len,
234 urb->transfer_buffer_length - urb->actual_length); 234 urb->transfer_buffer_length - urb->actual_length);
235 PACKET("IN%s/%d qh%p len%d\n", ep->nak_count ? "/retry" : "", 235 PACKET("IN%s/%d qh%p len%d\n", ep->nak_count ? "/retry" : "",
236 !!usb_gettoggle(urb->dev, ep->epnum, 0), ep, len); 236 !!usb_gettoggle(urb->dev, ep->epnum, 0), ep, len);
@@ -255,7 +255,7 @@ static void out_packet(
255 buf = urb->transfer_buffer + urb->actual_length; 255 buf = urb->transfer_buffer + urb->actual_length;
256 prefetch(buf); 256 prefetch(buf);
257 257
258 len = min((int)ep->maxpacket, 258 len = min_t(u32, ep->maxpacket,
259 urb->transfer_buffer_length - urb->actual_length); 259 urb->transfer_buffer_length - urb->actual_length);
260 260
261 if (!(control & SL11H_HCTLMASK_ISOCH) 261 if (!(control & SL11H_HCTLMASK_ISOCH)
diff --git a/drivers/usb/host/uhci-debug.c b/drivers/usb/host/uhci-debug.c
index 20cc58b97807..e52b954dda47 100644
--- a/drivers/usb/host/uhci-debug.c
+++ b/drivers/usb/host/uhci-debug.c
@@ -118,7 +118,9 @@ static int uhci_show_urbp(struct urb_priv *urbp, char *buf, int len, int space)
118 } 118 }
119 119
120 out += sprintf(out, "%s%s", ptype, (urbp->fsbr ? " FSBR" : "")); 120 out += sprintf(out, "%s%s", ptype, (urbp->fsbr ? " FSBR" : ""));
121 out += sprintf(out, " Actlen=%d", urbp->urb->actual_length); 121 out += sprintf(out, " Actlen=%d%s", urbp->urb->actual_length,
122 (urbp->qh->type == USB_ENDPOINT_XFER_CONTROL ?
123 "-8" : ""));
122 124
123 if (urbp->urb->unlinked) 125 if (urbp->urb->unlinked)
124 out += sprintf(out, " Unlinked=%d", urbp->urb->unlinked); 126 out += sprintf(out, " Unlinked=%d", urbp->urb->unlinked);
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h
index 7d01c5677f92..26bd1b2bcbfc 100644
--- a/drivers/usb/host/uhci-hcd.h
+++ b/drivers/usb/host/uhci-hcd.h
@@ -73,11 +73,11 @@
73#define USBLEGSUP_RWC 0x8f00 /* the R/WC bits */ 73#define USBLEGSUP_RWC 0x8f00 /* the R/WC bits */
74#define USBLEGSUP_RO 0x5040 /* R/O and reserved bits */ 74#define USBLEGSUP_RO 0x5040 /* R/O and reserved bits */
75 75
76#define UHCI_PTR_BITS __constant_cpu_to_le32(0x000F) 76#define UHCI_PTR_BITS cpu_to_le32(0x000F)
77#define UHCI_PTR_TERM __constant_cpu_to_le32(0x0001) 77#define UHCI_PTR_TERM cpu_to_le32(0x0001)
78#define UHCI_PTR_QH __constant_cpu_to_le32(0x0002) 78#define UHCI_PTR_QH cpu_to_le32(0x0002)
79#define UHCI_PTR_DEPTH __constant_cpu_to_le32(0x0004) 79#define UHCI_PTR_DEPTH cpu_to_le32(0x0004)
80#define UHCI_PTR_BREADTH __constant_cpu_to_le32(0x0000) 80#define UHCI_PTR_BREADTH cpu_to_le32(0x0000)
81 81
82#define UHCI_NUMFRAMES 1024 /* in the frame list [array] */ 82#define UHCI_NUMFRAMES 1024 /* in the frame list [array] */
83#define UHCI_MAX_SOF_NUMBER 2047 /* in an SOF packet */ 83#define UHCI_MAX_SOF_NUMBER 2047 /* in an SOF packet */
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index 5631d89c8730..3e5807d14ffb 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -402,7 +402,7 @@ static void uhci_fixup_toggles(struct uhci_qh *qh, int skip_first)
402 /* Otherwise all the toggles in the URB have to be switched */ 402 /* Otherwise all the toggles in the URB have to be switched */
403 } else { 403 } else {
404 list_for_each_entry(td, &urbp->td_list, list) { 404 list_for_each_entry(td, &urbp->td_list, list) {
405 td->token ^= __constant_cpu_to_le32( 405 td->token ^= cpu_to_le32(
406 TD_TOKEN_TOGGLE); 406 TD_TOKEN_TOGGLE);
407 toggle ^= 1; 407 toggle ^= 1;
408 } 408 }
@@ -883,7 +883,7 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
883 883
884 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); 884 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0);
885 wmb(); 885 wmb();
886 qh->dummy_td->status |= __constant_cpu_to_le32(TD_CTRL_ACTIVE); 886 qh->dummy_td->status |= cpu_to_le32(TD_CTRL_ACTIVE);
887 qh->dummy_td = td; 887 qh->dummy_td = td;
888 888
889 /* Low-speed transfers get a different queue, and won't hog the bus. 889 /* Low-speed transfers get a different queue, and won't hog the bus.
@@ -899,8 +899,6 @@ static int uhci_submit_control(struct uhci_hcd *uhci, struct urb *urb,
899 } 899 }
900 if (qh->state != QH_STATE_ACTIVE) 900 if (qh->state != QH_STATE_ACTIVE)
901 qh->skel = skel; 901 qh->skel = skel;
902
903 urb->actual_length = -8; /* Account for the SETUP packet */
904 return 0; 902 return 0;
905 903
906nomem: 904nomem:
@@ -1003,7 +1001,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb,
1003 * fast side but not enough to justify delaying an interrupt 1001 * fast side but not enough to justify delaying an interrupt
1004 * more than 2 or 3 URBs, so we will ignore the URB_NO_INTERRUPT 1002 * more than 2 or 3 URBs, so we will ignore the URB_NO_INTERRUPT
1005 * flag setting. */ 1003 * flag setting. */
1006 td->status |= __constant_cpu_to_le32(TD_CTRL_IOC); 1004 td->status |= cpu_to_le32(TD_CTRL_IOC);
1007 1005
1008 /* 1006 /*
1009 * Build the new dummy TD and activate the old one 1007 * Build the new dummy TD and activate the old one
@@ -1015,7 +1013,7 @@ static int uhci_submit_common(struct uhci_hcd *uhci, struct urb *urb,
1015 1013
1016 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0); 1014 uhci_fill_td(td, 0, USB_PID_OUT | uhci_explen(0), 0);
1017 wmb(); 1015 wmb();
1018 qh->dummy_td->status |= __constant_cpu_to_le32(TD_CTRL_ACTIVE); 1016 qh->dummy_td->status |= cpu_to_le32(TD_CTRL_ACTIVE);
1019 qh->dummy_td = td; 1017 qh->dummy_td = td;
1020 1018
1021 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), 1019 usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
@@ -1317,7 +1315,7 @@ static int uhci_submit_isochronous(struct uhci_hcd *uhci, struct urb *urb,
1317 } 1315 }
1318 1316
1319 /* Set the interrupt-on-completion flag on the last packet. */ 1317 /* Set the interrupt-on-completion flag on the last packet. */
1320 td->status |= __constant_cpu_to_le32(TD_CTRL_IOC); 1318 td->status |= cpu_to_le32(TD_CTRL_IOC);
1321 1319
1322 /* Add the TDs to the frame list */ 1320 /* Add the TDs to the frame list */
1323 frame = urb->start_frame; 1321 frame = urb->start_frame;
@@ -1494,11 +1492,10 @@ __acquires(uhci->lock)
1494 1492
1495 if (qh->type == USB_ENDPOINT_XFER_CONTROL) { 1493 if (qh->type == USB_ENDPOINT_XFER_CONTROL) {
1496 1494
1497 /* urb->actual_length < 0 means the setup transaction didn't 1495 /* Subtract off the length of the SETUP packet from
1498 * complete successfully. Either it failed or the URB was 1496 * urb->actual_length.
1499 * unlinked first. Regardless, don't confuse people with a 1497 */
1500 * negative length. */ 1498 urb->actual_length -= min_t(u32, 8, urb->actual_length);
1501 urb->actual_length = max(urb->actual_length, 0);
1502 } 1499 }
1503 1500
1504 /* When giving back the first URB in an Isochronous queue, 1501 /* When giving back the first URB in an Isochronous queue,
diff --git a/drivers/usb/image/mdc800.c b/drivers/usb/image/mdc800.c
index 972f20b3406c..eca355dccf65 100644
--- a/drivers/usb/image/mdc800.c
+++ b/drivers/usb/image/mdc800.c
@@ -188,7 +188,7 @@ static struct usb_endpoint_descriptor mdc800_ed [4] =
188 .bDescriptorType = 0, 188 .bDescriptorType = 0,
189 .bEndpointAddress = 0x01, 189 .bEndpointAddress = 0x01,
190 .bmAttributes = 0x02, 190 .bmAttributes = 0x02,
191 .wMaxPacketSize = __constant_cpu_to_le16(8), 191 .wMaxPacketSize = cpu_to_le16(8),
192 .bInterval = 0, 192 .bInterval = 0,
193 .bRefresh = 0, 193 .bRefresh = 0,
194 .bSynchAddress = 0, 194 .bSynchAddress = 0,
@@ -198,7 +198,7 @@ static struct usb_endpoint_descriptor mdc800_ed [4] =
198 .bDescriptorType = 0, 198 .bDescriptorType = 0,
199 .bEndpointAddress = 0x82, 199 .bEndpointAddress = 0x82,
200 .bmAttributes = 0x03, 200 .bmAttributes = 0x03,
201 .wMaxPacketSize = __constant_cpu_to_le16(8), 201 .wMaxPacketSize = cpu_to_le16(8),
202 .bInterval = 0, 202 .bInterval = 0,
203 .bRefresh = 0, 203 .bRefresh = 0,
204 .bSynchAddress = 0, 204 .bSynchAddress = 0,
@@ -208,7 +208,7 @@ static struct usb_endpoint_descriptor mdc800_ed [4] =
208 .bDescriptorType = 0, 208 .bDescriptorType = 0,
209 .bEndpointAddress = 0x03, 209 .bEndpointAddress = 0x03,
210 .bmAttributes = 0x02, 210 .bmAttributes = 0x02,
211 .wMaxPacketSize = __constant_cpu_to_le16(64), 211 .wMaxPacketSize = cpu_to_le16(64),
212 .bInterval = 0, 212 .bInterval = 0,
213 .bRefresh = 0, 213 .bRefresh = 0,
214 .bSynchAddress = 0, 214 .bSynchAddress = 0,
@@ -218,7 +218,7 @@ static struct usb_endpoint_descriptor mdc800_ed [4] =
218 .bDescriptorType = 0, 218 .bDescriptorType = 0,
219 .bEndpointAddress = 0x84, 219 .bEndpointAddress = 0x84,
220 .bmAttributes = 0x02, 220 .bmAttributes = 0x02,
221 .wMaxPacketSize = __constant_cpu_to_le16(64), 221 .wMaxPacketSize = cpu_to_le16(64),
222 .bInterval = 0, 222 .bInterval = 0,
223 .bRefresh = 0, 223 .bRefresh = 0,
224 .bSynchAddress = 0, 224 .bSynchAddress = 0,
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index e463db5d8188..a68d91a11bee 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -135,45 +135,6 @@ config USB_CYTHERM
135 To compile this driver as a module, choose M here: the 135 To compile this driver as a module, choose M here: the
136 module will be called cytherm. 136 module will be called cytherm.
137 137
138config USB_PHIDGET
139 tristate "USB Phidgets drivers"
140 depends on USB
141 help
142 Say Y here to enable the various drivers for devices from
143 Phidgets inc.
144
145config USB_PHIDGETKIT
146 tristate "USB PhidgetInterfaceKit support"
147 depends on USB_PHIDGET
148 help
149 Say Y here if you want to connect a PhidgetInterfaceKit USB device
150 from Phidgets Inc.
151
152 To compile this driver as a module, choose M here: the
153 module will be called phidgetkit.
154
155config USB_PHIDGETMOTORCONTROL
156 tristate "USB PhidgetMotorControl support"
157 depends on USB_PHIDGET
158 help
159 Say Y here if you want to connect a PhidgetMotorControl USB device
160 from Phidgets Inc.
161
162 To compile this driver as a module, choose M here: the
163 module will be called phidgetmotorcontrol.
164
165config USB_PHIDGETSERVO
166 tristate "USB PhidgetServo support"
167 depends on USB_PHIDGET
168 help
169 Say Y here if you want to connect an 1 or 4 Motor PhidgetServo
170 servo controller version 2.0 or 3.0.
171
172 Phidgets Inc. has a web page at <http://www.phidgets.com/>.
173
174 To compile this driver as a module, choose M here: the
175 module will be called phidgetservo.
176
177config USB_IDMOUSE 138config USB_IDMOUSE
178 tristate "Siemens ID USB Mouse Fingerprint sensor support" 139 tristate "Siemens ID USB Mouse Fingerprint sensor support"
179 depends on USB 140 depends on USB
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index 1334f7bdd7be..0826aab8303f 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -18,10 +18,6 @@ obj-$(CONFIG_USB_LCD) += usblcd.o
18obj-$(CONFIG_USB_LD) += ldusb.o 18obj-$(CONFIG_USB_LD) += ldusb.o
19obj-$(CONFIG_USB_LED) += usbled.o 19obj-$(CONFIG_USB_LED) += usbled.o
20obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o 20obj-$(CONFIG_USB_LEGOTOWER) += legousbtower.o
21obj-$(CONFIG_USB_PHIDGET) += phidget.o
22obj-$(CONFIG_USB_PHIDGETKIT) += phidgetkit.o
23obj-$(CONFIG_USB_PHIDGETMOTORCONTROL) += phidgetmotorcontrol.o
24obj-$(CONFIG_USB_PHIDGETSERVO) += phidgetservo.o
25obj-$(CONFIG_USB_RIO500) += rio500.o 21obj-$(CONFIG_USB_RIO500) += rio500.o
26obj-$(CONFIG_USB_TEST) += usbtest.o 22obj-$(CONFIG_USB_TEST) += usbtest.o
27obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o 23obj-$(CONFIG_USB_TRANCEVIBRATOR) += trancevibrator.o
diff --git a/drivers/usb/misc/ftdi-elan.c b/drivers/usb/misc/ftdi-elan.c
index 79a7668ef264..9d0675ed0d4c 100644
--- a/drivers/usb/misc/ftdi-elan.c
+++ b/drivers/usb/misc/ftdi-elan.c
@@ -1568,7 +1568,7 @@ static int ftdi_elan_edset_input(struct usb_ftdi *ftdi, u8 ed_number,
1568 struct u132_target *target = &ftdi->target[ed]; 1568 struct u132_target *target = &ftdi->target[ed];
1569 struct u132_command *command = &ftdi->command[ 1569 struct u132_command *command = &ftdi->command[
1570 COMMAND_MASK & ftdi->command_next]; 1570 COMMAND_MASK & ftdi->command_next];
1571 int remaining_length = urb->transfer_buffer_length - 1571 u32 remaining_length = urb->transfer_buffer_length -
1572 urb->actual_length; 1572 urb->actual_length;
1573 command->header = 0x82 | (ed << 5); 1573 command->header = 0x82 | (ed << 5);
1574 if (remaining_length == 0) { 1574 if (remaining_length == 0) {
@@ -1702,7 +1702,7 @@ static int ftdi_elan_edset_output(struct usb_ftdi *ftdi, u8 ed_number,
1702 | (address << 0); 1702 | (address << 0);
1703 command->width = usb_maxpacket(urb->dev, urb->pipe, 1703 command->width = usb_maxpacket(urb->dev, urb->pipe,
1704 usb_pipeout(urb->pipe)); 1704 usb_pipeout(urb->pipe));
1705 command->follows = min(1024, 1705 command->follows = min_t(u32, 1024,
1706 urb->transfer_buffer_length - 1706 urb->transfer_buffer_length -
1707 urb->actual_length); 1707 urb->actual_length);
1708 command->value = 0; 1708 command->value = 0;
@@ -1766,7 +1766,7 @@ static int ftdi_elan_edset_single(struct usb_ftdi *ftdi, u8 ed_number,
1766 mutex_lock(&ftdi->u132_lock); 1766 mutex_lock(&ftdi->u132_lock);
1767 command_size = ftdi->command_next - ftdi->command_head; 1767 command_size = ftdi->command_next - ftdi->command_head;
1768 if (command_size < COMMAND_SIZE) { 1768 if (command_size < COMMAND_SIZE) {
1769 int remaining_length = urb->transfer_buffer_length - 1769 u32 remaining_length = urb->transfer_buffer_length -
1770 urb->actual_length; 1770 urb->actual_length;
1771 struct u132_target *target = &ftdi->target[ed]; 1771 struct u132_target *target = &ftdi->target[ed];
1772 struct u132_command *command = &ftdi->command[ 1772 struct u132_command *command = &ftdi->command[
diff --git a/drivers/usb/misc/phidget.c b/drivers/usb/misc/phidget.c
deleted file mode 100644
index 735ed33f4f7f..000000000000
--- a/drivers/usb/misc/phidget.c
+++ /dev/null
@@ -1,43 +0,0 @@
1/*
2 * USB Phidgets class
3 *
4 * Copyright (C) 2006 Sean Young <sean@mess.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/err.h>
16#include <linux/device.h>
17
18struct class *phidget_class;
19
20static int __init init_phidget(void)
21{
22 phidget_class = class_create(THIS_MODULE, "phidget");
23
24 if (IS_ERR(phidget_class))
25 return PTR_ERR(phidget_class);
26
27 return 0;
28}
29
30static void __exit cleanup_phidget(void)
31{
32 class_destroy(phidget_class);
33}
34
35EXPORT_SYMBOL_GPL(phidget_class);
36
37module_init(init_phidget);
38module_exit(cleanup_phidget);
39
40MODULE_LICENSE("GPL");
41MODULE_AUTHOR("Sean Young <sean@mess.org>");
42MODULE_DESCRIPTION("Container module for phidget class");
43
diff --git a/drivers/usb/misc/phidget.h b/drivers/usb/misc/phidget.h
deleted file mode 100644
index c4011907d431..000000000000
--- a/drivers/usb/misc/phidget.h
+++ /dev/null
@@ -1,12 +0,0 @@
1/*
2 * USB Phidgets class
3 *
4 * Copyright (C) 2006 Sean Young <sean@mess.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12extern struct class *phidget_class;
diff --git a/drivers/usb/misc/phidgetkit.c b/drivers/usb/misc/phidgetkit.c
deleted file mode 100644
index cc8e0a926f99..000000000000
--- a/drivers/usb/misc/phidgetkit.c
+++ /dev/null
@@ -1,740 +0,0 @@
1/*
2 * USB PhidgetInterfaceKit driver 1.0
3 *
4 * Copyright (C) 2004, 2006 Sean Young <sean@mess.org>
5 * Copyright (C) 2005 Daniel Saakes <daniel@saakes.net>
6 * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This is a driver for the USB PhidgetInterfaceKit.
14 */
15
16#include <linux/kernel.h>
17#include <linux/errno.h>
18#include <linux/init.h>
19#include <linux/slab.h>
20#include <linux/module.h>
21#include <linux/usb.h>
22
23#include "phidget.h"
24
25#define DRIVER_AUTHOR "Sean Young <sean@mess.org>"
26#define DRIVER_DESC "USB PhidgetInterfaceKit Driver"
27
28#define USB_VENDOR_ID_GLAB 0x06c2
29#define USB_DEVICE_ID_INTERFACEKIT004 0x0040
30#define USB_DEVICE_ID_INTERFACEKIT01616 0x0044
31#define USB_DEVICE_ID_INTERFACEKIT888 0x0045
32#define USB_DEVICE_ID_INTERFACEKIT047 0x0051
33#define USB_DEVICE_ID_INTERFACEKIT088 0x0053
34
35#define USB_VENDOR_ID_WISEGROUP 0x0925
36#define USB_DEVICE_ID_INTERFACEKIT884 0x8201
37
38#define MAX_INTERFACES 16
39
40#define URB_INT_SIZE 8
41
42struct driver_interfacekit {
43 int sensors;
44 int inputs;
45 int outputs;
46 int has_lcd;
47 int amnesiac;
48};
49
50#define ifkit(_sensors, _inputs, _outputs, _lcd, _amnesiac) \
51{ \
52 .sensors = _sensors, \
53 .inputs = _inputs, \
54 .outputs = _outputs, \
55 .has_lcd = _lcd, \
56 .amnesiac = _amnesiac \
57};
58
59static const struct driver_interfacekit ph_004 = ifkit(0, 0, 4, 0, 0);
60static const struct driver_interfacekit ph_888n = ifkit(8, 8, 8, 0, 1);
61static const struct driver_interfacekit ph_888o = ifkit(8, 8, 8, 0, 0);
62static const struct driver_interfacekit ph_047 = ifkit(0, 4, 7, 1, 0);
63static const struct driver_interfacekit ph_884 = ifkit(8, 8, 4, 0, 0);
64static const struct driver_interfacekit ph_088 = ifkit(0, 8, 8, 1, 0);
65static const struct driver_interfacekit ph_01616 = ifkit(0, 16, 16, 0, 0);
66
67static unsigned long device_no;
68
69struct interfacekit {
70 struct usb_device *udev;
71 struct usb_interface *intf;
72 struct driver_interfacekit *ifkit;
73 struct device *dev;
74 unsigned long outputs;
75 int dev_no;
76 u8 inputs[MAX_INTERFACES];
77 u16 sensors[MAX_INTERFACES];
78 u8 lcd_files_on;
79
80 struct urb *irq;
81 unsigned char *data;
82 dma_addr_t data_dma;
83
84 struct delayed_work do_notify;
85 struct delayed_work do_resubmit;
86 unsigned long input_events;
87 unsigned long sensor_events;
88};
89
90static struct usb_device_id id_table[] = {
91 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT004),
92 .driver_info = (kernel_ulong_t)&ph_004},
93 {USB_DEVICE_VER(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT888, 0, 0x814),
94 .driver_info = (kernel_ulong_t)&ph_888o},
95 {USB_DEVICE_VER(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT888, 0x0815, 0xffff),
96 .driver_info = (kernel_ulong_t)&ph_888n},
97 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT047),
98 .driver_info = (kernel_ulong_t)&ph_047},
99 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT088),
100 .driver_info = (kernel_ulong_t)&ph_088},
101 {USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_INTERFACEKIT01616),
102 .driver_info = (kernel_ulong_t)&ph_01616},
103 {USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_INTERFACEKIT884),
104 .driver_info = (kernel_ulong_t)&ph_884},
105 {}
106};
107MODULE_DEVICE_TABLE(usb, id_table);
108
109static int set_outputs(struct interfacekit *kit)
110{
111 u8 *buffer;
112 int retval;
113
114 buffer = kzalloc(4, GFP_KERNEL);
115 if (!buffer) {
116 dev_err(&kit->udev->dev, "%s - out of memory\n", __func__);
117 return -ENOMEM;
118 }
119 buffer[0] = (u8)kit->outputs;
120 buffer[1] = (u8)(kit->outputs >> 8);
121
122 dev_dbg(&kit->udev->dev, "sending data: 0x%04x\n", (u16)kit->outputs);
123
124 retval = usb_control_msg(kit->udev,
125 usb_sndctrlpipe(kit->udev, 0),
126 0x09, 0x21, 0x0200, 0x0000, buffer, 4, 2000);
127
128 if (retval != 4)
129 dev_err(&kit->udev->dev, "usb_control_msg returned %d\n",
130 retval);
131 kfree(buffer);
132
133 if (kit->ifkit->amnesiac)
134 schedule_delayed_work(&kit->do_resubmit, HZ / 2);
135
136 return retval < 0 ? retval : 0;
137}
138
139static int change_string(struct interfacekit *kit, const char *display, unsigned char row)
140{
141 unsigned char *buffer;
142 unsigned char *form_buffer;
143 int retval = -ENOMEM;
144 int i,j, len, buf_ptr;
145
146 buffer = kmalloc(8, GFP_KERNEL);
147 form_buffer = kmalloc(30, GFP_KERNEL);
148 if ((!buffer) || (!form_buffer)) {
149 dev_err(&kit->udev->dev, "%s - out of memory\n", __func__);
150 goto exit;
151 }
152
153 len = strlen(display);
154 if (len > 20)
155 len = 20;
156
157 dev_dbg(&kit->udev->dev, "Setting LCD line %d to %s\n", row, display);
158
159 form_buffer[0] = row * 0x40 + 0x80;
160 form_buffer[1] = 0x02;
161 buf_ptr = 2;
162 for (i = 0; i<len; i++)
163 form_buffer[buf_ptr++] = display[i];
164
165 for (i = 0; i < (20 - len); i++)
166 form_buffer[buf_ptr++] = 0x20;
167 form_buffer[buf_ptr++] = 0x01;
168 form_buffer[buf_ptr++] = row * 0x40 + 0x80 + strlen(display);
169
170 for (i = 0; i < buf_ptr; i += 7) {
171 if ((buf_ptr - i) > 7)
172 len = 7;
173 else
174 len = (buf_ptr - i);
175 for (j = 0; j < len; j++)
176 buffer[j] = form_buffer[i + j];
177 buffer[7] = len;
178
179 retval = usb_control_msg(kit->udev,
180 usb_sndctrlpipe(kit->udev, 0),
181 0x09, 0x21, 0x0200, 0x0000, buffer, 8, 2000);
182 if (retval < 0)
183 goto exit;
184 }
185
186 retval = 0;
187exit:
188 kfree(buffer);
189 kfree(form_buffer);
190
191 return retval;
192}
193
194#define set_lcd_line(number) \
195static ssize_t lcd_line_##number(struct device *dev, \
196 struct device_attribute *attr, \
197 const char *buf, size_t count) \
198{ \
199 struct interfacekit *kit = dev_get_drvdata(dev); \
200 change_string(kit, buf, number - 1); \
201 return count; \
202}
203
204#define lcd_line_attr(number) \
205 __ATTR(lcd_line_##number, S_IWUGO, NULL, lcd_line_##number)
206
207set_lcd_line(1);
208set_lcd_line(2);
209
210static ssize_t set_backlight(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
211{
212 struct interfacekit *kit = dev_get_drvdata(dev);
213 int enabled;
214 unsigned char *buffer;
215 int retval = -ENOMEM;
216
217 buffer = kzalloc(8, GFP_KERNEL);
218 if (!buffer) {
219 dev_err(&kit->udev->dev, "%s - out of memory\n", __func__);
220 goto exit;
221 }
222
223 if (sscanf(buf, "%d", &enabled) < 1) {
224 retval = -EINVAL;
225 goto exit;
226 }
227 if (enabled)
228 buffer[0] = 0x01;
229 buffer[7] = 0x11;
230
231 dev_dbg(&kit->udev->dev, "Setting backlight to %s\n", enabled ? "on" : "off");
232
233 retval = usb_control_msg(kit->udev,
234 usb_sndctrlpipe(kit->udev, 0),
235 0x09, 0x21, 0x0200, 0x0000, buffer, 8, 2000);
236 if (retval < 0)
237 goto exit;
238
239 retval = count;
240exit:
241 kfree(buffer);
242 return retval;
243}
244
245static struct device_attribute dev_lcd_line_attrs[] = {
246 lcd_line_attr(1),
247 lcd_line_attr(2),
248 __ATTR(backlight, S_IWUGO, NULL, set_backlight)
249};
250
251static void remove_lcd_files(struct interfacekit *kit)
252{
253 int i;
254
255 if (kit->lcd_files_on) {
256 dev_dbg(&kit->udev->dev, "Removing lcd files\n");
257
258 for (i=0; i<ARRAY_SIZE(dev_lcd_line_attrs); i++)
259 device_remove_file(kit->dev, &dev_lcd_line_attrs[i]);
260 }
261}
262
263static ssize_t enable_lcd_files(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
264{
265 struct interfacekit *kit = dev_get_drvdata(dev);
266 int enable;
267 int i, rc;
268
269 if (kit->ifkit->has_lcd == 0)
270 return -ENODEV;
271
272 if (sscanf(buf, "%d", &enable) < 1)
273 return -EINVAL;
274
275 if (enable) {
276 if (!kit->lcd_files_on) {
277 dev_dbg(&kit->udev->dev, "Adding lcd files\n");
278 for (i=0; i<ARRAY_SIZE(dev_lcd_line_attrs); i++) {
279 rc = device_create_file(kit->dev,
280 &dev_lcd_line_attrs[i]);
281 if (rc)
282 goto out;
283 }
284 kit->lcd_files_on = 1;
285 }
286 } else {
287 if (kit->lcd_files_on) {
288 remove_lcd_files(kit);
289 kit->lcd_files_on = 0;
290 }
291 }
292
293 return count;
294out:
295 while (i-- > 0)
296 device_remove_file(kit->dev, &dev_lcd_line_attrs[i]);
297
298 return rc;
299}
300
301static DEVICE_ATTR(lcd, S_IWUGO, NULL, enable_lcd_files);
302
303static void interfacekit_irq(struct urb *urb)
304{
305 struct interfacekit *kit = urb->context;
306 unsigned char *buffer = kit->data;
307 int i, level, sensor;
308 int retval;
309 int status = urb->status;
310
311 switch (status) {
312 case 0: /* success */
313 break;
314 case -ECONNRESET: /* unlink */
315 case -ENOENT:
316 case -ESHUTDOWN:
317 return;
318 /* -EPIPE: should clear the halt */
319 default: /* error */
320 goto resubmit;
321 }
322
323 /* digital inputs */
324 if (kit->ifkit->inputs == 16) {
325 for (i=0; i < 8; i++) {
326 level = (buffer[0] >> i) & 1;
327 if (kit->inputs[i] != level) {
328 kit->inputs[i] = level;
329 set_bit(i, &kit->input_events);
330 }
331 level = (buffer[1] >> i) & 1;
332 if (kit->inputs[8 + i] != level) {
333 kit->inputs[8 + i] = level;
334 set_bit(8 + i, &kit->input_events);
335 }
336 }
337 }
338 else if (kit->ifkit->inputs == 8) {
339 for (i=0; i < 8; i++) {
340 level = (buffer[1] >> i) & 1;
341 if (kit->inputs[i] != level) {
342 kit->inputs[i] = level;
343 set_bit(i, &kit->input_events);
344 }
345 }
346 }
347
348 /* analog inputs */
349 if (kit->ifkit->sensors) {
350 sensor = (buffer[0] & 1) ? 4 : 0;
351
352 level = buffer[2] + (buffer[3] & 0x0f) * 256;
353 if (level != kit->sensors[sensor]) {
354 kit->sensors[sensor] = level;
355 set_bit(sensor, &kit->sensor_events);
356 }
357 sensor++;
358 level = buffer[4] + (buffer[3] & 0xf0) * 16;
359 if (level != kit->sensors[sensor]) {
360 kit->sensors[sensor] = level;
361 set_bit(sensor, &kit->sensor_events);
362 }
363 sensor++;
364 level = buffer[5] + (buffer[6] & 0x0f) * 256;
365 if (level != kit->sensors[sensor]) {
366 kit->sensors[sensor] = level;
367 set_bit(sensor, &kit->sensor_events);
368 }
369 sensor++;
370 level = buffer[7] + (buffer[6] & 0xf0) * 16;
371 if (level != kit->sensors[sensor]) {
372 kit->sensors[sensor] = level;
373 set_bit(sensor, &kit->sensor_events);
374 }
375 }
376
377 if (kit->input_events || kit->sensor_events)
378 schedule_delayed_work(&kit->do_notify, 0);
379
380resubmit:
381 retval = usb_submit_urb(urb, GFP_ATOMIC);
382 if (retval)
383 err("can't resubmit intr, %s-%s/interfacekit0, retval %d",
384 kit->udev->bus->bus_name,
385 kit->udev->devpath, retval);
386}
387
388static void do_notify(struct work_struct *work)
389{
390 struct interfacekit *kit =
391 container_of(work, struct interfacekit, do_notify.work);
392 int i;
393 char sysfs_file[8];
394
395 for (i=0; i<kit->ifkit->inputs; i++) {
396 if (test_and_clear_bit(i, &kit->input_events)) {
397 sprintf(sysfs_file, "input%d", i + 1);
398 sysfs_notify(&kit->dev->kobj, NULL, sysfs_file);
399 }
400 }
401
402 for (i=0; i<kit->ifkit->sensors; i++) {
403 if (test_and_clear_bit(i, &kit->sensor_events)) {
404 sprintf(sysfs_file, "sensor%d", i + 1);
405 sysfs_notify(&kit->dev->kobj, NULL, sysfs_file);
406 }
407 }
408}
409
410static void do_resubmit(struct work_struct *work)
411{
412 struct interfacekit *kit =
413 container_of(work, struct interfacekit, do_resubmit.work);
414 set_outputs(kit);
415}
416
417#define show_set_output(value) \
418static ssize_t set_output##value(struct device *dev, \
419 struct device_attribute *attr, \
420 const char *buf, size_t count) \
421{ \
422 struct interfacekit *kit = dev_get_drvdata(dev); \
423 int enable; \
424 int retval; \
425 \
426 if (sscanf(buf, "%d", &enable) < 1) \
427 return -EINVAL; \
428 \
429 if (enable) \
430 set_bit(value - 1, &kit->outputs); \
431 else \
432 clear_bit(value - 1, &kit->outputs); \
433 \
434 retval = set_outputs(kit); \
435 \
436 return retval ? retval : count; \
437} \
438 \
439static ssize_t show_output##value(struct device *dev, \
440 struct device_attribute *attr, \
441 char *buf) \
442{ \
443 struct interfacekit *kit = dev_get_drvdata(dev); \
444 \
445 return sprintf(buf, "%d\n", !!test_bit(value - 1, &kit->outputs));\
446}
447
448#define output_attr(value) \
449 __ATTR(output##value, S_IWUGO | S_IRUGO, \
450 show_output##value, set_output##value)
451
452show_set_output(1);
453show_set_output(2);
454show_set_output(3);
455show_set_output(4);
456show_set_output(5);
457show_set_output(6);
458show_set_output(7);
459show_set_output(8);
460show_set_output(9);
461show_set_output(10);
462show_set_output(11);
463show_set_output(12);
464show_set_output(13);
465show_set_output(14);
466show_set_output(15);
467show_set_output(16);
468
469static struct device_attribute dev_output_attrs[] = {
470 output_attr(1), output_attr(2), output_attr(3), output_attr(4),
471 output_attr(5), output_attr(6), output_attr(7), output_attr(8),
472 output_attr(9), output_attr(10), output_attr(11), output_attr(12),
473 output_attr(13), output_attr(14), output_attr(15), output_attr(16)
474};
475
476#define show_input(value) \
477static ssize_t show_input##value(struct device *dev, \
478 struct device_attribute *attr, char *buf) \
479{ \
480 struct interfacekit *kit = dev_get_drvdata(dev); \
481 \
482 return sprintf(buf, "%d\n", (int)kit->inputs[value - 1]); \
483}
484
485#define input_attr(value) \
486 __ATTR(input##value, S_IRUGO, show_input##value, NULL)
487
488show_input(1);
489show_input(2);
490show_input(3);
491show_input(4);
492show_input(5);
493show_input(6);
494show_input(7);
495show_input(8);
496show_input(9);
497show_input(10);
498show_input(11);
499show_input(12);
500show_input(13);
501show_input(14);
502show_input(15);
503show_input(16);
504
505static struct device_attribute dev_input_attrs[] = {
506 input_attr(1), input_attr(2), input_attr(3), input_attr(4),
507 input_attr(5), input_attr(6), input_attr(7), input_attr(8),
508 input_attr(9), input_attr(10), input_attr(11), input_attr(12),
509 input_attr(13), input_attr(14), input_attr(15), input_attr(16)
510};
511
512#define show_sensor(value) \
513static ssize_t show_sensor##value(struct device *dev, \
514 struct device_attribute *attr, \
515 char *buf) \
516{ \
517 struct interfacekit *kit = dev_get_drvdata(dev); \
518 \
519 return sprintf(buf, "%d\n", (int)kit->sensors[value - 1]); \
520}
521
522#define sensor_attr(value) \
523 __ATTR(sensor##value, S_IRUGO, show_sensor##value, NULL)
524
525show_sensor(1);
526show_sensor(2);
527show_sensor(3);
528show_sensor(4);
529show_sensor(5);
530show_sensor(6);
531show_sensor(7);
532show_sensor(8);
533
534static struct device_attribute dev_sensor_attrs[] = {
535 sensor_attr(1), sensor_attr(2), sensor_attr(3), sensor_attr(4),
536 sensor_attr(5), sensor_attr(6), sensor_attr(7), sensor_attr(8)
537};
538
539static int interfacekit_probe(struct usb_interface *intf, const struct usb_device_id *id)
540{
541 struct usb_device *dev = interface_to_usbdev(intf);
542 struct usb_host_interface *interface;
543 struct usb_endpoint_descriptor *endpoint;
544 struct interfacekit *kit;
545 struct driver_interfacekit *ifkit;
546 int pipe, maxp, rc = -ENOMEM;
547 int bit, value, i;
548
549 ifkit = (struct driver_interfacekit *)id->driver_info;
550 if (!ifkit)
551 return -ENODEV;
552
553 interface = intf->cur_altsetting;
554 if (interface->desc.bNumEndpoints != 1)
555 return -ENODEV;
556
557 endpoint = &interface->endpoint[0].desc;
558 if (!usb_endpoint_dir_in(endpoint))
559 return -ENODEV;
560 /*
561 * bmAttributes
562 */
563 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
564 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
565
566 kit = kzalloc(sizeof(*kit), GFP_KERNEL);
567 if (!kit)
568 goto out;
569
570 kit->dev_no = -1;
571 kit->ifkit = ifkit;
572 kit->data = usb_buffer_alloc(dev, URB_INT_SIZE, GFP_ATOMIC, &kit->data_dma);
573 if (!kit->data)
574 goto out;
575
576 kit->irq = usb_alloc_urb(0, GFP_KERNEL);
577 if (!kit->irq)
578 goto out;
579
580 kit->udev = usb_get_dev(dev);
581 kit->intf = intf;
582 INIT_DELAYED_WORK(&kit->do_notify, do_notify);
583 INIT_DELAYED_WORK(&kit->do_resubmit, do_resubmit);
584 usb_fill_int_urb(kit->irq, kit->udev, pipe, kit->data,
585 maxp > URB_INT_SIZE ? URB_INT_SIZE : maxp,
586 interfacekit_irq, kit, endpoint->bInterval);
587 kit->irq->transfer_dma = kit->data_dma;
588 kit->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
589
590 usb_set_intfdata(intf, kit);
591
592 do {
593 bit = find_first_zero_bit(&device_no, sizeof(device_no));
594 value = test_and_set_bit(bit, &device_no);
595 } while(value);
596 kit->dev_no = bit;
597
598 kit->dev = device_create(phidget_class, &kit->udev->dev, MKDEV(0, 0),
599 kit, "interfacekit%d", kit->dev_no);
600 if (IS_ERR(kit->dev)) {
601 rc = PTR_ERR(kit->dev);
602 kit->dev = NULL;
603 goto out;
604 }
605
606 if (usb_submit_urb(kit->irq, GFP_KERNEL)) {
607 rc = -EIO;
608 goto out;
609 }
610
611 for (i=0; i<ifkit->outputs; i++ ) {
612 rc = device_create_file(kit->dev, &dev_output_attrs[i]);
613 if (rc)
614 goto out2;
615 }
616
617 for (i=0; i<ifkit->inputs; i++ ) {
618 rc = device_create_file(kit->dev, &dev_input_attrs[i]);
619 if (rc)
620 goto out3;
621 }
622
623 for (i=0; i<ifkit->sensors; i++ ) {
624 rc = device_create_file(kit->dev, &dev_sensor_attrs[i]);
625 if (rc)
626 goto out4;
627 }
628
629 if (ifkit->has_lcd) {
630 rc = device_create_file(kit->dev, &dev_attr_lcd);
631 if (rc)
632 goto out4;
633
634 }
635
636 dev_info(&intf->dev, "USB PhidgetInterfaceKit %d/%d/%d attached\n",
637 ifkit->sensors, ifkit->inputs, ifkit->outputs);
638
639 return 0;
640
641out4:
642 while (i-- > 0)
643 device_remove_file(kit->dev, &dev_sensor_attrs[i]);
644
645 i = ifkit->inputs;
646out3:
647 while (i-- > 0)
648 device_remove_file(kit->dev, &dev_input_attrs[i]);
649
650 i = ifkit->outputs;
651out2:
652 while (i-- > 0)
653 device_remove_file(kit->dev, &dev_output_attrs[i]);
654out:
655 if (kit) {
656 usb_free_urb(kit->irq);
657 if (kit->data)
658 usb_buffer_free(dev, URB_INT_SIZE, kit->data, kit->data_dma);
659 if (kit->dev)
660 device_unregister(kit->dev);
661 if (kit->dev_no >= 0)
662 clear_bit(kit->dev_no, &device_no);
663
664 kfree(kit);
665 }
666
667 return rc;
668}
669
670static void interfacekit_disconnect(struct usb_interface *interface)
671{
672 struct interfacekit *kit;
673 int i;
674
675 kit = usb_get_intfdata(interface);
676 usb_set_intfdata(interface, NULL);
677 if (!kit)
678 return;
679
680 usb_kill_urb(kit->irq);
681 usb_free_urb(kit->irq);
682 usb_buffer_free(kit->udev, URB_INT_SIZE, kit->data, kit->data_dma);
683
684 cancel_delayed_work(&kit->do_notify);
685 cancel_delayed_work(&kit->do_resubmit);
686
687 for (i=0; i<kit->ifkit->outputs; i++)
688 device_remove_file(kit->dev, &dev_output_attrs[i]);
689
690 for (i=0; i<kit->ifkit->inputs; i++)
691 device_remove_file(kit->dev, &dev_input_attrs[i]);
692
693 for (i=0; i<kit->ifkit->sensors; i++)
694 device_remove_file(kit->dev, &dev_sensor_attrs[i]);
695
696 if (kit->ifkit->has_lcd) {
697 device_remove_file(kit->dev, &dev_attr_lcd);
698 remove_lcd_files(kit);
699 }
700
701 device_unregister(kit->dev);
702
703 dev_info(&interface->dev, "USB PhidgetInterfaceKit %d/%d/%d detached\n",
704 kit->ifkit->sensors, kit->ifkit->inputs, kit->ifkit->outputs);
705
706 usb_put_dev(kit->udev);
707 clear_bit(kit->dev_no, &device_no);
708
709 kfree(kit);
710}
711
712static struct usb_driver interfacekit_driver = {
713 .name = "phidgetkit",
714 .probe = interfacekit_probe,
715 .disconnect = interfacekit_disconnect,
716 .id_table = id_table
717};
718
719static int __init interfacekit_init(void)
720{
721 int retval = 0;
722
723 retval = usb_register(&interfacekit_driver);
724 if (retval)
725 err("usb_register failed. Error number %d", retval);
726
727 return retval;
728}
729
730static void __exit interfacekit_exit(void)
731{
732 usb_deregister(&interfacekit_driver);
733}
734
735module_init(interfacekit_init);
736module_exit(interfacekit_exit);
737
738MODULE_AUTHOR(DRIVER_AUTHOR);
739MODULE_DESCRIPTION(DRIVER_DESC);
740MODULE_LICENSE("GPL");
diff --git a/drivers/usb/misc/phidgetmotorcontrol.c b/drivers/usb/misc/phidgetmotorcontrol.c
deleted file mode 100644
index 38088b44349e..000000000000
--- a/drivers/usb/misc/phidgetmotorcontrol.c
+++ /dev/null
@@ -1,465 +0,0 @@
1/*
2 * USB Phidget MotorControl driver
3 *
4 * Copyright (C) 2006 Sean Young <sean@mess.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 */
11
12#include <linux/kernel.h>
13#include <linux/errno.h>
14#include <linux/init.h>
15#include <linux/module.h>
16#include <linux/usb.h>
17
18#include "phidget.h"
19
20#define DRIVER_AUTHOR "Sean Young <sean@mess.org>"
21#define DRIVER_DESC "USB PhidgetMotorControl Driver"
22
23#define USB_VENDOR_ID_GLAB 0x06c2
24#define USB_DEVICE_ID_MOTORCONTROL 0x0058
25
26#define URB_INT_SIZE 8
27
28static unsigned long device_no;
29
30struct motorcontrol {
31 struct usb_device *udev;
32 struct usb_interface *intf;
33 struct device *dev;
34 int dev_no;
35 u8 inputs[4];
36 s8 desired_speed[2];
37 s8 speed[2];
38 s16 _current[2];
39 s8 acceleration[2];
40 struct urb *irq;
41 unsigned char *data;
42 dma_addr_t data_dma;
43
44 struct delayed_work do_notify;
45 unsigned long input_events;
46 unsigned long speed_events;
47 unsigned long exceed_events;
48};
49
50static struct usb_device_id id_table[] = {
51 { USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_MOTORCONTROL) },
52 {}
53};
54MODULE_DEVICE_TABLE(usb, id_table);
55
56static int set_motor(struct motorcontrol *mc, int motor)
57{
58 u8 *buffer;
59 int speed, speed2, acceleration;
60 int retval;
61
62 buffer = kzalloc(8, GFP_KERNEL);
63 if (!buffer) {
64 dev_err(&mc->intf->dev, "%s - out of memory\n", __func__);
65 return -ENOMEM;
66 }
67
68 acceleration = mc->acceleration[motor] * 10;
69 /* -127 <= speed <= 127 */
70 speed = (mc->desired_speed[motor] * 127) / 100;
71 /* -0x7300 <= speed2 <= 0x7300 */
72 speed2 = (mc->desired_speed[motor] * 230 * 128) / 100;
73
74 buffer[0] = motor;
75 buffer[1] = speed;
76 buffer[2] = acceleration >> 8;
77 buffer[3] = acceleration;
78 buffer[4] = speed2 >> 8;
79 buffer[5] = speed2;
80
81 retval = usb_control_msg(mc->udev,
82 usb_sndctrlpipe(mc->udev, 0),
83 0x09, 0x21, 0x0200, 0x0000, buffer, 8, 2000);
84
85 if (retval != 8)
86 dev_err(&mc->intf->dev, "usb_control_msg returned %d\n",
87 retval);
88 kfree(buffer);
89
90 return retval < 0 ? retval : 0;
91}
92
93static void motorcontrol_irq(struct urb *urb)
94{
95 struct motorcontrol *mc = urb->context;
96 unsigned char *buffer = mc->data;
97 int i, level;
98 int retval;
99 int status = urb->status;;
100
101 switch (status) {
102 case 0: /* success */
103 break;
104 case -ECONNRESET: /* unlink */
105 case -ENOENT:
106 case -ESHUTDOWN:
107 return;
108 /* -EPIPE: should clear the halt */
109 default: /* error */
110 goto resubmit;
111 }
112
113 /* digital inputs */
114 for (i=0; i<4; i++) {
115 level = (buffer[0] >> i) & 1;
116 if (mc->inputs[i] != level) {
117 mc->inputs[i] = level;
118 set_bit(i, &mc->input_events);
119 }
120 }
121
122 /* motor speed */
123 if (buffer[2] == 0) {
124 for (i=0; i<2; i++) {
125 level = ((s8)buffer[4+i]) * 100 / 127;
126 if (mc->speed[i] != level) {
127 mc->speed[i] = level;
128 set_bit(i, &mc->speed_events);
129 }
130 }
131 } else {
132 int index = buffer[3] & 1;
133
134 level = ((s8)buffer[4] << 8) | buffer[5];
135 level = level * 100 / 29440;
136 if (mc->speed[index] != level) {
137 mc->speed[index] = level;
138 set_bit(index, &mc->speed_events);
139 }
140
141 level = ((s8)buffer[6] << 8) | buffer[7];
142 mc->_current[index] = level * 100 / 1572;
143 }
144
145 if (buffer[1] & 1)
146 set_bit(0, &mc->exceed_events);
147
148 if (buffer[1] & 2)
149 set_bit(1, &mc->exceed_events);
150
151 if (mc->input_events || mc->exceed_events || mc->speed_events)
152 schedule_delayed_work(&mc->do_notify, 0);
153
154resubmit:
155 retval = usb_submit_urb(urb, GFP_ATOMIC);
156 if (retval)
157 dev_err(&mc->intf->dev,
158 "can't resubmit intr, %s-%s/motorcontrol0, retval %d\n",
159 mc->udev->bus->bus_name,
160 mc->udev->devpath, retval);
161}
162
163static void do_notify(struct work_struct *work)
164{
165 struct motorcontrol *mc =
166 container_of(work, struct motorcontrol, do_notify.work);
167 int i;
168 char sysfs_file[8];
169
170 for (i=0; i<4; i++) {
171 if (test_and_clear_bit(i, &mc->input_events)) {
172 sprintf(sysfs_file, "input%d", i);
173 sysfs_notify(&mc->dev->kobj, NULL, sysfs_file);
174 }
175 }
176
177 for (i=0; i<2; i++) {
178 if (test_and_clear_bit(i, &mc->speed_events)) {
179 sprintf(sysfs_file, "speed%d", i);
180 sysfs_notify(&mc->dev->kobj, NULL, sysfs_file);
181 }
182 }
183
184 for (i=0; i<2; i++) {
185 if (test_and_clear_bit(i, &mc->exceed_events))
186 dev_warn(&mc->intf->dev,
187 "motor #%d exceeds 1.5 Amp current limit\n", i);
188 }
189}
190
191#define show_set_speed(value) \
192static ssize_t set_speed##value(struct device *dev, \
193 struct device_attribute *attr, \
194 const char *buf, size_t count) \
195{ \
196 struct motorcontrol *mc = dev_get_drvdata(dev); \
197 int speed; \
198 int retval; \
199 \
200 if (sscanf(buf, "%d", &speed) < 1) \
201 return -EINVAL; \
202 \
203 if (speed < -100 || speed > 100) \
204 return -EINVAL; \
205 \
206 mc->desired_speed[value] = speed; \
207 \
208 retval = set_motor(mc, value); \
209 \
210 return retval ? retval : count; \
211} \
212 \
213static ssize_t show_speed##value(struct device *dev, \
214 struct device_attribute *attr, \
215 char *buf) \
216{ \
217 struct motorcontrol *mc = dev_get_drvdata(dev); \
218 \
219 return sprintf(buf, "%d\n", mc->speed[value]); \
220}
221
222#define speed_attr(value) \
223 __ATTR(speed##value, S_IWUGO | S_IRUGO, \
224 show_speed##value, set_speed##value)
225
226show_set_speed(0);
227show_set_speed(1);
228
229#define show_set_acceleration(value) \
230static ssize_t set_acceleration##value(struct device *dev, \
231 struct device_attribute *attr, \
232 const char *buf, size_t count) \
233{ \
234 struct motorcontrol *mc = dev_get_drvdata(dev); \
235 int acceleration; \
236 int retval; \
237 \
238 if (sscanf(buf, "%d", &acceleration) < 1) \
239 return -EINVAL; \
240 \
241 if (acceleration < 0 || acceleration > 100) \
242 return -EINVAL; \
243 \
244 mc->acceleration[value] = acceleration; \
245 \
246 retval = set_motor(mc, value); \
247 \
248 return retval ? retval : count; \
249} \
250 \
251static ssize_t show_acceleration##value(struct device *dev, \
252 struct device_attribute *attr, \
253 char *buf) \
254{ \
255 struct motorcontrol *mc = dev_get_drvdata(dev); \
256 \
257 return sprintf(buf, "%d\n", mc->acceleration[value]); \
258}
259
260#define acceleration_attr(value) \
261 __ATTR(acceleration##value, S_IWUGO | S_IRUGO, \
262 show_acceleration##value, set_acceleration##value)
263
264show_set_acceleration(0);
265show_set_acceleration(1);
266
267#define show_current(value) \
268static ssize_t show_current##value(struct device *dev, \
269 struct device_attribute *attr, \
270 char *buf) \
271{ \
272 struct motorcontrol *mc = dev_get_drvdata(dev); \
273 \
274 return sprintf(buf, "%dmA\n", (int)mc->_current[value]); \
275}
276
277#define current_attr(value) \
278 __ATTR(current##value, S_IRUGO, show_current##value, NULL)
279
280show_current(0);
281show_current(1);
282
283#define show_input(value) \
284static ssize_t show_input##value(struct device *dev, \
285 struct device_attribute *attr, \
286 char *buf) \
287{ \
288 struct motorcontrol *mc = dev_get_drvdata(dev); \
289 \
290 return sprintf(buf, "%d\n", (int)mc->inputs[value]); \
291}
292
293#define input_attr(value) \
294 __ATTR(input##value, S_IRUGO, show_input##value, NULL)
295
296show_input(0);
297show_input(1);
298show_input(2);
299show_input(3);
300
301static struct device_attribute dev_attrs[] = {
302 input_attr(0),
303 input_attr(1),
304 input_attr(2),
305 input_attr(3),
306 speed_attr(0),
307 speed_attr(1),
308 acceleration_attr(0),
309 acceleration_attr(1),
310 current_attr(0),
311 current_attr(1)
312};
313
314static int motorcontrol_probe(struct usb_interface *intf, const struct usb_device_id *id)
315{
316 struct usb_device *dev = interface_to_usbdev(intf);
317 struct usb_host_interface *interface;
318 struct usb_endpoint_descriptor *endpoint;
319 struct motorcontrol *mc;
320 int pipe, maxp, rc = -ENOMEM;
321 int bit, value, i;
322
323 interface = intf->cur_altsetting;
324 if (interface->desc.bNumEndpoints != 1)
325 return -ENODEV;
326
327 endpoint = &interface->endpoint[0].desc;
328 if (!usb_endpoint_dir_in(endpoint))
329 return -ENODEV;
330
331 /*
332 * bmAttributes
333 */
334 pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);
335 maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));
336
337 mc = kzalloc(sizeof(*mc), GFP_KERNEL);
338 if (!mc)
339 goto out;
340
341 mc->dev_no = -1;
342 mc->data = usb_buffer_alloc(dev, URB_INT_SIZE, GFP_ATOMIC, &mc->data_dma);
343 if (!mc->data)
344 goto out;
345
346 mc->irq = usb_alloc_urb(0, GFP_KERNEL);
347 if (!mc->irq)
348 goto out;
349
350 mc->udev = usb_get_dev(dev);
351 mc->intf = intf;
352 mc->acceleration[0] = mc->acceleration[1] = 10;
353 INIT_DELAYED_WORK(&mc->do_notify, do_notify);
354 usb_fill_int_urb(mc->irq, mc->udev, pipe, mc->data,
355 maxp > URB_INT_SIZE ? URB_INT_SIZE : maxp,
356 motorcontrol_irq, mc, endpoint->bInterval);
357 mc->irq->transfer_dma = mc->data_dma;
358 mc->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
359
360 usb_set_intfdata(intf, mc);
361
362 do {
363 bit = find_first_zero_bit(&device_no, sizeof(device_no));
364 value = test_and_set_bit(bit, &device_no);
365 } while(value);
366 mc->dev_no = bit;
367
368 mc->dev = device_create(phidget_class, &mc->udev->dev, MKDEV(0, 0), mc,
369 "motorcontrol%d", mc->dev_no);
370 if (IS_ERR(mc->dev)) {
371 rc = PTR_ERR(mc->dev);
372 mc->dev = NULL;
373 goto out;
374 }
375
376 if (usb_submit_urb(mc->irq, GFP_KERNEL)) {
377 rc = -EIO;
378 goto out;
379 }
380
381 for (i=0; i<ARRAY_SIZE(dev_attrs); i++) {
382 rc = device_create_file(mc->dev, &dev_attrs[i]);
383 if (rc)
384 goto out2;
385 }
386
387 dev_info(&intf->dev, "USB PhidgetMotorControl attached\n");
388
389 return 0;
390out2:
391 while (i-- > 0)
392 device_remove_file(mc->dev, &dev_attrs[i]);
393out:
394 if (mc) {
395 usb_free_urb(mc->irq);
396 if (mc->data)
397 usb_buffer_free(dev, URB_INT_SIZE, mc->data, mc->data_dma);
398 if (mc->dev)
399 device_unregister(mc->dev);
400 if (mc->dev_no >= 0)
401 clear_bit(mc->dev_no, &device_no);
402
403 kfree(mc);
404 }
405
406 return rc;
407}
408
409static void motorcontrol_disconnect(struct usb_interface *interface)
410{
411 struct motorcontrol *mc;
412 int i;
413
414 mc = usb_get_intfdata(interface);
415 usb_set_intfdata(interface, NULL);
416 if (!mc)
417 return;
418
419 usb_kill_urb(mc->irq);
420 usb_free_urb(mc->irq);
421 usb_buffer_free(mc->udev, URB_INT_SIZE, mc->data, mc->data_dma);
422
423 cancel_delayed_work(&mc->do_notify);
424
425 for (i=0; i<ARRAY_SIZE(dev_attrs); i++)
426 device_remove_file(mc->dev, &dev_attrs[i]);
427
428 device_unregister(mc->dev);
429
430 usb_put_dev(mc->udev);
431 clear_bit(mc->dev_no, &device_no);
432 kfree(mc);
433
434 dev_info(&interface->dev, "USB PhidgetMotorControl detached\n");
435}
436
437static struct usb_driver motorcontrol_driver = {
438 .name = "phidgetmotorcontrol",
439 .probe = motorcontrol_probe,
440 .disconnect = motorcontrol_disconnect,
441 .id_table = id_table
442};
443
444static int __init motorcontrol_init(void)
445{
446 int retval = 0;
447
448 retval = usb_register(&motorcontrol_driver);
449 if (retval)
450 err("usb_register failed. Error number %d", retval);
451
452 return retval;
453}
454
455static void __exit motorcontrol_exit(void)
456{
457 usb_deregister(&motorcontrol_driver);
458}
459
460module_init(motorcontrol_init);
461module_exit(motorcontrol_exit);
462
463MODULE_AUTHOR(DRIVER_AUTHOR);
464MODULE_DESCRIPTION(DRIVER_DESC);
465MODULE_LICENSE("GPL");
diff --git a/drivers/usb/misc/phidgetservo.c b/drivers/usb/misc/phidgetservo.c
deleted file mode 100644
index bef6fe16364b..000000000000
--- a/drivers/usb/misc/phidgetservo.c
+++ /dev/null
@@ -1,375 +0,0 @@
1/*
2 * USB PhidgetServo driver 1.0
3 *
4 * Copyright (C) 2004, 2006 Sean Young <sean@mess.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This is a driver for the USB PhidgetServo version 2.0 and 3.0 servo
12 * controllers available at: http://www.phidgets.com/
13 *
14 * Note that the driver takes input as: degrees.minutes
15 *
16 * CAUTION: Generally you should use 0 < degrees < 180 as anything else
17 * is probably beyond the range of your servo and may damage it.
18 */
19
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/init.h>
23#include <linux/slab.h>
24#include <linux/module.h>
25#include <linux/usb.h>
26
27#include "phidget.h"
28
29#define DRIVER_AUTHOR "Sean Young <sean@mess.org>"
30#define DRIVER_DESC "USB PhidgetServo Driver"
31
32#define VENDOR_ID_GLAB 0x06c2
33#define DEVICE_ID_GLAB_PHIDGETSERVO_QUAD 0x0038
34#define DEVICE_ID_GLAB_PHIDGETSERVO_UNI 0x0039
35
36#define VENDOR_ID_WISEGROUP 0x0925
37#define VENDOR_ID_WISEGROUP_PHIDGETSERVO_QUAD 0x8101
38#define VENDOR_ID_WISEGROUP_PHIDGETSERVO_UNI 0x8104
39
40#define SERVO_VERSION_30 0x01
41#define SERVO_COUNT_QUAD 0x02
42
43static struct usb_device_id id_table[] = {
44 {
45 USB_DEVICE(VENDOR_ID_GLAB, DEVICE_ID_GLAB_PHIDGETSERVO_QUAD),
46 .driver_info = SERVO_VERSION_30 | SERVO_COUNT_QUAD
47 },
48 {
49 USB_DEVICE(VENDOR_ID_GLAB, DEVICE_ID_GLAB_PHIDGETSERVO_UNI),
50 .driver_info = SERVO_VERSION_30
51 },
52 {
53 USB_DEVICE(VENDOR_ID_WISEGROUP,
54 VENDOR_ID_WISEGROUP_PHIDGETSERVO_QUAD),
55 .driver_info = SERVO_COUNT_QUAD
56 },
57 {
58 USB_DEVICE(VENDOR_ID_WISEGROUP,
59 VENDOR_ID_WISEGROUP_PHIDGETSERVO_UNI),
60 .driver_info = 0
61 },
62 {}
63};
64
65MODULE_DEVICE_TABLE(usb, id_table);
66
67static int unsigned long device_no;
68
69struct phidget_servo {
70 struct usb_device *udev;
71 struct device *dev;
72 int dev_no;
73 ulong type;
74 int pulse[4];
75 int degrees[4];
76 int minutes[4];
77};
78
79static int
80change_position_v30(struct phidget_servo *servo, int servo_no, int degrees,
81 int minutes)
82{
83 int retval;
84 unsigned char *buffer;
85
86 if (degrees < -23 || degrees > 362)
87 return -EINVAL;
88
89 buffer = kmalloc(6, GFP_KERNEL);
90 if (!buffer) {
91 dev_err(&servo->udev->dev, "%s - out of memory\n",
92 __func__);
93 return -ENOMEM;
94 }
95
96 /*
97 * pulse = 0 - 4095
98 * angle = 0 - 180 degrees
99 *
100 * pulse = angle * 10.6 + 243.8
101 */
102 servo->pulse[servo_no] = ((degrees*60 + minutes)*106 + 2438*60)/600;
103 servo->degrees[servo_no]= degrees;
104 servo->minutes[servo_no]= minutes;
105
106 /*
107 * The PhidgetServo v3.0 is controlled by sending 6 bytes,
108 * 4 * 12 bits for each servo.
109 *
110 * low = lower 8 bits pulse
111 * high = higher 4 bits pulse
112 *
113 * offset bits
114 * +---+-----------------+
115 * | 0 | low 0 |
116 * +---+--------+--------+
117 * | 1 | high 1 | high 0 |
118 * +---+--------+--------+
119 * | 2 | low 1 |
120 * +---+-----------------+
121 * | 3 | low 2 |
122 * +---+--------+--------+
123 * | 4 | high 3 | high 2 |
124 * +---+--------+--------+
125 * | 5 | low 3 |
126 * +---+-----------------+
127 */
128
129 buffer[0] = servo->pulse[0] & 0xff;
130 buffer[1] = (servo->pulse[0] >> 8 & 0x0f)
131 | (servo->pulse[1] >> 4 & 0xf0);
132 buffer[2] = servo->pulse[1] & 0xff;
133 buffer[3] = servo->pulse[2] & 0xff;
134 buffer[4] = (servo->pulse[2] >> 8 & 0x0f)
135 | (servo->pulse[3] >> 4 & 0xf0);
136 buffer[5] = servo->pulse[3] & 0xff;
137
138 dev_dbg(&servo->udev->dev,
139 "data: %02x %02x %02x %02x %02x %02x\n",
140 buffer[0], buffer[1], buffer[2],
141 buffer[3], buffer[4], buffer[5]);
142
143 retval = usb_control_msg(servo->udev,
144 usb_sndctrlpipe(servo->udev, 0),
145 0x09, 0x21, 0x0200, 0x0000, buffer, 6, 2000);
146
147 kfree(buffer);
148
149 return retval;
150}
151
152static int
153change_position_v20(struct phidget_servo *servo, int servo_no, int degrees,
154 int minutes)
155{
156 int retval;
157 unsigned char *buffer;
158
159 if (degrees < -23 || degrees > 278)
160 return -EINVAL;
161
162 buffer = kmalloc(2, GFP_KERNEL);
163 if (!buffer) {
164 dev_err(&servo->udev->dev, "%s - out of memory\n",
165 __func__);
166 return -ENOMEM;
167 }
168
169 /*
170 * angle = 0 - 180 degrees
171 * pulse = angle + 23
172 */
173 servo->pulse[servo_no]= degrees + 23;
174 servo->degrees[servo_no]= degrees;
175 servo->minutes[servo_no]= 0;
176
177 /*
178 * The PhidgetServo v2.0 is controlled by sending two bytes. The
179 * first byte is the servo number xor'ed with 2:
180 *
181 * servo 0 = 2
182 * servo 1 = 3
183 * servo 2 = 0
184 * servo 3 = 1
185 *
186 * The second byte is the position.
187 */
188
189 buffer[0] = servo_no ^ 2;
190 buffer[1] = servo->pulse[servo_no];
191
192 dev_dbg(&servo->udev->dev, "data: %02x %02x\n", buffer[0], buffer[1]);
193
194 retval = usb_control_msg(servo->udev,
195 usb_sndctrlpipe(servo->udev, 0),
196 0x09, 0x21, 0x0200, 0x0000, buffer, 2, 2000);
197
198 kfree(buffer);
199
200 return retval;
201}
202
203#define show_set(value) \
204static ssize_t set_servo##value (struct device *dev, \
205 struct device_attribute *attr, \
206 const char *buf, size_t count) \
207{ \
208 int degrees, minutes, retval; \
209 struct phidget_servo *servo = dev_get_drvdata(dev); \
210 \
211 minutes = 0; \
212 /* must at least convert degrees */ \
213 if (sscanf(buf, "%d.%d", &degrees, &minutes) < 1) { \
214 return -EINVAL; \
215 } \
216 \
217 if (minutes < 0 || minutes > 59) \
218 return -EINVAL; \
219 \
220 if (servo->type & SERVO_VERSION_30) \
221 retval = change_position_v30(servo, value, degrees, \
222 minutes); \
223 else \
224 retval = change_position_v20(servo, value, degrees, \
225 minutes); \
226 \
227 return retval < 0 ? retval : count; \
228} \
229 \
230static ssize_t show_servo##value (struct device *dev, \
231 struct device_attribute *attr, \
232 char *buf) \
233{ \
234 struct phidget_servo *servo = dev_get_drvdata(dev); \
235 \
236 return sprintf(buf, "%d.%02d\n", servo->degrees[value], \
237 servo->minutes[value]); \
238}
239
240#define servo_attr(value) \
241 __ATTR(servo##value, S_IWUGO | S_IRUGO, \
242 show_servo##value, set_servo##value)
243show_set(0);
244show_set(1);
245show_set(2);
246show_set(3);
247
248static struct device_attribute dev_attrs[] = {
249 servo_attr(0), servo_attr(1), servo_attr(2), servo_attr(3)
250};
251
252static int
253servo_probe(struct usb_interface *interface, const struct usb_device_id *id)
254{
255 struct usb_device *udev = interface_to_usbdev(interface);
256 struct phidget_servo *dev;
257 int bit, value, rc;
258 int servo_count, i;
259
260 dev = kzalloc(sizeof (struct phidget_servo), GFP_KERNEL);
261 if (dev == NULL) {
262 dev_err(&interface->dev, "%s - out of memory\n", __func__);
263 rc = -ENOMEM;
264 goto out;
265 }
266
267 dev->udev = usb_get_dev(udev);
268 dev->type = id->driver_info;
269 dev->dev_no = -1;
270 usb_set_intfdata(interface, dev);
271
272 do {
273 bit = find_first_zero_bit(&device_no, sizeof(device_no));
274 value = test_and_set_bit(bit, &device_no);
275 } while (value);
276 dev->dev_no = bit;
277
278 dev->dev = device_create(phidget_class, &dev->udev->dev, MKDEV(0, 0),
279 dev, "servo%d", dev->dev_no);
280 if (IS_ERR(dev->dev)) {
281 rc = PTR_ERR(dev->dev);
282 dev->dev = NULL;
283 goto out;
284 }
285
286 servo_count = dev->type & SERVO_COUNT_QUAD ? 4 : 1;
287
288 for (i=0; i<servo_count; i++) {
289 rc = device_create_file(dev->dev, &dev_attrs[i]);
290 if (rc)
291 goto out2;
292 }
293
294 dev_info(&interface->dev, "USB %d-Motor PhidgetServo v%d.0 attached\n",
295 servo_count, dev->type & SERVO_VERSION_30 ? 3 : 2);
296
297 if (!(dev->type & SERVO_VERSION_30))
298 dev_info(&interface->dev,
299 "WARNING: v2.0 not tested! Please report if it works.\n");
300
301 return 0;
302out2:
303 while (i-- > 0)
304 device_remove_file(dev->dev, &dev_attrs[i]);
305out:
306 if (dev) {
307 if (dev->dev)
308 device_unregister(dev->dev);
309 if (dev->dev_no >= 0)
310 clear_bit(dev->dev_no, &device_no);
311
312 kfree(dev);
313 }
314
315 return rc;
316}
317
318static void
319servo_disconnect(struct usb_interface *interface)
320{
321 struct phidget_servo *dev;
322 int servo_count, i;
323
324 dev = usb_get_intfdata(interface);
325 usb_set_intfdata(interface, NULL);
326
327 if (!dev)
328 return;
329
330 servo_count = dev->type & SERVO_COUNT_QUAD ? 4 : 1;
331
332 for (i=0; i<servo_count; i++)
333 device_remove_file(dev->dev, &dev_attrs[i]);
334
335 device_unregister(dev->dev);
336 usb_put_dev(dev->udev);
337
338 dev_info(&interface->dev, "USB %d-Motor PhidgetServo v%d.0 detached\n",
339 servo_count, dev->type & SERVO_VERSION_30 ? 3 : 2);
340
341 clear_bit(dev->dev_no, &device_no);
342 kfree(dev);
343}
344
345static struct usb_driver servo_driver = {
346 .name = "phidgetservo",
347 .probe = servo_probe,
348 .disconnect = servo_disconnect,
349 .id_table = id_table
350};
351
352static int __init
353phidget_servo_init(void)
354{
355 int retval;
356
357 retval = usb_register(&servo_driver);
358 if (retval)
359 err("usb_register failed. Error number %d", retval);
360
361 return retval;
362}
363
364static void __exit
365phidget_servo_exit(void)
366{
367 usb_deregister(&servo_driver);
368}
369
370module_init(phidget_servo_init);
371module_exit(phidget_servo_exit);
372
373MODULE_AUTHOR(DRIVER_AUTHOR);
374MODULE_DESCRIPTION(DRIVER_DESC);
375MODULE_LICENSE("GPL");
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index 4cf27c72423e..f8d9045d668a 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -37,10 +37,13 @@
37#define MON_IOCX_GET _IOW(MON_IOC_MAGIC, 6, struct mon_bin_get) 37#define MON_IOCX_GET _IOW(MON_IOC_MAGIC, 6, struct mon_bin_get)
38#define MON_IOCX_MFETCH _IOWR(MON_IOC_MAGIC, 7, struct mon_bin_mfetch) 38#define MON_IOCX_MFETCH _IOWR(MON_IOC_MAGIC, 7, struct mon_bin_mfetch)
39#define MON_IOCH_MFLUSH _IO(MON_IOC_MAGIC, 8) 39#define MON_IOCH_MFLUSH _IO(MON_IOC_MAGIC, 8)
40/* #9 was MON_IOCT_SETAPI */
41#define MON_IOCX_GETX _IOW(MON_IOC_MAGIC, 10, struct mon_bin_get)
40 42
41#ifdef CONFIG_COMPAT 43#ifdef CONFIG_COMPAT
42#define MON_IOCX_GET32 _IOW(MON_IOC_MAGIC, 6, struct mon_bin_get32) 44#define MON_IOCX_GET32 _IOW(MON_IOC_MAGIC, 6, struct mon_bin_get32)
43#define MON_IOCX_MFETCH32 _IOWR(MON_IOC_MAGIC, 7, struct mon_bin_mfetch32) 45#define MON_IOCX_MFETCH32 _IOWR(MON_IOC_MAGIC, 7, struct mon_bin_mfetch32)
46#define MON_IOCX_GETX32 _IOW(MON_IOC_MAGIC, 10, struct mon_bin_get32)
44#endif 47#endif
45 48
46/* 49/*
@@ -92,7 +95,29 @@ struct mon_bin_hdr {
92 int status; 95 int status;
93 unsigned int len_urb; /* Length of data (submitted or actual) */ 96 unsigned int len_urb; /* Length of data (submitted or actual) */
94 unsigned int len_cap; /* Delivered length */ 97 unsigned int len_cap; /* Delivered length */
95 unsigned char setup[SETUP_LEN]; /* Only for Control S-type */ 98 union {
99 unsigned char setup[SETUP_LEN]; /* Only for Control S-type */
100 struct iso_rec {
101 int error_count;
102 int numdesc;
103 } iso;
104 } s;
105 int interval;
106 int start_frame;
107 unsigned int xfer_flags;
108 unsigned int ndesc; /* Actual number of ISO descriptors */
109};
110
111/*
112 * ISO vector, packed into the head of data stream.
113 * This has to take 16 bytes to make sure that the end of buffer
114 * wrap is not happening in the middle of a descriptor.
115 */
116struct mon_bin_isodesc {
117 int iso_status;
118 unsigned int iso_off;
119 unsigned int iso_len;
120 u32 _pad;
96}; 121};
97 122
98/* per file statistic */ 123/* per file statistic */
@@ -102,7 +127,7 @@ struct mon_bin_stats {
102}; 127};
103 128
104struct mon_bin_get { 129struct mon_bin_get {
105 struct mon_bin_hdr __user *hdr; /* Only 48 bytes, not 64. */ 130 struct mon_bin_hdr __user *hdr; /* Can be 48 bytes or 64. */
106 void __user *data; 131 void __user *data;
107 size_t alloc; /* Length of data (can be zero) */ 132 size_t alloc; /* Length of data (can be zero) */
108}; 133};
@@ -131,6 +156,11 @@ struct mon_bin_mfetch32 {
131#define PKT_ALIGN 64 156#define PKT_ALIGN 64
132#define PKT_SIZE 64 157#define PKT_SIZE 64
133 158
159#define PKT_SZ_API0 48 /* API 0 (2.6.20) size */
160#define PKT_SZ_API1 64 /* API 1 size: extra fields */
161
162#define ISODESC_MAX 128 /* Same number as usbfs allows, 2048 bytes. */
163
134/* max number of USB bus supported */ 164/* max number of USB bus supported */
135#define MON_BIN_MAX_MINOR 128 165#define MON_BIN_MAX_MINOR 128
136 166
@@ -360,12 +390,8 @@ static inline char mon_bin_get_setup(unsigned char *setupb,
360 const struct urb *urb, char ev_type) 390 const struct urb *urb, char ev_type)
361{ 391{
362 392
363 if (!usb_endpoint_xfer_control(&urb->ep->desc) || ev_type != 'S')
364 return '-';
365
366 if (urb->setup_packet == NULL) 393 if (urb->setup_packet == NULL)
367 return 'Z'; 394 return 'Z';
368
369 memcpy(setupb, urb->setup_packet, SETUP_LEN); 395 memcpy(setupb, urb->setup_packet, SETUP_LEN);
370 return 0; 396 return 0;
371} 397}
@@ -387,6 +413,26 @@ static char mon_bin_get_data(const struct mon_reader_bin *rp,
387 return 0; 413 return 0;
388} 414}
389 415
416static void mon_bin_get_isodesc(const struct mon_reader_bin *rp,
417 unsigned int offset, struct urb *urb, char ev_type, unsigned int ndesc)
418{
419 struct mon_bin_isodesc *dp;
420 struct usb_iso_packet_descriptor *fp;
421
422 fp = urb->iso_frame_desc;
423 while (ndesc-- != 0) {
424 dp = (struct mon_bin_isodesc *)
425 (rp->b_vec[offset / CHUNK_SIZE].ptr + offset % CHUNK_SIZE);
426 dp->iso_status = fp->status;
427 dp->iso_off = fp->offset;
428 dp->iso_len = (ev_type == 'S') ? fp->length : fp->actual_length;
429 dp->_pad = 0;
430 if ((offset += sizeof(struct mon_bin_isodesc)) >= rp->b_size)
431 offset = 0;
432 fp++;
433 }
434}
435
390static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb, 436static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb,
391 char ev_type, int status) 437 char ev_type, int status)
392{ 438{
@@ -396,6 +442,7 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb,
396 unsigned int urb_length; 442 unsigned int urb_length;
397 unsigned int offset; 443 unsigned int offset;
398 unsigned int length; 444 unsigned int length;
445 unsigned int ndesc, lendesc;
399 unsigned char dir; 446 unsigned char dir;
400 struct mon_bin_hdr *ep; 447 struct mon_bin_hdr *ep;
401 char data_tag = 0; 448 char data_tag = 0;
@@ -407,6 +454,19 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb,
407 /* 454 /*
408 * Find the maximum allowable length, then allocate space. 455 * Find the maximum allowable length, then allocate space.
409 */ 456 */
457 if (usb_endpoint_xfer_isoc(epd)) {
458 if (urb->number_of_packets < 0) {
459 ndesc = 0;
460 } else if (urb->number_of_packets >= ISODESC_MAX) {
461 ndesc = ISODESC_MAX;
462 } else {
463 ndesc = urb->number_of_packets;
464 }
465 } else {
466 ndesc = 0;
467 }
468 lendesc = ndesc*sizeof(struct mon_bin_isodesc);
469
410 urb_length = (ev_type == 'S') ? 470 urb_length = (ev_type == 'S') ?
411 urb->transfer_buffer_length : urb->actual_length; 471 urb->transfer_buffer_length : urb->actual_length;
412 length = urb_length; 472 length = urb_length;
@@ -429,10 +489,12 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb,
429 dir = 0; 489 dir = 0;
430 } 490 }
431 491
432 if (rp->mmap_active) 492 if (rp->mmap_active) {
433 offset = mon_buff_area_alloc_contiguous(rp, length + PKT_SIZE); 493 offset = mon_buff_area_alloc_contiguous(rp,
434 else 494 length + PKT_SIZE + lendesc);
435 offset = mon_buff_area_alloc(rp, length + PKT_SIZE); 495 } else {
496 offset = mon_buff_area_alloc(rp, length + PKT_SIZE + lendesc);
497 }
436 if (offset == ~0) { 498 if (offset == ~0) {
437 rp->cnt_lost++; 499 rp->cnt_lost++;
438 spin_unlock_irqrestore(&rp->b_lock, flags); 500 spin_unlock_irqrestore(&rp->b_lock, flags);
@@ -456,9 +518,31 @@ static void mon_bin_event(struct mon_reader_bin *rp, struct urb *urb,
456 ep->ts_usec = ts.tv_usec; 518 ep->ts_usec = ts.tv_usec;
457 ep->status = status; 519 ep->status = status;
458 ep->len_urb = urb_length; 520 ep->len_urb = urb_length;
459 ep->len_cap = length; 521 ep->len_cap = length + lendesc;
522 ep->xfer_flags = urb->transfer_flags;
523
524 if (usb_endpoint_xfer_int(epd)) {
525 ep->interval = urb->interval;
526 } else if (usb_endpoint_xfer_isoc(epd)) {
527 ep->interval = urb->interval;
528 ep->start_frame = urb->start_frame;
529 ep->s.iso.error_count = urb->error_count;
530 ep->s.iso.numdesc = urb->number_of_packets;
531 }
532
533 if (usb_endpoint_xfer_control(epd) && ev_type == 'S') {
534 ep->flag_setup = mon_bin_get_setup(ep->s.setup, urb, ev_type);
535 } else {
536 ep->flag_setup = '-';
537 }
538
539 if (ndesc != 0) {
540 ep->ndesc = ndesc;
541 mon_bin_get_isodesc(rp, offset, urb, ev_type, ndesc);
542 if ((offset += lendesc) >= rp->b_size)
543 offset -= rp->b_size;
544 }
460 545
461 ep->flag_setup = mon_bin_get_setup(ep->setup, urb, ev_type);
462 if (length != 0) { 546 if (length != 0) {
463 ep->flag_data = mon_bin_get_data(rp, offset, urb, length); 547 ep->flag_data = mon_bin_get_data(rp, offset, urb, length);
464 if (ep->flag_data != 0) { /* Yes, it's 0x00, not '0' */ 548 if (ep->flag_data != 0) { /* Yes, it's 0x00, not '0' */
@@ -592,7 +676,8 @@ err_alloc:
592 * Returns zero or error. 676 * Returns zero or error.
593 */ 677 */
594static int mon_bin_get_event(struct file *file, struct mon_reader_bin *rp, 678static int mon_bin_get_event(struct file *file, struct mon_reader_bin *rp,
595 struct mon_bin_hdr __user *hdr, void __user *data, unsigned int nbytes) 679 struct mon_bin_hdr __user *hdr, unsigned int hdrbytes,
680 void __user *data, unsigned int nbytes)
596{ 681{
597 unsigned long flags; 682 unsigned long flags;
598 struct mon_bin_hdr *ep; 683 struct mon_bin_hdr *ep;
@@ -609,7 +694,7 @@ static int mon_bin_get_event(struct file *file, struct mon_reader_bin *rp,
609 694
610 ep = MON_OFF2HDR(rp, rp->b_out); 695 ep = MON_OFF2HDR(rp, rp->b_out);
611 696
612 if (copy_to_user(hdr, ep, sizeof(struct mon_bin_hdr))) { 697 if (copy_to_user(hdr, ep, hdrbytes)) {
613 mutex_unlock(&rp->fetch_lock); 698 mutex_unlock(&rp->fetch_lock);
614 return -EFAULT; 699 return -EFAULT;
615 } 700 }
@@ -657,6 +742,7 @@ static ssize_t mon_bin_read(struct file *file, char __user *buf,
657 size_t nbytes, loff_t *ppos) 742 size_t nbytes, loff_t *ppos)
658{ 743{
659 struct mon_reader_bin *rp = file->private_data; 744 struct mon_reader_bin *rp = file->private_data;
745 unsigned int hdrbytes = PKT_SZ_API0;
660 unsigned long flags; 746 unsigned long flags;
661 struct mon_bin_hdr *ep; 747 struct mon_bin_hdr *ep;
662 unsigned int offset; 748 unsigned int offset;
@@ -674,8 +760,8 @@ static ssize_t mon_bin_read(struct file *file, char __user *buf,
674 760
675 ep = MON_OFF2HDR(rp, rp->b_out); 761 ep = MON_OFF2HDR(rp, rp->b_out);
676 762
677 if (rp->b_read < sizeof(struct mon_bin_hdr)) { 763 if (rp->b_read < hdrbytes) {
678 step_len = min(nbytes, sizeof(struct mon_bin_hdr) - rp->b_read); 764 step_len = min(nbytes, (size_t)(hdrbytes - rp->b_read));
679 ptr = ((char *)ep) + rp->b_read; 765 ptr = ((char *)ep) + rp->b_read;
680 if (step_len && copy_to_user(buf, ptr, step_len)) { 766 if (step_len && copy_to_user(buf, ptr, step_len)) {
681 mutex_unlock(&rp->fetch_lock); 767 mutex_unlock(&rp->fetch_lock);
@@ -687,13 +773,13 @@ static ssize_t mon_bin_read(struct file *file, char __user *buf,
687 done += step_len; 773 done += step_len;
688 } 774 }
689 775
690 if (rp->b_read >= sizeof(struct mon_bin_hdr)) { 776 if (rp->b_read >= hdrbytes) {
691 step_len = ep->len_cap; 777 step_len = ep->len_cap;
692 step_len -= rp->b_read - sizeof(struct mon_bin_hdr); 778 step_len -= rp->b_read - hdrbytes;
693 if (step_len > nbytes) 779 if (step_len > nbytes)
694 step_len = nbytes; 780 step_len = nbytes;
695 offset = rp->b_out + PKT_SIZE; 781 offset = rp->b_out + PKT_SIZE;
696 offset += rp->b_read - sizeof(struct mon_bin_hdr); 782 offset += rp->b_read - hdrbytes;
697 if (offset >= rp->b_size) 783 if (offset >= rp->b_size)
698 offset -= rp->b_size; 784 offset -= rp->b_size;
699 if (copy_from_buf(rp, offset, buf, step_len)) { 785 if (copy_from_buf(rp, offset, buf, step_len)) {
@@ -709,7 +795,7 @@ static ssize_t mon_bin_read(struct file *file, char __user *buf,
709 /* 795 /*
710 * Check if whole packet was read, and if so, jump to the next one. 796 * Check if whole packet was read, and if so, jump to the next one.
711 */ 797 */
712 if (rp->b_read >= sizeof(struct mon_bin_hdr) + ep->len_cap) { 798 if (rp->b_read >= hdrbytes + ep->len_cap) {
713 spin_lock_irqsave(&rp->b_lock, flags); 799 spin_lock_irqsave(&rp->b_lock, flags);
714 mon_buff_area_free(rp, PKT_SIZE + ep->len_cap); 800 mon_buff_area_free(rp, PKT_SIZE + ep->len_cap);
715 spin_unlock_irqrestore(&rp->b_lock, flags); 801 spin_unlock_irqrestore(&rp->b_lock, flags);
@@ -908,6 +994,7 @@ static int mon_bin_ioctl(struct inode *inode, struct file *file,
908 break; 994 break;
909 995
910 case MON_IOCX_GET: 996 case MON_IOCX_GET:
997 case MON_IOCX_GETX:
911 { 998 {
912 struct mon_bin_get getb; 999 struct mon_bin_get getb;
913 1000
@@ -917,8 +1004,9 @@ static int mon_bin_ioctl(struct inode *inode, struct file *file,
917 1004
918 if (getb.alloc > 0x10000000) /* Want to cast to u32 */ 1005 if (getb.alloc > 0x10000000) /* Want to cast to u32 */
919 return -EINVAL; 1006 return -EINVAL;
920 ret = mon_bin_get_event(file, rp, 1007 ret = mon_bin_get_event(file, rp, getb.hdr,
921 getb.hdr, getb.data, (unsigned int)getb.alloc); 1008 (cmd == MON_IOCX_GET)? PKT_SZ_API0: PKT_SZ_API1,
1009 getb.data, (unsigned int)getb.alloc);
922 } 1010 }
923 break; 1011 break;
924 1012
@@ -984,16 +1072,18 @@ static long mon_bin_compat_ioctl(struct file *file,
984 1072
985 switch (cmd) { 1073 switch (cmd) {
986 1074
987 case MON_IOCX_GET32: { 1075 case MON_IOCX_GET32:
1076 case MON_IOCX_GETX32:
1077 {
988 struct mon_bin_get32 getb; 1078 struct mon_bin_get32 getb;
989 1079
990 if (copy_from_user(&getb, (void __user *)arg, 1080 if (copy_from_user(&getb, (void __user *)arg,
991 sizeof(struct mon_bin_get32))) 1081 sizeof(struct mon_bin_get32)))
992 return -EFAULT; 1082 return -EFAULT;
993 1083
994 ret = mon_bin_get_event(file, rp, 1084 ret = mon_bin_get_event(file, rp, compat_ptr(getb.hdr32),
995 compat_ptr(getb.hdr32), compat_ptr(getb.data32), 1085 (cmd == MON_IOCX_GET32)? PKT_SZ_API0: PKT_SZ_API1,
996 getb.alloc32); 1086 compat_ptr(getb.data32), getb.alloc32);
997 if (ret < 0) 1087 if (ret < 0)
998 return ret; 1088 return ret;
999 } 1089 }
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 9985db08e7db..b66e8544d8b9 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -20,8 +20,8 @@ config USB_MUSB_HDRC
20 it's being used with, including the USB peripheral role, 20 it's being used with, including the USB peripheral role,
21 or the USB host role, or both. 21 or the USB host role, or both.
22 22
23 Texas Instruments parts using this IP include DaVinci 644x, 23 Texas Instruments familiies using this IP include DaVinci
24 OMAP 243x, OMAP 343x, and TUSB 6010. 24 (35x, 644x ...), OMAP 243x, OMAP 3, and TUSB 6010.
25 25
26 Analog Devices parts using this IP include Blackfin BF54x, 26 Analog Devices parts using this IP include Blackfin BF54x,
27 BF525 and BF527. 27 BF525 and BF527.
@@ -40,7 +40,7 @@ config USB_MUSB_SOC
40 default y if (BF54x && !BF544) 40 default y if (BF54x && !BF544)
41 default y if (BF52x && !BF522 && !BF523) 41 default y if (BF52x && !BF522 && !BF523)
42 42
43comment "DaVinci 644x USB support" 43comment "DaVinci 35x and 644x USB support"
44 depends on USB_MUSB_HDRC && ARCH_DAVINCI 44 depends on USB_MUSB_HDRC && ARCH_DAVINCI
45 45
46comment "OMAP 243x high speed USB support" 46comment "OMAP 243x high speed USB support"
diff --git a/drivers/usb/musb/davinci.c b/drivers/usb/musb/davinci.c
index 2dc7606f319c..10d11ab113ab 100644
--- a/drivers/usb/musb/davinci.c
+++ b/drivers/usb/musb/davinci.c
@@ -48,6 +48,9 @@
48#include "cppi_dma.h" 48#include "cppi_dma.h"
49 49
50 50
51#define USB_PHY_CTRL IO_ADDRESS(USBPHY_CTL_PADDR)
52#define DM355_DEEPSLEEP IO_ADDRESS(DM355_DEEPSLEEP_PADDR)
53
51/* REVISIT (PM) we should be able to keep the PHY in low power mode most 54/* REVISIT (PM) we should be able to keep the PHY in low power mode most
52 * of the time (24 MHZ oscillator and PLL off, etc) by setting POWER.D0 55 * of the time (24 MHZ oscillator and PLL off, etc) by setting POWER.D0
53 * and, when in host mode, autosuspending idle root ports... PHYPLLON 56 * and, when in host mode, autosuspending idle root ports... PHYPLLON
@@ -56,20 +59,26 @@
56 59
57static inline void phy_on(void) 60static inline void phy_on(void)
58{ 61{
59 /* start the on-chip PHY and its PLL */ 62 u32 phy_ctrl = __raw_readl(USB_PHY_CTRL);
60 __raw_writel(USBPHY_SESNDEN | USBPHY_VBDTCTEN | USBPHY_PHYPLLON, 63
61 (void __force __iomem *) IO_ADDRESS(USBPHY_CTL_PADDR)); 64 /* power everything up; start the on-chip PHY and its PLL */
62 while ((__raw_readl((void __force __iomem *) 65 phy_ctrl &= ~(USBPHY_OSCPDWN | USBPHY_OTGPDWN | USBPHY_PHYPDWN);
63 IO_ADDRESS(USBPHY_CTL_PADDR)) 66 phy_ctrl |= USBPHY_SESNDEN | USBPHY_VBDTCTEN | USBPHY_PHYPLLON;
64 & USBPHY_PHYCLKGD) == 0) 67 __raw_writel(phy_ctrl, USB_PHY_CTRL);
68
69 /* wait for PLL to lock before proceeding */
70 while ((__raw_readl(USB_PHY_CTRL) & USBPHY_PHYCLKGD) == 0)
65 cpu_relax(); 71 cpu_relax();
66} 72}
67 73
68static inline void phy_off(void) 74static inline void phy_off(void)
69{ 75{
70 /* powerdown the on-chip PHY and its oscillator */ 76 u32 phy_ctrl = __raw_readl(USB_PHY_CTRL);
71 __raw_writel(USBPHY_OSCPDWN | USBPHY_PHYPDWN, (void __force __iomem *) 77
72 IO_ADDRESS(USBPHY_CTL_PADDR)); 78 /* powerdown the on-chip PHY, its PLL, and the OTG block */
79 phy_ctrl &= ~(USBPHY_SESNDEN | USBPHY_VBDTCTEN | USBPHY_PHYPLLON);
80 phy_ctrl |= USBPHY_OSCPDWN | USBPHY_OTGPDWN | USBPHY_PHYPDWN;
81 __raw_writel(phy_ctrl, USB_PHY_CTRL);
73} 82}
74 83
75static int dma_off = 1; 84static int dma_off = 1;
@@ -126,10 +135,6 @@ void musb_platform_disable(struct musb *musb)
126} 135}
127 136
128 137
129/* REVISIT it's not clear whether DaVinci can support full OTG. */
130
131static int vbus_state = -1;
132
133#ifdef CONFIG_USB_MUSB_HDRC_HCD 138#ifdef CONFIG_USB_MUSB_HDRC_HCD
134#define portstate(stmt) stmt 139#define portstate(stmt) stmt
135#else 140#else
@@ -137,10 +142,19 @@ static int vbus_state = -1;
137#endif 142#endif
138 143
139 144
140/* VBUS SWITCHING IS BOARD-SPECIFIC */ 145/*
146 * VBUS SWITCHING IS BOARD-SPECIFIC ... at least for the DM6446 EVM,
147 * which doesn't wire DRVVBUS to the FET that switches it. Unclear
148 * if that's a problem with the DM6446 chip or just with that board.
149 *
150 * In either case, the DM355 EVM automates DRVVBUS the normal way,
151 * when J10 is out, and TI documents it as handling OTG.
152 */
141 153
142#ifdef CONFIG_MACH_DAVINCI_EVM 154#ifdef CONFIG_MACH_DAVINCI_EVM
143 155
156static int vbus_state = -1;
157
144/* I2C operations are always synchronous, and require a task context. 158/* I2C operations are always synchronous, and require a task context.
145 * With unloaded systems, using the shared workqueue seems to suffice 159 * With unloaded systems, using the shared workqueue seems to suffice
146 * to satisfy the 100msec A_WAIT_VRISE timeout... 160 * to satisfy the 100msec A_WAIT_VRISE timeout...
@@ -150,12 +164,12 @@ static void evm_deferred_drvvbus(struct work_struct *ignored)
150 gpio_set_value_cansleep(GPIO_nVBUS_DRV, vbus_state); 164 gpio_set_value_cansleep(GPIO_nVBUS_DRV, vbus_state);
151 vbus_state = !vbus_state; 165 vbus_state = !vbus_state;
152} 166}
153static DECLARE_WORK(evm_vbus_work, evm_deferred_drvvbus);
154 167
155#endif /* EVM */ 168#endif /* EVM */
156 169
157static void davinci_source_power(struct musb *musb, int is_on, int immediate) 170static void davinci_source_power(struct musb *musb, int is_on, int immediate)
158{ 171{
172#ifdef CONFIG_MACH_DAVINCI_EVM
159 if (is_on) 173 if (is_on)
160 is_on = 1; 174 is_on = 1;
161 175
@@ -163,16 +177,17 @@ static void davinci_source_power(struct musb *musb, int is_on, int immediate)
163 return; 177 return;
164 vbus_state = !is_on; /* 0/1 vs "-1 == unknown/init" */ 178 vbus_state = !is_on; /* 0/1 vs "-1 == unknown/init" */
165 179
166#ifdef CONFIG_MACH_DAVINCI_EVM
167 if (machine_is_davinci_evm()) { 180 if (machine_is_davinci_evm()) {
181 static DECLARE_WORK(evm_vbus_work, evm_deferred_drvvbus);
182
168 if (immediate) 183 if (immediate)
169 gpio_set_value_cansleep(GPIO_nVBUS_DRV, vbus_state); 184 gpio_set_value_cansleep(GPIO_nVBUS_DRV, vbus_state);
170 else 185 else
171 schedule_work(&evm_vbus_work); 186 schedule_work(&evm_vbus_work);
172 } 187 }
173#endif
174 if (immediate) 188 if (immediate)
175 vbus_state = is_on; 189 vbus_state = is_on;
190#endif
176} 191}
177 192
178static void davinci_set_vbus(struct musb *musb, int is_on) 193static void davinci_set_vbus(struct musb *musb, int is_on)
@@ -391,6 +406,17 @@ int __init musb_platform_init(struct musb *musb)
391 musb->board_set_vbus = davinci_set_vbus; 406 musb->board_set_vbus = davinci_set_vbus;
392 davinci_source_power(musb, 0, 1); 407 davinci_source_power(musb, 0, 1);
393 408
409 /* dm355 EVM swaps D+/D- for signal integrity, and
410 * is clocked from the main 24 MHz crystal.
411 */
412 if (machine_is_davinci_dm355_evm()) {
413 u32 phy_ctrl = __raw_readl(USB_PHY_CTRL);
414
415 phy_ctrl &= ~(3 << 9);
416 phy_ctrl |= USBPHY_DATAPOL;
417 __raw_writel(phy_ctrl, USB_PHY_CTRL);
418 }
419
394 /* reset the controller */ 420 /* reset the controller */
395 musb_writel(tibase, DAVINCI_USB_CTRL_REG, 0x1); 421 musb_writel(tibase, DAVINCI_USB_CTRL_REG, 0x1);
396 422
@@ -401,8 +427,7 @@ int __init musb_platform_init(struct musb *musb)
401 427
402 /* NOTE: irqs are in mixed mode, not bypass to pure-musb */ 428 /* NOTE: irqs are in mixed mode, not bypass to pure-musb */
403 pr_debug("DaVinci OTG revision %08x phy %03x control %02x\n", 429 pr_debug("DaVinci OTG revision %08x phy %03x control %02x\n",
404 revision, __raw_readl((void __force __iomem *) 430 revision, __raw_readl(USB_PHY_CTRL),
405 IO_ADDRESS(USBPHY_CTL_PADDR)),
406 musb_readb(tibase, DAVINCI_USB_CTRL_REG)); 431 musb_readb(tibase, DAVINCI_USB_CTRL_REG));
407 432
408 musb->isr = davinci_interrupt; 433 musb->isr = davinci_interrupt;
diff --git a/drivers/usb/musb/davinci.h b/drivers/usb/musb/davinci.h
index 7fb6238e270f..046c84433cad 100644
--- a/drivers/usb/musb/davinci.h
+++ b/drivers/usb/musb/davinci.h
@@ -15,14 +15,21 @@
15 */ 15 */
16 16
17/* Integrated highspeed/otg PHY */ 17/* Integrated highspeed/otg PHY */
18#define USBPHY_CTL_PADDR (DAVINCI_SYSTEM_MODULE_BASE + 0x34) 18#define USBPHY_CTL_PADDR (DAVINCI_SYSTEM_MODULE_BASE + 0x34)
19#define USBPHY_PHYCLKGD (1 << 8) 19#define USBPHY_DATAPOL BIT(11) /* (dm355) switch D+/D- */
20#define USBPHY_SESNDEN (1 << 7) /* v(sess_end) comparator */ 20#define USBPHY_PHYCLKGD BIT(8)
21#define USBPHY_VBDTCTEN (1 << 6) /* v(bus) comparator */ 21#define USBPHY_SESNDEN BIT(7) /* v(sess_end) comparator */
22#define USBPHY_PHYPLLON (1 << 4) /* override pll suspend */ 22#define USBPHY_VBDTCTEN BIT(6) /* v(bus) comparator */
23#define USBPHY_CLKO1SEL (1 << 3) 23#define USBPHY_VBUSSENS BIT(5) /* (dm355,ro) is vbus > 0.5V */
24#define USBPHY_OSCPDWN (1 << 2) 24#define USBPHY_PHYPLLON BIT(4) /* override pll suspend */
25#define USBPHY_PHYPDWN (1 << 0) 25#define USBPHY_CLKO1SEL BIT(3)
26#define USBPHY_OSCPDWN BIT(2)
27#define USBPHY_OTGPDWN BIT(1)
28#define USBPHY_PHYPDWN BIT(0)
29
30#define DM355_DEEPSLEEP_PADDR (DAVINCI_SYSTEM_MODULE_BASE + 0x48)
31#define DRVVBUS_FORCE BIT(2)
32#define DRVVBUS_OVERRIDE BIT(1)
26 33
27/* For now include usb OTG module registers here */ 34/* For now include usb OTG module registers here */
28#define DAVINCI_USB_VERSION_REG 0x00 35#define DAVINCI_USB_VERSION_REG 0x00
diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index af77e4659006..338cd1611ab3 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -769,7 +769,7 @@ static irqreturn_t musb_stage2_irq(struct musb *musb, u8 int_usb,
769 case OTG_STATE_A_SUSPEND: 769 case OTG_STATE_A_SUSPEND:
770 usb_hcd_resume_root_hub(musb_to_hcd(musb)); 770 usb_hcd_resume_root_hub(musb_to_hcd(musb));
771 musb_root_disconnect(musb); 771 musb_root_disconnect(musb);
772 if (musb->a_wait_bcon != 0) 772 if (musb->a_wait_bcon != 0 && is_otg_enabled(musb))
773 musb_platform_try_idle(musb, jiffies 773 musb_platform_try_idle(musb, jiffies
774 + msecs_to_jiffies(musb->a_wait_bcon)); 774 + msecs_to_jiffies(musb->a_wait_bcon));
775 break; 775 break;
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 630946a2d9fc..efb39b5e55b5 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -331,7 +331,6 @@ struct musb {
331 struct list_head control; /* of musb_qh */ 331 struct list_head control; /* of musb_qh */
332 struct list_head in_bulk; /* of musb_qh */ 332 struct list_head in_bulk; /* of musb_qh */
333 struct list_head out_bulk; /* of musb_qh */ 333 struct list_head out_bulk; /* of musb_qh */
334 struct musb_qh *periodic[32]; /* tree of interrupt+iso */
335#endif 334#endif
336 335
337 /* called with IRQs blocked; ON/nonzero implies starting a session, 336 /* called with IRQs blocked; ON/nonzero implies starting a session,
@@ -479,10 +478,11 @@ static inline void musb_configure_ep0(struct musb *musb)
479static inline int musb_read_fifosize(struct musb *musb, 478static inline int musb_read_fifosize(struct musb *musb,
480 struct musb_hw_ep *hw_ep, u8 epnum) 479 struct musb_hw_ep *hw_ep, u8 epnum)
481{ 480{
481 void *mbase = musb->mregs;
482 u8 reg = 0; 482 u8 reg = 0;
483 483
484 /* read from core using indexed model */ 484 /* read from core using indexed model */
485 reg = musb_readb(hw_ep->regs, 0x10 + MUSB_FIFOSIZE); 485 reg = musb_readb(mbase, MUSB_EP_OFFSET(epnum, MUSB_FIFOSIZE));
486 /* 0's returned when no more endpoints */ 486 /* 0's returned when no more endpoints */
487 if (!reg) 487 if (!reg)
488 return -ENODEV; 488 return -ENODEV;
@@ -509,6 +509,7 @@ static inline void musb_configure_ep0(struct musb *musb)
509{ 509{
510 musb->endpoints[0].max_packet_sz_tx = MUSB_EP0_FIFOSIZE; 510 musb->endpoints[0].max_packet_sz_tx = MUSB_EP0_FIFOSIZE;
511 musb->endpoints[0].max_packet_sz_rx = MUSB_EP0_FIFOSIZE; 511 musb->endpoints[0].max_packet_sz_rx = MUSB_EP0_FIFOSIZE;
512 musb->endpoints[0].is_shared_fifo = true;
512} 513}
513#endif /* CONFIG_BLACKFIN */ 514#endif /* CONFIG_BLACKFIN */
514 515
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index 6dbbd0786a6a..499c431a6d62 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -64,11 +64,8 @@
64 * 64 *
65 * - DMA (Mentor/OMAP) ...has at least toggle update problems 65 * - DMA (Mentor/OMAP) ...has at least toggle update problems
66 * 66 *
67 * - Still no traffic scheduling code to make NAKing for bulk or control 67 * - [23-feb-2009] minimal traffic scheduling to avoid bulk RX packet
68 * transfers unable to starve other requests; or to make efficient use 68 * starvation ... nothing yet for TX, interrupt, or bulk.
69 * of hardware with periodic transfers. (Note that network drivers
70 * commonly post bulk reads that stay pending for a long time; these
71 * would make very visible trouble.)
72 * 69 *
73 * - Not tested with HNP, but some SRP paths seem to behave. 70 * - Not tested with HNP, but some SRP paths seem to behave.
74 * 71 *
@@ -88,11 +85,8 @@
88 * 85 *
89 * CONTROL transfers all go through ep0. BULK ones go through dedicated IN 86 * CONTROL transfers all go through ep0. BULK ones go through dedicated IN
90 * and OUT endpoints ... hardware is dedicated for those "async" queue(s). 87 * and OUT endpoints ... hardware is dedicated for those "async" queue(s).
91 *
92 * (Yes, bulk _could_ use more of the endpoints than that, and would even 88 * (Yes, bulk _could_ use more of the endpoints than that, and would even
93 * benefit from it ... one remote device may easily be NAKing while others 89 * benefit from it.)
94 * need to perform transfers in that same direction. The same thing could
95 * be done in software though, assuming dma cooperates.)
96 * 90 *
97 * INTERUPPT and ISOCHRONOUS transfers are scheduled to the other endpoints. 91 * INTERUPPT and ISOCHRONOUS transfers are scheduled to the other endpoints.
98 * So far that scheduling is both dumb and optimistic: the endpoint will be 92 * So far that scheduling is both dumb and optimistic: the endpoint will be
@@ -201,8 +195,9 @@ musb_start_urb(struct musb *musb, int is_in, struct musb_qh *qh)
201 len = urb->iso_frame_desc[0].length; 195 len = urb->iso_frame_desc[0].length;
202 break; 196 break;
203 default: /* bulk, interrupt */ 197 default: /* bulk, interrupt */
204 buf = urb->transfer_buffer; 198 /* actual_length may be nonzero on retry paths */
205 len = urb->transfer_buffer_length; 199 buf = urb->transfer_buffer + urb->actual_length;
200 len = urb->transfer_buffer_length - urb->actual_length;
206 } 201 }
207 202
208 DBG(4, "qh %p urb %p dev%d ep%d%s%s, hw_ep %d, %p/%d\n", 203 DBG(4, "qh %p urb %p dev%d ep%d%s%s, hw_ep %d, %p/%d\n",
@@ -395,7 +390,6 @@ musb_giveback(struct musb_qh *qh, struct urb *urb, int status)
395 * de-allocated if it's tracked and allocated; 390 * de-allocated if it's tracked and allocated;
396 * and where we'd update the schedule tree... 391 * and where we'd update the schedule tree...
397 */ 392 */
398 musb->periodic[ep->epnum] = NULL;
399 kfree(qh); 393 kfree(qh);
400 qh = NULL; 394 qh = NULL;
401 break; 395 break;
@@ -1045,7 +1039,8 @@ irqreturn_t musb_h_ep0_irq(struct musb *musb)
1045 1039
1046 /* NOTE: this code path would be a good place to PAUSE a 1040 /* NOTE: this code path would be a good place to PAUSE a
1047 * control transfer, if another one is queued, so that 1041 * control transfer, if another one is queued, so that
1048 * ep0 is more likely to stay busy. 1042 * ep0 is more likely to stay busy. That's already done
1043 * for bulk RX transfers.
1049 * 1044 *
1050 * if (qh->ring.next != &musb->control), then 1045 * if (qh->ring.next != &musb->control), then
1051 * we have a candidate... NAKing is *NOT* an error 1046 * we have a candidate... NAKing is *NOT* an error
@@ -1197,6 +1192,7 @@ void musb_host_tx(struct musb *musb, u8 epnum)
1197 /* NOTE: this code path would be a good place to PAUSE a 1192 /* NOTE: this code path would be a good place to PAUSE a
1198 * transfer, if there's some other (nonperiodic) tx urb 1193 * transfer, if there's some other (nonperiodic) tx urb
1199 * that could use this fifo. (dma complicates it...) 1194 * that could use this fifo. (dma complicates it...)
1195 * That's already done for bulk RX transfers.
1200 * 1196 *
1201 * if (bulk && qh->ring.next != &musb->out_bulk), then 1197 * if (bulk && qh->ring.next != &musb->out_bulk), then
1202 * we have a candidate... NAKing is *NOT* an error 1198 * we have a candidate... NAKing is *NOT* an error
@@ -1358,6 +1354,50 @@ finish:
1358 1354
1359#endif 1355#endif
1360 1356
1357/* Schedule next QH from musb->in_bulk and move the current qh to
1358 * the end; avoids starvation for other endpoints.
1359 */
1360static void musb_bulk_rx_nak_timeout(struct musb *musb, struct musb_hw_ep *ep)
1361{
1362 struct dma_channel *dma;
1363 struct urb *urb;
1364 void __iomem *mbase = musb->mregs;
1365 void __iomem *epio = ep->regs;
1366 struct musb_qh *cur_qh, *next_qh;
1367 u16 rx_csr;
1368
1369 musb_ep_select(mbase, ep->epnum);
1370 dma = is_dma_capable() ? ep->rx_channel : NULL;
1371
1372 /* clear nak timeout bit */
1373 rx_csr = musb_readw(epio, MUSB_RXCSR);
1374 rx_csr |= MUSB_RXCSR_H_WZC_BITS;
1375 rx_csr &= ~MUSB_RXCSR_DATAERROR;
1376 musb_writew(epio, MUSB_RXCSR, rx_csr);
1377
1378 cur_qh = first_qh(&musb->in_bulk);
1379 if (cur_qh) {
1380 urb = next_urb(cur_qh);
1381 if (dma_channel_status(dma) == MUSB_DMA_STATUS_BUSY) {
1382 dma->status = MUSB_DMA_STATUS_CORE_ABORT;
1383 musb->dma_controller->channel_abort(dma);
1384 urb->actual_length += dma->actual_len;
1385 dma->actual_len = 0L;
1386 }
1387 musb_save_toggle(ep, 1, urb);
1388
1389 /* move cur_qh to end of queue */
1390 list_move_tail(&cur_qh->ring, &musb->in_bulk);
1391
1392 /* get the next qh from musb->in_bulk */
1393 next_qh = first_qh(&musb->in_bulk);
1394
1395 /* set rx_reinit and schedule the next qh */
1396 ep->rx_reinit = 1;
1397 musb_start_urb(musb, 1, next_qh);
1398 }
1399}
1400
1361/* 1401/*
1362 * Service an RX interrupt for the given IN endpoint; docs cover bulk, iso, 1402 * Service an RX interrupt for the given IN endpoint; docs cover bulk, iso,
1363 * and high-bandwidth IN transfer cases. 1403 * and high-bandwidth IN transfer cases.
@@ -1421,18 +1461,26 @@ void musb_host_rx(struct musb *musb, u8 epnum)
1421 } else if (rx_csr & MUSB_RXCSR_DATAERROR) { 1461 } else if (rx_csr & MUSB_RXCSR_DATAERROR) {
1422 1462
1423 if (USB_ENDPOINT_XFER_ISOC != qh->type) { 1463 if (USB_ENDPOINT_XFER_ISOC != qh->type) {
1424 /* NOTE this code path would be a good place to PAUSE a 1464 DBG(6, "RX end %d NAK timeout\n", epnum);
1425 * transfer, if there's some other (nonperiodic) rx urb 1465
1426 * that could use this fifo. (dma complicates it...) 1466 /* NOTE: NAKing is *NOT* an error, so we want to
1467 * continue. Except ... if there's a request for
1468 * another QH, use that instead of starving it.
1427 * 1469 *
1428 * if (bulk && qh->ring.next != &musb->in_bulk), then 1470 * Devices like Ethernet and serial adapters keep
1429 * we have a candidate... NAKing is *NOT* an error 1471 * reads posted at all times, which will starve
1472 * other devices without this logic.
1430 */ 1473 */
1431 DBG(6, "RX end %d NAK timeout\n", epnum); 1474 if (usb_pipebulk(urb->pipe)
1475 && qh->mux == 1
1476 && !list_is_singular(&musb->in_bulk)) {
1477 musb_bulk_rx_nak_timeout(musb, hw_ep);
1478 return;
1479 }
1432 musb_ep_select(mbase, epnum); 1480 musb_ep_select(mbase, epnum);
1433 musb_writew(epio, MUSB_RXCSR, 1481 rx_csr |= MUSB_RXCSR_H_WZC_BITS;
1434 MUSB_RXCSR_H_WZC_BITS 1482 rx_csr &= ~MUSB_RXCSR_DATAERROR;
1435 | MUSB_RXCSR_H_REQPKT); 1483 musb_writew(epio, MUSB_RXCSR, rx_csr);
1436 1484
1437 goto finish; 1485 goto finish;
1438 } else { 1486 } else {
@@ -1711,31 +1759,27 @@ static int musb_schedule(
1711 1759
1712 /* else, periodic transfers get muxed to other endpoints */ 1760 /* else, periodic transfers get muxed to other endpoints */
1713 1761
1714 /* FIXME this doesn't consider direction, so it can only 1762 /*
1715 * work for one half of the endpoint hardware, and assumes 1763 * We know this qh hasn't been scheduled, so all we need to do
1716 * the previous cases handled all non-shared endpoints...
1717 */
1718
1719 /* we know this qh hasn't been scheduled, so all we need to do
1720 * is choose which hardware endpoint to put it on ... 1764 * is choose which hardware endpoint to put it on ...
1721 * 1765 *
1722 * REVISIT what we really want here is a regular schedule tree 1766 * REVISIT what we really want here is a regular schedule tree
1723 * like e.g. OHCI uses, but for now musb->periodic is just an 1767 * like e.g. OHCI uses.
1724 * array of the _single_ logical endpoint associated with a
1725 * given physical one (identity mapping logical->physical).
1726 *
1727 * that simplistic approach makes TT scheduling a lot simpler;
1728 * there is none, and thus none of its complexity...
1729 */ 1768 */
1730 best_diff = 4096; 1769 best_diff = 4096;
1731 best_end = -1; 1770 best_end = -1;
1732 1771
1733 for (epnum = 1; epnum < musb->nr_endpoints; epnum++) { 1772 for (epnum = 1, hw_ep = musb->endpoints + 1;
1773 epnum < musb->nr_endpoints;
1774 epnum++, hw_ep++) {
1734 int diff; 1775 int diff;
1735 1776
1736 if (musb->periodic[epnum]) 1777 if (is_in || hw_ep->is_shared_fifo) {
1778 if (hw_ep->in_qh != NULL)
1779 continue;
1780 } else if (hw_ep->out_qh != NULL)
1737 continue; 1781 continue;
1738 hw_ep = &musb->endpoints[epnum]; 1782
1739 if (hw_ep == musb->bulk_ep) 1783 if (hw_ep == musb->bulk_ep)
1740 continue; 1784 continue;
1741 1785
@@ -1756,6 +1800,17 @@ static int musb_schedule(
1756 head = &musb->in_bulk; 1800 head = &musb->in_bulk;
1757 else 1801 else
1758 head = &musb->out_bulk; 1802 head = &musb->out_bulk;
1803
1804 /* Enable bulk RX NAK timeout scheme when bulk requests are
1805 * multiplexed. This scheme doen't work in high speed to full
1806 * speed scenario as NAK interrupts are not coming from a
1807 * full speed device connected to a high speed device.
1808 * NAK timeout interval is 8 (128 uframe or 16ms) for HS and
1809 * 4 (8 frame or 8ms) for FS device.
1810 */
1811 if (is_in && qh->dev)
1812 qh->intv_reg =
1813 (USB_SPEED_HIGH == qh->dev->speed) ? 8 : 4;
1759 goto success; 1814 goto success;
1760 } else if (best_end < 0) { 1815 } else if (best_end < 0) {
1761 return -ENOSPC; 1816 return -ENOSPC;
@@ -1764,7 +1819,6 @@ static int musb_schedule(
1764 idle = 1; 1819 idle = 1;
1765 qh->mux = 0; 1820 qh->mux = 0;
1766 hw_ep = musb->endpoints + best_end; 1821 hw_ep = musb->endpoints + best_end;
1767 musb->periodic[best_end] = qh;
1768 DBG(4, "qh %p periodic slot %d\n", qh, best_end); 1822 DBG(4, "qh %p periodic slot %d\n", qh, best_end);
1769success: 1823success:
1770 if (head) { 1824 if (head) {
@@ -1888,13 +1942,11 @@ static int musb_urb_enqueue(
1888 * 1942 *
1889 * The downside of disabling this is that transfer scheduling 1943 * The downside of disabling this is that transfer scheduling
1890 * gets VERY unfair for nonperiodic transfers; a misbehaving 1944 * gets VERY unfair for nonperiodic transfers; a misbehaving
1891 * peripheral could make that hurt. Or for reads, one that's 1945 * peripheral could make that hurt. That's perfectly normal
1892 * perfectly normal: network and other drivers keep reads 1946 * for reads from network or serial adapters ... so we have
1893 * posted at all times, having one pending for a week should 1947 * partial NAKlimit support for bulk RX.
1894 * be perfectly safe.
1895 * 1948 *
1896 * The upside of disabling it is avoidng transfer scheduling 1949 * The upside of disabling it is simpler transfer scheduling.
1897 * code to put this aside for while.
1898 */ 1950 */
1899 interval = 0; 1951 interval = 0;
1900 } 1952 }
diff --git a/drivers/usb/musb/musb_virthub.c b/drivers/usb/musb/musb_virthub.c
index e0e9ce584175..bf677acc83db 100644
--- a/drivers/usb/musb/musb_virthub.c
+++ b/drivers/usb/musb/musb_virthub.c
@@ -285,7 +285,7 @@ int musb_hub_control(
285 desc->bDescLength = 9; 285 desc->bDescLength = 9;
286 desc->bDescriptorType = 0x29; 286 desc->bDescriptorType = 0x29;
287 desc->bNbrPorts = 1; 287 desc->bNbrPorts = 1;
288 desc->wHubCharacteristics = __constant_cpu_to_le16( 288 desc->wHubCharacteristics = cpu_to_le16(
289 0x0001 /* per-port power switching */ 289 0x0001 /* per-port power switching */
290 | 0x0010 /* no overcurrent reporting */ 290 | 0x0010 /* no overcurrent reporting */
291 ); 291 );
diff --git a/drivers/usb/otg/Kconfig b/drivers/usb/otg/Kconfig
index ee55b449ffde..aa884d072f0b 100644
--- a/drivers/usb/otg/Kconfig
+++ b/drivers/usb/otg/Kconfig
@@ -43,7 +43,7 @@ config ISP1301_OMAP
43 43
44config TWL4030_USB 44config TWL4030_USB
45 tristate "TWL4030 USB Transceiver Driver" 45 tristate "TWL4030 USB Transceiver Driver"
46 depends on TWL4030_CORE 46 depends on TWL4030_CORE && REGULATOR_TWL4030
47 select USB_OTG_UTILS 47 select USB_OTG_UTILS
48 help 48 help
49 Enable this to support the USB OTG transceiver on TWL4030 49 Enable this to support the USB OTG transceiver on TWL4030
@@ -51,4 +51,12 @@ config TWL4030_USB
51 This transceiver supports high and full speed devices plus, 51 This transceiver supports high and full speed devices plus,
52 in host mode, low speed. 52 in host mode, low speed.
53 53
54config NOP_USB_XCEIV
55 tristate "NOP USB Transceiver Driver"
56 select USB_OTG_UTILS
57 help
58 this driver is to be used by all the usb transceiver which are either
59 built-in with usb ip or which are autonomous and doesn't require any
60 phy programming such as ISP1x04 etc.
61
54endif # USB || OTG 62endif # USB || OTG
diff --git a/drivers/usb/otg/Makefile b/drivers/usb/otg/Makefile
index d73c7cf5e2f7..208167856529 100644
--- a/drivers/usb/otg/Makefile
+++ b/drivers/usb/otg/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_USB_OTG_UTILS) += otg.o
9obj-$(CONFIG_USB_GPIO_VBUS) += gpio_vbus.o 9obj-$(CONFIG_USB_GPIO_VBUS) += gpio_vbus.o
10obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o 10obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
11obj-$(CONFIG_TWL4030_USB) += twl4030-usb.o 11obj-$(CONFIG_TWL4030_USB) += twl4030-usb.o
12obj-$(CONFIG_NOP_USB_XCEIV) += nop-usb-xceiv.o
12 13
13ccflags-$(CONFIG_USB_DEBUG) += -DDEBUG 14ccflags-$(CONFIG_USB_DEBUG) += -DDEBUG
14ccflags-$(CONFIG_USB_GADGET_DEBUG) += -DDEBUG 15ccflags-$(CONFIG_USB_GADGET_DEBUG) += -DDEBUG
diff --git a/drivers/usb/otg/gpio_vbus.c b/drivers/usb/otg/gpio_vbus.c
index 63a6036f04be..1c26c94513e9 100644
--- a/drivers/usb/otg/gpio_vbus.c
+++ b/drivers/usb/otg/gpio_vbus.c
@@ -13,6 +13,7 @@
13#include <linux/gpio.h> 13#include <linux/gpio.h>
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include <linux/usb.h> 15#include <linux/usb.h>
16#include <linux/workqueue.h>
16 17
17#include <linux/regulator/consumer.h> 18#include <linux/regulator/consumer.h>
18 19
@@ -34,6 +35,7 @@ struct gpio_vbus_data {
34 struct regulator *vbus_draw; 35 struct regulator *vbus_draw;
35 int vbus_draw_enabled; 36 int vbus_draw_enabled;
36 unsigned mA; 37 unsigned mA;
38 struct work_struct work;
37}; 39};
38 40
39 41
@@ -76,24 +78,26 @@ static void set_vbus_draw(struct gpio_vbus_data *gpio_vbus, unsigned mA)
76 gpio_vbus->mA = mA; 78 gpio_vbus->mA = mA;
77} 79}
78 80
79/* VBUS change IRQ handler */ 81static int is_vbus_powered(struct gpio_vbus_mach_info *pdata)
80static irqreturn_t gpio_vbus_irq(int irq, void *data)
81{ 82{
82 struct platform_device *pdev = data; 83 int vbus;
83 struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data;
84 struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev);
85 int gpio, vbus;
86 84
87 vbus = gpio_get_value(pdata->gpio_vbus); 85 vbus = gpio_get_value(pdata->gpio_vbus);
88 if (pdata->gpio_vbus_inverted) 86 if (pdata->gpio_vbus_inverted)
89 vbus = !vbus; 87 vbus = !vbus;
90 88
91 dev_dbg(&pdev->dev, "VBUS %s (gadget: %s)\n", 89 return vbus;
92 vbus ? "supplied" : "inactive", 90}
93 gpio_vbus->otg.gadget ? gpio_vbus->otg.gadget->name : "none"); 91
92static void gpio_vbus_work(struct work_struct *work)
93{
94 struct gpio_vbus_data *gpio_vbus =
95 container_of(work, struct gpio_vbus_data, work);
96 struct gpio_vbus_mach_info *pdata = gpio_vbus->dev->platform_data;
97 int gpio;
94 98
95 if (!gpio_vbus->otg.gadget) 99 if (!gpio_vbus->otg.gadget)
96 return IRQ_HANDLED; 100 return;
97 101
98 /* Peripheral controllers which manage the pullup themselves won't have 102 /* Peripheral controllers which manage the pullup themselves won't have
99 * gpio_pullup configured here. If it's configured here, we'll do what 103 * gpio_pullup configured here. If it's configured here, we'll do what
@@ -101,7 +105,7 @@ static irqreturn_t gpio_vbus_irq(int irq, void *data)
101 * that may complicate usb_gadget_{,dis}connect() support. 105 * that may complicate usb_gadget_{,dis}connect() support.
102 */ 106 */
103 gpio = pdata->gpio_pullup; 107 gpio = pdata->gpio_pullup;
104 if (vbus) { 108 if (is_vbus_powered(pdata)) {
105 gpio_vbus->otg.state = OTG_STATE_B_PERIPHERAL; 109 gpio_vbus->otg.state = OTG_STATE_B_PERIPHERAL;
106 usb_gadget_vbus_connect(gpio_vbus->otg.gadget); 110 usb_gadget_vbus_connect(gpio_vbus->otg.gadget);
107 111
@@ -121,6 +125,21 @@ static irqreturn_t gpio_vbus_irq(int irq, void *data)
121 usb_gadget_vbus_disconnect(gpio_vbus->otg.gadget); 125 usb_gadget_vbus_disconnect(gpio_vbus->otg.gadget);
122 gpio_vbus->otg.state = OTG_STATE_B_IDLE; 126 gpio_vbus->otg.state = OTG_STATE_B_IDLE;
123 } 127 }
128}
129
130/* VBUS change IRQ handler */
131static irqreturn_t gpio_vbus_irq(int irq, void *data)
132{
133 struct platform_device *pdev = data;
134 struct gpio_vbus_mach_info *pdata = pdev->dev.platform_data;
135 struct gpio_vbus_data *gpio_vbus = platform_get_drvdata(pdev);
136
137 dev_dbg(&pdev->dev, "VBUS %s (gadget: %s)\n",
138 is_vbus_powered(pdata) ? "supplied" : "inactive",
139 gpio_vbus->otg.gadget ? gpio_vbus->otg.gadget->name : "none");
140
141 if (gpio_vbus->otg.gadget)
142 schedule_work(&gpio_vbus->work);
124 143
125 return IRQ_HANDLED; 144 return IRQ_HANDLED;
126} 145}
@@ -257,6 +276,7 @@ static int __init gpio_vbus_probe(struct platform_device *pdev)
257 irq, err); 276 irq, err);
258 goto err_irq; 277 goto err_irq;
259 } 278 }
279 INIT_WORK(&gpio_vbus->work, gpio_vbus_work);
260 280
261 /* only active when a gadget is registered */ 281 /* only active when a gadget is registered */
262 err = otg_set_transceiver(&gpio_vbus->otg); 282 err = otg_set_transceiver(&gpio_vbus->otg);
diff --git a/drivers/usb/otg/nop-usb-xceiv.c b/drivers/usb/otg/nop-usb-xceiv.c
new file mode 100644
index 000000000000..4b933f646f2e
--- /dev/null
+++ b/drivers/usb/otg/nop-usb-xceiv.c
@@ -0,0 +1,180 @@
1/*
2 * drivers/usb/otg/nop-usb-xceiv.c
3 *
4 * NOP USB transceiver for all USB transceiver which are either built-in
5 * into USB IP or which are mostly autonomous.
6 *
7 * Copyright (C) 2009 Texas Instruments Inc
8 * Author: Ajay Kumar Gupta <ajay.gupta@ti.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 * Current status:
25 * this is to add "nop" transceiver for all those phy which is
26 * autonomous such as isp1504 etc.
27 */
28
29#include <linux/module.h>
30#include <linux/platform_device.h>
31#include <linux/dma-mapping.h>
32#include <linux/usb/otg.h>
33
34struct nop_usb_xceiv {
35 struct otg_transceiver otg;
36 struct device *dev;
37};
38
39static u64 nop_xceiv_dmamask = DMA_32BIT_MASK;
40
41static struct platform_device nop_xceiv_device = {
42 .name = "nop_usb_xceiv",
43 .id = -1,
44 .dev = {
45 .dma_mask = &nop_xceiv_dmamask,
46 .coherent_dma_mask = DMA_32BIT_MASK,
47 .platform_data = NULL,
48 },
49};
50
51void usb_nop_xceiv_register(void)
52{
53 if (platform_device_register(&nop_xceiv_device) < 0) {
54 printk(KERN_ERR "Unable to register usb nop transceiver\n");
55 return;
56 }
57}
58
59void usb_nop_xceiv_unregister(void)
60{
61 platform_device_unregister(&nop_xceiv_device);
62}
63
64static inline struct nop_usb_xceiv *xceiv_to_nop(struct otg_transceiver *x)
65{
66 return container_of(x, struct nop_usb_xceiv, otg);
67}
68
69static int nop_set_suspend(struct otg_transceiver *x, int suspend)
70{
71 return 0;
72}
73
74static int nop_set_peripheral(struct otg_transceiver *x,
75 struct usb_gadget *gadget)
76{
77 struct nop_usb_xceiv *nop;
78
79 if (!x)
80 return -ENODEV;
81
82 nop = xceiv_to_nop(x);
83
84 if (!gadget) {
85 nop->otg.gadget = NULL;
86 return -ENODEV;
87 }
88
89 nop->otg.gadget = gadget;
90 nop->otg.state = OTG_STATE_B_IDLE;
91 return 0;
92}
93
94static int nop_set_host(struct otg_transceiver *x, struct usb_bus *host)
95{
96 struct nop_usb_xceiv *nop;
97
98 if (!x)
99 return -ENODEV;
100
101 nop = xceiv_to_nop(x);
102
103 if (!host) {
104 nop->otg.host = NULL;
105 return -ENODEV;
106 }
107
108 nop->otg.host = host;
109 return 0;
110}
111
112static int __devinit nop_usb_xceiv_probe(struct platform_device *pdev)
113{
114 struct nop_usb_xceiv *nop;
115 int err;
116
117 nop = kzalloc(sizeof *nop, GFP_KERNEL);
118 if (!nop)
119 return -ENOMEM;
120
121 nop->dev = &pdev->dev;
122 nop->otg.dev = nop->dev;
123 nop->otg.label = "nop-xceiv";
124 nop->otg.state = OTG_STATE_UNDEFINED;
125 nop->otg.set_host = nop_set_host;
126 nop->otg.set_peripheral = nop_set_peripheral;
127 nop->otg.set_suspend = nop_set_suspend;
128
129 err = otg_set_transceiver(&nop->otg);
130 if (err) {
131 dev_err(&pdev->dev, "can't register transceiver, err: %d\n",
132 err);
133 goto exit;
134 }
135
136 platform_set_drvdata(pdev, nop);
137
138 return 0;
139exit:
140 kfree(nop);
141 return err;
142}
143
144static int __devexit nop_usb_xceiv_remove(struct platform_device *pdev)
145{
146 struct nop_usb_xceiv *nop = platform_get_drvdata(pdev);
147
148 otg_set_transceiver(NULL);
149
150 platform_set_drvdata(pdev, NULL);
151 kfree(nop);
152
153 return 0;
154}
155
156static struct platform_driver nop_usb_xceiv_driver = {
157 .probe = nop_usb_xceiv_probe,
158 .remove = __devexit_p(nop_usb_xceiv_remove),
159 .driver = {
160 .name = "nop_usb_xceiv",
161 .owner = THIS_MODULE,
162 },
163};
164
165static int __init nop_usb_xceiv_init(void)
166{
167 return platform_driver_register(&nop_usb_xceiv_driver);
168}
169subsys_initcall(nop_usb_xceiv_init);
170
171static void __exit nop_usb_xceiv_exit(void)
172{
173 platform_driver_unregister(&nop_usb_xceiv_driver);
174}
175module_exit(nop_usb_xceiv_exit);
176
177MODULE_ALIAS("platform:nop_usb_xceiv");
178MODULE_AUTHOR("Texas Instruments Inc");
179MODULE_DESCRIPTION("NOP USB Transceiver driver");
180MODULE_LICENSE("GPL");
diff --git a/drivers/usb/otg/twl4030-usb.c b/drivers/usb/otg/twl4030-usb.c
index 416e4410be02..d9478d0e1c8b 100644
--- a/drivers/usb/otg/twl4030-usb.c
+++ b/drivers/usb/otg/twl4030-usb.c
@@ -34,6 +34,8 @@
34#include <linux/delay.h> 34#include <linux/delay.h>
35#include <linux/usb/otg.h> 35#include <linux/usb/otg.h>
36#include <linux/i2c/twl4030.h> 36#include <linux/i2c/twl4030.h>
37#include <linux/regulator/consumer.h>
38#include <linux/err.h>
37 39
38 40
39/* Register defines */ 41/* Register defines */
@@ -246,6 +248,11 @@ struct twl4030_usb {
246 struct otg_transceiver otg; 248 struct otg_transceiver otg;
247 struct device *dev; 249 struct device *dev;
248 250
251 /* TWL4030 internal USB regulator supplies */
252 struct regulator *usb1v5;
253 struct regulator *usb1v8;
254 struct regulator *usb3v1;
255
249 /* for vbus reporting with irqs disabled */ 256 /* for vbus reporting with irqs disabled */
250 spinlock_t lock; 257 spinlock_t lock;
251 258
@@ -434,6 +441,18 @@ static void twl4030_phy_power(struct twl4030_usb *twl, int on)
434 441
435 pwr = twl4030_usb_read(twl, PHY_PWR_CTRL); 442 pwr = twl4030_usb_read(twl, PHY_PWR_CTRL);
436 if (on) { 443 if (on) {
444 regulator_enable(twl->usb3v1);
445 regulator_enable(twl->usb1v8);
446 /*
447 * Disabling usb3v1 regulator (= writing 0 to VUSB3V1_DEV_GRP
448 * in twl4030) resets the VUSB_DEDICATED2 register. This reset
449 * enables VUSB3V1_SLEEP bit that remaps usb3v1 ACTIVE state to
450 * SLEEP. We work around this by clearing the bit after usv3v1
451 * is re-activated. This ensures that VUSB3V1 is really active.
452 */
453 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0,
454 VUSB_DEDICATED2);
455 regulator_enable(twl->usb1v5);
437 pwr &= ~PHY_PWR_PHYPWD; 456 pwr &= ~PHY_PWR_PHYPWD;
438 WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0); 457 WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0);
439 twl4030_usb_write(twl, PHY_CLK_CTRL, 458 twl4030_usb_write(twl, PHY_CLK_CTRL,
@@ -443,6 +462,9 @@ static void twl4030_phy_power(struct twl4030_usb *twl, int on)
443 } else { 462 } else {
444 pwr |= PHY_PWR_PHYPWD; 463 pwr |= PHY_PWR_PHYPWD;
445 WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0); 464 WARN_ON(twl4030_usb_write_verify(twl, PHY_PWR_CTRL, pwr) < 0);
465 regulator_disable(twl->usb1v5);
466 regulator_disable(twl->usb1v8);
467 regulator_disable(twl->usb3v1);
446 } 468 }
447} 469}
448 470
@@ -468,7 +490,7 @@ static void twl4030_phy_resume(struct twl4030_usb *twl)
468 twl->asleep = 0; 490 twl->asleep = 0;
469} 491}
470 492
471static void twl4030_usb_ldo_init(struct twl4030_usb *twl) 493static int twl4030_usb_ldo_init(struct twl4030_usb *twl)
472{ 494{
473 /* Enable writing to power configuration registers */ 495 /* Enable writing to power configuration registers */
474 twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0xC0, PROTECT_KEY); 496 twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0xC0, PROTECT_KEY);
@@ -480,20 +502,45 @@ static void twl4030_usb_ldo_init(struct twl4030_usb *twl)
480 /* input to VUSB3V1 LDO is from VBAT, not VBUS */ 502 /* input to VUSB3V1 LDO is from VBAT, not VBUS */
481 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x14, VUSB_DEDICATED1); 503 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x14, VUSB_DEDICATED1);
482 504
483 /* turn on 3.1V regulator */ 505 /* Initialize 3.1V regulator */
484 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x20, VUSB3V1_DEV_GRP); 506 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB3V1_DEV_GRP);
507
508 twl->usb3v1 = regulator_get(twl->dev, "usb3v1");
509 if (IS_ERR(twl->usb3v1))
510 return -ENODEV;
511
485 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB3V1_TYPE); 512 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB3V1_TYPE);
486 513
487 /* turn on 1.5V regulator */ 514 /* Initialize 1.5V regulator */
488 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x20, VUSB1V5_DEV_GRP); 515 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V5_DEV_GRP);
516
517 twl->usb1v5 = regulator_get(twl->dev, "usb1v5");
518 if (IS_ERR(twl->usb1v5))
519 goto fail1;
520
489 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V5_TYPE); 521 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V5_TYPE);
490 522
491 /* turn on 1.8V regulator */ 523 /* Initialize 1.8V regulator */
492 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0x20, VUSB1V8_DEV_GRP); 524 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V8_DEV_GRP);
525
526 twl->usb1v8 = regulator_get(twl->dev, "usb1v8");
527 if (IS_ERR(twl->usb1v8))
528 goto fail2;
529
493 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE); 530 twl4030_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, 0, VUSB1V8_TYPE);
494 531
495 /* disable access to power configuration registers */ 532 /* disable access to power configuration registers */
496 twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, PROTECT_KEY); 533 twl4030_i2c_write_u8(TWL4030_MODULE_PM_MASTER, 0, PROTECT_KEY);
534
535 return 0;
536
537fail2:
538 regulator_put(twl->usb1v5);
539 twl->usb1v5 = NULL;
540fail1:
541 regulator_put(twl->usb3v1);
542 twl->usb3v1 = NULL;
543 return -ENODEV;
497} 544}
498 545
499static ssize_t twl4030_usb_vbus_show(struct device *dev, 546static ssize_t twl4030_usb_vbus_show(struct device *dev,
@@ -598,7 +645,7 @@ static int __init twl4030_usb_probe(struct platform_device *pdev)
598{ 645{
599 struct twl4030_usb_data *pdata = pdev->dev.platform_data; 646 struct twl4030_usb_data *pdata = pdev->dev.platform_data;
600 struct twl4030_usb *twl; 647 struct twl4030_usb *twl;
601 int status; 648 int status, err;
602 649
603 if (!pdata) { 650 if (!pdata) {
604 dev_dbg(&pdev->dev, "platform_data not available\n"); 651 dev_dbg(&pdev->dev, "platform_data not available\n");
@@ -622,7 +669,12 @@ static int __init twl4030_usb_probe(struct platform_device *pdev)
622 /* init spinlock for workqueue */ 669 /* init spinlock for workqueue */
623 spin_lock_init(&twl->lock); 670 spin_lock_init(&twl->lock);
624 671
625 twl4030_usb_ldo_init(twl); 672 err = twl4030_usb_ldo_init(twl);
673 if (err) {
674 dev_err(&pdev->dev, "ldo init failed\n");
675 kfree(twl);
676 return err;
677 }
626 otg_set_transceiver(&twl->otg); 678 otg_set_transceiver(&twl->otg);
627 679
628 platform_set_drvdata(pdev, twl); 680 platform_set_drvdata(pdev, twl);
@@ -688,6 +740,9 @@ static int __exit twl4030_usb_remove(struct platform_device *pdev)
688 twl4030_usb_clear_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB); 740 twl4030_usb_clear_bits(twl, POWER_CTRL, POWER_CTRL_OTG_ENAB);
689 741
690 twl4030_phy_power(twl, 0); 742 twl4030_phy_power(twl, 0);
743 regulator_put(twl->usb1v5);
744 regulator_put(twl->usb1v8);
745 regulator_put(twl->usb3v1);
691 746
692 kfree(twl); 747 kfree(twl);
693 748
diff --git a/drivers/usb/serial/Kconfig b/drivers/usb/serial/Kconfig
index b361f05cafac..a65f9196b0a0 100644
--- a/drivers/usb/serial/Kconfig
+++ b/drivers/usb/serial/Kconfig
@@ -116,14 +116,14 @@ config USB_SERIAL_DIGI_ACCELEPORT
116 To compile this driver as a module, choose M here: the 116 To compile this driver as a module, choose M here: the
117 module will be called digi_acceleport. 117 module will be called digi_acceleport.
118 118
119config USB_SERIAL_CP2101 119config USB_SERIAL_CP210X
120 tristate "USB CP2101 UART Bridge Controller" 120 tristate "USB CP210x family of UART Bridge Controllers"
121 help 121 help
122 Say Y here if you want to use a CP2101/CP2102 based USB to RS232 122 Say Y here if you want to use a CP2101/CP2102/CP2103 based USB
123 converter. 123 to RS232 converters.
124 124
125 To compile this driver as a module, choose M here: the 125 To compile this driver as a module, choose M here: the
126 module will be called cp2101. 126 module will be called cp210x.
127 127
128config USB_SERIAL_CYPRESS_M8 128config USB_SERIAL_CYPRESS_M8
129 tristate "USB Cypress M8 USB Serial Driver" 129 tristate "USB Cypress M8 USB Serial Driver"
@@ -472,6 +472,15 @@ config USB_SERIAL_OTI6858
472 To compile this driver as a module, choose M here: the 472 To compile this driver as a module, choose M here: the
473 module will be called oti6858. 473 module will be called oti6858.
474 474
475config USB_SERIAL_QUALCOMM
476 tristate "USB Qualcomm Serial modem"
477 help
478 Say Y here if you have a Qualcomm USB modem device. These are
479 usually wireless cellular modems.
480
481 To compile this driver as a module, choose M here: the
482 module will be called qcserial.
483
475config USB_SERIAL_SPCP8X5 484config USB_SERIAL_SPCP8X5
476 tristate "USB SPCP8x5 USB To Serial Driver" 485 tristate "USB SPCP8x5 USB To Serial Driver"
477 help 486 help
@@ -515,6 +524,15 @@ config USB_SERIAL_SIERRAWIRELESS
515 To compile this driver as a module, choose M here: the 524 To compile this driver as a module, choose M here: the
516 module will be called sierra. 525 module will be called sierra.
517 526
527config USB_SERIAL_SYMBOL
528 tristate "USB Symbol Barcode driver (serial mode)"
529 help
530 Say Y here if you want to use a Symbol USB Barcode device
531 in serial emulation mode.
532
533 To compile this driver as a module, choose M here: the
534 module will be called symbolserial.
535
518config USB_SERIAL_TI 536config USB_SERIAL_TI
519 tristate "USB TI 3410/5052 Serial Driver" 537 tristate "USB TI 3410/5052 Serial Driver"
520 help 538 help
diff --git a/drivers/usb/serial/Makefile b/drivers/usb/serial/Makefile
index b75be91eb8f1..66619beb6cc0 100644
--- a/drivers/usb/serial/Makefile
+++ b/drivers/usb/serial/Makefile
@@ -15,7 +15,7 @@ obj-$(CONFIG_USB_SERIAL_AIRCABLE) += aircable.o
15obj-$(CONFIG_USB_SERIAL_ARK3116) += ark3116.o 15obj-$(CONFIG_USB_SERIAL_ARK3116) += ark3116.o
16obj-$(CONFIG_USB_SERIAL_BELKIN) += belkin_sa.o 16obj-$(CONFIG_USB_SERIAL_BELKIN) += belkin_sa.o
17obj-$(CONFIG_USB_SERIAL_CH341) += ch341.o 17obj-$(CONFIG_USB_SERIAL_CH341) += ch341.o
18obj-$(CONFIG_USB_SERIAL_CP2101) += cp2101.o 18obj-$(CONFIG_USB_SERIAL_CP210X) += cp210x.o
19obj-$(CONFIG_USB_SERIAL_CYBERJACK) += cyberjack.o 19obj-$(CONFIG_USB_SERIAL_CYBERJACK) += cyberjack.o
20obj-$(CONFIG_USB_SERIAL_CYPRESS_M8) += cypress_m8.o 20obj-$(CONFIG_USB_SERIAL_CYPRESS_M8) += cypress_m8.o
21obj-$(CONFIG_USB_SERIAL_DEBUG) += usb_debug.o 21obj-$(CONFIG_USB_SERIAL_DEBUG) += usb_debug.o
@@ -45,10 +45,12 @@ obj-$(CONFIG_USB_SERIAL_OPTICON) += opticon.o
45obj-$(CONFIG_USB_SERIAL_OPTION) += option.o 45obj-$(CONFIG_USB_SERIAL_OPTION) += option.o
46obj-$(CONFIG_USB_SERIAL_OTI6858) += oti6858.o 46obj-$(CONFIG_USB_SERIAL_OTI6858) += oti6858.o
47obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o 47obj-$(CONFIG_USB_SERIAL_PL2303) += pl2303.o
48obj-$(CONFIG_USB_SERIAL_QUALCOMM) += qcserial.o
48obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o 49obj-$(CONFIG_USB_SERIAL_SAFE) += safe_serial.o
49obj-$(CONFIG_USB_SERIAL_SIEMENS_MPI) += siemens_mpi.o 50obj-$(CONFIG_USB_SERIAL_SIEMENS_MPI) += siemens_mpi.o
50obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o 51obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o
51obj-$(CONFIG_USB_SERIAL_SPCP8X5) += spcp8x5.o 52obj-$(CONFIG_USB_SERIAL_SPCP8X5) += spcp8x5.o
53obj-$(CONFIG_USB_SERIAL_SYMBOL) += symbolserial.o
52obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o 54obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o
53obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o 55obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o
54obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o 56obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index f61e3ca64305..ab4cc277aa65 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -1,5 +1,7 @@
1/* 1/*
2 * Copyright 2007, Frank A Kingswood <frank@kingswood-consulting.co.uk> 2 * Copyright 2007, Frank A Kingswood <frank@kingswood-consulting.co.uk>
3 * Copyright 2007, Werner Cornelius <werner@cornelius-consult.de>
4 * Copyright 2009, Boris Hajduk <boris@hajduk.org>
3 * 5 *
4 * ch341.c implements a serial port driver for the Winchiphead CH341. 6 * ch341.c implements a serial port driver for the Winchiphead CH341.
5 * 7 *
@@ -21,9 +23,39 @@
21#include <linux/usb/serial.h> 23#include <linux/usb/serial.h>
22#include <linux/serial.h> 24#include <linux/serial.h>
23 25
24#define DEFAULT_BAUD_RATE 2400 26#define DEFAULT_BAUD_RATE 9600
25#define DEFAULT_TIMEOUT 1000 27#define DEFAULT_TIMEOUT 1000
26 28
29/* flags for IO-Bits */
30#define CH341_BIT_RTS (1 << 6)
31#define CH341_BIT_DTR (1 << 5)
32
33/******************************/
34/* interrupt pipe definitions */
35/******************************/
36/* always 4 interrupt bytes */
37/* first irq byte normally 0x08 */
38/* second irq byte base 0x7d + below */
39/* third irq byte base 0x94 + below */
40/* fourth irq byte normally 0xee */
41
42/* second interrupt byte */
43#define CH341_MULT_STAT 0x04 /* multiple status since last interrupt event */
44
45/* status returned in third interrupt answer byte, inverted in data
46 from irq */
47#define CH341_BIT_CTS 0x01
48#define CH341_BIT_DSR 0x02
49#define CH341_BIT_RI 0x04
50#define CH341_BIT_DCD 0x08
51#define CH341_BITS_MODEM_STAT 0x0f /* all bits */
52
53/*******************************/
54/* baudrate calculation factor */
55/*******************************/
56#define CH341_BAUDBASE_FACTOR 1532620800
57#define CH341_BAUDBASE_DIVMAX 3
58
27static int debug; 59static int debug;
28 60
29static struct usb_device_id id_table [] = { 61static struct usb_device_id id_table [] = {
@@ -34,9 +66,12 @@ static struct usb_device_id id_table [] = {
34MODULE_DEVICE_TABLE(usb, id_table); 66MODULE_DEVICE_TABLE(usb, id_table);
35 67
36struct ch341_private { 68struct ch341_private {
37 unsigned baud_rate; 69 spinlock_t lock; /* access lock */
38 u8 dtr; 70 wait_queue_head_t delta_msr_wait; /* wait queue for modem status */
39 u8 rts; 71 unsigned baud_rate; /* set baud rate */
72 u8 line_control; /* set line control value RTS/DTR */
73 u8 line_status; /* active status of modem control inputs */
74 u8 multi_status_change; /* status changed multiple since last call */
40}; 75};
41 76
42static int ch341_control_out(struct usb_device *dev, u8 request, 77static int ch341_control_out(struct usb_device *dev, u8 request,
@@ -72,37 +107,28 @@ static int ch341_set_baudrate(struct usb_device *dev,
72{ 107{
73 short a, b; 108 short a, b;
74 int r; 109 int r;
110 unsigned long factor;
111 short divisor;
75 112
76 dbg("ch341_set_baudrate(%d)", priv->baud_rate); 113 dbg("ch341_set_baudrate(%d)", priv->baud_rate);
77 switch (priv->baud_rate) { 114
78 case 2400: 115 if (!priv->baud_rate)
79 a = 0xd901;
80 b = 0x0038;
81 break;
82 case 4800:
83 a = 0x6402;
84 b = 0x001f;
85 break;
86 case 9600:
87 a = 0xb202;
88 b = 0x0013;
89 break;
90 case 19200:
91 a = 0xd902;
92 b = 0x000d;
93 break;
94 case 38400:
95 a = 0x6403;
96 b = 0x000a;
97 break;
98 case 115200:
99 a = 0xcc03;
100 b = 0x0008;
101 break;
102 default:
103 return -EINVAL; 116 return -EINVAL;
117 factor = (CH341_BAUDBASE_FACTOR / priv->baud_rate);
118 divisor = CH341_BAUDBASE_DIVMAX;
119
120 while ((factor > 0xfff0) && divisor) {
121 factor >>= 3;
122 divisor--;
104 } 123 }
105 124
125 if (factor > 0xfff0)
126 return -EINVAL;
127
128 factor = 0x10000 - factor;
129 a = (factor & 0xff00) | divisor;
130 b = factor & 0xff;
131
106 r = ch341_control_out(dev, 0x9a, 0x1312, a); 132 r = ch341_control_out(dev, 0x9a, 0x1312, a);
107 if (!r) 133 if (!r)
108 r = ch341_control_out(dev, 0x9a, 0x0f2c, b); 134 r = ch341_control_out(dev, 0x9a, 0x0f2c, b);
@@ -110,19 +136,18 @@ static int ch341_set_baudrate(struct usb_device *dev,
110 return r; 136 return r;
111} 137}
112 138
113static int ch341_set_handshake(struct usb_device *dev, 139static int ch341_set_handshake(struct usb_device *dev, u8 control)
114 struct ch341_private *priv)
115{ 140{
116 dbg("ch341_set_handshake(%d,%d)", priv->dtr, priv->rts); 141 dbg("ch341_set_handshake(0x%02x)", control);
117 return ch341_control_out(dev, 0xa4, 142 return ch341_control_out(dev, 0xa4, ~control, 0);
118 ~((priv->dtr?1<<5:0)|(priv->rts?1<<6:0)), 0);
119} 143}
120 144
121static int ch341_get_status(struct usb_device *dev) 145static int ch341_get_status(struct usb_device *dev, struct ch341_private *priv)
122{ 146{
123 char *buffer; 147 char *buffer;
124 int r; 148 int r;
125 const unsigned size = 8; 149 const unsigned size = 8;
150 unsigned long flags;
126 151
127 dbg("ch341_get_status()"); 152 dbg("ch341_get_status()");
128 153
@@ -134,10 +159,15 @@ static int ch341_get_status(struct usb_device *dev)
134 if (r < 0) 159 if (r < 0)
135 goto out; 160 goto out;
136 161
137 /* Not having the datasheet for the CH341, we ignore the bytes returned 162 /* setup the private status if available */
138 * from the device. Return error if the device did not respond in time. 163 if (r == 2) {
139 */ 164 r = 0;
140 r = 0; 165 spin_lock_irqsave(&priv->lock, flags);
166 priv->line_status = (~(*buffer)) & CH341_BITS_MODEM_STAT;
167 priv->multi_status_change = 0;
168 spin_unlock_irqrestore(&priv->lock, flags);
169 } else
170 r = -EPROTO;
141 171
142out: kfree(buffer); 172out: kfree(buffer);
143 return r; 173 return r;
@@ -180,7 +210,7 @@ static int ch341_configure(struct usb_device *dev, struct ch341_private *priv)
180 goto out; 210 goto out;
181 211
182 /* expect 0xff 0xee */ 212 /* expect 0xff 0xee */
183 r = ch341_get_status(dev); 213 r = ch341_get_status(dev, priv);
184 if (r < 0) 214 if (r < 0)
185 goto out; 215 goto out;
186 216
@@ -192,12 +222,12 @@ static int ch341_configure(struct usb_device *dev, struct ch341_private *priv)
192 if (r < 0) 222 if (r < 0)
193 goto out; 223 goto out;
194 224
195 r = ch341_set_handshake(dev, priv); 225 r = ch341_set_handshake(dev, priv->line_control);
196 if (r < 0) 226 if (r < 0)
197 goto out; 227 goto out;
198 228
199 /* expect 0x9f 0xee */ 229 /* expect 0x9f 0xee */
200 r = ch341_get_status(dev); 230 r = ch341_get_status(dev, priv);
201 231
202out: kfree(buffer); 232out: kfree(buffer);
203 return r; 233 return r;
@@ -216,9 +246,10 @@ static int ch341_attach(struct usb_serial *serial)
216 if (!priv) 246 if (!priv)
217 return -ENOMEM; 247 return -ENOMEM;
218 248
249 spin_lock_init(&priv->lock);
250 init_waitqueue_head(&priv->delta_msr_wait);
219 priv->baud_rate = DEFAULT_BAUD_RATE; 251 priv->baud_rate = DEFAULT_BAUD_RATE;
220 priv->dtr = 1; 252 priv->line_control = CH341_BIT_RTS | CH341_BIT_DTR;
221 priv->rts = 1;
222 253
223 r = ch341_configure(serial->dev, priv); 254 r = ch341_configure(serial->dev, priv);
224 if (r < 0) 255 if (r < 0)
@@ -231,6 +262,35 @@ error: kfree(priv);
231 return r; 262 return r;
232} 263}
233 264
265static void ch341_close(struct tty_struct *tty, struct usb_serial_port *port,
266 struct file *filp)
267{
268 struct ch341_private *priv = usb_get_serial_port_data(port);
269 unsigned long flags;
270 unsigned int c_cflag;
271
272 dbg("%s - port %d", __func__, port->number);
273
274 /* shutdown our urbs */
275 dbg("%s - shutting down urbs", __func__);
276 usb_kill_urb(port->write_urb);
277 usb_kill_urb(port->read_urb);
278 usb_kill_urb(port->interrupt_in_urb);
279
280 if (tty) {
281 c_cflag = tty->termios->c_cflag;
282 if (c_cflag & HUPCL) {
283 /* drop DTR and RTS */
284 spin_lock_irqsave(&priv->lock, flags);
285 priv->line_control = 0;
286 spin_unlock_irqrestore(&priv->lock, flags);
287 ch341_set_handshake(port->serial->dev, 0);
288 }
289 }
290 wake_up_interruptible(&priv->delta_msr_wait);
291}
292
293
234/* open this device, set default parameters */ 294/* open this device, set default parameters */
235static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port, 295static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port,
236 struct file *filp) 296 struct file *filp)
@@ -242,14 +302,13 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port,
242 dbg("ch341_open()"); 302 dbg("ch341_open()");
243 303
244 priv->baud_rate = DEFAULT_BAUD_RATE; 304 priv->baud_rate = DEFAULT_BAUD_RATE;
245 priv->dtr = 1; 305 priv->line_control = CH341_BIT_RTS | CH341_BIT_DTR;
246 priv->rts = 1;
247 306
248 r = ch341_configure(serial->dev, priv); 307 r = ch341_configure(serial->dev, priv);
249 if (r) 308 if (r)
250 goto out; 309 goto out;
251 310
252 r = ch341_set_handshake(serial->dev, priv); 311 r = ch341_set_handshake(serial->dev, priv->line_control);
253 if (r) 312 if (r)
254 goto out; 313 goto out;
255 314
@@ -257,6 +316,16 @@ static int ch341_open(struct tty_struct *tty, struct usb_serial_port *port,
257 if (r) 316 if (r)
258 goto out; 317 goto out;
259 318
319 dbg("%s - submitting interrupt urb", __func__);
320 port->interrupt_in_urb->dev = serial->dev;
321 r = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
322 if (r) {
323 dev_err(&port->dev, "%s - failed submitting interrupt urb,"
324 " error %d\n", __func__, r);
325 ch341_close(tty, port, NULL);
326 return -EPROTO;
327 }
328
260 r = usb_serial_generic_open(tty, port, filp); 329 r = usb_serial_generic_open(tty, port, filp);
261 330
262out: return r; 331out: return r;
@@ -270,46 +339,224 @@ static void ch341_set_termios(struct tty_struct *tty,
270{ 339{
271 struct ch341_private *priv = usb_get_serial_port_data(port); 340 struct ch341_private *priv = usb_get_serial_port_data(port);
272 unsigned baud_rate; 341 unsigned baud_rate;
342 unsigned long flags;
273 343
274 dbg("ch341_set_termios()"); 344 dbg("ch341_set_termios()");
275 345
346 if (!tty || !tty->termios)
347 return;
348
276 baud_rate = tty_get_baud_rate(tty); 349 baud_rate = tty_get_baud_rate(tty);
277 350
278 switch (baud_rate) { 351 priv->baud_rate = baud_rate;
279 case 2400: 352
280 case 4800: 353 if (baud_rate) {
281 case 9600: 354 spin_lock_irqsave(&priv->lock, flags);
282 case 19200: 355 priv->line_control |= (CH341_BIT_DTR | CH341_BIT_RTS);
283 case 38400: 356 spin_unlock_irqrestore(&priv->lock, flags);
284 case 115200: 357 ch341_set_baudrate(port->serial->dev, priv);
285 priv->baud_rate = baud_rate; 358 } else {
286 break; 359 spin_lock_irqsave(&priv->lock, flags);
287 default: 360 priv->line_control &= ~(CH341_BIT_DTR | CH341_BIT_RTS);
288 dbg("Rate %d not supported, using %d", 361 spin_unlock_irqrestore(&priv->lock, flags);
289 baud_rate, DEFAULT_BAUD_RATE);
290 priv->baud_rate = DEFAULT_BAUD_RATE;
291 } 362 }
292 363
293 ch341_set_baudrate(port->serial->dev, priv); 364 ch341_set_handshake(port->serial->dev, priv->line_control);
294 365
295 /* Unimplemented: 366 /* Unimplemented:
296 * (cflag & CSIZE) : data bits [5, 8] 367 * (cflag & CSIZE) : data bits [5, 8]
297 * (cflag & PARENB) : parity {NONE, EVEN, ODD} 368 * (cflag & PARENB) : parity {NONE, EVEN, ODD}
298 * (cflag & CSTOPB) : stop bits [1, 2] 369 * (cflag & CSTOPB) : stop bits [1, 2]
299 */ 370 */
371}
372
373static int ch341_tiocmset(struct tty_struct *tty, struct file *file,
374 unsigned int set, unsigned int clear)
375{
376 struct usb_serial_port *port = tty->driver_data;
377 struct ch341_private *priv = usb_get_serial_port_data(port);
378 unsigned long flags;
379 u8 control;
380
381 spin_lock_irqsave(&priv->lock, flags);
382 if (set & TIOCM_RTS)
383 priv->line_control |= CH341_BIT_RTS;
384 if (set & TIOCM_DTR)
385 priv->line_control |= CH341_BIT_DTR;
386 if (clear & TIOCM_RTS)
387 priv->line_control &= ~CH341_BIT_RTS;
388 if (clear & TIOCM_DTR)
389 priv->line_control &= ~CH341_BIT_DTR;
390 control = priv->line_control;
391 spin_unlock_irqrestore(&priv->lock, flags);
392
393 return ch341_set_handshake(port->serial->dev, control);
394}
395
396static void ch341_read_int_callback(struct urb *urb)
397{
398 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
399 unsigned char *data = urb->transfer_buffer;
400 unsigned int actual_length = urb->actual_length;
401 int status;
402
403 dbg("%s (%d)", __func__, port->number);
404
405 switch (urb->status) {
406 case 0:
407 /* success */
408 break;
409 case -ECONNRESET:
410 case -ENOENT:
411 case -ESHUTDOWN:
412 /* this urb is terminated, clean up */
413 dbg("%s - urb shutting down with status: %d", __func__,
414 urb->status);
415 return;
416 default:
417 dbg("%s - nonzero urb status received: %d", __func__,
418 urb->status);
419 goto exit;
420 }
300 421
301 /* Copy back the old hardware settings */ 422 usb_serial_debug_data(debug, &port->dev, __func__,
302 tty_termios_copy_hw(tty->termios, old_termios); 423 urb->actual_length, urb->transfer_buffer);
303 /* And re-encode with the new baud */ 424
304 tty_encode_baud_rate(tty, baud_rate, baud_rate); 425 if (actual_length >= 4) {
426 struct ch341_private *priv = usb_get_serial_port_data(port);
427 unsigned long flags;
428
429 spin_lock_irqsave(&priv->lock, flags);
430 priv->line_status = (~(data[2])) & CH341_BITS_MODEM_STAT;
431 if ((data[1] & CH341_MULT_STAT))
432 priv->multi_status_change = 1;
433 spin_unlock_irqrestore(&priv->lock, flags);
434 wake_up_interruptible(&priv->delta_msr_wait);
435 }
436
437exit:
438 status = usb_submit_urb(urb, GFP_ATOMIC);
439 if (status)
440 dev_err(&urb->dev->dev,
441 "%s - usb_submit_urb failed with result %d\n",
442 __func__, status);
443}
444
445static int wait_modem_info(struct usb_serial_port *port, unsigned int arg)
446{
447 struct ch341_private *priv = usb_get_serial_port_data(port);
448 unsigned long flags;
449 u8 prevstatus;
450 u8 status;
451 u8 changed;
452 u8 multi_change = 0;
453
454 spin_lock_irqsave(&priv->lock, flags);
455 prevstatus = priv->line_status;
456 priv->multi_status_change = 0;
457 spin_unlock_irqrestore(&priv->lock, flags);
458
459 while (!multi_change) {
460 interruptible_sleep_on(&priv->delta_msr_wait);
461 /* see if a signal did it */
462 if (signal_pending(current))
463 return -ERESTARTSYS;
464
465 spin_lock_irqsave(&priv->lock, flags);
466 status = priv->line_status;
467 multi_change = priv->multi_status_change;
468 spin_unlock_irqrestore(&priv->lock, flags);
469
470 changed = prevstatus ^ status;
471
472 if (((arg & TIOCM_RNG) && (changed & CH341_BIT_RI)) ||
473 ((arg & TIOCM_DSR) && (changed & CH341_BIT_DSR)) ||
474 ((arg & TIOCM_CD) && (changed & CH341_BIT_DCD)) ||
475 ((arg & TIOCM_CTS) && (changed & CH341_BIT_CTS))) {
476 return 0;
477 }
478 prevstatus = status;
479 }
480
481 return 0;
482}
483
484/*static int ch341_ioctl(struct usb_serial_port *port, struct file *file,*/
485static int ch341_ioctl(struct tty_struct *tty, struct file *file,
486 unsigned int cmd, unsigned long arg)
487{
488 struct usb_serial_port *port = tty->driver_data;
489 dbg("%s (%d) cmd = 0x%04x", __func__, port->number, cmd);
490
491 switch (cmd) {
492 case TIOCMIWAIT:
493 dbg("%s (%d) TIOCMIWAIT", __func__, port->number);
494 return wait_modem_info(port, arg);
495
496 default:
497 dbg("%s not supported = 0x%04x", __func__, cmd);
498 break;
499 }
500
501 return -ENOIOCTLCMD;
502}
503
504static int ch341_tiocmget(struct tty_struct *tty, struct file *file)
505{
506 struct usb_serial_port *port = tty->driver_data;
507 struct ch341_private *priv = usb_get_serial_port_data(port);
508 unsigned long flags;
509 u8 mcr;
510 u8 status;
511 unsigned int result;
512
513 dbg("%s (%d)", __func__, port->number);
514
515 spin_lock_irqsave(&priv->lock, flags);
516 mcr = priv->line_control;
517 status = priv->line_status;
518 spin_unlock_irqrestore(&priv->lock, flags);
519
520 result = ((mcr & CH341_BIT_DTR) ? TIOCM_DTR : 0)
521 | ((mcr & CH341_BIT_RTS) ? TIOCM_RTS : 0)
522 | ((status & CH341_BIT_CTS) ? TIOCM_CTS : 0)
523 | ((status & CH341_BIT_DSR) ? TIOCM_DSR : 0)
524 | ((status & CH341_BIT_RI) ? TIOCM_RI : 0)
525 | ((status & CH341_BIT_DCD) ? TIOCM_CD : 0);
526
527 dbg("%s - result = %x", __func__, result);
528
529 return result;
530}
531
532
533static int ch341_reset_resume(struct usb_interface *intf)
534{
535 struct usb_device *dev = interface_to_usbdev(intf);
536 struct usb_serial *serial = NULL;
537 struct ch341_private *priv;
538
539 serial = usb_get_intfdata(intf);
540 priv = usb_get_serial_port_data(serial->port[0]);
541
542 /*reconfigure ch341 serial port after bus-reset*/
543 ch341_configure(dev, priv);
544
545 usb_serial_resume(intf);
546
547 return 0;
305} 548}
306 549
307static struct usb_driver ch341_driver = { 550static struct usb_driver ch341_driver = {
308 .name = "ch341", 551 .name = "ch341",
309 .probe = usb_serial_probe, 552 .probe = usb_serial_probe,
310 .disconnect = usb_serial_disconnect, 553 .disconnect = usb_serial_disconnect,
554 .suspend = usb_serial_suspend,
555 .resume = usb_serial_resume,
556 .reset_resume = ch341_reset_resume,
311 .id_table = id_table, 557 .id_table = id_table,
312 .no_dynamic_id = 1, 558 .no_dynamic_id = 1,
559 .supports_autosuspend = 1,
313}; 560};
314 561
315static struct usb_serial_driver ch341_device = { 562static struct usb_serial_driver ch341_device = {
@@ -317,12 +564,17 @@ static struct usb_serial_driver ch341_device = {
317 .owner = THIS_MODULE, 564 .owner = THIS_MODULE,
318 .name = "ch341-uart", 565 .name = "ch341-uart",
319 }, 566 },
320 .id_table = id_table, 567 .id_table = id_table,
321 .usb_driver = &ch341_driver, 568 .usb_driver = &ch341_driver,
322 .num_ports = 1, 569 .num_ports = 1,
323 .open = ch341_open, 570 .open = ch341_open,
324 .set_termios = ch341_set_termios, 571 .close = ch341_close,
325 .attach = ch341_attach, 572 .ioctl = ch341_ioctl,
573 .set_termios = ch341_set_termios,
574 .tiocmget = ch341_tiocmget,
575 .tiocmset = ch341_tiocmset,
576 .read_int_callback = ch341_read_int_callback,
577 .attach = ch341_attach,
326}; 578};
327 579
328static int __init ch341_init(void) 580static int __init ch341_init(void)
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp210x.c
index 9b4082b58c5b..e8d5133ce9c8 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp210x.c
@@ -11,10 +11,6 @@
11 * thanks to Karl Hiramoto karl@hiramoto.org. RTSCTS hardware flow 11 * thanks to Karl Hiramoto karl@hiramoto.org. RTSCTS hardware flow
12 * control thanks to Munir Nassar nassarmu@real-time.com 12 * control thanks to Munir Nassar nassarmu@real-time.com
13 * 13 *
14 * Outstanding Issues:
15 * Buffers are not flushed when the port is opened.
16 * Multiple calls to write() may fail with "Resource temporarily unavailable"
17 *
18 */ 14 */
19 15
20#include <linux/kernel.h> 16#include <linux/kernel.h>
@@ -31,7 +27,7 @@
31/* 27/*
32 * Version Information 28 * Version Information
33 */ 29 */
34#define DRIVER_VERSION "v0.07" 30#define DRIVER_VERSION "v0.08"
35#define DRIVER_DESC "Silicon Labs CP2101/CP2102 RS232 serial adaptor driver" 31#define DRIVER_DESC "Silicon Labs CP2101/CP2102 RS232 serial adaptor driver"
36 32
37/* 33/*
@@ -42,17 +38,21 @@ static int cp2101_open(struct tty_struct *, struct usb_serial_port *,
42static void cp2101_cleanup(struct usb_serial_port *); 38static void cp2101_cleanup(struct usb_serial_port *);
43static void cp2101_close(struct tty_struct *, struct usb_serial_port *, 39static void cp2101_close(struct tty_struct *, struct usb_serial_port *,
44 struct file*); 40 struct file*);
45static void cp2101_get_termios(struct tty_struct *); 41static void cp2101_get_termios(struct tty_struct *,
42 struct usb_serial_port *port);
43static void cp2101_get_termios_port(struct usb_serial_port *port,
44 unsigned int *cflagp, unsigned int *baudp);
46static void cp2101_set_termios(struct tty_struct *, struct usb_serial_port *, 45static void cp2101_set_termios(struct tty_struct *, struct usb_serial_port *,
47 struct ktermios*); 46 struct ktermios*);
48static int cp2101_tiocmget(struct tty_struct *, struct file *); 47static int cp2101_tiocmget(struct tty_struct *, struct file *);
49static int cp2101_tiocmset(struct tty_struct *, struct file *, 48static int cp2101_tiocmset(struct tty_struct *, struct file *,
50 unsigned int, unsigned int); 49 unsigned int, unsigned int);
50static int cp2101_tiocmset_port(struct usb_serial_port *port, struct file *,
51 unsigned int, unsigned int);
51static void cp2101_break_ctl(struct tty_struct *, int); 52static void cp2101_break_ctl(struct tty_struct *, int);
52static int cp2101_startup(struct usb_serial *); 53static int cp2101_startup(struct usb_serial *);
53static void cp2101_shutdown(struct usb_serial *); 54static void cp2101_shutdown(struct usb_serial *);
54 55
55
56static int debug; 56static int debug;
57 57
58static struct usb_device_id id_table [] = { 58static struct usb_device_id id_table [] = {
@@ -91,6 +91,7 @@ static struct usb_device_id id_table [] = {
91 { USB_DEVICE(0x10c4, 0x8293) }, /* Telegesys ETRX2USB */ 91 { USB_DEVICE(0x10c4, 0x8293) }, /* Telegesys ETRX2USB */
92 { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */ 92 { USB_DEVICE(0x10C4, 0x8341) }, /* Siemens MC35PU GPRS Modem */
93 { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */ 93 { USB_DEVICE(0x10C4, 0x83A8) }, /* Amber Wireless AMB2560 */
94 { USB_DEVICE(0x10C4, 0x846E) }, /* BEI USB Sensor Interface (VCP) */
94 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */ 95 { USB_DEVICE(0x10C4, 0xEA60) }, /* Silicon Labs factory default */
95 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */ 96 { USB_DEVICE(0x10C4, 0xEA61) }, /* Silicon Labs factory default */
96 { USB_DEVICE(0x10C4, 0xF001) }, /* Elan Digital Systems USBscope50 */ 97 { USB_DEVICE(0x10C4, 0xF001) }, /* Elan Digital Systems USBscope50 */
@@ -225,7 +226,7 @@ static int cp2101_get_config(struct usb_serial_port *port, u8 request,
225 kfree(buf); 226 kfree(buf);
226 227
227 if (result != size) { 228 if (result != size) {
228 dev_err(&port->dev, "%s - Unable to send config request, " 229 dbg("%s - Unable to send config request, "
229 "request=0x%x size=%d result=%d\n", 230 "request=0x%x size=%d result=%d\n",
230 __func__, request, size, result); 231 __func__, request, size, result);
231 return -EPROTO; 232 return -EPROTO;
@@ -276,7 +277,7 @@ static int cp2101_set_config(struct usb_serial_port *port, u8 request,
276 kfree(buf); 277 kfree(buf);
277 278
278 if ((size > 2 && result != size) || result < 0) { 279 if ((size > 2 && result != size) || result < 0) {
279 dev_err(&port->dev, "%s - Unable to send request, " 280 dbg("%s - Unable to send request, "
280 "request=0x%x size=%d result=%d\n", 281 "request=0x%x size=%d result=%d\n",
281 __func__, request, size, result); 282 __func__, request, size, result);
282 return -EPROTO; 283 return -EPROTO;
@@ -301,6 +302,47 @@ static inline int cp2101_set_config_single(struct usb_serial_port *port,
301 return cp2101_set_config(port, request, &data, 2); 302 return cp2101_set_config(port, request, &data, 2);
302} 303}
303 304
305/*
306 * cp2101_quantise_baudrate
307 * Quantises the baud rate as per AN205 Table 1
308 */
309static unsigned int cp2101_quantise_baudrate(unsigned int baud) {
310 if (baud <= 56) baud = 0;
311 else if (baud <= 300) baud = 300;
312 else if (baud <= 600) baud = 600;
313 else if (baud <= 1200) baud = 1200;
314 else if (baud <= 1800) baud = 1800;
315 else if (baud <= 2400) baud = 2400;
316 else if (baud <= 4000) baud = 4000;
317 else if (baud <= 4803) baud = 4800;
318 else if (baud <= 7207) baud = 7200;
319 else if (baud <= 9612) baud = 9600;
320 else if (baud <= 14428) baud = 14400;
321 else if (baud <= 16062) baud = 16000;
322 else if (baud <= 19250) baud = 19200;
323 else if (baud <= 28912) baud = 28800;
324 else if (baud <= 38601) baud = 38400;
325 else if (baud <= 51558) baud = 51200;
326 else if (baud <= 56280) baud = 56000;
327 else if (baud <= 58053) baud = 57600;
328 else if (baud <= 64111) baud = 64000;
329 else if (baud <= 77608) baud = 76800;
330 else if (baud <= 117028) baud = 115200;
331 else if (baud <= 129347) baud = 128000;
332 else if (baud <= 156868) baud = 153600;
333 else if (baud <= 237832) baud = 230400;
334 else if (baud <= 254234) baud = 250000;
335 else if (baud <= 273066) baud = 256000;
336 else if (baud <= 491520) baud = 460800;
337 else if (baud <= 567138) baud = 500000;
338 else if (baud <= 670254) baud = 576000;
339 else if (baud <= 1053257) baud = 921600;
340 else if (baud <= 1474560) baud = 1228800;
341 else if (baud <= 2457600) baud = 1843200;
342 else baud = 3686400;
343 return baud;
344}
345
304static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port, 346static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port,
305 struct file *filp) 347 struct file *filp)
306{ 348{
@@ -331,10 +373,12 @@ static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port,
331 } 373 }
332 374
333 /* Configure the termios structure */ 375 /* Configure the termios structure */
334 cp2101_get_termios(tty); 376 cp2101_get_termios(tty, port);
335 377
336 /* Set the DTR and RTS pins low */ 378 /* Set the DTR and RTS pins low */
337 cp2101_tiocmset(tty, NULL, TIOCM_DTR | TIOCM_RTS, 0); 379 cp2101_tiocmset_port(tty ? (struct usb_serial_port *) tty->driver_data
380 : port,
381 NULL, TIOCM_DTR | TIOCM_RTS, 0);
338 382
339 return 0; 383 return 0;
340} 384}
@@ -376,9 +420,31 @@ static void cp2101_close(struct tty_struct *tty, struct usb_serial_port *port,
376 * from the device, corrects any unsupported values, and configures the 420 * from the device, corrects any unsupported values, and configures the
377 * termios structure to reflect the state of the device 421 * termios structure to reflect the state of the device
378 */ 422 */
379static void cp2101_get_termios (struct tty_struct *tty) 423static void cp2101_get_termios(struct tty_struct *tty,
424 struct usb_serial_port *port)
425{
426 unsigned int baud;
427
428 if (tty) {
429 cp2101_get_termios_port(tty->driver_data,
430 &tty->termios->c_cflag, &baud);
431 tty_encode_baud_rate(tty, baud, baud);
432 }
433
434 else {
435 unsigned int cflag;
436 cflag = 0;
437 cp2101_get_termios_port(port, &cflag, &baud);
438 }
439}
440
441/*
442 * cp2101_get_termios_port
443 * This is the heart of cp2101_get_termios which always uses a &usb_serial_port.
444 */
445static void cp2101_get_termios_port(struct usb_serial_port *port,
446 unsigned int *cflagp, unsigned int *baudp)
380{ 447{
381 struct usb_serial_port *port = tty->driver_data;
382 unsigned int cflag, modem_ctl[4]; 448 unsigned int cflag, modem_ctl[4];
383 unsigned int baud; 449 unsigned int baud;
384 unsigned int bits; 450 unsigned int bits;
@@ -388,12 +454,12 @@ static void cp2101_get_termios (struct tty_struct *tty)
388 cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2); 454 cp2101_get_config(port, CP2101_BAUDRATE, &baud, 2);
389 /* Convert to baudrate */ 455 /* Convert to baudrate */
390 if (baud) 456 if (baud)
391 baud = BAUD_RATE_GEN_FREQ / baud; 457 baud = cp2101_quantise_baudrate((BAUD_RATE_GEN_FREQ + baud/2)/ baud);
392 458
393 dbg("%s - baud rate = %d", __func__, baud); 459 dbg("%s - baud rate = %d", __func__, baud);
460 *baudp = baud;
394 461
395 tty_encode_baud_rate(tty, baud, baud); 462 cflag = *cflagp;
396 cflag = tty->termios->c_cflag;
397 463
398 cp2101_get_config(port, CP2101_BITS, &bits, 2); 464 cp2101_get_config(port, CP2101_BITS, &bits, 2);
399 cflag &= ~CSIZE; 465 cflag &= ~CSIZE;
@@ -499,7 +565,7 @@ static void cp2101_get_termios (struct tty_struct *tty)
499 cflag &= ~CRTSCTS; 565 cflag &= ~CRTSCTS;
500 } 566 }
501 567
502 tty->termios->c_cflag = cflag; 568 *cflagp = cflag;
503} 569}
504 570
505static void cp2101_set_termios(struct tty_struct *tty, 571static void cp2101_set_termios(struct tty_struct *tty,
@@ -517,46 +583,16 @@ static void cp2101_set_termios(struct tty_struct *tty,
517 tty->termios->c_cflag &= ~CMSPAR; 583 tty->termios->c_cflag &= ~CMSPAR;
518 cflag = tty->termios->c_cflag; 584 cflag = tty->termios->c_cflag;
519 old_cflag = old_termios->c_cflag; 585 old_cflag = old_termios->c_cflag;
520 baud = tty_get_baud_rate(tty); 586 baud = cp2101_quantise_baudrate(tty_get_baud_rate(tty));
521 587
522 /* If the baud rate is to be updated*/ 588 /* If the baud rate is to be updated*/
523 if (baud != tty_termios_baud_rate(old_termios)) { 589 if (baud != tty_termios_baud_rate(old_termios) && baud != 0) {
524 switch (baud) { 590 dbg("%s - Setting baud rate to %d baud", __func__,
525 case 0: 591 baud);
526 case 600: 592 if (cp2101_set_config_single(port, CP2101_BAUDRATE,
527 case 1200: 593 ((BAUD_RATE_GEN_FREQ + baud/2) / baud))) {
528 case 1800: 594 dbg("Baud rate requested not supported by device\n");
529 case 2400: 595 baud = tty_termios_baud_rate(old_termios);
530 case 4800:
531 case 7200:
532 case 9600:
533 case 14400:
534 case 19200:
535 case 28800:
536 case 38400:
537 case 55854:
538 case 57600:
539 case 115200:
540 case 127117:
541 case 230400:
542 case 460800:
543 case 921600:
544 case 3686400:
545 break;
546 default:
547 baud = 9600;
548 break;
549 }
550
551 if (baud) {
552 dbg("%s - Setting baud rate to %d baud", __func__,
553 baud);
554 if (cp2101_set_config_single(port, CP2101_BAUDRATE,
555 (BAUD_RATE_GEN_FREQ / baud))) {
556 dev_err(&port->dev, "Baud rate requested not "
557 "supported by device\n");
558 baud = tty_termios_baud_rate(old_termios);
559 }
560 } 596 }
561 } 597 }
562 /* Report back the resulting baud rate */ 598 /* Report back the resulting baud rate */
@@ -588,14 +624,14 @@ static void cp2101_set_termios(struct tty_struct *tty,
588 dbg("%s - data bits = 9", __func__); 624 dbg("%s - data bits = 9", __func__);
589 break;*/ 625 break;*/
590 default: 626 default:
591 dev_err(&port->dev, "cp2101 driver does not " 627 dbg("cp2101 driver does not "
592 "support the number of bits requested," 628 "support the number of bits requested,"
593 " using 8 bit mode\n"); 629 " using 8 bit mode\n");
594 bits |= BITS_DATA_8; 630 bits |= BITS_DATA_8;
595 break; 631 break;
596 } 632 }
597 if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) 633 if (cp2101_set_config(port, CP2101_BITS, &bits, 2))
598 dev_err(&port->dev, "Number of data bits requested " 634 dbg("Number of data bits requested "
599 "not supported by device\n"); 635 "not supported by device\n");
600 } 636 }
601 637
@@ -612,7 +648,7 @@ static void cp2101_set_termios(struct tty_struct *tty,
612 } 648 }
613 } 649 }
614 if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) 650 if (cp2101_set_config(port, CP2101_BITS, &bits, 2))
615 dev_err(&port->dev, "Parity mode not supported " 651 dbg("Parity mode not supported "
616 "by device\n"); 652 "by device\n");
617 } 653 }
618 654
@@ -627,7 +663,7 @@ static void cp2101_set_termios(struct tty_struct *tty,
627 dbg("%s - stop bits = 1", __func__); 663 dbg("%s - stop bits = 1", __func__);
628 } 664 }
629 if (cp2101_set_config(port, CP2101_BITS, &bits, 2)) 665 if (cp2101_set_config(port, CP2101_BITS, &bits, 2))
630 dev_err(&port->dev, "Number of stop bits requested " 666 dbg("Number of stop bits requested "
631 "not supported by device\n"); 667 "not supported by device\n");
632 } 668 }
633 669
@@ -661,6 +697,12 @@ static int cp2101_tiocmset (struct tty_struct *tty, struct file *file,
661 unsigned int set, unsigned int clear) 697 unsigned int set, unsigned int clear)
662{ 698{
663 struct usb_serial_port *port = tty->driver_data; 699 struct usb_serial_port *port = tty->driver_data;
700 return cp2101_tiocmset_port(port, file, set, clear);
701}
702
703static int cp2101_tiocmset_port(struct usb_serial_port *port, struct file *file,
704 unsigned int set, unsigned int clear)
705{
664 unsigned int control = 0; 706 unsigned int control = 0;
665 707
666 dbg("%s - port %d", __func__, port->number); 708 dbg("%s - port %d", __func__, port->number);
@@ -685,7 +727,6 @@ static int cp2101_tiocmset (struct tty_struct *tty, struct file *file,
685 dbg("%s - control = 0x%.4x", __func__, control); 727 dbg("%s - control = 0x%.4x", __func__, control);
686 728
687 return cp2101_set_config(port, CP2101_CONTROL, &control, 2); 729 return cp2101_set_config(port, CP2101_CONTROL, &control, 2);
688
689} 730}
690 731
691static int cp2101_tiocmget (struct tty_struct *tty, struct file *file) 732static int cp2101_tiocmget (struct tty_struct *tty, struct file *file)
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index ae84c326a540..dcc87aaa8628 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -1938,18 +1938,16 @@ static void ftdi_process_read(struct work_struct *work)
1938 /* Compare new line status to the old one, signal if different/ 1938 /* Compare new line status to the old one, signal if different/
1939 N.B. packet may be processed more than once, but differences 1939 N.B. packet may be processed more than once, but differences
1940 are only processed once. */ 1940 are only processed once. */
1941 if (priv != NULL) { 1941 char new_status = data[packet_offset + 0] &
1942 char new_status = data[packet_offset + 0] & 1942 FTDI_STATUS_B0_MASK;
1943 FTDI_STATUS_B0_MASK; 1943 if (new_status != priv->prev_status) {
1944 if (new_status != priv->prev_status) { 1944 priv->diff_status |=
1945 priv->diff_status |= 1945 new_status ^ priv->prev_status;
1946 new_status ^ priv->prev_status; 1946 wake_up_interruptible(&priv->delta_msr_wait);
1947 wake_up_interruptible(&priv->delta_msr_wait); 1947 priv->prev_status = new_status;
1948 priv->prev_status = new_status;
1949 }
1950 } 1948 }
1951 1949
1952 length = min(PKTSZ, urb->actual_length-packet_offset)-2; 1950 length = min_t(u32, PKTSZ, urb->actual_length-packet_offset)-2;
1953 if (length < 0) { 1951 if (length < 0) {
1954 dev_err(&port->dev, "%s - bad packet length: %d\n", 1952 dev_err(&port->dev, "%s - bad packet length: %d\n",
1955 __func__, length+2); 1953 __func__, length+2);
@@ -2294,11 +2292,8 @@ static int ftdi_tiocmget(struct tty_struct *tty, struct file *file)
2294 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE, 2292 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
2295 0, 0, 2293 0, 0,
2296 buf, 1, WDR_TIMEOUT); 2294 buf, 1, WDR_TIMEOUT);
2297 if (ret < 0) { 2295 if (ret < 0)
2298 dbg("%s Could not get modem status of device - err: %d", __func__,
2299 ret);
2300 return ret; 2296 return ret;
2301 }
2302 break; 2297 break;
2303 case FT8U232AM: 2298 case FT8U232AM:
2304 case FT232BM: 2299 case FT232BM:
@@ -2313,15 +2308,11 @@ static int ftdi_tiocmget(struct tty_struct *tty, struct file *file)
2313 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE, 2308 FTDI_SIO_GET_MODEM_STATUS_REQUEST_TYPE,
2314 0, priv->interface, 2309 0, priv->interface,
2315 buf, 2, WDR_TIMEOUT); 2310 buf, 2, WDR_TIMEOUT);
2316 if (ret < 0) { 2311 if (ret < 0)
2317 dbg("%s Could not get modem status of device - err: %d", __func__,
2318 ret);
2319 return ret; 2312 return ret;
2320 }
2321 break; 2313 break;
2322 default: 2314 default:
2323 return -EFAULT; 2315 return -EFAULT;
2324 break;
2325 } 2316 }
2326 2317
2327 return (buf[0] & FTDI_SIO_DSR_MASK ? TIOCM_DSR : 0) | 2318 return (buf[0] & FTDI_SIO_DSR_MASK ? TIOCM_DSR : 0) |
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index 814909f1ee63..9d57cace3731 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -177,14 +177,6 @@ int usb_serial_generic_resume(struct usb_serial *serial)
177 struct usb_serial_port *port; 177 struct usb_serial_port *port;
178 int i, c = 0, r; 178 int i, c = 0, r;
179 179
180#ifdef CONFIG_PM
181 /*
182 * If this is an autoresume, don't submit URBs.
183 * They will be submitted in the open function instead.
184 */
185 if (serial->dev->auto_pm)
186 return 0;
187#endif
188 for (i = 0; i < serial->num_ports; i++) { 180 for (i = 0; i < serial->num_ports; i++) {
189 port = serial->port[i]; 181 port = serial->port[i];
190 if (port->port.count && port->read_urb) { 182 if (port->port.count && port->read_urb) {
@@ -196,6 +188,7 @@ int usb_serial_generic_resume(struct usb_serial *serial)
196 188
197 return c ? -EIO : 0; 189 return c ? -EIO : 0;
198} 190}
191EXPORT_SYMBOL_GPL(usb_serial_generic_resume);
199 192
200void usb_serial_generic_close(struct tty_struct *tty, 193void usb_serial_generic_close(struct tty_struct *tty,
201 struct usb_serial_port *port, struct file *filp) 194 struct usb_serial_port *port, struct file *filp)
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index 132be74d2b89..ef92095b0732 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -78,6 +78,7 @@ static int ipaq_open(struct tty_struct *tty,
78 struct usb_serial_port *port, struct file *filp); 78 struct usb_serial_port *port, struct file *filp);
79static void ipaq_close(struct tty_struct *tty, 79static void ipaq_close(struct tty_struct *tty,
80 struct usb_serial_port *port, struct file *filp); 80 struct usb_serial_port *port, struct file *filp);
81static int ipaq_calc_num_ports(struct usb_serial *serial);
81static int ipaq_startup(struct usb_serial *serial); 82static int ipaq_startup(struct usb_serial *serial);
82static void ipaq_shutdown(struct usb_serial *serial); 83static void ipaq_shutdown(struct usb_serial *serial);
83static int ipaq_write(struct tty_struct *tty, struct usb_serial_port *port, 84static int ipaq_write(struct tty_struct *tty, struct usb_serial_port *port,
@@ -572,15 +573,10 @@ static struct usb_serial_driver ipaq_device = {
572 .description = "PocketPC PDA", 573 .description = "PocketPC PDA",
573 .usb_driver = &ipaq_driver, 574 .usb_driver = &ipaq_driver,
574 .id_table = ipaq_id_table, 575 .id_table = ipaq_id_table,
575 /*
576 * some devices have an extra endpoint, which
577 * must be ignored as it would make the core
578 * create a second port which oopses when used
579 */
580 .num_ports = 1,
581 .open = ipaq_open, 576 .open = ipaq_open,
582 .close = ipaq_close, 577 .close = ipaq_close,
583 .attach = ipaq_startup, 578 .attach = ipaq_startup,
579 .calc_num_ports = ipaq_calc_num_ports,
584 .shutdown = ipaq_shutdown, 580 .shutdown = ipaq_shutdown,
585 .write = ipaq_write, 581 .write = ipaq_write,
586 .write_room = ipaq_write_room, 582 .write_room = ipaq_write_room,
@@ -956,14 +952,49 @@ static void ipaq_destroy_lists(struct usb_serial_port *port)
956} 952}
957 953
958 954
955static int ipaq_calc_num_ports(struct usb_serial *serial)
956{
957 /*
958 * some devices have 3 endpoints, the 3rd of which
959 * must be ignored as it would make the core
960 * create a second port which oopses when used
961 */
962 int ipaq_num_ports = 1;
963
964 dbg("%s - numberofendpoints: %d", __FUNCTION__,
965 (int)serial->interface->cur_altsetting->desc.bNumEndpoints);
966
967 /*
968 * a few devices have 4 endpoints, seemingly Yakuma devices,
969 * and we need the second pair, so let them have 2 ports
970 *
971 * TODO: can we drop port 1 ?
972 */
973 if (serial->interface->cur_altsetting->desc.bNumEndpoints > 3) {
974 ipaq_num_ports = 2;
975 }
976
977 return ipaq_num_ports;
978}
979
980
959static int ipaq_startup(struct usb_serial *serial) 981static int ipaq_startup(struct usb_serial *serial)
960{ 982{
961 dbg("%s", __func__); 983 dbg("%s", __func__);
962 if (serial->dev->actconfig->desc.bConfigurationValue != 1) { 984 if (serial->dev->actconfig->desc.bConfigurationValue != 1) {
985 /*
986 * FIXME: HP iPaq rx3715, possibly others, have 1 config that
987 * is labeled as 2
988 */
989
963 dev_err(&serial->dev->dev, "active config #%d != 1 ??\n", 990 dev_err(&serial->dev->dev, "active config #%d != 1 ??\n",
964 serial->dev->actconfig->desc.bConfigurationValue); 991 serial->dev->actconfig->desc.bConfigurationValue);
965 return -ENODEV; 992 return -ENODEV;
966 } 993 }
994
995 dbg("%s - iPAQ module configured for %d ports",
996 __FUNCTION__, serial->num_ports);
997
967 return usb_reset_configuration(serial->dev); 998 return usb_reset_configuration(serial->dev);
968} 999}
969 1000
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 9878c0fb3859..00daa8f7759a 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -1507,7 +1507,7 @@ static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
1507 } else { 1507 } else {
1508 dev_warn(&serial->interface->dev, 1508 dev_warn(&serial->interface->dev,
1509 "unsupported endpoint type %x\n", 1509 "unsupported endpoint type %x\n",
1510 ep_desc->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK); 1510 usb_endpoint_type(ep_desc));
1511 usb_free_urb(urb); 1511 usb_free_urb(urb);
1512 return NULL; 1512 return NULL;
1513 } 1513 }
diff --git a/drivers/usb/serial/opticon.c b/drivers/usb/serial/opticon.c
index cea326f1f105..839583dc8b6a 100644
--- a/drivers/usb/serial/opticon.c
+++ b/drivers/usb/serial/opticon.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * Opticon USB barcode to serial driver 2 * Opticon USB barcode to serial driver
3 * 3 *
4 * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de> 4 * Copyright (C) 2008 - 2009 Greg Kroah-Hartman <gregkh@suse.de>
5 * Copyright (C) 2008 Novell Inc. 5 * Copyright (C) 2008 - 2009 Novell Inc.
6 * 6 *
7 * This program is free software; you can redistribute it and/or 7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version 8 * modify it under the terms of the GNU General Public License version
@@ -14,6 +14,7 @@
14#include <linux/tty.h> 14#include <linux/tty.h>
15#include <linux/tty_driver.h> 15#include <linux/tty_driver.h>
16#include <linux/tty_flip.h> 16#include <linux/tty_flip.h>
17#include <linux/serial.h>
17#include <linux/module.h> 18#include <linux/module.h>
18#include <linux/usb.h> 19#include <linux/usb.h>
19#include <linux/usb/serial.h> 20#include <linux/usb/serial.h>
@@ -40,8 +41,12 @@ struct opticon_private {
40 bool throttled; 41 bool throttled;
41 bool actually_throttled; 42 bool actually_throttled;
42 bool rts; 43 bool rts;
44 int outstanding_urbs;
43}; 45};
44 46
47/* max number of write urbs in flight */
48#define URB_UPPER_LIMIT 4
49
45static void opticon_bulk_callback(struct urb *urb) 50static void opticon_bulk_callback(struct urb *urb)
46{ 51{
47 struct opticon_private *priv = urb->context; 52 struct opticon_private *priv = urb->context;
@@ -106,7 +111,6 @@ static void opticon_bulk_callback(struct urb *urb)
106 priv->rts = false; 111 priv->rts = false;
107 else 112 else
108 priv->rts = true; 113 priv->rts = true;
109 /* FIXME change the RTS level */
110 } else { 114 } else {
111 dev_dbg(&priv->udev->dev, 115 dev_dbg(&priv->udev->dev,
112 "Unknown data packet received from the device:" 116 "Unknown data packet received from the device:"
@@ -188,6 +192,120 @@ static void opticon_close(struct tty_struct *tty, struct usb_serial_port *port,
188 usb_kill_urb(priv->bulk_read_urb); 192 usb_kill_urb(priv->bulk_read_urb);
189} 193}
190 194
195static void opticon_write_bulk_callback(struct urb *urb)
196{
197 struct opticon_private *priv = urb->context;
198 int status = urb->status;
199 unsigned long flags;
200
201 /* free up the transfer buffer, as usb_free_urb() does not do this */
202 kfree(urb->transfer_buffer);
203
204 if (status)
205 dbg("%s - nonzero write bulk status received: %d",
206 __func__, status);
207
208 spin_lock_irqsave(&priv->lock, flags);
209 --priv->outstanding_urbs;
210 spin_unlock_irqrestore(&priv->lock, flags);
211
212 usb_serial_port_softint(priv->port);
213}
214
215static int opticon_write(struct tty_struct *tty, struct usb_serial_port *port,
216 const unsigned char *buf, int count)
217{
218 struct opticon_private *priv = usb_get_serial_data(port->serial);
219 struct usb_serial *serial = port->serial;
220 struct urb *urb;
221 unsigned char *buffer;
222 unsigned long flags;
223 int status;
224
225 dbg("%s - port %d", __func__, port->number);
226
227 spin_lock_irqsave(&priv->lock, flags);
228 if (priv->outstanding_urbs > URB_UPPER_LIMIT) {
229 spin_unlock_irqrestore(&priv->lock, flags);
230 dbg("%s - write limit hit\n", __func__);
231 return 0;
232 }
233 priv->outstanding_urbs++;
234 spin_unlock_irqrestore(&priv->lock, flags);
235
236 buffer = kmalloc(count, GFP_ATOMIC);
237 if (!buffer) {
238 dev_err(&port->dev, "out of memory\n");
239 count = -ENOMEM;
240 goto error_no_buffer;
241 }
242
243 urb = usb_alloc_urb(0, GFP_ATOMIC);
244 if (!urb) {
245 dev_err(&port->dev, "no more free urbs\n");
246 count = -ENOMEM;
247 goto error_no_urb;
248 }
249
250 memcpy(buffer, buf, count);
251
252 usb_serial_debug_data(debug, &port->dev, __func__, count, buffer);
253
254 usb_fill_bulk_urb(urb, serial->dev,
255 usb_sndbulkpipe(serial->dev,
256 port->bulk_out_endpointAddress),
257 buffer, count, opticon_write_bulk_callback, priv);
258
259 /* send it down the pipe */
260 status = usb_submit_urb(urb, GFP_ATOMIC);
261 if (status) {
262 dev_err(&port->dev,
263 "%s - usb_submit_urb(write bulk) failed with status = %d\n",
264 __func__, status);
265 count = status;
266 goto error;
267 }
268
269 /* we are done with this urb, so let the host driver
270 * really free it when it is finished with it */
271 usb_free_urb(urb);
272
273 return count;
274error:
275 usb_free_urb(urb);
276error_no_urb:
277 kfree(buffer);
278error_no_buffer:
279 spin_lock_irqsave(&priv->lock, flags);
280 --priv->outstanding_urbs;
281 spin_unlock_irqrestore(&priv->lock, flags);
282 return count;
283}
284
285static int opticon_write_room(struct tty_struct *tty)
286{
287 struct usb_serial_port *port = tty->driver_data;
288 struct opticon_private *priv = usb_get_serial_data(port->serial);
289 unsigned long flags;
290
291 dbg("%s - port %d", __func__, port->number);
292
293 /*
294 * We really can take almost anything the user throws at us
295 * but let's pick a nice big number to tell the tty
296 * layer that we have lots of free space, unless we don't.
297 */
298 spin_lock_irqsave(&priv->lock, flags);
299 if (priv->outstanding_urbs > URB_UPPER_LIMIT * 2 / 3) {
300 spin_unlock_irqrestore(&priv->lock, flags);
301 dbg("%s - write limit hit\n", __func__);
302 return 0;
303 }
304 spin_unlock_irqrestore(&priv->lock, flags);
305
306 return 2048;
307}
308
191static void opticon_throttle(struct tty_struct *tty) 309static void opticon_throttle(struct tty_struct *tty)
192{ 310{
193 struct usb_serial_port *port = tty->driver_data; 311 struct usb_serial_port *port = tty->driver_data;
@@ -223,6 +341,67 @@ static void opticon_unthrottle(struct tty_struct *tty)
223 __func__, result); 341 __func__, result);
224} 342}
225 343
344static int opticon_tiocmget(struct tty_struct *tty, struct file *file)
345{
346 struct usb_serial_port *port = tty->driver_data;
347 struct opticon_private *priv = usb_get_serial_data(port->serial);
348 unsigned long flags;
349 int result = 0;
350
351 dbg("%s - port %d", __func__, port->number);
352
353 spin_lock_irqsave(&priv->lock, flags);
354 if (priv->rts)
355 result = TIOCM_RTS;
356 spin_unlock_irqrestore(&priv->lock, flags);
357
358 dbg("%s - %x", __func__, result);
359 return result;
360}
361
362static int get_serial_info(struct opticon_private *priv,
363 struct serial_struct __user *serial)
364{
365 struct serial_struct tmp;
366
367 if (!serial)
368 return -EFAULT;
369
370 memset(&tmp, 0x00, sizeof(tmp));
371
372 /* fake emulate a 16550 uart to make userspace code happy */
373 tmp.type = PORT_16550A;
374 tmp.line = priv->serial->minor;
375 tmp.port = 0;
376 tmp.irq = 0;
377 tmp.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
378 tmp.xmit_fifo_size = 1024;
379 tmp.baud_base = 9600;
380 tmp.close_delay = 5*HZ;
381 tmp.closing_wait = 30*HZ;
382
383 if (copy_to_user(serial, &tmp, sizeof(*serial)))
384 return -EFAULT;
385 return 0;
386}
387
388static int opticon_ioctl(struct tty_struct *tty, struct file *file,
389 unsigned int cmd, unsigned long arg)
390{
391 struct usb_serial_port *port = tty->driver_data;
392 struct opticon_private *priv = usb_get_serial_data(port->serial);
393
394 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
395
396 switch (cmd) {
397 case TIOCGSERIAL:
398 return get_serial_info(priv,
399 (struct serial_struct __user *)arg);
400 }
401
402 return -ENOIOCTLCMD;
403}
404
226static int opticon_startup(struct usb_serial *serial) 405static int opticon_startup(struct usb_serial *serial)
227{ 406{
228 struct opticon_private *priv; 407 struct opticon_private *priv;
@@ -306,11 +485,37 @@ static void opticon_shutdown(struct usb_serial *serial)
306 usb_set_serial_data(serial, NULL); 485 usb_set_serial_data(serial, NULL);
307} 486}
308 487
488static int opticon_suspend(struct usb_interface *intf, pm_message_t message)
489{
490 struct usb_serial *serial = usb_get_intfdata(intf);
491 struct opticon_private *priv = usb_get_serial_data(serial);
492
493 usb_kill_urb(priv->bulk_read_urb);
494 return 0;
495}
496
497static int opticon_resume(struct usb_interface *intf)
498{
499 struct usb_serial *serial = usb_get_intfdata(intf);
500 struct opticon_private *priv = usb_get_serial_data(serial);
501 struct usb_serial_port *port = serial->port[0];
502 int result;
503
504 mutex_lock(&port->mutex);
505 if (port->port.count)
506 result = usb_submit_urb(priv->bulk_read_urb, GFP_NOIO);
507 else
508 result = 0;
509 mutex_unlock(&port->mutex);
510 return result;
511}
309 512
310static struct usb_driver opticon_driver = { 513static struct usb_driver opticon_driver = {
311 .name = "opticon", 514 .name = "opticon",
312 .probe = usb_serial_probe, 515 .probe = usb_serial_probe,
313 .disconnect = usb_serial_disconnect, 516 .disconnect = usb_serial_disconnect,
517 .suspend = opticon_suspend,
518 .resume = opticon_resume,
314 .id_table = id_table, 519 .id_table = id_table,
315 .no_dynamic_id = 1, 520 .no_dynamic_id = 1,
316}; 521};
@@ -326,9 +531,13 @@ static struct usb_serial_driver opticon_device = {
326 .attach = opticon_startup, 531 .attach = opticon_startup,
327 .open = opticon_open, 532 .open = opticon_open,
328 .close = opticon_close, 533 .close = opticon_close,
534 .write = opticon_write,
535 .write_room = opticon_write_room,
329 .shutdown = opticon_shutdown, 536 .shutdown = opticon_shutdown,
330 .throttle = opticon_throttle, 537 .throttle = opticon_throttle,
331 .unthrottle = opticon_unthrottle, 538 .unthrottle = opticon_unthrottle,
539 .ioctl = opticon_ioctl,
540 .tiocmget = opticon_tiocmget,
332}; 541};
333 542
334static int __init opticon_init(void) 543static int __init opticon_init(void)
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 61ebddc48497..d560c0b54e6e 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -62,6 +62,8 @@ static int option_tiocmget(struct tty_struct *tty, struct file *file);
62static int option_tiocmset(struct tty_struct *tty, struct file *file, 62static int option_tiocmset(struct tty_struct *tty, struct file *file,
63 unsigned int set, unsigned int clear); 63 unsigned int set, unsigned int clear);
64static int option_send_setup(struct tty_struct *tty, struct usb_serial_port *port); 64static int option_send_setup(struct tty_struct *tty, struct usb_serial_port *port);
65static int option_suspend(struct usb_serial *serial, pm_message_t message);
66static int option_resume(struct usb_serial *serial);
65 67
66/* Vendor and product IDs */ 68/* Vendor and product IDs */
67#define OPTION_VENDOR_ID 0x0AF0 69#define OPTION_VENDOR_ID 0x0AF0
@@ -523,6 +525,8 @@ static struct usb_driver option_driver = {
523 .name = "option", 525 .name = "option",
524 .probe = usb_serial_probe, 526 .probe = usb_serial_probe,
525 .disconnect = usb_serial_disconnect, 527 .disconnect = usb_serial_disconnect,
528 .suspend = usb_serial_suspend,
529 .resume = usb_serial_resume,
526 .id_table = option_ids, 530 .id_table = option_ids,
527 .no_dynamic_id = 1, 531 .no_dynamic_id = 1,
528}; 532};
@@ -551,6 +555,8 @@ static struct usb_serial_driver option_1port_device = {
551 .attach = option_startup, 555 .attach = option_startup,
552 .shutdown = option_shutdown, 556 .shutdown = option_shutdown,
553 .read_int_callback = option_instat_callback, 557 .read_int_callback = option_instat_callback,
558 .suspend = option_suspend,
559 .resume = option_resume,
554}; 560};
555 561
556static int debug; 562static int debug;
@@ -821,10 +827,10 @@ static void option_instat_callback(struct urb *urb)
821 req_pkt->bRequestType, req_pkt->bRequest); 827 req_pkt->bRequestType, req_pkt->bRequest);
822 } 828 }
823 } else 829 } else
824 dbg("%s: error %d", __func__, status); 830 err("%s: error %d", __func__, status);
825 831
826 /* Resubmit urb so we continue receiving IRQ data */ 832 /* Resubmit urb so we continue receiving IRQ data */
827 if (status != -ESHUTDOWN) { 833 if (status != -ESHUTDOWN && status != -ENOENT) {
828 urb->dev = serial->dev; 834 urb->dev = serial->dev;
829 err = usb_submit_urb(urb, GFP_ATOMIC); 835 err = usb_submit_urb(urb, GFP_ATOMIC);
830 if (err) 836 if (err)
@@ -843,7 +849,6 @@ static int option_write_room(struct tty_struct *tty)
843 849
844 portdata = usb_get_serial_port_data(port); 850 portdata = usb_get_serial_port_data(port);
845 851
846
847 for (i = 0; i < N_OUT_URB; i++) { 852 for (i = 0; i < N_OUT_URB; i++) {
848 this_urb = portdata->out_urbs[i]; 853 this_urb = portdata->out_urbs[i];
849 if (this_urb && !test_bit(i, &portdata->out_busy)) 854 if (this_urb && !test_bit(i, &portdata->out_busy))
@@ -1105,14 +1110,12 @@ bail_out_error:
1105 return 1; 1110 return 1;
1106} 1111}
1107 1112
1108static void option_shutdown(struct usb_serial *serial) 1113static void stop_read_write_urbs(struct usb_serial *serial)
1109{ 1114{
1110 int i, j; 1115 int i, j;
1111 struct usb_serial_port *port; 1116 struct usb_serial_port *port;
1112 struct option_port_private *portdata; 1117 struct option_port_private *portdata;
1113 1118
1114 dbg("%s", __func__);
1115
1116 /* Stop reading/writing urbs */ 1119 /* Stop reading/writing urbs */
1117 for (i = 0; i < serial->num_ports; ++i) { 1120 for (i = 0; i < serial->num_ports; ++i) {
1118 port = serial->port[i]; 1121 port = serial->port[i];
@@ -1122,6 +1125,17 @@ static void option_shutdown(struct usb_serial *serial)
1122 for (j = 0; j < N_OUT_URB; j++) 1125 for (j = 0; j < N_OUT_URB; j++)
1123 usb_kill_urb(portdata->out_urbs[j]); 1126 usb_kill_urb(portdata->out_urbs[j]);
1124 } 1127 }
1128}
1129
1130static void option_shutdown(struct usb_serial *serial)
1131{
1132 int i, j;
1133 struct usb_serial_port *port;
1134 struct option_port_private *portdata;
1135
1136 dbg("%s", __func__);
1137
1138 stop_read_write_urbs(serial);
1125 1139
1126 /* Now free them */ 1140 /* Now free them */
1127 for (i = 0; i < serial->num_ports; ++i) { 1141 for (i = 0; i < serial->num_ports; ++i) {
@@ -1152,6 +1166,66 @@ static void option_shutdown(struct usb_serial *serial)
1152 } 1166 }
1153} 1167}
1154 1168
1169static int option_suspend(struct usb_serial *serial, pm_message_t message)
1170{
1171 dbg("%s entered", __func__);
1172 stop_read_write_urbs(serial);
1173
1174 return 0;
1175}
1176
1177static int option_resume(struct usb_serial *serial)
1178{
1179 int err, i, j;
1180 struct usb_serial_port *port;
1181 struct urb *urb;
1182 struct option_port_private *portdata;
1183
1184 dbg("%s entered", __func__);
1185 /* get the interrupt URBs resubmitted unconditionally */
1186 for (i = 0; i < serial->num_ports; i++) {
1187 port = serial->port[i];
1188 if (!port->interrupt_in_urb) {
1189 dbg("%s: No interrupt URB for port %d\n", __func__, i);
1190 continue;
1191 }
1192 port->interrupt_in_urb->dev = serial->dev;
1193 err = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO);
1194 dbg("Submitted interrupt URB for port %d (result %d)", i, err);
1195 if (err < 0) {
1196 err("%s: Error %d for interrupt URB of port%d",
1197 __func__, err, i);
1198 return err;
1199 }
1200 }
1201
1202 for (i = 0; i < serial->num_ports; i++) {
1203 /* walk all ports */
1204 port = serial->port[i];
1205 portdata = usb_get_serial_port_data(port);
1206 mutex_lock(&port->mutex);
1207
1208 /* skip closed ports */
1209 if (!port->port.count) {
1210 mutex_unlock(&port->mutex);
1211 continue;
1212 }
1213
1214 for (j = 0; j < N_IN_URB; j++) {
1215 urb = portdata->in_urbs[j];
1216 err = usb_submit_urb(urb, GFP_NOIO);
1217 if (err < 0) {
1218 mutex_unlock(&port->mutex);
1219 err("%s: Error %d for bulk URB %d",
1220 __func__, err, i);
1221 return err;
1222 }
1223 }
1224 mutex_unlock(&port->mutex);
1225 }
1226 return 0;
1227}
1228
1155MODULE_AUTHOR(DRIVER_AUTHOR); 1229MODULE_AUTHOR(DRIVER_AUTHOR);
1156MODULE_DESCRIPTION(DRIVER_DESC); 1230MODULE_DESCRIPTION(DRIVER_DESC);
1157MODULE_VERSION(DRIVER_VERSION); 1231MODULE_VERSION(DRIVER_VERSION);
diff --git a/drivers/usb/serial/qcserial.c b/drivers/usb/serial/qcserial.c
new file mode 100644
index 000000000000..e6d6b0c17fd9
--- /dev/null
+++ b/drivers/usb/serial/qcserial.c
@@ -0,0 +1,147 @@
1/*
2 * Qualcomm Serial USB driver
3 *
4 * Copyright (c) 2008 QUALCOMM Incorporated.
5 * Copyright (c) 2009 Greg Kroah-Hartman <gregkh@suse.de>
6 * Copyright (c) 2009 Novell Inc.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License version
10 * 2 as published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/tty.h>
15#include <linux/tty_flip.h>
16#include <linux/usb.h>
17#include <linux/usb/serial.h>
18
19#define DRIVER_AUTHOR "Qualcomm Inc"
20#define DRIVER_DESC "Qualcomm USB Serial driver"
21
22static int debug;
23
24static struct usb_device_id id_table[] = {
25 {USB_DEVICE(0x05c6, 0x9211)}, /* Acer Gobi QDL device */
26 {USB_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */
27 {USB_DEVICE(0x03f0, 0x1f1d)}, /* HP un2400 Gobi Modem Device */
28 {USB_DEVICE(0x03f0, 0x201d)}, /* HP un2400 Gobi QDL Device */
29 { } /* Terminating entry */
30};
31MODULE_DEVICE_TABLE(usb, id_table);
32
33static struct usb_driver qcdriver = {
34 .name = "qcserial",
35 .probe = usb_serial_probe,
36 .disconnect = usb_serial_disconnect,
37 .id_table = id_table,
38 .suspend = usb_serial_suspend,
39 .resume = usb_serial_resume,
40 .supports_autosuspend = true,
41};
42
43static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id)
44{
45 int retval = -ENODEV;
46 __u8 nintf;
47 __u8 ifnum;
48
49 dbg("%s", __func__);
50
51 nintf = serial->dev->actconfig->desc.bNumInterfaces;
52 dbg("Num Interfaces = %d", nintf);
53 ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber;
54 dbg("This Interface = %d", ifnum);
55
56 switch (nintf) {
57 case 1:
58 /* QDL mode */
59 if (serial->interface->num_altsetting == 2) {
60 struct usb_host_interface *intf;
61
62 intf = &serial->interface->altsetting[1];
63 if (intf->desc.bNumEndpoints == 2) {
64 if (usb_endpoint_is_bulk_in(&intf->endpoint[0].desc) &&
65 usb_endpoint_is_bulk_out(&intf->endpoint[1].desc)) {
66 dbg("QDL port found");
67 retval = usb_set_interface(serial->dev, ifnum, 1);
68 if (retval < 0) {
69 dev_err(&serial->dev->dev,
70 "Could not set interface, error %d\n",
71 retval);
72 retval = -ENODEV;
73 }
74 return retval;
75 }
76 }
77 }
78 break;
79
80 case 4:
81 /* Composite mode */
82 if (ifnum == 2) {
83 dbg("Modem port found");
84 retval = usb_set_interface(serial->dev, ifnum, 0);
85 if (retval < 0) {
86 dev_err(&serial->dev->dev,
87 "Could not set interface, error %d\n",
88 retval);
89 retval = -ENODEV;
90 }
91 return retval;
92 }
93 break;
94
95 default:
96 dev_err(&serial->dev->dev,
97 "unknown number of interfaces: %d\n", nintf);
98 return -ENODEV;
99 }
100
101 return retval;
102}
103
104static struct usb_serial_driver qcdevice = {
105 .driver = {
106 .owner = THIS_MODULE,
107 .name = "qcserial",
108 },
109 .description = "Qualcomm USB modem",
110 .id_table = id_table,
111 .usb_driver = &qcdriver,
112 .num_ports = 1,
113 .probe = qcprobe,
114};
115
116static int __init qcinit(void)
117{
118 int retval;
119
120 retval = usb_serial_register(&qcdevice);
121 if (retval)
122 return retval;
123
124 retval = usb_register(&qcdriver);
125 if (retval) {
126 usb_serial_deregister(&qcdevice);
127 return retval;
128 }
129
130 return 0;
131}
132
133static void __exit qcexit(void)
134{
135 usb_deregister(&qcdriver);
136 usb_serial_deregister(&qcdevice);
137}
138
139module_init(qcinit);
140module_exit(qcexit);
141
142MODULE_AUTHOR(DRIVER_AUTHOR);
143MODULE_DESCRIPTION(DRIVER_DESC);
144MODULE_LICENSE("GPL v2");
145
146module_param(debug, bool, S_IRUGO | S_IWUSR);
147MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/serial/symbolserial.c b/drivers/usb/serial/symbolserial.c
new file mode 100644
index 000000000000..8b3cbc87adc7
--- /dev/null
+++ b/drivers/usb/serial/symbolserial.c
@@ -0,0 +1,399 @@
1/*
2 * Symbol USB barcode to serial driver
3 *
4 * Copyright (C) 2009 Greg Kroah-Hartman <gregkh@suse.de>
5 * Copyright (C) 2009 Novell Inc.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/tty.h>
15#include <linux/tty_driver.h>
16#include <linux/tty_flip.h>
17#include <linux/module.h>
18#include <linux/usb.h>
19#include <linux/usb/serial.h>
20#include <linux/uaccess.h>
21
22static int debug;
23
24static struct usb_device_id id_table[] = {
25 { USB_DEVICE(0x05e0, 0x0600) },
26 { },
27};
28MODULE_DEVICE_TABLE(usb, id_table);
29
30/* This structure holds all of the individual device information */
31struct symbol_private {
32 struct usb_device *udev;
33 struct usb_serial *serial;
34 struct usb_serial_port *port;
35 unsigned char *int_buffer;
36 struct urb *int_urb;
37 int buffer_size;
38 u8 bInterval;
39 u8 int_address;
40 spinlock_t lock; /* protects the following flags */
41 bool throttled;
42 bool actually_throttled;
43 bool rts;
44};
45
46static void symbol_int_callback(struct urb *urb)
47{
48 struct symbol_private *priv = urb->context;
49 unsigned char *data = urb->transfer_buffer;
50 struct usb_serial_port *port = priv->port;
51 int status = urb->status;
52 struct tty_struct *tty;
53 int result;
54 int available_room = 0;
55 int data_length;
56
57 dbg("%s - port %d", __func__, port->number);
58
59 switch (status) {
60 case 0:
61 /* success */
62 break;
63 case -ECONNRESET:
64 case -ENOENT:
65 case -ESHUTDOWN:
66 /* this urb is terminated, clean up */
67 dbg("%s - urb shutting down with status: %d",
68 __func__, status);
69 return;
70 default:
71 dbg("%s - nonzero urb status received: %d",
72 __func__, status);
73 goto exit;
74 }
75
76 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length,
77 data);
78
79 if (urb->actual_length > 1) {
80 data_length = urb->actual_length - 1;
81
82 /*
83 * Data from the device comes with a 1 byte header:
84 *
85 * <size of data>data...
86 * This is real data to be sent to the tty layer
87 * we pretty much just ignore the size and send everything
88 * else to the tty layer.
89 */
90 tty = tty_port_tty_get(&port->port);
91 if (tty) {
92 available_room = tty_buffer_request_room(tty,
93 data_length);
94 if (available_room) {
95 tty_insert_flip_string(tty, &data[1],
96 available_room);
97 tty_flip_buffer_push(tty);
98 }
99 tty_kref_put(tty);
100 }
101 } else {
102 dev_dbg(&priv->udev->dev,
103 "Improper ammount of data received from the device, "
104 "%d bytes", urb->actual_length);
105 }
106
107exit:
108 spin_lock(&priv->lock);
109
110 /* Continue trying to always read if we should */
111 if (!priv->throttled) {
112 usb_fill_int_urb(priv->int_urb, priv->udev,
113 usb_rcvintpipe(priv->udev,
114 priv->int_address),
115 priv->int_buffer, priv->buffer_size,
116 symbol_int_callback, priv, priv->bInterval);
117 result = usb_submit_urb(priv->int_urb, GFP_ATOMIC);
118 if (result)
119 dev_err(&port->dev,
120 "%s - failed resubmitting read urb, error %d\n",
121 __func__, result);
122 } else
123 priv->actually_throttled = true;
124 spin_unlock(&priv->lock);
125}
126
127static int symbol_open(struct tty_struct *tty, struct usb_serial_port *port,
128 struct file *filp)
129{
130 struct symbol_private *priv = usb_get_serial_data(port->serial);
131 unsigned long flags;
132 int result = 0;
133
134 dbg("%s - port %d", __func__, port->number);
135
136 spin_lock_irqsave(&priv->lock, flags);
137 priv->throttled = false;
138 priv->actually_throttled = false;
139 priv->port = port;
140 spin_unlock_irqrestore(&priv->lock, flags);
141
142 /*
143 * Force low_latency on so that our tty_push actually forces the data
144 * through, otherwise it is scheduled, and with high data rates (like
145 * with OHCI) data can get lost.
146 */
147 if (tty)
148 tty->low_latency = 1;
149
150 /* Start reading from the device */
151 usb_fill_int_urb(priv->int_urb, priv->udev,
152 usb_rcvintpipe(priv->udev, priv->int_address),
153 priv->int_buffer, priv->buffer_size,
154 symbol_int_callback, priv, priv->bInterval);
155 result = usb_submit_urb(priv->int_urb, GFP_KERNEL);
156 if (result)
157 dev_err(&port->dev,
158 "%s - failed resubmitting read urb, error %d\n",
159 __func__, result);
160 return result;
161}
162
163static void symbol_close(struct tty_struct *tty, struct usb_serial_port *port,
164 struct file *filp)
165{
166 struct symbol_private *priv = usb_get_serial_data(port->serial);
167
168 dbg("%s - port %d", __func__, port->number);
169
170 /* shutdown our urbs */
171 usb_kill_urb(priv->int_urb);
172}
173
174static void symbol_throttle(struct tty_struct *tty)
175{
176 struct usb_serial_port *port = tty->driver_data;
177 struct symbol_private *priv = usb_get_serial_data(port->serial);
178 unsigned long flags;
179
180 dbg("%s - port %d", __func__, port->number);
181 spin_lock_irqsave(&priv->lock, flags);
182 priv->throttled = true;
183 spin_unlock_irqrestore(&priv->lock, flags);
184}
185
186static void symbol_unthrottle(struct tty_struct *tty)
187{
188 struct usb_serial_port *port = tty->driver_data;
189 struct symbol_private *priv = usb_get_serial_data(port->serial);
190 unsigned long flags;
191 int result;
192
193 dbg("%s - port %d", __func__, port->number);
194
195 spin_lock_irqsave(&priv->lock, flags);
196 priv->throttled = false;
197 priv->actually_throttled = false;
198 spin_unlock_irqrestore(&priv->lock, flags);
199
200 priv->int_urb->dev = port->serial->dev;
201 result = usb_submit_urb(priv->int_urb, GFP_ATOMIC);
202 if (result)
203 dev_err(&port->dev,
204 "%s - failed submitting read urb, error %d\n",
205 __func__, result);
206}
207
208static int symbol_ioctl(struct tty_struct *tty, struct file *file,
209 unsigned int cmd, unsigned long arg)
210{
211 struct usb_serial_port *port = tty->driver_data;
212 struct device *dev = &port->dev;
213
214 /*
215 * Right now we need to figure out what commands
216 * most userspace tools want to see for this driver,
217 * so just log the things.
218 */
219 switch (cmd) {
220 case TIOCSERGETLSR:
221 dev_info(dev, "%s: TIOCSERGETLSR\n", __func__);
222 break;
223
224 case TIOCGSERIAL:
225 dev_info(dev, "%s: TIOCGSERIAL\n", __func__);
226 break;
227
228 case TIOCMIWAIT:
229 dev_info(dev, "%s: TIOCMIWAIT\n", __func__);
230 break;
231
232 case TIOCGICOUNT:
233 dev_info(dev, "%s: TIOCGICOUNT\n", __func__);
234 break;
235 default:
236 dev_info(dev, "%s: unknown (%d)\n", __func__, cmd);
237 }
238 return -ENOIOCTLCMD;
239}
240
241static int symbol_tiocmget(struct tty_struct *tty, struct file *file)
242{
243 struct usb_serial_port *port = tty->driver_data;
244 struct device *dev = &port->dev;
245
246 /* TODO */
247 /* probably just need to shadow whatever was sent to us here */
248 dev_info(dev, "%s\n", __func__);
249 return 0;
250}
251
252static int symbol_tiocmset(struct tty_struct *tty, struct file *file,
253 unsigned int set, unsigned int clear)
254{
255 struct usb_serial_port *port = tty->driver_data;
256 struct device *dev = &port->dev;
257
258 /* TODO */
259 /* probably just need to shadow whatever was sent to us here */
260 dev_info(dev, "%s\n", __func__);
261 return 0;
262}
263
264static int symbol_startup(struct usb_serial *serial)
265{
266 struct symbol_private *priv;
267 struct usb_host_interface *intf;
268 int i;
269 int retval = -ENOMEM;
270 bool int_in_found = false;
271
272 /* create our private serial structure */
273 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
274 if (priv == NULL) {
275 dev_err(&serial->dev->dev, "%s - Out of memory\n", __func__);
276 return -ENOMEM;
277 }
278 spin_lock_init(&priv->lock);
279 priv->serial = serial;
280 priv->port = serial->port[0];
281 priv->udev = serial->dev;
282
283 /* find our interrupt endpoint */
284 intf = serial->interface->altsetting;
285 for (i = 0; i < intf->desc.bNumEndpoints; ++i) {
286 struct usb_endpoint_descriptor *endpoint;
287
288 endpoint = &intf->endpoint[i].desc;
289 if (!usb_endpoint_is_int_in(endpoint))
290 continue;
291
292 priv->int_urb = usb_alloc_urb(0, GFP_KERNEL);
293 if (!priv->int_urb) {
294 dev_err(&priv->udev->dev, "out of memory\n");
295 goto error;
296 }
297
298 priv->buffer_size = le16_to_cpu(endpoint->wMaxPacketSize) * 2;
299 priv->int_buffer = kmalloc(priv->buffer_size, GFP_KERNEL);
300 if (!priv->int_buffer) {
301 dev_err(&priv->udev->dev, "out of memory\n");
302 goto error;
303 }
304
305 priv->int_address = endpoint->bEndpointAddress;
306 priv->bInterval = endpoint->bInterval;
307
308 /* set up our int urb */
309 usb_fill_int_urb(priv->int_urb, priv->udev,
310 usb_rcvintpipe(priv->udev,
311 endpoint->bEndpointAddress),
312 priv->int_buffer, priv->buffer_size,
313 symbol_int_callback, priv, priv->bInterval);
314
315 int_in_found = true;
316 break;
317 }
318
319 if (!int_in_found) {
320 dev_err(&priv->udev->dev,
321 "Error - the proper endpoints were not found!\n");
322 goto error;
323 }
324
325 usb_set_serial_data(serial, priv);
326 return 0;
327
328error:
329 usb_free_urb(priv->int_urb);
330 kfree(priv->int_buffer);
331 kfree(priv);
332 return retval;
333}
334
335static void symbol_shutdown(struct usb_serial *serial)
336{
337 struct symbol_private *priv = usb_get_serial_data(serial);
338
339 dbg("%s", __func__);
340
341 usb_kill_urb(priv->int_urb);
342 usb_free_urb(priv->int_urb);
343 kfree(priv->int_buffer);
344 kfree(priv);
345 usb_set_serial_data(serial, NULL);
346}
347
348static struct usb_driver symbol_driver = {
349 .name = "symbol",
350 .probe = usb_serial_probe,
351 .disconnect = usb_serial_disconnect,
352 .id_table = id_table,
353 .no_dynamic_id = 1,
354};
355
356static struct usb_serial_driver symbol_device = {
357 .driver = {
358 .owner = THIS_MODULE,
359 .name = "symbol",
360 },
361 .id_table = id_table,
362 .usb_driver = &symbol_driver,
363 .num_ports = 1,
364 .attach = symbol_startup,
365 .open = symbol_open,
366 .close = symbol_close,
367 .shutdown = symbol_shutdown,
368 .throttle = symbol_throttle,
369 .unthrottle = symbol_unthrottle,
370 .ioctl = symbol_ioctl,
371 .tiocmget = symbol_tiocmget,
372 .tiocmset = symbol_tiocmset,
373};
374
375static int __init symbol_init(void)
376{
377 int retval;
378
379 retval = usb_serial_register(&symbol_device);
380 if (retval)
381 return retval;
382 retval = usb_register(&symbol_driver);
383 if (retval)
384 usb_serial_deregister(&symbol_device);
385 return retval;
386}
387
388static void __exit symbol_exit(void)
389{
390 usb_deregister(&symbol_driver);
391 usb_serial_deregister(&symbol_device);
392}
393
394module_init(symbol_init);
395module_exit(symbol_exit);
396MODULE_LICENSE("GPL");
397
398module_param(debug, bool, S_IRUGO | S_IWUSR);
399MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index cfcfd5ab06ce..742a5bc44be8 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -204,6 +204,11 @@ static int serial_open (struct tty_struct *tty, struct file *filp)
204 goto bailout_kref_put; 204 goto bailout_kref_put;
205 } 205 }
206 206
207 if (port->serial->disconnected) {
208 retval = -ENODEV;
209 goto bailout_kref_put;
210 }
211
207 if (mutex_lock_interruptible(&port->mutex)) { 212 if (mutex_lock_interruptible(&port->mutex)) {
208 retval = -ERESTARTSYS; 213 retval = -ERESTARTSYS;
209 goto bailout_kref_put; 214 goto bailout_kref_put;
@@ -1067,6 +1072,8 @@ int usb_serial_suspend(struct usb_interface *intf, pm_message_t message)
1067 struct usb_serial_port *port; 1072 struct usb_serial_port *port;
1068 int i, r = 0; 1073 int i, r = 0;
1069 1074
1075 serial->suspending = 1;
1076
1070 for (i = 0; i < serial->num_ports; ++i) { 1077 for (i = 0; i < serial->num_ports; ++i) {
1071 port = serial->port[i]; 1078 port = serial->port[i];
1072 if (port) 1079 if (port)
@@ -1083,10 +1090,15 @@ EXPORT_SYMBOL(usb_serial_suspend);
1083int usb_serial_resume(struct usb_interface *intf) 1090int usb_serial_resume(struct usb_interface *intf)
1084{ 1091{
1085 struct usb_serial *serial = usb_get_intfdata(intf); 1092 struct usb_serial *serial = usb_get_intfdata(intf);
1093 int rv;
1086 1094
1095 serial->suspending = 0;
1087 if (serial->type->resume) 1096 if (serial->type->resume)
1088 return serial->type->resume(serial); 1097 rv = serial->type->resume(serial);
1089 return 0; 1098 else
1099 rv = usb_serial_generic_resume(serial);
1100
1101 return rv;
1090} 1102}
1091EXPORT_SYMBOL(usb_serial_resume); 1103EXPORT_SYMBOL(usb_serial_resume);
1092 1104
@@ -1222,7 +1234,6 @@ static void fixup_generic(struct usb_serial_driver *device)
1222 set_to_generic_if_null(device, read_bulk_callback); 1234 set_to_generic_if_null(device, read_bulk_callback);
1223 set_to_generic_if_null(device, write_bulk_callback); 1235 set_to_generic_if_null(device, write_bulk_callback);
1224 set_to_generic_if_null(device, shutdown); 1236 set_to_generic_if_null(device, shutdown);
1225 set_to_generic_if_null(device, resume);
1226} 1237}
1227 1238
1228int usb_serial_register(struct usb_serial_driver *driver) 1239int usb_serial_register(struct usb_serial_driver *driver)
@@ -1230,6 +1241,9 @@ int usb_serial_register(struct usb_serial_driver *driver)
1230 /* must be called with BKL held */ 1241 /* must be called with BKL held */
1231 int retval; 1242 int retval;
1232 1243
1244 if (usb_disabled())
1245 return -ENODEV;
1246
1233 fixup_generic(driver); 1247 fixup_generic(driver);
1234 1248
1235 if (!driver->description) 1249 if (!driver->description)
diff --git a/drivers/usb/storage/Kconfig b/drivers/usb/storage/Kconfig
index 9df6887b91f6..8a372bac0e43 100644
--- a/drivers/usb/storage/Kconfig
+++ b/drivers/usb/storage/Kconfig
@@ -2,8 +2,8 @@
2# USB Storage driver configuration 2# USB Storage driver configuration
3# 3#
4 4
5comment "NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may also be needed;" 5comment "NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may"
6comment "see USB_STORAGE Help for more information" 6comment "also be needed; see USB_STORAGE Help for more info"
7 depends on USB 7 depends on USB
8 8
9config USB_STORAGE 9config USB_STORAGE
@@ -32,21 +32,25 @@ config USB_STORAGE_DEBUG
32 verbose debugging messages. 32 verbose debugging messages.
33 33
34config USB_STORAGE_DATAFAB 34config USB_STORAGE_DATAFAB
35 bool "Datafab Compact Flash Reader support" 35 tristate "Datafab Compact Flash Reader support"
36 depends on USB_STORAGE 36 depends on USB_STORAGE
37 help 37 help
38 Support for certain Datafab CompactFlash readers. 38 Support for certain Datafab CompactFlash readers.
39 Datafab has a web page at <http://www.datafabusa.com/>. 39 Datafab has a web page at <http://www.datafabusa.com/>.
40 40
41 If this driver is compiled as a module, it will be named ums-datafab.
42
41config USB_STORAGE_FREECOM 43config USB_STORAGE_FREECOM
42 bool "Freecom USB/ATAPI Bridge support" 44 tristate "Freecom USB/ATAPI Bridge support"
43 depends on USB_STORAGE 45 depends on USB_STORAGE
44 help 46 help
45 Support for the Freecom USB to IDE/ATAPI adaptor. 47 Support for the Freecom USB to IDE/ATAPI adaptor.
46 Freecom has a web page at <http://www.freecom.de/>. 48 Freecom has a web page at <http://www.freecom.de/>.
47 49
50 If this driver is compiled as a module, it will be named ums-freecom.
51
48config USB_STORAGE_ISD200 52config USB_STORAGE_ISD200
49 bool "ISD-200 USB/ATA Bridge support" 53 tristate "ISD-200 USB/ATA Bridge support"
50 depends on USB_STORAGE 54 depends on USB_STORAGE
51 ---help--- 55 ---help---
52 Say Y here if you want to use USB Mass Store devices based 56 Say Y here if you want to use USB Mass Store devices based
@@ -61,8 +65,10 @@ config USB_STORAGE_ISD200
61 - CyQ've CQ8060A CDRW drive 65 - CyQ've CQ8060A CDRW drive
62 - Planex eXtreme Drive RX-25HU USB-IDE cable (not model RX-25U) 66 - Planex eXtreme Drive RX-25HU USB-IDE cable (not model RX-25U)
63 67
68 If this driver is compiled as a module, it will be named ums-isd200.
69
64config USB_STORAGE_USBAT 70config USB_STORAGE_USBAT
65 bool "USBAT/USBAT02-based storage support" 71 tristate "USBAT/USBAT02-based storage support"
66 depends on USB_STORAGE 72 depends on USB_STORAGE
67 help 73 help
68 Say Y here to include additional code to support storage devices 74 Say Y here to include additional code to support storage devices
@@ -82,30 +88,38 @@ config USB_STORAGE_USBAT
82 - RCA LYRA MP3 portable 88 - RCA LYRA MP3 portable
83 - Sandisk ImageMate SDDR-05b 89 - Sandisk ImageMate SDDR-05b
84 90
91 If this driver is compiled as a module, it will be named ums-usbat.
92
85config USB_STORAGE_SDDR09 93config USB_STORAGE_SDDR09
86 bool "SanDisk SDDR-09 (and other SmartMedia, including DPCM) support" 94 tristate "SanDisk SDDR-09 (and other SmartMedia, including DPCM) support"
87 depends on USB_STORAGE 95 depends on USB_STORAGE
88 help 96 help
89 Say Y here to include additional code to support the Sandisk SDDR-09 97 Say Y here to include additional code to support the Sandisk SDDR-09
90 SmartMedia reader in the USB Mass Storage driver. 98 SmartMedia reader in the USB Mass Storage driver.
91 Also works for the Microtech Zio! CompactFlash/SmartMedia reader. 99 Also works for the Microtech Zio! CompactFlash/SmartMedia reader.
92 100
101 If this driver is compiled as a module, it will be named ums-sddr09.
102
93config USB_STORAGE_SDDR55 103config USB_STORAGE_SDDR55
94 bool "SanDisk SDDR-55 SmartMedia support" 104 tristate "SanDisk SDDR-55 SmartMedia support"
95 depends on USB_STORAGE 105 depends on USB_STORAGE
96 help 106 help
97 Say Y here to include additional code to support the Sandisk SDDR-55 107 Say Y here to include additional code to support the Sandisk SDDR-55
98 SmartMedia reader in the USB Mass Storage driver. 108 SmartMedia reader in the USB Mass Storage driver.
99 109
110 If this driver is compiled as a module, it will be named ums-sddr55.
111
100config USB_STORAGE_JUMPSHOT 112config USB_STORAGE_JUMPSHOT
101 bool "Lexar Jumpshot Compact Flash Reader" 113 tristate "Lexar Jumpshot Compact Flash Reader"
102 depends on USB_STORAGE 114 depends on USB_STORAGE
103 help 115 help
104 Say Y here to include additional code to support the Lexar Jumpshot 116 Say Y here to include additional code to support the Lexar Jumpshot
105 USB CompactFlash reader. 117 USB CompactFlash reader.
106 118
119 If this driver is compiled as a module, it will be named ums-jumpshot.
120
107config USB_STORAGE_ALAUDA 121config USB_STORAGE_ALAUDA
108 bool "Olympus MAUSB-10/Fuji DPC-R1 support" 122 tristate "Olympus MAUSB-10/Fuji DPC-R1 support"
109 depends on USB_STORAGE 123 depends on USB_STORAGE
110 help 124 help
111 Say Y here to include additional code to support the Olympus MAUSB-10 125 Say Y here to include additional code to support the Olympus MAUSB-10
@@ -114,8 +128,10 @@ config USB_STORAGE_ALAUDA
114 These devices are based on the Alauda chip and support both 128 These devices are based on the Alauda chip and support both
115 XD and SmartMedia cards. 129 XD and SmartMedia cards.
116 130
131 If this driver is compiled as a module, it will be named ums-alauda.
132
117config USB_STORAGE_ONETOUCH 133config USB_STORAGE_ONETOUCH
118 bool "Support OneTouch Button on Maxtor Hard Drives" 134 tristate "Support OneTouch Button on Maxtor Hard Drives"
119 depends on USB_STORAGE 135 depends on USB_STORAGE
120 depends on INPUT=y || INPUT=USB_STORAGE 136 depends on INPUT=y || INPUT=USB_STORAGE
121 help 137 help
@@ -127,8 +143,10 @@ config USB_STORAGE_ONETOUCH
127 this input in any keybinding software. (e.g. gnome's keyboard short- 143 this input in any keybinding software. (e.g. gnome's keyboard short-
128 cuts) 144 cuts)
129 145
146 If this driver is compiled as a module, it will be named ums-onetouch.
147
130config USB_STORAGE_KARMA 148config USB_STORAGE_KARMA
131 bool "Support for Rio Karma music player" 149 tristate "Support for Rio Karma music player"
132 depends on USB_STORAGE 150 depends on USB_STORAGE
133 help 151 help
134 Say Y here to include additional code to support the Rio Karma 152 Say Y here to include additional code to support the Rio Karma
@@ -139,8 +157,10 @@ config USB_STORAGE_KARMA
139 on the resulting scsi device node returns the Karma to normal 157 on the resulting scsi device node returns the Karma to normal
140 operation. 158 operation.
141 159
160 If this driver is compiled as a module, it will be named ums-karma.
161
142config USB_STORAGE_CYPRESS_ATACB 162config USB_STORAGE_CYPRESS_ATACB
143 bool "SAT emulation on Cypress USB/ATA Bridge with ATACB" 163 tristate "SAT emulation on Cypress USB/ATA Bridge with ATACB"
144 depends on USB_STORAGE 164 depends on USB_STORAGE
145 ---help--- 165 ---help---
146 Say Y here if you want to use SAT (ata pass through) on devices based 166 Say Y here if you want to use SAT (ata pass through) on devices based
@@ -150,6 +170,8 @@ config USB_STORAGE_CYPRESS_ATACB
150 If you say no here your device will still work with the standard usb 170 If you say no here your device will still work with the standard usb
151 mass storage class. 171 mass storage class.
152 172
173 If this driver is compiled as a module, it will be named ums-cypress.
174
153config USB_LIBUSUAL 175config USB_LIBUSUAL
154 bool "The shared table of common (or usual) storage devices" 176 bool "The shared table of common (or usual) storage devices"
155 depends on USB 177 depends on USB
diff --git a/drivers/usb/storage/Makefile b/drivers/usb/storage/Makefile
index b32069313390..5be54c019662 100644
--- a/drivers/usb/storage/Makefile
+++ b/drivers/usb/storage/Makefile
@@ -10,21 +10,36 @@ EXTRA_CFLAGS := -Idrivers/scsi
10obj-$(CONFIG_USB_STORAGE) += usb-storage.o 10obj-$(CONFIG_USB_STORAGE) += usb-storage.o
11 11
12usb-storage-obj-$(CONFIG_USB_STORAGE_DEBUG) += debug.o 12usb-storage-obj-$(CONFIG_USB_STORAGE_DEBUG) += debug.o
13usb-storage-obj-$(CONFIG_USB_STORAGE_USBAT) += shuttle_usbat.o
14usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR09) += sddr09.o
15usb-storage-obj-$(CONFIG_USB_STORAGE_SDDR55) += sddr55.o
16usb-storage-obj-$(CONFIG_USB_STORAGE_FREECOM) += freecom.o
17usb-storage-obj-$(CONFIG_USB_STORAGE_ISD200) += isd200.o
18usb-storage-obj-$(CONFIG_USB_STORAGE_DATAFAB) += datafab.o
19usb-storage-obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += jumpshot.o
20usb-storage-obj-$(CONFIG_USB_STORAGE_ALAUDA) += alauda.o
21usb-storage-obj-$(CONFIG_USB_STORAGE_ONETOUCH) += onetouch.o
22usb-storage-obj-$(CONFIG_USB_STORAGE_KARMA) += karma.o
23usb-storage-obj-$(CONFIG_USB_STORAGE_CYPRESS_ATACB) += cypress_atacb.o
24 13
25usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \ 14usb-storage-objs := scsiglue.o protocol.o transport.o usb.o \
26 initializers.o sierra_ms.o option_ms.o $(usb-storage-obj-y) 15 initializers.o sierra_ms.o option_ms.o $(usb-storage-obj-y)
27 16
28ifneq ($(CONFIG_USB_LIBUSUAL),) 17ifeq ($(CONFIG_USB_LIBUSUAL),)
29 obj-$(CONFIG_USB) += libusual.o 18 usb-storage-objs += usual-tables.o
19else
20 obj-$(CONFIG_USB) += libusual.o usual-tables.o
30endif 21endif
22
23obj-$(CONFIG_USB_STORAGE_ALAUDA) += ums-alauda.o
24obj-$(CONFIG_USB_STORAGE_CYPRESS_ATACB) += ums-cypress.o
25obj-$(CONFIG_USB_STORAGE_DATAFAB) += ums-datafab.o
26obj-$(CONFIG_USB_STORAGE_FREECOM) += ums-freecom.o
27obj-$(CONFIG_USB_STORAGE_ISD200) += ums-isd200.o
28obj-$(CONFIG_USB_STORAGE_JUMPSHOT) += ums-jumpshot.o
29obj-$(CONFIG_USB_STORAGE_KARMA) += ums-karma.o
30obj-$(CONFIG_USB_STORAGE_ONETOUCH) += ums-onetouch.o
31obj-$(CONFIG_USB_STORAGE_SDDR09) += ums-sddr09.o
32obj-$(CONFIG_USB_STORAGE_SDDR55) += ums-sddr55.o
33obj-$(CONFIG_USB_STORAGE_USBAT) += ums-usbat.o
34
35ums-alauda-objs := alauda.o
36ums-cypress-objs := cypress_atacb.o
37ums-datafab-objs := datafab.o
38ums-freecom-objs := freecom.o
39ums-isd200-objs := isd200.o
40ums-jumpshot-objs := jumpshot.o
41ums-karma-objs := karma.o
42ums-onetouch-objs := onetouch.o
43ums-sddr09-objs := sddr09.o
44ums-sddr55-objs := sddr55.o
45ums-usbat-objs := shuttle_usbat.o
diff --git a/drivers/usb/storage/alauda.c b/drivers/usb/storage/alauda.c
index 8d3711a7ff06..67edc65acb8e 100644
--- a/drivers/usb/storage/alauda.c
+++ b/drivers/usb/storage/alauda.c
@@ -31,6 +31,8 @@
31 * 675 Mass Ave, Cambridge, MA 02139, USA. 31 * 675 Mass Ave, Cambridge, MA 02139, USA.
32 */ 32 */
33 33
34#include <linux/module.h>
35
34#include <scsi/scsi.h> 36#include <scsi/scsi.h>
35#include <scsi/scsi_cmnd.h> 37#include <scsi/scsi_cmnd.h>
36#include <scsi/scsi_device.h> 38#include <scsi/scsi_device.h>
@@ -39,7 +41,79 @@
39#include "transport.h" 41#include "transport.h"
40#include "protocol.h" 42#include "protocol.h"
41#include "debug.h" 43#include "debug.h"
42#include "alauda.h" 44
45MODULE_DESCRIPTION("Driver for Alauda-based card readers");
46MODULE_AUTHOR("Daniel Drake <dsd@gentoo.org>");
47MODULE_LICENSE("GPL");
48
49/*
50 * Status bytes
51 */
52#define ALAUDA_STATUS_ERROR 0x01
53#define ALAUDA_STATUS_READY 0x40
54
55/*
56 * Control opcodes (for request field)
57 */
58#define ALAUDA_GET_XD_MEDIA_STATUS 0x08
59#define ALAUDA_GET_SM_MEDIA_STATUS 0x98
60#define ALAUDA_ACK_XD_MEDIA_CHANGE 0x0a
61#define ALAUDA_ACK_SM_MEDIA_CHANGE 0x9a
62#define ALAUDA_GET_XD_MEDIA_SIG 0x86
63#define ALAUDA_GET_SM_MEDIA_SIG 0x96
64
65/*
66 * Bulk command identity (byte 0)
67 */
68#define ALAUDA_BULK_CMD 0x40
69
70/*
71 * Bulk opcodes (byte 1)
72 */
73#define ALAUDA_BULK_GET_REDU_DATA 0x85
74#define ALAUDA_BULK_READ_BLOCK 0x94
75#define ALAUDA_BULK_ERASE_BLOCK 0xa3
76#define ALAUDA_BULK_WRITE_BLOCK 0xb4
77#define ALAUDA_BULK_GET_STATUS2 0xb7
78#define ALAUDA_BULK_RESET_MEDIA 0xe0
79
80/*
81 * Port to operate on (byte 8)
82 */
83#define ALAUDA_PORT_XD 0x00
84#define ALAUDA_PORT_SM 0x01
85
86/*
87 * LBA and PBA are unsigned ints. Special values.
88 */
89#define UNDEF 0xffff
90#define SPARE 0xfffe
91#define UNUSABLE 0xfffd
92
93struct alauda_media_info {
94 unsigned long capacity; /* total media size in bytes */
95 unsigned int pagesize; /* page size in bytes */
96 unsigned int blocksize; /* number of pages per block */
97 unsigned int uzonesize; /* number of usable blocks per zone */
98 unsigned int zonesize; /* number of blocks per zone */
99 unsigned int blockmask; /* mask to get page from address */
100
101 unsigned char pageshift;
102 unsigned char blockshift;
103 unsigned char zoneshift;
104
105 u16 **lba_to_pba; /* logical to physical block map */
106 u16 **pba_to_lba; /* physical to logical block map */
107};
108
109struct alauda_info {
110 struct alauda_media_info port[2];
111 int wr_ep; /* endpoint to write data out of */
112
113 unsigned char sense_key;
114 unsigned long sense_asc; /* additional sense code */
115 unsigned long sense_ascq; /* additional sense code qualifier */
116};
43 117
44#define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) ) 118#define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) )
45#define LSB_of(s) ((s)&0xFF) 119#define LSB_of(s) ((s)&0xFF)
@@ -52,6 +126,48 @@
52#define PBA_HI(pba) (pba >> 3) 126#define PBA_HI(pba) (pba >> 3)
53#define PBA_ZONE(pba) (pba >> 11) 127#define PBA_ZONE(pba) (pba >> 11)
54 128
129static int init_alauda(struct us_data *us);
130
131
132/*
133 * The table of devices
134 */
135#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
136 vendorName, productName, useProtocol, useTransport, \
137 initFunction, flags) \
138{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
139 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
140
141struct usb_device_id alauda_usb_ids[] = {
142# include "unusual_alauda.h"
143 { } /* Terminating entry */
144};
145MODULE_DEVICE_TABLE(usb, alauda_usb_ids);
146
147#undef UNUSUAL_DEV
148
149/*
150 * The flags table
151 */
152#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
153 vendor_name, product_name, use_protocol, use_transport, \
154 init_function, Flags) \
155{ \
156 .vendorName = vendor_name, \
157 .productName = product_name, \
158 .useProtocol = use_protocol, \
159 .useTransport = use_transport, \
160 .initFunction = init_function, \
161}
162
163static struct us_unusual_dev alauda_unusual_dev_list[] = {
164# include "unusual_alauda.h"
165 { } /* Terminating entry */
166};
167
168#undef UNUSUAL_DEV
169
170
55/* 171/*
56 * Media handling 172 * Media handling
57 */ 173 */
@@ -307,7 +423,8 @@ static int alauda_init_media(struct us_data *us)
307 data[0], data[1], data[2], data[3]); 423 data[0], data[1], data[2], data[3]);
308 media_info = alauda_card_find_id(data[1]); 424 media_info = alauda_card_find_id(data[1]);
309 if (media_info == NULL) { 425 if (media_info == NULL) {
310 printk("alauda_init_media: Unrecognised media signature: " 426 printk(KERN_WARNING
427 "alauda_init_media: Unrecognised media signature: "
311 "%02X %02X %02X %02X\n", 428 "%02X %02X %02X %02X\n",
312 data[0], data[1], data[2], data[3]); 429 data[0], data[1], data[2], data[3]);
313 return USB_STOR_TRANSPORT_ERROR; 430 return USB_STOR_TRANSPORT_ERROR;
@@ -518,7 +635,8 @@ static int alauda_read_map(struct us_data *us, unsigned int zone)
518 635
519 /* check even parity */ 636 /* check even parity */
520 if (parity[data[6] ^ data[7]]) { 637 if (parity[data[6] ^ data[7]]) {
521 printk("alauda_read_map: Bad parity in LBA for block %d" 638 printk(KERN_WARNING
639 "alauda_read_map: Bad parity in LBA for block %d"
522 " (%02X %02X)\n", i, data[6], data[7]); 640 " (%02X %02X)\n", i, data[6], data[7]);
523 pba_to_lba[i] = UNUSABLE; 641 pba_to_lba[i] = UNUSABLE;
524 continue; 642 continue;
@@ -538,13 +656,16 @@ static int alauda_read_map(struct us_data *us, unsigned int zone)
538 */ 656 */
539 657
540 if (lba_offset >= uzonesize) { 658 if (lba_offset >= uzonesize) {
541 printk("alauda_read_map: Bad low LBA %d for block %d\n", 659 printk(KERN_WARNING
660 "alauda_read_map: Bad low LBA %d for block %d\n",
542 lba_real, blocknum); 661 lba_real, blocknum);
543 continue; 662 continue;
544 } 663 }
545 664
546 if (lba_to_pba[lba_offset] != UNDEF) { 665 if (lba_to_pba[lba_offset] != UNDEF) {
547 printk("alauda_read_map: LBA %d seen for PBA %d and %d\n", 666 printk(KERN_WARNING
667 "alauda_read_map: "
668 "LBA %d seen for PBA %d and %d\n",
548 lba_real, lba_to_pba[lba_offset], blocknum); 669 lba_real, lba_to_pba[lba_offset], blocknum);
549 continue; 670 continue;
550 } 671 }
@@ -712,13 +833,15 @@ static int alauda_write_lba(struct us_data *us, u16 lba,
712 if (pba == 1) { 833 if (pba == 1) {
713 /* Maybe it is impossible to write to PBA 1. 834 /* Maybe it is impossible to write to PBA 1.
714 Fake success, but don't do anything. */ 835 Fake success, but don't do anything. */
715 printk("alauda_write_lba: avoid writing to pba 1\n"); 836 printk(KERN_WARNING
837 "alauda_write_lba: avoid writing to pba 1\n");
716 return USB_STOR_TRANSPORT_GOOD; 838 return USB_STOR_TRANSPORT_GOOD;
717 } 839 }
718 840
719 new_pba = alauda_find_unused_pba(&MEDIA_INFO(us), zone); 841 new_pba = alauda_find_unused_pba(&MEDIA_INFO(us), zone);
720 if (!new_pba) { 842 if (!new_pba) {
721 printk("alauda_write_lba: Out of unused blocks\n"); 843 printk(KERN_WARNING
844 "alauda_write_lba: Out of unused blocks\n");
722 return USB_STOR_TRANSPORT_ERROR; 845 return USB_STOR_TRANSPORT_ERROR;
723 } 846 }
724 847
@@ -818,7 +941,7 @@ static int alauda_read_data(struct us_data *us, unsigned long address,
818 len = min(sectors, blocksize) * (pagesize + 64); 941 len = min(sectors, blocksize) * (pagesize + 64);
819 buffer = kmalloc(len, GFP_NOIO); 942 buffer = kmalloc(len, GFP_NOIO);
820 if (buffer == NULL) { 943 if (buffer == NULL) {
821 printk("alauda_read_data: Out of memory\n"); 944 printk(KERN_WARNING "alauda_read_data: Out of memory\n");
822 return USB_STOR_TRANSPORT_ERROR; 945 return USB_STOR_TRANSPORT_ERROR;
823 } 946 }
824 947
@@ -911,7 +1034,7 @@ static int alauda_write_data(struct us_data *us, unsigned long address,
911 len = min(sectors, blocksize) * pagesize; 1034 len = min(sectors, blocksize) * pagesize;
912 buffer = kmalloc(len, GFP_NOIO); 1035 buffer = kmalloc(len, GFP_NOIO);
913 if (buffer == NULL) { 1036 if (buffer == NULL) {
914 printk("alauda_write_data: Out of memory\n"); 1037 printk(KERN_WARNING "alauda_write_data: Out of memory\n");
915 return USB_STOR_TRANSPORT_ERROR; 1038 return USB_STOR_TRANSPORT_ERROR;
916 } 1039 }
917 1040
@@ -921,7 +1044,7 @@ static int alauda_write_data(struct us_data *us, unsigned long address,
921 */ 1044 */
922 blockbuffer = kmalloc((pagesize + 64) * blocksize, GFP_NOIO); 1045 blockbuffer = kmalloc((pagesize + 64) * blocksize, GFP_NOIO);
923 if (blockbuffer == NULL) { 1046 if (blockbuffer == NULL) {
924 printk("alauda_write_data: Out of memory\n"); 1047 printk(KERN_WARNING "alauda_write_data: Out of memory\n");
925 kfree(buffer); 1048 kfree(buffer);
926 return USB_STOR_TRANSPORT_ERROR; 1049 return USB_STOR_TRANSPORT_ERROR;
927 } 1050 }
@@ -991,7 +1114,7 @@ static void alauda_info_destructor(void *extra)
991/* 1114/*
992 * Initialize alauda_info struct and find the data-write endpoint 1115 * Initialize alauda_info struct and find the data-write endpoint
993 */ 1116 */
994int init_alauda(struct us_data *us) 1117static int init_alauda(struct us_data *us)
995{ 1118{
996 struct alauda_info *info; 1119 struct alauda_info *info;
997 struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting; 1120 struct usb_host_interface *altsetting = us->pusb_intf->cur_altsetting;
@@ -1013,7 +1136,7 @@ int init_alauda(struct us_data *us)
1013 return USB_STOR_TRANSPORT_GOOD; 1136 return USB_STOR_TRANSPORT_GOOD;
1014} 1137}
1015 1138
1016int alauda_transport(struct scsi_cmnd *srb, struct us_data *us) 1139static int alauda_transport(struct scsi_cmnd *srb, struct us_data *us)
1017{ 1140{
1018 int rc; 1141 int rc;
1019 struct alauda_info *info = (struct alauda_info *) us->extra; 1142 struct alauda_info *info = (struct alauda_info *) us->extra;
@@ -1121,3 +1244,48 @@ int alauda_transport(struct scsi_cmnd *srb, struct us_data *us)
1121 return USB_STOR_TRANSPORT_FAILED; 1244 return USB_STOR_TRANSPORT_FAILED;
1122} 1245}
1123 1246
1247static int alauda_probe(struct usb_interface *intf,
1248 const struct usb_device_id *id)
1249{
1250 struct us_data *us;
1251 int result;
1252
1253 result = usb_stor_probe1(&us, intf, id,
1254 (id - alauda_usb_ids) + alauda_unusual_dev_list);
1255 if (result)
1256 return result;
1257
1258 us->transport_name = "Alauda Control/Bulk";
1259 us->transport = alauda_transport;
1260 us->transport_reset = usb_stor_Bulk_reset;
1261 us->max_lun = 1;
1262
1263 result = usb_stor_probe2(us);
1264 return result;
1265}
1266
1267static struct usb_driver alauda_driver = {
1268 .name = "ums-alauda",
1269 .probe = alauda_probe,
1270 .disconnect = usb_stor_disconnect,
1271 .suspend = usb_stor_suspend,
1272 .resume = usb_stor_resume,
1273 .reset_resume = usb_stor_reset_resume,
1274 .pre_reset = usb_stor_pre_reset,
1275 .post_reset = usb_stor_post_reset,
1276 .id_table = alauda_usb_ids,
1277 .soft_unbind = 1,
1278};
1279
1280static int __init alauda_init(void)
1281{
1282 return usb_register(&alauda_driver);
1283}
1284
1285static void __exit alauda_exit(void)
1286{
1287 usb_deregister(&alauda_driver);
1288}
1289
1290module_init(alauda_init);
1291module_exit(alauda_exit);
diff --git a/drivers/usb/storage/alauda.h b/drivers/usb/storage/alauda.h
deleted file mode 100644
index a700f87d0803..000000000000
--- a/drivers/usb/storage/alauda.h
+++ /dev/null
@@ -1,100 +0,0 @@
1/*
2 * Driver for Alauda-based card readers
3 *
4 * Current development and maintenance by:
5 * (c) 2005 Daniel Drake <dsd@gentoo.org>
6 *
7 * See alauda.c for more explanation.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#ifndef _USB_ALAUDA_H
25#define _USB_ALAUDA_H
26
27/*
28 * Status bytes
29 */
30#define ALAUDA_STATUS_ERROR 0x01
31#define ALAUDA_STATUS_READY 0x40
32
33/*
34 * Control opcodes (for request field)
35 */
36#define ALAUDA_GET_XD_MEDIA_STATUS 0x08
37#define ALAUDA_GET_SM_MEDIA_STATUS 0x98
38#define ALAUDA_ACK_XD_MEDIA_CHANGE 0x0a
39#define ALAUDA_ACK_SM_MEDIA_CHANGE 0x9a
40#define ALAUDA_GET_XD_MEDIA_SIG 0x86
41#define ALAUDA_GET_SM_MEDIA_SIG 0x96
42
43/*
44 * Bulk command identity (byte 0)
45 */
46#define ALAUDA_BULK_CMD 0x40
47
48/*
49 * Bulk opcodes (byte 1)
50 */
51#define ALAUDA_BULK_GET_REDU_DATA 0x85
52#define ALAUDA_BULK_READ_BLOCK 0x94
53#define ALAUDA_BULK_ERASE_BLOCK 0xa3
54#define ALAUDA_BULK_WRITE_BLOCK 0xb4
55#define ALAUDA_BULK_GET_STATUS2 0xb7
56#define ALAUDA_BULK_RESET_MEDIA 0xe0
57
58/*
59 * Port to operate on (byte 8)
60 */
61#define ALAUDA_PORT_XD 0x00
62#define ALAUDA_PORT_SM 0x01
63
64/*
65 * LBA and PBA are unsigned ints. Special values.
66 */
67#define UNDEF 0xffff
68#define SPARE 0xfffe
69#define UNUSABLE 0xfffd
70
71int init_alauda(struct us_data *us);
72int alauda_transport(struct scsi_cmnd *srb, struct us_data *us);
73
74struct alauda_media_info {
75 unsigned long capacity; /* total media size in bytes */
76 unsigned int pagesize; /* page size in bytes */
77 unsigned int blocksize; /* number of pages per block */
78 unsigned int uzonesize; /* number of usable blocks per zone */
79 unsigned int zonesize; /* number of blocks per zone */
80 unsigned int blockmask; /* mask to get page from address */
81
82 unsigned char pageshift;
83 unsigned char blockshift;
84 unsigned char zoneshift;
85
86 u16 **lba_to_pba; /* logical to physical block map */
87 u16 **pba_to_lba; /* physical to logical block map */
88};
89
90struct alauda_info {
91 struct alauda_media_info port[2];
92 int wr_ep; /* endpoint to write data out of */
93
94 unsigned char sense_key;
95 unsigned long sense_asc; /* additional sense code */
96 unsigned long sense_ascq; /* additional sense code qualifier */
97};
98
99#endif
100
diff --git a/drivers/usb/storage/cypress_atacb.c b/drivers/usb/storage/cypress_atacb.c
index 898e67d30e56..c84471821183 100644
--- a/drivers/usb/storage/cypress_atacb.c
+++ b/drivers/usb/storage/cypress_atacb.c
@@ -19,6 +19,7 @@
19 * 675 Mass Ave, Cambridge, MA 02139, USA. 19 * 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22#include <linux/module.h>
22#include <scsi/scsi.h> 23#include <scsi/scsi.h>
23#include <scsi/scsi_cmnd.h> 24#include <scsi/scsi_cmnd.h>
24#include <scsi/scsi_eh.h> 25#include <scsi/scsi_eh.h>
@@ -29,6 +30,49 @@
29#include "scsiglue.h" 30#include "scsiglue.h"
30#include "debug.h" 31#include "debug.h"
31 32
33MODULE_DESCRIPTION("SAT support for Cypress USB/ATA bridges with ATACB");
34MODULE_AUTHOR("Matthieu Castet <castet.matthieu@free.fr>");
35MODULE_LICENSE("GPL");
36
37/*
38 * The table of devices
39 */
40#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
41 vendorName, productName, useProtocol, useTransport, \
42 initFunction, flags) \
43{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
44 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
45
46struct usb_device_id cypress_usb_ids[] = {
47# include "unusual_cypress.h"
48 { } /* Terminating entry */
49};
50MODULE_DEVICE_TABLE(usb, cypress_usb_ids);
51
52#undef UNUSUAL_DEV
53
54/*
55 * The flags table
56 */
57#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
58 vendor_name, product_name, use_protocol, use_transport, \
59 init_function, Flags) \
60{ \
61 .vendorName = vendor_name, \
62 .productName = product_name, \
63 .useProtocol = use_protocol, \
64 .useTransport = use_transport, \
65 .initFunction = init_function, \
66}
67
68static struct us_unusual_dev cypress_unusual_dev_list[] = {
69# include "unusual_cypress.h"
70 { } /* Terminating entry */
71};
72
73#undef UNUSUAL_DEV
74
75
32/* 76/*
33 * ATACB is a protocol used on cypress usb<->ata bridge to 77 * ATACB is a protocol used on cypress usb<->ata bridge to
34 * send raw ATA command over mass storage 78 * send raw ATA command over mass storage
@@ -36,7 +80,7 @@
36 * More info that be found on cy7c68310_8.pdf and cy7c68300c_8.pdf 80 * More info that be found on cy7c68310_8.pdf and cy7c68300c_8.pdf
37 * datasheet from cypress.com. 81 * datasheet from cypress.com.
38 */ 82 */
39void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us) 83static void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us)
40{ 84{
41 unsigned char save_cmnd[MAX_COMMAND_SIZE]; 85 unsigned char save_cmnd[MAX_COMMAND_SIZE];
42 86
@@ -133,19 +177,18 @@ void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us)
133 177
134 /* build the command for 178 /* build the command for
135 * reading the ATA registers */ 179 * reading the ATA registers */
136 scsi_eh_prep_cmnd(srb, &ses, NULL, 0, 0); 180 scsi_eh_prep_cmnd(srb, &ses, NULL, 0, sizeof(regs));
137 srb->sdb.length = sizeof(regs); 181
138 sg_init_one(&ses.sense_sgl, regs, srb->sdb.length);
139 srb->sdb.table.sgl = &ses.sense_sgl;
140 srb->sc_data_direction = DMA_FROM_DEVICE;
141 srb->sdb.table.nents = 1;
142 /* we use the same command as before, but we set 182 /* we use the same command as before, but we set
143 * the read taskfile bit, for not executing atacb command, 183 * the read taskfile bit, for not executing atacb command,
144 * but reading register selected in srb->cmnd[4] 184 * but reading register selected in srb->cmnd[4]
145 */ 185 */
186 srb->cmd_len = 16;
187 srb->cmnd = ses.cmnd;
146 srb->cmnd[2] = 1; 188 srb->cmnd[2] = 1;
147 189
148 usb_stor_transparent_scsi_command(srb, us); 190 usb_stor_transparent_scsi_command(srb, us);
191 memcpy(regs, srb->sense_buffer, sizeof(regs));
149 tmp_result = srb->result; 192 tmp_result = srb->result;
150 scsi_eh_restore_cmnd(srb, &ses); 193 scsi_eh_restore_cmnd(srb, &ses);
151 /* we fail to get registers, report invalid command */ 194 /* we fail to get registers, report invalid command */
@@ -162,8 +205,8 @@ void cypress_atacb_passthrough(struct scsi_cmnd *srb, struct us_data *us)
162 205
163 /* XXX we should generate sk, asc, ascq from status and error 206 /* XXX we should generate sk, asc, ascq from status and error
164 * regs 207 * regs
165 * (see 11.1 Error translation ­ ATA device error to SCSI error map) 208 * (see 11.1 Error translation ATA device error to SCSI error
166 * and ata_to_sense_error from libata. 209 * map, and ata_to_sense_error from libata.)
167 */ 210 */
168 211
169 /* Sense data is current and format is descriptor. */ 212 /* Sense data is current and format is descriptor. */
@@ -198,3 +241,48 @@ end:
198 if (srb->cmnd[0] == ATA_12) 241 if (srb->cmnd[0] == ATA_12)
199 srb->cmd_len = 12; 242 srb->cmd_len = 12;
200} 243}
244
245
246static int cypress_probe(struct usb_interface *intf,
247 const struct usb_device_id *id)
248{
249 struct us_data *us;
250 int result;
251
252 result = usb_stor_probe1(&us, intf, id,
253 (id - cypress_usb_ids) + cypress_unusual_dev_list);
254 if (result)
255 return result;
256
257 us->protocol_name = "Transparent SCSI with Cypress ATACB";
258 us->proto_handler = cypress_atacb_passthrough;
259
260 result = usb_stor_probe2(us);
261 return result;
262}
263
264static struct usb_driver cypress_driver = {
265 .name = "ums-cypress",
266 .probe = cypress_probe,
267 .disconnect = usb_stor_disconnect,
268 .suspend = usb_stor_suspend,
269 .resume = usb_stor_resume,
270 .reset_resume = usb_stor_reset_resume,
271 .pre_reset = usb_stor_pre_reset,
272 .post_reset = usb_stor_post_reset,
273 .id_table = cypress_usb_ids,
274 .soft_unbind = 1,
275};
276
277static int __init cypress_init(void)
278{
279 return usb_register(&cypress_driver);
280}
281
282static void __exit cypress_exit(void)
283{
284 usb_deregister(&cypress_driver);
285}
286
287module_init(cypress_init);
288module_exit(cypress_exit);
diff --git a/drivers/usb/storage/datafab.c b/drivers/usb/storage/datafab.c
index 17f1ae232919..2b6e565262c2 100644
--- a/drivers/usb/storage/datafab.c
+++ b/drivers/usb/storage/datafab.c
@@ -49,6 +49,7 @@
49 */ 49 */
50 50
51#include <linux/errno.h> 51#include <linux/errno.h>
52#include <linux/module.h>
52#include <linux/slab.h> 53#include <linux/slab.h>
53 54
54#include <scsi/scsi.h> 55#include <scsi/scsi.h>
@@ -58,12 +59,65 @@
58#include "transport.h" 59#include "transport.h"
59#include "protocol.h" 60#include "protocol.h"
60#include "debug.h" 61#include "debug.h"
61#include "datafab.h" 62
63MODULE_DESCRIPTION("Driver for Datafab USB Compact Flash reader");
64MODULE_AUTHOR("Jimmie Mayfield <mayfield+datafab@sackheads.org>");
65MODULE_LICENSE("GPL");
66
67struct datafab_info {
68 unsigned long sectors; /* total sector count */
69 unsigned long ssize; /* sector size in bytes */
70 signed char lun; /* used for dual-slot readers */
71
72 /* the following aren't used yet */
73 unsigned char sense_key;
74 unsigned long sense_asc; /* additional sense code */
75 unsigned long sense_ascq; /* additional sense code qualifier */
76};
62 77
63static int datafab_determine_lun(struct us_data *us, 78static int datafab_determine_lun(struct us_data *us,
64 struct datafab_info *info); 79 struct datafab_info *info);
65 80
66 81
82/*
83 * The table of devices
84 */
85#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
86 vendorName, productName, useProtocol, useTransport, \
87 initFunction, flags) \
88{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
89 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
90
91struct usb_device_id datafab_usb_ids[] = {
92# include "unusual_datafab.h"
93 { } /* Terminating entry */
94};
95MODULE_DEVICE_TABLE(usb, datafab_usb_ids);
96
97#undef UNUSUAL_DEV
98
99/*
100 * The flags table
101 */
102#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
103 vendor_name, product_name, use_protocol, use_transport, \
104 init_function, Flags) \
105{ \
106 .vendorName = vendor_name, \
107 .productName = product_name, \
108 .useProtocol = use_protocol, \
109 .useTransport = use_transport, \
110 .initFunction = init_function, \
111}
112
113static struct us_unusual_dev datafab_unusual_dev_list[] = {
114# include "unusual_datafab.h"
115 { } /* Terminating entry */
116};
117
118#undef UNUSUAL_DEV
119
120
67static inline int 121static inline int
68datafab_bulk_read(struct us_data *us, unsigned char *data, unsigned int len) { 122datafab_bulk_read(struct us_data *us, unsigned char *data, unsigned int len) {
69 if (len == 0) 123 if (len == 0)
@@ -500,7 +554,7 @@ static void datafab_info_destructor(void *extra)
500 554
501// Transport for the Datafab MDCFE-B 555// Transport for the Datafab MDCFE-B
502// 556//
503int datafab_transport(struct scsi_cmnd * srb, struct us_data *us) 557static int datafab_transport(struct scsi_cmnd *srb, struct us_data *us)
504{ 558{
505 struct datafab_info *info; 559 struct datafab_info *info;
506 int rc; 560 int rc;
@@ -665,3 +719,49 @@ int datafab_transport(struct scsi_cmnd * srb, struct us_data *us)
665 info->sense_ascq = 0x00; 719 info->sense_ascq = 0x00;
666 return USB_STOR_TRANSPORT_FAILED; 720 return USB_STOR_TRANSPORT_FAILED;
667} 721}
722
723static int datafab_probe(struct usb_interface *intf,
724 const struct usb_device_id *id)
725{
726 struct us_data *us;
727 int result;
728
729 result = usb_stor_probe1(&us, intf, id,
730 (id - datafab_usb_ids) + datafab_unusual_dev_list);
731 if (result)
732 return result;
733
734 us->transport_name = "Datafab Bulk-Only";
735 us->transport = datafab_transport;
736 us->transport_reset = usb_stor_Bulk_reset;
737 us->max_lun = 1;
738
739 result = usb_stor_probe2(us);
740 return result;
741}
742
743static struct usb_driver datafab_driver = {
744 .name = "ums-datafab",
745 .probe = datafab_probe,
746 .disconnect = usb_stor_disconnect,
747 .suspend = usb_stor_suspend,
748 .resume = usb_stor_resume,
749 .reset_resume = usb_stor_reset_resume,
750 .pre_reset = usb_stor_pre_reset,
751 .post_reset = usb_stor_post_reset,
752 .id_table = datafab_usb_ids,
753 .soft_unbind = 1,
754};
755
756static int __init datafab_init(void)
757{
758 return usb_register(&datafab_driver);
759}
760
761static void __exit datafab_exit(void)
762{
763 usb_deregister(&datafab_driver);
764}
765
766module_init(datafab_init);
767module_exit(datafab_exit);
diff --git a/drivers/usb/storage/datafab.h b/drivers/usb/storage/datafab.h
deleted file mode 100644
index 32e3f271e582..000000000000
--- a/drivers/usb/storage/datafab.h
+++ /dev/null
@@ -1,40 +0,0 @@
1/* Driver for Datafab MDCFE-B USB Compact Flash reader
2 * Header File
3 *
4 * Current development and maintenance by:
5 * (c) 2000 Jimmie Mayfield (mayfield+datafab@sackheads.org)
6 *
7 * See datafab.c for more explanation
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#ifndef _USB_DATAFAB_MDCFE_B_H
25#define _USB_DATAFAB_MDCFE_B_H
26
27extern int datafab_transport(struct scsi_cmnd *srb, struct us_data *us);
28
29struct datafab_info {
30 unsigned long sectors; // total sector count
31 unsigned long ssize; // sector size in bytes
32 signed char lun; // used for dual-slot readers
33
34 // the following aren't used yet
35 unsigned char sense_key;
36 unsigned long sense_asc; // additional sense code
37 unsigned long sense_ascq; // additional sense code qualifier
38};
39
40#endif
diff --git a/drivers/usb/storage/freecom.c b/drivers/usb/storage/freecom.c
index 73ac7262239e..54cc94277acb 100644
--- a/drivers/usb/storage/freecom.c
+++ b/drivers/usb/storage/freecom.c
@@ -26,6 +26,7 @@
26 * (http://www.freecom.de/) 26 * (http://www.freecom.de/)
27 */ 27 */
28 28
29#include <linux/module.h>
29#include <scsi/scsi.h> 30#include <scsi/scsi.h>
30#include <scsi/scsi_cmnd.h> 31#include <scsi/scsi_cmnd.h>
31 32
@@ -33,7 +34,10 @@
33#include "transport.h" 34#include "transport.h"
34#include "protocol.h" 35#include "protocol.h"
35#include "debug.h" 36#include "debug.h"
36#include "freecom.h" 37
38MODULE_DESCRIPTION("Driver for Freecom USB/IDE adaptor");
39MODULE_AUTHOR("David Brown <usb-storage@davidb.org>");
40MODULE_LICENSE("GPL");
37 41
38#ifdef CONFIG_USB_STORAGE_DEBUG 42#ifdef CONFIG_USB_STORAGE_DEBUG
39static void pdump (void *, int); 43static void pdump (void *, int);
@@ -103,6 +107,47 @@ struct freecom_status {
103#define FCM_PACKET_LENGTH 64 107#define FCM_PACKET_LENGTH 64
104#define FCM_STATUS_PACKET_LENGTH 4 108#define FCM_STATUS_PACKET_LENGTH 4
105 109
110static int init_freecom(struct us_data *us);
111
112
113/*
114 * The table of devices
115 */
116#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
117 vendorName, productName, useProtocol, useTransport, \
118 initFunction, flags) \
119{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
120 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
121
122struct usb_device_id freecom_usb_ids[] = {
123# include "unusual_freecom.h"
124 { } /* Terminating entry */
125};
126MODULE_DEVICE_TABLE(usb, freecom_usb_ids);
127
128#undef UNUSUAL_DEV
129
130/*
131 * The flags table
132 */
133#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
134 vendor_name, product_name, use_protocol, use_transport, \
135 init_function, Flags) \
136{ \
137 .vendorName = vendor_name, \
138 .productName = product_name, \
139 .useProtocol = use_protocol, \
140 .useTransport = use_transport, \
141 .initFunction = init_function, \
142}
143
144static struct us_unusual_dev freecom_unusual_dev_list[] = {
145# include "unusual_freecom.h"
146 { } /* Terminating entry */
147};
148
149#undef UNUSUAL_DEV
150
106static int 151static int
107freecom_readdata (struct scsi_cmnd *srb, struct us_data *us, 152freecom_readdata (struct scsi_cmnd *srb, struct us_data *us,
108 unsigned int ipipe, unsigned int opipe, int count) 153 unsigned int ipipe, unsigned int opipe, int count)
@@ -173,7 +218,7 @@ freecom_writedata (struct scsi_cmnd *srb, struct us_data *us,
173 * Transport for the Freecom USB/IDE adaptor. 218 * Transport for the Freecom USB/IDE adaptor.
174 * 219 *
175 */ 220 */
176int freecom_transport(struct scsi_cmnd *srb, struct us_data *us) 221static int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
177{ 222{
178 struct freecom_cb_wrap *fcb; 223 struct freecom_cb_wrap *fcb;
179 struct freecom_status *fst; 224 struct freecom_status *fst;
@@ -377,8 +422,7 @@ int freecom_transport(struct scsi_cmnd *srb, struct us_data *us)
377 return USB_STOR_TRANSPORT_GOOD; 422 return USB_STOR_TRANSPORT_GOOD;
378} 423}
379 424
380int 425static int init_freecom(struct us_data *us)
381freecom_init (struct us_data *us)
382{ 426{
383 int result; 427 int result;
384 char *buffer = us->iobuf; 428 char *buffer = us->iobuf;
@@ -417,7 +461,7 @@ freecom_init (struct us_data *us)
417 return USB_STOR_TRANSPORT_GOOD; 461 return USB_STOR_TRANSPORT_GOOD;
418} 462}
419 463
420int usb_stor_freecom_reset(struct us_data *us) 464static int usb_stor_freecom_reset(struct us_data *us)
421{ 465{
422 printk (KERN_CRIT "freecom reset called\n"); 466 printk (KERN_CRIT "freecom reset called\n");
423 467
@@ -479,3 +523,48 @@ static void pdump (void *ibuffer, int length)
479} 523}
480#endif 524#endif
481 525
526static int freecom_probe(struct usb_interface *intf,
527 const struct usb_device_id *id)
528{
529 struct us_data *us;
530 int result;
531
532 result = usb_stor_probe1(&us, intf, id,
533 (id - freecom_usb_ids) + freecom_unusual_dev_list);
534 if (result)
535 return result;
536
537 us->transport_name = "Freecom";
538 us->transport = freecom_transport;
539 us->transport_reset = usb_stor_freecom_reset;
540 us->max_lun = 0;
541
542 result = usb_stor_probe2(us);
543 return result;
544}
545
546static struct usb_driver freecom_driver = {
547 .name = "ums-freecom",
548 .probe = freecom_probe,
549 .disconnect = usb_stor_disconnect,
550 .suspend = usb_stor_suspend,
551 .resume = usb_stor_resume,
552 .reset_resume = usb_stor_reset_resume,
553 .pre_reset = usb_stor_pre_reset,
554 .post_reset = usb_stor_post_reset,
555 .id_table = freecom_usb_ids,
556 .soft_unbind = 1,
557};
558
559static int __init freecom_init(void)
560{
561 return usb_register(&freecom_driver);
562}
563
564static void __exit freecom_exit(void)
565{
566 usb_deregister(&freecom_driver);
567}
568
569module_init(freecom_init);
570module_exit(freecom_exit);
diff --git a/drivers/usb/storage/isd200.c b/drivers/usb/storage/isd200.c
index 383abf2516a5..882c57b399f7 100644
--- a/drivers/usb/storage/isd200.c
+++ b/drivers/usb/storage/isd200.c
@@ -44,6 +44,7 @@
44 44
45#include <linux/jiffies.h> 45#include <linux/jiffies.h>
46#include <linux/errno.h> 46#include <linux/errno.h>
47#include <linux/module.h>
47#include <linux/slab.h> 48#include <linux/slab.h>
48#include <linux/hdreg.h> 49#include <linux/hdreg.h>
49#include <linux/scatterlist.h> 50#include <linux/scatterlist.h>
@@ -57,7 +58,53 @@
57#include "protocol.h" 58#include "protocol.h"
58#include "debug.h" 59#include "debug.h"
59#include "scsiglue.h" 60#include "scsiglue.h"
60#include "isd200.h" 61
62MODULE_DESCRIPTION("Driver for In-System Design, Inc. ISD200 ASIC");
63MODULE_AUTHOR("Björn Stenberg <bjorn@haxx.se>");
64MODULE_LICENSE("GPL");
65
66static int isd200_Initialization(struct us_data *us);
67
68
69/*
70 * The table of devices
71 */
72#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
73 vendorName, productName, useProtocol, useTransport, \
74 initFunction, flags) \
75{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
76 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
77
78struct usb_device_id isd200_usb_ids[] = {
79# include "unusual_isd200.h"
80 { } /* Terminating entry */
81};
82MODULE_DEVICE_TABLE(usb, isd200_usb_ids);
83
84#undef UNUSUAL_DEV
85#undef USUAL_DEV
86
87/*
88 * The flags table
89 */
90#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
91 vendor_name, product_name, use_protocol, use_transport, \
92 init_function, Flags) \
93{ \
94 .vendorName = vendor_name, \
95 .productName = product_name, \
96 .useProtocol = use_protocol, \
97 .useTransport = use_transport, \
98 .initFunction = init_function, \
99}
100
101static struct us_unusual_dev isd200_unusual_dev_list[] = {
102# include "unusual_isd200.h"
103 { } /* Terminating entry */
104};
105
106#undef UNUSUAL_DEV
107#undef USUAL_DEV
61 108
62 109
63/* Timeout defines (in Seconds) */ 110/* Timeout defines (in Seconds) */
@@ -1518,7 +1565,7 @@ static int isd200_init_info(struct us_data *us)
1518 * Initialization for the ISD200 1565 * Initialization for the ISD200
1519 */ 1566 */
1520 1567
1521int isd200_Initialization(struct us_data *us) 1568static int isd200_Initialization(struct us_data *us)
1522{ 1569{
1523 US_DEBUGP("ISD200 Initialization...\n"); 1570 US_DEBUGP("ISD200 Initialization...\n");
1524 1571
@@ -1549,7 +1596,7 @@ int isd200_Initialization(struct us_data *us)
1549 * 1596 *
1550 */ 1597 */
1551 1598
1552void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us) 1599static void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us)
1553{ 1600{
1554 int sendToTransport = 1, orig_bufflen; 1601 int sendToTransport = 1, orig_bufflen;
1555 union ata_cdb ataCdb; 1602 union ata_cdb ataCdb;
@@ -1570,3 +1617,47 @@ void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us)
1570 1617
1571 isd200_srb_set_bufflen(srb, orig_bufflen); 1618 isd200_srb_set_bufflen(srb, orig_bufflen);
1572} 1619}
1620
1621static int isd200_probe(struct usb_interface *intf,
1622 const struct usb_device_id *id)
1623{
1624 struct us_data *us;
1625 int result;
1626
1627 result = usb_stor_probe1(&us, intf, id,
1628 (id - isd200_usb_ids) + isd200_unusual_dev_list);
1629 if (result)
1630 return result;
1631
1632 us->protocol_name = "ISD200 ATA/ATAPI";
1633 us->proto_handler = isd200_ata_command;
1634
1635 result = usb_stor_probe2(us);
1636 return result;
1637}
1638
1639static struct usb_driver isd200_driver = {
1640 .name = "ums-isd200",
1641 .probe = isd200_probe,
1642 .disconnect = usb_stor_disconnect,
1643 .suspend = usb_stor_suspend,
1644 .resume = usb_stor_resume,
1645 .reset_resume = usb_stor_reset_resume,
1646 .pre_reset = usb_stor_pre_reset,
1647 .post_reset = usb_stor_post_reset,
1648 .id_table = isd200_usb_ids,
1649 .soft_unbind = 1,
1650};
1651
1652static int __init isd200_init(void)
1653{
1654 return usb_register(&isd200_driver);
1655}
1656
1657static void __exit isd200_exit(void)
1658{
1659 usb_deregister(&isd200_driver);
1660}
1661
1662module_init(isd200_init);
1663module_exit(isd200_exit);
diff --git a/drivers/usb/storage/jumpshot.c b/drivers/usb/storage/jumpshot.c
index df67f13c9e73..1c69420e3acf 100644
--- a/drivers/usb/storage/jumpshot.c
+++ b/drivers/usb/storage/jumpshot.c
@@ -46,6 +46,7 @@
46 */ 46 */
47 47
48#include <linux/errno.h> 48#include <linux/errno.h>
49#include <linux/module.h>
49#include <linux/slab.h> 50#include <linux/slab.h>
50 51
51#include <scsi/scsi.h> 52#include <scsi/scsi.h>
@@ -55,9 +56,61 @@
55#include "transport.h" 56#include "transport.h"
56#include "protocol.h" 57#include "protocol.h"
57#include "debug.h" 58#include "debug.h"
58#include "jumpshot.h"
59 59
60 60
61MODULE_DESCRIPTION("Driver for Lexar \"Jumpshot\" Compact Flash reader");
62MODULE_AUTHOR("Jimmie Mayfield <mayfield+usb@sackheads.org>");
63MODULE_LICENSE("GPL");
64
65/*
66 * The table of devices
67 */
68#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
69 vendorName, productName, useProtocol, useTransport, \
70 initFunction, flags) \
71{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
72 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
73
74struct usb_device_id jumpshot_usb_ids[] = {
75# include "unusual_jumpshot.h"
76 { } /* Terminating entry */
77};
78MODULE_DEVICE_TABLE(usb, jumpshot_usb_ids);
79
80#undef UNUSUAL_DEV
81
82/*
83 * The flags table
84 */
85#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
86 vendor_name, product_name, use_protocol, use_transport, \
87 init_function, Flags) \
88{ \
89 .vendorName = vendor_name, \
90 .productName = product_name, \
91 .useProtocol = use_protocol, \
92 .useTransport = use_transport, \
93 .initFunction = init_function, \
94}
95
96static struct us_unusual_dev jumpshot_unusual_dev_list[] = {
97# include "unusual_jumpshot.h"
98 { } /* Terminating entry */
99};
100
101#undef UNUSUAL_DEV
102
103
104struct jumpshot_info {
105 unsigned long sectors; /* total sector count */
106 unsigned long ssize; /* sector size in bytes */
107
108 /* the following aren't used yet */
109 unsigned char sense_key;
110 unsigned long sense_asc; /* additional sense code */
111 unsigned long sense_ascq; /* additional sense code qualifier */
112};
113
61static inline int jumpshot_bulk_read(struct us_data *us, 114static inline int jumpshot_bulk_read(struct us_data *us,
62 unsigned char *data, 115 unsigned char *data,
63 unsigned int len) 116 unsigned int len)
@@ -429,7 +482,7 @@ static void jumpshot_info_destructor(void *extra)
429 482
430// Transport for the Lexar 'Jumpshot' 483// Transport for the Lexar 'Jumpshot'
431// 484//
432int jumpshot_transport(struct scsi_cmnd * srb, struct us_data *us) 485static int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us)
433{ 486{
434 struct jumpshot_info *info; 487 struct jumpshot_info *info;
435 int rc; 488 int rc;
@@ -592,3 +645,49 @@ int jumpshot_transport(struct scsi_cmnd * srb, struct us_data *us)
592 info->sense_ascq = 0x00; 645 info->sense_ascq = 0x00;
593 return USB_STOR_TRANSPORT_FAILED; 646 return USB_STOR_TRANSPORT_FAILED;
594} 647}
648
649static int jumpshot_probe(struct usb_interface *intf,
650 const struct usb_device_id *id)
651{
652 struct us_data *us;
653 int result;
654
655 result = usb_stor_probe1(&us, intf, id,
656 (id - jumpshot_usb_ids) + jumpshot_unusual_dev_list);
657 if (result)
658 return result;
659
660 us->transport_name = "Lexar Jumpshot Control/Bulk";
661 us->transport = jumpshot_transport;
662 us->transport_reset = usb_stor_Bulk_reset;
663 us->max_lun = 1;
664
665 result = usb_stor_probe2(us);
666 return result;
667}
668
669static struct usb_driver jumpshot_driver = {
670 .name = "ums-jumpshot",
671 .probe = jumpshot_probe,
672 .disconnect = usb_stor_disconnect,
673 .suspend = usb_stor_suspend,
674 .resume = usb_stor_resume,
675 .reset_resume = usb_stor_reset_resume,
676 .pre_reset = usb_stor_pre_reset,
677 .post_reset = usb_stor_post_reset,
678 .id_table = jumpshot_usb_ids,
679 .soft_unbind = 1,
680};
681
682static int __init jumpshot_init(void)
683{
684 return usb_register(&jumpshot_driver);
685}
686
687static void __exit jumpshot_exit(void)
688{
689 usb_deregister(&jumpshot_driver);
690}
691
692module_init(jumpshot_init);
693module_exit(jumpshot_exit);
diff --git a/drivers/usb/storage/jumpshot.h b/drivers/usb/storage/jumpshot.h
deleted file mode 100644
index 19bac9d1558f..000000000000
--- a/drivers/usb/storage/jumpshot.h
+++ /dev/null
@@ -1,39 +0,0 @@
1/* Driver for Lexar "Jumpshot" USB Compact Flash reader
2 * Header File
3 *
4 * Current development and maintenance by:
5 * (c) 2000 Jimmie Mayfield (mayfield+usb@sackheads.org)
6 *
7 * See jumpshot.c for more explanation
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#ifndef _USB_JUMPSHOT_H
25#define _USB_JUMPSHOT_H
26
27extern int jumpshot_transport(struct scsi_cmnd *srb, struct us_data *us);
28
29struct jumpshot_info {
30 unsigned long sectors; // total sector count
31 unsigned long ssize; // sector size in bytes
32
33 // the following aren't used yet
34 unsigned char sense_key;
35 unsigned long sense_asc; // additional sense code
36 unsigned long sense_ascq; // additional sense code qualifier
37};
38
39#endif
diff --git a/drivers/usb/storage/karma.c b/drivers/usb/storage/karma.c
index 0d79ae5683f7..7953d93a7739 100644
--- a/drivers/usb/storage/karma.c
+++ b/drivers/usb/storage/karma.c
@@ -18,6 +18,8 @@
18 * 675 Mass Ave, Cambridge, MA 02139, USA. 18 * 675 Mass Ave, Cambridge, MA 02139, USA.
19 */ 19 */
20 20
21#include <linux/module.h>
22
21#include <scsi/scsi.h> 23#include <scsi/scsi.h>
22#include <scsi/scsi_cmnd.h> 24#include <scsi/scsi_cmnd.h>
23#include <scsi/scsi_device.h> 25#include <scsi/scsi_device.h>
@@ -25,7 +27,10 @@
25#include "usb.h" 27#include "usb.h"
26#include "transport.h" 28#include "transport.h"
27#include "debug.h" 29#include "debug.h"
28#include "karma.h" 30
31MODULE_DESCRIPTION("Driver for Rio Karma");
32MODULE_AUTHOR("Bob Copeland <me@bobcopeland.com>, Keith Bennett <keith@mcs.st-and.ac.uk>");
33MODULE_LICENSE("GPL");
29 34
30#define RIO_PREFIX "RIOP\x00" 35#define RIO_PREFIX "RIOP\x00"
31#define RIO_PREFIX_LEN 5 36#define RIO_PREFIX_LEN 5
@@ -36,13 +41,53 @@
36#define RIO_LEAVE_STORAGE 0x2 41#define RIO_LEAVE_STORAGE 0x2
37#define RIO_RESET 0xC 42#define RIO_RESET 0xC
38 43
39extern int usb_stor_Bulk_transport(struct scsi_cmnd *, struct us_data *);
40
41struct karma_data { 44struct karma_data {
42 int in_storage; 45 int in_storage;
43 char *recv; 46 char *recv;
44}; 47};
45 48
49static int rio_karma_init(struct us_data *us);
50
51
52/*
53 * The table of devices
54 */
55#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
56 vendorName, productName, useProtocol, useTransport, \
57 initFunction, flags) \
58{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
59 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
60
61struct usb_device_id karma_usb_ids[] = {
62# include "unusual_karma.h"
63 { } /* Terminating entry */
64};
65MODULE_DEVICE_TABLE(usb, karma_usb_ids);
66
67#undef UNUSUAL_DEV
68
69/*
70 * The flags table
71 */
72#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
73 vendor_name, product_name, use_protocol, use_transport, \
74 init_function, Flags) \
75{ \
76 .vendorName = vendor_name, \
77 .productName = product_name, \
78 .useProtocol = use_protocol, \
79 .useTransport = use_transport, \
80 .initFunction = init_function, \
81}
82
83static struct us_unusual_dev karma_unusual_dev_list[] = {
84# include "unusual_karma.h"
85 { } /* Terminating entry */
86};
87
88#undef UNUSUAL_DEV
89
90
46/* 91/*
47 * Send commands to Rio Karma. 92 * Send commands to Rio Karma.
48 * 93 *
@@ -104,7 +149,7 @@ err:
104 * Trap START_STOP and READ_10 to leave/re-enter storage mode. 149 * Trap START_STOP and READ_10 to leave/re-enter storage mode.
105 * Everything else is propagated to the normal bulk layer. 150 * Everything else is propagated to the normal bulk layer.
106 */ 151 */
107int rio_karma_transport(struct scsi_cmnd *srb, struct us_data *us) 152static int rio_karma_transport(struct scsi_cmnd *srb, struct us_data *us)
108{ 153{
109 int ret; 154 int ret;
110 struct karma_data *data = (struct karma_data *) us->extra; 155 struct karma_data *data = (struct karma_data *) us->extra;
@@ -133,7 +178,7 @@ static void rio_karma_destructor(void *extra)
133 kfree(data->recv); 178 kfree(data->recv);
134} 179}
135 180
136int rio_karma_init(struct us_data *us) 181static int rio_karma_init(struct us_data *us)
137{ 182{
138 int ret = 0; 183 int ret = 0;
139 struct karma_data *data = kzalloc(sizeof(struct karma_data), GFP_NOIO); 184 struct karma_data *data = kzalloc(sizeof(struct karma_data), GFP_NOIO);
@@ -153,3 +198,48 @@ int rio_karma_init(struct us_data *us)
153out: 198out:
154 return ret; 199 return ret;
155} 200}
201
202static int karma_probe(struct usb_interface *intf,
203 const struct usb_device_id *id)
204{
205 struct us_data *us;
206 int result;
207
208 result = usb_stor_probe1(&us, intf, id,
209 (id - karma_usb_ids) + karma_unusual_dev_list);
210 if (result)
211 return result;
212
213 us->transport_name = "Rio Karma/Bulk";
214 us->transport = rio_karma_transport;
215 us->transport_reset = usb_stor_Bulk_reset;
216
217 result = usb_stor_probe2(us);
218 return result;
219}
220
221static struct usb_driver karma_driver = {
222 .name = "ums-karma",
223 .probe = karma_probe,
224 .disconnect = usb_stor_disconnect,
225 .suspend = usb_stor_suspend,
226 .resume = usb_stor_resume,
227 .reset_resume = usb_stor_reset_resume,
228 .pre_reset = usb_stor_pre_reset,
229 .post_reset = usb_stor_post_reset,
230 .id_table = karma_usb_ids,
231 .soft_unbind = 1,
232};
233
234static int __init karma_init(void)
235{
236 return usb_register(&karma_driver);
237}
238
239static void __exit karma_exit(void)
240{
241 usb_deregister(&karma_driver);
242}
243
244module_init(karma_init);
245module_exit(karma_exit);
diff --git a/drivers/usb/storage/karma.h b/drivers/usb/storage/karma.h
deleted file mode 100644
index 8a60972af8c5..000000000000
--- a/drivers/usb/storage/karma.h
+++ /dev/null
@@ -1,7 +0,0 @@
1#ifndef _KARMA_USB_H
2#define _KARMA_USB_H
3
4extern int rio_karma_init(struct us_data *us);
5extern int rio_karma_transport(struct scsi_cmnd *srb, struct us_data *us);
6
7#endif
diff --git a/drivers/usb/storage/libusual.c b/drivers/usb/storage/libusual.c
index f970b27ba308..fe3ffe1459b2 100644
--- a/drivers/usb/storage/libusual.c
+++ b/drivers/usb/storage/libusual.c
@@ -38,37 +38,6 @@ static atomic_t total_threads = ATOMIC_INIT(0);
38static int usu_probe_thread(void *arg); 38static int usu_probe_thread(void *arg);
39 39
40/* 40/*
41 * The table.
42 */
43#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
44 vendorName, productName,useProtocol, useTransport, \
45 initFunction, flags) \
46{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin,bcdDeviceMax), \
47 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
48
49#define COMPLIANT_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
50 vendorName, productName, useProtocol, useTransport, \
51 initFunction, flags) \
52{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
53 .driver_info = (flags) }
54
55#define USUAL_DEV(useProto, useTrans, useType) \
56{ USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans), \
57 .driver_info = ((useType)<<24) }
58
59struct usb_device_id storage_usb_ids [] = {
60# include "unusual_devs.h"
61 { } /* Terminating entry */
62};
63
64#undef USUAL_DEV
65#undef UNUSUAL_DEV
66#undef COMPLIANT_DEV
67
68MODULE_DEVICE_TABLE(usb, storage_usb_ids);
69EXPORT_SYMBOL_GPL(storage_usb_ids);
70
71/*
72 * @type: the module type as an integer 41 * @type: the module type as an integer
73 */ 42 */
74void usb_usual_set_present(int type) 43void usb_usual_set_present(int type)
@@ -167,7 +136,7 @@ static struct usb_driver usu_driver = {
167 .name = "libusual", 136 .name = "libusual",
168 .probe = usu_probe, 137 .probe = usu_probe,
169 .disconnect = usu_disconnect, 138 .disconnect = usu_disconnect,
170 .id_table = storage_usb_ids, 139 .id_table = usb_storage_usb_ids,
171}; 140};
172 141
173/* 142/*
diff --git a/drivers/usb/storage/onetouch.c b/drivers/usb/storage/onetouch.c
index c7bf8954b4e4..380233bd6a39 100644
--- a/drivers/usb/storage/onetouch.c
+++ b/drivers/usb/storage/onetouch.c
@@ -35,9 +35,16 @@
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/usb/input.h> 36#include <linux/usb/input.h>
37#include "usb.h" 37#include "usb.h"
38#include "onetouch.h"
39#include "debug.h" 38#include "debug.h"
40 39
40MODULE_DESCRIPTION("Maxtor USB OneTouch hard drive button driver");
41MODULE_AUTHOR("Nick Sillik <n.sillik@temple.edu>");
42MODULE_LICENSE("GPL");
43
44#define ONETOUCH_PKT_LEN 0x02
45#define ONETOUCH_BUTTON KEY_PROG1
46
47static int onetouch_connect_input(struct us_data *ss);
41static void onetouch_release_input(void *onetouch_); 48static void onetouch_release_input(void *onetouch_);
42 49
43struct usb_onetouch { 50struct usb_onetouch {
@@ -52,6 +59,46 @@ struct usb_onetouch {
52 unsigned int is_open:1; 59 unsigned int is_open:1;
53}; 60};
54 61
62
63/*
64 * The table of devices
65 */
66#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
67 vendorName, productName, useProtocol, useTransport, \
68 initFunction, flags) \
69{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
70 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
71
72struct usb_device_id onetouch_usb_ids[] = {
73# include "unusual_onetouch.h"
74 { } /* Terminating entry */
75};
76MODULE_DEVICE_TABLE(usb, onetouch_usb_ids);
77
78#undef UNUSUAL_DEV
79
80/*
81 * The flags table
82 */
83#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
84 vendor_name, product_name, use_protocol, use_transport, \
85 init_function, Flags) \
86{ \
87 .vendorName = vendor_name, \
88 .productName = product_name, \
89 .useProtocol = use_protocol, \
90 .useTransport = use_transport, \
91 .initFunction = init_function, \
92}
93
94static struct us_unusual_dev onetouch_unusual_dev_list[] = {
95# include "unusual_onetouch.h"
96 { } /* Terminating entry */
97};
98
99#undef UNUSUAL_DEV
100
101
55static void usb_onetouch_irq(struct urb *urb) 102static void usb_onetouch_irq(struct urb *urb)
56{ 103{
57 struct usb_onetouch *onetouch = urb->context; 104 struct usb_onetouch *onetouch = urb->context;
@@ -127,7 +174,7 @@ static void usb_onetouch_pm_hook(struct us_data *us, int action)
127} 174}
128#endif /* CONFIG_PM */ 175#endif /* CONFIG_PM */
129 176
130int onetouch_connect_input(struct us_data *ss) 177static int onetouch_connect_input(struct us_data *ss)
131{ 178{
132 struct usb_device *udev = ss->pusb_dev; 179 struct usb_device *udev = ss->pusb_dev;
133 struct usb_host_interface *interface; 180 struct usb_host_interface *interface;
@@ -236,3 +283,46 @@ static void onetouch_release_input(void *onetouch_)
236 onetouch->data, onetouch->data_dma); 283 onetouch->data, onetouch->data_dma);
237 } 284 }
238} 285}
286
287static int onetouch_probe(struct usb_interface *intf,
288 const struct usb_device_id *id)
289{
290 struct us_data *us;
291 int result;
292
293 result = usb_stor_probe1(&us, intf, id,
294 (id - onetouch_usb_ids) + onetouch_unusual_dev_list);
295 if (result)
296 return result;
297
298 /* Use default transport and protocol */
299
300 result = usb_stor_probe2(us);
301 return result;
302}
303
304static struct usb_driver onetouch_driver = {
305 .name = "ums-onetouch",
306 .probe = onetouch_probe,
307 .disconnect = usb_stor_disconnect,
308 .suspend = usb_stor_suspend,
309 .resume = usb_stor_resume,
310 .reset_resume = usb_stor_reset_resume,
311 .pre_reset = usb_stor_pre_reset,
312 .post_reset = usb_stor_post_reset,
313 .id_table = onetouch_usb_ids,
314 .soft_unbind = 1,
315};
316
317static int __init onetouch_init(void)
318{
319 return usb_register(&onetouch_driver);
320}
321
322static void __exit onetouch_exit(void)
323{
324 usb_deregister(&onetouch_driver);
325}
326
327module_init(onetouch_init);
328module_exit(onetouch_exit);
diff --git a/drivers/usb/storage/onetouch.h b/drivers/usb/storage/onetouch.h
deleted file mode 100644
index 41c7aa8f0446..000000000000
--- a/drivers/usb/storage/onetouch.h
+++ /dev/null
@@ -1,9 +0,0 @@
1#ifndef _ONETOUCH_H_
2#define _ONETOUCH_H_
3
4#define ONETOUCH_PKT_LEN 0x02
5#define ONETOUCH_BUTTON KEY_PROG1
6
7int onetouch_connect_input(struct us_data *ss);
8
9#endif
diff --git a/drivers/usb/storage/protocol.c b/drivers/usb/storage/protocol.c
index be441d84bc64..fc310f75eada 100644
--- a/drivers/usb/storage/protocol.c
+++ b/drivers/usb/storage/protocol.c
@@ -121,6 +121,7 @@ void usb_stor_transparent_scsi_command(struct scsi_cmnd *srb,
121 /* send the command to the transport layer */ 121 /* send the command to the transport layer */
122 usb_stor_invoke_transport(srb, us); 122 usb_stor_invoke_transport(srb, us);
123} 123}
124EXPORT_SYMBOL_GPL(usb_stor_transparent_scsi_command);
124 125
125/*********************************************************************** 126/***********************************************************************
126 * Scatter-gather transfer buffer access routines 127 * Scatter-gather transfer buffer access routines
@@ -199,6 +200,7 @@ unsigned int usb_stor_access_xfer_buf(unsigned char *buffer,
199 /* Return the amount actually transferred */ 200 /* Return the amount actually transferred */
200 return cnt; 201 return cnt;
201} 202}
203EXPORT_SYMBOL_GPL(usb_stor_access_xfer_buf);
202 204
203/* Store the contents of buffer into srb's transfer buffer and set the 205/* Store the contents of buffer into srb's transfer buffer and set the
204 * SCSI residue. 206 * SCSI residue.
@@ -215,3 +217,4 @@ void usb_stor_set_xfer_buf(unsigned char *buffer,
215 if (buflen < scsi_bufflen(srb)) 217 if (buflen < scsi_bufflen(srb))
216 scsi_set_resid(srb, scsi_bufflen(srb) - buflen); 218 scsi_set_resid(srb, scsi_bufflen(srb) - buflen);
217} 219}
220EXPORT_SYMBOL_GPL(usb_stor_set_xfer_buf);
diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 727c506417cc..4ca3b5860643 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -135,6 +135,12 @@ static int slave_configure(struct scsi_device *sdev)
135 if (sdev->request_queue->max_sectors > max_sectors) 135 if (sdev->request_queue->max_sectors > max_sectors)
136 blk_queue_max_sectors(sdev->request_queue, 136 blk_queue_max_sectors(sdev->request_queue,
137 max_sectors); 137 max_sectors);
138 } else if (sdev->type == TYPE_TAPE) {
139 /* Tapes need much higher max_sector limits, so just
140 * raise it to the maximum possible (4 GB / 512) and
141 * let the queue segment size sort out the real limit.
142 */
143 blk_queue_max_sectors(sdev->request_queue, 0x7FFFFF);
138 } 144 }
139 145
140 /* Some USB host controllers can't do DMA; they have to use PIO. 146 /* Some USB host controllers can't do DMA; they have to use PIO.
@@ -563,4 +569,4 @@ unsigned char usb_stor_sense_invalidCDB[18] = {
563 [7] = 0x0a, /* additional length */ 569 [7] = 0x0a, /* additional length */
564 [12] = 0x24 /* Invalid Field in CDB */ 570 [12] = 0x24 /* Invalid Field in CDB */
565}; 571};
566 572EXPORT_SYMBOL_GPL(usb_stor_sense_invalidCDB);
diff --git a/drivers/usb/storage/sddr09.c b/drivers/usb/storage/sddr09.c
index 531ae5c5abf3..ab5f9f37575a 100644
--- a/drivers/usb/storage/sddr09.c
+++ b/drivers/usb/storage/sddr09.c
@@ -41,6 +41,7 @@
41 */ 41 */
42 42
43#include <linux/errno.h> 43#include <linux/errno.h>
44#include <linux/module.h>
44#include <linux/slab.h> 45#include <linux/slab.h>
45 46
46#include <scsi/scsi.h> 47#include <scsi/scsi.h>
@@ -51,7 +52,53 @@
51#include "transport.h" 52#include "transport.h"
52#include "protocol.h" 53#include "protocol.h"
53#include "debug.h" 54#include "debug.h"
54#include "sddr09.h" 55
56MODULE_DESCRIPTION("Driver for SanDisk SDDR-09 SmartMedia reader");
57MODULE_AUTHOR("Andries Brouwer <aeb@cwi.nl>, Robert Baruch <autophile@starband.net>");
58MODULE_LICENSE("GPL");
59
60static int usb_stor_sddr09_dpcm_init(struct us_data *us);
61static int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us);
62static int usb_stor_sddr09_init(struct us_data *us);
63
64
65/*
66 * The table of devices
67 */
68#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
69 vendorName, productName, useProtocol, useTransport, \
70 initFunction, flags) \
71{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
72 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
73
74struct usb_device_id sddr09_usb_ids[] = {
75# include "unusual_sddr09.h"
76 { } /* Terminating entry */
77};
78MODULE_DEVICE_TABLE(usb, sddr09_usb_ids);
79
80#undef UNUSUAL_DEV
81
82/*
83 * The flags table
84 */
85#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
86 vendor_name, product_name, use_protocol, use_transport, \
87 init_function, Flags) \
88{ \
89 .vendorName = vendor_name, \
90 .productName = product_name, \
91 .useProtocol = use_protocol, \
92 .useTransport = use_transport, \
93 .initFunction = init_function, \
94}
95
96static struct us_unusual_dev sddr09_unusual_dev_list[] = {
97# include "unusual_sddr09.h"
98 { } /* Terminating entry */
99};
100
101#undef UNUSUAL_DEV
55 102
56 103
57#define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) ) 104#define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) )
@@ -723,7 +770,7 @@ sddr09_read_data(struct us_data *us,
723 len = min(sectors, (unsigned int) info->blocksize) * info->pagesize; 770 len = min(sectors, (unsigned int) info->blocksize) * info->pagesize;
724 buffer = kmalloc(len, GFP_NOIO); 771 buffer = kmalloc(len, GFP_NOIO);
725 if (buffer == NULL) { 772 if (buffer == NULL) {
726 printk("sddr09_read_data: Out of memory\n"); 773 printk(KERN_WARNING "sddr09_read_data: Out of memory\n");
727 return -ENOMEM; 774 return -ENOMEM;
728 } 775 }
729 776
@@ -838,7 +885,8 @@ sddr09_write_lba(struct us_data *us, unsigned int lba,
838 if (pba == UNDEF) { 885 if (pba == UNDEF) {
839 pba = sddr09_find_unused_pba(info, lba); 886 pba = sddr09_find_unused_pba(info, lba);
840 if (!pba) { 887 if (!pba) {
841 printk("sddr09_write_lba: Out of unused blocks\n"); 888 printk(KERN_WARNING
889 "sddr09_write_lba: Out of unused blocks\n");
842 return -ENOSPC; 890 return -ENOSPC;
843 } 891 }
844 info->pba_to_lba[pba] = lba; 892 info->pba_to_lba[pba] = lba;
@@ -849,7 +897,7 @@ sddr09_write_lba(struct us_data *us, unsigned int lba,
849 if (pba == 1) { 897 if (pba == 1) {
850 /* Maybe it is impossible to write to PBA 1. 898 /* Maybe it is impossible to write to PBA 1.
851 Fake success, but don't do anything. */ 899 Fake success, but don't do anything. */
852 printk("sddr09: avoid writing to pba 1\n"); 900 printk(KERN_WARNING "sddr09: avoid writing to pba 1\n");
853 return 0; 901 return 0;
854 } 902 }
855 903
@@ -954,7 +1002,7 @@ sddr09_write_data(struct us_data *us,
954 blocklen = (pagelen << info->blockshift); 1002 blocklen = (pagelen << info->blockshift);
955 blockbuffer = kmalloc(blocklen, GFP_NOIO); 1003 blockbuffer = kmalloc(blocklen, GFP_NOIO);
956 if (!blockbuffer) { 1004 if (!blockbuffer) {
957 printk("sddr09_write_data: Out of memory\n"); 1005 printk(KERN_WARNING "sddr09_write_data: Out of memory\n");
958 return -ENOMEM; 1006 return -ENOMEM;
959 } 1007 }
960 1008
@@ -965,7 +1013,7 @@ sddr09_write_data(struct us_data *us,
965 len = min(sectors, (unsigned int) info->blocksize) * info->pagesize; 1013 len = min(sectors, (unsigned int) info->blocksize) * info->pagesize;
966 buffer = kmalloc(len, GFP_NOIO); 1014 buffer = kmalloc(len, GFP_NOIO);
967 if (buffer == NULL) { 1015 if (buffer == NULL) {
968 printk("sddr09_write_data: Out of memory\n"); 1016 printk(KERN_WARNING "sddr09_write_data: Out of memory\n");
969 kfree(blockbuffer); 1017 kfree(blockbuffer);
970 return -ENOMEM; 1018 return -ENOMEM;
971 } 1019 }
@@ -1112,7 +1160,7 @@ sddr09_get_cardinfo(struct us_data *us, unsigned char flags) {
1112 1160
1113 if (result) { 1161 if (result) {
1114 US_DEBUGP("Result of read_deviceID is %d\n", result); 1162 US_DEBUGP("Result of read_deviceID is %d\n", result);
1115 printk("sddr09: could not read card info\n"); 1163 printk(KERN_WARNING "sddr09: could not read card info\n");
1116 return NULL; 1164 return NULL;
1117 } 1165 }
1118 1166
@@ -1153,7 +1201,7 @@ sddr09_get_cardinfo(struct us_data *us, unsigned char flags) {
1153 sprintf(blurbtxt + strlen(blurbtxt), 1201 sprintf(blurbtxt + strlen(blurbtxt),
1154 ", WP"); 1202 ", WP");
1155 1203
1156 printk("%s\n", blurbtxt); 1204 printk(KERN_WARNING "%s\n", blurbtxt);
1157 1205
1158 return cardinfo; 1206 return cardinfo;
1159} 1207}
@@ -1184,7 +1232,7 @@ sddr09_read_map(struct us_data *us) {
1184 alloc_len = (alloc_blocks << CONTROL_SHIFT); 1232 alloc_len = (alloc_blocks << CONTROL_SHIFT);
1185 buffer = kmalloc(alloc_len, GFP_NOIO); 1233 buffer = kmalloc(alloc_len, GFP_NOIO);
1186 if (buffer == NULL) { 1234 if (buffer == NULL) {
1187 printk("sddr09_read_map: out of memory\n"); 1235 printk(KERN_WARNING "sddr09_read_map: out of memory\n");
1188 result = -1; 1236 result = -1;
1189 goto done; 1237 goto done;
1190 } 1238 }
@@ -1198,7 +1246,7 @@ sddr09_read_map(struct us_data *us) {
1198 info->pba_to_lba = kmalloc(numblocks*sizeof(int), GFP_NOIO); 1246 info->pba_to_lba = kmalloc(numblocks*sizeof(int), GFP_NOIO);
1199 1247
1200 if (info->lba_to_pba == NULL || info->pba_to_lba == NULL) { 1248 if (info->lba_to_pba == NULL || info->pba_to_lba == NULL) {
1201 printk("sddr09_read_map: out of memory\n"); 1249 printk(KERN_WARNING "sddr09_read_map: out of memory\n");
1202 result = -1; 1250 result = -1;
1203 goto done; 1251 goto done;
1204 } 1252 }
@@ -1238,7 +1286,8 @@ sddr09_read_map(struct us_data *us) {
1238 if (ptr[j] != 0) 1286 if (ptr[j] != 0)
1239 goto nonz; 1287 goto nonz;
1240 info->pba_to_lba[i] = UNUSABLE; 1288 info->pba_to_lba[i] = UNUSABLE;
1241 printk("sddr09: PBA %d has no logical mapping\n", i); 1289 printk(KERN_WARNING "sddr09: PBA %d has no logical mapping\n",
1290 i);
1242 continue; 1291 continue;
1243 1292
1244 nonz: 1293 nonz:
@@ -1251,7 +1300,8 @@ sddr09_read_map(struct us_data *us) {
1251 nonff: 1300 nonff:
1252 /* normal PBAs start with six FFs */ 1301 /* normal PBAs start with six FFs */
1253 if (j < 6) { 1302 if (j < 6) {
1254 printk("sddr09: PBA %d has no logical mapping: " 1303 printk(KERN_WARNING
1304 "sddr09: PBA %d has no logical mapping: "
1255 "reserved area = %02X%02X%02X%02X " 1305 "reserved area = %02X%02X%02X%02X "
1256 "data status %02X block status %02X\n", 1306 "data status %02X block status %02X\n",
1257 i, ptr[0], ptr[1], ptr[2], ptr[3], 1307 i, ptr[0], ptr[1], ptr[2], ptr[3],
@@ -1261,7 +1311,8 @@ sddr09_read_map(struct us_data *us) {
1261 } 1311 }
1262 1312
1263 if ((ptr[6] >> 4) != 0x01) { 1313 if ((ptr[6] >> 4) != 0x01) {
1264 printk("sddr09: PBA %d has invalid address field " 1314 printk(KERN_WARNING
1315 "sddr09: PBA %d has invalid address field "
1265 "%02X%02X/%02X%02X\n", 1316 "%02X%02X/%02X%02X\n",
1266 i, ptr[6], ptr[7], ptr[11], ptr[12]); 1317 i, ptr[6], ptr[7], ptr[11], ptr[12]);
1267 info->pba_to_lba[i] = UNUSABLE; 1318 info->pba_to_lba[i] = UNUSABLE;
@@ -1270,7 +1321,8 @@ sddr09_read_map(struct us_data *us) {
1270 1321
1271 /* check even parity */ 1322 /* check even parity */
1272 if (parity[ptr[6] ^ ptr[7]]) { 1323 if (parity[ptr[6] ^ ptr[7]]) {
1273 printk("sddr09: Bad parity in LBA for block %d" 1324 printk(KERN_WARNING
1325 "sddr09: Bad parity in LBA for block %d"
1274 " (%02X %02X)\n", i, ptr[6], ptr[7]); 1326 " (%02X %02X)\n", i, ptr[6], ptr[7]);
1275 info->pba_to_lba[i] = UNUSABLE; 1327 info->pba_to_lba[i] = UNUSABLE;
1276 continue; 1328 continue;
@@ -1289,7 +1341,8 @@ sddr09_read_map(struct us_data *us) {
1289 */ 1341 */
1290 1342
1291 if (lba >= 1000) { 1343 if (lba >= 1000) {
1292 printk("sddr09: Bad low LBA %d for block %d\n", 1344 printk(KERN_WARNING
1345 "sddr09: Bad low LBA %d for block %d\n",
1293 lba, i); 1346 lba, i);
1294 goto possibly_erase; 1347 goto possibly_erase;
1295 } 1348 }
@@ -1297,7 +1350,8 @@ sddr09_read_map(struct us_data *us) {
1297 lba += 1000*(i/0x400); 1350 lba += 1000*(i/0x400);
1298 1351
1299 if (info->lba_to_pba[lba] != UNDEF) { 1352 if (info->lba_to_pba[lba] != UNDEF) {
1300 printk("sddr09: LBA %d seen for PBA %d and %d\n", 1353 printk(KERN_WARNING
1354 "sddr09: LBA %d seen for PBA %d and %d\n",
1301 lba, info->lba_to_pba[lba], i); 1355 lba, info->lba_to_pba[lba], i);
1302 goto possibly_erase; 1356 goto possibly_erase;
1303 } 1357 }
@@ -1399,7 +1453,7 @@ sddr09_common_init(struct us_data *us) {
1399 * unusual devices list but called from here then LUN 0 of the combo reader 1453 * unusual devices list but called from here then LUN 0 of the combo reader
1400 * is not recognized. But I do not know what precisely these calls do. 1454 * is not recognized. But I do not know what precisely these calls do.
1401 */ 1455 */
1402int 1456static int
1403usb_stor_sddr09_dpcm_init(struct us_data *us) { 1457usb_stor_sddr09_dpcm_init(struct us_data *us) {
1404 int result; 1458 int result;
1405 unsigned char *data = us->iobuf; 1459 unsigned char *data = us->iobuf;
@@ -1449,7 +1503,7 @@ usb_stor_sddr09_dpcm_init(struct us_data *us) {
1449/* 1503/*
1450 * Transport for the Microtech DPCM-USB 1504 * Transport for the Microtech DPCM-USB
1451 */ 1505 */
1452int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us) 1506static int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us)
1453{ 1507{
1454 int ret; 1508 int ret;
1455 1509
@@ -1491,7 +1545,7 @@ int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us)
1491/* 1545/*
1492 * Transport for the Sandisk SDDR-09 1546 * Transport for the Sandisk SDDR-09
1493 */ 1547 */
1494int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us) 1548static int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
1495{ 1549{
1496 static unsigned char sensekey = 0, sensecode = 0; 1550 static unsigned char sensekey = 0, sensecode = 0;
1497 static unsigned char havefakesense = 0; 1551 static unsigned char havefakesense = 0;
@@ -1690,7 +1744,60 @@ int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us)
1690/* 1744/*
1691 * Initialization routine for the sddr09 subdriver 1745 * Initialization routine for the sddr09 subdriver
1692 */ 1746 */
1693int 1747static int
1694usb_stor_sddr09_init(struct us_data *us) { 1748usb_stor_sddr09_init(struct us_data *us) {
1695 return sddr09_common_init(us); 1749 return sddr09_common_init(us);
1696} 1750}
1751
1752static int sddr09_probe(struct usb_interface *intf,
1753 const struct usb_device_id *id)
1754{
1755 struct us_data *us;
1756 int result;
1757
1758 result = usb_stor_probe1(&us, intf, id,
1759 (id - sddr09_usb_ids) + sddr09_unusual_dev_list);
1760 if (result)
1761 return result;
1762
1763 if (us->protocol == US_PR_DPCM_USB) {
1764 us->transport_name = "Control/Bulk-EUSB/SDDR09";
1765 us->transport = dpcm_transport;
1766 us->transport_reset = usb_stor_CB_reset;
1767 us->max_lun = 1;
1768 } else {
1769 us->transport_name = "EUSB/SDDR09";
1770 us->transport = sddr09_transport;
1771 us->transport_reset = usb_stor_CB_reset;
1772 us->max_lun = 0;
1773 }
1774
1775 result = usb_stor_probe2(us);
1776 return result;
1777}
1778
1779static struct usb_driver sddr09_driver = {
1780 .name = "ums-sddr09",
1781 .probe = sddr09_probe,
1782 .disconnect = usb_stor_disconnect,
1783 .suspend = usb_stor_suspend,
1784 .resume = usb_stor_resume,
1785 .reset_resume = usb_stor_reset_resume,
1786 .pre_reset = usb_stor_pre_reset,
1787 .post_reset = usb_stor_post_reset,
1788 .id_table = sddr09_usb_ids,
1789 .soft_unbind = 1,
1790};
1791
1792static int __init sddr09_init(void)
1793{
1794 return usb_register(&sddr09_driver);
1795}
1796
1797static void __exit sddr09_exit(void)
1798{
1799 usb_deregister(&sddr09_driver);
1800}
1801
1802module_init(sddr09_init);
1803module_exit(sddr09_exit);
diff --git a/drivers/usb/storage/sddr09.h b/drivers/usb/storage/sddr09.h
deleted file mode 100644
index b701172e12e3..000000000000
--- a/drivers/usb/storage/sddr09.h
+++ /dev/null
@@ -1,38 +0,0 @@
1/* Driver for SanDisk SDDR-09 SmartMedia reader
2 * Header File
3 *
4 * Current development and maintenance by:
5 * (c) 2000 Robert Baruch (autophile@dol.net)
6 * (c) 2002 Andries Brouwer (aeb@cwi.nl)
7 *
8 * See sddr09.c for more explanation
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2, or (at your option) any
13 * later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25#ifndef _USB_SHUTTLE_EUSB_SDDR09_H
26#define _USB_SHUTTLE_EUSB_SDDR09_H
27
28/* Sandisk SDDR-09 stuff */
29
30extern int sddr09_transport(struct scsi_cmnd *srb, struct us_data *us);
31extern int usb_stor_sddr09_init(struct us_data *us);
32
33/* Microtech DPCM-USB stuff */
34
35extern int dpcm_transport(struct scsi_cmnd *srb, struct us_data *us);
36extern int usb_stor_sddr09_dpcm_init(struct us_data *us);
37
38#endif
diff --git a/drivers/usb/storage/sddr55.c b/drivers/usb/storage/sddr55.c
index 0d8df7577899..44dfed7754ed 100644
--- a/drivers/usb/storage/sddr55.c
+++ b/drivers/usb/storage/sddr55.c
@@ -24,6 +24,7 @@
24 24
25#include <linux/jiffies.h> 25#include <linux/jiffies.h>
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/module.h>
27#include <linux/slab.h> 28#include <linux/slab.h>
28 29
29#include <scsi/scsi.h> 30#include <scsi/scsi.h>
@@ -33,7 +34,48 @@
33#include "transport.h" 34#include "transport.h"
34#include "protocol.h" 35#include "protocol.h"
35#include "debug.h" 36#include "debug.h"
36#include "sddr55.h" 37
38MODULE_DESCRIPTION("Driver for SanDisk SDDR-55 SmartMedia reader");
39MODULE_AUTHOR("Simon Munton");
40MODULE_LICENSE("GPL");
41
42/*
43 * The table of devices
44 */
45#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
46 vendorName, productName, useProtocol, useTransport, \
47 initFunction, flags) \
48{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
49 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
50
51struct usb_device_id sddr55_usb_ids[] = {
52# include "unusual_sddr55.h"
53 { } /* Terminating entry */
54};
55MODULE_DEVICE_TABLE(usb, sddr55_usb_ids);
56
57#undef UNUSUAL_DEV
58
59/*
60 * The flags table
61 */
62#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
63 vendor_name, product_name, use_protocol, use_transport, \
64 init_function, Flags) \
65{ \
66 .vendorName = vendor_name, \
67 .productName = product_name, \
68 .useProtocol = use_protocol, \
69 .useTransport = use_transport, \
70 .initFunction = init_function, \
71}
72
73static struct us_unusual_dev sddr55_unusual_dev_list[] = {
74# include "unusual_sddr55.h"
75 { } /* Terminating entry */
76};
77
78#undef UNUSUAL_DEV
37 79
38 80
39#define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) ) 81#define short_pack(lsb,msb) ( ((u16)(lsb)) | ( ((u16)(msb))<<8 ) )
@@ -513,7 +555,8 @@ static int sddr55_read_deviceID(struct us_data *us,
513} 555}
514 556
515 557
516int sddr55_reset(struct us_data *us) { 558static int sddr55_reset(struct us_data *us)
559{
517 return 0; 560 return 0;
518} 561}
519 562
@@ -703,7 +746,9 @@ static int sddr55_read_map(struct us_data *us) {
703 746
704 if (info->lba_to_pba[lba + zone * 1000] != NOT_ALLOCATED && 747 if (info->lba_to_pba[lba + zone * 1000] != NOT_ALLOCATED &&
705 !info->force_read_only) { 748 !info->force_read_only) {
706 printk("sddr55: map inconsistency at LBA %04X\n", lba + zone * 1000); 749 printk(KERN_WARNING
750 "sddr55: map inconsistency at LBA %04X\n",
751 lba + zone * 1000);
707 info->force_read_only = 1; 752 info->force_read_only = 1;
708 } 753 }
709 754
@@ -732,7 +777,7 @@ static void sddr55_card_info_destructor(void *extra) {
732/* 777/*
733 * Transport for the Sandisk SDDR-55 778 * Transport for the Sandisk SDDR-55
734 */ 779 */
735int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us) 780static int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us)
736{ 781{
737 int result; 782 int result;
738 static unsigned char inquiry_response[8] = { 783 static unsigned char inquiry_response[8] = {
@@ -929,3 +974,49 @@ int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us)
929 return USB_STOR_TRANSPORT_FAILED; // FIXME: sense buffer? 974 return USB_STOR_TRANSPORT_FAILED; // FIXME: sense buffer?
930} 975}
931 976
977
978static int sddr55_probe(struct usb_interface *intf,
979 const struct usb_device_id *id)
980{
981 struct us_data *us;
982 int result;
983
984 result = usb_stor_probe1(&us, intf, id,
985 (id - sddr55_usb_ids) + sddr55_unusual_dev_list);
986 if (result)
987 return result;
988
989 us->transport_name = "SDDR55";
990 us->transport = sddr55_transport;
991 us->transport_reset = sddr55_reset;
992 us->max_lun = 0;
993
994 result = usb_stor_probe2(us);
995 return result;
996}
997
998static struct usb_driver sddr55_driver = {
999 .name = "ums-sddr55",
1000 .probe = sddr55_probe,
1001 .disconnect = usb_stor_disconnect,
1002 .suspend = usb_stor_suspend,
1003 .resume = usb_stor_resume,
1004 .reset_resume = usb_stor_reset_resume,
1005 .pre_reset = usb_stor_pre_reset,
1006 .post_reset = usb_stor_post_reset,
1007 .id_table = sddr55_usb_ids,
1008 .soft_unbind = 1,
1009};
1010
1011static int __init sddr55_init(void)
1012{
1013 return usb_register(&sddr55_driver);
1014}
1015
1016static void __exit sddr55_exit(void)
1017{
1018 usb_deregister(&sddr55_driver);
1019}
1020
1021module_init(sddr55_init);
1022module_exit(sddr55_exit);
diff --git a/drivers/usb/storage/shuttle_usbat.c b/drivers/usb/storage/shuttle_usbat.c
index ae6d64810d2a..b62a28814ebe 100644
--- a/drivers/usb/storage/shuttle_usbat.c
+++ b/drivers/usb/storage/shuttle_usbat.c
@@ -42,6 +42,7 @@
42 */ 42 */
43 43
44#include <linux/errno.h> 44#include <linux/errno.h>
45#include <linux/module.h>
45#include <linux/slab.h> 46#include <linux/slab.h>
46#include <linux/cdrom.h> 47#include <linux/cdrom.h>
47 48
@@ -52,7 +53,100 @@
52#include "transport.h" 53#include "transport.h"
53#include "protocol.h" 54#include "protocol.h"
54#include "debug.h" 55#include "debug.h"
55#include "shuttle_usbat.h" 56
57MODULE_DESCRIPTION("Driver for SCM Microsystems (a.k.a. Shuttle) USB-ATAPI cable");
58MODULE_AUTHOR("Daniel Drake <dsd@gentoo.org>, Robert Baruch <autophile@starband.net>");
59MODULE_LICENSE("GPL");
60
61/* Supported device types */
62#define USBAT_DEV_HP8200 0x01
63#define USBAT_DEV_FLASH 0x02
64
65#define USBAT_EPP_PORT 0x10
66#define USBAT_EPP_REGISTER 0x30
67#define USBAT_ATA 0x40
68#define USBAT_ISA 0x50
69
70/* Commands (need to be logically OR'd with an access type */
71#define USBAT_CMD_READ_REG 0x00
72#define USBAT_CMD_WRITE_REG 0x01
73#define USBAT_CMD_READ_BLOCK 0x02
74#define USBAT_CMD_WRITE_BLOCK 0x03
75#define USBAT_CMD_COND_READ_BLOCK 0x04
76#define USBAT_CMD_COND_WRITE_BLOCK 0x05
77#define USBAT_CMD_WRITE_REGS 0x07
78
79/* Commands (these don't need an access type) */
80#define USBAT_CMD_EXEC_CMD 0x80
81#define USBAT_CMD_SET_FEAT 0x81
82#define USBAT_CMD_UIO 0x82
83
84/* Methods of accessing UIO register */
85#define USBAT_UIO_READ 1
86#define USBAT_UIO_WRITE 0
87
88/* Qualifier bits */
89#define USBAT_QUAL_FCQ 0x20 /* full compare */
90#define USBAT_QUAL_ALQ 0x10 /* auto load subcount */
91
92/* USBAT Flash Media status types */
93#define USBAT_FLASH_MEDIA_NONE 0
94#define USBAT_FLASH_MEDIA_CF 1
95
96/* USBAT Flash Media change types */
97#define USBAT_FLASH_MEDIA_SAME 0
98#define USBAT_FLASH_MEDIA_CHANGED 1
99
100/* USBAT ATA registers */
101#define USBAT_ATA_DATA 0x10 /* read/write data (R/W) */
102#define USBAT_ATA_FEATURES 0x11 /* set features (W) */
103#define USBAT_ATA_ERROR 0x11 /* error (R) */
104#define USBAT_ATA_SECCNT 0x12 /* sector count (R/W) */
105#define USBAT_ATA_SECNUM 0x13 /* sector number (R/W) */
106#define USBAT_ATA_LBA_ME 0x14 /* cylinder low (R/W) */
107#define USBAT_ATA_LBA_HI 0x15 /* cylinder high (R/W) */
108#define USBAT_ATA_DEVICE 0x16 /* head/device selection (R/W) */
109#define USBAT_ATA_STATUS 0x17 /* device status (R) */
110#define USBAT_ATA_CMD 0x17 /* device command (W) */
111#define USBAT_ATA_ALTSTATUS 0x0E /* status (no clear IRQ) (R) */
112
113/* USBAT User I/O Data registers */
114#define USBAT_UIO_EPAD 0x80 /* Enable Peripheral Control Signals */
115#define USBAT_UIO_CDT 0x40 /* Card Detect (Read Only) */
116 /* CDT = ACKD & !UI1 & !UI0 */
117#define USBAT_UIO_1 0x20 /* I/O 1 */
118#define USBAT_UIO_0 0x10 /* I/O 0 */
119#define USBAT_UIO_EPP_ATA 0x08 /* 1=EPP mode, 0=ATA mode */
120#define USBAT_UIO_UI1 0x04 /* Input 1 */
121#define USBAT_UIO_UI0 0x02 /* Input 0 */
122#define USBAT_UIO_INTR_ACK 0x01 /* Interrupt (ATA/ISA)/Acknowledge (EPP) */
123
124/* USBAT User I/O Enable registers */
125#define USBAT_UIO_DRVRST 0x80 /* Reset Peripheral */
126#define USBAT_UIO_ACKD 0x40 /* Enable Card Detect */
127#define USBAT_UIO_OE1 0x20 /* I/O 1 set=output/clr=input */
128 /* If ACKD=1, set OE1 to 1 also. */
129#define USBAT_UIO_OE0 0x10 /* I/O 0 set=output/clr=input */
130#define USBAT_UIO_ADPRST 0x01 /* Reset SCM chip */
131
132/* USBAT Features */
133#define USBAT_FEAT_ETEN 0x80 /* External trigger enable */
134#define USBAT_FEAT_U1 0x08
135#define USBAT_FEAT_U0 0x04
136#define USBAT_FEAT_ET1 0x02
137#define USBAT_FEAT_ET2 0x01
138
139struct usbat_info {
140 int devicetype;
141
142 /* Used for Flash readers only */
143 unsigned long sectors; /* total sector count */
144 unsigned long ssize; /* sector size in bytes */
145
146 unsigned char sense_key;
147 unsigned long sense_asc; /* additional sense code */
148 unsigned long sense_ascq; /* additional sense code qualifier */
149};
56 150
57#define short_pack(LSB,MSB) ( ((u16)(LSB)) | ( ((u16)(MSB))<<8 ) ) 151#define short_pack(LSB,MSB) ( ((u16)(LSB)) | ( ((u16)(MSB))<<8 ) )
58#define LSB_of(s) ((s)&0xFF) 152#define LSB_of(s) ((s)&0xFF)
@@ -63,6 +157,48 @@ static int transferred = 0;
63static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us); 157static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us);
64static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us); 158static int usbat_hp8200e_transport(struct scsi_cmnd *srb, struct us_data *us);
65 159
160static int init_usbat_cd(struct us_data *us);
161static int init_usbat_flash(struct us_data *us);
162
163
164/*
165 * The table of devices
166 */
167#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
168 vendorName, productName, useProtocol, useTransport, \
169 initFunction, flags) \
170{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
171 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
172
173struct usb_device_id usbat_usb_ids[] = {
174# include "unusual_usbat.h"
175 { } /* Terminating entry */
176};
177MODULE_DEVICE_TABLE(usb, usbat_usb_ids);
178
179#undef UNUSUAL_DEV
180
181/*
182 * The flags table
183 */
184#define UNUSUAL_DEV(idVendor, idProduct, bcdDeviceMin, bcdDeviceMax, \
185 vendor_name, product_name, use_protocol, use_transport, \
186 init_function, Flags) \
187{ \
188 .vendorName = vendor_name, \
189 .productName = product_name, \
190 .useProtocol = use_protocol, \
191 .useTransport = use_transport, \
192 .initFunction = init_function, \
193}
194
195static struct us_unusual_dev usbat_unusual_dev_list[] = {
196# include "unusual_usbat.h"
197 { } /* Terminating entry */
198};
199
200#undef UNUSUAL_DEV
201
66/* 202/*
67 * Convenience function to produce an ATA read/write sectors command 203 * Convenience function to produce an ATA read/write sectors command
68 * Use cmd=0x20 for read, cmd=0x30 for write 204 * Use cmd=0x20 for read, cmd=0x30 for write
@@ -1684,37 +1820,61 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
1684 return USB_STOR_TRANSPORT_FAILED; 1820 return USB_STOR_TRANSPORT_FAILED;
1685} 1821}
1686 1822
1687int init_usbat_cd(struct us_data *us) 1823static int init_usbat_cd(struct us_data *us)
1688{ 1824{
1689 return init_usbat(us, USBAT_DEV_HP8200); 1825 return init_usbat(us, USBAT_DEV_HP8200);
1690} 1826}
1691 1827
1692 1828static int init_usbat_flash(struct us_data *us)
1693int init_usbat_flash(struct us_data *us)
1694{ 1829{
1695 return init_usbat(us, USBAT_DEV_FLASH); 1830 return init_usbat(us, USBAT_DEV_FLASH);
1696} 1831}
1697 1832
1698int init_usbat_probe(struct us_data *us) 1833static int usbat_probe(struct usb_interface *intf,
1834 const struct usb_device_id *id)
1699{ 1835{
1700 return init_usbat(us, 0); 1836 struct us_data *us;
1837 int result;
1838
1839 result = usb_stor_probe1(&us, intf, id,
1840 (id - usbat_usb_ids) + usbat_unusual_dev_list);
1841 if (result)
1842 return result;
1843
1844 /* The actual transport will be determined later by the
1845 * initialization routine; this is just a placeholder.
1846 */
1847 us->transport_name = "Shuttle USBAT";
1848 us->transport = usbat_flash_transport;
1849 us->transport_reset = usb_stor_CB_reset;
1850 us->max_lun = 1;
1851
1852 result = usb_stor_probe2(us);
1853 return result;
1701} 1854}
1702 1855
1703/* 1856static struct usb_driver usbat_driver = {
1704 * Default transport function. Attempts to detect which transport function 1857 .name = "ums-usbat",
1705 * should be called, makes it the new default, and calls it. 1858 .probe = usbat_probe,
1706 * 1859 .disconnect = usb_stor_disconnect,
1707 * This function should never be called. Our usbat_init() function detects the 1860 .suspend = usb_stor_suspend,
1708 * device type and changes the us->transport ptr to the transport function 1861 .resume = usb_stor_resume,
1709 * relevant to the device. 1862 .reset_resume = usb_stor_reset_resume,
1710 * However, we'll support this impossible(?) case anyway. 1863 .pre_reset = usb_stor_pre_reset,
1711 */ 1864 .post_reset = usb_stor_post_reset,
1712int usbat_transport(struct scsi_cmnd *srb, struct us_data *us) 1865 .id_table = usbat_usb_ids,
1866 .soft_unbind = 1,
1867};
1868
1869static int __init usbat_init(void)
1713{ 1870{
1714 struct usbat_info *info = (struct usbat_info*) (us->extra); 1871 return usb_register(&usbat_driver);
1715 1872}
1716 if (usbat_set_transport(us, info, 0))
1717 return USB_STOR_TRANSPORT_ERROR;
1718 1873
1719 return us->transport(srb, us); 1874static void __exit usbat_exit(void)
1875{
1876 usb_deregister(&usbat_driver);
1720} 1877}
1878
1879module_init(usbat_init);
1880module_exit(usbat_exit);
diff --git a/drivers/usb/storage/shuttle_usbat.h b/drivers/usb/storage/shuttle_usbat.h
deleted file mode 100644
index d8bfc43e9044..000000000000
--- a/drivers/usb/storage/shuttle_usbat.h
+++ /dev/null
@@ -1,123 +0,0 @@
1/* Driver for SCM Microsystems USB-ATAPI cable
2 * Header File
3 *
4 * Current development and maintenance by:
5 * (c) 2000 Robert Baruch (autophile@dol.net)
6 * (c) 2004, 2005 Daniel Drake <dsd@gentoo.org>
7 *
8 * See shuttle_usbat.c for more explanation
9 *
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2, or (at your option) any
13 * later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25#ifndef _USB_SHUTTLE_USBAT_H
26#define _USB_SHUTTLE_USBAT_H
27
28/* Supported device types */
29#define USBAT_DEV_HP8200 0x01
30#define USBAT_DEV_FLASH 0x02
31
32#define USBAT_EPP_PORT 0x10
33#define USBAT_EPP_REGISTER 0x30
34#define USBAT_ATA 0x40
35#define USBAT_ISA 0x50
36
37/* Commands (need to be logically OR'd with an access type */
38#define USBAT_CMD_READ_REG 0x00
39#define USBAT_CMD_WRITE_REG 0x01
40#define USBAT_CMD_READ_BLOCK 0x02
41#define USBAT_CMD_WRITE_BLOCK 0x03
42#define USBAT_CMD_COND_READ_BLOCK 0x04
43#define USBAT_CMD_COND_WRITE_BLOCK 0x05
44#define USBAT_CMD_WRITE_REGS 0x07
45
46/* Commands (these don't need an access type) */
47#define USBAT_CMD_EXEC_CMD 0x80
48#define USBAT_CMD_SET_FEAT 0x81
49#define USBAT_CMD_UIO 0x82
50
51/* Methods of accessing UIO register */
52#define USBAT_UIO_READ 1
53#define USBAT_UIO_WRITE 0
54
55/* Qualifier bits */
56#define USBAT_QUAL_FCQ 0x20 /* full compare */
57#define USBAT_QUAL_ALQ 0x10 /* auto load subcount */
58
59/* USBAT Flash Media status types */
60#define USBAT_FLASH_MEDIA_NONE 0
61#define USBAT_FLASH_MEDIA_CF 1
62
63/* USBAT Flash Media change types */
64#define USBAT_FLASH_MEDIA_SAME 0
65#define USBAT_FLASH_MEDIA_CHANGED 1
66
67/* USBAT ATA registers */
68#define USBAT_ATA_DATA 0x10 /* read/write data (R/W) */
69#define USBAT_ATA_FEATURES 0x11 /* set features (W) */
70#define USBAT_ATA_ERROR 0x11 /* error (R) */
71#define USBAT_ATA_SECCNT 0x12 /* sector count (R/W) */
72#define USBAT_ATA_SECNUM 0x13 /* sector number (R/W) */
73#define USBAT_ATA_LBA_ME 0x14 /* cylinder low (R/W) */
74#define USBAT_ATA_LBA_HI 0x15 /* cylinder high (R/W) */
75#define USBAT_ATA_DEVICE 0x16 /* head/device selection (R/W) */
76#define USBAT_ATA_STATUS 0x17 /* device status (R) */
77#define USBAT_ATA_CMD 0x17 /* device command (W) */
78#define USBAT_ATA_ALTSTATUS 0x0E /* status (no clear IRQ) (R) */
79
80/* USBAT User I/O Data registers */
81#define USBAT_UIO_EPAD 0x80 /* Enable Peripheral Control Signals */
82#define USBAT_UIO_CDT 0x40 /* Card Detect (Read Only) */
83 /* CDT = ACKD & !UI1 & !UI0 */
84#define USBAT_UIO_1 0x20 /* I/O 1 */
85#define USBAT_UIO_0 0x10 /* I/O 0 */
86#define USBAT_UIO_EPP_ATA 0x08 /* 1=EPP mode, 0=ATA mode */
87#define USBAT_UIO_UI1 0x04 /* Input 1 */
88#define USBAT_UIO_UI0 0x02 /* Input 0 */
89#define USBAT_UIO_INTR_ACK 0x01 /* Interrupt (ATA/ISA)/Acknowledge (EPP) */
90
91/* USBAT User I/O Enable registers */
92#define USBAT_UIO_DRVRST 0x80 /* Reset Peripheral */
93#define USBAT_UIO_ACKD 0x40 /* Enable Card Detect */
94#define USBAT_UIO_OE1 0x20 /* I/O 1 set=output/clr=input */
95 /* If ACKD=1, set OE1 to 1 also. */
96#define USBAT_UIO_OE0 0x10 /* I/O 0 set=output/clr=input */
97#define USBAT_UIO_ADPRST 0x01 /* Reset SCM chip */
98
99/* USBAT Features */
100#define USBAT_FEAT_ETEN 0x80 /* External trigger enable */
101#define USBAT_FEAT_U1 0x08
102#define USBAT_FEAT_U0 0x04
103#define USBAT_FEAT_ET1 0x02
104#define USBAT_FEAT_ET2 0x01
105
106extern int usbat_transport(struct scsi_cmnd *srb, struct us_data *us);
107extern int init_usbat_cd(struct us_data *us);
108extern int init_usbat_flash(struct us_data *us);
109extern int init_usbat_probe(struct us_data *us);
110
111struct usbat_info {
112 int devicetype;
113
114 /* Used for Flash readers only */
115 unsigned long sectors; /* total sector count */
116 unsigned long ssize; /* sector size in bytes */
117
118 unsigned char sense_key;
119 unsigned long sense_asc; /* additional sense code */
120 unsigned long sense_ascq; /* additional sense code qualifier */
121};
122
123#endif
diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
index fb65d221cedf..d48c8553539d 100644
--- a/drivers/usb/storage/transport.c
+++ b/drivers/usb/storage/transport.c
@@ -220,6 +220,7 @@ int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
220 status = us->current_urb->actual_length; 220 status = us->current_urb->actual_length;
221 return status; 221 return status;
222} 222}
223EXPORT_SYMBOL_GPL(usb_stor_control_msg);
223 224
224/* This is a version of usb_clear_halt() that allows early termination and 225/* This is a version of usb_clear_halt() that allows early termination and
225 * doesn't read the status from the device -- this is because some devices 226 * doesn't read the status from the device -- this is because some devices
@@ -254,6 +255,7 @@ int usb_stor_clear_halt(struct us_data *us, unsigned int pipe)
254 US_DEBUGP("%s: result = %d\n", __func__, result); 255 US_DEBUGP("%s: result = %d\n", __func__, result);
255 return result; 256 return result;
256} 257}
258EXPORT_SYMBOL_GPL(usb_stor_clear_halt);
257 259
258 260
259/* 261/*
@@ -352,6 +354,7 @@ int usb_stor_ctrl_transfer(struct us_data *us, unsigned int pipe,
352 return interpret_urb_result(us, pipe, size, result, 354 return interpret_urb_result(us, pipe, size, result,
353 us->current_urb->actual_length); 355 us->current_urb->actual_length);
354} 356}
357EXPORT_SYMBOL_GPL(usb_stor_ctrl_transfer);
355 358
356/* 359/*
357 * Receive one interrupt buffer, without timeouts, but allowing early 360 * Receive one interrupt buffer, without timeouts, but allowing early
@@ -407,6 +410,7 @@ int usb_stor_bulk_transfer_buf(struct us_data *us, unsigned int pipe,
407 return interpret_urb_result(us, pipe, length, result, 410 return interpret_urb_result(us, pipe, length, result,
408 us->current_urb->actual_length); 411 us->current_urb->actual_length);
409} 412}
413EXPORT_SYMBOL_GPL(usb_stor_bulk_transfer_buf);
410 414
411/* 415/*
412 * Transfer a scatter-gather list via bulk transfer 416 * Transfer a scatter-gather list via bulk transfer
@@ -474,6 +478,7 @@ int usb_stor_bulk_srb(struct us_data* us, unsigned int pipe,
474 scsi_set_resid(srb, scsi_bufflen(srb) - partial); 478 scsi_set_resid(srb, scsi_bufflen(srb) - partial);
475 return result; 479 return result;
476} 480}
481EXPORT_SYMBOL_GPL(usb_stor_bulk_srb);
477 482
478/* 483/*
479 * Transfer an entire SCSI command's worth of data payload over the bulk 484 * Transfer an entire SCSI command's worth of data payload over the bulk
@@ -509,6 +514,7 @@ int usb_stor_bulk_transfer_sg(struct us_data* us, unsigned int pipe,
509 *residual = length_left; 514 *residual = length_left;
510 return result; 515 return result;
511} 516}
517EXPORT_SYMBOL_GPL(usb_stor_bulk_transfer_sg);
512 518
513/*********************************************************************** 519/***********************************************************************
514 * Transport routines 520 * Transport routines
@@ -940,6 +946,7 @@ int usb_stor_CB_transport(struct scsi_cmnd *srb, struct us_data *us)
940 usb_stor_clear_halt(us, pipe); 946 usb_stor_clear_halt(us, pipe);
941 return USB_STOR_TRANSPORT_FAILED; 947 return USB_STOR_TRANSPORT_FAILED;
942} 948}
949EXPORT_SYMBOL_GPL(usb_stor_CB_transport);
943 950
944/* 951/*
945 * Bulk only transport 952 * Bulk only transport
@@ -1156,6 +1163,7 @@ int usb_stor_Bulk_transport(struct scsi_cmnd *srb, struct us_data *us)
1156 /* we should never get here, but if we do, we're in trouble */ 1163 /* we should never get here, but if we do, we're in trouble */
1157 return USB_STOR_TRANSPORT_ERROR; 1164 return USB_STOR_TRANSPORT_ERROR;
1158} 1165}
1166EXPORT_SYMBOL_GPL(usb_stor_Bulk_transport);
1159 1167
1160/*********************************************************************** 1168/***********************************************************************
1161 * Reset routines 1169 * Reset routines
@@ -1230,6 +1238,7 @@ int usb_stor_CB_reset(struct us_data *us)
1230 USB_TYPE_CLASS | USB_RECIP_INTERFACE, 1238 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1231 0, us->ifnum, us->iobuf, CB_RESET_CMD_SIZE); 1239 0, us->ifnum, us->iobuf, CB_RESET_CMD_SIZE);
1232} 1240}
1241EXPORT_SYMBOL_GPL(usb_stor_CB_reset);
1233 1242
1234/* This issues a Bulk-only Reset to the device in question, including 1243/* This issues a Bulk-only Reset to the device in question, including
1235 * clearing the subsequent endpoint halts that may occur. 1244 * clearing the subsequent endpoint halts that may occur.
@@ -1242,6 +1251,7 @@ int usb_stor_Bulk_reset(struct us_data *us)
1242 USB_TYPE_CLASS | USB_RECIP_INTERFACE, 1251 USB_TYPE_CLASS | USB_RECIP_INTERFACE,
1243 0, us->ifnum, NULL, 0); 1252 0, us->ifnum, NULL, 0);
1244} 1253}
1254EXPORT_SYMBOL_GPL(usb_stor_Bulk_reset);
1245 1255
1246/* Issue a USB port reset to the device. The caller must not hold 1256/* Issue a USB port reset to the device. The caller must not hold
1247 * us->dev_mutex. 1257 * us->dev_mutex.
diff --git a/drivers/usb/storage/freecom.h b/drivers/usb/storage/unusual_alauda.h
index 20d0fe6ba0c8..8c412f885dd2 100644
--- a/drivers/usb/storage/freecom.h
+++ b/drivers/usb/storage/unusual_alauda.h
@@ -1,13 +1,4 @@
1/* Driver for Freecom USB/IDE adaptor 1/* Unusual Devices File for the Alauda-based card readers
2 *
3 * Freecom v0.1:
4 *
5 * First release
6 *
7 * Current development and maintenance by:
8 * (c) 2000 David Brown <usb-storage@davidb.org>
9 *
10 * See freecom.c for more explanation
11 * 2 *
12 * This program is free software; you can redistribute it and/or modify it 3 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the 4 * under the terms of the GNU General Public License as published by the
@@ -24,11 +15,17 @@
24 * 675 Mass Ave, Cambridge, MA 02139, USA. 15 * 675 Mass Ave, Cambridge, MA 02139, USA.
25 */ 16 */
26 17
27#ifndef _FREECOM_USB_H 18#if defined(CONFIG_USB_STORAGE_ALAUDA) || \
28#define _FREECOM_USB_H 19 defined(CONFIG_USB_STORAGE_ALAUDA_MODULE)
20
21UNUSUAL_DEV( 0x0584, 0x0008, 0x0102, 0x0102,
22 "Fujifilm",
23 "DPC-R1 (Alauda)",
24 US_SC_SCSI, US_PR_ALAUDA, init_alauda, 0),
29 25
30extern int freecom_transport(struct scsi_cmnd *srb, struct us_data *us); 26UNUSUAL_DEV( 0x07b4, 0x010a, 0x0102, 0x0102,
31extern int usb_stor_freecom_reset(struct us_data *us); 27 "Olympus",
32extern int freecom_init (struct us_data *us); 28 "MAUSB-10 (Alauda)",
29 US_SC_SCSI, US_PR_ALAUDA, init_alauda, 0),
33 30
34#endif 31#endif /* defined(CONFIG_USB_STORAGE_ALAUDA) || ... */
diff --git a/drivers/usb/storage/unusual_cypress.h b/drivers/usb/storage/unusual_cypress.h
new file mode 100644
index 000000000000..44be6d75dab6
--- /dev/null
+++ b/drivers/usb/storage/unusual_cypress.h
@@ -0,0 +1,34 @@
1/* Unusual Devices File for devices based on the Cypress USB/ATA bridge
2 * with support for ATACB
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2, or (at your option) any
7 * later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 675 Mass Ave, Cambridge, MA 02139, USA.
17 */
18
19#if defined(CONFIG_USB_STORAGE_CYPRESS_ATACB) || \
20 defined(CONFIG_USB_STORAGE_CYPRESS_ATACB_MODULE)
21
22/* CY7C68300 : support atacb */
23UNUSUAL_DEV( 0x04b4, 0x6830, 0x0000, 0x9999,
24 "Cypress",
25 "Cypress AT2LP",
26 US_SC_CYP_ATACB, US_PR_DEVICE, NULL, 0),
27
28/* CY7C68310 : support atacb and atacb2 */
29UNUSUAL_DEV( 0x04b4, 0x6831, 0x0000, 0x9999,
30 "Cypress",
31 "Cypress ISD-300LP",
32 US_SC_CYP_ATACB, US_PR_DEVICE, NULL, 0),
33
34#endif /* defined(CONFIG_USB_STORAGE_CYPRESS_ATACB) || ... */
diff --git a/drivers/usb/storage/unusual_datafab.h b/drivers/usb/storage/unusual_datafab.h
new file mode 100644
index 000000000000..c9298ce9f223
--- /dev/null
+++ b/drivers/usb/storage/unusual_datafab.h
@@ -0,0 +1,98 @@
1/* Unusual Devices File for the Datafab USB Compact Flash reader
2 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2, or (at your option) any
6 * later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18#if defined(CONFIG_USB_STORAGE_DATAFAB) || \
19 defined(CONFIG_USB_STORAGE_DATAFAB_MODULE)
20
21UNUSUAL_DEV( 0x07c4, 0xa000, 0x0000, 0x0015,
22 "Datafab",
23 "MDCFE-B USB CF Reader",
24 US_SC_SCSI, US_PR_DATAFAB, NULL,
25 0),
26
27/*
28 * The following Datafab-based devices may or may not work
29 * using the current driver...the 0xffff is arbitrary since I
30 * don't know what device versions exist for these guys.
31 *
32 * The 0xa003 and 0xa004 devices in particular I'm curious about.
33 * I'm told they exist but so far nobody has come forward to say that
34 * they work with this driver. Given the success we've had getting
35 * other Datafab-based cards operational with this driver, I've decided
36 * to leave these two devices in the list.
37 */
38UNUSUAL_DEV( 0x07c4, 0xa001, 0x0000, 0xffff,
39 "SIIG/Datafab",
40 "SIIG/Datafab Memory Stick+CF Reader/Writer",
41 US_SC_SCSI, US_PR_DATAFAB, NULL,
42 0),
43
44/* Reported by Josef Reisinger <josef.reisinger@netcologne.de> */
45UNUSUAL_DEV( 0x07c4, 0xa002, 0x0000, 0xffff,
46 "Datafab/Unknown",
47 "MD2/MD3 Disk enclosure",
48 US_SC_SCSI, US_PR_DATAFAB, NULL,
49 US_FL_SINGLE_LUN),
50
51UNUSUAL_DEV( 0x07c4, 0xa003, 0x0000, 0xffff,
52 "Datafab/Unknown",
53 "Datafab-based Reader",
54 US_SC_SCSI, US_PR_DATAFAB, NULL,
55 0),
56
57UNUSUAL_DEV( 0x07c4, 0xa004, 0x0000, 0xffff,
58 "Datafab/Unknown",
59 "Datafab-based Reader",
60 US_SC_SCSI, US_PR_DATAFAB, NULL,
61 0),
62
63UNUSUAL_DEV( 0x07c4, 0xa005, 0x0000, 0xffff,
64 "PNY/Datafab",
65 "PNY/Datafab CF+SM Reader",
66 US_SC_SCSI, US_PR_DATAFAB, NULL,
67 0),
68
69UNUSUAL_DEV( 0x07c4, 0xa006, 0x0000, 0xffff,
70 "Simple Tech/Datafab",
71 "Simple Tech/Datafab CF+SM Reader",
72 US_SC_SCSI, US_PR_DATAFAB, NULL,
73 0),
74
75/* Submitted by Olaf Hering <olh@suse.de> */
76UNUSUAL_DEV( 0x07c4, 0xa109, 0x0000, 0xffff,
77 "Datafab Systems, Inc.",
78 "USB to CF + SM Combo (LC1)",
79 US_SC_SCSI, US_PR_DATAFAB, NULL,
80 0),
81
82/* Reported by Felix Moeller <felix@derklecks.de>
83 * in Germany this is sold by Hama with the productnumber 46952
84 * as "DualSlot CompactFlash(TM) & MStick Drive USB"
85 */
86UNUSUAL_DEV( 0x07c4, 0xa10b, 0x0000, 0xffff,
87 "DataFab Systems Inc.",
88 "USB CF+MS",
89 US_SC_SCSI, US_PR_DATAFAB, NULL,
90 0),
91
92UNUSUAL_DEV( 0x0c0b, 0xa109, 0x0000, 0xffff,
93 "Acomdata",
94 "CF",
95 US_SC_SCSI, US_PR_DATAFAB, NULL,
96 US_FL_SINGLE_LUN),
97
98#endif /* defined(CONFIG_USB_STORAGE_DATAFAB) || ... */
diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
index cfde74a6faa3..1c1f643e8a78 100644
--- a/drivers/usb/storage/unusual_devs.h
+++ b/drivers/usb/storage/unusual_devs.h
@@ -53,6 +53,11 @@
53 * as opposed to devices that do something strangely or wrongly. 53 * as opposed to devices that do something strangely or wrongly.
54 */ 54 */
55 55
56#if !defined(CONFIG_USB_STORAGE_SDDR09) && \
57 !defined(CONFIG_USB_STORAGE_SDDR09_MODULE)
58#define NO_SDDR09
59#endif
60
56/* patch submitted by Vivian Bregier <Vivian.Bregier@imag.fr> 61/* patch submitted by Vivian Bregier <Vivian.Bregier@imag.fr>
57 */ 62 */
58UNUSUAL_DEV( 0x03eb, 0x2002, 0x0100, 0x0100, 63UNUSUAL_DEV( 0x03eb, 0x2002, 0x0100, 0x0100,
@@ -80,18 +85,6 @@ UNUSUAL_DEV( 0x03f0, 0x0107, 0x0200, 0x0200,
80 "CD-Writer+", 85 "CD-Writer+",
81 US_SC_8070, US_PR_CB, NULL, 0), 86 US_SC_8070, US_PR_CB, NULL, 0),
82 87
83#ifdef CONFIG_USB_STORAGE_USBAT
84UNUSUAL_DEV( 0x03f0, 0x0207, 0x0001, 0x0001,
85 "HP",
86 "CD-Writer+ 8200e",
87 US_SC_8070, US_PR_USBAT, init_usbat_cd, 0),
88
89UNUSUAL_DEV( 0x03f0, 0x0307, 0x0001, 0x0001,
90 "HP",
91 "CD-Writer+ CD-4e",
92 US_SC_8070, US_PR_USBAT, init_usbat_cd, 0),
93#endif
94
95/* Reported by Ben Efros <ben@pc-doctor.com> */ 88/* Reported by Ben Efros <ben@pc-doctor.com> */
96UNUSUAL_DEV( 0x03f0, 0x070c, 0x0000, 0x0000, 89UNUSUAL_DEV( 0x03f0, 0x070c, 0x0000, 0x0000,
97 "HP", 90 "HP",
@@ -246,12 +239,7 @@ UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210,
246 US_SC_DEVICE, US_PR_DEVICE, NULL, 239 US_SC_DEVICE, US_PR_DEVICE, NULL,
247 US_FL_SINGLE_LUN ), 240 US_FL_SINGLE_LUN ),
248 241
249#ifdef CONFIG_USB_STORAGE_SDDR09 242#ifdef NO_SDDR09
250UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100,
251 "Microtech",
252 "CameraMate (DPCM_USB)",
253 US_SC_SCSI, US_PR_DPCM_USB, NULL, 0 ),
254#else
255UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100, 243UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100,
256 "Microtech", 244 "Microtech",
257 "CameraMate", 245 "CameraMate",
@@ -288,13 +276,6 @@ UNUSUAL_DEV( 0x0457, 0x0151, 0x0100, 0x0100,
288 US_SC_DEVICE, US_PR_DEVICE, NULL, 276 US_SC_DEVICE, US_PR_DEVICE, NULL,
289 US_FL_NOT_LOCKABLE ), 277 US_FL_NOT_LOCKABLE ),
290 278
291#ifdef CONFIG_USB_STORAGE_KARMA
292UNUSUAL_DEV( 0x045a, 0x5210, 0x0101, 0x0101,
293 "Rio",
294 "Rio Karma",
295 US_SC_SCSI, US_PR_KARMA, rio_karma_init, 0),
296#endif
297
298/* Reported by Tamas Kerecsen <kerecsen@bigfoot.com> 279/* Reported by Tamas Kerecsen <kerecsen@bigfoot.com>
299 * Obviously the PROM has not been customized by the VAR; 280 * Obviously the PROM has not been customized by the VAR;
300 * the Vendor and Product string descriptors are: 281 * the Vendor and Product string descriptors are:
@@ -375,22 +356,6 @@ UNUSUAL_DEV( 0x04b3, 0x4001, 0x0110, 0x0110,
375 US_SC_DEVICE, US_PR_CB, NULL, 356 US_SC_DEVICE, US_PR_CB, NULL,
376 US_FL_MAX_SECTORS_MIN), 357 US_FL_MAX_SECTORS_MIN),
377 358
378#ifdef CONFIG_USB_STORAGE_CYPRESS_ATACB
379/* CY7C68300 : support atacb */
380UNUSUAL_DEV( 0x04b4, 0x6830, 0x0000, 0x9999,
381 "Cypress",
382 "Cypress AT2LP",
383 US_SC_CYP_ATACB, US_PR_DEVICE, NULL,
384 0),
385
386/* CY7C68310 : support atacb and atacb2 */
387UNUSUAL_DEV( 0x04b4, 0x6831, 0x0000, 0x9999,
388 "Cypress",
389 "Cypress ISD-300LP",
390 US_SC_CYP_ATACB, US_PR_DEVICE, NULL,
391 0),
392#endif
393
394/* Reported by Simon Levitt <simon@whattf.com> 359/* Reported by Simon Levitt <simon@whattf.com>
395 * This entry needs Sub and Proto fields */ 360 * This entry needs Sub and Proto fields */
396UNUSUAL_DEV( 0x04b8, 0x0601, 0x0100, 0x0100, 361UNUSUAL_DEV( 0x04b8, 0x0601, 0x0100, 0x0100,
@@ -467,20 +432,7 @@ UNUSUAL_DEV( 0x04e6, 0x0002, 0x0100, 0x0100,
467 US_SC_DEVICE, US_PR_DEVICE, usb_stor_euscsi_init, 432 US_SC_DEVICE, US_PR_DEVICE, usb_stor_euscsi_init,
468 US_FL_SCM_MULT_TARG ), 433 US_FL_SCM_MULT_TARG ),
469 434
470#ifdef CONFIG_USB_STORAGE_SDDR09 435#ifdef NO_SDDR09
471UNUSUAL_DEV( 0x04e6, 0x0003, 0x0000, 0x9999,
472 "Sandisk",
473 "ImageMate SDDR09",
474 US_SC_SCSI, US_PR_EUSB_SDDR09, usb_stor_sddr09_init,
475 0),
476
477/* This entry is from Andries.Brouwer@cwi.nl */
478UNUSUAL_DEV( 0x04e6, 0x0005, 0x0100, 0x0208,
479 "SCM Microsystems",
480 "eUSB SmartMedia / CompactFlash Adapter",
481 US_SC_SCSI, US_PR_DPCM_USB, usb_stor_sddr09_dpcm_init,
482 0),
483#else
484UNUSUAL_DEV( 0x04e6, 0x0005, 0x0100, 0x0208, 436UNUSUAL_DEV( 0x04e6, 0x0005, 0x0100, 0x0208,
485 "SCM Microsystems", 437 "SCM Microsystems",
486 "eUSB CompactFlash Adapter", 438 "eUSB CompactFlash Adapter",
@@ -535,14 +487,6 @@ UNUSUAL_DEV( 0x04e6, 0x0101, 0x0200, 0x0200,
535 "CD-RW Device", 487 "CD-RW Device",
536 US_SC_8020, US_PR_CB, NULL, 0), 488 US_SC_8020, US_PR_CB, NULL, 0),
537 489
538#ifdef CONFIG_USB_STORAGE_USBAT
539UNUSUAL_DEV( 0x04e6, 0x1010, 0x0000, 0x9999,
540 "Shuttle/SCM",
541 "USBAT-02",
542 US_SC_SCSI, US_PR_USBAT, init_usbat_flash,
543 US_FL_SINGLE_LUN),
544#endif
545
546/* Reported by Dmitry Khlystov <adminimus@gmail.com> */ 490/* Reported by Dmitry Khlystov <adminimus@gmail.com> */
547UNUSUAL_DEV( 0x04e8, 0x507c, 0x0220, 0x0220, 491UNUSUAL_DEV( 0x04e8, 0x507c, 0x0220, 0x0220,
548 "Samsung", 492 "Samsung",
@@ -645,14 +589,6 @@ UNUSUAL_DEV( 0x054c, 0x0025, 0x0100, 0x0100,
645 US_SC_DEVICE, US_PR_DEVICE, NULL, 589 US_SC_DEVICE, US_PR_DEVICE, NULL,
646 US_FL_SINGLE_LUN ), 590 US_FL_SINGLE_LUN ),
647 591
648#ifdef CONFIG_USB_STORAGE_ISD200
649UNUSUAL_DEV( 0x054c, 0x002b, 0x0100, 0x0110,
650 "Sony",
651 "Portable USB Harddrive V2",
652 US_SC_ISD200, US_PR_BULK, isd200_Initialization,
653 0 ),
654#endif
655
656/* Submitted by Olaf Hering, <olh@suse.de> SuSE Bugzilla #49049 */ 592/* Submitted by Olaf Hering, <olh@suse.de> SuSE Bugzilla #49049 */
657UNUSUAL_DEV( 0x054c, 0x002c, 0x0501, 0x2000, 593UNUSUAL_DEV( 0x054c, 0x002c, 0x0501, 0x2000,
658 "Sony", 594 "Sony",
@@ -749,13 +685,6 @@ UNUSUAL_DEV( 0x057b, 0x0022, 0x0000, 0x9999,
749 "Silicon Media R/W", 685 "Silicon Media R/W",
750 US_SC_DEVICE, US_PR_DEVICE, NULL, 0), 686 US_SC_DEVICE, US_PR_DEVICE, NULL, 0),
751 687
752#ifdef CONFIG_USB_STORAGE_ALAUDA
753UNUSUAL_DEV( 0x0584, 0x0008, 0x0102, 0x0102,
754 "Fujifilm",
755 "DPC-R1 (Alauda)",
756 US_SC_SCSI, US_PR_ALAUDA, init_alauda, 0 ),
757#endif
758
759/* Reported by RTE <raszilki@yandex.ru> */ 688/* Reported by RTE <raszilki@yandex.ru> */
760UNUSUAL_DEV( 0x058f, 0x6387, 0x0141, 0x0141, 689UNUSUAL_DEV( 0x058f, 0x6387, 0x0141, 0x0141,
761 "JetFlash", 690 "JetFlash",
@@ -798,32 +727,6 @@ UNUSUAL_DEV( 0x05ab, 0x0060, 0x1104, 0x1110,
798 US_SC_SCSI, US_PR_BULK, NULL, 727 US_SC_SCSI, US_PR_BULK, NULL,
799 US_FL_NEED_OVERRIDE ), 728 US_FL_NEED_OVERRIDE ),
800 729
801#ifdef CONFIG_USB_STORAGE_ISD200
802UNUSUAL_DEV( 0x05ab, 0x0031, 0x0100, 0x0110,
803 "In-System",
804 "USB/IDE Bridge (ATA/ATAPI)",
805 US_SC_ISD200, US_PR_BULK, isd200_Initialization,
806 0 ),
807
808UNUSUAL_DEV( 0x05ab, 0x0301, 0x0100, 0x0110,
809 "In-System",
810 "Portable USB Harddrive V2",
811 US_SC_ISD200, US_PR_BULK, isd200_Initialization,
812 0 ),
813
814UNUSUAL_DEV( 0x05ab, 0x0351, 0x0100, 0x0110,
815 "In-System",
816 "Portable USB Harddrive V2",
817 US_SC_ISD200, US_PR_BULK, isd200_Initialization,
818 0 ),
819
820UNUSUAL_DEV( 0x05ab, 0x5701, 0x0100, 0x0110,
821 "In-System",
822 "USB Storage Adapter V2",
823 US_SC_ISD200, US_PR_BULK, isd200_Initialization,
824 0 ),
825#endif
826
827/* Submitted by Sven Anderson <sven-linux@anderson.de> 730/* Submitted by Sven Anderson <sven-linux@anderson.de>
828 * There are at least four ProductIDs used for iPods, so I added 0x1202 and 731 * There are at least four ProductIDs used for iPods, so I added 0x1202 and
829 * 0x1204. They just need the US_FL_FIX_CAPACITY. As the bcdDevice appears 732 * 0x1204. They just need the US_FL_FIX_CAPACITY. As the bcdDevice appears
@@ -877,14 +780,6 @@ UNUSUAL_DEV( 0x05c6, 0x1000, 0x0000, 0x9999,
877 US_SC_DEVICE, US_PR_DEVICE, option_ms_init, 780 US_SC_DEVICE, US_PR_DEVICE, option_ms_init,
878 0), 781 0),
879 782
880#ifdef CONFIG_USB_STORAGE_JUMPSHOT
881UNUSUAL_DEV( 0x05dc, 0x0001, 0x0000, 0x0001,
882 "Lexar",
883 "Jumpshot USB CF Reader",
884 US_SC_SCSI, US_PR_JUMPSHOT, NULL,
885 US_FL_NEED_OVERRIDE ),
886#endif
887
888/* Reported by Blake Matheny <bmatheny@purdue.edu> */ 783/* Reported by Blake Matheny <bmatheny@purdue.edu> */
889UNUSUAL_DEV( 0x05dc, 0xb002, 0x0000, 0x0113, 784UNUSUAL_DEV( 0x05dc, 0xb002, 0x0000, 0x0113,
890 "Lexar", 785 "Lexar",
@@ -935,14 +830,6 @@ UNUSUAL_DEV( 0x0644, 0x0000, 0x0100, 0x0100,
935 "Floppy Drive", 830 "Floppy Drive",
936 US_SC_UFI, US_PR_CB, NULL, 0 ), 831 US_SC_UFI, US_PR_CB, NULL, 0 ),
937 832
938#ifdef CONFIG_USB_STORAGE_SDDR09
939UNUSUAL_DEV( 0x066b, 0x0105, 0x0100, 0x0100,
940 "Olympus",
941 "Camedia MAUSB-2",
942 US_SC_SCSI, US_PR_EUSB_SDDR09, usb_stor_sddr09_init,
943 0),
944#endif
945
946/* Reported by Darsen Lu <darsen@micro.ee.nthu.edu.tw> */ 833/* Reported by Darsen Lu <darsen@micro.ee.nthu.edu.tw> */
947UNUSUAL_DEV( 0x066f, 0x8000, 0x0001, 0x0001, 834UNUSUAL_DEV( 0x066f, 0x8000, 0x0001, 0x0001,
948 "SigmaTel", 835 "SigmaTel",
@@ -1043,35 +930,12 @@ UNUSUAL_DEV( 0x0781, 0x0002, 0x0009, 0x0009,
1043 US_SC_DEVICE, US_PR_DEVICE, NULL, 930 US_SC_DEVICE, US_PR_DEVICE, NULL,
1044 US_FL_FIX_CAPACITY ), 931 US_FL_FIX_CAPACITY ),
1045 932
1046#ifdef CONFIG_USB_STORAGE_USBAT
1047UNUSUAL_DEV( 0x0781, 0x0005, 0x0005, 0x0005,
1048 "Sandisk",
1049 "ImageMate SDDR-05b",
1050 US_SC_SCSI, US_PR_USBAT, init_usbat_flash,
1051 US_FL_SINGLE_LUN ),
1052#endif
1053
1054UNUSUAL_DEV( 0x0781, 0x0100, 0x0100, 0x0100, 933UNUSUAL_DEV( 0x0781, 0x0100, 0x0100, 0x0100,
1055 "Sandisk", 934 "Sandisk",
1056 "ImageMate SDDR-12", 935 "ImageMate SDDR-12",
1057 US_SC_SCSI, US_PR_CB, NULL, 936 US_SC_SCSI, US_PR_CB, NULL,
1058 US_FL_SINGLE_LUN ), 937 US_FL_SINGLE_LUN ),
1059 938
1060#ifdef CONFIG_USB_STORAGE_SDDR09
1061UNUSUAL_DEV( 0x0781, 0x0200, 0x0000, 0x9999,
1062 "Sandisk",
1063 "ImageMate SDDR-09",
1064 US_SC_SCSI, US_PR_EUSB_SDDR09, usb_stor_sddr09_init,
1065 0),
1066#endif
1067
1068#ifdef CONFIG_USB_STORAGE_FREECOM
1069UNUSUAL_DEV( 0x07ab, 0xfc01, 0x0000, 0x9999,
1070 "Freecom",
1071 "USB-IDE",
1072 US_SC_QIC, US_PR_FREECOM, freecom_init, 0),
1073#endif
1074
1075/* Reported by Eero Volotinen <eero@ping-viini.org> */ 939/* Reported by Eero Volotinen <eero@ping-viini.org> */
1076UNUSUAL_DEV( 0x07ab, 0xfccd, 0x0000, 0x9999, 940UNUSUAL_DEV( 0x07ab, 0xfccd, 0x0000, 0x9999,
1077 "Freecom Technologies", 941 "Freecom Technologies",
@@ -1091,12 +955,7 @@ UNUSUAL_DEV( 0x07af, 0x0005, 0x0100, 0x0100,
1091 US_SC_DEVICE, US_PR_DEVICE, usb_stor_euscsi_init, 955 US_SC_DEVICE, US_PR_DEVICE, usb_stor_euscsi_init,
1092 US_FL_SCM_MULT_TARG ), 956 US_FL_SCM_MULT_TARG ),
1093 957
1094#ifdef CONFIG_USB_STORAGE_SDDR09 958#ifdef NO_SDDR09
1095UNUSUAL_DEV( 0x07af, 0x0006, 0x0100, 0x0100,
1096 "Microtech",
1097 "CameraMate (DPCM_USB)",
1098 US_SC_SCSI, US_PR_DPCM_USB, NULL, 0 ),
1099#else
1100UNUSUAL_DEV( 0x07af, 0x0006, 0x0100, 0x0100, 959UNUSUAL_DEV( 0x07af, 0x0006, 0x0100, 0x0100,
1101 "Microtech", 960 "Microtech",
1102 "CameraMate", 961 "CameraMate",
@@ -1104,108 +963,6 @@ UNUSUAL_DEV( 0x07af, 0x0006, 0x0100, 0x0100,
1104 US_FL_SINGLE_LUN ), 963 US_FL_SINGLE_LUN ),
1105#endif 964#endif
1106 965
1107#ifdef CONFIG_USB_STORAGE_ALAUDA
1108UNUSUAL_DEV( 0x07b4, 0x010a, 0x0102, 0x0102,
1109 "Olympus",
1110 "MAUSB-10 (Alauda)",
1111 US_SC_SCSI, US_PR_ALAUDA, init_alauda, 0 ),
1112#endif
1113
1114#ifdef CONFIG_USB_STORAGE_DATAFAB
1115UNUSUAL_DEV( 0x07c4, 0xa000, 0x0000, 0x0015,
1116 "Datafab",
1117 "MDCFE-B USB CF Reader",
1118 US_SC_SCSI, US_PR_DATAFAB, NULL,
1119 0 ),
1120
1121/*
1122 * The following Datafab-based devices may or may not work
1123 * using the current driver...the 0xffff is arbitrary since I
1124 * don't know what device versions exist for these guys.
1125 *
1126 * The 0xa003 and 0xa004 devices in particular I'm curious about.
1127 * I'm told they exist but so far nobody has come forward to say that
1128 * they work with this driver. Given the success we've had getting
1129 * other Datafab-based cards operational with this driver, I've decided
1130 * to leave these two devices in the list.
1131 */
1132UNUSUAL_DEV( 0x07c4, 0xa001, 0x0000, 0xffff,
1133 "SIIG/Datafab",
1134 "SIIG/Datafab Memory Stick+CF Reader/Writer",
1135 US_SC_SCSI, US_PR_DATAFAB, NULL,
1136 0 ),
1137
1138/* Reported by Josef Reisinger <josef.reisinger@netcologne.de> */
1139UNUSUAL_DEV( 0x07c4, 0xa002, 0x0000, 0xffff,
1140 "Datafab/Unknown",
1141 "MD2/MD3 Disk enclosure",
1142 US_SC_SCSI, US_PR_DATAFAB, NULL,
1143 US_FL_SINGLE_LUN ),
1144
1145UNUSUAL_DEV( 0x07c4, 0xa003, 0x0000, 0xffff,
1146 "Datafab/Unknown",
1147 "Datafab-based Reader",
1148 US_SC_SCSI, US_PR_DATAFAB, NULL,
1149 0 ),
1150
1151UNUSUAL_DEV( 0x07c4, 0xa004, 0x0000, 0xffff,
1152 "Datafab/Unknown",
1153 "Datafab-based Reader",
1154 US_SC_SCSI, US_PR_DATAFAB, NULL,
1155 0 ),
1156
1157UNUSUAL_DEV( 0x07c4, 0xa005, 0x0000, 0xffff,
1158 "PNY/Datafab",
1159 "PNY/Datafab CF+SM Reader",
1160 US_SC_SCSI, US_PR_DATAFAB, NULL,
1161 0 ),
1162
1163UNUSUAL_DEV( 0x07c4, 0xa006, 0x0000, 0xffff,
1164 "Simple Tech/Datafab",
1165 "Simple Tech/Datafab CF+SM Reader",
1166 US_SC_SCSI, US_PR_DATAFAB, NULL,
1167 0 ),
1168#endif
1169
1170#ifdef CONFIG_USB_STORAGE_SDDR55
1171/* Contributed by Peter Waechtler */
1172UNUSUAL_DEV( 0x07c4, 0xa103, 0x0000, 0x9999,
1173 "Datafab",
1174 "MDSM-B reader",
1175 US_SC_SCSI, US_PR_SDDR55, NULL,
1176 US_FL_FIX_INQUIRY ),
1177#endif
1178
1179#ifdef CONFIG_USB_STORAGE_DATAFAB
1180/* Submitted by Olaf Hering <olh@suse.de> */
1181UNUSUAL_DEV( 0x07c4, 0xa109, 0x0000, 0xffff,
1182 "Datafab Systems, Inc.",
1183 "USB to CF + SM Combo (LC1)",
1184 US_SC_SCSI, US_PR_DATAFAB, NULL,
1185 0 ),
1186#endif
1187#ifdef CONFIG_USB_STORAGE_SDDR55
1188/* SM part - aeb <Andries.Brouwer@cwi.nl> */
1189UNUSUAL_DEV( 0x07c4, 0xa109, 0x0000, 0xffff,
1190 "Datafab Systems, Inc.",
1191 "USB to CF + SM Combo (LC1)",
1192 US_SC_SCSI, US_PR_SDDR55, NULL,
1193 US_FL_SINGLE_LUN ),
1194#endif
1195
1196#ifdef CONFIG_USB_STORAGE_DATAFAB
1197/* Reported by Felix Moeller <felix@derklecks.de>
1198 * in Germany this is sold by Hama with the productnumber 46952
1199 * as "DualSlot CompactFlash(TM) & MStick Drive USB"
1200 */
1201UNUSUAL_DEV( 0x07c4, 0xa10b, 0x0000, 0xffff,
1202 "DataFab Systems Inc.",
1203 "USB CF+MS",
1204 US_SC_SCSI, US_PR_DATAFAB, NULL,
1205 0 ),
1206
1207#endif
1208
1209/* Datafab KECF-USB / Sagatek DCS-CF / Simpletech Flashlink UCF-100 966/* Datafab KECF-USB / Sagatek DCS-CF / Simpletech Flashlink UCF-100
1210 * Only revision 1.13 tested (same for all of the above devices, 967 * Only revision 1.13 tested (same for all of the above devices,
1211 * based on the Datafab DF-UG-07 chip). Needed for US_FL_FIX_INQUIRY. 968 * based on the Datafab DF-UG-07 chip). Needed for US_FL_FIX_INQUIRY.
@@ -1409,29 +1166,6 @@ UNUSUAL_DEV( 0x0bc2, 0x3010, 0x0000, 0x0000,
1409 US_SC_DEVICE, US_PR_DEVICE, NULL, 1166 US_SC_DEVICE, US_PR_DEVICE, NULL,
1410 US_FL_SANE_SENSE ), 1167 US_FL_SANE_SENSE ),
1411 1168
1412#ifdef CONFIG_USB_STORAGE_ISD200
1413UNUSUAL_DEV( 0x0bf6, 0xa001, 0x0100, 0x0110,
1414 "ATI",
1415 "USB Cable 205",
1416 US_SC_ISD200, US_PR_BULK, isd200_Initialization,
1417 0 ),
1418#endif
1419
1420#ifdef CONFIG_USB_STORAGE_DATAFAB
1421UNUSUAL_DEV( 0x0c0b, 0xa109, 0x0000, 0xffff,
1422 "Acomdata",
1423 "CF",
1424 US_SC_SCSI, US_PR_DATAFAB, NULL,
1425 US_FL_SINGLE_LUN ),
1426#endif
1427#ifdef CONFIG_USB_STORAGE_SDDR55
1428UNUSUAL_DEV( 0x0c0b, 0xa109, 0x0000, 0xffff,
1429 "Acomdata",
1430 "SM",
1431 US_SC_SCSI, US_PR_SDDR55, NULL,
1432 US_FL_SINGLE_LUN ),
1433#endif
1434
1435UNUSUAL_DEV( 0x0d49, 0x7310, 0x0000, 0x9999, 1169UNUSUAL_DEV( 0x0d49, 0x7310, 0x0000, 0x9999,
1436 "Maxtor", 1170 "Maxtor",
1437 "USB to SATA", 1171 "USB to SATA",
@@ -1448,23 +1182,6 @@ UNUSUAL_DEV( 0x0c45, 0x1060, 0x0100, 0x0100,
1448 US_SC_DEVICE, US_PR_DEVICE, NULL, 1182 US_SC_DEVICE, US_PR_DEVICE, NULL,
1449 US_FL_SINGLE_LUN ), 1183 US_FL_SINGLE_LUN ),
1450 1184
1451/* Submitted by: Nick Sillik <n.sillik@temple.edu>
1452 * Needed for OneTouch extension to usb-storage
1453 *
1454 */
1455#ifdef CONFIG_USB_STORAGE_ONETOUCH
1456 UNUSUAL_DEV( 0x0d49, 0x7000, 0x0000, 0x9999,
1457 "Maxtor",
1458 "OneTouch External Harddrive",
1459 US_SC_DEVICE, US_PR_DEVICE, onetouch_connect_input,
1460 0),
1461 UNUSUAL_DEV( 0x0d49, 0x7010, 0x0000, 0x9999,
1462 "Maxtor",
1463 "OneTouch External Harddrive",
1464 US_SC_DEVICE, US_PR_DEVICE, onetouch_connect_input,
1465 0),
1466#endif
1467
1468/* Submitted by Joris Struyve <joris@struyve.be> */ 1185/* Submitted by Joris Struyve <joris@struyve.be> */
1469UNUSUAL_DEV( 0x0d96, 0x410a, 0x0001, 0xffff, 1186UNUSUAL_DEV( 0x0d96, 0x410a, 0x0001, 0xffff,
1470 "Medion", 1187 "Medion",
@@ -2117,14 +1834,6 @@ UNUSUAL_DEV( 0x4146, 0xba01, 0x0100, 0x0100,
2117 "Micro Mini 1GB", 1834 "Micro Mini 1GB",
2118 US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_NOT_LOCKABLE ), 1835 US_SC_DEVICE, US_PR_DEVICE, NULL, US_FL_NOT_LOCKABLE ),
2119 1836
2120#ifdef CONFIG_USB_STORAGE_SDDR55
2121UNUSUAL_DEV( 0x55aa, 0xa103, 0x0000, 0x9999,
2122 "Sandisk",
2123 "ImageMate SDDR55",
2124 US_SC_SCSI, US_PR_SDDR55, NULL,
2125 US_FL_SINGLE_LUN),
2126#endif
2127
2128/* Reported by Andrew Simmons <andrew.simmons@gmail.com> */ 1837/* Reported by Andrew Simmons <andrew.simmons@gmail.com> */
2129UNUSUAL_DEV( 0xed06, 0x4500, 0x0001, 0x0001, 1838UNUSUAL_DEV( 0xed06, 0x4500, 0x0001, 0x0001,
2130 "DataStor", 1839 "DataStor",
diff --git a/drivers/usb/storage/cypress_atacb.h b/drivers/usb/storage/unusual_freecom.h
index fbada898d56b..375867942391 100644
--- a/drivers/usb/storage/cypress_atacb.h
+++ b/drivers/usb/storage/unusual_freecom.h
@@ -1,8 +1,4 @@
1/* 1/* Unusual Devices File for the Freecom USB/IDE adaptor
2 * Support for emulating SAT (ata pass through) on devices based
3 * on the Cypress USB/ATA bridge supporting ATACB.
4 *
5 * Copyright (c) 2008 Matthieu Castet (castet.matthieu@free.fr)
6 * 2 *
7 * This program is free software; you can redistribute it and/or modify it 3 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the 4 * under the terms of the GNU General Public License as published by the
@@ -19,7 +15,12 @@
19 * 675 Mass Ave, Cambridge, MA 02139, USA. 15 * 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 16 */
21 17
22#ifndef _CYPRESS_ATACB_H_ 18#if defined(CONFIG_USB_STORAGE_FREECOM) || \
23#define _CYPRESS_ATACB_H_ 19 defined(CONFIG_USB_STORAGE_FREECOM_MODULE)
24extern void cypress_atacb_passthrough(struct scsi_cmnd*, struct us_data*); 20
25#endif 21UNUSUAL_DEV( 0x07ab, 0xfc01, 0x0000, 0x9999,
22 "Freecom",
23 "USB-IDE",
24 US_SC_QIC, US_PR_FREECOM, init_freecom, 0),
25
26#endif /* defined(CONFIG_USB_STORAGE_FREECOM) || ... */
diff --git a/drivers/usb/storage/unusual_isd200.h b/drivers/usb/storage/unusual_isd200.h
new file mode 100644
index 000000000000..0d99dde3382a
--- /dev/null
+++ b/drivers/usb/storage/unusual_isd200.h
@@ -0,0 +1,57 @@
1/* Unusual Devices File for In-System Design, Inc. ISD200 ASIC
2 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2, or (at your option) any
6 * later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18#if defined(CONFIG_USB_STORAGE_ISD200) || \
19 defined(CONFIG_USB_STORAGE_ISD200_MODULE)
20
21UNUSUAL_DEV( 0x054c, 0x002b, 0x0100, 0x0110,
22 "Sony",
23 "Portable USB Harddrive V2",
24 US_SC_ISD200, US_PR_BULK, isd200_Initialization,
25 0),
26
27UNUSUAL_DEV( 0x05ab, 0x0031, 0x0100, 0x0110,
28 "In-System",
29 "USB/IDE Bridge (ATA/ATAPI)",
30 US_SC_ISD200, US_PR_BULK, isd200_Initialization,
31 0),
32
33UNUSUAL_DEV( 0x05ab, 0x0301, 0x0100, 0x0110,
34 "In-System",
35 "Portable USB Harddrive V2",
36 US_SC_ISD200, US_PR_BULK, isd200_Initialization,
37 0),
38
39UNUSUAL_DEV( 0x05ab, 0x0351, 0x0100, 0x0110,
40 "In-System",
41 "Portable USB Harddrive V2",
42 US_SC_ISD200, US_PR_BULK, isd200_Initialization,
43 0),
44
45UNUSUAL_DEV( 0x05ab, 0x5701, 0x0100, 0x0110,
46 "In-System",
47 "USB Storage Adapter V2",
48 US_SC_ISD200, US_PR_BULK, isd200_Initialization,
49 0),
50
51UNUSUAL_DEV( 0x0bf6, 0xa001, 0x0100, 0x0110,
52 "ATI",
53 "USB Cable 205",
54 US_SC_ISD200, US_PR_BULK, isd200_Initialization,
55 0),
56
57#endif /* defined(CONFIG_USB_STORAGE_ISD200) || ... */
diff --git a/drivers/usb/storage/sddr55.h b/drivers/usb/storage/unusual_jumpshot.h
index a815a0470c84..2e549b1c2c62 100644
--- a/drivers/usb/storage/sddr55.h
+++ b/drivers/usb/storage/unusual_jumpshot.h
@@ -1,10 +1,4 @@
1/* Driver for SanDisk SDDR-55 SmartMedia reader 1/* Unusual Devices File for the Lexar "Jumpshot" Compact Flash reader
2 * Header File
3 *
4 * Current development and maintenance by:
5 * (c) 2002 Simon Munton
6 *
7 * See sddr55.c for more explanation
8 * 2 *
9 * This program is free software; you can redistribute it and/or modify it 3 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the 4 * under the terms of the GNU General Public License as published by the
@@ -21,12 +15,13 @@
21 * 675 Mass Ave, Cambridge, MA 02139, USA. 15 * 675 Mass Ave, Cambridge, MA 02139, USA.
22 */ 16 */
23 17
24#ifndef _USB_SHUTTLE_EUSB_SDDR55_H 18#if defined(CONFIG_USB_STORAGE_JUMPSHOT) || \
25#define _USB_SHUTTLE_EUSB_SDDR55_H 19 defined(CONFIG_USB_STORAGE_JUMPSHOT_MODULE)
26
27/* Sandisk SDDR-55 stuff */
28 20
29extern int sddr55_transport(struct scsi_cmnd *srb, struct us_data *us); 21UNUSUAL_DEV( 0x05dc, 0x0001, 0x0000, 0x0001,
30extern int sddr55_reset(struct us_data *us); 22 "Lexar",
23 "Jumpshot USB CF Reader",
24 US_SC_SCSI, US_PR_JUMPSHOT, NULL,
25 US_FL_NEED_OVERRIDE),
31 26
32#endif 27#endif /* defined(CONFIG_USB_STORAGE_JUMPSHOT) || ... */
diff --git a/drivers/usb/storage/isd200.h b/drivers/usb/storage/unusual_karma.h
index 0a35f4fa78f8..12ae3a03e802 100644
--- a/drivers/usb/storage/isd200.h
+++ b/drivers/usb/storage/unusual_karma.h
@@ -1,11 +1,4 @@
1/* Header File for In-System Design, Inc. ISD200 ASIC 1/* Unusual Devices File for the Rio Karma
2 *
3 * First release
4 *
5 * Current development and maintenance by:
6 * (c) 2000 In-System Design, Inc. (support@in-system.com)
7 *
8 * See isd200.c for more information.
9 * 2 *
10 * This program is free software; you can redistribute it and/or modify it 3 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the 4 * under the terms of the GNU General Public License as published by the
@@ -22,10 +15,12 @@
22 * 675 Mass Ave, Cambridge, MA 02139, USA. 15 * 675 Mass Ave, Cambridge, MA 02139, USA.
23 */ 16 */
24 17
25#ifndef _USB_ISD200_H 18#if defined(CONFIG_USB_STORAGE_KARMA) || \
26#define _USB_ISD200_H 19 defined(CONFIG_USB_STORAGE_KARMA_MODULE)
27 20
28extern void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us); 21UNUSUAL_DEV( 0x045a, 0x5210, 0x0101, 0x0101,
29extern int isd200_Initialization(struct us_data *us); 22 "Rio",
23 "Rio Karma",
24 US_SC_SCSI, US_PR_KARMA, rio_karma_init, 0),
30 25
31#endif 26#endif /* defined(CONFIG_USB_STORAGE_KARMA) || ... */
diff --git a/drivers/usb/storage/unusual_onetouch.h b/drivers/usb/storage/unusual_onetouch.h
new file mode 100644
index 000000000000..bd9306b637df
--- /dev/null
+++ b/drivers/usb/storage/unusual_onetouch.h
@@ -0,0 +1,36 @@
1/* Unusual Devices File for the Maxtor OneTouch USB hard drive's button
2 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2, or (at your option) any
6 * later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18#if defined(CONFIG_USB_STORAGE_ONETOUCH) || \
19 defined(CONFIG_USB_STORAGE_ONETOUCH_MODULE)
20
21/* Submitted by: Nick Sillik <n.sillik@temple.edu>
22 * Needed for OneTouch extension to usb-storage
23 */
24UNUSUAL_DEV( 0x0d49, 0x7000, 0x0000, 0x9999,
25 "Maxtor",
26 "OneTouch External Harddrive",
27 US_SC_DEVICE, US_PR_DEVICE, onetouch_connect_input,
28 0),
29
30UNUSUAL_DEV( 0x0d49, 0x7010, 0x0000, 0x9999,
31 "Maxtor",
32 "OneTouch External Harddrive",
33 US_SC_DEVICE, US_PR_DEVICE, onetouch_connect_input,
34 0),
35
36#endif /* defined(CONFIG_USB_STORAGE_ONETOUCH) || ... */
diff --git a/drivers/usb/storage/unusual_sddr09.h b/drivers/usb/storage/unusual_sddr09.h
new file mode 100644
index 000000000000..50cab511a4d7
--- /dev/null
+++ b/drivers/usb/storage/unusual_sddr09.h
@@ -0,0 +1,56 @@
1/* Unusual Devices File for SanDisk SDDR-09 SmartMedia reader
2 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2, or (at your option) any
6 * later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18#if defined(CONFIG_USB_STORAGE_SDDR09) || \
19 defined(CONFIG_USB_STORAGE_SDDR09_MODULE)
20
21UNUSUAL_DEV( 0x0436, 0x0005, 0x0100, 0x0100,
22 "Microtech",
23 "CameraMate (DPCM_USB)",
24 US_SC_SCSI, US_PR_DPCM_USB, NULL, 0),
25
26UNUSUAL_DEV( 0x04e6, 0x0003, 0x0000, 0x9999,
27 "Sandisk",
28 "ImageMate SDDR09",
29 US_SC_SCSI, US_PR_EUSB_SDDR09, usb_stor_sddr09_init,
30 0),
31
32/* This entry is from Andries.Brouwer@cwi.nl */
33UNUSUAL_DEV( 0x04e6, 0x0005, 0x0100, 0x0208,
34 "SCM Microsystems",
35 "eUSB SmartMedia / CompactFlash Adapter",
36 US_SC_SCSI, US_PR_DPCM_USB, usb_stor_sddr09_dpcm_init,
37 0),
38
39UNUSUAL_DEV( 0x066b, 0x0105, 0x0100, 0x0100,
40 "Olympus",
41 "Camedia MAUSB-2",
42 US_SC_SCSI, US_PR_EUSB_SDDR09, usb_stor_sddr09_init,
43 0),
44
45UNUSUAL_DEV( 0x0781, 0x0200, 0x0000, 0x9999,
46 "Sandisk",
47 "ImageMate SDDR-09",
48 US_SC_SCSI, US_PR_EUSB_SDDR09, usb_stor_sddr09_init,
49 0),
50
51UNUSUAL_DEV( 0x07af, 0x0006, 0x0100, 0x0100,
52 "Microtech",
53 "CameraMate (DPCM_USB)",
54 US_SC_SCSI, US_PR_DPCM_USB, NULL, 0),
55
56#endif /* defined(CONFIG_USB_STORAGE_SDDR09) || ... */
diff --git a/drivers/usb/storage/unusual_sddr55.h b/drivers/usb/storage/unusual_sddr55.h
new file mode 100644
index 000000000000..ae81ef7a1cfd
--- /dev/null
+++ b/drivers/usb/storage/unusual_sddr55.h
@@ -0,0 +1,44 @@
1/* Unusual Devices File for SanDisk SDDR-55 SmartMedia reader
2 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2, or (at your option) any
6 * later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18#if defined(CONFIG_USB_STORAGE_SDDR55) || \
19 defined(CONFIG_USB_STORAGE_SDDR55_MODULE)
20
21/* Contributed by Peter Waechtler */
22UNUSUAL_DEV( 0x07c4, 0xa103, 0x0000, 0x9999,
23 "Datafab",
24 "MDSM-B reader",
25 US_SC_SCSI, US_PR_SDDR55, NULL,
26 US_FL_FIX_INQUIRY),
27
28/* SM part - aeb <Andries.Brouwer@cwi.nl> */
29UNUSUAL_DEV( 0x07c4, 0xa109, 0x0000, 0xffff,
30 "Datafab Systems, Inc.",
31 "USB to CF + SM Combo (LC1)",
32 US_SC_SCSI, US_PR_SDDR55, NULL, 0),
33
34UNUSUAL_DEV( 0x0c0b, 0xa109, 0x0000, 0xffff,
35 "Acomdata",
36 "SM",
37 US_SC_SCSI, US_PR_SDDR55, NULL, 0),
38
39UNUSUAL_DEV( 0x55aa, 0xa103, 0x0000, 0x9999,
40 "Sandisk",
41 "ImageMate SDDR55",
42 US_SC_SCSI, US_PR_SDDR55, NULL, 0),
43
44#endif /* defined(CONFIG_USB_STORAGE_SDDR55) || ... */
diff --git a/drivers/usb/storage/unusual_usbat.h b/drivers/usb/storage/unusual_usbat.h
new file mode 100644
index 000000000000..80e869f10180
--- /dev/null
+++ b/drivers/usb/storage/unusual_usbat.h
@@ -0,0 +1,43 @@
1/* Unusual Devices File for SCM Microsystems (a.k.a. Shuttle) USB-ATAPI cable
2 *
3 * This program is free software; you can redistribute it and/or modify it
4 * under the terms of the GNU General Public License as published by the
5 * Free Software Foundation; either version 2, or (at your option) any
6 * later version.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 675 Mass Ave, Cambridge, MA 02139, USA.
16 */
17
18#if defined(CONFIG_USB_STORAGE_USBAT) || \
19 defined(CONFIG_USB_STORAGE_USBAT_MODULE)
20
21UNUSUAL_DEV( 0x03f0, 0x0207, 0x0001, 0x0001,
22 "HP",
23 "CD-Writer+ 8200e",
24 US_SC_8070, US_PR_USBAT, init_usbat_cd, 0),
25
26UNUSUAL_DEV( 0x03f0, 0x0307, 0x0001, 0x0001,
27 "HP",
28 "CD-Writer+ CD-4e",
29 US_SC_8070, US_PR_USBAT, init_usbat_cd, 0),
30
31UNUSUAL_DEV( 0x04e6, 0x1010, 0x0000, 0x9999,
32 "Shuttle/SCM",
33 "USBAT-02",
34 US_SC_SCSI, US_PR_USBAT, init_usbat_flash,
35 US_FL_SINGLE_LUN),
36
37UNUSUAL_DEV( 0x0781, 0x0005, 0x0005, 0x0005,
38 "Sandisk",
39 "ImageMate SDDR-05b",
40 US_SC_SCSI, US_PR_USBAT, init_usbat_flash,
41 US_FL_SINGLE_LUN),
42
43#endif /* defined(CONFIG_USB_STORAGE_USBAT) || ... */
diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
index 4becf495ca2d..8060b85fe1a3 100644
--- a/drivers/usb/storage/usb.c
+++ b/drivers/usb/storage/usb.c
@@ -5,7 +5,7 @@
5 * 5 *
6 * Developed with the assistance of: 6 * Developed with the assistance of:
7 * (c) 2000 David L. Brown, Jr. (usb-storage@davidb.org) 7 * (c) 2000 David L. Brown, Jr. (usb-storage@davidb.org)
8 * (c) 2003 Alan Stern (stern@rowland.harvard.edu) 8 * (c) 2003-2009 Alan Stern (stern@rowland.harvard.edu)
9 * 9 *
10 * Initial work by: 10 * Initial work by:
11 * (c) 1999 Michael Gee (michael@linuxspecific.com) 11 * (c) 1999 Michael Gee (michael@linuxspecific.com)
@@ -66,39 +66,6 @@
66#include "debug.h" 66#include "debug.h"
67#include "initializers.h" 67#include "initializers.h"
68 68
69#ifdef CONFIG_USB_STORAGE_USBAT
70#include "shuttle_usbat.h"
71#endif
72#ifdef CONFIG_USB_STORAGE_SDDR09
73#include "sddr09.h"
74#endif
75#ifdef CONFIG_USB_STORAGE_SDDR55
76#include "sddr55.h"
77#endif
78#ifdef CONFIG_USB_STORAGE_FREECOM
79#include "freecom.h"
80#endif
81#ifdef CONFIG_USB_STORAGE_ISD200
82#include "isd200.h"
83#endif
84#ifdef CONFIG_USB_STORAGE_DATAFAB
85#include "datafab.h"
86#endif
87#ifdef CONFIG_USB_STORAGE_JUMPSHOT
88#include "jumpshot.h"
89#endif
90#ifdef CONFIG_USB_STORAGE_ONETOUCH
91#include "onetouch.h"
92#endif
93#ifdef CONFIG_USB_STORAGE_ALAUDA
94#include "alauda.h"
95#endif
96#ifdef CONFIG_USB_STORAGE_KARMA
97#include "karma.h"
98#endif
99#ifdef CONFIG_USB_STORAGE_CYPRESS_ATACB
100#include "cypress_atacb.h"
101#endif
102#include "sierra_ms.h" 69#include "sierra_ms.h"
103#include "option_ms.h" 70#include "option_ms.h"
104 71
@@ -118,36 +85,8 @@ MODULE_PARM_DESC(quirks, "supplemental list of device IDs and their quirks");
118 85
119/* 86/*
120 * The entries in this table correspond, line for line, 87 * The entries in this table correspond, line for line,
121 * with the entries of us_unusual_dev_list[]. 88 * with the entries in usb_storage_usb_ids[], defined in usual-tables.c.
122 */ 89 */
123#ifndef CONFIG_USB_LIBUSUAL
124
125#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
126 vendorName, productName,useProtocol, useTransport, \
127 initFunction, flags) \
128{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin,bcdDeviceMax), \
129 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
130
131#define COMPLIANT_DEV UNUSUAL_DEV
132
133#define USUAL_DEV(useProto, useTrans, useType) \
134{ USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans), \
135 .driver_info = (USB_US_TYPE_STOR<<24) }
136
137static struct usb_device_id storage_usb_ids [] = {
138
139# include "unusual_devs.h"
140#undef UNUSUAL_DEV
141#undef COMPLIANT_DEV
142#undef USUAL_DEV
143 /* Terminating entry */
144 { }
145};
146
147MODULE_DEVICE_TABLE (usb, storage_usb_ids);
148#endif /* CONFIG_USB_LIBUSUAL */
149
150/* This is the list of devices we recognize, along with their flag data */
151 90
152/* The vendor name should be kept at eight characters or less, and 91/* The vendor name should be kept at eight characters or less, and
153 * the product name should be kept at 16 characters or less. If a device 92 * the product name should be kept at 16 characters or less. If a device
@@ -179,18 +118,17 @@ MODULE_DEVICE_TABLE (usb, storage_usb_ids);
179 118
180static struct us_unusual_dev us_unusual_dev_list[] = { 119static struct us_unusual_dev us_unusual_dev_list[] = {
181# include "unusual_devs.h" 120# include "unusual_devs.h"
182# undef UNUSUAL_DEV 121 { } /* Terminating entry */
183# undef COMPLIANT_DEV
184# undef USUAL_DEV
185
186 /* Terminating entry */
187 { NULL }
188}; 122};
189 123
124#undef UNUSUAL_DEV
125#undef COMPLIANT_DEV
126#undef USUAL_DEV
127
190 128
191#ifdef CONFIG_PM /* Minimal support for suspend and resume */ 129#ifdef CONFIG_PM /* Minimal support for suspend and resume */
192 130
193static int storage_suspend(struct usb_interface *iface, pm_message_t message) 131int usb_stor_suspend(struct usb_interface *iface, pm_message_t message)
194{ 132{
195 struct us_data *us = usb_get_intfdata(iface); 133 struct us_data *us = usb_get_intfdata(iface);
196 134
@@ -207,8 +145,9 @@ static int storage_suspend(struct usb_interface *iface, pm_message_t message)
207 mutex_unlock(&us->dev_mutex); 145 mutex_unlock(&us->dev_mutex);
208 return 0; 146 return 0;
209} 147}
148EXPORT_SYMBOL_GPL(usb_stor_suspend);
210 149
211static int storage_resume(struct usb_interface *iface) 150int usb_stor_resume(struct usb_interface *iface)
212{ 151{
213 struct us_data *us = usb_get_intfdata(iface); 152 struct us_data *us = usb_get_intfdata(iface);
214 153
@@ -221,8 +160,9 @@ static int storage_resume(struct usb_interface *iface)
221 mutex_unlock(&us->dev_mutex); 160 mutex_unlock(&us->dev_mutex);
222 return 0; 161 return 0;
223} 162}
163EXPORT_SYMBOL_GPL(usb_stor_resume);
224 164
225static int storage_reset_resume(struct usb_interface *iface) 165int usb_stor_reset_resume(struct usb_interface *iface)
226{ 166{
227 struct us_data *us = usb_get_intfdata(iface); 167 struct us_data *us = usb_get_intfdata(iface);
228 168
@@ -235,6 +175,7 @@ static int storage_reset_resume(struct usb_interface *iface)
235 * the device */ 175 * the device */
236 return 0; 176 return 0;
237} 177}
178EXPORT_SYMBOL_GPL(usb_stor_reset_resume);
238 179
239#endif /* CONFIG_PM */ 180#endif /* CONFIG_PM */
240 181
@@ -243,7 +184,7 @@ static int storage_reset_resume(struct usb_interface *iface)
243 * a USB port reset, whether from this driver or a different one. 184 * a USB port reset, whether from this driver or a different one.
244 */ 185 */
245 186
246static int storage_pre_reset(struct usb_interface *iface) 187int usb_stor_pre_reset(struct usb_interface *iface)
247{ 188{
248 struct us_data *us = usb_get_intfdata(iface); 189 struct us_data *us = usb_get_intfdata(iface);
249 190
@@ -253,8 +194,9 @@ static int storage_pre_reset(struct usb_interface *iface)
253 mutex_lock(&us->dev_mutex); 194 mutex_lock(&us->dev_mutex);
254 return 0; 195 return 0;
255} 196}
197EXPORT_SYMBOL_GPL(usb_stor_pre_reset);
256 198
257static int storage_post_reset(struct usb_interface *iface) 199int usb_stor_post_reset(struct usb_interface *iface)
258{ 200{
259 struct us_data *us = usb_get_intfdata(iface); 201 struct us_data *us = usb_get_intfdata(iface);
260 202
@@ -269,6 +211,7 @@ static int storage_post_reset(struct usb_interface *iface)
269 mutex_unlock(&us->dev_mutex); 211 mutex_unlock(&us->dev_mutex);
270 return 0; 212 return 0;
271} 213}
214EXPORT_SYMBOL_GPL(usb_stor_post_reset);
272 215
273/* 216/*
274 * fill_inquiry_response takes an unsigned char array (which must 217 * fill_inquiry_response takes an unsigned char array (which must
@@ -311,6 +254,7 @@ void fill_inquiry_response(struct us_data *us, unsigned char *data,
311 254
312 usb_stor_set_xfer_buf(data, data_len, us->srb); 255 usb_stor_set_xfer_buf(data, data_len, us->srb);
313} 256}
257EXPORT_SYMBOL_GPL(fill_inquiry_response);
314 258
315static int usb_stor_control_thread(void * __us) 259static int usb_stor_control_thread(void * __us)
316{ 260{
@@ -551,20 +495,13 @@ static void adjust_quirks(struct us_data *us)
551 vid, pid, f); 495 vid, pid, f);
552} 496}
553 497
554/* Find an unusual_dev descriptor (always succeeds in the current code) */
555static struct us_unusual_dev *find_unusual(const struct usb_device_id *id)
556{
557 const int id_index = id - storage_usb_ids;
558 return &us_unusual_dev_list[id_index];
559}
560
561/* Get the unusual_devs entries and the string descriptors */ 498/* Get the unusual_devs entries and the string descriptors */
562static int get_device_info(struct us_data *us, const struct usb_device_id *id) 499static int get_device_info(struct us_data *us, const struct usb_device_id *id,
500 struct us_unusual_dev *unusual_dev)
563{ 501{
564 struct usb_device *dev = us->pusb_dev; 502 struct usb_device *dev = us->pusb_dev;
565 struct usb_interface_descriptor *idesc = 503 struct usb_interface_descriptor *idesc =
566 &us->pusb_intf->cur_altsetting->desc; 504 &us->pusb_intf->cur_altsetting->desc;
567 struct us_unusual_dev *unusual_dev = find_unusual(id);
568 505
569 /* Store the entries */ 506 /* Store the entries */
570 us->unusual_dev = unusual_dev; 507 us->unusual_dev = unusual_dev;
@@ -629,7 +566,7 @@ static int get_device_info(struct us_data *us, const struct usb_device_id *id)
629} 566}
630 567
631/* Get the transport settings */ 568/* Get the transport settings */
632static int get_transport(struct us_data *us) 569static void get_transport(struct us_data *us)
633{ 570{
634 switch (us->protocol) { 571 switch (us->protocol) {
635 case US_PR_CB: 572 case US_PR_CB:
@@ -651,100 +588,11 @@ static int get_transport(struct us_data *us)
651 us->transport = usb_stor_Bulk_transport; 588 us->transport = usb_stor_Bulk_transport;
652 us->transport_reset = usb_stor_Bulk_reset; 589 us->transport_reset = usb_stor_Bulk_reset;
653 break; 590 break;
654
655#ifdef CONFIG_USB_STORAGE_USBAT
656 case US_PR_USBAT:
657 us->transport_name = "Shuttle USBAT";
658 us->transport = usbat_transport;
659 us->transport_reset = usb_stor_CB_reset;
660 us->max_lun = 1;
661 break;
662#endif
663
664#ifdef CONFIG_USB_STORAGE_SDDR09
665 case US_PR_EUSB_SDDR09:
666 us->transport_name = "EUSB/SDDR09";
667 us->transport = sddr09_transport;
668 us->transport_reset = usb_stor_CB_reset;
669 us->max_lun = 0;
670 break;
671#endif
672
673#ifdef CONFIG_USB_STORAGE_SDDR55
674 case US_PR_SDDR55:
675 us->transport_name = "SDDR55";
676 us->transport = sddr55_transport;
677 us->transport_reset = sddr55_reset;
678 us->max_lun = 0;
679 break;
680#endif
681
682#ifdef CONFIG_USB_STORAGE_DPCM
683 case US_PR_DPCM_USB:
684 us->transport_name = "Control/Bulk-EUSB/SDDR09";
685 us->transport = dpcm_transport;
686 us->transport_reset = usb_stor_CB_reset;
687 us->max_lun = 1;
688 break;
689#endif
690
691#ifdef CONFIG_USB_STORAGE_FREECOM
692 case US_PR_FREECOM:
693 us->transport_name = "Freecom";
694 us->transport = freecom_transport;
695 us->transport_reset = usb_stor_freecom_reset;
696 us->max_lun = 0;
697 break;
698#endif
699
700#ifdef CONFIG_USB_STORAGE_DATAFAB
701 case US_PR_DATAFAB:
702 us->transport_name = "Datafab Bulk-Only";
703 us->transport = datafab_transport;
704 us->transport_reset = usb_stor_Bulk_reset;
705 us->max_lun = 1;
706 break;
707#endif
708
709#ifdef CONFIG_USB_STORAGE_JUMPSHOT
710 case US_PR_JUMPSHOT:
711 us->transport_name = "Lexar Jumpshot Control/Bulk";
712 us->transport = jumpshot_transport;
713 us->transport_reset = usb_stor_Bulk_reset;
714 us->max_lun = 1;
715 break;
716#endif
717
718#ifdef CONFIG_USB_STORAGE_ALAUDA
719 case US_PR_ALAUDA:
720 us->transport_name = "Alauda Control/Bulk";
721 us->transport = alauda_transport;
722 us->transport_reset = usb_stor_Bulk_reset;
723 us->max_lun = 1;
724 break;
725#endif
726
727#ifdef CONFIG_USB_STORAGE_KARMA
728 case US_PR_KARMA:
729 us->transport_name = "Rio Karma/Bulk";
730 us->transport = rio_karma_transport;
731 us->transport_reset = usb_stor_Bulk_reset;
732 break;
733#endif
734
735 default:
736 return -EIO;
737 } 591 }
738 US_DEBUGP("Transport: %s\n", us->transport_name);
739
740 /* fix for single-lun devices */
741 if (us->fflags & US_FL_SINGLE_LUN)
742 us->max_lun = 0;
743 return 0;
744} 592}
745 593
746/* Get the protocol settings */ 594/* Get the protocol settings */
747static int get_protocol(struct us_data *us) 595static void get_protocol(struct us_data *us)
748{ 596{
749 switch (us->subclass) { 597 switch (us->subclass) {
750 case US_SC_RBC: 598 case US_SC_RBC:
@@ -779,26 +627,7 @@ static int get_protocol(struct us_data *us)
779 us->protocol_name = "Uniform Floppy Interface (UFI)"; 627 us->protocol_name = "Uniform Floppy Interface (UFI)";
780 us->proto_handler = usb_stor_ufi_command; 628 us->proto_handler = usb_stor_ufi_command;
781 break; 629 break;
782
783#ifdef CONFIG_USB_STORAGE_ISD200
784 case US_SC_ISD200:
785 us->protocol_name = "ISD200 ATA/ATAPI";
786 us->proto_handler = isd200_ata_command;
787 break;
788#endif
789
790#ifdef CONFIG_USB_STORAGE_CYPRESS_ATACB
791 case US_SC_CYP_ATACB:
792 us->protocol_name = "Transparent SCSI with Cypress ATACB";
793 us->proto_handler = cypress_atacb_passthrough;
794 break;
795#endif
796
797 default:
798 return -EIO;
799 } 630 }
800 US_DEBUGP("Protocol: %s\n", us->protocol_name);
801 return 0;
802} 631}
803 632
804/* Get the pipe settings */ 633/* Get the pipe settings */
@@ -846,12 +675,12 @@ static int get_pipes(struct us_data *us)
846 us->send_ctrl_pipe = usb_sndctrlpipe(us->pusb_dev, 0); 675 us->send_ctrl_pipe = usb_sndctrlpipe(us->pusb_dev, 0);
847 us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0); 676 us->recv_ctrl_pipe = usb_rcvctrlpipe(us->pusb_dev, 0);
848 us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev, 677 us->send_bulk_pipe = usb_sndbulkpipe(us->pusb_dev,
849 ep_out->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 678 usb_endpoint_num(ep_out));
850 us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev, 679 us->recv_bulk_pipe = usb_rcvbulkpipe(us->pusb_dev,
851 ep_in->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 680 usb_endpoint_num(ep_in));
852 if (ep_int) { 681 if (ep_int) {
853 us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev, 682 us->recv_intr_pipe = usb_rcvintpipe(us->pusb_dev,
854 ep_int->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK); 683 usb_endpoint_num(ep_int));
855 us->ep_bInterval = ep_int->bInterval; 684 us->ep_bInterval = ep_int->bInterval;
856 } 685 }
857 return 0; 686 return 0;
@@ -1012,17 +841,15 @@ static int usb_stor_scan_thread(void * __us)
1012} 841}
1013 842
1014 843
1015/* Probe to see if we can drive a newly-connected USB device */ 844/* First part of general USB mass-storage probing */
1016static int storage_probe(struct usb_interface *intf, 845int usb_stor_probe1(struct us_data **pus,
1017 const struct usb_device_id *id) 846 struct usb_interface *intf,
847 const struct usb_device_id *id,
848 struct us_unusual_dev *unusual_dev)
1018{ 849{
1019 struct Scsi_Host *host; 850 struct Scsi_Host *host;
1020 struct us_data *us; 851 struct us_data *us;
1021 int result; 852 int result;
1022 struct task_struct *th;
1023
1024 if (usb_usual_check_type(id, USB_US_TYPE_STOR))
1025 return -ENXIO;
1026 853
1027 US_DEBUGP("USB Mass Storage device detected\n"); 854 US_DEBUGP("USB Mass Storage device detected\n");
1028 855
@@ -1041,7 +868,7 @@ static int storage_probe(struct usb_interface *intf,
1041 * Allow 16-byte CDBs and thus > 2TB 868 * Allow 16-byte CDBs and thus > 2TB
1042 */ 869 */
1043 host->max_cmd_len = 16; 870 host->max_cmd_len = 16;
1044 us = host_to_us(host); 871 *pus = us = host_to_us(host);
1045 memset(us, 0, sizeof(struct us_data)); 872 memset(us, 0, sizeof(struct us_data));
1046 mutex_init(&(us->dev_mutex)); 873 mutex_init(&(us->dev_mutex));
1047 init_completion(&us->cmnd_ready); 874 init_completion(&us->cmnd_ready);
@@ -1054,24 +881,46 @@ static int storage_probe(struct usb_interface *intf,
1054 if (result) 881 if (result)
1055 goto BadDevice; 882 goto BadDevice;
1056 883
1057 /* 884 /* Get the unusual_devs entries and the descriptors */
1058 * Get the unusual_devs entries and the descriptors 885 result = get_device_info(us, id, unusual_dev);
1059 *
1060 * id_index is calculated in the declaration to be the index number
1061 * of the match from the usb_device_id table, so we can find the
1062 * corresponding entry in the private table.
1063 */
1064 result = get_device_info(us, id);
1065 if (result) 886 if (result)
1066 goto BadDevice; 887 goto BadDevice;
1067 888
1068 /* Get the transport, protocol, and pipe settings */ 889 /* Get standard transport and protocol settings */
1069 result = get_transport(us); 890 get_transport(us);
1070 if (result) 891 get_protocol(us);
1071 goto BadDevice; 892
1072 result = get_protocol(us); 893 /* Give the caller a chance to fill in specialized transport
1073 if (result) 894 * or protocol settings.
895 */
896 return 0;
897
898BadDevice:
899 US_DEBUGP("storage_probe() failed\n");
900 release_everything(us);
901 return result;
902}
903EXPORT_SYMBOL_GPL(usb_stor_probe1);
904
905/* Second part of general USB mass-storage probing */
906int usb_stor_probe2(struct us_data *us)
907{
908 struct task_struct *th;
909 int result;
910
911 /* Make sure the transport and protocol have both been set */
912 if (!us->transport || !us->proto_handler) {
913 result = -ENXIO;
1074 goto BadDevice; 914 goto BadDevice;
915 }
916 US_DEBUGP("Transport: %s\n", us->transport_name);
917 US_DEBUGP("Protocol: %s\n", us->protocol_name);
918
919 /* fix for single-lun devices */
920 if (us->fflags & US_FL_SINGLE_LUN)
921 us->max_lun = 0;
922
923 /* Find the endpoints and calculate pipe values */
1075 result = get_pipes(us); 924 result = get_pipes(us);
1076 if (result) 925 if (result)
1077 goto BadDevice; 926 goto BadDevice;
@@ -1080,7 +929,7 @@ static int storage_probe(struct usb_interface *intf,
1080 result = usb_stor_acquire_resources(us); 929 result = usb_stor_acquire_resources(us);
1081 if (result) 930 if (result)
1082 goto BadDevice; 931 goto BadDevice;
1083 result = scsi_add_host(host, &intf->dev); 932 result = scsi_add_host(us_to_host(us), &us->pusb_intf->dev);
1084 if (result) { 933 if (result) {
1085 printk(KERN_WARNING USB_STORAGE 934 printk(KERN_WARNING USB_STORAGE
1086 "Unable to add the scsi host\n"); 935 "Unable to add the scsi host\n");
@@ -1108,9 +957,10 @@ BadDevice:
1108 release_everything(us); 957 release_everything(us);
1109 return result; 958 return result;
1110} 959}
960EXPORT_SYMBOL_GPL(usb_stor_probe2);
1111 961
1112/* Handle a disconnect event from the USB core */ 962/* Handle a USB mass-storage disconnect */
1113static void storage_disconnect(struct usb_interface *intf) 963void usb_stor_disconnect(struct usb_interface *intf)
1114{ 964{
1115 struct us_data *us = usb_get_intfdata(intf); 965 struct us_data *us = usb_get_intfdata(intf);
1116 966
@@ -1118,6 +968,42 @@ static void storage_disconnect(struct usb_interface *intf)
1118 quiesce_and_remove_host(us); 968 quiesce_and_remove_host(us);
1119 release_everything(us); 969 release_everything(us);
1120} 970}
971EXPORT_SYMBOL_GPL(usb_stor_disconnect);
972
973/* The main probe routine for standard devices */
974static int storage_probe(struct usb_interface *intf,
975 const struct usb_device_id *id)
976{
977 struct us_data *us;
978 int result;
979
980 /*
981 * If libusual is configured, let it decide whether a standard
982 * device should be handled by usb-storage or by ub.
983 * If the device isn't standard (is handled by a subdriver
984 * module) then don't accept it.
985 */
986 if (usb_usual_check_type(id, USB_US_TYPE_STOR) ||
987 usb_usual_ignore_device(intf))
988 return -ENXIO;
989
990 /*
991 * Call the general probe procedures.
992 *
993 * The unusual_dev_list array is parallel to the usb_storage_usb_ids
994 * table, so we use the index of the id entry to find the
995 * corresponding unusual_devs entry.
996 */
997 result = usb_stor_probe1(&us, intf, id,
998 (id - usb_storage_usb_ids) + us_unusual_dev_list);
999 if (result)
1000 return result;
1001
1002 /* No special transport or protocol settings in the main module */
1003
1004 result = usb_stor_probe2(us);
1005 return result;
1006}
1121 1007
1122/*********************************************************************** 1008/***********************************************************************
1123 * Initialization and registration 1009 * Initialization and registration
@@ -1126,15 +1012,13 @@ static void storage_disconnect(struct usb_interface *intf)
1126static struct usb_driver usb_storage_driver = { 1012static struct usb_driver usb_storage_driver = {
1127 .name = "usb-storage", 1013 .name = "usb-storage",
1128 .probe = storage_probe, 1014 .probe = storage_probe,
1129 .disconnect = storage_disconnect, 1015 .disconnect = usb_stor_disconnect,
1130#ifdef CONFIG_PM 1016 .suspend = usb_stor_suspend,
1131 .suspend = storage_suspend, 1017 .resume = usb_stor_resume,
1132 .resume = storage_resume, 1018 .reset_resume = usb_stor_reset_resume,
1133 .reset_resume = storage_reset_resume, 1019 .pre_reset = usb_stor_pre_reset,
1134#endif 1020 .post_reset = usb_stor_post_reset,
1135 .pre_reset = storage_pre_reset, 1021 .id_table = usb_storage_usb_ids,
1136 .post_reset = storage_post_reset,
1137 .id_table = storage_usb_ids,
1138 .soft_unbind = 1, 1022 .soft_unbind = 1,
1139}; 1023};
1140 1024
diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
index 65e674e4be99..2609efb2bd7e 100644
--- a/drivers/usb/storage/usb.h
+++ b/drivers/usb/storage/usb.h
@@ -177,4 +177,25 @@ extern void fill_inquiry_response(struct us_data *us,
177#define scsi_unlock(host) spin_unlock_irq(host->host_lock) 177#define scsi_unlock(host) spin_unlock_irq(host->host_lock)
178#define scsi_lock(host) spin_lock_irq(host->host_lock) 178#define scsi_lock(host) spin_lock_irq(host->host_lock)
179 179
180/* General routines provided by the usb-storage standard core */
181#ifdef CONFIG_PM
182extern int usb_stor_suspend(struct usb_interface *iface, pm_message_t message);
183extern int usb_stor_resume(struct usb_interface *iface);
184extern int usb_stor_reset_resume(struct usb_interface *iface);
185#else
186#define usb_stor_suspend NULL
187#define usb_stor_resume NULL
188#define usb_stor_reset_resume NULL
189#endif
190
191extern int usb_stor_pre_reset(struct usb_interface *iface);
192extern int usb_stor_post_reset(struct usb_interface *iface);
193
194extern int usb_stor_probe1(struct us_data **pus,
195 struct usb_interface *intf,
196 const struct usb_device_id *id,
197 struct us_unusual_dev *unusual_dev);
198extern int usb_stor_probe2(struct us_data *us);
199extern void usb_stor_disconnect(struct usb_interface *intf);
200
180#endif 201#endif
diff --git a/drivers/usb/storage/usual-tables.c b/drivers/usb/storage/usual-tables.c
new file mode 100644
index 000000000000..468bde7d1971
--- /dev/null
+++ b/drivers/usb/storage/usual-tables.c
@@ -0,0 +1,116 @@
1/* Driver for USB Mass Storage devices
2 * Usual Tables File for usb-storage and libusual
3 *
4 * Copyright (C) 2009 Alan Stern (stern@rowland.harvard.edu)
5 *
6 * Please see http://www.one-eyed-alien.net/~mdharm/linux-usb for more
7 * information about this driver.
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/usb.h>
27#include <linux/usb_usual.h>
28
29
30/*
31 * The table of devices
32 */
33#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
34 vendorName, productName, useProtocol, useTransport, \
35 initFunction, flags) \
36{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
37 .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
38
39#define COMPLIANT_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
40 vendorName, productName, useProtocol, useTransport, \
41 initFunction, flags) \
42{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
43 .driver_info = (flags) }
44
45#define USUAL_DEV(useProto, useTrans, useType) \
46{ USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans), \
47 .driver_info = ((useType)<<24) }
48
49struct usb_device_id usb_storage_usb_ids[] = {
50# include "unusual_devs.h"
51 { } /* Terminating entry */
52};
53EXPORT_SYMBOL_GPL(usb_storage_usb_ids);
54
55MODULE_DEVICE_TABLE(usb, usb_storage_usb_ids);
56
57#undef UNUSUAL_DEV
58#undef COMPLIANT_DEV
59#undef USUAL_DEV
60
61
62/*
63 * The table of devices to ignore
64 */
65struct ignore_entry {
66 u16 vid, pid, bcdmin, bcdmax;
67};
68
69#define UNUSUAL_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
70 vendorName, productName, useProtocol, useTransport, \
71 initFunction, flags) \
72{ \
73 .vid = id_vendor, \
74 .pid = id_product, \
75 .bcdmin = bcdDeviceMin, \
76 .bcdmax = bcdDeviceMax, \
77}
78
79static struct ignore_entry ignore_ids[] = {
80# include "unusual_alauda.h"
81# include "unusual_cypress.h"
82# include "unusual_datafab.h"
83# include "unusual_freecom.h"
84# include "unusual_isd200.h"
85# include "unusual_jumpshot.h"
86# include "unusual_karma.h"
87# include "unusual_onetouch.h"
88# include "unusual_sddr09.h"
89# include "unusual_sddr55.h"
90# include "unusual_usbat.h"
91 { } /* Terminating entry */
92};
93
94#undef UNUSUAL_DEV
95
96
97/* Return an error if a device is in the ignore_ids list */
98int usb_usual_ignore_device(struct usb_interface *intf)
99{
100 struct usb_device *udev;
101 unsigned vid, pid, bcd;
102 struct ignore_entry *p;
103
104 udev = interface_to_usbdev(intf);
105 vid = le16_to_cpu(udev->descriptor.idVendor);
106 pid = le16_to_cpu(udev->descriptor.idProduct);
107 bcd = le16_to_cpu(udev->descriptor.bcdDevice);
108
109 for (p = ignore_ids; p->vid; ++p) {
110 if (p->vid == vid && p->pid == pid &&
111 p->bcdmin <= bcd && p->bcdmax >= bcd)
112 return -ENXIO;
113 }
114 return 0;
115}
116EXPORT_SYMBOL_GPL(usb_usual_ignore_device);
diff --git a/drivers/usb/usb-skeleton.c b/drivers/usb/usb-skeleton.c
index be76084c8d7e..60ba631e99c2 100644
--- a/drivers/usb/usb-skeleton.c
+++ b/drivers/usb/usb-skeleton.c
@@ -410,7 +410,9 @@ static int skel_probe(struct usb_interface *interface, const struct usb_device_i
410 } 410 }
411 411
412 /* let the user know what node this device is now attached to */ 412 /* let the user know what node this device is now attached to */
413 info("USB Skeleton device now attached to USBSkel-%d", interface->minor); 413 dev_info(&interface->dev,
414 "USB Skeleton device now attached to USBSkel-%d",
415 interface->minor);
414 return 0; 416 return 0;
415 417
416error: 418error:
@@ -441,7 +443,7 @@ static void skel_disconnect(struct usb_interface *interface)
441 /* decrement our usage count */ 443 /* decrement our usage count */
442 kref_put(&dev->kref, skel_delete); 444 kref_put(&dev->kref, skel_delete);
443 445
444 info("USB Skeleton #%d now disconnected", minor); 446 dev_info(&interface->dev, "USB Skeleton #%d now disconnected", minor);
445} 447}
446 448
447static void skel_draw_down(struct usb_skel *dev) 449static void skel_draw_down(struct usb_skel *dev)
diff --git a/drivers/usb/wusbcore/cbaf.c b/drivers/usb/wusbcore/cbaf.c
index 1335cbe1191d..25eae405f622 100644
--- a/drivers/usb/wusbcore/cbaf.c
+++ b/drivers/usb/wusbcore/cbaf.c
@@ -638,8 +638,7 @@ static void cbaf_disconnect(struct usb_interface *iface)
638 usb_put_intf(iface); 638 usb_put_intf(iface);
639 kfree(cbaf->buffer); 639 kfree(cbaf->buffer);
640 /* paranoia: clean up crypto keys */ 640 /* paranoia: clean up crypto keys */
641 memset(cbaf, 0, sizeof(*cbaf)); 641 kzfree(cbaf);
642 kfree(cbaf);
643} 642}
644 643
645static struct usb_device_id cbaf_id_table[] = { 644static struct usb_device_id cbaf_id_table[] = {
diff --git a/drivers/usb/wusbcore/devconnect.c b/drivers/usb/wusbcore/devconnect.c
index 8e18141bb2e0..f0aac0cf315a 100644
--- a/drivers/usb/wusbcore/devconnect.c
+++ b/drivers/usb/wusbcore/devconnect.c
@@ -889,6 +889,8 @@ static void wusb_dev_add_ncb(struct usb_device *usb_dev)
889 if (usb_dev->wusb == 0 || usb_dev->devnum == 1) 889 if (usb_dev->wusb == 0 || usb_dev->devnum == 1)
890 return; /* skip non wusb and wusb RHs */ 890 return; /* skip non wusb and wusb RHs */
891 891
892 usb_set_device_state(usb_dev, USB_STATE_UNAUTHENTICATED);
893
892 wusbhc = wusbhc_get_by_usb_dev(usb_dev); 894 wusbhc = wusbhc_get_by_usb_dev(usb_dev);
893 if (wusbhc == NULL) 895 if (wusbhc == NULL)
894 goto error_nodev; 896 goto error_nodev;
diff --git a/drivers/usb/wusbcore/security.c b/drivers/usb/wusbcore/security.c
index f4aa28eca70d..8118db7f1d8d 100644
--- a/drivers/usb/wusbcore/security.c
+++ b/drivers/usb/wusbcore/security.c
@@ -312,6 +312,7 @@ int wusb_dev_update_address(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
312 result = wusb_set_dev_addr(wusbhc, wusb_dev, 0); 312 result = wusb_set_dev_addr(wusbhc, wusb_dev, 0);
313 if (result < 0) 313 if (result < 0)
314 goto error_addr0; 314 goto error_addr0;
315 usb_set_device_state(usb_dev, USB_STATE_DEFAULT);
315 usb_ep0_reinit(usb_dev); 316 usb_ep0_reinit(usb_dev);
316 317
317 /* Set new (authenticated) address. */ 318 /* Set new (authenticated) address. */
@@ -327,6 +328,7 @@ int wusb_dev_update_address(struct wusbhc *wusbhc, struct wusb_dev *wusb_dev)
327 result = wusb_set_dev_addr(wusbhc, wusb_dev, new_address); 328 result = wusb_set_dev_addr(wusbhc, wusb_dev, new_address);
328 if (result < 0) 329 if (result < 0)
329 goto error_addr; 330 goto error_addr;
331 usb_set_device_state(usb_dev, USB_STATE_ADDRESS);
330 usb_ep0_reinit(usb_dev); 332 usb_ep0_reinit(usb_dev);
331 usb_dev->authenticated = 1; 333 usb_dev->authenticated = 1;
332error_addr: 334error_addr:
diff --git a/drivers/video/au1100fb.c b/drivers/video/au1100fb.c
index 62bd4441b5e0..378f27745a1d 100644
--- a/drivers/video/au1100fb.c
+++ b/drivers/video/au1100fb.c
@@ -457,7 +457,7 @@ static struct fb_ops au1100fb_ops =
457 457
458/* AU1100 LCD controller device driver */ 458/* AU1100 LCD controller device driver */
459 459
460static int __init au1100fb_drv_probe(struct device *dev) 460static int __init au1100fb_drv_probe(struct platform_device *dev)
461{ 461{
462 struct au1100fb_device *fbdev = NULL; 462 struct au1100fb_device *fbdev = NULL;
463 struct resource *regs_res; 463 struct resource *regs_res;
@@ -475,7 +475,7 @@ static int __init au1100fb_drv_probe(struct device *dev)
475 475
476 fbdev->panel = &known_lcd_panels[drv_info.panel_idx]; 476 fbdev->panel = &known_lcd_panels[drv_info.panel_idx];
477 477
478 dev_set_drvdata(dev, (void*)fbdev); 478 platform_set_drvdata(dev, (void *)fbdev);
479 479
480 /* Allocate region for our registers and map them */ 480 /* Allocate region for our registers and map them */
481 if (!(regs_res = platform_get_resource(to_platform_device(dev), 481 if (!(regs_res = platform_get_resource(to_platform_device(dev),
@@ -583,19 +583,19 @@ failed:
583 fb_dealloc_cmap(&fbdev->info.cmap); 583 fb_dealloc_cmap(&fbdev->info.cmap);
584 } 584 }
585 kfree(fbdev); 585 kfree(fbdev);
586 dev_set_drvdata(dev, NULL); 586 platform_set_drvdata(dev, NULL);
587 587
588 return 0; 588 return 0;
589} 589}
590 590
591int au1100fb_drv_remove(struct device *dev) 591int au1100fb_drv_remove(struct platform_device *dev)
592{ 592{
593 struct au1100fb_device *fbdev = NULL; 593 struct au1100fb_device *fbdev = NULL;
594 594
595 if (!dev) 595 if (!dev)
596 return -ENODEV; 596 return -ENODEV;
597 597
598 fbdev = (struct au1100fb_device*) dev_get_drvdata(dev); 598 fbdev = (struct au1100fb_device *) platform_get_drvdata(dev);
599 599
600#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO) 600#if !defined(CONFIG_FRAMEBUFFER_CONSOLE) && defined(CONFIG_LOGO)
601 au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info); 601 au1100fb_fb_blank(VESA_POWERDOWN, &fbdev->info);
@@ -620,9 +620,9 @@ int au1100fb_drv_remove(struct device *dev)
620static u32 sys_clksrc; 620static u32 sys_clksrc;
621static struct au1100fb_regs fbregs; 621static struct au1100fb_regs fbregs;
622 622
623int au1100fb_drv_suspend(struct device *dev, pm_message_t state) 623int au1100fb_drv_suspend(struct platform_device *dev, pm_message_t state)
624{ 624{
625 struct au1100fb_device *fbdev = dev_get_drvdata(dev); 625 struct au1100fb_device *fbdev = platform_get_drvdata(dev);
626 626
627 if (!fbdev) 627 if (!fbdev)
628 return 0; 628 return 0;
@@ -641,9 +641,9 @@ int au1100fb_drv_suspend(struct device *dev, pm_message_t state)
641 return 0; 641 return 0;
642} 642}
643 643
644int au1100fb_drv_resume(struct device *dev) 644int au1100fb_drv_resume(struct platform_device *dev)
645{ 645{
646 struct au1100fb_device *fbdev = dev_get_drvdata(dev); 646 struct au1100fb_device *fbdev = platform_get_drvdata(dev);
647 647
648 if (!fbdev) 648 if (!fbdev)
649 return 0; 649 return 0;
@@ -663,10 +663,11 @@ int au1100fb_drv_resume(struct device *dev)
663#define au1100fb_drv_resume NULL 663#define au1100fb_drv_resume NULL
664#endif 664#endif
665 665
666static struct device_driver au1100fb_driver = { 666static struct platform_driver au1100fb_driver = {
667 .name = "au1100-lcd", 667 .driver = {
668 .bus = &platform_bus_type, 668 .name = "au1100-lcd",
669 669 .owner = THIS_MODULE,
670 },
670 .probe = au1100fb_drv_probe, 671 .probe = au1100fb_drv_probe,
671 .remove = au1100fb_drv_remove, 672 .remove = au1100fb_drv_remove,
672 .suspend = au1100fb_drv_suspend, 673 .suspend = au1100fb_drv_suspend,
@@ -753,12 +754,12 @@ int __init au1100fb_init(void)
753 return ret; 754 return ret;
754 } 755 }
755 756
756 return driver_register(&au1100fb_driver); 757 return platform_driver_register(&au1100fb_driver);
757} 758}
758 759
759void __exit au1100fb_cleanup(void) 760void __exit au1100fb_cleanup(void)
760{ 761{
761 driver_unregister(&au1100fb_driver); 762 platform_driver_unregister(&au1100fb_driver);
762 763
763 kfree(drv_info.opt_mode); 764 kfree(drv_info.opt_mode);
764} 765}
diff --git a/drivers/video/au1200fb.c b/drivers/video/au1200fb.c
index 03e57ef88378..0d96f1d2d4c5 100644
--- a/drivers/video/au1200fb.c
+++ b/drivers/video/au1200fb.c
@@ -1622,7 +1622,7 @@ static int au1200fb_init_fbinfo(struct au1200fb_device *fbdev)
1622 1622
1623/* AU1200 LCD controller device driver */ 1623/* AU1200 LCD controller device driver */
1624 1624
1625static int au1200fb_drv_probe(struct device *dev) 1625static int au1200fb_drv_probe(struct platform_device *dev)
1626{ 1626{
1627 struct au1200fb_device *fbdev; 1627 struct au1200fb_device *fbdev;
1628 unsigned long page; 1628 unsigned long page;
@@ -1645,7 +1645,7 @@ static int au1200fb_drv_probe(struct device *dev)
1645 /* Allocate the framebuffer to the maximum screen size */ 1645 /* Allocate the framebuffer to the maximum screen size */
1646 fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8; 1646 fbdev->fb_len = (win->w[plane].xres * win->w[plane].yres * bpp) / 8;
1647 1647
1648 fbdev->fb_mem = dma_alloc_noncoherent(dev, 1648 fbdev->fb_mem = dma_alloc_noncoherent(&dev->dev,
1649 PAGE_ALIGN(fbdev->fb_len), 1649 PAGE_ALIGN(fbdev->fb_len),
1650 &fbdev->fb_phys, GFP_KERNEL); 1650 &fbdev->fb_phys, GFP_KERNEL);
1651 if (!fbdev->fb_mem) { 1651 if (!fbdev->fb_mem) {
@@ -1715,7 +1715,7 @@ failed:
1715 return ret; 1715 return ret;
1716} 1716}
1717 1717
1718static int au1200fb_drv_remove(struct device *dev) 1718static int au1200fb_drv_remove(struct platform_device *dev)
1719{ 1719{
1720 struct au1200fb_device *fbdev; 1720 struct au1200fb_device *fbdev;
1721 int plane; 1721 int plane;
@@ -1733,7 +1733,8 @@ static int au1200fb_drv_remove(struct device *dev)
1733 /* Clean up all probe data */ 1733 /* Clean up all probe data */
1734 unregister_framebuffer(&fbdev->fb_info); 1734 unregister_framebuffer(&fbdev->fb_info);
1735 if (fbdev->fb_mem) 1735 if (fbdev->fb_mem)
1736 dma_free_noncoherent(dev, PAGE_ALIGN(fbdev->fb_len), 1736 dma_free_noncoherent(&dev->dev,
1737 PAGE_ALIGN(fbdev->fb_len),
1737 fbdev->fb_mem, fbdev->fb_phys); 1738 fbdev->fb_mem, fbdev->fb_phys);
1738 if (fbdev->fb_info.cmap.len != 0) 1739 if (fbdev->fb_info.cmap.len != 0)
1739 fb_dealloc_cmap(&fbdev->fb_info.cmap); 1740 fb_dealloc_cmap(&fbdev->fb_info.cmap);
@@ -1747,22 +1748,24 @@ static int au1200fb_drv_remove(struct device *dev)
1747} 1748}
1748 1749
1749#ifdef CONFIG_PM 1750#ifdef CONFIG_PM
1750static int au1200fb_drv_suspend(struct device *dev, u32 state, u32 level) 1751static int au1200fb_drv_suspend(struct platform_device *dev, u32 state)
1751{ 1752{
1752 /* TODO */ 1753 /* TODO */
1753 return 0; 1754 return 0;
1754} 1755}
1755 1756
1756static int au1200fb_drv_resume(struct device *dev, u32 level) 1757static int au1200fb_drv_resume(struct platform_device *dev)
1757{ 1758{
1758 /* TODO */ 1759 /* TODO */
1759 return 0; 1760 return 0;
1760} 1761}
1761#endif /* CONFIG_PM */ 1762#endif /* CONFIG_PM */
1762 1763
1763static struct device_driver au1200fb_driver = { 1764static struct platform_driver au1200fb_driver = {
1764 .name = "au1200-lcd", 1765 .driver = {
1765 .bus = &platform_bus_type, 1766 .name = "au1200-lcd",
1767 .owner = THIS_MODULE,
1768 },
1766 .probe = au1200fb_drv_probe, 1769 .probe = au1200fb_drv_probe,
1767 .remove = au1200fb_drv_remove, 1770 .remove = au1200fb_drv_remove,
1768#ifdef CONFIG_PM 1771#ifdef CONFIG_PM
@@ -1906,12 +1909,12 @@ static int __init au1200fb_init(void)
1906 printk(KERN_INFO "Power management device entry for the au1200fb loaded.\n"); 1909 printk(KERN_INFO "Power management device entry for the au1200fb loaded.\n");
1907 #endif 1910 #endif
1908 1911
1909 return driver_register(&au1200fb_driver); 1912 return platform_driver_register(&au1200fb_driver);
1910} 1913}
1911 1914
1912static void __exit au1200fb_cleanup(void) 1915static void __exit au1200fb_cleanup(void)
1913{ 1916{
1914 driver_unregister(&au1200fb_driver); 1917 platform_driver_unregister(&au1200fb_driver);
1915} 1918}
1916 1919
1917module_init(au1200fb_init); 1920module_init(au1200fb_init);
diff --git a/drivers/video/pmag-ba-fb.c b/drivers/video/pmag-ba-fb.c
index 3a3f80f65219..0573ec685a57 100644
--- a/drivers/video/pmag-ba-fb.c
+++ b/drivers/video/pmag-ba-fb.c
@@ -151,7 +151,7 @@ static int __init pmagbafb_probe(struct device *dev)
151 151
152 info = framebuffer_alloc(sizeof(struct pmagbafb_par), dev); 152 info = framebuffer_alloc(sizeof(struct pmagbafb_par), dev);
153 if (!info) { 153 if (!info) {
154 printk(KERN_ERR "%s: Cannot allocate memory\n", dev->bus_id); 154 printk(KERN_ERR "%s: Cannot allocate memory\n", dev_name(dev));
155 return -ENOMEM; 155 return -ENOMEM;
156 } 156 }
157 157
@@ -160,7 +160,7 @@ static int __init pmagbafb_probe(struct device *dev)
160 160
161 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { 161 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
162 printk(KERN_ERR "%s: Cannot allocate color map\n", 162 printk(KERN_ERR "%s: Cannot allocate color map\n",
163 dev->bus_id); 163 dev_name(dev));
164 err = -ENOMEM; 164 err = -ENOMEM;
165 goto err_alloc; 165 goto err_alloc;
166 } 166 }
@@ -173,8 +173,9 @@ static int __init pmagbafb_probe(struct device *dev)
173 /* Request the I/O MEM resource. */ 173 /* Request the I/O MEM resource. */
174 start = tdev->resource.start; 174 start = tdev->resource.start;
175 len = tdev->resource.end - start + 1; 175 len = tdev->resource.end - start + 1;
176 if (!request_mem_region(start, len, dev->bus_id)) { 176 if (!request_mem_region(start, len, dev_name(dev))) {
177 printk(KERN_ERR "%s: Cannot reserve FB region\n", dev->bus_id); 177 printk(KERN_ERR "%s: Cannot reserve FB region\n",
178 dev_name(dev));
178 err = -EBUSY; 179 err = -EBUSY;
179 goto err_cmap; 180 goto err_cmap;
180 } 181 }
@@ -183,7 +184,7 @@ static int __init pmagbafb_probe(struct device *dev)
183 info->fix.mmio_start = start; 184 info->fix.mmio_start = start;
184 par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len); 185 par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
185 if (!par->mmio) { 186 if (!par->mmio) {
186 printk(KERN_ERR "%s: Cannot map MMIO\n", dev->bus_id); 187 printk(KERN_ERR "%s: Cannot map MMIO\n", dev_name(dev));
187 err = -ENOMEM; 188 err = -ENOMEM;
188 goto err_resource; 189 goto err_resource;
189 } 190 }
@@ -194,7 +195,7 @@ static int __init pmagbafb_probe(struct device *dev)
194 info->screen_base = ioremap_nocache(info->fix.smem_start, 195 info->screen_base = ioremap_nocache(info->fix.smem_start,
195 info->fix.smem_len); 196 info->fix.smem_len);
196 if (!info->screen_base) { 197 if (!info->screen_base) {
197 printk(KERN_ERR "%s: Cannot map FB\n", dev->bus_id); 198 printk(KERN_ERR "%s: Cannot map FB\n", dev_name(dev));
198 err = -ENOMEM; 199 err = -ENOMEM;
199 goto err_mmio_map; 200 goto err_mmio_map;
200 } 201 }
@@ -205,14 +206,14 @@ static int __init pmagbafb_probe(struct device *dev)
205 err = register_framebuffer(info); 206 err = register_framebuffer(info);
206 if (err < 0) { 207 if (err < 0) {
207 printk(KERN_ERR "%s: Cannot register framebuffer\n", 208 printk(KERN_ERR "%s: Cannot register framebuffer\n",
208 dev->bus_id); 209 dev_name(dev));
209 goto err_smem_map; 210 goto err_smem_map;
210 } 211 }
211 212
212 get_device(dev); 213 get_device(dev);
213 214
214 pr_info("fb%d: %s frame buffer device at %s\n", 215 pr_info("fb%d: %s frame buffer device at %s\n",
215 info->node, info->fix.id, dev->bus_id); 216 info->node, info->fix.id, dev_name(dev));
216 217
217 return 0; 218 return 0;
218 219
diff --git a/drivers/video/pmagb-b-fb.c b/drivers/video/pmagb-b-fb.c
index 9b80597241b0..98748723af9f 100644
--- a/drivers/video/pmagb-b-fb.c
+++ b/drivers/video/pmagb-b-fb.c
@@ -258,7 +258,7 @@ static int __init pmagbbfb_probe(struct device *dev)
258 258
259 info = framebuffer_alloc(sizeof(struct pmagbbfb_par), dev); 259 info = framebuffer_alloc(sizeof(struct pmagbbfb_par), dev);
260 if (!info) { 260 if (!info) {
261 printk(KERN_ERR "%s: Cannot allocate memory\n", dev->bus_id); 261 printk(KERN_ERR "%s: Cannot allocate memory\n", dev_name(dev));
262 return -ENOMEM; 262 return -ENOMEM;
263 } 263 }
264 264
@@ -267,7 +267,7 @@ static int __init pmagbbfb_probe(struct device *dev)
267 267
268 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { 268 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
269 printk(KERN_ERR "%s: Cannot allocate color map\n", 269 printk(KERN_ERR "%s: Cannot allocate color map\n",
270 dev->bus_id); 270 dev_name(dev));
271 err = -ENOMEM; 271 err = -ENOMEM;
272 goto err_alloc; 272 goto err_alloc;
273 } 273 }
@@ -280,8 +280,9 @@ static int __init pmagbbfb_probe(struct device *dev)
280 /* Request the I/O MEM resource. */ 280 /* Request the I/O MEM resource. */
281 start = tdev->resource.start; 281 start = tdev->resource.start;
282 len = tdev->resource.end - start + 1; 282 len = tdev->resource.end - start + 1;
283 if (!request_mem_region(start, len, dev->bus_id)) { 283 if (!request_mem_region(start, len, dev_name(dev))) {
284 printk(KERN_ERR "%s: Cannot reserve FB region\n", dev->bus_id); 284 printk(KERN_ERR "%s: Cannot reserve FB region\n",
285 dev_name(dev));
285 err = -EBUSY; 286 err = -EBUSY;
286 goto err_cmap; 287 goto err_cmap;
287 } 288 }
@@ -290,7 +291,7 @@ static int __init pmagbbfb_probe(struct device *dev)
290 info->fix.mmio_start = start; 291 info->fix.mmio_start = start;
291 par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len); 292 par->mmio = ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
292 if (!par->mmio) { 293 if (!par->mmio) {
293 printk(KERN_ERR "%s: Cannot map MMIO\n", dev->bus_id); 294 printk(KERN_ERR "%s: Cannot map MMIO\n", dev_name(dev));
294 err = -ENOMEM; 295 err = -ENOMEM;
295 goto err_resource; 296 goto err_resource;
296 } 297 }
@@ -301,7 +302,7 @@ static int __init pmagbbfb_probe(struct device *dev)
301 info->fix.smem_start = start + PMAGB_B_FBMEM; 302 info->fix.smem_start = start + PMAGB_B_FBMEM;
302 par->smem = ioremap_nocache(info->fix.smem_start, info->fix.smem_len); 303 par->smem = ioremap_nocache(info->fix.smem_start, info->fix.smem_len);
303 if (!par->smem) { 304 if (!par->smem) {
304 printk(KERN_ERR "%s: Cannot map FB\n", dev->bus_id); 305 printk(KERN_ERR "%s: Cannot map FB\n", dev_name(dev));
305 err = -ENOMEM; 306 err = -ENOMEM;
306 goto err_mmio_map; 307 goto err_mmio_map;
307 } 308 }
@@ -316,7 +317,7 @@ static int __init pmagbbfb_probe(struct device *dev)
316 err = register_framebuffer(info); 317 err = register_framebuffer(info);
317 if (err < 0) { 318 if (err < 0) {
318 printk(KERN_ERR "%s: Cannot register framebuffer\n", 319 printk(KERN_ERR "%s: Cannot register framebuffer\n",
319 dev->bus_id); 320 dev_name(dev));
320 goto err_smem_map; 321 goto err_smem_map;
321 } 322 }
322 323
@@ -328,7 +329,7 @@ static int __init pmagbbfb_probe(struct device *dev)
328 par->osc1 / 1000, par->osc1 % 1000); 329 par->osc1 / 1000, par->osc1 % 1000);
329 330
330 pr_info("fb%d: %s frame buffer device at %s\n", 331 pr_info("fb%d: %s frame buffer device at %s\n",
331 info->node, info->fix.id, dev->bus_id); 332 info->node, info->fix.id, dev_name(dev));
332 pr_info("fb%d: Osc0: %s, Osc1: %s, Osc%u selected\n", 333 pr_info("fb%d: Osc0: %s, Osc1: %s, Osc%u selected\n",
333 info->node, freq0, par->osc1 ? freq1 : "disabled", 334 info->node, freq0, par->osc1 ? freq1 : "disabled",
334 par->osc1 != 0); 335 par->osc1 != 0);
diff --git a/drivers/video/ps3fb.c b/drivers/video/ps3fb.c
index 87f826e4c958..e00c1dff55de 100644
--- a/drivers/video/ps3fb.c
+++ b/drivers/video/ps3fb.c
@@ -1213,7 +1213,7 @@ static int __devinit ps3fb_probe(struct ps3_system_bus_device *dev)
1213 dev->core.driver_data = info; 1213 dev->core.driver_data = info;
1214 1214
1215 dev_info(info->device, "%s %s, using %u KiB of video memory\n", 1215 dev_info(info->device, "%s %s, using %u KiB of video memory\n",
1216 dev_driver_string(info->dev), info->dev->bus_id, 1216 dev_driver_string(info->dev), dev_name(info->dev),
1217 info->fix.smem_len >> 10); 1217 info->fix.smem_len >> 10);
1218 1218
1219 task = kthread_run(ps3fbd, info, DEVICE_NAME); 1219 task = kthread_run(ps3fbd, info, DEVICE_NAME);
diff --git a/drivers/video/pvr2fb.c b/drivers/video/pvr2fb.c
index 0a0fd48a8566..53f8f1100e81 100644
--- a/drivers/video/pvr2fb.c
+++ b/drivers/video/pvr2fb.c
@@ -61,7 +61,7 @@
61#include <mach-dreamcast/mach/sysasic.h> 61#include <mach-dreamcast/mach/sysasic.h>
62#endif 62#endif
63 63
64#ifdef CONFIG_SH_DMA 64#ifdef CONFIG_PVR2_DMA
65#include <linux/pagemap.h> 65#include <linux/pagemap.h>
66#include <mach/dma.h> 66#include <mach/dma.h>
67#include <asm/dma.h> 67#include <asm/dma.h>
@@ -188,7 +188,7 @@ static unsigned int is_blanked = 0; /* Is the screen blanked? */
188static unsigned long pvr2fb_map; 188static unsigned long pvr2fb_map;
189#endif 189#endif
190 190
191#ifdef CONFIG_SH_DMA 191#ifdef CONFIG_PVR2_DMA
192static unsigned int shdma = PVR2_CASCADE_CHAN; 192static unsigned int shdma = PVR2_CASCADE_CHAN;
193static unsigned int pvr2dma = ONCHIP_NR_DMA_CHANNELS; 193static unsigned int pvr2dma = ONCHIP_NR_DMA_CHANNELS;
194#endif 194#endif
@@ -207,7 +207,7 @@ static irqreturn_t pvr2fb_interrupt(int irq, void *dev_id);
207static int pvr2_init_cable(void); 207static int pvr2_init_cable(void);
208static int pvr2_get_param(const struct pvr2_params *p, const char *s, 208static int pvr2_get_param(const struct pvr2_params *p, const char *s,
209 int val, int size); 209 int val, int size);
210#ifdef CONFIG_SH_DMA 210#ifdef CONFIG_PVR2_DMA
211static ssize_t pvr2fb_write(struct fb_info *info, const char *buf, 211static ssize_t pvr2fb_write(struct fb_info *info, const char *buf,
212 size_t count, loff_t *ppos); 212 size_t count, loff_t *ppos);
213#endif 213#endif
@@ -218,7 +218,7 @@ static struct fb_ops pvr2fb_ops = {
218 .fb_blank = pvr2fb_blank, 218 .fb_blank = pvr2fb_blank,
219 .fb_check_var = pvr2fb_check_var, 219 .fb_check_var = pvr2fb_check_var,
220 .fb_set_par = pvr2fb_set_par, 220 .fb_set_par = pvr2fb_set_par,
221#ifdef CONFIG_SH_DMA 221#ifdef CONFIG_PVR2_DMA
222 .fb_write = pvr2fb_write, 222 .fb_write = pvr2fb_write,
223#endif 223#endif
224 .fb_fillrect = cfb_fillrect, 224 .fb_fillrect = cfb_fillrect,
@@ -671,7 +671,7 @@ static int pvr2_init_cable(void)
671 return cable_type; 671 return cable_type;
672} 672}
673 673
674#ifdef CONFIG_SH_DMA 674#ifdef CONFIG_PVR2_DMA
675static ssize_t pvr2fb_write(struct fb_info *info, const char *buf, 675static ssize_t pvr2fb_write(struct fb_info *info, const char *buf,
676 size_t count, loff_t *ppos) 676 size_t count, loff_t *ppos)
677{ 677{
@@ -743,7 +743,7 @@ out_unmap:
743 743
744 return ret; 744 return ret;
745} 745}
746#endif /* CONFIG_SH_DMA */ 746#endif /* CONFIG_PVR2_DMA */
747 747
748/** 748/**
749 * pvr2fb_common_init 749 * pvr2fb_common_init
@@ -893,7 +893,7 @@ static int __init pvr2fb_dc_init(void)
893 return -EBUSY; 893 return -EBUSY;
894 } 894 }
895 895
896#ifdef CONFIG_SH_DMA 896#ifdef CONFIG_PVR2_DMA
897 if (request_dma(pvr2dma, "pvr2") != 0) { 897 if (request_dma(pvr2dma, "pvr2") != 0) {
898 free_irq(HW_EVENT_VSYNC, 0); 898 free_irq(HW_EVENT_VSYNC, 0);
899 return -EBUSY; 899 return -EBUSY;
@@ -915,7 +915,7 @@ static void __exit pvr2fb_dc_exit(void)
915 } 915 }
916 916
917 free_irq(HW_EVENT_VSYNC, 0); 917 free_irq(HW_EVENT_VSYNC, 0);
918#ifdef CONFIG_SH_DMA 918#ifdef CONFIG_PVR2_DMA
919 free_dma(pvr2dma); 919 free_dma(pvr2dma);
920#endif 920#endif
921} 921}
diff --git a/drivers/video/sh_mobile_lcdcfb.c b/drivers/video/sh_mobile_lcdcfb.c
index 2c5d069e5f06..92ea0ab44ce2 100644
--- a/drivers/video/sh_mobile_lcdcfb.c
+++ b/drivers/video/sh_mobile_lcdcfb.c
@@ -33,6 +33,8 @@ struct sh_mobile_lcdc_chan {
33 struct fb_info info; 33 struct fb_info info;
34 dma_addr_t dma_handle; 34 dma_addr_t dma_handle;
35 struct fb_deferred_io defio; 35 struct fb_deferred_io defio;
36 unsigned long frame_end;
37 wait_queue_head_t frame_end_wait;
36}; 38};
37 39
38struct sh_mobile_lcdc_priv { 40struct sh_mobile_lcdc_priv {
@@ -226,7 +228,10 @@ static void sh_mobile_lcdc_deferred_io_touch(struct fb_info *info)
226static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data) 228static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
227{ 229{
228 struct sh_mobile_lcdc_priv *priv = data; 230 struct sh_mobile_lcdc_priv *priv = data;
231 struct sh_mobile_lcdc_chan *ch;
229 unsigned long tmp; 232 unsigned long tmp;
233 int is_sub;
234 int k;
230 235
231 /* acknowledge interrupt */ 236 /* acknowledge interrupt */
232 tmp = lcdc_read(priv, _LDINTR); 237 tmp = lcdc_read(priv, _LDINTR);
@@ -234,8 +239,24 @@ static irqreturn_t sh_mobile_lcdc_irq(int irq, void *data)
234 tmp |= 0x000000ff ^ LDINTR_FS; /* status in low 8 */ 239 tmp |= 0x000000ff ^ LDINTR_FS; /* status in low 8 */
235 lcdc_write(priv, _LDINTR, tmp); 240 lcdc_write(priv, _LDINTR, tmp);
236 241
237 /* disable clocks */ 242 /* figure out if this interrupt is for main or sub lcd */
238 sh_mobile_lcdc_clk_off(priv); 243 is_sub = (lcdc_read(priv, _LDSR) & (1 << 10)) ? 1 : 0;
244
245 /* wake up channel and disable clocks*/
246 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
247 ch = &priv->ch[k];
248
249 if (!ch->enabled)
250 continue;
251
252 if (is_sub == lcdc_chan_is_sublcd(ch)) {
253 ch->frame_end = 1;
254 wake_up(&ch->frame_end_wait);
255
256 sh_mobile_lcdc_clk_off(priv);
257 }
258 }
259
239 return IRQ_HANDLED; 260 return IRQ_HANDLED;
240} 261}
241 262
@@ -448,18 +469,27 @@ static void sh_mobile_lcdc_stop(struct sh_mobile_lcdc_priv *priv)
448 struct sh_mobile_lcdc_board_cfg *board_cfg; 469 struct sh_mobile_lcdc_board_cfg *board_cfg;
449 int k; 470 int k;
450 471
451 /* tell the board code to disable the panel */ 472 /* clean up deferred io and ask board code to disable panel */
452 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) { 473 for (k = 0; k < ARRAY_SIZE(priv->ch); k++) {
453 ch = &priv->ch[k]; 474 ch = &priv->ch[k];
454 board_cfg = &ch->cfg.board_cfg;
455 if (board_cfg->display_off)
456 board_cfg->display_off(board_cfg->board_data);
457 475
458 /* cleanup deferred io if enabled */ 476 /* deferred io mode:
477 * flush frame, and wait for frame end interrupt
478 * clean up deferred io and enable clock
479 */
459 if (ch->info.fbdefio) { 480 if (ch->info.fbdefio) {
481 ch->frame_end = 0;
482 schedule_delayed_work(&ch->info.deferred_work, 0);
483 wait_event(ch->frame_end_wait, ch->frame_end);
460 fb_deferred_io_cleanup(&ch->info); 484 fb_deferred_io_cleanup(&ch->info);
461 ch->info.fbdefio = NULL; 485 ch->info.fbdefio = NULL;
486 sh_mobile_lcdc_clk_on(priv);
462 } 487 }
488
489 board_cfg = &ch->cfg.board_cfg;
490 if (board_cfg->display_off)
491 board_cfg->display_off(board_cfg->board_data);
492
463 } 493 }
464 494
465 /* stop the lcdc */ 495 /* stop the lcdc */
@@ -652,6 +682,26 @@ static int sh_mobile_lcdc_set_bpp(struct fb_var_screeninfo *var, int bpp)
652 return 0; 682 return 0;
653} 683}
654 684
685static int sh_mobile_lcdc_suspend(struct device *dev)
686{
687 struct platform_device *pdev = to_platform_device(dev);
688
689 sh_mobile_lcdc_stop(platform_get_drvdata(pdev));
690 return 0;
691}
692
693static int sh_mobile_lcdc_resume(struct device *dev)
694{
695 struct platform_device *pdev = to_platform_device(dev);
696
697 return sh_mobile_lcdc_start(platform_get_drvdata(pdev));
698}
699
700static struct dev_pm_ops sh_mobile_lcdc_dev_pm_ops = {
701 .suspend = sh_mobile_lcdc_suspend,
702 .resume = sh_mobile_lcdc_resume,
703};
704
655static int sh_mobile_lcdc_remove(struct platform_device *pdev); 705static int sh_mobile_lcdc_remove(struct platform_device *pdev);
656 706
657static int __init sh_mobile_lcdc_probe(struct platform_device *pdev) 707static int __init sh_mobile_lcdc_probe(struct platform_device *pdev)
@@ -687,7 +737,7 @@ static int __init sh_mobile_lcdc_probe(struct platform_device *pdev)
687 } 737 }
688 738
689 error = request_irq(i, sh_mobile_lcdc_irq, IRQF_DISABLED, 739 error = request_irq(i, sh_mobile_lcdc_irq, IRQF_DISABLED,
690 pdev->dev.bus_id, priv); 740 dev_name(&pdev->dev), priv);
691 if (error) { 741 if (error) {
692 dev_err(&pdev->dev, "unable to request irq\n"); 742 dev_err(&pdev->dev, "unable to request irq\n");
693 goto err1; 743 goto err1;
@@ -707,6 +757,7 @@ static int __init sh_mobile_lcdc_probe(struct platform_device *pdev)
707 dev_err(&pdev->dev, "unsupported interface type\n"); 757 dev_err(&pdev->dev, "unsupported interface type\n");
708 goto err1; 758 goto err1;
709 } 759 }
760 init_waitqueue_head(&priv->ch[i].frame_end_wait);
710 761
711 switch (pdata->ch[i].chan) { 762 switch (pdata->ch[i].chan) {
712 case LCDC_CHAN_MAINLCD: 763 case LCDC_CHAN_MAINLCD:
@@ -860,6 +911,7 @@ static struct platform_driver sh_mobile_lcdc_driver = {
860 .driver = { 911 .driver = {
861 .name = "sh_mobile_lcdc_fb", 912 .name = "sh_mobile_lcdc_fb",
862 .owner = THIS_MODULE, 913 .owner = THIS_MODULE,
914 .pm = &sh_mobile_lcdc_dev_pm_ops,
863 }, 915 },
864 .probe = sh_mobile_lcdc_probe, 916 .probe = sh_mobile_lcdc_probe,
865 .remove = sh_mobile_lcdc_remove, 917 .remove = sh_mobile_lcdc_remove,
diff --git a/drivers/video/tmiofb.c b/drivers/video/tmiofb.c
index 7baf2dd12d50..a1eb0862255b 100644
--- a/drivers/video/tmiofb.c
+++ b/drivers/video/tmiofb.c
@@ -751,7 +751,7 @@ static int __devinit tmiofb_probe(struct platform_device *dev)
751 } 751 }
752 752
753 retval = request_irq(irq, &tmiofb_irq, IRQF_DISABLED, 753 retval = request_irq(irq, &tmiofb_irq, IRQF_DISABLED,
754 dev->dev.bus_id, info); 754 dev_name(&dev->dev), info);
755 755
756 if (retval) 756 if (retval)
757 goto err_request_irq; 757 goto err_request_irq;
diff --git a/drivers/watchdog/rm9k_wdt.c b/drivers/watchdog/rm9k_wdt.c
index f1ae3729a19e..cce1982a1b58 100644
--- a/drivers/watchdog/rm9k_wdt.c
+++ b/drivers/watchdog/rm9k_wdt.c
@@ -59,8 +59,8 @@ static long wdt_gpi_ioctl(struct file *, unsigned int, unsigned long);
59static int wdt_gpi_notify(struct notifier_block *, unsigned long, void *); 59static int wdt_gpi_notify(struct notifier_block *, unsigned long, void *);
60static const struct resource *wdt_gpi_get_resource(struct platform_device *, 60static const struct resource *wdt_gpi_get_resource(struct platform_device *,
61 const char *, unsigned int); 61 const char *, unsigned int);
62static int __init wdt_gpi_probe(struct device *); 62static int __init wdt_gpi_probe(struct platform_device *);
63static int __exit wdt_gpi_remove(struct device *); 63static int __exit wdt_gpi_remove(struct platform_device *);
64 64
65 65
66static const char wdt_gpi_name[] = "wdt_gpi"; 66static const char wdt_gpi_name[] = "wdt_gpi";
@@ -346,10 +346,9 @@ static const struct resource *wdt_gpi_get_resource(struct platform_device *pdv,
346} 346}
347 347
348/* No hotplugging on the platform bus - use __init */ 348/* No hotplugging on the platform bus - use __init */
349static int __init wdt_gpi_probe(struct device *dev) 349static int __init wdt_gpi_probe(struct platform_device *pdv)
350{ 350{
351 int res; 351 int res;
352 struct platform_device * const pdv = to_platform_device(dev);
353 const struct resource 352 const struct resource
354 * const rr = wdt_gpi_get_resource(pdv, WDT_RESOURCE_REGS, 353 * const rr = wdt_gpi_get_resource(pdv, WDT_RESOURCE_REGS,
355 IORESOURCE_MEM), 354 IORESOURCE_MEM),
@@ -374,7 +373,7 @@ static int __init wdt_gpi_probe(struct device *dev)
374 return res; 373 return res;
375} 374}
376 375
377static int __exit wdt_gpi_remove(struct device *dev) 376static int __exit wdt_gpi_remove(struct platform_device *dev)
378{ 377{
379 int res; 378 int res;
380 379
@@ -387,15 +386,13 @@ static int __exit wdt_gpi_remove(struct device *dev)
387 386
388 387
389/* Device driver init & exit */ 388/* Device driver init & exit */
390static struct device_driver wdt_gpi_driver = { 389static struct platform_driver wgt_gpi_driver = {
391 .name = (char *) wdt_gpi_name, 390 .driver = {
392 .bus = &platform_bus_type, 391 .name = wdt_gpi_name,
393 .owner = THIS_MODULE, 392 .owner = THIS_MODULE,
393 },
394 .probe = wdt_gpi_probe, 394 .probe = wdt_gpi_probe,
395 .remove = __exit_p(wdt_gpi_remove), 395 .remove = __devexit_p(wdt_gpi_remove),
396 .shutdown = NULL,
397 .suspend = NULL,
398 .resume = NULL,
399}; 396};
400 397
401static int __init wdt_gpi_init_module(void) 398static int __init wdt_gpi_init_module(void)
@@ -403,12 +400,12 @@ static int __init wdt_gpi_init_module(void)
403 atomic_set(&opencnt, 1); 400 atomic_set(&opencnt, 1);
404 if (timeout > MAX_TIMEOUT_SECONDS) 401 if (timeout > MAX_TIMEOUT_SECONDS)
405 timeout = MAX_TIMEOUT_SECONDS; 402 timeout = MAX_TIMEOUT_SECONDS;
406 return driver_register(&wdt_gpi_driver); 403 return platform_driver_register(&wdt_gpi_driver);
407} 404}
408 405
409static void __exit wdt_gpi_cleanup_module(void) 406static void __exit wdt_gpi_cleanup_module(void)
410{ 407{
411 driver_unregister(&wdt_gpi_driver); 408 platform_driver_unregister(&wdt_gpi_driver);
412} 409}
413 410
414module_init(wdt_gpi_init_module); 411module_init(wdt_gpi_init_module);
diff --git a/drivers/zorro/zorro.c b/drivers/zorro/zorro.c
index a1585d6f6486..d45fb34e2d23 100644
--- a/drivers/zorro/zorro.c
+++ b/drivers/zorro/zorro.c
@@ -140,7 +140,7 @@ static int __init zorro_init(void)
140 140
141 /* Initialize the Zorro bus */ 141 /* Initialize the Zorro bus */
142 INIT_LIST_HEAD(&zorro_bus.devices); 142 INIT_LIST_HEAD(&zorro_bus.devices);
143 strcpy(zorro_bus.dev.bus_id, "zorro"); 143 dev_set_name(&zorro_bus.dev, "zorro");
144 error = device_register(&zorro_bus.dev); 144 error = device_register(&zorro_bus.dev);
145 if (error) { 145 if (error) {
146 pr_err("Zorro: Error registering zorro_bus\n"); 146 pr_err("Zorro: Error registering zorro_bus\n");
@@ -167,7 +167,7 @@ static int __init zorro_init(void)
167 if (request_resource(zorro_find_parent_resource(z), &z->resource)) 167 if (request_resource(zorro_find_parent_resource(z), &z->resource))
168 pr_err("Zorro: Address space collision on device %s %pR\n", 168 pr_err("Zorro: Address space collision on device %s %pR\n",
169 z->name, &z->resource); 169 z->name, &z->resource);
170 sprintf(z->dev.bus_id, "%02x", i); 170 dev_set_name(&z->dev, "%02x", i);
171 z->dev.parent = &zorro_bus.dev; 171 z->dev.parent = &zorro_bus.dev;
172 z->dev.bus = &zorro_bus_type; 172 z->dev.bus = &zorro_bus_type;
173 error = device_register(&z->dev); 173 error = device_register(&z->dev);
diff --git a/fs/gfs2/Kconfig b/fs/gfs2/Kconfig
index e563a6449811..3a981b7f64ca 100644
--- a/fs/gfs2/Kconfig
+++ b/fs/gfs2/Kconfig
@@ -1,6 +1,10 @@
1config GFS2_FS 1config GFS2_FS
2 tristate "GFS2 file system support" 2 tristate "GFS2 file system support"
3 depends on EXPERIMENTAL && (64BIT || LBD) 3 depends on EXPERIMENTAL && (64BIT || LBD)
4 select DLM if GFS2_FS_LOCKING_DLM
5 select CONFIGFS_FS if GFS2_FS_LOCKING_DLM
6 select SYSFS if GFS2_FS_LOCKING_DLM
7 select IP_SCTP if DLM_SCTP
4 select FS_POSIX_ACL 8 select FS_POSIX_ACL
5 select CRC32 9 select CRC32
6 help 10 help
@@ -18,17 +22,16 @@ config GFS2_FS
18 the locking module below. Documentation and utilities for GFS2 can 22 the locking module below. Documentation and utilities for GFS2 can
19 be found here: http://sources.redhat.com/cluster 23 be found here: http://sources.redhat.com/cluster
20 24
21 The "nolock" lock module is now built in to GFS2 by default. 25 The "nolock" lock module is now built in to GFS2 by default. If
26 you want to use the DLM, be sure to enable HOTPLUG and IPv4/6
27 networking.
22 28
23config GFS2_FS_LOCKING_DLM 29config GFS2_FS_LOCKING_DLM
24 tristate "GFS2 DLM locking module" 30 bool "GFS2 DLM locking"
25 depends on GFS2_FS && SYSFS && NET && INET && (IPV6 || IPV6=n) 31 depends on (GFS2_FS!=n) && NET && INET && (IPV6 || IPV6=n) && HOTPLUG
26 select IP_SCTP if DLM_SCTP
27 select CONFIGFS_FS
28 select DLM
29 help 32 help
30 Multiple node locking module for GFS2 33 Multiple node locking module for GFS2
31 34
32 Most users of GFS2 will require this module. It provides the locking 35 Most users of GFS2 will require this. It provides the locking
33 interface between GFS2 and the DLM, which is required to use GFS2 36 interface between GFS2 and the DLM, which is required to use GFS2
34 in a cluster environment. 37 in a cluster environment.
diff --git a/fs/gfs2/Makefile b/fs/gfs2/Makefile
index c1b4ec6a9650..a851ea4bdf70 100644
--- a/fs/gfs2/Makefile
+++ b/fs/gfs2/Makefile
@@ -1,9 +1,9 @@
1obj-$(CONFIG_GFS2_FS) += gfs2.o 1obj-$(CONFIG_GFS2_FS) += gfs2.o
2gfs2-y := acl.o bmap.o dir.o eaops.o eattr.o glock.o \ 2gfs2-y := acl.o bmap.o dir.o eaops.o eattr.o glock.o \
3 glops.o inode.o log.o lops.o locking.o main.o meta_io.o \ 3 glops.o inode.o log.o lops.o main.o meta_io.o \
4 mount.o ops_address.o ops_dentry.o ops_export.o ops_file.o \ 4 mount.o ops_address.o ops_dentry.o ops_export.o ops_file.o \
5 ops_fstype.o ops_inode.o ops_super.o quota.o \ 5 ops_fstype.o ops_inode.o ops_super.o quota.o \
6 recovery.o rgrp.o super.o sys.o trans.o util.o 6 recovery.o rgrp.o super.o sys.o trans.o util.o
7 7
8obj-$(CONFIG_GFS2_FS_LOCKING_DLM) += locking/dlm/ 8gfs2-$(CONFIG_GFS2_FS_LOCKING_DLM) += lock_dlm.o
9 9
diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c
index e335dceb6a4f..43764f4fa763 100644
--- a/fs/gfs2/acl.c
+++ b/fs/gfs2/acl.c
@@ -15,7 +15,6 @@
15#include <linux/posix_acl.h> 15#include <linux/posix_acl.h>
16#include <linux/posix_acl_xattr.h> 16#include <linux/posix_acl_xattr.h>
17#include <linux/gfs2_ondisk.h> 17#include <linux/gfs2_ondisk.h>
18#include <linux/lm_interface.h>
19 18
20#include "gfs2.h" 19#include "gfs2.h"
21#include "incore.h" 20#include "incore.h"
diff --git a/fs/gfs2/bmap.c b/fs/gfs2/bmap.c
index 11ffc56f1f81..3a5d3f883e10 100644
--- a/fs/gfs2/bmap.c
+++ b/fs/gfs2/bmap.c
@@ -13,7 +13,6 @@
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/gfs2_ondisk.h> 14#include <linux/gfs2_ondisk.h>
15#include <linux/crc32.h> 15#include <linux/crc32.h>
16#include <linux/lm_interface.h>
17 16
18#include "gfs2.h" 17#include "gfs2.h"
19#include "incore.h" 18#include "incore.h"
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index b7c8e5c70791..aef4d0c06748 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -60,7 +60,6 @@
60#include <linux/gfs2_ondisk.h> 60#include <linux/gfs2_ondisk.h>
61#include <linux/crc32.h> 61#include <linux/crc32.h>
62#include <linux/vmalloc.h> 62#include <linux/vmalloc.h>
63#include <linux/lm_interface.h>
64 63
65#include "gfs2.h" 64#include "gfs2.h"
66#include "incore.h" 65#include "incore.h"
diff --git a/fs/gfs2/eaops.c b/fs/gfs2/eaops.c
index f114ba2b3557..dee9b03e5b37 100644
--- a/fs/gfs2/eaops.c
+++ b/fs/gfs2/eaops.c
@@ -14,7 +14,6 @@
14#include <linux/capability.h> 14#include <linux/capability.h>
15#include <linux/xattr.h> 15#include <linux/xattr.h>
16#include <linux/gfs2_ondisk.h> 16#include <linux/gfs2_ondisk.h>
17#include <linux/lm_interface.h>
18#include <asm/uaccess.h> 17#include <asm/uaccess.h>
19 18
20#include "gfs2.h" 19#include "gfs2.h"
diff --git a/fs/gfs2/eattr.c b/fs/gfs2/eattr.c
index 0d1c76d906ae..899763aed217 100644
--- a/fs/gfs2/eattr.c
+++ b/fs/gfs2/eattr.c
@@ -13,7 +13,6 @@
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/xattr.h> 14#include <linux/xattr.h>
15#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
16#include <linux/lm_interface.h>
17#include <asm/uaccess.h> 16#include <asm/uaccess.h>
18 17
19#include "gfs2.h" 18#include "gfs2.h"
diff --git a/fs/gfs2/glock.c b/fs/gfs2/glock.c
index 6b983aef785d..3984e47d1d33 100644
--- a/fs/gfs2/glock.c
+++ b/fs/gfs2/glock.c
@@ -10,7 +10,6 @@
10#include <linux/sched.h> 10#include <linux/sched.h>
11#include <linux/slab.h> 11#include <linux/slab.h>
12#include <linux/spinlock.h> 12#include <linux/spinlock.h>
13#include <linux/completion.h>
14#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
15#include <linux/delay.h> 14#include <linux/delay.h>
16#include <linux/sort.h> 15#include <linux/sort.h>
@@ -18,7 +17,6 @@
18#include <linux/kallsyms.h> 17#include <linux/kallsyms.h>
19#include <linux/gfs2_ondisk.h> 18#include <linux/gfs2_ondisk.h>
20#include <linux/list.h> 19#include <linux/list.h>
21#include <linux/lm_interface.h>
22#include <linux/wait.h> 20#include <linux/wait.h>
23#include <linux/module.h> 21#include <linux/module.h>
24#include <linux/rwsem.h> 22#include <linux/rwsem.h>
@@ -155,13 +153,10 @@ static void glock_free(struct gfs2_glock *gl)
155 struct gfs2_sbd *sdp = gl->gl_sbd; 153 struct gfs2_sbd *sdp = gl->gl_sbd;
156 struct inode *aspace = gl->gl_aspace; 154 struct inode *aspace = gl->gl_aspace;
157 155
158 if (sdp->sd_lockstruct.ls_ops->lm_put_lock)
159 sdp->sd_lockstruct.ls_ops->lm_put_lock(gl->gl_lock);
160
161 if (aspace) 156 if (aspace)
162 gfs2_aspace_put(aspace); 157 gfs2_aspace_put(aspace);
163 158
164 kmem_cache_free(gfs2_glock_cachep, gl); 159 sdp->sd_lockstruct.ls_ops->lm_put_lock(gfs2_glock_cachep, gl);
165} 160}
166 161
167/** 162/**
@@ -172,6 +167,7 @@ static void glock_free(struct gfs2_glock *gl)
172 167
173static void gfs2_glock_hold(struct gfs2_glock *gl) 168static void gfs2_glock_hold(struct gfs2_glock *gl)
174{ 169{
170 GLOCK_BUG_ON(gl, atomic_read(&gl->gl_ref) == 0);
175 atomic_inc(&gl->gl_ref); 171 atomic_inc(&gl->gl_ref);
176} 172}
177 173
@@ -211,17 +207,15 @@ int gfs2_glock_put(struct gfs2_glock *gl)
211 atomic_dec(&lru_count); 207 atomic_dec(&lru_count);
212 } 208 }
213 spin_unlock(&lru_lock); 209 spin_unlock(&lru_lock);
214 GLOCK_BUG_ON(gl, gl->gl_state != LM_ST_UNLOCKED);
215 GLOCK_BUG_ON(gl, !list_empty(&gl->gl_lru));
216 GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders)); 210 GLOCK_BUG_ON(gl, !list_empty(&gl->gl_holders));
217 glock_free(gl); 211 glock_free(gl);
218 rv = 1; 212 rv = 1;
219 goto out; 213 goto out;
220 } 214 }
221 write_unlock(gl_lock_addr(gl->gl_hash));
222 /* 1 for being hashed, 1 for having state != LM_ST_UNLOCKED */ 215 /* 1 for being hashed, 1 for having state != LM_ST_UNLOCKED */
223 if (atomic_read(&gl->gl_ref) == 2) 216 if (atomic_read(&gl->gl_ref) == 2)
224 gfs2_glock_schedule_for_reclaim(gl); 217 gfs2_glock_schedule_for_reclaim(gl);
218 write_unlock(gl_lock_addr(gl->gl_hash));
225out: 219out:
226 return rv; 220 return rv;
227} 221}
@@ -256,27 +250,6 @@ static struct gfs2_glock *search_bucket(unsigned int hash,
256} 250}
257 251
258/** 252/**
259 * gfs2_glock_find() - Find glock by lock number
260 * @sdp: The GFS2 superblock
261 * @name: The lock name
262 *
263 * Returns: NULL, or the struct gfs2_glock with the requested number
264 */
265
266static struct gfs2_glock *gfs2_glock_find(const struct gfs2_sbd *sdp,
267 const struct lm_lockname *name)
268{
269 unsigned int hash = gl_hash(sdp, name);
270 struct gfs2_glock *gl;
271
272 read_lock(gl_lock_addr(hash));
273 gl = search_bucket(hash, sdp, name);
274 read_unlock(gl_lock_addr(hash));
275
276 return gl;
277}
278
279/**
280 * may_grant - check if its ok to grant a new lock 253 * may_grant - check if its ok to grant a new lock
281 * @gl: The glock 254 * @gl: The glock
282 * @gh: The lock request which we wish to grant 255 * @gh: The lock request which we wish to grant
@@ -523,7 +496,7 @@ out_locked:
523} 496}
524 497
525static unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock, 498static unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock,
526 unsigned int cur_state, unsigned int req_state, 499 unsigned int req_state,
527 unsigned int flags) 500 unsigned int flags)
528{ 501{
529 int ret = LM_OUT_ERROR; 502 int ret = LM_OUT_ERROR;
@@ -532,7 +505,7 @@ static unsigned int gfs2_lm_lock(struct gfs2_sbd *sdp, void *lock,
532 return req_state == LM_ST_UNLOCKED ? 0 : req_state; 505 return req_state == LM_ST_UNLOCKED ? 0 : req_state;
533 506
534 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) 507 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
535 ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock, cur_state, 508 ret = sdp->sd_lockstruct.ls_ops->lm_lock(lock,
536 req_state, flags); 509 req_state, flags);
537 return ret; 510 return ret;
538} 511}
@@ -575,7 +548,7 @@ __acquires(&gl->gl_spin)
575 gl->gl_state == LM_ST_DEFERRED) && 548 gl->gl_state == LM_ST_DEFERRED) &&
576 !(lck_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) 549 !(lck_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)))
577 lck_flags |= LM_FLAG_TRY_1CB; 550 lck_flags |= LM_FLAG_TRY_1CB;
578 ret = gfs2_lm_lock(sdp, gl->gl_lock, gl->gl_state, target, lck_flags); 551 ret = gfs2_lm_lock(sdp, gl, target, lck_flags);
579 552
580 if (!(ret & LM_OUT_ASYNC)) { 553 if (!(ret & LM_OUT_ASYNC)) {
581 finish_xmote(gl, ret); 554 finish_xmote(gl, ret);
@@ -624,10 +597,11 @@ __acquires(&gl->gl_spin)
624 597
625 GLOCK_BUG_ON(gl, test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags)); 598 GLOCK_BUG_ON(gl, test_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags));
626 599
600 down_read(&gfs2_umount_flush_sem);
627 if (test_bit(GLF_DEMOTE, &gl->gl_flags) && 601 if (test_bit(GLF_DEMOTE, &gl->gl_flags) &&
628 gl->gl_demote_state != gl->gl_state) { 602 gl->gl_demote_state != gl->gl_state) {
629 if (find_first_holder(gl)) 603 if (find_first_holder(gl))
630 goto out; 604 goto out_unlock;
631 if (nonblock) 605 if (nonblock)
632 goto out_sched; 606 goto out_sched;
633 set_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags); 607 set_bit(GLF_DEMOTE_IN_PROGRESS, &gl->gl_flags);
@@ -638,23 +612,26 @@ __acquires(&gl->gl_spin)
638 gfs2_demote_wake(gl); 612 gfs2_demote_wake(gl);
639 ret = do_promote(gl); 613 ret = do_promote(gl);
640 if (ret == 0) 614 if (ret == 0)
641 goto out; 615 goto out_unlock;
642 if (ret == 2) 616 if (ret == 2)
643 return; 617 goto out_sem;
644 gh = find_first_waiter(gl); 618 gh = find_first_waiter(gl);
645 gl->gl_target = gh->gh_state; 619 gl->gl_target = gh->gh_state;
646 if (!(gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))) 620 if (!(gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB)))
647 do_error(gl, 0); /* Fail queued try locks */ 621 do_error(gl, 0); /* Fail queued try locks */
648 } 622 }
649 do_xmote(gl, gh, gl->gl_target); 623 do_xmote(gl, gh, gl->gl_target);
624out_sem:
625 up_read(&gfs2_umount_flush_sem);
650 return; 626 return;
651 627
652out_sched: 628out_sched:
653 gfs2_glock_hold(gl); 629 gfs2_glock_hold(gl);
654 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0) 630 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
655 gfs2_glock_put(gl); 631 gfs2_glock_put(gl);
656out: 632out_unlock:
657 clear_bit(GLF_LOCK, &gl->gl_flags); 633 clear_bit(GLF_LOCK, &gl->gl_flags);
634 goto out_sem;
658} 635}
659 636
660static void glock_work_func(struct work_struct *work) 637static void glock_work_func(struct work_struct *work)
@@ -681,18 +658,6 @@ static void glock_work_func(struct work_struct *work)
681 gfs2_glock_put(gl); 658 gfs2_glock_put(gl);
682} 659}
683 660
684static int gfs2_lm_get_lock(struct gfs2_sbd *sdp, struct lm_lockname *name,
685 void **lockp)
686{
687 int error = -EIO;
688 if (!sdp->sd_lockstruct.ls_ops->lm_get_lock)
689 return 0;
690 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
691 error = sdp->sd_lockstruct.ls_ops->lm_get_lock(
692 sdp->sd_lockstruct.ls_lockspace, name, lockp);
693 return error;
694}
695
696/** 661/**
697 * gfs2_glock_get() - Get a glock, or create one if one doesn't exist 662 * gfs2_glock_get() - Get a glock, or create one if one doesn't exist
698 * @sdp: The GFS2 superblock 663 * @sdp: The GFS2 superblock
@@ -719,10 +684,11 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
719 gl = search_bucket(hash, sdp, &name); 684 gl = search_bucket(hash, sdp, &name);
720 read_unlock(gl_lock_addr(hash)); 685 read_unlock(gl_lock_addr(hash));
721 686
722 if (gl || !create) { 687 *glp = gl;
723 *glp = gl; 688 if (gl)
724 return 0; 689 return 0;
725 } 690 if (!create)
691 return -ENOENT;
726 692
727 gl = kmem_cache_alloc(gfs2_glock_cachep, GFP_KERNEL); 693 gl = kmem_cache_alloc(gfs2_glock_cachep, GFP_KERNEL);
728 if (!gl) 694 if (!gl)
@@ -736,7 +702,9 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
736 gl->gl_demote_state = LM_ST_EXCLUSIVE; 702 gl->gl_demote_state = LM_ST_EXCLUSIVE;
737 gl->gl_hash = hash; 703 gl->gl_hash = hash;
738 gl->gl_ops = glops; 704 gl->gl_ops = glops;
739 gl->gl_stamp = jiffies; 705 snprintf(gl->gl_strname, GDLM_STRNAME_BYTES, "%8x%16llx", name.ln_type, (unsigned long long)number);
706 memset(&gl->gl_lksb, 0, sizeof(struct dlm_lksb));
707 gl->gl_lksb.sb_lvbptr = gl->gl_lvb;
740 gl->gl_tchange = jiffies; 708 gl->gl_tchange = jiffies;
741 gl->gl_object = NULL; 709 gl->gl_object = NULL;
742 gl->gl_sbd = sdp; 710 gl->gl_sbd = sdp;
@@ -753,10 +721,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
753 } 721 }
754 } 722 }
755 723
756 error = gfs2_lm_get_lock(sdp, &name, &gl->gl_lock);
757 if (error)
758 goto fail_aspace;
759
760 write_lock(gl_lock_addr(hash)); 724 write_lock(gl_lock_addr(hash));
761 tmp = search_bucket(hash, sdp, &name); 725 tmp = search_bucket(hash, sdp, &name);
762 if (tmp) { 726 if (tmp) {
@@ -772,9 +736,6 @@ int gfs2_glock_get(struct gfs2_sbd *sdp, u64 number,
772 736
773 return 0; 737 return 0;
774 738
775fail_aspace:
776 if (gl->gl_aspace)
777 gfs2_aspace_put(gl->gl_aspace);
778fail: 739fail:
779 kmem_cache_free(gfs2_glock_cachep, gl); 740 kmem_cache_free(gfs2_glock_cachep, gl);
780 return error; 741 return error;
@@ -966,7 +927,7 @@ do_cancel:
966 if (!(gh->gh_flags & LM_FLAG_PRIORITY)) { 927 if (!(gh->gh_flags & LM_FLAG_PRIORITY)) {
967 spin_unlock(&gl->gl_spin); 928 spin_unlock(&gl->gl_spin);
968 if (sdp->sd_lockstruct.ls_ops->lm_cancel) 929 if (sdp->sd_lockstruct.ls_ops->lm_cancel)
969 sdp->sd_lockstruct.ls_ops->lm_cancel(gl->gl_lock); 930 sdp->sd_lockstruct.ls_ops->lm_cancel(gl);
970 spin_lock(&gl->gl_spin); 931 spin_lock(&gl->gl_spin);
971 } 932 }
972 return; 933 return;
@@ -1051,7 +1012,6 @@ void gfs2_glock_dq(struct gfs2_holder *gh)
1051 spin_lock(&gl->gl_spin); 1012 spin_lock(&gl->gl_spin);
1052 clear_bit(GLF_LOCK, &gl->gl_flags); 1013 clear_bit(GLF_LOCK, &gl->gl_flags);
1053 } 1014 }
1054 gl->gl_stamp = jiffies;
1055 if (list_empty(&gl->gl_holders) && 1015 if (list_empty(&gl->gl_holders) &&
1056 !test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) && 1016 !test_bit(GLF_PENDING_DEMOTE, &gl->gl_flags) &&
1057 !test_bit(GLF_DEMOTE, &gl->gl_flags)) 1017 !test_bit(GLF_DEMOTE, &gl->gl_flags))
@@ -1240,70 +1200,13 @@ void gfs2_glock_dq_uninit_m(unsigned int num_gh, struct gfs2_holder *ghs)
1240 gfs2_glock_dq_uninit(&ghs[x]); 1200 gfs2_glock_dq_uninit(&ghs[x]);
1241} 1201}
1242 1202
1243static int gfs2_lm_hold_lvb(struct gfs2_sbd *sdp, void *lock, char **lvbp) 1203void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
1244{
1245 int error = -EIO;
1246 if (!sdp->sd_lockstruct.ls_ops->lm_hold_lvb)
1247 return 0;
1248 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
1249 error = sdp->sd_lockstruct.ls_ops->lm_hold_lvb(lock, lvbp);
1250 return error;
1251}
1252
1253/**
1254 * gfs2_lvb_hold - attach a LVB from a glock
1255 * @gl: The glock in question
1256 *
1257 */
1258
1259int gfs2_lvb_hold(struct gfs2_glock *gl)
1260{
1261 int error;
1262
1263 if (!atomic_read(&gl->gl_lvb_count)) {
1264 error = gfs2_lm_hold_lvb(gl->gl_sbd, gl->gl_lock, &gl->gl_lvb);
1265 if (error)
1266 return error;
1267 gfs2_glock_hold(gl);
1268 }
1269 atomic_inc(&gl->gl_lvb_count);
1270
1271 return 0;
1272}
1273
1274/**
1275 * gfs2_lvb_unhold - detach a LVB from a glock
1276 * @gl: The glock in question
1277 *
1278 */
1279
1280void gfs2_lvb_unhold(struct gfs2_glock *gl)
1281{
1282 struct gfs2_sbd *sdp = gl->gl_sbd;
1283
1284 gfs2_glock_hold(gl);
1285 gfs2_assert(gl->gl_sbd, atomic_read(&gl->gl_lvb_count) > 0);
1286 if (atomic_dec_and_test(&gl->gl_lvb_count)) {
1287 if (sdp->sd_lockstruct.ls_ops->lm_unhold_lvb)
1288 sdp->sd_lockstruct.ls_ops->lm_unhold_lvb(gl->gl_lock, gl->gl_lvb);
1289 gl->gl_lvb = NULL;
1290 gfs2_glock_put(gl);
1291 }
1292 gfs2_glock_put(gl);
1293}
1294
1295static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name,
1296 unsigned int state)
1297{ 1204{
1298 struct gfs2_glock *gl;
1299 unsigned long delay = 0; 1205 unsigned long delay = 0;
1300 unsigned long holdtime; 1206 unsigned long holdtime;
1301 unsigned long now = jiffies; 1207 unsigned long now = jiffies;
1302 1208
1303 gl = gfs2_glock_find(sdp, name); 1209 gfs2_glock_hold(gl);
1304 if (!gl)
1305 return;
1306
1307 holdtime = gl->gl_tchange + gl->gl_ops->go_min_hold_time; 1210 holdtime = gl->gl_tchange + gl->gl_ops->go_min_hold_time;
1308 if (time_before(now, holdtime)) 1211 if (time_before(now, holdtime))
1309 delay = holdtime - now; 1212 delay = holdtime - now;
@@ -1317,74 +1220,33 @@ static void blocking_cb(struct gfs2_sbd *sdp, struct lm_lockname *name,
1317 gfs2_glock_put(gl); 1220 gfs2_glock_put(gl);
1318} 1221}
1319 1222
1320static void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid)
1321{
1322 struct gfs2_jdesc *jd;
1323
1324 spin_lock(&sdp->sd_jindex_spin);
1325 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
1326 if (jd->jd_jid != jid)
1327 continue;
1328 jd->jd_dirty = 1;
1329 break;
1330 }
1331 spin_unlock(&sdp->sd_jindex_spin);
1332}
1333
1334/** 1223/**
1335 * gfs2_glock_cb - Callback used by locking module 1224 * gfs2_glock_complete - Callback used by locking
1336 * @sdp: Pointer to the superblock 1225 * @gl: Pointer to the glock
1337 * @type: Type of callback 1226 * @ret: The return value from the dlm
1338 * @data: Type dependent data pointer
1339 * 1227 *
1340 * Called by the locking module when it wants to tell us something.
1341 * Either we need to drop a lock, one of our ASYNC requests completed, or
1342 * a journal from another client needs to be recovered.
1343 */ 1228 */
1344 1229
1345void gfs2_glock_cb(void *cb_data, unsigned int type, void *data) 1230void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
1346{ 1231{
1347 struct gfs2_sbd *sdp = cb_data; 1232 struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
1348 1233 gl->gl_reply = ret;
1349 switch (type) { 1234 if (unlikely(test_bit(DFL_BLOCK_LOCKS, &ls->ls_flags))) {
1350 case LM_CB_NEED_E: 1235 struct gfs2_holder *gh;
1351 blocking_cb(sdp, data, LM_ST_UNLOCKED); 1236 spin_lock(&gl->gl_spin);
1352 return; 1237 gh = find_first_waiter(gl);
1353 1238 if ((!(gh && (gh->gh_flags & LM_FLAG_NOEXP)) &&
1354 case LM_CB_NEED_D: 1239 (gl->gl_target != LM_ST_UNLOCKED)) ||
1355 blocking_cb(sdp, data, LM_ST_DEFERRED); 1240 ((ret & ~LM_OUT_ST_MASK) != 0))
1356 return; 1241 set_bit(GLF_FROZEN, &gl->gl_flags);
1357 1242 spin_unlock(&gl->gl_spin);
1358 case LM_CB_NEED_S: 1243 if (test_bit(GLF_FROZEN, &gl->gl_flags))
1359 blocking_cb(sdp, data, LM_ST_SHARED);
1360 return;
1361
1362 case LM_CB_ASYNC: {
1363 struct lm_async_cb *async = data;
1364 struct gfs2_glock *gl;
1365
1366 down_read(&gfs2_umount_flush_sem);
1367 gl = gfs2_glock_find(sdp, &async->lc_name);
1368 if (gfs2_assert_warn(sdp, gl))
1369 return; 1244 return;
1370 gl->gl_reply = async->lc_ret;
1371 set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1372 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
1373 gfs2_glock_put(gl);
1374 up_read(&gfs2_umount_flush_sem);
1375 return;
1376 }
1377
1378 case LM_CB_NEED_RECOVERY:
1379 gfs2_jdesc_make_dirty(sdp, *(unsigned int *)data);
1380 if (sdp->sd_recoverd_process)
1381 wake_up_process(sdp->sd_recoverd_process);
1382 return;
1383
1384 default:
1385 gfs2_assert_warn(sdp, 0);
1386 return;
1387 } 1245 }
1246 set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1247 gfs2_glock_hold(gl);
1248 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
1249 gfs2_glock_put(gl);
1388} 1250}
1389 1251
1390/** 1252/**
@@ -1515,6 +1377,25 @@ out:
1515 return has_entries; 1377 return has_entries;
1516} 1378}
1517 1379
1380
1381/**
1382 * thaw_glock - thaw out a glock which has an unprocessed reply waiting
1383 * @gl: The glock to thaw
1384 *
1385 * N.B. When we freeze a glock, we leave a ref to the glock outstanding,
1386 * so this has to result in the ref count being dropped by one.
1387 */
1388
1389static void thaw_glock(struct gfs2_glock *gl)
1390{
1391 if (!test_and_clear_bit(GLF_FROZEN, &gl->gl_flags))
1392 return;
1393 set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
1394 gfs2_glock_hold(gl);
1395 if (queue_delayed_work(glock_workqueue, &gl->gl_work, 0) == 0)
1396 gfs2_glock_put(gl);
1397}
1398
1518/** 1399/**
1519 * clear_glock - look at a glock and see if we can free it from glock cache 1400 * clear_glock - look at a glock and see if we can free it from glock cache
1520 * @gl: the glock to look at 1401 * @gl: the glock to look at
@@ -1540,6 +1421,20 @@ static void clear_glock(struct gfs2_glock *gl)
1540} 1421}
1541 1422
1542/** 1423/**
1424 * gfs2_glock_thaw - Thaw any frozen glocks
1425 * @sdp: The super block
1426 *
1427 */
1428
1429void gfs2_glock_thaw(struct gfs2_sbd *sdp)
1430{
1431 unsigned x;
1432
1433 for (x = 0; x < GFS2_GL_HASH_SIZE; x++)
1434 examine_bucket(thaw_glock, sdp, x);
1435}
1436
1437/**
1543 * gfs2_gl_hash_clear - Empty out the glock hash table 1438 * gfs2_gl_hash_clear - Empty out the glock hash table
1544 * @sdp: the filesystem 1439 * @sdp: the filesystem
1545 * @wait: wait until it's all gone 1440 * @wait: wait until it's all gone
@@ -1619,7 +1514,7 @@ static const char *hflags2str(char *buf, unsigned flags, unsigned long iflags)
1619 if (flags & LM_FLAG_NOEXP) 1514 if (flags & LM_FLAG_NOEXP)
1620 *p++ = 'e'; 1515 *p++ = 'e';
1621 if (flags & LM_FLAG_ANY) 1516 if (flags & LM_FLAG_ANY)
1622 *p++ = 'a'; 1517 *p++ = 'A';
1623 if (flags & LM_FLAG_PRIORITY) 1518 if (flags & LM_FLAG_PRIORITY)
1624 *p++ = 'p'; 1519 *p++ = 'p';
1625 if (flags & GL_ASYNC) 1520 if (flags & GL_ASYNC)
@@ -1683,6 +1578,10 @@ static const char *gflags2str(char *buf, const unsigned long *gflags)
1683 *p++ = 'i'; 1578 *p++ = 'i';
1684 if (test_bit(GLF_REPLY_PENDING, gflags)) 1579 if (test_bit(GLF_REPLY_PENDING, gflags))
1685 *p++ = 'r'; 1580 *p++ = 'r';
1581 if (test_bit(GLF_INITIAL, gflags))
1582 *p++ = 'I';
1583 if (test_bit(GLF_FROZEN, gflags))
1584 *p++ = 'F';
1686 *p = 0; 1585 *p = 0;
1687 return buf; 1586 return buf;
1688} 1587}
@@ -1717,14 +1616,13 @@ static int __dump_glock(struct seq_file *seq, const struct gfs2_glock *gl)
1717 dtime *= 1000000/HZ; /* demote time in uSec */ 1616 dtime *= 1000000/HZ; /* demote time in uSec */
1718 if (!test_bit(GLF_DEMOTE, &gl->gl_flags)) 1617 if (!test_bit(GLF_DEMOTE, &gl->gl_flags))
1719 dtime = 0; 1618 dtime = 0;
1720 gfs2_print_dbg(seq, "G: s:%s n:%u/%llu f:%s t:%s d:%s/%llu l:%d a:%d r:%d\n", 1619 gfs2_print_dbg(seq, "G: s:%s n:%u/%llu f:%s t:%s d:%s/%llu a:%d r:%d\n",
1721 state2str(gl->gl_state), 1620 state2str(gl->gl_state),
1722 gl->gl_name.ln_type, 1621 gl->gl_name.ln_type,
1723 (unsigned long long)gl->gl_name.ln_number, 1622 (unsigned long long)gl->gl_name.ln_number,
1724 gflags2str(gflags_buf, &gl->gl_flags), 1623 gflags2str(gflags_buf, &gl->gl_flags),
1725 state2str(gl->gl_target), 1624 state2str(gl->gl_target),
1726 state2str(gl->gl_demote_state), dtime, 1625 state2str(gl->gl_demote_state), dtime,
1727 atomic_read(&gl->gl_lvb_count),
1728 atomic_read(&gl->gl_ail_count), 1626 atomic_read(&gl->gl_ail_count),
1729 atomic_read(&gl->gl_ref)); 1627 atomic_read(&gl->gl_ref));
1730 1628
diff --git a/fs/gfs2/glock.h b/fs/gfs2/glock.h
index 543ec7ecfbda..a602a28f6f08 100644
--- a/fs/gfs2/glock.h
+++ b/fs/gfs2/glock.h
@@ -11,15 +11,130 @@
11#define __GLOCK_DOT_H__ 11#define __GLOCK_DOT_H__
12 12
13#include <linux/sched.h> 13#include <linux/sched.h>
14#include <linux/parser.h>
14#include "incore.h" 15#include "incore.h"
15 16
16/* Flags for lock requests; used in gfs2_holder gh_flag field. 17/* Options for hostdata parser */
17 From lm_interface.h: 18
19enum {
20 Opt_jid,
21 Opt_id,
22 Opt_first,
23 Opt_nodir,
24 Opt_err,
25};
26
27/*
28 * lm_lockname types
29 */
30
31#define LM_TYPE_RESERVED 0x00
32#define LM_TYPE_NONDISK 0x01
33#define LM_TYPE_INODE 0x02
34#define LM_TYPE_RGRP 0x03
35#define LM_TYPE_META 0x04
36#define LM_TYPE_IOPEN 0x05
37#define LM_TYPE_FLOCK 0x06
38#define LM_TYPE_PLOCK 0x07
39#define LM_TYPE_QUOTA 0x08
40#define LM_TYPE_JOURNAL 0x09
41
42/*
43 * lm_lock() states
44 *
45 * SHARED is compatible with SHARED, not with DEFERRED or EX.
46 * DEFERRED is compatible with DEFERRED, not with SHARED or EX.
47 */
48
49#define LM_ST_UNLOCKED 0
50#define LM_ST_EXCLUSIVE 1
51#define LM_ST_DEFERRED 2
52#define LM_ST_SHARED 3
53
54/*
55 * lm_lock() flags
56 *
57 * LM_FLAG_TRY
58 * Don't wait to acquire the lock if it can't be granted immediately.
59 *
60 * LM_FLAG_TRY_1CB
61 * Send one blocking callback if TRY is set and the lock is not granted.
62 *
63 * LM_FLAG_NOEXP
64 * GFS sets this flag on lock requests it makes while doing journal recovery.
65 * These special requests should not be blocked due to the recovery like
66 * ordinary locks would be.
67 *
68 * LM_FLAG_ANY
69 * A SHARED request may also be granted in DEFERRED, or a DEFERRED request may
70 * also be granted in SHARED. The preferred state is whichever is compatible
71 * with other granted locks, or the specified state if no other locks exist.
72 *
73 * LM_FLAG_PRIORITY
74 * Override fairness considerations. Suppose a lock is held in a shared state
75 * and there is a pending request for the deferred state. A shared lock
76 * request with the priority flag would be allowed to bypass the deferred
77 * request and directly join the other shared lock. A shared lock request
78 * without the priority flag might be forced to wait until the deferred
79 * requested had acquired and released the lock.
80 */
81
18#define LM_FLAG_TRY 0x00000001 82#define LM_FLAG_TRY 0x00000001
19#define LM_FLAG_TRY_1CB 0x00000002 83#define LM_FLAG_TRY_1CB 0x00000002
20#define LM_FLAG_NOEXP 0x00000004 84#define LM_FLAG_NOEXP 0x00000004
21#define LM_FLAG_ANY 0x00000008 85#define LM_FLAG_ANY 0x00000008
22#define LM_FLAG_PRIORITY 0x00000010 */ 86#define LM_FLAG_PRIORITY 0x00000010
87#define GL_ASYNC 0x00000040
88#define GL_EXACT 0x00000080
89#define GL_SKIP 0x00000100
90#define GL_ATIME 0x00000200
91#define GL_NOCACHE 0x00000400
92
93/*
94 * lm_lock() and lm_async_cb return flags
95 *
96 * LM_OUT_ST_MASK
97 * Masks the lower two bits of lock state in the returned value.
98 *
99 * LM_OUT_CANCELED
100 * The lock request was canceled.
101 *
102 * LM_OUT_ASYNC
103 * The result of the request will be returned in an LM_CB_ASYNC callback.
104 *
105 */
106
107#define LM_OUT_ST_MASK 0x00000003
108#define LM_OUT_CANCELED 0x00000008
109#define LM_OUT_ASYNC 0x00000080
110#define LM_OUT_ERROR 0x00000100
111
112/*
113 * lm_recovery_done() messages
114 */
115
116#define LM_RD_GAVEUP 308
117#define LM_RD_SUCCESS 309
118
119#define GLR_TRYFAILED 13
120
121struct lm_lockops {
122 const char *lm_proto_name;
123 int (*lm_mount) (struct gfs2_sbd *sdp, const char *fsname);
124 void (*lm_unmount) (struct gfs2_sbd *sdp);
125 void (*lm_withdraw) (struct gfs2_sbd *sdp);
126 void (*lm_put_lock) (struct kmem_cache *cachep, void *gl);
127 unsigned int (*lm_lock) (struct gfs2_glock *gl,
128 unsigned int req_state, unsigned int flags);
129 void (*lm_cancel) (struct gfs2_glock *gl);
130 const match_table_t *lm_tokens;
131};
132
133#define LM_FLAG_TRY 0x00000001
134#define LM_FLAG_TRY_1CB 0x00000002
135#define LM_FLAG_NOEXP 0x00000004
136#define LM_FLAG_ANY 0x00000008
137#define LM_FLAG_PRIORITY 0x00000010
23 138
24#define GL_ASYNC 0x00000040 139#define GL_ASYNC 0x00000040
25#define GL_EXACT 0x00000080 140#define GL_EXACT 0x00000080
@@ -128,10 +243,12 @@ static inline int gfs2_glock_nq_init(struct gfs2_glock *gl,
128int gfs2_lvb_hold(struct gfs2_glock *gl); 243int gfs2_lvb_hold(struct gfs2_glock *gl);
129void gfs2_lvb_unhold(struct gfs2_glock *gl); 244void gfs2_lvb_unhold(struct gfs2_glock *gl);
130 245
131void gfs2_glock_cb(void *cb_data, unsigned int type, void *data); 246void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state);
247void gfs2_glock_complete(struct gfs2_glock *gl, int ret);
132void gfs2_reclaim_glock(struct gfs2_sbd *sdp); 248void gfs2_reclaim_glock(struct gfs2_sbd *sdp);
133void gfs2_gl_hash_clear(struct gfs2_sbd *sdp); 249void gfs2_gl_hash_clear(struct gfs2_sbd *sdp);
134void gfs2_glock_finish_truncate(struct gfs2_inode *ip); 250void gfs2_glock_finish_truncate(struct gfs2_inode *ip);
251void gfs2_glock_thaw(struct gfs2_sbd *sdp);
135 252
136int __init gfs2_glock_init(void); 253int __init gfs2_glock_init(void);
137void gfs2_glock_exit(void); 254void gfs2_glock_exit(void);
@@ -141,4 +258,6 @@ void gfs2_delete_debugfs_file(struct gfs2_sbd *sdp);
141int gfs2_register_debugfs(void); 258int gfs2_register_debugfs(void);
142void gfs2_unregister_debugfs(void); 259void gfs2_unregister_debugfs(void);
143 260
261extern const struct lm_lockops gfs2_dlm_ops;
262
144#endif /* __GLOCK_DOT_H__ */ 263#endif /* __GLOCK_DOT_H__ */
diff --git a/fs/gfs2/glops.c b/fs/gfs2/glops.c
index 8522d3aa64fc..bf23a62aa925 100644
--- a/fs/gfs2/glops.c
+++ b/fs/gfs2/glops.c
@@ -12,7 +12,6 @@
12#include <linux/completion.h> 12#include <linux/completion.h>
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/gfs2_ondisk.h> 14#include <linux/gfs2_ondisk.h>
15#include <linux/lm_interface.h>
16#include <linux/bio.h> 15#include <linux/bio.h>
17 16
18#include "gfs2.h" 17#include "gfs2.h"
@@ -38,20 +37,25 @@
38static void gfs2_ail_empty_gl(struct gfs2_glock *gl) 37static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
39{ 38{
40 struct gfs2_sbd *sdp = gl->gl_sbd; 39 struct gfs2_sbd *sdp = gl->gl_sbd;
41 unsigned int blocks;
42 struct list_head *head = &gl->gl_ail_list; 40 struct list_head *head = &gl->gl_ail_list;
43 struct gfs2_bufdata *bd; 41 struct gfs2_bufdata *bd;
44 struct buffer_head *bh; 42 struct buffer_head *bh;
45 int error; 43 struct gfs2_trans tr;
46 44
47 blocks = atomic_read(&gl->gl_ail_count); 45 memset(&tr, 0, sizeof(tr));
48 if (!blocks) 46 tr.tr_revokes = atomic_read(&gl->gl_ail_count);
49 return;
50 47
51 error = gfs2_trans_begin(sdp, 0, blocks); 48 if (!tr.tr_revokes)
52 if (gfs2_assert_withdraw(sdp, !error))
53 return; 49 return;
54 50
51 /* A shortened, inline version of gfs2_trans_begin() */
52 tr.tr_reserved = 1 + gfs2_struct2blk(sdp, tr.tr_revokes, sizeof(u64));
53 tr.tr_ip = (unsigned long)__builtin_return_address(0);
54 INIT_LIST_HEAD(&tr.tr_list_buf);
55 gfs2_log_reserve(sdp, tr.tr_reserved);
56 BUG_ON(current->journal_info);
57 current->journal_info = &tr;
58
55 gfs2_log_lock(sdp); 59 gfs2_log_lock(sdp);
56 while (!list_empty(head)) { 60 while (!list_empty(head)) {
57 bd = list_entry(head->next, struct gfs2_bufdata, 61 bd = list_entry(head->next, struct gfs2_bufdata,
@@ -72,29 +76,7 @@ static void gfs2_ail_empty_gl(struct gfs2_glock *gl)
72} 76}
73 77
74/** 78/**
75 * gfs2_pte_inval - Sync and invalidate all PTEs associated with a glock 79 * rgrp_go_sync - sync out the metadata for this glock
76 * @gl: the glock
77 *
78 */
79
80static void gfs2_pte_inval(struct gfs2_glock *gl)
81{
82 struct gfs2_inode *ip;
83 struct inode *inode;
84
85 ip = gl->gl_object;
86 inode = &ip->i_inode;
87 if (!ip || !S_ISREG(inode->i_mode))
88 return;
89
90 unmap_shared_mapping_range(inode->i_mapping, 0, 0);
91 if (test_bit(GIF_SW_PAGED, &ip->i_flags))
92 set_bit(GLF_DIRTY, &gl->gl_flags);
93
94}
95
96/**
97 * meta_go_sync - sync out the metadata for this glock
98 * @gl: the glock 80 * @gl: the glock
99 * 81 *
100 * Called when demoting or unlocking an EX glock. We must flush 82 * Called when demoting or unlocking an EX glock. We must flush
@@ -102,36 +84,42 @@ static void gfs2_pte_inval(struct gfs2_glock *gl)
102 * not return to caller to demote/unlock the glock until I/O is complete. 84 * not return to caller to demote/unlock the glock until I/O is complete.
103 */ 85 */
104 86
105static void meta_go_sync(struct gfs2_glock *gl) 87static void rgrp_go_sync(struct gfs2_glock *gl)
106{ 88{
107 if (gl->gl_state != LM_ST_EXCLUSIVE) 89 struct address_space *metamapping = gl->gl_aspace->i_mapping;
90 int error;
91
92 if (!test_and_clear_bit(GLF_DIRTY, &gl->gl_flags))
108 return; 93 return;
94 BUG_ON(gl->gl_state != LM_ST_EXCLUSIVE);
109 95
110 if (test_and_clear_bit(GLF_DIRTY, &gl->gl_flags)) { 96 gfs2_log_flush(gl->gl_sbd, gl);
111 gfs2_log_flush(gl->gl_sbd, gl); 97 filemap_fdatawrite(metamapping);
112 gfs2_meta_sync(gl); 98 error = filemap_fdatawait(metamapping);
113 gfs2_ail_empty_gl(gl); 99 mapping_set_error(metamapping, error);
114 } 100 gfs2_ail_empty_gl(gl);
115} 101}
116 102
117/** 103/**
118 * meta_go_inval - invalidate the metadata for this glock 104 * rgrp_go_inval - invalidate the metadata for this glock
119 * @gl: the glock 105 * @gl: the glock
120 * @flags: 106 * @flags:
121 * 107 *
108 * We never used LM_ST_DEFERRED with resource groups, so that we
109 * should always see the metadata flag set here.
110 *
122 */ 111 */
123 112
124static void meta_go_inval(struct gfs2_glock *gl, int flags) 113static void rgrp_go_inval(struct gfs2_glock *gl, int flags)
125{ 114{
126 if (!(flags & DIO_METADATA)) 115 struct address_space *mapping = gl->gl_aspace->i_mapping;
127 return;
128 116
129 gfs2_meta_inval(gl); 117 BUG_ON(!(flags & DIO_METADATA));
130 if (gl->gl_object == GFS2_I(gl->gl_sbd->sd_rindex)) 118 gfs2_assert_withdraw(gl->gl_sbd, !atomic_read(&gl->gl_ail_count));
131 gl->gl_sbd->sd_rindex_uptodate = 0; 119 truncate_inode_pages(mapping, 0);
132 else if (gl->gl_ops == &gfs2_rgrp_glops && gl->gl_object) {
133 struct gfs2_rgrpd *rgd = (struct gfs2_rgrpd *)gl->gl_object;
134 120
121 if (gl->gl_object) {
122 struct gfs2_rgrpd *rgd = (struct gfs2_rgrpd *)gl->gl_object;
135 rgd->rd_flags &= ~GFS2_RDF_UPTODATE; 123 rgd->rd_flags &= ~GFS2_RDF_UPTODATE;
136 } 124 }
137} 125}
@@ -148,48 +136,54 @@ static void inode_go_sync(struct gfs2_glock *gl)
148 struct address_space *metamapping = gl->gl_aspace->i_mapping; 136 struct address_space *metamapping = gl->gl_aspace->i_mapping;
149 int error; 137 int error;
150 138
151 if (gl->gl_state != LM_ST_UNLOCKED)
152 gfs2_pte_inval(gl);
153 if (gl->gl_state != LM_ST_EXCLUSIVE)
154 return;
155
156 if (ip && !S_ISREG(ip->i_inode.i_mode)) 139 if (ip && !S_ISREG(ip->i_inode.i_mode))
157 ip = NULL; 140 ip = NULL;
141 if (ip && test_and_clear_bit(GIF_SW_PAGED, &ip->i_flags))
142 unmap_shared_mapping_range(ip->i_inode.i_mapping, 0, 0);
143 if (!test_and_clear_bit(GLF_DIRTY, &gl->gl_flags))
144 return;
158 145
159 if (test_bit(GLF_DIRTY, &gl->gl_flags)) { 146 BUG_ON(gl->gl_state != LM_ST_EXCLUSIVE);
160 gfs2_log_flush(gl->gl_sbd, gl); 147
161 filemap_fdatawrite(metamapping); 148 gfs2_log_flush(gl->gl_sbd, gl);
162 if (ip) { 149 filemap_fdatawrite(metamapping);
163 struct address_space *mapping = ip->i_inode.i_mapping; 150 if (ip) {
164 filemap_fdatawrite(mapping); 151 struct address_space *mapping = ip->i_inode.i_mapping;
165 error = filemap_fdatawait(mapping); 152 filemap_fdatawrite(mapping);
166 mapping_set_error(mapping, error); 153 error = filemap_fdatawait(mapping);
167 } 154 mapping_set_error(mapping, error);
168 error = filemap_fdatawait(metamapping);
169 mapping_set_error(metamapping, error);
170 clear_bit(GLF_DIRTY, &gl->gl_flags);
171 gfs2_ail_empty_gl(gl);
172 } 155 }
156 error = filemap_fdatawait(metamapping);
157 mapping_set_error(metamapping, error);
158 gfs2_ail_empty_gl(gl);
173} 159}
174 160
175/** 161/**
176 * inode_go_inval - prepare a inode glock to be released 162 * inode_go_inval - prepare a inode glock to be released
177 * @gl: the glock 163 * @gl: the glock
178 * @flags: 164 * @flags:
165 *
166 * Normally we invlidate everything, but if we are moving into
167 * LM_ST_DEFERRED from LM_ST_SHARED or LM_ST_EXCLUSIVE then we
168 * can keep hold of the metadata, since it won't have changed.
179 * 169 *
180 */ 170 */
181 171
182static void inode_go_inval(struct gfs2_glock *gl, int flags) 172static void inode_go_inval(struct gfs2_glock *gl, int flags)
183{ 173{
184 struct gfs2_inode *ip = gl->gl_object; 174 struct gfs2_inode *ip = gl->gl_object;
185 int meta = (flags & DIO_METADATA);
186 175
187 if (meta) { 176 gfs2_assert_withdraw(gl->gl_sbd, !atomic_read(&gl->gl_ail_count));
188 gfs2_meta_inval(gl); 177
178 if (flags & DIO_METADATA) {
179 struct address_space *mapping = gl->gl_aspace->i_mapping;
180 truncate_inode_pages(mapping, 0);
189 if (ip) 181 if (ip)
190 set_bit(GIF_INVALID, &ip->i_flags); 182 set_bit(GIF_INVALID, &ip->i_flags);
191 } 183 }
192 184
185 if (ip == GFS2_I(gl->gl_sbd->sd_rindex))
186 gl->gl_sbd->sd_rindex_uptodate = 0;
193 if (ip && S_ISREG(ip->i_inode.i_mode)) 187 if (ip && S_ISREG(ip->i_inode.i_mode))
194 truncate_inode_pages(ip->i_inode.i_mapping, 0); 188 truncate_inode_pages(ip->i_inode.i_mapping, 0);
195} 189}
@@ -390,20 +384,7 @@ static int trans_go_demote_ok(const struct gfs2_glock *gl)
390 return 0; 384 return 0;
391} 385}
392 386
393/**
394 * quota_go_demote_ok - Check to see if it's ok to unlock a quota glock
395 * @gl: the glock
396 *
397 * Returns: 1 if it's ok
398 */
399
400static int quota_go_demote_ok(const struct gfs2_glock *gl)
401{
402 return !atomic_read(&gl->gl_lvb_count);
403}
404
405const struct gfs2_glock_operations gfs2_meta_glops = { 387const struct gfs2_glock_operations gfs2_meta_glops = {
406 .go_xmote_th = meta_go_sync,
407 .go_type = LM_TYPE_META, 388 .go_type = LM_TYPE_META,
408}; 389};
409 390
@@ -418,8 +399,8 @@ const struct gfs2_glock_operations gfs2_inode_glops = {
418}; 399};
419 400
420const struct gfs2_glock_operations gfs2_rgrp_glops = { 401const struct gfs2_glock_operations gfs2_rgrp_glops = {
421 .go_xmote_th = meta_go_sync, 402 .go_xmote_th = rgrp_go_sync,
422 .go_inval = meta_go_inval, 403 .go_inval = rgrp_go_inval,
423 .go_demote_ok = rgrp_go_demote_ok, 404 .go_demote_ok = rgrp_go_demote_ok,
424 .go_lock = rgrp_go_lock, 405 .go_lock = rgrp_go_lock,
425 .go_unlock = rgrp_go_unlock, 406 .go_unlock = rgrp_go_unlock,
@@ -448,7 +429,6 @@ const struct gfs2_glock_operations gfs2_nondisk_glops = {
448}; 429};
449 430
450const struct gfs2_glock_operations gfs2_quota_glops = { 431const struct gfs2_glock_operations gfs2_quota_glops = {
451 .go_demote_ok = quota_go_demote_ok,
452 .go_type = LM_TYPE_QUOTA, 432 .go_type = LM_TYPE_QUOTA,
453}; 433};
454 434
@@ -456,3 +436,15 @@ const struct gfs2_glock_operations gfs2_journal_glops = {
456 .go_type = LM_TYPE_JOURNAL, 436 .go_type = LM_TYPE_JOURNAL,
457}; 437};
458 438
439const struct gfs2_glock_operations *gfs2_glops_list[] = {
440 [LM_TYPE_META] = &gfs2_meta_glops,
441 [LM_TYPE_INODE] = &gfs2_inode_glops,
442 [LM_TYPE_RGRP] = &gfs2_rgrp_glops,
443 [LM_TYPE_NONDISK] = &gfs2_trans_glops,
444 [LM_TYPE_IOPEN] = &gfs2_iopen_glops,
445 [LM_TYPE_FLOCK] = &gfs2_flock_glops,
446 [LM_TYPE_NONDISK] = &gfs2_nondisk_glops,
447 [LM_TYPE_QUOTA] = &gfs2_quota_glops,
448 [LM_TYPE_JOURNAL] = &gfs2_journal_glops,
449};
450
diff --git a/fs/gfs2/glops.h b/fs/gfs2/glops.h
index a1d9b5b024e6..b3aa2e3210fd 100644
--- a/fs/gfs2/glops.h
+++ b/fs/gfs2/glops.h
@@ -21,5 +21,6 @@ extern const struct gfs2_glock_operations gfs2_flock_glops;
21extern const struct gfs2_glock_operations gfs2_nondisk_glops; 21extern const struct gfs2_glock_operations gfs2_nondisk_glops;
22extern const struct gfs2_glock_operations gfs2_quota_glops; 22extern const struct gfs2_glock_operations gfs2_quota_glops;
23extern const struct gfs2_glock_operations gfs2_journal_glops; 23extern const struct gfs2_glock_operations gfs2_journal_glops;
24extern const struct gfs2_glock_operations *gfs2_glops_list[];
24 25
25#endif /* __GLOPS_DOT_H__ */ 26#endif /* __GLOPS_DOT_H__ */
diff --git a/fs/gfs2/incore.h b/fs/gfs2/incore.h
index 608849d00021..399d1b978049 100644
--- a/fs/gfs2/incore.h
+++ b/fs/gfs2/incore.h
@@ -12,6 +12,8 @@
12 12
13#include <linux/fs.h> 13#include <linux/fs.h>
14#include <linux/workqueue.h> 14#include <linux/workqueue.h>
15#include <linux/dlm.h>
16#include <linux/buffer_head.h>
15 17
16#define DIO_WAIT 0x00000010 18#define DIO_WAIT 0x00000010
17#define DIO_METADATA 0x00000020 19#define DIO_METADATA 0x00000020
@@ -26,6 +28,7 @@ struct gfs2_trans;
26struct gfs2_ail; 28struct gfs2_ail;
27struct gfs2_jdesc; 29struct gfs2_jdesc;
28struct gfs2_sbd; 30struct gfs2_sbd;
31struct lm_lockops;
29 32
30typedef void (*gfs2_glop_bh_t) (struct gfs2_glock *gl, unsigned int ret); 33typedef void (*gfs2_glop_bh_t) (struct gfs2_glock *gl, unsigned int ret);
31 34
@@ -121,6 +124,28 @@ struct gfs2_bufdata {
121 struct list_head bd_ail_gl_list; 124 struct list_head bd_ail_gl_list;
122}; 125};
123 126
127/*
128 * Internally, we prefix things with gdlm_ and GDLM_ (for gfs-dlm) since a
129 * prefix of lock_dlm_ gets awkward.
130 */
131
132#define GDLM_STRNAME_BYTES 25
133#define GDLM_LVB_SIZE 32
134
135enum {
136 DFL_BLOCK_LOCKS = 0,
137};
138
139struct lm_lockname {
140 u64 ln_number;
141 unsigned int ln_type;
142};
143
144#define lm_name_equal(name1, name2) \
145 (((name1)->ln_number == (name2)->ln_number) && \
146 ((name1)->ln_type == (name2)->ln_type))
147
148
124struct gfs2_glock_operations { 149struct gfs2_glock_operations {
125 void (*go_xmote_th) (struct gfs2_glock *gl); 150 void (*go_xmote_th) (struct gfs2_glock *gl);
126 int (*go_xmote_bh) (struct gfs2_glock *gl, struct gfs2_holder *gh); 151 int (*go_xmote_bh) (struct gfs2_glock *gl, struct gfs2_holder *gh);
@@ -162,6 +187,8 @@ enum {
162 GLF_LFLUSH = 7, 187 GLF_LFLUSH = 7,
163 GLF_INVALIDATE_IN_PROGRESS = 8, 188 GLF_INVALIDATE_IN_PROGRESS = 8,
164 GLF_REPLY_PENDING = 9, 189 GLF_REPLY_PENDING = 9,
190 GLF_INITIAL = 10,
191 GLF_FROZEN = 11,
165}; 192};
166 193
167struct gfs2_glock { 194struct gfs2_glock {
@@ -176,16 +203,15 @@ struct gfs2_glock {
176 unsigned int gl_target; 203 unsigned int gl_target;
177 unsigned int gl_reply; 204 unsigned int gl_reply;
178 unsigned int gl_hash; 205 unsigned int gl_hash;
206 unsigned int gl_req;
179 unsigned int gl_demote_state; /* state requested by remote node */ 207 unsigned int gl_demote_state; /* state requested by remote node */
180 unsigned long gl_demote_time; /* time of first demote request */ 208 unsigned long gl_demote_time; /* time of first demote request */
181 struct list_head gl_holders; 209 struct list_head gl_holders;
182 210
183 const struct gfs2_glock_operations *gl_ops; 211 const struct gfs2_glock_operations *gl_ops;
184 void *gl_lock; 212 char gl_strname[GDLM_STRNAME_BYTES];
185 char *gl_lvb; 213 struct dlm_lksb gl_lksb;
186 atomic_t gl_lvb_count; 214 char gl_lvb[32];
187
188 unsigned long gl_stamp;
189 unsigned long gl_tchange; 215 unsigned long gl_tchange;
190 void *gl_object; 216 void *gl_object;
191 217
@@ -283,7 +309,9 @@ enum {
283 309
284struct gfs2_quota_data { 310struct gfs2_quota_data {
285 struct list_head qd_list; 311 struct list_head qd_list;
286 unsigned int qd_count; 312 struct list_head qd_reclaim;
313
314 atomic_t qd_count;
287 315
288 u32 qd_id; 316 u32 qd_id;
289 unsigned long qd_flags; /* QDF_... */ 317 unsigned long qd_flags; /* QDF_... */
@@ -303,7 +331,6 @@ struct gfs2_quota_data {
303 331
304 u64 qd_sync_gen; 332 u64 qd_sync_gen;
305 unsigned long qd_last_warn; 333 unsigned long qd_last_warn;
306 unsigned long qd_last_touched;
307}; 334};
308 335
309struct gfs2_trans { 336struct gfs2_trans {
@@ -390,7 +417,7 @@ struct gfs2_args {
390 unsigned int ar_suiddir:1; /* suiddir support */ 417 unsigned int ar_suiddir:1; /* suiddir support */
391 unsigned int ar_data:2; /* ordered/writeback */ 418 unsigned int ar_data:2; /* ordered/writeback */
392 unsigned int ar_meta:1; /* mount metafs */ 419 unsigned int ar_meta:1; /* mount metafs */
393 unsigned int ar_num_glockd; /* Number of glockd threads */ 420 unsigned int ar_discard:1; /* discard requests */
394}; 421};
395 422
396struct gfs2_tune { 423struct gfs2_tune {
@@ -406,7 +433,6 @@ struct gfs2_tune {
406 unsigned int gt_quota_warn_period; /* Secs between quota warn msgs */ 433 unsigned int gt_quota_warn_period; /* Secs between quota warn msgs */
407 unsigned int gt_quota_scale_num; /* Numerator */ 434 unsigned int gt_quota_scale_num; /* Numerator */
408 unsigned int gt_quota_scale_den; /* Denominator */ 435 unsigned int gt_quota_scale_den; /* Denominator */
409 unsigned int gt_quota_cache_secs;
410 unsigned int gt_quota_quantum; /* Secs between syncs to quota file */ 436 unsigned int gt_quota_quantum; /* Secs between syncs to quota file */
411 unsigned int gt_new_files_jdata; 437 unsigned int gt_new_files_jdata;
412 unsigned int gt_max_readahead; /* Max bytes to read-ahead from disk */ 438 unsigned int gt_max_readahead; /* Max bytes to read-ahead from disk */
@@ -445,6 +471,31 @@ struct gfs2_sb_host {
445 471
446 char sb_lockproto[GFS2_LOCKNAME_LEN]; 472 char sb_lockproto[GFS2_LOCKNAME_LEN];
447 char sb_locktable[GFS2_LOCKNAME_LEN]; 473 char sb_locktable[GFS2_LOCKNAME_LEN];
474 u8 sb_uuid[16];
475};
476
477/*
478 * lm_mount() return values
479 *
480 * ls_jid - the journal ID this node should use
481 * ls_first - this node is the first to mount the file system
482 * ls_lockspace - lock module's context for this file system
483 * ls_ops - lock module's functions
484 */
485
486struct lm_lockstruct {
487 u32 ls_id;
488 unsigned int ls_jid;
489 unsigned int ls_first;
490 unsigned int ls_first_done;
491 unsigned int ls_nodir;
492 const struct lm_lockops *ls_ops;
493 unsigned long ls_flags;
494 dlm_lockspace_t *ls_dlm;
495
496 int ls_recover_jid;
497 int ls_recover_jid_done;
498 int ls_recover_jid_status;
448}; 499};
449 500
450struct gfs2_sbd { 501struct gfs2_sbd {
@@ -520,7 +571,6 @@ struct gfs2_sbd {
520 spinlock_t sd_jindex_spin; 571 spinlock_t sd_jindex_spin;
521 struct mutex sd_jindex_mutex; 572 struct mutex sd_jindex_mutex;
522 unsigned int sd_journals; 573 unsigned int sd_journals;
523 unsigned long sd_jindex_refresh_time;
524 574
525 struct gfs2_jdesc *sd_jdesc; 575 struct gfs2_jdesc *sd_jdesc;
526 struct gfs2_holder sd_journal_gh; 576 struct gfs2_holder sd_journal_gh;
@@ -540,7 +590,6 @@ struct gfs2_sbd {
540 590
541 struct list_head sd_quota_list; 591 struct list_head sd_quota_list;
542 atomic_t sd_quota_count; 592 atomic_t sd_quota_count;
543 spinlock_t sd_quota_spin;
544 struct mutex sd_quota_mutex; 593 struct mutex sd_quota_mutex;
545 wait_queue_head_t sd_quota_wait; 594 wait_queue_head_t sd_quota_wait;
546 struct list_head sd_trunc_list; 595 struct list_head sd_trunc_list;
diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
index 3b87c188da41..7b277d449155 100644
--- a/fs/gfs2/inode.c
+++ b/fs/gfs2/inode.c
@@ -16,7 +16,6 @@
16#include <linux/sort.h> 16#include <linux/sort.h>
17#include <linux/gfs2_ondisk.h> 17#include <linux/gfs2_ondisk.h>
18#include <linux/crc32.h> 18#include <linux/crc32.h>
19#include <linux/lm_interface.h>
20#include <linux/security.h> 19#include <linux/security.h>
21#include <linux/time.h> 20#include <linux/time.h>
22 21
@@ -137,16 +136,16 @@ void gfs2_set_iop(struct inode *inode)
137 136
138 if (S_ISREG(mode)) { 137 if (S_ISREG(mode)) {
139 inode->i_op = &gfs2_file_iops; 138 inode->i_op = &gfs2_file_iops;
140 if (sdp->sd_args.ar_localflocks) 139 if (gfs2_localflocks(sdp))
141 inode->i_fop = &gfs2_file_fops_nolock; 140 inode->i_fop = gfs2_file_fops_nolock;
142 else 141 else
143 inode->i_fop = &gfs2_file_fops; 142 inode->i_fop = gfs2_file_fops;
144 } else if (S_ISDIR(mode)) { 143 } else if (S_ISDIR(mode)) {
145 inode->i_op = &gfs2_dir_iops; 144 inode->i_op = &gfs2_dir_iops;
146 if (sdp->sd_args.ar_localflocks) 145 if (gfs2_localflocks(sdp))
147 inode->i_fop = &gfs2_dir_fops_nolock; 146 inode->i_fop = gfs2_dir_fops_nolock;
148 else 147 else
149 inode->i_fop = &gfs2_dir_fops; 148 inode->i_fop = gfs2_dir_fops;
150 } else if (S_ISLNK(mode)) { 149 } else if (S_ISLNK(mode)) {
151 inode->i_op = &gfs2_symlink_iops; 150 inode->i_op = &gfs2_symlink_iops;
152 } else { 151 } else {
diff --git a/fs/gfs2/inode.h b/fs/gfs2/inode.h
index d5329364cdff..dca4fee3078b 100644
--- a/fs/gfs2/inode.h
+++ b/fs/gfs2/inode.h
@@ -101,12 +101,26 @@ void gfs2_dinode_print(const struct gfs2_inode *ip);
101extern const struct inode_operations gfs2_file_iops; 101extern const struct inode_operations gfs2_file_iops;
102extern const struct inode_operations gfs2_dir_iops; 102extern const struct inode_operations gfs2_dir_iops;
103extern const struct inode_operations gfs2_symlink_iops; 103extern const struct inode_operations gfs2_symlink_iops;
104extern const struct file_operations gfs2_file_fops; 104extern const struct file_operations *gfs2_file_fops_nolock;
105extern const struct file_operations gfs2_dir_fops; 105extern const struct file_operations *gfs2_dir_fops_nolock;
106extern const struct file_operations gfs2_file_fops_nolock;
107extern const struct file_operations gfs2_dir_fops_nolock;
108 106
109extern void gfs2_set_inode_flags(struct inode *inode); 107extern void gfs2_set_inode_flags(struct inode *inode);
108
109#ifdef CONFIG_GFS2_FS_LOCKING_DLM
110extern const struct file_operations *gfs2_file_fops;
111extern const struct file_operations *gfs2_dir_fops;
112static inline int gfs2_localflocks(const struct gfs2_sbd *sdp)
113{
114 return sdp->sd_args.ar_localflocks;
115}
116#else /* Single node only */
117#define gfs2_file_fops NULL
118#define gfs2_dir_fops NULL
119static inline int gfs2_localflocks(const struct gfs2_sbd *sdp)
120{
121 return 1;
122}
123#endif /* CONFIG_GFS2_FS_LOCKING_DLM */
110 124
111#endif /* __INODE_DOT_H__ */ 125#endif /* __INODE_DOT_H__ */
112 126
diff --git a/fs/gfs2/lock_dlm.c b/fs/gfs2/lock_dlm.c
new file mode 100644
index 000000000000..46df988323bc
--- /dev/null
+++ b/fs/gfs2/lock_dlm.c
@@ -0,0 +1,241 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include <linux/fs.h>
11#include <linux/dlm.h>
12#include <linux/types.h>
13#include <linux/gfs2_ondisk.h>
14
15#include "incore.h"
16#include "glock.h"
17#include "util.h"
18
19
20static void gdlm_ast(void *arg)
21{
22 struct gfs2_glock *gl = arg;
23 unsigned ret = gl->gl_state;
24
25 BUG_ON(gl->gl_lksb.sb_flags & DLM_SBF_DEMOTED);
26
27 if (gl->gl_lksb.sb_flags & DLM_SBF_VALNOTVALID)
28 memset(gl->gl_lvb, 0, GDLM_LVB_SIZE);
29
30 switch (gl->gl_lksb.sb_status) {
31 case -DLM_EUNLOCK: /* Unlocked, so glock can be freed */
32 kmem_cache_free(gfs2_glock_cachep, gl);
33 return;
34 case -DLM_ECANCEL: /* Cancel while getting lock */
35 ret |= LM_OUT_CANCELED;
36 goto out;
37 case -EAGAIN: /* Try lock fails */
38 goto out;
39 case -EINVAL: /* Invalid */
40 case -ENOMEM: /* Out of memory */
41 ret |= LM_OUT_ERROR;
42 goto out;
43 case 0: /* Success */
44 break;
45 default: /* Something unexpected */
46 BUG();
47 }
48
49 ret = gl->gl_req;
50 if (gl->gl_lksb.sb_flags & DLM_SBF_ALTMODE) {
51 if (gl->gl_req == LM_ST_SHARED)
52 ret = LM_ST_DEFERRED;
53 else if (gl->gl_req == LM_ST_DEFERRED)
54 ret = LM_ST_SHARED;
55 else
56 BUG();
57 }
58
59 set_bit(GLF_INITIAL, &gl->gl_flags);
60 gfs2_glock_complete(gl, ret);
61 return;
62out:
63 if (!test_bit(GLF_INITIAL, &gl->gl_flags))
64 gl->gl_lksb.sb_lkid = 0;
65 gfs2_glock_complete(gl, ret);
66}
67
68static void gdlm_bast(void *arg, int mode)
69{
70 struct gfs2_glock *gl = arg;
71
72 switch (mode) {
73 case DLM_LOCK_EX:
74 gfs2_glock_cb(gl, LM_ST_UNLOCKED);
75 break;
76 case DLM_LOCK_CW:
77 gfs2_glock_cb(gl, LM_ST_DEFERRED);
78 break;
79 case DLM_LOCK_PR:
80 gfs2_glock_cb(gl, LM_ST_SHARED);
81 break;
82 default:
83 printk(KERN_ERR "unknown bast mode %d", mode);
84 BUG();
85 }
86}
87
88/* convert gfs lock-state to dlm lock-mode */
89
90static int make_mode(const unsigned int lmstate)
91{
92 switch (lmstate) {
93 case LM_ST_UNLOCKED:
94 return DLM_LOCK_NL;
95 case LM_ST_EXCLUSIVE:
96 return DLM_LOCK_EX;
97 case LM_ST_DEFERRED:
98 return DLM_LOCK_CW;
99 case LM_ST_SHARED:
100 return DLM_LOCK_PR;
101 }
102 printk(KERN_ERR "unknown LM state %d", lmstate);
103 BUG();
104 return -1;
105}
106
107static u32 make_flags(const u32 lkid, const unsigned int gfs_flags,
108 const int req)
109{
110 u32 lkf = 0;
111
112 if (gfs_flags & LM_FLAG_TRY)
113 lkf |= DLM_LKF_NOQUEUE;
114
115 if (gfs_flags & LM_FLAG_TRY_1CB) {
116 lkf |= DLM_LKF_NOQUEUE;
117 lkf |= DLM_LKF_NOQUEUEBAST;
118 }
119
120 if (gfs_flags & LM_FLAG_PRIORITY) {
121 lkf |= DLM_LKF_NOORDER;
122 lkf |= DLM_LKF_HEADQUE;
123 }
124
125 if (gfs_flags & LM_FLAG_ANY) {
126 if (req == DLM_LOCK_PR)
127 lkf |= DLM_LKF_ALTCW;
128 else if (req == DLM_LOCK_CW)
129 lkf |= DLM_LKF_ALTPR;
130 else
131 BUG();
132 }
133
134 if (lkid != 0)
135 lkf |= DLM_LKF_CONVERT;
136
137 lkf |= DLM_LKF_VALBLK;
138
139 return lkf;
140}
141
142static unsigned int gdlm_lock(struct gfs2_glock *gl,
143 unsigned int req_state, unsigned int flags)
144{
145 struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
146 int error;
147 int req;
148 u32 lkf;
149
150 gl->gl_req = req_state;
151 req = make_mode(req_state);
152 lkf = make_flags(gl->gl_lksb.sb_lkid, flags, req);
153
154 /*
155 * Submit the actual lock request.
156 */
157
158 error = dlm_lock(ls->ls_dlm, req, &gl->gl_lksb, lkf, gl->gl_strname,
159 GDLM_STRNAME_BYTES - 1, 0, gdlm_ast, gl, gdlm_bast);
160 if (error == -EAGAIN)
161 return 0;
162 if (error)
163 return LM_OUT_ERROR;
164 return LM_OUT_ASYNC;
165}
166
167static void gdlm_put_lock(struct kmem_cache *cachep, void *ptr)
168{
169 struct gfs2_glock *gl = ptr;
170 struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
171 int error;
172
173 if (gl->gl_lksb.sb_lkid == 0) {
174 kmem_cache_free(cachep, gl);
175 return;
176 }
177
178 error = dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, DLM_LKF_VALBLK,
179 NULL, gl);
180 if (error) {
181 printk(KERN_ERR "gdlm_unlock %x,%llx err=%d\n",
182 gl->gl_name.ln_type,
183 (unsigned long long)gl->gl_name.ln_number, error);
184 return;
185 }
186}
187
188static void gdlm_cancel(struct gfs2_glock *gl)
189{
190 struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
191 dlm_unlock(ls->ls_dlm, gl->gl_lksb.sb_lkid, DLM_LKF_CANCEL, NULL, gl);
192}
193
194static int gdlm_mount(struct gfs2_sbd *sdp, const char *fsname)
195{
196 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
197 int error;
198
199 if (fsname == NULL) {
200 fs_info(sdp, "no fsname found\n");
201 return -EINVAL;
202 }
203
204 error = dlm_new_lockspace(fsname, strlen(fsname), &ls->ls_dlm,
205 DLM_LSFL_FS | DLM_LSFL_NEWEXCL |
206 (ls->ls_nodir ? DLM_LSFL_NODIR : 0),
207 GDLM_LVB_SIZE);
208 if (error)
209 printk(KERN_ERR "dlm_new_lockspace error %d", error);
210
211 return error;
212}
213
214static void gdlm_unmount(struct gfs2_sbd *sdp)
215{
216 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
217
218 if (ls->ls_dlm) {
219 dlm_release_lockspace(ls->ls_dlm, 2);
220 ls->ls_dlm = NULL;
221 }
222}
223
224static const match_table_t dlm_tokens = {
225 { Opt_jid, "jid=%d"},
226 { Opt_id, "id=%d"},
227 { Opt_first, "first=%d"},
228 { Opt_nodir, "nodir=%d"},
229 { Opt_err, NULL },
230};
231
232const struct lm_lockops gfs2_dlm_ops = {
233 .lm_proto_name = "lock_dlm",
234 .lm_mount = gdlm_mount,
235 .lm_unmount = gdlm_unmount,
236 .lm_put_lock = gdlm_put_lock,
237 .lm_lock = gdlm_lock,
238 .lm_cancel = gdlm_cancel,
239 .lm_tokens = &dlm_tokens,
240};
241
diff --git a/fs/gfs2/locking.c b/fs/gfs2/locking.c
deleted file mode 100644
index 523243a13a21..000000000000
--- a/fs/gfs2/locking.c
+++ /dev/null
@@ -1,232 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/string.h>
13#include <linux/slab.h>
14#include <linux/wait.h>
15#include <linux/sched.h>
16#include <linux/kmod.h>
17#include <linux/fs.h>
18#include <linux/delay.h>
19#include <linux/lm_interface.h>
20
21struct lmh_wrapper {
22 struct list_head lw_list;
23 const struct lm_lockops *lw_ops;
24};
25
26static int nolock_mount(char *table_name, char *host_data,
27 lm_callback_t cb, void *cb_data,
28 unsigned int min_lvb_size, int flags,
29 struct lm_lockstruct *lockstruct,
30 struct kobject *fskobj);
31
32/* List of registered low-level locking protocols. A file system selects one
33 of them by name at mount time, e.g. lock_nolock, lock_dlm. */
34
35static const struct lm_lockops nolock_ops = {
36 .lm_proto_name = "lock_nolock",
37 .lm_mount = nolock_mount,
38};
39
40static struct lmh_wrapper nolock_proto = {
41 .lw_list = LIST_HEAD_INIT(nolock_proto.lw_list),
42 .lw_ops = &nolock_ops,
43};
44
45static LIST_HEAD(lmh_list);
46static DEFINE_MUTEX(lmh_lock);
47
48static int nolock_mount(char *table_name, char *host_data,
49 lm_callback_t cb, void *cb_data,
50 unsigned int min_lvb_size, int flags,
51 struct lm_lockstruct *lockstruct,
52 struct kobject *fskobj)
53{
54 char *c;
55 unsigned int jid;
56
57 c = strstr(host_data, "jid=");
58 if (!c)
59 jid = 0;
60 else {
61 c += 4;
62 sscanf(c, "%u", &jid);
63 }
64
65 lockstruct->ls_jid = jid;
66 lockstruct->ls_first = 1;
67 lockstruct->ls_lvb_size = min_lvb_size;
68 lockstruct->ls_ops = &nolock_ops;
69 lockstruct->ls_flags = LM_LSFLAG_LOCAL;
70
71 return 0;
72}
73
74/**
75 * gfs2_register_lockproto - Register a low-level locking protocol
76 * @proto: the protocol definition
77 *
78 * Returns: 0 on success, -EXXX on failure
79 */
80
81int gfs2_register_lockproto(const struct lm_lockops *proto)
82{
83 struct lmh_wrapper *lw;
84
85 mutex_lock(&lmh_lock);
86
87 list_for_each_entry(lw, &lmh_list, lw_list) {
88 if (!strcmp(lw->lw_ops->lm_proto_name, proto->lm_proto_name)) {
89 mutex_unlock(&lmh_lock);
90 printk(KERN_INFO "GFS2: protocol %s already exists\n",
91 proto->lm_proto_name);
92 return -EEXIST;
93 }
94 }
95
96 lw = kzalloc(sizeof(struct lmh_wrapper), GFP_KERNEL);
97 if (!lw) {
98 mutex_unlock(&lmh_lock);
99 return -ENOMEM;
100 }
101
102 lw->lw_ops = proto;
103 list_add(&lw->lw_list, &lmh_list);
104
105 mutex_unlock(&lmh_lock);
106
107 return 0;
108}
109
110/**
111 * gfs2_unregister_lockproto - Unregister a low-level locking protocol
112 * @proto: the protocol definition
113 *
114 */
115
116void gfs2_unregister_lockproto(const struct lm_lockops *proto)
117{
118 struct lmh_wrapper *lw;
119
120 mutex_lock(&lmh_lock);
121
122 list_for_each_entry(lw, &lmh_list, lw_list) {
123 if (!strcmp(lw->lw_ops->lm_proto_name, proto->lm_proto_name)) {
124 list_del(&lw->lw_list);
125 mutex_unlock(&lmh_lock);
126 kfree(lw);
127 return;
128 }
129 }
130
131 mutex_unlock(&lmh_lock);
132
133 printk(KERN_WARNING "GFS2: can't unregister lock protocol %s\n",
134 proto->lm_proto_name);
135}
136
137/**
138 * gfs2_mount_lockproto - Mount a lock protocol
139 * @proto_name - the name of the protocol
140 * @table_name - the name of the lock space
141 * @host_data - data specific to this host
142 * @cb - the callback to the code using the lock module
143 * @sdp - The GFS2 superblock
144 * @min_lvb_size - the mininum LVB size that the caller can deal with
145 * @flags - LM_MFLAG_*
146 * @lockstruct - a structure returned describing the mount
147 *
148 * Returns: 0 on success, -EXXX on failure
149 */
150
151int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data,
152 lm_callback_t cb, void *cb_data,
153 unsigned int min_lvb_size, int flags,
154 struct lm_lockstruct *lockstruct,
155 struct kobject *fskobj)
156{
157 struct lmh_wrapper *lw = NULL;
158 int try = 0;
159 int error, found;
160
161
162retry:
163 mutex_lock(&lmh_lock);
164
165 if (list_empty(&nolock_proto.lw_list))
166 list_add(&nolock_proto.lw_list, &lmh_list);
167
168 found = 0;
169 list_for_each_entry(lw, &lmh_list, lw_list) {
170 if (!strcmp(lw->lw_ops->lm_proto_name, proto_name)) {
171 found = 1;
172 break;
173 }
174 }
175
176 if (!found) {
177 if (!try && capable(CAP_SYS_MODULE)) {
178 try = 1;
179 mutex_unlock(&lmh_lock);
180 request_module(proto_name);
181 goto retry;
182 }
183 printk(KERN_INFO "GFS2: can't find protocol %s\n", proto_name);
184 error = -ENOENT;
185 goto out;
186 }
187
188 if (lw->lw_ops->lm_owner &&
189 !try_module_get(lw->lw_ops->lm_owner)) {
190 try = 0;
191 mutex_unlock(&lmh_lock);
192 msleep(1000);
193 goto retry;
194 }
195
196 error = lw->lw_ops->lm_mount(table_name, host_data, cb, cb_data,
197 min_lvb_size, flags, lockstruct, fskobj);
198 if (error)
199 module_put(lw->lw_ops->lm_owner);
200out:
201 mutex_unlock(&lmh_lock);
202 return error;
203}
204
205void gfs2_unmount_lockproto(struct lm_lockstruct *lockstruct)
206{
207 mutex_lock(&lmh_lock);
208 if (lockstruct->ls_ops->lm_unmount)
209 lockstruct->ls_ops->lm_unmount(lockstruct->ls_lockspace);
210 if (lockstruct->ls_ops->lm_owner)
211 module_put(lockstruct->ls_ops->lm_owner);
212 mutex_unlock(&lmh_lock);
213}
214
215/**
216 * gfs2_withdraw_lockproto - abnormally unmount a lock module
217 * @lockstruct: the lockstruct passed into mount
218 *
219 */
220
221void gfs2_withdraw_lockproto(struct lm_lockstruct *lockstruct)
222{
223 mutex_lock(&lmh_lock);
224 lockstruct->ls_ops->lm_withdraw(lockstruct->ls_lockspace);
225 if (lockstruct->ls_ops->lm_owner)
226 module_put(lockstruct->ls_ops->lm_owner);
227 mutex_unlock(&lmh_lock);
228}
229
230EXPORT_SYMBOL_GPL(gfs2_register_lockproto);
231EXPORT_SYMBOL_GPL(gfs2_unregister_lockproto);
232
diff --git a/fs/gfs2/locking/dlm/Makefile b/fs/gfs2/locking/dlm/Makefile
deleted file mode 100644
index 2609bb6cd013..000000000000
--- a/fs/gfs2/locking/dlm/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
1obj-$(CONFIG_GFS2_FS_LOCKING_DLM) += lock_dlm.o
2lock_dlm-y := lock.o main.o mount.o sysfs.o thread.o
3
diff --git a/fs/gfs2/locking/dlm/lock.c b/fs/gfs2/locking/dlm/lock.c
deleted file mode 100644
index 2482c9047505..000000000000
--- a/fs/gfs2/locking/dlm/lock.c
+++ /dev/null
@@ -1,708 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include "lock_dlm.h"
11
12static char junk_lvb[GDLM_LVB_SIZE];
13
14
15/* convert dlm lock-mode to gfs lock-state */
16
17static s16 gdlm_make_lmstate(s16 dlmmode)
18{
19 switch (dlmmode) {
20 case DLM_LOCK_IV:
21 case DLM_LOCK_NL:
22 return LM_ST_UNLOCKED;
23 case DLM_LOCK_EX:
24 return LM_ST_EXCLUSIVE;
25 case DLM_LOCK_CW:
26 return LM_ST_DEFERRED;
27 case DLM_LOCK_PR:
28 return LM_ST_SHARED;
29 }
30 gdlm_assert(0, "unknown DLM mode %d", dlmmode);
31 return -1;
32}
33
34/* A lock placed on this queue is re-submitted to DLM as soon as the lock_dlm
35 thread gets to it. */
36
37static void queue_submit(struct gdlm_lock *lp)
38{
39 struct gdlm_ls *ls = lp->ls;
40
41 spin_lock(&ls->async_lock);
42 list_add_tail(&lp->delay_list, &ls->submit);
43 spin_unlock(&ls->async_lock);
44 wake_up(&ls->thread_wait);
45}
46
47static void wake_up_ast(struct gdlm_lock *lp)
48{
49 clear_bit(LFL_AST_WAIT, &lp->flags);
50 smp_mb__after_clear_bit();
51 wake_up_bit(&lp->flags, LFL_AST_WAIT);
52}
53
54static void gdlm_delete_lp(struct gdlm_lock *lp)
55{
56 struct gdlm_ls *ls = lp->ls;
57
58 spin_lock(&ls->async_lock);
59 if (!list_empty(&lp->delay_list))
60 list_del_init(&lp->delay_list);
61 ls->all_locks_count--;
62 spin_unlock(&ls->async_lock);
63
64 kfree(lp);
65}
66
67static void gdlm_queue_delayed(struct gdlm_lock *lp)
68{
69 struct gdlm_ls *ls = lp->ls;
70
71 spin_lock(&ls->async_lock);
72 list_add_tail(&lp->delay_list, &ls->delayed);
73 spin_unlock(&ls->async_lock);
74}
75
76static void process_complete(struct gdlm_lock *lp)
77{
78 struct gdlm_ls *ls = lp->ls;
79 struct lm_async_cb acb;
80
81 memset(&acb, 0, sizeof(acb));
82
83 if (lp->lksb.sb_status == -DLM_ECANCEL) {
84 log_info("complete dlm cancel %x,%llx flags %lx",
85 lp->lockname.ln_type,
86 (unsigned long long)lp->lockname.ln_number,
87 lp->flags);
88
89 lp->req = lp->cur;
90 acb.lc_ret |= LM_OUT_CANCELED;
91 if (lp->cur == DLM_LOCK_IV)
92 lp->lksb.sb_lkid = 0;
93 goto out;
94 }
95
96 if (test_and_clear_bit(LFL_DLM_UNLOCK, &lp->flags)) {
97 if (lp->lksb.sb_status != -DLM_EUNLOCK) {
98 log_info("unlock sb_status %d %x,%llx flags %lx",
99 lp->lksb.sb_status, lp->lockname.ln_type,
100 (unsigned long long)lp->lockname.ln_number,
101 lp->flags);
102 return;
103 }
104
105 lp->cur = DLM_LOCK_IV;
106 lp->req = DLM_LOCK_IV;
107 lp->lksb.sb_lkid = 0;
108
109 if (test_and_clear_bit(LFL_UNLOCK_DELETE, &lp->flags)) {
110 gdlm_delete_lp(lp);
111 return;
112 }
113 goto out;
114 }
115
116 if (lp->lksb.sb_flags & DLM_SBF_VALNOTVALID)
117 memset(lp->lksb.sb_lvbptr, 0, GDLM_LVB_SIZE);
118
119 if (lp->lksb.sb_flags & DLM_SBF_ALTMODE) {
120 if (lp->req == DLM_LOCK_PR)
121 lp->req = DLM_LOCK_CW;
122 else if (lp->req == DLM_LOCK_CW)
123 lp->req = DLM_LOCK_PR;
124 }
125
126 /*
127 * A canceled lock request. The lock was just taken off the delayed
128 * list and was never even submitted to dlm.
129 */
130
131 if (test_and_clear_bit(LFL_CANCEL, &lp->flags)) {
132 log_info("complete internal cancel %x,%llx",
133 lp->lockname.ln_type,
134 (unsigned long long)lp->lockname.ln_number);
135 lp->req = lp->cur;
136 acb.lc_ret |= LM_OUT_CANCELED;
137 goto out;
138 }
139
140 /*
141 * An error occured.
142 */
143
144 if (lp->lksb.sb_status) {
145 /* a "normal" error */
146 if ((lp->lksb.sb_status == -EAGAIN) &&
147 (lp->lkf & DLM_LKF_NOQUEUE)) {
148 lp->req = lp->cur;
149 if (lp->cur == DLM_LOCK_IV)
150 lp->lksb.sb_lkid = 0;
151 goto out;
152 }
153
154 /* this could only happen with cancels I think */
155 log_info("ast sb_status %d %x,%llx flags %lx",
156 lp->lksb.sb_status, lp->lockname.ln_type,
157 (unsigned long long)lp->lockname.ln_number,
158 lp->flags);
159 return;
160 }
161
162 /*
163 * This is an AST for an EX->EX conversion for sync_lvb from GFS.
164 */
165
166 if (test_and_clear_bit(LFL_SYNC_LVB, &lp->flags)) {
167 wake_up_ast(lp);
168 return;
169 }
170
171 /*
172 * A lock has been demoted to NL because it initially completed during
173 * BLOCK_LOCKS. Now it must be requested in the originally requested
174 * mode.
175 */
176
177 if (test_and_clear_bit(LFL_REREQUEST, &lp->flags)) {
178 gdlm_assert(lp->req == DLM_LOCK_NL, "%x,%llx",
179 lp->lockname.ln_type,
180 (unsigned long long)lp->lockname.ln_number);
181 gdlm_assert(lp->prev_req > DLM_LOCK_NL, "%x,%llx",
182 lp->lockname.ln_type,
183 (unsigned long long)lp->lockname.ln_number);
184
185 lp->cur = DLM_LOCK_NL;
186 lp->req = lp->prev_req;
187 lp->prev_req = DLM_LOCK_IV;
188 lp->lkf &= ~DLM_LKF_CONVDEADLK;
189
190 set_bit(LFL_NOCACHE, &lp->flags);
191
192 if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) &&
193 !test_bit(LFL_NOBLOCK, &lp->flags))
194 gdlm_queue_delayed(lp);
195 else
196 queue_submit(lp);
197 return;
198 }
199
200 /*
201 * A request is granted during dlm recovery. It may be granted
202 * because the locks of a failed node were cleared. In that case,
203 * there may be inconsistent data beneath this lock and we must wait
204 * for recovery to complete to use it. When gfs recovery is done this
205 * granted lock will be converted to NL and then reacquired in this
206 * granted state.
207 */
208
209 if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) &&
210 !test_bit(LFL_NOBLOCK, &lp->flags) &&
211 lp->req != DLM_LOCK_NL) {
212
213 lp->cur = lp->req;
214 lp->prev_req = lp->req;
215 lp->req = DLM_LOCK_NL;
216 lp->lkf |= DLM_LKF_CONVERT;
217 lp->lkf &= ~DLM_LKF_CONVDEADLK;
218
219 log_debug("rereq %x,%llx id %x %d,%d",
220 lp->lockname.ln_type,
221 (unsigned long long)lp->lockname.ln_number,
222 lp->lksb.sb_lkid, lp->cur, lp->req);
223
224 set_bit(LFL_REREQUEST, &lp->flags);
225 queue_submit(lp);
226 return;
227 }
228
229 /*
230 * DLM demoted the lock to NL before it was granted so GFS must be
231 * told it cannot cache data for this lock.
232 */
233
234 if (lp->lksb.sb_flags & DLM_SBF_DEMOTED)
235 set_bit(LFL_NOCACHE, &lp->flags);
236
237out:
238 /*
239 * This is an internal lock_dlm lock
240 */
241
242 if (test_bit(LFL_INLOCK, &lp->flags)) {
243 clear_bit(LFL_NOBLOCK, &lp->flags);
244 lp->cur = lp->req;
245 wake_up_ast(lp);
246 return;
247 }
248
249 /*
250 * Normal completion of a lock request. Tell GFS it now has the lock.
251 */
252
253 clear_bit(LFL_NOBLOCK, &lp->flags);
254 lp->cur = lp->req;
255
256 acb.lc_name = lp->lockname;
257 acb.lc_ret |= gdlm_make_lmstate(lp->cur);
258
259 ls->fscb(ls->sdp, LM_CB_ASYNC, &acb);
260}
261
262static void gdlm_ast(void *astarg)
263{
264 struct gdlm_lock *lp = astarg;
265 clear_bit(LFL_ACTIVE, &lp->flags);
266 process_complete(lp);
267}
268
269static void process_blocking(struct gdlm_lock *lp, int bast_mode)
270{
271 struct gdlm_ls *ls = lp->ls;
272 unsigned int cb = 0;
273
274 switch (gdlm_make_lmstate(bast_mode)) {
275 case LM_ST_EXCLUSIVE:
276 cb = LM_CB_NEED_E;
277 break;
278 case LM_ST_DEFERRED:
279 cb = LM_CB_NEED_D;
280 break;
281 case LM_ST_SHARED:
282 cb = LM_CB_NEED_S;
283 break;
284 default:
285 gdlm_assert(0, "unknown bast mode %u", bast_mode);
286 }
287
288 ls->fscb(ls->sdp, cb, &lp->lockname);
289}
290
291
292static void gdlm_bast(void *astarg, int mode)
293{
294 struct gdlm_lock *lp = astarg;
295
296 if (!mode) {
297 printk(KERN_INFO "lock_dlm: bast mode zero %x,%llx\n",
298 lp->lockname.ln_type,
299 (unsigned long long)lp->lockname.ln_number);
300 return;
301 }
302
303 process_blocking(lp, mode);
304}
305
306/* convert gfs lock-state to dlm lock-mode */
307
308static s16 make_mode(s16 lmstate)
309{
310 switch (lmstate) {
311 case LM_ST_UNLOCKED:
312 return DLM_LOCK_NL;
313 case LM_ST_EXCLUSIVE:
314 return DLM_LOCK_EX;
315 case LM_ST_DEFERRED:
316 return DLM_LOCK_CW;
317 case LM_ST_SHARED:
318 return DLM_LOCK_PR;
319 }
320 gdlm_assert(0, "unknown LM state %d", lmstate);
321 return -1;
322}
323
324
325/* verify agreement with GFS on the current lock state, NB: DLM_LOCK_NL and
326 DLM_LOCK_IV are both considered LM_ST_UNLOCKED by GFS. */
327
328static void check_cur_state(struct gdlm_lock *lp, unsigned int cur_state)
329{
330 s16 cur = make_mode(cur_state);
331 if (lp->cur != DLM_LOCK_IV)
332 gdlm_assert(lp->cur == cur, "%d, %d", lp->cur, cur);
333}
334
335static inline unsigned int make_flags(struct gdlm_lock *lp,
336 unsigned int gfs_flags,
337 s16 cur, s16 req)
338{
339 unsigned int lkf = 0;
340
341 if (gfs_flags & LM_FLAG_TRY)
342 lkf |= DLM_LKF_NOQUEUE;
343
344 if (gfs_flags & LM_FLAG_TRY_1CB) {
345 lkf |= DLM_LKF_NOQUEUE;
346 lkf |= DLM_LKF_NOQUEUEBAST;
347 }
348
349 if (gfs_flags & LM_FLAG_PRIORITY) {
350 lkf |= DLM_LKF_NOORDER;
351 lkf |= DLM_LKF_HEADQUE;
352 }
353
354 if (gfs_flags & LM_FLAG_ANY) {
355 if (req == DLM_LOCK_PR)
356 lkf |= DLM_LKF_ALTCW;
357 else if (req == DLM_LOCK_CW)
358 lkf |= DLM_LKF_ALTPR;
359 }
360
361 if (lp->lksb.sb_lkid != 0) {
362 lkf |= DLM_LKF_CONVERT;
363 }
364
365 if (lp->lvb)
366 lkf |= DLM_LKF_VALBLK;
367
368 return lkf;
369}
370
371/* make_strname - convert GFS lock numbers to a string */
372
373static inline void make_strname(const struct lm_lockname *lockname,
374 struct gdlm_strname *str)
375{
376 sprintf(str->name, "%8x%16llx", lockname->ln_type,
377 (unsigned long long)lockname->ln_number);
378 str->namelen = GDLM_STRNAME_BYTES;
379}
380
381static int gdlm_create_lp(struct gdlm_ls *ls, struct lm_lockname *name,
382 struct gdlm_lock **lpp)
383{
384 struct gdlm_lock *lp;
385
386 lp = kzalloc(sizeof(struct gdlm_lock), GFP_NOFS);
387 if (!lp)
388 return -ENOMEM;
389
390 lp->lockname = *name;
391 make_strname(name, &lp->strname);
392 lp->ls = ls;
393 lp->cur = DLM_LOCK_IV;
394 INIT_LIST_HEAD(&lp->delay_list);
395
396 spin_lock(&ls->async_lock);
397 ls->all_locks_count++;
398 spin_unlock(&ls->async_lock);
399
400 *lpp = lp;
401 return 0;
402}
403
404int gdlm_get_lock(void *lockspace, struct lm_lockname *name,
405 void **lockp)
406{
407 struct gdlm_lock *lp;
408 int error;
409
410 error = gdlm_create_lp(lockspace, name, &lp);
411
412 *lockp = lp;
413 return error;
414}
415
416void gdlm_put_lock(void *lock)
417{
418 gdlm_delete_lp(lock);
419}
420
421unsigned int gdlm_do_lock(struct gdlm_lock *lp)
422{
423 struct gdlm_ls *ls = lp->ls;
424 int error, bast = 1;
425
426 /*
427 * When recovery is in progress, delay lock requests for submission
428 * once recovery is done. Requests for recovery (NOEXP) and unlocks
429 * can pass.
430 */
431
432 if (test_bit(DFL_BLOCK_LOCKS, &ls->flags) &&
433 !test_bit(LFL_NOBLOCK, &lp->flags) && lp->req != DLM_LOCK_NL) {
434 gdlm_queue_delayed(lp);
435 return LM_OUT_ASYNC;
436 }
437
438 /*
439 * Submit the actual lock request.
440 */
441
442 if (test_bit(LFL_NOBAST, &lp->flags))
443 bast = 0;
444
445 set_bit(LFL_ACTIVE, &lp->flags);
446
447 log_debug("lk %x,%llx id %x %d,%d %x", lp->lockname.ln_type,
448 (unsigned long long)lp->lockname.ln_number, lp->lksb.sb_lkid,
449 lp->cur, lp->req, lp->lkf);
450
451 error = dlm_lock(ls->dlm_lockspace, lp->req, &lp->lksb, lp->lkf,
452 lp->strname.name, lp->strname.namelen, 0, gdlm_ast,
453 lp, bast ? gdlm_bast : NULL);
454
455 if ((error == -EAGAIN) && (lp->lkf & DLM_LKF_NOQUEUE)) {
456 lp->lksb.sb_status = -EAGAIN;
457 gdlm_ast(lp);
458 error = 0;
459 }
460
461 if (error) {
462 log_error("%s: gdlm_lock %x,%llx err=%d cur=%d req=%d lkf=%x "
463 "flags=%lx", ls->fsname, lp->lockname.ln_type,
464 (unsigned long long)lp->lockname.ln_number, error,
465 lp->cur, lp->req, lp->lkf, lp->flags);
466 return LM_OUT_ERROR;
467 }
468 return LM_OUT_ASYNC;
469}
470
471static unsigned int gdlm_do_unlock(struct gdlm_lock *lp)
472{
473 struct gdlm_ls *ls = lp->ls;
474 unsigned int lkf = 0;
475 int error;
476
477 set_bit(LFL_DLM_UNLOCK, &lp->flags);
478 set_bit(LFL_ACTIVE, &lp->flags);
479
480 if (lp->lvb)
481 lkf = DLM_LKF_VALBLK;
482
483 log_debug("un %x,%llx %x %d %x", lp->lockname.ln_type,
484 (unsigned long long)lp->lockname.ln_number,
485 lp->lksb.sb_lkid, lp->cur, lkf);
486
487 error = dlm_unlock(ls->dlm_lockspace, lp->lksb.sb_lkid, lkf, NULL, lp);
488
489 if (error) {
490 log_error("%s: gdlm_unlock %x,%llx err=%d cur=%d req=%d lkf=%x "
491 "flags=%lx", ls->fsname, lp->lockname.ln_type,
492 (unsigned long long)lp->lockname.ln_number, error,
493 lp->cur, lp->req, lp->lkf, lp->flags);
494 return LM_OUT_ERROR;
495 }
496 return LM_OUT_ASYNC;
497}
498
499unsigned int gdlm_lock(void *lock, unsigned int cur_state,
500 unsigned int req_state, unsigned int flags)
501{
502 struct gdlm_lock *lp = lock;
503
504 if (req_state == LM_ST_UNLOCKED)
505 return gdlm_unlock(lock, cur_state);
506
507 if (req_state == LM_ST_UNLOCKED)
508 return gdlm_unlock(lock, cur_state);
509
510 clear_bit(LFL_DLM_CANCEL, &lp->flags);
511 if (flags & LM_FLAG_NOEXP)
512 set_bit(LFL_NOBLOCK, &lp->flags);
513
514 check_cur_state(lp, cur_state);
515 lp->req = make_mode(req_state);
516 lp->lkf = make_flags(lp, flags, lp->cur, lp->req);
517
518 return gdlm_do_lock(lp);
519}
520
521unsigned int gdlm_unlock(void *lock, unsigned int cur_state)
522{
523 struct gdlm_lock *lp = lock;
524
525 clear_bit(LFL_DLM_CANCEL, &lp->flags);
526 if (lp->cur == DLM_LOCK_IV)
527 return 0;
528 return gdlm_do_unlock(lp);
529}
530
531void gdlm_cancel(void *lock)
532{
533 struct gdlm_lock *lp = lock;
534 struct gdlm_ls *ls = lp->ls;
535 int error, delay_list = 0;
536
537 if (test_bit(LFL_DLM_CANCEL, &lp->flags))
538 return;
539
540 log_info("gdlm_cancel %x,%llx flags %lx", lp->lockname.ln_type,
541 (unsigned long long)lp->lockname.ln_number, lp->flags);
542
543 spin_lock(&ls->async_lock);
544 if (!list_empty(&lp->delay_list)) {
545 list_del_init(&lp->delay_list);
546 delay_list = 1;
547 }
548 spin_unlock(&ls->async_lock);
549
550 if (delay_list) {
551 set_bit(LFL_CANCEL, &lp->flags);
552 set_bit(LFL_ACTIVE, &lp->flags);
553 gdlm_ast(lp);
554 return;
555 }
556
557 if (!test_bit(LFL_ACTIVE, &lp->flags) ||
558 test_bit(LFL_DLM_UNLOCK, &lp->flags)) {
559 log_info("gdlm_cancel skip %x,%llx flags %lx",
560 lp->lockname.ln_type,
561 (unsigned long long)lp->lockname.ln_number, lp->flags);
562 return;
563 }
564
565 /* the lock is blocked in the dlm */
566
567 set_bit(LFL_DLM_CANCEL, &lp->flags);
568 set_bit(LFL_ACTIVE, &lp->flags);
569
570 error = dlm_unlock(ls->dlm_lockspace, lp->lksb.sb_lkid, DLM_LKF_CANCEL,
571 NULL, lp);
572
573 log_info("gdlm_cancel rv %d %x,%llx flags %lx", error,
574 lp->lockname.ln_type,
575 (unsigned long long)lp->lockname.ln_number, lp->flags);
576
577 if (error == -EBUSY)
578 clear_bit(LFL_DLM_CANCEL, &lp->flags);
579}
580
581static int gdlm_add_lvb(struct gdlm_lock *lp)
582{
583 char *lvb;
584
585 lvb = kzalloc(GDLM_LVB_SIZE, GFP_NOFS);
586 if (!lvb)
587 return -ENOMEM;
588
589 lp->lksb.sb_lvbptr = lvb;
590 lp->lvb = lvb;
591 return 0;
592}
593
594static void gdlm_del_lvb(struct gdlm_lock *lp)
595{
596 kfree(lp->lvb);
597 lp->lvb = NULL;
598 lp->lksb.sb_lvbptr = NULL;
599}
600
601static int gdlm_ast_wait(void *word)
602{
603 schedule();
604 return 0;
605}
606
607/* This can do a synchronous dlm request (requiring a lock_dlm thread to get
608 the completion) because gfs won't call hold_lvb() during a callback (from
609 the context of a lock_dlm thread). */
610
611static int hold_null_lock(struct gdlm_lock *lp)
612{
613 struct gdlm_lock *lpn = NULL;
614 int error;
615
616 if (lp->hold_null) {
617 printk(KERN_INFO "lock_dlm: lvb already held\n");
618 return 0;
619 }
620
621 error = gdlm_create_lp(lp->ls, &lp->lockname, &lpn);
622 if (error)
623 goto out;
624
625 lpn->lksb.sb_lvbptr = junk_lvb;
626 lpn->lvb = junk_lvb;
627
628 lpn->req = DLM_LOCK_NL;
629 lpn->lkf = DLM_LKF_VALBLK | DLM_LKF_EXPEDITE;
630 set_bit(LFL_NOBAST, &lpn->flags);
631 set_bit(LFL_INLOCK, &lpn->flags);
632 set_bit(LFL_AST_WAIT, &lpn->flags);
633
634 gdlm_do_lock(lpn);
635 wait_on_bit(&lpn->flags, LFL_AST_WAIT, gdlm_ast_wait, TASK_UNINTERRUPTIBLE);
636 error = lpn->lksb.sb_status;
637 if (error) {
638 printk(KERN_INFO "lock_dlm: hold_null_lock dlm error %d\n",
639 error);
640 gdlm_delete_lp(lpn);
641 lpn = NULL;
642 }
643out:
644 lp->hold_null = lpn;
645 return error;
646}
647
648/* This cannot do a synchronous dlm request (requiring a lock_dlm thread to get
649 the completion) because gfs may call unhold_lvb() during a callback (from
650 the context of a lock_dlm thread) which could cause a deadlock since the
651 other lock_dlm thread could be engaged in recovery. */
652
653static void unhold_null_lock(struct gdlm_lock *lp)
654{
655 struct gdlm_lock *lpn = lp->hold_null;
656
657 gdlm_assert(lpn, "%x,%llx", lp->lockname.ln_type,
658 (unsigned long long)lp->lockname.ln_number);
659 lpn->lksb.sb_lvbptr = NULL;
660 lpn->lvb = NULL;
661 set_bit(LFL_UNLOCK_DELETE, &lpn->flags);
662 gdlm_do_unlock(lpn);
663 lp->hold_null = NULL;
664}
665
666/* Acquire a NL lock because gfs requires the value block to remain
667 intact on the resource while the lvb is "held" even if it's holding no locks
668 on the resource. */
669
670int gdlm_hold_lvb(void *lock, char **lvbp)
671{
672 struct gdlm_lock *lp = lock;
673 int error;
674
675 error = gdlm_add_lvb(lp);
676 if (error)
677 return error;
678
679 *lvbp = lp->lvb;
680
681 error = hold_null_lock(lp);
682 if (error)
683 gdlm_del_lvb(lp);
684
685 return error;
686}
687
688void gdlm_unhold_lvb(void *lock, char *lvb)
689{
690 struct gdlm_lock *lp = lock;
691
692 unhold_null_lock(lp);
693 gdlm_del_lvb(lp);
694}
695
696void gdlm_submit_delayed(struct gdlm_ls *ls)
697{
698 struct gdlm_lock *lp, *safe;
699
700 spin_lock(&ls->async_lock);
701 list_for_each_entry_safe(lp, safe, &ls->delayed, delay_list) {
702 list_del_init(&lp->delay_list);
703 list_add_tail(&lp->delay_list, &ls->submit);
704 }
705 spin_unlock(&ls->async_lock);
706 wake_up(&ls->thread_wait);
707}
708
diff --git a/fs/gfs2/locking/dlm/lock_dlm.h b/fs/gfs2/locking/dlm/lock_dlm.h
deleted file mode 100644
index 3c98e7c6f93b..000000000000
--- a/fs/gfs2/locking/dlm/lock_dlm.h
+++ /dev/null
@@ -1,166 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#ifndef LOCK_DLM_DOT_H
11#define LOCK_DLM_DOT_H
12
13#include <linux/module.h>
14#include <linux/slab.h>
15#include <linux/spinlock.h>
16#include <linux/types.h>
17#include <linux/string.h>
18#include <linux/list.h>
19#include <linux/socket.h>
20#include <linux/delay.h>
21#include <linux/kthread.h>
22#include <linux/kobject.h>
23#include <linux/fcntl.h>
24#include <linux/wait.h>
25#include <net/sock.h>
26
27#include <linux/dlm.h>
28#include <linux/dlm_plock.h>
29#include <linux/lm_interface.h>
30
31/*
32 * Internally, we prefix things with gdlm_ and GDLM_ (for gfs-dlm) since a
33 * prefix of lock_dlm_ gets awkward. Externally, GFS refers to this module
34 * as "lock_dlm".
35 */
36
37#define GDLM_STRNAME_BYTES 24
38#define GDLM_LVB_SIZE 32
39#define GDLM_DROP_COUNT 0
40#define GDLM_DROP_PERIOD 60
41#define GDLM_NAME_LEN 128
42
43/* GFS uses 12 bytes to identify a resource (32 bit type + 64 bit number).
44 We sprintf these numbers into a 24 byte string of hex values to make them
45 human-readable (to make debugging simpler.) */
46
47struct gdlm_strname {
48 unsigned char name[GDLM_STRNAME_BYTES];
49 unsigned short namelen;
50};
51
52enum {
53 DFL_BLOCK_LOCKS = 0,
54 DFL_SPECTATOR = 1,
55 DFL_WITHDRAW = 2,
56};
57
58struct gdlm_ls {
59 u32 id;
60 int jid;
61 int first;
62 int first_done;
63 unsigned long flags;
64 struct kobject kobj;
65 char clustername[GDLM_NAME_LEN];
66 char fsname[GDLM_NAME_LEN];
67 int fsflags;
68 dlm_lockspace_t *dlm_lockspace;
69 lm_callback_t fscb;
70 struct gfs2_sbd *sdp;
71 int recover_jid;
72 int recover_jid_done;
73 int recover_jid_status;
74 spinlock_t async_lock;
75 struct list_head delayed;
76 struct list_head submit;
77 u32 all_locks_count;
78 wait_queue_head_t wait_control;
79 struct task_struct *thread;
80 wait_queue_head_t thread_wait;
81};
82
83enum {
84 LFL_NOBLOCK = 0,
85 LFL_NOCACHE = 1,
86 LFL_DLM_UNLOCK = 2,
87 LFL_DLM_CANCEL = 3,
88 LFL_SYNC_LVB = 4,
89 LFL_FORCE_PROMOTE = 5,
90 LFL_REREQUEST = 6,
91 LFL_ACTIVE = 7,
92 LFL_INLOCK = 8,
93 LFL_CANCEL = 9,
94 LFL_NOBAST = 10,
95 LFL_HEADQUE = 11,
96 LFL_UNLOCK_DELETE = 12,
97 LFL_AST_WAIT = 13,
98};
99
100struct gdlm_lock {
101 struct gdlm_ls *ls;
102 struct lm_lockname lockname;
103 struct gdlm_strname strname;
104 char *lvb;
105 struct dlm_lksb lksb;
106
107 s16 cur;
108 s16 req;
109 s16 prev_req;
110 u32 lkf; /* dlm flags DLM_LKF_ */
111 unsigned long flags; /* lock_dlm flags LFL_ */
112
113 struct list_head delay_list; /* delayed */
114 struct gdlm_lock *hold_null; /* NL lock for hold_lvb */
115};
116
117#define gdlm_assert(assertion, fmt, args...) \
118do { \
119 if (unlikely(!(assertion))) { \
120 printk(KERN_EMERG "lock_dlm: fatal assertion failed \"%s\"\n" \
121 "lock_dlm: " fmt "\n", \
122 #assertion, ##args); \
123 BUG(); \
124 } \
125} while (0)
126
127#define log_print(lev, fmt, arg...) printk(lev "lock_dlm: " fmt "\n" , ## arg)
128#define log_info(fmt, arg...) log_print(KERN_INFO , fmt , ## arg)
129#define log_error(fmt, arg...) log_print(KERN_ERR , fmt , ## arg)
130#ifdef LOCK_DLM_LOG_DEBUG
131#define log_debug(fmt, arg...) log_print(KERN_DEBUG , fmt , ## arg)
132#else
133#define log_debug(fmt, arg...)
134#endif
135
136/* sysfs.c */
137
138int gdlm_sysfs_init(void);
139void gdlm_sysfs_exit(void);
140int gdlm_kobject_setup(struct gdlm_ls *, struct kobject *);
141void gdlm_kobject_release(struct gdlm_ls *);
142
143/* thread.c */
144
145int gdlm_init_threads(struct gdlm_ls *);
146void gdlm_release_threads(struct gdlm_ls *);
147
148/* lock.c */
149
150void gdlm_submit_delayed(struct gdlm_ls *);
151unsigned int gdlm_do_lock(struct gdlm_lock *);
152
153int gdlm_get_lock(void *, struct lm_lockname *, void **);
154void gdlm_put_lock(void *);
155unsigned int gdlm_lock(void *, unsigned int, unsigned int, unsigned int);
156unsigned int gdlm_unlock(void *, unsigned int);
157void gdlm_cancel(void *);
158int gdlm_hold_lvb(void *, char **);
159void gdlm_unhold_lvb(void *, char *);
160
161/* mount.c */
162
163extern const struct lm_lockops gdlm_ops;
164
165#endif
166
diff --git a/fs/gfs2/locking/dlm/main.c b/fs/gfs2/locking/dlm/main.c
deleted file mode 100644
index b9a03a7ff801..000000000000
--- a/fs/gfs2/locking/dlm/main.c
+++ /dev/null
@@ -1,48 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include <linux/init.h>
11
12#include "lock_dlm.h"
13
14static int __init init_lock_dlm(void)
15{
16 int error;
17
18 error = gfs2_register_lockproto(&gdlm_ops);
19 if (error) {
20 printk(KERN_WARNING "lock_dlm: can't register protocol: %d\n",
21 error);
22 return error;
23 }
24
25 error = gdlm_sysfs_init();
26 if (error) {
27 gfs2_unregister_lockproto(&gdlm_ops);
28 return error;
29 }
30
31 printk(KERN_INFO
32 "Lock_DLM (built %s %s) installed\n", __DATE__, __TIME__);
33 return 0;
34}
35
36static void __exit exit_lock_dlm(void)
37{
38 gdlm_sysfs_exit();
39 gfs2_unregister_lockproto(&gdlm_ops);
40}
41
42module_init(init_lock_dlm);
43module_exit(exit_lock_dlm);
44
45MODULE_DESCRIPTION("GFS DLM Locking Module");
46MODULE_AUTHOR("Red Hat, Inc.");
47MODULE_LICENSE("GPL");
48
diff --git a/fs/gfs2/locking/dlm/mount.c b/fs/gfs2/locking/dlm/mount.c
deleted file mode 100644
index 1aa7eb6a0226..000000000000
--- a/fs/gfs2/locking/dlm/mount.c
+++ /dev/null
@@ -1,276 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include "lock_dlm.h"
11
12const struct lm_lockops gdlm_ops;
13
14
15static struct gdlm_ls *init_gdlm(lm_callback_t cb, struct gfs2_sbd *sdp,
16 int flags, char *table_name)
17{
18 struct gdlm_ls *ls;
19 char buf[256], *p;
20
21 ls = kzalloc(sizeof(struct gdlm_ls), GFP_KERNEL);
22 if (!ls)
23 return NULL;
24
25 ls->fscb = cb;
26 ls->sdp = sdp;
27 ls->fsflags = flags;
28 spin_lock_init(&ls->async_lock);
29 INIT_LIST_HEAD(&ls->delayed);
30 INIT_LIST_HEAD(&ls->submit);
31 init_waitqueue_head(&ls->thread_wait);
32 init_waitqueue_head(&ls->wait_control);
33 ls->jid = -1;
34
35 strncpy(buf, table_name, 256);
36 buf[255] = '\0';
37
38 p = strchr(buf, ':');
39 if (!p) {
40 log_info("invalid table_name \"%s\"", table_name);
41 kfree(ls);
42 return NULL;
43 }
44 *p = '\0';
45 p++;
46
47 strncpy(ls->clustername, buf, GDLM_NAME_LEN);
48 strncpy(ls->fsname, p, GDLM_NAME_LEN);
49
50 return ls;
51}
52
53static int make_args(struct gdlm_ls *ls, char *data_arg, int *nodir)
54{
55 char data[256];
56 char *options, *x, *y;
57 int error = 0;
58
59 memset(data, 0, 256);
60 strncpy(data, data_arg, 255);
61
62 if (!strlen(data)) {
63 log_error("no mount options, (u)mount helpers not installed");
64 return -EINVAL;
65 }
66
67 for (options = data; (x = strsep(&options, ":")); ) {
68 if (!*x)
69 continue;
70
71 y = strchr(x, '=');
72 if (y)
73 *y++ = 0;
74
75 if (!strcmp(x, "jid")) {
76 if (!y) {
77 log_error("need argument to jid");
78 error = -EINVAL;
79 break;
80 }
81 sscanf(y, "%u", &ls->jid);
82
83 } else if (!strcmp(x, "first")) {
84 if (!y) {
85 log_error("need argument to first");
86 error = -EINVAL;
87 break;
88 }
89 sscanf(y, "%u", &ls->first);
90
91 } else if (!strcmp(x, "id")) {
92 if (!y) {
93 log_error("need argument to id");
94 error = -EINVAL;
95 break;
96 }
97 sscanf(y, "%u", &ls->id);
98
99 } else if (!strcmp(x, "nodir")) {
100 if (!y) {
101 log_error("need argument to nodir");
102 error = -EINVAL;
103 break;
104 }
105 sscanf(y, "%u", nodir);
106
107 } else {
108 log_error("unkonwn option: %s", x);
109 error = -EINVAL;
110 break;
111 }
112 }
113
114 return error;
115}
116
117static int gdlm_mount(char *table_name, char *host_data,
118 lm_callback_t cb, void *cb_data,
119 unsigned int min_lvb_size, int flags,
120 struct lm_lockstruct *lockstruct,
121 struct kobject *fskobj)
122{
123 struct gdlm_ls *ls;
124 int error = -ENOMEM, nodir = 0;
125
126 if (min_lvb_size > GDLM_LVB_SIZE)
127 goto out;
128
129 ls = init_gdlm(cb, cb_data, flags, table_name);
130 if (!ls)
131 goto out;
132
133 error = make_args(ls, host_data, &nodir);
134 if (error)
135 goto out;
136
137 error = gdlm_init_threads(ls);
138 if (error)
139 goto out_free;
140
141 error = gdlm_kobject_setup(ls, fskobj);
142 if (error)
143 goto out_thread;
144
145 error = dlm_new_lockspace(ls->fsname, strlen(ls->fsname),
146 &ls->dlm_lockspace,
147 DLM_LSFL_FS | DLM_LSFL_NEWEXCL |
148 (nodir ? DLM_LSFL_NODIR : 0),
149 GDLM_LVB_SIZE);
150 if (error) {
151 log_error("dlm_new_lockspace error %d", error);
152 goto out_kobj;
153 }
154
155 lockstruct->ls_jid = ls->jid;
156 lockstruct->ls_first = ls->first;
157 lockstruct->ls_lockspace = ls;
158 lockstruct->ls_ops = &gdlm_ops;
159 lockstruct->ls_flags = 0;
160 lockstruct->ls_lvb_size = GDLM_LVB_SIZE;
161 return 0;
162
163out_kobj:
164 gdlm_kobject_release(ls);
165out_thread:
166 gdlm_release_threads(ls);
167out_free:
168 kfree(ls);
169out:
170 return error;
171}
172
173static void gdlm_unmount(void *lockspace)
174{
175 struct gdlm_ls *ls = lockspace;
176
177 log_debug("unmount flags %lx", ls->flags);
178
179 /* FIXME: serialize unmount and withdraw in case they
180 happen at once. Also, if unmount follows withdraw,
181 wait for withdraw to finish. */
182
183 if (test_bit(DFL_WITHDRAW, &ls->flags))
184 goto out;
185
186 gdlm_kobject_release(ls);
187 dlm_release_lockspace(ls->dlm_lockspace, 2);
188 gdlm_release_threads(ls);
189 BUG_ON(ls->all_locks_count);
190out:
191 kfree(ls);
192}
193
194static void gdlm_recovery_done(void *lockspace, unsigned int jid,
195 unsigned int message)
196{
197 char env_jid[20];
198 char env_status[20];
199 char *envp[] = { env_jid, env_status, NULL };
200 struct gdlm_ls *ls = lockspace;
201 ls->recover_jid_done = jid;
202 ls->recover_jid_status = message;
203 sprintf(env_jid, "JID=%d", jid);
204 sprintf(env_status, "RECOVERY=%s",
205 message == LM_RD_SUCCESS ? "Done" : "Failed");
206 kobject_uevent_env(&ls->kobj, KOBJ_CHANGE, envp);
207}
208
209static void gdlm_others_may_mount(void *lockspace)
210{
211 char *message = "FIRSTMOUNT=Done";
212 char *envp[] = { message, NULL };
213 struct gdlm_ls *ls = lockspace;
214 ls->first_done = 1;
215 kobject_uevent_env(&ls->kobj, KOBJ_CHANGE, envp);
216}
217
218/* Userspace gets the offline uevent, blocks new gfs locks on
219 other mounters, and lets us know (sets WITHDRAW flag). Then,
220 userspace leaves the mount group while we leave the lockspace. */
221
222static void gdlm_withdraw(void *lockspace)
223{
224 struct gdlm_ls *ls = lockspace;
225
226 kobject_uevent(&ls->kobj, KOBJ_OFFLINE);
227
228 wait_event_interruptible(ls->wait_control,
229 test_bit(DFL_WITHDRAW, &ls->flags));
230
231 dlm_release_lockspace(ls->dlm_lockspace, 2);
232 gdlm_release_threads(ls);
233 gdlm_kobject_release(ls);
234}
235
236static int gdlm_plock(void *lockspace, struct lm_lockname *name,
237 struct file *file, int cmd, struct file_lock *fl)
238{
239 struct gdlm_ls *ls = lockspace;
240 return dlm_posix_lock(ls->dlm_lockspace, name->ln_number, file, cmd, fl);
241}
242
243static int gdlm_punlock(void *lockspace, struct lm_lockname *name,
244 struct file *file, struct file_lock *fl)
245{
246 struct gdlm_ls *ls = lockspace;
247 return dlm_posix_unlock(ls->dlm_lockspace, name->ln_number, file, fl);
248}
249
250static int gdlm_plock_get(void *lockspace, struct lm_lockname *name,
251 struct file *file, struct file_lock *fl)
252{
253 struct gdlm_ls *ls = lockspace;
254 return dlm_posix_get(ls->dlm_lockspace, name->ln_number, file, fl);
255}
256
257const struct lm_lockops gdlm_ops = {
258 .lm_proto_name = "lock_dlm",
259 .lm_mount = gdlm_mount,
260 .lm_others_may_mount = gdlm_others_may_mount,
261 .lm_unmount = gdlm_unmount,
262 .lm_withdraw = gdlm_withdraw,
263 .lm_get_lock = gdlm_get_lock,
264 .lm_put_lock = gdlm_put_lock,
265 .lm_lock = gdlm_lock,
266 .lm_unlock = gdlm_unlock,
267 .lm_plock = gdlm_plock,
268 .lm_punlock = gdlm_punlock,
269 .lm_plock_get = gdlm_plock_get,
270 .lm_cancel = gdlm_cancel,
271 .lm_hold_lvb = gdlm_hold_lvb,
272 .lm_unhold_lvb = gdlm_unhold_lvb,
273 .lm_recovery_done = gdlm_recovery_done,
274 .lm_owner = THIS_MODULE,
275};
276
diff --git a/fs/gfs2/locking/dlm/sysfs.c b/fs/gfs2/locking/dlm/sysfs.c
deleted file mode 100644
index 9b7edcf7bd49..000000000000
--- a/fs/gfs2/locking/dlm/sysfs.c
+++ /dev/null
@@ -1,226 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include <linux/ctype.h>
11#include <linux/stat.h>
12
13#include "lock_dlm.h"
14
15static ssize_t proto_name_show(struct gdlm_ls *ls, char *buf)
16{
17 return sprintf(buf, "%s\n", gdlm_ops.lm_proto_name);
18}
19
20static ssize_t block_show(struct gdlm_ls *ls, char *buf)
21{
22 ssize_t ret;
23 int val = 0;
24
25 if (test_bit(DFL_BLOCK_LOCKS, &ls->flags))
26 val = 1;
27 ret = sprintf(buf, "%d\n", val);
28 return ret;
29}
30
31static ssize_t block_store(struct gdlm_ls *ls, const char *buf, size_t len)
32{
33 ssize_t ret = len;
34 int val;
35
36 val = simple_strtol(buf, NULL, 0);
37
38 if (val == 1)
39 set_bit(DFL_BLOCK_LOCKS, &ls->flags);
40 else if (val == 0) {
41 clear_bit(DFL_BLOCK_LOCKS, &ls->flags);
42 gdlm_submit_delayed(ls);
43 } else {
44 ret = -EINVAL;
45 }
46 return ret;
47}
48
49static ssize_t withdraw_show(struct gdlm_ls *ls, char *buf)
50{
51 ssize_t ret;
52 int val = 0;
53
54 if (test_bit(DFL_WITHDRAW, &ls->flags))
55 val = 1;
56 ret = sprintf(buf, "%d\n", val);
57 return ret;
58}
59
60static ssize_t withdraw_store(struct gdlm_ls *ls, const char *buf, size_t len)
61{
62 ssize_t ret = len;
63 int val;
64
65 val = simple_strtol(buf, NULL, 0);
66
67 if (val == 1)
68 set_bit(DFL_WITHDRAW, &ls->flags);
69 else
70 ret = -EINVAL;
71 wake_up(&ls->wait_control);
72 return ret;
73}
74
75static ssize_t id_show(struct gdlm_ls *ls, char *buf)
76{
77 return sprintf(buf, "%u\n", ls->id);
78}
79
80static ssize_t jid_show(struct gdlm_ls *ls, char *buf)
81{
82 return sprintf(buf, "%d\n", ls->jid);
83}
84
85static ssize_t first_show(struct gdlm_ls *ls, char *buf)
86{
87 return sprintf(buf, "%d\n", ls->first);
88}
89
90static ssize_t first_done_show(struct gdlm_ls *ls, char *buf)
91{
92 return sprintf(buf, "%d\n", ls->first_done);
93}
94
95static ssize_t recover_show(struct gdlm_ls *ls, char *buf)
96{
97 return sprintf(buf, "%d\n", ls->recover_jid);
98}
99
100static ssize_t recover_store(struct gdlm_ls *ls, const char *buf, size_t len)
101{
102 ls->recover_jid = simple_strtol(buf, NULL, 0);
103 ls->fscb(ls->sdp, LM_CB_NEED_RECOVERY, &ls->recover_jid);
104 return len;
105}
106
107static ssize_t recover_done_show(struct gdlm_ls *ls, char *buf)
108{
109 return sprintf(buf, "%d\n", ls->recover_jid_done);
110}
111
112static ssize_t recover_status_show(struct gdlm_ls *ls, char *buf)
113{
114 return sprintf(buf, "%d\n", ls->recover_jid_status);
115}
116
117struct gdlm_attr {
118 struct attribute attr;
119 ssize_t (*show)(struct gdlm_ls *, char *);
120 ssize_t (*store)(struct gdlm_ls *, const char *, size_t);
121};
122
123#define GDLM_ATTR(_name,_mode,_show,_store) \
124static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
125
126GDLM_ATTR(proto_name, 0444, proto_name_show, NULL);
127GDLM_ATTR(block, 0644, block_show, block_store);
128GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
129GDLM_ATTR(id, 0444, id_show, NULL);
130GDLM_ATTR(jid, 0444, jid_show, NULL);
131GDLM_ATTR(first, 0444, first_show, NULL);
132GDLM_ATTR(first_done, 0444, first_done_show, NULL);
133GDLM_ATTR(recover, 0644, recover_show, recover_store);
134GDLM_ATTR(recover_done, 0444, recover_done_show, NULL);
135GDLM_ATTR(recover_status, 0444, recover_status_show, NULL);
136
137static struct attribute *gdlm_attrs[] = {
138 &gdlm_attr_proto_name.attr,
139 &gdlm_attr_block.attr,
140 &gdlm_attr_withdraw.attr,
141 &gdlm_attr_id.attr,
142 &gdlm_attr_jid.attr,
143 &gdlm_attr_first.attr,
144 &gdlm_attr_first_done.attr,
145 &gdlm_attr_recover.attr,
146 &gdlm_attr_recover_done.attr,
147 &gdlm_attr_recover_status.attr,
148 NULL,
149};
150
151static ssize_t gdlm_attr_show(struct kobject *kobj, struct attribute *attr,
152 char *buf)
153{
154 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
155 struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
156 return a->show ? a->show(ls, buf) : 0;
157}
158
159static ssize_t gdlm_attr_store(struct kobject *kobj, struct attribute *attr,
160 const char *buf, size_t len)
161{
162 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
163 struct gdlm_attr *a = container_of(attr, struct gdlm_attr, attr);
164 return a->store ? a->store(ls, buf, len) : len;
165}
166
167static struct sysfs_ops gdlm_attr_ops = {
168 .show = gdlm_attr_show,
169 .store = gdlm_attr_store,
170};
171
172static struct kobj_type gdlm_ktype = {
173 .default_attrs = gdlm_attrs,
174 .sysfs_ops = &gdlm_attr_ops,
175};
176
177static struct kset *gdlm_kset;
178
179int gdlm_kobject_setup(struct gdlm_ls *ls, struct kobject *fskobj)
180{
181 int error;
182
183 ls->kobj.kset = gdlm_kset;
184 error = kobject_init_and_add(&ls->kobj, &gdlm_ktype, fskobj,
185 "lock_module");
186 if (error)
187 log_error("can't register kobj %d", error);
188 kobject_uevent(&ls->kobj, KOBJ_ADD);
189
190 return error;
191}
192
193void gdlm_kobject_release(struct gdlm_ls *ls)
194{
195 kobject_put(&ls->kobj);
196}
197
198static int gdlm_uevent(struct kset *kset, struct kobject *kobj,
199 struct kobj_uevent_env *env)
200{
201 struct gdlm_ls *ls = container_of(kobj, struct gdlm_ls, kobj);
202 add_uevent_var(env, "LOCKTABLE=%s:%s", ls->clustername, ls->fsname);
203 add_uevent_var(env, "LOCKPROTO=lock_dlm");
204 return 0;
205}
206
207static struct kset_uevent_ops gdlm_uevent_ops = {
208 .uevent = gdlm_uevent,
209};
210
211
212int gdlm_sysfs_init(void)
213{
214 gdlm_kset = kset_create_and_add("lock_dlm", &gdlm_uevent_ops, kernel_kobj);
215 if (!gdlm_kset) {
216 printk(KERN_WARNING "%s: can not create kset\n", __func__);
217 return -ENOMEM;
218 }
219 return 0;
220}
221
222void gdlm_sysfs_exit(void)
223{
224 kset_unregister(gdlm_kset);
225}
226
diff --git a/fs/gfs2/locking/dlm/thread.c b/fs/gfs2/locking/dlm/thread.c
deleted file mode 100644
index 38823efd698c..000000000000
--- a/fs/gfs2/locking/dlm/thread.c
+++ /dev/null
@@ -1,68 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2005 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#include "lock_dlm.h"
11
12static inline int no_work(struct gdlm_ls *ls)
13{
14 int ret;
15
16 spin_lock(&ls->async_lock);
17 ret = list_empty(&ls->submit);
18 spin_unlock(&ls->async_lock);
19
20 return ret;
21}
22
23static int gdlm_thread(void *data)
24{
25 struct gdlm_ls *ls = (struct gdlm_ls *) data;
26 struct gdlm_lock *lp = NULL;
27
28 while (!kthread_should_stop()) {
29 wait_event_interruptible(ls->thread_wait,
30 !no_work(ls) || kthread_should_stop());
31
32 spin_lock(&ls->async_lock);
33
34 if (!list_empty(&ls->submit)) {
35 lp = list_entry(ls->submit.next, struct gdlm_lock,
36 delay_list);
37 list_del_init(&lp->delay_list);
38 spin_unlock(&ls->async_lock);
39 gdlm_do_lock(lp);
40 spin_lock(&ls->async_lock);
41 }
42 spin_unlock(&ls->async_lock);
43 }
44
45 return 0;
46}
47
48int gdlm_init_threads(struct gdlm_ls *ls)
49{
50 struct task_struct *p;
51 int error;
52
53 p = kthread_run(gdlm_thread, ls, "lock_dlm");
54 error = IS_ERR(p);
55 if (error) {
56 log_error("can't start lock_dlm thread %d", error);
57 return error;
58 }
59 ls->thread = p;
60
61 return 0;
62}
63
64void gdlm_release_threads(struct gdlm_ls *ls)
65{
66 kthread_stop(ls->thread);
67}
68
diff --git a/fs/gfs2/log.c b/fs/gfs2/log.c
index ad305854bdc6..98918a756410 100644
--- a/fs/gfs2/log.c
+++ b/fs/gfs2/log.c
@@ -14,7 +14,6 @@
14#include <linux/buffer_head.h> 14#include <linux/buffer_head.h>
15#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
16#include <linux/crc32.h> 16#include <linux/crc32.h>
17#include <linux/lm_interface.h>
18#include <linux/delay.h> 17#include <linux/delay.h>
19#include <linux/kthread.h> 18#include <linux/kthread.h>
20#include <linux/freezer.h> 19#include <linux/freezer.h>
diff --git a/fs/gfs2/lops.c b/fs/gfs2/lops.c
index 4390f6f4047d..80e4f5f898bb 100644
--- a/fs/gfs2/lops.c
+++ b/fs/gfs2/lops.c
@@ -13,7 +13,6 @@
13#include <linux/completion.h> 13#include <linux/completion.h>
14#include <linux/buffer_head.h> 14#include <linux/buffer_head.h>
15#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
16#include <linux/lm_interface.h>
17 16
18#include "gfs2.h" 17#include "gfs2.h"
19#include "incore.h" 18#include "incore.h"
diff --git a/fs/gfs2/main.c b/fs/gfs2/main.c
index 7cacfde32194..a6892ed0840a 100644
--- a/fs/gfs2/main.c
+++ b/fs/gfs2/main.c
@@ -14,7 +14,6 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/gfs2_ondisk.h> 16#include <linux/gfs2_ondisk.h>
17#include <linux/lm_interface.h>
18#include <asm/atomic.h> 17#include <asm/atomic.h>
19 18
20#include "gfs2.h" 19#include "gfs2.h"
@@ -23,6 +22,12 @@
23#include "sys.h" 22#include "sys.h"
24#include "util.h" 23#include "util.h"
25#include "glock.h" 24#include "glock.h"
25#include "quota.h"
26
27static struct shrinker qd_shrinker = {
28 .shrink = gfs2_shrink_qd_memory,
29 .seeks = DEFAULT_SEEKS,
30};
26 31
27static void gfs2_init_inode_once(void *foo) 32static void gfs2_init_inode_once(void *foo)
28{ 33{
@@ -41,8 +46,6 @@ static void gfs2_init_glock_once(void *foo)
41 INIT_HLIST_NODE(&gl->gl_list); 46 INIT_HLIST_NODE(&gl->gl_list);
42 spin_lock_init(&gl->gl_spin); 47 spin_lock_init(&gl->gl_spin);
43 INIT_LIST_HEAD(&gl->gl_holders); 48 INIT_LIST_HEAD(&gl->gl_holders);
44 gl->gl_lvb = NULL;
45 atomic_set(&gl->gl_lvb_count, 0);
46 INIT_LIST_HEAD(&gl->gl_lru); 49 INIT_LIST_HEAD(&gl->gl_lru);
47 INIT_LIST_HEAD(&gl->gl_ail_list); 50 INIT_LIST_HEAD(&gl->gl_ail_list);
48 atomic_set(&gl->gl_ail_count, 0); 51 atomic_set(&gl->gl_ail_count, 0);
@@ -100,6 +103,8 @@ static int __init init_gfs2_fs(void)
100 if (!gfs2_quotad_cachep) 103 if (!gfs2_quotad_cachep)
101 goto fail; 104 goto fail;
102 105
106 register_shrinker(&qd_shrinker);
107
103 error = register_filesystem(&gfs2_fs_type); 108 error = register_filesystem(&gfs2_fs_type);
104 if (error) 109 if (error)
105 goto fail; 110 goto fail;
@@ -117,6 +122,7 @@ static int __init init_gfs2_fs(void)
117fail_unregister: 122fail_unregister:
118 unregister_filesystem(&gfs2_fs_type); 123 unregister_filesystem(&gfs2_fs_type);
119fail: 124fail:
125 unregister_shrinker(&qd_shrinker);
120 gfs2_glock_exit(); 126 gfs2_glock_exit();
121 127
122 if (gfs2_quotad_cachep) 128 if (gfs2_quotad_cachep)
@@ -145,6 +151,7 @@ fail:
145 151
146static void __exit exit_gfs2_fs(void) 152static void __exit exit_gfs2_fs(void)
147{ 153{
154 unregister_shrinker(&qd_shrinker);
148 gfs2_glock_exit(); 155 gfs2_glock_exit();
149 gfs2_unregister_debugfs(); 156 gfs2_unregister_debugfs();
150 unregister_filesystem(&gfs2_fs_type); 157 unregister_filesystem(&gfs2_fs_type);
diff --git a/fs/gfs2/meta_io.c b/fs/gfs2/meta_io.c
index 09853620c951..8d6f13256b26 100644
--- a/fs/gfs2/meta_io.c
+++ b/fs/gfs2/meta_io.c
@@ -19,7 +19,6 @@
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/bio.h> 20#include <linux/bio.h>
21#include <linux/gfs2_ondisk.h> 21#include <linux/gfs2_ondisk.h>
22#include <linux/lm_interface.h>
23 22
24#include "gfs2.h" 23#include "gfs2.h"
25#include "incore.h" 24#include "incore.h"
@@ -90,27 +89,6 @@ void gfs2_aspace_put(struct inode *aspace)
90} 89}
91 90
92/** 91/**
93 * gfs2_meta_inval - Invalidate all buffers associated with a glock
94 * @gl: the glock
95 *
96 */
97
98void gfs2_meta_inval(struct gfs2_glock *gl)
99{
100 struct gfs2_sbd *sdp = gl->gl_sbd;
101 struct inode *aspace = gl->gl_aspace;
102 struct address_space *mapping = gl->gl_aspace->i_mapping;
103
104 gfs2_assert_withdraw(sdp, !atomic_read(&gl->gl_ail_count));
105
106 atomic_inc(&aspace->i_writecount);
107 truncate_inode_pages(mapping, 0);
108 atomic_dec(&aspace->i_writecount);
109
110 gfs2_assert_withdraw(sdp, !mapping->nrpages);
111}
112
113/**
114 * gfs2_meta_sync - Sync all buffers associated with a glock 92 * gfs2_meta_sync - Sync all buffers associated with a glock
115 * @gl: The glock 93 * @gl: The glock
116 * 94 *
diff --git a/fs/gfs2/meta_io.h b/fs/gfs2/meta_io.h
index b1a5f3674d43..de270c2f9b63 100644
--- a/fs/gfs2/meta_io.h
+++ b/fs/gfs2/meta_io.h
@@ -40,7 +40,6 @@ static inline void gfs2_buffer_copy_tail(struct buffer_head *to_bh,
40struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp); 40struct inode *gfs2_aspace_get(struct gfs2_sbd *sdp);
41void gfs2_aspace_put(struct inode *aspace); 41void gfs2_aspace_put(struct inode *aspace);
42 42
43void gfs2_meta_inval(struct gfs2_glock *gl);
44void gfs2_meta_sync(struct gfs2_glock *gl); 43void gfs2_meta_sync(struct gfs2_glock *gl);
45 44
46struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno); 45struct buffer_head *gfs2_meta_new(struct gfs2_glock *gl, u64 blkno);
diff --git a/fs/gfs2/mount.c b/fs/gfs2/mount.c
index 3cb0a44ba023..f7e8527a21e0 100644
--- a/fs/gfs2/mount.c
+++ b/fs/gfs2/mount.c
@@ -12,12 +12,11 @@
12#include <linux/completion.h> 12#include <linux/completion.h>
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/gfs2_ondisk.h> 14#include <linux/gfs2_ondisk.h>
15#include <linux/lm_interface.h>
16#include <linux/parser.h> 15#include <linux/parser.h>
17 16
18#include "gfs2.h" 17#include "gfs2.h"
19#include "incore.h" 18#include "incore.h"
20#include "mount.h" 19#include "super.h"
21#include "sys.h" 20#include "sys.h"
22#include "util.h" 21#include "util.h"
23 22
@@ -37,11 +36,15 @@ enum {
37 Opt_quota_off, 36 Opt_quota_off,
38 Opt_quota_account, 37 Opt_quota_account,
39 Opt_quota_on, 38 Opt_quota_on,
39 Opt_quota,
40 Opt_noquota,
40 Opt_suiddir, 41 Opt_suiddir,
41 Opt_nosuiddir, 42 Opt_nosuiddir,
42 Opt_data_writeback, 43 Opt_data_writeback,
43 Opt_data_ordered, 44 Opt_data_ordered,
44 Opt_meta, 45 Opt_meta,
46 Opt_discard,
47 Opt_nodiscard,
45 Opt_err, 48 Opt_err,
46}; 49};
47 50
@@ -61,11 +64,15 @@ static const match_table_t tokens = {
61 {Opt_quota_off, "quota=off"}, 64 {Opt_quota_off, "quota=off"},
62 {Opt_quota_account, "quota=account"}, 65 {Opt_quota_account, "quota=account"},
63 {Opt_quota_on, "quota=on"}, 66 {Opt_quota_on, "quota=on"},
67 {Opt_quota, "quota"},
68 {Opt_noquota, "noquota"},
64 {Opt_suiddir, "suiddir"}, 69 {Opt_suiddir, "suiddir"},
65 {Opt_nosuiddir, "nosuiddir"}, 70 {Opt_nosuiddir, "nosuiddir"},
66 {Opt_data_writeback, "data=writeback"}, 71 {Opt_data_writeback, "data=writeback"},
67 {Opt_data_ordered, "data=ordered"}, 72 {Opt_data_ordered, "data=ordered"},
68 {Opt_meta, "meta"}, 73 {Opt_meta, "meta"},
74 {Opt_discard, "discard"},
75 {Opt_nodiscard, "nodiscard"},
69 {Opt_err, NULL} 76 {Opt_err, NULL}
70}; 77};
71 78
@@ -77,101 +84,46 @@ static const match_table_t tokens = {
77 * Return: errno 84 * Return: errno
78 */ 85 */
79 86
80int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount) 87int gfs2_mount_args(struct gfs2_sbd *sdp, struct gfs2_args *args, char *options)
81{ 88{
82 struct gfs2_args *args = &sdp->sd_args; 89 char *o;
83 char *data = data_arg; 90 int token;
84 char *options, *o, *v; 91 substring_t tmp[MAX_OPT_ARGS];
85 int error = 0;
86
87 if (!remount) {
88 /* Set some defaults */
89 args->ar_quota = GFS2_QUOTA_DEFAULT;
90 args->ar_data = GFS2_DATA_DEFAULT;
91 }
92 92
93 /* Split the options into tokens with the "," character and 93 /* Split the options into tokens with the "," character and
94 process them */ 94 process them */
95 95
96 for (options = data; (o = strsep(&options, ",")); ) { 96 while (1) {
97 int token; 97 o = strsep(&options, ",");
98 substring_t tmp[MAX_OPT_ARGS]; 98 if (o == NULL)
99 99 break;
100 if (!*o) 100 if (*o == '\0')
101 continue; 101 continue;
102 102
103 token = match_token(o, tokens, tmp); 103 token = match_token(o, tokens, tmp);
104 switch (token) { 104 switch (token) {
105 case Opt_lockproto: 105 case Opt_lockproto:
106 v = match_strdup(&tmp[0]); 106 match_strlcpy(args->ar_lockproto, &tmp[0],
107 if (!v) { 107 GFS2_LOCKNAME_LEN);
108 fs_info(sdp, "no memory for lockproto\n");
109 error = -ENOMEM;
110 goto out_error;
111 }
112
113 if (remount && strcmp(v, args->ar_lockproto)) {
114 kfree(v);
115 goto cant_remount;
116 }
117
118 strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
119 args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
120 kfree(v);
121 break; 108 break;
122 case Opt_locktable: 109 case Opt_locktable:
123 v = match_strdup(&tmp[0]); 110 match_strlcpy(args->ar_locktable, &tmp[0],
124 if (!v) { 111 GFS2_LOCKNAME_LEN);
125 fs_info(sdp, "no memory for locktable\n");
126 error = -ENOMEM;
127 goto out_error;
128 }
129
130 if (remount && strcmp(v, args->ar_locktable)) {
131 kfree(v);
132 goto cant_remount;
133 }
134
135 strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
136 args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0;
137 kfree(v);
138 break; 112 break;
139 case Opt_hostdata: 113 case Opt_hostdata:
140 v = match_strdup(&tmp[0]); 114 match_strlcpy(args->ar_hostdata, &tmp[0],
141 if (!v) { 115 GFS2_LOCKNAME_LEN);
142 fs_info(sdp, "no memory for hostdata\n");
143 error = -ENOMEM;
144 goto out_error;
145 }
146
147 if (remount && strcmp(v, args->ar_hostdata)) {
148 kfree(v);
149 goto cant_remount;
150 }
151
152 strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
153 args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
154 kfree(v);
155 break; 116 break;
156 case Opt_spectator: 117 case Opt_spectator:
157 if (remount && !args->ar_spectator)
158 goto cant_remount;
159 args->ar_spectator = 1; 118 args->ar_spectator = 1;
160 sdp->sd_vfs->s_flags |= MS_RDONLY;
161 break; 119 break;
162 case Opt_ignore_local_fs: 120 case Opt_ignore_local_fs:
163 if (remount && !args->ar_ignore_local_fs)
164 goto cant_remount;
165 args->ar_ignore_local_fs = 1; 121 args->ar_ignore_local_fs = 1;
166 break; 122 break;
167 case Opt_localflocks: 123 case Opt_localflocks:
168 if (remount && !args->ar_localflocks)
169 goto cant_remount;
170 args->ar_localflocks = 1; 124 args->ar_localflocks = 1;
171 break; 125 break;
172 case Opt_localcaching: 126 case Opt_localcaching:
173 if (remount && !args->ar_localcaching)
174 goto cant_remount;
175 args->ar_localcaching = 1; 127 args->ar_localcaching = 1;
176 break; 128 break;
177 case Opt_debug: 129 case Opt_debug:
@@ -181,25 +133,23 @@ int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
181 args->ar_debug = 0; 133 args->ar_debug = 0;
182 break; 134 break;
183 case Opt_upgrade: 135 case Opt_upgrade:
184 if (remount && !args->ar_upgrade)
185 goto cant_remount;
186 args->ar_upgrade = 1; 136 args->ar_upgrade = 1;
187 break; 137 break;
188 case Opt_acl: 138 case Opt_acl:
189 args->ar_posix_acl = 1; 139 args->ar_posix_acl = 1;
190 sdp->sd_vfs->s_flags |= MS_POSIXACL;
191 break; 140 break;
192 case Opt_noacl: 141 case Opt_noacl:
193 args->ar_posix_acl = 0; 142 args->ar_posix_acl = 0;
194 sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
195 break; 143 break;
196 case Opt_quota_off: 144 case Opt_quota_off:
145 case Opt_noquota:
197 args->ar_quota = GFS2_QUOTA_OFF; 146 args->ar_quota = GFS2_QUOTA_OFF;
198 break; 147 break;
199 case Opt_quota_account: 148 case Opt_quota_account:
200 args->ar_quota = GFS2_QUOTA_ACCOUNT; 149 args->ar_quota = GFS2_QUOTA_ACCOUNT;
201 break; 150 break;
202 case Opt_quota_on: 151 case Opt_quota_on:
152 case Opt_quota:
203 args->ar_quota = GFS2_QUOTA_ON; 153 args->ar_quota = GFS2_QUOTA_ON;
204 break; 154 break;
205 case Opt_suiddir: 155 case Opt_suiddir:
@@ -215,29 +165,21 @@ int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
215 args->ar_data = GFS2_DATA_ORDERED; 165 args->ar_data = GFS2_DATA_ORDERED;
216 break; 166 break;
217 case Opt_meta: 167 case Opt_meta:
218 if (remount && args->ar_meta != 1)
219 goto cant_remount;
220 args->ar_meta = 1; 168 args->ar_meta = 1;
221 break; 169 break;
170 case Opt_discard:
171 args->ar_discard = 1;
172 break;
173 case Opt_nodiscard:
174 args->ar_discard = 0;
175 break;
222 case Opt_err: 176 case Opt_err:
223 default: 177 default:
224 fs_info(sdp, "unknown option: %s\n", o); 178 fs_info(sdp, "invalid mount option: %s\n", o);
225 error = -EINVAL; 179 return -EINVAL;
226 goto out_error;
227 } 180 }
228 } 181 }
229 182
230out_error: 183 return 0;
231 if (error)
232 fs_info(sdp, "invalid mount option(s)\n");
233
234 if (data != data_arg)
235 kfree(data);
236
237 return error;
238
239cant_remount:
240 fs_info(sdp, "can't remount with option %s\n", o);
241 return -EINVAL;
242} 184}
243 185
diff --git a/fs/gfs2/mount.h b/fs/gfs2/mount.h
deleted file mode 100644
index 401288acfdf3..000000000000
--- a/fs/gfs2/mount.h
+++ /dev/null
@@ -1,17 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#ifndef __MOUNT_DOT_H__
11#define __MOUNT_DOT_H__
12
13struct gfs2_sbd;
14
15int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount);
16
17#endif /* __MOUNT_DOT_H__ */
diff --git a/fs/gfs2/ops_address.c b/fs/gfs2/ops_address.c
index 4ddab67867eb..a6dde1751e17 100644
--- a/fs/gfs2/ops_address.c
+++ b/fs/gfs2/ops_address.c
@@ -19,7 +19,6 @@
19#include <linux/writeback.h> 19#include <linux/writeback.h>
20#include <linux/swap.h> 20#include <linux/swap.h>
21#include <linux/gfs2_ondisk.h> 21#include <linux/gfs2_ondisk.h>
22#include <linux/lm_interface.h>
23#include <linux/backing-dev.h> 22#include <linux/backing-dev.h>
24 23
25#include "gfs2.h" 24#include "gfs2.h"
@@ -442,6 +441,7 @@ static int stuffed_readpage(struct gfs2_inode *ip, struct page *page)
442 */ 441 */
443 if (unlikely(page->index)) { 442 if (unlikely(page->index)) {
444 zero_user(page, 0, PAGE_CACHE_SIZE); 443 zero_user(page, 0, PAGE_CACHE_SIZE);
444 SetPageUptodate(page);
445 return 0; 445 return 0;
446 } 446 }
447 447
@@ -1096,6 +1096,7 @@ static const struct address_space_operations gfs2_writeback_aops = {
1096 .releasepage = gfs2_releasepage, 1096 .releasepage = gfs2_releasepage,
1097 .direct_IO = gfs2_direct_IO, 1097 .direct_IO = gfs2_direct_IO,
1098 .migratepage = buffer_migrate_page, 1098 .migratepage = buffer_migrate_page,
1099 .is_partially_uptodate = block_is_partially_uptodate,
1099}; 1100};
1100 1101
1101static const struct address_space_operations gfs2_ordered_aops = { 1102static const struct address_space_operations gfs2_ordered_aops = {
@@ -1111,6 +1112,7 @@ static const struct address_space_operations gfs2_ordered_aops = {
1111 .releasepage = gfs2_releasepage, 1112 .releasepage = gfs2_releasepage,
1112 .direct_IO = gfs2_direct_IO, 1113 .direct_IO = gfs2_direct_IO,
1113 .migratepage = buffer_migrate_page, 1114 .migratepage = buffer_migrate_page,
1115 .is_partially_uptodate = block_is_partially_uptodate,
1114}; 1116};
1115 1117
1116static const struct address_space_operations gfs2_jdata_aops = { 1118static const struct address_space_operations gfs2_jdata_aops = {
@@ -1125,6 +1127,7 @@ static const struct address_space_operations gfs2_jdata_aops = {
1125 .bmap = gfs2_bmap, 1127 .bmap = gfs2_bmap,
1126 .invalidatepage = gfs2_invalidatepage, 1128 .invalidatepage = gfs2_invalidatepage,
1127 .releasepage = gfs2_releasepage, 1129 .releasepage = gfs2_releasepage,
1130 .is_partially_uptodate = block_is_partially_uptodate,
1128}; 1131};
1129 1132
1130void gfs2_set_aops(struct inode *inode) 1133void gfs2_set_aops(struct inode *inode)
diff --git a/fs/gfs2/ops_dentry.c b/fs/gfs2/ops_dentry.c
index c2ad36330ca3..5eb57b044382 100644
--- a/fs/gfs2/ops_dentry.c
+++ b/fs/gfs2/ops_dentry.c
@@ -13,7 +13,6 @@
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/gfs2_ondisk.h> 14#include <linux/gfs2_ondisk.h>
15#include <linux/crc32.h> 15#include <linux/crc32.h>
16#include <linux/lm_interface.h>
17 16
18#include "gfs2.h" 17#include "gfs2.h"
19#include "incore.h" 18#include "incore.h"
diff --git a/fs/gfs2/ops_export.c b/fs/gfs2/ops_export.c
index 7fdeb14ddd1a..9200ef221716 100644
--- a/fs/gfs2/ops_export.c
+++ b/fs/gfs2/ops_export.c
@@ -14,7 +14,6 @@
14#include <linux/exportfs.h> 14#include <linux/exportfs.h>
15#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
16#include <linux/crc32.h> 16#include <linux/crc32.h>
17#include <linux/lm_interface.h>
18 17
19#include "gfs2.h" 18#include "gfs2.h"
20#include "incore.h" 19#include "incore.h"
diff --git a/fs/gfs2/ops_file.c b/fs/gfs2/ops_file.c
index 93fe41b67f97..3b9e8de3500b 100644
--- a/fs/gfs2/ops_file.c
+++ b/fs/gfs2/ops_file.c
@@ -20,9 +20,10 @@
20#include <linux/gfs2_ondisk.h> 20#include <linux/gfs2_ondisk.h>
21#include <linux/ext2_fs.h> 21#include <linux/ext2_fs.h>
22#include <linux/crc32.h> 22#include <linux/crc32.h>
23#include <linux/lm_interface.h>
24#include <linux/writeback.h> 23#include <linux/writeback.h>
25#include <asm/uaccess.h> 24#include <asm/uaccess.h>
25#include <linux/dlm.h>
26#include <linux/dlm_plock.h>
26 27
27#include "gfs2.h" 28#include "gfs2.h"
28#include "incore.h" 29#include "incore.h"
@@ -354,7 +355,9 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct page *page)
354 if (ret) 355 if (ret)
355 goto out; 356 goto out;
356 357
358 set_bit(GLF_DIRTY, &ip->i_gl->gl_flags);
357 set_bit(GIF_SW_PAGED, &ip->i_flags); 359 set_bit(GIF_SW_PAGED, &ip->i_flags);
360
358 ret = gfs2_write_alloc_required(ip, pos, PAGE_CACHE_SIZE, &alloc_required); 361 ret = gfs2_write_alloc_required(ip, pos, PAGE_CACHE_SIZE, &alloc_required);
359 if (ret || !alloc_required) 362 if (ret || !alloc_required)
360 goto out_unlock; 363 goto out_unlock;
@@ -560,57 +563,24 @@ static int gfs2_fsync(struct file *file, struct dentry *dentry, int datasync)
560 return ret; 563 return ret;
561} 564}
562 565
566#ifdef CONFIG_GFS2_FS_LOCKING_DLM
567
563/** 568/**
564 * gfs2_setlease - acquire/release a file lease 569 * gfs2_setlease - acquire/release a file lease
565 * @file: the file pointer 570 * @file: the file pointer
566 * @arg: lease type 571 * @arg: lease type
567 * @fl: file lock 572 * @fl: file lock
568 * 573 *
574 * We don't currently have a way to enforce a lease across the whole
575 * cluster; until we do, disable leases (by just returning -EINVAL),
576 * unless the administrator has requested purely local locking.
577 *
569 * Returns: errno 578 * Returns: errno
570 */ 579 */
571 580
572static int gfs2_setlease(struct file *file, long arg, struct file_lock **fl) 581static int gfs2_setlease(struct file *file, long arg, struct file_lock **fl)
573{ 582{
574 struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host); 583 return -EINVAL;
575
576 /*
577 * We don't currently have a way to enforce a lease across the whole
578 * cluster; until we do, disable leases (by just returning -EINVAL),
579 * unless the administrator has requested purely local locking.
580 */
581 if (!sdp->sd_args.ar_localflocks)
582 return -EINVAL;
583 return generic_setlease(file, arg, fl);
584}
585
586static int gfs2_lm_plock_get(struct gfs2_sbd *sdp, struct lm_lockname *name,
587 struct file *file, struct file_lock *fl)
588{
589 int error = -EIO;
590 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
591 error = sdp->sd_lockstruct.ls_ops->lm_plock_get(
592 sdp->sd_lockstruct.ls_lockspace, name, file, fl);
593 return error;
594}
595
596static int gfs2_lm_plock(struct gfs2_sbd *sdp, struct lm_lockname *name,
597 struct file *file, int cmd, struct file_lock *fl)
598{
599 int error = -EIO;
600 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
601 error = sdp->sd_lockstruct.ls_ops->lm_plock(
602 sdp->sd_lockstruct.ls_lockspace, name, file, cmd, fl);
603 return error;
604}
605
606static int gfs2_lm_punlock(struct gfs2_sbd *sdp, struct lm_lockname *name,
607 struct file *file, struct file_lock *fl)
608{
609 int error = -EIO;
610 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
611 error = sdp->sd_lockstruct.ls_ops->lm_punlock(
612 sdp->sd_lockstruct.ls_lockspace, name, file, fl);
613 return error;
614} 584}
615 585
616/** 586/**
@@ -626,9 +596,7 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
626{ 596{
627 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host); 597 struct gfs2_inode *ip = GFS2_I(file->f_mapping->host);
628 struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host); 598 struct gfs2_sbd *sdp = GFS2_SB(file->f_mapping->host);
629 struct lm_lockname name = 599 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
630 { .ln_number = ip->i_no_addr,
631 .ln_type = LM_TYPE_PLOCK };
632 600
633 if (!(fl->fl_flags & FL_POSIX)) 601 if (!(fl->fl_flags & FL_POSIX))
634 return -ENOLCK; 602 return -ENOLCK;
@@ -640,12 +608,14 @@ static int gfs2_lock(struct file *file, int cmd, struct file_lock *fl)
640 cmd = F_SETLK; 608 cmd = F_SETLK;
641 fl->fl_type = F_UNLCK; 609 fl->fl_type = F_UNLCK;
642 } 610 }
611 if (unlikely(test_bit(SDF_SHUTDOWN, &sdp->sd_flags)))
612 return -EIO;
643 if (IS_GETLK(cmd)) 613 if (IS_GETLK(cmd))
644 return gfs2_lm_plock_get(sdp, &name, file, fl); 614 return dlm_posix_get(ls->ls_dlm, ip->i_no_addr, file, fl);
645 else if (fl->fl_type == F_UNLCK) 615 else if (fl->fl_type == F_UNLCK)
646 return gfs2_lm_punlock(sdp, &name, file, fl); 616 return dlm_posix_unlock(ls->ls_dlm, ip->i_no_addr, file, fl);
647 else 617 else
648 return gfs2_lm_plock(sdp, &name, file, cmd, fl); 618 return dlm_posix_lock(ls->ls_dlm, ip->i_no_addr, file, cmd, fl);
649} 619}
650 620
651static int do_flock(struct file *file, int cmd, struct file_lock *fl) 621static int do_flock(struct file *file, int cmd, struct file_lock *fl)
@@ -732,7 +702,7 @@ static int gfs2_flock(struct file *file, int cmd, struct file_lock *fl)
732 } 702 }
733} 703}
734 704
735const struct file_operations gfs2_file_fops = { 705const struct file_operations *gfs2_file_fops = &(const struct file_operations){
736 .llseek = gfs2_llseek, 706 .llseek = gfs2_llseek,
737 .read = do_sync_read, 707 .read = do_sync_read,
738 .aio_read = generic_file_aio_read, 708 .aio_read = generic_file_aio_read,
@@ -750,7 +720,7 @@ const struct file_operations gfs2_file_fops = {
750 .setlease = gfs2_setlease, 720 .setlease = gfs2_setlease,
751}; 721};
752 722
753const struct file_operations gfs2_dir_fops = { 723const struct file_operations *gfs2_dir_fops = &(const struct file_operations){
754 .readdir = gfs2_readdir, 724 .readdir = gfs2_readdir,
755 .unlocked_ioctl = gfs2_ioctl, 725 .unlocked_ioctl = gfs2_ioctl,
756 .open = gfs2_open, 726 .open = gfs2_open,
@@ -760,7 +730,9 @@ const struct file_operations gfs2_dir_fops = {
760 .flock = gfs2_flock, 730 .flock = gfs2_flock,
761}; 731};
762 732
763const struct file_operations gfs2_file_fops_nolock = { 733#endif /* CONFIG_GFS2_FS_LOCKING_DLM */
734
735const struct file_operations *gfs2_file_fops_nolock = &(const struct file_operations){
764 .llseek = gfs2_llseek, 736 .llseek = gfs2_llseek,
765 .read = do_sync_read, 737 .read = do_sync_read,
766 .aio_read = generic_file_aio_read, 738 .aio_read = generic_file_aio_read,
@@ -773,10 +745,10 @@ const struct file_operations gfs2_file_fops_nolock = {
773 .fsync = gfs2_fsync, 745 .fsync = gfs2_fsync,
774 .splice_read = generic_file_splice_read, 746 .splice_read = generic_file_splice_read,
775 .splice_write = generic_file_splice_write, 747 .splice_write = generic_file_splice_write,
776 .setlease = gfs2_setlease, 748 .setlease = generic_setlease,
777}; 749};
778 750
779const struct file_operations gfs2_dir_fops_nolock = { 751const struct file_operations *gfs2_dir_fops_nolock = &(const struct file_operations){
780 .readdir = gfs2_readdir, 752 .readdir = gfs2_readdir,
781 .unlocked_ioctl = gfs2_ioctl, 753 .unlocked_ioctl = gfs2_ioctl,
782 .open = gfs2_open, 754 .open = gfs2_open,
diff --git a/fs/gfs2/ops_fstype.c b/fs/gfs2/ops_fstype.c
index f91eebdde581..51883b3ad89c 100644
--- a/fs/gfs2/ops_fstype.c
+++ b/fs/gfs2/ops_fstype.c
@@ -17,7 +17,6 @@
17#include <linux/namei.h> 17#include <linux/namei.h>
18#include <linux/mount.h> 18#include <linux/mount.h>
19#include <linux/gfs2_ondisk.h> 19#include <linux/gfs2_ondisk.h>
20#include <linux/lm_interface.h>
21 20
22#include "gfs2.h" 21#include "gfs2.h"
23#include "incore.h" 22#include "incore.h"
@@ -25,7 +24,6 @@
25#include "glock.h" 24#include "glock.h"
26#include "glops.h" 25#include "glops.h"
27#include "inode.h" 26#include "inode.h"
28#include "mount.h"
29#include "recovery.h" 27#include "recovery.h"
30#include "rgrp.h" 28#include "rgrp.h"
31#include "super.h" 29#include "super.h"
@@ -64,7 +62,6 @@ static void gfs2_tune_init(struct gfs2_tune *gt)
64 gt->gt_quota_warn_period = 10; 62 gt->gt_quota_warn_period = 10;
65 gt->gt_quota_scale_num = 1; 63 gt->gt_quota_scale_num = 1;
66 gt->gt_quota_scale_den = 1; 64 gt->gt_quota_scale_den = 1;
67 gt->gt_quota_cache_secs = 300;
68 gt->gt_quota_quantum = 60; 65 gt->gt_quota_quantum = 60;
69 gt->gt_new_files_jdata = 0; 66 gt->gt_new_files_jdata = 0;
70 gt->gt_max_readahead = 1 << 18; 67 gt->gt_max_readahead = 1 << 18;
@@ -100,7 +97,6 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
100 mutex_init(&sdp->sd_jindex_mutex); 97 mutex_init(&sdp->sd_jindex_mutex);
101 98
102 INIT_LIST_HEAD(&sdp->sd_quota_list); 99 INIT_LIST_HEAD(&sdp->sd_quota_list);
103 spin_lock_init(&sdp->sd_quota_spin);
104 mutex_init(&sdp->sd_quota_mutex); 100 mutex_init(&sdp->sd_quota_mutex);
105 init_waitqueue_head(&sdp->sd_quota_wait); 101 init_waitqueue_head(&sdp->sd_quota_wait);
106 INIT_LIST_HEAD(&sdp->sd_trunc_list); 102 INIT_LIST_HEAD(&sdp->sd_trunc_list);
@@ -238,6 +234,7 @@ static void gfs2_sb_in(struct gfs2_sb_host *sb, const void *buf)
238 234
239 memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN); 235 memcpy(sb->sb_lockproto, str->sb_lockproto, GFS2_LOCKNAME_LEN);
240 memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN); 236 memcpy(sb->sb_locktable, str->sb_locktable, GFS2_LOCKNAME_LEN);
237 memcpy(sb->sb_uuid, str->sb_uuid, 16);
241} 238}
242 239
243/** 240/**
@@ -299,15 +296,15 @@ static int gfs2_read_super(struct gfs2_sbd *sdp, sector_t sector)
299 __free_page(page); 296 __free_page(page);
300 return 0; 297 return 0;
301} 298}
299
302/** 300/**
303 * gfs2_read_sb - Read super block 301 * gfs2_read_sb - Read super block
304 * @sdp: The GFS2 superblock 302 * @sdp: The GFS2 superblock
305 * @gl: the glock for the superblock (assumed to be held)
306 * @silent: Don't print message if mount fails 303 * @silent: Don't print message if mount fails
307 * 304 *
308 */ 305 */
309 306
310static int gfs2_read_sb(struct gfs2_sbd *sdp, struct gfs2_glock *gl, int silent) 307static int gfs2_read_sb(struct gfs2_sbd *sdp, int silent)
311{ 308{
312 u32 hash_blocks, ind_blocks, leaf_blocks; 309 u32 hash_blocks, ind_blocks, leaf_blocks;
313 u32 tmp_blocks; 310 u32 tmp_blocks;
@@ -527,7 +524,7 @@ static int init_sb(struct gfs2_sbd *sdp, int silent)
527 return ret; 524 return ret;
528 } 525 }
529 526
530 ret = gfs2_read_sb(sdp, sb_gh.gh_gl, silent); 527 ret = gfs2_read_sb(sdp, silent);
531 if (ret) { 528 if (ret) {
532 fs_err(sdp, "can't read superblock: %d\n", ret); 529 fs_err(sdp, "can't read superblock: %d\n", ret);
533 goto out; 530 goto out;
@@ -630,13 +627,13 @@ static int map_journal_extents(struct gfs2_sbd *sdp)
630 return rc; 627 return rc;
631} 628}
632 629
633static void gfs2_lm_others_may_mount(struct gfs2_sbd *sdp) 630static void gfs2_others_may_mount(struct gfs2_sbd *sdp)
634{ 631{
635 if (!sdp->sd_lockstruct.ls_ops->lm_others_may_mount) 632 char *message = "FIRSTMOUNT=Done";
636 return; 633 char *envp[] = { message, NULL };
637 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) 634 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
638 sdp->sd_lockstruct.ls_ops->lm_others_may_mount( 635 ls->ls_first_done = 1;
639 sdp->sd_lockstruct.ls_lockspace); 636 kobject_uevent_env(&sdp->sd_kobj, KOBJ_CHANGE, envp);
640} 637}
641 638
642/** 639/**
@@ -796,7 +793,7 @@ static int init_journal(struct gfs2_sbd *sdp, int undo)
796 } 793 }
797 } 794 }
798 795
799 gfs2_lm_others_may_mount(sdp); 796 gfs2_others_may_mount(sdp);
800 } else if (!sdp->sd_args.ar_spectator) { 797 } else if (!sdp->sd_args.ar_spectator) {
801 error = gfs2_recover_journal(sdp->sd_jdesc); 798 error = gfs2_recover_journal(sdp->sd_jdesc);
802 if (error) { 799 if (error) {
@@ -1005,7 +1002,6 @@ static int init_threads(struct gfs2_sbd *sdp, int undo)
1005 goto fail_quotad; 1002 goto fail_quotad;
1006 1003
1007 sdp->sd_log_flush_time = jiffies; 1004 sdp->sd_log_flush_time = jiffies;
1008 sdp->sd_jindex_refresh_time = jiffies;
1009 1005
1010 p = kthread_run(gfs2_logd, sdp, "gfs2_logd"); 1006 p = kthread_run(gfs2_logd, sdp, "gfs2_logd");
1011 error = IS_ERR(p); 1007 error = IS_ERR(p);
@@ -1033,6 +1029,17 @@ fail:
1033 return error; 1029 return error;
1034} 1030}
1035 1031
1032static const match_table_t nolock_tokens = {
1033 { Opt_jid, "jid=%d\n", },
1034 { Opt_err, NULL },
1035};
1036
1037static const struct lm_lockops nolock_ops = {
1038 .lm_proto_name = "lock_nolock",
1039 .lm_put_lock = kmem_cache_free,
1040 .lm_tokens = &nolock_tokens,
1041};
1042
1036/** 1043/**
1037 * gfs2_lm_mount - mount a locking protocol 1044 * gfs2_lm_mount - mount a locking protocol
1038 * @sdp: the filesystem 1045 * @sdp: the filesystem
@@ -1044,31 +1051,73 @@ fail:
1044 1051
1045static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent) 1052static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
1046{ 1053{
1047 char *proto = sdp->sd_proto_name; 1054 const struct lm_lockops *lm;
1048 char *table = sdp->sd_table_name; 1055 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
1049 int flags = LM_MFLAG_CONV_NODROP; 1056 struct gfs2_args *args = &sdp->sd_args;
1050 int error; 1057 const char *proto = sdp->sd_proto_name;
1058 const char *table = sdp->sd_table_name;
1059 const char *fsname;
1060 char *o, *options;
1061 int ret;
1051 1062
1052 if (sdp->sd_args.ar_spectator) 1063 if (!strcmp("lock_nolock", proto)) {
1053 flags |= LM_MFLAG_SPECTATOR; 1064 lm = &nolock_ops;
1065 sdp->sd_args.ar_localflocks = 1;
1066 sdp->sd_args.ar_localcaching = 1;
1067#ifdef CONFIG_GFS2_FS_LOCKING_DLM
1068 } else if (!strcmp("lock_dlm", proto)) {
1069 lm = &gfs2_dlm_ops;
1070#endif
1071 } else {
1072 printk(KERN_INFO "GFS2: can't find protocol %s\n", proto);
1073 return -ENOENT;
1074 }
1054 1075
1055 fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table); 1076 fs_info(sdp, "Trying to join cluster \"%s\", \"%s\"\n", proto, table);
1056 1077
1057 error = gfs2_mount_lockproto(proto, table, sdp->sd_args.ar_hostdata, 1078 ls->ls_ops = lm;
1058 gfs2_glock_cb, sdp, 1079 ls->ls_first = 1;
1059 GFS2_MIN_LVB_SIZE, flags, 1080 ls->ls_id = 0;
1060 &sdp->sd_lockstruct, &sdp->sd_kobj);
1061 if (error) {
1062 fs_info(sdp, "can't mount proto=%s, table=%s, hostdata=%s\n",
1063 proto, table, sdp->sd_args.ar_hostdata);
1064 goto out;
1065 }
1066 1081
1067 if (gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_ops) || 1082 for (options = args->ar_hostdata; (o = strsep(&options, ":")); ) {
1068 gfs2_assert_warn(sdp, sdp->sd_lockstruct.ls_lvb_size >= 1083 substring_t tmp[MAX_OPT_ARGS];
1069 GFS2_MIN_LVB_SIZE)) { 1084 int token, option;
1070 gfs2_unmount_lockproto(&sdp->sd_lockstruct); 1085
1071 goto out; 1086 if (!o || !*o)
1087 continue;
1088
1089 token = match_token(o, *lm->lm_tokens, tmp);
1090 switch (token) {
1091 case Opt_jid:
1092 ret = match_int(&tmp[0], &option);
1093 if (ret || option < 0)
1094 goto hostdata_error;
1095 ls->ls_jid = option;
1096 break;
1097 case Opt_id:
1098 ret = match_int(&tmp[0], &option);
1099 if (ret)
1100 goto hostdata_error;
1101 ls->ls_id = option;
1102 break;
1103 case Opt_first:
1104 ret = match_int(&tmp[0], &option);
1105 if (ret || (option != 0 && option != 1))
1106 goto hostdata_error;
1107 ls->ls_first = option;
1108 break;
1109 case Opt_nodir:
1110 ret = match_int(&tmp[0], &option);
1111 if (ret || (option != 0 && option != 1))
1112 goto hostdata_error;
1113 ls->ls_nodir = option;
1114 break;
1115 case Opt_err:
1116 default:
1117hostdata_error:
1118 fs_info(sdp, "unknown hostdata (%s)\n", o);
1119 return -EINVAL;
1120 }
1072 } 1121 }
1073 1122
1074 if (sdp->sd_args.ar_spectator) 1123 if (sdp->sd_args.ar_spectator)
@@ -1077,22 +1126,25 @@ static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
1077 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table, 1126 snprintf(sdp->sd_fsname, GFS2_FSNAME_LEN, "%s.%u", table,
1078 sdp->sd_lockstruct.ls_jid); 1127 sdp->sd_lockstruct.ls_jid);
1079 1128
1080 fs_info(sdp, "Joined cluster. Now mounting FS...\n"); 1129 fsname = strchr(table, ':');
1081 1130 if (fsname)
1082 if ((sdp->sd_lockstruct.ls_flags & LM_LSFLAG_LOCAL) && 1131 fsname++;
1083 !sdp->sd_args.ar_ignore_local_fs) { 1132 if (lm->lm_mount == NULL) {
1084 sdp->sd_args.ar_localflocks = 1; 1133 fs_info(sdp, "Now mounting FS...\n");
1085 sdp->sd_args.ar_localcaching = 1; 1134 return 0;
1086 } 1135 }
1087 1136 ret = lm->lm_mount(sdp, fsname);
1088out: 1137 if (ret == 0)
1089 return error; 1138 fs_info(sdp, "Joined cluster. Now mounting FS...\n");
1139 return ret;
1090} 1140}
1091 1141
1092void gfs2_lm_unmount(struct gfs2_sbd *sdp) 1142void gfs2_lm_unmount(struct gfs2_sbd *sdp)
1093{ 1143{
1094 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) 1144 const struct lm_lockops *lm = sdp->sd_lockstruct.ls_ops;
1095 gfs2_unmount_lockproto(&sdp->sd_lockstruct); 1145 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags)) &&
1146 lm->lm_unmount)
1147 lm->lm_unmount(sdp);
1096} 1148}
1097 1149
1098/** 1150/**
@@ -1116,12 +1168,20 @@ static int fill_super(struct super_block *sb, void *data, int silent)
1116 return -ENOMEM; 1168 return -ENOMEM;
1117 } 1169 }
1118 1170
1119 error = gfs2_mount_args(sdp, (char *)data, 0); 1171 sdp->sd_args.ar_quota = GFS2_QUOTA_DEFAULT;
1172 sdp->sd_args.ar_data = GFS2_DATA_DEFAULT;
1173
1174 error = gfs2_mount_args(sdp, &sdp->sd_args, data);
1120 if (error) { 1175 if (error) {
1121 printk(KERN_WARNING "GFS2: can't parse mount arguments\n"); 1176 printk(KERN_WARNING "GFS2: can't parse mount arguments\n");
1122 goto fail; 1177 goto fail;
1123 } 1178 }
1124 1179
1180 if (sdp->sd_args.ar_spectator)
1181 sb->s_flags |= MS_RDONLY;
1182 if (sdp->sd_args.ar_posix_acl)
1183 sb->s_flags |= MS_POSIXACL;
1184
1125 sb->s_magic = GFS2_MAGIC; 1185 sb->s_magic = GFS2_MAGIC;
1126 sb->s_op = &gfs2_super_ops; 1186 sb->s_op = &gfs2_super_ops;
1127 sb->s_export_op = &gfs2_export_ops; 1187 sb->s_export_op = &gfs2_export_ops;
@@ -1199,6 +1259,8 @@ fail_sb:
1199 dput(sdp->sd_root_dir); 1259 dput(sdp->sd_root_dir);
1200 if (sdp->sd_master_dir) 1260 if (sdp->sd_master_dir)
1201 dput(sdp->sd_master_dir); 1261 dput(sdp->sd_master_dir);
1262 if (sb->s_root)
1263 dput(sb->s_root);
1202 sb->s_root = NULL; 1264 sb->s_root = NULL;
1203fail_locking: 1265fail_locking:
1204 init_locking(sdp, &mount_gh, UNDO); 1266 init_locking(sdp, &mount_gh, UNDO);
diff --git a/fs/gfs2/ops_inode.c b/fs/gfs2/ops_inode.c
index 49877546beb9..abd5429ae285 100644
--- a/fs/gfs2/ops_inode.c
+++ b/fs/gfs2/ops_inode.c
@@ -18,7 +18,6 @@
18#include <linux/posix_acl.h> 18#include <linux/posix_acl.h>
19#include <linux/gfs2_ondisk.h> 19#include <linux/gfs2_ondisk.h>
20#include <linux/crc32.h> 20#include <linux/crc32.h>
21#include <linux/lm_interface.h>
22#include <linux/fiemap.h> 21#include <linux/fiemap.h>
23#include <asm/uaccess.h> 22#include <asm/uaccess.h>
24 23
diff --git a/fs/gfs2/ops_super.c b/fs/gfs2/ops_super.c
index 320323d03479..458019569dcb 100644
--- a/fs/gfs2/ops_super.c
+++ b/fs/gfs2/ops_super.c
@@ -19,7 +19,6 @@
19#include <linux/delay.h> 19#include <linux/delay.h>
20#include <linux/gfs2_ondisk.h> 20#include <linux/gfs2_ondisk.h>
21#include <linux/crc32.h> 21#include <linux/crc32.h>
22#include <linux/lm_interface.h>
23#include <linux/time.h> 22#include <linux/time.h>
24 23
25#include "gfs2.h" 24#include "gfs2.h"
@@ -27,7 +26,6 @@
27#include "glock.h" 26#include "glock.h"
28#include "inode.h" 27#include "inode.h"
29#include "log.h" 28#include "log.h"
30#include "mount.h"
31#include "quota.h" 29#include "quota.h"
32#include "recovery.h" 30#include "recovery.h"
33#include "rgrp.h" 31#include "rgrp.h"
@@ -40,6 +38,8 @@
40#include "bmap.h" 38#include "bmap.h"
41#include "meta_io.h" 39#include "meta_io.h"
42 40
41#define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
42
43/** 43/**
44 * gfs2_write_inode - Make sure the inode is stable on the disk 44 * gfs2_write_inode - Make sure the inode is stable on the disk
45 * @inode: The inode 45 * @inode: The inode
@@ -435,25 +435,45 @@ static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
435static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data) 435static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
436{ 436{
437 struct gfs2_sbd *sdp = sb->s_fs_info; 437 struct gfs2_sbd *sdp = sb->s_fs_info;
438 struct gfs2_args args = sdp->sd_args; /* Default to current settings */
438 int error; 439 int error;
439 440
440 error = gfs2_mount_args(sdp, data, 1); 441 error = gfs2_mount_args(sdp, &args, data);
441 if (error) 442 if (error)
442 return error; 443 return error;
443 444
445 /* Not allowed to change locking details */
446 if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) ||
447 strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) ||
448 strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata))
449 return -EINVAL;
450
451 /* Some flags must not be changed */
452 if (args_neq(&args, &sdp->sd_args, spectator) ||
453 args_neq(&args, &sdp->sd_args, ignore_local_fs) ||
454 args_neq(&args, &sdp->sd_args, localflocks) ||
455 args_neq(&args, &sdp->sd_args, localcaching) ||
456 args_neq(&args, &sdp->sd_args, meta))
457 return -EINVAL;
458
444 if (sdp->sd_args.ar_spectator) 459 if (sdp->sd_args.ar_spectator)
445 *flags |= MS_RDONLY; 460 *flags |= MS_RDONLY;
446 else { 461
447 if (*flags & MS_RDONLY) { 462 if ((sb->s_flags ^ *flags) & MS_RDONLY) {
448 if (!(sb->s_flags & MS_RDONLY)) 463 if (*flags & MS_RDONLY)
449 error = gfs2_make_fs_ro(sdp); 464 error = gfs2_make_fs_ro(sdp);
450 } else if (!(*flags & MS_RDONLY) && 465 else
451 (sb->s_flags & MS_RDONLY)) {
452 error = gfs2_make_fs_rw(sdp); 466 error = gfs2_make_fs_rw(sdp);
453 } 467 if (error)
468 return error;
454 } 469 }
455 470
456 return error; 471 sdp->sd_args = args;
472 if (sdp->sd_args.ar_posix_acl)
473 sb->s_flags |= MS_POSIXACL;
474 else
475 sb->s_flags &= ~MS_POSIXACL;
476 return 0;
457} 477}
458 478
459/** 479/**
@@ -588,6 +608,8 @@ static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
588 } 608 }
589 seq_printf(s, ",data=%s", state); 609 seq_printf(s, ",data=%s", state);
590 } 610 }
611 if (args->ar_discard)
612 seq_printf(s, ",discard");
591 613
592 return 0; 614 return 0;
593} 615}
diff --git a/fs/gfs2/quota.c b/fs/gfs2/quota.c
index b08d09696b3e..8d53f66b5bcc 100644
--- a/fs/gfs2/quota.c
+++ b/fs/gfs2/quota.c
@@ -45,7 +45,6 @@
45#include <linux/fs.h> 45#include <linux/fs.h>
46#include <linux/bio.h> 46#include <linux/bio.h>
47#include <linux/gfs2_ondisk.h> 47#include <linux/gfs2_ondisk.h>
48#include <linux/lm_interface.h>
49#include <linux/kthread.h> 48#include <linux/kthread.h>
50#include <linux/freezer.h> 49#include <linux/freezer.h>
51 50
@@ -80,6 +79,51 @@ struct gfs2_quota_change_host {
80 u32 qc_id; 79 u32 qc_id;
81}; 80};
82 81
82static LIST_HEAD(qd_lru_list);
83static atomic_t qd_lru_count = ATOMIC_INIT(0);
84static spinlock_t qd_lru_lock = SPIN_LOCK_UNLOCKED;
85
86int gfs2_shrink_qd_memory(int nr, gfp_t gfp_mask)
87{
88 struct gfs2_quota_data *qd;
89 struct gfs2_sbd *sdp;
90
91 if (nr == 0)
92 goto out;
93
94 if (!(gfp_mask & __GFP_FS))
95 return -1;
96
97 spin_lock(&qd_lru_lock);
98 while (nr && !list_empty(&qd_lru_list)) {
99 qd = list_entry(qd_lru_list.next,
100 struct gfs2_quota_data, qd_reclaim);
101 sdp = qd->qd_gl->gl_sbd;
102
103 /* Free from the filesystem-specific list */
104 list_del(&qd->qd_list);
105
106 gfs2_assert_warn(sdp, !qd->qd_change);
107 gfs2_assert_warn(sdp, !qd->qd_slot_count);
108 gfs2_assert_warn(sdp, !qd->qd_bh_count);
109
110 gfs2_glock_put(qd->qd_gl);
111 atomic_dec(&sdp->sd_quota_count);
112
113 /* Delete it from the common reclaim list */
114 list_del_init(&qd->qd_reclaim);
115 atomic_dec(&qd_lru_count);
116 spin_unlock(&qd_lru_lock);
117 kmem_cache_free(gfs2_quotad_cachep, qd);
118 spin_lock(&qd_lru_lock);
119 nr--;
120 }
121 spin_unlock(&qd_lru_lock);
122
123out:
124 return (atomic_read(&qd_lru_count) * sysctl_vfs_cache_pressure) / 100;
125}
126
83static u64 qd2offset(struct gfs2_quota_data *qd) 127static u64 qd2offset(struct gfs2_quota_data *qd)
84{ 128{
85 u64 offset; 129 u64 offset;
@@ -100,22 +144,18 @@ static int qd_alloc(struct gfs2_sbd *sdp, int user, u32 id,
100 if (!qd) 144 if (!qd)
101 return -ENOMEM; 145 return -ENOMEM;
102 146
103 qd->qd_count = 1; 147 atomic_set(&qd->qd_count, 1);
104 qd->qd_id = id; 148 qd->qd_id = id;
105 if (user) 149 if (user)
106 set_bit(QDF_USER, &qd->qd_flags); 150 set_bit(QDF_USER, &qd->qd_flags);
107 qd->qd_slot = -1; 151 qd->qd_slot = -1;
152 INIT_LIST_HEAD(&qd->qd_reclaim);
108 153
109 error = gfs2_glock_get(sdp, 2 * (u64)id + !user, 154 error = gfs2_glock_get(sdp, 2 * (u64)id + !user,
110 &gfs2_quota_glops, CREATE, &qd->qd_gl); 155 &gfs2_quota_glops, CREATE, &qd->qd_gl);
111 if (error) 156 if (error)
112 goto fail; 157 goto fail;
113 158
114 error = gfs2_lvb_hold(qd->qd_gl);
115 gfs2_glock_put(qd->qd_gl);
116 if (error)
117 goto fail;
118
119 *qdp = qd; 159 *qdp = qd;
120 160
121 return 0; 161 return 0;
@@ -135,11 +175,17 @@ static int qd_get(struct gfs2_sbd *sdp, int user, u32 id, int create,
135 175
136 for (;;) { 176 for (;;) {
137 found = 0; 177 found = 0;
138 spin_lock(&sdp->sd_quota_spin); 178 spin_lock(&qd_lru_lock);
139 list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) { 179 list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) {
140 if (qd->qd_id == id && 180 if (qd->qd_id == id &&
141 !test_bit(QDF_USER, &qd->qd_flags) == !user) { 181 !test_bit(QDF_USER, &qd->qd_flags) == !user) {
142 qd->qd_count++; 182 if (!atomic_read(&qd->qd_count) &&
183 !list_empty(&qd->qd_reclaim)) {
184 /* Remove it from reclaim list */
185 list_del_init(&qd->qd_reclaim);
186 atomic_dec(&qd_lru_count);
187 }
188 atomic_inc(&qd->qd_count);
143 found = 1; 189 found = 1;
144 break; 190 break;
145 } 191 }
@@ -155,11 +201,11 @@ static int qd_get(struct gfs2_sbd *sdp, int user, u32 id, int create,
155 new_qd = NULL; 201 new_qd = NULL;
156 } 202 }
157 203
158 spin_unlock(&sdp->sd_quota_spin); 204 spin_unlock(&qd_lru_lock);
159 205
160 if (qd || !create) { 206 if (qd || !create) {
161 if (new_qd) { 207 if (new_qd) {
162 gfs2_lvb_unhold(new_qd->qd_gl); 208 gfs2_glock_put(new_qd->qd_gl);
163 kmem_cache_free(gfs2_quotad_cachep, new_qd); 209 kmem_cache_free(gfs2_quotad_cachep, new_qd);
164 } 210 }
165 *qdp = qd; 211 *qdp = qd;
@@ -175,21 +221,18 @@ static int qd_get(struct gfs2_sbd *sdp, int user, u32 id, int create,
175static void qd_hold(struct gfs2_quota_data *qd) 221static void qd_hold(struct gfs2_quota_data *qd)
176{ 222{
177 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 223 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
178 224 gfs2_assert(sdp, atomic_read(&qd->qd_count));
179 spin_lock(&sdp->sd_quota_spin); 225 atomic_inc(&qd->qd_count);
180 gfs2_assert(sdp, qd->qd_count);
181 qd->qd_count++;
182 spin_unlock(&sdp->sd_quota_spin);
183} 226}
184 227
185static void qd_put(struct gfs2_quota_data *qd) 228static void qd_put(struct gfs2_quota_data *qd)
186{ 229{
187 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 230 if (atomic_dec_and_lock(&qd->qd_count, &qd_lru_lock)) {
188 spin_lock(&sdp->sd_quota_spin); 231 /* Add to the reclaim list */
189 gfs2_assert(sdp, qd->qd_count); 232 list_add_tail(&qd->qd_reclaim, &qd_lru_list);
190 if (!--qd->qd_count) 233 atomic_inc(&qd_lru_count);
191 qd->qd_last_touched = jiffies; 234 spin_unlock(&qd_lru_lock);
192 spin_unlock(&sdp->sd_quota_spin); 235 }
193} 236}
194 237
195static int slot_get(struct gfs2_quota_data *qd) 238static int slot_get(struct gfs2_quota_data *qd)
@@ -198,10 +241,10 @@ static int slot_get(struct gfs2_quota_data *qd)
198 unsigned int c, o = 0, b; 241 unsigned int c, o = 0, b;
199 unsigned char byte = 0; 242 unsigned char byte = 0;
200 243
201 spin_lock(&sdp->sd_quota_spin); 244 spin_lock(&qd_lru_lock);
202 245
203 if (qd->qd_slot_count++) { 246 if (qd->qd_slot_count++) {
204 spin_unlock(&sdp->sd_quota_spin); 247 spin_unlock(&qd_lru_lock);
205 return 0; 248 return 0;
206 } 249 }
207 250
@@ -225,13 +268,13 @@ found:
225 268
226 sdp->sd_quota_bitmap[c][o] |= 1 << b; 269 sdp->sd_quota_bitmap[c][o] |= 1 << b;
227 270
228 spin_unlock(&sdp->sd_quota_spin); 271 spin_unlock(&qd_lru_lock);
229 272
230 return 0; 273 return 0;
231 274
232fail: 275fail:
233 qd->qd_slot_count--; 276 qd->qd_slot_count--;
234 spin_unlock(&sdp->sd_quota_spin); 277 spin_unlock(&qd_lru_lock);
235 return -ENOSPC; 278 return -ENOSPC;
236} 279}
237 280
@@ -239,23 +282,23 @@ static void slot_hold(struct gfs2_quota_data *qd)
239{ 282{
240 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 283 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
241 284
242 spin_lock(&sdp->sd_quota_spin); 285 spin_lock(&qd_lru_lock);
243 gfs2_assert(sdp, qd->qd_slot_count); 286 gfs2_assert(sdp, qd->qd_slot_count);
244 qd->qd_slot_count++; 287 qd->qd_slot_count++;
245 spin_unlock(&sdp->sd_quota_spin); 288 spin_unlock(&qd_lru_lock);
246} 289}
247 290
248static void slot_put(struct gfs2_quota_data *qd) 291static void slot_put(struct gfs2_quota_data *qd)
249{ 292{
250 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd; 293 struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
251 294
252 spin_lock(&sdp->sd_quota_spin); 295 spin_lock(&qd_lru_lock);
253 gfs2_assert(sdp, qd->qd_slot_count); 296 gfs2_assert(sdp, qd->qd_slot_count);
254 if (!--qd->qd_slot_count) { 297 if (!--qd->qd_slot_count) {
255 gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, qd->qd_slot, 0); 298 gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, qd->qd_slot, 0);
256 qd->qd_slot = -1; 299 qd->qd_slot = -1;
257 } 300 }
258 spin_unlock(&sdp->sd_quota_spin); 301 spin_unlock(&qd_lru_lock);
259} 302}
260 303
261static int bh_get(struct gfs2_quota_data *qd) 304static int bh_get(struct gfs2_quota_data *qd)
@@ -330,7 +373,7 @@ static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
330 if (sdp->sd_vfs->s_flags & MS_RDONLY) 373 if (sdp->sd_vfs->s_flags & MS_RDONLY)
331 return 0; 374 return 0;
332 375
333 spin_lock(&sdp->sd_quota_spin); 376 spin_lock(&qd_lru_lock);
334 377
335 list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) { 378 list_for_each_entry(qd, &sdp->sd_quota_list, qd_list) {
336 if (test_bit(QDF_LOCKED, &qd->qd_flags) || 379 if (test_bit(QDF_LOCKED, &qd->qd_flags) ||
@@ -341,8 +384,8 @@ static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
341 list_move_tail(&qd->qd_list, &sdp->sd_quota_list); 384 list_move_tail(&qd->qd_list, &sdp->sd_quota_list);
342 385
343 set_bit(QDF_LOCKED, &qd->qd_flags); 386 set_bit(QDF_LOCKED, &qd->qd_flags);
344 gfs2_assert_warn(sdp, qd->qd_count); 387 gfs2_assert_warn(sdp, atomic_read(&qd->qd_count));
345 qd->qd_count++; 388 atomic_inc(&qd->qd_count);
346 qd->qd_change_sync = qd->qd_change; 389 qd->qd_change_sync = qd->qd_change;
347 gfs2_assert_warn(sdp, qd->qd_slot_count); 390 gfs2_assert_warn(sdp, qd->qd_slot_count);
348 qd->qd_slot_count++; 391 qd->qd_slot_count++;
@@ -354,7 +397,7 @@ static int qd_fish(struct gfs2_sbd *sdp, struct gfs2_quota_data **qdp)
354 if (!found) 397 if (!found)
355 qd = NULL; 398 qd = NULL;
356 399
357 spin_unlock(&sdp->sd_quota_spin); 400 spin_unlock(&qd_lru_lock);
358 401
359 if (qd) { 402 if (qd) {
360 gfs2_assert_warn(sdp, qd->qd_change_sync); 403 gfs2_assert_warn(sdp, qd->qd_change_sync);
@@ -379,24 +422,24 @@ static int qd_trylock(struct gfs2_quota_data *qd)
379 if (sdp->sd_vfs->s_flags & MS_RDONLY) 422 if (sdp->sd_vfs->s_flags & MS_RDONLY)
380 return 0; 423 return 0;
381 424
382 spin_lock(&sdp->sd_quota_spin); 425 spin_lock(&qd_lru_lock);
383 426
384 if (test_bit(QDF_LOCKED, &qd->qd_flags) || 427 if (test_bit(QDF_LOCKED, &qd->qd_flags) ||
385 !test_bit(QDF_CHANGE, &qd->qd_flags)) { 428 !test_bit(QDF_CHANGE, &qd->qd_flags)) {
386 spin_unlock(&sdp->sd_quota_spin); 429 spin_unlock(&qd_lru_lock);
387 return 0; 430 return 0;
388 } 431 }
389 432
390 list_move_tail(&qd->qd_list, &sdp->sd_quota_list); 433 list_move_tail(&qd->qd_list, &sdp->sd_quota_list);
391 434
392 set_bit(QDF_LOCKED, &qd->qd_flags); 435 set_bit(QDF_LOCKED, &qd->qd_flags);
393 gfs2_assert_warn(sdp, qd->qd_count); 436 gfs2_assert_warn(sdp, atomic_read(&qd->qd_count));
394 qd->qd_count++; 437 atomic_inc(&qd->qd_count);
395 qd->qd_change_sync = qd->qd_change; 438 qd->qd_change_sync = qd->qd_change;
396 gfs2_assert_warn(sdp, qd->qd_slot_count); 439 gfs2_assert_warn(sdp, qd->qd_slot_count);
397 qd->qd_slot_count++; 440 qd->qd_slot_count++;
398 441
399 spin_unlock(&sdp->sd_quota_spin); 442 spin_unlock(&qd_lru_lock);
400 443
401 gfs2_assert_warn(sdp, qd->qd_change_sync); 444 gfs2_assert_warn(sdp, qd->qd_change_sync);
402 if (bh_get(qd)) { 445 if (bh_get(qd)) {
@@ -556,9 +599,9 @@ static void do_qc(struct gfs2_quota_data *qd, s64 change)
556 x = be64_to_cpu(qc->qc_change) + change; 599 x = be64_to_cpu(qc->qc_change) + change;
557 qc->qc_change = cpu_to_be64(x); 600 qc->qc_change = cpu_to_be64(x);
558 601
559 spin_lock(&sdp->sd_quota_spin); 602 spin_lock(&qd_lru_lock);
560 qd->qd_change = x; 603 qd->qd_change = x;
561 spin_unlock(&sdp->sd_quota_spin); 604 spin_unlock(&qd_lru_lock);
562 605
563 if (!x) { 606 if (!x) {
564 gfs2_assert_warn(sdp, test_bit(QDF_CHANGE, &qd->qd_flags)); 607 gfs2_assert_warn(sdp, test_bit(QDF_CHANGE, &qd->qd_flags));
@@ -802,8 +845,8 @@ restart:
802 loff_t pos; 845 loff_t pos;
803 gfs2_glock_dq_uninit(q_gh); 846 gfs2_glock_dq_uninit(q_gh);
804 error = gfs2_glock_nq_init(qd->qd_gl, 847 error = gfs2_glock_nq_init(qd->qd_gl,
805 LM_ST_EXCLUSIVE, GL_NOCACHE, 848 LM_ST_EXCLUSIVE, GL_NOCACHE,
806 q_gh); 849 q_gh);
807 if (error) 850 if (error)
808 return error; 851 return error;
809 852
@@ -820,7 +863,6 @@ restart:
820 863
821 gfs2_glock_dq_uninit(&i_gh); 864 gfs2_glock_dq_uninit(&i_gh);
822 865
823
824 gfs2_quota_in(&q, buf); 866 gfs2_quota_in(&q, buf);
825 qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb; 867 qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb;
826 qlvb->qb_magic = cpu_to_be32(GFS2_MAGIC); 868 qlvb->qb_magic = cpu_to_be32(GFS2_MAGIC);
@@ -890,9 +932,9 @@ static int need_sync(struct gfs2_quota_data *qd)
890 if (!qd->qd_qb.qb_limit) 932 if (!qd->qd_qb.qb_limit)
891 return 0; 933 return 0;
892 934
893 spin_lock(&sdp->sd_quota_spin); 935 spin_lock(&qd_lru_lock);
894 value = qd->qd_change; 936 value = qd->qd_change;
895 spin_unlock(&sdp->sd_quota_spin); 937 spin_unlock(&qd_lru_lock);
896 938
897 spin_lock(&gt->gt_spin); 939 spin_lock(&gt->gt_spin);
898 num = gt->gt_quota_scale_num; 940 num = gt->gt_quota_scale_num;
@@ -985,9 +1027,9 @@ int gfs2_quota_check(struct gfs2_inode *ip, u32 uid, u32 gid)
985 continue; 1027 continue;
986 1028
987 value = (s64)be64_to_cpu(qd->qd_qb.qb_value); 1029 value = (s64)be64_to_cpu(qd->qd_qb.qb_value);
988 spin_lock(&sdp->sd_quota_spin); 1030 spin_lock(&qd_lru_lock);
989 value += qd->qd_change; 1031 value += qd->qd_change;
990 spin_unlock(&sdp->sd_quota_spin); 1032 spin_unlock(&qd_lru_lock);
991 1033
992 if (be64_to_cpu(qd->qd_qb.qb_limit) && (s64)be64_to_cpu(qd->qd_qb.qb_limit) < value) { 1034 if (be64_to_cpu(qd->qd_qb.qb_limit) && (s64)be64_to_cpu(qd->qd_qb.qb_limit) < value) {
993 print_message(qd, "exceeded"); 1035 print_message(qd, "exceeded");
@@ -1171,13 +1213,12 @@ int gfs2_quota_init(struct gfs2_sbd *sdp)
1171 qd->qd_change = qc.qc_change; 1213 qd->qd_change = qc.qc_change;
1172 qd->qd_slot = slot; 1214 qd->qd_slot = slot;
1173 qd->qd_slot_count = 1; 1215 qd->qd_slot_count = 1;
1174 qd->qd_last_touched = jiffies;
1175 1216
1176 spin_lock(&sdp->sd_quota_spin); 1217 spin_lock(&qd_lru_lock);
1177 gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, slot, 1); 1218 gfs2_icbit_munge(sdp, sdp->sd_quota_bitmap, slot, 1);
1178 list_add(&qd->qd_list, &sdp->sd_quota_list); 1219 list_add(&qd->qd_list, &sdp->sd_quota_list);
1179 atomic_inc(&sdp->sd_quota_count); 1220 atomic_inc(&sdp->sd_quota_count);
1180 spin_unlock(&sdp->sd_quota_spin); 1221 spin_unlock(&qd_lru_lock);
1181 1222
1182 found++; 1223 found++;
1183 } 1224 }
@@ -1197,73 +1238,48 @@ fail:
1197 return error; 1238 return error;
1198} 1239}
1199 1240
1200static void gfs2_quota_scan(struct gfs2_sbd *sdp)
1201{
1202 struct gfs2_quota_data *qd, *safe;
1203 LIST_HEAD(dead);
1204
1205 spin_lock(&sdp->sd_quota_spin);
1206 list_for_each_entry_safe(qd, safe, &sdp->sd_quota_list, qd_list) {
1207 if (!qd->qd_count &&
1208 time_after_eq(jiffies, qd->qd_last_touched +
1209 gfs2_tune_get(sdp, gt_quota_cache_secs) * HZ)) {
1210 list_move(&qd->qd_list, &dead);
1211 gfs2_assert_warn(sdp,
1212 atomic_read(&sdp->sd_quota_count) > 0);
1213 atomic_dec(&sdp->sd_quota_count);
1214 }
1215 }
1216 spin_unlock(&sdp->sd_quota_spin);
1217
1218 while (!list_empty(&dead)) {
1219 qd = list_entry(dead.next, struct gfs2_quota_data, qd_list);
1220 list_del(&qd->qd_list);
1221
1222 gfs2_assert_warn(sdp, !qd->qd_change);
1223 gfs2_assert_warn(sdp, !qd->qd_slot_count);
1224 gfs2_assert_warn(sdp, !qd->qd_bh_count);
1225
1226 gfs2_lvb_unhold(qd->qd_gl);
1227 kmem_cache_free(gfs2_quotad_cachep, qd);
1228 }
1229}
1230
1231void gfs2_quota_cleanup(struct gfs2_sbd *sdp) 1241void gfs2_quota_cleanup(struct gfs2_sbd *sdp)
1232{ 1242{
1233 struct list_head *head = &sdp->sd_quota_list; 1243 struct list_head *head = &sdp->sd_quota_list;
1234 struct gfs2_quota_data *qd; 1244 struct gfs2_quota_data *qd;
1235 unsigned int x; 1245 unsigned int x;
1236 1246
1237 spin_lock(&sdp->sd_quota_spin); 1247 spin_lock(&qd_lru_lock);
1238 while (!list_empty(head)) { 1248 while (!list_empty(head)) {
1239 qd = list_entry(head->prev, struct gfs2_quota_data, qd_list); 1249 qd = list_entry(head->prev, struct gfs2_quota_data, qd_list);
1240 1250
1241 if (qd->qd_count > 1 || 1251 if (atomic_read(&qd->qd_count) > 1 ||
1242 (qd->qd_count && !test_bit(QDF_CHANGE, &qd->qd_flags))) { 1252 (atomic_read(&qd->qd_count) &&
1253 !test_bit(QDF_CHANGE, &qd->qd_flags))) {
1243 list_move(&qd->qd_list, head); 1254 list_move(&qd->qd_list, head);
1244 spin_unlock(&sdp->sd_quota_spin); 1255 spin_unlock(&qd_lru_lock);
1245 schedule(); 1256 schedule();
1246 spin_lock(&sdp->sd_quota_spin); 1257 spin_lock(&qd_lru_lock);
1247 continue; 1258 continue;
1248 } 1259 }
1249 1260
1250 list_del(&qd->qd_list); 1261 list_del(&qd->qd_list);
1262 /* Also remove if this qd exists in the reclaim list */
1263 if (!list_empty(&qd->qd_reclaim)) {
1264 list_del_init(&qd->qd_reclaim);
1265 atomic_dec(&qd_lru_count);
1266 }
1251 atomic_dec(&sdp->sd_quota_count); 1267 atomic_dec(&sdp->sd_quota_count);
1252 spin_unlock(&sdp->sd_quota_spin); 1268 spin_unlock(&qd_lru_lock);
1253 1269
1254 if (!qd->qd_count) { 1270 if (!atomic_read(&qd->qd_count)) {
1255 gfs2_assert_warn(sdp, !qd->qd_change); 1271 gfs2_assert_warn(sdp, !qd->qd_change);
1256 gfs2_assert_warn(sdp, !qd->qd_slot_count); 1272 gfs2_assert_warn(sdp, !qd->qd_slot_count);
1257 } else 1273 } else
1258 gfs2_assert_warn(sdp, qd->qd_slot_count == 1); 1274 gfs2_assert_warn(sdp, qd->qd_slot_count == 1);
1259 gfs2_assert_warn(sdp, !qd->qd_bh_count); 1275 gfs2_assert_warn(sdp, !qd->qd_bh_count);
1260 1276
1261 gfs2_lvb_unhold(qd->qd_gl); 1277 gfs2_glock_put(qd->qd_gl);
1262 kmem_cache_free(gfs2_quotad_cachep, qd); 1278 kmem_cache_free(gfs2_quotad_cachep, qd);
1263 1279
1264 spin_lock(&sdp->sd_quota_spin); 1280 spin_lock(&qd_lru_lock);
1265 } 1281 }
1266 spin_unlock(&sdp->sd_quota_spin); 1282 spin_unlock(&qd_lru_lock);
1267 1283
1268 gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_quota_count)); 1284 gfs2_assert_warn(sdp, !atomic_read(&sdp->sd_quota_count));
1269 1285
@@ -1341,9 +1357,6 @@ int gfs2_quotad(void *data)
1341 quotad_check_timeo(sdp, "sync", gfs2_quota_sync, t, 1357 quotad_check_timeo(sdp, "sync", gfs2_quota_sync, t,
1342 &quotad_timeo, &tune->gt_quota_quantum); 1358 &quotad_timeo, &tune->gt_quota_quantum);
1343 1359
1344 /* FIXME: This should be turned into a shrinker */
1345 gfs2_quota_scan(sdp);
1346
1347 /* Check for & recover partially truncated inodes */ 1360 /* Check for & recover partially truncated inodes */
1348 quotad_check_trunc_list(sdp); 1361 quotad_check_trunc_list(sdp);
1349 1362
diff --git a/fs/gfs2/quota.h b/fs/gfs2/quota.h
index cec9032be97d..0fa5fa63d0e8 100644
--- a/fs/gfs2/quota.h
+++ b/fs/gfs2/quota.h
@@ -49,4 +49,6 @@ static inline int gfs2_quota_lock_check(struct gfs2_inode *ip)
49 return ret; 49 return ret;
50} 50}
51 51
52extern int gfs2_shrink_qd_memory(int nr, gfp_t gfp_mask);
53
52#endif /* __QUOTA_DOT_H__ */ 54#endif /* __QUOTA_DOT_H__ */
diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c
index efd09c3d2b26..247e8f7d6b3d 100644
--- a/fs/gfs2/recovery.c
+++ b/fs/gfs2/recovery.c
@@ -13,7 +13,6 @@
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/gfs2_ondisk.h> 14#include <linux/gfs2_ondisk.h>
15#include <linux/crc32.h> 15#include <linux/crc32.h>
16#include <linux/lm_interface.h>
17#include <linux/kthread.h> 16#include <linux/kthread.h>
18#include <linux/freezer.h> 17#include <linux/freezer.h>
19 18
@@ -427,20 +426,23 @@ static int clean_journal(struct gfs2_jdesc *jd, struct gfs2_log_header_host *hea
427} 426}
428 427
429 428
430static void gfs2_lm_recovery_done(struct gfs2_sbd *sdp, unsigned int jid, 429static void gfs2_recovery_done(struct gfs2_sbd *sdp, unsigned int jid,
431 unsigned int message) 430 unsigned int message)
432{ 431{
433 if (!sdp->sd_lockstruct.ls_ops->lm_recovery_done) 432 char env_jid[20];
434 return; 433 char env_status[20];
435 434 char *envp[] = { env_jid, env_status, NULL };
436 if (likely(!test_bit(SDF_SHUTDOWN, &sdp->sd_flags))) 435 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
437 sdp->sd_lockstruct.ls_ops->lm_recovery_done( 436 ls->ls_recover_jid_done = jid;
438 sdp->sd_lockstruct.ls_lockspace, jid, message); 437 ls->ls_recover_jid_status = message;
438 sprintf(env_jid, "JID=%d", jid);
439 sprintf(env_status, "RECOVERY=%s",
440 message == LM_RD_SUCCESS ? "Done" : "Failed");
441 kobject_uevent_env(&sdp->sd_kobj, KOBJ_CHANGE, envp);
439} 442}
440 443
441
442/** 444/**
443 * gfs2_recover_journal - recovery a given journal 445 * gfs2_recover_journal - recover a given journal
444 * @jd: the struct gfs2_jdesc describing the journal 446 * @jd: the struct gfs2_jdesc describing the journal
445 * 447 *
446 * Acquire the journal's lock, check to see if the journal is clean, and 448 * Acquire the journal's lock, check to see if the journal is clean, and
@@ -561,7 +563,7 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd)
561 if (jd->jd_jid != sdp->sd_lockstruct.ls_jid) 563 if (jd->jd_jid != sdp->sd_lockstruct.ls_jid)
562 gfs2_glock_dq_uninit(&ji_gh); 564 gfs2_glock_dq_uninit(&ji_gh);
563 565
564 gfs2_lm_recovery_done(sdp, jd->jd_jid, LM_RD_SUCCESS); 566 gfs2_recovery_done(sdp, jd->jd_jid, LM_RD_SUCCESS);
565 567
566 if (jd->jd_jid != sdp->sd_lockstruct.ls_jid) 568 if (jd->jd_jid != sdp->sd_lockstruct.ls_jid)
567 gfs2_glock_dq_uninit(&j_gh); 569 gfs2_glock_dq_uninit(&j_gh);
@@ -581,7 +583,7 @@ fail_gunlock_j:
581 fs_info(sdp, "jid=%u: %s\n", jd->jd_jid, (error) ? "Failed" : "Done"); 583 fs_info(sdp, "jid=%u: %s\n", jd->jd_jid, (error) ? "Failed" : "Done");
582 584
583fail: 585fail:
584 gfs2_lm_recovery_done(sdp, jd->jd_jid, LM_RD_GAVEUP); 586 gfs2_recovery_done(sdp, jd->jd_jid, LM_RD_GAVEUP);
585 return error; 587 return error;
586} 588}
587 589
diff --git a/fs/gfs2/rgrp.c b/fs/gfs2/rgrp.c
index 8b01c635d925..f03d024038ea 100644
--- a/fs/gfs2/rgrp.c
+++ b/fs/gfs2/rgrp.c
@@ -13,8 +13,8 @@
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/fs.h> 14#include <linux/fs.h>
15#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
16#include <linux/lm_interface.h>
17#include <linux/prefetch.h> 16#include <linux/prefetch.h>
17#include <linux/blkdev.h>
18 18
19#include "gfs2.h" 19#include "gfs2.h"
20#include "incore.h" 20#include "incore.h"
@@ -132,81 +132,90 @@ static inline unsigned char gfs2_testbit(struct gfs2_rgrpd *rgd,
132} 132}
133 133
134/** 134/**
135 * gfs2_bit_search
136 * @ptr: Pointer to bitmap data
137 * @mask: Mask to use (normally 0x55555.... but adjusted for search start)
138 * @state: The state we are searching for
139 *
140 * We xor the bitmap data with a patter which is the bitwise opposite
141 * of what we are looking for, this gives rise to a pattern of ones
142 * wherever there is a match. Since we have two bits per entry, we
143 * take this pattern, shift it down by one place and then and it with
144 * the original. All the even bit positions (0,2,4, etc) then represent
145 * successful matches, so we mask with 0x55555..... to remove the unwanted
146 * odd bit positions.
147 *
148 * This allows searching of a whole u64 at once (32 blocks) with a
149 * single test (on 64 bit arches).
150 */
151
152static inline u64 gfs2_bit_search(const __le64 *ptr, u64 mask, u8 state)
153{
154 u64 tmp;
155 static const u64 search[] = {
156 [0] = 0xffffffffffffffffULL,
157 [1] = 0xaaaaaaaaaaaaaaaaULL,
158 [2] = 0x5555555555555555ULL,
159 [3] = 0x0000000000000000ULL,
160 };
161 tmp = le64_to_cpu(*ptr) ^ search[state];
162 tmp &= (tmp >> 1);
163 tmp &= mask;
164 return tmp;
165}
166
167/**
135 * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing 168 * gfs2_bitfit - Search an rgrp's bitmap buffer to find a bit-pair representing
136 * a block in a given allocation state. 169 * a block in a given allocation state.
137 * @buffer: the buffer that holds the bitmaps 170 * @buffer: the buffer that holds the bitmaps
138 * @buflen: the length (in bytes) of the buffer 171 * @len: the length (in bytes) of the buffer
139 * @goal: start search at this block's bit-pair (within @buffer) 172 * @goal: start search at this block's bit-pair (within @buffer)
140 * @old_state: GFS2_BLKST_XXX the state of the block we're looking for. 173 * @state: GFS2_BLKST_XXX the state of the block we're looking for.
141 * 174 *
142 * Scope of @goal and returned block number is only within this bitmap buffer, 175 * Scope of @goal and returned block number is only within this bitmap buffer,
143 * not entire rgrp or filesystem. @buffer will be offset from the actual 176 * not entire rgrp or filesystem. @buffer will be offset from the actual
144 * beginning of a bitmap block buffer, skipping any header structures. 177 * beginning of a bitmap block buffer, skipping any header structures, but
178 * headers are always a multiple of 64 bits long so that the buffer is
179 * always aligned to a 64 bit boundary.
180 *
181 * The size of the buffer is in bytes, but is it assumed that it is
182 * always ok to to read a complete multiple of 64 bits at the end
183 * of the block in case the end is no aligned to a natural boundary.
145 * 184 *
146 * Return: the block number (bitmap buffer scope) that was found 185 * Return: the block number (bitmap buffer scope) that was found
147 */ 186 */
148 187
149static u32 gfs2_bitfit(const u8 *buffer, unsigned int buflen, u32 goal, 188static u32 gfs2_bitfit(const u8 *buf, const unsigned int len,
150 u8 old_state) 189 u32 goal, u8 state)
151{ 190{
152 const u8 *byte, *start, *end; 191 u32 spoint = (goal << 1) & ((8*sizeof(u64)) - 1);
153 int bit, startbit; 192 const __le64 *ptr = ((__le64 *)buf) + (goal >> 5);
154 u32 g1, g2, misaligned; 193 const __le64 *end = (__le64 *)(buf + ALIGN(len, sizeof(u64)));
155 unsigned long *plong; 194 u64 tmp;
156 unsigned long lskipval; 195 u64 mask = 0x5555555555555555ULL;
157 196 u32 bit;
158 lskipval = (old_state & GFS2_BLKST_USED) ? LBITSKIP00 : LBITSKIP55; 197
159 g1 = (goal / GFS2_NBBY); 198 BUG_ON(state > 3);
160 start = buffer + g1; 199
161 byte = start; 200 /* Mask off bits we don't care about at the start of the search */
162 end = buffer + buflen; 201 mask <<= spoint;
163 g2 = ALIGN(g1, sizeof(unsigned long)); 202 tmp = gfs2_bit_search(ptr, mask, state);
164 plong = (unsigned long *)(buffer + g2); 203 ptr++;
165 startbit = bit = (goal % GFS2_NBBY) * GFS2_BIT_SIZE; 204 while(tmp == 0 && ptr < end) {
166 misaligned = g2 - g1; 205 tmp = gfs2_bit_search(ptr, 0x5555555555555555ULL, state);
167 if (!misaligned) 206 ptr++;
168 goto ulong_aligned;
169/* parse the bitmap a byte at a time */
170misaligned:
171 while (byte < end) {
172 if (((*byte >> bit) & GFS2_BIT_MASK) == old_state) {
173 return goal +
174 (((byte - start) * GFS2_NBBY) +
175 ((bit - startbit) >> 1));
176 }
177 bit += GFS2_BIT_SIZE;
178 if (bit >= GFS2_NBBY * GFS2_BIT_SIZE) {
179 bit = 0;
180 byte++;
181 misaligned--;
182 if (!misaligned) {
183 plong = (unsigned long *)byte;
184 goto ulong_aligned;
185 }
186 }
187 }
188 return BFITNOENT;
189
190/* parse the bitmap a unsigned long at a time */
191ulong_aligned:
192 /* Stop at "end - 1" or else prefetch can go past the end and segfault.
193 We could "if" it but we'd lose some of the performance gained.
194 This way will only slow down searching the very last 4/8 bytes
195 depending on architecture. I've experimented with several ways
196 of writing this section such as using an else before the goto
197 but this one seems to be the fastest. */
198 while ((unsigned char *)plong < end - sizeof(unsigned long)) {
199 prefetch(plong + 1);
200 if (((*plong) & LBITMASK) != lskipval)
201 break;
202 plong++;
203 }
204 if ((unsigned char *)plong < end) {
205 byte = (const u8 *)plong;
206 misaligned += sizeof(unsigned long) - 1;
207 goto misaligned;
208 } 207 }
209 return BFITNOENT; 208 /* Mask off any bits which are more than len bytes from the start */
209 if (ptr == end && (len & (sizeof(u64) - 1)))
210 tmp &= (((u64)~0) >> (64 - 8*(len & (sizeof(u64) - 1))));
211 /* Didn't find anything, so return */
212 if (tmp == 0)
213 return BFITNOENT;
214 ptr--;
215 bit = fls64(tmp);
216 bit--; /* fls64 always adds one to the bit count */
217 bit /= 2; /* two bits per entry in the bitmap */
218 return (((const unsigned char *)ptr - buf) * GFS2_NBBY) + bit;
210} 219}
211 220
212/** 221/**
@@ -831,6 +840,58 @@ void gfs2_rgrp_bh_put(struct gfs2_rgrpd *rgd)
831 spin_unlock(&sdp->sd_rindex_spin); 840 spin_unlock(&sdp->sd_rindex_spin);
832} 841}
833 842
843static void gfs2_rgrp_send_discards(struct gfs2_sbd *sdp, u64 offset,
844 const struct gfs2_bitmap *bi)
845{
846 struct super_block *sb = sdp->sd_vfs;
847 struct block_device *bdev = sb->s_bdev;
848 const unsigned int sects_per_blk = sdp->sd_sb.sb_bsize /
849 bdev_hardsect_size(sb->s_bdev);
850 u64 blk;
851 sector_t start = 0;
852 sector_t nr_sects = 0;
853 int rv;
854 unsigned int x;
855
856 for (x = 0; x < bi->bi_len; x++) {
857 const u8 *orig = bi->bi_bh->b_data + bi->bi_offset + x;
858 const u8 *clone = bi->bi_clone + bi->bi_offset + x;
859 u8 diff = ~(*orig | (*orig >> 1)) & (*clone | (*clone >> 1));
860 diff &= 0x55;
861 if (diff == 0)
862 continue;
863 blk = offset + ((bi->bi_start + x) * GFS2_NBBY);
864 blk *= sects_per_blk; /* convert to sectors */
865 while(diff) {
866 if (diff & 1) {
867 if (nr_sects == 0)
868 goto start_new_extent;
869 if ((start + nr_sects) != blk) {
870 rv = blkdev_issue_discard(bdev, start,
871 nr_sects, GFP_NOFS);
872 if (rv)
873 goto fail;
874 nr_sects = 0;
875start_new_extent:
876 start = blk;
877 }
878 nr_sects += sects_per_blk;
879 }
880 diff >>= 2;
881 blk += sects_per_blk;
882 }
883 }
884 if (nr_sects) {
885 rv = blkdev_issue_discard(bdev, start, nr_sects, GFP_NOFS);
886 if (rv)
887 goto fail;
888 }
889 return;
890fail:
891 fs_warn(sdp, "error %d on discard request, turning discards off for this filesystem", rv);
892 sdp->sd_args.ar_discard = 0;
893}
894
834void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd) 895void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd)
835{ 896{
836 struct gfs2_sbd *sdp = rgd->rd_sbd; 897 struct gfs2_sbd *sdp = rgd->rd_sbd;
@@ -841,6 +902,8 @@ void gfs2_rgrp_repolish_clones(struct gfs2_rgrpd *rgd)
841 struct gfs2_bitmap *bi = rgd->rd_bits + x; 902 struct gfs2_bitmap *bi = rgd->rd_bits + x;
842 if (!bi->bi_clone) 903 if (!bi->bi_clone)
843 continue; 904 continue;
905 if (sdp->sd_args.ar_discard)
906 gfs2_rgrp_send_discards(sdp, rgd->rd_data0, bi);
844 memcpy(bi->bi_clone + bi->bi_offset, 907 memcpy(bi->bi_clone + bi->bi_offset,
845 bi->bi_bh->b_data + bi->bi_offset, bi->bi_len); 908 bi->bi_bh->b_data + bi->bi_offset, bi->bi_len);
846 } 909 }
diff --git a/fs/gfs2/super.c b/fs/gfs2/super.c
index 141b781f2fcc..601913e0a482 100644
--- a/fs/gfs2/super.c
+++ b/fs/gfs2/super.c
@@ -15,7 +15,6 @@
15#include <linux/crc32.h> 15#include <linux/crc32.h>
16#include <linux/gfs2_ondisk.h> 16#include <linux/gfs2_ondisk.h>
17#include <linux/bio.h> 17#include <linux/bio.h>
18#include <linux/lm_interface.h>
19 18
20#include "gfs2.h" 19#include "gfs2.h"
21#include "incore.h" 20#include "incore.h"
@@ -339,7 +338,6 @@ static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp,
339 struct gfs2_holder *t_gh) 338 struct gfs2_holder *t_gh)
340{ 339{
341 struct gfs2_inode *ip; 340 struct gfs2_inode *ip;
342 struct gfs2_holder ji_gh;
343 struct gfs2_jdesc *jd; 341 struct gfs2_jdesc *jd;
344 struct lfcc *lfcc; 342 struct lfcc *lfcc;
345 LIST_HEAD(list); 343 LIST_HEAD(list);
@@ -387,7 +385,6 @@ out:
387 gfs2_glock_dq_uninit(&lfcc->gh); 385 gfs2_glock_dq_uninit(&lfcc->gh);
388 kfree(lfcc); 386 kfree(lfcc);
389 } 387 }
390 gfs2_glock_dq_uninit(&ji_gh);
391 return error; 388 return error;
392} 389}
393 390
diff --git a/fs/gfs2/super.h b/fs/gfs2/super.h
index f6b8b00ad881..91abdbedcc86 100644
--- a/fs/gfs2/super.h
+++ b/fs/gfs2/super.h
@@ -14,7 +14,7 @@
14#include <linux/dcache.h> 14#include <linux/dcache.h>
15#include "incore.h" 15#include "incore.h"
16 16
17void gfs2_lm_unmount(struct gfs2_sbd *sdp); 17extern void gfs2_lm_unmount(struct gfs2_sbd *sdp);
18 18
19static inline unsigned int gfs2_jindex_size(struct gfs2_sbd *sdp) 19static inline unsigned int gfs2_jindex_size(struct gfs2_sbd *sdp)
20{ 20{
@@ -27,21 +27,23 @@ static inline unsigned int gfs2_jindex_size(struct gfs2_sbd *sdp)
27 27
28void gfs2_jindex_free(struct gfs2_sbd *sdp); 28void gfs2_jindex_free(struct gfs2_sbd *sdp);
29 29
30struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid); 30extern int gfs2_mount_args(struct gfs2_sbd *sdp, struct gfs2_args *args, char *data);
31int gfs2_jdesc_check(struct gfs2_jdesc *jd);
32 31
33int gfs2_lookup_in_master_dir(struct gfs2_sbd *sdp, char *filename, 32extern struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid);
34 struct gfs2_inode **ipp); 33extern int gfs2_jdesc_check(struct gfs2_jdesc *jd);
35 34
36int gfs2_make_fs_rw(struct gfs2_sbd *sdp); 35extern int gfs2_lookup_in_master_dir(struct gfs2_sbd *sdp, char *filename,
36 struct gfs2_inode **ipp);
37 37
38int gfs2_statfs_init(struct gfs2_sbd *sdp); 38extern int gfs2_make_fs_rw(struct gfs2_sbd *sdp);
39void gfs2_statfs_change(struct gfs2_sbd *sdp,
40 s64 total, s64 free, s64 dinodes);
41int gfs2_statfs_sync(struct gfs2_sbd *sdp);
42 39
43int gfs2_freeze_fs(struct gfs2_sbd *sdp); 40extern int gfs2_statfs_init(struct gfs2_sbd *sdp);
44void gfs2_unfreeze_fs(struct gfs2_sbd *sdp); 41extern void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free,
42 s64 dinodes);
43extern int gfs2_statfs_sync(struct gfs2_sbd *sdp);
44
45extern int gfs2_freeze_fs(struct gfs2_sbd *sdp);
46extern void gfs2_unfreeze_fs(struct gfs2_sbd *sdp);
45 47
46extern struct file_system_type gfs2_fs_type; 48extern struct file_system_type gfs2_fs_type;
47extern struct file_system_type gfs2meta_fs_type; 49extern struct file_system_type gfs2meta_fs_type;
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index 26c1fa777a95..7655f5025fec 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -14,9 +14,8 @@
14#include <linux/buffer_head.h> 14#include <linux/buffer_head.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/kobject.h> 16#include <linux/kobject.h>
17#include <linux/gfs2_ondisk.h>
18#include <linux/lm_interface.h>
19#include <asm/uaccess.h> 17#include <asm/uaccess.h>
18#include <linux/gfs2_ondisk.h>
20 19
21#include "gfs2.h" 20#include "gfs2.h"
22#include "incore.h" 21#include "incore.h"
@@ -25,6 +24,7 @@
25#include "glock.h" 24#include "glock.h"
26#include "quota.h" 25#include "quota.h"
27#include "util.h" 26#include "util.h"
27#include "glops.h"
28 28
29static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) 29static ssize_t id_show(struct gfs2_sbd *sdp, char *buf)
30{ 30{
@@ -37,6 +37,30 @@ static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf)
37 return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname); 37 return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname);
38} 38}
39 39
40static int gfs2_uuid_valid(const u8 *uuid)
41{
42 int i;
43
44 for (i = 0; i < 16; i++) {
45 if (uuid[i])
46 return 1;
47 }
48 return 0;
49}
50
51static ssize_t uuid_show(struct gfs2_sbd *sdp, char *buf)
52{
53 const u8 *uuid = sdp->sd_sb.sb_uuid;
54 buf[0] = '\0';
55 if (!gfs2_uuid_valid(uuid))
56 return 0;
57 return snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X-%02X%02X-"
58 "%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X\n",
59 uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5],
60 uuid[6], uuid[7], uuid[8], uuid[9], uuid[10], uuid[11],
61 uuid[12], uuid[13], uuid[14], uuid[15]);
62}
63
40static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) 64static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf)
41{ 65{
42 unsigned int count; 66 unsigned int count;
@@ -148,6 +172,46 @@ static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf,
148 return len; 172 return len;
149} 173}
150 174
175static ssize_t demote_rq_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
176{
177 struct gfs2_glock *gl;
178 const struct gfs2_glock_operations *glops;
179 unsigned int glmode;
180 unsigned int gltype;
181 unsigned long long glnum;
182 char mode[16];
183 int rv;
184
185 if (!capable(CAP_SYS_ADMIN))
186 return -EACCES;
187
188 rv = sscanf(buf, "%u:%llu %15s", &gltype, &glnum,
189 mode);
190 if (rv != 3)
191 return -EINVAL;
192
193 if (strcmp(mode, "EX") == 0)
194 glmode = LM_ST_UNLOCKED;
195 else if ((strcmp(mode, "CW") == 0) || (strcmp(mode, "DF") == 0))
196 glmode = LM_ST_DEFERRED;
197 else if ((strcmp(mode, "PR") == 0) || (strcmp(mode, "SH") == 0))
198 glmode = LM_ST_SHARED;
199 else
200 return -EINVAL;
201
202 if (gltype > LM_TYPE_JOURNAL)
203 return -EINVAL;
204 glops = gfs2_glops_list[gltype];
205 if (glops == NULL)
206 return -EINVAL;
207 rv = gfs2_glock_get(sdp, glnum, glops, 0, &gl);
208 if (rv)
209 return rv;
210 gfs2_glock_cb(gl, glmode);
211 gfs2_glock_put(gl);
212 return len;
213}
214
151struct gfs2_attr { 215struct gfs2_attr {
152 struct attribute attr; 216 struct attribute attr;
153 ssize_t (*show)(struct gfs2_sbd *, char *); 217 ssize_t (*show)(struct gfs2_sbd *, char *);
@@ -159,22 +223,26 @@ static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store)
159 223
160GFS2_ATTR(id, 0444, id_show, NULL); 224GFS2_ATTR(id, 0444, id_show, NULL);
161GFS2_ATTR(fsname, 0444, fsname_show, NULL); 225GFS2_ATTR(fsname, 0444, fsname_show, NULL);
226GFS2_ATTR(uuid, 0444, uuid_show, NULL);
162GFS2_ATTR(freeze, 0644, freeze_show, freeze_store); 227GFS2_ATTR(freeze, 0644, freeze_show, freeze_store);
163GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store); 228GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
164GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store); 229GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store);
165GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store); 230GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store);
166GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store); 231GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store);
167GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store); 232GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store);
233GFS2_ATTR(demote_rq, 0200, NULL, demote_rq_store);
168 234
169static struct attribute *gfs2_attrs[] = { 235static struct attribute *gfs2_attrs[] = {
170 &gfs2_attr_id.attr, 236 &gfs2_attr_id.attr,
171 &gfs2_attr_fsname.attr, 237 &gfs2_attr_fsname.attr,
238 &gfs2_attr_uuid.attr,
172 &gfs2_attr_freeze.attr, 239 &gfs2_attr_freeze.attr,
173 &gfs2_attr_withdraw.attr, 240 &gfs2_attr_withdraw.attr,
174 &gfs2_attr_statfs_sync.attr, 241 &gfs2_attr_statfs_sync.attr,
175 &gfs2_attr_quota_sync.attr, 242 &gfs2_attr_quota_sync.attr,
176 &gfs2_attr_quota_refresh_user.attr, 243 &gfs2_attr_quota_refresh_user.attr,
177 &gfs2_attr_quota_refresh_group.attr, 244 &gfs2_attr_quota_refresh_group.attr,
245 &gfs2_attr_demote_rq.attr,
178 NULL, 246 NULL,
179}; 247};
180 248
@@ -224,14 +292,145 @@ static struct lockstruct_attr lockstruct_attr_##name = __ATTR_RO(name)
224 292
225LOCKSTRUCT_ATTR(jid, "%u\n"); 293LOCKSTRUCT_ATTR(jid, "%u\n");
226LOCKSTRUCT_ATTR(first, "%u\n"); 294LOCKSTRUCT_ATTR(first, "%u\n");
227LOCKSTRUCT_ATTR(lvb_size, "%u\n");
228LOCKSTRUCT_ATTR(flags, "%d\n");
229 295
230static struct attribute *lockstruct_attrs[] = { 296static struct attribute *lockstruct_attrs[] = {
231 &lockstruct_attr_jid.attr, 297 &lockstruct_attr_jid.attr,
232 &lockstruct_attr_first.attr, 298 &lockstruct_attr_first.attr,
233 &lockstruct_attr_lvb_size.attr, 299 NULL,
234 &lockstruct_attr_flags.attr, 300};
301
302/*
303 * lock_module. Originally from lock_dlm
304 */
305
306static ssize_t proto_name_show(struct gfs2_sbd *sdp, char *buf)
307{
308 const struct lm_lockops *ops = sdp->sd_lockstruct.ls_ops;
309 return sprintf(buf, "%s\n", ops->lm_proto_name);
310}
311
312static ssize_t block_show(struct gfs2_sbd *sdp, char *buf)
313{
314 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
315 ssize_t ret;
316 int val = 0;
317
318 if (test_bit(DFL_BLOCK_LOCKS, &ls->ls_flags))
319 val = 1;
320 ret = sprintf(buf, "%d\n", val);
321 return ret;
322}
323
324static ssize_t block_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
325{
326 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
327 ssize_t ret = len;
328 int val;
329
330 val = simple_strtol(buf, NULL, 0);
331
332 if (val == 1)
333 set_bit(DFL_BLOCK_LOCKS, &ls->ls_flags);
334 else if (val == 0) {
335 clear_bit(DFL_BLOCK_LOCKS, &ls->ls_flags);
336 smp_mb__after_clear_bit();
337 gfs2_glock_thaw(sdp);
338 } else {
339 ret = -EINVAL;
340 }
341 return ret;
342}
343
344static ssize_t lkid_show(struct gfs2_sbd *sdp, char *buf)
345{
346 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
347 return sprintf(buf, "%u\n", ls->ls_id);
348}
349
350static ssize_t lkfirst_show(struct gfs2_sbd *sdp, char *buf)
351{
352 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
353 return sprintf(buf, "%d\n", ls->ls_first);
354}
355
356static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf)
357{
358 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
359 return sprintf(buf, "%d\n", ls->ls_first_done);
360}
361
362static ssize_t recover_show(struct gfs2_sbd *sdp, char *buf)
363{
364 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
365 return sprintf(buf, "%d\n", ls->ls_recover_jid);
366}
367
368static void gfs2_jdesc_make_dirty(struct gfs2_sbd *sdp, unsigned int jid)
369{
370 struct gfs2_jdesc *jd;
371
372 spin_lock(&sdp->sd_jindex_spin);
373 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
374 if (jd->jd_jid != jid)
375 continue;
376 jd->jd_dirty = 1;
377 break;
378 }
379 spin_unlock(&sdp->sd_jindex_spin);
380}
381
382static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
383{
384 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
385 ls->ls_recover_jid = simple_strtol(buf, NULL, 0);
386 gfs2_jdesc_make_dirty(sdp, ls->ls_recover_jid);
387 if (sdp->sd_recoverd_process)
388 wake_up_process(sdp->sd_recoverd_process);
389 return len;
390}
391
392static ssize_t recover_done_show(struct gfs2_sbd *sdp, char *buf)
393{
394 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
395 return sprintf(buf, "%d\n", ls->ls_recover_jid_done);
396}
397
398static ssize_t recover_status_show(struct gfs2_sbd *sdp, char *buf)
399{
400 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
401 return sprintf(buf, "%d\n", ls->ls_recover_jid_status);
402}
403
404struct gdlm_attr {
405 struct attribute attr;
406 ssize_t (*show)(struct gfs2_sbd *sdp, char *);
407 ssize_t (*store)(struct gfs2_sbd *sdp, const char *, size_t);
408};
409
410#define GDLM_ATTR(_name,_mode,_show,_store) \
411static struct gdlm_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
412
413GDLM_ATTR(proto_name, 0444, proto_name_show, NULL);
414GDLM_ATTR(block, 0644, block_show, block_store);
415GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
416GDLM_ATTR(id, 0444, lkid_show, NULL);
417GDLM_ATTR(first, 0444, lkfirst_show, NULL);
418GDLM_ATTR(first_done, 0444, first_done_show, NULL);
419GDLM_ATTR(recover, 0644, recover_show, recover_store);
420GDLM_ATTR(recover_done, 0444, recover_done_show, NULL);
421GDLM_ATTR(recover_status, 0444, recover_status_show, NULL);
422
423static struct attribute *lock_module_attrs[] = {
424 &gdlm_attr_proto_name.attr,
425 &gdlm_attr_block.attr,
426 &gdlm_attr_withdraw.attr,
427 &gdlm_attr_id.attr,
428 &lockstruct_attr_jid.attr,
429 &gdlm_attr_first.attr,
430 &gdlm_attr_first_done.attr,
431 &gdlm_attr_recover.attr,
432 &gdlm_attr_recover_done.attr,
433 &gdlm_attr_recover_status.attr,
235 NULL, 434 NULL,
236}; 435};
237 436
@@ -373,7 +572,6 @@ TUNE_ATTR(complain_secs, 0);
373TUNE_ATTR(statfs_slow, 0); 572TUNE_ATTR(statfs_slow, 0);
374TUNE_ATTR(new_files_jdata, 0); 573TUNE_ATTR(new_files_jdata, 0);
375TUNE_ATTR(quota_simul_sync, 1); 574TUNE_ATTR(quota_simul_sync, 1);
376TUNE_ATTR(quota_cache_secs, 1);
377TUNE_ATTR(stall_secs, 1); 575TUNE_ATTR(stall_secs, 1);
378TUNE_ATTR(statfs_quantum, 1); 576TUNE_ATTR(statfs_quantum, 1);
379TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process); 577TUNE_ATTR_DAEMON(recoverd_secs, recoverd_process);
@@ -389,7 +587,6 @@ static struct attribute *tune_attrs[] = {
389 &tune_attr_complain_secs.attr, 587 &tune_attr_complain_secs.attr,
390 &tune_attr_statfs_slow.attr, 588 &tune_attr_statfs_slow.attr,
391 &tune_attr_quota_simul_sync.attr, 589 &tune_attr_quota_simul_sync.attr,
392 &tune_attr_quota_cache_secs.attr,
393 &tune_attr_stall_secs.attr, 590 &tune_attr_stall_secs.attr,
394 &tune_attr_statfs_quantum.attr, 591 &tune_attr_statfs_quantum.attr,
395 &tune_attr_recoverd_secs.attr, 592 &tune_attr_recoverd_secs.attr,
@@ -414,6 +611,11 @@ static struct attribute_group tune_group = {
414 .attrs = tune_attrs, 611 .attrs = tune_attrs,
415}; 612};
416 613
614static struct attribute_group lock_module_group = {
615 .name = "lock_module",
616 .attrs = lock_module_attrs,
617};
618
417int gfs2_sys_fs_add(struct gfs2_sbd *sdp) 619int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
418{ 620{
419 int error; 621 int error;
@@ -436,9 +638,15 @@ int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
436 if (error) 638 if (error)
437 goto fail_args; 639 goto fail_args;
438 640
641 error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group);
642 if (error)
643 goto fail_tune;
644
439 kobject_uevent(&sdp->sd_kobj, KOBJ_ADD); 645 kobject_uevent(&sdp->sd_kobj, KOBJ_ADD);
440 return 0; 646 return 0;
441 647
648fail_tune:
649 sysfs_remove_group(&sdp->sd_kobj, &tune_group);
442fail_args: 650fail_args:
443 sysfs_remove_group(&sdp->sd_kobj, &args_group); 651 sysfs_remove_group(&sdp->sd_kobj, &args_group);
444fail_lockstruct: 652fail_lockstruct:
@@ -455,15 +663,27 @@ void gfs2_sys_fs_del(struct gfs2_sbd *sdp)
455 sysfs_remove_group(&sdp->sd_kobj, &tune_group); 663 sysfs_remove_group(&sdp->sd_kobj, &tune_group);
456 sysfs_remove_group(&sdp->sd_kobj, &args_group); 664 sysfs_remove_group(&sdp->sd_kobj, &args_group);
457 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group); 665 sysfs_remove_group(&sdp->sd_kobj, &lockstruct_group);
666 sysfs_remove_group(&sdp->sd_kobj, &lock_module_group);
458 kobject_put(&sdp->sd_kobj); 667 kobject_put(&sdp->sd_kobj);
459} 668}
460 669
670
461static int gfs2_uevent(struct kset *kset, struct kobject *kobj, 671static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
462 struct kobj_uevent_env *env) 672 struct kobj_uevent_env *env)
463{ 673{
464 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); 674 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
675 const u8 *uuid = sdp->sd_sb.sb_uuid;
676
465 add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name); 677 add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name);
466 add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name); 678 add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name);
679 if (gfs2_uuid_valid(uuid)) {
680 add_uevent_var(env, "UUID=%02X%02X%02X%02X-%02X%02X-%02X%02X-"
681 "%02X%02X-%02X%02X%02X%02X%02X%02X",
682 uuid[0], uuid[1], uuid[2], uuid[3], uuid[4],
683 uuid[5], uuid[6], uuid[7], uuid[8], uuid[9],
684 uuid[10], uuid[11], uuid[12], uuid[13],
685 uuid[14], uuid[15]);
686 }
467 return 0; 687 return 0;
468} 688}
469 689
diff --git a/fs/gfs2/trans.c b/fs/gfs2/trans.c
index f677b8a83f0c..053752d4b27f 100644
--- a/fs/gfs2/trans.c
+++ b/fs/gfs2/trans.c
@@ -12,9 +12,8 @@
12#include <linux/spinlock.h> 12#include <linux/spinlock.h>
13#include <linux/completion.h> 13#include <linux/completion.h>
14#include <linux/buffer_head.h> 14#include <linux/buffer_head.h>
15#include <linux/gfs2_ondisk.h>
16#include <linux/kallsyms.h> 15#include <linux/kallsyms.h>
17#include <linux/lm_interface.h> 16#include <linux/gfs2_ondisk.h>
18 17
19#include "gfs2.h" 18#include "gfs2.h"
20#include "incore.h" 19#include "incore.h"
@@ -88,9 +87,11 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
88 87
89 if (!tr->tr_touched) { 88 if (!tr->tr_touched) {
90 gfs2_log_release(sdp, tr->tr_reserved); 89 gfs2_log_release(sdp, tr->tr_reserved);
91 gfs2_glock_dq(&tr->tr_t_gh); 90 if (tr->tr_t_gh.gh_gl) {
92 gfs2_holder_uninit(&tr->tr_t_gh); 91 gfs2_glock_dq(&tr->tr_t_gh);
93 kfree(tr); 92 gfs2_holder_uninit(&tr->tr_t_gh);
93 kfree(tr);
94 }
94 return; 95 return;
95 } 96 }
96 97
@@ -106,9 +107,11 @@ void gfs2_trans_end(struct gfs2_sbd *sdp)
106 } 107 }
107 108
108 gfs2_log_commit(sdp, tr); 109 gfs2_log_commit(sdp, tr);
109 gfs2_glock_dq(&tr->tr_t_gh); 110 if (tr->tr_t_gh.gh_gl) {
110 gfs2_holder_uninit(&tr->tr_t_gh); 111 gfs2_glock_dq(&tr->tr_t_gh);
111 kfree(tr); 112 gfs2_holder_uninit(&tr->tr_t_gh);
113 kfree(tr);
114 }
112 115
113 if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS) 116 if (sdp->sd_vfs->s_flags & MS_SYNCHRONOUS)
114 gfs2_log_flush(sdp, NULL); 117 gfs2_log_flush(sdp, NULL);
diff --git a/fs/gfs2/util.c b/fs/gfs2/util.c
index 374f50e95496..9d12b1118ba0 100644
--- a/fs/gfs2/util.c
+++ b/fs/gfs2/util.c
@@ -13,7 +13,6 @@
13#include <linux/buffer_head.h> 13#include <linux/buffer_head.h>
14#include <linux/crc32.h> 14#include <linux/crc32.h>
15#include <linux/gfs2_ondisk.h> 15#include <linux/gfs2_ondisk.h>
16#include <linux/lm_interface.h>
17#include <asm/uaccess.h> 16#include <asm/uaccess.h>
18 17
19#include "gfs2.h" 18#include "gfs2.h"
@@ -35,6 +34,8 @@ void gfs2_assert_i(struct gfs2_sbd *sdp)
35 34
36int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...) 35int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
37{ 36{
37 struct lm_lockstruct *ls = &sdp->sd_lockstruct;
38 const struct lm_lockops *lm = ls->ls_ops;
38 va_list args; 39 va_list args;
39 40
40 if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags)) 41 if (test_and_set_bit(SDF_SHUTDOWN, &sdp->sd_flags))
@@ -47,8 +48,12 @@ int gfs2_lm_withdraw(struct gfs2_sbd *sdp, char *fmt, ...)
47 fs_err(sdp, "about to withdraw this file system\n"); 48 fs_err(sdp, "about to withdraw this file system\n");
48 BUG_ON(sdp->sd_args.ar_debug); 49 BUG_ON(sdp->sd_args.ar_debug);
49 50
50 fs_err(sdp, "telling LM to withdraw\n"); 51 kobject_uevent(&sdp->sd_kobj, KOBJ_OFFLINE);
51 gfs2_withdraw_lockproto(&sdp->sd_lockstruct); 52
53 if (lm->lm_unmount) {
54 fs_err(sdp, "telling LM to unmount\n");
55 lm->lm_unmount(sdp);
56 }
52 fs_err(sdp, "withdrawn\n"); 57 fs_err(sdp, "withdrawn\n");
53 dump_stack(); 58 dump_stack();
54 59
diff --git a/fs/inode.c b/fs/inode.c
index 8a47ccd9fc38..643ac43e5a5c 100644
--- a/fs/inode.c
+++ b/fs/inode.c
@@ -1300,6 +1300,40 @@ sector_t bmap(struct inode * inode, sector_t block)
1300} 1300}
1301EXPORT_SYMBOL(bmap); 1301EXPORT_SYMBOL(bmap);
1302 1302
1303/*
1304 * With relative atime, only update atime if the previous atime is
1305 * earlier than either the ctime or mtime or if at least a day has
1306 * passed since the last atime update.
1307 */
1308static int relatime_need_update(struct vfsmount *mnt, struct inode *inode,
1309 struct timespec now)
1310{
1311
1312 if (!(mnt->mnt_flags & MNT_RELATIME))
1313 return 1;
1314 /*
1315 * Is mtime younger than atime? If yes, update atime:
1316 */
1317 if (timespec_compare(&inode->i_mtime, &inode->i_atime) >= 0)
1318 return 1;
1319 /*
1320 * Is ctime younger than atime? If yes, update atime:
1321 */
1322 if (timespec_compare(&inode->i_ctime, &inode->i_atime) >= 0)
1323 return 1;
1324
1325 /*
1326 * Is the previous atime value older than a day? If yes,
1327 * update atime:
1328 */
1329 if ((long)(now.tv_sec - inode->i_atime.tv_sec) >= 24*60*60)
1330 return 1;
1331 /*
1332 * Good, we can skip the atime update:
1333 */
1334 return 0;
1335}
1336
1303/** 1337/**
1304 * touch_atime - update the access time 1338 * touch_atime - update the access time
1305 * @mnt: mount the inode is accessed on 1339 * @mnt: mount the inode is accessed on
@@ -1327,17 +1361,12 @@ void touch_atime(struct vfsmount *mnt, struct dentry *dentry)
1327 goto out; 1361 goto out;
1328 if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode)) 1362 if ((mnt->mnt_flags & MNT_NODIRATIME) && S_ISDIR(inode->i_mode))
1329 goto out; 1363 goto out;
1330 if (mnt->mnt_flags & MNT_RELATIME) {
1331 /*
1332 * With relative atime, only update atime if the previous
1333 * atime is earlier than either the ctime or mtime.
1334 */
1335 if (timespec_compare(&inode->i_mtime, &inode->i_atime) < 0 &&
1336 timespec_compare(&inode->i_ctime, &inode->i_atime) < 0)
1337 goto out;
1338 }
1339 1364
1340 now = current_fs_time(inode->i_sb); 1365 now = current_fs_time(inode->i_sb);
1366
1367 if (!relatime_need_update(mnt, inode, now))
1368 goto out;
1369
1341 if (timespec_equal(&inode->i_atime, &now)) 1370 if (timespec_equal(&inode->i_atime, &now))
1342 goto out; 1371 goto out;
1343 1372
diff --git a/fs/namespace.c b/fs/namespace.c
index 06f8e63f6cb1..f0e753097353 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -780,6 +780,7 @@ static void show_mnt_opts(struct seq_file *m, struct vfsmount *mnt)
780 { MNT_NOATIME, ",noatime" }, 780 { MNT_NOATIME, ",noatime" },
781 { MNT_NODIRATIME, ",nodiratime" }, 781 { MNT_NODIRATIME, ",nodiratime" },
782 { MNT_RELATIME, ",relatime" }, 782 { MNT_RELATIME, ",relatime" },
783 { MNT_STRICTATIME, ",strictatime" },
783 { 0, NULL } 784 { 0, NULL }
784 }; 785 };
785 const struct proc_fs_info *fs_infop; 786 const struct proc_fs_info *fs_infop;
@@ -1919,6 +1920,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
1919 if (data_page) 1920 if (data_page)
1920 ((char *)data_page)[PAGE_SIZE - 1] = 0; 1921 ((char *)data_page)[PAGE_SIZE - 1] = 0;
1921 1922
1923 /* Default to relatime */
1924 mnt_flags |= MNT_RELATIME;
1925
1922 /* Separate the per-mountpoint flags */ 1926 /* Separate the per-mountpoint flags */
1923 if (flags & MS_NOSUID) 1927 if (flags & MS_NOSUID)
1924 mnt_flags |= MNT_NOSUID; 1928 mnt_flags |= MNT_NOSUID;
@@ -1930,13 +1934,14 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
1930 mnt_flags |= MNT_NOATIME; 1934 mnt_flags |= MNT_NOATIME;
1931 if (flags & MS_NODIRATIME) 1935 if (flags & MS_NODIRATIME)
1932 mnt_flags |= MNT_NODIRATIME; 1936 mnt_flags |= MNT_NODIRATIME;
1933 if (flags & MS_RELATIME) 1937 if (flags & MS_STRICTATIME)
1934 mnt_flags |= MNT_RELATIME; 1938 mnt_flags &= ~(MNT_RELATIME | MNT_NOATIME);
1935 if (flags & MS_RDONLY) 1939 if (flags & MS_RDONLY)
1936 mnt_flags |= MNT_READONLY; 1940 mnt_flags |= MNT_READONLY;
1937 1941
1938 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE | 1942 flags &= ~(MS_NOSUID | MS_NOEXEC | MS_NODEV | MS_ACTIVE |
1939 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT); 1943 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
1944 MS_STRICTATIME);
1940 1945
1941 /* ... and get the mountpoint */ 1946 /* ... and get the mountpoint */
1942 retval = kern_path(dir_name, LOOKUP_FOLLOW, &path); 1947 retval = kern_path(dir_name, LOOKUP_FOLLOW, &path);
diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 6d720243f5f4..38e337d51ced 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -400,7 +400,7 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
400 pdev->devt = devt; 400 pdev->devt = devt;
401 401
402 /* delay uevent until 'holders' subdir is created */ 402 /* delay uevent until 'holders' subdir is created */
403 pdev->uevent_suppress = 1; 403 dev_set_uevent_suppress(pdev, 1);
404 err = device_add(pdev); 404 err = device_add(pdev);
405 if (err) 405 if (err)
406 goto out_put; 406 goto out_put;
@@ -410,7 +410,7 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
410 if (!p->holder_dir) 410 if (!p->holder_dir)
411 goto out_del; 411 goto out_del;
412 412
413 pdev->uevent_suppress = 0; 413 dev_set_uevent_suppress(pdev, 0);
414 if (flags & ADDPART_FLAG_WHOLEDISK) { 414 if (flags & ADDPART_FLAG_WHOLEDISK) {
415 err = device_create_file(pdev, &dev_attr_whole_disk); 415 err = device_create_file(pdev, &dev_attr_whole_disk);
416 if (err) 416 if (err)
@@ -422,7 +422,7 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
422 rcu_assign_pointer(ptbl->part[partno], p); 422 rcu_assign_pointer(ptbl->part[partno], p);
423 423
424 /* suppress uevent if the disk supresses it */ 424 /* suppress uevent if the disk supresses it */
425 if (!ddev->uevent_suppress) 425 if (!dev_get_uevent_suppress(pdev))
426 kobject_uevent(&pdev->kobj, KOBJ_ADD); 426 kobject_uevent(&pdev->kobj, KOBJ_ADD);
427 427
428 return p; 428 return p;
@@ -455,7 +455,7 @@ void register_disk(struct gendisk *disk)
455 dev_set_name(ddev, disk->disk_name); 455 dev_set_name(ddev, disk->disk_name);
456 456
457 /* delay uevents, until we scanned partition table */ 457 /* delay uevents, until we scanned partition table */
458 ddev->uevent_suppress = 1; 458 dev_set_uevent_suppress(ddev, 1);
459 459
460 if (device_add(ddev)) 460 if (device_add(ddev))
461 return; 461 return;
@@ -490,7 +490,7 @@ void register_disk(struct gendisk *disk)
490 490
491exit: 491exit:
492 /* announce disk after possible partitions are created */ 492 /* announce disk after possible partitions are created */
493 ddev->uevent_suppress = 0; 493 dev_set_uevent_suppress(ddev, 0);
494 kobject_uevent(&ddev->kobj, KOBJ_ADD); 494 kobject_uevent(&ddev->kobj, KOBJ_ADD);
495 495
496 /* announce possible partitions */ 496 /* announce possible partitions */
diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
index f2c478c3424e..07703d3ff4a1 100644
--- a/fs/sysfs/bin.c
+++ b/fs/sysfs/bin.c
@@ -21,15 +21,28 @@
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/mm.h>
24 25
25#include <asm/uaccess.h> 26#include <asm/uaccess.h>
26 27
27#include "sysfs.h" 28#include "sysfs.h"
28 29
30/*
31 * There's one bin_buffer for each open file.
32 *
33 * filp->private_data points to bin_buffer and
34 * sysfs_dirent->s_bin_attr.buffers points to a the bin_buffer s
35 * sysfs_dirent->s_bin_attr.buffers is protected by sysfs_bin_lock
36 */
37static DEFINE_MUTEX(sysfs_bin_lock);
38
29struct bin_buffer { 39struct bin_buffer {
30 struct mutex mutex; 40 struct mutex mutex;
31 void *buffer; 41 void *buffer;
32 int mmapped; 42 int mmapped;
43 struct vm_operations_struct *vm_ops;
44 struct file *file;
45 struct hlist_node list;
33}; 46};
34 47
35static int 48static int
@@ -168,6 +181,175 @@ out_free:
168 return count; 181 return count;
169} 182}
170 183
184static void bin_vma_open(struct vm_area_struct *vma)
185{
186 struct file *file = vma->vm_file;
187 struct bin_buffer *bb = file->private_data;
188 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
189
190 if (!bb->vm_ops || !bb->vm_ops->open)
191 return;
192
193 if (!sysfs_get_active_two(attr_sd))
194 return;
195
196 bb->vm_ops->open(vma);
197
198 sysfs_put_active_two(attr_sd);
199}
200
201static void bin_vma_close(struct vm_area_struct *vma)
202{
203 struct file *file = vma->vm_file;
204 struct bin_buffer *bb = file->private_data;
205 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
206
207 if (!bb->vm_ops || !bb->vm_ops->close)
208 return;
209
210 if (!sysfs_get_active_two(attr_sd))
211 return;
212
213 bb->vm_ops->close(vma);
214
215 sysfs_put_active_two(attr_sd);
216}
217
218static int bin_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
219{
220 struct file *file = vma->vm_file;
221 struct bin_buffer *bb = file->private_data;
222 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
223 int ret;
224
225 if (!bb->vm_ops || !bb->vm_ops->fault)
226 return VM_FAULT_SIGBUS;
227
228 if (!sysfs_get_active_two(attr_sd))
229 return VM_FAULT_SIGBUS;
230
231 ret = bb->vm_ops->fault(vma, vmf);
232
233 sysfs_put_active_two(attr_sd);
234 return ret;
235}
236
237static int bin_page_mkwrite(struct vm_area_struct *vma, struct page *page)
238{
239 struct file *file = vma->vm_file;
240 struct bin_buffer *bb = file->private_data;
241 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
242 int ret;
243
244 if (!bb->vm_ops)
245 return -EINVAL;
246
247 if (!bb->vm_ops->page_mkwrite)
248 return 0;
249
250 if (!sysfs_get_active_two(attr_sd))
251 return -EINVAL;
252
253 ret = bb->vm_ops->page_mkwrite(vma, page);
254
255 sysfs_put_active_two(attr_sd);
256 return ret;
257}
258
259static int bin_access(struct vm_area_struct *vma, unsigned long addr,
260 void *buf, int len, int write)
261{
262 struct file *file = vma->vm_file;
263 struct bin_buffer *bb = file->private_data;
264 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
265 int ret;
266
267 if (!bb->vm_ops || !bb->vm_ops->access)
268 return -EINVAL;
269
270 if (!sysfs_get_active_two(attr_sd))
271 return -EINVAL;
272
273 ret = bb->vm_ops->access(vma, addr, buf, len, write);
274
275 sysfs_put_active_two(attr_sd);
276 return ret;
277}
278
279#ifdef CONFIG_NUMA
280static int bin_set_policy(struct vm_area_struct *vma, struct mempolicy *new)
281{
282 struct file *file = vma->vm_file;
283 struct bin_buffer *bb = file->private_data;
284 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
285 int ret;
286
287 if (!bb->vm_ops || !bb->vm_ops->set_policy)
288 return 0;
289
290 if (!sysfs_get_active_two(attr_sd))
291 return -EINVAL;
292
293 ret = bb->vm_ops->set_policy(vma, new);
294
295 sysfs_put_active_two(attr_sd);
296 return ret;
297}
298
299static struct mempolicy *bin_get_policy(struct vm_area_struct *vma,
300 unsigned long addr)
301{
302 struct file *file = vma->vm_file;
303 struct bin_buffer *bb = file->private_data;
304 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
305 struct mempolicy *pol;
306
307 if (!bb->vm_ops || !bb->vm_ops->get_policy)
308 return vma->vm_policy;
309
310 if (!sysfs_get_active_two(attr_sd))
311 return vma->vm_policy;
312
313 pol = bb->vm_ops->get_policy(vma, addr);
314
315 sysfs_put_active_two(attr_sd);
316 return pol;
317}
318
319static int bin_migrate(struct vm_area_struct *vma, const nodemask_t *from,
320 const nodemask_t *to, unsigned long flags)
321{
322 struct file *file = vma->vm_file;
323 struct bin_buffer *bb = file->private_data;
324 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
325 int ret;
326
327 if (!bb->vm_ops || !bb->vm_ops->migrate)
328 return 0;
329
330 if (!sysfs_get_active_two(attr_sd))
331 return 0;
332
333 ret = bb->vm_ops->migrate(vma, from, to, flags);
334
335 sysfs_put_active_two(attr_sd);
336 return ret;
337}
338#endif
339
340static struct vm_operations_struct bin_vm_ops = {
341 .open = bin_vma_open,
342 .close = bin_vma_close,
343 .fault = bin_fault,
344 .page_mkwrite = bin_page_mkwrite,
345 .access = bin_access,
346#ifdef CONFIG_NUMA
347 .set_policy = bin_set_policy,
348 .get_policy = bin_get_policy,
349 .migrate = bin_migrate,
350#endif
351};
352
171static int mmap(struct file *file, struct vm_area_struct *vma) 353static int mmap(struct file *file, struct vm_area_struct *vma)
172{ 354{
173 struct bin_buffer *bb = file->private_data; 355 struct bin_buffer *bb = file->private_data;
@@ -179,18 +361,37 @@ static int mmap(struct file *file, struct vm_area_struct *vma)
179 mutex_lock(&bb->mutex); 361 mutex_lock(&bb->mutex);
180 362
181 /* need attr_sd for attr, its parent for kobj */ 363 /* need attr_sd for attr, its parent for kobj */
364 rc = -ENODEV;
182 if (!sysfs_get_active_two(attr_sd)) 365 if (!sysfs_get_active_two(attr_sd))
183 return -ENODEV; 366 goto out_unlock;
184 367
185 rc = -EINVAL; 368 rc = -EINVAL;
186 if (attr->mmap) 369 if (!attr->mmap)
187 rc = attr->mmap(kobj, attr, vma); 370 goto out_put;
371
372 rc = attr->mmap(kobj, attr, vma);
373 if (rc)
374 goto out_put;
188 375
189 if (rc == 0 && !bb->mmapped) 376 /*
190 bb->mmapped = 1; 377 * PowerPC's pci_mmap of legacy_mem uses shmem_zero_setup()
191 else 378 * to satisfy versions of X which crash if the mmap fails: that
192 sysfs_put_active_two(attr_sd); 379 * substitutes a new vm_file, and we don't then want bin_vm_ops.
380 */
381 if (vma->vm_file != file)
382 goto out_put;
193 383
384 rc = -EINVAL;
385 if (bb->mmapped && bb->vm_ops != vma->vm_ops)
386 goto out_put;
387
388 rc = 0;
389 bb->mmapped = 1;
390 bb->vm_ops = vma->vm_ops;
391 vma->vm_ops = &bin_vm_ops;
392out_put:
393 sysfs_put_active_two(attr_sd);
394out_unlock:
194 mutex_unlock(&bb->mutex); 395 mutex_unlock(&bb->mutex);
195 396
196 return rc; 397 return rc;
@@ -223,8 +424,13 @@ static int open(struct inode * inode, struct file * file)
223 goto err_out; 424 goto err_out;
224 425
225 mutex_init(&bb->mutex); 426 mutex_init(&bb->mutex);
427 bb->file = file;
226 file->private_data = bb; 428 file->private_data = bb;
227 429
430 mutex_lock(&sysfs_bin_lock);
431 hlist_add_head(&bb->list, &attr_sd->s_bin_attr.buffers);
432 mutex_unlock(&sysfs_bin_lock);
433
228 /* open succeeded, put active references */ 434 /* open succeeded, put active references */
229 sysfs_put_active_two(attr_sd); 435 sysfs_put_active_two(attr_sd);
230 return 0; 436 return 0;
@@ -237,11 +443,12 @@ static int open(struct inode * inode, struct file * file)
237 443
238static int release(struct inode * inode, struct file * file) 444static int release(struct inode * inode, struct file * file)
239{ 445{
240 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
241 struct bin_buffer *bb = file->private_data; 446 struct bin_buffer *bb = file->private_data;
242 447
243 if (bb->mmapped) 448 mutex_lock(&sysfs_bin_lock);
244 sysfs_put_active_two(attr_sd); 449 hlist_del(&bb->list);
450 mutex_unlock(&sysfs_bin_lock);
451
245 kfree(bb->buffer); 452 kfree(bb->buffer);
246 kfree(bb); 453 kfree(bb);
247 return 0; 454 return 0;
@@ -256,6 +463,26 @@ const struct file_operations bin_fops = {
256 .release = release, 463 .release = release,
257}; 464};
258 465
466
467void unmap_bin_file(struct sysfs_dirent *attr_sd)
468{
469 struct bin_buffer *bb;
470 struct hlist_node *tmp;
471
472 if (sysfs_type(attr_sd) != SYSFS_KOBJ_BIN_ATTR)
473 return;
474
475 mutex_lock(&sysfs_bin_lock);
476
477 hlist_for_each_entry(bb, tmp, &attr_sd->s_bin_attr.buffers, list) {
478 struct inode *inode = bb->file->f_path.dentry->d_inode;
479
480 unmap_mapping_range(inode->i_mapping, 0, 0, 1);
481 }
482
483 mutex_unlock(&sysfs_bin_lock);
484}
485
259/** 486/**
260 * sysfs_create_bin_file - create binary file for object. 487 * sysfs_create_bin_file - create binary file for object.
261 * @kobj: object. 488 * @kobj: object.
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 82d3b79d0e08..66aeb4fff0c3 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -434,6 +434,26 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
434} 434}
435 435
436/** 436/**
437 * sysfs_pathname - return full path to sysfs dirent
438 * @sd: sysfs_dirent whose path we want
439 * @path: caller allocated buffer
440 *
441 * Gives the name "/" to the sysfs_root entry; any path returned
442 * is relative to wherever sysfs is mounted.
443 *
444 * XXX: does no error checking on @path size
445 */
446static char *sysfs_pathname(struct sysfs_dirent *sd, char *path)
447{
448 if (sd->s_parent) {
449 sysfs_pathname(sd->s_parent, path);
450 strcat(path, "/");
451 }
452 strcat(path, sd->s_name);
453 return path;
454}
455
456/**
437 * sysfs_add_one - add sysfs_dirent to parent 457 * sysfs_add_one - add sysfs_dirent to parent
438 * @acxt: addrm context to use 458 * @acxt: addrm context to use
439 * @sd: sysfs_dirent to be added 459 * @sd: sysfs_dirent to be added
@@ -458,8 +478,16 @@ int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
458 int ret; 478 int ret;
459 479
460 ret = __sysfs_add_one(acxt, sd); 480 ret = __sysfs_add_one(acxt, sd);
461 WARN(ret == -EEXIST, KERN_WARNING "sysfs: duplicate filename '%s' " 481 if (ret == -EEXIST) {
462 "can not be created\n", sd->s_name); 482 char *path = kzalloc(PATH_MAX, GFP_KERNEL);
483 WARN(1, KERN_WARNING
484 "sysfs: cannot create duplicate filename '%s'\n",
485 (path == NULL) ? sd->s_name :
486 strcat(strcat(sysfs_pathname(acxt->parent_sd, path), "/"),
487 sd->s_name));
488 kfree(path);
489 }
490
463 return ret; 491 return ret;
464} 492}
465 493
@@ -581,6 +609,7 @@ void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt)
581 609
582 sysfs_drop_dentry(sd); 610 sysfs_drop_dentry(sd);
583 sysfs_deactivate(sd); 611 sysfs_deactivate(sd);
612 unmap_bin_file(sd);
584 sysfs_put(sd); 613 sysfs_put(sd);
585 } 614 }
586} 615}
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 1f4a3f877262..289c43a47263 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -659,13 +659,16 @@ void sysfs_remove_file_from_group(struct kobject *kobj,
659EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group); 659EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group);
660 660
661struct sysfs_schedule_callback_struct { 661struct sysfs_schedule_callback_struct {
662 struct kobject *kobj; 662 struct list_head workq_list;
663 struct kobject *kobj;
663 void (*func)(void *); 664 void (*func)(void *);
664 void *data; 665 void *data;
665 struct module *owner; 666 struct module *owner;
666 struct work_struct work; 667 struct work_struct work;
667}; 668};
668 669
670static DEFINE_MUTEX(sysfs_workq_mutex);
671static LIST_HEAD(sysfs_workq);
669static void sysfs_schedule_callback_work(struct work_struct *work) 672static void sysfs_schedule_callback_work(struct work_struct *work)
670{ 673{
671 struct sysfs_schedule_callback_struct *ss = container_of(work, 674 struct sysfs_schedule_callback_struct *ss = container_of(work,
@@ -674,6 +677,9 @@ static void sysfs_schedule_callback_work(struct work_struct *work)
674 (ss->func)(ss->data); 677 (ss->func)(ss->data);
675 kobject_put(ss->kobj); 678 kobject_put(ss->kobj);
676 module_put(ss->owner); 679 module_put(ss->owner);
680 mutex_lock(&sysfs_workq_mutex);
681 list_del(&ss->workq_list);
682 mutex_unlock(&sysfs_workq_mutex);
677 kfree(ss); 683 kfree(ss);
678} 684}
679 685
@@ -695,15 +701,25 @@ static void sysfs_schedule_callback_work(struct work_struct *work)
695 * until @func returns. 701 * until @func returns.
696 * 702 *
697 * Returns 0 if the request was submitted, -ENOMEM if storage could not 703 * Returns 0 if the request was submitted, -ENOMEM if storage could not
698 * be allocated, -ENODEV if a reference to @owner isn't available. 704 * be allocated, -ENODEV if a reference to @owner isn't available,
705 * -EAGAIN if a callback has already been scheduled for @kobj.
699 */ 706 */
700int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *), 707int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
701 void *data, struct module *owner) 708 void *data, struct module *owner)
702{ 709{
703 struct sysfs_schedule_callback_struct *ss; 710 struct sysfs_schedule_callback_struct *ss, *tmp;
704 711
705 if (!try_module_get(owner)) 712 if (!try_module_get(owner))
706 return -ENODEV; 713 return -ENODEV;
714
715 mutex_lock(&sysfs_workq_mutex);
716 list_for_each_entry_safe(ss, tmp, &sysfs_workq, workq_list)
717 if (ss->kobj == kobj) {
718 mutex_unlock(&sysfs_workq_mutex);
719 return -EAGAIN;
720 }
721 mutex_unlock(&sysfs_workq_mutex);
722
707 ss = kmalloc(sizeof(*ss), GFP_KERNEL); 723 ss = kmalloc(sizeof(*ss), GFP_KERNEL);
708 if (!ss) { 724 if (!ss) {
709 module_put(owner); 725 module_put(owner);
@@ -715,6 +731,10 @@ int sysfs_schedule_callback(struct kobject *kobj, void (*func)(void *),
715 ss->data = data; 731 ss->data = data;
716 ss->owner = owner; 732 ss->owner = owner;
717 INIT_WORK(&ss->work, sysfs_schedule_callback_work); 733 INIT_WORK(&ss->work, sysfs_schedule_callback_work);
734 INIT_LIST_HEAD(&ss->workq_list);
735 mutex_lock(&sysfs_workq_mutex);
736 list_add_tail(&ss->workq_list, &sysfs_workq);
737 mutex_unlock(&sysfs_workq_mutex);
718 schedule_work(&ss->work); 738 schedule_work(&ss->work);
719 return 0; 739 return 0;
720} 740}
diff --git a/fs/sysfs/inode.c b/fs/sysfs/inode.c
index dfa3d94cfc74..555f0ff988df 100644
--- a/fs/sysfs/inode.c
+++ b/fs/sysfs/inode.c
@@ -147,6 +147,7 @@ static void sysfs_init_inode(struct sysfs_dirent *sd, struct inode *inode)
147{ 147{
148 struct bin_attribute *bin_attr; 148 struct bin_attribute *bin_attr;
149 149
150 inode->i_private = sysfs_get(sd);
150 inode->i_mapping->a_ops = &sysfs_aops; 151 inode->i_mapping->a_ops = &sysfs_aops;
151 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info; 152 inode->i_mapping->backing_dev_info = &sysfs_backing_dev_info;
152 inode->i_op = &sysfs_inode_operations; 153 inode->i_op = &sysfs_inode_operations;
@@ -214,6 +215,22 @@ struct inode * sysfs_get_inode(struct sysfs_dirent *sd)
214 return inode; 215 return inode;
215} 216}
216 217
218/*
219 * The sysfs_dirent serves as both an inode and a directory entry for sysfs.
220 * To prevent the sysfs inode numbers from being freed prematurely we take a
221 * reference to sysfs_dirent from the sysfs inode. A
222 * super_operations.delete_inode() implementation is needed to drop that
223 * reference upon inode destruction.
224 */
225void sysfs_delete_inode(struct inode *inode)
226{
227 struct sysfs_dirent *sd = inode->i_private;
228
229 truncate_inode_pages(&inode->i_data, 0);
230 clear_inode(inode);
231 sysfs_put(sd);
232}
233
217int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name) 234int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name)
218{ 235{
219 struct sysfs_addrm_cxt acxt; 236 struct sysfs_addrm_cxt acxt;
diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c
index ab343e371d64..49749955ccaf 100644
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -17,11 +17,10 @@
17#include <linux/pagemap.h> 17#include <linux/pagemap.h>
18#include <linux/init.h> 18#include <linux/init.h>
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/magic.h>
20 21
21#include "sysfs.h" 22#include "sysfs.h"
22 23
23/* Random magic number */
24#define SYSFS_MAGIC 0x62656572
25 24
26static struct vfsmount *sysfs_mount; 25static struct vfsmount *sysfs_mount;
27struct super_block * sysfs_sb = NULL; 26struct super_block * sysfs_sb = NULL;
@@ -30,6 +29,7 @@ struct kmem_cache *sysfs_dir_cachep;
30static const struct super_operations sysfs_ops = { 29static const struct super_operations sysfs_ops = {
31 .statfs = simple_statfs, 30 .statfs = simple_statfs,
32 .drop_inode = generic_delete_inode, 31 .drop_inode = generic_delete_inode,
32 .delete_inode = sysfs_delete_inode,
33}; 33};
34 34
35struct sysfs_dirent sysfs_root = { 35struct sysfs_dirent sysfs_root = {
@@ -53,7 +53,9 @@ static int sysfs_fill_super(struct super_block *sb, void *data, int silent)
53 sysfs_sb = sb; 53 sysfs_sb = sb;
54 54
55 /* get root inode, initialize and unlock it */ 55 /* get root inode, initialize and unlock it */
56 mutex_lock(&sysfs_mutex);
56 inode = sysfs_get_inode(&sysfs_root); 57 inode = sysfs_get_inode(&sysfs_root);
58 mutex_unlock(&sysfs_mutex);
57 if (!inode) { 59 if (!inode) {
58 pr_debug("sysfs: could not get root inode\n"); 60 pr_debug("sysfs: could not get root inode\n");
59 return -ENOMEM; 61 return -ENOMEM;
diff --git a/fs/sysfs/sysfs.h b/fs/sysfs/sysfs.h
index 93c6d6b27c4d..3fa0d98481e2 100644
--- a/fs/sysfs/sysfs.h
+++ b/fs/sysfs/sysfs.h
@@ -28,6 +28,7 @@ struct sysfs_elem_attr {
28 28
29struct sysfs_elem_bin_attr { 29struct sysfs_elem_bin_attr {
30 struct bin_attribute *bin_attr; 30 struct bin_attribute *bin_attr;
31 struct hlist_head buffers;
31}; 32};
32 33
33/* 34/*
@@ -145,6 +146,7 @@ static inline void __sysfs_put(struct sysfs_dirent *sd)
145 * inode.c 146 * inode.c
146 */ 147 */
147struct inode *sysfs_get_inode(struct sysfs_dirent *sd); 148struct inode *sysfs_get_inode(struct sysfs_dirent *sd);
149void sysfs_delete_inode(struct inode *inode);
148int sysfs_setattr(struct dentry *dentry, struct iattr *iattr); 150int sysfs_setattr(struct dentry *dentry, struct iattr *iattr);
149int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name); 151int sysfs_hash_and_remove(struct sysfs_dirent *dir_sd, const char *name);
150int sysfs_inode_init(void); 152int sysfs_inode_init(void);
@@ -163,6 +165,7 @@ int sysfs_add_file_mode(struct sysfs_dirent *dir_sd,
163 * bin.c 165 * bin.c
164 */ 166 */
165extern const struct file_operations bin_fops; 167extern const struct file_operations bin_fops;
168void unmap_bin_file(struct sysfs_dirent *attr_sd);
166 169
167/* 170/*
168 * symlink.c 171 * symlink.c
diff --git a/include/asm-frv/ide.h b/include/asm-frv/ide.h
deleted file mode 100644
index 361076611855..000000000000
--- a/include/asm-frv/ide.h
+++ /dev/null
@@ -1,24 +0,0 @@
1/* ide.h: FRV IDE declarations
2 *
3 * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#ifndef _ASM_IDE_H
13#define _ASM_IDE_H
14
15#ifdef __KERNEL__
16
17#include <asm/setup.h>
18#include <asm/io.h>
19#include <asm/irq.h>
20
21#include <asm-generic/ide_iops.h>
22
23#endif /* __KERNEL__ */
24#endif /* _ASM_IDE_H */
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index c61fab1dd2f8..aca40b93bd28 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -80,6 +80,11 @@
80 VMLINUX_SYMBOL(__start___tracepoints) = .; \ 80 VMLINUX_SYMBOL(__start___tracepoints) = .; \
81 *(__tracepoints) \ 81 *(__tracepoints) \
82 VMLINUX_SYMBOL(__stop___tracepoints) = .; \ 82 VMLINUX_SYMBOL(__stop___tracepoints) = .; \
83 /* implement dynamic printk debug */ \
84 . = ALIGN(8); \
85 VMLINUX_SYMBOL(__start___verbose) = .; \
86 *(__verbose) \
87 VMLINUX_SYMBOL(__stop___verbose) = .; \
83 LIKELY_PROFILE() \ 88 LIKELY_PROFILE() \
84 BRANCH_PROFILE() 89 BRANCH_PROFILE()
85 90
@@ -309,15 +314,7 @@
309 CPU_DISCARD(init.data) \ 314 CPU_DISCARD(init.data) \
310 CPU_DISCARD(init.rodata) \ 315 CPU_DISCARD(init.rodata) \
311 MEM_DISCARD(init.data) \ 316 MEM_DISCARD(init.data) \
312 MEM_DISCARD(init.rodata) \ 317 MEM_DISCARD(init.rodata)
313 /* implement dynamic printk debug */ \
314 VMLINUX_SYMBOL(__start___verbose_strings) = .; \
315 *(__verbose_strings) \
316 VMLINUX_SYMBOL(__stop___verbose_strings) = .; \
317 . = ALIGN(8); \
318 VMLINUX_SYMBOL(__start___verbose) = .; \
319 *(__verbose) \
320 VMLINUX_SYMBOL(__stop___verbose) = .;
321 318
322#define INIT_TEXT \ 319#define INIT_TEXT \
323 *(.init.text) \ 320 *(.init.text) \
diff --git a/include/asm-mn10300/ide.h b/include/asm-mn10300/ide.h
deleted file mode 100644
index 6adcdd92e83d..000000000000
--- a/include/asm-mn10300/ide.h
+++ /dev/null
@@ -1,39 +0,0 @@
1/* MN10300 Arch-specific IDE code
2 *
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 * - Derived from include/asm-i386/ide.h
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public Licence
9 * as published by the Free Software Foundation; either version
10 * 2 of the Licence, or (at your option) any later version.
11 */
12
13#ifndef _ASM_IDE_H
14#define _ASM_IDE_H
15
16#ifdef __KERNEL__
17
18#include <asm/intctl-regs.h>
19
20#undef SUPPORT_SLOW_DATA_PORTS
21#define SUPPORT_SLOW_DATA_PORTS 0
22
23#undef SUPPORT_VLB_SYNC
24#define SUPPORT_VLB_SYNC 0
25
26/*
27 * some bits needed for parts of the IDE subsystem to compile
28 */
29#define __ide_mm_insw(port, addr, n) \
30 insw((unsigned long) (port), (addr), (n))
31#define __ide_mm_insl(port, addr, n) \
32 insl((unsigned long) (port), (addr), (n))
33#define __ide_mm_outsw(port, addr, n) \
34 outsw((unsigned long) (port), (addr), (n))
35#define __ide_mm_outsl(port, addr, n) \
36 outsl((unsigned long) (port), (addr), (n))
37
38#endif /* __KERNEL__ */
39#endif /* _ASM_IDE_H */
diff --git a/include/asm-mn10300/pci.h b/include/asm-mn10300/pci.h
index cd9cc5c89cea..0517b45313d8 100644
--- a/include/asm-mn10300/pci.h
+++ b/include/asm-mn10300/pci.h
@@ -121,4 +121,9 @@ pcibios_select_root(struct pci_dev *pdev, struct resource *res)
121 121
122#define pcibios_scan_all_fns(a, b) 0 122#define pcibios_scan_all_fns(a, b) 0
123 123
124static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
125{
126 return channel ? 15 : 14;
127}
128
124#endif /* _ASM_PCI_H */ 129#endif /* _ASM_PCI_H */
diff --git a/include/crypto/aes.h b/include/crypto/aes.h
index 656a4c66a568..7524ba3b6f3c 100644
--- a/include/crypto/aes.h
+++ b/include/crypto/aes.h
@@ -17,10 +17,14 @@
17#define AES_MAX_KEYLENGTH (15 * 16) 17#define AES_MAX_KEYLENGTH (15 * 16)
18#define AES_MAX_KEYLENGTH_U32 (AES_MAX_KEYLENGTH / sizeof(u32)) 18#define AES_MAX_KEYLENGTH_U32 (AES_MAX_KEYLENGTH / sizeof(u32))
19 19
20/*
21 * Please ensure that the first two fields are 16-byte aligned
22 * relative to the start of the structure, i.e., don't move them!
23 */
20struct crypto_aes_ctx { 24struct crypto_aes_ctx {
21 u32 key_length;
22 u32 key_enc[AES_MAX_KEYLENGTH_U32]; 25 u32 key_enc[AES_MAX_KEYLENGTH_U32];
23 u32 key_dec[AES_MAX_KEYLENGTH_U32]; 26 u32 key_dec[AES_MAX_KEYLENGTH_U32];
27 u32 key_length;
24}; 28};
25 29
26extern const u32 crypto_ft_tab[4][256]; 30extern const u32 crypto_ft_tab[4][256];
diff --git a/include/crypto/compress.h b/include/crypto/compress.h
new file mode 100644
index 000000000000..86163ef24219
--- /dev/null
+++ b/include/crypto/compress.h
@@ -0,0 +1,145 @@
1/*
2 * Compress: Compression algorithms under the cryptographic API.
3 *
4 * Copyright 2008 Sony Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.
17 * If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef _CRYPTO_COMPRESS_H
21#define _CRYPTO_COMPRESS_H
22
23#include <linux/crypto.h>
24
25
26struct comp_request {
27 const void *next_in; /* next input byte */
28 void *next_out; /* next output byte */
29 unsigned int avail_in; /* bytes available at next_in */
30 unsigned int avail_out; /* bytes available at next_out */
31};
32
33enum zlib_comp_params {
34 ZLIB_COMP_LEVEL = 1, /* e.g. Z_DEFAULT_COMPRESSION */
35 ZLIB_COMP_METHOD, /* e.g. Z_DEFLATED */
36 ZLIB_COMP_WINDOWBITS, /* e.g. MAX_WBITS */
37 ZLIB_COMP_MEMLEVEL, /* e.g. DEF_MEM_LEVEL */
38 ZLIB_COMP_STRATEGY, /* e.g. Z_DEFAULT_STRATEGY */
39 __ZLIB_COMP_MAX,
40};
41
42#define ZLIB_COMP_MAX (__ZLIB_COMP_MAX - 1)
43
44
45enum zlib_decomp_params {
46 ZLIB_DECOMP_WINDOWBITS = 1, /* e.g. DEF_WBITS */
47 __ZLIB_DECOMP_MAX,
48};
49
50#define ZLIB_DECOMP_MAX (__ZLIB_DECOMP_MAX - 1)
51
52
53struct crypto_pcomp {
54 struct crypto_tfm base;
55};
56
57struct pcomp_alg {
58 int (*compress_setup)(struct crypto_pcomp *tfm, void *params,
59 unsigned int len);
60 int (*compress_init)(struct crypto_pcomp *tfm);
61 int (*compress_update)(struct crypto_pcomp *tfm,
62 struct comp_request *req);
63 int (*compress_final)(struct crypto_pcomp *tfm,
64 struct comp_request *req);
65 int (*decompress_setup)(struct crypto_pcomp *tfm, void *params,
66 unsigned int len);
67 int (*decompress_init)(struct crypto_pcomp *tfm);
68 int (*decompress_update)(struct crypto_pcomp *tfm,
69 struct comp_request *req);
70 int (*decompress_final)(struct crypto_pcomp *tfm,
71 struct comp_request *req);
72
73 struct crypto_alg base;
74};
75
76extern struct crypto_pcomp *crypto_alloc_pcomp(const char *alg_name, u32 type,
77 u32 mask);
78
79static inline struct crypto_tfm *crypto_pcomp_tfm(struct crypto_pcomp *tfm)
80{
81 return &tfm->base;
82}
83
84static inline void crypto_free_pcomp(struct crypto_pcomp *tfm)
85{
86 crypto_destroy_tfm(tfm, crypto_pcomp_tfm(tfm));
87}
88
89static inline struct pcomp_alg *__crypto_pcomp_alg(struct crypto_alg *alg)
90{
91 return container_of(alg, struct pcomp_alg, base);
92}
93
94static inline struct pcomp_alg *crypto_pcomp_alg(struct crypto_pcomp *tfm)
95{
96 return __crypto_pcomp_alg(crypto_pcomp_tfm(tfm)->__crt_alg);
97}
98
99static inline int crypto_compress_setup(struct crypto_pcomp *tfm,
100 void *params, unsigned int len)
101{
102 return crypto_pcomp_alg(tfm)->compress_setup(tfm, params, len);
103}
104
105static inline int crypto_compress_init(struct crypto_pcomp *tfm)
106{
107 return crypto_pcomp_alg(tfm)->compress_init(tfm);
108}
109
110static inline int crypto_compress_update(struct crypto_pcomp *tfm,
111 struct comp_request *req)
112{
113 return crypto_pcomp_alg(tfm)->compress_update(tfm, req);
114}
115
116static inline int crypto_compress_final(struct crypto_pcomp *tfm,
117 struct comp_request *req)
118{
119 return crypto_pcomp_alg(tfm)->compress_final(tfm, req);
120}
121
122static inline int crypto_decompress_setup(struct crypto_pcomp *tfm,
123 void *params, unsigned int len)
124{
125 return crypto_pcomp_alg(tfm)->decompress_setup(tfm, params, len);
126}
127
128static inline int crypto_decompress_init(struct crypto_pcomp *tfm)
129{
130 return crypto_pcomp_alg(tfm)->decompress_init(tfm);
131}
132
133static inline int crypto_decompress_update(struct crypto_pcomp *tfm,
134 struct comp_request *req)
135{
136 return crypto_pcomp_alg(tfm)->decompress_update(tfm, req);
137}
138
139static inline int crypto_decompress_final(struct crypto_pcomp *tfm,
140 struct comp_request *req)
141{
142 return crypto_pcomp_alg(tfm)->decompress_final(tfm, req);
143}
144
145#endif /* _CRYPTO_COMPRESS_H */
diff --git a/include/crypto/cryptd.h b/include/crypto/cryptd.h
new file mode 100644
index 000000000000..55fa7bbdbc71
--- /dev/null
+++ b/include/crypto/cryptd.h
@@ -0,0 +1,27 @@
1/*
2 * Software async crypto daemon
3 */
4
5#ifndef _CRYPTO_CRYPT_H
6#define _CRYPTO_CRYPT_H
7
8#include <linux/crypto.h>
9#include <linux/kernel.h>
10
11struct cryptd_ablkcipher {
12 struct crypto_ablkcipher base;
13};
14
15static inline struct cryptd_ablkcipher *__cryptd_ablkcipher_cast(
16 struct crypto_ablkcipher *tfm)
17{
18 return (struct cryptd_ablkcipher *)tfm;
19}
20
21/* alg_name should be algorithm to be cryptd-ed */
22struct cryptd_ablkcipher *cryptd_alloc_ablkcipher(const char *alg_name,
23 u32 type, u32 mask);
24struct crypto_blkcipher *cryptd_ablkcipher_child(struct cryptd_ablkcipher *tfm);
25void cryptd_free_ablkcipher(struct cryptd_ablkcipher *tfm);
26
27#endif
diff --git a/include/crypto/crypto_wq.h b/include/crypto/crypto_wq.h
new file mode 100644
index 000000000000..a7d252daf91b
--- /dev/null
+++ b/include/crypto/crypto_wq.h
@@ -0,0 +1,7 @@
1#ifndef CRYPTO_WQ_H
2#define CRYPTO_WQ_H
3
4#include <linux/workqueue.h>
5
6extern struct workqueue_struct *kcrypto_wq;
7#endif
diff --git a/include/crypto/hash.h b/include/crypto/hash.h
index d797e119e3d5..d56bb71617c3 100644
--- a/include/crypto/hash.h
+++ b/include/crypto/hash.h
@@ -231,6 +231,11 @@ static inline unsigned int crypto_shash_alignmask(
231 return crypto_tfm_alg_alignmask(crypto_shash_tfm(tfm)); 231 return crypto_tfm_alg_alignmask(crypto_shash_tfm(tfm));
232} 232}
233 233
234static inline unsigned int crypto_shash_blocksize(struct crypto_shash *tfm)
235{
236 return crypto_tfm_alg_blocksize(crypto_shash_tfm(tfm));
237}
238
234static inline struct shash_alg *__crypto_shash_alg(struct crypto_alg *alg) 239static inline struct shash_alg *__crypto_shash_alg(struct crypto_alg *alg)
235{ 240{
236 return container_of(alg, struct shash_alg, base); 241 return container_of(alg, struct shash_alg, base);
diff --git a/include/crypto/internal/compress.h b/include/crypto/internal/compress.h
new file mode 100644
index 000000000000..178a888d1d93
--- /dev/null
+++ b/include/crypto/internal/compress.h
@@ -0,0 +1,28 @@
1/*
2 * Compress: Compression algorithms under the cryptographic API.
3 *
4 * Copyright 2008 Sony Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program.
17 * If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef _CRYPTO_INTERNAL_COMPRESS_H
21#define _CRYPTO_INTERNAL_COMPRESS_H
22
23#include <crypto/compress.h>
24
25extern int crypto_register_pcomp(struct pcomp_alg *alg);
26extern int crypto_unregister_pcomp(struct pcomp_alg *alg);
27
28#endif /* _CRYPTO_INTERNAL_COMPRESS_H */
diff --git a/include/linux/ata.h b/include/linux/ata.h
index 9a061accd8b8..6617c9f8f2ca 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -108,6 +108,8 @@ enum {
108 ATA_PIO5 = ATA_PIO4 | (1 << 5), 108 ATA_PIO5 = ATA_PIO4 | (1 << 5),
109 ATA_PIO6 = ATA_PIO5 | (1 << 6), 109 ATA_PIO6 = ATA_PIO5 | (1 << 6),
110 110
111 ATA_PIO4_ONLY = (1 << 4),
112
111 ATA_SWDMA0 = (1 << 0), 113 ATA_SWDMA0 = (1 << 0),
112 ATA_SWDMA1 = ATA_SWDMA0 | (1 << 1), 114 ATA_SWDMA1 = ATA_SWDMA0 | (1 << 1),
113 ATA_SWDMA2 = ATA_SWDMA1 | (1 << 2), 115 ATA_SWDMA2 = ATA_SWDMA1 | (1 << 2),
@@ -117,6 +119,8 @@ enum {
117 ATA_MWDMA0 = (1 << 0), 119 ATA_MWDMA0 = (1 << 0),
118 ATA_MWDMA1 = ATA_MWDMA0 | (1 << 1), 120 ATA_MWDMA1 = ATA_MWDMA0 | (1 << 1),
119 ATA_MWDMA2 = ATA_MWDMA1 | (1 << 2), 121 ATA_MWDMA2 = ATA_MWDMA1 | (1 << 2),
122 ATA_MWDMA3 = ATA_MWDMA2 | (1 << 3),
123 ATA_MWDMA4 = ATA_MWDMA3 | (1 << 4),
120 124
121 ATA_MWDMA12_ONLY = (1 << 1) | (1 << 2), 125 ATA_MWDMA12_ONLY = (1 << 1) | (1 << 2),
122 ATA_MWDMA2_ONLY = (1 << 2), 126 ATA_MWDMA2_ONLY = (1 << 2),
@@ -131,6 +135,8 @@ enum {
131 ATA_UDMA7 = ATA_UDMA6 | (1 << 7), 135 ATA_UDMA7 = ATA_UDMA6 | (1 << 7),
132 /* ATA_UDMA7 is just for completeness... doesn't exist (yet?). */ 136 /* ATA_UDMA7 is just for completeness... doesn't exist (yet?). */
133 137
138 ATA_UDMA24_ONLY = (1 << 2) | (1 << 4),
139
134 ATA_UDMA_MASK_40C = ATA_UDMA2, /* udma0-2 */ 140 ATA_UDMA_MASK_40C = ATA_UDMA2, /* udma0-2 */
135 141
136 /* DMA-related */ 142 /* DMA-related */
@@ -244,8 +250,6 @@ enum {
244 ATA_CMD_MEDIA_UNLOCK = 0xDF, 250 ATA_CMD_MEDIA_UNLOCK = 0xDF,
245 /* marked obsolete in the ATA/ATAPI-7 spec */ 251 /* marked obsolete in the ATA/ATAPI-7 spec */
246 ATA_CMD_RESTORE = 0x10, 252 ATA_CMD_RESTORE = 0x10,
247 /* EXABYTE specific */
248 ATA_EXABYTE_ENABLE_NEST = 0xF0,
249 253
250 /* READ_LOG_EXT pages */ 254 /* READ_LOG_EXT pages */
251 ATA_LOG_SATA_NCQ = 0x10, 255 ATA_LOG_SATA_NCQ = 0x10,
diff --git a/include/linux/console.h b/include/linux/console.h
index a67a90cf8268..dcca5339ceb3 100644
--- a/include/linux/console.h
+++ b/include/linux/console.h
@@ -137,8 +137,8 @@ extern void resume_console(void);
137int mda_console_init(void); 137int mda_console_init(void);
138void prom_con_init(void); 138void prom_con_init(void);
139 139
140void vcs_make_sysfs(struct tty_struct *tty); 140void vcs_make_sysfs(int index);
141void vcs_remove_sysfs(struct tty_struct *tty); 141void vcs_remove_sysfs(int index);
142 142
143/* Some debug stub to catch some of the obvious races in the VT code */ 143/* Some debug stub to catch some of the obvious races in the VT code */
144#if 1 144#if 1
diff --git a/include/linux/crypto.h b/include/linux/crypto.h
index 1f2e9020acc6..ec29fa268b94 100644
--- a/include/linux/crypto.h
+++ b/include/linux/crypto.h
@@ -40,6 +40,7 @@
40#define CRYPTO_ALG_TYPE_SHASH 0x00000009 40#define CRYPTO_ALG_TYPE_SHASH 0x00000009
41#define CRYPTO_ALG_TYPE_AHASH 0x0000000a 41#define CRYPTO_ALG_TYPE_AHASH 0x0000000a
42#define CRYPTO_ALG_TYPE_RNG 0x0000000c 42#define CRYPTO_ALG_TYPE_RNG 0x0000000c
43#define CRYPTO_ALG_TYPE_PCOMPRESS 0x0000000f
43 44
44#define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e 45#define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e
45#define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000c 46#define CRYPTO_ALG_TYPE_AHASH_MASK 0x0000000c
@@ -548,9 +549,6 @@ struct crypto_attr_u32 {
548 * Transform user interface. 549 * Transform user interface.
549 */ 550 */
550 551
551struct crypto_tfm *crypto_alloc_tfm(const char *alg_name,
552 const struct crypto_type *frontend,
553 u32 type, u32 mask);
554struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask); 552struct crypto_tfm *crypto_alloc_base(const char *alg_name, u32 type, u32 mask);
555void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm); 553void crypto_destroy_tfm(void *mem, struct crypto_tfm *tfm);
556 554
diff --git a/include/linux/device.h b/include/linux/device.h
index 47f343c7bdda..2918c0e8fdfd 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -28,6 +28,7 @@
28#define BUS_ID_SIZE 20 28#define BUS_ID_SIZE 20
29 29
30struct device; 30struct device;
31struct device_private;
31struct device_driver; 32struct device_driver;
32struct driver_private; 33struct driver_private;
33struct class; 34struct class;
@@ -147,7 +148,7 @@ extern void put_driver(struct device_driver *drv);
147extern struct device_driver *driver_find(const char *name, 148extern struct device_driver *driver_find(const char *name,
148 struct bus_type *bus); 149 struct bus_type *bus);
149extern int driver_probe_done(void); 150extern int driver_probe_done(void);
150extern int wait_for_device_probe(void); 151extern void wait_for_device_probe(void);
151 152
152 153
153/* sysfs interface for exporting driver attributes */ 154/* sysfs interface for exporting driver attributes */
@@ -367,15 +368,11 @@ struct device_dma_parameters {
367}; 368};
368 369
369struct device { 370struct device {
370 struct klist klist_children;
371 struct klist_node knode_parent; /* node in sibling list */
372 struct klist_node knode_driver;
373 struct klist_node knode_bus;
374 struct device *parent; 371 struct device *parent;
375 372
373 struct device_private *p;
374
376 struct kobject kobj; 375 struct kobject kobj;
377 char bus_id[BUS_ID_SIZE]; /* position on parent bus */
378 unsigned uevent_suppress:1;
379 const char *init_name; /* initial name of the device */ 376 const char *init_name; /* initial name of the device */
380 struct device_type *type; 377 struct device_type *type;
381 378
@@ -387,8 +384,13 @@ struct device {
387 struct device_driver *driver; /* which driver has allocated this 384 struct device_driver *driver; /* which driver has allocated this
388 device */ 385 device */
389 void *driver_data; /* data private to the driver */ 386 void *driver_data; /* data private to the driver */
390 void *platform_data; /* Platform specific data, device 387
391 core doesn't touch it */ 388 void *platform_data; /* We will remove platform_data
389 field if all platform devices
390 pass its platform specific data
391 from platform_device->platform_data,
392 other kind of devices should not
393 use platform_data. */
392 struct dev_pm_info power; 394 struct dev_pm_info power;
393 395
394#ifdef CONFIG_NUMA 396#ifdef CONFIG_NUMA
@@ -427,8 +429,7 @@ struct device {
427 429
428static inline const char *dev_name(const struct device *dev) 430static inline const char *dev_name(const struct device *dev)
429{ 431{
430 /* will be changed into kobject_name(&dev->kobj) in the near future */ 432 return kobject_name(&dev->kobj);
431 return dev->bus_id;
432} 433}
433 434
434extern int dev_set_name(struct device *dev, const char *name, ...) 435extern int dev_set_name(struct device *dev, const char *name, ...)
@@ -463,6 +464,16 @@ static inline void dev_set_drvdata(struct device *dev, void *data)
463 dev->driver_data = data; 464 dev->driver_data = data;
464} 465}
465 466
467static inline unsigned int dev_get_uevent_suppress(const struct device *dev)
468{
469 return dev->kobj.uevent_suppress;
470}
471
472static inline void dev_set_uevent_suppress(struct device *dev, int val)
473{
474 dev->kobj.uevent_suppress = val;
475}
476
466static inline int device_is_registered(struct device *dev) 477static inline int device_is_registered(struct device *dev)
467{ 478{
468 return dev->kobj.state_in_sysfs; 479 return dev->kobj.state_in_sysfs;
@@ -483,7 +494,8 @@ extern int device_for_each_child(struct device *dev, void *data,
483extern struct device *device_find_child(struct device *dev, void *data, 494extern struct device *device_find_child(struct device *dev, void *data,
484 int (*match)(struct device *dev, void *data)); 495 int (*match)(struct device *dev, void *data));
485extern int device_rename(struct device *dev, char *new_name); 496extern int device_rename(struct device *dev, char *new_name);
486extern int device_move(struct device *dev, struct device *new_parent); 497extern int device_move(struct device *dev, struct device *new_parent,
498 enum dpm_order dpm_order);
487 499
488/* 500/*
489 * Root device objects for grouping under /sys/devices 501 * Root device objects for grouping under /sys/devices
@@ -570,7 +582,7 @@ extern const char *dev_driver_string(const struct device *dev);
570#if defined(DEBUG) 582#if defined(DEBUG)
571#define dev_dbg(dev, format, arg...) \ 583#define dev_dbg(dev, format, arg...) \
572 dev_printk(KERN_DEBUG , dev , format , ## arg) 584 dev_printk(KERN_DEBUG , dev , format , ## arg)
573#elif defined(CONFIG_DYNAMIC_PRINTK_DEBUG) 585#elif defined(CONFIG_DYNAMIC_DEBUG)
574#define dev_dbg(dev, format, ...) do { \ 586#define dev_dbg(dev, format, ...) do { \
575 dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \ 587 dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
576 } while (0) 588 } while (0)
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
new file mode 100644
index 000000000000..baabf33be244
--- /dev/null
+++ b/include/linux/dynamic_debug.h
@@ -0,0 +1,88 @@
1#ifndef _DYNAMIC_DEBUG_H
2#define _DYNAMIC_DEBUG_H
3
4/* dynamic_printk_enabled, and dynamic_printk_enabled2 are bitmasks in which
5 * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They
6 * use independent hash functions, to reduce the chance of false positives.
7 */
8extern long long dynamic_debug_enabled;
9extern long long dynamic_debug_enabled2;
10
11/*
12 * An instance of this structure is created in a special
13 * ELF section at every dynamic debug callsite. At runtime,
14 * the special section is treated as an array of these.
15 */
16struct _ddebug {
17 /*
18 * These fields are used to drive the user interface
19 * for selecting and displaying debug callsites.
20 */
21 const char *modname;
22 const char *function;
23 const char *filename;
24 const char *format;
25 char primary_hash;
26 char secondary_hash;
27 unsigned int lineno:24;
28 /*
29 * The flags field controls the behaviour at the callsite.
30 * The bits here are changed dynamically when the user
31 * writes commands to <debugfs>/dynamic_debug/ddebug
32 */
33#define _DPRINTK_FLAGS_PRINT (1<<0) /* printk() a message using the format */
34#define _DPRINTK_FLAGS_DEFAULT 0
35 unsigned int flags:8;
36} __attribute__((aligned(8)));
37
38
39int ddebug_add_module(struct _ddebug *tab, unsigned int n,
40 const char *modname);
41
42#if defined(CONFIG_DYNAMIC_DEBUG)
43extern int ddebug_remove_module(char *mod_name);
44
45#define __dynamic_dbg_enabled(dd) ({ \
46 int __ret = 0; \
47 if (unlikely((dynamic_debug_enabled & (1LL << DEBUG_HASH)) && \
48 (dynamic_debug_enabled2 & (1LL << DEBUG_HASH2)))) \
49 if (unlikely(dd.flags)) \
50 __ret = 1; \
51 __ret; })
52
53#define dynamic_pr_debug(fmt, ...) do { \
54 static struct _ddebug descriptor \
55 __used \
56 __attribute__((section("__verbose"), aligned(8))) = \
57 { KBUILD_MODNAME, __func__, __FILE__, fmt, DEBUG_HASH, \
58 DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \
59 if (__dynamic_dbg_enabled(descriptor)) \
60 printk(KERN_DEBUG KBUILD_MODNAME ":" pr_fmt(fmt), \
61 ##__VA_ARGS__); \
62 } while (0)
63
64
65#define dynamic_dev_dbg(dev, fmt, ...) do { \
66 static struct _ddebug descriptor \
67 __used \
68 __attribute__((section("__verbose"), aligned(8))) = \
69 { KBUILD_MODNAME, __func__, __FILE__, fmt, DEBUG_HASH, \
70 DEBUG_HASH2, __LINE__, _DPRINTK_FLAGS_DEFAULT }; \
71 if (__dynamic_dbg_enabled(descriptor)) \
72 dev_printk(KERN_DEBUG, dev, \
73 KBUILD_MODNAME ": " pr_fmt(fmt),\
74 ##__VA_ARGS__); \
75 } while (0)
76
77#else
78
79static inline int ddebug_remove_module(char *mod)
80{
81 return 0;
82}
83
84#define dynamic_pr_debug(fmt, ...) do { } while (0)
85#define dynamic_dev_dbg(dev, format, ...) do { } while (0)
86#endif
87
88#endif
diff --git a/include/linux/dynamic_printk.h b/include/linux/dynamic_printk.h
deleted file mode 100644
index 2d528d009074..000000000000
--- a/include/linux/dynamic_printk.h
+++ /dev/null
@@ -1,93 +0,0 @@
1#ifndef _DYNAMIC_PRINTK_H
2#define _DYNAMIC_PRINTK_H
3
4#define DYNAMIC_DEBUG_HASH_BITS 6
5#define DEBUG_HASH_TABLE_SIZE (1 << DYNAMIC_DEBUG_HASH_BITS)
6
7#define TYPE_BOOLEAN 1
8
9#define DYNAMIC_ENABLED_ALL 0
10#define DYNAMIC_ENABLED_NONE 1
11#define DYNAMIC_ENABLED_SOME 2
12
13extern int dynamic_enabled;
14
15/* dynamic_printk_enabled, and dynamic_printk_enabled2 are bitmasks in which
16 * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They
17 * use independent hash functions, to reduce the chance of false positives.
18 */
19extern long long dynamic_printk_enabled;
20extern long long dynamic_printk_enabled2;
21
22struct mod_debug {
23 char *modname;
24 char *logical_modname;
25 char *flag_names;
26 int type;
27 int hash;
28 int hash2;
29} __attribute__((aligned(8)));
30
31int register_dynamic_debug_module(char *mod_name, int type, char *share_name,
32 char *flags, int hash, int hash2);
33
34#if defined(CONFIG_DYNAMIC_PRINTK_DEBUG)
35extern int unregister_dynamic_debug_module(char *mod_name);
36extern int __dynamic_dbg_enabled_helper(char *modname, int type,
37 int value, int hash);
38
39#define __dynamic_dbg_enabled(module, type, value, level, hash) ({ \
40 int __ret = 0; \
41 if (unlikely((dynamic_printk_enabled & (1LL << DEBUG_HASH)) && \
42 (dynamic_printk_enabled2 & (1LL << DEBUG_HASH2)))) \
43 __ret = __dynamic_dbg_enabled_helper(module, type, \
44 value, hash);\
45 __ret; })
46
47#define dynamic_pr_debug(fmt, ...) do { \
48 static char mod_name[] \
49 __attribute__((section("__verbose_strings"))) \
50 = KBUILD_MODNAME; \
51 static struct mod_debug descriptor \
52 __used \
53 __attribute__((section("__verbose"), aligned(8))) = \
54 { mod_name, mod_name, NULL, TYPE_BOOLEAN, DEBUG_HASH, DEBUG_HASH2 };\
55 if (__dynamic_dbg_enabled(KBUILD_MODNAME, TYPE_BOOLEAN, \
56 0, 0, DEBUG_HASH)) \
57 printk(KERN_DEBUG KBUILD_MODNAME ":" fmt, \
58 ##__VA_ARGS__); \
59 } while (0)
60
61#define dynamic_dev_dbg(dev, format, ...) do { \
62 static char mod_name[] \
63 __attribute__((section("__verbose_strings"))) \
64 = KBUILD_MODNAME; \
65 static struct mod_debug descriptor \
66 __used \
67 __attribute__((section("__verbose"), aligned(8))) = \
68 { mod_name, mod_name, NULL, TYPE_BOOLEAN, DEBUG_HASH, DEBUG_HASH2 };\
69 if (__dynamic_dbg_enabled(KBUILD_MODNAME, TYPE_BOOLEAN, \
70 0, 0, DEBUG_HASH)) \
71 dev_printk(KERN_DEBUG, dev, \
72 KBUILD_MODNAME ": " format, \
73 ##__VA_ARGS__); \
74 } while (0)
75
76#else
77
78static inline int unregister_dynamic_debug_module(const char *mod_name)
79{
80 return 0;
81}
82static inline int __dynamic_dbg_enabled_helper(char *modname, int type,
83 int value, int hash)
84{
85 return 0;
86}
87
88#define __dynamic_dbg_enabled(module, type, value, level, hash) ({ 0; })
89#define dynamic_pr_debug(fmt, ...) do { } while (0)
90#define dynamic_dev_dbg(dev, format, ...) do { } while (0)
91#endif
92
93#endif
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 92734c0012e6..5bc81c4a98c1 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -141,6 +141,7 @@ struct inodes_stat_t {
141#define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */ 141#define MS_RELATIME (1<<21) /* Update atime relative to mtime/ctime. */
142#define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */ 142#define MS_KERNMOUNT (1<<22) /* this is a kern_mount call */
143#define MS_I_VERSION (1<<23) /* Update inode I_version field */ 143#define MS_I_VERSION (1<<23) /* Update inode I_version field */
144#define MS_STRICTATIME (1<<24) /* Always perform atime updates */
144#define MS_ACTIVE (1<<30) 145#define MS_ACTIVE (1<<30)
145#define MS_NOUSER (1<<31) 146#define MS_NOUSER (1<<31)
146 147
diff --git a/include/linux/ide.h b/include/linux/ide.h
index 25087aead657..854eba8b2ba3 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -26,7 +26,7 @@
26#include <asm/io.h> 26#include <asm/io.h>
27#include <asm/mutex.h> 27#include <asm/mutex.h>
28 28
29#if defined(CONFIG_CRIS) || defined(CONFIG_FRV) 29#if defined(CONFIG_CRIS) || defined(CONFIG_FRV) || defined(CONFIG_MN10300)
30# define SUPPORT_VLB_SYNC 0 30# define SUPPORT_VLB_SYNC 0
31#else 31#else
32# define SUPPORT_VLB_SYNC 1 32# define SUPPORT_VLB_SYNC 1
@@ -193,24 +193,8 @@ static inline void ide_std_init_ports(hw_regs_t *hw,
193 hw->io_ports.ctl_addr = ctl_addr; 193 hw->io_ports.ctl_addr = ctl_addr;
194} 194}
195 195
196/* for IDE PCI controllers in legacy mode, temporary */ 196#if defined(CONFIG_ARM) || defined(CONFIG_M68K) || defined(CONFIG_MIPS) || \
197static inline int __ide_default_irq(unsigned long base) 197 defined(CONFIG_PARISC) || defined(CONFIG_PPC) || defined(CONFIG_SPARC)
198{
199 switch (base) {
200#ifdef CONFIG_IA64
201 case 0x1f0: return isa_irq_to_vector(14);
202 case 0x170: return isa_irq_to_vector(15);
203#else
204 case 0x1f0: return 14;
205 case 0x170: return 15;
206#endif
207 }
208 return 0;
209}
210
211#if defined(CONFIG_ARM) || defined(CONFIG_FRV) || defined(CONFIG_M68K) || \
212 defined(CONFIG_MIPS) || defined(CONFIG_MN10300) || defined(CONFIG_PARISC) \
213 || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || defined(CONFIG_SPARC64)
214#include <asm/ide.h> 198#include <asm/ide.h>
215#else 199#else
216#include <asm-generic/ide_iops.h> 200#include <asm-generic/ide_iops.h>
@@ -866,7 +850,7 @@ struct ide_host {
866 ide_hwif_t *ports[MAX_HOST_PORTS + 1]; 850 ide_hwif_t *ports[MAX_HOST_PORTS + 1];
867 unsigned int n_ports; 851 unsigned int n_ports;
868 struct device *dev[2]; 852 struct device *dev[2];
869 unsigned int (*init_chipset)(struct pci_dev *); 853 int (*init_chipset)(struct pci_dev *);
870 irq_handler_t irq_handler; 854 irq_handler_t irq_handler;
871 unsigned long host_flags; 855 unsigned long host_flags;
872 void *host_priv; 856 void *host_priv;
@@ -1146,11 +1130,14 @@ int generic_ide_ioctl(ide_drive_t *, struct block_device *, unsigned, unsigned l
1146extern int ide_vlb_clk; 1130extern int ide_vlb_clk;
1147extern int ide_pci_clk; 1131extern int ide_pci_clk;
1148 1132
1149extern int ide_end_request (ide_drive_t *drive, int uptodate, int nrsecs); 1133int ide_end_request(ide_drive_t *, int, int);
1150int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq, 1134int ide_end_dequeued_request(ide_drive_t *, struct request *, int, int);
1151 int uptodate, int nr_sectors); 1135void ide_kill_rq(ide_drive_t *, struct request *);
1152 1136
1153extern void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry); 1137void __ide_set_handler(ide_drive_t *, ide_handler_t *, unsigned int,
1138 ide_expiry_t *);
1139void ide_set_handler(ide_drive_t *, ide_handler_t *, unsigned int,
1140 ide_expiry_t *);
1154 1141
1155void ide_execute_command(ide_drive_t *, u8, ide_handler_t *, unsigned int, 1142void ide_execute_command(ide_drive_t *, u8, ide_handler_t *, unsigned int,
1156 ide_expiry_t *); 1143 ide_expiry_t *);
@@ -1169,13 +1156,14 @@ int ide_busy_sleep(ide_hwif_t *, unsigned long, int);
1169 1156
1170int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long); 1157int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long);
1171 1158
1159ide_startstop_t ide_do_park_unpark(ide_drive_t *, struct request *);
1160ide_startstop_t ide_do_devset(ide_drive_t *, struct request *);
1161
1172extern ide_startstop_t ide_do_reset (ide_drive_t *); 1162extern ide_startstop_t ide_do_reset (ide_drive_t *);
1173 1163
1174extern int ide_devset_execute(ide_drive_t *drive, 1164extern int ide_devset_execute(ide_drive_t *drive,
1175 const struct ide_devset *setting, int arg); 1165 const struct ide_devset *setting, int arg);
1176 1166
1177extern void ide_do_drive_cmd(ide_drive_t *, struct request *);
1178
1179extern void ide_end_drive_cmd(ide_drive_t *, u8, u8); 1167extern void ide_end_drive_cmd(ide_drive_t *, u8, u8);
1180 1168
1181void ide_tf_dump(const char *, struct ide_taskfile *); 1169void ide_tf_dump(const char *, struct ide_taskfile *);
@@ -1200,10 +1188,6 @@ void SELECT_MASK(ide_drive_t *, int);
1200u8 ide_read_error(ide_drive_t *); 1188u8 ide_read_error(ide_drive_t *);
1201void ide_read_bcount_and_ireason(ide_drive_t *, u16 *, u8 *); 1189void ide_read_bcount_and_ireason(ide_drive_t *, u16 *, u8 *);
1202 1190
1203extern int drive_is_ready(ide_drive_t *);
1204
1205void ide_pktcmd_tf_load(ide_drive_t *, u32, u16, u8);
1206
1207int ide_check_atapi_device(ide_drive_t *, const char *); 1191int ide_check_atapi_device(ide_drive_t *, const char *);
1208 1192
1209void ide_init_pc(struct ide_atapi_pc *); 1193void ide_init_pc(struct ide_atapi_pc *);
@@ -1251,6 +1235,8 @@ int ide_no_data_taskfile(ide_drive_t *, ide_task_t *);
1251 1235
1252int ide_taskfile_ioctl(ide_drive_t *, unsigned int, unsigned long); 1236int ide_taskfile_ioctl(ide_drive_t *, unsigned int, unsigned long);
1253 1237
1238int ide_dev_read_id(ide_drive_t *, u8, u16 *);
1239
1254extern int ide_driveid_update(ide_drive_t *); 1240extern int ide_driveid_update(ide_drive_t *);
1255extern int ide_config_drive_speed(ide_drive_t *, u8); 1241extern int ide_config_drive_speed(ide_drive_t *, u8);
1256extern u8 eighty_ninty_three (ide_drive_t *); 1242extern u8 eighty_ninty_three (ide_drive_t *);
@@ -1280,7 +1266,7 @@ static inline int ide_pci_is_in_compatibility_mode(struct pci_dev *dev)
1280 return 0; 1266 return 0;
1281} 1267}
1282 1268
1283void ide_pci_setup_ports(struct pci_dev *, const struct ide_port_info *, int, 1269void ide_pci_setup_ports(struct pci_dev *, const struct ide_port_info *,
1284 hw_regs_t *, hw_regs_t **); 1270 hw_regs_t *, hw_regs_t **);
1285void ide_setup_pci_noise(struct pci_dev *, const struct ide_port_info *); 1271void ide_setup_pci_noise(struct pci_dev *, const struct ide_port_info *);
1286 1272
@@ -1349,10 +1335,6 @@ enum {
1349 IDE_HFLAG_ERROR_STOPS_FIFO = (1 << 19), 1335 IDE_HFLAG_ERROR_STOPS_FIFO = (1 << 19),
1350 /* serialize ports */ 1336 /* serialize ports */
1351 IDE_HFLAG_SERIALIZE = (1 << 20), 1337 IDE_HFLAG_SERIALIZE = (1 << 20),
1352 /* use legacy IRQs */
1353 IDE_HFLAG_LEGACY_IRQS = (1 << 21),
1354 /* force use of legacy IRQs */
1355 IDE_HFLAG_FORCE_LEGACY_IRQS = (1 << 22),
1356 /* host is TRM290 */ 1338 /* host is TRM290 */
1357 IDE_HFLAG_TRM290 = (1 << 23), 1339 IDE_HFLAG_TRM290 = (1 << 23),
1358 /* use 32-bit I/O ops */ 1340 /* use 32-bit I/O ops */
@@ -1380,7 +1362,7 @@ enum {
1380 1362
1381struct ide_port_info { 1363struct ide_port_info {
1382 char *name; 1364 char *name;
1383 unsigned int (*init_chipset)(struct pci_dev *); 1365 int (*init_chipset)(struct pci_dev *);
1384 void (*init_iops)(ide_hwif_t *); 1366 void (*init_iops)(ide_hwif_t *);
1385 void (*init_hwif)(ide_hwif_t *); 1367 void (*init_hwif)(ide_hwif_t *);
1386 int (*init_dma)(ide_hwif_t *, 1368 int (*init_dma)(ide_hwif_t *,
@@ -1471,6 +1453,7 @@ static inline int config_drive_for_dma(ide_drive_t *drive) { return 0; }
1471 1453
1472void ide_dma_lost_irq(ide_drive_t *); 1454void ide_dma_lost_irq(ide_drive_t *);
1473void ide_dma_timeout(ide_drive_t *); 1455void ide_dma_timeout(ide_drive_t *);
1456ide_startstop_t ide_dma_timeout_retry(ide_drive_t *, int);
1474 1457
1475#else 1458#else
1476static inline int ide_id_dma_bug(ide_drive_t *drive) { return 0; } 1459static inline int ide_id_dma_bug(ide_drive_t *drive) { return 0; }
@@ -1482,21 +1465,24 @@ static inline void ide_dma_on(ide_drive_t *drive) { ; }
1482static inline void ide_dma_verbose(ide_drive_t *drive) { ; } 1465static inline void ide_dma_verbose(ide_drive_t *drive) { ; }
1483static inline int ide_set_dma(ide_drive_t *drive) { return 1; } 1466static inline int ide_set_dma(ide_drive_t *drive) { return 1; }
1484static inline void ide_check_dma_crc(ide_drive_t *drive) { ; } 1467static inline void ide_check_dma_crc(ide_drive_t *drive) { ; }
1468static inline ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error) { return ide_stopped; }
1485static inline void ide_release_dma_engine(ide_hwif_t *hwif) { ; } 1469static inline void ide_release_dma_engine(ide_hwif_t *hwif) { ; }
1486#endif /* CONFIG_BLK_DEV_IDEDMA */ 1470#endif /* CONFIG_BLK_DEV_IDEDMA */
1487 1471
1488#ifdef CONFIG_BLK_DEV_IDEACPI 1472#ifdef CONFIG_BLK_DEV_IDEACPI
1473int ide_acpi_init(void);
1489extern int ide_acpi_exec_tfs(ide_drive_t *drive); 1474extern int ide_acpi_exec_tfs(ide_drive_t *drive);
1490extern void ide_acpi_get_timing(ide_hwif_t *hwif); 1475extern void ide_acpi_get_timing(ide_hwif_t *hwif);
1491extern void ide_acpi_push_timing(ide_hwif_t *hwif); 1476extern void ide_acpi_push_timing(ide_hwif_t *hwif);
1492extern void ide_acpi_init(ide_hwif_t *hwif); 1477void ide_acpi_init_port(ide_hwif_t *);
1493void ide_acpi_port_init_devices(ide_hwif_t *); 1478void ide_acpi_port_init_devices(ide_hwif_t *);
1494extern void ide_acpi_set_state(ide_hwif_t *hwif, int on); 1479extern void ide_acpi_set_state(ide_hwif_t *hwif, int on);
1495#else 1480#else
1481static inline int ide_acpi_init(void) { return 0; }
1496static inline int ide_acpi_exec_tfs(ide_drive_t *drive) { return 0; } 1482static inline int ide_acpi_exec_tfs(ide_drive_t *drive) { return 0; }
1497static inline void ide_acpi_get_timing(ide_hwif_t *hwif) { ; } 1483static inline void ide_acpi_get_timing(ide_hwif_t *hwif) { ; }
1498static inline void ide_acpi_push_timing(ide_hwif_t *hwif) { ; } 1484static inline void ide_acpi_push_timing(ide_hwif_t *hwif) { ; }
1499static inline void ide_acpi_init(ide_hwif_t *hwif) { ; } 1485static inline void ide_acpi_init_port(ide_hwif_t *hwif) { ; }
1500static inline void ide_acpi_port_init_devices(ide_hwif_t *hwif) { ; } 1486static inline void ide_acpi_port_init_devices(ide_hwif_t *hwif) { ; }
1501static inline void ide_acpi_set_state(ide_hwif_t *hwif, int on) {} 1487static inline void ide_acpi_set_state(ide_hwif_t *hwif, int on) {}
1502#endif 1488#endif
@@ -1530,9 +1516,7 @@ static inline void ide_set_hwifdata (ide_hwif_t * hwif, void *data)
1530 hwif->hwif_data = data; 1516 hwif->hwif_data = data;
1531} 1517}
1532 1518
1533const char *ide_xfer_verbose(u8 mode);
1534extern void ide_toggle_bounce(ide_drive_t *drive, int on); 1519extern void ide_toggle_bounce(ide_drive_t *drive, int on);
1535extern int ide_set_xfer_rate(ide_drive_t *drive, u8 rate);
1536 1520
1537u64 ide_get_lba_addr(struct ide_taskfile *, int); 1521u64 ide_get_lba_addr(struct ide_taskfile *, int);
1538u8 ide_dump_status(ide_drive_t *, const char *, u8); 1522u8 ide_dump_status(ide_drive_t *, const char *, u8);
@@ -1571,14 +1555,18 @@ void ide_timing_merge(struct ide_timing *, struct ide_timing *,
1571 struct ide_timing *, unsigned int); 1555 struct ide_timing *, unsigned int);
1572int ide_timing_compute(ide_drive_t *, u8, struct ide_timing *, int, int); 1556int ide_timing_compute(ide_drive_t *, u8, struct ide_timing *, int, int);
1573 1557
1558#ifdef CONFIG_IDE_XFER_MODE
1574int ide_scan_pio_blacklist(char *); 1559int ide_scan_pio_blacklist(char *);
1575 1560const char *ide_xfer_verbose(u8);
1576u8 ide_get_best_pio_mode(ide_drive_t *, u8, u8); 1561u8 ide_get_best_pio_mode(ide_drive_t *, u8, u8);
1577
1578int ide_set_pio_mode(ide_drive_t *, u8); 1562int ide_set_pio_mode(ide_drive_t *, u8);
1579int ide_set_dma_mode(ide_drive_t *, u8); 1563int ide_set_dma_mode(ide_drive_t *, u8);
1580
1581void ide_set_pio(ide_drive_t *, u8); 1564void ide_set_pio(ide_drive_t *, u8);
1565int ide_set_xfer_rate(ide_drive_t *, u8);
1566#else
1567static inline void ide_set_pio(ide_drive_t *drive, u8 pio) { ; }
1568static inline int ide_set_xfer_rate(ide_drive_t *drive, u8 rate) { return -1; }
1569#endif
1582 1570
1583static inline void ide_set_max_pio(ide_drive_t *drive) 1571static inline void ide_set_max_pio(ide_drive_t *drive)
1584{ 1572{
@@ -1611,6 +1599,10 @@ static inline ide_drive_t *ide_get_pair_dev(ide_drive_t *drive)
1611#define ide_port_for_each_dev(i, dev, port) \ 1599#define ide_port_for_each_dev(i, dev, port) \
1612 for ((i) = 0; ((dev) = (port)->devices[i]) || (i) < MAX_DRIVES; (i)++) 1600 for ((i) = 0; ((dev) = (port)->devices[i]) || (i) < MAX_DRIVES; (i)++)
1613 1601
1602#define ide_port_for_each_present_dev(i, dev, port) \
1603 for ((i) = 0; ((dev) = (port)->devices[i]) || (i) < MAX_DRIVES; (i)++) \
1604 if ((dev)->dev_flags & IDE_DFLAG_PRESENT)
1605
1614#define ide_host_for_each_port(i, port, host) \ 1606#define ide_host_for_each_port(i, port, host) \
1615 for ((i) = 0; ((port) = (host)->ports[i]) || (i) < MAX_HOST_PORTS; (i)++) 1607 for ((i) = 0; ((port) = (host)->ports[i]) || (i) < MAX_HOST_PORTS; (i)++)
1616 1608
diff --git a/include/linux/input.h b/include/linux/input.h
index 1249a0c20a38..6b28048fc568 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -661,6 +661,7 @@ struct input_absinfo {
661#define SW_DOCK 0x05 /* set = plugged into dock */ 661#define SW_DOCK 0x05 /* set = plugged into dock */
662#define SW_LINEOUT_INSERT 0x06 /* set = inserted */ 662#define SW_LINEOUT_INSERT 0x06 /* set = inserted */
663#define SW_JACK_PHYSICAL_INSERT 0x07 /* set = mechanical switch set */ 663#define SW_JACK_PHYSICAL_INSERT 0x07 /* set = mechanical switch set */
664#define SW_VIDEOOUT_INSERT 0x08 /* set = inserted */
664#define SW_MAX 0x0f 665#define SW_MAX 0x0f
665#define SW_CNT (SW_MAX+1) 666#define SW_CNT (SW_MAX+1)
666 667
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 7fa371898e3e..914918abfdd1 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -16,7 +16,7 @@
16#include <linux/log2.h> 16#include <linux/log2.h>
17#include <linux/typecheck.h> 17#include <linux/typecheck.h>
18#include <linux/ratelimit.h> 18#include <linux/ratelimit.h>
19#include <linux/dynamic_printk.h> 19#include <linux/dynamic_debug.h>
20#include <asm/byteorder.h> 20#include <asm/byteorder.h>
21#include <asm/bug.h> 21#include <asm/bug.h>
22 22
@@ -358,9 +358,10 @@ static inline char *pack_hex_byte(char *buf, u8 byte)
358#if defined(DEBUG) 358#if defined(DEBUG)
359#define pr_debug(fmt, ...) \ 359#define pr_debug(fmt, ...) \
360 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) 360 printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
361#elif defined(CONFIG_DYNAMIC_PRINTK_DEBUG) 361#elif defined(CONFIG_DYNAMIC_DEBUG)
362/* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
362#define pr_debug(fmt, ...) do { \ 363#define pr_debug(fmt, ...) do { \
363 dynamic_pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \ 364 dynamic_pr_debug(fmt, ##__VA_ARGS__); \
364 } while (0) 365 } while (0)
365#else 366#else
366#define pr_debug(fmt, ...) \ 367#define pr_debug(fmt, ...) \
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index 5437ac0276e2..58ae8e00fcdd 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -68,10 +68,13 @@ struct kobject {
68 unsigned int state_in_sysfs:1; 68 unsigned int state_in_sysfs:1;
69 unsigned int state_add_uevent_sent:1; 69 unsigned int state_add_uevent_sent:1;
70 unsigned int state_remove_uevent_sent:1; 70 unsigned int state_remove_uevent_sent:1;
71 unsigned int uevent_suppress:1;
71}; 72};
72 73
73extern int kobject_set_name(struct kobject *kobj, const char *name, ...) 74extern int kobject_set_name(struct kobject *kobj, const char *name, ...)
74 __attribute__((format(printf, 2, 3))); 75 __attribute__((format(printf, 2, 3)));
76extern int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
77 va_list vargs);
75 78
76static inline const char *kobject_name(const struct kobject *kobj) 79static inline const char *kobject_name(const struct kobject *kobj)
77{ 80{
diff --git a/include/linux/libata.h b/include/linux/libata.h
index dc18b87ed722..76262d83656b 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -795,6 +795,7 @@ struct ata_port_operations {
795 ata_reset_fn_t pmp_hardreset; 795 ata_reset_fn_t pmp_hardreset;
796 ata_postreset_fn_t pmp_postreset; 796 ata_postreset_fn_t pmp_postreset;
797 void (*error_handler)(struct ata_port *ap); 797 void (*error_handler)(struct ata_port *ap);
798 void (*lost_interrupt)(struct ata_port *ap);
798 void (*post_internal_cmd)(struct ata_queued_cmd *qc); 799 void (*post_internal_cmd)(struct ata_queued_cmd *qc);
799 800
800 /* 801 /*
@@ -836,6 +837,8 @@ struct ata_port_operations {
836 void (*bmdma_start)(struct ata_queued_cmd *qc); 837 void (*bmdma_start)(struct ata_queued_cmd *qc);
837 void (*bmdma_stop)(struct ata_queued_cmd *qc); 838 void (*bmdma_stop)(struct ata_queued_cmd *qc);
838 u8 (*bmdma_status)(struct ata_port *ap); 839 u8 (*bmdma_status)(struct ata_port *ap);
840
841 void (*drain_fifo)(struct ata_queued_cmd *qc);
839#endif /* CONFIG_ATA_SFF */ 842#endif /* CONFIG_ATA_SFF */
840 843
841 ssize_t (*em_show)(struct ata_port *ap, char *buf); 844 ssize_t (*em_show)(struct ata_port *ap, char *buf);
@@ -1008,6 +1011,9 @@ extern int ata_cable_sata(struct ata_port *ap);
1008extern int ata_cable_ignore(struct ata_port *ap); 1011extern int ata_cable_ignore(struct ata_port *ap);
1009extern int ata_cable_unknown(struct ata_port *ap); 1012extern int ata_cable_unknown(struct ata_port *ap);
1010 1013
1014extern void ata_pio_queue_task(struct ata_port *ap, void *data,
1015 unsigned long delay);
1016
1011/* Timing helpers */ 1017/* Timing helpers */
1012extern unsigned int ata_pio_need_iordy(const struct ata_device *); 1018extern unsigned int ata_pio_need_iordy(const struct ata_device *);
1013extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode); 1019extern const struct ata_timing *ata_timing_find_mode(u8 xfer_mode);
@@ -1572,6 +1578,7 @@ extern bool ata_sff_qc_fill_rtf(struct ata_queued_cmd *qc);
1572extern unsigned int ata_sff_host_intr(struct ata_port *ap, 1578extern unsigned int ata_sff_host_intr(struct ata_port *ap,
1573 struct ata_queued_cmd *qc); 1579 struct ata_queued_cmd *qc);
1574extern irqreturn_t ata_sff_interrupt(int irq, void *dev_instance); 1580extern irqreturn_t ata_sff_interrupt(int irq, void *dev_instance);
1581extern void ata_sff_lost_interrupt(struct ata_port *ap);
1575extern void ata_sff_freeze(struct ata_port *ap); 1582extern void ata_sff_freeze(struct ata_port *ap);
1576extern void ata_sff_thaw(struct ata_port *ap); 1583extern void ata_sff_thaw(struct ata_port *ap);
1577extern int ata_sff_prereset(struct ata_link *link, unsigned long deadline); 1584extern int ata_sff_prereset(struct ata_link *link, unsigned long deadline);
@@ -1584,6 +1591,7 @@ extern int ata_sff_softreset(struct ata_link *link, unsigned int *classes,
1584extern int sata_sff_hardreset(struct ata_link *link, unsigned int *class, 1591extern int sata_sff_hardreset(struct ata_link *link, unsigned int *class,
1585 unsigned long deadline); 1592 unsigned long deadline);
1586extern void ata_sff_postreset(struct ata_link *link, unsigned int *classes); 1593extern void ata_sff_postreset(struct ata_link *link, unsigned int *classes);
1594extern void ata_sff_drain_fifo(struct ata_queued_cmd *qc);
1587extern void ata_sff_error_handler(struct ata_port *ap); 1595extern void ata_sff_error_handler(struct ata_port *ap);
1588extern void ata_sff_post_internal_cmd(struct ata_queued_cmd *qc); 1596extern void ata_sff_post_internal_cmd(struct ata_queued_cmd *qc);
1589extern int ata_sff_port_start(struct ata_port *ap); 1597extern int ata_sff_port_start(struct ata_port *ap);
diff --git a/include/linux/lm_interface.h b/include/linux/lm_interface.h
deleted file mode 100644
index 2ed8fa1b762b..000000000000
--- a/include/linux/lm_interface.h
+++ /dev/null
@@ -1,277 +0,0 @@
1/*
2 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
3 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
4 *
5 * This copyrighted material is made available to anyone wishing to use,
6 * modify, copy, or redistribute it subject to the terms and conditions
7 * of the GNU General Public License version 2.
8 */
9
10#ifndef __LM_INTERFACE_DOT_H__
11#define __LM_INTERFACE_DOT_H__
12
13
14typedef void (*lm_callback_t) (void *ptr, unsigned int type, void *data);
15
16/*
17 * lm_mount() flags
18 *
19 * LM_MFLAG_SPECTATOR
20 * GFS is asking to join the filesystem's lockspace, but it doesn't want to
21 * modify the filesystem. The lock module shouldn't assign a journal to the FS
22 * mount. It shouldn't send recovery callbacks to the FS mount. If the node
23 * dies or withdraws, all locks can be wiped immediately.
24 *
25 * LM_MFLAG_CONV_NODROP
26 * Do not allow the dlm to internally resolve conversion deadlocks by demoting
27 * the lock to unlocked and then reacquiring it in the requested mode. Instead,
28 * it should cancel the request and return LM_OUT_CONV_DEADLK.
29 */
30
31#define LM_MFLAG_SPECTATOR 0x00000001
32#define LM_MFLAG_CONV_NODROP 0x00000002
33
34/*
35 * lm_lockstruct flags
36 *
37 * LM_LSFLAG_LOCAL
38 * The lock_nolock module returns LM_LSFLAG_LOCAL to GFS, indicating that GFS
39 * can make single-node optimizations.
40 */
41
42#define LM_LSFLAG_LOCAL 0x00000001
43
44/*
45 * lm_lockname types
46 */
47
48#define LM_TYPE_RESERVED 0x00
49#define LM_TYPE_NONDISK 0x01
50#define LM_TYPE_INODE 0x02
51#define LM_TYPE_RGRP 0x03
52#define LM_TYPE_META 0x04
53#define LM_TYPE_IOPEN 0x05
54#define LM_TYPE_FLOCK 0x06
55#define LM_TYPE_PLOCK 0x07
56#define LM_TYPE_QUOTA 0x08
57#define LM_TYPE_JOURNAL 0x09
58
59/*
60 * lm_lock() states
61 *
62 * SHARED is compatible with SHARED, not with DEFERRED or EX.
63 * DEFERRED is compatible with DEFERRED, not with SHARED or EX.
64 */
65
66#define LM_ST_UNLOCKED 0
67#define LM_ST_EXCLUSIVE 1
68#define LM_ST_DEFERRED 2
69#define LM_ST_SHARED 3
70
71/*
72 * lm_lock() flags
73 *
74 * LM_FLAG_TRY
75 * Don't wait to acquire the lock if it can't be granted immediately.
76 *
77 * LM_FLAG_TRY_1CB
78 * Send one blocking callback if TRY is set and the lock is not granted.
79 *
80 * LM_FLAG_NOEXP
81 * GFS sets this flag on lock requests it makes while doing journal recovery.
82 * These special requests should not be blocked due to the recovery like
83 * ordinary locks would be.
84 *
85 * LM_FLAG_ANY
86 * A SHARED request may also be granted in DEFERRED, or a DEFERRED request may
87 * also be granted in SHARED. The preferred state is whichever is compatible
88 * with other granted locks, or the specified state if no other locks exist.
89 *
90 * LM_FLAG_PRIORITY
91 * Override fairness considerations. Suppose a lock is held in a shared state
92 * and there is a pending request for the deferred state. A shared lock
93 * request with the priority flag would be allowed to bypass the deferred
94 * request and directly join the other shared lock. A shared lock request
95 * without the priority flag might be forced to wait until the deferred
96 * requested had acquired and released the lock.
97 */
98
99#define LM_FLAG_TRY 0x00000001
100#define LM_FLAG_TRY_1CB 0x00000002
101#define LM_FLAG_NOEXP 0x00000004
102#define LM_FLAG_ANY 0x00000008
103#define LM_FLAG_PRIORITY 0x00000010
104
105/*
106 * lm_lock() and lm_async_cb return flags
107 *
108 * LM_OUT_ST_MASK
109 * Masks the lower two bits of lock state in the returned value.
110 *
111 * LM_OUT_CACHEABLE
112 * The lock hasn't been released so GFS can continue to cache data for it.
113 *
114 * LM_OUT_CANCELED
115 * The lock request was canceled.
116 *
117 * LM_OUT_ASYNC
118 * The result of the request will be returned in an LM_CB_ASYNC callback.
119 *
120 * LM_OUT_CONV_DEADLK
121 * The lock request was canceled do to a conversion deadlock.
122 */
123
124#define LM_OUT_ST_MASK 0x00000003
125#define LM_OUT_CANCELED 0x00000008
126#define LM_OUT_ASYNC 0x00000080
127#define LM_OUT_ERROR 0x00000100
128
129/*
130 * lm_callback_t types
131 *
132 * LM_CB_NEED_E LM_CB_NEED_D LM_CB_NEED_S
133 * Blocking callback, a remote node is requesting the given lock in
134 * EXCLUSIVE, DEFERRED, or SHARED.
135 *
136 * LM_CB_NEED_RECOVERY
137 * The given journal needs to be recovered.
138 *
139 * LM_CB_ASYNC
140 * The given lock has been granted.
141 */
142
143#define LM_CB_NEED_E 257
144#define LM_CB_NEED_D 258
145#define LM_CB_NEED_S 259
146#define LM_CB_NEED_RECOVERY 260
147#define LM_CB_ASYNC 262
148
149/*
150 * lm_recovery_done() messages
151 */
152
153#define LM_RD_GAVEUP 308
154#define LM_RD_SUCCESS 309
155
156
157struct lm_lockname {
158 u64 ln_number;
159 unsigned int ln_type;
160};
161
162#define lm_name_equal(name1, name2) \
163 (((name1)->ln_number == (name2)->ln_number) && \
164 ((name1)->ln_type == (name2)->ln_type)) \
165
166struct lm_async_cb {
167 struct lm_lockname lc_name;
168 int lc_ret;
169};
170
171struct lm_lockstruct;
172
173struct lm_lockops {
174 const char *lm_proto_name;
175
176 /*
177 * Mount/Unmount
178 */
179
180 int (*lm_mount) (char *table_name, char *host_data,
181 lm_callback_t cb, void *cb_data,
182 unsigned int min_lvb_size, int flags,
183 struct lm_lockstruct *lockstruct,
184 struct kobject *fskobj);
185
186 void (*lm_others_may_mount) (void *lockspace);
187
188 void (*lm_unmount) (void *lockspace);
189
190 void (*lm_withdraw) (void *lockspace);
191
192 /*
193 * Lock oriented operations
194 */
195
196 int (*lm_get_lock) (void *lockspace, struct lm_lockname *name, void **lockp);
197
198 void (*lm_put_lock) (void *lock);
199
200 unsigned int (*lm_lock) (void *lock, unsigned int cur_state,
201 unsigned int req_state, unsigned int flags);
202
203 unsigned int (*lm_unlock) (void *lock, unsigned int cur_state);
204
205 void (*lm_cancel) (void *lock);
206
207 int (*lm_hold_lvb) (void *lock, char **lvbp);
208 void (*lm_unhold_lvb) (void *lock, char *lvb);
209
210 /*
211 * Posix Lock oriented operations
212 */
213
214 int (*lm_plock_get) (void *lockspace, struct lm_lockname *name,
215 struct file *file, struct file_lock *fl);
216
217 int (*lm_plock) (void *lockspace, struct lm_lockname *name,
218 struct file *file, int cmd, struct file_lock *fl);
219
220 int (*lm_punlock) (void *lockspace, struct lm_lockname *name,
221 struct file *file, struct file_lock *fl);
222
223 /*
224 * Client oriented operations
225 */
226
227 void (*lm_recovery_done) (void *lockspace, unsigned int jid,
228 unsigned int message);
229
230 struct module *lm_owner;
231};
232
233/*
234 * lm_mount() return values
235 *
236 * ls_jid - the journal ID this node should use
237 * ls_first - this node is the first to mount the file system
238 * ls_lvb_size - size in bytes of lock value blocks
239 * ls_lockspace - lock module's context for this file system
240 * ls_ops - lock module's functions
241 * ls_flags - lock module features
242 */
243
244struct lm_lockstruct {
245 unsigned int ls_jid;
246 unsigned int ls_first;
247 unsigned int ls_lvb_size;
248 void *ls_lockspace;
249 const struct lm_lockops *ls_ops;
250 int ls_flags;
251};
252
253/*
254 * Lock module bottom interface. A lock module makes itself available to GFS
255 * with these functions.
256 */
257
258int gfs2_register_lockproto(const struct lm_lockops *proto);
259void gfs2_unregister_lockproto(const struct lm_lockops *proto);
260
261/*
262 * Lock module top interface. GFS calls these functions when mounting or
263 * unmounting a file system.
264 */
265
266int gfs2_mount_lockproto(char *proto_name, char *table_name, char *host_data,
267 lm_callback_t cb, void *cb_data,
268 unsigned int min_lvb_size, int flags,
269 struct lm_lockstruct *lockstruct,
270 struct kobject *fskobj);
271
272void gfs2_unmount_lockproto(struct lm_lockstruct *lockstruct);
273
274void gfs2_withdraw_lockproto(struct lm_lockstruct *lockstruct);
275
276#endif /* __LM_INTERFACE_DOT_H__ */
277
diff --git a/include/linux/maple.h b/include/linux/maple.h
index c23d3f51ba40..d9a51b9b3300 100644
--- a/include/linux/maple.h
+++ b/include/linux/maple.h
@@ -8,33 +8,49 @@ extern struct bus_type maple_bus_type;
8 8
9/* Maple Bus command and response codes */ 9/* Maple Bus command and response codes */
10enum maple_code { 10enum maple_code {
11 MAPLE_RESPONSE_FILEERR = -5, 11 MAPLE_RESPONSE_FILEERR = -5,
12 MAPLE_RESPONSE_AGAIN = -4, /* request should be retransmitted */ 12 MAPLE_RESPONSE_AGAIN, /* retransmit */
13 MAPLE_RESPONSE_BADCMD = -3, 13 MAPLE_RESPONSE_BADCMD,
14 MAPLE_RESPONSE_BADFUNC = -2, 14 MAPLE_RESPONSE_BADFUNC,
15 MAPLE_RESPONSE_NONE = -1, /* unit didn't respond at all */ 15 MAPLE_RESPONSE_NONE, /* unit didn't respond*/
16 MAPLE_COMMAND_DEVINFO = 1, 16 MAPLE_COMMAND_DEVINFO = 1,
17 MAPLE_COMMAND_ALLINFO = 2, 17 MAPLE_COMMAND_ALLINFO,
18 MAPLE_COMMAND_RESET = 3, 18 MAPLE_COMMAND_RESET,
19 MAPLE_COMMAND_KILL = 4, 19 MAPLE_COMMAND_KILL,
20 MAPLE_RESPONSE_DEVINFO = 5, 20 MAPLE_RESPONSE_DEVINFO,
21 MAPLE_RESPONSE_ALLINFO = 6, 21 MAPLE_RESPONSE_ALLINFO,
22 MAPLE_RESPONSE_OK = 7, 22 MAPLE_RESPONSE_OK,
23 MAPLE_RESPONSE_DATATRF = 8, 23 MAPLE_RESPONSE_DATATRF,
24 MAPLE_COMMAND_GETCOND = 9, 24 MAPLE_COMMAND_GETCOND,
25 MAPLE_COMMAND_GETMINFO = 10, 25 MAPLE_COMMAND_GETMINFO,
26 MAPLE_COMMAND_BREAD = 11, 26 MAPLE_COMMAND_BREAD,
27 MAPLE_COMMAND_BWRITE = 12, 27 MAPLE_COMMAND_BWRITE,
28 MAPLE_COMMAND_SETCOND = 14 28 MAPLE_COMMAND_BSYNC,
29 MAPLE_COMMAND_SETCOND,
30 MAPLE_COMMAND_MICCONTROL
31};
32
33enum maple_file_errors {
34 MAPLE_FILEERR_INVALID_PARTITION = 0x01000000,
35 MAPLE_FILEERR_PHASE_ERROR = 0x02000000,
36 MAPLE_FILEERR_INVALID_BLOCK = 0x04000000,
37 MAPLE_FILEERR_WRITE_ERROR = 0x08000000,
38 MAPLE_FILEERR_INVALID_WRITE_LENGTH = 0x10000000,
39 MAPLE_FILEERR_BAD_CRC = 0x20000000
40};
41
42struct maple_buffer {
43 char bufx[0x400];
44 void *buf;
29}; 45};
30 46
31struct mapleq { 47struct mapleq {
32 struct list_head list; 48 struct list_head list;
33 struct maple_device *dev; 49 struct maple_device *dev;
34 void *sendbuf, *recvbuf, *recvbufdcsp; 50 struct maple_buffer *recvbuf;
51 void *sendbuf, *recvbuf_p2;
35 unsigned char length; 52 unsigned char length;
36 enum maple_code command; 53 enum maple_code command;
37 struct mutex mutex;
38}; 54};
39 55
40struct maple_devinfo { 56struct maple_devinfo {
@@ -52,11 +68,15 @@ struct maple_device {
52 struct maple_driver *driver; 68 struct maple_driver *driver;
53 struct mapleq *mq; 69 struct mapleq *mq;
54 void (*callback) (struct mapleq * mq); 70 void (*callback) (struct mapleq * mq);
71 void (*fileerr_handler)(struct maple_device *mdev, void *recvbuf);
72 int (*can_unload)(struct maple_device *mdev);
55 unsigned long when, interval, function; 73 unsigned long when, interval, function;
56 struct maple_devinfo devinfo; 74 struct maple_devinfo devinfo;
57 unsigned char port, unit; 75 unsigned char port, unit;
58 char product_name[32]; 76 char product_name[32];
59 char product_licence[64]; 77 char product_licence[64];
78 atomic_t busy;
79 wait_queue_head_t maple_wait;
60 struct device dev; 80 struct device dev;
61}; 81};
62 82
@@ -72,7 +92,7 @@ void maple_getcond_callback(struct maple_device *dev,
72int maple_driver_register(struct maple_driver *); 92int maple_driver_register(struct maple_driver *);
73void maple_driver_unregister(struct maple_driver *); 93void maple_driver_unregister(struct maple_driver *);
74 94
75int maple_add_packet_sleeps(struct maple_device *mdev, u32 function, 95int maple_add_packet(struct maple_device *mdev, u32 function,
76 u32 command, u32 length, void *data); 96 u32 command, u32 length, void *data);
77void maple_clear_dev(struct maple_device *mdev); 97void maple_clear_dev(struct maple_device *mdev);
78 98
diff --git a/include/linux/mfd/wm8350/audio.h b/include/linux/mfd/wm8350/audio.h
index af95a1d2f3a1..d899dc0223ba 100644
--- a/include/linux/mfd/wm8350/audio.h
+++ b/include/linux/mfd/wm8350/audio.h
@@ -490,6 +490,7 @@
490/* 490/*
491 * R231 (0xE7) - Jack Status 491 * R231 (0xE7) - Jack Status
492 */ 492 */
493#define WM8350_JACK_L_LVL 0x0800
493#define WM8350_JACK_R_LVL 0x0400 494#define WM8350_JACK_R_LVL 0x0400
494 495
495/* 496/*
diff --git a/include/linux/mfd/wm8400-audio.h b/include/linux/mfd/wm8400-audio.h
index b6640e018046..e06ed3eb1d0a 100644
--- a/include/linux/mfd/wm8400-audio.h
+++ b/include/linux/mfd/wm8400-audio.h
@@ -1181,6 +1181,7 @@
1181#define WM8400_FLL_OUTDIV_SHIFT 0 /* FLL_OUTDIV - [2:0] */ 1181#define WM8400_FLL_OUTDIV_SHIFT 0 /* FLL_OUTDIV - [2:0] */
1182#define WM8400_FLL_OUTDIV_WIDTH 3 /* FLL_OUTDIV - [2:0] */ 1182#define WM8400_FLL_OUTDIV_WIDTH 3 /* FLL_OUTDIV - [2:0] */
1183 1183
1184struct wm8400;
1184void wm8400_reset_codec_reg_cache(struct wm8400 *wm8400); 1185void wm8400_reset_codec_reg_cache(struct wm8400 *wm8400);
1185 1186
1186#endif 1187#endif
diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
index fde86671f48f..1bf5900ffe43 100644
--- a/include/linux/mod_devicetable.h
+++ b/include/linux/mod_devicetable.h
@@ -454,4 +454,13 @@ struct dmi_system_id {
454 454
455#define DMI_MATCH(a, b) { a, b } 455#define DMI_MATCH(a, b) { a, b }
456 456
457#define PLATFORM_NAME_SIZE 20
458#define PLATFORM_MODULE_PREFIX "platform:"
459
460struct platform_device_id {
461 char name[PLATFORM_NAME_SIZE];
462 kernel_ulong_t driver_data
463 __attribute__((aligned(sizeof(kernel_ulong_t))));
464};
465
457#endif /* LINUX_MOD_DEVICETABLE_H */ 466#endif /* LINUX_MOD_DEVICETABLE_H */
diff --git a/include/linux/mount.h b/include/linux/mount.h
index cab2a85e2ee8..51f55f903aff 100644
--- a/include/linux/mount.h
+++ b/include/linux/mount.h
@@ -27,6 +27,7 @@ struct mnt_namespace;
27#define MNT_NODIRATIME 0x10 27#define MNT_NODIRATIME 0x10
28#define MNT_RELATIME 0x20 28#define MNT_RELATIME 0x20
29#define MNT_READONLY 0x40 /* does the user want this to be r/o? */ 29#define MNT_READONLY 0x40 /* does the user want this to be r/o? */
30#define MNT_STRICTATIME 0x80
30 31
31#define MNT_SHRINKABLE 0x100 32#define MNT_SHRINKABLE 0x100
32#define MNT_IMBALANCED_WRITE_COUNT 0x200 /* just for debugging */ 33#define MNT_IMBALANCED_WRITE_COUNT 0x200 /* just for debugging */
diff --git a/include/linux/pci_ids.h b/include/linux/pci_ids.h
index aca8c458aa8a..02c18b903986 100644
--- a/include/linux/pci_ids.h
+++ b/include/linux/pci_ids.h
@@ -2112,6 +2112,8 @@
2112#define PCI_DEVICE_ID_MELLANOX_SINAI_OLD 0x5e8c 2112#define PCI_DEVICE_ID_MELLANOX_SINAI_OLD 0x5e8c
2113#define PCI_DEVICE_ID_MELLANOX_SINAI 0x6274 2113#define PCI_DEVICE_ID_MELLANOX_SINAI 0x6274
2114 2114
2115#define PCI_VENDOR_ID_DFI 0x15bd
2116
2115#define PCI_VENDOR_ID_QUICKNET 0x15e2 2117#define PCI_VENDOR_ID_QUICKNET 0x15e2
2116#define PCI_DEVICE_ID_QUICKNET_XJ 0x0500 2118#define PCI_DEVICE_ID_QUICKNET_XJ 0x0500
2117 2119
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 9a342699c607..76e470a299bf 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -12,6 +12,7 @@
12#define _PLATFORM_DEVICE_H_ 12#define _PLATFORM_DEVICE_H_
13 13
14#include <linux/device.h> 14#include <linux/device.h>
15#include <linux/mod_devicetable.h>
15 16
16struct platform_device { 17struct platform_device {
17 const char * name; 18 const char * name;
@@ -19,8 +20,13 @@ struct platform_device {
19 struct device dev; 20 struct device dev;
20 u32 num_resources; 21 u32 num_resources;
21 struct resource * resource; 22 struct resource * resource;
23 void *platform_data;
24
25 struct platform_device_id *id_entry;
22}; 26};
23 27
28#define platform_get_device_id(pdev) ((pdev)->id_entry)
29
24#define to_platform_device(x) container_of((x), struct platform_device, dev) 30#define to_platform_device(x) container_of((x), struct platform_device, dev)
25 31
26extern int platform_device_register(struct platform_device *); 32extern int platform_device_register(struct platform_device *);
@@ -56,6 +62,7 @@ struct platform_driver {
56 int (*resume_early)(struct platform_device *); 62 int (*resume_early)(struct platform_device *);
57 int (*resume)(struct platform_device *); 63 int (*resume)(struct platform_device *);
58 struct device_driver driver; 64 struct device_driver driver;
65 struct platform_device_id *id_table;
59}; 66};
60 67
61extern int platform_driver_register(struct platform_driver *); 68extern int platform_driver_register(struct platform_driver *);
diff --git a/include/linux/pm.h b/include/linux/pm.h
index 24ba5f67b3a3..1d4e2d289821 100644
--- a/include/linux/pm.h
+++ b/include/linux/pm.h
@@ -400,6 +400,9 @@ extern void __suspend_report_result(const char *function, void *fn, int ret);
400 400
401#else /* !CONFIG_PM_SLEEP */ 401#else /* !CONFIG_PM_SLEEP */
402 402
403#define device_pm_lock() do {} while (0)
404#define device_pm_unlock() do {} while (0)
405
403static inline int device_suspend(pm_message_t state) 406static inline int device_suspend(pm_message_t state)
404{ 407{
405 return 0; 408 return 0;
@@ -409,6 +412,14 @@ static inline int device_suspend(pm_message_t state)
409 412
410#endif /* !CONFIG_PM_SLEEP */ 413#endif /* !CONFIG_PM_SLEEP */
411 414
415/* How to reorder dpm_list after device_move() */
416enum dpm_order {
417 DPM_ORDER_NONE,
418 DPM_ORDER_DEV_AFTER_PARENT,
419 DPM_ORDER_PARENT_BEFORE_DEV,
420 DPM_ORDER_DEV_LAST,
421};
422
412/* 423/*
413 * Global Power Management flags 424 * Global Power Management flags
414 * Used to keep APM and ACPI from both being active 425 * Used to keep APM and ACPI from both being active
diff --git a/include/linux/sh_cmt.h b/include/linux/sh_cmt.h
new file mode 100644
index 000000000000..68cacde5954f
--- /dev/null
+++ b/include/linux/sh_cmt.h
@@ -0,0 +1,13 @@
1#ifndef __SH_CMT_H__
2#define __SH_CMT_H__
3
4struct sh_cmt_config {
5 char *name;
6 unsigned long channel_offset;
7 int timer_bit;
8 char *clk;
9 unsigned long clockevent_rating;
10 unsigned long clocksource_rating;
11};
12
13#endif /* __SH_CMT_H__ */
diff --git a/include/linux/sh_intc.h b/include/linux/sh_intc.h
index 68e212ff9dde..eb1423a0078d 100644
--- a/include/linux/sh_intc.h
+++ b/include/linux/sh_intc.h
@@ -85,6 +85,7 @@ struct intc_desc symbol __initdata = { \
85} 85}
86#endif 86#endif
87 87
88unsigned int intc_evt2irq(unsigned int vector);
88void __init register_intc_controller(struct intc_desc *desc); 89void __init register_intc_controller(struct intc_desc *desc);
89int intc_set_priority(unsigned int irq, unsigned int prio); 90int intc_set_priority(unsigned int irq, unsigned int prio);
90 91
diff --git a/include/linux/timeriomem-rng.h b/include/linux/timeriomem-rng.h
new file mode 100644
index 000000000000..dd253177f65f
--- /dev/null
+++ b/include/linux/timeriomem-rng.h
@@ -0,0 +1,21 @@
1/*
2 * linux/include/linux/timeriomem-rng.h
3 *
4 * Copyright (c) 2009 Alexander Clouter <alex@digriz.org.uk>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/completion.h>
12
13struct timeriomem_rng_data {
14 struct completion completion;
15 unsigned int present:1;
16
17 u32 __iomem *address;
18
19 /* measures in usecs */
20 unsigned int period;
21};
diff --git a/include/linux/uio_driver.h b/include/linux/uio_driver.h
index a0bb6bd2e5c1..5dcc9ff72f69 100644
--- a/include/linux/uio_driver.h
+++ b/include/linux/uio_driver.h
@@ -22,6 +22,7 @@ struct uio_map;
22 22
23/** 23/**
24 * struct uio_mem - description of a UIO memory region 24 * struct uio_mem - description of a UIO memory region
25 * @name: name of the memory region for identification
25 * @addr: address of the device's memory 26 * @addr: address of the device's memory
26 * @size: size of IO 27 * @size: size of IO
27 * @memtype: type of memory addr points to 28 * @memtype: type of memory addr points to
@@ -29,6 +30,7 @@ struct uio_map;
29 * @map: for use by the UIO core only. 30 * @map: for use by the UIO core only.
30 */ 31 */
31struct uio_mem { 32struct uio_mem {
33 const char *name;
32 unsigned long addr; 34 unsigned long addr;
33 unsigned long size; 35 unsigned long size;
34 int memtype; 36 int memtype;
@@ -42,12 +44,14 @@ struct uio_portio;
42 44
43/** 45/**
44 * struct uio_port - description of a UIO port region 46 * struct uio_port - description of a UIO port region
47 * @name: name of the port region for identification
45 * @start: start of port region 48 * @start: start of port region
46 * @size: size of port region 49 * @size: size of port region
47 * @porttype: type of port (see UIO_PORT_* below) 50 * @porttype: type of port (see UIO_PORT_* below)
48 * @portio: for use by the UIO core only. 51 * @portio: for use by the UIO core only.
49 */ 52 */
50struct uio_port { 53struct uio_port {
54 const char *name;
51 unsigned long start; 55 unsigned long start;
52 unsigned long size; 56 unsigned long size;
53 int porttype; 57 int porttype;
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 88079fd60235..c6b2ab41b908 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -643,186 +643,6 @@ static inline int usb_make_path(struct usb_device *dev, char *buf, size_t size)
643 643
644/*-------------------------------------------------------------------------*/ 644/*-------------------------------------------------------------------------*/
645 645
646/**
647 * usb_endpoint_num - get the endpoint's number
648 * @epd: endpoint to be checked
649 *
650 * Returns @epd's number: 0 to 15.
651 */
652static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
653{
654 return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
655}
656
657/**
658 * usb_endpoint_type - get the endpoint's transfer type
659 * @epd: endpoint to be checked
660 *
661 * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according
662 * to @epd's transfer type.
663 */
664static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
665{
666 return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
667}
668
669/**
670 * usb_endpoint_dir_in - check if the endpoint has IN direction
671 * @epd: endpoint to be checked
672 *
673 * Returns true if the endpoint is of type IN, otherwise it returns false.
674 */
675static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
676{
677 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
678}
679
680/**
681 * usb_endpoint_dir_out - check if the endpoint has OUT direction
682 * @epd: endpoint to be checked
683 *
684 * Returns true if the endpoint is of type OUT, otherwise it returns false.
685 */
686static inline int usb_endpoint_dir_out(
687 const struct usb_endpoint_descriptor *epd)
688{
689 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
690}
691
692/**
693 * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type
694 * @epd: endpoint to be checked
695 *
696 * Returns true if the endpoint is of type bulk, otherwise it returns false.
697 */
698static inline int usb_endpoint_xfer_bulk(
699 const struct usb_endpoint_descriptor *epd)
700{
701 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
702 USB_ENDPOINT_XFER_BULK);
703}
704
705/**
706 * usb_endpoint_xfer_control - check if the endpoint has control transfer type
707 * @epd: endpoint to be checked
708 *
709 * Returns true if the endpoint is of type control, otherwise it returns false.
710 */
711static inline int usb_endpoint_xfer_control(
712 const struct usb_endpoint_descriptor *epd)
713{
714 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
715 USB_ENDPOINT_XFER_CONTROL);
716}
717
718/**
719 * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type
720 * @epd: endpoint to be checked
721 *
722 * Returns true if the endpoint is of type interrupt, otherwise it returns
723 * false.
724 */
725static inline int usb_endpoint_xfer_int(
726 const struct usb_endpoint_descriptor *epd)
727{
728 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
729 USB_ENDPOINT_XFER_INT);
730}
731
732/**
733 * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type
734 * @epd: endpoint to be checked
735 *
736 * Returns true if the endpoint is of type isochronous, otherwise it returns
737 * false.
738 */
739static inline int usb_endpoint_xfer_isoc(
740 const struct usb_endpoint_descriptor *epd)
741{
742 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
743 USB_ENDPOINT_XFER_ISOC);
744}
745
746/**
747 * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN
748 * @epd: endpoint to be checked
749 *
750 * Returns true if the endpoint has bulk transfer type and IN direction,
751 * otherwise it returns false.
752 */
753static inline int usb_endpoint_is_bulk_in(
754 const struct usb_endpoint_descriptor *epd)
755{
756 return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd));
757}
758
759/**
760 * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT
761 * @epd: endpoint to be checked
762 *
763 * Returns true if the endpoint has bulk transfer type and OUT direction,
764 * otherwise it returns false.
765 */
766static inline int usb_endpoint_is_bulk_out(
767 const struct usb_endpoint_descriptor *epd)
768{
769 return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd));
770}
771
772/**
773 * usb_endpoint_is_int_in - check if the endpoint is interrupt IN
774 * @epd: endpoint to be checked
775 *
776 * Returns true if the endpoint has interrupt transfer type and IN direction,
777 * otherwise it returns false.
778 */
779static inline int usb_endpoint_is_int_in(
780 const struct usb_endpoint_descriptor *epd)
781{
782 return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd));
783}
784
785/**
786 * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT
787 * @epd: endpoint to be checked
788 *
789 * Returns true if the endpoint has interrupt transfer type and OUT direction,
790 * otherwise it returns false.
791 */
792static inline int usb_endpoint_is_int_out(
793 const struct usb_endpoint_descriptor *epd)
794{
795 return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd));
796}
797
798/**
799 * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN
800 * @epd: endpoint to be checked
801 *
802 * Returns true if the endpoint has isochronous transfer type and IN direction,
803 * otherwise it returns false.
804 */
805static inline int usb_endpoint_is_isoc_in(
806 const struct usb_endpoint_descriptor *epd)
807{
808 return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd));
809}
810
811/**
812 * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT
813 * @epd: endpoint to be checked
814 *
815 * Returns true if the endpoint has isochronous transfer type and OUT direction,
816 * otherwise it returns false.
817 */
818static inline int usb_endpoint_is_isoc_out(
819 const struct usb_endpoint_descriptor *epd)
820{
821 return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd));
822}
823
824/*-------------------------------------------------------------------------*/
825
826#define USB_DEVICE_ID_MATCH_DEVICE \ 646#define USB_DEVICE_ID_MATCH_DEVICE \
827 (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT) 647 (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
828#define USB_DEVICE_ID_MATCH_DEV_RANGE \ 648#define USB_DEVICE_ID_MATCH_DEV_RANGE \
@@ -1357,8 +1177,8 @@ struct urb {
1357 unsigned int transfer_flags; /* (in) URB_SHORT_NOT_OK | ...*/ 1177 unsigned int transfer_flags; /* (in) URB_SHORT_NOT_OK | ...*/
1358 void *transfer_buffer; /* (in) associated data buffer */ 1178 void *transfer_buffer; /* (in) associated data buffer */
1359 dma_addr_t transfer_dma; /* (in) dma addr for transfer_buffer */ 1179 dma_addr_t transfer_dma; /* (in) dma addr for transfer_buffer */
1360 int transfer_buffer_length; /* (in) data buffer length */ 1180 u32 transfer_buffer_length; /* (in) data buffer length */
1361 int actual_length; /* (return) actual transfer length */ 1181 u32 actual_length; /* (return) actual transfer length */
1362 unsigned char *setup_packet; /* (in) setup packet (control only) */ 1182 unsigned char *setup_packet; /* (in) setup packet (control only) */
1363 dma_addr_t setup_dma; /* (in) dma addr for setup_packet */ 1183 dma_addr_t setup_dma; /* (in) dma addr for setup_packet */
1364 int start_frame; /* (modify) start frame (ISO) */ 1184 int start_frame; /* (modify) start frame (ISO) */
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index 9b42baed3900..b145119a90da 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -102,7 +102,7 @@
102#define USB_REQ_LOOPBACK_DATA_READ 0x16 102#define USB_REQ_LOOPBACK_DATA_READ 0x16
103#define USB_REQ_SET_INTERFACE_DS 0x17 103#define USB_REQ_SET_INTERFACE_DS 0x17
104 104
105/* The Link Power Mangement (LPM) ECN defines USB_REQ_TEST_AND_SET command, 105/* The Link Power Management (LPM) ECN defines USB_REQ_TEST_AND_SET command,
106 * used by hubs to put ports into a new L1 suspend state, except that it 106 * used by hubs to put ports into a new L1 suspend state, except that it
107 * forgot to define its number ... 107 * forgot to define its number ...
108 */ 108 */
@@ -353,6 +353,185 @@ struct usb_endpoint_descriptor {
353#define USB_ENDPOINT_XFER_INT 3 353#define USB_ENDPOINT_XFER_INT 3
354#define USB_ENDPOINT_MAX_ADJUSTABLE 0x80 354#define USB_ENDPOINT_MAX_ADJUSTABLE 0x80
355 355
356/*-------------------------------------------------------------------------*/
357
358/**
359 * usb_endpoint_num - get the endpoint's number
360 * @epd: endpoint to be checked
361 *
362 * Returns @epd's number: 0 to 15.
363 */
364static inline int usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
365{
366 return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
367}
368
369/**
370 * usb_endpoint_type - get the endpoint's transfer type
371 * @epd: endpoint to be checked
372 *
373 * Returns one of USB_ENDPOINT_XFER_{CONTROL, ISOC, BULK, INT} according
374 * to @epd's transfer type.
375 */
376static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
377{
378 return epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK;
379}
380
381/**
382 * usb_endpoint_dir_in - check if the endpoint has IN direction
383 * @epd: endpoint to be checked
384 *
385 * Returns true if the endpoint is of type IN, otherwise it returns false.
386 */
387static inline int usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
388{
389 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN);
390}
391
392/**
393 * usb_endpoint_dir_out - check if the endpoint has OUT direction
394 * @epd: endpoint to be checked
395 *
396 * Returns true if the endpoint is of type OUT, otherwise it returns false.
397 */
398static inline int usb_endpoint_dir_out(
399 const struct usb_endpoint_descriptor *epd)
400{
401 return ((epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT);
402}
403
404/**
405 * usb_endpoint_xfer_bulk - check if the endpoint has bulk transfer type
406 * @epd: endpoint to be checked
407 *
408 * Returns true if the endpoint is of type bulk, otherwise it returns false.
409 */
410static inline int usb_endpoint_xfer_bulk(
411 const struct usb_endpoint_descriptor *epd)
412{
413 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
414 USB_ENDPOINT_XFER_BULK);
415}
416
417/**
418 * usb_endpoint_xfer_control - check if the endpoint has control transfer type
419 * @epd: endpoint to be checked
420 *
421 * Returns true if the endpoint is of type control, otherwise it returns false.
422 */
423static inline int usb_endpoint_xfer_control(
424 const struct usb_endpoint_descriptor *epd)
425{
426 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
427 USB_ENDPOINT_XFER_CONTROL);
428}
429
430/**
431 * usb_endpoint_xfer_int - check if the endpoint has interrupt transfer type
432 * @epd: endpoint to be checked
433 *
434 * Returns true if the endpoint is of type interrupt, otherwise it returns
435 * false.
436 */
437static inline int usb_endpoint_xfer_int(
438 const struct usb_endpoint_descriptor *epd)
439{
440 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
441 USB_ENDPOINT_XFER_INT);
442}
443
444/**
445 * usb_endpoint_xfer_isoc - check if the endpoint has isochronous transfer type
446 * @epd: endpoint to be checked
447 *
448 * Returns true if the endpoint is of type isochronous, otherwise it returns
449 * false.
450 */
451static inline int usb_endpoint_xfer_isoc(
452 const struct usb_endpoint_descriptor *epd)
453{
454 return ((epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ==
455 USB_ENDPOINT_XFER_ISOC);
456}
457
458/**
459 * usb_endpoint_is_bulk_in - check if the endpoint is bulk IN
460 * @epd: endpoint to be checked
461 *
462 * Returns true if the endpoint has bulk transfer type and IN direction,
463 * otherwise it returns false.
464 */
465static inline int usb_endpoint_is_bulk_in(
466 const struct usb_endpoint_descriptor *epd)
467{
468 return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_in(epd));
469}
470
471/**
472 * usb_endpoint_is_bulk_out - check if the endpoint is bulk OUT
473 * @epd: endpoint to be checked
474 *
475 * Returns true if the endpoint has bulk transfer type and OUT direction,
476 * otherwise it returns false.
477 */
478static inline int usb_endpoint_is_bulk_out(
479 const struct usb_endpoint_descriptor *epd)
480{
481 return (usb_endpoint_xfer_bulk(epd) && usb_endpoint_dir_out(epd));
482}
483
484/**
485 * usb_endpoint_is_int_in - check if the endpoint is interrupt IN
486 * @epd: endpoint to be checked
487 *
488 * Returns true if the endpoint has interrupt transfer type and IN direction,
489 * otherwise it returns false.
490 */
491static inline int usb_endpoint_is_int_in(
492 const struct usb_endpoint_descriptor *epd)
493{
494 return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_in(epd));
495}
496
497/**
498 * usb_endpoint_is_int_out - check if the endpoint is interrupt OUT
499 * @epd: endpoint to be checked
500 *
501 * Returns true if the endpoint has interrupt transfer type and OUT direction,
502 * otherwise it returns false.
503 */
504static inline int usb_endpoint_is_int_out(
505 const struct usb_endpoint_descriptor *epd)
506{
507 return (usb_endpoint_xfer_int(epd) && usb_endpoint_dir_out(epd));
508}
509
510/**
511 * usb_endpoint_is_isoc_in - check if the endpoint is isochronous IN
512 * @epd: endpoint to be checked
513 *
514 * Returns true if the endpoint has isochronous transfer type and IN direction,
515 * otherwise it returns false.
516 */
517static inline int usb_endpoint_is_isoc_in(
518 const struct usb_endpoint_descriptor *epd)
519{
520 return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_in(epd));
521}
522
523/**
524 * usb_endpoint_is_isoc_out - check if the endpoint is isochronous OUT
525 * @epd: endpoint to be checked
526 *
527 * Returns true if the endpoint has isochronous transfer type and OUT direction,
528 * otherwise it returns false.
529 */
530static inline int usb_endpoint_is_isoc_out(
531 const struct usb_endpoint_descriptor *epd)
532{
533 return (usb_endpoint_xfer_isoc(epd) && usb_endpoint_dir_out(epd));
534}
356 535
357/*-------------------------------------------------------------------------*/ 536/*-------------------------------------------------------------------------*/
358 537
@@ -584,8 +763,8 @@ enum usb_device_state {
584 /* chapter 9 and authentication (wireless) device states */ 763 /* chapter 9 and authentication (wireless) device states */
585 USB_STATE_ATTACHED, 764 USB_STATE_ATTACHED,
586 USB_STATE_POWERED, /* wired */ 765 USB_STATE_POWERED, /* wired */
587 USB_STATE_UNAUTHENTICATED, /* auth */
588 USB_STATE_RECONNECTING, /* auth */ 766 USB_STATE_RECONNECTING, /* auth */
767 USB_STATE_UNAUTHENTICATED, /* auth */
589 USB_STATE_DEFAULT, /* limited function */ 768 USB_STATE_DEFAULT, /* limited function */
590 USB_STATE_ADDRESS, 769 USB_STATE_ADDRESS,
591 USB_STATE_CONFIGURED, /* most functions */ 770 USB_STATE_CONFIGURED, /* most functions */
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index 935c380ffe47..acd7b0f06c8a 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -244,6 +244,10 @@ int usb_add_config(struct usb_composite_dev *,
244 * value; it should return zero on successful initialization. 244 * value; it should return zero on successful initialization.
245 * @unbind: Reverses @bind(); called as a side effect of unregistering 245 * @unbind: Reverses @bind(); called as a side effect of unregistering
246 * this driver. 246 * this driver.
247 * @suspend: Notifies when the host stops sending USB traffic,
248 * after function notifications
249 * @resume: Notifies configuration when the host restarts USB traffic,
250 * before function notifications
247 * 251 *
248 * Devices default to reporting self powered operation. Devices which rely 252 * Devices default to reporting self powered operation. Devices which rely
249 * on bus powered operation should report this in their @bind() method. 253 * on bus powered operation should report this in their @bind() method.
@@ -268,6 +272,10 @@ struct usb_composite_driver {
268 272
269 int (*bind)(struct usb_composite_dev *); 273 int (*bind)(struct usb_composite_dev *);
270 int (*unbind)(struct usb_composite_dev *); 274 int (*unbind)(struct usb_composite_dev *);
275
276 /* global suspend hooks */
277 void (*suspend)(struct usb_composite_dev *);
278 void (*resume)(struct usb_composite_dev *);
271}; 279};
272 280
273extern int usb_composite_register(struct usb_composite_driver *); 281extern int usb_composite_register(struct usb_composite_driver *);
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 0460a746480c..bbf45d500b6d 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -598,6 +598,7 @@ static inline int usb_gadget_clear_selfpowered(struct usb_gadget *gadget)
598/** 598/**
599 * usb_gadget_vbus_connect - Notify controller that VBUS is powered 599 * usb_gadget_vbus_connect - Notify controller that VBUS is powered
600 * @gadget:The device which now has VBUS power. 600 * @gadget:The device which now has VBUS power.
601 * Context: can sleep
601 * 602 *
602 * This call is used by a driver for an external transceiver (or GPIO) 603 * This call is used by a driver for an external transceiver (or GPIO)
603 * that detects a VBUS power session starting. Common responses include 604 * that detects a VBUS power session starting. Common responses include
@@ -636,6 +637,7 @@ static inline int usb_gadget_vbus_draw(struct usb_gadget *gadget, unsigned mA)
636/** 637/**
637 * usb_gadget_vbus_disconnect - notify controller about VBUS session end 638 * usb_gadget_vbus_disconnect - notify controller about VBUS session end
638 * @gadget:the device whose VBUS supply is being described 639 * @gadget:the device whose VBUS supply is being described
640 * Context: can sleep
639 * 641 *
640 * This call is used by a driver for an external transceiver (or GPIO) 642 * This call is used by a driver for an external transceiver (or GPIO)
641 * that detects a VBUS power session ending. Common responses include 643 * that detects a VBUS power session ending. Common responses include
@@ -792,19 +794,20 @@ struct usb_gadget_driver {
792/** 794/**
793 * usb_gadget_register_driver - register a gadget driver 795 * usb_gadget_register_driver - register a gadget driver
794 * @driver:the driver being registered 796 * @driver:the driver being registered
797 * Context: can sleep
795 * 798 *
796 * Call this in your gadget driver's module initialization function, 799 * Call this in your gadget driver's module initialization function,
797 * to tell the underlying usb controller driver about your driver. 800 * to tell the underlying usb controller driver about your driver.
798 * The driver's bind() function will be called to bind it to a 801 * The driver's bind() function will be called to bind it to a
799 * gadget before this registration call returns. It's expected that 802 * gadget before this registration call returns. It's expected that
800 * the bind() functions will be in init sections. 803 * the bind() functions will be in init sections.
801 * This function must be called in a context that can sleep.
802 */ 804 */
803int usb_gadget_register_driver(struct usb_gadget_driver *driver); 805int usb_gadget_register_driver(struct usb_gadget_driver *driver);
804 806
805/** 807/**
806 * usb_gadget_unregister_driver - unregister a gadget driver 808 * usb_gadget_unregister_driver - unregister a gadget driver
807 * @driver:the driver being unregistered 809 * @driver:the driver being unregistered
810 * Context: can sleep
808 * 811 *
809 * Call this in your gadget driver's module cleanup function, 812 * Call this in your gadget driver's module cleanup function,
810 * to tell the underlying usb controller that your driver is 813 * to tell the underlying usb controller that your driver is
@@ -813,7 +816,6 @@ int usb_gadget_register_driver(struct usb_gadget_driver *driver);
813 * to unbind() and clean up any device state, before this procedure 816 * to unbind() and clean up any device state, before this procedure
814 * finally returns. It's expected that the unbind() functions 817 * finally returns. It's expected that the unbind() functions
815 * will in in exit sections, so may not be linked in some kernels. 818 * will in in exit sections, so may not be linked in some kernels.
816 * This function must be called in a context that can sleep.
817 */ 819 */
818int usb_gadget_unregister_driver(struct usb_gadget_driver *driver); 820int usb_gadget_unregister_driver(struct usb_gadget_driver *driver);
819 821
diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
index 94df4fe6c6c0..1aaa826396a1 100644
--- a/include/linux/usb/otg.h
+++ b/include/linux/usb/otg.h
@@ -80,12 +80,17 @@ struct otg_transceiver {
80 80
81/* for board-specific init logic */ 81/* for board-specific init logic */
82extern int otg_set_transceiver(struct otg_transceiver *); 82extern int otg_set_transceiver(struct otg_transceiver *);
83#ifdef CONFIG_NOP_USB_XCEIV
84extern void usb_nop_xceiv_register(void);
85extern void usb_nop_xceiv_unregister(void);
86#endif
83 87
84 88
85/* for usb host and peripheral controller drivers */ 89/* for usb host and peripheral controller drivers */
86extern struct otg_transceiver *otg_get_transceiver(void); 90extern struct otg_transceiver *otg_get_transceiver(void);
87extern void otg_put_transceiver(struct otg_transceiver *); 91extern void otg_put_transceiver(struct otg_transceiver *);
88 92
93/* Context: can sleep */
89static inline int 94static inline int
90otg_start_hnp(struct otg_transceiver *otg) 95otg_start_hnp(struct otg_transceiver *otg)
91{ 96{
@@ -102,6 +107,8 @@ otg_set_host(struct otg_transceiver *otg, struct usb_bus *host)
102 107
103 108
104/* for usb peripheral controller drivers */ 109/* for usb peripheral controller drivers */
110
111/* Context: can sleep */
105static inline int 112static inline int
106otg_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *periph) 113otg_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *periph)
107{ 114{
@@ -114,6 +121,7 @@ otg_set_power(struct otg_transceiver *otg, unsigned mA)
114 return otg->set_power(otg, mA); 121 return otg->set_power(otg, mA);
115} 122}
116 123
124/* Context: can sleep */
117static inline int 125static inline int
118otg_set_suspend(struct otg_transceiver *otg, int suspend) 126otg_set_suspend(struct otg_transceiver *otg, int suspend)
119{ 127{
diff --git a/include/linux/usb/quirks.h b/include/linux/usb/quirks.h
index 7f6c603db654..2526f3bbd273 100644
--- a/include/linux/usb/quirks.h
+++ b/include/linux/usb/quirks.h
@@ -16,4 +16,7 @@
16/* device can't handle Set-Interface requests */ 16/* device can't handle Set-Interface requests */
17#define USB_QUIRK_NO_SET_INTF 0x00000004 17#define USB_QUIRK_NO_SET_INTF 0x00000004
18 18
19/* device can't handle its Configuration or Interface strings */
20#define USB_QUIRK_CONFIG_INTF_STRINGS 0x00000008
21
19#endif /* __LINUX_USB_QUIRKS_H */ 22#endif /* __LINUX_USB_QUIRKS_H */
diff --git a/include/linux/usb/serial.h b/include/linux/usb/serial.h
index 0b8617a9176d..b95842542590 100644
--- a/include/linux/usb/serial.h
+++ b/include/linux/usb/serial.h
@@ -130,7 +130,8 @@ struct usb_serial {
130 struct usb_device *dev; 130 struct usb_device *dev;
131 struct usb_serial_driver *type; 131 struct usb_serial_driver *type;
132 struct usb_interface *interface; 132 struct usb_interface *interface;
133 unsigned char disconnected; 133 unsigned char disconnected:1;
134 unsigned char suspending:1;
134 unsigned char minor; 135 unsigned char minor;
135 unsigned char num_ports; 136 unsigned char num_ports;
136 unsigned char num_port_pointers; 137 unsigned char num_port_pointers;
diff --git a/include/linux/usb_usual.h b/include/linux/usb_usual.h
index 1eea1ab68dc4..3d15fb9bc116 100644
--- a/include/linux/usb_usual.h
+++ b/include/linux/usb_usual.h
@@ -96,39 +96,26 @@ enum { US_DO_ALL_FLAGS };
96#define US_PR_CBI 0x00 /* Control/Bulk/Interrupt */ 96#define US_PR_CBI 0x00 /* Control/Bulk/Interrupt */
97#define US_PR_CB 0x01 /* Control/Bulk w/o interrupt */ 97#define US_PR_CB 0x01 /* Control/Bulk w/o interrupt */
98#define US_PR_BULK 0x50 /* bulk only */ 98#define US_PR_BULK 0x50 /* bulk only */
99#ifdef CONFIG_USB_STORAGE_USBAT 99
100#define US_PR_USBAT 0x80 /* SCM-ATAPI bridge */ 100#define US_PR_USBAT 0x80 /* SCM-ATAPI bridge */
101#endif
102#ifdef CONFIG_USB_STORAGE_SDDR09
103#define US_PR_EUSB_SDDR09 0x81 /* SCM-SCSI bridge for SDDR-09 */ 101#define US_PR_EUSB_SDDR09 0x81 /* SCM-SCSI bridge for SDDR-09 */
104#endif
105#ifdef CONFIG_USB_STORAGE_SDDR55
106#define US_PR_SDDR55 0x82 /* SDDR-55 (made up) */ 102#define US_PR_SDDR55 0x82 /* SDDR-55 (made up) */
107#endif
108#define US_PR_DPCM_USB 0xf0 /* Combination CB/SDDR09 */ 103#define US_PR_DPCM_USB 0xf0 /* Combination CB/SDDR09 */
109#ifdef CONFIG_USB_STORAGE_FREECOM
110#define US_PR_FREECOM 0xf1 /* Freecom */ 104#define US_PR_FREECOM 0xf1 /* Freecom */
111#endif
112#ifdef CONFIG_USB_STORAGE_DATAFAB
113#define US_PR_DATAFAB 0xf2 /* Datafab chipsets */ 105#define US_PR_DATAFAB 0xf2 /* Datafab chipsets */
114#endif
115#ifdef CONFIG_USB_STORAGE_JUMPSHOT
116#define US_PR_JUMPSHOT 0xf3 /* Lexar Jumpshot */ 106#define US_PR_JUMPSHOT 0xf3 /* Lexar Jumpshot */
117#endif
118#ifdef CONFIG_USB_STORAGE_ALAUDA
119#define US_PR_ALAUDA 0xf4 /* Alauda chipsets */ 107#define US_PR_ALAUDA 0xf4 /* Alauda chipsets */
120#endif
121#ifdef CONFIG_USB_STORAGE_KARMA
122#define US_PR_KARMA 0xf5 /* Rio Karma */ 108#define US_PR_KARMA 0xf5 /* Rio Karma */
123#endif
124 109
125#define US_PR_DEVICE 0xff /* Use device's value */ 110#define US_PR_DEVICE 0xff /* Use device's value */
126 111
127/* 112/*
128 */ 113 */
114extern int usb_usual_ignore_device(struct usb_interface *intf);
115extern struct usb_device_id usb_storage_usb_ids[];
116
129#ifdef CONFIG_USB_LIBUSUAL 117#ifdef CONFIG_USB_LIBUSUAL
130 118
131extern struct usb_device_id storage_usb_ids[];
132extern void usb_usual_set_present(int type); 119extern void usb_usual_set_present(int type);
133extern void usb_usual_clear_present(int type); 120extern void usb_usual_clear_present(int type);
134extern int usb_usual_check_type(const struct usb_device_id *, int type); 121extern int usb_usual_check_type(const struct usb_device_id *, int type);
diff --git a/include/linux/wimax/debug.h b/include/linux/wimax/debug.h
index ba0c49399a83..c703e0340423 100644
--- a/include/linux/wimax/debug.h
+++ b/include/linux/wimax/debug.h
@@ -178,7 +178,7 @@ void __d_head(char *head, size_t head_size,
178 WARN_ON(1); 178 WARN_ON(1);
179 } else 179 } else
180 snprintf(head, head_size, "%s %s: ", 180 snprintf(head, head_size, "%s %s: ",
181 dev_driver_string(dev), dev->bus_id); 181 dev_driver_string(dev), dev_name(dev));
182} 182}
183 183
184 184
diff --git a/include/sound/ad1816a.h b/include/sound/ad1816a.h
index b3aa62ee3c8d..d010858c33c2 100644
--- a/include/sound/ad1816a.h
+++ b/include/sound/ad1816a.h
@@ -169,5 +169,7 @@ extern int snd_ad1816a_create(struct snd_card *card, unsigned long port,
169 169
170extern int snd_ad1816a_pcm(struct snd_ad1816a *chip, int device, struct snd_pcm **rpcm); 170extern int snd_ad1816a_pcm(struct snd_ad1816a *chip, int device, struct snd_pcm **rpcm);
171extern int snd_ad1816a_mixer(struct snd_ad1816a *chip); 171extern int snd_ad1816a_mixer(struct snd_ad1816a *chip);
172extern int snd_ad1816a_timer(struct snd_ad1816a *chip, int device,
173 struct snd_timer **rtimer);
172 174
173#endif /* __SOUND_AD1816A_H */ 175#endif /* __SOUND_AD1816A_H */
diff --git a/include/sound/asound.h b/include/sound/asound.h
index 1c02ed1d7c4a..fad3e0c7b932 100644
--- a/include/sound/asound.h
+++ b/include/sound/asound.h
@@ -126,12 +126,10 @@ struct snd_hwdep_dsp_image {
126 unsigned long driver_data; /* W: driver-specific data */ 126 unsigned long driver_data; /* W: driver-specific data */
127}; 127};
128 128
129enum { 129#define SNDRV_HWDEP_IOCTL_PVERSION _IOR ('H', 0x00, int)
130 SNDRV_HWDEP_IOCTL_PVERSION = _IOR ('H', 0x00, int), 130#define SNDRV_HWDEP_IOCTL_INFO _IOR ('H', 0x01, struct snd_hwdep_info)
131 SNDRV_HWDEP_IOCTL_INFO = _IOR ('H', 0x01, struct snd_hwdep_info), 131#define SNDRV_HWDEP_IOCTL_DSP_STATUS _IOR('H', 0x02, struct snd_hwdep_dsp_status)
132 SNDRV_HWDEP_IOCTL_DSP_STATUS = _IOR('H', 0x02, struct snd_hwdep_dsp_status), 132#define SNDRV_HWDEP_IOCTL_DSP_LOAD _IOW('H', 0x03, struct snd_hwdep_dsp_image)
133 SNDRV_HWDEP_IOCTL_DSP_LOAD = _IOW('H', 0x03, struct snd_hwdep_dsp_image)
134};
135 133
136/***************************************************************************** 134/*****************************************************************************
137 * * 135 * *
@@ -451,40 +449,35 @@ enum {
451 SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC, 449 SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC,
452}; 450};
453 451
454enum { 452#define SNDRV_PCM_IOCTL_PVERSION _IOR('A', 0x00, int)
455 SNDRV_PCM_IOCTL_PVERSION = _IOR('A', 0x00, int), 453#define SNDRV_PCM_IOCTL_INFO _IOR('A', 0x01, struct snd_pcm_info)
456 SNDRV_PCM_IOCTL_INFO = _IOR('A', 0x01, struct snd_pcm_info), 454#define SNDRV_PCM_IOCTL_TSTAMP _IOW('A', 0x02, int)
457 SNDRV_PCM_IOCTL_TSTAMP = _IOW('A', 0x02, int), 455#define SNDRV_PCM_IOCTL_TTSTAMP _IOW('A', 0x03, int)
458 SNDRV_PCM_IOCTL_TTSTAMP = _IOW('A', 0x03, int), 456#define SNDRV_PCM_IOCTL_HW_REFINE _IOWR('A', 0x10, struct snd_pcm_hw_params)
459 SNDRV_PCM_IOCTL_HW_REFINE = _IOWR('A', 0x10, struct snd_pcm_hw_params), 457#define SNDRV_PCM_IOCTL_HW_PARAMS _IOWR('A', 0x11, struct snd_pcm_hw_params)
460 SNDRV_PCM_IOCTL_HW_PARAMS = _IOWR('A', 0x11, struct snd_pcm_hw_params), 458#define SNDRV_PCM_IOCTL_HW_FREE _IO('A', 0x12)
461 SNDRV_PCM_IOCTL_HW_FREE = _IO('A', 0x12), 459#define SNDRV_PCM_IOCTL_SW_PARAMS _IOWR('A', 0x13, struct snd_pcm_sw_params)
462 SNDRV_PCM_IOCTL_SW_PARAMS = _IOWR('A', 0x13, struct snd_pcm_sw_params), 460#define SNDRV_PCM_IOCTL_STATUS _IOR('A', 0x20, struct snd_pcm_status)
463 SNDRV_PCM_IOCTL_STATUS = _IOR('A', 0x20, struct snd_pcm_status), 461#define SNDRV_PCM_IOCTL_DELAY _IOR('A', 0x21, snd_pcm_sframes_t)
464 SNDRV_PCM_IOCTL_DELAY = _IOR('A', 0x21, snd_pcm_sframes_t), 462#define SNDRV_PCM_IOCTL_HWSYNC _IO('A', 0x22)
465 SNDRV_PCM_IOCTL_HWSYNC = _IO('A', 0x22), 463#define SNDRV_PCM_IOCTL_SYNC_PTR _IOWR('A', 0x23, struct snd_pcm_sync_ptr)
466 SNDRV_PCM_IOCTL_SYNC_PTR = _IOWR('A', 0x23, struct snd_pcm_sync_ptr), 464#define SNDRV_PCM_IOCTL_CHANNEL_INFO _IOR('A', 0x32, struct snd_pcm_channel_info)
467 SNDRV_PCM_IOCTL_CHANNEL_INFO = _IOR('A', 0x32, struct snd_pcm_channel_info), 465#define SNDRV_PCM_IOCTL_PREPARE _IO('A', 0x40)
468 SNDRV_PCM_IOCTL_PREPARE = _IO('A', 0x40), 466#define SNDRV_PCM_IOCTL_RESET _IO('A', 0x41)
469 SNDRV_PCM_IOCTL_RESET = _IO('A', 0x41), 467#define SNDRV_PCM_IOCTL_START _IO('A', 0x42)
470 SNDRV_PCM_IOCTL_START = _IO('A', 0x42), 468#define SNDRV_PCM_IOCTL_DROP _IO('A', 0x43)
471 SNDRV_PCM_IOCTL_DROP = _IO('A', 0x43), 469#define SNDRV_PCM_IOCTL_DRAIN _IO('A', 0x44)
472 SNDRV_PCM_IOCTL_DRAIN = _IO('A', 0x44), 470#define SNDRV_PCM_IOCTL_PAUSE _IOW('A', 0x45, int)
473 SNDRV_PCM_IOCTL_PAUSE = _IOW('A', 0x45, int), 471#define SNDRV_PCM_IOCTL_REWIND _IOW('A', 0x46, snd_pcm_uframes_t)
474 SNDRV_PCM_IOCTL_REWIND = _IOW('A', 0x46, snd_pcm_uframes_t), 472#define SNDRV_PCM_IOCTL_RESUME _IO('A', 0x47)
475 SNDRV_PCM_IOCTL_RESUME = _IO('A', 0x47), 473#define SNDRV_PCM_IOCTL_XRUN _IO('A', 0x48)
476 SNDRV_PCM_IOCTL_XRUN = _IO('A', 0x48), 474#define SNDRV_PCM_IOCTL_FORWARD _IOW('A', 0x49, snd_pcm_uframes_t)
477 SNDRV_PCM_IOCTL_FORWARD = _IOW('A', 0x49, snd_pcm_uframes_t), 475#define SNDRV_PCM_IOCTL_WRITEI_FRAMES _IOW('A', 0x50, struct snd_xferi)
478 SNDRV_PCM_IOCTL_WRITEI_FRAMES = _IOW('A', 0x50, struct snd_xferi), 476#define SNDRV_PCM_IOCTL_READI_FRAMES _IOR('A', 0x51, struct snd_xferi)
479 SNDRV_PCM_IOCTL_READI_FRAMES = _IOR('A', 0x51, struct snd_xferi), 477#define SNDRV_PCM_IOCTL_WRITEN_FRAMES _IOW('A', 0x52, struct snd_xfern)
480 SNDRV_PCM_IOCTL_WRITEN_FRAMES = _IOW('A', 0x52, struct snd_xfern), 478#define SNDRV_PCM_IOCTL_READN_FRAMES _IOR('A', 0x53, struct snd_xfern)
481 SNDRV_PCM_IOCTL_READN_FRAMES = _IOR('A', 0x53, struct snd_xfern), 479#define SNDRV_PCM_IOCTL_LINK _IOW('A', 0x60, int)
482 SNDRV_PCM_IOCTL_LINK = _IOW('A', 0x60, int), 480#define SNDRV_PCM_IOCTL_UNLINK _IO('A', 0x61)
483 SNDRV_PCM_IOCTL_UNLINK = _IO('A', 0x61),
484};
485
486/* Trick to make alsa-lib/acinclude.m4 happy */
487#define SNDRV_PCM_IOCTL_REWIND SNDRV_PCM_IOCTL_REWIND
488 481
489/***************************************************************************** 482/*****************************************************************************
490 * * 483 * *
@@ -538,14 +531,12 @@ struct snd_rawmidi_status {
538 unsigned char reserved[16]; /* reserved for future use */ 531 unsigned char reserved[16]; /* reserved for future use */
539}; 532};
540 533
541enum { 534#define SNDRV_RAWMIDI_IOCTL_PVERSION _IOR('W', 0x00, int)
542 SNDRV_RAWMIDI_IOCTL_PVERSION = _IOR('W', 0x00, int), 535#define SNDRV_RAWMIDI_IOCTL_INFO _IOR('W', 0x01, struct snd_rawmidi_info)
543 SNDRV_RAWMIDI_IOCTL_INFO = _IOR('W', 0x01, struct snd_rawmidi_info), 536#define SNDRV_RAWMIDI_IOCTL_PARAMS _IOWR('W', 0x10, struct snd_rawmidi_params)
544 SNDRV_RAWMIDI_IOCTL_PARAMS = _IOWR('W', 0x10, struct snd_rawmidi_params), 537#define SNDRV_RAWMIDI_IOCTL_STATUS _IOWR('W', 0x20, struct snd_rawmidi_status)
545 SNDRV_RAWMIDI_IOCTL_STATUS = _IOWR('W', 0x20, struct snd_rawmidi_status), 538#define SNDRV_RAWMIDI_IOCTL_DROP _IOW('W', 0x30, int)
546 SNDRV_RAWMIDI_IOCTL_DROP = _IOW('W', 0x30, int), 539#define SNDRV_RAWMIDI_IOCTL_DRAIN _IOW('W', 0x31, int)
547 SNDRV_RAWMIDI_IOCTL_DRAIN = _IOW('W', 0x31, int),
548};
549 540
550/* 541/*
551 * Timer section - /dev/snd/timer 542 * Timer section - /dev/snd/timer
@@ -654,23 +645,21 @@ struct snd_timer_status {
654 unsigned char reserved[64]; /* reserved */ 645 unsigned char reserved[64]; /* reserved */
655}; 646};
656 647
657enum { 648#define SNDRV_TIMER_IOCTL_PVERSION _IOR('T', 0x00, int)
658 SNDRV_TIMER_IOCTL_PVERSION = _IOR('T', 0x00, int), 649#define SNDRV_TIMER_IOCTL_NEXT_DEVICE _IOWR('T', 0x01, struct snd_timer_id)
659 SNDRV_TIMER_IOCTL_NEXT_DEVICE = _IOWR('T', 0x01, struct snd_timer_id), 650#define SNDRV_TIMER_IOCTL_TREAD _IOW('T', 0x02, int)
660 SNDRV_TIMER_IOCTL_TREAD = _IOW('T', 0x02, int), 651#define SNDRV_TIMER_IOCTL_GINFO _IOWR('T', 0x03, struct snd_timer_ginfo)
661 SNDRV_TIMER_IOCTL_GINFO = _IOWR('T', 0x03, struct snd_timer_ginfo), 652#define SNDRV_TIMER_IOCTL_GPARAMS _IOW('T', 0x04, struct snd_timer_gparams)
662 SNDRV_TIMER_IOCTL_GPARAMS = _IOW('T', 0x04, struct snd_timer_gparams), 653#define SNDRV_TIMER_IOCTL_GSTATUS _IOWR('T', 0x05, struct snd_timer_gstatus)
663 SNDRV_TIMER_IOCTL_GSTATUS = _IOWR('T', 0x05, struct snd_timer_gstatus), 654#define SNDRV_TIMER_IOCTL_SELECT _IOW('T', 0x10, struct snd_timer_select)
664 SNDRV_TIMER_IOCTL_SELECT = _IOW('T', 0x10, struct snd_timer_select), 655#define SNDRV_TIMER_IOCTL_INFO _IOR('T', 0x11, struct snd_timer_info)
665 SNDRV_TIMER_IOCTL_INFO = _IOR('T', 0x11, struct snd_timer_info), 656#define SNDRV_TIMER_IOCTL_PARAMS _IOW('T', 0x12, struct snd_timer_params)
666 SNDRV_TIMER_IOCTL_PARAMS = _IOW('T', 0x12, struct snd_timer_params), 657#define SNDRV_TIMER_IOCTL_STATUS _IOR('T', 0x14, struct snd_timer_status)
667 SNDRV_TIMER_IOCTL_STATUS = _IOR('T', 0x14, struct snd_timer_status), 658/* The following four ioctls are changed since 1.0.9 due to confliction */
668 /* The following four ioctls are changed since 1.0.9 due to confliction */ 659#define SNDRV_TIMER_IOCTL_START _IO('T', 0xa0)
669 SNDRV_TIMER_IOCTL_START = _IO('T', 0xa0), 660#define SNDRV_TIMER_IOCTL_STOP _IO('T', 0xa1)
670 SNDRV_TIMER_IOCTL_STOP = _IO('T', 0xa1), 661#define SNDRV_TIMER_IOCTL_CONTINUE _IO('T', 0xa2)
671 SNDRV_TIMER_IOCTL_CONTINUE = _IO('T', 0xa2), 662#define SNDRV_TIMER_IOCTL_PAUSE _IO('T', 0xa3)
672 SNDRV_TIMER_IOCTL_PAUSE = _IO('T', 0xa3),
673};
674 663
675struct snd_timer_read { 664struct snd_timer_read {
676 unsigned int resolution; 665 unsigned int resolution;
@@ -847,33 +836,31 @@ struct snd_ctl_tlv {
847 unsigned int tlv[0]; /* first TLV */ 836 unsigned int tlv[0]; /* first TLV */
848}; 837};
849 838
850enum { 839#define SNDRV_CTL_IOCTL_PVERSION _IOR('U', 0x00, int)
851 SNDRV_CTL_IOCTL_PVERSION = _IOR('U', 0x00, int), 840#define SNDRV_CTL_IOCTL_CARD_INFO _IOR('U', 0x01, struct snd_ctl_card_info)
852 SNDRV_CTL_IOCTL_CARD_INFO = _IOR('U', 0x01, struct snd_ctl_card_info), 841#define SNDRV_CTL_IOCTL_ELEM_LIST _IOWR('U', 0x10, struct snd_ctl_elem_list)
853 SNDRV_CTL_IOCTL_ELEM_LIST = _IOWR('U', 0x10, struct snd_ctl_elem_list), 842#define SNDRV_CTL_IOCTL_ELEM_INFO _IOWR('U', 0x11, struct snd_ctl_elem_info)
854 SNDRV_CTL_IOCTL_ELEM_INFO = _IOWR('U', 0x11, struct snd_ctl_elem_info), 843#define SNDRV_CTL_IOCTL_ELEM_READ _IOWR('U', 0x12, struct snd_ctl_elem_value)
855 SNDRV_CTL_IOCTL_ELEM_READ = _IOWR('U', 0x12, struct snd_ctl_elem_value), 844#define SNDRV_CTL_IOCTL_ELEM_WRITE _IOWR('U', 0x13, struct snd_ctl_elem_value)
856 SNDRV_CTL_IOCTL_ELEM_WRITE = _IOWR('U', 0x13, struct snd_ctl_elem_value), 845#define SNDRV_CTL_IOCTL_ELEM_LOCK _IOW('U', 0x14, struct snd_ctl_elem_id)
857 SNDRV_CTL_IOCTL_ELEM_LOCK = _IOW('U', 0x14, struct snd_ctl_elem_id), 846#define SNDRV_CTL_IOCTL_ELEM_UNLOCK _IOW('U', 0x15, struct snd_ctl_elem_id)
858 SNDRV_CTL_IOCTL_ELEM_UNLOCK = _IOW('U', 0x15, struct snd_ctl_elem_id), 847#define SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS _IOWR('U', 0x16, int)
859 SNDRV_CTL_IOCTL_SUBSCRIBE_EVENTS = _IOWR('U', 0x16, int), 848#define SNDRV_CTL_IOCTL_ELEM_ADD _IOWR('U', 0x17, struct snd_ctl_elem_info)
860 SNDRV_CTL_IOCTL_ELEM_ADD = _IOWR('U', 0x17, struct snd_ctl_elem_info), 849#define SNDRV_CTL_IOCTL_ELEM_REPLACE _IOWR('U', 0x18, struct snd_ctl_elem_info)
861 SNDRV_CTL_IOCTL_ELEM_REPLACE = _IOWR('U', 0x18, struct snd_ctl_elem_info), 850#define SNDRV_CTL_IOCTL_ELEM_REMOVE _IOWR('U', 0x19, struct snd_ctl_elem_id)
862 SNDRV_CTL_IOCTL_ELEM_REMOVE = _IOWR('U', 0x19, struct snd_ctl_elem_id), 851#define SNDRV_CTL_IOCTL_TLV_READ _IOWR('U', 0x1a, struct snd_ctl_tlv)
863 SNDRV_CTL_IOCTL_TLV_READ = _IOWR('U', 0x1a, struct snd_ctl_tlv), 852#define SNDRV_CTL_IOCTL_TLV_WRITE _IOWR('U', 0x1b, struct snd_ctl_tlv)
864 SNDRV_CTL_IOCTL_TLV_WRITE = _IOWR('U', 0x1b, struct snd_ctl_tlv), 853#define SNDRV_CTL_IOCTL_TLV_COMMAND _IOWR('U', 0x1c, struct snd_ctl_tlv)
865 SNDRV_CTL_IOCTL_TLV_COMMAND = _IOWR('U', 0x1c, struct snd_ctl_tlv), 854#define SNDRV_CTL_IOCTL_HWDEP_NEXT_DEVICE _IOWR('U', 0x20, int)
866 SNDRV_CTL_IOCTL_HWDEP_NEXT_DEVICE = _IOWR('U', 0x20, int), 855#define SNDRV_CTL_IOCTL_HWDEP_INFO _IOR('U', 0x21, struct snd_hwdep_info)
867 SNDRV_CTL_IOCTL_HWDEP_INFO = _IOR('U', 0x21, struct snd_hwdep_info), 856#define SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE _IOR('U', 0x30, int)
868 SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE = _IOR('U', 0x30, int), 857#define SNDRV_CTL_IOCTL_PCM_INFO _IOWR('U', 0x31, struct snd_pcm_info)
869 SNDRV_CTL_IOCTL_PCM_INFO = _IOWR('U', 0x31, struct snd_pcm_info), 858#define SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE _IOW('U', 0x32, int)
870 SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE = _IOW('U', 0x32, int), 859#define SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE _IOWR('U', 0x40, int)
871 SNDRV_CTL_IOCTL_RAWMIDI_NEXT_DEVICE = _IOWR('U', 0x40, int), 860#define SNDRV_CTL_IOCTL_RAWMIDI_INFO _IOWR('U', 0x41, struct snd_rawmidi_info)
872 SNDRV_CTL_IOCTL_RAWMIDI_INFO = _IOWR('U', 0x41, struct snd_rawmidi_info), 861#define SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE _IOW('U', 0x42, int)
873 SNDRV_CTL_IOCTL_RAWMIDI_PREFER_SUBDEVICE = _IOW('U', 0x42, int), 862#define SNDRV_CTL_IOCTL_POWER _IOWR('U', 0xd0, int)
874 SNDRV_CTL_IOCTL_POWER = _IOWR('U', 0xd0, int), 863#define SNDRV_CTL_IOCTL_POWER_STATE _IOR('U', 0xd1, int)
875 SNDRV_CTL_IOCTL_POWER_STATE = _IOR('U', 0xd1, int),
876};
877 864
878/* 865/*
879 * Read interface. 866 * Read interface.
@@ -919,18 +906,4 @@ struct snd_ctl_event {
919#define SNDRV_CTL_NAME_IEC958_PCM_STREAM "PCM Stream" 906#define SNDRV_CTL_NAME_IEC958_PCM_STREAM "PCM Stream"
920#define SNDRV_CTL_NAME_IEC958(expl,direction,what) "IEC958 " expl SNDRV_CTL_NAME_##direction SNDRV_CTL_NAME_IEC958_##what 907#define SNDRV_CTL_NAME_IEC958(expl,direction,what) "IEC958 " expl SNDRV_CTL_NAME_##direction SNDRV_CTL_NAME_IEC958_##what
921 908
922/*
923 *
924 */
925
926struct snd_xferv {
927 const struct iovec *vector;
928 unsigned long count;
929};
930
931enum {
932 SNDRV_IOCTL_READV = _IOW('K', 0x00, struct snd_xferv),
933 SNDRV_IOCTL_WRITEV = _IOW('K', 0x01, struct snd_xferv),
934};
935
936#endif /* __SOUND_ASOUND_H */ 909#endif /* __SOUND_ASOUND_H */
diff --git a/include/sound/atmel-abdac.h b/include/sound/atmel-abdac.h
new file mode 100644
index 000000000000..edff6a8ba1b5
--- /dev/null
+++ b/include/sound/atmel-abdac.h
@@ -0,0 +1,23 @@
1/*
2 * Driver for the Atmel Audio Bitstream DAC (ABDAC)
3 *
4 * Copyright (C) 2009 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10#ifndef __INCLUDE_SOUND_ATMEL_ABDAC_H
11#define __INCLUDE_SOUND_ATMEL_ABDAC_H
12
13#include <linux/dw_dmac.h>
14
15/**
16 * struct atmel_abdac_pdata - board specific ABDAC configuration
17 * @dws: DMA slave interface to use for sound playback.
18 */
19struct atmel_abdac_pdata {
20 struct dw_dma_slave dws;
21};
22
23#endif /* __INCLUDE_SOUND_ATMEL_ABDAC_H */
diff --git a/include/sound/atmel-ac97c.h b/include/sound/atmel-ac97c.h
new file mode 100644
index 000000000000..e6aabdb45865
--- /dev/null
+++ b/include/sound/atmel-ac97c.h
@@ -0,0 +1,40 @@
1/*
2 * Driver for the Atmel AC97C controller
3 *
4 * Copyright (C) 2005-2009 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10#ifndef __INCLUDE_SOUND_ATMEL_AC97C_H
11#define __INCLUDE_SOUND_ATMEL_AC97C_H
12
13#include <linux/dw_dmac.h>
14
15#define AC97C_CAPTURE 0x01
16#define AC97C_PLAYBACK 0x02
17#define AC97C_BOTH (AC97C_CAPTURE | AC97C_PLAYBACK)
18
19/**
20 * struct atmel_ac97c_pdata - board specific AC97C configuration
21 * @rx_dws: DMA slave interface to use for sound capture.
22 * @tx_dws: DMA slave interface to use for sound playback.
23 * @reset_pin: GPIO pin wired to the reset input on the external AC97 codec,
24 * optional to use, set to -ENODEV if not in use. AC97 layer will
25 * try to do a software reset of the external codec anyway.
26 * @flags: Flags for which directions should be enabled.
27 *
28 * If the user do not want to use a DMA channel for playback or capture, i.e.
29 * only one feature is required on the board. The slave for playback or capture
30 * can be set to NULL. The AC97C driver will take use of this when setting up
31 * the sound streams.
32 */
33struct ac97c_platform_data {
34 struct dw_dma_slave rx_dws;
35 struct dw_dma_slave tx_dws;
36 unsigned int flags;
37 int reset_pin;
38};
39
40#endif /* __INCLUDE_SOUND_ATMEL_AC97C_H */
diff --git a/include/sound/control.h b/include/sound/control.h
index 4721b4bba053..ef96f07aa03b 100644
--- a/include/sound/control.h
+++ b/include/sound/control.h
@@ -171,6 +171,54 @@ int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
171 */ 171 */
172struct snd_kcontrol *snd_ctl_make_virtual_master(char *name, 172struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
173 const unsigned int *tlv); 173 const unsigned int *tlv);
174int snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave); 174int _snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave,
175 175 unsigned int flags);
176/* optional flags for slave */
177#define SND_CTL_SLAVE_NEED_UPDATE (1 << 0)
178
179/**
180 * snd_ctl_add_slave - Add a virtual slave control
181 * @master: vmaster element
182 * @slave: slave element to add
183 *
184 * Add a virtual slave control to the given master element created via
185 * snd_ctl_create_virtual_master() beforehand.
186 * Returns zero if successful or a negative error code.
187 *
188 * All slaves must be the same type (returning the same information
189 * via info callback). The fucntion doesn't check it, so it's your
190 * responsibility.
191 *
192 * Also, some additional limitations:
193 * at most two channels,
194 * logarithmic volume control (dB level) thus no linear volume,
195 * master can only attenuate the volume without gain
196 */
197static inline int
198snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave)
199{
200 return _snd_ctl_add_slave(master, slave, 0);
201}
202
203/**
204 * snd_ctl_add_slave_uncached - Add a virtual slave control
205 * @master: vmaster element
206 * @slave: slave element to add
207 *
208 * Add a virtual slave control to the given master.
209 * Unlike snd_ctl_add_slave(), the element added via this function
210 * is supposed to have volatile values, and get callback is called
211 * at each time quried from the master.
212 *
213 * When the control peeks the hardware values directly and the value
214 * can be changed by other means than the put callback of the element,
215 * this function should be used to keep the value always up-to-date.
216 */
217static inline int
218snd_ctl_add_slave_uncached(struct snd_kcontrol *master,
219 struct snd_kcontrol *slave)
220{
221 return _snd_ctl_add_slave(master, slave, SND_CTL_SLAVE_NEED_UPDATE);
222}
223
176#endif /* __SOUND_CONTROL_H */ 224#endif /* __SOUND_CONTROL_H */
diff --git a/include/sound/core.h b/include/sound/core.h
index f632484bc743..3dea79829acc 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -97,9 +97,9 @@ struct snd_device {
97 97
98struct snd_monitor_file { 98struct snd_monitor_file {
99 struct file *file; 99 struct file *file;
100 struct snd_monitor_file *next;
101 const struct file_operations *disconnected_f_op; 100 const struct file_operations *disconnected_f_op;
102 struct list_head shutdown_list; 101 struct list_head shutdown_list; /* still need to shutdown */
102 struct list_head list; /* link of monitor files */
103}; 103};
104 104
105/* main structure for soundcard */ 105/* main structure for soundcard */
@@ -134,7 +134,7 @@ struct snd_card {
134 struct snd_info_entry *proc_id; /* the card id */ 134 struct snd_info_entry *proc_id; /* the card id */
135 struct proc_dir_entry *proc_root_link; /* number link to real id */ 135 struct proc_dir_entry *proc_root_link; /* number link to real id */
136 136
137 struct snd_monitor_file *files; /* all files associated to this card */ 137 struct list_head files_list; /* all files associated to this card */
138 struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown 138 struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown
139 state */ 139 state */
140 spinlock_t files_lock; /* lock the files for this card */ 140 spinlock_t files_lock; /* lock the files for this card */
@@ -296,8 +296,20 @@ int snd_card_locked(int card);
296extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd); 296extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
297#endif 297#endif
298 298
299int snd_card_create(int idx, const char *id,
300 struct module *module, int extra_size,
301 struct snd_card **card_ret);
302
303static inline __deprecated
299struct snd_card *snd_card_new(int idx, const char *id, 304struct snd_card *snd_card_new(int idx, const char *id,
300 struct module *module, int extra_size); 305 struct module *module, int extra_size)
306{
307 struct snd_card *card;
308 if (snd_card_create(idx, id, module, extra_size, &card) < 0)
309 return NULL;
310 return card;
311}
312
301int snd_card_disconnect(struct snd_card *card); 313int snd_card_disconnect(struct snd_card *card);
302int snd_card_free(struct snd_card *card); 314int snd_card_free(struct snd_card *card);
303int snd_card_free_when_closed(struct snd_card *card); 315int snd_card_free_when_closed(struct snd_card *card);
@@ -446,21 +458,33 @@ static inline int __snd_bug_on(int cond)
446struct snd_pci_quirk { 458struct snd_pci_quirk {
447 unsigned short subvendor; /* PCI subvendor ID */ 459 unsigned short subvendor; /* PCI subvendor ID */
448 unsigned short subdevice; /* PCI subdevice ID */ 460 unsigned short subdevice; /* PCI subdevice ID */
461 unsigned short subdevice_mask; /* bitmask to match */
449 int value; /* value */ 462 int value; /* value */
450#ifdef CONFIG_SND_DEBUG_VERBOSE 463#ifdef CONFIG_SND_DEBUG_VERBOSE
451 const char *name; /* name of the device (optional) */ 464 const char *name; /* name of the device (optional) */
452#endif 465#endif
453}; 466};
454 467
455#define _SND_PCI_QUIRK_ID(vend,dev) \ 468#define _SND_PCI_QUIRK_ID_MASK(vend, mask, dev) \
456 .subvendor = (vend), .subdevice = (dev) 469 .subvendor = (vend), .subdevice = (dev), .subdevice_mask = (mask)
470#define _SND_PCI_QUIRK_ID(vend, dev) \
471 _SND_PCI_QUIRK_ID_MASK(vend, 0xffff, dev)
457#define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)} 472#define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)}
458#ifdef CONFIG_SND_DEBUG_VERBOSE 473#ifdef CONFIG_SND_DEBUG_VERBOSE
459#define SND_PCI_QUIRK(vend,dev,xname,val) \ 474#define SND_PCI_QUIRK(vend,dev,xname,val) \
460 {_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)} 475 {_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)}
476#define SND_PCI_QUIRK_VENDOR(vend, xname, val) \
477 {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val), .name = (xname)}
478#define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \
479 {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), \
480 .value = (val), .name = (xname)}
461#else 481#else
462#define SND_PCI_QUIRK(vend,dev,xname,val) \ 482#define SND_PCI_QUIRK(vend,dev,xname,val) \
463 {_SND_PCI_QUIRK_ID(vend, dev), .value = (val)} 483 {_SND_PCI_QUIRK_ID(vend, dev), .value = (val)}
484#define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \
485 {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), .value = (val)}
486#define SND_PCI_QUIRK_VENDOR(vend, xname, val) \
487 {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val)}
464#endif 488#endif
465 489
466const struct snd_pci_quirk * 490const struct snd_pci_quirk *
diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
index d9eea013c753..8c05e47a4090 100644
--- a/include/sound/hwdep.h
+++ b/include/sound/hwdep.h
@@ -27,18 +27,28 @@
27 27
28struct snd_hwdep; 28struct snd_hwdep;
29 29
30/* hwdep file ops; all ops can be NULL */
30struct snd_hwdep_ops { 31struct snd_hwdep_ops {
31 long long (*llseek) (struct snd_hwdep *hw, struct file * file, long long offset, int orig); 32 long long (*llseek)(struct snd_hwdep *hw, struct file *file,
32 long (*read) (struct snd_hwdep *hw, char __user *buf, long count, loff_t *offset); 33 long long offset, int orig);
33 long (*write) (struct snd_hwdep *hw, const char __user *buf, long count, loff_t *offset); 34 long (*read)(struct snd_hwdep *hw, char __user *buf,
34 int (*open) (struct snd_hwdep * hw, struct file * file); 35 long count, loff_t *offset);
35 int (*release) (struct snd_hwdep *hw, struct file * file); 36 long (*write)(struct snd_hwdep *hw, const char __user *buf,
36 unsigned int (*poll) (struct snd_hwdep *hw, struct file * file, poll_table * wait); 37 long count, loff_t *offset);
37 int (*ioctl) (struct snd_hwdep *hw, struct file * file, unsigned int cmd, unsigned long arg); 38 int (*open)(struct snd_hwdep *hw, struct file * file);
38 int (*ioctl_compat) (struct snd_hwdep *hw, struct file * file, unsigned int cmd, unsigned long arg); 39 int (*release)(struct snd_hwdep *hw, struct file * file);
39 int (*mmap) (struct snd_hwdep *hw, struct file * file, struct vm_area_struct * vma); 40 unsigned int (*poll)(struct snd_hwdep *hw, struct file *file,
40 int (*dsp_status) (struct snd_hwdep *hw, struct snd_hwdep_dsp_status *status); 41 poll_table *wait);
41 int (*dsp_load) (struct snd_hwdep *hw, struct snd_hwdep_dsp_image *image); 42 int (*ioctl)(struct snd_hwdep *hw, struct file *file,
43 unsigned int cmd, unsigned long arg);
44 int (*ioctl_compat)(struct snd_hwdep *hw, struct file *file,
45 unsigned int cmd, unsigned long arg);
46 int (*mmap)(struct snd_hwdep *hw, struct file *file,
47 struct vm_area_struct *vma);
48 int (*dsp_status)(struct snd_hwdep *hw,
49 struct snd_hwdep_dsp_status *status);
50 int (*dsp_load)(struct snd_hwdep *hw,
51 struct snd_hwdep_dsp_image *image);
42}; 52};
43 53
44struct snd_hwdep { 54struct snd_hwdep {
@@ -61,9 +71,9 @@ struct snd_hwdep {
61 void (*private_free) (struct snd_hwdep *hwdep); 71 void (*private_free) (struct snd_hwdep *hwdep);
62 72
63 struct mutex open_mutex; 73 struct mutex open_mutex;
64 int used; 74 int used; /* reference counter */
65 unsigned int dsp_loaded; 75 unsigned int dsp_loaded; /* bit fields of loaded dsp indices */
66 unsigned int exclusive: 1; 76 unsigned int exclusive:1; /* exclusive access mode */
67}; 77};
68 78
69extern int snd_hwdep_new(struct snd_card *card, char *id, int device, 79extern int snd_hwdep_new(struct snd_card *card, char *id, int device,
diff --git a/include/sound/jack.h b/include/sound/jack.h
index 2e0315cdd0d6..6b013c6f6a04 100644
--- a/include/sound/jack.h
+++ b/include/sound/jack.h
@@ -30,6 +30,9 @@ struct input_dev;
30/** 30/**
31 * Jack types which can be reported. These values are used as a 31 * Jack types which can be reported. These values are used as a
32 * bitmask. 32 * bitmask.
33 *
34 * Note that this must be kept in sync with the lookup table in
35 * sound/core/jack.c.
33 */ 36 */
34enum snd_jack_types { 37enum snd_jack_types {
35 SND_JACK_HEADPHONE = 0x0001, 38 SND_JACK_HEADPHONE = 0x0001,
@@ -37,6 +40,8 @@ enum snd_jack_types {
37 SND_JACK_HEADSET = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE, 40 SND_JACK_HEADSET = SND_JACK_HEADPHONE | SND_JACK_MICROPHONE,
38 SND_JACK_LINEOUT = 0x0004, 41 SND_JACK_LINEOUT = 0x0004,
39 SND_JACK_MECHANICAL = 0x0008, /* If detected separately */ 42 SND_JACK_MECHANICAL = 0x0008, /* If detected separately */
43 SND_JACK_VIDEOOUT = 0x0010,
44 SND_JACK_AVOUT = SND_JACK_LINEOUT | SND_JACK_VIDEOOUT,
40}; 45};
41 46
42struct snd_jack { 47struct snd_jack {
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 40c5a6fa6bcd..8904b1900d7f 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -364,7 +364,6 @@ struct snd_pcm_substream {
364 /* -- timer section -- */ 364 /* -- timer section -- */
365 struct snd_timer *timer; /* timer */ 365 struct snd_timer *timer; /* timer */
366 unsigned timer_running: 1; /* time is running */ 366 unsigned timer_running: 1; /* time is running */
367 spinlock_t timer_lock;
368 /* -- next substream -- */ 367 /* -- next substream -- */
369 struct snd_pcm_substream *next; 368 struct snd_pcm_substream *next;
370 /* -- linked substreams -- */ 369 /* -- linked substreams -- */
@@ -451,7 +450,7 @@ struct snd_pcm_notify {
451 450
452extern const struct file_operations snd_pcm_f_ops[2]; 451extern const struct file_operations snd_pcm_f_ops[2];
453 452
454int snd_pcm_new(struct snd_card *card, char *id, int device, 453int snd_pcm_new(struct snd_card *card, const char *id, int device,
455 int playback_count, int capture_count, 454 int playback_count, int capture_count,
456 struct snd_pcm **rpcm); 455 struct snd_pcm **rpcm);
457int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count); 456int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count);
diff --git a/include/sound/pxa2xx-lib.h b/include/sound/pxa2xx-lib.h
index 2fd3d251d9a5..2c894b600e5b 100644
--- a/include/sound/pxa2xx-lib.h
+++ b/include/sound/pxa2xx-lib.h
@@ -42,4 +42,19 @@ extern int pxa2xx_ac97_hw_resume(void);
42extern int pxa2xx_ac97_hw_probe(struct platform_device *dev); 42extern int pxa2xx_ac97_hw_probe(struct platform_device *dev);
43extern void pxa2xx_ac97_hw_remove(struct platform_device *dev); 43extern void pxa2xx_ac97_hw_remove(struct platform_device *dev);
44 44
45/* AC97 platform_data */
46/**
47 * struct pxa2xx_ac97_platform_data - pxa ac97 platform data
48 * @reset_gpio: AC97 reset gpio (normally gpio113 or gpio95)
49 * a -1 value means no gpio will be used for reset
50 *
51 * Platform data should only be specified for pxa27x CPUs where a silicon bug
52 * prevents correct operation of the reset line. If not specified, the default
53 * behaviour is to consider gpio 113 as the AC97 reset line, which is the
54 * default on most boards.
55 */
56struct pxa2xx_ac97_platform_data {
57 int reset_gpio;
58};
59
45#endif 60#endif
diff --git a/include/sound/rawmidi.h b/include/sound/rawmidi.h
index b550a416d075..c23c26585700 100644
--- a/include/sound/rawmidi.h
+++ b/include/sound/rawmidi.h
@@ -42,7 +42,6 @@
42#define SNDRV_RAWMIDI_LFLG_INPUT (1<<1) 42#define SNDRV_RAWMIDI_LFLG_INPUT (1<<1)
43#define SNDRV_RAWMIDI_LFLG_OPEN (3<<0) 43#define SNDRV_RAWMIDI_LFLG_OPEN (3<<0)
44#define SNDRV_RAWMIDI_LFLG_APPEND (1<<2) 44#define SNDRV_RAWMIDI_LFLG_APPEND (1<<2)
45#define SNDRV_RAWMIDI_LFLG_NOOPENLOCK (1<<3)
46 45
47struct snd_rawmidi; 46struct snd_rawmidi;
48struct snd_rawmidi_substream; 47struct snd_rawmidi_substream;
diff --git a/include/sound/sb.h b/include/sound/sb.h
index 85f93c5fe1e4..4e62ee1e4115 100644
--- a/include/sound/sb.h
+++ b/include/sound/sb.h
@@ -249,6 +249,7 @@ struct snd_sb {
249#define SB_ALS4000_3D_AUTO_MUTE 0x52 249#define SB_ALS4000_3D_AUTO_MUTE 0x52
250#define SB_ALS4000_ANALOG_BLOCK_CTRL 0x53 250#define SB_ALS4000_ANALOG_BLOCK_CTRL 0x53
251#define SB_ALS4000_3D_DELAYLINE_PATTERN 0x54 251#define SB_ALS4000_3D_DELAYLINE_PATTERN 0x54
252#define SB_ALS4000_CR3_CONFIGURATION 0xc3 /* bit 7 is Digital Loop Enable */
252#define SB_ALS4000_QSOUND 0xdb 253#define SB_ALS4000_QSOUND 0xdb
253 254
254/* IRQ setting bitmap */ 255/* IRQ setting bitmap */
@@ -330,7 +331,8 @@ enum {
330 SB_MIX_DOUBLE, 331 SB_MIX_DOUBLE,
331 SB_MIX_INPUT_SW, 332 SB_MIX_INPUT_SW,
332 SB_MIX_CAPTURE_PRO, 333 SB_MIX_CAPTURE_PRO,
333 SB_MIX_CAPTURE_DT019X 334 SB_MIX_CAPTURE_DT019X,
335 SB_MIX_MONO_CAPTURE_ALS4K
334}; 336};
335 337
336#define SB_MIXVAL_DOUBLE(left_reg, right_reg, left_shift, right_shift, mask) \ 338#define SB_MIXVAL_DOUBLE(left_reg, right_reg, left_shift, right_shift, mask) \
diff --git a/include/sound/sfnt_info.h b/include/sound/sfnt_info.h
index 5d1ab9c4950f..1bce7fd1725f 100644
--- a/include/sound/sfnt_info.h
+++ b/include/sound/sfnt_info.h
@@ -202,13 +202,11 @@ struct snd_emux_misc_mode {
202 int value2; /* reserved */ 202 int value2; /* reserved */
203}; 203};
204 204
205enum { 205#define SNDRV_EMUX_IOCTL_VERSION _IOR('H', 0x80, unsigned int)
206 SNDRV_EMUX_IOCTL_VERSION = _IOR('H', 0x80, unsigned int), 206#define SNDRV_EMUX_IOCTL_LOAD_PATCH _IOWR('H', 0x81, struct soundfont_patch_info)
207 SNDRV_EMUX_IOCTL_LOAD_PATCH = _IOWR('H', 0x81, struct soundfont_patch_info), 207#define SNDRV_EMUX_IOCTL_RESET_SAMPLES _IO('H', 0x82)
208 SNDRV_EMUX_IOCTL_RESET_SAMPLES = _IO('H', 0x82), 208#define SNDRV_EMUX_IOCTL_REMOVE_LAST_SAMPLES _IO('H', 0x83)
209 SNDRV_EMUX_IOCTL_REMOVE_LAST_SAMPLES = _IO('H', 0x83), 209#define SNDRV_EMUX_IOCTL_MEM_AVAIL _IOW('H', 0x84, int)
210 SNDRV_EMUX_IOCTL_MEM_AVAIL = _IOW('H', 0x84, int), 210#define SNDRV_EMUX_IOCTL_MISC_MODE _IOWR('H', 0x84, struct snd_emux_misc_mode)
211 SNDRV_EMUX_IOCTL_MISC_MODE = _IOWR('H', 0x84, struct snd_emux_misc_mode),
212};
213 211
214#endif /* __SOUND_SFNT_INFO_H */ 212#endif /* __SOUND_SFNT_INFO_H */
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index 24247f763608..13676472ddfc 100644
--- a/include/sound/soc-dai.h
+++ b/include/sound/soc-dai.h
@@ -203,7 +203,7 @@ struct snd_soc_dai {
203 int (*resume)(struct snd_soc_dai *dai); 203 int (*resume)(struct snd_soc_dai *dai);
204 204
205 /* ops */ 205 /* ops */
206 struct snd_soc_dai_ops ops; 206 struct snd_soc_dai_ops *ops;
207 207
208 /* DAI capabilities */ 208 /* DAI capabilities */
209 struct snd_soc_pcm_stream capture; 209 struct snd_soc_pcm_stream capture;
diff --git a/include/sound/soc-dapm.h b/include/sound/soc-dapm.h
index dfa804958820..a7def6a9a030 100644
--- a/include/sound/soc-dapm.h
+++ b/include/sound/soc-dapm.h
@@ -76,6 +76,11 @@
76 wcontrols, wncontrols)\ 76 wcontrols, wncontrols)\
77{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \ 77{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \
78 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols} 78 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols}
79#define SND_SOC_DAPM_MIXER_NAMED_CTL(wname, wreg, wshift, winvert, \
80 wcontrols, wncontrols)\
81{ .id = snd_soc_dapm_mixer_named_ctl, .name = wname, .reg = wreg, \
82 .shift = wshift, .invert = winvert, .kcontrols = wcontrols, \
83 .num_kcontrols = wncontrols}
79#define SND_SOC_DAPM_MICBIAS(wname, wreg, wshift, winvert) \ 84#define SND_SOC_DAPM_MICBIAS(wname, wreg, wshift, winvert) \
80{ .id = snd_soc_dapm_micbias, .name = wname, .reg = wreg, .shift = wshift, \ 85{ .id = snd_soc_dapm_micbias, .name = wname, .reg = wreg, .shift = wshift, \
81 .invert = winvert, .kcontrols = NULL, .num_kcontrols = 0} 86 .invert = winvert, .kcontrols = NULL, .num_kcontrols = 0}
@@ -101,6 +106,11 @@
101{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \ 106{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \
102 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols, \ 107 .invert = winvert, .kcontrols = wcontrols, .num_kcontrols = wncontrols, \
103 .event = wevent, .event_flags = wflags} 108 .event = wevent, .event_flags = wflags}
109#define SND_SOC_DAPM_MIXER_NAMED_CTL_E(wname, wreg, wshift, winvert, \
110 wcontrols, wncontrols, wevent, wflags) \
111{ .id = snd_soc_dapm_mixer, .name = wname, .reg = wreg, .shift = wshift, \
112 .invert = winvert, .kcontrols = wcontrols, \
113 .num_kcontrols = wncontrols, .event = wevent, .event_flags = wflags}
104#define SND_SOC_DAPM_MICBIAS_E(wname, wreg, wshift, winvert, wevent, wflags) \ 114#define SND_SOC_DAPM_MICBIAS_E(wname, wreg, wshift, winvert, wevent, wflags) \
105{ .id = snd_soc_dapm_micbias, .name = wname, .reg = wreg, .shift = wshift, \ 115{ .id = snd_soc_dapm_micbias, .name = wname, .reg = wreg, .shift = wshift, \
106 .invert = winvert, .kcontrols = NULL, .num_kcontrols = 0, \ 116 .invert = winvert, .kcontrols = NULL, .num_kcontrols = 0, \
@@ -182,6 +192,12 @@
182 .get = snd_soc_dapm_get_value_enum_double, \ 192 .get = snd_soc_dapm_get_value_enum_double, \
183 .put = snd_soc_dapm_put_value_enum_double, \ 193 .put = snd_soc_dapm_put_value_enum_double, \
184 .private_value = (unsigned long)&xenum } 194 .private_value = (unsigned long)&xenum }
195#define SOC_DAPM_PIN_SWITCH(xname) \
196{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname " Switch", \
197 .info = snd_soc_dapm_info_pin_switch, \
198 .get = snd_soc_dapm_get_pin_switch, \
199 .put = snd_soc_dapm_put_pin_switch, \
200 .private_value = (unsigned long)xname }
185 201
186/* dapm stream operations */ 202/* dapm stream operations */
187#define SND_SOC_DAPM_STREAM_NOP 0x0 203#define SND_SOC_DAPM_STREAM_NOP 0x0
@@ -228,6 +244,12 @@ int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
228 struct snd_ctl_elem_value *ucontrol); 244 struct snd_ctl_elem_value *ucontrol);
229int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol, 245int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
230 struct snd_ctl_elem_value *ucontrol); 246 struct snd_ctl_elem_value *ucontrol);
247int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
248 struct snd_ctl_elem_info *uinfo);
249int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
250 struct snd_ctl_elem_value *uncontrol);
251int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
252 struct snd_ctl_elem_value *uncontrol);
231int snd_soc_dapm_new_control(struct snd_soc_codec *codec, 253int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
232 const struct snd_soc_dapm_widget *widget); 254 const struct snd_soc_dapm_widget *widget);
233int snd_soc_dapm_new_controls(struct snd_soc_codec *codec, 255int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
@@ -250,10 +272,10 @@ int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
250int snd_soc_dapm_sys_add(struct device *dev); 272int snd_soc_dapm_sys_add(struct device *dev);
251 273
252/* dapm audio pin control and status */ 274/* dapm audio pin control and status */
253int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, char *pin); 275int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin);
254int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, char *pin); 276int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin);
255int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, char *pin); 277int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin);
256int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, char *pin); 278int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin);
257int snd_soc_dapm_sync(struct snd_soc_codec *codec); 279int snd_soc_dapm_sync(struct snd_soc_codec *codec);
258 280
259/* dapm widget types */ 281/* dapm widget types */
@@ -263,6 +285,7 @@ enum snd_soc_dapm_type {
263 snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */ 285 snd_soc_dapm_mux, /* selects 1 analog signal from many inputs */
264 snd_soc_dapm_value_mux, /* selects 1 analog signal from many inputs */ 286 snd_soc_dapm_value_mux, /* selects 1 analog signal from many inputs */
265 snd_soc_dapm_mixer, /* mixes several analog signals together */ 287 snd_soc_dapm_mixer, /* mixes several analog signals together */
288 snd_soc_dapm_mixer_named_ctl, /* mixer with named controls */
266 snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */ 289 snd_soc_dapm_pga, /* programmable gain/attenuation (volume) */
267 snd_soc_dapm_adc, /* analog to digital converter */ 290 snd_soc_dapm_adc, /* analog to digital converter */
268 snd_soc_dapm_dac, /* digital to analog converter */ 291 snd_soc_dapm_dac, /* digital to analog converter */
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 24593ac3ea19..a40bc6f316fc 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -16,6 +16,8 @@
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/types.h> 17#include <linux/types.h>
18#include <linux/workqueue.h> 18#include <linux/workqueue.h>
19#include <linux/interrupt.h>
20#include <linux/kernel.h>
19#include <sound/core.h> 21#include <sound/core.h>
20#include <sound/pcm.h> 22#include <sound/pcm.h>
21#include <sound/control.h> 23#include <sound/control.h>
@@ -154,6 +156,8 @@ enum snd_soc_bias_level {
154 SND_SOC_BIAS_OFF, 156 SND_SOC_BIAS_OFF,
155}; 157};
156 158
159struct snd_jack;
160struct snd_soc_card;
157struct snd_soc_device; 161struct snd_soc_device;
158struct snd_soc_pcm_stream; 162struct snd_soc_pcm_stream;
159struct snd_soc_ops; 163struct snd_soc_ops;
@@ -164,6 +168,11 @@ struct snd_soc_platform;
164struct snd_soc_codec; 168struct snd_soc_codec;
165struct soc_enum; 169struct soc_enum;
166struct snd_soc_ac97_ops; 170struct snd_soc_ac97_ops;
171struct snd_soc_jack;
172struct snd_soc_jack_pin;
173#ifdef CONFIG_GPIOLIB
174struct snd_soc_jack_gpio;
175#endif
167 176
168typedef int (*hw_write_t)(void *,const char* ,int); 177typedef int (*hw_write_t)(void *,const char* ,int);
169typedef int (*hw_read_t)(void *,char* ,int); 178typedef int (*hw_read_t)(void *,char* ,int);
@@ -184,6 +193,19 @@ int snd_soc_init_card(struct snd_soc_device *socdev);
184int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream, 193int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
185 const struct snd_pcm_hardware *hw); 194 const struct snd_pcm_hardware *hw);
186 195
196/* Jack reporting */
197int snd_soc_jack_new(struct snd_soc_card *card, const char *id, int type,
198 struct snd_soc_jack *jack);
199void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
200int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
201 struct snd_soc_jack_pin *pins);
202#ifdef CONFIG_GPIOLIB
203int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
204 struct snd_soc_jack_gpio *gpios);
205void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
206 struct snd_soc_jack_gpio *gpios);
207#endif
208
187/* codec IO */ 209/* codec IO */
188#define snd_soc_read(codec, reg) codec->read(codec, reg) 210#define snd_soc_read(codec, reg) codec->read(codec, reg)
189#define snd_soc_write(codec, reg, value) codec->write(codec, reg, value) 211#define snd_soc_write(codec, reg, value) codec->write(codec, reg, value)
@@ -203,6 +225,8 @@ void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
203 */ 225 */
204struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template, 226struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
205 void *data, char *long_name); 227 void *data, char *long_name);
228int snd_soc_add_controls(struct snd_soc_codec *codec,
229 const struct snd_kcontrol_new *controls, int num_controls);
206int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol, 230int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
207 struct snd_ctl_elem_info *uinfo); 231 struct snd_ctl_elem_info *uinfo);
208int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol, 232int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
@@ -237,6 +261,48 @@ int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
237int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol, 261int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
238 struct snd_ctl_elem_value *ucontrol); 262 struct snd_ctl_elem_value *ucontrol);
239 263
264/**
265 * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
266 *
267 * @pin: name of the pin to update
268 * @mask: bits to check for in reported jack status
269 * @invert: if non-zero then pin is enabled when status is not reported
270 */
271struct snd_soc_jack_pin {
272 struct list_head list;
273 const char *pin;
274 int mask;
275 bool invert;
276};
277
278/**
279 * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
280 *
281 * @gpio: gpio number
282 * @name: gpio name
283 * @report: value to report when jack detected
284 * @invert: report presence in low state
285 * @debouce_time: debouce time in ms
286 */
287#ifdef CONFIG_GPIOLIB
288struct snd_soc_jack_gpio {
289 unsigned int gpio;
290 const char *name;
291 int report;
292 int invert;
293 int debounce_time;
294 struct snd_soc_jack *jack;
295 struct work_struct work;
296};
297#endif
298
299struct snd_soc_jack {
300 struct snd_jack *jack;
301 struct snd_soc_card *card;
302 struct list_head pins;
303 int status;
304};
305
240/* SoC PCM stream information */ 306/* SoC PCM stream information */
241struct snd_soc_pcm_stream { 307struct snd_soc_pcm_stream {
242 char *stream_name; 308 char *stream_name;
@@ -384,6 +450,8 @@ struct snd_soc_card {
384 450
385 struct snd_soc_device *socdev; 451 struct snd_soc_device *socdev;
386 452
453 struct snd_soc_codec *codec;
454
387 struct snd_soc_platform *platform; 455 struct snd_soc_platform *platform;
388 struct delayed_work delayed_work; 456 struct delayed_work delayed_work;
389 struct work_struct deferred_resume_work; 457 struct work_struct deferred_resume_work;
@@ -393,7 +461,6 @@ struct snd_soc_card {
393struct snd_soc_device { 461struct snd_soc_device {
394 struct device *dev; 462 struct device *dev;
395 struct snd_soc_card *card; 463 struct snd_soc_card *card;
396 struct snd_soc_codec *codec;
397 struct snd_soc_codec_device *codec_dev; 464 struct snd_soc_codec_device *codec_dev;
398 void *codec_data; 465 void *codec_data;
399}; 466};
diff --git a/include/sound/uda1341.h b/include/sound/uda1341.h
deleted file mode 100644
index 110d5dc3a2be..000000000000
--- a/include/sound/uda1341.h
+++ /dev/null
@@ -1,126 +0,0 @@
1/*
2 * linux/include/linux/l3/uda1341.h
3 *
4 * Philips UDA1341 mixer device driver for ALSA
5 *
6 * Copyright (c) 2002 Tomas Kasparek <tomas.kasparek@seznam.cz>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License.
10 *
11 * History:
12 *
13 * 2002-03-13 Tomas Kasparek Initial release - based on uda1341.h from OSS
14 * 2002-03-30 Tomas Kasparek Proc filesystem support, complete mixer and DSP
15 * features support
16 */
17
18#define UDA1341_ALSA_NAME "snd-uda1341"
19
20/*
21 * Default rate set after inicialization
22 */
23#define AUDIO_RATE_DEFAULT 44100
24
25/*
26 * UDA1341 L3 address and command types
27 */
28#define UDA1341_L3ADDR 5
29#define UDA1341_DATA0 (UDA1341_L3ADDR << 2 | 0)
30#define UDA1341_DATA1 (UDA1341_L3ADDR << 2 | 1)
31#define UDA1341_STATUS (UDA1341_L3ADDR << 2 | 2)
32
33enum uda1341_onoff {
34 OFF=0,
35 ON,
36};
37
38enum uda1341_format {
39 I2S=0,
40 LSB16,
41 LSB18,
42 LSB20,
43 MSB,
44 LSB16MSB,
45 LSB18MSB,
46 LSB20MSB,
47};
48
49enum uda1341_fs {
50 F512=0,
51 F384,
52 F256,
53 Funused,
54};
55
56enum uda1341_peak {
57 BEFORE=0,
58 AFTER,
59};
60
61enum uda1341_filter {
62 FLAT=0,
63 MIN,
64 MIN2,
65 MAX,
66};
67
68enum uda1341_mixer {
69 DOUBLE,
70 LINE,
71 MIC,
72 MIXER,
73};
74
75enum uda1341_deemp {
76 NONE,
77 D32,
78 D44,
79 D48,
80};
81
82enum uda1341_config {
83 CMD_READ_REG = 0,
84 CMD_RESET,
85 CMD_FS,
86 CMD_FORMAT,
87 CMD_OGAIN,
88 CMD_IGAIN,
89 CMD_DAC,
90 CMD_ADC,
91 CMD_VOLUME,
92 CMD_BASS,
93 CMD_TREBBLE,
94 CMD_PEAK,
95 CMD_DEEMP,
96 CMD_MUTE,
97 CMD_FILTER,
98 CMD_CH1,
99 CMD_CH2,
100 CMD_MIC,
101 CMD_MIXER,
102 CMD_AGC,
103 CMD_IG,
104 CMD_AGC_TIME,
105 CMD_AGC_LEVEL,
106#ifdef CONFIG_PM
107 CMD_SUSPEND,
108 CMD_RESUME,
109#endif
110 CMD_LAST,
111};
112
113enum write_through {
114 //used in update_bits (write_cfg) to avoid l3_write - just update local copy of regs.
115 REGS_ONLY=0,
116 //update local regs and write value to uda1341 - do l3_write
117 FLUSH,
118};
119
120int __init snd_chip_uda1341_mixer_new(struct snd_card *card, struct l3_client **clnt);
121
122/*
123 * Local variables:
124 * indent-tabs-mode: t
125 * End:
126 */
diff --git a/include/sound/version.h b/include/sound/version.h
index 2b48237e23bf..a7e74e23ad2e 100644
--- a/include/sound/version.h
+++ b/include/sound/version.h
@@ -1,3 +1,3 @@
1/* include/version.h */ 1/* include/version.h */
2#define CONFIG_SND_VERSION "1.0.18a" 2#define CONFIG_SND_VERSION "1.0.19"
3#define CONFIG_SND_DATE "" 3#define CONFIG_SND_DATE ""
diff --git a/include/sound/wss.h b/include/sound/wss.h
index fd01f22825cd..6d65f322f1d5 100644
--- a/include/sound/wss.h
+++ b/include/sound/wss.h
@@ -154,6 +154,7 @@ int snd_wss_create(struct snd_card *card,
154 unsigned short hardware, 154 unsigned short hardware,
155 unsigned short hwshare, 155 unsigned short hwshare,
156 struct snd_wss **rchip); 156 struct snd_wss **rchip);
157int snd_wss_free(struct snd_wss *chip);
157int snd_wss_pcm(struct snd_wss *chip, int device, struct snd_pcm **rpcm); 158int snd_wss_pcm(struct snd_wss *chip, int device, struct snd_pcm **rpcm);
158int snd_wss_timer(struct snd_wss *chip, int device, struct snd_timer **rtimer); 159int snd_wss_timer(struct snd_wss *chip, int device, struct snd_timer **rtimer);
159int snd_wss_mixer(struct snd_wss *chip); 160int snd_wss_mixer(struct snd_wss *chip);
diff --git a/kernel/module.c b/kernel/module.c
index 1196f5d11700..77672233387f 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -822,7 +822,7 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
822 mutex_lock(&module_mutex); 822 mutex_lock(&module_mutex);
823 /* Store the name of the last unloaded module for diagnostic purposes */ 823 /* Store the name of the last unloaded module for diagnostic purposes */
824 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module)); 824 strlcpy(last_unloaded_module, mod->name, sizeof(last_unloaded_module));
825 unregister_dynamic_debug_module(mod->name); 825 ddebug_remove_module(mod->name);
826 free_module(mod); 826 free_module(mod);
827 827
828 out: 828 out:
@@ -1827,19 +1827,13 @@ static inline void add_kallsyms(struct module *mod,
1827} 1827}
1828#endif /* CONFIG_KALLSYMS */ 1828#endif /* CONFIG_KALLSYMS */
1829 1829
1830static void dynamic_printk_setup(struct mod_debug *debug, unsigned int num) 1830static void dynamic_debug_setup(struct _ddebug *debug, unsigned int num)
1831{ 1831{
1832#ifdef CONFIG_DYNAMIC_PRINTK_DEBUG 1832#ifdef CONFIG_DYNAMIC_DEBUG
1833 unsigned int i; 1833 if (ddebug_add_module(debug, num, debug->modname))
1834 1834 printk(KERN_ERR "dynamic debug error adding module: %s\n",
1835 for (i = 0; i < num; i++) { 1835 debug->modname);
1836 register_dynamic_debug_module(debug[i].modname, 1836#endif
1837 debug[i].type,
1838 debug[i].logical_modname,
1839 debug[i].flag_names,
1840 debug[i].hash, debug[i].hash2);
1841 }
1842#endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */
1843} 1837}
1844 1838
1845static void *module_alloc_update_bounds(unsigned long size) 1839static void *module_alloc_update_bounds(unsigned long size)
@@ -2213,12 +2207,13 @@ static noinline struct module *load_module(void __user *umod,
2213 add_kallsyms(mod, sechdrs, symindex, strindex, secstrings); 2207 add_kallsyms(mod, sechdrs, symindex, strindex, secstrings);
2214 2208
2215 if (!mod->taints) { 2209 if (!mod->taints) {
2216 struct mod_debug *debug; 2210 struct _ddebug *debug;
2217 unsigned int num_debug; 2211 unsigned int num_debug;
2218 2212
2219 debug = section_objs(hdr, sechdrs, secstrings, "__verbose", 2213 debug = section_objs(hdr, sechdrs, secstrings, "__verbose",
2220 sizeof(*debug), &num_debug); 2214 sizeof(*debug), &num_debug);
2221 dynamic_printk_setup(debug, num_debug); 2215 if (debug)
2216 dynamic_debug_setup(debug, num_debug);
2222 } 2217 }
2223 2218
2224 /* sechdrs[0].sh_size is always zero */ 2219 /* sechdrs[0].sh_size is always zero */
diff --git a/lib/Kconfig b/lib/Kconfig
index 03c2c24b9083..cea9e30a88ff 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -174,4 +174,10 @@ config DISABLE_OBSOLETE_CPUMASK_FUNCTIONS
174 bool "Disable obsolete cpumask functions" if DEBUG_PER_CPU_MAPS 174 bool "Disable obsolete cpumask functions" if DEBUG_PER_CPU_MAPS
175 depends on EXPERIMENTAL && BROKEN 175 depends on EXPERIMENTAL && BROKEN
176 176
177#
178# Netlink attribute parsing support is select'ed if needed
179#
180config NLATTR
181 bool
182
177endmenu 183endmenu
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 1bcf9cd4baa0..8fee0a13ac58 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -847,60 +847,70 @@ config BUILD_DOCSRC
847 847
848 Say N if you are unsure. 848 Say N if you are unsure.
849 849
850config DYNAMIC_PRINTK_DEBUG 850config DYNAMIC_DEBUG
851 bool "Enable dynamic printk() call support" 851 bool "Enable dynamic printk() support"
852 default n 852 default n
853 depends on PRINTK 853 depends on PRINTK
854 depends on DEBUG_FS
854 select PRINTK_DEBUG 855 select PRINTK_DEBUG
855 help 856 help
856 857
857 Compiles debug level messages into the kernel, which would not 858 Compiles debug level messages into the kernel, which would not
858 otherwise be available at runtime. These messages can then be 859 otherwise be available at runtime. These messages can then be
859 enabled/disabled on a per module basis. This mechanism implicitly 860 enabled/disabled based on various levels of scope - per source file,
860 enables all pr_debug() and dev_dbg() calls. The impact of this 861 function, module, format string, and line number. This mechanism
861 compile option is a larger kernel text size of about 2%. 862 implicitly enables all pr_debug() and dev_dbg() calls. The impact of
863 this compile option is a larger kernel text size of about 2%.
862 864
863 Usage: 865 Usage:
864 866
865 Dynamic debugging is controlled by the debugfs file, 867 Dynamic debugging is controlled via the 'dynamic_debug/ddebug' file,
866 dynamic_printk/modules. This file contains a list of the modules that 868 which is contained in the 'debugfs' filesystem. Thus, the debugfs
867 can be enabled. The format of the file is the module name, followed 869 filesystem must first be mounted before making use of this feature.
868 by a set of flags that can be enabled. The first flag is always the 870 We refer the control file as: <debugfs>/dynamic_debug/ddebug. This
869 'enabled' flag. For example: 871 file contains a list of the debug statements that can be enabled. The
872 format for each line of the file is:
870 873
871 <module_name> <enabled=0/1> 874 filename:lineno [module]function flags format
872 .
873 .
874 .
875 875
876 <module_name> : Name of the module in which the debug call resides 876 filename : source file of the debug statement
877 <enabled=0/1> : whether the messages are enabled or not 877 lineno : line number of the debug statement
878 module : module that contains the debug statement
879 function : function that contains the debug statement
880 flags : 'p' means the line is turned 'on' for printing
881 format : the format used for the debug statement
878 882
879 From a live system: 883 From a live system:
880 884
881 snd_hda_intel enabled=0 885 nullarbor:~ # cat <debugfs>/dynamic_debug/ddebug
882 fixup enabled=0 886 # filename:lineno [module]function flags format
883 driver enabled=0 887 fs/aio.c:222 [aio]__put_ioctx - "__put_ioctx:\040freeing\040%p\012"
888 fs/aio.c:248 [aio]ioctx_alloc - "ENOMEM:\040nr_events\040too\040high\012"
889 fs/aio.c:1770 [aio]sys_io_cancel - "calling\040cancel\012"
884 890
885 Enable a module: 891 Example usage:
886 892
887 $echo "set enabled=1 <module_name>" > dynamic_printk/modules 893 // enable the message at line 1603 of file svcsock.c
894 nullarbor:~ # echo -n 'file svcsock.c line 1603 +p' >
895 <debugfs>/dynamic_debug/ddebug
888 896
889 Disable a module: 897 // enable all the messages in file svcsock.c
898 nullarbor:~ # echo -n 'file svcsock.c +p' >
899 <debugfs>/dynamic_debug/ddebug
890 900
891 $echo "set enabled=0 <module_name>" > dynamic_printk/modules 901 // enable all the messages in the NFS server module
902 nullarbor:~ # echo -n 'module nfsd +p' >
903 <debugfs>/dynamic_debug/ddebug
892 904
893 Enable all modules: 905 // enable all 12 messages in the function svc_process()
906 nullarbor:~ # echo -n 'func svc_process +p' >
907 <debugfs>/dynamic_debug/ddebug
894 908
895 $echo "set enabled=1 all" > dynamic_printk/modules 909 // disable all 12 messages in the function svc_process()
910 nullarbor:~ # echo -n 'func svc_process -p' >
911 <debugfs>/dynamic_debug/ddebug
896 912
897 Disable all modules: 913 See Documentation/dynamic-debug-howto.txt for additional information.
898
899 $echo "set enabled=0 all" > dynamic_printk/modules
900
901 Finally, passing "dynamic_printk" at the command line enables
902 debugging for all modules. This mode can be turned off via the above
903 disable command.
904 914
905source "samples/Kconfig" 915source "samples/Kconfig"
906 916
diff --git a/lib/Makefile b/lib/Makefile
index 32b0e64ded27..0dd9229fab7e 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -82,7 +82,9 @@ obj-$(CONFIG_HAVE_LMB) += lmb.o
82 82
83obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o 83obj-$(CONFIG_HAVE_ARCH_TRACEHOOK) += syscall.o
84 84
85obj-$(CONFIG_DYNAMIC_PRINTK_DEBUG) += dynamic_printk.o 85obj-$(CONFIG_DYNAMIC_DEBUG) += dynamic_debug.o
86
87obj-$(CONFIG_NLATTR) += nlattr.o
86 88
87hostprogs-y := gen_crc32table 89hostprogs-y := gen_crc32table
88clean-files := crc32table.h 90clean-files := crc32table.h
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
new file mode 100644
index 000000000000..833139ce1e22
--- /dev/null
+++ b/lib/dynamic_debug.c
@@ -0,0 +1,769 @@
1/*
2 * lib/dynamic_debug.c
3 *
4 * make pr_debug()/dev_dbg() calls runtime configurable based upon their
5 * source module.
6 *
7 * Copyright (C) 2008 Jason Baron <jbaron@redhat.com>
8 * By Greg Banks <gnb@melbourne.sgi.com>
9 * Copyright (c) 2008 Silicon Graphics Inc. All Rights Reserved.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/moduleparam.h>
15#include <linux/kallsyms.h>
16#include <linux/version.h>
17#include <linux/types.h>
18#include <linux/mutex.h>
19#include <linux/proc_fs.h>
20#include <linux/seq_file.h>
21#include <linux/list.h>
22#include <linux/sysctl.h>
23#include <linux/ctype.h>
24#include <linux/uaccess.h>
25#include <linux/dynamic_debug.h>
26#include <linux/debugfs.h>
27
28extern struct _ddebug __start___verbose[];
29extern struct _ddebug __stop___verbose[];
30
31/* dynamic_debug_enabled, and dynamic_debug_enabled2 are bitmasks in which
32 * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They
33 * use independent hash functions, to reduce the chance of false positives.
34 */
35long long dynamic_debug_enabled;
36EXPORT_SYMBOL_GPL(dynamic_debug_enabled);
37long long dynamic_debug_enabled2;
38EXPORT_SYMBOL_GPL(dynamic_debug_enabled2);
39
40struct ddebug_table {
41 struct list_head link;
42 char *mod_name;
43 unsigned int num_ddebugs;
44 unsigned int num_enabled;
45 struct _ddebug *ddebugs;
46};
47
48struct ddebug_query {
49 const char *filename;
50 const char *module;
51 const char *function;
52 const char *format;
53 unsigned int first_lineno, last_lineno;
54};
55
56struct ddebug_iter {
57 struct ddebug_table *table;
58 unsigned int idx;
59};
60
61static DEFINE_MUTEX(ddebug_lock);
62static LIST_HEAD(ddebug_tables);
63static int verbose = 0;
64
65/* Return the last part of a pathname */
66static inline const char *basename(const char *path)
67{
68 const char *tail = strrchr(path, '/');
69 return tail ? tail+1 : path;
70}
71
72/* format a string into buf[] which describes the _ddebug's flags */
73static char *ddebug_describe_flags(struct _ddebug *dp, char *buf,
74 size_t maxlen)
75{
76 char *p = buf;
77
78 BUG_ON(maxlen < 4);
79 if (dp->flags & _DPRINTK_FLAGS_PRINT)
80 *p++ = 'p';
81 if (p == buf)
82 *p++ = '-';
83 *p = '\0';
84
85 return buf;
86}
87
88/*
89 * must be called with ddebug_lock held
90 */
91
92static int disabled_hash(char hash, bool first_table)
93{
94 struct ddebug_table *dt;
95 char table_hash_value;
96
97 list_for_each_entry(dt, &ddebug_tables, link) {
98 if (first_table)
99 table_hash_value = dt->ddebugs->primary_hash;
100 else
101 table_hash_value = dt->ddebugs->secondary_hash;
102 if (dt->num_enabled && (hash == table_hash_value))
103 return 0;
104 }
105 return 1;
106}
107
108/*
109 * Search the tables for _ddebug's which match the given
110 * `query' and apply the `flags' and `mask' to them. Tells
111 * the user which ddebug's were changed, or whether none
112 * were matched.
113 */
114static void ddebug_change(const struct ddebug_query *query,
115 unsigned int flags, unsigned int mask)
116{
117 int i;
118 struct ddebug_table *dt;
119 unsigned int newflags;
120 unsigned int nfound = 0;
121 char flagbuf[8];
122
123 /* search for matching ddebugs */
124 mutex_lock(&ddebug_lock);
125 list_for_each_entry(dt, &ddebug_tables, link) {
126
127 /* match against the module name */
128 if (query->module != NULL &&
129 strcmp(query->module, dt->mod_name))
130 continue;
131
132 for (i = 0 ; i < dt->num_ddebugs ; i++) {
133 struct _ddebug *dp = &dt->ddebugs[i];
134
135 /* match against the source filename */
136 if (query->filename != NULL &&
137 strcmp(query->filename, dp->filename) &&
138 strcmp(query->filename, basename(dp->filename)))
139 continue;
140
141 /* match against the function */
142 if (query->function != NULL &&
143 strcmp(query->function, dp->function))
144 continue;
145
146 /* match against the format */
147 if (query->format != NULL &&
148 strstr(dp->format, query->format) == NULL)
149 continue;
150
151 /* match against the line number range */
152 if (query->first_lineno &&
153 dp->lineno < query->first_lineno)
154 continue;
155 if (query->last_lineno &&
156 dp->lineno > query->last_lineno)
157 continue;
158
159 nfound++;
160
161 newflags = (dp->flags & mask) | flags;
162 if (newflags == dp->flags)
163 continue;
164
165 if (!newflags)
166 dt->num_enabled--;
167 else if (!dp-flags)
168 dt->num_enabled++;
169 dp->flags = newflags;
170 if (newflags) {
171 dynamic_debug_enabled |=
172 (1LL << dp->primary_hash);
173 dynamic_debug_enabled2 |=
174 (1LL << dp->secondary_hash);
175 } else {
176 if (disabled_hash(dp->primary_hash, true))
177 dynamic_debug_enabled &=
178 ~(1LL << dp->primary_hash);
179 if (disabled_hash(dp->secondary_hash, false))
180 dynamic_debug_enabled2 &=
181 ~(1LL << dp->secondary_hash);
182 }
183 if (verbose)
184 printk(KERN_INFO
185 "ddebug: changed %s:%d [%s]%s %s\n",
186 dp->filename, dp->lineno,
187 dt->mod_name, dp->function,
188 ddebug_describe_flags(dp, flagbuf,
189 sizeof(flagbuf)));
190 }
191 }
192 mutex_unlock(&ddebug_lock);
193
194 if (!nfound && verbose)
195 printk(KERN_INFO "ddebug: no matches for query\n");
196}
197
198/*
199 * Split the buffer `buf' into space-separated words.
200 * Handles simple " and ' quoting, i.e. without nested,
201 * embedded or escaped \". Return the number of words
202 * or <0 on error.
203 */
204static int ddebug_tokenize(char *buf, char *words[], int maxwords)
205{
206 int nwords = 0;
207
208 while (*buf) {
209 char *end;
210
211 /* Skip leading whitespace */
212 while (*buf && isspace(*buf))
213 buf++;
214 if (!*buf)
215 break; /* oh, it was trailing whitespace */
216
217 /* Run `end' over a word, either whitespace separated or quoted */
218 if (*buf == '"' || *buf == '\'') {
219 int quote = *buf++;
220 for (end = buf ; *end && *end != quote ; end++)
221 ;
222 if (!*end)
223 return -EINVAL; /* unclosed quote */
224 } else {
225 for (end = buf ; *end && !isspace(*end) ; end++)
226 ;
227 BUG_ON(end == buf);
228 }
229 /* Here `buf' is the start of the word, `end' is one past the end */
230
231 if (nwords == maxwords)
232 return -EINVAL; /* ran out of words[] before bytes */
233 if (*end)
234 *end++ = '\0'; /* terminate the word */
235 words[nwords++] = buf;
236 buf = end;
237 }
238
239 if (verbose) {
240 int i;
241 printk(KERN_INFO "%s: split into words:", __func__);
242 for (i = 0 ; i < nwords ; i++)
243 printk(" \"%s\"", words[i]);
244 printk("\n");
245 }
246
247 return nwords;
248}
249
250/*
251 * Parse a single line number. Note that the empty string ""
252 * is treated as a special case and converted to zero, which
253 * is later treated as a "don't care" value.
254 */
255static inline int parse_lineno(const char *str, unsigned int *val)
256{
257 char *end = NULL;
258 BUG_ON(str == NULL);
259 if (*str == '\0') {
260 *val = 0;
261 return 0;
262 }
263 *val = simple_strtoul(str, &end, 10);
264 return end == NULL || end == str || *end != '\0' ? -EINVAL : 0;
265}
266
267/*
268 * Undo octal escaping in a string, inplace. This is useful to
269 * allow the user to express a query which matches a format
270 * containing embedded spaces.
271 */
272#define isodigit(c) ((c) >= '0' && (c) <= '7')
273static char *unescape(char *str)
274{
275 char *in = str;
276 char *out = str;
277
278 while (*in) {
279 if (*in == '\\') {
280 if (in[1] == '\\') {
281 *out++ = '\\';
282 in += 2;
283 continue;
284 } else if (in[1] == 't') {
285 *out++ = '\t';
286 in += 2;
287 continue;
288 } else if (in[1] == 'n') {
289 *out++ = '\n';
290 in += 2;
291 continue;
292 } else if (isodigit(in[1]) &&
293 isodigit(in[2]) &&
294 isodigit(in[3])) {
295 *out++ = ((in[1] - '0')<<6) |
296 ((in[2] - '0')<<3) |
297 (in[3] - '0');
298 in += 4;
299 continue;
300 }
301 }
302 *out++ = *in++;
303 }
304 *out = '\0';
305
306 return str;
307}
308
309/*
310 * Parse words[] as a ddebug query specification, which is a series
311 * of (keyword, value) pairs chosen from these possibilities:
312 *
313 * func <function-name>
314 * file <full-pathname>
315 * file <base-filename>
316 * module <module-name>
317 * format <escaped-string-to-find-in-format>
318 * line <lineno>
319 * line <first-lineno>-<last-lineno> // where either may be empty
320 */
321static int ddebug_parse_query(char *words[], int nwords,
322 struct ddebug_query *query)
323{
324 unsigned int i;
325
326 /* check we have an even number of words */
327 if (nwords % 2 != 0)
328 return -EINVAL;
329 memset(query, 0, sizeof(*query));
330
331 for (i = 0 ; i < nwords ; i += 2) {
332 if (!strcmp(words[i], "func"))
333 query->function = words[i+1];
334 else if (!strcmp(words[i], "file"))
335 query->filename = words[i+1];
336 else if (!strcmp(words[i], "module"))
337 query->module = words[i+1];
338 else if (!strcmp(words[i], "format"))
339 query->format = unescape(words[i+1]);
340 else if (!strcmp(words[i], "line")) {
341 char *first = words[i+1];
342 char *last = strchr(first, '-');
343 if (last)
344 *last++ = '\0';
345 if (parse_lineno(first, &query->first_lineno) < 0)
346 return -EINVAL;
347 if (last != NULL) {
348 /* range <first>-<last> */
349 if (parse_lineno(last, &query->last_lineno) < 0)
350 return -EINVAL;
351 } else {
352 query->last_lineno = query->first_lineno;
353 }
354 } else {
355 if (verbose)
356 printk(KERN_ERR "%s: unknown keyword \"%s\"\n",
357 __func__, words[i]);
358 return -EINVAL;
359 }
360 }
361
362 if (verbose)
363 printk(KERN_INFO "%s: q->function=\"%s\" q->filename=\"%s\" "
364 "q->module=\"%s\" q->format=\"%s\" q->lineno=%u-%u\n",
365 __func__, query->function, query->filename,
366 query->module, query->format, query->first_lineno,
367 query->last_lineno);
368
369 return 0;
370}
371
372/*
373 * Parse `str' as a flags specification, format [-+=][p]+.
374 * Sets up *maskp and *flagsp to be used when changing the
375 * flags fields of matched _ddebug's. Returns 0 on success
376 * or <0 on error.
377 */
378static int ddebug_parse_flags(const char *str, unsigned int *flagsp,
379 unsigned int *maskp)
380{
381 unsigned flags = 0;
382 int op = '=';
383
384 switch (*str) {
385 case '+':
386 case '-':
387 case '=':
388 op = *str++;
389 break;
390 default:
391 return -EINVAL;
392 }
393 if (verbose)
394 printk(KERN_INFO "%s: op='%c'\n", __func__, op);
395
396 for ( ; *str ; ++str) {
397 switch (*str) {
398 case 'p':
399 flags |= _DPRINTK_FLAGS_PRINT;
400 break;
401 default:
402 return -EINVAL;
403 }
404 }
405 if (flags == 0)
406 return -EINVAL;
407 if (verbose)
408 printk(KERN_INFO "%s: flags=0x%x\n", __func__, flags);
409
410 /* calculate final *flagsp, *maskp according to mask and op */
411 switch (op) {
412 case '=':
413 *maskp = 0;
414 *flagsp = flags;
415 break;
416 case '+':
417 *maskp = ~0U;
418 *flagsp = flags;
419 break;
420 case '-':
421 *maskp = ~flags;
422 *flagsp = 0;
423 break;
424 }
425 if (verbose)
426 printk(KERN_INFO "%s: *flagsp=0x%x *maskp=0x%x\n",
427 __func__, *flagsp, *maskp);
428 return 0;
429}
430
431/*
432 * File_ops->write method for <debugfs>/dynamic_debug/conrol. Gathers the
433 * command text from userspace, parses and executes it.
434 */
435static ssize_t ddebug_proc_write(struct file *file, const char __user *ubuf,
436 size_t len, loff_t *offp)
437{
438 unsigned int flags = 0, mask = 0;
439 struct ddebug_query query;
440#define MAXWORDS 9
441 int nwords;
442 char *words[MAXWORDS];
443 char tmpbuf[256];
444
445 if (len == 0)
446 return 0;
447 /* we don't check *offp -- multiple writes() are allowed */
448 if (len > sizeof(tmpbuf)-1)
449 return -E2BIG;
450 if (copy_from_user(tmpbuf, ubuf, len))
451 return -EFAULT;
452 tmpbuf[len] = '\0';
453 if (verbose)
454 printk(KERN_INFO "%s: read %d bytes from userspace\n",
455 __func__, (int)len);
456
457 nwords = ddebug_tokenize(tmpbuf, words, MAXWORDS);
458 if (nwords < 0)
459 return -EINVAL;
460 if (ddebug_parse_query(words, nwords-1, &query))
461 return -EINVAL;
462 if (ddebug_parse_flags(words[nwords-1], &flags, &mask))
463 return -EINVAL;
464
465 /* actually go and implement the change */
466 ddebug_change(&query, flags, mask);
467
468 *offp += len;
469 return len;
470}
471
472/*
473 * Set the iterator to point to the first _ddebug object
474 * and return a pointer to that first object. Returns
475 * NULL if there are no _ddebugs at all.
476 */
477static struct _ddebug *ddebug_iter_first(struct ddebug_iter *iter)
478{
479 if (list_empty(&ddebug_tables)) {
480 iter->table = NULL;
481 iter->idx = 0;
482 return NULL;
483 }
484 iter->table = list_entry(ddebug_tables.next,
485 struct ddebug_table, link);
486 iter->idx = 0;
487 return &iter->table->ddebugs[iter->idx];
488}
489
490/*
491 * Advance the iterator to point to the next _ddebug
492 * object from the one the iterator currently points at,
493 * and returns a pointer to the new _ddebug. Returns
494 * NULL if the iterator has seen all the _ddebugs.
495 */
496static struct _ddebug *ddebug_iter_next(struct ddebug_iter *iter)
497{
498 if (iter->table == NULL)
499 return NULL;
500 if (++iter->idx == iter->table->num_ddebugs) {
501 /* iterate to next table */
502 iter->idx = 0;
503 if (list_is_last(&iter->table->link, &ddebug_tables)) {
504 iter->table = NULL;
505 return NULL;
506 }
507 iter->table = list_entry(iter->table->link.next,
508 struct ddebug_table, link);
509 }
510 return &iter->table->ddebugs[iter->idx];
511}
512
513/*
514 * Seq_ops start method. Called at the start of every
515 * read() call from userspace. Takes the ddebug_lock and
516 * seeks the seq_file's iterator to the given position.
517 */
518static void *ddebug_proc_start(struct seq_file *m, loff_t *pos)
519{
520 struct ddebug_iter *iter = m->private;
521 struct _ddebug *dp;
522 int n = *pos;
523
524 if (verbose)
525 printk(KERN_INFO "%s: called m=%p *pos=%lld\n",
526 __func__, m, (unsigned long long)*pos);
527
528 mutex_lock(&ddebug_lock);
529
530 if (!n)
531 return SEQ_START_TOKEN;
532 if (n < 0)
533 return NULL;
534 dp = ddebug_iter_first(iter);
535 while (dp != NULL && --n > 0)
536 dp = ddebug_iter_next(iter);
537 return dp;
538}
539
540/*
541 * Seq_ops next method. Called several times within a read()
542 * call from userspace, with ddebug_lock held. Walks to the
543 * next _ddebug object with a special case for the header line.
544 */
545static void *ddebug_proc_next(struct seq_file *m, void *p, loff_t *pos)
546{
547 struct ddebug_iter *iter = m->private;
548 struct _ddebug *dp;
549
550 if (verbose)
551 printk(KERN_INFO "%s: called m=%p p=%p *pos=%lld\n",
552 __func__, m, p, (unsigned long long)*pos);
553
554 if (p == SEQ_START_TOKEN)
555 dp = ddebug_iter_first(iter);
556 else
557 dp = ddebug_iter_next(iter);
558 ++*pos;
559 return dp;
560}
561
562/*
563 * Seq_ops show method. Called several times within a read()
564 * call from userspace, with ddebug_lock held. Formats the
565 * current _ddebug as a single human-readable line, with a
566 * special case for the header line.
567 */
568static int ddebug_proc_show(struct seq_file *m, void *p)
569{
570 struct ddebug_iter *iter = m->private;
571 struct _ddebug *dp = p;
572 char flagsbuf[8];
573
574 if (verbose)
575 printk(KERN_INFO "%s: called m=%p p=%p\n",
576 __func__, m, p);
577
578 if (p == SEQ_START_TOKEN) {
579 seq_puts(m,
580 "# filename:lineno [module]function flags format\n");
581 return 0;
582 }
583
584 seq_printf(m, "%s:%u [%s]%s %s \"",
585 dp->filename, dp->lineno,
586 iter->table->mod_name, dp->function,
587 ddebug_describe_flags(dp, flagsbuf, sizeof(flagsbuf)));
588 seq_escape(m, dp->format, "\t\r\n\"");
589 seq_puts(m, "\"\n");
590
591 return 0;
592}
593
594/*
595 * Seq_ops stop method. Called at the end of each read()
596 * call from userspace. Drops ddebug_lock.
597 */
598static void ddebug_proc_stop(struct seq_file *m, void *p)
599{
600 if (verbose)
601 printk(KERN_INFO "%s: called m=%p p=%p\n",
602 __func__, m, p);
603 mutex_unlock(&ddebug_lock);
604}
605
606static const struct seq_operations ddebug_proc_seqops = {
607 .start = ddebug_proc_start,
608 .next = ddebug_proc_next,
609 .show = ddebug_proc_show,
610 .stop = ddebug_proc_stop
611};
612
613/*
614 * File_ops->open method for <debugfs>/dynamic_debug/control. Does the seq_file
615 * setup dance, and also creates an iterator to walk the _ddebugs.
616 * Note that we create a seq_file always, even for O_WRONLY files
617 * where it's not needed, as doing so simplifies the ->release method.
618 */
619static int ddebug_proc_open(struct inode *inode, struct file *file)
620{
621 struct ddebug_iter *iter;
622 int err;
623
624 if (verbose)
625 printk(KERN_INFO "%s: called\n", __func__);
626
627 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
628 if (iter == NULL)
629 return -ENOMEM;
630
631 err = seq_open(file, &ddebug_proc_seqops);
632 if (err) {
633 kfree(iter);
634 return err;
635 }
636 ((struct seq_file *) file->private_data)->private = iter;
637 return 0;
638}
639
640static const struct file_operations ddebug_proc_fops = {
641 .owner = THIS_MODULE,
642 .open = ddebug_proc_open,
643 .read = seq_read,
644 .llseek = seq_lseek,
645 .release = seq_release_private,
646 .write = ddebug_proc_write
647};
648
649/*
650 * Allocate a new ddebug_table for the given module
651 * and add it to the global list.
652 */
653int ddebug_add_module(struct _ddebug *tab, unsigned int n,
654 const char *name)
655{
656 struct ddebug_table *dt;
657 char *new_name;
658
659 dt = kzalloc(sizeof(*dt), GFP_KERNEL);
660 if (dt == NULL)
661 return -ENOMEM;
662 new_name = kstrdup(name, GFP_KERNEL);
663 if (new_name == NULL) {
664 kfree(dt);
665 return -ENOMEM;
666 }
667 dt->mod_name = new_name;
668 dt->num_ddebugs = n;
669 dt->num_enabled = 0;
670 dt->ddebugs = tab;
671
672 mutex_lock(&ddebug_lock);
673 list_add_tail(&dt->link, &ddebug_tables);
674 mutex_unlock(&ddebug_lock);
675
676 if (verbose)
677 printk(KERN_INFO "%u debug prints in module %s\n",
678 n, dt->mod_name);
679 return 0;
680}
681EXPORT_SYMBOL_GPL(ddebug_add_module);
682
683static void ddebug_table_free(struct ddebug_table *dt)
684{
685 list_del_init(&dt->link);
686 kfree(dt->mod_name);
687 kfree(dt);
688}
689
690/*
691 * Called in response to a module being unloaded. Removes
692 * any ddebug_table's which point at the module.
693 */
694int ddebug_remove_module(char *mod_name)
695{
696 struct ddebug_table *dt, *nextdt;
697 int ret = -ENOENT;
698
699 if (verbose)
700 printk(KERN_INFO "%s: removing module \"%s\"\n",
701 __func__, mod_name);
702
703 mutex_lock(&ddebug_lock);
704 list_for_each_entry_safe(dt, nextdt, &ddebug_tables, link) {
705 if (!strcmp(dt->mod_name, mod_name)) {
706 ddebug_table_free(dt);
707 ret = 0;
708 }
709 }
710 mutex_unlock(&ddebug_lock);
711 return ret;
712}
713EXPORT_SYMBOL_GPL(ddebug_remove_module);
714
715static void ddebug_remove_all_tables(void)
716{
717 mutex_lock(&ddebug_lock);
718 while (!list_empty(&ddebug_tables)) {
719 struct ddebug_table *dt = list_entry(ddebug_tables.next,
720 struct ddebug_table,
721 link);
722 ddebug_table_free(dt);
723 }
724 mutex_unlock(&ddebug_lock);
725}
726
727static int __init dynamic_debug_init(void)
728{
729 struct dentry *dir, *file;
730 struct _ddebug *iter, *iter_start;
731 const char *modname = NULL;
732 int ret = 0;
733 int n = 0;
734
735 dir = debugfs_create_dir("dynamic_debug", NULL);
736 if (!dir)
737 return -ENOMEM;
738 file = debugfs_create_file("control", 0644, dir, NULL,
739 &ddebug_proc_fops);
740 if (!file) {
741 debugfs_remove(dir);
742 return -ENOMEM;
743 }
744 if (__start___verbose != __stop___verbose) {
745 iter = __start___verbose;
746 modname = iter->modname;
747 iter_start = iter;
748 for (; iter < __stop___verbose; iter++) {
749 if (strcmp(modname, iter->modname)) {
750 ret = ddebug_add_module(iter_start, n, modname);
751 if (ret)
752 goto out_free;
753 n = 0;
754 modname = iter->modname;
755 iter_start = iter;
756 }
757 n++;
758 }
759 ret = ddebug_add_module(iter_start, n, modname);
760 }
761out_free:
762 if (ret) {
763 ddebug_remove_all_tables();
764 debugfs_remove(dir);
765 debugfs_remove(file);
766 }
767 return 0;
768}
769module_init(dynamic_debug_init);
diff --git a/lib/dynamic_printk.c b/lib/dynamic_printk.c
deleted file mode 100644
index 165a19763dc9..000000000000
--- a/lib/dynamic_printk.c
+++ /dev/null
@@ -1,414 +0,0 @@
1/*
2 * lib/dynamic_printk.c
3 *
4 * make pr_debug()/dev_dbg() calls runtime configurable based upon their
5 * their source module.
6 *
7 * Copyright (C) 2008 Red Hat, Inc., Jason Baron <jbaron@redhat.com>
8 */
9
10#include <linux/kernel.h>
11#include <linux/module.h>
12#include <linux/uaccess.h>
13#include <linux/seq_file.h>
14#include <linux/debugfs.h>
15#include <linux/fs.h>
16
17extern struct mod_debug __start___verbose[];
18extern struct mod_debug __stop___verbose[];
19
20struct debug_name {
21 struct hlist_node hlist;
22 struct hlist_node hlist2;
23 int hash1;
24 int hash2;
25 char *name;
26 int enable;
27 int type;
28};
29
30static int nr_entries;
31static int num_enabled;
32int dynamic_enabled = DYNAMIC_ENABLED_NONE;
33static struct hlist_head module_table[DEBUG_HASH_TABLE_SIZE] =
34 { [0 ... DEBUG_HASH_TABLE_SIZE-1] = HLIST_HEAD_INIT };
35static struct hlist_head module_table2[DEBUG_HASH_TABLE_SIZE] =
36 { [0 ... DEBUG_HASH_TABLE_SIZE-1] = HLIST_HEAD_INIT };
37static DECLARE_MUTEX(debug_list_mutex);
38
39/* dynamic_printk_enabled, and dynamic_printk_enabled2 are bitmasks in which
40 * bit n is set to 1 if any modname hashes into the bucket n, 0 otherwise. They
41 * use independent hash functions, to reduce the chance of false positives.
42 */
43long long dynamic_printk_enabled;
44EXPORT_SYMBOL_GPL(dynamic_printk_enabled);
45long long dynamic_printk_enabled2;
46EXPORT_SYMBOL_GPL(dynamic_printk_enabled2);
47
48/* returns the debug module pointer. */
49static struct debug_name *find_debug_module(char *module_name)
50{
51 int i;
52 struct hlist_head *head;
53 struct hlist_node *node;
54 struct debug_name *element;
55
56 element = NULL;
57 for (i = 0; i < DEBUG_HASH_TABLE_SIZE; i++) {
58 head = &module_table[i];
59 hlist_for_each_entry_rcu(element, node, head, hlist)
60 if (!strcmp(element->name, module_name))
61 return element;
62 }
63 return NULL;
64}
65
66/* returns the debug module pointer. */
67static struct debug_name *find_debug_module_hash(char *module_name, int hash)
68{
69 struct hlist_head *head;
70 struct hlist_node *node;
71 struct debug_name *element;
72
73 element = NULL;
74 head = &module_table[hash];
75 hlist_for_each_entry_rcu(element, node, head, hlist)
76 if (!strcmp(element->name, module_name))
77 return element;
78 return NULL;
79}
80
81/* caller must hold mutex*/
82static int __add_debug_module(char *mod_name, int hash, int hash2)
83{
84 struct debug_name *new;
85 char *module_name;
86 int ret = 0;
87
88 if (find_debug_module(mod_name)) {
89 ret = -EINVAL;
90 goto out;
91 }
92 module_name = kmalloc(strlen(mod_name) + 1, GFP_KERNEL);
93 if (!module_name) {
94 ret = -ENOMEM;
95 goto out;
96 }
97 module_name = strcpy(module_name, mod_name);
98 module_name[strlen(mod_name)] = '\0';
99 new = kzalloc(sizeof(struct debug_name), GFP_KERNEL);
100 if (!new) {
101 kfree(module_name);
102 ret = -ENOMEM;
103 goto out;
104 }
105 INIT_HLIST_NODE(&new->hlist);
106 INIT_HLIST_NODE(&new->hlist2);
107 new->name = module_name;
108 new->hash1 = hash;
109 new->hash2 = hash2;
110 hlist_add_head_rcu(&new->hlist, &module_table[hash]);
111 hlist_add_head_rcu(&new->hlist2, &module_table2[hash2]);
112 nr_entries++;
113out:
114 return ret;
115}
116
117int unregister_dynamic_debug_module(char *mod_name)
118{
119 struct debug_name *element;
120 int ret = 0;
121
122 down(&debug_list_mutex);
123 element = find_debug_module(mod_name);
124 if (!element) {
125 ret = -EINVAL;
126 goto out;
127 }
128 hlist_del_rcu(&element->hlist);
129 hlist_del_rcu(&element->hlist2);
130 synchronize_rcu();
131 kfree(element->name);
132 if (element->enable)
133 num_enabled--;
134 kfree(element);
135 nr_entries--;
136out:
137 up(&debug_list_mutex);
138 return ret;
139}
140EXPORT_SYMBOL_GPL(unregister_dynamic_debug_module);
141
142int register_dynamic_debug_module(char *mod_name, int type, char *share_name,
143 char *flags, int hash, int hash2)
144{
145 struct debug_name *elem;
146 int ret = 0;
147
148 down(&debug_list_mutex);
149 elem = find_debug_module(mod_name);
150 if (!elem) {
151 if (__add_debug_module(mod_name, hash, hash2))
152 goto out;
153 elem = find_debug_module(mod_name);
154 if (dynamic_enabled == DYNAMIC_ENABLED_ALL &&
155 !strcmp(mod_name, share_name)) {
156 elem->enable = true;
157 num_enabled++;
158 }
159 }
160 elem->type |= type;
161out:
162 up(&debug_list_mutex);
163 return ret;
164}
165EXPORT_SYMBOL_GPL(register_dynamic_debug_module);
166
167int __dynamic_dbg_enabled_helper(char *mod_name, int type, int value, int hash)
168{
169 struct debug_name *elem;
170 int ret = 0;
171
172 if (dynamic_enabled == DYNAMIC_ENABLED_ALL)
173 return 1;
174 rcu_read_lock();
175 elem = find_debug_module_hash(mod_name, hash);
176 if (elem && elem->enable)
177 ret = 1;
178 rcu_read_unlock();
179 return ret;
180}
181EXPORT_SYMBOL_GPL(__dynamic_dbg_enabled_helper);
182
183static void set_all(bool enable)
184{
185 struct debug_name *e;
186 struct hlist_node *node;
187 int i;
188 long long enable_mask;
189
190 for (i = 0; i < DEBUG_HASH_TABLE_SIZE; i++) {
191 if (module_table[i].first != NULL) {
192 hlist_for_each_entry(e, node, &module_table[i], hlist) {
193 e->enable = enable;
194 }
195 }
196 }
197 if (enable)
198 enable_mask = ULLONG_MAX;
199 else
200 enable_mask = 0;
201 dynamic_printk_enabled = enable_mask;
202 dynamic_printk_enabled2 = enable_mask;
203}
204
205static int disabled_hash(int i, bool first_table)
206{
207 struct debug_name *e;
208 struct hlist_node *node;
209
210 if (first_table) {
211 hlist_for_each_entry(e, node, &module_table[i], hlist) {
212 if (e->enable)
213 return 0;
214 }
215 } else {
216 hlist_for_each_entry(e, node, &module_table2[i], hlist2) {
217 if (e->enable)
218 return 0;
219 }
220 }
221 return 1;
222}
223
224static ssize_t pr_debug_write(struct file *file, const char __user *buf,
225 size_t length, loff_t *ppos)
226{
227 char *buffer, *s, *value_str, *setting_str;
228 int err, value;
229 struct debug_name *elem = NULL;
230 int all = 0;
231
232 if (length > PAGE_SIZE || length < 0)
233 return -EINVAL;
234
235 buffer = (char *)__get_free_page(GFP_KERNEL);
236 if (!buffer)
237 return -ENOMEM;
238
239 err = -EFAULT;
240 if (copy_from_user(buffer, buf, length))
241 goto out;
242
243 err = -EINVAL;
244 if (length < PAGE_SIZE)
245 buffer[length] = '\0';
246 else if (buffer[PAGE_SIZE-1])
247 goto out;
248
249 err = -EINVAL;
250 down(&debug_list_mutex);
251
252 if (strncmp("set", buffer, 3))
253 goto out_up;
254 s = buffer + 3;
255 setting_str = strsep(&s, "=");
256 if (s == NULL)
257 goto out_up;
258 setting_str = strstrip(setting_str);
259 value_str = strsep(&s, " ");
260 if (s == NULL)
261 goto out_up;
262 s = strstrip(s);
263 if (!strncmp(s, "all", 3))
264 all = 1;
265 else
266 elem = find_debug_module(s);
267 if (!strncmp(setting_str, "enable", 6)) {
268 value = !!simple_strtol(value_str, NULL, 10);
269 if (all) {
270 if (value) {
271 set_all(true);
272 num_enabled = nr_entries;
273 dynamic_enabled = DYNAMIC_ENABLED_ALL;
274 } else {
275 set_all(false);
276 num_enabled = 0;
277 dynamic_enabled = DYNAMIC_ENABLED_NONE;
278 }
279 err = 0;
280 } else if (elem) {
281 if (value && (elem->enable == 0)) {
282 dynamic_printk_enabled |= (1LL << elem->hash1);
283 dynamic_printk_enabled2 |= (1LL << elem->hash2);
284 elem->enable = 1;
285 num_enabled++;
286 dynamic_enabled = DYNAMIC_ENABLED_SOME;
287 err = 0;
288 printk(KERN_DEBUG
289 "debugging enabled for module %s\n",
290 elem->name);
291 } else if (!value && (elem->enable == 1)) {
292 elem->enable = 0;
293 num_enabled--;
294 if (disabled_hash(elem->hash1, true))
295 dynamic_printk_enabled &=
296 ~(1LL << elem->hash1);
297 if (disabled_hash(elem->hash2, false))
298 dynamic_printk_enabled2 &=
299 ~(1LL << elem->hash2);
300 if (num_enabled)
301 dynamic_enabled = DYNAMIC_ENABLED_SOME;
302 else
303 dynamic_enabled = DYNAMIC_ENABLED_NONE;
304 err = 0;
305 printk(KERN_DEBUG
306 "debugging disabled for module %s\n",
307 elem->name);
308 }
309 }
310 }
311 if (!err)
312 err = length;
313out_up:
314 up(&debug_list_mutex);
315out:
316 free_page((unsigned long)buffer);
317 return err;
318}
319
320static void *pr_debug_seq_start(struct seq_file *f, loff_t *pos)
321{
322 return (*pos < DEBUG_HASH_TABLE_SIZE) ? pos : NULL;
323}
324
325static void *pr_debug_seq_next(struct seq_file *s, void *v, loff_t *pos)
326{
327 (*pos)++;
328 if (*pos >= DEBUG_HASH_TABLE_SIZE)
329 return NULL;
330 return pos;
331}
332
333static void pr_debug_seq_stop(struct seq_file *s, void *v)
334{
335 /* Nothing to do */
336}
337
338static int pr_debug_seq_show(struct seq_file *s, void *v)
339{
340 struct hlist_head *head;
341 struct hlist_node *node;
342 struct debug_name *elem;
343 unsigned int i = *(loff_t *) v;
344
345 rcu_read_lock();
346 head = &module_table[i];
347 hlist_for_each_entry_rcu(elem, node, head, hlist) {
348 seq_printf(s, "%s enabled=%d", elem->name, elem->enable);
349 seq_printf(s, "\n");
350 }
351 rcu_read_unlock();
352 return 0;
353}
354
355static struct seq_operations pr_debug_seq_ops = {
356 .start = pr_debug_seq_start,
357 .next = pr_debug_seq_next,
358 .stop = pr_debug_seq_stop,
359 .show = pr_debug_seq_show
360};
361
362static int pr_debug_open(struct inode *inode, struct file *filp)
363{
364 return seq_open(filp, &pr_debug_seq_ops);
365}
366
367static const struct file_operations pr_debug_operations = {
368 .open = pr_debug_open,
369 .read = seq_read,
370 .write = pr_debug_write,
371 .llseek = seq_lseek,
372 .release = seq_release,
373};
374
375static int __init dynamic_printk_init(void)
376{
377 struct dentry *dir, *file;
378 struct mod_debug *iter;
379 unsigned long value;
380
381 dir = debugfs_create_dir("dynamic_printk", NULL);
382 if (!dir)
383 return -ENOMEM;
384 file = debugfs_create_file("modules", 0644, dir, NULL,
385 &pr_debug_operations);
386 if (!file) {
387 debugfs_remove(dir);
388 return -ENOMEM;
389 }
390 for (value = (unsigned long)__start___verbose;
391 value < (unsigned long)__stop___verbose;
392 value += sizeof(struct mod_debug)) {
393 iter = (struct mod_debug *)value;
394 register_dynamic_debug_module(iter->modname,
395 iter->type,
396 iter->logical_modname,
397 iter->flag_names, iter->hash, iter->hash2);
398 }
399 if (dynamic_enabled == DYNAMIC_ENABLED_ALL)
400 set_all(true);
401 return 0;
402}
403module_init(dynamic_printk_init);
404/* may want to move this earlier so we can get traces as early as possible */
405
406static int __init dynamic_printk_setup(char *str)
407{
408 if (str)
409 return -ENOENT;
410 dynamic_enabled = DYNAMIC_ENABLED_ALL;
411 return 0;
412}
413/* Use early_param(), so we can get debug output as early as possible */
414early_param("dynamic_printk", dynamic_printk_setup);
diff --git a/lib/kobject.c b/lib/kobject.c
index 0487d1f64806..a6dec32f2ddd 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -212,7 +212,7 @@ static int kobject_add_internal(struct kobject *kobj)
212 * @fmt: format string used to build the name 212 * @fmt: format string used to build the name
213 * @vargs: vargs to format the string. 213 * @vargs: vargs to format the string.
214 */ 214 */
215static int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, 215int kobject_set_name_vargs(struct kobject *kobj, const char *fmt,
216 va_list vargs) 216 va_list vargs)
217{ 217{
218 const char *old_name = kobj->name; 218 const char *old_name = kobj->name;
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index 318328ddbd1c..e68e743bd861 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -118,6 +118,13 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
118 kset = top_kobj->kset; 118 kset = top_kobj->kset;
119 uevent_ops = kset->uevent_ops; 119 uevent_ops = kset->uevent_ops;
120 120
121 /* skip the event, if uevent_suppress is set*/
122 if (kobj->uevent_suppress) {
123 pr_debug("kobject: '%s' (%p): %s: uevent_suppress "
124 "caused the event to drop!\n",
125 kobject_name(kobj), kobj, __func__);
126 return 0;
127 }
121 /* skip the event, if the filter returns zero. */ 128 /* skip the event, if the filter returns zero. */
122 if (uevent_ops && uevent_ops->filter) 129 if (uevent_ops && uevent_ops->filter)
123 if (!uevent_ops->filter(kset, kobj)) { 130 if (!uevent_ops->filter(kset, kobj)) {
@@ -248,7 +255,7 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action,
248 goto exit; 255 goto exit;
249 256
250 retval = call_usermodehelper(argv[0], argv, 257 retval = call_usermodehelper(argv[0], argv,
251 env->envp, UMH_WAIT_EXEC); 258 env->envp, UMH_NO_WAIT);
252 } 259 }
253 260
254exit: 261exit:
diff --git a/net/netlink/attr.c b/lib/nlattr.c
index 56c3ce7fe29a..80009a24e21d 100644
--- a/net/netlink/attr.c
+++ b/lib/nlattr.c
@@ -281,6 +281,7 @@ int nla_strcmp(const struct nlattr *nla, const char *str)
281 return d; 281 return d;
282} 282}
283 283
284#ifdef CONFIG_NET
284/** 285/**
285 * __nla_reserve - reserve room for attribute on the skb 286 * __nla_reserve - reserve room for attribute on the skb
286 * @skb: socket buffer to reserve room on 287 * @skb: socket buffer to reserve room on
@@ -305,6 +306,7 @@ struct nlattr *__nla_reserve(struct sk_buff *skb, int attrtype, int attrlen)
305 306
306 return nla; 307 return nla;
307} 308}
309EXPORT_SYMBOL(__nla_reserve);
308 310
309/** 311/**
310 * __nla_reserve_nohdr - reserve room for attribute without header 312 * __nla_reserve_nohdr - reserve room for attribute without header
@@ -325,6 +327,7 @@ void *__nla_reserve_nohdr(struct sk_buff *skb, int attrlen)
325 327
326 return start; 328 return start;
327} 329}
330EXPORT_SYMBOL(__nla_reserve_nohdr);
328 331
329/** 332/**
330 * nla_reserve - reserve room for attribute on the skb 333 * nla_reserve - reserve room for attribute on the skb
@@ -345,6 +348,7 @@ struct nlattr *nla_reserve(struct sk_buff *skb, int attrtype, int attrlen)
345 348
346 return __nla_reserve(skb, attrtype, attrlen); 349 return __nla_reserve(skb, attrtype, attrlen);
347} 350}
351EXPORT_SYMBOL(nla_reserve);
348 352
349/** 353/**
350 * nla_reserve_nohdr - reserve room for attribute without header 354 * nla_reserve_nohdr - reserve room for attribute without header
@@ -363,6 +367,7 @@ void *nla_reserve_nohdr(struct sk_buff *skb, int attrlen)
363 367
364 return __nla_reserve_nohdr(skb, attrlen); 368 return __nla_reserve_nohdr(skb, attrlen);
365} 369}
370EXPORT_SYMBOL(nla_reserve_nohdr);
366 371
367/** 372/**
368 * __nla_put - Add a netlink attribute to a socket buffer 373 * __nla_put - Add a netlink attribute to a socket buffer
@@ -382,6 +387,7 @@ void __nla_put(struct sk_buff *skb, int attrtype, int attrlen,
382 nla = __nla_reserve(skb, attrtype, attrlen); 387 nla = __nla_reserve(skb, attrtype, attrlen);
383 memcpy(nla_data(nla), data, attrlen); 388 memcpy(nla_data(nla), data, attrlen);
384} 389}
390EXPORT_SYMBOL(__nla_put);
385 391
386/** 392/**
387 * __nla_put_nohdr - Add a netlink attribute without header 393 * __nla_put_nohdr - Add a netlink attribute without header
@@ -399,6 +405,7 @@ void __nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data)
399 start = __nla_reserve_nohdr(skb, attrlen); 405 start = __nla_reserve_nohdr(skb, attrlen);
400 memcpy(start, data, attrlen); 406 memcpy(start, data, attrlen);
401} 407}
408EXPORT_SYMBOL(__nla_put_nohdr);
402 409
403/** 410/**
404 * nla_put - Add a netlink attribute to a socket buffer 411 * nla_put - Add a netlink attribute to a socket buffer
@@ -418,6 +425,7 @@ int nla_put(struct sk_buff *skb, int attrtype, int attrlen, const void *data)
418 __nla_put(skb, attrtype, attrlen, data); 425 __nla_put(skb, attrtype, attrlen, data);
419 return 0; 426 return 0;
420} 427}
428EXPORT_SYMBOL(nla_put);
421 429
422/** 430/**
423 * nla_put_nohdr - Add a netlink attribute without header 431 * nla_put_nohdr - Add a netlink attribute without header
@@ -436,6 +444,7 @@ int nla_put_nohdr(struct sk_buff *skb, int attrlen, const void *data)
436 __nla_put_nohdr(skb, attrlen, data); 444 __nla_put_nohdr(skb, attrlen, data);
437 return 0; 445 return 0;
438} 446}
447EXPORT_SYMBOL(nla_put_nohdr);
439 448
440/** 449/**
441 * nla_append - Add a netlink attribute without header or padding 450 * nla_append - Add a netlink attribute without header or padding
@@ -454,20 +463,13 @@ int nla_append(struct sk_buff *skb, int attrlen, const void *data)
454 memcpy(skb_put(skb, attrlen), data, attrlen); 463 memcpy(skb_put(skb, attrlen), data, attrlen);
455 return 0; 464 return 0;
456} 465}
466EXPORT_SYMBOL(nla_append);
467#endif
457 468
458EXPORT_SYMBOL(nla_validate); 469EXPORT_SYMBOL(nla_validate);
459EXPORT_SYMBOL(nla_parse); 470EXPORT_SYMBOL(nla_parse);
460EXPORT_SYMBOL(nla_find); 471EXPORT_SYMBOL(nla_find);
461EXPORT_SYMBOL(nla_strlcpy); 472EXPORT_SYMBOL(nla_strlcpy);
462EXPORT_SYMBOL(__nla_reserve);
463EXPORT_SYMBOL(__nla_reserve_nohdr);
464EXPORT_SYMBOL(nla_reserve);
465EXPORT_SYMBOL(nla_reserve_nohdr);
466EXPORT_SYMBOL(__nla_put);
467EXPORT_SYMBOL(__nla_put_nohdr);
468EXPORT_SYMBOL(nla_put);
469EXPORT_SYMBOL(nla_put_nohdr);
470EXPORT_SYMBOL(nla_memcpy); 473EXPORT_SYMBOL(nla_memcpy);
471EXPORT_SYMBOL(nla_memcmp); 474EXPORT_SYMBOL(nla_memcmp);
472EXPORT_SYMBOL(nla_strcmp); 475EXPORT_SYMBOL(nla_strcmp);
473EXPORT_SYMBOL(nla_append);
diff --git a/mm/page-writeback.c b/mm/page-writeback.c
index 74dc57c74349..40ca7cdb653e 100644
--- a/mm/page-writeback.c
+++ b/mm/page-writeback.c
@@ -66,7 +66,7 @@ static inline long sync_writeback_pages(void)
66/* 66/*
67 * Start background writeback (via pdflush) at this percentage 67 * Start background writeback (via pdflush) at this percentage
68 */ 68 */
69int dirty_background_ratio = 5; 69int dirty_background_ratio = 10;
70 70
71/* 71/*
72 * dirty_background_bytes starts at 0 (disabled) so that it is a function of 72 * dirty_background_bytes starts at 0 (disabled) so that it is a function of
@@ -83,7 +83,7 @@ int vm_highmem_is_dirtyable;
83/* 83/*
84 * The generator of dirty data starts writeback at this percentage 84 * The generator of dirty data starts writeback at this percentage
85 */ 85 */
86int vm_dirty_ratio = 10; 86int vm_dirty_ratio = 20;
87 87
88/* 88/*
89 * vm_dirty_bytes starts at 0 (disabled) so that it is a function of 89 * vm_dirty_bytes starts at 0 (disabled) so that it is a function of
diff --git a/net/Kconfig b/net/Kconfig
index cdb8fdef6c4a..eab40a481356 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -4,6 +4,7 @@
4 4
5menuconfig NET 5menuconfig NET
6 bool "Networking support" 6 bool "Networking support"
7 select NLATTR
7 ---help--- 8 ---help---
8 Unless you really know what you are doing, you should say Y here. 9 Unless you really know what you are doing, you should say Y here.
9 The reason is that some programs need kernel networking support even 10 The reason is that some programs need kernel networking support even
diff --git a/net/bluetooth/hci_sysfs.c b/net/bluetooth/hci_sysfs.c
index 1a1f916be44e..ed82796d4a0f 100644
--- a/net/bluetooth/hci_sysfs.c
+++ b/net/bluetooth/hci_sysfs.c
@@ -140,7 +140,7 @@ static void del_conn(struct work_struct *work)
140 dev = device_find_child(&conn->dev, NULL, __match_tty); 140 dev = device_find_child(&conn->dev, NULL, __match_tty);
141 if (!dev) 141 if (!dev)
142 break; 142 break;
143 device_move(dev, NULL); 143 device_move(dev, NULL, DPM_ORDER_DEV_LAST);
144 put_device(dev); 144 put_device(dev);
145 } 145 }
146 146
diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
index d030c69cb5a3..abdc703a11d2 100644
--- a/net/bluetooth/rfcomm/tty.c
+++ b/net/bluetooth/rfcomm/tty.c
@@ -731,7 +731,8 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
731 remove_wait_queue(&dev->wait, &wait); 731 remove_wait_queue(&dev->wait, &wait);
732 732
733 if (err == 0) 733 if (err == 0)
734 device_move(dev->tty_dev, rfcomm_get_device(dev)); 734 device_move(dev->tty_dev, rfcomm_get_device(dev),
735 DPM_ORDER_DEV_AFTER_PARENT);
735 736
736 rfcomm_tty_copy_pending(dev); 737 rfcomm_tty_copy_pending(dev);
737 738
@@ -751,7 +752,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
751 752
752 if (atomic_dec_and_test(&dev->opened)) { 753 if (atomic_dec_and_test(&dev->opened)) {
753 if (dev->tty_dev->parent) 754 if (dev->tty_dev->parent)
754 device_move(dev->tty_dev, NULL); 755 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
755 756
756 /* Close DLC and dettach TTY */ 757 /* Close DLC and dettach TTY */
757 rfcomm_dlc_close(dev->dlc, 0); 758 rfcomm_dlc_close(dev->dlc, 0);
diff --git a/net/netfilter/nf_conntrack_pptp.c b/net/netfilter/nf_conntrack_pptp.c
index 9e169ef2e854..12bd09dbd36c 100644
--- a/net/netfilter/nf_conntrack_pptp.c
+++ b/net/netfilter/nf_conntrack_pptp.c
@@ -66,7 +66,7 @@ void
66 struct nf_conntrack_expect *exp) __read_mostly; 66 struct nf_conntrack_expect *exp) __read_mostly;
67EXPORT_SYMBOL_GPL(nf_nat_pptp_hook_expectfn); 67EXPORT_SYMBOL_GPL(nf_nat_pptp_hook_expectfn);
68 68
69#if defined(DEBUG) || defined(CONFIG_DYNAMIC_PRINTK_DEBUG) 69#if defined(DEBUG) || defined(CONFIG_DYNAMIC_DEBUG)
70/* PptpControlMessageType names */ 70/* PptpControlMessageType names */
71const char *const pptp_msg_name[] = { 71const char *const pptp_msg_name[] = {
72 "UNKNOWN_MESSAGE", 72 "UNKNOWN_MESSAGE",
diff --git a/net/netlink/Makefile b/net/netlink/Makefile
index e3589c2de49e..bdd6ddf4e95b 100644
--- a/net/netlink/Makefile
+++ b/net/netlink/Makefile
@@ -2,4 +2,4 @@
2# Makefile for the netlink driver. 2# Makefile for the netlink driver.
3# 3#
4 4
5obj-y := af_netlink.o attr.o genetlink.o 5obj-y := af_netlink.o genetlink.o
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index e06365775bdf..c18fa150b6fe 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -97,7 +97,7 @@ modname_flags = $(if $(filter 1,$(words $(modname))),\
97 -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))") 97 -D"KBUILD_MODNAME=KBUILD_STR($(call name-fix,$(modname)))")
98 98
99#hash values 99#hash values
100ifdef CONFIG_DYNAMIC_PRINTK_DEBUG 100ifdef CONFIG_DYNAMIC_DEBUG
101debug_flags = -D"DEBUG_HASH=$(shell ./scripts/basic/hash djb2 $(@D)$(modname))"\ 101debug_flags = -D"DEBUG_HASH=$(shell ./scripts/basic/hash djb2 $(@D)$(modname))"\
102 -D"DEBUG_HASH2=$(shell ./scripts/basic/hash r5 $(@D)$(modname))" 102 -D"DEBUG_HASH2=$(shell ./scripts/basic/hash r5 $(@D)$(modname))"
103else 103else
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 4eea60b1693e..a3344285ccf4 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -710,6 +710,14 @@ static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
710 strcat(alias, ":"); 710 strcat(alias, ":");
711 return 1; 711 return 1;
712} 712}
713
714static int do_platform_entry(const char *filename,
715 struct platform_device_id *id, char *alias)
716{
717 sprintf(alias, PLATFORM_MODULE_PREFIX "%s", id->name);
718 return 1;
719}
720
713/* Ignore any prefix, eg. some architectures prepend _ */ 721/* Ignore any prefix, eg. some architectures prepend _ */
714static inline int sym_is(const char *symbol, const char *name) 722static inline int sym_is(const char *symbol, const char *name)
715{ 723{
@@ -849,6 +857,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
849 do_table(symval, sym->st_size, 857 do_table(symval, sym->st_size,
850 sizeof(struct dmi_system_id), "dmi", 858 sizeof(struct dmi_system_id), "dmi",
851 do_dmi_entry, mod); 859 do_dmi_entry, mod);
860 else if (sym_is(symname, "__mod_platform_device_table"))
861 do_table(symval, sym->st_size,
862 sizeof(struct platform_device_id), "platform",
863 do_platform_entry, mod);
852 free(zeros); 864 free(zeros);
853} 865}
854 866
diff --git a/sound/Kconfig b/sound/Kconfig
index 200aca1faa71..1eceb85287c5 100644
--- a/sound/Kconfig
+++ b/sound/Kconfig
@@ -60,6 +60,8 @@ source "sound/aoa/Kconfig"
60 60
61source "sound/arm/Kconfig" 61source "sound/arm/Kconfig"
62 62
63source "sound/atmel/Kconfig"
64
63source "sound/spi/Kconfig" 65source "sound/spi/Kconfig"
64 66
65source "sound/mips/Kconfig" 67source "sound/mips/Kconfig"
diff --git a/sound/Makefile b/sound/Makefile
index c76d70716fa5..ec467decfa79 100644
--- a/sound/Makefile
+++ b/sound/Makefile
@@ -6,7 +6,7 @@ obj-$(CONFIG_SOUND_PRIME) += sound_firmware.o
6obj-$(CONFIG_SOUND_PRIME) += oss/ 6obj-$(CONFIG_SOUND_PRIME) += oss/
7obj-$(CONFIG_DMASOUND) += oss/ 7obj-$(CONFIG_DMASOUND) += oss/
8obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \ 8obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \
9 sparc/ spi/ parisc/ pcmcia/ mips/ soc/ 9 sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/
10obj-$(CONFIG_SND_AOA) += aoa/ 10obj-$(CONFIG_SND_AOA) += aoa/
11 11
12# This one must be compilable even if sound is configured out 12# This one must be compilable even if sound is configured out
diff --git a/sound/aoa/aoa-gpio.h b/sound/aoa/aoa-gpio.h
index ee64f5de8966..6065b0344e23 100644
--- a/sound/aoa/aoa-gpio.h
+++ b/sound/aoa/aoa-gpio.h
@@ -34,10 +34,12 @@ struct gpio_methods {
34 void (*set_headphone)(struct gpio_runtime *rt, int on); 34 void (*set_headphone)(struct gpio_runtime *rt, int on);
35 void (*set_speakers)(struct gpio_runtime *rt, int on); 35 void (*set_speakers)(struct gpio_runtime *rt, int on);
36 void (*set_lineout)(struct gpio_runtime *rt, int on); 36 void (*set_lineout)(struct gpio_runtime *rt, int on);
37 void (*set_master)(struct gpio_runtime *rt, int on);
37 38
38 int (*get_headphone)(struct gpio_runtime *rt); 39 int (*get_headphone)(struct gpio_runtime *rt);
39 int (*get_speakers)(struct gpio_runtime *rt); 40 int (*get_speakers)(struct gpio_runtime *rt);
40 int (*get_lineout)(struct gpio_runtime *rt); 41 int (*get_lineout)(struct gpio_runtime *rt);
42 int (*get_master)(struct gpio_runtime *rt);
41 43
42 void (*set_hw_reset)(struct gpio_runtime *rt, int on); 44 void (*set_hw_reset)(struct gpio_runtime *rt, int on);
43 45
diff --git a/sound/aoa/core/alsa.c b/sound/aoa/core/alsa.c
index 617850463582..0fa3855b4790 100644
--- a/sound/aoa/core/alsa.c
+++ b/sound/aoa/core/alsa.c
@@ -23,9 +23,10 @@ int aoa_alsa_init(char *name, struct module *mod, struct device *dev)
23 /* cannot be EEXIST due to usage in aoa_fabric_register */ 23 /* cannot be EEXIST due to usage in aoa_fabric_register */
24 return -EBUSY; 24 return -EBUSY;
25 25
26 alsa_card = snd_card_new(index, name, mod, sizeof(struct aoa_card)); 26 err = snd_card_create(index, name, mod, sizeof(struct aoa_card),
27 if (!alsa_card) 27 &alsa_card);
28 return -ENOMEM; 28 if (err < 0)
29 return err;
29 aoa_card = alsa_card->private_data; 30 aoa_card = alsa_card->private_data;
30 aoa_card->alsa_card = alsa_card; 31 aoa_card->alsa_card = alsa_card;
31 alsa_card->dev = dev; 32 alsa_card->dev = dev;
diff --git a/sound/aoa/core/gpio-feature.c b/sound/aoa/core/gpio-feature.c
index c93ad5dec66b..de8e03afa97b 100644
--- a/sound/aoa/core/gpio-feature.c
+++ b/sound/aoa/core/gpio-feature.c
@@ -14,7 +14,7 @@
14#include <linux/interrupt.h> 14#include <linux/interrupt.h>
15#include "../aoa.h" 15#include "../aoa.h"
16 16
17/* TODO: these are 20 global variables 17/* TODO: these are lots of global variables
18 * that aren't used on most machines... 18 * that aren't used on most machines...
19 * Move them into a dynamically allocated 19 * Move them into a dynamically allocated
20 * structure and use that. 20 * structure and use that.
@@ -23,6 +23,7 @@
23/* these are the GPIO numbers (register addresses as offsets into 23/* these are the GPIO numbers (register addresses as offsets into
24 * the GPIO space) */ 24 * the GPIO space) */
25static int headphone_mute_gpio; 25static int headphone_mute_gpio;
26static int master_mute_gpio;
26static int amp_mute_gpio; 27static int amp_mute_gpio;
27static int lineout_mute_gpio; 28static int lineout_mute_gpio;
28static int hw_reset_gpio; 29static int hw_reset_gpio;
@@ -32,6 +33,7 @@ static int linein_detect_gpio;
32 33
33/* see the SWITCH_GPIO macro */ 34/* see the SWITCH_GPIO macro */
34static int headphone_mute_gpio_activestate; 35static int headphone_mute_gpio_activestate;
36static int master_mute_gpio_activestate;
35static int amp_mute_gpio_activestate; 37static int amp_mute_gpio_activestate;
36static int lineout_mute_gpio_activestate; 38static int lineout_mute_gpio_activestate;
37static int hw_reset_gpio_activestate; 39static int hw_reset_gpio_activestate;
@@ -156,6 +158,7 @@ static int ftr_gpio_get_##name(struct gpio_runtime *rt) \
156FTR_GPIO(headphone, 0); 158FTR_GPIO(headphone, 0);
157FTR_GPIO(amp, 1); 159FTR_GPIO(amp, 1);
158FTR_GPIO(lineout, 2); 160FTR_GPIO(lineout, 2);
161FTR_GPIO(master, 3);
159 162
160static void ftr_gpio_set_hw_reset(struct gpio_runtime *rt, int on) 163static void ftr_gpio_set_hw_reset(struct gpio_runtime *rt, int on)
161{ 164{
@@ -172,6 +175,8 @@ static void ftr_gpio_set_hw_reset(struct gpio_runtime *rt, int on)
172 hw_reset_gpio, v); 175 hw_reset_gpio, v);
173} 176}
174 177
178static struct gpio_methods methods;
179
175static void ftr_gpio_all_amps_off(struct gpio_runtime *rt) 180static void ftr_gpio_all_amps_off(struct gpio_runtime *rt)
176{ 181{
177 int saved; 182 int saved;
@@ -181,6 +186,8 @@ static void ftr_gpio_all_amps_off(struct gpio_runtime *rt)
181 ftr_gpio_set_headphone(rt, 0); 186 ftr_gpio_set_headphone(rt, 0);
182 ftr_gpio_set_amp(rt, 0); 187 ftr_gpio_set_amp(rt, 0);
183 ftr_gpio_set_lineout(rt, 0); 188 ftr_gpio_set_lineout(rt, 0);
189 if (methods.set_master)
190 ftr_gpio_set_master(rt, 0);
184 rt->implementation_private = saved; 191 rt->implementation_private = saved;
185} 192}
186 193
@@ -193,6 +200,8 @@ static void ftr_gpio_all_amps_restore(struct gpio_runtime *rt)
193 ftr_gpio_set_headphone(rt, (s>>0)&1); 200 ftr_gpio_set_headphone(rt, (s>>0)&1);
194 ftr_gpio_set_amp(rt, (s>>1)&1); 201 ftr_gpio_set_amp(rt, (s>>1)&1);
195 ftr_gpio_set_lineout(rt, (s>>2)&1); 202 ftr_gpio_set_lineout(rt, (s>>2)&1);
203 if (methods.set_master)
204 ftr_gpio_set_master(rt, (s>>3)&1);
196} 205}
197 206
198static void ftr_handle_notify(struct work_struct *work) 207static void ftr_handle_notify(struct work_struct *work)
@@ -231,6 +240,12 @@ static void ftr_gpio_init(struct gpio_runtime *rt)
231 get_gpio("hw-reset", "audio-hw-reset", 240 get_gpio("hw-reset", "audio-hw-reset",
232 &hw_reset_gpio, 241 &hw_reset_gpio,
233 &hw_reset_gpio_activestate); 242 &hw_reset_gpio_activestate);
243 if (get_gpio("master-mute", NULL,
244 &master_mute_gpio,
245 &master_mute_gpio_activestate)) {
246 methods.set_master = ftr_gpio_set_master;
247 methods.get_master = ftr_gpio_get_master;
248 }
234 249
235 headphone_detect_node = get_gpio("headphone-detect", NULL, 250 headphone_detect_node = get_gpio("headphone-detect", NULL,
236 &headphone_detect_gpio, 251 &headphone_detect_gpio,
diff --git a/sound/aoa/fabrics/layout.c b/sound/aoa/fabrics/layout.c
index ad60f5d10e82..fbf5c933baa4 100644
--- a/sound/aoa/fabrics/layout.c
+++ b/sound/aoa/fabrics/layout.c
@@ -1,16 +1,14 @@
1/* 1/*
2 * Apple Onboard Audio driver -- layout fabric 2 * Apple Onboard Audio driver -- layout/machine id fabric
3 * 3 *
4 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net> 4 * Copyright 2006-2008 Johannes Berg <johannes@sipsolutions.net>
5 * 5 *
6 * GPL v2, can be found in COPYING. 6 * GPL v2, can be found in COPYING.
7 * 7 *
8 * 8 *
9 * This fabric module looks for sound codecs 9 * This fabric module looks for sound codecs based on the
10 * based on the layout-id property in the device tree. 10 * layout-id or device-id property in the device tree.
11 *
12 */ 11 */
13
14#include <asm/prom.h> 12#include <asm/prom.h>
15#include <linux/list.h> 13#include <linux/list.h>
16#include <linux/module.h> 14#include <linux/module.h>
@@ -63,7 +61,7 @@ struct codec_connect_info {
63#define LAYOUT_FLAG_COMBO_LINEOUT_SPDIF (1<<0) 61#define LAYOUT_FLAG_COMBO_LINEOUT_SPDIF (1<<0)
64 62
65struct layout { 63struct layout {
66 unsigned int layout_id; 64 unsigned int layout_id, device_id;
67 struct codec_connect_info codecs[MAX_CODECS_PER_BUS]; 65 struct codec_connect_info codecs[MAX_CODECS_PER_BUS];
68 int flags; 66 int flags;
69 67
@@ -111,6 +109,10 @@ MODULE_ALIAS("sound-layout-96");
111MODULE_ALIAS("sound-layout-98"); 109MODULE_ALIAS("sound-layout-98");
112MODULE_ALIAS("sound-layout-100"); 110MODULE_ALIAS("sound-layout-100");
113 111
112MODULE_ALIAS("aoa-device-id-14");
113MODULE_ALIAS("aoa-device-id-22");
114MODULE_ALIAS("aoa-device-id-35");
115
114/* onyx with all but microphone connected */ 116/* onyx with all but microphone connected */
115static struct codec_connection onyx_connections_nomic[] = { 117static struct codec_connection onyx_connections_nomic[] = {
116 { 118 {
@@ -518,6 +520,27 @@ static struct layout layouts[] = {
518 .connections = onyx_connections_noheadphones, 520 .connections = onyx_connections_noheadphones,
519 }, 521 },
520 }, 522 },
523 /* PowerMac3,4 */
524 { .device_id = 14,
525 .codecs[0] = {
526 .name = "tas",
527 .connections = tas_connections_noline,
528 },
529 },
530 /* PowerMac3,6 */
531 { .device_id = 22,
532 .codecs[0] = {
533 .name = "tas",
534 .connections = tas_connections_all,
535 },
536 },
537 /* PowerBook5,2 */
538 { .device_id = 35,
539 .codecs[0] = {
540 .name = "tas",
541 .connections = tas_connections_all,
542 },
543 },
521 {} 544 {}
522}; 545};
523 546
@@ -526,7 +549,7 @@ static struct layout *find_layout_by_id(unsigned int id)
526 struct layout *l; 549 struct layout *l;
527 550
528 l = layouts; 551 l = layouts;
529 while (l->layout_id) { 552 while (l->codecs[0].name) {
530 if (l->layout_id == id) 553 if (l->layout_id == id)
531 return l; 554 return l;
532 l++; 555 l++;
@@ -534,6 +557,19 @@ static struct layout *find_layout_by_id(unsigned int id)
534 return NULL; 557 return NULL;
535} 558}
536 559
560static struct layout *find_layout_by_device(unsigned int id)
561{
562 struct layout *l;
563
564 l = layouts;
565 while (l->codecs[0].name) {
566 if (l->device_id == id)
567 return l;
568 l++;
569 }
570 return NULL;
571}
572
537static void use_layout(struct layout *l) 573static void use_layout(struct layout *l)
538{ 574{
539 int i; 575 int i;
@@ -564,6 +600,7 @@ struct layout_dev {
564 struct snd_kcontrol *headphone_ctrl; 600 struct snd_kcontrol *headphone_ctrl;
565 struct snd_kcontrol *lineout_ctrl; 601 struct snd_kcontrol *lineout_ctrl;
566 struct snd_kcontrol *speaker_ctrl; 602 struct snd_kcontrol *speaker_ctrl;
603 struct snd_kcontrol *master_ctrl;
567 struct snd_kcontrol *headphone_detected_ctrl; 604 struct snd_kcontrol *headphone_detected_ctrl;
568 struct snd_kcontrol *lineout_detected_ctrl; 605 struct snd_kcontrol *lineout_detected_ctrl;
569 606
@@ -615,6 +652,7 @@ static struct snd_kcontrol_new n##_ctl = { \
615AMP_CONTROL(headphone, "Headphone Switch"); 652AMP_CONTROL(headphone, "Headphone Switch");
616AMP_CONTROL(speakers, "Speakers Switch"); 653AMP_CONTROL(speakers, "Speakers Switch");
617AMP_CONTROL(lineout, "Line-Out Switch"); 654AMP_CONTROL(lineout, "Line-Out Switch");
655AMP_CONTROL(master, "Master Switch");
618 656
619static int detect_choice_get(struct snd_kcontrol *kcontrol, 657static int detect_choice_get(struct snd_kcontrol *kcontrol,
620 struct snd_ctl_elem_value *ucontrol) 658 struct snd_ctl_elem_value *ucontrol)
@@ -855,6 +893,11 @@ static void layout_attached_codec(struct aoa_codec *codec)
855 lineout = codec->gpio->methods->get_detect(codec->gpio, 893 lineout = codec->gpio->methods->get_detect(codec->gpio,
856 AOA_NOTIFY_LINE_OUT); 894 AOA_NOTIFY_LINE_OUT);
857 895
896 if (codec->gpio->methods->set_master) {
897 ctl = snd_ctl_new1(&master_ctl, codec->gpio);
898 ldev->master_ctrl = ctl;
899 aoa_snd_ctl_add(ctl);
900 }
858 while (cc->connected) { 901 while (cc->connected) {
859 if (cc->connected & CC_SPEAKERS) { 902 if (cc->connected & CC_SPEAKERS) {
860 if (headphones <= 0 && lineout <= 0) 903 if (headphones <= 0 && lineout <= 0)
@@ -938,8 +981,8 @@ static struct aoa_fabric layout_fabric = {
938static int aoa_fabric_layout_probe(struct soundbus_dev *sdev) 981static int aoa_fabric_layout_probe(struct soundbus_dev *sdev)
939{ 982{
940 struct device_node *sound = NULL; 983 struct device_node *sound = NULL;
941 const unsigned int *layout_id; 984 const unsigned int *id;
942 struct layout *layout; 985 struct layout *layout = NULL;
943 struct layout_dev *ldev = NULL; 986 struct layout_dev *ldev = NULL;
944 int err; 987 int err;
945 988
@@ -952,15 +995,18 @@ static int aoa_fabric_layout_probe(struct soundbus_dev *sdev)
952 if (sound->type && strcasecmp(sound->type, "soundchip") == 0) 995 if (sound->type && strcasecmp(sound->type, "soundchip") == 0)
953 break; 996 break;
954 } 997 }
955 if (!sound) return -ENODEV; 998 if (!sound)
999 return -ENODEV;
956 1000
957 layout_id = of_get_property(sound, "layout-id", NULL); 1001 id = of_get_property(sound, "layout-id", NULL);
958 if (!layout_id) 1002 if (id) {
959 goto outnodev; 1003 layout = find_layout_by_id(*id);
960 printk(KERN_INFO "snd-aoa-fabric-layout: found bus with layout %d\n", 1004 } else {
961 *layout_id); 1005 id = of_get_property(sound, "device-id", NULL);
1006 if (id)
1007 layout = find_layout_by_device(*id);
1008 }
962 1009
963 layout = find_layout_by_id(*layout_id);
964 if (!layout) { 1010 if (!layout) {
965 printk(KERN_ERR "snd-aoa-fabric-layout: unknown layout\n"); 1011 printk(KERN_ERR "snd-aoa-fabric-layout: unknown layout\n");
966 goto outnodev; 1012 goto outnodev;
@@ -976,6 +1022,7 @@ static int aoa_fabric_layout_probe(struct soundbus_dev *sdev)
976 ldev->layout = layout; 1022 ldev->layout = layout;
977 ldev->gpio.node = sound->parent; 1023 ldev->gpio.node = sound->parent;
978 switch (layout->layout_id) { 1024 switch (layout->layout_id) {
1025 case 0: /* anything with device_id, not layout_id */
979 case 41: /* that unknown machine no one seems to have */ 1026 case 41: /* that unknown machine no one seems to have */
980 case 51: /* PowerBook5,4 */ 1027 case 51: /* PowerBook5,4 */
981 case 58: /* Mac Mini */ 1028 case 58: /* Mac Mini */
diff --git a/sound/aoa/soundbus/i2sbus/core.c b/sound/aoa/soundbus/i2sbus/core.c
index be468edf3ecb..418c84c99d69 100644
--- a/sound/aoa/soundbus/i2sbus/core.c
+++ b/sound/aoa/soundbus/i2sbus/core.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * i2sbus driver 2 * i2sbus driver
3 * 3 *
4 * Copyright 2006 Johannes Berg <johannes@sipsolutions.net> 4 * Copyright 2006-2008 Johannes Berg <johannes@sipsolutions.net>
5 * 5 *
6 * GPL v2, can be found in COPYING. 6 * GPL v2, can be found in COPYING.
7 */ 7 */
@@ -186,13 +186,25 @@ static int i2sbus_add_dev(struct macio_dev *macio,
186 } 186 }
187 } 187 }
188 if (i == 1) { 188 if (i == 1) {
189 const u32 *layout_id = 189 const u32 *id = of_get_property(sound, "layout-id", NULL);
190 of_get_property(sound, "layout-id", NULL); 190
191 if (layout_id) { 191 if (id) {
192 layout = *layout_id; 192 layout = *id;
193 snprintf(dev->sound.modalias, 32, 193 snprintf(dev->sound.modalias, 32,
194 "sound-layout-%d", layout); 194 "sound-layout-%d", layout);
195 ok = 1; 195 ok = 1;
196 } else {
197 id = of_get_property(sound, "device-id", NULL);
198 /*
199 * We probably cannot handle all device-id machines,
200 * so restrict to those we do handle for now.
201 */
202 if (id && (*id == 22 || *id == 14 || *id == 35)) {
203 snprintf(dev->sound.modalias, 32,
204 "aoa-device-id-%d", *id);
205 ok = 1;
206 layout = -1;
207 }
196 } 208 }
197 } 209 }
198 /* for the time being, until we can handle non-layout-id 210 /* for the time being, until we can handle non-layout-id
diff --git a/sound/arm/Kconfig b/sound/arm/Kconfig
index f8e6de48d816..885683a3b0bd 100644
--- a/sound/arm/Kconfig
+++ b/sound/arm/Kconfig
@@ -11,17 +11,6 @@ menuconfig SND_ARM
11 11
12if SND_ARM 12if SND_ARM
13 13
14config SND_SA11XX_UDA1341
15 tristate "SA11xx UDA1341TS driver (iPaq H3600)"
16 depends on ARCH_SA1100 && L3
17 select SND_PCM
18 help
19 Say Y here if you have a Compaq iPaq H3x00 handheld computer
20 and want to use its Philips UDA 1341 audio chip.
21
22 To compile this driver as a module, choose M here: the module
23 will be called snd-sa11xx-uda1341.
24
25config SND_ARMAACI 14config SND_ARMAACI
26 tristate "ARM PrimeCell PL041 AC Link support" 15 tristate "ARM PrimeCell PL041 AC Link support"
27 depends on ARM_AMBA 16 depends on ARM_AMBA
diff --git a/sound/arm/Makefile b/sound/arm/Makefile
index 2054de11de8a..5a549ed6c8aa 100644
--- a/sound/arm/Makefile
+++ b/sound/arm/Makefile
@@ -2,9 +2,6 @@
2# Makefile for ALSA 2# Makefile for ALSA
3# 3#
4 4
5obj-$(CONFIG_SND_SA11XX_UDA1341) += snd-sa11xx-uda1341.o
6snd-sa11xx-uda1341-objs := sa11xx-uda1341.o
7
8obj-$(CONFIG_SND_ARMAACI) += snd-aaci.o 5obj-$(CONFIG_SND_ARMAACI) += snd-aaci.o
9snd-aaci-objs := aaci.o devdma.o 6snd-aaci-objs := aaci.o devdma.o
10 7
diff --git a/sound/arm/aaci.c b/sound/arm/aaci.c
index 772901e41ecb..7fbd68fab944 100644
--- a/sound/arm/aaci.c
+++ b/sound/arm/aaci.c
@@ -995,10 +995,11 @@ static struct aaci * __devinit aaci_init_card(struct amba_device *dev)
995{ 995{
996 struct aaci *aaci; 996 struct aaci *aaci;
997 struct snd_card *card; 997 struct snd_card *card;
998 int err;
998 999
999 card = snd_card_new(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 1000 err = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
1000 THIS_MODULE, sizeof(struct aaci)); 1001 THIS_MODULE, sizeof(struct aaci), &card);
1001 if (card == NULL) 1002 if (err < 0)
1002 return NULL; 1003 return NULL;
1003 1004
1004 card->private_free = aaci_free_card; 1005 card->private_free = aaci_free_card;
diff --git a/sound/arm/pxa2xx-ac97-lib.c b/sound/arm/pxa2xx-ac97-lib.c
index 35afd0c33be5..2e6355f4cbb9 100644
--- a/sound/arm/pxa2xx-ac97-lib.c
+++ b/sound/arm/pxa2xx-ac97-lib.c
@@ -31,6 +31,7 @@ static DECLARE_WAIT_QUEUE_HEAD(gsr_wq);
31static volatile long gsr_bits; 31static volatile long gsr_bits;
32static struct clk *ac97_clk; 32static struct clk *ac97_clk;
33static struct clk *ac97conf_clk; 33static struct clk *ac97conf_clk;
34static int reset_gpio;
34 35
35/* 36/*
36 * Beware PXA27x bugs: 37 * Beware PXA27x bugs:
@@ -42,6 +43,45 @@ static struct clk *ac97conf_clk;
42 * 1 jiffy timeout if interrupt never comes). 43 * 1 jiffy timeout if interrupt never comes).
43 */ 44 */
44 45
46enum {
47 RESETGPIO_FORCE_HIGH,
48 RESETGPIO_FORCE_LOW,
49 RESETGPIO_NORMAL_ALTFUNC
50};
51
52/**
53 * set_resetgpio_mode - computes and sets the AC97_RESET gpio mode on PXA
54 * @mode: chosen action
55 *
56 * As the PXA27x CPUs suffer from a AC97 bug, a manual control of the reset line
57 * must be done to insure proper work of AC97 reset line. This function
58 * computes the correct gpio_mode for further use by reset functions, and
59 * applied the change through pxa_gpio_mode.
60 */
61static void set_resetgpio_mode(int resetgpio_action)
62{
63 int mode = 0;
64
65 if (reset_gpio)
66 switch (resetgpio_action) {
67 case RESETGPIO_NORMAL_ALTFUNC:
68 if (reset_gpio == 113)
69 mode = 113 | GPIO_OUT | GPIO_DFLT_LOW;
70 if (reset_gpio == 95)
71 mode = 95 | GPIO_ALT_FN_1_OUT;
72 break;
73 case RESETGPIO_FORCE_LOW:
74 mode = reset_gpio | GPIO_OUT | GPIO_DFLT_LOW;
75 break;
76 case RESETGPIO_FORCE_HIGH:
77 mode = reset_gpio | GPIO_OUT | GPIO_DFLT_HIGH;
78 break;
79 };
80
81 if (mode)
82 pxa_gpio_mode(mode);
83}
84
45unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg) 85unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
46{ 86{
47 unsigned short val = -1; 87 unsigned short val = -1;
@@ -137,10 +177,10 @@ static inline void pxa_ac97_warm_pxa27x(void)
137 177
138 /* warm reset broken on Bulverde, 178 /* warm reset broken on Bulverde,
139 so manually keep AC97 reset high */ 179 so manually keep AC97 reset high */
140 pxa_gpio_mode(113 | GPIO_OUT | GPIO_DFLT_HIGH); 180 set_resetgpio_mode(RESETGPIO_FORCE_HIGH);
141 udelay(10); 181 udelay(10);
142 GCR |= GCR_WARM_RST; 182 GCR |= GCR_WARM_RST;
143 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); 183 set_resetgpio_mode(RESETGPIO_NORMAL_ALTFUNC);
144 udelay(500); 184 udelay(500);
145} 185}
146 186
@@ -308,8 +348,8 @@ int pxa2xx_ac97_hw_resume(void)
308 pxa_gpio_mode(GPIO29_SDATA_IN_AC97_MD); 348 pxa_gpio_mode(GPIO29_SDATA_IN_AC97_MD);
309 } 349 }
310 if (cpu_is_pxa27x()) { 350 if (cpu_is_pxa27x()) {
311 /* Use GPIO 113 as AC97 Reset on Bulverde */ 351 /* Use GPIO 113 or 95 as AC97 Reset on Bulverde */
312 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); 352 set_resetgpio_mode(RESETGPIO_NORMAL_ALTFUNC);
313 } 353 }
314 clk_enable(ac97_clk); 354 clk_enable(ac97_clk);
315 return 0; 355 return 0;
@@ -320,6 +360,27 @@ EXPORT_SYMBOL_GPL(pxa2xx_ac97_hw_resume);
320int __devinit pxa2xx_ac97_hw_probe(struct platform_device *dev) 360int __devinit pxa2xx_ac97_hw_probe(struct platform_device *dev)
321{ 361{
322 int ret; 362 int ret;
363 struct pxa2xx_ac97_platform_data *pdata = dev->dev.platform_data;
364
365 if (pdata) {
366 switch (pdata->reset_gpio) {
367 case 95:
368 case 113:
369 reset_gpio = pdata->reset_gpio;
370 break;
371 case 0:
372 reset_gpio = 113;
373 break;
374 case -1:
375 break;
376 default:
377 dev_err(&dev->dev, "Invalid reset GPIO %d\n",
378 pdata->reset_gpio);
379 }
380 } else {
381 if (cpu_is_pxa27x())
382 reset_gpio = 113;
383 }
323 384
324 if (cpu_is_pxa25x() || cpu_is_pxa27x()) { 385 if (cpu_is_pxa25x() || cpu_is_pxa27x()) {
325 pxa_gpio_mode(GPIO31_SYNC_AC97_MD); 386 pxa_gpio_mode(GPIO31_SYNC_AC97_MD);
@@ -330,7 +391,7 @@ int __devinit pxa2xx_ac97_hw_probe(struct platform_device *dev)
330 391
331 if (cpu_is_pxa27x()) { 392 if (cpu_is_pxa27x()) {
332 /* Use GPIO 113 as AC97 Reset on Bulverde */ 393 /* Use GPIO 113 as AC97 Reset on Bulverde */
333 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); 394 set_resetgpio_mode(RESETGPIO_NORMAL_ALTFUNC);
334 ac97conf_clk = clk_get(&dev->dev, "AC97CONFCLK"); 395 ac97conf_clk = clk_get(&dev->dev, "AC97CONFCLK");
335 if (IS_ERR(ac97conf_clk)) { 396 if (IS_ERR(ac97conf_clk)) {
336 ret = PTR_ERR(ac97conf_clk); 397 ret = PTR_ERR(ac97conf_clk);
diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c
index 85cf591d4e11..7ed100c80a5f 100644
--- a/sound/arm/pxa2xx-ac97.c
+++ b/sound/arm/pxa2xx-ac97.c
@@ -173,10 +173,9 @@ static int __devinit pxa2xx_ac97_probe(struct platform_device *dev)
173 struct snd_ac97_template ac97_template; 173 struct snd_ac97_template ac97_template;
174 int ret; 174 int ret;
175 175
176 ret = -ENOMEM; 176 ret = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
177 card = snd_card_new(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1, 177 THIS_MODULE, 0, &card);
178 THIS_MODULE, 0); 178 if (ret < 0)
179 if (!card)
180 goto err; 179 goto err;
181 180
182 card->dev = &dev->dev; 181 card->dev = &dev->dev;
diff --git a/sound/arm/sa11xx-uda1341.c b/sound/arm/sa11xx-uda1341.c
deleted file mode 100644
index 1dcd51d81d10..000000000000
--- a/sound/arm/sa11xx-uda1341.c
+++ /dev/null
@@ -1,983 +0,0 @@
1/*
2 * Driver for Philips UDA1341TS on Compaq iPAQ H3600 soundcard
3 * Copyright (C) 2002 Tomas Kasparek <tomas.kasparek@seznam.cz>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License.
7 *
8 * History:
9 *
10 * 2002-03-13 Tomas Kasparek initial release - based on h3600-uda1341.c from OSS
11 * 2002-03-20 Tomas Kasparek playback over ALSA is working
12 * 2002-03-28 Tomas Kasparek playback over OSS emulation is working
13 * 2002-03-29 Tomas Kasparek basic capture is working (native ALSA)
14 * 2002-03-29 Tomas Kasparek capture is working (OSS emulation)
15 * 2002-04-04 Tomas Kasparek better rates handling (allow non-standard rates)
16 * 2003-02-14 Brian Avery fixed full duplex mode, other updates
17 * 2003-02-20 Tomas Kasparek merged updates by Brian (except HAL)
18 * 2003-04-19 Jaroslav Kysela recoded DMA stuff to follow 2.4.18rmk3-hh24 kernel
19 * working suspend and resume
20 * 2003-04-28 Tomas Kasparek updated work by Jaroslav to compile it under 2.5.x again
21 * merged HAL layer (patches from Brian)
22 */
23
24/***************************************************************************************************
25*
26* To understand what Alsa Drivers should be doing look at "Writing an Alsa Driver" by Takashi Iwai
27* available in the Alsa doc section on the website
28*
29* A few notes to make things clearer. The UDA1341 is hooked up to Serial port 4 on the SA1100.
30* We are using SSP mode to talk to the UDA1341. The UDA1341 bit & wordselect clocks are generated
31* by this UART. Unfortunately, the clock only runs if the transmit buffer has something in it.
32* So, if we are just recording, we feed the transmit DMA stream a bunch of 0x0000 so that the
33* transmit buffer is full and the clock keeps going. The zeroes come from FLUSH_BASE_PHYS which
34* is a mem loc that always decodes to 0's w/ no off chip access.
35*
36* Some alsa terminology:
37* frame => num_channels * sample_size e.g stereo 16 bit is 2 * 16 = 32 bytes
38* period => the least number of bytes that will generate an interrupt e.g. we have a 1024 byte
39* buffer and 4 periods in the runtime structure this means we'll get an int every 256
40* bytes or 4 times per buffer.
41* A number of the sizes are in frames rather than bytes, use frames_to_bytes and
42* bytes_to_frames to convert. The easiest way to tell the units is to look at the
43* type i.e. runtime-> buffer_size is in frames and its type is snd_pcm_uframes_t
44*
45* Notes about the pointer fxn:
46* The pointer fxn needs to return the offset into the dma buffer in frames.
47* Interrupts must be blocked before calling the dma_get_pos fxn to avoid race with interrupts.
48*
49* Notes about pause/resume
50* Implementing this would be complicated so it's skipped. The problem case is:
51* A full duplex connection is going, then play is paused. At this point you need to start xmitting
52* 0's to keep the record active which means you cant just freeze the dma and resume it later you'd
53* need to save off the dma info, and restore it properly on a resume. Yeach!
54*
55* Notes about transfer methods:
56* The async write calls fail. I probably need to implement something else to support them?
57*
58***************************************************************************************************/
59
60#include <linux/module.h>
61#include <linux/moduleparam.h>
62#include <linux/init.h>
63#include <linux/err.h>
64#include <linux/platform_device.h>
65#include <linux/errno.h>
66#include <linux/ioctl.h>
67#include <linux/delay.h>
68#include <linux/slab.h>
69
70#ifdef CONFIG_PM
71#include <linux/pm.h>
72#endif
73
74#include <mach/hardware.h>
75#include <mach/h3600.h>
76#include <asm/mach-types.h>
77#include <asm/dma.h>
78
79#include <sound/core.h>
80#include <sound/pcm.h>
81#include <sound/initval.h>
82
83#include <linux/l3/l3.h>
84
85#undef DEBUG_MODE
86#undef DEBUG_FUNCTION_NAMES
87#include <sound/uda1341.h>
88
89/*
90 * FIXME: Is this enough as autodetection of 2.4.X-rmkY-hhZ kernels?
91 * We use DMA stuff from 2.4.18-rmk3-hh24 here to be able to compile this
92 * module for Familiar 0.6.1
93 */
94
95/* {{{ Type definitions */
96
97MODULE_AUTHOR("Tomas Kasparek <tomas.kasparek@seznam.cz>");
98MODULE_LICENSE("GPL");
99MODULE_DESCRIPTION("SA1100/SA1111 + UDA1341TS driver for ALSA");
100MODULE_SUPPORTED_DEVICE("{{UDA1341,iPAQ H3600 UDA1341TS}}");
101
102static char *id; /* ID for this card */
103
104module_param(id, charp, 0444);
105MODULE_PARM_DESC(id, "ID string for SA1100/SA1111 + UDA1341TS soundcard.");
106
107struct audio_stream {
108 char *id; /* identification string */
109 int stream_id; /* numeric identification */
110 dma_device_t dma_dev; /* device identifier for DMA */
111#ifdef HH_VERSION
112 dmach_t dmach; /* dma channel identification */
113#else
114 dma_regs_t *dma_regs; /* points to our DMA registers */
115#endif
116 unsigned int active:1; /* we are using this stream for transfer now */
117 int period; /* current transfer period */
118 int periods; /* current count of periods registerd in the DMA engine */
119 int tx_spin; /* are we recoding - flag used to do DMA trans. for sync */
120 unsigned int old_offset;
121 spinlock_t dma_lock; /* for locking in DMA operations (see dma-sa1100.c in the kernel) */
122 struct snd_pcm_substream *stream;
123};
124
125struct sa11xx_uda1341 {
126 struct snd_card *card;
127 struct l3_client *uda1341;
128 struct snd_pcm *pcm;
129 long samplerate;
130 struct audio_stream s[2]; /* playback & capture */
131};
132
133static unsigned int rates[] = {
134 8000, 10666, 10985, 14647,
135 16000, 21970, 22050, 24000,
136 29400, 32000, 44100, 48000,
137};
138
139static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
140 .count = ARRAY_SIZE(rates),
141 .list = rates,
142 .mask = 0,
143};
144
145static struct platform_device *device;
146
147/* }}} */
148
149/* {{{ Clock and sample rate stuff */
150
151/*
152 * Stop-gap solution until rest of hh.org HAL stuff is merged.
153 */
154#define GPIO_H3600_CLK_SET0 GPIO_GPIO (12)
155#define GPIO_H3600_CLK_SET1 GPIO_GPIO (13)
156
157#ifdef CONFIG_SA1100_H3XXX
158#define clr_sa11xx_uda1341_egpio(x) clr_h3600_egpio(x)
159#define set_sa11xx_uda1341_egpio(x) set_h3600_egpio(x)
160#else
161#error This driver could serve H3x00 handhelds only!
162#endif
163
164static void sa11xx_uda1341_set_audio_clock(long val)
165{
166 switch (val) {
167 case 24000: case 32000: case 48000: /* 00: 12.288 MHz */
168 GPCR = GPIO_H3600_CLK_SET0 | GPIO_H3600_CLK_SET1;
169 break;
170
171 case 22050: case 29400: case 44100: /* 01: 11.2896 MHz */
172 GPSR = GPIO_H3600_CLK_SET0;
173 GPCR = GPIO_H3600_CLK_SET1;
174 break;
175
176 case 8000: case 10666: case 16000: /* 10: 4.096 MHz */
177 GPCR = GPIO_H3600_CLK_SET0;
178 GPSR = GPIO_H3600_CLK_SET1;
179 break;
180
181 case 10985: case 14647: case 21970: /* 11: 5.6245 MHz */
182 GPSR = GPIO_H3600_CLK_SET0 | GPIO_H3600_CLK_SET1;
183 break;
184 }
185}
186
187static void sa11xx_uda1341_set_samplerate(struct sa11xx_uda1341 *sa11xx_uda1341, long rate)
188{
189 int clk_div = 0;
190 int clk=0;
191
192 /* We don't want to mess with clocks when frames are in flight */
193 Ser4SSCR0 &= ~SSCR0_SSE;
194 /* wait for any frame to complete */
195 udelay(125);
196
197 /*
198 * We have the following clock sources:
199 * 4.096 MHz, 5.6245 MHz, 11.2896 MHz, 12.288 MHz
200 * Those can be divided either by 256, 384 or 512.
201 * This makes up 12 combinations for the following samplerates...
202 */
203 if (rate >= 48000)
204 rate = 48000;
205 else if (rate >= 44100)
206 rate = 44100;
207 else if (rate >= 32000)
208 rate = 32000;
209 else if (rate >= 29400)
210 rate = 29400;
211 else if (rate >= 24000)
212 rate = 24000;
213 else if (rate >= 22050)
214 rate = 22050;
215 else if (rate >= 21970)
216 rate = 21970;
217 else if (rate >= 16000)
218 rate = 16000;
219 else if (rate >= 14647)
220 rate = 14647;
221 else if (rate >= 10985)
222 rate = 10985;
223 else if (rate >= 10666)
224 rate = 10666;
225 else
226 rate = 8000;
227
228 /* Set the external clock generator */
229
230 sa11xx_uda1341_set_audio_clock(rate);
231
232 /* Select the clock divisor */
233 switch (rate) {
234 case 8000:
235 case 10985:
236 case 22050:
237 case 24000:
238 clk = F512;
239 clk_div = SSCR0_SerClkDiv(16);
240 break;
241 case 16000:
242 case 21970:
243 case 44100:
244 case 48000:
245 clk = F256;
246 clk_div = SSCR0_SerClkDiv(8);
247 break;
248 case 10666:
249 case 14647:
250 case 29400:
251 case 32000:
252 clk = F384;
253 clk_div = SSCR0_SerClkDiv(12);
254 break;
255 }
256
257 /* FMT setting should be moved away when other FMTs are added (FIXME) */
258 l3_command(sa11xx_uda1341->uda1341, CMD_FORMAT, (void *)LSB16);
259
260 l3_command(sa11xx_uda1341->uda1341, CMD_FS, (void *)clk);
261 Ser4SSCR0 = (Ser4SSCR0 & ~0xff00) + clk_div + SSCR0_SSE;
262 sa11xx_uda1341->samplerate = rate;
263}
264
265/* }}} */
266
267/* {{{ HW init and shutdown */
268
269static void sa11xx_uda1341_audio_init(struct sa11xx_uda1341 *sa11xx_uda1341)
270{
271 unsigned long flags;
272
273 /* Setup DMA stuff */
274 sa11xx_uda1341->s[SNDRV_PCM_STREAM_PLAYBACK].id = "UDA1341 out";
275 sa11xx_uda1341->s[SNDRV_PCM_STREAM_PLAYBACK].stream_id = SNDRV_PCM_STREAM_PLAYBACK;
276 sa11xx_uda1341->s[SNDRV_PCM_STREAM_PLAYBACK].dma_dev = DMA_Ser4SSPWr;
277
278 sa11xx_uda1341->s[SNDRV_PCM_STREAM_CAPTURE].id = "UDA1341 in";
279 sa11xx_uda1341->s[SNDRV_PCM_STREAM_CAPTURE].stream_id = SNDRV_PCM_STREAM_CAPTURE;
280 sa11xx_uda1341->s[SNDRV_PCM_STREAM_CAPTURE].dma_dev = DMA_Ser4SSPRd;
281
282 /* Initialize the UDA1341 internal state */
283
284 /* Setup the uarts */
285 local_irq_save(flags);
286 GAFR |= (GPIO_SSP_CLK);
287 GPDR &= ~(GPIO_SSP_CLK);
288 Ser4SSCR0 = 0;
289 Ser4SSCR0 = SSCR0_DataSize(16) + SSCR0_TI + SSCR0_SerClkDiv(8);
290 Ser4SSCR1 = SSCR1_SClkIactL + SSCR1_SClk1P + SSCR1_ExtClk;
291 Ser4SSCR0 |= SSCR0_SSE;
292 local_irq_restore(flags);
293
294 /* Enable the audio power */
295
296 clr_sa11xx_uda1341_egpio(IPAQ_EGPIO_CODEC_NRESET);
297 set_sa11xx_uda1341_egpio(IPAQ_EGPIO_AUDIO_ON);
298 set_sa11xx_uda1341_egpio(IPAQ_EGPIO_QMUTE);
299
300 /* Wait for the UDA1341 to wake up */
301 mdelay(1); //FIXME - was removed by Perex - Why?
302
303 /* Initialize the UDA1341 internal state */
304 l3_open(sa11xx_uda1341->uda1341);
305
306 /* external clock configuration (after l3_open - regs must be initialized */
307 sa11xx_uda1341_set_samplerate(sa11xx_uda1341, sa11xx_uda1341->samplerate);
308
309 /* Wait for the UDA1341 to wake up */
310 set_sa11xx_uda1341_egpio(IPAQ_EGPIO_CODEC_NRESET);
311 mdelay(1);
312
313 /* make the left and right channels unswapped (flip the WS latch) */
314 Ser4SSDR = 0;
315
316 clr_sa11xx_uda1341_egpio(IPAQ_EGPIO_QMUTE);
317}
318
319static void sa11xx_uda1341_audio_shutdown(struct sa11xx_uda1341 *sa11xx_uda1341)
320{
321 /* mute on */
322 set_sa11xx_uda1341_egpio(IPAQ_EGPIO_QMUTE);
323
324 /* disable the audio power and all signals leading to the audio chip */
325 l3_close(sa11xx_uda1341->uda1341);
326 Ser4SSCR0 = 0;
327 clr_sa11xx_uda1341_egpio(IPAQ_EGPIO_CODEC_NRESET);
328
329 /* power off and mute off */
330 /* FIXME - is muting off necesary??? */
331
332 clr_sa11xx_uda1341_egpio(IPAQ_EGPIO_AUDIO_ON);
333 clr_sa11xx_uda1341_egpio(IPAQ_EGPIO_QMUTE);
334}
335
336/* }}} */
337
338/* {{{ DMA staff */
339
340/*
341 * these are the address and sizes used to fill the xmit buffer
342 * so we can get a clock in record only mode
343 */
344#define FORCE_CLOCK_ADDR (dma_addr_t)FLUSH_BASE_PHYS
345#define FORCE_CLOCK_SIZE 4096 // was 2048
346
347// FIXME Why this value exactly - wrote comment
348#define DMA_BUF_SIZE 8176 /* <= MAX_DMA_SIZE from asm/arch-sa1100/dma.h */
349
350#ifdef HH_VERSION
351
352static int audio_dma_request(struct audio_stream *s, void (*callback)(void *, int))
353{
354 int ret;
355
356 ret = sa1100_request_dma(&s->dmach, s->id, s->dma_dev);
357 if (ret < 0) {
358 printk(KERN_ERR "unable to grab audio dma 0x%x\n", s->dma_dev);
359 return ret;
360 }
361 sa1100_dma_set_callback(s->dmach, callback);
362 return 0;
363}
364
365static inline void audio_dma_free(struct audio_stream *s)
366{
367 sa1100_free_dma(s->dmach);
368 s->dmach = -1;
369}
370
371#else
372
373static int audio_dma_request(struct audio_stream *s, void (*callback)(void *))
374{
375 int ret;
376
377 ret = sa1100_request_dma(s->dma_dev, s->id, callback, s, &s->dma_regs);
378 if (ret < 0)
379 printk(KERN_ERR "unable to grab audio dma 0x%x\n", s->dma_dev);
380 return ret;
381}
382
383static void audio_dma_free(struct audio_stream *s)
384{
385 sa1100_free_dma(s->dma_regs);
386 s->dma_regs = 0;
387}
388
389#endif
390
391static u_int audio_get_dma_pos(struct audio_stream *s)
392{
393 struct snd_pcm_substream *substream = s->stream;
394 struct snd_pcm_runtime *runtime = substream->runtime;
395 unsigned int offset;
396 unsigned long flags;
397 dma_addr_t addr;
398
399 // this must be called w/ interrupts locked out see dma-sa1100.c in the kernel
400 spin_lock_irqsave(&s->dma_lock, flags);
401#ifdef HH_VERSION
402 sa1100_dma_get_current(s->dmach, NULL, &addr);
403#else
404 addr = sa1100_get_dma_pos((s)->dma_regs);
405#endif
406 offset = addr - runtime->dma_addr;
407 spin_unlock_irqrestore(&s->dma_lock, flags);
408
409 offset = bytes_to_frames(runtime,offset);
410 if (offset >= runtime->buffer_size)
411 offset = 0;
412
413 return offset;
414}
415
416/*
417 * this stops the dma and clears the dma ptrs
418 */
419static void audio_stop_dma(struct audio_stream *s)
420{
421 unsigned long flags;
422
423 spin_lock_irqsave(&s->dma_lock, flags);
424 s->active = 0;
425 s->period = 0;
426 /* this stops the dma channel and clears the buffer ptrs */
427#ifdef HH_VERSION
428 sa1100_dma_flush_all(s->dmach);
429#else
430 sa1100_clear_dma(s->dma_regs);
431#endif
432 spin_unlock_irqrestore(&s->dma_lock, flags);
433}
434
435static void audio_process_dma(struct audio_stream *s)
436{
437 struct snd_pcm_substream *substream = s->stream;
438 struct snd_pcm_runtime *runtime;
439 unsigned int dma_size;
440 unsigned int offset;
441 int ret;
442
443 /* we are requested to process synchronization DMA transfer */
444 if (s->tx_spin) {
445 if (snd_BUG_ON(s->stream_id != SNDRV_PCM_STREAM_PLAYBACK))
446 return;
447 /* fill the xmit dma buffers and return */
448#ifdef HH_VERSION
449 sa1100_dma_set_spin(s->dmach, FORCE_CLOCK_ADDR, FORCE_CLOCK_SIZE);
450#else
451 while (1) {
452 ret = sa1100_start_dma(s->dma_regs, FORCE_CLOCK_ADDR, FORCE_CLOCK_SIZE);
453 if (ret)
454 return;
455 }
456#endif
457 return;
458 }
459
460 /* must be set here - only valid for running streams, not for forced_clock dma fills */
461 runtime = substream->runtime;
462 while (s->active && s->periods < runtime->periods) {
463 dma_size = frames_to_bytes(runtime, runtime->period_size);
464 if (s->old_offset) {
465 /* a little trick, we need resume from old position */
466 offset = frames_to_bytes(runtime, s->old_offset - 1);
467 s->old_offset = 0;
468 s->periods = 0;
469 s->period = offset / dma_size;
470 offset %= dma_size;
471 dma_size = dma_size - offset;
472 if (!dma_size)
473 continue; /* special case */
474 } else {
475 offset = dma_size * s->period;
476 snd_BUG_ON(dma_size > DMA_BUF_SIZE);
477 }
478#ifdef HH_VERSION
479 ret = sa1100_dma_queue_buffer(s->dmach, s, runtime->dma_addr + offset, dma_size);
480 if (ret)
481 return; //FIXME
482#else
483 ret = sa1100_start_dma((s)->dma_regs, runtime->dma_addr + offset, dma_size);
484 if (ret) {
485 printk(KERN_ERR "audio_process_dma: cannot queue DMA buffer (%i)\n", ret);
486 return;
487 }
488#endif
489
490 s->period++;
491 s->period %= runtime->periods;
492 s->periods++;
493 }
494}
495
496#ifdef HH_VERSION
497static void audio_dma_callback(void *data, int size)
498#else
499static void audio_dma_callback(void *data)
500#endif
501{
502 struct audio_stream *s = data;
503
504 /*
505 * If we are getting a callback for an active stream then we inform
506 * the PCM middle layer we've finished a period
507 */
508 if (s->active)
509 snd_pcm_period_elapsed(s->stream);
510
511 spin_lock(&s->dma_lock);
512 if (!s->tx_spin && s->periods > 0)
513 s->periods--;
514 audio_process_dma(s);
515 spin_unlock(&s->dma_lock);
516}
517
518/* }}} */
519
520/* {{{ PCM setting */
521
522/* {{{ trigger & timer */
523
524static int snd_sa11xx_uda1341_trigger(struct snd_pcm_substream *substream, int cmd)
525{
526 struct sa11xx_uda1341 *chip = snd_pcm_substream_chip(substream);
527 int stream_id = substream->pstr->stream;
528 struct audio_stream *s = &chip->s[stream_id];
529 struct audio_stream *s1 = &chip->s[stream_id ^ 1];
530 int err = 0;
531
532 /* note local interrupts are already disabled in the midlevel code */
533 spin_lock(&s->dma_lock);
534 switch (cmd) {
535 case SNDRV_PCM_TRIGGER_START:
536 /* now we need to make sure a record only stream has a clock */
537 if (stream_id == SNDRV_PCM_STREAM_CAPTURE && !s1->active) {
538 /* we need to force fill the xmit DMA with zeros */
539 s1->tx_spin = 1;
540 audio_process_dma(s1);
541 }
542 /* this case is when you were recording then you turn on a
543 * playback stream so we stop (also clears it) the dma first,
544 * clear the sync flag and then we let it turned on
545 */
546 else {
547 s->tx_spin = 0;
548 }
549
550 /* requested stream startup */
551 s->active = 1;
552 audio_process_dma(s);
553 break;
554 case SNDRV_PCM_TRIGGER_STOP:
555 /* requested stream shutdown */
556 audio_stop_dma(s);
557
558 /*
559 * now we need to make sure a record only stream has a clock
560 * so if we're stopping a playback with an active capture
561 * we need to turn the 0 fill dma on for the xmit side
562 */
563 if (stream_id == SNDRV_PCM_STREAM_PLAYBACK && s1->active) {
564 /* we need to force fill the xmit DMA with zeros */
565 s->tx_spin = 1;
566 audio_process_dma(s);
567 }
568 /*
569 * we killed a capture only stream, so we should also kill
570 * the zero fill transmit
571 */
572 else {
573 if (s1->tx_spin) {
574 s1->tx_spin = 0;
575 audio_stop_dma(s1);
576 }
577 }
578
579 break;
580 case SNDRV_PCM_TRIGGER_SUSPEND:
581 s->active = 0;
582#ifdef HH_VERSION
583 sa1100_dma_stop(s->dmach);
584#else
585 //FIXME - DMA API
586#endif
587 s->old_offset = audio_get_dma_pos(s) + 1;
588#ifdef HH_VERSION
589 sa1100_dma_flush_all(s->dmach);
590#else
591 //FIXME - DMA API
592#endif
593 s->periods = 0;
594 break;
595 case SNDRV_PCM_TRIGGER_RESUME:
596 s->active = 1;
597 s->tx_spin = 0;
598 audio_process_dma(s);
599 if (stream_id == SNDRV_PCM_STREAM_CAPTURE && !s1->active) {
600 s1->tx_spin = 1;
601 audio_process_dma(s1);
602 }
603 break;
604 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
605#ifdef HH_VERSION
606 sa1100_dma_stop(s->dmach);
607#else
608 //FIXME - DMA API
609#endif
610 s->active = 0;
611 if (stream_id == SNDRV_PCM_STREAM_PLAYBACK) {
612 if (s1->active) {
613 s->tx_spin = 1;
614 s->old_offset = audio_get_dma_pos(s) + 1;
615#ifdef HH_VERSION
616 sa1100_dma_flush_all(s->dmach);
617#else
618 //FIXME - DMA API
619#endif
620 audio_process_dma(s);
621 }
622 } else {
623 if (s1->tx_spin) {
624 s1->tx_spin = 0;
625#ifdef HH_VERSION
626 sa1100_dma_flush_all(s1->dmach);
627#else
628 //FIXME - DMA API
629#endif
630 }
631 }
632 break;
633 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
634 s->active = 1;
635 if (s->old_offset) {
636 s->tx_spin = 0;
637 audio_process_dma(s);
638 break;
639 }
640 if (stream_id == SNDRV_PCM_STREAM_CAPTURE && !s1->active) {
641 s1->tx_spin = 1;
642 audio_process_dma(s1);
643 }
644#ifdef HH_VERSION
645 sa1100_dma_resume(s->dmach);
646#else
647 //FIXME - DMA API
648#endif
649 break;
650 default:
651 err = -EINVAL;
652 break;
653 }
654 spin_unlock(&s->dma_lock);
655 return err;
656}
657
658static int snd_sa11xx_uda1341_prepare(struct snd_pcm_substream *substream)
659{
660 struct sa11xx_uda1341 *chip = snd_pcm_substream_chip(substream);
661 struct snd_pcm_runtime *runtime = substream->runtime;
662 struct audio_stream *s = &chip->s[substream->pstr->stream];
663
664 /* set requested samplerate */
665 sa11xx_uda1341_set_samplerate(chip, runtime->rate);
666
667 /* set requestd format when available */
668 /* set FMT here !!! FIXME */
669
670 s->period = 0;
671 s->periods = 0;
672
673 return 0;
674}
675
676static snd_pcm_uframes_t snd_sa11xx_uda1341_pointer(struct snd_pcm_substream *substream)
677{
678 struct sa11xx_uda1341 *chip = snd_pcm_substream_chip(substream);
679 return audio_get_dma_pos(&chip->s[substream->pstr->stream]);
680}
681
682/* }}} */
683
684static struct snd_pcm_hardware snd_sa11xx_uda1341_capture =
685{
686 .info = (SNDRV_PCM_INFO_INTERLEAVED |
687 SNDRV_PCM_INFO_BLOCK_TRANSFER |
688 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
689 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
690 .formats = SNDRV_PCM_FMTBIT_S16_LE,
691 .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
692 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |\
693 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
694 SNDRV_PCM_RATE_KNOT),
695 .rate_min = 8000,
696 .rate_max = 48000,
697 .channels_min = 2,
698 .channels_max = 2,
699 .buffer_bytes_max = 64*1024,
700 .period_bytes_min = 64,
701 .period_bytes_max = DMA_BUF_SIZE,
702 .periods_min = 2,
703 .periods_max = 255,
704 .fifo_size = 0,
705};
706
707static struct snd_pcm_hardware snd_sa11xx_uda1341_playback =
708{
709 .info = (SNDRV_PCM_INFO_INTERLEAVED |
710 SNDRV_PCM_INFO_BLOCK_TRANSFER |
711 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
712 SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME),
713 .formats = SNDRV_PCM_FMTBIT_S16_LE,
714 .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |\
715 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |\
716 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
717 SNDRV_PCM_RATE_KNOT),
718 .rate_min = 8000,
719 .rate_max = 48000,
720 .channels_min = 2,
721 .channels_max = 2,
722 .buffer_bytes_max = 64*1024,
723 .period_bytes_min = 64,
724 .period_bytes_max = DMA_BUF_SIZE,
725 .periods_min = 2,
726 .periods_max = 255,
727 .fifo_size = 0,
728};
729
730static int snd_card_sa11xx_uda1341_open(struct snd_pcm_substream *substream)
731{
732 struct sa11xx_uda1341 *chip = snd_pcm_substream_chip(substream);
733 struct snd_pcm_runtime *runtime = substream->runtime;
734 int stream_id = substream->pstr->stream;
735 int err;
736
737 chip->s[stream_id].stream = substream;
738
739 if (stream_id == SNDRV_PCM_STREAM_PLAYBACK)
740 runtime->hw = snd_sa11xx_uda1341_playback;
741 else
742 runtime->hw = snd_sa11xx_uda1341_capture;
743 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
744 return err;
745 if ((err = snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates)) < 0)
746 return err;
747
748 return 0;
749}
750
751static int snd_card_sa11xx_uda1341_close(struct snd_pcm_substream *substream)
752{
753 struct sa11xx_uda1341 *chip = snd_pcm_substream_chip(substream);
754
755 chip->s[substream->pstr->stream].stream = NULL;
756 return 0;
757}
758
759/* {{{ HW params & free */
760
761static int snd_sa11xx_uda1341_hw_params(struct snd_pcm_substream *substream,
762 struct snd_pcm_hw_params *hw_params)
763{
764
765 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
766}
767
768static int snd_sa11xx_uda1341_hw_free(struct snd_pcm_substream *substream)
769{
770 return snd_pcm_lib_free_pages(substream);
771}
772
773/* }}} */
774
775static struct snd_pcm_ops snd_card_sa11xx_uda1341_playback_ops = {
776 .open = snd_card_sa11xx_uda1341_open,
777 .close = snd_card_sa11xx_uda1341_close,
778 .ioctl = snd_pcm_lib_ioctl,
779 .hw_params = snd_sa11xx_uda1341_hw_params,
780 .hw_free = snd_sa11xx_uda1341_hw_free,
781 .prepare = snd_sa11xx_uda1341_prepare,
782 .trigger = snd_sa11xx_uda1341_trigger,
783 .pointer = snd_sa11xx_uda1341_pointer,
784};
785
786static struct snd_pcm_ops snd_card_sa11xx_uda1341_capture_ops = {
787 .open = snd_card_sa11xx_uda1341_open,
788 .close = snd_card_sa11xx_uda1341_close,
789 .ioctl = snd_pcm_lib_ioctl,
790 .hw_params = snd_sa11xx_uda1341_hw_params,
791 .hw_free = snd_sa11xx_uda1341_hw_free,
792 .prepare = snd_sa11xx_uda1341_prepare,
793 .trigger = snd_sa11xx_uda1341_trigger,
794 .pointer = snd_sa11xx_uda1341_pointer,
795};
796
797static int __init snd_card_sa11xx_uda1341_pcm(struct sa11xx_uda1341 *sa11xx_uda1341, int device)
798{
799 struct snd_pcm *pcm;
800 int err;
801
802 if ((err = snd_pcm_new(sa11xx_uda1341->card, "UDA1341 PCM", device, 1, 1, &pcm)) < 0)
803 return err;
804
805 /*
806 * this sets up our initial buffers and sets the dma_type to isa.
807 * isa works but I'm not sure why (or if) it's the right choice
808 * this may be too large, trying it for now
809 */
810 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
811 snd_dma_isa_data(),
812 64*1024, 64*1024);
813
814 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_card_sa11xx_uda1341_playback_ops);
815 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_card_sa11xx_uda1341_capture_ops);
816 pcm->private_data = sa11xx_uda1341;
817 pcm->info_flags = 0;
818 strcpy(pcm->name, "UDA1341 PCM");
819
820 sa11xx_uda1341_audio_init(sa11xx_uda1341);
821
822 /* setup DMA controller */
823 audio_dma_request(&sa11xx_uda1341->s[SNDRV_PCM_STREAM_PLAYBACK], audio_dma_callback);
824 audio_dma_request(&sa11xx_uda1341->s[SNDRV_PCM_STREAM_CAPTURE], audio_dma_callback);
825
826 sa11xx_uda1341->pcm = pcm;
827
828 return 0;
829}
830
831/* }}} */
832
833/* {{{ module init & exit */
834
835#ifdef CONFIG_PM
836
837static int snd_sa11xx_uda1341_suspend(struct platform_device *devptr,
838 pm_message_t state)
839{
840 struct snd_card *card = platform_get_drvdata(devptr);
841 struct sa11xx_uda1341 *chip = card->private_data;
842
843 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
844 snd_pcm_suspend_all(chip->pcm);
845#ifdef HH_VERSION
846 sa1100_dma_sleep(chip->s[SNDRV_PCM_STREAM_PLAYBACK].dmach);
847 sa1100_dma_sleep(chip->s[SNDRV_PCM_STREAM_CAPTURE].dmach);
848#else
849 //FIXME
850#endif
851 l3_command(chip->uda1341, CMD_SUSPEND, NULL);
852 sa11xx_uda1341_audio_shutdown(chip);
853
854 return 0;
855}
856
857static int snd_sa11xx_uda1341_resume(struct platform_device *devptr)
858{
859 struct snd_card *card = platform_get_drvdata(devptr);
860 struct sa11xx_uda1341 *chip = card->private_data;
861
862 sa11xx_uda1341_audio_init(chip);
863 l3_command(chip->uda1341, CMD_RESUME, NULL);
864#ifdef HH_VERSION
865 sa1100_dma_wakeup(chip->s[SNDRV_PCM_STREAM_PLAYBACK].dmach);
866 sa1100_dma_wakeup(chip->s[SNDRV_PCM_STREAM_CAPTURE].dmach);
867#else
868 //FIXME
869#endif
870 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
871 return 0;
872}
873#endif /* COMFIG_PM */
874
875void snd_sa11xx_uda1341_free(struct snd_card *card)
876{
877 struct sa11xx_uda1341 *chip = card->private_data;
878
879 audio_dma_free(&chip->s[SNDRV_PCM_STREAM_PLAYBACK]);
880 audio_dma_free(&chip->s[SNDRV_PCM_STREAM_CAPTURE]);
881}
882
883static int __devinit sa11xx_uda1341_probe(struct platform_device *devptr)
884{
885 int err;
886 struct snd_card *card;
887 struct sa11xx_uda1341 *chip;
888
889 /* register the soundcard */
890 card = snd_card_new(-1, id, THIS_MODULE, sizeof(struct sa11xx_uda1341));
891 if (card == NULL)
892 return -ENOMEM;
893
894 chip = card->private_data;
895 spin_lock_init(&chip->s[0].dma_lock);
896 spin_lock_init(&chip->s[1].dma_lock);
897
898 card->private_free = snd_sa11xx_uda1341_free;
899 chip->card = card;
900 chip->samplerate = AUDIO_RATE_DEFAULT;
901
902 // mixer
903 if ((err = snd_chip_uda1341_mixer_new(card, &chip->uda1341)))
904 goto nodev;
905
906 // PCM
907 if ((err = snd_card_sa11xx_uda1341_pcm(chip, 0)) < 0)
908 goto nodev;
909
910 strcpy(card->driver, "UDA1341");
911 strcpy(card->shortname, "H3600 UDA1341TS");
912 sprintf(card->longname, "Compaq iPAQ H3600 with Philips UDA1341TS");
913
914 snd_card_set_dev(card, &devptr->dev);
915
916 if ((err = snd_card_register(card)) == 0) {
917 printk( KERN_INFO "iPAQ audio support initialized\n" );
918 platform_set_drvdata(devptr, card);
919 return 0;
920 }
921
922 nodev:
923 snd_card_free(card);
924 return err;
925}
926
927static int __devexit sa11xx_uda1341_remove(struct platform_device *devptr)
928{
929 snd_card_free(platform_get_drvdata(devptr));
930 platform_set_drvdata(devptr, NULL);
931 return 0;
932}
933
934#define SA11XX_UDA1341_DRIVER "sa11xx_uda1341"
935
936static struct platform_driver sa11xx_uda1341_driver = {
937 .probe = sa11xx_uda1341_probe,
938 .remove = __devexit_p(sa11xx_uda1341_remove),
939#ifdef CONFIG_PM
940 .suspend = snd_sa11xx_uda1341_suspend,
941 .resume = snd_sa11xx_uda1341_resume,
942#endif
943 .driver = {
944 .name = SA11XX_UDA1341_DRIVER,
945 },
946};
947
948static int __init sa11xx_uda1341_init(void)
949{
950 int err;
951
952 if (!machine_is_h3xxx())
953 return -ENODEV;
954 if ((err = platform_driver_register(&sa11xx_uda1341_driver)) < 0)
955 return err;
956 device = platform_device_register_simple(SA11XX_UDA1341_DRIVER, -1, NULL, 0);
957 if (!IS_ERR(device)) {
958 if (platform_get_drvdata(device))
959 return 0;
960 platform_device_unregister(device);
961 err = -ENODEV;
962 } else
963 err = PTR_ERR(device);
964 platform_driver_unregister(&sa11xx_uda1341_driver);
965 return err;
966}
967
968static void __exit sa11xx_uda1341_exit(void)
969{
970 platform_device_unregister(device);
971 platform_driver_unregister(&sa11xx_uda1341_driver);
972}
973
974module_init(sa11xx_uda1341_init);
975module_exit(sa11xx_uda1341_exit);
976
977/* }}} */
978
979/*
980 * Local variables:
981 * indent-tabs-mode: t
982 * End:
983 */
diff --git a/sound/atmel/Kconfig b/sound/atmel/Kconfig
new file mode 100644
index 000000000000..6c228a91940d
--- /dev/null
+++ b/sound/atmel/Kconfig
@@ -0,0 +1,19 @@
1menu "Atmel devices (AVR32 and AT91)"
2 depends on AVR32 || ARCH_AT91
3
4config SND_ATMEL_ABDAC
5 tristate "Atmel Audio Bitstream DAC (ABDAC) driver"
6 select SND_PCM
7 depends on DW_DMAC && AVR32
8 help
9 ALSA sound driver for the Atmel Audio Bitstream DAC (ABDAC).
10
11config SND_ATMEL_AC97C
12 tristate "Atmel AC97 Controller (AC97C) driver"
13 select SND_PCM
14 select SND_AC97_CODEC
15 depends on DW_DMAC && AVR32
16 help
17 ALSA sound driver for the Atmel AC97 controller.
18
19endmenu
diff --git a/sound/atmel/Makefile b/sound/atmel/Makefile
new file mode 100644
index 000000000000..219dcfac6086
--- /dev/null
+++ b/sound/atmel/Makefile
@@ -0,0 +1,5 @@
1snd-atmel-abdac-objs := abdac.o
2snd-atmel-ac97c-objs := ac97c.o
3
4obj-$(CONFIG_SND_ATMEL_ABDAC) += snd-atmel-abdac.o
5obj-$(CONFIG_SND_ATMEL_AC97C) += snd-atmel-ac97c.o
diff --git a/sound/atmel/abdac.c b/sound/atmel/abdac.c
new file mode 100644
index 000000000000..28b3c7f7cfe6
--- /dev/null
+++ b/sound/atmel/abdac.c
@@ -0,0 +1,602 @@
1/*
2 * Driver for the Atmel on-chip Audio Bitstream DAC (ABDAC)
3 *
4 * Copyright (C) 2006-2009 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10#include <linux/clk.h>
11#include <linux/bitmap.h>
12#include <linux/dw_dmac.h>
13#include <linux/dmaengine.h>
14#include <linux/dma-mapping.h>
15#include <linux/init.h>
16#include <linux/interrupt.h>
17#include <linux/module.h>
18#include <linux/platform_device.h>
19#include <linux/io.h>
20
21#include <sound/core.h>
22#include <sound/initval.h>
23#include <sound/pcm.h>
24#include <sound/pcm_params.h>
25#include <sound/atmel-abdac.h>
26
27/* DAC register offsets */
28#define DAC_DATA 0x0000
29#define DAC_CTRL 0x0008
30#define DAC_INT_MASK 0x000c
31#define DAC_INT_EN 0x0010
32#define DAC_INT_DIS 0x0014
33#define DAC_INT_CLR 0x0018
34#define DAC_INT_STATUS 0x001c
35
36/* Bitfields in CTRL */
37#define DAC_SWAP_OFFSET 30
38#define DAC_SWAP_SIZE 1
39#define DAC_EN_OFFSET 31
40#define DAC_EN_SIZE 1
41
42/* Bitfields in INT_MASK/INT_EN/INT_DIS/INT_STATUS/INT_CLR */
43#define DAC_UNDERRUN_OFFSET 28
44#define DAC_UNDERRUN_SIZE 1
45#define DAC_TX_READY_OFFSET 29
46#define DAC_TX_READY_SIZE 1
47
48/* Bit manipulation macros */
49#define DAC_BIT(name) \
50 (1 << DAC_##name##_OFFSET)
51#define DAC_BF(name, value) \
52 (((value) & ((1 << DAC_##name##_SIZE) - 1)) \
53 << DAC_##name##_OFFSET)
54#define DAC_BFEXT(name, value) \
55 (((value) >> DAC_##name##_OFFSET) \
56 & ((1 << DAC_##name##_SIZE) - 1))
57#define DAC_BFINS(name, value, old) \
58 (((old) & ~(((1 << DAC_##name##_SIZE) - 1) \
59 << DAC_##name##_OFFSET)) \
60 | DAC_BF(name, value))
61
62/* Register access macros */
63#define dac_readl(port, reg) \
64 __raw_readl((port)->regs + DAC_##reg)
65#define dac_writel(port, reg, value) \
66 __raw_writel((value), (port)->regs + DAC_##reg)
67
68/*
69 * ABDAC supports a maximum of 6 different rates from a generic clock. The
70 * generic clock has a power of two divider, which gives 6 steps from 192 kHz
71 * to 5112 Hz.
72 */
73#define MAX_NUM_RATES 6
74/* ALSA seems to use rates between 192000 Hz and 5112 Hz. */
75#define RATE_MAX 192000
76#define RATE_MIN 5112
77
78enum {
79 DMA_READY = 0,
80};
81
82struct atmel_abdac_dma {
83 struct dma_chan *chan;
84 struct dw_cyclic_desc *cdesc;
85};
86
87struct atmel_abdac {
88 struct clk *pclk;
89 struct clk *sample_clk;
90 struct platform_device *pdev;
91 struct atmel_abdac_dma dma;
92
93 struct snd_pcm_hw_constraint_list constraints_rates;
94 struct snd_pcm_substream *substream;
95 struct snd_card *card;
96 struct snd_pcm *pcm;
97
98 void __iomem *regs;
99 unsigned long flags;
100 unsigned int rates[MAX_NUM_RATES];
101 unsigned int rates_num;
102 int irq;
103};
104
105#define get_dac(card) ((struct atmel_abdac *)(card)->private_data)
106
107/* This function is called by the DMA driver. */
108static void atmel_abdac_dma_period_done(void *arg)
109{
110 struct atmel_abdac *dac = arg;
111 snd_pcm_period_elapsed(dac->substream);
112}
113
114static int atmel_abdac_prepare_dma(struct atmel_abdac *dac,
115 struct snd_pcm_substream *substream,
116 enum dma_data_direction direction)
117{
118 struct dma_chan *chan = dac->dma.chan;
119 struct dw_cyclic_desc *cdesc;
120 struct snd_pcm_runtime *runtime = substream->runtime;
121 unsigned long buffer_len, period_len;
122
123 /*
124 * We don't do DMA on "complex" transfers, i.e. with
125 * non-halfword-aligned buffers or lengths.
126 */
127 if (runtime->dma_addr & 1 || runtime->buffer_size & 1) {
128 dev_dbg(&dac->pdev->dev, "too complex transfer\n");
129 return -EINVAL;
130 }
131
132 buffer_len = frames_to_bytes(runtime, runtime->buffer_size);
133 period_len = frames_to_bytes(runtime, runtime->period_size);
134
135 cdesc = dw_dma_cyclic_prep(chan, runtime->dma_addr, buffer_len,
136 period_len, DMA_TO_DEVICE);
137 if (IS_ERR(cdesc)) {
138 dev_dbg(&dac->pdev->dev, "could not prepare cyclic DMA\n");
139 return PTR_ERR(cdesc);
140 }
141
142 cdesc->period_callback = atmel_abdac_dma_period_done;
143 cdesc->period_callback_param = dac;
144
145 dac->dma.cdesc = cdesc;
146
147 set_bit(DMA_READY, &dac->flags);
148
149 return 0;
150}
151
152static struct snd_pcm_hardware atmel_abdac_hw = {
153 .info = (SNDRV_PCM_INFO_MMAP
154 | SNDRV_PCM_INFO_MMAP_VALID
155 | SNDRV_PCM_INFO_INTERLEAVED
156 | SNDRV_PCM_INFO_BLOCK_TRANSFER
157 | SNDRV_PCM_INFO_RESUME
158 | SNDRV_PCM_INFO_PAUSE),
159 .formats = (SNDRV_PCM_FMTBIT_S16_BE),
160 .rates = (SNDRV_PCM_RATE_KNOT),
161 .rate_min = RATE_MIN,
162 .rate_max = RATE_MAX,
163 .channels_min = 2,
164 .channels_max = 2,
165 .buffer_bytes_max = 64 * 4096,
166 .period_bytes_min = 4096,
167 .period_bytes_max = 4096,
168 .periods_min = 4,
169 .periods_max = 64,
170};
171
172static int atmel_abdac_open(struct snd_pcm_substream *substream)
173{
174 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
175
176 dac->substream = substream;
177 atmel_abdac_hw.rate_max = dac->rates[dac->rates_num - 1];
178 atmel_abdac_hw.rate_min = dac->rates[0];
179 substream->runtime->hw = atmel_abdac_hw;
180
181 return snd_pcm_hw_constraint_list(substream->runtime, 0,
182 SNDRV_PCM_HW_PARAM_RATE, &dac->constraints_rates);
183}
184
185static int atmel_abdac_close(struct snd_pcm_substream *substream)
186{
187 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
188 dac->substream = NULL;
189 return 0;
190}
191
192static int atmel_abdac_hw_params(struct snd_pcm_substream *substream,
193 struct snd_pcm_hw_params *hw_params)
194{
195 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
196 int retval;
197
198 retval = snd_pcm_lib_malloc_pages(substream,
199 params_buffer_bytes(hw_params));
200 if (retval < 0)
201 return retval;
202 /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
203 if (retval == 1)
204 if (test_and_clear_bit(DMA_READY, &dac->flags))
205 dw_dma_cyclic_free(dac->dma.chan);
206
207 return retval;
208}
209
210static int atmel_abdac_hw_free(struct snd_pcm_substream *substream)
211{
212 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
213 if (test_and_clear_bit(DMA_READY, &dac->flags))
214 dw_dma_cyclic_free(dac->dma.chan);
215 return snd_pcm_lib_free_pages(substream);
216}
217
218static int atmel_abdac_prepare(struct snd_pcm_substream *substream)
219{
220 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
221 int retval;
222
223 retval = clk_set_rate(dac->sample_clk, 256 * substream->runtime->rate);
224 if (retval)
225 return retval;
226
227 if (!test_bit(DMA_READY, &dac->flags))
228 retval = atmel_abdac_prepare_dma(dac, substream, DMA_TO_DEVICE);
229
230 return retval;
231}
232
233static int atmel_abdac_trigger(struct snd_pcm_substream *substream, int cmd)
234{
235 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
236 int retval = 0;
237
238 switch (cmd) {
239 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
240 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
241 case SNDRV_PCM_TRIGGER_START:
242 clk_enable(dac->sample_clk);
243 retval = dw_dma_cyclic_start(dac->dma.chan);
244 if (retval)
245 goto out;
246 dac_writel(dac, CTRL, DAC_BIT(EN));
247 break;
248 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
249 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
250 case SNDRV_PCM_TRIGGER_STOP:
251 dw_dma_cyclic_stop(dac->dma.chan);
252 dac_writel(dac, DATA, 0);
253 dac_writel(dac, CTRL, 0);
254 clk_disable(dac->sample_clk);
255 break;
256 default:
257 retval = -EINVAL;
258 break;
259 }
260out:
261 return retval;
262}
263
264static snd_pcm_uframes_t
265atmel_abdac_pointer(struct snd_pcm_substream *substream)
266{
267 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
268 struct snd_pcm_runtime *runtime = substream->runtime;
269 snd_pcm_uframes_t frames;
270 unsigned long bytes;
271
272 bytes = dw_dma_get_src_addr(dac->dma.chan);
273 bytes -= runtime->dma_addr;
274
275 frames = bytes_to_frames(runtime, bytes);
276 if (frames >= runtime->buffer_size)
277 frames -= runtime->buffer_size;
278
279 return frames;
280}
281
282static irqreturn_t abdac_interrupt(int irq, void *dev_id)
283{
284 struct atmel_abdac *dac = dev_id;
285 u32 status;
286
287 status = dac_readl(dac, INT_STATUS);
288 if (status & DAC_BIT(UNDERRUN)) {
289 dev_err(&dac->pdev->dev, "underrun detected\n");
290 dac_writel(dac, INT_CLR, DAC_BIT(UNDERRUN));
291 } else {
292 dev_err(&dac->pdev->dev, "spurious interrupt (status=0x%x)\n",
293 status);
294 dac_writel(dac, INT_CLR, status);
295 }
296
297 return IRQ_HANDLED;
298}
299
300static struct snd_pcm_ops atmel_abdac_ops = {
301 .open = atmel_abdac_open,
302 .close = atmel_abdac_close,
303 .ioctl = snd_pcm_lib_ioctl,
304 .hw_params = atmel_abdac_hw_params,
305 .hw_free = atmel_abdac_hw_free,
306 .prepare = atmel_abdac_prepare,
307 .trigger = atmel_abdac_trigger,
308 .pointer = atmel_abdac_pointer,
309};
310
311static int __devinit atmel_abdac_pcm_new(struct atmel_abdac *dac)
312{
313 struct snd_pcm_hardware hw = atmel_abdac_hw;
314 struct snd_pcm *pcm;
315 int retval;
316
317 retval = snd_pcm_new(dac->card, dac->card->shortname,
318 dac->pdev->id, 1, 0, &pcm);
319 if (retval)
320 return retval;
321
322 strcpy(pcm->name, dac->card->shortname);
323 pcm->private_data = dac;
324 pcm->info_flags = 0;
325 dac->pcm = pcm;
326
327 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &atmel_abdac_ops);
328
329 retval = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
330 &dac->pdev->dev, hw.periods_min * hw.period_bytes_min,
331 hw.buffer_bytes_max);
332
333 return retval;
334}
335
336static bool filter(struct dma_chan *chan, void *slave)
337{
338 struct dw_dma_slave *dws = slave;
339
340 if (dws->dma_dev == chan->device->dev) {
341 chan->private = dws;
342 return true;
343 } else
344 return false;
345}
346
347static int set_sample_rates(struct atmel_abdac *dac)
348{
349 long new_rate = RATE_MAX;
350 int retval = -EINVAL;
351 int index = 0;
352
353 /* we start at 192 kHz and work our way down to 5112 Hz */
354 while (new_rate >= RATE_MIN && index < (MAX_NUM_RATES + 1)) {
355 new_rate = clk_round_rate(dac->sample_clk, 256 * new_rate);
356 if (new_rate < 0)
357 break;
358 /* make sure we are below the ABDAC clock */
359 if (new_rate <= clk_get_rate(dac->pclk)) {
360 dac->rates[index] = new_rate / 256;
361 index++;
362 }
363 /* divide by 256 and then by two to get next rate */
364 new_rate /= 256 * 2;
365 }
366
367 if (index) {
368 int i;
369
370 /* reverse array, smallest go first */
371 for (i = 0; i < (index / 2); i++) {
372 unsigned int tmp = dac->rates[index - 1 - i];
373 dac->rates[index - 1 - i] = dac->rates[i];
374 dac->rates[i] = tmp;
375 }
376
377 dac->constraints_rates.count = index;
378 dac->constraints_rates.list = dac->rates;
379 dac->constraints_rates.mask = 0;
380 dac->rates_num = index;
381
382 retval = 0;
383 }
384
385 return retval;
386}
387
388static int __devinit atmel_abdac_probe(struct platform_device *pdev)
389{
390 struct snd_card *card;
391 struct atmel_abdac *dac;
392 struct resource *regs;
393 struct atmel_abdac_pdata *pdata;
394 struct clk *pclk;
395 struct clk *sample_clk;
396 int retval;
397 int irq;
398
399 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
400 if (!regs) {
401 dev_dbg(&pdev->dev, "no memory resource\n");
402 return -ENXIO;
403 }
404
405 irq = platform_get_irq(pdev, 0);
406 if (irq < 0) {
407 dev_dbg(&pdev->dev, "could not get IRQ number\n");
408 return irq;
409 }
410
411 pdata = pdev->dev.platform_data;
412 if (!pdata) {
413 dev_dbg(&pdev->dev, "no platform data\n");
414 return -ENXIO;
415 }
416
417 pclk = clk_get(&pdev->dev, "pclk");
418 if (IS_ERR(pclk)) {
419 dev_dbg(&pdev->dev, "no peripheral clock\n");
420 return PTR_ERR(pclk);
421 }
422 sample_clk = clk_get(&pdev->dev, "sample_clk");
423 if (IS_ERR(pclk)) {
424 dev_dbg(&pdev->dev, "no sample clock\n");
425 retval = PTR_ERR(pclk);
426 goto out_put_pclk;
427 }
428 clk_enable(pclk);
429
430 retval = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
431 THIS_MODULE, sizeof(struct atmel_abdac), &card);
432 if (retval) {
433 dev_dbg(&pdev->dev, "could not create sound card device\n");
434 goto out_put_sample_clk;
435 }
436
437 dac = get_dac(card);
438
439 dac->irq = irq;
440 dac->card = card;
441 dac->pclk = pclk;
442 dac->sample_clk = sample_clk;
443 dac->pdev = pdev;
444
445 retval = set_sample_rates(dac);
446 if (retval < 0) {
447 dev_dbg(&pdev->dev, "could not set supported rates\n");
448 goto out_free_card;
449 }
450
451 dac->regs = ioremap(regs->start, regs->end - regs->start + 1);
452 if (!dac->regs) {
453 dev_dbg(&pdev->dev, "could not remap register memory\n");
454 goto out_free_card;
455 }
456
457 /* make sure the DAC is silent and disabled */
458 dac_writel(dac, DATA, 0);
459 dac_writel(dac, CTRL, 0);
460
461 retval = request_irq(irq, abdac_interrupt, 0, "abdac", dac);
462 if (retval) {
463 dev_dbg(&pdev->dev, "could not request irq\n");
464 goto out_unmap_regs;
465 }
466
467 snd_card_set_dev(card, &pdev->dev);
468
469 if (pdata->dws.dma_dev) {
470 struct dw_dma_slave *dws = &pdata->dws;
471 dma_cap_mask_t mask;
472
473 dws->tx_reg = regs->start + DAC_DATA;
474
475 dma_cap_zero(mask);
476 dma_cap_set(DMA_SLAVE, mask);
477
478 dac->dma.chan = dma_request_channel(mask, filter, dws);
479 }
480 if (!pdata->dws.dma_dev || !dac->dma.chan) {
481 dev_dbg(&pdev->dev, "DMA not available\n");
482 retval = -ENODEV;
483 goto out_unset_card_dev;
484 }
485
486 strcpy(card->driver, "Atmel ABDAC");
487 strcpy(card->shortname, "Atmel ABDAC");
488 sprintf(card->longname, "Atmel Audio Bitstream DAC");
489
490 retval = atmel_abdac_pcm_new(dac);
491 if (retval) {
492 dev_dbg(&pdev->dev, "could not register ABDAC pcm device\n");
493 goto out_release_dma;
494 }
495
496 retval = snd_card_register(card);
497 if (retval) {
498 dev_dbg(&pdev->dev, "could not register sound card\n");
499 goto out_release_dma;
500 }
501
502 platform_set_drvdata(pdev, card);
503
504 dev_info(&pdev->dev, "Atmel ABDAC at 0x%p using %s\n",
505 dac->regs, dac->dma.chan->dev->device.bus_id);
506
507 return retval;
508
509out_release_dma:
510 dma_release_channel(dac->dma.chan);
511 dac->dma.chan = NULL;
512out_unset_card_dev:
513 snd_card_set_dev(card, NULL);
514 free_irq(irq, dac);
515out_unmap_regs:
516 iounmap(dac->regs);
517out_free_card:
518 snd_card_free(card);
519out_put_sample_clk:
520 clk_put(sample_clk);
521 clk_disable(pclk);
522out_put_pclk:
523 clk_put(pclk);
524 return retval;
525}
526
527#ifdef CONFIG_PM
528static int atmel_abdac_suspend(struct platform_device *pdev, pm_message_t msg)
529{
530 struct snd_card *card = platform_get_drvdata(pdev);
531 struct atmel_abdac *dac = card->private_data;
532
533 dw_dma_cyclic_stop(dac->dma.chan);
534 clk_disable(dac->sample_clk);
535 clk_disable(dac->pclk);
536
537 return 0;
538}
539
540static int atmel_abdac_resume(struct platform_device *pdev)
541{
542 struct snd_card *card = platform_get_drvdata(pdev);
543 struct atmel_abdac *dac = card->private_data;
544
545 clk_enable(dac->pclk);
546 clk_enable(dac->sample_clk);
547 if (test_bit(DMA_READY, &dac->flags))
548 dw_dma_cyclic_start(dac->dma.chan);
549
550 return 0;
551}
552#else
553#define atmel_abdac_suspend NULL
554#define atmel_abdac_resume NULL
555#endif
556
557static int __devexit atmel_abdac_remove(struct platform_device *pdev)
558{
559 struct snd_card *card = platform_get_drvdata(pdev);
560 struct atmel_abdac *dac = get_dac(card);
561
562 clk_put(dac->sample_clk);
563 clk_disable(dac->pclk);
564 clk_put(dac->pclk);
565
566 dma_release_channel(dac->dma.chan);
567 dac->dma.chan = NULL;
568 snd_card_set_dev(card, NULL);
569 iounmap(dac->regs);
570 free_irq(dac->irq, dac);
571 snd_card_free(card);
572
573 platform_set_drvdata(pdev, NULL);
574
575 return 0;
576}
577
578static struct platform_driver atmel_abdac_driver = {
579 .remove = __devexit_p(atmel_abdac_remove),
580 .driver = {
581 .name = "atmel_abdac",
582 },
583 .suspend = atmel_abdac_suspend,
584 .resume = atmel_abdac_resume,
585};
586
587static int __init atmel_abdac_init(void)
588{
589 return platform_driver_probe(&atmel_abdac_driver,
590 atmel_abdac_probe);
591}
592module_init(atmel_abdac_init);
593
594static void __exit atmel_abdac_exit(void)
595{
596 platform_driver_unregister(&atmel_abdac_driver);
597}
598module_exit(atmel_abdac_exit);
599
600MODULE_LICENSE("GPL");
601MODULE_DESCRIPTION("Driver for Atmel Audio Bitstream DAC (ABDAC)");
602MODULE_AUTHOR("Hans-Christian Egtvedt <hans-christian.egtvedt@atmel.com>");
diff --git a/sound/atmel/ac97c.c b/sound/atmel/ac97c.c
new file mode 100644
index 000000000000..dd72e00e5ae1
--- /dev/null
+++ b/sound/atmel/ac97c.c
@@ -0,0 +1,932 @@
1/*
2 * Driver for the Atmel AC97C controller
3 *
4 * Copyright (C) 2005-2009 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10#include <linux/clk.h>
11#include <linux/delay.h>
12#include <linux/bitmap.h>
13#include <linux/dmaengine.h>
14#include <linux/dma-mapping.h>
15#include <linux/init.h>
16#include <linux/interrupt.h>
17#include <linux/module.h>
18#include <linux/platform_device.h>
19#include <linux/mutex.h>
20#include <linux/gpio.h>
21#include <linux/io.h>
22
23#include <sound/core.h>
24#include <sound/initval.h>
25#include <sound/pcm.h>
26#include <sound/pcm_params.h>
27#include <sound/ac97_codec.h>
28#include <sound/atmel-ac97c.h>
29#include <sound/memalloc.h>
30
31#include <linux/dw_dmac.h>
32
33#include "ac97c.h"
34
35enum {
36 DMA_TX_READY = 0,
37 DMA_RX_READY,
38 DMA_TX_CHAN_PRESENT,
39 DMA_RX_CHAN_PRESENT,
40};
41
42/* Serialize access to opened variable */
43static DEFINE_MUTEX(opened_mutex);
44
45struct atmel_ac97c_dma {
46 struct dma_chan *rx_chan;
47 struct dma_chan *tx_chan;
48};
49
50struct atmel_ac97c {
51 struct clk *pclk;
52 struct platform_device *pdev;
53 struct atmel_ac97c_dma dma;
54
55 struct snd_pcm_substream *playback_substream;
56 struct snd_pcm_substream *capture_substream;
57 struct snd_card *card;
58 struct snd_pcm *pcm;
59 struct snd_ac97 *ac97;
60 struct snd_ac97_bus *ac97_bus;
61
62 u64 cur_format;
63 unsigned int cur_rate;
64 unsigned long flags;
65 /* Serialize access to opened variable */
66 spinlock_t lock;
67 void __iomem *regs;
68 int opened;
69 int reset_pin;
70};
71
72#define get_chip(card) ((struct atmel_ac97c *)(card)->private_data)
73
74#define ac97c_writel(chip, reg, val) \
75 __raw_writel((val), (chip)->regs + AC97C_##reg)
76#define ac97c_readl(chip, reg) \
77 __raw_readl((chip)->regs + AC97C_##reg)
78
79/* This function is called by the DMA driver. */
80static void atmel_ac97c_dma_playback_period_done(void *arg)
81{
82 struct atmel_ac97c *chip = arg;
83 snd_pcm_period_elapsed(chip->playback_substream);
84}
85
86static void atmel_ac97c_dma_capture_period_done(void *arg)
87{
88 struct atmel_ac97c *chip = arg;
89 snd_pcm_period_elapsed(chip->capture_substream);
90}
91
92static int atmel_ac97c_prepare_dma(struct atmel_ac97c *chip,
93 struct snd_pcm_substream *substream,
94 enum dma_data_direction direction)
95{
96 struct dma_chan *chan;
97 struct dw_cyclic_desc *cdesc;
98 struct snd_pcm_runtime *runtime = substream->runtime;
99 unsigned long buffer_len, period_len;
100
101 /*
102 * We don't do DMA on "complex" transfers, i.e. with
103 * non-halfword-aligned buffers or lengths.
104 */
105 if (runtime->dma_addr & 1 || runtime->buffer_size & 1) {
106 dev_dbg(&chip->pdev->dev, "too complex transfer\n");
107 return -EINVAL;
108 }
109
110 if (direction == DMA_TO_DEVICE)
111 chan = chip->dma.tx_chan;
112 else
113 chan = chip->dma.rx_chan;
114
115 buffer_len = frames_to_bytes(runtime, runtime->buffer_size);
116 period_len = frames_to_bytes(runtime, runtime->period_size);
117
118 cdesc = dw_dma_cyclic_prep(chan, runtime->dma_addr, buffer_len,
119 period_len, direction);
120 if (IS_ERR(cdesc)) {
121 dev_dbg(&chip->pdev->dev, "could not prepare cyclic DMA\n");
122 return PTR_ERR(cdesc);
123 }
124
125 if (direction == DMA_TO_DEVICE) {
126 cdesc->period_callback = atmel_ac97c_dma_playback_period_done;
127 set_bit(DMA_TX_READY, &chip->flags);
128 } else {
129 cdesc->period_callback = atmel_ac97c_dma_capture_period_done;
130 set_bit(DMA_RX_READY, &chip->flags);
131 }
132
133 cdesc->period_callback_param = chip;
134
135 return 0;
136}
137
138static struct snd_pcm_hardware atmel_ac97c_hw = {
139 .info = (SNDRV_PCM_INFO_MMAP
140 | SNDRV_PCM_INFO_MMAP_VALID
141 | SNDRV_PCM_INFO_INTERLEAVED
142 | SNDRV_PCM_INFO_BLOCK_TRANSFER
143 | SNDRV_PCM_INFO_JOINT_DUPLEX
144 | SNDRV_PCM_INFO_RESUME
145 | SNDRV_PCM_INFO_PAUSE),
146 .formats = (SNDRV_PCM_FMTBIT_S16_BE
147 | SNDRV_PCM_FMTBIT_S16_LE),
148 .rates = (SNDRV_PCM_RATE_CONTINUOUS),
149 .rate_min = 4000,
150 .rate_max = 48000,
151 .channels_min = 1,
152 .channels_max = 2,
153 .buffer_bytes_max = 64 * 4096,
154 .period_bytes_min = 4096,
155 .period_bytes_max = 4096,
156 .periods_min = 4,
157 .periods_max = 64,
158};
159
160static int atmel_ac97c_playback_open(struct snd_pcm_substream *substream)
161{
162 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
163 struct snd_pcm_runtime *runtime = substream->runtime;
164
165 mutex_lock(&opened_mutex);
166 chip->opened++;
167 runtime->hw = atmel_ac97c_hw;
168 if (chip->cur_rate) {
169 runtime->hw.rate_min = chip->cur_rate;
170 runtime->hw.rate_max = chip->cur_rate;
171 }
172 if (chip->cur_format)
173 runtime->hw.formats = (1ULL << chip->cur_format);
174 mutex_unlock(&opened_mutex);
175 chip->playback_substream = substream;
176 return 0;
177}
178
179static int atmel_ac97c_capture_open(struct snd_pcm_substream *substream)
180{
181 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
182 struct snd_pcm_runtime *runtime = substream->runtime;
183
184 mutex_lock(&opened_mutex);
185 chip->opened++;
186 runtime->hw = atmel_ac97c_hw;
187 if (chip->cur_rate) {
188 runtime->hw.rate_min = chip->cur_rate;
189 runtime->hw.rate_max = chip->cur_rate;
190 }
191 if (chip->cur_format)
192 runtime->hw.formats = (1ULL << chip->cur_format);
193 mutex_unlock(&opened_mutex);
194 chip->capture_substream = substream;
195 return 0;
196}
197
198static int atmel_ac97c_playback_close(struct snd_pcm_substream *substream)
199{
200 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
201
202 mutex_lock(&opened_mutex);
203 chip->opened--;
204 if (!chip->opened) {
205 chip->cur_rate = 0;
206 chip->cur_format = 0;
207 }
208 mutex_unlock(&opened_mutex);
209
210 chip->playback_substream = NULL;
211
212 return 0;
213}
214
215static int atmel_ac97c_capture_close(struct snd_pcm_substream *substream)
216{
217 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
218
219 mutex_lock(&opened_mutex);
220 chip->opened--;
221 if (!chip->opened) {
222 chip->cur_rate = 0;
223 chip->cur_format = 0;
224 }
225 mutex_unlock(&opened_mutex);
226
227 chip->capture_substream = NULL;
228
229 return 0;
230}
231
232static int atmel_ac97c_playback_hw_params(struct snd_pcm_substream *substream,
233 struct snd_pcm_hw_params *hw_params)
234{
235 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
236 int retval;
237
238 retval = snd_pcm_lib_malloc_pages(substream,
239 params_buffer_bytes(hw_params));
240 if (retval < 0)
241 return retval;
242 /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
243 if (retval == 1)
244 if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
245 dw_dma_cyclic_free(chip->dma.tx_chan);
246
247 /* Set restrictions to params. */
248 mutex_lock(&opened_mutex);
249 chip->cur_rate = params_rate(hw_params);
250 chip->cur_format = params_format(hw_params);
251 mutex_unlock(&opened_mutex);
252
253 return retval;
254}
255
256static int atmel_ac97c_capture_hw_params(struct snd_pcm_substream *substream,
257 struct snd_pcm_hw_params *hw_params)
258{
259 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
260 int retval;
261
262 retval = snd_pcm_lib_malloc_pages(substream,
263 params_buffer_bytes(hw_params));
264 if (retval < 0)
265 return retval;
266 /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
267 if (retval == 1)
268 if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
269 dw_dma_cyclic_free(chip->dma.rx_chan);
270
271 /* Set restrictions to params. */
272 mutex_lock(&opened_mutex);
273 chip->cur_rate = params_rate(hw_params);
274 chip->cur_format = params_format(hw_params);
275 mutex_unlock(&opened_mutex);
276
277 return retval;
278}
279
280static int atmel_ac97c_playback_hw_free(struct snd_pcm_substream *substream)
281{
282 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
283 if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
284 dw_dma_cyclic_free(chip->dma.tx_chan);
285 return snd_pcm_lib_free_pages(substream);
286}
287
288static int atmel_ac97c_capture_hw_free(struct snd_pcm_substream *substream)
289{
290 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
291 if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
292 dw_dma_cyclic_free(chip->dma.rx_chan);
293 return snd_pcm_lib_free_pages(substream);
294}
295
296static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
297{
298 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
299 struct snd_pcm_runtime *runtime = substream->runtime;
300 unsigned long word = 0;
301 int retval;
302
303 /* assign channels to AC97C channel A */
304 switch (runtime->channels) {
305 case 1:
306 word |= AC97C_CH_ASSIGN(PCM_LEFT, A);
307 break;
308 case 2:
309 word |= AC97C_CH_ASSIGN(PCM_LEFT, A)
310 | AC97C_CH_ASSIGN(PCM_RIGHT, A);
311 break;
312 default:
313 /* TODO: support more than two channels */
314 return -EINVAL;
315 break;
316 }
317 ac97c_writel(chip, OCA, word);
318
319 /* configure sample format and size */
320 word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
321
322 switch (runtime->format) {
323 case SNDRV_PCM_FORMAT_S16_LE:
324 word |= AC97C_CMR_CEM_LITTLE;
325 break;
326 case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
327 default:
328 word &= ~(AC97C_CMR_CEM_LITTLE);
329 break;
330 }
331
332 ac97c_writel(chip, CAMR, word);
333
334 /* set variable rate if needed */
335 if (runtime->rate != 48000) {
336 word = ac97c_readl(chip, MR);
337 word |= AC97C_MR_VRA;
338 ac97c_writel(chip, MR, word);
339 } else {
340 word = ac97c_readl(chip, MR);
341 word &= ~(AC97C_MR_VRA);
342 ac97c_writel(chip, MR, word);
343 }
344
345 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE,
346 runtime->rate);
347 if (retval)
348 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
349 runtime->rate);
350
351 if (!test_bit(DMA_TX_READY, &chip->flags))
352 retval = atmel_ac97c_prepare_dma(chip, substream,
353 DMA_TO_DEVICE);
354
355 return retval;
356}
357
358static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
359{
360 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
361 struct snd_pcm_runtime *runtime = substream->runtime;
362 unsigned long word = 0;
363 int retval;
364
365 /* assign channels to AC97C channel A */
366 switch (runtime->channels) {
367 case 1:
368 word |= AC97C_CH_ASSIGN(PCM_LEFT, A);
369 break;
370 case 2:
371 word |= AC97C_CH_ASSIGN(PCM_LEFT, A)
372 | AC97C_CH_ASSIGN(PCM_RIGHT, A);
373 break;
374 default:
375 /* TODO: support more than two channels */
376 return -EINVAL;
377 break;
378 }
379 ac97c_writel(chip, ICA, word);
380
381 /* configure sample format and size */
382 word = AC97C_CMR_DMAEN | AC97C_CMR_SIZE_16;
383
384 switch (runtime->format) {
385 case SNDRV_PCM_FORMAT_S16_LE:
386 word |= AC97C_CMR_CEM_LITTLE;
387 break;
388 case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
389 default:
390 word &= ~(AC97C_CMR_CEM_LITTLE);
391 break;
392 }
393
394 ac97c_writel(chip, CAMR, word);
395
396 /* set variable rate if needed */
397 if (runtime->rate != 48000) {
398 word = ac97c_readl(chip, MR);
399 word |= AC97C_MR_VRA;
400 ac97c_writel(chip, MR, word);
401 } else {
402 word = ac97c_readl(chip, MR);
403 word &= ~(AC97C_MR_VRA);
404 ac97c_writel(chip, MR, word);
405 }
406
407 retval = snd_ac97_set_rate(chip->ac97, AC97_PCM_LR_ADC_RATE,
408 runtime->rate);
409 if (retval)
410 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
411 runtime->rate);
412
413 if (!test_bit(DMA_RX_READY, &chip->flags))
414 retval = atmel_ac97c_prepare_dma(chip, substream,
415 DMA_FROM_DEVICE);
416
417 return retval;
418}
419
420static int
421atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd)
422{
423 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
424 unsigned long camr;
425 int retval = 0;
426
427 camr = ac97c_readl(chip, CAMR);
428
429 switch (cmd) {
430 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
431 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
432 case SNDRV_PCM_TRIGGER_START:
433 retval = dw_dma_cyclic_start(chip->dma.tx_chan);
434 if (retval)
435 goto out;
436 camr |= AC97C_CMR_CENA;
437 break;
438 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
439 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
440 case SNDRV_PCM_TRIGGER_STOP:
441 dw_dma_cyclic_stop(chip->dma.tx_chan);
442 if (chip->opened <= 1)
443 camr &= ~AC97C_CMR_CENA;
444 break;
445 default:
446 retval = -EINVAL;
447 goto out;
448 }
449
450 ac97c_writel(chip, CAMR, camr);
451out:
452 return retval;
453}
454
455static int
456atmel_ac97c_capture_trigger(struct snd_pcm_substream *substream, int cmd)
457{
458 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
459 unsigned long camr;
460 int retval = 0;
461
462 camr = ac97c_readl(chip, CAMR);
463
464 switch (cmd) {
465 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
466 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
467 case SNDRV_PCM_TRIGGER_START:
468 retval = dw_dma_cyclic_start(chip->dma.rx_chan);
469 if (retval)
470 goto out;
471 camr |= AC97C_CMR_CENA;
472 break;
473 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
474 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
475 case SNDRV_PCM_TRIGGER_STOP:
476 dw_dma_cyclic_stop(chip->dma.rx_chan);
477 if (chip->opened <= 1)
478 camr &= ~AC97C_CMR_CENA;
479 break;
480 default:
481 retval = -EINVAL;
482 break;
483 }
484
485 ac97c_writel(chip, CAMR, camr);
486out:
487 return retval;
488}
489
490static snd_pcm_uframes_t
491atmel_ac97c_playback_pointer(struct snd_pcm_substream *substream)
492{
493 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
494 struct snd_pcm_runtime *runtime = substream->runtime;
495 snd_pcm_uframes_t frames;
496 unsigned long bytes;
497
498 bytes = dw_dma_get_src_addr(chip->dma.tx_chan);
499 bytes -= runtime->dma_addr;
500
501 frames = bytes_to_frames(runtime, bytes);
502 if (frames >= runtime->buffer_size)
503 frames -= runtime->buffer_size;
504 return frames;
505}
506
507static snd_pcm_uframes_t
508atmel_ac97c_capture_pointer(struct snd_pcm_substream *substream)
509{
510 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
511 struct snd_pcm_runtime *runtime = substream->runtime;
512 snd_pcm_uframes_t frames;
513 unsigned long bytes;
514
515 bytes = dw_dma_get_dst_addr(chip->dma.rx_chan);
516 bytes -= runtime->dma_addr;
517
518 frames = bytes_to_frames(runtime, bytes);
519 if (frames >= runtime->buffer_size)
520 frames -= runtime->buffer_size;
521 return frames;
522}
523
524static struct snd_pcm_ops atmel_ac97_playback_ops = {
525 .open = atmel_ac97c_playback_open,
526 .close = atmel_ac97c_playback_close,
527 .ioctl = snd_pcm_lib_ioctl,
528 .hw_params = atmel_ac97c_playback_hw_params,
529 .hw_free = atmel_ac97c_playback_hw_free,
530 .prepare = atmel_ac97c_playback_prepare,
531 .trigger = atmel_ac97c_playback_trigger,
532 .pointer = atmel_ac97c_playback_pointer,
533};
534
535static struct snd_pcm_ops atmel_ac97_capture_ops = {
536 .open = atmel_ac97c_capture_open,
537 .close = atmel_ac97c_capture_close,
538 .ioctl = snd_pcm_lib_ioctl,
539 .hw_params = atmel_ac97c_capture_hw_params,
540 .hw_free = atmel_ac97c_capture_hw_free,
541 .prepare = atmel_ac97c_capture_prepare,
542 .trigger = atmel_ac97c_capture_trigger,
543 .pointer = atmel_ac97c_capture_pointer,
544};
545
546static int __devinit atmel_ac97c_pcm_new(struct atmel_ac97c *chip)
547{
548 struct snd_pcm *pcm;
549 struct snd_pcm_hardware hw = atmel_ac97c_hw;
550 int capture, playback, retval;
551
552 capture = test_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
553 playback = test_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
554
555 retval = snd_pcm_new(chip->card, chip->card->shortname,
556 chip->pdev->id, playback, capture, &pcm);
557 if (retval)
558 return retval;
559
560 if (capture)
561 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
562 &atmel_ac97_capture_ops);
563 if (playback)
564 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
565 &atmel_ac97_playback_ops);
566
567 retval = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
568 &chip->pdev->dev, hw.periods_min * hw.period_bytes_min,
569 hw.buffer_bytes_max);
570 if (retval)
571 return retval;
572
573 pcm->private_data = chip;
574 pcm->info_flags = 0;
575 strcpy(pcm->name, chip->card->shortname);
576 chip->pcm = pcm;
577
578 return 0;
579}
580
581static int atmel_ac97c_mixer_new(struct atmel_ac97c *chip)
582{
583 struct snd_ac97_template template;
584 memset(&template, 0, sizeof(template));
585 template.private_data = chip;
586 return snd_ac97_mixer(chip->ac97_bus, &template, &chip->ac97);
587}
588
589static void atmel_ac97c_write(struct snd_ac97 *ac97, unsigned short reg,
590 unsigned short val)
591{
592 struct atmel_ac97c *chip = get_chip(ac97);
593 unsigned long word;
594 int timeout = 40;
595
596 word = (reg & 0x7f) << 16 | val;
597
598 do {
599 if (ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) {
600 ac97c_writel(chip, COTHR, word);
601 return;
602 }
603 udelay(1);
604 } while (--timeout);
605
606 dev_dbg(&chip->pdev->dev, "codec write timeout\n");
607}
608
609static unsigned short atmel_ac97c_read(struct snd_ac97 *ac97,
610 unsigned short reg)
611{
612 struct atmel_ac97c *chip = get_chip(ac97);
613 unsigned long word;
614 int timeout = 40;
615 int write = 10;
616
617 word = (0x80 | (reg & 0x7f)) << 16;
618
619 if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0)
620 ac97c_readl(chip, CORHR);
621
622retry_write:
623 timeout = 40;
624
625 do {
626 if ((ac97c_readl(chip, COSR) & AC97C_CSR_TXRDY) != 0) {
627 ac97c_writel(chip, COTHR, word);
628 goto read_reg;
629 }
630 udelay(10);
631 } while (--timeout);
632
633 if (!--write)
634 goto timed_out;
635 goto retry_write;
636
637read_reg:
638 do {
639 if ((ac97c_readl(chip, COSR) & AC97C_CSR_RXRDY) != 0) {
640 unsigned short val = ac97c_readl(chip, CORHR);
641 return val;
642 }
643 udelay(10);
644 } while (--timeout);
645
646 if (!--write)
647 goto timed_out;
648 goto retry_write;
649
650timed_out:
651 dev_dbg(&chip->pdev->dev, "codec read timeout\n");
652 return 0xffff;
653}
654
655static bool filter(struct dma_chan *chan, void *slave)
656{
657 struct dw_dma_slave *dws = slave;
658
659 if (dws->dma_dev == chan->device->dev) {
660 chan->private = dws;
661 return true;
662 } else
663 return false;
664}
665
666static void atmel_ac97c_reset(struct atmel_ac97c *chip)
667{
668 ac97c_writel(chip, MR, AC97C_MR_WRST);
669
670 if (gpio_is_valid(chip->reset_pin)) {
671 gpio_set_value(chip->reset_pin, 0);
672 /* AC97 v2.2 specifications says minimum 1 us. */
673 udelay(10);
674 gpio_set_value(chip->reset_pin, 1);
675 }
676
677 udelay(1);
678 ac97c_writel(chip, MR, AC97C_MR_ENA);
679}
680
681static int __devinit atmel_ac97c_probe(struct platform_device *pdev)
682{
683 struct snd_card *card;
684 struct atmel_ac97c *chip;
685 struct resource *regs;
686 struct ac97c_platform_data *pdata;
687 struct clk *pclk;
688 static struct snd_ac97_bus_ops ops = {
689 .write = atmel_ac97c_write,
690 .read = atmel_ac97c_read,
691 };
692 int retval;
693
694 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
695 if (!regs) {
696 dev_dbg(&pdev->dev, "no memory resource\n");
697 return -ENXIO;
698 }
699
700 pdata = pdev->dev.platform_data;
701 if (!pdata) {
702 dev_dbg(&pdev->dev, "no platform data\n");
703 return -ENXIO;
704 }
705
706 pclk = clk_get(&pdev->dev, "pclk");
707 if (IS_ERR(pclk)) {
708 dev_dbg(&pdev->dev, "no peripheral clock\n");
709 return PTR_ERR(pclk);
710 }
711 clk_enable(pclk);
712
713 retval = snd_card_create(SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1,
714 THIS_MODULE, sizeof(struct atmel_ac97c), &card);
715 if (retval) {
716 dev_dbg(&pdev->dev, "could not create sound card device\n");
717 goto err_snd_card_new;
718 }
719
720 chip = get_chip(card);
721
722 spin_lock_init(&chip->lock);
723
724 strcpy(card->driver, "Atmel AC97C");
725 strcpy(card->shortname, "Atmel AC97C");
726 sprintf(card->longname, "Atmel AC97 controller");
727
728 chip->card = card;
729 chip->pclk = pclk;
730 chip->pdev = pdev;
731 chip->regs = ioremap(regs->start, regs->end - regs->start + 1);
732
733 if (!chip->regs) {
734 dev_dbg(&pdev->dev, "could not remap register memory\n");
735 goto err_ioremap;
736 }
737
738 if (gpio_is_valid(pdata->reset_pin)) {
739 if (gpio_request(pdata->reset_pin, "reset_pin")) {
740 dev_dbg(&pdev->dev, "reset pin not available\n");
741 chip->reset_pin = -ENODEV;
742 } else {
743 gpio_direction_output(pdata->reset_pin, 1);
744 chip->reset_pin = pdata->reset_pin;
745 }
746 }
747
748 snd_card_set_dev(card, &pdev->dev);
749
750 retval = snd_ac97_bus(card, 0, &ops, chip, &chip->ac97_bus);
751 if (retval) {
752 dev_dbg(&pdev->dev, "could not register on ac97 bus\n");
753 goto err_ac97_bus;
754 }
755
756 atmel_ac97c_reset(chip);
757
758 retval = atmel_ac97c_mixer_new(chip);
759 if (retval) {
760 dev_dbg(&pdev->dev, "could not register ac97 mixer\n");
761 goto err_ac97_bus;
762 }
763
764 if (pdata->rx_dws.dma_dev) {
765 struct dw_dma_slave *dws = &pdata->rx_dws;
766 dma_cap_mask_t mask;
767
768 dws->rx_reg = regs->start + AC97C_CARHR + 2;
769
770 dma_cap_zero(mask);
771 dma_cap_set(DMA_SLAVE, mask);
772
773 chip->dma.rx_chan = dma_request_channel(mask, filter, dws);
774
775 dev_info(&chip->pdev->dev, "using %s for DMA RX\n",
776 chip->dma.rx_chan->dev->device.bus_id);
777 set_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
778 }
779
780 if (pdata->tx_dws.dma_dev) {
781 struct dw_dma_slave *dws = &pdata->tx_dws;
782 dma_cap_mask_t mask;
783
784 dws->tx_reg = regs->start + AC97C_CATHR + 2;
785
786 dma_cap_zero(mask);
787 dma_cap_set(DMA_SLAVE, mask);
788
789 chip->dma.tx_chan = dma_request_channel(mask, filter, dws);
790
791 dev_info(&chip->pdev->dev, "using %s for DMA TX\n",
792 chip->dma.tx_chan->dev->device.bus_id);
793 set_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
794 }
795
796 if (!test_bit(DMA_RX_CHAN_PRESENT, &chip->flags) &&
797 !test_bit(DMA_TX_CHAN_PRESENT, &chip->flags)) {
798 dev_dbg(&pdev->dev, "DMA not available\n");
799 retval = -ENODEV;
800 goto err_dma;
801 }
802
803 retval = atmel_ac97c_pcm_new(chip);
804 if (retval) {
805 dev_dbg(&pdev->dev, "could not register ac97 pcm device\n");
806 goto err_dma;
807 }
808
809 retval = snd_card_register(card);
810 if (retval) {
811 dev_dbg(&pdev->dev, "could not register sound card\n");
812 goto err_ac97_bus;
813 }
814
815 platform_set_drvdata(pdev, card);
816
817 dev_info(&pdev->dev, "Atmel AC97 controller at 0x%p\n",
818 chip->regs);
819
820 return 0;
821
822err_dma:
823 if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
824 dma_release_channel(chip->dma.rx_chan);
825 if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
826 dma_release_channel(chip->dma.tx_chan);
827 clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
828 clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
829 chip->dma.rx_chan = NULL;
830 chip->dma.tx_chan = NULL;
831err_ac97_bus:
832 snd_card_set_dev(card, NULL);
833
834 if (gpio_is_valid(chip->reset_pin))
835 gpio_free(chip->reset_pin);
836
837 iounmap(chip->regs);
838err_ioremap:
839 snd_card_free(card);
840err_snd_card_new:
841 clk_disable(pclk);
842 clk_put(pclk);
843 return retval;
844}
845
846#ifdef CONFIG_PM
847static int atmel_ac97c_suspend(struct platform_device *pdev, pm_message_t msg)
848{
849 struct snd_card *card = platform_get_drvdata(pdev);
850 struct atmel_ac97c *chip = card->private_data;
851
852 if (test_bit(DMA_RX_READY, &chip->flags))
853 dw_dma_cyclic_stop(chip->dma.rx_chan);
854 if (test_bit(DMA_TX_READY, &chip->flags))
855 dw_dma_cyclic_stop(chip->dma.tx_chan);
856 clk_disable(chip->pclk);
857
858 return 0;
859}
860
861static int atmel_ac97c_resume(struct platform_device *pdev)
862{
863 struct snd_card *card = platform_get_drvdata(pdev);
864 struct atmel_ac97c *chip = card->private_data;
865
866 clk_enable(chip->pclk);
867 if (test_bit(DMA_RX_READY, &chip->flags))
868 dw_dma_cyclic_start(chip->dma.rx_chan);
869 if (test_bit(DMA_TX_READY, &chip->flags))
870 dw_dma_cyclic_start(chip->dma.tx_chan);
871
872 return 0;
873}
874#else
875#define atmel_ac97c_suspend NULL
876#define atmel_ac97c_resume NULL
877#endif
878
879static int __devexit atmel_ac97c_remove(struct platform_device *pdev)
880{
881 struct snd_card *card = platform_get_drvdata(pdev);
882 struct atmel_ac97c *chip = get_chip(card);
883
884 if (gpio_is_valid(chip->reset_pin))
885 gpio_free(chip->reset_pin);
886
887 clk_disable(chip->pclk);
888 clk_put(chip->pclk);
889 iounmap(chip->regs);
890
891 if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
892 dma_release_channel(chip->dma.rx_chan);
893 if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
894 dma_release_channel(chip->dma.tx_chan);
895 clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
896 clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
897 chip->dma.rx_chan = NULL;
898 chip->dma.tx_chan = NULL;
899
900 snd_card_set_dev(card, NULL);
901 snd_card_free(card);
902
903 platform_set_drvdata(pdev, NULL);
904
905 return 0;
906}
907
908static struct platform_driver atmel_ac97c_driver = {
909 .remove = __devexit_p(atmel_ac97c_remove),
910 .driver = {
911 .name = "atmel_ac97c",
912 },
913 .suspend = atmel_ac97c_suspend,
914 .resume = atmel_ac97c_resume,
915};
916
917static int __init atmel_ac97c_init(void)
918{
919 return platform_driver_probe(&atmel_ac97c_driver,
920 atmel_ac97c_probe);
921}
922module_init(atmel_ac97c_init);
923
924static void __exit atmel_ac97c_exit(void)
925{
926 platform_driver_unregister(&atmel_ac97c_driver);
927}
928module_exit(atmel_ac97c_exit);
929
930MODULE_LICENSE("GPL");
931MODULE_DESCRIPTION("Driver for Atmel AC97 controller");
932MODULE_AUTHOR("Hans-Christian Egtvedt <hans-christian.egtvedt@atmel.com>");
diff --git a/sound/atmel/ac97c.h b/sound/atmel/ac97c.h
new file mode 100644
index 000000000000..c17bd5825980
--- /dev/null
+++ b/sound/atmel/ac97c.h
@@ -0,0 +1,71 @@
1/*
2 * Register definitions for the Atmel AC97C controller
3 *
4 * Copyright (C) 2005-2009 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10#ifndef __SOUND_ATMEL_AC97C_H
11#define __SOUND_ATMEL_AC97C_H
12
13#define AC97C_MR 0x08
14#define AC97C_ICA 0x10
15#define AC97C_OCA 0x14
16#define AC97C_CARHR 0x20
17#define AC97C_CATHR 0x24
18#define AC97C_CASR 0x28
19#define AC97C_CAMR 0x2c
20#define AC97C_CBRHR 0x30
21#define AC97C_CBTHR 0x34
22#define AC97C_CBSR 0x38
23#define AC97C_CBMR 0x3c
24#define AC97C_CORHR 0x40
25#define AC97C_COTHR 0x44
26#define AC97C_COSR 0x48
27#define AC97C_COMR 0x4c
28#define AC97C_SR 0x50
29#define AC97C_IER 0x54
30#define AC97C_IDR 0x58
31#define AC97C_IMR 0x5c
32#define AC97C_VERSION 0xfc
33
34#define AC97C_CATPR PDC_TPR
35#define AC97C_CATCR PDC_TCR
36#define AC97C_CATNPR PDC_TNPR
37#define AC97C_CATNCR PDC_TNCR
38#define AC97C_CARPR PDC_RPR
39#define AC97C_CARCR PDC_RCR
40#define AC97C_CARNPR PDC_RNPR
41#define AC97C_CARNCR PDC_RNCR
42#define AC97C_PTCR PDC_PTCR
43
44#define AC97C_MR_ENA (1 << 0)
45#define AC97C_MR_WRST (1 << 1)
46#define AC97C_MR_VRA (1 << 2)
47
48#define AC97C_CSR_TXRDY (1 << 0)
49#define AC97C_CSR_UNRUN (1 << 2)
50#define AC97C_CSR_RXRDY (1 << 4)
51#define AC97C_CSR_ENDTX (1 << 10)
52#define AC97C_CSR_ENDRX (1 << 14)
53
54#define AC97C_CMR_SIZE_20 (0 << 16)
55#define AC97C_CMR_SIZE_18 (1 << 16)
56#define AC97C_CMR_SIZE_16 (2 << 16)
57#define AC97C_CMR_SIZE_10 (3 << 16)
58#define AC97C_CMR_CEM_LITTLE (1 << 18)
59#define AC97C_CMR_CEM_BIG (0 << 18)
60#define AC97C_CMR_CENA (1 << 21)
61#define AC97C_CMR_DMAEN (1 << 22)
62
63#define AC97C_SR_CAEVT (1 << 3)
64
65#define AC97C_CH_ASSIGN(slot, channel) \
66 (AC97C_CHANNEL_##channel << (3 * (AC97_SLOT_##slot - 3)))
67#define AC97C_CHANNEL_NONE 0x0
68#define AC97C_CHANNEL_A 0x1
69#define AC97C_CHANNEL_B 0x2
70
71#endif /* __SOUND_ATMEL_AC97C_H */
diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c
index 195cafc5a553..a70ee7f1ed98 100644
--- a/sound/core/hwdep.c
+++ b/sound/core/hwdep.c
@@ -99,9 +99,6 @@ static int snd_hwdep_open(struct inode *inode, struct file * file)
99 if (hw == NULL) 99 if (hw == NULL)
100 return -ENODEV; 100 return -ENODEV;
101 101
102 if (!hw->ops.open)
103 return -ENXIO;
104
105 if (!try_module_get(hw->card->module)) 102 if (!try_module_get(hw->card->module))
106 return -EFAULT; 103 return -EFAULT;
107 104
@@ -113,6 +110,10 @@ static int snd_hwdep_open(struct inode *inode, struct file * file)
113 err = -EBUSY; 110 err = -EBUSY;
114 break; 111 break;
115 } 112 }
113 if (!hw->ops.open) {
114 err = 0;
115 break;
116 }
116 err = hw->ops.open(hw, file); 117 err = hw->ops.open(hw, file);
117 if (err >= 0) 118 if (err >= 0)
118 break; 119 break;
@@ -151,7 +152,7 @@ static int snd_hwdep_open(struct inode *inode, struct file * file)
151 152
152static int snd_hwdep_release(struct inode *inode, struct file * file) 153static int snd_hwdep_release(struct inode *inode, struct file * file)
153{ 154{
154 int err = -ENXIO; 155 int err = 0;
155 struct snd_hwdep *hw = file->private_data; 156 struct snd_hwdep *hw = file->private_data;
156 struct module *mod = hw->card->module; 157 struct module *mod = hw->card->module;
157 158
diff --git a/sound/core/init.c b/sound/core/init.c
index 0d5520c415d3..fd56afe846ed 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -121,31 +121,44 @@ static inline int init_info_for_card(struct snd_card *card)
121#endif 121#endif
122 122
123/** 123/**
124 * snd_card_new - create and initialize a soundcard structure 124 * snd_card_create - create and initialize a soundcard structure
125 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)] 125 * @idx: card index (address) [0 ... (SNDRV_CARDS-1)]
126 * @xid: card identification (ASCII string) 126 * @xid: card identification (ASCII string)
127 * @module: top level module for locking 127 * @module: top level module for locking
128 * @extra_size: allocate this extra size after the main soundcard structure 128 * @extra_size: allocate this extra size after the main soundcard structure
129 * @card_ret: the pointer to store the created card instance
129 * 130 *
130 * Creates and initializes a soundcard structure. 131 * Creates and initializes a soundcard structure.
131 * 132 *
132 * Returns kmallocated snd_card structure. Creates the ALSA control interface 133 * The function allocates snd_card instance via kzalloc with the given
133 * (which is blocked until snd_card_register function is called). 134 * space for the driver to use freely. The allocated struct is stored
135 * in the given card_ret pointer.
136 *
137 * Returns zero if successful or a negative error code.
134 */ 138 */
135struct snd_card *snd_card_new(int idx, const char *xid, 139int snd_card_create(int idx, const char *xid,
136 struct module *module, int extra_size) 140 struct module *module, int extra_size,
141 struct snd_card **card_ret)
137{ 142{
138 struct snd_card *card; 143 struct snd_card *card;
139 int err, idx2; 144 int err, idx2;
140 145
146 if (snd_BUG_ON(!card_ret))
147 return -EINVAL;
148 *card_ret = NULL;
149
141 if (extra_size < 0) 150 if (extra_size < 0)
142 extra_size = 0; 151 extra_size = 0;
143 card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL); 152 card = kzalloc(sizeof(*card) + extra_size, GFP_KERNEL);
144 if (card == NULL) 153 if (!card)
145 return NULL; 154 return -ENOMEM;
146 if (xid) { 155 if (xid) {
147 if (!snd_info_check_reserved_words(xid)) 156 if (!snd_info_check_reserved_words(xid)) {
157 snd_printk(KERN_ERR
158 "given id string '%s' is reserved.\n", xid);
159 err = -EBUSY;
148 goto __error; 160 goto __error;
161 }
149 strlcpy(card->id, xid, sizeof(card->id)); 162 strlcpy(card->id, xid, sizeof(card->id));
150 } 163 }
151 err = 0; 164 err = 0;
@@ -195,6 +208,7 @@ struct snd_card *snd_card_new(int idx, const char *xid,
195 INIT_LIST_HEAD(&card->controls); 208 INIT_LIST_HEAD(&card->controls);
196 INIT_LIST_HEAD(&card->ctl_files); 209 INIT_LIST_HEAD(&card->ctl_files);
197 spin_lock_init(&card->files_lock); 210 spin_lock_init(&card->files_lock);
211 INIT_LIST_HEAD(&card->files_list);
198 init_waitqueue_head(&card->shutdown_sleep); 212 init_waitqueue_head(&card->shutdown_sleep);
199#ifdef CONFIG_PM 213#ifdef CONFIG_PM
200 mutex_init(&card->power_lock); 214 mutex_init(&card->power_lock);
@@ -202,26 +216,28 @@ struct snd_card *snd_card_new(int idx, const char *xid,
202#endif 216#endif
203 /* the control interface cannot be accessed from the user space until */ 217 /* the control interface cannot be accessed from the user space until */
204 /* snd_cards_bitmask and snd_cards are set with snd_card_register */ 218 /* snd_cards_bitmask and snd_cards are set with snd_card_register */
205 if ((err = snd_ctl_create(card)) < 0) { 219 err = snd_ctl_create(card);
206 snd_printd("unable to register control minors\n"); 220 if (err < 0) {
221 snd_printk(KERN_ERR "unable to register control minors\n");
207 goto __error; 222 goto __error;
208 } 223 }
209 if ((err = snd_info_card_create(card)) < 0) { 224 err = snd_info_card_create(card);
210 snd_printd("unable to create card info\n"); 225 if (err < 0) {
226 snd_printk(KERN_ERR "unable to create card info\n");
211 goto __error_ctl; 227 goto __error_ctl;
212 } 228 }
213 if (extra_size > 0) 229 if (extra_size > 0)
214 card->private_data = (char *)card + sizeof(struct snd_card); 230 card->private_data = (char *)card + sizeof(struct snd_card);
215 return card; 231 *card_ret = card;
232 return 0;
216 233
217 __error_ctl: 234 __error_ctl:
218 snd_device_free_all(card, SNDRV_DEV_CMD_PRE); 235 snd_device_free_all(card, SNDRV_DEV_CMD_PRE);
219 __error: 236 __error:
220 kfree(card); 237 kfree(card);
221 return NULL; 238 return err;
222} 239}
223 240EXPORT_SYMBOL(snd_card_create);
224EXPORT_SYMBOL(snd_card_new);
225 241
226/* return non-zero if a card is already locked */ 242/* return non-zero if a card is already locked */
227int snd_card_locked(int card) 243int snd_card_locked(int card)
@@ -259,6 +275,7 @@ static int snd_disconnect_release(struct inode *inode, struct file *file)
259 list_for_each_entry(_df, &shutdown_files, shutdown_list) { 275 list_for_each_entry(_df, &shutdown_files, shutdown_list) {
260 if (_df->file == file) { 276 if (_df->file == file) {
261 df = _df; 277 df = _df;
278 list_del_init(&df->shutdown_list);
262 break; 279 break;
263 } 280 }
264 } 281 }
@@ -347,8 +364,7 @@ int snd_card_disconnect(struct snd_card *card)
347 /* phase 2: replace file->f_op with special dummy operations */ 364 /* phase 2: replace file->f_op with special dummy operations */
348 365
349 spin_lock(&card->files_lock); 366 spin_lock(&card->files_lock);
350 mfile = card->files; 367 list_for_each_entry(mfile, &card->files_list, list) {
351 while (mfile) {
352 file = mfile->file; 368 file = mfile->file;
353 369
354 /* it's critical part, use endless loop */ 370 /* it's critical part, use endless loop */
@@ -361,8 +377,6 @@ int snd_card_disconnect(struct snd_card *card)
361 377
362 mfile->file->f_op = &snd_shutdown_f_ops; 378 mfile->file->f_op = &snd_shutdown_f_ops;
363 fops_get(mfile->file->f_op); 379 fops_get(mfile->file->f_op);
364
365 mfile = mfile->next;
366 } 380 }
367 spin_unlock(&card->files_lock); 381 spin_unlock(&card->files_lock);
368 382
@@ -442,7 +456,7 @@ int snd_card_free_when_closed(struct snd_card *card)
442 return ret; 456 return ret;
443 457
444 spin_lock(&card->files_lock); 458 spin_lock(&card->files_lock);
445 if (card->files == NULL) 459 if (list_empty(&card->files_list))
446 free_now = 1; 460 free_now = 1;
447 else 461 else
448 card->free_on_last_close = 1; 462 card->free_on_last_close = 1;
@@ -462,7 +476,7 @@ int snd_card_free(struct snd_card *card)
462 return ret; 476 return ret;
463 477
464 /* wait, until all devices are ready for the free operation */ 478 /* wait, until all devices are ready for the free operation */
465 wait_event(card->shutdown_sleep, card->files == NULL); 479 wait_event(card->shutdown_sleep, list_empty(&card->files_list));
466 snd_card_do_free(card); 480 snd_card_do_free(card);
467 return 0; 481 return 0;
468} 482}
@@ -809,15 +823,13 @@ int snd_card_file_add(struct snd_card *card, struct file *file)
809 return -ENOMEM; 823 return -ENOMEM;
810 mfile->file = file; 824 mfile->file = file;
811 mfile->disconnected_f_op = NULL; 825 mfile->disconnected_f_op = NULL;
812 mfile->next = NULL;
813 spin_lock(&card->files_lock); 826 spin_lock(&card->files_lock);
814 if (card->shutdown) { 827 if (card->shutdown) {
815 spin_unlock(&card->files_lock); 828 spin_unlock(&card->files_lock);
816 kfree(mfile); 829 kfree(mfile);
817 return -ENODEV; 830 return -ENODEV;
818 } 831 }
819 mfile->next = card->files; 832 list_add(&mfile->list, &card->files_list);
820 card->files = mfile;
821 spin_unlock(&card->files_lock); 833 spin_unlock(&card->files_lock);
822 return 0; 834 return 0;
823} 835}
@@ -839,29 +851,20 @@ EXPORT_SYMBOL(snd_card_file_add);
839 */ 851 */
840int snd_card_file_remove(struct snd_card *card, struct file *file) 852int snd_card_file_remove(struct snd_card *card, struct file *file)
841{ 853{
842 struct snd_monitor_file *mfile, *pfile = NULL; 854 struct snd_monitor_file *mfile, *found = NULL;
843 int last_close = 0; 855 int last_close = 0;
844 856
845 spin_lock(&card->files_lock); 857 spin_lock(&card->files_lock);
846 mfile = card->files; 858 list_for_each_entry(mfile, &card->files_list, list) {
847 while (mfile) {
848 if (mfile->file == file) { 859 if (mfile->file == file) {
849 if (pfile) 860 list_del(&mfile->list);
850 pfile->next = mfile->next; 861 if (mfile->disconnected_f_op)
851 else 862 fops_put(mfile->disconnected_f_op);
852 card->files = mfile->next; 863 found = mfile;
853 break; 864 break;
854 } 865 }
855 pfile = mfile;
856 mfile = mfile->next;
857 }
858 if (mfile && mfile->disconnected_f_op) {
859 fops_put(mfile->disconnected_f_op);
860 spin_lock(&shutdown_lock);
861 list_del(&mfile->shutdown_list);
862 spin_unlock(&shutdown_lock);
863 } 866 }
864 if (card->files == NULL) 867 if (list_empty(&card->files_list))
865 last_close = 1; 868 last_close = 1;
866 spin_unlock(&card->files_lock); 869 spin_unlock(&card->files_lock);
867 if (last_close) { 870 if (last_close) {
@@ -869,11 +872,11 @@ int snd_card_file_remove(struct snd_card *card, struct file *file)
869 if (card->free_on_last_close) 872 if (card->free_on_last_close)
870 snd_card_do_free(card); 873 snd_card_do_free(card);
871 } 874 }
872 if (!mfile) { 875 if (!found) {
873 snd_printk(KERN_ERR "ALSA card file remove problem (%p)\n", file); 876 snd_printk(KERN_ERR "ALSA card file remove problem (%p)\n", file);
874 return -ENOENT; 877 return -ENOENT;
875 } 878 }
876 kfree(mfile); 879 kfree(found);
877 return 0; 880 return 0;
878} 881}
879 882
diff --git a/sound/core/jack.c b/sound/core/jack.c
index 077a85262c1c..c8254c667c62 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -23,6 +23,14 @@
23#include <sound/jack.h> 23#include <sound/jack.h>
24#include <sound/core.h> 24#include <sound/core.h>
25 25
26static int jack_types[] = {
27 SW_HEADPHONE_INSERT,
28 SW_MICROPHONE_INSERT,
29 SW_LINEOUT_INSERT,
30 SW_JACK_PHYSICAL_INSERT,
31 SW_VIDEOOUT_INSERT,
32};
33
26static int snd_jack_dev_free(struct snd_device *device) 34static int snd_jack_dev_free(struct snd_device *device)
27{ 35{
28 struct snd_jack *jack = device->device_data; 36 struct snd_jack *jack = device->device_data;
@@ -79,6 +87,7 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
79{ 87{
80 struct snd_jack *jack; 88 struct snd_jack *jack;
81 int err; 89 int err;
90 int i;
82 static struct snd_device_ops ops = { 91 static struct snd_device_ops ops = {
83 .dev_free = snd_jack_dev_free, 92 .dev_free = snd_jack_dev_free,
84 .dev_register = snd_jack_dev_register, 93 .dev_register = snd_jack_dev_register,
@@ -100,18 +109,10 @@ int snd_jack_new(struct snd_card *card, const char *id, int type,
100 109
101 jack->type = type; 110 jack->type = type;
102 111
103 if (type & SND_JACK_HEADPHONE) 112 for (i = 0; i < ARRAY_SIZE(jack_types); i++)
104 input_set_capability(jack->input_dev, EV_SW, 113 if (type & (1 << i))
105 SW_HEADPHONE_INSERT); 114 input_set_capability(jack->input_dev, EV_SW,
106 if (type & SND_JACK_LINEOUT) 115 jack_types[i]);
107 input_set_capability(jack->input_dev, EV_SW,
108 SW_LINEOUT_INSERT);
109 if (type & SND_JACK_MICROPHONE)
110 input_set_capability(jack->input_dev, EV_SW,
111 SW_MICROPHONE_INSERT);
112 if (type & SND_JACK_MECHANICAL)
113 input_set_capability(jack->input_dev, EV_SW,
114 SW_JACK_PHYSICAL_INSERT);
115 116
116 err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops); 117 err = snd_device_new(card, SNDRV_DEV_JACK, jack, &ops);
117 if (err < 0) 118 if (err < 0)
@@ -154,21 +155,17 @@ EXPORT_SYMBOL(snd_jack_set_parent);
154 */ 155 */
155void snd_jack_report(struct snd_jack *jack, int status) 156void snd_jack_report(struct snd_jack *jack, int status)
156{ 157{
158 int i;
159
157 if (!jack) 160 if (!jack)
158 return; 161 return;
159 162
160 if (jack->type & SND_JACK_HEADPHONE) 163 for (i = 0; i < ARRAY_SIZE(jack_types); i++) {
161 input_report_switch(jack->input_dev, SW_HEADPHONE_INSERT, 164 int testbit = 1 << i;
162 status & SND_JACK_HEADPHONE); 165 if (jack->type & testbit)
163 if (jack->type & SND_JACK_LINEOUT) 166 input_report_switch(jack->input_dev, jack_types[i],
164 input_report_switch(jack->input_dev, SW_LINEOUT_INSERT, 167 status & testbit);
165 status & SND_JACK_LINEOUT); 168 }
166 if (jack->type & SND_JACK_MICROPHONE)
167 input_report_switch(jack->input_dev, SW_MICROPHONE_INSERT,
168 status & SND_JACK_MICROPHONE);
169 if (jack->type & SND_JACK_MECHANICAL)
170 input_report_switch(jack->input_dev, SW_JACK_PHYSICAL_INSERT,
171 status & SND_JACK_MECHANICAL);
172 169
173 input_sync(jack->input_dev); 170 input_sync(jack->input_dev);
174} 171}
diff --git a/sound/core/misc.c b/sound/core/misc.c
index 38524f615d94..a9710e0c97af 100644
--- a/sound/core/misc.c
+++ b/sound/core/misc.c
@@ -95,12 +95,14 @@ snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list)
95{ 95{
96 const struct snd_pci_quirk *q; 96 const struct snd_pci_quirk *q;
97 97
98 for (q = list; q->subvendor; q++) 98 for (q = list; q->subvendor; q++) {
99 if (q->subvendor == pci->subsystem_vendor && 99 if (q->subvendor != pci->subsystem_vendor)
100 (!q->subdevice || q->subdevice == pci->subsystem_device)) 100 continue;
101 if (!q->subdevice ||
102 (pci->subsystem_device & q->subdevice_mask) == q->subdevice)
101 return q; 103 return q;
104 }
102 return NULL; 105 return NULL;
103} 106}
104
105EXPORT_SYMBOL(snd_pci_quirk_lookup); 107EXPORT_SYMBOL(snd_pci_quirk_lookup);
106#endif 108#endif
diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
index 699d2890535c..2864cefb773c 100644
--- a/sound/core/oss/pcm_oss.c
+++ b/sound/core/oss/pcm_oss.c
@@ -1160,9 +1160,11 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
1160 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1160 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
1161#ifdef OSS_DEBUG 1161#ifdef OSS_DEBUG
1162 if (runtime->status->state == SNDRV_PCM_STATE_XRUN) 1162 if (runtime->status->state == SNDRV_PCM_STATE_XRUN)
1163 printk("pcm_oss: write: recovering from XRUN\n"); 1163 printk(KERN_DEBUG "pcm_oss: write: "
1164 "recovering from XRUN\n");
1164 else 1165 else
1165 printk("pcm_oss: write: recovering from SUSPEND\n"); 1166 printk(KERN_DEBUG "pcm_oss: write: "
1167 "recovering from SUSPEND\n");
1166#endif 1168#endif
1167 ret = snd_pcm_oss_prepare(substream); 1169 ret = snd_pcm_oss_prepare(substream);
1168 if (ret < 0) 1170 if (ret < 0)
@@ -1196,9 +1198,11 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
1196 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1198 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
1197#ifdef OSS_DEBUG 1199#ifdef OSS_DEBUG
1198 if (runtime->status->state == SNDRV_PCM_STATE_XRUN) 1200 if (runtime->status->state == SNDRV_PCM_STATE_XRUN)
1199 printk("pcm_oss: read: recovering from XRUN\n"); 1201 printk(KERN_DEBUG "pcm_oss: read: "
1202 "recovering from XRUN\n");
1200 else 1203 else
1201 printk("pcm_oss: read: recovering from SUSPEND\n"); 1204 printk(KERN_DEBUG "pcm_oss: read: "
1205 "recovering from SUSPEND\n");
1202#endif 1206#endif
1203 ret = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DRAIN, NULL); 1207 ret = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DRAIN, NULL);
1204 if (ret < 0) 1208 if (ret < 0)
@@ -1242,9 +1246,11 @@ snd_pcm_sframes_t snd_pcm_oss_writev3(struct snd_pcm_substream *substream, void
1242 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1246 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
1243#ifdef OSS_DEBUG 1247#ifdef OSS_DEBUG
1244 if (runtime->status->state == SNDRV_PCM_STATE_XRUN) 1248 if (runtime->status->state == SNDRV_PCM_STATE_XRUN)
1245 printk("pcm_oss: writev: recovering from XRUN\n"); 1249 printk(KERN_DEBUG "pcm_oss: writev: "
1250 "recovering from XRUN\n");
1246 else 1251 else
1247 printk("pcm_oss: writev: recovering from SUSPEND\n"); 1252 printk(KERN_DEBUG "pcm_oss: writev: "
1253 "recovering from SUSPEND\n");
1248#endif 1254#endif
1249 ret = snd_pcm_oss_prepare(substream); 1255 ret = snd_pcm_oss_prepare(substream);
1250 if (ret < 0) 1256 if (ret < 0)
@@ -1278,9 +1284,11 @@ snd_pcm_sframes_t snd_pcm_oss_readv3(struct snd_pcm_substream *substream, void *
1278 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) { 1284 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
1279#ifdef OSS_DEBUG 1285#ifdef OSS_DEBUG
1280 if (runtime->status->state == SNDRV_PCM_STATE_XRUN) 1286 if (runtime->status->state == SNDRV_PCM_STATE_XRUN)
1281 printk("pcm_oss: readv: recovering from XRUN\n"); 1287 printk(KERN_DEBUG "pcm_oss: readv: "
1288 "recovering from XRUN\n");
1282 else 1289 else
1283 printk("pcm_oss: readv: recovering from SUSPEND\n"); 1290 printk(KERN_DEBUG "pcm_oss: readv: "
1291 "recovering from SUSPEND\n");
1284#endif 1292#endif
1285 ret = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DRAIN, NULL); 1293 ret = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DRAIN, NULL);
1286 if (ret < 0) 1294 if (ret < 0)
@@ -1533,7 +1541,7 @@ static int snd_pcm_oss_sync1(struct snd_pcm_substream *substream, size_t size)
1533 init_waitqueue_entry(&wait, current); 1541 init_waitqueue_entry(&wait, current);
1534 add_wait_queue(&runtime->sleep, &wait); 1542 add_wait_queue(&runtime->sleep, &wait);
1535#ifdef OSS_DEBUG 1543#ifdef OSS_DEBUG
1536 printk("sync1: size = %li\n", size); 1544 printk(KERN_DEBUG "sync1: size = %li\n", size);
1537#endif 1545#endif
1538 while (1) { 1546 while (1) {
1539 result = snd_pcm_oss_write2(substream, runtime->oss.buffer, size, 1); 1547 result = snd_pcm_oss_write2(substream, runtime->oss.buffer, size, 1);
@@ -1590,7 +1598,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
1590 mutex_lock(&runtime->oss.params_lock); 1598 mutex_lock(&runtime->oss.params_lock);
1591 if (runtime->oss.buffer_used > 0) { 1599 if (runtime->oss.buffer_used > 0) {
1592#ifdef OSS_DEBUG 1600#ifdef OSS_DEBUG
1593 printk("sync: buffer_used\n"); 1601 printk(KERN_DEBUG "sync: buffer_used\n");
1594#endif 1602#endif
1595 size = (8 * (runtime->oss.period_bytes - runtime->oss.buffer_used) + 7) / width; 1603 size = (8 * (runtime->oss.period_bytes - runtime->oss.buffer_used) + 7) / width;
1596 snd_pcm_format_set_silence(format, 1604 snd_pcm_format_set_silence(format,
@@ -1603,7 +1611,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
1603 } 1611 }
1604 } else if (runtime->oss.period_ptr > 0) { 1612 } else if (runtime->oss.period_ptr > 0) {
1605#ifdef OSS_DEBUG 1613#ifdef OSS_DEBUG
1606 printk("sync: period_ptr\n"); 1614 printk(KERN_DEBUG "sync: period_ptr\n");
1607#endif 1615#endif
1608 size = runtime->oss.period_bytes - runtime->oss.period_ptr; 1616 size = runtime->oss.period_bytes - runtime->oss.period_ptr;
1609 snd_pcm_format_set_silence(format, 1617 snd_pcm_format_set_silence(format,
@@ -1952,7 +1960,7 @@ static int snd_pcm_oss_set_trigger(struct snd_pcm_oss_file *pcm_oss_file, int tr
1952 int err, cmd; 1960 int err, cmd;
1953 1961
1954#ifdef OSS_DEBUG 1962#ifdef OSS_DEBUG
1955 printk("pcm_oss: trigger = 0x%x\n", trigger); 1963 printk(KERN_DEBUG "pcm_oss: trigger = 0x%x\n", trigger);
1956#endif 1964#endif
1957 1965
1958 psubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK]; 1966 psubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
@@ -2170,7 +2178,9 @@ static int snd_pcm_oss_get_space(struct snd_pcm_oss_file *pcm_oss_file, int stre
2170 } 2178 }
2171 2179
2172#ifdef OSS_DEBUG 2180#ifdef OSS_DEBUG
2173 printk("pcm_oss: space: bytes = %i, fragments = %i, fragstotal = %i, fragsize = %i\n", info.bytes, info.fragments, info.fragstotal, info.fragsize); 2181 printk(KERN_DEBUG "pcm_oss: space: bytes = %i, fragments = %i, "
2182 "fragstotal = %i, fragsize = %i\n",
2183 info.bytes, info.fragments, info.fragstotal, info.fragsize);
2174#endif 2184#endif
2175 if (copy_to_user(_info, &info, sizeof(info))) 2185 if (copy_to_user(_info, &info, sizeof(info)))
2176 return -EFAULT; 2186 return -EFAULT;
@@ -2473,7 +2483,7 @@ static long snd_pcm_oss_ioctl(struct file *file, unsigned int cmd, unsigned long
2473 if (((cmd >> 8) & 0xff) != 'P') 2483 if (((cmd >> 8) & 0xff) != 'P')
2474 return -EINVAL; 2484 return -EINVAL;
2475#ifdef OSS_DEBUG 2485#ifdef OSS_DEBUG
2476 printk("pcm_oss: ioctl = 0x%x\n", cmd); 2486 printk(KERN_DEBUG "pcm_oss: ioctl = 0x%x\n", cmd);
2477#endif 2487#endif
2478 switch (cmd) { 2488 switch (cmd) {
2479 case SNDCTL_DSP_RESET: 2489 case SNDCTL_DSP_RESET:
@@ -2627,7 +2637,8 @@ static ssize_t snd_pcm_oss_read(struct file *file, char __user *buf, size_t coun
2627#else 2637#else
2628 { 2638 {
2629 ssize_t res = snd_pcm_oss_read1(substream, buf, count); 2639 ssize_t res = snd_pcm_oss_read1(substream, buf, count);
2630 printk("pcm_oss: read %li bytes (returned %li bytes)\n", (long)count, (long)res); 2640 printk(KERN_DEBUG "pcm_oss: read %li bytes "
2641 "(returned %li bytes)\n", (long)count, (long)res);
2631 return res; 2642 return res;
2632 } 2643 }
2633#endif 2644#endif
@@ -2646,7 +2657,8 @@ static ssize_t snd_pcm_oss_write(struct file *file, const char __user *buf, size
2646 substream->f_flags = file->f_flags & O_NONBLOCK; 2657 substream->f_flags = file->f_flags & O_NONBLOCK;
2647 result = snd_pcm_oss_write1(substream, buf, count); 2658 result = snd_pcm_oss_write1(substream, buf, count);
2648#ifdef OSS_DEBUG 2659#ifdef OSS_DEBUG
2649 printk("pcm_oss: write %li bytes (wrote %li bytes)\n", (long)count, (long)result); 2660 printk(KERN_DEBUG "pcm_oss: write %li bytes (wrote %li bytes)\n",
2661 (long)count, (long)result);
2650#endif 2662#endif
2651 return result; 2663 return result;
2652} 2664}
@@ -2720,7 +2732,7 @@ static int snd_pcm_oss_mmap(struct file *file, struct vm_area_struct *area)
2720 int err; 2732 int err;
2721 2733
2722#ifdef OSS_DEBUG 2734#ifdef OSS_DEBUG
2723 printk("pcm_oss: mmap begin\n"); 2735 printk(KERN_DEBUG "pcm_oss: mmap begin\n");
2724#endif 2736#endif
2725 pcm_oss_file = file->private_data; 2737 pcm_oss_file = file->private_data;
2726 switch ((area->vm_flags & (VM_READ | VM_WRITE))) { 2738 switch ((area->vm_flags & (VM_READ | VM_WRITE))) {
@@ -2770,7 +2782,8 @@ static int snd_pcm_oss_mmap(struct file *file, struct vm_area_struct *area)
2770 runtime->silence_threshold = 0; 2782 runtime->silence_threshold = 0;
2771 runtime->silence_size = 0; 2783 runtime->silence_size = 0;
2772#ifdef OSS_DEBUG 2784#ifdef OSS_DEBUG
2773 printk("pcm_oss: mmap ok, bytes = 0x%x\n", runtime->oss.mmap_bytes); 2785 printk(KERN_DEBUG "pcm_oss: mmap ok, bytes = 0x%x\n",
2786 runtime->oss.mmap_bytes);
2774#endif 2787#endif
2775 /* In mmap mode we never stop */ 2788 /* In mmap mode we never stop */
2776 runtime->stop_threshold = runtime->boundary; 2789 runtime->stop_threshold = runtime->boundary;
diff --git a/sound/core/oss/pcm_plugin.h b/sound/core/oss/pcm_plugin.h
index ca2f4c39be46..b9afab603711 100644
--- a/sound/core/oss/pcm_plugin.h
+++ b/sound/core/oss/pcm_plugin.h
@@ -176,9 +176,9 @@ static inline int snd_pcm_plug_slave_format(int format, struct snd_mask *format_
176#endif 176#endif
177 177
178#ifdef PLUGIN_DEBUG 178#ifdef PLUGIN_DEBUG
179#define pdprintf( fmt, args... ) printk( "plugin: " fmt, ##args) 179#define pdprintf(fmt, args...) printk(KERN_DEBUG "plugin: " fmt, ##args)
180#else 180#else
181#define pdprintf( fmt, args... ) 181#define pdprintf(fmt, args...)
182#endif 182#endif
183 183
184#endif /* __PCM_PLUGIN_H */ 184#endif /* __PCM_PLUGIN_H */
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 192a433a2403..145931a9ff30 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -667,7 +667,6 @@ int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
667 spin_lock_init(&substream->self_group.lock); 667 spin_lock_init(&substream->self_group.lock);
668 INIT_LIST_HEAD(&substream->self_group.substreams); 668 INIT_LIST_HEAD(&substream->self_group.substreams);
669 list_add_tail(&substream->link_list, &substream->self_group.substreams); 669 list_add_tail(&substream->link_list, &substream->self_group.substreams);
670 spin_lock_init(&substream->timer_lock);
671 atomic_set(&substream->mmap_count, 0); 670 atomic_set(&substream->mmap_count, 0);
672 prev = substream; 671 prev = substream;
673 } 672 }
@@ -692,7 +691,7 @@ EXPORT_SYMBOL(snd_pcm_new_stream);
692 * 691 *
693 * Returns zero if successful, or a negative error code on failure. 692 * Returns zero if successful, or a negative error code on failure.
694 */ 693 */
695int snd_pcm_new(struct snd_card *card, char *id, int device, 694int snd_pcm_new(struct snd_card *card, const char *id, int device,
696 int playback_count, int capture_count, 695 int playback_count, int capture_count,
697 struct snd_pcm ** rpcm) 696 struct snd_pcm ** rpcm)
698{ 697{
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 921691080f35..fbb2e391591e 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -125,23 +125,32 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram
125 } 125 }
126} 126}
127 127
128#ifdef CONFIG_SND_PCM_XRUN_DEBUG
129#define xrun_debug(substream) ((substream)->pstr->xrun_debug)
130#else
131#define xrun_debug(substream) 0
132#endif
133
134#define dump_stack_on_xrun(substream) do { \
135 if (xrun_debug(substream) > 1) \
136 dump_stack(); \
137 } while (0)
138
128static void xrun(struct snd_pcm_substream *substream) 139static void xrun(struct snd_pcm_substream *substream)
129{ 140{
130 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN); 141 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
131#ifdef CONFIG_SND_PCM_XRUN_DEBUG 142 if (xrun_debug(substream)) {
132 if (substream->pstr->xrun_debug) {
133 snd_printd(KERN_DEBUG "XRUN: pcmC%dD%d%c\n", 143 snd_printd(KERN_DEBUG "XRUN: pcmC%dD%d%c\n",
134 substream->pcm->card->number, 144 substream->pcm->card->number,
135 substream->pcm->device, 145 substream->pcm->device,
136 substream->stream ? 'c' : 'p'); 146 substream->stream ? 'c' : 'p');
137 if (substream->pstr->xrun_debug > 1) 147 dump_stack_on_xrun(substream);
138 dump_stack();
139 } 148 }
140#endif
141} 149}
142 150
143static inline snd_pcm_uframes_t snd_pcm_update_hw_ptr_pos(struct snd_pcm_substream *substream, 151static snd_pcm_uframes_t
144 struct snd_pcm_runtime *runtime) 152snd_pcm_update_hw_ptr_pos(struct snd_pcm_substream *substream,
153 struct snd_pcm_runtime *runtime)
145{ 154{
146 snd_pcm_uframes_t pos; 155 snd_pcm_uframes_t pos;
147 156
@@ -150,17 +159,21 @@ static inline snd_pcm_uframes_t snd_pcm_update_hw_ptr_pos(struct snd_pcm_substre
150 pos = substream->ops->pointer(substream); 159 pos = substream->ops->pointer(substream);
151 if (pos == SNDRV_PCM_POS_XRUN) 160 if (pos == SNDRV_PCM_POS_XRUN)
152 return pos; /* XRUN */ 161 return pos; /* XRUN */
153#ifdef CONFIG_SND_DEBUG
154 if (pos >= runtime->buffer_size) { 162 if (pos >= runtime->buffer_size) {
155 snd_printk(KERN_ERR "BUG: stream = %i, pos = 0x%lx, buffer size = 0x%lx, period size = 0x%lx\n", substream->stream, pos, runtime->buffer_size, runtime->period_size); 163 if (printk_ratelimit()) {
164 snd_printd(KERN_ERR "BUG: stream = %i, pos = 0x%lx, "
165 "buffer size = 0x%lx, period size = 0x%lx\n",
166 substream->stream, pos, runtime->buffer_size,
167 runtime->period_size);
168 }
169 pos = 0;
156 } 170 }
157#endif
158 pos -= pos % runtime->min_align; 171 pos -= pos % runtime->min_align;
159 return pos; 172 return pos;
160} 173}
161 174
162static inline int snd_pcm_update_hw_ptr_post(struct snd_pcm_substream *substream, 175static int snd_pcm_update_hw_ptr_post(struct snd_pcm_substream *substream,
163 struct snd_pcm_runtime *runtime) 176 struct snd_pcm_runtime *runtime)
164{ 177{
165 snd_pcm_uframes_t avail; 178 snd_pcm_uframes_t avail;
166 179
@@ -182,11 +195,21 @@ static inline int snd_pcm_update_hw_ptr_post(struct snd_pcm_substream *substream
182 return 0; 195 return 0;
183} 196}
184 197
185static inline int snd_pcm_update_hw_ptr_interrupt(struct snd_pcm_substream *substream) 198#define hw_ptr_error(substream, fmt, args...) \
199 do { \
200 if (xrun_debug(substream)) { \
201 if (printk_ratelimit()) { \
202 snd_printd("PCM: " fmt, ##args); \
203 } \
204 dump_stack_on_xrun(substream); \
205 } \
206 } while (0)
207
208static int snd_pcm_update_hw_ptr_interrupt(struct snd_pcm_substream *substream)
186{ 209{
187 struct snd_pcm_runtime *runtime = substream->runtime; 210 struct snd_pcm_runtime *runtime = substream->runtime;
188 snd_pcm_uframes_t pos; 211 snd_pcm_uframes_t pos;
189 snd_pcm_uframes_t new_hw_ptr, hw_ptr_interrupt; 212 snd_pcm_uframes_t new_hw_ptr, hw_ptr_interrupt, hw_base;
190 snd_pcm_sframes_t delta; 213 snd_pcm_sframes_t delta;
191 214
192 pos = snd_pcm_update_hw_ptr_pos(substream, runtime); 215 pos = snd_pcm_update_hw_ptr_pos(substream, runtime);
@@ -194,36 +217,53 @@ static inline int snd_pcm_update_hw_ptr_interrupt(struct snd_pcm_substream *subs
194 xrun(substream); 217 xrun(substream);
195 return -EPIPE; 218 return -EPIPE;
196 } 219 }
197 if (runtime->period_size == runtime->buffer_size) 220 hw_base = runtime->hw_ptr_base;
198 goto __next_buf; 221 new_hw_ptr = hw_base + pos;
199 new_hw_ptr = runtime->hw_ptr_base + pos;
200 hw_ptr_interrupt = runtime->hw_ptr_interrupt + runtime->period_size; 222 hw_ptr_interrupt = runtime->hw_ptr_interrupt + runtime->period_size;
201 223 delta = new_hw_ptr - hw_ptr_interrupt;
202 delta = hw_ptr_interrupt - new_hw_ptr; 224 if (hw_ptr_interrupt >= runtime->boundary) {
203 if (delta > 0) { 225 hw_ptr_interrupt -= runtime->boundary;
204 if ((snd_pcm_uframes_t)delta < runtime->buffer_size / 2) { 226 if (hw_base < runtime->boundary / 2)
205#ifdef CONFIG_SND_PCM_XRUN_DEBUG 227 /* hw_base was already lapped; recalc delta */
206 if (runtime->periods > 1 && substream->pstr->xrun_debug) { 228 delta = new_hw_ptr - hw_ptr_interrupt;
207 snd_printd(KERN_ERR "Unexpected hw_pointer value [1] (stream = %i, delta: -%ld, max jitter = %ld): wrong interrupt acknowledge?\n", substream->stream, (long) delta, runtime->buffer_size / 2); 229 }
208 if (substream->pstr->xrun_debug > 1) 230 if (delta < 0) {
209 dump_stack(); 231 delta += runtime->buffer_size;
210 } 232 if (delta < 0) {
211#endif 233 hw_ptr_error(substream,
212 return 0; 234 "Unexpected hw_pointer value "
235 "(stream=%i, pos=%ld, intr_ptr=%ld)\n",
236 substream->stream, (long)pos,
237 (long)hw_ptr_interrupt);
238 /* rebase to interrupt position */
239 hw_base = new_hw_ptr = hw_ptr_interrupt;
240 /* align hw_base to buffer_size */
241 hw_base -= hw_base % runtime->buffer_size;
242 delta = 0;
243 } else {
244 hw_base += runtime->buffer_size;
245 if (hw_base >= runtime->boundary)
246 hw_base = 0;
247 new_hw_ptr = hw_base + pos;
213 } 248 }
214 __next_buf:
215 runtime->hw_ptr_base += runtime->buffer_size;
216 if (runtime->hw_ptr_base == runtime->boundary)
217 runtime->hw_ptr_base = 0;
218 new_hw_ptr = runtime->hw_ptr_base + pos;
219 } 249 }
220 250 if (delta > runtime->period_size) {
251 hw_ptr_error(substream,
252 "Lost interrupts? "
253 "(stream=%i, delta=%ld, intr_ptr=%ld)\n",
254 substream->stream, (long)delta,
255 (long)hw_ptr_interrupt);
256 /* rebase hw_ptr_interrupt */
257 hw_ptr_interrupt =
258 new_hw_ptr - new_hw_ptr % runtime->period_size;
259 }
221 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && 260 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
222 runtime->silence_size > 0) 261 runtime->silence_size > 0)
223 snd_pcm_playback_silence(substream, new_hw_ptr); 262 snd_pcm_playback_silence(substream, new_hw_ptr);
224 263
264 runtime->hw_ptr_base = hw_base;
225 runtime->status->hw_ptr = new_hw_ptr; 265 runtime->status->hw_ptr = new_hw_ptr;
226 runtime->hw_ptr_interrupt = new_hw_ptr - new_hw_ptr % runtime->period_size; 266 runtime->hw_ptr_interrupt = hw_ptr_interrupt;
227 267
228 return snd_pcm_update_hw_ptr_post(substream, runtime); 268 return snd_pcm_update_hw_ptr_post(substream, runtime);
229} 269}
@@ -233,7 +273,7 @@ int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream)
233{ 273{
234 struct snd_pcm_runtime *runtime = substream->runtime; 274 struct snd_pcm_runtime *runtime = substream->runtime;
235 snd_pcm_uframes_t pos; 275 snd_pcm_uframes_t pos;
236 snd_pcm_uframes_t old_hw_ptr, new_hw_ptr; 276 snd_pcm_uframes_t old_hw_ptr, new_hw_ptr, hw_base;
237 snd_pcm_sframes_t delta; 277 snd_pcm_sframes_t delta;
238 278
239 old_hw_ptr = runtime->status->hw_ptr; 279 old_hw_ptr = runtime->status->hw_ptr;
@@ -242,29 +282,38 @@ int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream)
242 xrun(substream); 282 xrun(substream);
243 return -EPIPE; 283 return -EPIPE;
244 } 284 }
245 new_hw_ptr = runtime->hw_ptr_base + pos; 285 hw_base = runtime->hw_ptr_base;
246 286 new_hw_ptr = hw_base + pos;
247 delta = old_hw_ptr - new_hw_ptr; 287
248 if (delta > 0) { 288 delta = new_hw_ptr - old_hw_ptr;
249 if ((snd_pcm_uframes_t)delta < runtime->buffer_size / 2) { 289 if (delta < 0) {
250#ifdef CONFIG_SND_PCM_XRUN_DEBUG 290 delta += runtime->buffer_size;
251 if (runtime->periods > 2 && substream->pstr->xrun_debug) { 291 if (delta < 0) {
252 snd_printd(KERN_ERR "Unexpected hw_pointer value [2] (stream = %i, delta: -%ld, max jitter = %ld): wrong interrupt acknowledge?\n", substream->stream, (long) delta, runtime->buffer_size / 2); 292 hw_ptr_error(substream,
253 if (substream->pstr->xrun_debug > 1) 293 "Unexpected hw_pointer value [2] "
254 dump_stack(); 294 "(stream=%i, pos=%ld, old_ptr=%ld)\n",
255 } 295 substream->stream, (long)pos,
256#endif 296 (long)old_hw_ptr);
257 return 0; 297 return 0;
258 } 298 }
259 runtime->hw_ptr_base += runtime->buffer_size; 299 hw_base += runtime->buffer_size;
260 if (runtime->hw_ptr_base == runtime->boundary) 300 if (hw_base >= runtime->boundary)
261 runtime->hw_ptr_base = 0; 301 hw_base = 0;
262 new_hw_ptr = runtime->hw_ptr_base + pos; 302 new_hw_ptr = hw_base + pos;
303 }
304 if (delta > runtime->period_size && runtime->periods > 1) {
305 hw_ptr_error(substream,
306 "hw_ptr skipping! "
307 "(pos=%ld, delta=%ld, period=%ld)\n",
308 (long)pos, (long)delta,
309 (long)runtime->period_size);
310 return 0;
263 } 311 }
264 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && 312 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
265 runtime->silence_size > 0) 313 runtime->silence_size > 0)
266 snd_pcm_playback_silence(substream, new_hw_ptr); 314 snd_pcm_playback_silence(substream, new_hw_ptr);
267 315
316 runtime->hw_ptr_base = hw_base;
268 runtime->status->hw_ptr = new_hw_ptr; 317 runtime->status->hw_ptr = new_hw_ptr;
269 318
270 return snd_pcm_update_hw_ptr_post(substream, runtime); 319 return snd_pcm_update_hw_ptr_post(substream, runtime);
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index a789efc9df39..d9b8f5379428 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -186,7 +186,7 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
186 if (!(params->rmask & (1 << k))) 186 if (!(params->rmask & (1 << k)))
187 continue; 187 continue;
188#ifdef RULES_DEBUG 188#ifdef RULES_DEBUG
189 printk("%s = ", snd_pcm_hw_param_names[k]); 189 printk(KERN_DEBUG "%s = ", snd_pcm_hw_param_names[k]);
190 printk("%04x%04x%04x%04x -> ", m->bits[3], m->bits[2], m->bits[1], m->bits[0]); 190 printk("%04x%04x%04x%04x -> ", m->bits[3], m->bits[2], m->bits[1], m->bits[0]);
191#endif 191#endif
192 changed = snd_mask_refine(m, constrs_mask(constrs, k)); 192 changed = snd_mask_refine(m, constrs_mask(constrs, k));
@@ -206,7 +206,7 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
206 if (!(params->rmask & (1 << k))) 206 if (!(params->rmask & (1 << k)))
207 continue; 207 continue;
208#ifdef RULES_DEBUG 208#ifdef RULES_DEBUG
209 printk("%s = ", snd_pcm_hw_param_names[k]); 209 printk(KERN_DEBUG "%s = ", snd_pcm_hw_param_names[k]);
210 if (i->empty) 210 if (i->empty)
211 printk("empty"); 211 printk("empty");
212 else 212 else
@@ -251,7 +251,7 @@ int snd_pcm_hw_refine(struct snd_pcm_substream *substream,
251 if (!doit) 251 if (!doit)
252 continue; 252 continue;
253#ifdef RULES_DEBUG 253#ifdef RULES_DEBUG
254 printk("Rule %d [%p]: ", k, r->func); 254 printk(KERN_DEBUG "Rule %d [%p]: ", k, r->func);
255 if (r->var >= 0) { 255 if (r->var >= 0) {
256 printk("%s = ", snd_pcm_hw_param_names[r->var]); 256 printk("%s = ", snd_pcm_hw_param_names[r->var]);
257 if (hw_is_mask(r->var)) { 257 if (hw_is_mask(r->var)) {
diff --git a/sound/core/pcm_timer.c b/sound/core/pcm_timer.c
index 2c89c04f2916..ca8068b63d6c 100644
--- a/sound/core/pcm_timer.c
+++ b/sound/core/pcm_timer.c
@@ -85,25 +85,19 @@ static unsigned long snd_pcm_timer_resolution(struct snd_timer * timer)
85 85
86static int snd_pcm_timer_start(struct snd_timer * timer) 86static int snd_pcm_timer_start(struct snd_timer * timer)
87{ 87{
88 unsigned long flags;
89 struct snd_pcm_substream *substream; 88 struct snd_pcm_substream *substream;
90 89
91 substream = snd_timer_chip(timer); 90 substream = snd_timer_chip(timer);
92 spin_lock_irqsave(&substream->timer_lock, flags);
93 substream->timer_running = 1; 91 substream->timer_running = 1;
94 spin_unlock_irqrestore(&substream->timer_lock, flags);
95 return 0; 92 return 0;
96} 93}
97 94
98static int snd_pcm_timer_stop(struct snd_timer * timer) 95static int snd_pcm_timer_stop(struct snd_timer * timer)
99{ 96{
100 unsigned long flags;
101 struct snd_pcm_substream *substream; 97 struct snd_pcm_substream *substream;
102 98
103 substream = snd_timer_chip(timer); 99 substream = snd_timer_chip(timer);
104 spin_lock_irqsave(&substream->timer_lock, flags);
105 substream->timer_running = 0; 100 substream->timer_running = 0;
106 spin_unlock_irqrestore(&substream->timer_lock, flags);
107 return 0; 101 return 0;
108} 102}
109 103
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 002777ba336a..473247c8e6d3 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -224,156 +224,143 @@ int snd_rawmidi_drain_input(struct snd_rawmidi_substream *substream)
224 return 0; 224 return 0;
225} 225}
226 226
227int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice, 227/* look for an available substream for the given stream direction;
228 int mode, struct snd_rawmidi_file * rfile) 228 * if a specific subdevice is given, try to assign it
229 */
230static int assign_substream(struct snd_rawmidi *rmidi, int subdevice,
231 int stream, int mode,
232 struct snd_rawmidi_substream **sub_ret)
233{
234 struct snd_rawmidi_substream *substream;
235 struct snd_rawmidi_str *s = &rmidi->streams[stream];
236 static unsigned int info_flags[2] = {
237 [SNDRV_RAWMIDI_STREAM_OUTPUT] = SNDRV_RAWMIDI_INFO_OUTPUT,
238 [SNDRV_RAWMIDI_STREAM_INPUT] = SNDRV_RAWMIDI_INFO_INPUT,
239 };
240
241 if (!(rmidi->info_flags & info_flags[stream]))
242 return -ENXIO;
243 if (subdevice >= 0 && subdevice >= s->substream_count)
244 return -ENODEV;
245 if (s->substream_opened >= s->substream_count)
246 return -EAGAIN;
247
248 list_for_each_entry(substream, &s->substreams, list) {
249 if (substream->opened) {
250 if (stream == SNDRV_RAWMIDI_STREAM_INPUT ||
251 !(mode & SNDRV_RAWMIDI_LFLG_APPEND))
252 continue;
253 }
254 if (subdevice < 0 || subdevice == substream->number) {
255 *sub_ret = substream;
256 return 0;
257 }
258 }
259 return -EAGAIN;
260}
261
262/* open and do ref-counting for the given substream */
263static int open_substream(struct snd_rawmidi *rmidi,
264 struct snd_rawmidi_substream *substream,
265 int mode)
266{
267 int err;
268
269 err = snd_rawmidi_runtime_create(substream);
270 if (err < 0)
271 return err;
272 err = substream->ops->open(substream);
273 if (err < 0)
274 return err;
275 substream->opened = 1;
276 if (substream->use_count++ == 0)
277 substream->active_sensing = 1;
278 if (mode & SNDRV_RAWMIDI_LFLG_APPEND)
279 substream->append = 1;
280 rmidi->streams[substream->stream].substream_opened++;
281 return 0;
282}
283
284static void close_substream(struct snd_rawmidi *rmidi,
285 struct snd_rawmidi_substream *substream,
286 int cleanup);
287
288static int rawmidi_open_priv(struct snd_rawmidi *rmidi, int subdevice, int mode,
289 struct snd_rawmidi_file *rfile)
229{ 290{
230 struct snd_rawmidi *rmidi;
231 struct list_head *list1, *list2;
232 struct snd_rawmidi_substream *sinput = NULL, *soutput = NULL; 291 struct snd_rawmidi_substream *sinput = NULL, *soutput = NULL;
233 struct snd_rawmidi_runtime *input = NULL, *output = NULL;
234 int err; 292 int err;
235 293
236 if (rfile) 294 rfile->input = rfile->output = NULL;
237 rfile->input = rfile->output = NULL;
238 mutex_lock(&register_mutex);
239 rmidi = snd_rawmidi_search(card, device);
240 mutex_unlock(&register_mutex);
241 if (rmidi == NULL) {
242 err = -ENODEV;
243 goto __error1;
244 }
245 if (!try_module_get(rmidi->card->module)) {
246 err = -EFAULT;
247 goto __error1;
248 }
249 if (!(mode & SNDRV_RAWMIDI_LFLG_NOOPENLOCK))
250 mutex_lock(&rmidi->open_mutex);
251 if (mode & SNDRV_RAWMIDI_LFLG_INPUT) { 295 if (mode & SNDRV_RAWMIDI_LFLG_INPUT) {
252 if (!(rmidi->info_flags & SNDRV_RAWMIDI_INFO_INPUT)) { 296 err = assign_substream(rmidi, subdevice,
253 err = -ENXIO; 297 SNDRV_RAWMIDI_STREAM_INPUT,
254 goto __error; 298 mode, &sinput);
255 } 299 if (err < 0)
256 if (subdevice >= 0 && (unsigned int)subdevice >= rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substream_count) {
257 err = -ENODEV;
258 goto __error;
259 }
260 if (rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substream_opened >=
261 rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substream_count) {
262 err = -EAGAIN;
263 goto __error; 300 goto __error;
264 }
265 } 301 }
266 if (mode & SNDRV_RAWMIDI_LFLG_OUTPUT) { 302 if (mode & SNDRV_RAWMIDI_LFLG_OUTPUT) {
267 if (!(rmidi->info_flags & SNDRV_RAWMIDI_INFO_OUTPUT)) { 303 err = assign_substream(rmidi, subdevice,
268 err = -ENXIO; 304 SNDRV_RAWMIDI_STREAM_OUTPUT,
269 goto __error; 305 mode, &soutput);
270 } 306 if (err < 0)
271 if (subdevice >= 0 && (unsigned int)subdevice >= rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substream_count) {
272 err = -ENODEV;
273 goto __error;
274 }
275 if (rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substream_opened >=
276 rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substream_count) {
277 err = -EAGAIN;
278 goto __error; 307 goto __error;
279 }
280 }
281 list1 = rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams.next;
282 while (1) {
283 if (list1 == &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams) {
284 sinput = NULL;
285 if (mode & SNDRV_RAWMIDI_LFLG_INPUT) {
286 err = -EAGAIN;
287 goto __error;
288 }
289 break;
290 }
291 sinput = list_entry(list1, struct snd_rawmidi_substream, list);
292 if ((mode & SNDRV_RAWMIDI_LFLG_INPUT) && sinput->opened)
293 goto __nexti;
294 if (subdevice < 0 || (subdevice >= 0 && subdevice == sinput->number))
295 break;
296 __nexti:
297 list1 = list1->next;
298 } 308 }
299 list2 = rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams.next; 309
300 while (1) { 310 if (sinput) {
301 if (list2 == &rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams) { 311 err = open_substream(rmidi, sinput, mode);
302 soutput = NULL; 312 if (err < 0)
303 if (mode & SNDRV_RAWMIDI_LFLG_OUTPUT) {
304 err = -EAGAIN;
305 goto __error;
306 }
307 break;
308 }
309 soutput = list_entry(list2, struct snd_rawmidi_substream, list);
310 if (mode & SNDRV_RAWMIDI_LFLG_OUTPUT) {
311 if (mode & SNDRV_RAWMIDI_LFLG_APPEND) {
312 if (soutput->opened && !soutput->append)
313 goto __nexto;
314 } else {
315 if (soutput->opened)
316 goto __nexto;
317 }
318 }
319 if (subdevice < 0 || (subdevice >= 0 && subdevice == soutput->number))
320 break;
321 __nexto:
322 list2 = list2->next;
323 }
324 if (mode & SNDRV_RAWMIDI_LFLG_INPUT) {
325 if ((err = snd_rawmidi_runtime_create(sinput)) < 0)
326 goto __error;
327 input = sinput->runtime;
328 if ((err = sinput->ops->open(sinput)) < 0)
329 goto __error; 313 goto __error;
330 sinput->opened = 1;
331 rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substream_opened++;
332 } else {
333 sinput = NULL;
334 } 314 }
335 if (mode & SNDRV_RAWMIDI_LFLG_OUTPUT) { 315 if (soutput) {
336 if (soutput->opened) 316 err = open_substream(rmidi, soutput, mode);
337 goto __skip_output; 317 if (err < 0) {
338 if ((err = snd_rawmidi_runtime_create(soutput)) < 0) { 318 if (sinput)
339 if (mode & SNDRV_RAWMIDI_LFLG_INPUT) 319 close_substream(rmidi, sinput, 0);
340 sinput->ops->close(sinput);
341 goto __error;
342 }
343 output = soutput->runtime;
344 if ((err = soutput->ops->open(soutput)) < 0) {
345 if (mode & SNDRV_RAWMIDI_LFLG_INPUT)
346 sinput->ops->close(sinput);
347 goto __error; 320 goto __error;
348 } 321 }
349 __skip_output:
350 soutput->opened = 1;
351 if (mode & SNDRV_RAWMIDI_LFLG_APPEND)
352 soutput->append = 1;
353 if (soutput->use_count++ == 0)
354 soutput->active_sensing = 1;
355 rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substream_opened++;
356 } else {
357 soutput = NULL;
358 }
359 if (!(mode & SNDRV_RAWMIDI_LFLG_NOOPENLOCK))
360 mutex_unlock(&rmidi->open_mutex);
361 if (rfile) {
362 rfile->rmidi = rmidi;
363 rfile->input = sinput;
364 rfile->output = soutput;
365 } 322 }
323
324 rfile->rmidi = rmidi;
325 rfile->input = sinput;
326 rfile->output = soutput;
366 return 0; 327 return 0;
367 328
368 __error: 329 __error:
369 if (input != NULL) 330 if (sinput && sinput->runtime)
370 snd_rawmidi_runtime_free(sinput); 331 snd_rawmidi_runtime_free(sinput);
371 if (output != NULL) 332 if (soutput && soutput->runtime)
372 snd_rawmidi_runtime_free(soutput); 333 snd_rawmidi_runtime_free(soutput);
373 module_put(rmidi->card->module); 334 return err;
374 if (!(mode & SNDRV_RAWMIDI_LFLG_NOOPENLOCK)) 335}
375 mutex_unlock(&rmidi->open_mutex); 336
376 __error1: 337/* called from sound/core/seq/seq_midi.c */
338int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice,
339 int mode, struct snd_rawmidi_file * rfile)
340{
341 struct snd_rawmidi *rmidi;
342 int err;
343
344 if (snd_BUG_ON(!rfile))
345 return -EINVAL;
346
347 mutex_lock(&register_mutex);
348 rmidi = snd_rawmidi_search(card, device);
349 if (rmidi == NULL) {
350 mutex_unlock(&register_mutex);
351 return -ENODEV;
352 }
353 if (!try_module_get(rmidi->card->module)) {
354 mutex_unlock(&register_mutex);
355 return -ENXIO;
356 }
357 mutex_unlock(&register_mutex);
358
359 mutex_lock(&rmidi->open_mutex);
360 err = rawmidi_open_priv(rmidi, subdevice, mode, rfile);
361 mutex_unlock(&rmidi->open_mutex);
362 if (err < 0)
363 module_put(rmidi->card->module);
377 return err; 364 return err;
378} 365}
379 366
@@ -385,10 +372,13 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
385 unsigned short fflags; 372 unsigned short fflags;
386 int err; 373 int err;
387 struct snd_rawmidi *rmidi; 374 struct snd_rawmidi *rmidi;
388 struct snd_rawmidi_file *rawmidi_file; 375 struct snd_rawmidi_file *rawmidi_file = NULL;
389 wait_queue_t wait; 376 wait_queue_t wait;
390 struct snd_ctl_file *kctl; 377 struct snd_ctl_file *kctl;
391 378
379 if ((file->f_flags & O_APPEND) && !(file->f_flags & O_NONBLOCK))
380 return -EINVAL; /* invalid combination */
381
392 if (maj == snd_major) { 382 if (maj == snd_major) {
393 rmidi = snd_lookup_minor_data(iminor(inode), 383 rmidi = snd_lookup_minor_data(iminor(inode),
394 SNDRV_DEVICE_TYPE_RAWMIDI); 384 SNDRV_DEVICE_TYPE_RAWMIDI);
@@ -402,24 +392,25 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
402 392
403 if (rmidi == NULL) 393 if (rmidi == NULL)
404 return -ENODEV; 394 return -ENODEV;
405 if ((file->f_flags & O_APPEND) && !(file->f_flags & O_NONBLOCK)) 395
406 return -EINVAL; /* invalid combination */ 396 if (!try_module_get(rmidi->card->module))
397 return -ENXIO;
398
399 mutex_lock(&rmidi->open_mutex);
407 card = rmidi->card; 400 card = rmidi->card;
408 err = snd_card_file_add(card, file); 401 err = snd_card_file_add(card, file);
409 if (err < 0) 402 if (err < 0)
410 return -ENODEV; 403 goto __error_card;
411 fflags = snd_rawmidi_file_flags(file); 404 fflags = snd_rawmidi_file_flags(file);
412 if ((file->f_flags & O_APPEND) || maj == SOUND_MAJOR) /* OSS emul? */ 405 if ((file->f_flags & O_APPEND) || maj == SOUND_MAJOR) /* OSS emul? */
413 fflags |= SNDRV_RAWMIDI_LFLG_APPEND; 406 fflags |= SNDRV_RAWMIDI_LFLG_APPEND;
414 fflags |= SNDRV_RAWMIDI_LFLG_NOOPENLOCK;
415 rawmidi_file = kmalloc(sizeof(*rawmidi_file), GFP_KERNEL); 407 rawmidi_file = kmalloc(sizeof(*rawmidi_file), GFP_KERNEL);
416 if (rawmidi_file == NULL) { 408 if (rawmidi_file == NULL) {
417 snd_card_file_remove(card, file); 409 err = -ENOMEM;
418 return -ENOMEM; 410 goto __error;
419 } 411 }
420 init_waitqueue_entry(&wait, current); 412 init_waitqueue_entry(&wait, current);
421 add_wait_queue(&rmidi->open_wait, &wait); 413 add_wait_queue(&rmidi->open_wait, &wait);
422 mutex_lock(&rmidi->open_mutex);
423 while (1) { 414 while (1) {
424 subdevice = -1; 415 subdevice = -1;
425 read_lock(&card->ctl_files_rwlock); 416 read_lock(&card->ctl_files_rwlock);
@@ -431,8 +422,7 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
431 } 422 }
432 } 423 }
433 read_unlock(&card->ctl_files_rwlock); 424 read_unlock(&card->ctl_files_rwlock);
434 err = snd_rawmidi_kernel_open(rmidi->card, rmidi->device, 425 err = rawmidi_open_priv(rmidi, subdevice, fflags, rawmidi_file);
435 subdevice, fflags, rawmidi_file);
436 if (err >= 0) 426 if (err >= 0)
437 break; 427 break;
438 if (err == -EAGAIN) { 428 if (err == -EAGAIN) {
@@ -451,67 +441,89 @@ static int snd_rawmidi_open(struct inode *inode, struct file *file)
451 break; 441 break;
452 } 442 }
453 } 443 }
444 remove_wait_queue(&rmidi->open_wait, &wait);
445 if (err < 0) {
446 kfree(rawmidi_file);
447 goto __error;
448 }
454#ifdef CONFIG_SND_OSSEMUL 449#ifdef CONFIG_SND_OSSEMUL
455 if (rawmidi_file->input && rawmidi_file->input->runtime) 450 if (rawmidi_file->input && rawmidi_file->input->runtime)
456 rawmidi_file->input->runtime->oss = (maj == SOUND_MAJOR); 451 rawmidi_file->input->runtime->oss = (maj == SOUND_MAJOR);
457 if (rawmidi_file->output && rawmidi_file->output->runtime) 452 if (rawmidi_file->output && rawmidi_file->output->runtime)
458 rawmidi_file->output->runtime->oss = (maj == SOUND_MAJOR); 453 rawmidi_file->output->runtime->oss = (maj == SOUND_MAJOR);
459#endif 454#endif
460 remove_wait_queue(&rmidi->open_wait, &wait); 455 file->private_data = rawmidi_file;
461 if (err >= 0) { 456 mutex_unlock(&rmidi->open_mutex);
462 file->private_data = rawmidi_file; 457 return 0;
463 } else { 458
464 snd_card_file_remove(card, file); 459 __error:
465 kfree(rawmidi_file); 460 snd_card_file_remove(card, file);
466 } 461 __error_card:
467 mutex_unlock(&rmidi->open_mutex); 462 mutex_unlock(&rmidi->open_mutex);
463 module_put(rmidi->card->module);
468 return err; 464 return err;
469} 465}
470 466
471int snd_rawmidi_kernel_release(struct snd_rawmidi_file * rfile) 467static void close_substream(struct snd_rawmidi *rmidi,
468 struct snd_rawmidi_substream *substream,
469 int cleanup)
472{ 470{
473 struct snd_rawmidi *rmidi; 471 rmidi->streams[substream->stream].substream_opened--;
474 struct snd_rawmidi_substream *substream; 472 if (--substream->use_count)
475 struct snd_rawmidi_runtime *runtime; 473 return;
476 474
477 if (snd_BUG_ON(!rfile)) 475 if (cleanup) {
478 return -ENXIO; 476 if (substream->stream == SNDRV_RAWMIDI_STREAM_INPUT)
479 rmidi = rfile->rmidi; 477 snd_rawmidi_input_trigger(substream, 0);
480 mutex_lock(&rmidi->open_mutex); 478 else {
481 if (rfile->input != NULL) {
482 substream = rfile->input;
483 rfile->input = NULL;
484 runtime = substream->runtime;
485 snd_rawmidi_input_trigger(substream, 0);
486 substream->ops->close(substream);
487 if (runtime->private_free != NULL)
488 runtime->private_free(substream);
489 snd_rawmidi_runtime_free(substream);
490 substream->opened = 0;
491 rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substream_opened--;
492 }
493 if (rfile->output != NULL) {
494 substream = rfile->output;
495 rfile->output = NULL;
496 if (--substream->use_count == 0) {
497 runtime = substream->runtime;
498 if (substream->active_sensing) { 479 if (substream->active_sensing) {
499 unsigned char buf = 0xfe; 480 unsigned char buf = 0xfe;
500 /* sending single active sensing message to shut the device up */ 481 /* sending single active sensing message
482 * to shut the device up
483 */
501 snd_rawmidi_kernel_write(substream, &buf, 1); 484 snd_rawmidi_kernel_write(substream, &buf, 1);
502 } 485 }
503 if (snd_rawmidi_drain_output(substream) == -ERESTARTSYS) 486 if (snd_rawmidi_drain_output(substream) == -ERESTARTSYS)
504 snd_rawmidi_output_trigger(substream, 0); 487 snd_rawmidi_output_trigger(substream, 0);
505 substream->ops->close(substream);
506 if (runtime->private_free != NULL)
507 runtime->private_free(substream);
508 snd_rawmidi_runtime_free(substream);
509 substream->opened = 0;
510 substream->append = 0;
511 } 488 }
512 rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substream_opened--;
513 } 489 }
490 substream->ops->close(substream);
491 if (substream->runtime->private_free)
492 substream->runtime->private_free(substream);
493 snd_rawmidi_runtime_free(substream);
494 substream->opened = 0;
495 substream->append = 0;
496}
497
498static void rawmidi_release_priv(struct snd_rawmidi_file *rfile)
499{
500 struct snd_rawmidi *rmidi;
501
502 rmidi = rfile->rmidi;
503 mutex_lock(&rmidi->open_mutex);
504 if (rfile->input) {
505 close_substream(rmidi, rfile->input, 1);
506 rfile->input = NULL;
507 }
508 if (rfile->output) {
509 close_substream(rmidi, rfile->output, 1);
510 rfile->output = NULL;
511 }
512 rfile->rmidi = NULL;
514 mutex_unlock(&rmidi->open_mutex); 513 mutex_unlock(&rmidi->open_mutex);
514 wake_up(&rmidi->open_wait);
515}
516
517/* called from sound/core/seq/seq_midi.c */
518int snd_rawmidi_kernel_release(struct snd_rawmidi_file *rfile)
519{
520 struct snd_rawmidi *rmidi;
521
522 if (snd_BUG_ON(!rfile))
523 return -ENXIO;
524
525 rmidi = rfile->rmidi;
526 rawmidi_release_priv(rfile);
515 module_put(rmidi->card->module); 527 module_put(rmidi->card->module);
516 return 0; 528 return 0;
517} 529}
@@ -520,15 +532,14 @@ static int snd_rawmidi_release(struct inode *inode, struct file *file)
520{ 532{
521 struct snd_rawmidi_file *rfile; 533 struct snd_rawmidi_file *rfile;
522 struct snd_rawmidi *rmidi; 534 struct snd_rawmidi *rmidi;
523 int err;
524 535
525 rfile = file->private_data; 536 rfile = file->private_data;
526 err = snd_rawmidi_kernel_release(rfile);
527 rmidi = rfile->rmidi; 537 rmidi = rfile->rmidi;
528 wake_up(&rmidi->open_wait); 538 rawmidi_release_priv(rfile);
529 kfree(rfile); 539 kfree(rfile);
530 snd_card_file_remove(rmidi->card, file); 540 snd_card_file_remove(rmidi->card, file);
531 return err; 541 module_put(rmidi->card->module);
542 return 0;
532} 543}
533 544
534static int snd_rawmidi_info(struct snd_rawmidi_substream *substream, 545static int snd_rawmidi_info(struct snd_rawmidi_substream *substream,
diff --git a/sound/core/seq/oss/seq_oss_device.h b/sound/core/seq/oss/seq_oss_device.h
index bf8d2b4cb15e..c0154a959d55 100644
--- a/sound/core/seq/oss/seq_oss_device.h
+++ b/sound/core/seq/oss/seq_oss_device.h
@@ -181,7 +181,7 @@ char *enabled_str(int bool);
181/* for debug */ 181/* for debug */
182#ifdef SNDRV_SEQ_OSS_DEBUG 182#ifdef SNDRV_SEQ_OSS_DEBUG
183extern int seq_oss_debug; 183extern int seq_oss_debug;
184#define debug_printk(x) do { if (seq_oss_debug > 0) snd_printk x; } while (0) 184#define debug_printk(x) do { if (seq_oss_debug > 0) snd_printd x; } while (0)
185#else 185#else
186#define debug_printk(x) /**/ 186#define debug_printk(x) /**/
187#endif 187#endif
diff --git a/sound/core/seq/seq_prioq.c b/sound/core/seq/seq_prioq.c
index 0101a8b99b73..29896ab23403 100644
--- a/sound/core/seq/seq_prioq.c
+++ b/sound/core/seq/seq_prioq.c
@@ -321,7 +321,8 @@ void snd_seq_prioq_leave(struct snd_seq_prioq * f, int client, int timestamp)
321 freeprev = cell; 321 freeprev = cell;
322 } else { 322 } else {
323#if 0 323#if 0
324 printk("type = %i, source = %i, dest = %i, client = %i\n", 324 printk(KERN_DEBUG "type = %i, source = %i, dest = %i, "
325 "client = %i\n",
325 cell->event.type, 326 cell->event.type,
326 cell->event.source.client, 327 cell->event.source.client,
327 cell->event.dest.client, 328 cell->event.dest.client,
diff --git a/sound/core/vmaster.c b/sound/core/vmaster.c
index 4cc57f902e2c..257624bd1997 100644
--- a/sound/core/vmaster.c
+++ b/sound/core/vmaster.c
@@ -50,18 +50,38 @@ struct link_slave {
50 struct link_master *master; 50 struct link_master *master;
51 struct link_ctl_info info; 51 struct link_ctl_info info;
52 int vals[2]; /* current values */ 52 int vals[2]; /* current values */
53 unsigned int flags;
53 struct snd_kcontrol slave; /* the copy of original control entry */ 54 struct snd_kcontrol slave; /* the copy of original control entry */
54}; 55};
55 56
57static int slave_update(struct link_slave *slave)
58{
59 struct snd_ctl_elem_value *uctl;
60 int err, ch;
61
62 uctl = kmalloc(sizeof(*uctl), GFP_KERNEL);
63 if (!uctl)
64 return -ENOMEM;
65 uctl->id = slave->slave.id;
66 err = slave->slave.get(&slave->slave, uctl);
67 for (ch = 0; ch < slave->info.count; ch++)
68 slave->vals[ch] = uctl->value.integer.value[ch];
69 kfree(uctl);
70 return 0;
71}
72
56/* get the slave ctl info and save the initial values */ 73/* get the slave ctl info and save the initial values */
57static int slave_init(struct link_slave *slave) 74static int slave_init(struct link_slave *slave)
58{ 75{
59 struct snd_ctl_elem_info *uinfo; 76 struct snd_ctl_elem_info *uinfo;
60 struct snd_ctl_elem_value *uctl; 77 int err;
61 int err, ch;
62 78
63 if (slave->info.count) 79 if (slave->info.count) {
64 return 0; /* already initialized */ 80 /* already initialized */
81 if (slave->flags & SND_CTL_SLAVE_NEED_UPDATE)
82 return slave_update(slave);
83 return 0;
84 }
65 85
66 uinfo = kmalloc(sizeof(*uinfo), GFP_KERNEL); 86 uinfo = kmalloc(sizeof(*uinfo), GFP_KERNEL);
67 if (!uinfo) 87 if (!uinfo)
@@ -85,15 +105,7 @@ static int slave_init(struct link_slave *slave)
85 slave->info.max_val = uinfo->value.integer.max; 105 slave->info.max_val = uinfo->value.integer.max;
86 kfree(uinfo); 106 kfree(uinfo);
87 107
88 uctl = kmalloc(sizeof(*uctl), GFP_KERNEL); 108 return slave_update(slave);
89 if (!uctl)
90 return -ENOMEM;
91 uctl->id = slave->slave.id;
92 err = slave->slave.get(&slave->slave, uctl);
93 for (ch = 0; ch < slave->info.count; ch++)
94 slave->vals[ch] = uctl->value.integer.value[ch];
95 kfree(uctl);
96 return 0;
97} 109}
98 110
99/* initialize master volume */ 111/* initialize master volume */
@@ -229,7 +241,8 @@ static void slave_free(struct snd_kcontrol *kcontrol)
229 * - logarithmic volume control (dB level), no linear volume 241 * - logarithmic volume control (dB level), no linear volume
230 * - master can only attenuate the volume, no gain 242 * - master can only attenuate the volume, no gain
231 */ 243 */
232int snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave) 244int _snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave,
245 unsigned int flags)
233{ 246{
234 struct link_master *master_link = snd_kcontrol_chip(master); 247 struct link_master *master_link = snd_kcontrol_chip(master);
235 struct link_slave *srec; 248 struct link_slave *srec;
@@ -241,6 +254,7 @@ int snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave)
241 srec->slave = *slave; 254 srec->slave = *slave;
242 memcpy(srec->slave.vd, slave->vd, slave->count * sizeof(*slave->vd)); 255 memcpy(srec->slave.vd, slave->vd, slave->count * sizeof(*slave->vd));
243 srec->master = master_link; 256 srec->master = master_link;
257 srec->flags = flags;
244 258
245 /* override callbacks */ 259 /* override callbacks */
246 slave->info = slave_info; 260 slave->info = slave_info;
@@ -254,8 +268,7 @@ int snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave)
254 list_add_tail(&srec->list, &master_link->slaves); 268 list_add_tail(&srec->list, &master_link->slaves);
255 return 0; 269 return 0;
256} 270}
257 271EXPORT_SYMBOL(_snd_ctl_add_slave);
258EXPORT_SYMBOL(snd_ctl_add_slave);
259 272
260/* 273/*
261 * ctl callbacks for master controls 274 * ctl callbacks for master controls
@@ -327,8 +340,20 @@ static void master_free(struct snd_kcontrol *kcontrol)
327} 340}
328 341
329 342
330/* 343/**
331 * Create a virtual master control with the given name 344 * snd_ctl_make_virtual_master - Create a virtual master control
345 * @name: name string of the control element to create
346 * @tlv: optional TLV int array for dB information
347 *
348 * Creates a virtual matster control with the given name string.
349 * Returns the created control element, or NULL for errors (ENOMEM).
350 *
351 * After creating a vmaster element, you can add the slave controls
352 * via snd_ctl_add_slave() or snd_ctl_add_slave_uncached().
353 *
354 * The optional argument @tlv can be used to specify the TLV information
355 * for dB scale of the master control. It should be a single element
356 * with #SNDRV_CTL_TLVT_DB_SCALE type, and should be the max 0dB.
332 */ 357 */
333struct snd_kcontrol *snd_ctl_make_virtual_master(char *name, 358struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
334 const unsigned int *tlv) 359 const unsigned int *tlv)
@@ -367,5 +392,4 @@ struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
367 392
368 return kctl; 393 return kctl;
369} 394}
370
371EXPORT_SYMBOL(snd_ctl_make_virtual_master); 395EXPORT_SYMBOL(snd_ctl_make_virtual_master);
diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index 73be7e14a603..54239d2e0997 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -588,10 +588,10 @@ static int __devinit snd_dummy_probe(struct platform_device *devptr)
588 int idx, err; 588 int idx, err;
589 int dev = devptr->id; 589 int dev = devptr->id;
590 590
591 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 591 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
592 sizeof(struct snd_dummy)); 592 sizeof(struct snd_dummy), &card);
593 if (card == NULL) 593 if (err < 0)
594 return -ENOMEM; 594 return err;
595 dummy = card->private_data; 595 dummy = card->private_data;
596 dummy->card = card; 596 dummy->card = card;
597 for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) { 597 for (idx = 0; idx < MAX_PCM_DEVICES && idx < pcm_devs[dev]; idx++) {
diff --git a/sound/drivers/ml403-ac97cr.c b/sound/drivers/ml403-ac97cr.c
index 7783843ca9ae..1950ffce2b54 100644
--- a/sound/drivers/ml403-ac97cr.c
+++ b/sound/drivers/ml403-ac97cr.c
@@ -1279,9 +1279,9 @@ static int __devinit snd_ml403_ac97cr_probe(struct platform_device *pfdev)
1279 if (!enable[dev]) 1279 if (!enable[dev])
1280 return -ENOENT; 1280 return -ENOENT;
1281 1281
1282 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 1282 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
1283 if (card == NULL) 1283 if (err < 0)
1284 return -ENOMEM; 1284 return err;
1285 err = snd_ml403_ac97cr_create(card, pfdev, &ml403_ac97cr); 1285 err = snd_ml403_ac97cr_create(card, pfdev, &ml403_ac97cr);
1286 if (err < 0) { 1286 if (err < 0) {
1287 PDEBUG(INIT_FAILURE, "probe(): create failed!\n"); 1287 PDEBUG(INIT_FAILURE, "probe(): create failed!\n");
diff --git a/sound/drivers/mpu401/mpu401.c b/sound/drivers/mpu401/mpu401.c
index 5b996f3faba5..149d05a8202d 100644
--- a/sound/drivers/mpu401/mpu401.c
+++ b/sound/drivers/mpu401/mpu401.c
@@ -73,9 +73,9 @@ static int snd_mpu401_create(int dev, struct snd_card **rcard)
73 snd_printk(KERN_ERR "the uart_enter option is obsolete; remove it\n"); 73 snd_printk(KERN_ERR "the uart_enter option is obsolete; remove it\n");
74 74
75 *rcard = NULL; 75 *rcard = NULL;
76 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 76 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
77 if (card == NULL) 77 if (err < 0)
78 return -ENOMEM; 78 return err;
79 strcpy(card->driver, "MPU-401 UART"); 79 strcpy(card->driver, "MPU-401 UART");
80 strcpy(card->shortname, card->driver); 80 strcpy(card->shortname, card->driver);
81 sprintf(card->longname, "%s at %#lx, ", card->shortname, port[dev]); 81 sprintf(card->longname, "%s at %#lx, ", card->shortname, port[dev]);
diff --git a/sound/drivers/mtpav.c b/sound/drivers/mtpav.c
index 48b64e6b2670..2f8f295d6b0c 100644
--- a/sound/drivers/mtpav.c
+++ b/sound/drivers/mtpav.c
@@ -303,8 +303,10 @@ static void snd_mtpav_output_port_write(struct mtpav *mtp_card,
303 303
304 snd_mtpav_send_byte(mtp_card, 0xf5); 304 snd_mtpav_send_byte(mtp_card, 0xf5);
305 snd_mtpav_send_byte(mtp_card, portp->hwport); 305 snd_mtpav_send_byte(mtp_card, portp->hwport);
306 //snd_printk("new outport: 0x%x\n", (unsigned int) portp->hwport); 306 /*
307 307 snd_printk(KERN_DEBUG "new outport: 0x%x\n",
308 (unsigned int) portp->hwport);
309 */
308 if (!(outbyte & 0x80) && portp->running_status) 310 if (!(outbyte & 0x80) && portp->running_status)
309 snd_mtpav_send_byte(mtp_card, portp->running_status); 311 snd_mtpav_send_byte(mtp_card, portp->running_status);
310 } 312 }
@@ -540,7 +542,7 @@ static void snd_mtpav_read_bytes(struct mtpav *mcrd)
540 542
541 u8 sbyt = snd_mtpav_getreg(mcrd, SREG); 543 u8 sbyt = snd_mtpav_getreg(mcrd, SREG);
542 544
543 //printk("snd_mtpav_read_bytes() sbyt: 0x%x\n", sbyt); 545 /* printk(KERN_DEBUG "snd_mtpav_read_bytes() sbyt: 0x%x\n", sbyt); */
544 546
545 if (!(sbyt & SIGS_BYTE)) 547 if (!(sbyt & SIGS_BYTE))
546 return; 548 return;
@@ -585,12 +587,12 @@ static irqreturn_t snd_mtpav_irqh(int irq, void *dev_id)
585static int __devinit snd_mtpav_get_ISA(struct mtpav * mcard) 587static int __devinit snd_mtpav_get_ISA(struct mtpav * mcard)
586{ 588{
587 if ((mcard->res_port = request_region(port, 3, "MotuMTPAV MIDI")) == NULL) { 589 if ((mcard->res_port = request_region(port, 3, "MotuMTPAV MIDI")) == NULL) {
588 snd_printk("MTVAP port 0x%lx is busy\n", port); 590 snd_printk(KERN_ERR "MTVAP port 0x%lx is busy\n", port);
589 return -EBUSY; 591 return -EBUSY;
590 } 592 }
591 mcard->port = port; 593 mcard->port = port;
592 if (request_irq(irq, snd_mtpav_irqh, IRQF_DISABLED, "MOTU MTPAV", mcard)) { 594 if (request_irq(irq, snd_mtpav_irqh, IRQF_DISABLED, "MOTU MTPAV", mcard)) {
593 snd_printk("MTVAP IRQ %d busy\n", irq); 595 snd_printk(KERN_ERR "MTVAP IRQ %d busy\n", irq);
594 return -EBUSY; 596 return -EBUSY;
595 } 597 }
596 mcard->irq = irq; 598 mcard->irq = irq;
@@ -696,9 +698,9 @@ static int __devinit snd_mtpav_probe(struct platform_device *dev)
696 int err; 698 int err;
697 struct mtpav *mtp_card; 699 struct mtpav *mtp_card;
698 700
699 card = snd_card_new(index, id, THIS_MODULE, sizeof(*mtp_card)); 701 err = snd_card_create(index, id, THIS_MODULE, sizeof(*mtp_card), &card);
700 if (! card) 702 if (err < 0)
701 return -ENOMEM; 703 return err;
702 704
703 mtp_card = card->private_data; 705 mtp_card = card->private_data;
704 spin_lock_init(&mtp_card->spinlock); 706 spin_lock_init(&mtp_card->spinlock);
diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
index 87ba1ddc0115..9284829bf927 100644
--- a/sound/drivers/mts64.c
+++ b/sound/drivers/mts64.c
@@ -957,10 +957,10 @@ static int __devinit snd_mts64_probe(struct platform_device *pdev)
957 if ((err = snd_mts64_probe_port(p)) < 0) 957 if ((err = snd_mts64_probe_port(p)) < 0)
958 return err; 958 return err;
959 959
960 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 960 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
961 if (card == NULL) { 961 if (err < 0) {
962 snd_printd("Cannot create card\n"); 962 snd_printd("Cannot create card\n");
963 return -ENOMEM; 963 return err;
964 } 964 }
965 strcpy(card->driver, DRIVER_NAME); 965 strcpy(card->driver, DRIVER_NAME);
966 strcpy(card->shortname, "ESI " CARD_NAME); 966 strcpy(card->shortname, "ESI " CARD_NAME);
@@ -1015,7 +1015,7 @@ static int __devinit snd_mts64_probe(struct platform_device *pdev)
1015 goto __err; 1015 goto __err;
1016 } 1016 }
1017 1017
1018 snd_printk("ESI Miditerminal 4140 on 0x%lx\n", p->base); 1018 snd_printk(KERN_INFO "ESI Miditerminal 4140 on 0x%lx\n", p->base);
1019 return 0; 1019 return 0;
1020 1020
1021__err: 1021__err:
diff --git a/sound/drivers/opl3/opl3_lib.c b/sound/drivers/opl3/opl3_lib.c
index 780582340fef..6e31e46ca393 100644
--- a/sound/drivers/opl3/opl3_lib.c
+++ b/sound/drivers/opl3/opl3_lib.c
@@ -302,7 +302,7 @@ void snd_opl3_interrupt(struct snd_hwdep * hw)
302 opl3 = hw->private_data; 302 opl3 = hw->private_data;
303 status = inb(opl3->l_port); 303 status = inb(opl3->l_port);
304#if 0 304#if 0
305 snd_printk("AdLib IRQ status = 0x%x\n", status); 305 snd_printk(KERN_DEBUG "AdLib IRQ status = 0x%x\n", status);
306#endif 306#endif
307 if (!(status & 0x80)) 307 if (!(status & 0x80))
308 return; 308 return;
diff --git a/sound/drivers/opl3/opl3_midi.c b/sound/drivers/opl3/opl3_midi.c
index 16feafa2c51e..6e7d09ae0e82 100644
--- a/sound/drivers/opl3/opl3_midi.c
+++ b/sound/drivers/opl3/opl3_midi.c
@@ -125,7 +125,7 @@ static void debug_alloc(struct snd_opl3 *opl3, char *s, int voice) {
125 int i; 125 int i;
126 char *str = "x.24"; 126 char *str = "x.24";
127 127
128 printk("time %.5i: %s [%.2i]: ", opl3->use_time, s, voice); 128 printk(KERN_DEBUG "time %.5i: %s [%.2i]: ", opl3->use_time, s, voice);
129 for (i = 0; i < opl3->max_voices; i++) 129 for (i = 0; i < opl3->max_voices; i++)
130 printk("%c", *(str + opl3->voices[i].state + 1)); 130 printk("%c", *(str + opl3->voices[i].state + 1));
131 printk("\n"); 131 printk("\n");
@@ -218,7 +218,7 @@ static int opl3_get_voice(struct snd_opl3 *opl3, int instr_4op,
218 for (i = 0; i < END; i++) { 218 for (i = 0; i < END; i++) {
219 if (best[i].voice >= 0) { 219 if (best[i].voice >= 0) {
220#ifdef DEBUG_ALLOC 220#ifdef DEBUG_ALLOC
221 printk("%s %iop allocation on voice %i\n", 221 printk(KERN_DEBUG "%s %iop allocation on voice %i\n",
222 alloc_type[i], instr_4op ? 4 : 2, 222 alloc_type[i], instr_4op ? 4 : 2,
223 best[i].voice); 223 best[i].voice);
224#endif 224#endif
@@ -317,7 +317,7 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
317 opl3 = p; 317 opl3 = p;
318 318
319#ifdef DEBUG_MIDI 319#ifdef DEBUG_MIDI
320 snd_printk("Note on, ch %i, inst %i, note %i, vel %i\n", 320 snd_printk(KERN_DEBUG "Note on, ch %i, inst %i, note %i, vel %i\n",
321 chan->number, chan->midi_program, note, vel); 321 chan->number, chan->midi_program, note, vel);
322#endif 322#endif
323 323
@@ -372,7 +372,7 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
372 return; 372 return;
373 } 373 }
374#ifdef DEBUG_MIDI 374#ifdef DEBUG_MIDI
375 snd_printk(" --> OPL%i instrument: %s\n", 375 snd_printk(KERN_DEBUG " --> OPL%i instrument: %s\n",
376 instr_4op ? 3 : 2, patch->name); 376 instr_4op ? 3 : 2, patch->name);
377#endif 377#endif
378 /* in SYNTH mode, application takes care of voices */ 378 /* in SYNTH mode, application takes care of voices */
@@ -431,7 +431,7 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
431 } 431 }
432 432
433#ifdef DEBUG_MIDI 433#ifdef DEBUG_MIDI
434 snd_printk(" --> setting OPL3 connection: 0x%x\n", 434 snd_printk(KERN_DEBUG " --> setting OPL3 connection: 0x%x\n",
435 opl3->connection_reg); 435 opl3->connection_reg);
436#endif 436#endif
437 /* 437 /*
@@ -466,7 +466,7 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
466 /* Program the FM voice characteristics */ 466 /* Program the FM voice characteristics */
467 for (i = 0; i < (instr_4op ? 4 : 2); i++) { 467 for (i = 0; i < (instr_4op ? 4 : 2); i++) {
468#ifdef DEBUG_MIDI 468#ifdef DEBUG_MIDI
469 snd_printk(" --> programming operator %i\n", i); 469 snd_printk(KERN_DEBUG " --> programming operator %i\n", i);
470#endif 470#endif
471 op_offset = snd_opl3_regmap[voice_offset][i]; 471 op_offset = snd_opl3_regmap[voice_offset][i];
472 472
@@ -546,7 +546,7 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
546 blocknum |= OPL3_KEYON_BIT; 546 blocknum |= OPL3_KEYON_BIT;
547 547
548#ifdef DEBUG_MIDI 548#ifdef DEBUG_MIDI
549 snd_printk(" --> trigger voice %i\n", voice); 549 snd_printk(KERN_DEBUG " --> trigger voice %i\n", voice);
550#endif 550#endif
551 /* Set OPL3 KEYON_BLOCK register of requested voice */ 551 /* Set OPL3 KEYON_BLOCK register of requested voice */
552 opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset); 552 opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset);
@@ -602,7 +602,7 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
602 prg = extra_prg - 1; 602 prg = extra_prg - 1;
603 } 603 }
604#ifdef DEBUG_MIDI 604#ifdef DEBUG_MIDI
605 snd_printk(" *** allocating extra program\n"); 605 snd_printk(KERN_DEBUG " *** allocating extra program\n");
606#endif 606#endif
607 goto __extra_prg; 607 goto __extra_prg;
608 } 608 }
@@ -633,7 +633,7 @@ static void snd_opl3_kill_voice(struct snd_opl3 *opl3, int voice)
633 633
634 /* kill voice */ 634 /* kill voice */
635#ifdef DEBUG_MIDI 635#ifdef DEBUG_MIDI
636 snd_printk(" --> kill voice %i\n", voice); 636 snd_printk(KERN_DEBUG " --> kill voice %i\n", voice);
637#endif 637#endif
638 opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset); 638 opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset);
639 /* clear Key ON bit */ 639 /* clear Key ON bit */
@@ -670,7 +670,7 @@ void snd_opl3_note_off(void *p, int note, int vel, struct snd_midi_channel *chan
670 opl3 = p; 670 opl3 = p;
671 671
672#ifdef DEBUG_MIDI 672#ifdef DEBUG_MIDI
673 snd_printk("Note off, ch %i, inst %i, note %i\n", 673 snd_printk(KERN_DEBUG "Note off, ch %i, inst %i, note %i\n",
674 chan->number, chan->midi_program, note); 674 chan->number, chan->midi_program, note);
675#endif 675#endif
676 676
@@ -709,7 +709,7 @@ void snd_opl3_key_press(void *p, int note, int vel, struct snd_midi_channel *cha
709 709
710 opl3 = p; 710 opl3 = p;
711#ifdef DEBUG_MIDI 711#ifdef DEBUG_MIDI
712 snd_printk("Key pressure, ch#: %i, inst#: %i\n", 712 snd_printk(KERN_DEBUG "Key pressure, ch#: %i, inst#: %i\n",
713 chan->number, chan->midi_program); 713 chan->number, chan->midi_program);
714#endif 714#endif
715} 715}
@@ -723,7 +723,7 @@ void snd_opl3_terminate_note(void *p, int note, struct snd_midi_channel *chan)
723 723
724 opl3 = p; 724 opl3 = p;
725#ifdef DEBUG_MIDI 725#ifdef DEBUG_MIDI
726 snd_printk("Terminate note, ch#: %i, inst#: %i\n", 726 snd_printk(KERN_DEBUG "Terminate note, ch#: %i, inst#: %i\n",
727 chan->number, chan->midi_program); 727 chan->number, chan->midi_program);
728#endif 728#endif
729} 729}
@@ -812,7 +812,7 @@ void snd_opl3_control(void *p, int type, struct snd_midi_channel *chan)
812 812
813 opl3 = p; 813 opl3 = p;
814#ifdef DEBUG_MIDI 814#ifdef DEBUG_MIDI
815 snd_printk("Controller, TYPE = %i, ch#: %i, inst#: %i\n", 815 snd_printk(KERN_DEBUG "Controller, TYPE = %i, ch#: %i, inst#: %i\n",
816 type, chan->number, chan->midi_program); 816 type, chan->number, chan->midi_program);
817#endif 817#endif
818 818
@@ -849,7 +849,7 @@ void snd_opl3_nrpn(void *p, struct snd_midi_channel *chan,
849 849
850 opl3 = p; 850 opl3 = p;
851#ifdef DEBUG_MIDI 851#ifdef DEBUG_MIDI
852 snd_printk("NRPN, ch#: %i, inst#: %i\n", 852 snd_printk(KERN_DEBUG "NRPN, ch#: %i, inst#: %i\n",
853 chan->number, chan->midi_program); 853 chan->number, chan->midi_program);
854#endif 854#endif
855} 855}
@@ -864,6 +864,6 @@ void snd_opl3_sysex(void *p, unsigned char *buf, int len,
864 864
865 opl3 = p; 865 opl3 = p;
866#ifdef DEBUG_MIDI 866#ifdef DEBUG_MIDI
867 snd_printk("SYSEX\n"); 867 snd_printk(KERN_DEBUG "SYSEX\n");
868#endif 868#endif
869} 869}
diff --git a/sound/drivers/opl3/opl3_oss.c b/sound/drivers/opl3/opl3_oss.c
index 9a2271dc046a..a54b1dc5cc78 100644
--- a/sound/drivers/opl3/opl3_oss.c
+++ b/sound/drivers/opl3/opl3_oss.c
@@ -220,14 +220,14 @@ static int snd_opl3_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format,
220 return -EINVAL; 220 return -EINVAL;
221 221
222 if (count < (int)sizeof(sbi)) { 222 if (count < (int)sizeof(sbi)) {
223 snd_printk("FM Error: Patch record too short\n"); 223 snd_printk(KERN_ERR "FM Error: Patch record too short\n");
224 return -EINVAL; 224 return -EINVAL;
225 } 225 }
226 if (copy_from_user(&sbi, buf, sizeof(sbi))) 226 if (copy_from_user(&sbi, buf, sizeof(sbi)))
227 return -EFAULT; 227 return -EFAULT;
228 228
229 if (sbi.channel < 0 || sbi.channel >= SBFM_MAXINSTR) { 229 if (sbi.channel < 0 || sbi.channel >= SBFM_MAXINSTR) {
230 snd_printk("FM Error: Invalid instrument number %d\n", 230 snd_printk(KERN_ERR "FM Error: Invalid instrument number %d\n",
231 sbi.channel); 231 sbi.channel);
232 return -EINVAL; 232 return -EINVAL;
233 } 233 }
@@ -254,7 +254,9 @@ static int snd_opl3_ioctl_seq_oss(struct snd_seq_oss_arg *arg, unsigned int cmd,
254 opl3 = arg->private_data; 254 opl3 = arg->private_data;
255 switch (cmd) { 255 switch (cmd) {
256 case SNDCTL_FM_LOAD_INSTR: 256 case SNDCTL_FM_LOAD_INSTR:
257 snd_printk("OPL3: Obsolete ioctl(SNDCTL_FM_LOAD_INSTR) used. Fix the program.\n"); 257 snd_printk(KERN_ERR "OPL3: "
258 "Obsolete ioctl(SNDCTL_FM_LOAD_INSTR) used. "
259 "Fix the program.\n");
258 return -EINVAL; 260 return -EINVAL;
259 261
260 case SNDCTL_SYNTH_MEMAVL: 262 case SNDCTL_SYNTH_MEMAVL:
diff --git a/sound/drivers/opl3/opl3_synth.c b/sound/drivers/opl3/opl3_synth.c
index 962bb9c8b9c8..6d57b6441dec 100644
--- a/sound/drivers/opl3/opl3_synth.c
+++ b/sound/drivers/opl3/opl3_synth.c
@@ -168,7 +168,7 @@ int snd_opl3_ioctl(struct snd_hwdep * hw, struct file *file,
168 168
169#ifdef CONFIG_SND_DEBUG 169#ifdef CONFIG_SND_DEBUG
170 default: 170 default:
171 snd_printk("unknown IOCTL: 0x%x\n", cmd); 171 snd_printk(KERN_WARNING "unknown IOCTL: 0x%x\n", cmd);
172#endif 172#endif
173 } 173 }
174 return -ENOTTY; 174 return -ENOTTY;
diff --git a/sound/drivers/pcsp/pcsp.c b/sound/drivers/pcsp/pcsp.c
index a4049eb94d35..b60cef257b58 100644
--- a/sound/drivers/pcsp/pcsp.c
+++ b/sound/drivers/pcsp/pcsp.c
@@ -57,7 +57,7 @@ static int __devinit snd_pcsp_create(struct snd_card *card)
57 else 57 else
58 min_div = MAX_DIV; 58 min_div = MAX_DIV;
59#if PCSP_DEBUG 59#if PCSP_DEBUG
60 printk("PCSP: lpj=%li, min_div=%i, res=%li\n", 60 printk(KERN_DEBUG "PCSP: lpj=%li, min_div=%i, res=%li\n",
61 loops_per_jiffy, min_div, tp.tv_nsec); 61 loops_per_jiffy, min_div, tp.tv_nsec);
62#endif 62#endif
63 63
@@ -98,9 +98,9 @@ static int __devinit snd_card_pcsp_probe(int devnum, struct device *dev)
98 hrtimer_init(&pcsp_chip.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); 98 hrtimer_init(&pcsp_chip.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
99 pcsp_chip.timer.function = pcsp_do_timer; 99 pcsp_chip.timer.function = pcsp_do_timer;
100 100
101 card = snd_card_new(index, id, THIS_MODULE, 0); 101 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
102 if (!card) 102 if (err < 0)
103 return -ENOMEM; 103 return err;
104 104
105 err = snd_pcsp_create(card); 105 err = snd_pcsp_create(card);
106 if (err < 0) { 106 if (err < 0) {
diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
index b1c047ec19af..60158e2e0eaf 100644
--- a/sound/drivers/portman2x4.c
+++ b/sound/drivers/portman2x4.c
@@ -746,10 +746,10 @@ static int __devinit snd_portman_probe(struct platform_device *pdev)
746 if ((err = snd_portman_probe_port(p)) < 0) 746 if ((err = snd_portman_probe_port(p)) < 0)
747 return err; 747 return err;
748 748
749 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 749 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
750 if (card == NULL) { 750 if (err < 0) {
751 snd_printd("Cannot create card\n"); 751 snd_printd("Cannot create card\n");
752 return -ENOMEM; 752 return err;
753 } 753 }
754 strcpy(card->driver, DRIVER_NAME); 754 strcpy(card->driver, DRIVER_NAME);
755 strcpy(card->shortname, CARD_NAME); 755 strcpy(card->shortname, CARD_NAME);
diff --git a/sound/drivers/serial-u16550.c b/sound/drivers/serial-u16550.c
index d8aab9da97c2..b2b6d50c9425 100644
--- a/sound/drivers/serial-u16550.c
+++ b/sound/drivers/serial-u16550.c
@@ -241,7 +241,8 @@ static void snd_uart16550_io_loop(struct snd_uart16550 * uart)
241 snd_rawmidi_receive(uart->midi_input[substream], &c, 1); 241 snd_rawmidi_receive(uart->midi_input[substream], &c, 1);
242 242
243 if (status & UART_LSR_OE) 243 if (status & UART_LSR_OE)
244 snd_printk("%s: Overrun on device at 0x%lx\n", 244 snd_printk(KERN_WARNING
245 "%s: Overrun on device at 0x%lx\n",
245 uart->rmidi->name, uart->base); 246 uart->rmidi->name, uart->base);
246 } 247 }
247 248
@@ -636,7 +637,8 @@ static int snd_uart16550_output_byte(struct snd_uart16550 *uart,
636 } 637 }
637 } else { 638 } else {
638 if (!snd_uart16550_write_buffer(uart, midi_byte)) { 639 if (!snd_uart16550_write_buffer(uart, midi_byte)) {
639 snd_printk("%s: Buffer overrun on device at 0x%lx\n", 640 snd_printk(KERN_WARNING
641 "%s: Buffer overrun on device at 0x%lx\n",
640 uart->rmidi->name, uart->base); 642 uart->rmidi->name, uart->base);
641 return 0; 643 return 0;
642 } 644 }
@@ -815,7 +817,8 @@ static int __devinit snd_uart16550_create(struct snd_card *card,
815 if (irq >= 0 && irq != SNDRV_AUTO_IRQ) { 817 if (irq >= 0 && irq != SNDRV_AUTO_IRQ) {
816 if (request_irq(irq, snd_uart16550_interrupt, 818 if (request_irq(irq, snd_uart16550_interrupt,
817 IRQF_DISABLED, "Serial MIDI", uart)) { 819 IRQF_DISABLED, "Serial MIDI", uart)) {
818 snd_printk("irq %d busy. Using Polling.\n", irq); 820 snd_printk(KERN_WARNING
821 "irq %d busy. Using Polling.\n", irq);
819 } else { 822 } else {
820 uart->irq = irq; 823 uart->irq = irq;
821 } 824 }
@@ -919,26 +922,29 @@ static int __devinit snd_serial_probe(struct platform_device *devptr)
919 case SNDRV_SERIAL_GENERIC: 922 case SNDRV_SERIAL_GENERIC:
920 break; 923 break;
921 default: 924 default:
922 snd_printk("Adaptor type is out of range 0-%d (%d)\n", 925 snd_printk(KERN_ERR
926 "Adaptor type is out of range 0-%d (%d)\n",
923 SNDRV_SERIAL_MAX_ADAPTOR, adaptor[dev]); 927 SNDRV_SERIAL_MAX_ADAPTOR, adaptor[dev]);
924 return -ENODEV; 928 return -ENODEV;
925 } 929 }
926 930
927 if (outs[dev] < 1 || outs[dev] > SNDRV_SERIAL_MAX_OUTS) { 931 if (outs[dev] < 1 || outs[dev] > SNDRV_SERIAL_MAX_OUTS) {
928 snd_printk("Count of outputs is out of range 1-%d (%d)\n", 932 snd_printk(KERN_ERR
933 "Count of outputs is out of range 1-%d (%d)\n",
929 SNDRV_SERIAL_MAX_OUTS, outs[dev]); 934 SNDRV_SERIAL_MAX_OUTS, outs[dev]);
930 return -ENODEV; 935 return -ENODEV;
931 } 936 }
932 937
933 if (ins[dev] < 1 || ins[dev] > SNDRV_SERIAL_MAX_INS) { 938 if (ins[dev] < 1 || ins[dev] > SNDRV_SERIAL_MAX_INS) {
934 snd_printk("Count of inputs is out of range 1-%d (%d)\n", 939 snd_printk(KERN_ERR
940 "Count of inputs is out of range 1-%d (%d)\n",
935 SNDRV_SERIAL_MAX_INS, ins[dev]); 941 SNDRV_SERIAL_MAX_INS, ins[dev]);
936 return -ENODEV; 942 return -ENODEV;
937 } 943 }
938 944
939 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 945 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
940 if (card == NULL) 946 if (err < 0)
941 return -ENOMEM; 947 return err;
942 948
943 strcpy(card->driver, "Serial"); 949 strcpy(card->driver, "Serial");
944 strcpy(card->shortname, "Serial MIDI (UART16550A)"); 950 strcpy(card->shortname, "Serial MIDI (UART16550A)");
diff --git a/sound/drivers/virmidi.c b/sound/drivers/virmidi.c
index f79e3614079d..0e631c3221e3 100644
--- a/sound/drivers/virmidi.c
+++ b/sound/drivers/virmidi.c
@@ -90,15 +90,17 @@ static int __devinit snd_virmidi_probe(struct platform_device *devptr)
90 int idx, err; 90 int idx, err;
91 int dev = devptr->id; 91 int dev = devptr->id;
92 92
93 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 93 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
94 sizeof(struct snd_card_virmidi)); 94 sizeof(struct snd_card_virmidi), &card);
95 if (card == NULL) 95 if (err < 0)
96 return -ENOMEM; 96 return err;
97 vmidi = (struct snd_card_virmidi *)card->private_data; 97 vmidi = (struct snd_card_virmidi *)card->private_data;
98 vmidi->card = card; 98 vmidi->card = card;
99 99
100 if (midi_devs[dev] > MAX_MIDI_DEVICES) { 100 if (midi_devs[dev] > MAX_MIDI_DEVICES) {
101 snd_printk("too much midi devices for virmidi %d: force to use %d\n", dev, MAX_MIDI_DEVICES); 101 snd_printk(KERN_WARNING
102 "too much midi devices for virmidi %d: "
103 "force to use %d\n", dev, MAX_MIDI_DEVICES);
102 midi_devs[dev] = MAX_MIDI_DEVICES; 104 midi_devs[dev] = MAX_MIDI_DEVICES;
103 } 105 }
104 for (idx = 0; idx < midi_devs[dev]; idx++) { 106 for (idx = 0; idx < midi_devs[dev]; idx++) {
diff --git a/sound/drivers/vx/vx_core.c b/sound/drivers/vx/vx_core.c
index 14e3354be43a..19c6e376c7c7 100644
--- a/sound/drivers/vx/vx_core.c
+++ b/sound/drivers/vx/vx_core.c
@@ -688,7 +688,8 @@ int snd_vx_dsp_load(struct vx_core *chip, const struct firmware *dsp)
688 image = dsp->data + i; 688 image = dsp->data + i;
689 /* Wait DSP ready for a new read */ 689 /* Wait DSP ready for a new read */
690 if ((err = vx_wait_isr_bit(chip, ISR_TX_EMPTY)) < 0) { 690 if ((err = vx_wait_isr_bit(chip, ISR_TX_EMPTY)) < 0) {
691 printk("dsp loading error at position %d\n", i); 691 printk(KERN_ERR
692 "dsp loading error at position %d\n", i);
692 return err; 693 return err;
693 } 694 }
694 cptr = image; 695 cptr = image;
diff --git a/sound/drivers/vx/vx_hwdep.c b/sound/drivers/vx/vx_hwdep.c
index 8d6362e2d4c9..46df8817c18f 100644
--- a/sound/drivers/vx/vx_hwdep.c
+++ b/sound/drivers/vx/vx_hwdep.c
@@ -119,16 +119,6 @@ void snd_vx_free_firmware(struct vx_core *chip)
119 119
120#else /* old style firmware loading */ 120#else /* old style firmware loading */
121 121
122static int vx_hwdep_open(struct snd_hwdep *hw, struct file *file)
123{
124 return 0;
125}
126
127static int vx_hwdep_release(struct snd_hwdep *hw, struct file *file)
128{
129 return 0;
130}
131
132static int vx_hwdep_dsp_status(struct snd_hwdep *hw, 122static int vx_hwdep_dsp_status(struct snd_hwdep *hw,
133 struct snd_hwdep_dsp_status *info) 123 struct snd_hwdep_dsp_status *info)
134{ 124{
@@ -243,8 +233,6 @@ int snd_vx_setup_firmware(struct vx_core *chip)
243 233
244 hw->iface = SNDRV_HWDEP_IFACE_VX; 234 hw->iface = SNDRV_HWDEP_IFACE_VX;
245 hw->private_data = chip; 235 hw->private_data = chip;
246 hw->ops.open = vx_hwdep_open;
247 hw->ops.release = vx_hwdep_release;
248 hw->ops.dsp_status = vx_hwdep_dsp_status; 236 hw->ops.dsp_status = vx_hwdep_dsp_status;
249 hw->ops.dsp_load = vx_hwdep_dsp_load; 237 hw->ops.dsp_load = vx_hwdep_dsp_load;
250 hw->exclusive = 1; 238 hw->exclusive = 1;
diff --git a/sound/drivers/vx/vx_uer.c b/sound/drivers/vx/vx_uer.c
index 0e1ba9b47904..b0560fec6bba 100644
--- a/sound/drivers/vx/vx_uer.c
+++ b/sound/drivers/vx/vx_uer.c
@@ -103,7 +103,7 @@ static void vx_write_one_cbit(struct vx_core *chip, int index, int val)
103 * returns the frequency of UER, or 0 if not sync, 103 * returns the frequency of UER, or 0 if not sync,
104 * or a negative error code. 104 * or a negative error code.
105 */ 105 */
106static int vx_read_uer_status(struct vx_core *chip, int *mode) 106static int vx_read_uer_status(struct vx_core *chip, unsigned int *mode)
107{ 107{
108 int val, freq; 108 int val, freq;
109 109
diff --git a/sound/i2c/Makefile b/sound/i2c/Makefile
index 37970666a453..36879bf88700 100644
--- a/sound/i2c/Makefile
+++ b/sound/i2c/Makefile
@@ -7,8 +7,6 @@ snd-i2c-objs := i2c.o
7snd-cs8427-objs := cs8427.o 7snd-cs8427-objs := cs8427.o
8snd-tea6330t-objs := tea6330t.o 8snd-tea6330t-objs := tea6330t.o
9 9
10obj-$(CONFIG_L3) += l3/
11
12obj-$(CONFIG_SND) += other/ 10obj-$(CONFIG_SND) += other/
13 11
14# Toplevel Module Dependency 12# Toplevel Module Dependency
diff --git a/sound/i2c/l3/Makefile b/sound/i2c/l3/Makefile
deleted file mode 100644
index 49455b8dcc04..000000000000
--- a/sound/i2c/l3/Makefile
+++ /dev/null
@@ -1,8 +0,0 @@
1#
2# Makefile for ALSA
3#
4
5snd-uda1341-objs := uda1341.o
6
7# Module Dependency
8obj-$(CONFIG_SND_SA11XX_UDA1341) += snd-uda1341.o
diff --git a/sound/i2c/l3/uda1341.c b/sound/i2c/l3/uda1341.c
deleted file mode 100644
index 9840eb43648d..000000000000
--- a/sound/i2c/l3/uda1341.c
+++ /dev/null
@@ -1,935 +0,0 @@
1/*
2 * Philips UDA1341 mixer device driver
3 * Copyright (c) 2002 Tomas Kasparek <tomas.kasparek@seznam.cz>
4 *
5 * Portions are Copyright (C) 2000 Lernout & Hauspie Speech Products, N.V.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License.
9 *
10 * History:
11 *
12 * 2002-03-13 Tomas Kasparek initial release - based on uda1341.c from OSS
13 * 2002-03-28 Tomas Kasparek basic mixer is working (volume, bass, treble)
14 * 2002-03-30 Tomas Kasparek proc filesystem support, complete mixer and DSP
15 * features support
16 * 2002-04-12 Tomas Kasparek proc interface update, code cleanup
17 * 2002-05-12 Tomas Kasparek another code cleanup
18 */
19
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/types.h>
23#include <linux/slab.h>
24#include <linux/errno.h>
25#include <linux/ioctl.h>
26
27#include <asm/uaccess.h>
28
29#include <sound/core.h>
30#include <sound/control.h>
31#include <sound/initval.h>
32#include <sound/info.h>
33
34#include <linux/l3/l3.h>
35
36#include <sound/uda1341.h>
37
38/* {{{ HW regs definition */
39
40#define STAT0 0x00
41#define STAT1 0x80
42#define STAT_MASK 0x80
43
44#define DATA0_0 0x00
45#define DATA0_1 0x40
46#define DATA0_2 0x80
47#define DATA_MASK 0xc0
48
49#define IS_DATA0(x) ((x) >= data0_0 && (x) <= data0_2)
50#define IS_DATA1(x) ((x) == data1)
51#define IS_STATUS(x) ((x) == stat0 || (x) == stat1)
52#define IS_EXTEND(x) ((x) >= ext0 && (x) <= ext6)
53
54/* }}} */
55
56
57static const char *peak_names[] = {
58 "before",
59 "after",
60};
61
62static const char *filter_names[] = {
63 "flat",
64 "min",
65 "min",
66 "max",
67};
68
69static const char *mixer_names[] = {
70 "double differential",
71 "input channel 1 (line in)",
72 "input channel 2 (microphone)",
73 "digital mixer",
74};
75
76static const char *deemp_names[] = {
77 "none",
78 "32 kHz",
79 "44.1 kHz",
80 "48 kHz",
81};
82
83enum uda1341_regs_names {
84 stat0,
85 stat1,
86 data0_0,
87 data0_1,
88 data0_2,
89 data1,
90 ext0,
91 ext1,
92 ext2,
93 empty,
94 ext4,
95 ext5,
96 ext6,
97 uda1341_reg_last,
98};
99
100static const char *uda1341_reg_names[] = {
101 "stat 0 ",
102 "stat 1 ",
103 "data 00",
104 "data 01",
105 "data 02",
106 "data 1 ",
107 "ext 0",
108 "ext 1",
109 "ext 2",
110 "empty",
111 "ext 4",
112 "ext 5",
113 "ext 6",
114};
115
116static const int uda1341_enum_items[] = {
117 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
118 2, //peak - before/after
119 4, //deemp - none/32/44.1/48
120 0,
121 4, //filter - flat/min/min/max
122 0, 0, 0,
123 4, //mixer - differ/line/mic/mixer
124 0, 0, 0, 0, 0,
125};
126
127static const char ** uda1341_enum_names[] = {
128 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
129 peak_names, //peak - before/after
130 deemp_names, //deemp - none/32/44.1/48
131 NULL,
132 filter_names, //filter - flat/min/min/max
133 NULL, NULL, NULL,
134 mixer_names, //mixer - differ/line/mic/mixer
135 NULL, NULL, NULL, NULL, NULL,
136};
137
138typedef int uda1341_cfg[CMD_LAST];
139
140struct uda1341 {
141 int (*write) (struct l3_client *uda1341, unsigned short reg, unsigned short val);
142 int (*read) (struct l3_client *uda1341, unsigned short reg);
143 unsigned char regs[uda1341_reg_last];
144 int active;
145 spinlock_t reg_lock;
146 struct snd_card *card;
147 uda1341_cfg cfg;
148#ifdef CONFIG_PM
149 unsigned char suspend_regs[uda1341_reg_last];
150 uda1341_cfg suspend_cfg;
151#endif
152};
153
154/* transfer 8bit integer into string with binary representation */
155static void int2str_bin8(uint8_t val, char *buf)
156{
157 const int size = sizeof(val) * 8;
158 int i;
159
160 for (i= 0; i < size; i++){
161 *(buf++) = (val >> (size - 1)) ? '1' : '0';
162 val <<= 1;
163 }
164 *buf = '\0'; //end the string with zero
165}
166
167/* {{{ HW manipulation routines */
168
169static int snd_uda1341_codec_write(struct l3_client *clnt, unsigned short reg, unsigned short val)
170{
171 struct uda1341 *uda = clnt->driver_data;
172 unsigned char buf[2] = { 0xc0, 0xe0 }; // for EXT addressing
173 int err = 0;
174
175 uda->regs[reg] = val;
176
177 if (uda->active) {
178 if (IS_DATA0(reg)) {
179 err = l3_write(clnt, UDA1341_DATA0, (const unsigned char *)&val, 1);
180 } else if (IS_DATA1(reg)) {
181 err = l3_write(clnt, UDA1341_DATA1, (const unsigned char *)&val, 1);
182 } else if (IS_STATUS(reg)) {
183 err = l3_write(clnt, UDA1341_STATUS, (const unsigned char *)&val, 1);
184 } else if (IS_EXTEND(reg)) {
185 buf[0] |= (reg - ext0) & 0x7; //EXT address
186 buf[1] |= val; //EXT data
187 err = l3_write(clnt, UDA1341_DATA0, (const unsigned char *)buf, 2);
188 }
189 } else
190 printk(KERN_ERR "UDA1341 codec not active!\n");
191 return err;
192}
193
194static int snd_uda1341_codec_read(struct l3_client *clnt, unsigned short reg)
195{
196 unsigned char val;
197 int err;
198
199 err = l3_read(clnt, reg, &val, 1);
200 if (err == 1)
201 // use just 6bits - the rest is address of the reg
202 return val & 63;
203 return err < 0 ? err : -EIO;
204}
205
206static inline int snd_uda1341_valid_reg(struct l3_client *clnt, unsigned short reg)
207{
208 return reg < uda1341_reg_last;
209}
210
211static int snd_uda1341_update_bits(struct l3_client *clnt, unsigned short reg,
212 unsigned short mask, unsigned short shift,
213 unsigned short value, int flush)
214{
215 int change;
216 unsigned short old, new;
217 struct uda1341 *uda = clnt->driver_data;
218
219#if 0
220 printk(KERN_DEBUG "update_bits: reg: %s mask: %d shift: %d val: %d\n",
221 uda1341_reg_names[reg], mask, shift, value);
222#endif
223
224 if (!snd_uda1341_valid_reg(clnt, reg))
225 return -EINVAL;
226 spin_lock(&uda->reg_lock);
227 old = uda->regs[reg];
228 new = (old & ~(mask << shift)) | (value << shift);
229 change = old != new;
230 if (change) {
231 if (flush) uda->write(clnt, reg, new);
232 uda->regs[reg] = new;
233 }
234 spin_unlock(&uda->reg_lock);
235 return change;
236}
237
238static int snd_uda1341_cfg_write(struct l3_client *clnt, unsigned short what,
239 unsigned short value, int flush)
240{
241 struct uda1341 *uda = clnt->driver_data;
242 int ret = 0;
243#ifdef CONFIG_PM
244 int reg;
245#endif
246
247#if 0
248 printk(KERN_DEBUG "cfg_write what: %d value: %d\n", what, value);
249#endif
250
251 uda->cfg[what] = value;
252
253 switch(what) {
254 case CMD_RESET:
255 ret = snd_uda1341_update_bits(clnt, data0_2, 1, 2, 1, flush); // MUTE
256 ret = snd_uda1341_update_bits(clnt, stat0, 1, 6, 1, flush); // RESET
257 ret = snd_uda1341_update_bits(clnt, stat0, 1, 6, 0, flush); // RESTORE
258 uda->cfg[CMD_RESET]=0;
259 break;
260 case CMD_FS:
261 ret = snd_uda1341_update_bits(clnt, stat0, 3, 4, value, flush);
262 break;
263 case CMD_FORMAT:
264 ret = snd_uda1341_update_bits(clnt, stat0, 7, 1, value, flush);
265 break;
266 case CMD_OGAIN:
267 ret = snd_uda1341_update_bits(clnt, stat1, 1, 6, value, flush);
268 break;
269 case CMD_IGAIN:
270 ret = snd_uda1341_update_bits(clnt, stat1, 1, 5, value, flush);
271 break;
272 case CMD_DAC:
273 ret = snd_uda1341_update_bits(clnt, stat1, 1, 0, value, flush);
274 break;
275 case CMD_ADC:
276 ret = snd_uda1341_update_bits(clnt, stat1, 1, 1, value, flush);
277 break;
278 case CMD_VOLUME:
279 ret = snd_uda1341_update_bits(clnt, data0_0, 63, 0, value, flush);
280 break;
281 case CMD_BASS:
282 ret = snd_uda1341_update_bits(clnt, data0_1, 15, 2, value, flush);
283 break;
284 case CMD_TREBBLE:
285 ret = snd_uda1341_update_bits(clnt, data0_1, 3, 0, value, flush);
286 break;
287 case CMD_PEAK:
288 ret = snd_uda1341_update_bits(clnt, data0_2, 1, 5, value, flush);
289 break;
290 case CMD_DEEMP:
291 ret = snd_uda1341_update_bits(clnt, data0_2, 3, 3, value, flush);
292 break;
293 case CMD_MUTE:
294 ret = snd_uda1341_update_bits(clnt, data0_2, 1, 2, value, flush);
295 break;
296 case CMD_FILTER:
297 ret = snd_uda1341_update_bits(clnt, data0_2, 3, 0, value, flush);
298 break;
299 case CMD_CH1:
300 ret = snd_uda1341_update_bits(clnt, ext0, 31, 0, value, flush);
301 break;
302 case CMD_CH2:
303 ret = snd_uda1341_update_bits(clnt, ext1, 31, 0, value, flush);
304 break;
305 case CMD_MIC:
306 ret = snd_uda1341_update_bits(clnt, ext2, 7, 2, value, flush);
307 break;
308 case CMD_MIXER:
309 ret = snd_uda1341_update_bits(clnt, ext2, 3, 0, value, flush);
310 break;
311 case CMD_AGC:
312 ret = snd_uda1341_update_bits(clnt, ext4, 1, 4, value, flush);
313 break;
314 case CMD_IG:
315 ret = snd_uda1341_update_bits(clnt, ext4, 3, 0, value & 0x3, flush);
316 ret = snd_uda1341_update_bits(clnt, ext5, 31, 0, value >> 2, flush);
317 break;
318 case CMD_AGC_TIME:
319 ret = snd_uda1341_update_bits(clnt, ext6, 7, 2, value, flush);
320 break;
321 case CMD_AGC_LEVEL:
322 ret = snd_uda1341_update_bits(clnt, ext6, 3, 0, value, flush);
323 break;
324#ifdef CONFIG_PM
325 case CMD_SUSPEND:
326 for (reg = stat0; reg < uda1341_reg_last; reg++)
327 uda->suspend_regs[reg] = uda->regs[reg];
328 for (reg = 0; reg < CMD_LAST; reg++)
329 uda->suspend_cfg[reg] = uda->cfg[reg];
330 break;
331 case CMD_RESUME:
332 for (reg = stat0; reg < uda1341_reg_last; reg++)
333 snd_uda1341_codec_write(clnt, reg, uda->suspend_regs[reg]);
334 for (reg = 0; reg < CMD_LAST; reg++)
335 uda->cfg[reg] = uda->suspend_cfg[reg];
336 break;
337#endif
338 default:
339 ret = -EINVAL;
340 break;
341 }
342
343 if (!uda->active)
344 printk(KERN_ERR "UDA1341 codec not active!\n");
345 return ret;
346}
347
348/* }}} */
349
350/* {{{ Proc interface */
351#ifdef CONFIG_PROC_FS
352
353static const char *format_names[] = {
354 "I2S-bus",
355 "LSB 16bits",
356 "LSB 18bits",
357 "LSB 20bits",
358 "MSB",
359 "in LSB 16bits/out MSB",
360 "in LSB 18bits/out MSB",
361 "in LSB 20bits/out MSB",
362};
363
364static const char *fs_names[] = {
365 "512*fs",
366 "384*fs",
367 "256*fs",
368 "Unused - bad value!",
369};
370
371static const char* bass_values[][16] = {
372 {"0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB", "0 dB",
373 "0 dB", "0 dB", "0 dB", "0 dB", "undefined", }, //flat
374 {"0 dB", "2 dB", "4 dB", "6 dB", "8 dB", "10 dB", "12 dB", "14 dB", "16 dB", "18 dB", "18 dB",
375 "18 dB", "18 dB", "18 dB", "18 dB", "undefined",}, // min
376 {"0 dB", "2 dB", "4 dB", "6 dB", "8 dB", "10 dB", "12 dB", "14 dB", "16 dB", "18 dB", "18 dB",
377 "18 dB", "18 dB", "18 dB", "18 dB", "undefined",}, // min
378 {"0 dB", "2 dB", "4 dB", "6 dB", "8 dB", "10 dB", "12 dB", "14 dB", "16 dB", "18 dB", "20 dB",
379 "22 dB", "24 dB", "24 dB", "24 dB", "undefined",}, // max
380};
381
382static const char *mic_sens_value[] = {
383 "-3 dB", "0 dB", "3 dB", "9 dB", "15 dB", "21 dB", "27 dB", "not used",
384};
385
386static const unsigned short AGC_atime[] = {
387 11, 16, 11, 16, 21, 11, 16, 21,
388};
389
390static const unsigned short AGC_dtime[] = {
391 100, 100, 200, 200, 200, 400, 400, 400,
392};
393
394static const char *AGC_level[] = {
395 "-9.0", "-11.5", "-15.0", "-17.5",
396};
397
398static const char *ig_small_value[] = {
399 "-3.0", "-2.5", "-2.0", "-1.5", "-1.0", "-0.5",
400};
401
402/*
403 * this was computed as peak_value[i] = pow((63-i)*1.42,1.013)
404 *
405 * UDA1341 datasheet on page 21: Peak value (dB) = (Peak level - 63.5)*5*log2
406 * There is an table with these values [level]=value: [3]=-90.31, [7]=-84.29
407 * [61]=-2.78, [62] = -1.48, [63] = 0.0
408 * I tried to compute it, but using but even using logarithm with base either 10 or 2
409 * i was'n able to get values in the table from the formula. So I constructed another
410 * formula (see above) to interpolate the values as good as possible. If there is some
411 * mistake, please contact me on tomas.kasparek@seznam.cz. Thanks.
412 * UDA1341TS datasheet is available at:
413 * http://www-us9.semiconductors.com/acrobat/datasheets/UDA1341TS_3.pdf
414 */
415static const char *peak_value[] = {
416 "-INF dB", "N.A.", "N.A", "90.31 dB", "N.A.", "N.A.", "N.A.", "-84.29 dB",
417 "-82.65 dB", "-81.13 dB", "-79.61 dB", "-78.09 dB", "-76.57 dB", "-75.05 dB", "-73.53 dB",
418 "-72.01 dB", "-70.49 dB", "-68.97 dB", "-67.45 dB", "-65.93 dB", "-64.41 dB", "-62.90 dB",
419 "-61.38 dB", "-59.86 dB", "-58.35 dB", "-56.83 dB", "-55.32 dB", "-53.80 dB", "-52.29 dB",
420 "-50.78 dB", "-49.26 dB", "-47.75 dB", "-46.24 dB", "-44.73 dB", "-43.22 dB", "-41.71 dB",
421 "-40.20 dB", "-38.69 dB", "-37.19 dB", "-35.68 dB", "-34.17 dB", "-32.67 dB", "-31.17 dB",
422 "-29.66 dB", "-28.16 dB", "-26.66 dB", "-25.16 dB", "-23.66 dB", "-22.16 dB", "-20.67 dB",
423 "-19.17 dB", "-17.68 dB", "-16.19 dB", "-14.70 dB", "-13.21 dB", "-11.72 dB", "-10.24 dB",
424 "-8.76 dB", "-7.28 dB", "-5.81 dB", "-4.34 dB", "-2.88 dB", "-1.43 dB", "0.00 dB",
425};
426
427static void snd_uda1341_proc_read(struct snd_info_entry *entry,
428 struct snd_info_buffer *buffer)
429{
430 struct l3_client *clnt = entry->private_data;
431 struct uda1341 *uda = clnt->driver_data;
432 int peak;
433
434 peak = snd_uda1341_codec_read(clnt, UDA1341_DATA1);
435 if (peak < 0)
436 peak = 0;
437
438 snd_iprintf(buffer, "%s\n\n", uda->card->longname);
439
440 // for information about computed values see UDA1341TS datasheet pages 15 - 21
441 snd_iprintf(buffer, "DAC power : %s\n", uda->cfg[CMD_DAC] ? "on" : "off");
442 snd_iprintf(buffer, "ADC power : %s\n", uda->cfg[CMD_ADC] ? "on" : "off");
443 snd_iprintf(buffer, "Clock frequency : %s\n", fs_names[uda->cfg[CMD_FS]]);
444 snd_iprintf(buffer, "Data format : %s\n\n", format_names[uda->cfg[CMD_FORMAT]]);
445
446 snd_iprintf(buffer, "Filter mode : %s\n", filter_names[uda->cfg[CMD_FILTER]]);
447 snd_iprintf(buffer, "Mixer mode : %s\n", mixer_names[uda->cfg[CMD_MIXER]]);
448 snd_iprintf(buffer, "De-emphasis : %s\n", deemp_names[uda->cfg[CMD_DEEMP]]);
449 snd_iprintf(buffer, "Peak detection pos. : %s\n", uda->cfg[CMD_PEAK] ? "after" : "before");
450 snd_iprintf(buffer, "Peak value : %s\n\n", peak_value[peak]);
451
452 snd_iprintf(buffer, "Automatic Gain Ctrl : %s\n", uda->cfg[CMD_AGC] ? "on" : "off");
453 snd_iprintf(buffer, "AGC attack time : %d ms\n", AGC_atime[uda->cfg[CMD_AGC_TIME]]);
454 snd_iprintf(buffer, "AGC decay time : %d ms\n", AGC_dtime[uda->cfg[CMD_AGC_TIME]]);
455 snd_iprintf(buffer, "AGC output level : %s dB\n\n", AGC_level[uda->cfg[CMD_AGC_LEVEL]]);
456
457 snd_iprintf(buffer, "Mute : %s\n", uda->cfg[CMD_MUTE] ? "on" : "off");
458
459 if (uda->cfg[CMD_VOLUME] == 0)
460 snd_iprintf(buffer, "Volume : 0 dB\n");
461 else if (uda->cfg[CMD_VOLUME] < 62)
462 snd_iprintf(buffer, "Volume : %d dB\n", -1*uda->cfg[CMD_VOLUME] +1);
463 else
464 snd_iprintf(buffer, "Volume : -INF dB\n");
465 snd_iprintf(buffer, "Bass : %s\n", bass_values[uda->cfg[CMD_FILTER]][uda->cfg[CMD_BASS]]);
466 snd_iprintf(buffer, "Trebble : %d dB\n", uda->cfg[CMD_FILTER] ? 2*uda->cfg[CMD_TREBBLE] : 0);
467 snd_iprintf(buffer, "Input Gain (6dB) : %s\n", uda->cfg[CMD_IGAIN] ? "on" : "off");
468 snd_iprintf(buffer, "Output Gain (6dB) : %s\n", uda->cfg[CMD_OGAIN] ? "on" : "off");
469 snd_iprintf(buffer, "Mic sensitivity : %s\n", mic_sens_value[uda->cfg[CMD_MIC]]);
470
471
472 if(uda->cfg[CMD_CH1] < 31)
473 snd_iprintf(buffer, "Mixer gain channel 1: -%d.%c dB\n",
474 ((uda->cfg[CMD_CH1] >> 1) * 3) + (uda->cfg[CMD_CH1] & 1),
475 uda->cfg[CMD_CH1] & 1 ? '5' : '0');
476 else
477 snd_iprintf(buffer, "Mixer gain channel 1: -INF dB\n");
478 if(uda->cfg[CMD_CH2] < 31)
479 snd_iprintf(buffer, "Mixer gain channel 2: -%d.%c dB\n",
480 ((uda->cfg[CMD_CH2] >> 1) * 3) + (uda->cfg[CMD_CH2] & 1),
481 uda->cfg[CMD_CH2] & 1 ? '5' : '0');
482 else
483 snd_iprintf(buffer, "Mixer gain channel 2: -INF dB\n");
484
485 if(uda->cfg[CMD_IG] > 5)
486 snd_iprintf(buffer, "Input Amp. Gain ch 2: %d.%c dB\n",
487 (uda->cfg[CMD_IG] >> 1) -3, uda->cfg[CMD_IG] & 1 ? '5' : '0');
488 else
489 snd_iprintf(buffer, "Input Amp. Gain ch 2: %s dB\n", ig_small_value[uda->cfg[CMD_IG]]);
490}
491
492static void snd_uda1341_proc_regs_read(struct snd_info_entry *entry,
493 struct snd_info_buffer *buffer)
494{
495 struct l3_client *clnt = entry->private_data;
496 struct uda1341 *uda = clnt->driver_data;
497 int reg;
498 char buf[12];
499
500 for (reg = 0; reg < uda1341_reg_last; reg ++) {
501 if (reg == empty)
502 continue;
503 int2str_bin8(uda->regs[reg], buf);
504 snd_iprintf(buffer, "%s = %s\n", uda1341_reg_names[reg], buf);
505 }
506
507 int2str_bin8(snd_uda1341_codec_read(clnt, UDA1341_DATA1), buf);
508 snd_iprintf(buffer, "DATA1 = %s\n", buf);
509}
510#endif /* CONFIG_PROC_FS */
511
512static void __devinit snd_uda1341_proc_init(struct snd_card *card, struct l3_client *clnt)
513{
514 struct snd_info_entry *entry;
515
516 if (! snd_card_proc_new(card, "uda1341", &entry))
517 snd_info_set_text_ops(entry, clnt, snd_uda1341_proc_read);
518 if (! snd_card_proc_new(card, "uda1341-regs", &entry))
519 snd_info_set_text_ops(entry, clnt, snd_uda1341_proc_regs_read);
520}
521
522/* }}} */
523
524/* {{{ Mixer controls setting */
525
526/* {{{ UDA1341 single functions */
527
528#define UDA1341_SINGLE(xname, where, reg, shift, mask, invert) \
529{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_uda1341_info_single, \
530 .get = snd_uda1341_get_single, .put = snd_uda1341_put_single, \
531 .private_value = where | (reg << 5) | (shift << 9) | (mask << 12) | (invert << 18) \
532}
533
534static int snd_uda1341_info_single(struct snd_kcontrol *kcontrol,
535 struct snd_ctl_elem_info *uinfo)
536{
537 int mask = (kcontrol->private_value >> 12) & 63;
538
539 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
540 uinfo->count = 1;
541 uinfo->value.integer.min = 0;
542 uinfo->value.integer.max = mask;
543 return 0;
544}
545
546static int snd_uda1341_get_single(struct snd_kcontrol *kcontrol,
547 struct snd_ctl_elem_value *ucontrol)
548{
549 struct l3_client *clnt = snd_kcontrol_chip(kcontrol);
550 struct uda1341 *uda = clnt->driver_data;
551 int where = kcontrol->private_value & 31;
552 int mask = (kcontrol->private_value >> 12) & 63;
553 int invert = (kcontrol->private_value >> 18) & 1;
554
555 ucontrol->value.integer.value[0] = uda->cfg[where];
556 if (invert)
557 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
558
559 return 0;
560}
561
562static int snd_uda1341_put_single(struct snd_kcontrol *kcontrol,
563 struct snd_ctl_elem_value *ucontrol)
564{
565 struct l3_client *clnt = snd_kcontrol_chip(kcontrol);
566 struct uda1341 *uda = clnt->driver_data;
567 int where = kcontrol->private_value & 31;
568 int reg = (kcontrol->private_value >> 5) & 15;
569 int shift = (kcontrol->private_value >> 9) & 7;
570 int mask = (kcontrol->private_value >> 12) & 63;
571 int invert = (kcontrol->private_value >> 18) & 1;
572 unsigned short val;
573
574 val = (ucontrol->value.integer.value[0] & mask);
575 if (invert)
576 val = mask - val;
577
578 uda->cfg[where] = val;
579 return snd_uda1341_update_bits(clnt, reg, mask, shift, val, FLUSH);
580}
581
582/* }}} */
583
584/* {{{ UDA1341 enum functions */
585
586#define UDA1341_ENUM(xname, where, reg, shift, mask, invert) \
587{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_uda1341_info_enum, \
588 .get = snd_uda1341_get_enum, .put = snd_uda1341_put_enum, \
589 .private_value = where | (reg << 5) | (shift << 9) | (mask << 12) | (invert << 18) \
590}
591
592static int snd_uda1341_info_enum(struct snd_kcontrol *kcontrol,
593 struct snd_ctl_elem_info *uinfo)
594{
595 int where = kcontrol->private_value & 31;
596 const char **texts;
597
598 // this register we don't handle this way
599 if (!uda1341_enum_items[where])
600 return -EINVAL;
601
602 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
603 uinfo->count = 1;
604 uinfo->value.enumerated.items = uda1341_enum_items[where];
605
606 if (uinfo->value.enumerated.item >= uda1341_enum_items[where])
607 uinfo->value.enumerated.item = uda1341_enum_items[where] - 1;
608
609 texts = uda1341_enum_names[where];
610 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
611 return 0;
612}
613
614static int snd_uda1341_get_enum(struct snd_kcontrol *kcontrol,
615 struct snd_ctl_elem_value *ucontrol)
616{
617 struct l3_client *clnt = snd_kcontrol_chip(kcontrol);
618 struct uda1341 *uda = clnt->driver_data;
619 int where = kcontrol->private_value & 31;
620
621 ucontrol->value.enumerated.item[0] = uda->cfg[where];
622 return 0;
623}
624
625static int snd_uda1341_put_enum(struct snd_kcontrol *kcontrol,
626 struct snd_ctl_elem_value *ucontrol)
627{
628 struct l3_client *clnt = snd_kcontrol_chip(kcontrol);
629 struct uda1341 *uda = clnt->driver_data;
630 int where = kcontrol->private_value & 31;
631 int reg = (kcontrol->private_value >> 5) & 15;
632 int shift = (kcontrol->private_value >> 9) & 7;
633 int mask = (kcontrol->private_value >> 12) & 63;
634
635 uda->cfg[where] = (ucontrol->value.enumerated.item[0] & mask);
636
637 return snd_uda1341_update_bits(clnt, reg, mask, shift, uda->cfg[where], FLUSH);
638}
639
640/* }}} */
641
642/* {{{ UDA1341 2regs functions */
643
644#define UDA1341_2REGS(xname, where, reg_1, reg_2, shift_1, shift_2, mask_1, mask_2, invert) \
645{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), .info = snd_uda1341_info_2regs, \
646 .get = snd_uda1341_get_2regs, .put = snd_uda1341_put_2regs, \
647 .private_value = where | (reg_1 << 5) | (reg_2 << 9) | (shift_1 << 13) | (shift_2 << 16) | \
648 (mask_1 << 19) | (mask_2 << 25) | (invert << 31) \
649}
650
651
652static int snd_uda1341_info_2regs(struct snd_kcontrol *kcontrol,
653 struct snd_ctl_elem_info *uinfo)
654{
655 int mask_1 = (kcontrol->private_value >> 19) & 63;
656 int mask_2 = (kcontrol->private_value >> 25) & 63;
657 int mask;
658
659 mask = (mask_2 + 1) * (mask_1 + 1) - 1;
660 uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
661 uinfo->count = 1;
662 uinfo->value.integer.min = 0;
663 uinfo->value.integer.max = mask;
664 return 0;
665}
666
667static int snd_uda1341_get_2regs(struct snd_kcontrol *kcontrol,
668 struct snd_ctl_elem_value *ucontrol)
669{
670 struct l3_client *clnt = snd_kcontrol_chip(kcontrol);
671 struct uda1341 *uda = clnt->driver_data;
672 int where = kcontrol->private_value & 31;
673 int mask_1 = (kcontrol->private_value >> 19) & 63;
674 int mask_2 = (kcontrol->private_value >> 25) & 63;
675 int invert = (kcontrol->private_value >> 31) & 1;
676 int mask;
677
678 mask = (mask_2 + 1) * (mask_1 + 1) - 1;
679
680 ucontrol->value.integer.value[0] = uda->cfg[where];
681 if (invert)
682 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
683 return 0;
684}
685
686static int snd_uda1341_put_2regs(struct snd_kcontrol *kcontrol,
687 struct snd_ctl_elem_value *ucontrol)
688{
689 struct l3_client *clnt = snd_kcontrol_chip(kcontrol);
690 struct uda1341 *uda = clnt->driver_data;
691 int where = kcontrol->private_value & 31;
692 int reg_1 = (kcontrol->private_value >> 5) & 15;
693 int reg_2 = (kcontrol->private_value >> 9) & 15;
694 int shift_1 = (kcontrol->private_value >> 13) & 7;
695 int shift_2 = (kcontrol->private_value >> 16) & 7;
696 int mask_1 = (kcontrol->private_value >> 19) & 63;
697 int mask_2 = (kcontrol->private_value >> 25) & 63;
698 int invert = (kcontrol->private_value >> 31) & 1;
699 int mask;
700 unsigned short val1, val2, val;
701
702 val = ucontrol->value.integer.value[0];
703
704 mask = (mask_2 + 1) * (mask_1 + 1) - 1;
705
706 val1 = val & mask_1;
707 val2 = (val / (mask_1 + 1)) & mask_2;
708
709 if (invert) {
710 val1 = mask_1 - val1;
711 val2 = mask_2 - val2;
712 }
713
714 uda->cfg[where] = invert ? mask - val : val;
715
716 //FIXME - return value
717 snd_uda1341_update_bits(clnt, reg_1, mask_1, shift_1, val1, FLUSH);
718 return snd_uda1341_update_bits(clnt, reg_2, mask_2, shift_2, val2, FLUSH);
719}
720
721/* }}} */
722
723static struct snd_kcontrol_new snd_uda1341_controls[] = {
724 UDA1341_SINGLE("Master Playback Switch", CMD_MUTE, data0_2, 2, 1, 1),
725 UDA1341_SINGLE("Master Playback Volume", CMD_VOLUME, data0_0, 0, 63, 1),
726
727 UDA1341_SINGLE("Bass Playback Volume", CMD_BASS, data0_1, 2, 15, 0),
728 UDA1341_SINGLE("Treble Playback Volume", CMD_TREBBLE, data0_1, 0, 3, 0),
729
730 UDA1341_SINGLE("Input Gain Switch", CMD_IGAIN, stat1, 5, 1, 0),
731 UDA1341_SINGLE("Output Gain Switch", CMD_OGAIN, stat1, 6, 1, 0),
732
733 UDA1341_SINGLE("Mixer Gain Channel 1 Volume", CMD_CH1, ext0, 0, 31, 1),
734 UDA1341_SINGLE("Mixer Gain Channel 2 Volume", CMD_CH2, ext1, 0, 31, 1),
735
736 UDA1341_SINGLE("Mic Sensitivity Volume", CMD_MIC, ext2, 2, 7, 0),
737
738 UDA1341_SINGLE("AGC Output Level", CMD_AGC_LEVEL, ext6, 0, 3, 0),
739 UDA1341_SINGLE("AGC Time Constant", CMD_AGC_TIME, ext6, 2, 7, 0),
740 UDA1341_SINGLE("AGC Time Constant Switch", CMD_AGC, ext4, 4, 1, 0),
741
742 UDA1341_SINGLE("DAC Power", CMD_DAC, stat1, 0, 1, 0),
743 UDA1341_SINGLE("ADC Power", CMD_ADC, stat1, 1, 1, 0),
744
745 UDA1341_ENUM("Peak detection", CMD_PEAK, data0_2, 5, 1, 0),
746 UDA1341_ENUM("De-emphasis", CMD_DEEMP, data0_2, 3, 3, 0),
747 UDA1341_ENUM("Mixer mode", CMD_MIXER, ext2, 0, 3, 0),
748 UDA1341_ENUM("Filter mode", CMD_FILTER, data0_2, 0, 3, 0),
749
750 UDA1341_2REGS("Gain Input Amplifier Gain (channel 2)", CMD_IG, ext4, ext5, 0, 0, 3, 31, 0),
751};
752
753static void uda1341_free(struct l3_client *clnt)
754{
755 l3_detach_client(clnt); // calls kfree for driver_data (struct uda1341)
756 kfree(clnt);
757}
758
759static int uda1341_dev_free(struct snd_device *device)
760{
761 struct l3_client *clnt = device->device_data;
762 uda1341_free(clnt);
763 return 0;
764}
765
766int __init snd_chip_uda1341_mixer_new(struct snd_card *card, struct l3_client **clntp)
767{
768 static struct snd_device_ops ops = {
769 .dev_free = uda1341_dev_free,
770 };
771 struct l3_client *clnt;
772 int idx, err;
773
774 if (snd_BUG_ON(!card))
775 return -EINVAL;
776
777 clnt = kzalloc(sizeof(*clnt), GFP_KERNEL);
778 if (clnt == NULL)
779 return -ENOMEM;
780
781 if ((err = l3_attach_client(clnt, "l3-bit-sa1100-gpio", UDA1341_ALSA_NAME))) {
782 kfree(clnt);
783 return err;
784 }
785
786 for (idx = 0; idx < ARRAY_SIZE(snd_uda1341_controls); idx++) {
787 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_uda1341_controls[idx], clnt))) < 0) {
788 uda1341_free(clnt);
789 return err;
790 }
791 }
792
793 if ((err = snd_device_new(card, SNDRV_DEV_CODEC, clnt, &ops)) < 0) {
794 uda1341_free(clnt);
795 return err;
796 }
797
798 *clntp = clnt;
799 strcpy(card->mixername, "UDA1341TS Mixer");
800 ((struct uda1341 *)clnt->driver_data)->card = card;
801
802 snd_uda1341_proc_init(card, clnt);
803
804 return 0;
805}
806
807/* }}} */
808
809/* {{{ L3 operations */
810
811static int uda1341_attach(struct l3_client *clnt)
812{
813 struct uda1341 *uda;
814
815 uda = kzalloc(sizeof(*uda), 0, GFP_KERNEL);
816 if (!uda)
817 return -ENOMEM;
818
819 /* init fixed parts of my copy of registers */
820 uda->regs[stat0] = STAT0;
821 uda->regs[stat1] = STAT1;
822
823 uda->regs[data0_0] = DATA0_0;
824 uda->regs[data0_1] = DATA0_1;
825 uda->regs[data0_2] = DATA0_2;
826
827 uda->write = snd_uda1341_codec_write;
828 uda->read = snd_uda1341_codec_read;
829
830 spin_lock_init(&uda->reg_lock);
831
832 clnt->driver_data = uda;
833 return 0;
834}
835
836static void uda1341_detach(struct l3_client *clnt)
837{
838 kfree(clnt->driver_data);
839}
840
841static int
842uda1341_command(struct l3_client *clnt, int cmd, void *arg)
843{
844 if (cmd != CMD_READ_REG)
845 return snd_uda1341_cfg_write(clnt, cmd, (int) arg, FLUSH);
846
847 return snd_uda1341_codec_read(clnt, (int) arg);
848}
849
850static int uda1341_open(struct l3_client *clnt)
851{
852 struct uda1341 *uda = clnt->driver_data;
853
854 uda->active = 1;
855
856 /* init default configuration */
857 snd_uda1341_cfg_write(clnt, CMD_RESET, 0, REGS_ONLY);
858 snd_uda1341_cfg_write(clnt, CMD_FS, F256, FLUSH); // unknown state after reset
859 snd_uda1341_cfg_write(clnt, CMD_FORMAT, LSB16, FLUSH); // unknown state after reset
860 snd_uda1341_cfg_write(clnt, CMD_OGAIN, ON, FLUSH); // default off after reset
861 snd_uda1341_cfg_write(clnt, CMD_IGAIN, ON, FLUSH); // default off after reset
862 snd_uda1341_cfg_write(clnt, CMD_DAC, ON, FLUSH); // ??? default value after reset
863 snd_uda1341_cfg_write(clnt, CMD_ADC, ON, FLUSH); // ??? default value after reset
864 snd_uda1341_cfg_write(clnt, CMD_VOLUME, 20, FLUSH); // default 0dB after reset
865 snd_uda1341_cfg_write(clnt, CMD_BASS, 0, REGS_ONLY); // default value after reset
866 snd_uda1341_cfg_write(clnt, CMD_TREBBLE, 0, REGS_ONLY); // default value after reset
867 snd_uda1341_cfg_write(clnt, CMD_PEAK, AFTER, REGS_ONLY);// default value after reset
868 snd_uda1341_cfg_write(clnt, CMD_DEEMP, NONE, REGS_ONLY);// default value after reset
869 //at this moment should be QMUTED by h3600_audio_init
870 snd_uda1341_cfg_write(clnt, CMD_MUTE, OFF, REGS_ONLY); // default value after reset
871 snd_uda1341_cfg_write(clnt, CMD_FILTER, MAX, FLUSH); // defaul flat after reset
872 snd_uda1341_cfg_write(clnt, CMD_CH1, 31, FLUSH); // default value after reset
873 snd_uda1341_cfg_write(clnt, CMD_CH2, 4, FLUSH); // default value after reset
874 snd_uda1341_cfg_write(clnt, CMD_MIC, 4, FLUSH); // default 0dB after reset
875 snd_uda1341_cfg_write(clnt, CMD_MIXER, MIXER, FLUSH); // default doub.dif.mode
876 snd_uda1341_cfg_write(clnt, CMD_AGC, OFF, FLUSH); // default value after reset
877 snd_uda1341_cfg_write(clnt, CMD_IG, 0, FLUSH); // unknown state after reset
878 snd_uda1341_cfg_write(clnt, CMD_AGC_TIME, 0, FLUSH); // default value after reset
879 snd_uda1341_cfg_write(clnt, CMD_AGC_LEVEL, 0, FLUSH); // default value after reset
880
881 return 0;
882}
883
884static void uda1341_close(struct l3_client *clnt)
885{
886 struct uda1341 *uda = clnt->driver_data;
887
888 uda->active = 0;
889}
890
891/* }}} */
892
893/* {{{ Module and L3 initialization */
894
895static struct l3_ops uda1341_ops = {
896 .open = uda1341_open,
897 .command = uda1341_command,
898 .close = uda1341_close,
899};
900
901static struct l3_driver uda1341_driver = {
902 .name = UDA1341_ALSA_NAME,
903 .attach_client = uda1341_attach,
904 .detach_client = uda1341_detach,
905 .ops = &uda1341_ops,
906 .owner = THIS_MODULE,
907};
908
909static int __init uda1341_init(void)
910{
911 return l3_add_driver(&uda1341_driver);
912}
913
914static void __exit uda1341_exit(void)
915{
916 l3_del_driver(&uda1341_driver);
917}
918
919module_init(uda1341_init);
920module_exit(uda1341_exit);
921
922MODULE_AUTHOR("Tomas Kasparek <tomas.kasparek@seznam.cz>");
923MODULE_LICENSE("GPL");
924MODULE_DESCRIPTION("Philips UDA1341 CODEC driver for ALSA");
925MODULE_SUPPORTED_DEVICE("{{UDA1341,UDA1341TS}}");
926
927EXPORT_SYMBOL(snd_chip_uda1341_mixer_new);
928
929/* }}} */
930
931/*
932 * Local variables:
933 * indent-tabs-mode: t
934 * End:
935 */
diff --git a/sound/isa/Kconfig b/sound/isa/Kconfig
index ce0aa044e274..c5c9a9218ff6 100644
--- a/sound/isa/Kconfig
+++ b/sound/isa/Kconfig
@@ -56,8 +56,8 @@ config SND_AD1848
56 Say Y here to include support for AD1848 (Analog Devices) or 56 Say Y here to include support for AD1848 (Analog Devices) or
57 CS4248 (Cirrus Logic - Crystal Semiconductors) chips. 57 CS4248 (Cirrus Logic - Crystal Semiconductors) chips.
58 58
59 For newer chips from Cirrus Logic, use the CS4231, CS4232 or 59 For newer chips from Cirrus Logic, use the CS4231 or CS4232+
60 CS4236+ drivers. 60 drivers.
61 61
62 To compile this driver as a module, choose M here: the module 62 To compile this driver as a module, choose M here: the module
63 will be called snd-ad1848. 63 will be called snd-ad1848.
@@ -94,6 +94,8 @@ config SND_CMI8330
94 tristate "C-Media CMI8330" 94 tristate "C-Media CMI8330"
95 select SND_WSS_LIB 95 select SND_WSS_LIB
96 select SND_SB16_DSP 96 select SND_SB16_DSP
97 select SND_OPL3_LIB
98 select SND_MPU401_UART
97 help 99 help
98 Say Y here to include support for soundcards based on the 100 Say Y here to include support for soundcards based on the
99 C-Media CMI8330 chip. 101 C-Media CMI8330 chip.
@@ -112,26 +114,15 @@ config SND_CS4231
112 To compile this driver as a module, choose M here: the module 114 To compile this driver as a module, choose M here: the module
113 will be called snd-cs4231. 115 will be called snd-cs4231.
114 116
115config SND_CS4232
116 tristate "Generic Cirrus Logic CS4232 driver"
117 select SND_OPL3_LIB
118 select SND_MPU401_UART
119 select SND_WSS_LIB
120 help
121 Say Y here to include support for CS4232 chips from Cirrus
122 Logic - Crystal Semiconductors.
123
124 To compile this driver as a module, choose M here: the module
125 will be called snd-cs4232.
126
127config SND_CS4236 117config SND_CS4236
128 tristate "Generic Cirrus Logic CS4236+ driver" 118 tristate "Generic Cirrus Logic CS4232/CS4236+ driver"
129 select SND_OPL3_LIB 119 select SND_OPL3_LIB
130 select SND_MPU401_UART 120 select SND_MPU401_UART
131 select SND_WSS_LIB 121 select SND_WSS_LIB
132 help 122 help
133 Say Y to include support for CS4235,CS4236,CS4237B,CS4238B, 123 Say Y to include support for CS4232,CS4235,CS4236,CS4237B,
134 CS4239 chips from Cirrus Logic - Crystal Semiconductors. 124 CS4238B,CS4239 chips from Cirrus Logic - Crystal
125 Semiconductors.
135 126
136 To compile this driver as a module, choose M here: the module 127 To compile this driver as a module, choose M here: the module
137 will be called snd-cs4236. 128 will be called snd-cs4236.
@@ -377,14 +368,17 @@ config SND_SGALAXY
377 will be called snd-sgalaxy. 368 will be called snd-sgalaxy.
378 369
379config SND_SSCAPE 370config SND_SSCAPE
380 tristate "Ensoniq SoundScape PnP driver" 371 tristate "Ensoniq SoundScape driver"
381 select SND_HWDEP 372 select SND_HWDEP
382 select SND_MPU401_UART 373 select SND_MPU401_UART
383 select SND_WSS_LIB 374 select SND_WSS_LIB
384 help 375 help
385 Say Y here to include support for Ensoniq SoundScape PnP 376 Say Y here to include support for Ensoniq SoundScape
386 soundcards. 377 soundcards.
387 378
379 The PCM audio is supported on SoundScape Classic, Elite, PnP
380 and VIVO cards. The MIDI support is very experimental.
381
388 To compile this driver as a module, choose M here: the module 382 To compile this driver as a module, choose M here: the module
389 will be called snd-sscape. 383 will be called snd-sscape.
390 384
@@ -411,5 +405,36 @@ config SND_WAVEFRONT_FIRMWARE_IN_KERNEL
411 you need to install the firmware files from the 405 you need to install the firmware files from the
412 alsa-firmware package. 406 alsa-firmware package.
413 407
408config SND_MSND_PINNACLE
409 tristate "Turtle Beach MultiSound Pinnacle/Fiji driver"
410 depends on X86 && EXPERIMENTAL
411 select FW_LOADER
412 select SND_MPU401_UART
413 select SND_PCM
414 help
415 Say Y to include support for Turtle Beach MultiSound Pinnacle/
416 Fiji soundcards.
417
418 To compile this driver as a module, choose M here: the module
419 will be called snd-msnd-pinnacle.
420
421config SND_MSND_CLASSIC
422 tristate "Support for Turtle Beach MultiSound Classic, Tahiti, Monterey"
423 depends on X86 && EXPERIMENTAL
424 select FW_LOADER
425 select SND_MPU401_UART
426 select SND_PCM
427 help
428 Say M here if you have a Turtle Beach MultiSound Classic, Tahiti or
429 Monterey (not for the Pinnacle or Fiji).
430
431 See <file:Documentation/sound/oss/MultiSound> for important information
432 about this driver. Note that it has been discontinued, but the
433 Voyetra Turtle Beach knowledge base entry for it is still available
434 at <http://www.turtlebeach.com/site/kb_ftp/790.asp>.
435
436 To compile this driver as a module, choose M here: the module
437 will be called snd-msnd-classic.
438
414endif # SND_ISA 439endif # SND_ISA
415 440
diff --git a/sound/isa/Makefile b/sound/isa/Makefile
index 63af13d901a5..b906b9a1a81e 100644
--- a/sound/isa/Makefile
+++ b/sound/isa/Makefile
@@ -26,5 +26,5 @@ obj-$(CONFIG_SND_SC6000) += snd-sc6000.o
26obj-$(CONFIG_SND_SGALAXY) += snd-sgalaxy.o 26obj-$(CONFIG_SND_SGALAXY) += snd-sgalaxy.o
27obj-$(CONFIG_SND_SSCAPE) += snd-sscape.o 27obj-$(CONFIG_SND_SSCAPE) += snd-sscape.o
28 28
29obj-$(CONFIG_SND) += ad1816a/ ad1848/ cs423x/ es1688/ gus/ opti9xx/ \ 29obj-$(CONFIG_SND) += ad1816a/ ad1848/ cs423x/ es1688/ gus/ msnd/ opti9xx/ \
30 sb/ wavefront/ wss/ 30 sb/ wavefront/ wss/
diff --git a/sound/isa/ad1816a/ad1816a.c b/sound/isa/ad1816a/ad1816a.c
index 77524244a846..bbcbf92a8ebe 100644
--- a/sound/isa/ad1816a/ad1816a.c
+++ b/sound/isa/ad1816a/ad1816a.c
@@ -156,10 +156,12 @@ static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard
156 struct snd_card_ad1816a *acard; 156 struct snd_card_ad1816a *acard;
157 struct snd_ad1816a *chip; 157 struct snd_ad1816a *chip;
158 struct snd_opl3 *opl3; 158 struct snd_opl3 *opl3;
159 struct snd_timer *timer;
159 160
160 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE, 161 error = snd_card_create(index[dev], id[dev], THIS_MODULE,
161 sizeof(struct snd_card_ad1816a))) == NULL) 162 sizeof(struct snd_card_ad1816a), &card);
162 return -ENOMEM; 163 if (error < 0)
164 return error;
163 acard = (struct snd_card_ad1816a *)card->private_data; 165 acard = (struct snd_card_ad1816a *)card->private_data;
164 166
165 if ((error = snd_card_ad1816a_pnp(dev, acard, pcard, pid))) { 167 if ((error = snd_card_ad1816a_pnp(dev, acard, pcard, pid))) {
@@ -194,6 +196,12 @@ static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard
194 return error; 196 return error;
195 } 197 }
196 198
199 error = snd_ad1816a_timer(chip, 0, &timer);
200 if (error < 0) {
201 snd_card_free(card);
202 return error;
203 }
204
197 if (mpu_port[dev] > 0) { 205 if (mpu_port[dev] > 0) {
198 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 206 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
199 mpu_port[dev], 0, mpu_irq[dev], IRQF_DISABLED, 207 mpu_port[dev], 0, mpu_irq[dev], IRQF_DISABLED,
@@ -207,11 +215,8 @@ static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard
207 OPL3_HW_AUTO, 0, &opl3) < 0) { 215 OPL3_HW_AUTO, 0, &opl3) < 0) {
208 printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx.\n", fm_port[dev], fm_port[dev] + 2); 216 printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx.\n", fm_port[dev], fm_port[dev] + 2);
209 } else { 217 } else {
210 if ((error = snd_opl3_timer_new(opl3, 1, 2)) < 0) { 218 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
211 snd_card_free(card); 219 if (error < 0) {
212 return error;
213 }
214 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
215 snd_card_free(card); 220 snd_card_free(card);
216 return error; 221 return error;
217 } 222 }
diff --git a/sound/isa/ad1816a/ad1816a_lib.c b/sound/isa/ad1816a/ad1816a_lib.c
index 3bfca7c59baf..05aef8b97e96 100644
--- a/sound/isa/ad1816a/ad1816a_lib.c
+++ b/sound/isa/ad1816a/ad1816a_lib.c
@@ -37,7 +37,7 @@ static inline int snd_ad1816a_busy_wait(struct snd_ad1816a *chip)
37 if (inb(AD1816A_REG(AD1816A_CHIP_STATUS)) & AD1816A_READY) 37 if (inb(AD1816A_REG(AD1816A_CHIP_STATUS)) & AD1816A_READY)
38 return 0; 38 return 0;
39 39
40 snd_printk("chip busy.\n"); 40 snd_printk(KERN_WARNING "chip busy.\n");
41 return -EBUSY; 41 return -EBUSY;
42} 42}
43 43
@@ -196,7 +196,7 @@ static int snd_ad1816a_trigger(struct snd_ad1816a *chip, unsigned char what,
196 spin_unlock(&chip->lock); 196 spin_unlock(&chip->lock);
197 break; 197 break;
198 default: 198 default:
199 snd_printk("invalid trigger mode 0x%x.\n", what); 199 snd_printk(KERN_WARNING "invalid trigger mode 0x%x.\n", what);
200 error = -EINVAL; 200 error = -EINVAL;
201 } 201 }
202 202
@@ -377,7 +377,6 @@ static struct snd_pcm_hardware snd_ad1816a_capture = {
377 .fifo_size = 0, 377 .fifo_size = 0,
378}; 378};
379 379
380#if 0 /* not used now */
381static int snd_ad1816a_timer_close(struct snd_timer *timer) 380static int snd_ad1816a_timer_close(struct snd_timer *timer)
382{ 381{
383 struct snd_ad1816a *chip = snd_timer_chip(timer); 382 struct snd_ad1816a *chip = snd_timer_chip(timer);
@@ -442,8 +441,6 @@ static struct snd_timer_hardware snd_ad1816a_timer_table = {
442 .start = snd_ad1816a_timer_start, 441 .start = snd_ad1816a_timer_start,
443 .stop = snd_ad1816a_timer_stop, 442 .stop = snd_ad1816a_timer_stop,
444}; 443};
445#endif /* not used now */
446
447 444
448static int snd_ad1816a_playback_open(struct snd_pcm_substream *substream) 445static int snd_ad1816a_playback_open(struct snd_pcm_substream *substream)
449{ 446{
@@ -568,7 +565,7 @@ static const char __devinit *snd_ad1816a_chip_id(struct snd_ad1816a *chip)
568 case AD1816A_HW_AD1815: return "AD1815"; 565 case AD1816A_HW_AD1815: return "AD1815";
569 case AD1816A_HW_AD18MAX10: return "AD18max10"; 566 case AD1816A_HW_AD18MAX10: return "AD18max10";
570 default: 567 default:
571 snd_printk("Unknown chip version %d:%d.\n", 568 snd_printk(KERN_WARNING "Unknown chip version %d:%d.\n",
572 chip->version, chip->hardware); 569 chip->version, chip->hardware);
573 return "AD1816A - unknown"; 570 return "AD1816A - unknown";
574 } 571 }
@@ -687,7 +684,6 @@ int __devinit snd_ad1816a_pcm(struct snd_ad1816a *chip, int device, struct snd_p
687 return 0; 684 return 0;
688} 685}
689 686
690#if 0 /* not used now */
691int __devinit snd_ad1816a_timer(struct snd_ad1816a *chip, int device, struct snd_timer **rtimer) 687int __devinit snd_ad1816a_timer(struct snd_ad1816a *chip, int device, struct snd_timer **rtimer)
692{ 688{
693 struct snd_timer *timer; 689 struct snd_timer *timer;
@@ -709,7 +705,6 @@ int __devinit snd_ad1816a_timer(struct snd_ad1816a *chip, int device, struct snd
709 *rtimer = timer; 705 *rtimer = timer;
710 return 0; 706 return 0;
711} 707}
712#endif /* not used now */
713 708
714/* 709/*
715 * 710 *
diff --git a/sound/isa/ad1848/ad1848.c b/sound/isa/ad1848/ad1848.c
index 223a6c038819..4beeb6f98e0e 100644
--- a/sound/isa/ad1848/ad1848.c
+++ b/sound/isa/ad1848/ad1848.c
@@ -91,9 +91,9 @@ static int __devinit snd_ad1848_probe(struct device *dev, unsigned int n)
91 struct snd_pcm *pcm; 91 struct snd_pcm *pcm;
92 int error; 92 int error;
93 93
94 card = snd_card_new(index[n], id[n], THIS_MODULE, 0); 94 error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card);
95 if (!card) 95 if (error < 0)
96 return -EINVAL; 96 return error;
97 97
98 error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], -1, 98 error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], -1,
99 thinkpad[n] ? WSS_HW_THINKPAD : WSS_HW_DETECT, 99 thinkpad[n] ? WSS_HW_THINKPAD : WSS_HW_DETECT,
diff --git a/sound/isa/adlib.c b/sound/isa/adlib.c
index 374b7177e111..7465ae036e0b 100644
--- a/sound/isa/adlib.c
+++ b/sound/isa/adlib.c
@@ -53,10 +53,10 @@ static int __devinit snd_adlib_probe(struct device *dev, unsigned int n)
53 struct snd_opl3 *opl3; 53 struct snd_opl3 *opl3;
54 int error; 54 int error;
55 55
56 card = snd_card_new(index[n], id[n], THIS_MODULE, 0); 56 error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card);
57 if (!card) { 57 if (error < 0) {
58 dev_err(dev, "could not create card\n"); 58 dev_err(dev, "could not create card\n");
59 return -EINVAL; 59 return error;
60 } 60 }
61 61
62 card->private_data = request_region(port[n], 4, CRD_NAME); 62 card->private_data = request_region(port[n], 4, CRD_NAME);
diff --git a/sound/isa/als100.c b/sound/isa/als100.c
index f1ce30f379c9..5fd52e4d7079 100644
--- a/sound/isa/als100.c
+++ b/sound/isa/als100.c
@@ -163,9 +163,10 @@ static int __devinit snd_card_als100_probe(int dev,
163 struct snd_card_als100 *acard; 163 struct snd_card_als100 *acard;
164 struct snd_opl3 *opl3; 164 struct snd_opl3 *opl3;
165 165
166 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE, 166 error = snd_card_create(index[dev], id[dev], THIS_MODULE,
167 sizeof(struct snd_card_als100))) == NULL) 167 sizeof(struct snd_card_als100), &card);
168 return -ENOMEM; 168 if (error < 0)
169 return error;
169 acard = card->private_data; 170 acard = card->private_data;
170 171
171 if ((error = snd_card_als100_pnp(dev, acard, pcard, pid))) { 172 if ((error = snd_card_als100_pnp(dev, acard, pcard, pid))) {
diff --git a/sound/isa/azt2320.c b/sound/isa/azt2320.c
index 3e74d1a3928e..f7aa637b0d18 100644
--- a/sound/isa/azt2320.c
+++ b/sound/isa/azt2320.c
@@ -184,9 +184,10 @@ static int __devinit snd_card_azt2320_probe(int dev,
184 struct snd_wss *chip; 184 struct snd_wss *chip;
185 struct snd_opl3 *opl3; 185 struct snd_opl3 *opl3;
186 186
187 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE, 187 error = snd_card_create(index[dev], id[dev], THIS_MODULE,
188 sizeof(struct snd_card_azt2320))) == NULL) 188 sizeof(struct snd_card_azt2320), &card);
189 return -ENOMEM; 189 if (error < 0)
190 return error;
190 acard = (struct snd_card_azt2320 *)card->private_data; 191 acard = (struct snd_card_azt2320 *)card->private_data;
191 192
192 if ((error = snd_card_azt2320_pnp(dev, acard, pcard, pid))) { 193 if ((error = snd_card_azt2320_pnp(dev, acard, pcard, pid))) {
diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
index e49aec700a55..de83608719ea 100644
--- a/sound/isa/cmi8330.c
+++ b/sound/isa/cmi8330.c
@@ -31,11 +31,11 @@
31 * To quickly load the module, 31 * To quickly load the module,
32 * 32 *
33 * modprobe -a snd-cmi8330 sbport=0x220 sbirq=5 sbdma8=1 33 * modprobe -a snd-cmi8330 sbport=0x220 sbirq=5 sbdma8=1
34 * sbdma16=5 wssport=0x530 wssirq=11 wssdma=0 34 * sbdma16=5 wssport=0x530 wssirq=11 wssdma=0 fmport=0x388
35 * 35 *
36 * This card has two mixers and two PCM devices. I've cheesed it such 36 * This card has two mixers and two PCM devices. I've cheesed it such
37 * that recording and playback can be done through the same device. 37 * that recording and playback can be done through the same device.
38 * The driver "magically" routes the capturing to the AD1848 codec, 38 * The driver "magically" routes the capturing to the CMI8330 codec,
39 * and playback to the SB16 codec. This allows for full-duplex mode 39 * and playback to the SB16 codec. This allows for full-duplex mode
40 * to some extent. 40 * to some extent.
41 * The utilities in alsa-utils are aware of both devices, so passing 41 * The utilities in alsa-utils are aware of both devices, so passing
@@ -51,6 +51,8 @@
51#include <linux/moduleparam.h> 51#include <linux/moduleparam.h>
52#include <sound/core.h> 52#include <sound/core.h>
53#include <sound/wss.h> 53#include <sound/wss.h>
54#include <sound/opl3.h>
55#include <sound/mpu401.h>
54#include <sound/sb.h> 56#include <sound/sb.h>
55#include <sound/initval.h> 57#include <sound/initval.h>
56 58
@@ -79,6 +81,9 @@ static int sbdma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
79static long wssport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; 81static long wssport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
80static int wssirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; 82static int wssirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
81static int wssdma[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; 83static int wssdma[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
84static long fmport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
85static long mpuport[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
86static int mpuirq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
82 87
83module_param_array(index, int, NULL, 0444); 88module_param_array(index, int, NULL, 0444);
84MODULE_PARM_DESC(index, "Index value for CMI8330 soundcard."); 89MODULE_PARM_DESC(index, "Index value for CMI8330 soundcard.");
@@ -107,6 +112,12 @@ MODULE_PARM_DESC(wssirq, "IRQ # for CMI8330 WSS driver.");
107module_param_array(wssdma, int, NULL, 0444); 112module_param_array(wssdma, int, NULL, 0444);
108MODULE_PARM_DESC(wssdma, "DMA for CMI8330 WSS driver."); 113MODULE_PARM_DESC(wssdma, "DMA for CMI8330 WSS driver.");
109 114
115module_param_array(fmport, long, NULL, 0444);
116MODULE_PARM_DESC(fmport, "FM port # for CMI8330 driver.");
117module_param_array(mpuport, long, NULL, 0444);
118MODULE_PARM_DESC(mpuport, "MPU-401 port # for CMI8330 driver.");
119module_param_array(mpuirq, int, NULL, 0444);
120MODULE_PARM_DESC(mpuirq, "IRQ # for CMI8330 MPU-401 port.");
110#ifdef CONFIG_PNP 121#ifdef CONFIG_PNP
111static int isa_registered; 122static int isa_registered;
112static int pnp_registered; 123static int pnp_registered;
@@ -149,6 +160,7 @@ struct snd_cmi8330 {
149#ifdef CONFIG_PNP 160#ifdef CONFIG_PNP
150 struct pnp_dev *cap; 161 struct pnp_dev *cap;
151 struct pnp_dev *play; 162 struct pnp_dev *play;
163 struct pnp_dev *mpu;
152#endif 164#endif
153 struct snd_card *card; 165 struct snd_card *card;
154 struct snd_wss *wss; 166 struct snd_wss *wss;
@@ -165,7 +177,7 @@ struct snd_cmi8330 {
165#ifdef CONFIG_PNP 177#ifdef CONFIG_PNP
166 178
167static struct pnp_card_device_id snd_cmi8330_pnpids[] = { 179static struct pnp_card_device_id snd_cmi8330_pnpids[] = {
168 { .id = "CMI0001", .devs = { { "@@@0001" }, { "@X@0001" } } }, 180 { .id = "CMI0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" } } },
169 { .id = "" } 181 { .id = "" }
170}; 182};
171 183
@@ -219,8 +231,10 @@ WSS_SINGLE("3D Control - Switch", 0,
219 CMI8330_RMUX3D, 5, 1, 1), 231 CMI8330_RMUX3D, 5, 1, 1),
220WSS_SINGLE("PC Speaker Playback Volume", 0, 232WSS_SINGLE("PC Speaker Playback Volume", 0,
221 CMI8330_OUTPUTVOL, 3, 3, 0), 233 CMI8330_OUTPUTVOL, 3, 3, 0),
222WSS_SINGLE("FM Playback Switch", 0, 234WSS_DOUBLE("FM Playback Switch", 0,
223 CMI8330_RECMUX, 3, 1, 1), 235 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
236WSS_DOUBLE("FM Playback Volume", 0,
237 CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
224WSS_SINGLE(SNDRV_CTL_NAME_IEC958("Input ", CAPTURE, SWITCH), 0, 238WSS_SINGLE(SNDRV_CTL_NAME_IEC958("Input ", CAPTURE, SWITCH), 0,
225 CMI8330_RMUX3D, 7, 1, 1), 239 CMI8330_RMUX3D, 7, 1, 1),
226WSS_SINGLE(SNDRV_CTL_NAME_IEC958("Input ", PLAYBACK, SWITCH), 0, 240WSS_SINGLE(SNDRV_CTL_NAME_IEC958("Input ", PLAYBACK, SWITCH), 0,
@@ -323,16 +337,21 @@ static int __devinit snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard,
323 if (acard->play == NULL) 337 if (acard->play == NULL)
324 return -EBUSY; 338 return -EBUSY;
325 339
340 acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
341 if (acard->play == NULL)
342 return -EBUSY;
343
326 pdev = acard->cap; 344 pdev = acard->cap;
327 345
328 err = pnp_activate_dev(pdev); 346 err = pnp_activate_dev(pdev);
329 if (err < 0) { 347 if (err < 0) {
330 snd_printk(KERN_ERR "CMI8330/C3D (AD1848) PnP configure failure\n"); 348 snd_printk(KERN_ERR "CMI8330/C3D PnP configure failure\n");
331 return -EBUSY; 349 return -EBUSY;
332 } 350 }
333 wssport[dev] = pnp_port_start(pdev, 0); 351 wssport[dev] = pnp_port_start(pdev, 0);
334 wssdma[dev] = pnp_dma(pdev, 0); 352 wssdma[dev] = pnp_dma(pdev, 0);
335 wssirq[dev] = pnp_irq(pdev, 0); 353 wssirq[dev] = pnp_irq(pdev, 0);
354 fmport[dev] = pnp_port_start(pdev, 1);
336 355
337 /* allocate SB16 resources */ 356 /* allocate SB16 resources */
338 pdev = acard->play; 357 pdev = acard->play;
@@ -347,6 +366,17 @@ static int __devinit snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard,
347 sbdma16[dev] = pnp_dma(pdev, 1); 366 sbdma16[dev] = pnp_dma(pdev, 1);
348 sbirq[dev] = pnp_irq(pdev, 0); 367 sbirq[dev] = pnp_irq(pdev, 0);
349 368
369 /* allocate MPU-401 resources */
370 pdev = acard->mpu;
371
372 err = pnp_activate_dev(pdev);
373 if (err < 0) {
374 snd_printk(KERN_ERR
375 "CMI8330/C3D (MPU-401) PnP configure failure\n");
376 return -EBUSY;
377 }
378 mpuport[dev] = pnp_port_start(pdev, 0);
379 mpuirq[dev] = pnp_irq(pdev, 0);
350 return 0; 380 return 0;
351} 381}
352#endif 382#endif
@@ -467,26 +497,29 @@ static int snd_cmi8330_resume(struct snd_card *card)
467 497
468#define PFX "cmi8330: " 498#define PFX "cmi8330: "
469 499
470static struct snd_card *snd_cmi8330_card_new(int dev) 500static int snd_cmi8330_card_new(int dev, struct snd_card **cardp)
471{ 501{
472 struct snd_card *card; 502 struct snd_card *card;
473 struct snd_cmi8330 *acard; 503 struct snd_cmi8330 *acard;
504 int err;
474 505
475 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 506 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
476 sizeof(struct snd_cmi8330)); 507 sizeof(struct snd_cmi8330), &card);
477 if (card == NULL) { 508 if (err < 0) {
478 snd_printk(KERN_ERR PFX "could not get a new card\n"); 509 snd_printk(KERN_ERR PFX "could not get a new card\n");
479 return NULL; 510 return err;
480 } 511 }
481 acard = card->private_data; 512 acard = card->private_data;
482 acard->card = card; 513 acard->card = card;
483 return card; 514 *cardp = card;
515 return 0;
484} 516}
485 517
486static int __devinit snd_cmi8330_probe(struct snd_card *card, int dev) 518static int __devinit snd_cmi8330_probe(struct snd_card *card, int dev)
487{ 519{
488 struct snd_cmi8330 *acard; 520 struct snd_cmi8330 *acard;
489 int i, err; 521 int i, err;
522 struct snd_opl3 *opl3;
490 523
491 acard = card->private_data; 524 acard = card->private_data;
492 err = snd_wss_create(card, wssport[dev] + 4, -1, 525 err = snd_wss_create(card, wssport[dev] + 4, -1,
@@ -494,11 +527,11 @@ static int __devinit snd_cmi8330_probe(struct snd_card *card, int dev)
494 wssdma[dev], -1, 527 wssdma[dev], -1,
495 WSS_HW_DETECT, 0, &acard->wss); 528 WSS_HW_DETECT, 0, &acard->wss);
496 if (err < 0) { 529 if (err < 0) {
497 snd_printk(KERN_ERR PFX "(AD1848) device busy??\n"); 530 snd_printk(KERN_ERR PFX "(CMI8330) device busy??\n");
498 return err; 531 return err;
499 } 532 }
500 if (acard->wss->hardware != WSS_HW_CMI8330) { 533 if (acard->wss->hardware != WSS_HW_CMI8330) {
501 snd_printk(KERN_ERR PFX "(AD1848) not found during probe\n"); 534 snd_printk(KERN_ERR PFX "(CMI8330) not found during probe\n");
502 return -ENODEV; 535 return -ENODEV;
503 } 536 }
504 537
@@ -530,6 +563,27 @@ static int __devinit snd_cmi8330_probe(struct snd_card *card, int dev)
530 snd_printk(KERN_ERR PFX "failed to create pcms\n"); 563 snd_printk(KERN_ERR PFX "failed to create pcms\n");
531 return err; 564 return err;
532 } 565 }
566 if (fmport[dev] != SNDRV_AUTO_PORT) {
567 if (snd_opl3_create(card,
568 fmport[dev], fmport[dev] + 2,
569 OPL3_HW_AUTO, 0, &opl3) < 0) {
570 snd_printk(KERN_ERR PFX
571 "no OPL device at 0x%lx-0x%lx ?\n",
572 fmport[dev], fmport[dev] + 2);
573 } else {
574 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
575 if (err < 0)
576 return err;
577 }
578 }
579
580 if (mpuport[dev] != SNDRV_AUTO_PORT) {
581 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
582 mpuport[dev], 0, mpuirq[dev],
583 IRQF_DISABLED, NULL) < 0)
584 printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n",
585 mpuport[dev]);
586 }
533 587
534 strcpy(card->driver, "CMI8330/C3D"); 588 strcpy(card->driver, "CMI8330/C3D");
535 strcpy(card->shortname, "C-Media CMI8330/C3D"); 589 strcpy(card->shortname, "C-Media CMI8330/C3D");
@@ -564,9 +618,9 @@ static int __devinit snd_cmi8330_isa_probe(struct device *pdev,
564 struct snd_card *card; 618 struct snd_card *card;
565 int err; 619 int err;
566 620
567 card = snd_cmi8330_card_new(dev); 621 err = snd_cmi8330_card_new(dev, &card);
568 if (! card) 622 if (err < 0)
569 return -ENOMEM; 623 return err;
570 snd_card_set_dev(card, pdev); 624 snd_card_set_dev(card, pdev);
571 if ((err = snd_cmi8330_probe(card, dev)) < 0) { 625 if ((err = snd_cmi8330_probe(card, dev)) < 0) {
572 snd_card_free(card); 626 snd_card_free(card);
@@ -628,9 +682,9 @@ static int __devinit snd_cmi8330_pnp_detect(struct pnp_card_link *pcard,
628 if (dev >= SNDRV_CARDS) 682 if (dev >= SNDRV_CARDS)
629 return -ENODEV; 683 return -ENODEV;
630 684
631 card = snd_cmi8330_card_new(dev); 685 res = snd_cmi8330_card_new(dev, &card);
632 if (! card) 686 if (res < 0)
633 return -ENOMEM; 687 return res;
634 if ((res = snd_cmi8330_pnp(dev, card->private_data, pcard, pid)) < 0) { 688 if ((res = snd_cmi8330_pnp(dev, card->private_data, pcard, pid)) < 0) {
635 snd_printk(KERN_ERR PFX "PnP detection failed\n"); 689 snd_printk(KERN_ERR PFX "PnP detection failed\n");
636 snd_card_free(card); 690 snd_card_free(card);
diff --git a/sound/isa/cs423x/Makefile b/sound/isa/cs423x/Makefile
index 5870ca21ab59..6d397e8d54ac 100644
--- a/sound/isa/cs423x/Makefile
+++ b/sound/isa/cs423x/Makefile
@@ -3,13 +3,11 @@
3# Copyright (c) 2001 by Jaroslav Kysela <perex@perex.cz> 3# Copyright (c) 2001 by Jaroslav Kysela <perex@perex.cz>
4# 4#
5 5
6snd-cs4236-lib-objs := cs4236_lib.o
7snd-cs4231-objs := cs4231.o 6snd-cs4231-objs := cs4231.o
8snd-cs4232-objs := cs4232.o 7snd-cs4236-objs := cs4236.o cs4236_lib.o
9snd-cs4236-objs := cs4236.o
10 8
11# Toplevel Module Dependency 9# Toplevel Module Dependency
12obj-$(CONFIG_SND_CS4231) += snd-cs4231.o 10obj-$(CONFIG_SND_CS4231) += snd-cs4231.o
13obj-$(CONFIG_SND_CS4232) += snd-cs4232.o 11obj-$(CONFIG_SND_CS4236) += snd-cs4236.o
14obj-$(CONFIG_SND_CS4236) += snd-cs4236.o snd-cs4236-lib.o 12
15 13
diff --git a/sound/isa/cs423x/cs4231.c b/sound/isa/cs423x/cs4231.c
index f019d449e2d6..cb9153e75b82 100644
--- a/sound/isa/cs423x/cs4231.c
+++ b/sound/isa/cs423x/cs4231.c
@@ -95,9 +95,9 @@ static int __devinit snd_cs4231_probe(struct device *dev, unsigned int n)
95 struct snd_pcm *pcm; 95 struct snd_pcm *pcm;
96 int error; 96 int error;
97 97
98 card = snd_card_new(index[n], id[n], THIS_MODULE, 0); 98 error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card);
99 if (!card) 99 if (error < 0)
100 return -EINVAL; 100 return error;
101 101
102 error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], dma2[n], 102 error = snd_wss_create(card, port[n], -1, irq[n], dma1[n], dma2[n],
103 WSS_HW_DETECT, 0, &chip); 103 WSS_HW_DETECT, 0, &chip);
diff --git a/sound/isa/cs423x/cs4232.c b/sound/isa/cs423x/cs4232.c
deleted file mode 100644
index 9fad2e6c0c2c..000000000000
--- a/sound/isa/cs423x/cs4232.c
+++ /dev/null
@@ -1,2 +0,0 @@
1#define CS4232
2#include "cs4236.c"
diff --git a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c
index 019c9401663e..a076a6ce8071 100644
--- a/sound/isa/cs423x/cs4236.c
+++ b/sound/isa/cs423x/cs4236.c
@@ -33,17 +33,14 @@
33 33
34MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 34MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
35MODULE_LICENSE("GPL"); 35MODULE_LICENSE("GPL");
36#ifdef CS4232 36MODULE_DESCRIPTION("Cirrus Logic CS4232-9");
37MODULE_DESCRIPTION("Cirrus Logic CS4232");
38MODULE_SUPPORTED_DEVICE("{{Turtle Beach,TBS-2000}," 37MODULE_SUPPORTED_DEVICE("{{Turtle Beach,TBS-2000},"
39 "{Turtle Beach,Tropez Plus}," 38 "{Turtle Beach,Tropez Plus},"
40 "{SIC CrystalWave 32}," 39 "{SIC CrystalWave 32},"
41 "{Hewlett Packard,Omnibook 5500}," 40 "{Hewlett Packard,Omnibook 5500},"
42 "{TerraTec,Maestro 32/96}," 41 "{TerraTec,Maestro 32/96},"
43 "{Philips,PCA70PS}}"); 42 "{Philips,PCA70PS}},"
44#else 43 "{{Crystal Semiconductors,CS4235},"
45MODULE_DESCRIPTION("Cirrus Logic CS4235-9");
46MODULE_SUPPORTED_DEVICE("{{Crystal Semiconductors,CS4235},"
47 "{Crystal Semiconductors,CS4236}," 44 "{Crystal Semiconductors,CS4236},"
48 "{Crystal Semiconductors,CS4237}," 45 "{Crystal Semiconductors,CS4237},"
49 "{Crystal Semiconductors,CS4238}," 46 "{Crystal Semiconductors,CS4238},"
@@ -70,15 +67,11 @@ MODULE_SUPPORTED_DEVICE("{{Crystal Semiconductors,CS4235},"
70 "{Typhoon Soundsystem,CS4236B}," 67 "{Typhoon Soundsystem,CS4236B},"
71 "{Turtle Beach,Malibu}," 68 "{Turtle Beach,Malibu},"
72 "{Unknown,Digital PC 5000 Onboard}}"); 69 "{Unknown,Digital PC 5000 Onboard}}");
73#endif
74 70
75#ifdef CS4232 71MODULE_ALIAS("snd_cs4232");
76#define IDENT "CS4232" 72
77#define DEV_NAME "cs4232" 73#define IDENT "CS4232+"
78#else 74#define DEV_NAME "cs4232+"
79#define IDENT "CS4236+"
80#define DEV_NAME "cs4236"
81#endif
82 75
83static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 76static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
84static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 77static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
@@ -128,9 +121,7 @@ MODULE_PARM_DESC(dma2, "DMA2 # for " IDENT " driver.");
128#ifdef CONFIG_PNP 121#ifdef CONFIG_PNP
129static int isa_registered; 122static int isa_registered;
130static int pnpc_registered; 123static int pnpc_registered;
131#ifdef CS4232
132static int pnp_registered; 124static int pnp_registered;
133#endif
134#endif /* CONFIG_PNP */ 125#endif /* CONFIG_PNP */
135 126
136struct snd_card_cs4236 { 127struct snd_card_cs4236 {
@@ -145,11 +136,10 @@ struct snd_card_cs4236 {
145 136
146#ifdef CONFIG_PNP 137#ifdef CONFIG_PNP
147 138
148#ifdef CS4232
149/* 139/*
150 * PNP BIOS 140 * PNP BIOS
151 */ 141 */
152static const struct pnp_device_id snd_cs4232_pnpbiosids[] = { 142static const struct pnp_device_id snd_cs423x_pnpbiosids[] = {
153 { .id = "CSC0100" }, 143 { .id = "CSC0100" },
154 { .id = "CSC0000" }, 144 { .id = "CSC0000" },
155 /* Guillemot Turtlebeach something appears to be cs4232 compatible 145 /* Guillemot Turtlebeach something appears to be cs4232 compatible
@@ -157,10 +147,8 @@ static const struct pnp_device_id snd_cs4232_pnpbiosids[] = {
157 { .id = "GIM0100" }, 147 { .id = "GIM0100" },
158 { .id = "" } 148 { .id = "" }
159}; 149};
160MODULE_DEVICE_TABLE(pnp, snd_cs4232_pnpbiosids); 150MODULE_DEVICE_TABLE(pnp, snd_cs423x_pnpbiosids);
161#endif /* CS4232 */
162 151
163#ifdef CS4232
164#define CS423X_ISAPNP_DRIVER "cs4232_isapnp" 152#define CS423X_ISAPNP_DRIVER "cs4232_isapnp"
165static struct pnp_card_device_id snd_cs423x_pnpids[] = { 153static struct pnp_card_device_id snd_cs423x_pnpids[] = {
166 /* Philips PCA70PS */ 154 /* Philips PCA70PS */
@@ -179,12 +167,6 @@ static struct pnp_card_device_id snd_cs423x_pnpids[] = {
179 { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, 167 { .id = "CSCf032", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
180 /* Netfinity 3000 on-board soundcard */ 168 /* Netfinity 3000 on-board soundcard */
181 { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC010f" } } }, 169 { .id = "CSCe825", .devs = { { "CSC0100" }, { "CSC0110" }, { "CSC010f" } } },
182 /* --- */
183 { .id = "" } /* end */
184};
185#else /* CS4236 */
186#define CS423X_ISAPNP_DRIVER "cs4236_isapnp"
187static struct pnp_card_device_id snd_cs423x_pnpids[] = {
188 /* Intel Marlin Spike Motherboard - CS4235 */ 170 /* Intel Marlin Spike Motherboard - CS4235 */
189 { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } }, 171 { .id = "CSC0225", .devs = { { "CSC0000" }, { "CSC0010" }, { "CSC0003" } } },
190 /* Intel Marlin Spike Motherboard (#2) - CS4235 */ 172 /* Intel Marlin Spike Motherboard (#2) - CS4235 */
@@ -266,7 +248,6 @@ static struct pnp_card_device_id snd_cs423x_pnpids[] = {
266 /* --- */ 248 /* --- */
267 { .id = "" } /* end */ 249 { .id = "" } /* end */
268}; 250};
269#endif
270 251
271MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids); 252MODULE_DEVICE_TABLE(pnp_card, snd_cs423x_pnpids);
272 253
@@ -323,17 +304,19 @@ static int __devinit snd_cs423x_pnp_init_mpu(int dev, struct pnp_dev *pdev)
323 return 0; 304 return 0;
324} 305}
325 306
326#ifdef CS4232 307static int __devinit snd_card_cs423x_pnp(int dev, struct snd_card_cs4236 *acard,
327static int __devinit snd_card_cs4232_pnp(int dev, struct snd_card_cs4236 *acard, 308 struct pnp_dev *pdev,
328 struct pnp_dev *pdev) 309 struct pnp_dev *cdev)
329{ 310{
330 acard->wss = pdev; 311 acard->wss = pdev;
331 if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0) 312 if (snd_cs423x_pnp_init_wss(dev, acard->wss) < 0)
332 return -EBUSY; 313 return -EBUSY;
333 cport[dev] = -1; 314 if (cdev)
315 cport[dev] = pnp_port_start(cdev, 0);
316 else
317 cport[dev] = -1;
334 return 0; 318 return 0;
335} 319}
336#endif
337 320
338static int __devinit snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard, 321static int __devinit snd_card_cs423x_pnpc(int dev, struct snd_card_cs4236 *acard,
339 struct pnp_card_link *card, 322 struct pnp_card_link *card,
@@ -382,16 +365,18 @@ static void snd_card_cs4236_free(struct snd_card *card)
382 release_and_free_resource(acard->res_sb_port); 365 release_and_free_resource(acard->res_sb_port);
383} 366}
384 367
385static struct snd_card *snd_cs423x_card_new(int dev) 368static int snd_cs423x_card_new(int dev, struct snd_card **cardp)
386{ 369{
387 struct snd_card *card; 370 struct snd_card *card;
371 int err;
388 372
389 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 373 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
390 sizeof(struct snd_card_cs4236)); 374 sizeof(struct snd_card_cs4236), &card);
391 if (card == NULL) 375 if (err < 0)
392 return NULL; 376 return err;
393 card->private_free = snd_card_cs4236_free; 377 card->private_free = snd_card_cs4236_free;
394 return card; 378 *cardp = card;
379 return 0;
395} 380}
396 381
397static int __devinit snd_cs423x_probe(struct snd_card *card, int dev) 382static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
@@ -409,40 +394,39 @@ static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
409 return -EBUSY; 394 return -EBUSY;
410 } 395 }
411 396
412#ifdef CS4232
413 err = snd_wss_create(card, port[dev], cport[dev], 397 err = snd_wss_create(card, port[dev], cport[dev],
414 irq[dev], 398 irq[dev],
415 dma1[dev], dma2[dev], 399 dma1[dev], dma2[dev],
416 WSS_HW_DETECT, 0, &chip); 400 WSS_HW_DETECT3, 0, &chip);
417 if (err < 0)
418 return err;
419 acard->chip = chip;
420
421 err = snd_wss_pcm(chip, 0, &pcm);
422 if (err < 0)
423 return err;
424
425 err = snd_wss_mixer(chip);
426 if (err < 0) 401 if (err < 0)
427 return err; 402 return err;
428 403 if (chip->hardware & WSS_HW_CS4236B_MASK) {
429#else /* CS4236 */ 404 snd_wss_free(chip);
430 err = snd_cs4236_create(card, 405 err = snd_cs4236_create(card,
431 port[dev], cport[dev], 406 port[dev], cport[dev],
432 irq[dev], dma1[dev], dma2[dev], 407 irq[dev], dma1[dev], dma2[dev],
433 WSS_HW_DETECT, 0, &chip); 408 WSS_HW_DETECT, 0, &chip);
434 if (err < 0) 409 if (err < 0)
435 return err; 410 return err;
436 acard->chip = chip; 411 acard->chip = chip;
437 412
438 err = snd_cs4236_pcm(chip, 0, &pcm); 413 err = snd_cs4236_pcm(chip, 0, &pcm);
439 if (err < 0) 414 if (err < 0)
440 return err; 415 return err;
441 416
442 err = snd_cs4236_mixer(chip); 417 err = snd_cs4236_mixer(chip);
443 if (err < 0) 418 if (err < 0)
444 return err; 419 return err;
445#endif 420 } else {
421 acard->chip = chip;
422 err = snd_wss_pcm(chip, 0, &pcm);
423 if (err < 0)
424 return err;
425
426 err = snd_wss_mixer(chip);
427 if (err < 0)
428 return err;
429 }
446 strcpy(card->driver, pcm->name); 430 strcpy(card->driver, pcm->name);
447 strcpy(card->shortname, pcm->name); 431 strcpy(card->shortname, pcm->name);
448 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", 432 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i",
@@ -512,9 +496,9 @@ static int __devinit snd_cs423x_isa_probe(struct device *pdev,
512 struct snd_card *card; 496 struct snd_card *card;
513 int err; 497 int err;
514 498
515 card = snd_cs423x_card_new(dev); 499 err = snd_cs423x_card_new(dev, &card);
516 if (! card) 500 if (err < 0)
517 return -ENOMEM; 501 return err;
518 snd_card_set_dev(card, pdev); 502 snd_card_set_dev(card, pdev);
519 if ((err = snd_cs423x_probe(card, dev)) < 0) { 503 if ((err = snd_cs423x_probe(card, dev)) < 0) {
520 snd_card_free(card); 504 snd_card_free(card);
@@ -577,13 +561,14 @@ static struct isa_driver cs423x_isa_driver = {
577 561
578 562
579#ifdef CONFIG_PNP 563#ifdef CONFIG_PNP
580#ifdef CS4232 564static int __devinit snd_cs423x_pnpbios_detect(struct pnp_dev *pdev,
581static int __devinit snd_cs4232_pnpbios_detect(struct pnp_dev *pdev,
582 const struct pnp_device_id *id) 565 const struct pnp_device_id *id)
583{ 566{
584 static int dev; 567 static int dev;
585 int err; 568 int err;
586 struct snd_card *card; 569 struct snd_card *card;
570 struct pnp_dev *cdev;
571 char cid[PNP_ID_LEN];
587 572
588 if (pnp_device_is_isapnp(pdev)) 573 if (pnp_device_is_isapnp(pdev))
589 return -ENOENT; /* we have another procedure - card */ 574 return -ENOENT; /* we have another procedure - card */
@@ -594,10 +579,19 @@ static int __devinit snd_cs4232_pnpbios_detect(struct pnp_dev *pdev,
594 if (dev >= SNDRV_CARDS) 579 if (dev >= SNDRV_CARDS)
595 return -ENODEV; 580 return -ENODEV;
596 581
597 card = snd_cs423x_card_new(dev); 582 /* prepare second id */
598 if (! card) 583 strcpy(cid, pdev->id[0].id);
599 return -ENOMEM; 584 cid[5] = '1';
600 if ((err = snd_card_cs4232_pnp(dev, card->private_data, pdev)) < 0) { 585 cdev = NULL;
586 list_for_each_entry(cdev, &(pdev->protocol->devices), protocol_list) {
587 if (!strcmp(cdev->id[0].id, cid))
588 break;
589 }
590 err = snd_cs423x_card_new(dev, &card);
591 if (err < 0)
592 return err;
593 err = snd_card_cs423x_pnp(dev, card->private_data, pdev, cdev);
594 if (err < 0) {
601 printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n"); 595 printk(KERN_ERR "PnP BIOS detection failed for " IDENT "\n");
602 snd_card_free(card); 596 snd_card_free(card);
603 return err; 597 return err;
@@ -612,35 +606,34 @@ static int __devinit snd_cs4232_pnpbios_detect(struct pnp_dev *pdev,
612 return 0; 606 return 0;
613} 607}
614 608
615static void __devexit snd_cs4232_pnp_remove(struct pnp_dev * pdev) 609static void __devexit snd_cs423x_pnp_remove(struct pnp_dev *pdev)
616{ 610{
617 snd_card_free(pnp_get_drvdata(pdev)); 611 snd_card_free(pnp_get_drvdata(pdev));
618 pnp_set_drvdata(pdev, NULL); 612 pnp_set_drvdata(pdev, NULL);
619} 613}
620 614
621#ifdef CONFIG_PM 615#ifdef CONFIG_PM
622static int snd_cs4232_pnp_suspend(struct pnp_dev *pdev, pm_message_t state) 616static int snd_cs423x_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
623{ 617{
624 return snd_cs423x_suspend(pnp_get_drvdata(pdev)); 618 return snd_cs423x_suspend(pnp_get_drvdata(pdev));
625} 619}
626 620
627static int snd_cs4232_pnp_resume(struct pnp_dev *pdev) 621static int snd_cs423x_pnp_resume(struct pnp_dev *pdev)
628{ 622{
629 return snd_cs423x_resume(pnp_get_drvdata(pdev)); 623 return snd_cs423x_resume(pnp_get_drvdata(pdev));
630} 624}
631#endif 625#endif
632 626
633static struct pnp_driver cs4232_pnp_driver = { 627static struct pnp_driver cs423x_pnp_driver = {
634 .name = "cs4232-pnpbios", 628 .name = "cs423x-pnpbios",
635 .id_table = snd_cs4232_pnpbiosids, 629 .id_table = snd_cs423x_pnpbiosids,
636 .probe = snd_cs4232_pnpbios_detect, 630 .probe = snd_cs423x_pnpbios_detect,
637 .remove = __devexit_p(snd_cs4232_pnp_remove), 631 .remove = __devexit_p(snd_cs423x_pnp_remove),
638#ifdef CONFIG_PM 632#ifdef CONFIG_PM
639 .suspend = snd_cs4232_pnp_suspend, 633 .suspend = snd_cs423x_pnp_suspend,
640 .resume = snd_cs4232_pnp_resume, 634 .resume = snd_cs423x_pnp_resume,
641#endif 635#endif
642}; 636};
643#endif /* CS4232 */
644 637
645static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard, 638static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
646 const struct pnp_card_device_id *pid) 639 const struct pnp_card_device_id *pid)
@@ -656,9 +649,9 @@ static int __devinit snd_cs423x_pnpc_detect(struct pnp_card_link *pcard,
656 if (dev >= SNDRV_CARDS) 649 if (dev >= SNDRV_CARDS)
657 return -ENODEV; 650 return -ENODEV;
658 651
659 card = snd_cs423x_card_new(dev); 652 res = snd_cs423x_card_new(dev, &card);
660 if (! card) 653 if (res < 0)
661 return -ENOMEM; 654 return res;
662 if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) { 655 if ((res = snd_card_cs423x_pnpc(dev, card->private_data, pcard, pid)) < 0) {
663 printk(KERN_ERR "isapnp detection failed and probing for " IDENT 656 printk(KERN_ERR "isapnp detection failed and probing for " IDENT
664 " is not supported\n"); 657 " is not supported\n");
@@ -714,18 +707,14 @@ static int __init alsa_card_cs423x_init(void)
714#ifdef CONFIG_PNP 707#ifdef CONFIG_PNP
715 if (!err) 708 if (!err)
716 isa_registered = 1; 709 isa_registered = 1;
717#ifdef CS4232 710 err = pnp_register_driver(&cs423x_pnp_driver);
718 err = pnp_register_driver(&cs4232_pnp_driver);
719 if (!err) 711 if (!err)
720 pnp_registered = 1; 712 pnp_registered = 1;
721#endif
722 err = pnp_register_card_driver(&cs423x_pnpc_driver); 713 err = pnp_register_card_driver(&cs423x_pnpc_driver);
723 if (!err) 714 if (!err)
724 pnpc_registered = 1; 715 pnpc_registered = 1;
725#ifdef CS4232
726 if (pnp_registered) 716 if (pnp_registered)
727 err = 0; 717 err = 0;
728#endif
729 if (isa_registered) 718 if (isa_registered)
730 err = 0; 719 err = 0;
731#endif 720#endif
@@ -737,10 +726,8 @@ static void __exit alsa_card_cs423x_exit(void)
737#ifdef CONFIG_PNP 726#ifdef CONFIG_PNP
738 if (pnpc_registered) 727 if (pnpc_registered)
739 pnp_unregister_card_driver(&cs423x_pnpc_driver); 728 pnp_unregister_card_driver(&cs423x_pnpc_driver);
740#ifdef CS4232
741 if (pnp_registered) 729 if (pnp_registered)
742 pnp_unregister_driver(&cs4232_pnp_driver); 730 pnp_unregister_driver(&cs423x_pnp_driver);
743#endif
744 if (isa_registered) 731 if (isa_registered)
745#endif 732#endif
746 isa_unregister_driver(&cs423x_isa_driver); 733 isa_unregister_driver(&cs423x_isa_driver);
diff --git a/sound/isa/cs423x/cs4236_lib.c b/sound/isa/cs423x/cs4236_lib.c
index 6a85fdc53b60..38835f31298b 100644
--- a/sound/isa/cs423x/cs4236_lib.c
+++ b/sound/isa/cs423x/cs4236_lib.c
@@ -88,10 +88,6 @@
88#include <sound/wss.h> 88#include <sound/wss.h>
89#include <sound/asoundef.h> 89#include <sound/asoundef.h>
90 90
91MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
92MODULE_DESCRIPTION("Routines for control of CS4235/4236B/4237B/4238B/4239 chips");
93MODULE_LICENSE("GPL");
94
95/* 91/*
96 * 92 *
97 */ 93 */
@@ -286,7 +282,8 @@ int snd_cs4236_create(struct snd_card *card,
286 if (hardware == WSS_HW_DETECT) 282 if (hardware == WSS_HW_DETECT)
287 hardware = WSS_HW_DETECT3; 283 hardware = WSS_HW_DETECT3;
288 if (cport < 0x100) { 284 if (cport < 0x100) {
289 snd_printk("please, specify control port for CS4236+ chips\n"); 285 snd_printk(KERN_ERR "please, specify control port "
286 "for CS4236+ chips\n");
290 return -ENODEV; 287 return -ENODEV;
291 } 288 }
292 err = snd_wss_create(card, port, cport, 289 err = snd_wss_create(card, port, cport,
@@ -295,7 +292,8 @@ int snd_cs4236_create(struct snd_card *card,
295 return err; 292 return err;
296 293
297 if (!(chip->hardware & WSS_HW_CS4236B_MASK)) { 294 if (!(chip->hardware & WSS_HW_CS4236B_MASK)) {
298 snd_printk("CS4236+: MODE3 and extended registers not available, hardware=0x%x\n",chip->hardware); 295 snd_printk(KERN_ERR "CS4236+: MODE3 and extended registers "
296 "not available, hardware=0x%x\n", chip->hardware);
299 snd_device_free(card, chip); 297 snd_device_free(card, chip);
300 return -ENODEV; 298 return -ENODEV;
301 } 299 }
@@ -303,16 +301,19 @@ int snd_cs4236_create(struct snd_card *card,
303 { 301 {
304 int idx; 302 int idx;
305 for (idx = 0; idx < 8; idx++) 303 for (idx = 0; idx < 8; idx++)
306 snd_printk("CD%i = 0x%x\n", idx, inb(chip->cport + idx)); 304 snd_printk(KERN_DEBUG "CD%i = 0x%x\n",
305 idx, inb(chip->cport + idx));
307 for (idx = 0; idx < 9; idx++) 306 for (idx = 0; idx < 9; idx++)
308 snd_printk("C%i = 0x%x\n", idx, snd_cs4236_ctrl_in(chip, idx)); 307 snd_printk(KERN_DEBUG "C%i = 0x%x\n",
308 idx, snd_cs4236_ctrl_in(chip, idx));
309 } 309 }
310#endif 310#endif
311 ver1 = snd_cs4236_ctrl_in(chip, 1); 311 ver1 = snd_cs4236_ctrl_in(chip, 1);
312 ver2 = snd_cs4236_ext_in(chip, CS4236_VERSION); 312 ver2 = snd_cs4236_ext_in(chip, CS4236_VERSION);
313 snd_printdd("CS4236: [0x%lx] C1 (version) = 0x%x, ext = 0x%x\n", cport, ver1, ver2); 313 snd_printdd("CS4236: [0x%lx] C1 (version) = 0x%x, ext = 0x%x\n", cport, ver1, ver2);
314 if (ver1 != ver2) { 314 if (ver1 != ver2) {
315 snd_printk("CS4236+ chip detected, but control port 0x%lx is not valid\n", cport); 315 snd_printk(KERN_ERR "CS4236+ chip detected, but "
316 "control port 0x%lx is not valid\n", cport);
316 snd_device_free(card, chip); 317 snd_device_free(card, chip);
317 return -ENODEV; 318 return -ENODEV;
318 } 319 }
@@ -883,7 +884,8 @@ static int snd_cs4236_get_iec958_switch(struct snd_kcontrol *kcontrol, struct sn
883 spin_lock_irqsave(&chip->reg_lock, flags); 884 spin_lock_irqsave(&chip->reg_lock, flags);
884 ucontrol->value.integer.value[0] = chip->image[CS4231_ALT_FEATURE_1] & 0x02 ? 1 : 0; 885 ucontrol->value.integer.value[0] = chip->image[CS4231_ALT_FEATURE_1] & 0x02 ? 1 : 0;
885#if 0 886#if 0
886 printk("get valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n", 887 printk(KERN_DEBUG "get valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, "
888 "C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n",
887 snd_wss_in(chip, CS4231_ALT_FEATURE_1), 889 snd_wss_in(chip, CS4231_ALT_FEATURE_1),
888 snd_cs4236_ctrl_in(chip, 3), 890 snd_cs4236_ctrl_in(chip, 3),
889 snd_cs4236_ctrl_in(chip, 4), 891 snd_cs4236_ctrl_in(chip, 4),
@@ -920,7 +922,8 @@ static int snd_cs4236_put_iec958_switch(struct snd_kcontrol *kcontrol, struct sn
920 mutex_unlock(&chip->mce_mutex); 922 mutex_unlock(&chip->mce_mutex);
921 923
922#if 0 924#if 0
923 printk("set valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n", 925 printk(KERN_DEBUG "set valid: ALT = 0x%x, C3 = 0x%x, C4 = 0x%x, "
926 "C5 = 0x%x, C6 = 0x%x, C8 = 0x%x\n",
924 snd_wss_in(chip, CS4231_ALT_FEATURE_1), 927 snd_wss_in(chip, CS4231_ALT_FEATURE_1),
925 snd_cs4236_ctrl_in(chip, 3), 928 snd_cs4236_ctrl_in(chip, 3),
926 snd_cs4236_ctrl_in(chip, 4), 929 snd_cs4236_ctrl_in(chip, 4),
@@ -1015,23 +1018,3 @@ int snd_cs4236_mixer(struct snd_wss *chip)
1015 } 1018 }
1016 return 0; 1019 return 0;
1017} 1020}
1018
1019EXPORT_SYMBOL(snd_cs4236_create);
1020EXPORT_SYMBOL(snd_cs4236_pcm);
1021EXPORT_SYMBOL(snd_cs4236_mixer);
1022
1023/*
1024 * INIT part
1025 */
1026
1027static int __init alsa_cs4236_init(void)
1028{
1029 return 0;
1030}
1031
1032static void __exit alsa_cs4236_exit(void)
1033{
1034}
1035
1036module_init(alsa_cs4236_init)
1037module_exit(alsa_cs4236_exit)
diff --git a/sound/isa/dt019x.c b/sound/isa/dt019x.c
index a0242c3b613e..80f5b1af9be8 100644
--- a/sound/isa/dt019x.c
+++ b/sound/isa/dt019x.c
@@ -150,9 +150,10 @@ static int __devinit snd_card_dt019x_probe(int dev, struct pnp_card_link *pcard,
150 struct snd_card_dt019x *acard; 150 struct snd_card_dt019x *acard;
151 struct snd_opl3 *opl3; 151 struct snd_opl3 *opl3;
152 152
153 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE, 153 error = snd_card_create(index[dev], id[dev], THIS_MODULE,
154 sizeof(struct snd_card_dt019x))) == NULL) 154 sizeof(struct snd_card_dt019x), &card);
155 return -ENOMEM; 155 if (error < 0)
156 return error;
156 acard = card->private_data; 157 acard = card->private_data;
157 158
158 snd_card_set_dev(card, &pcard->card->dev); 159 snd_card_set_dev(card, &pcard->card->dev);
diff --git a/sound/isa/es1688/es1688.c b/sound/isa/es1688/es1688.c
index b46377139cf8..442b081cafb7 100644
--- a/sound/isa/es1688/es1688.c
+++ b/sound/isa/es1688/es1688.c
@@ -49,6 +49,7 @@ static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
49static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 49static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
50static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */ 50static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
51static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */ 51static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
52static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* Usually 0x388 */
52static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1}; 53static long mpu_port[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = -1};
53static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ 54static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
54static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */ 55static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
@@ -65,6 +66,8 @@ MODULE_PARM_DESC(port, "Port # for " CRD_NAME " driver.");
65module_param_array(mpu_port, long, NULL, 0444); 66module_param_array(mpu_port, long, NULL, 0444);
66MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver."); 67MODULE_PARM_DESC(mpu_port, "MPU-401 port # for " CRD_NAME " driver.");
67module_param_array(irq, int, NULL, 0444); 68module_param_array(irq, int, NULL, 0444);
69module_param_array(fm_port, long, NULL, 0444);
70MODULE_PARM_DESC(fm_port, "FM port # for ES1688 driver.");
68MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver."); 71MODULE_PARM_DESC(irq, "IRQ # for " CRD_NAME " driver.");
69module_param_array(mpu_irq, int, NULL, 0444); 72module_param_array(mpu_irq, int, NULL, 0444);
70MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver."); 73MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for " CRD_NAME " driver.");
@@ -122,9 +125,9 @@ static int __devinit snd_es1688_probe(struct device *dev, unsigned int n)
122 struct snd_pcm *pcm; 125 struct snd_pcm *pcm;
123 int error; 126 int error;
124 127
125 card = snd_card_new(index[n], id[n], THIS_MODULE, 0); 128 error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card);
126 if (!card) 129 if (error < 0)
127 return -EINVAL; 130 return error;
128 131
129 error = snd_es1688_legacy_create(card, dev, n, &chip); 132 error = snd_es1688_legacy_create(card, dev, n, &chip);
130 if (error < 0) 133 if (error < 0)
@@ -143,13 +146,19 @@ static int __devinit snd_es1688_probe(struct device *dev, unsigned int n)
143 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name, 146 sprintf(card->longname, "%s at 0x%lx, irq %i, dma %i", pcm->name,
144 chip->port, chip->irq, chip->dma8); 147 chip->port, chip->irq, chip->dma8);
145 148
146 if (snd_opl3_create(card, chip->port, chip->port + 2, 149 if (fm_port[n] == SNDRV_AUTO_PORT)
147 OPL3_HW_OPL3, 0, &opl3) < 0) 150 fm_port[n] = port[n]; /* share the same port */
148 dev_warn(dev, "opl3 not detected at 0x%lx\n", chip->port); 151
149 else { 152 if (fm_port[n] > 0) {
150 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL); 153 if (snd_opl3_create(card, fm_port[n], fm_port[n] + 2,
151 if (error < 0) 154 OPL3_HW_OPL3, 0, &opl3) < 0)
152 goto out; 155 dev_warn(dev,
156 "opl3 not detected at 0x%lx\n", fm_port[n]);
157 else {
158 error = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
159 if (error < 0)
160 goto out;
161 }
153 } 162 }
154 163
155 if (mpu_irq[n] >= 0 && mpu_irq[n] != SNDRV_AUTO_IRQ && 164 if (mpu_irq[n] >= 0 && mpu_irq[n] != SNDRV_AUTO_IRQ &&
diff --git a/sound/isa/es1688/es1688_lib.c b/sound/isa/es1688/es1688_lib.c
index 4fbb508a817f..4c6e14f87f2d 100644
--- a/sound/isa/es1688/es1688_lib.c
+++ b/sound/isa/es1688/es1688_lib.c
@@ -45,7 +45,7 @@ static int snd_es1688_dsp_command(struct snd_es1688 *chip, unsigned char val)
45 return 1; 45 return 1;
46 } 46 }
47#ifdef CONFIG_SND_DEBUG 47#ifdef CONFIG_SND_DEBUG
48 printk("snd_es1688_dsp_command: timeout (0x%x)\n", val); 48 printk(KERN_DEBUG "snd_es1688_dsp_command: timeout (0x%x)\n", val);
49#endif 49#endif
50 return 0; 50 return 0;
51} 51}
@@ -167,13 +167,16 @@ static int snd_es1688_probe(struct snd_es1688 *chip)
167 hw = ES1688_HW_AUTO; 167 hw = ES1688_HW_AUTO;
168 switch (chip->version & 0xfff0) { 168 switch (chip->version & 0xfff0) {
169 case 0x4880: 169 case 0x4880:
170 snd_printk("[0x%lx] ESS: AudioDrive ES488 detected, but driver is in another place\n", chip->port); 170 snd_printk(KERN_ERR "[0x%lx] ESS: AudioDrive ES488 detected, "
171 "but driver is in another place\n", chip->port);
171 return -ENODEV; 172 return -ENODEV;
172 case 0x6880: 173 case 0x6880:
173 hw = (chip->version & 0x0f) >= 8 ? ES1688_HW_1688 : ES1688_HW_688; 174 hw = (chip->version & 0x0f) >= 8 ? ES1688_HW_1688 : ES1688_HW_688;
174 break; 175 break;
175 default: 176 default:
176 snd_printk("[0x%lx] ESS: unknown AudioDrive chip with version 0x%x (Jazz16 soundcard?)\n", chip->port, chip->version); 177 snd_printk(KERN_ERR "[0x%lx] ESS: unknown AudioDrive chip "
178 "with version 0x%x (Jazz16 soundcard?)\n",
179 chip->port, chip->version);
177 return -ENODEV; 180 return -ENODEV;
178 } 181 }
179 182
@@ -223,7 +226,7 @@ static int snd_es1688_init(struct snd_es1688 * chip, int enable)
223 } 226 }
224 } 227 }
225#if 0 228#if 0
226 snd_printk("mpu cfg = 0x%x\n", cfg); 229 snd_printk(KERN_DEBUG "mpu cfg = 0x%x\n", cfg);
227#endif 230#endif
228 spin_lock_irqsave(&chip->reg_lock, flags); 231 spin_lock_irqsave(&chip->reg_lock, flags);
229 snd_es1688_mixer_write(chip, 0x40, cfg); 232 snd_es1688_mixer_write(chip, 0x40, cfg);
@@ -237,7 +240,9 @@ static int snd_es1688_init(struct snd_es1688 * chip, int enable)
237 cfg = 0xf0; /* enable only DMA counter interrupt */ 240 cfg = 0xf0; /* enable only DMA counter interrupt */
238 irq_bits = irqs[chip->irq & 0x0f]; 241 irq_bits = irqs[chip->irq & 0x0f];
239 if (irq_bits < 0) { 242 if (irq_bits < 0) {
240 snd_printk("[0x%lx] ESS: bad IRQ %d for ES1688 chip!!\n", chip->port, chip->irq); 243 snd_printk(KERN_ERR "[0x%lx] ESS: bad IRQ %d "
244 "for ES1688 chip!!\n",
245 chip->port, chip->irq);
241#if 0 246#if 0
242 irq_bits = 0; 247 irq_bits = 0;
243 cfg = 0x10; 248 cfg = 0x10;
@@ -250,7 +255,8 @@ static int snd_es1688_init(struct snd_es1688 * chip, int enable)
250 cfg = 0xf0; /* extended mode DMA enable */ 255 cfg = 0xf0; /* extended mode DMA enable */
251 dma = chip->dma8; 256 dma = chip->dma8;
252 if (dma > 3 || dma == 2) { 257 if (dma > 3 || dma == 2) {
253 snd_printk("[0x%lx] ESS: bad DMA channel %d for ES1688 chip!!\n", chip->port, dma); 258 snd_printk(KERN_ERR "[0x%lx] ESS: bad DMA channel %d "
259 "for ES1688 chip!!\n", chip->port, dma);
254#if 0 260#if 0
255 dma_bits = 0; 261 dma_bits = 0;
256 cfg = 0x00; /* disable all DMA */ 262 cfg = 0x00; /* disable all DMA */
@@ -341,8 +347,9 @@ static int snd_es1688_trigger(struct snd_es1688 *chip, int cmd, unsigned char va
341 return -EINVAL; /* something is wrong */ 347 return -EINVAL; /* something is wrong */
342 } 348 }
343#if 0 349#if 0
344 printk("trigger: val = 0x%x, value = 0x%x\n", val, value); 350 printk(KERN_DEBUG "trigger: val = 0x%x, value = 0x%x\n", val, value);
345 printk("trigger: pointer = 0x%x\n", snd_dma_pointer(chip->dma8, chip->dma_size)); 351 printk(KERN_DEBUG "trigger: pointer = 0x%x\n",
352 snd_dma_pointer(chip->dma8, chip->dma_size));
346#endif 353#endif
347 snd_es1688_write(chip, 0xb8, (val & 0xf0) | value); 354 snd_es1688_write(chip, 0xb8, (val & 0xf0) | value);
348 spin_unlock(&chip->reg_lock); 355 spin_unlock(&chip->reg_lock);
diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c
index 90498e4ca260..8cfbff73a835 100644
--- a/sound/isa/es18xx.c
+++ b/sound/isa/es18xx.c
@@ -2125,10 +2125,10 @@ static int __devinit snd_audiodrive_pnpc(int dev, struct snd_audiodrive *acard,
2125#define is_isapnp_selected(dev) 0 2125#define is_isapnp_selected(dev) 0
2126#endif 2126#endif
2127 2127
2128static struct snd_card *snd_es18xx_card_new(int dev) 2128static int snd_es18xx_card_new(int dev, struct snd_card **cardp)
2129{ 2129{
2130 return snd_card_new(index[dev], id[dev], THIS_MODULE, 2130 return snd_card_create(index[dev], id[dev], THIS_MODULE,
2131 sizeof(struct snd_audiodrive)); 2131 sizeof(struct snd_audiodrive), cardp);
2132} 2132}
2133 2133
2134static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev) 2134static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev)
@@ -2197,9 +2197,9 @@ static int __devinit snd_es18xx_isa_probe1(int dev, struct device *devptr)
2197 struct snd_card *card; 2197 struct snd_card *card;
2198 int err; 2198 int err;
2199 2199
2200 card = snd_es18xx_card_new(dev); 2200 err = snd_es18xx_card_new(dev, &card);
2201 if (! card) 2201 if (err < 0)
2202 return -ENOMEM; 2202 return err;
2203 snd_card_set_dev(card, devptr); 2203 snd_card_set_dev(card, devptr);
2204 if ((err = snd_audiodrive_probe(card, dev)) < 0) { 2204 if ((err = snd_audiodrive_probe(card, dev)) < 0) {
2205 snd_card_free(card); 2205 snd_card_free(card);
@@ -2303,9 +2303,9 @@ static int __devinit snd_audiodrive_pnp_detect(struct pnp_dev *pdev,
2303 if (dev >= SNDRV_CARDS) 2303 if (dev >= SNDRV_CARDS)
2304 return -ENODEV; 2304 return -ENODEV;
2305 2305
2306 card = snd_es18xx_card_new(dev); 2306 err = snd_es18xx_card_new(dev, &card);
2307 if (! card) 2307 if (err < 0)
2308 return -ENOMEM; 2308 return err;
2309 if ((err = snd_audiodrive_pnp(dev, card->private_data, pdev)) < 0) { 2309 if ((err = snd_audiodrive_pnp(dev, card->private_data, pdev)) < 0) {
2310 snd_card_free(card); 2310 snd_card_free(card);
2311 return err; 2311 return err;
@@ -2362,9 +2362,9 @@ static int __devinit snd_audiodrive_pnpc_detect(struct pnp_card_link *pcard,
2362 if (dev >= SNDRV_CARDS) 2362 if (dev >= SNDRV_CARDS)
2363 return -ENODEV; 2363 return -ENODEV;
2364 2364
2365 card = snd_es18xx_card_new(dev); 2365 res = snd_es18xx_card_new(dev, &card);
2366 if (! card) 2366 if (res < 0)
2367 return -ENOMEM; 2367 return res;
2368 2368
2369 if ((res = snd_audiodrive_pnpc(dev, card->private_data, pcard, pid)) < 0) { 2369 if ((res = snd_audiodrive_pnpc(dev, card->private_data, pcard, pid)) < 0) {
2370 snd_card_free(card); 2370 snd_card_free(card);
diff --git a/sound/isa/gus/gus_dma.c b/sound/isa/gus/gus_dma.c
index f45f6116c77a..36c27c832360 100644
--- a/sound/isa/gus/gus_dma.c
+++ b/sound/isa/gus/gus_dma.c
@@ -45,7 +45,8 @@ static void snd_gf1_dma_program(struct snd_gus_card * gus,
45 unsigned char dma_cmd; 45 unsigned char dma_cmd;
46 unsigned int address_high; 46 unsigned int address_high;
47 47
48 // snd_printk("dma_transfer: addr=0x%x, buf=0x%lx, count=0x%x\n", addr, (long) buf, count); 48 snd_printdd("dma_transfer: addr=0x%x, buf=0x%lx, count=0x%x\n",
49 addr, buf_addr, count);
49 50
50 if (gus->gf1.dma1 > 3) { 51 if (gus->gf1.dma1 > 3) {
51 if (gus->gf1.enh_mode) { 52 if (gus->gf1.enh_mode) {
@@ -77,7 +78,8 @@ static void snd_gf1_dma_program(struct snd_gus_card * gus,
77 snd_gf1_dma_ack(gus); 78 snd_gf1_dma_ack(gus);
78 snd_dma_program(gus->gf1.dma1, buf_addr, count, dma_cmd & SNDRV_GF1_DMA_READ ? DMA_MODE_READ : DMA_MODE_WRITE); 79 snd_dma_program(gus->gf1.dma1, buf_addr, count, dma_cmd & SNDRV_GF1_DMA_READ ? DMA_MODE_READ : DMA_MODE_WRITE);
79#if 0 80#if 0
80 snd_printk("address = 0x%x, count = 0x%x, dma_cmd = 0x%x\n", address << 1, count, dma_cmd); 81 snd_printk(KERN_DEBUG "address = 0x%x, count = 0x%x, dma_cmd = 0x%x\n",
82 address << 1, count, dma_cmd);
81#endif 83#endif
82 spin_lock_irqsave(&gus->reg_lock, flags); 84 spin_lock_irqsave(&gus->reg_lock, flags);
83 if (gus->gf1.enh_mode) { 85 if (gus->gf1.enh_mode) {
@@ -142,7 +144,9 @@ static void snd_gf1_dma_interrupt(struct snd_gus_card * gus)
142 snd_gf1_dma_program(gus, block->addr, block->buf_addr, block->count, (unsigned short) block->cmd); 144 snd_gf1_dma_program(gus, block->addr, block->buf_addr, block->count, (unsigned short) block->cmd);
143 kfree(block); 145 kfree(block);
144#if 0 146#if 0
145 printk("program dma (IRQ) - addr = 0x%x, buffer = 0x%lx, count = 0x%x, cmd = 0x%x\n", addr, (long) buffer, count, cmd); 147 snd_printd(KERN_DEBUG "program dma (IRQ) - "
148 "addr = 0x%x, buffer = 0x%lx, count = 0x%x, cmd = 0x%x\n",
149 block->addr, block->buf_addr, block->count, block->cmd);
146#endif 150#endif
147} 151}
148 152
@@ -203,13 +207,16 @@ int snd_gf1_dma_transfer_block(struct snd_gus_card * gus,
203 } 207 }
204 *block = *__block; 208 *block = *__block;
205 block->next = NULL; 209 block->next = NULL;
206#if 0 210
207 printk("addr = 0x%x, buffer = 0x%lx, count = 0x%x, cmd = 0x%x\n", block->addr, (long) block->buffer, block->count, block->cmd); 211 snd_printdd("addr = 0x%x, buffer = 0x%lx, count = 0x%x, cmd = 0x%x\n",
208#endif 212 block->addr, (long) block->buffer, block->count,
209#if 0 213 block->cmd);
210 printk("gus->gf1.dma_data_pcm_last = 0x%lx\n", (long)gus->gf1.dma_data_pcm_last); 214
211 printk("gus->gf1.dma_data_pcm = 0x%lx\n", (long)gus->gf1.dma_data_pcm); 215 snd_printdd("gus->gf1.dma_data_pcm_last = 0x%lx\n",
212#endif 216 (long)gus->gf1.dma_data_pcm_last);
217 snd_printdd("gus->gf1.dma_data_pcm = 0x%lx\n",
218 (long)gus->gf1.dma_data_pcm);
219
213 spin_lock_irqsave(&gus->dma_lock, flags); 220 spin_lock_irqsave(&gus->dma_lock, flags);
214 if (synth) { 221 if (synth) {
215 if (gus->gf1.dma_data_synth_last) { 222 if (gus->gf1.dma_data_synth_last) {
diff --git a/sound/isa/gus/gus_irq.c b/sound/isa/gus/gus_irq.c
index 041894ddd014..2055aff71b50 100644
--- a/sound/isa/gus/gus_irq.c
+++ b/sound/isa/gus/gus_irq.c
@@ -41,7 +41,7 @@ __again:
41 if (status == 0) 41 if (status == 0)
42 return IRQ_RETVAL(handled); 42 return IRQ_RETVAL(handled);
43 handled = 1; 43 handled = 1;
44 // snd_printk("IRQ: status = 0x%x\n", status); 44 /* snd_printk(KERN_DEBUG "IRQ: status = 0x%x\n", status); */
45 if (status & 0x02) { 45 if (status & 0x02) {
46 STAT_ADD(gus->gf1.interrupt_stat_midi_in); 46 STAT_ADD(gus->gf1.interrupt_stat_midi_in);
47 if (gus->gf1.interrupt_handler_midi_in) 47 if (gus->gf1.interrupt_handler_midi_in)
@@ -65,7 +65,9 @@ __again:
65 continue; /* multi request */ 65 continue; /* multi request */
66 already |= _current_; /* mark request */ 66 already |= _current_; /* mark request */
67#if 0 67#if 0
68 printk("voice = %i, voice_status = 0x%x, voice_verify = %i\n", voice, voice_status, inb(GUSP(gus, GF1PAGE))); 68 printk(KERN_DEBUG "voice = %i, voice_status = 0x%x, "
69 "voice_verify = %i\n",
70 voice, voice_status, inb(GUSP(gus, GF1PAGE)));
69#endif 71#endif
70 pvoice = &gus->gf1.voices[voice]; 72 pvoice = &gus->gf1.voices[voice];
71 if (pvoice->use) { 73 if (pvoice->use) {
diff --git a/sound/isa/gus/gus_pcm.c b/sound/isa/gus/gus_pcm.c
index 38510aeb21c6..edb11eefdfe3 100644
--- a/sound/isa/gus/gus_pcm.c
+++ b/sound/isa/gus/gus_pcm.c
@@ -82,7 +82,10 @@ static int snd_gf1_pcm_block_change(struct snd_pcm_substream *substream,
82 82
83 count += offset & 31; 83 count += offset & 31;
84 offset &= ~31; 84 offset &= ~31;
85 // snd_printk("block change - offset = 0x%x, count = 0x%x\n", offset, count); 85 /*
86 snd_printk(KERN_DEBUG "block change - offset = 0x%x, count = 0x%x\n",
87 offset, count);
88 */
86 memset(&block, 0, sizeof(block)); 89 memset(&block, 0, sizeof(block));
87 block.cmd = SNDRV_GF1_DMA_IRQ; 90 block.cmd = SNDRV_GF1_DMA_IRQ;
88 if (snd_pcm_format_unsigned(runtime->format)) 91 if (snd_pcm_format_unsigned(runtime->format))
@@ -135,7 +138,11 @@ static void snd_gf1_pcm_trigger_up(struct snd_pcm_substream *substream)
135 curr = begin + (pcmp->bpos * pcmp->block_size) / runtime->channels; 138 curr = begin + (pcmp->bpos * pcmp->block_size) / runtime->channels;
136 end = curr + (pcmp->block_size / runtime->channels); 139 end = curr + (pcmp->block_size / runtime->channels);
137 end -= snd_pcm_format_width(runtime->format) == 16 ? 2 : 1; 140 end -= snd_pcm_format_width(runtime->format) == 16 ? 2 : 1;
138 // snd_printk("init: curr=0x%x, begin=0x%x, end=0x%x, ctrl=0x%x, ramp=0x%x, rate=0x%x\n", curr, begin, end, voice_ctrl, ramp_ctrl, rate); 141 /*
142 snd_printk(KERN_DEBUG "init: curr=0x%x, begin=0x%x, end=0x%x, "
143 "ctrl=0x%x, ramp=0x%x, rate=0x%x\n",
144 curr, begin, end, voice_ctrl, ramp_ctrl, rate);
145 */
139 pan = runtime->channels == 2 ? (!voice ? 1 : 14) : 8; 146 pan = runtime->channels == 2 ? (!voice ? 1 : 14) : 8;
140 vol = !voice ? gus->gf1.pcm_volume_level_left : gus->gf1.pcm_volume_level_right; 147 vol = !voice ? gus->gf1.pcm_volume_level_left : gus->gf1.pcm_volume_level_right;
141 spin_lock_irqsave(&gus->reg_lock, flags); 148 spin_lock_irqsave(&gus->reg_lock, flags);
@@ -205,9 +212,11 @@ static void snd_gf1_pcm_interrupt_wave(struct snd_gus_card * gus,
205 ramp_ctrl = (snd_gf1_read8(gus, SNDRV_GF1_VB_VOLUME_CONTROL) & ~0xa4) | 0x03; 212 ramp_ctrl = (snd_gf1_read8(gus, SNDRV_GF1_VB_VOLUME_CONTROL) & ~0xa4) | 0x03;
206#if 0 213#if 0
207 snd_gf1_select_voice(gus, pvoice->number); 214 snd_gf1_select_voice(gus, pvoice->number);
208 printk("position = 0x%x\n", (snd_gf1_read_addr(gus, SNDRV_GF1_VA_CURRENT, voice_ctrl & 4) >> 4)); 215 printk(KERN_DEBUG "position = 0x%x\n",
216 (snd_gf1_read_addr(gus, SNDRV_GF1_VA_CURRENT, voice_ctrl & 4) >> 4));
209 snd_gf1_select_voice(gus, pcmp->pvoices[1]->number); 217 snd_gf1_select_voice(gus, pcmp->pvoices[1]->number);
210 printk("position = 0x%x\n", (snd_gf1_read_addr(gus, SNDRV_GF1_VA_CURRENT, voice_ctrl & 4) >> 4)); 218 printk(KERN_DEBUG "position = 0x%x\n",
219 (snd_gf1_read_addr(gus, SNDRV_GF1_VA_CURRENT, voice_ctrl & 4) >> 4));
211 snd_gf1_select_voice(gus, pvoice->number); 220 snd_gf1_select_voice(gus, pvoice->number);
212#endif 221#endif
213 pcmp->bpos++; 222 pcmp->bpos++;
@@ -299,7 +308,11 @@ static int snd_gf1_pcm_poke_block(struct snd_gus_card *gus, unsigned char *buf,
299 unsigned int len; 308 unsigned int len;
300 unsigned long flags; 309 unsigned long flags;
301 310
302 // printk("poke block; buf = 0x%x, pos = %i, count = %i, port = 0x%x\n", (int)buf, pos, count, gus->gf1.port); 311 /*
312 printk(KERN_DEBUG
313 "poke block; buf = 0x%x, pos = %i, count = %i, port = 0x%x\n",
314 (int)buf, pos, count, gus->gf1.port);
315 */
303 while (count > 0) { 316 while (count > 0) {
304 len = count; 317 len = count;
305 if (len > 512) /* limit, to allow IRQ */ 318 if (len > 512) /* limit, to allow IRQ */
@@ -680,7 +693,8 @@ static int snd_gf1_pcm_playback_open(struct snd_pcm_substream *substream)
680 runtime->private_free = snd_gf1_pcm_playback_free; 693 runtime->private_free = snd_gf1_pcm_playback_free;
681 694
682#if 0 695#if 0
683 printk("playback.buffer = 0x%lx, gf1.pcm_buffer = 0x%lx\n", (long) pcm->playback.buffer, (long) gus->gf1.pcm_buffer); 696 printk(KERN_DEBUG "playback.buffer = 0x%lx, gf1.pcm_buffer = 0x%lx\n",
697 (long) pcm->playback.buffer, (long) gus->gf1.pcm_buffer);
684#endif 698#endif
685 if ((err = snd_gf1_dma_init(gus)) < 0) 699 if ((err = snd_gf1_dma_init(gus)) < 0)
686 return err; 700 return err;
diff --git a/sound/isa/gus/gus_uart.c b/sound/isa/gus/gus_uart.c
index f0af3f79b08b..21cc42e4c4be 100644
--- a/sound/isa/gus/gus_uart.c
+++ b/sound/isa/gus/gus_uart.c
@@ -129,8 +129,14 @@ static int snd_gf1_uart_input_open(struct snd_rawmidi_substream *substream)
129 } 129 }
130 spin_unlock_irqrestore(&gus->uart_cmd_lock, flags); 130 spin_unlock_irqrestore(&gus->uart_cmd_lock, flags);
131#if 0 131#if 0
132 snd_printk("read init - enable = %i, cmd = 0x%x, stat = 0x%x\n", gus->uart_enable, gus->gf1.uart_cmd, snd_gf1_uart_stat(gus)); 132 snd_printk(KERN_DEBUG
133 snd_printk("[0x%x] reg (ctrl/status) = 0x%x, reg (data) = 0x%x (page = 0x%x)\n", gus->gf1.port + 0x100, inb(gus->gf1.port + 0x100), inb(gus->gf1.port + 0x101), inb(gus->gf1.port + 0x102)); 133 "read init - enable = %i, cmd = 0x%x, stat = 0x%x\n",
134 gus->uart_enable, gus->gf1.uart_cmd, snd_gf1_uart_stat(gus));
135 snd_printk(KERN_DEBUG
136 "[0x%x] reg (ctrl/status) = 0x%x, reg (data) = 0x%x "
137 "(page = 0x%x)\n",
138 gus->gf1.port + 0x100, inb(gus->gf1.port + 0x100),
139 inb(gus->gf1.port + 0x101), inb(gus->gf1.port + 0x102));
134#endif 140#endif
135 return 0; 141 return 0;
136} 142}
diff --git a/sound/isa/gus/gusclassic.c b/sound/isa/gus/gusclassic.c
index 426532a4d730..086b8f0e0f94 100644
--- a/sound/isa/gus/gusclassic.c
+++ b/sound/isa/gus/gusclassic.c
@@ -148,9 +148,9 @@ static int __devinit snd_gusclassic_probe(struct device *dev, unsigned int n)
148 struct snd_gus_card *gus; 148 struct snd_gus_card *gus;
149 int error; 149 int error;
150 150
151 card = snd_card_new(index[n], id[n], THIS_MODULE, 0); 151 error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card);
152 if (!card) 152 if (error < 0)
153 return -EINVAL; 153 return error;
154 154
155 if (pcm_channels[n] < 2) 155 if (pcm_channels[n] < 2)
156 pcm_channels[n] = 2; 156 pcm_channels[n] = 2;
diff --git a/sound/isa/gus/gusextreme.c b/sound/isa/gus/gusextreme.c
index 7ad4c3b41a84..180a8dea6bd9 100644
--- a/sound/isa/gus/gusextreme.c
+++ b/sound/isa/gus/gusextreme.c
@@ -241,9 +241,9 @@ static int __devinit snd_gusextreme_probe(struct device *dev, unsigned int n)
241 struct snd_opl3 *opl3; 241 struct snd_opl3 *opl3;
242 int error; 242 int error;
243 243
244 card = snd_card_new(index[n], id[n], THIS_MODULE, 0); 244 error = snd_card_create(index[n], id[n], THIS_MODULE, 0, &card);
245 if (!card) 245 if (error < 0)
246 return -EINVAL; 246 return error;
247 247
248 if (mpu_port[n] == SNDRV_AUTO_PORT) 248 if (mpu_port[n] == SNDRV_AUTO_PORT)
249 mpu_port[n] = 0; 249 mpu_port[n] = 0;
diff --git a/sound/isa/gus/gusmax.c b/sound/isa/gus/gusmax.c
index f94c1976e632..f26eac8d8110 100644
--- a/sound/isa/gus/gusmax.c
+++ b/sound/isa/gus/gusmax.c
@@ -214,10 +214,10 @@ static int __devinit snd_gusmax_probe(struct device *pdev, unsigned int dev)
214 struct snd_wss *wss; 214 struct snd_wss *wss;
215 struct snd_gusmax *maxcard; 215 struct snd_gusmax *maxcard;
216 216
217 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 217 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
218 sizeof(struct snd_gusmax)); 218 sizeof(struct snd_gusmax), &card);
219 if (card == NULL) 219 if (err < 0)
220 return -ENOMEM; 220 return err;
221 card->private_free = snd_gusmax_free; 221 card->private_free = snd_gusmax_free;
222 maxcard = (struct snd_gusmax *)card->private_data; 222 maxcard = (struct snd_gusmax *)card->private_data;
223 maxcard->card = card; 223 maxcard->card = card;
diff --git a/sound/isa/gus/interwave.c b/sound/isa/gus/interwave.c
index 5faecfb602d3..534a6eced2b8 100644
--- a/sound/isa/gus/interwave.c
+++ b/sound/isa/gus/interwave.c
@@ -170,7 +170,7 @@ static void snd_interwave_i2c_setlines(struct snd_i2c_bus *bus, int ctrl, int da
170 unsigned long port = bus->private_value; 170 unsigned long port = bus->private_value;
171 171
172#if 0 172#if 0
173 printk("i2c_setlines - 0x%lx <- %i,%i\n", port, ctrl, data); 173 printk(KERN_DEBUG "i2c_setlines - 0x%lx <- %i,%i\n", port, ctrl, data);
174#endif 174#endif
175 outb((data << 1) | ctrl, port); 175 outb((data << 1) | ctrl, port);
176 udelay(10); 176 udelay(10);
@@ -183,7 +183,7 @@ static int snd_interwave_i2c_getclockline(struct snd_i2c_bus *bus)
183 183
184 res = inb(port) & 1; 184 res = inb(port) & 1;
185#if 0 185#if 0
186 printk("i2c_getclockline - 0x%lx -> %i\n", port, res); 186 printk(KERN_DEBUG "i2c_getclockline - 0x%lx -> %i\n", port, res);
187#endif 187#endif
188 return res; 188 return res;
189} 189}
@@ -197,7 +197,7 @@ static int snd_interwave_i2c_getdataline(struct snd_i2c_bus *bus, int ack)
197 udelay(10); 197 udelay(10);
198 res = (inb(port) & 2) >> 1; 198 res = (inb(port) & 2) >> 1;
199#if 0 199#if 0
200 printk("i2c_getdataline - 0x%lx -> %i\n", port, res); 200 printk(KERN_DEBUG "i2c_getdataline - 0x%lx -> %i\n", port, res);
201#endif 201#endif
202 return res; 202 return res;
203} 203}
@@ -342,7 +342,8 @@ static void __devinit snd_interwave_bank_sizes(struct snd_gus_card * gus, int *s
342 snd_gf1_poke(gus, local, d); 342 snd_gf1_poke(gus, local, d);
343 snd_gf1_poke(gus, local + 1, d + 1); 343 snd_gf1_poke(gus, local + 1, d + 1);
344#if 0 344#if 0
345 printk("d = 0x%x, local = 0x%x, local + 1 = 0x%x, idx << 22 = 0x%x\n", 345 printk(KERN_DEBUG "d = 0x%x, local = 0x%x, "
346 "local + 1 = 0x%x, idx << 22 = 0x%x\n",
346 d, 347 d,
347 snd_gf1_peek(gus, local), 348 snd_gf1_peek(gus, local),
348 snd_gf1_peek(gus, local + 1), 349 snd_gf1_peek(gus, local + 1),
@@ -356,7 +357,8 @@ static void __devinit snd_interwave_bank_sizes(struct snd_gus_card * gus, int *s
356 } 357 }
357 } 358 }
358#if 0 359#if 0
359 printk("sizes: %i %i %i %i\n", sizes[0], sizes[1], sizes[2], sizes[3]); 360 printk(KERN_DEBUG "sizes: %i %i %i %i\n",
361 sizes[0], sizes[1], sizes[2], sizes[3]);
360#endif 362#endif
361} 363}
362 364
@@ -410,12 +412,12 @@ static void __devinit snd_interwave_detect_memory(struct snd_gus_card * gus)
410 lmct = (psizes[3] << 24) | (psizes[2] << 16) | 412 lmct = (psizes[3] << 24) | (psizes[2] << 16) |
411 (psizes[1] << 8) | psizes[0]; 413 (psizes[1] << 8) | psizes[0];
412#if 0 414#if 0
413 printk("lmct = 0x%08x\n", lmct); 415 printk(KERN_DEBUG "lmct = 0x%08x\n", lmct);
414#endif 416#endif
415 for (i = 0; i < ARRAY_SIZE(lmc); i++) 417 for (i = 0; i < ARRAY_SIZE(lmc); i++)
416 if (lmct == lmc[i]) { 418 if (lmct == lmc[i]) {
417#if 0 419#if 0
418 printk("found !!! %i\n", i); 420 printk(KERN_DEBUG "found !!! %i\n", i);
419#endif 421#endif
420 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | i); 422 snd_gf1_write16(gus, SNDRV_GF1_GW_MEMORY_CONFIG, (snd_gf1_look16(gus, SNDRV_GF1_GW_MEMORY_CONFIG) & 0xfff0) | i);
421 snd_interwave_bank_sizes(gus, psizes); 423 snd_interwave_bank_sizes(gus, psizes);
@@ -626,20 +628,22 @@ static void snd_interwave_free(struct snd_card *card)
626 free_irq(iwcard->irq, (void *)iwcard); 628 free_irq(iwcard->irq, (void *)iwcard);
627} 629}
628 630
629static struct snd_card *snd_interwave_card_new(int dev) 631static int snd_interwave_card_new(int dev, struct snd_card **cardp)
630{ 632{
631 struct snd_card *card; 633 struct snd_card *card;
632 struct snd_interwave *iwcard; 634 struct snd_interwave *iwcard;
635 int err;
633 636
634 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 637 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
635 sizeof(struct snd_interwave)); 638 sizeof(struct snd_interwave), &card);
636 if (card == NULL) 639 if (err < 0)
637 return NULL; 640 return err;
638 iwcard = card->private_data; 641 iwcard = card->private_data;
639 iwcard->card = card; 642 iwcard->card = card;
640 iwcard->irq = -1; 643 iwcard->irq = -1;
641 card->private_free = snd_interwave_free; 644 card->private_free = snd_interwave_free;
642 return card; 645 *cardp = card;
646 return 0;
643} 647}
644 648
645static int __devinit snd_interwave_probe(struct snd_card *card, int dev) 649static int __devinit snd_interwave_probe(struct snd_card *card, int dev)
@@ -778,9 +782,9 @@ static int __devinit snd_interwave_isa_probe1(int dev, struct device *devptr)
778 struct snd_card *card; 782 struct snd_card *card;
779 int err; 783 int err;
780 784
781 card = snd_interwave_card_new(dev); 785 err = snd_interwave_card_new(dev, &card);
782 if (! card) 786 if (err < 0)
783 return -ENOMEM; 787 return err;
784 788
785 snd_card_set_dev(card, devptr); 789 snd_card_set_dev(card, devptr);
786 if ((err = snd_interwave_probe(card, dev)) < 0) { 790 if ((err = snd_interwave_probe(card, dev)) < 0) {
@@ -876,9 +880,9 @@ static int __devinit snd_interwave_pnp_detect(struct pnp_card_link *pcard,
876 if (dev >= SNDRV_CARDS) 880 if (dev >= SNDRV_CARDS)
877 return -ENODEV; 881 return -ENODEV;
878 882
879 card = snd_interwave_card_new(dev); 883 res = snd_interwave_card_new(dev, &card);
880 if (! card) 884 if (res < 0)
881 return -ENOMEM; 885 return res;
882 886
883 if ((res = snd_interwave_pnp(dev, card->private_data, pcard, pid)) < 0) { 887 if ((res = snd_interwave_pnp(dev, card->private_data, pcard, pid)) < 0) {
884 snd_card_free(card); 888 snd_card_free(card);
diff --git a/sound/isa/msnd/Makefile b/sound/isa/msnd/Makefile
new file mode 100644
index 000000000000..2171c0aa2f62
--- /dev/null
+++ b/sound/isa/msnd/Makefile
@@ -0,0 +1,9 @@
1
2snd-msnd-lib-objs := msnd.o msnd_midi.o msnd_pinnacle_mixer.o
3snd-msnd-pinnacle-objs := msnd_pinnacle.o
4snd-msnd-classic-objs := msnd_classic.o
5
6# Toplevel Module Dependency
7obj-$(CONFIG_SND_MSND_PINNACLE) += snd-msnd-pinnacle.o snd-msnd-lib.o
8obj-$(CONFIG_SND_MSND_CLASSIC) += snd-msnd-classic.o snd-msnd-lib.o
9
diff --git a/sound/isa/msnd/msnd.c b/sound/isa/msnd/msnd.c
new file mode 100644
index 000000000000..906454413ed2
--- /dev/null
+++ b/sound/isa/msnd/msnd.c
@@ -0,0 +1,705 @@
1/*********************************************************************
2 *
3 * 2002/06/30 Karsten Wiese:
4 * removed kernel-version dependencies.
5 * ripped from linux kernel 2.4.18 (OSS Implementation) by me.
6 * In the OSS Version, this file is compiled to a separate MODULE,
7 * that is used by the pinnacle and the classic driver.
8 * since there is no classic driver for alsa yet (i dont have a classic
9 * & writing one blindfold is difficult) this file's object is statically
10 * linked into the pinnacle-driver-module for now. look for the string
11 * "uncomment this to make this a module again"
12 * to do guess what.
13 *
14 * the following is a copy of the 2.4.18 OSS FREE file-heading comment:
15 *
16 * msnd.c - Driver Base
17 *
18 * Turtle Beach MultiSound Sound Card Driver for Linux
19 *
20 * Copyright (C) 1998 Andrew Veliath
21 *
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 *
36 ********************************************************************/
37
38#include <linux/kernel.h>
39#include <linux/types.h>
40#include <linux/interrupt.h>
41#include <linux/io.h>
42#include <linux/fs.h>
43#include <linux/delay.h>
44
45#include <sound/core.h>
46#include <sound/initval.h>
47#include <sound/pcm.h>
48#include <sound/pcm_params.h>
49
50#include "msnd.h"
51
52#define LOGNAME "msnd"
53
54
55void snd_msnd_init_queue(void *base, int start, int size)
56{
57 writew(PCTODSP_BASED(start), base + JQS_wStart);
58 writew(PCTODSP_OFFSET(size) - 1, base + JQS_wSize);
59 writew(0, base + JQS_wHead);
60 writew(0, base + JQS_wTail);
61}
62EXPORT_SYMBOL(snd_msnd_init_queue);
63
64static int snd_msnd_wait_TXDE(struct snd_msnd *dev)
65{
66 unsigned int io = dev->io;
67 int timeout = 1000;
68
69 while (timeout-- > 0)
70 if (inb(io + HP_ISR) & HPISR_TXDE)
71 return 0;
72
73 return -EIO;
74}
75
76static int snd_msnd_wait_HC0(struct snd_msnd *dev)
77{
78 unsigned int io = dev->io;
79 int timeout = 1000;
80
81 while (timeout-- > 0)
82 if (!(inb(io + HP_CVR) & HPCVR_HC))
83 return 0;
84
85 return -EIO;
86}
87
88int snd_msnd_send_dsp_cmd(struct snd_msnd *dev, u8 cmd)
89{
90 unsigned long flags;
91
92 spin_lock_irqsave(&dev->lock, flags);
93 if (snd_msnd_wait_HC0(dev) == 0) {
94 outb(cmd, dev->io + HP_CVR);
95 spin_unlock_irqrestore(&dev->lock, flags);
96 return 0;
97 }
98 spin_unlock_irqrestore(&dev->lock, flags);
99
100 snd_printd(KERN_ERR LOGNAME ": Send DSP command timeout\n");
101
102 return -EIO;
103}
104EXPORT_SYMBOL(snd_msnd_send_dsp_cmd);
105
106int snd_msnd_send_word(struct snd_msnd *dev, unsigned char high,
107 unsigned char mid, unsigned char low)
108{
109 unsigned int io = dev->io;
110
111 if (snd_msnd_wait_TXDE(dev) == 0) {
112 outb(high, io + HP_TXH);
113 outb(mid, io + HP_TXM);
114 outb(low, io + HP_TXL);
115 return 0;
116 }
117
118 snd_printd(KERN_ERR LOGNAME ": Send host word timeout\n");
119
120 return -EIO;
121}
122EXPORT_SYMBOL(snd_msnd_send_word);
123
124int snd_msnd_upload_host(struct snd_msnd *dev, const u8 *bin, int len)
125{
126 int i;
127
128 if (len % 3 != 0) {
129 snd_printk(KERN_ERR LOGNAME
130 ": Upload host data not multiple of 3!\n");
131 return -EINVAL;
132 }
133
134 for (i = 0; i < len; i += 3)
135 if (snd_msnd_send_word(dev, bin[i], bin[i + 1], bin[i + 2]))
136 return -EIO;
137
138 inb(dev->io + HP_RXL);
139 inb(dev->io + HP_CVR);
140
141 return 0;
142}
143EXPORT_SYMBOL(snd_msnd_upload_host);
144
145int snd_msnd_enable_irq(struct snd_msnd *dev)
146{
147 unsigned long flags;
148
149 if (dev->irq_ref++)
150 return 0;
151
152 snd_printdd(LOGNAME ": Enabling IRQ\n");
153
154 spin_lock_irqsave(&dev->lock, flags);
155 if (snd_msnd_wait_TXDE(dev) == 0) {
156 outb(inb(dev->io + HP_ICR) | HPICR_TREQ, dev->io + HP_ICR);
157 if (dev->type == msndClassic)
158 outb(dev->irqid, dev->io + HP_IRQM);
159
160 outb(inb(dev->io + HP_ICR) & ~HPICR_TREQ, dev->io + HP_ICR);
161 outb(inb(dev->io + HP_ICR) | HPICR_RREQ, dev->io + HP_ICR);
162 enable_irq(dev->irq);
163 snd_msnd_init_queue(dev->DSPQ, dev->dspq_data_buff,
164 dev->dspq_buff_size);
165 spin_unlock_irqrestore(&dev->lock, flags);
166 return 0;
167 }
168 spin_unlock_irqrestore(&dev->lock, flags);
169
170 snd_printd(KERN_ERR LOGNAME ": Enable IRQ failed\n");
171
172 return -EIO;
173}
174EXPORT_SYMBOL(snd_msnd_enable_irq);
175
176int snd_msnd_disable_irq(struct snd_msnd *dev)
177{
178 unsigned long flags;
179
180 if (--dev->irq_ref > 0)
181 return 0;
182
183 if (dev->irq_ref < 0)
184 snd_printd(KERN_WARNING LOGNAME ": IRQ ref count is %d\n",
185 dev->irq_ref);
186
187 snd_printdd(LOGNAME ": Disabling IRQ\n");
188
189 spin_lock_irqsave(&dev->lock, flags);
190 if (snd_msnd_wait_TXDE(dev) == 0) {
191 outb(inb(dev->io + HP_ICR) & ~HPICR_RREQ, dev->io + HP_ICR);
192 if (dev->type == msndClassic)
193 outb(HPIRQ_NONE, dev->io + HP_IRQM);
194 disable_irq(dev->irq);
195 spin_unlock_irqrestore(&dev->lock, flags);
196 return 0;
197 }
198 spin_unlock_irqrestore(&dev->lock, flags);
199
200 snd_printd(KERN_ERR LOGNAME ": Disable IRQ failed\n");
201
202 return -EIO;
203}
204EXPORT_SYMBOL(snd_msnd_disable_irq);
205
206static inline long get_play_delay_jiffies(struct snd_msnd *chip, long size)
207{
208 long tmp = (size * HZ * chip->play_sample_size) / 8;
209 return tmp / (chip->play_sample_rate * chip->play_channels);
210}
211
212static void snd_msnd_dsp_write_flush(struct snd_msnd *chip)
213{
214 if (!(chip->mode & FMODE_WRITE) || !test_bit(F_WRITING, &chip->flags))
215 return;
216 set_bit(F_WRITEFLUSH, &chip->flags);
217/* interruptible_sleep_on_timeout(
218 &chip->writeflush,
219 get_play_delay_jiffies(&chip, chip->DAPF.len));*/
220 clear_bit(F_WRITEFLUSH, &chip->flags);
221 if (!signal_pending(current))
222 schedule_timeout_interruptible(
223 get_play_delay_jiffies(chip, chip->play_period_bytes));
224 clear_bit(F_WRITING, &chip->flags);
225}
226
227void snd_msnd_dsp_halt(struct snd_msnd *chip, struct file *file)
228{
229 if ((file ? file->f_mode : chip->mode) & FMODE_READ) {
230 clear_bit(F_READING, &chip->flags);
231 snd_msnd_send_dsp_cmd(chip, HDEX_RECORD_STOP);
232 snd_msnd_disable_irq(chip);
233 if (file) {
234 snd_printd(KERN_INFO LOGNAME
235 ": Stopping read for %p\n", file);
236 chip->mode &= ~FMODE_READ;
237 }
238 clear_bit(F_AUDIO_READ_INUSE, &chip->flags);
239 }
240 if ((file ? file->f_mode : chip->mode) & FMODE_WRITE) {
241 if (test_bit(F_WRITING, &chip->flags)) {
242 snd_msnd_dsp_write_flush(chip);
243 snd_msnd_send_dsp_cmd(chip, HDEX_PLAY_STOP);
244 }
245 snd_msnd_disable_irq(chip);
246 if (file) {
247 snd_printd(KERN_INFO
248 LOGNAME ": Stopping write for %p\n", file);
249 chip->mode &= ~FMODE_WRITE;
250 }
251 clear_bit(F_AUDIO_WRITE_INUSE, &chip->flags);
252 }
253}
254EXPORT_SYMBOL(snd_msnd_dsp_halt);
255
256
257int snd_msnd_DARQ(struct snd_msnd *chip, int bank)
258{
259 int /*size, n,*/ timeout = 3;
260 u16 wTmp;
261 /* void *DAQD; */
262
263 /* Increment the tail and check for queue wrap */
264 wTmp = readw(chip->DARQ + JQS_wTail) + PCTODSP_OFFSET(DAQDS__size);
265 if (wTmp > readw(chip->DARQ + JQS_wSize))
266 wTmp = 0;
267 while (wTmp == readw(chip->DARQ + JQS_wHead) && timeout--)
268 udelay(1);
269
270 if (chip->capturePeriods == 2) {
271 void *pDAQ = chip->mappedbase + DARQ_DATA_BUFF +
272 bank * DAQDS__size + DAQDS_wStart;
273 unsigned short offset = 0x3000 + chip->capturePeriodBytes;
274
275 if (readw(pDAQ) != PCTODSP_BASED(0x3000))
276 offset = 0x3000;
277 writew(PCTODSP_BASED(offset), pDAQ);
278 }
279
280 writew(wTmp, chip->DARQ + JQS_wTail);
281
282#if 0
283 /* Get our digital audio queue struct */
284 DAQD = bank * DAQDS__size + chip->mappedbase + DARQ_DATA_BUFF;
285
286 /* Get length of data */
287 size = readw(DAQD + DAQDS_wSize);
288
289 /* Read data from the head (unprotected bank 1 access okay
290 since this is only called inside an interrupt) */
291 outb(HPBLKSEL_1, chip->io + HP_BLKS);
292 n = msnd_fifo_write(&chip->DARF,
293 (char *)(chip->base + bank * DAR_BUFF_SIZE),
294 size, 0);
295 if (n <= 0) {
296 outb(HPBLKSEL_0, chip->io + HP_BLKS);
297 return n;
298 }
299 outb(HPBLKSEL_0, chip->io + HP_BLKS);
300#endif
301
302 return 1;
303}
304EXPORT_SYMBOL(snd_msnd_DARQ);
305
306int snd_msnd_DAPQ(struct snd_msnd *chip, int start)
307{
308 u16 DAPQ_tail;
309 int protect = start, nbanks = 0;
310 void *DAQD;
311 static int play_banks_submitted;
312 /* unsigned long flags;
313 spin_lock_irqsave(&chip->lock, flags); not necessary */
314
315 DAPQ_tail = readw(chip->DAPQ + JQS_wTail);
316 while (DAPQ_tail != readw(chip->DAPQ + JQS_wHead) || start) {
317 int bank_num = DAPQ_tail / PCTODSP_OFFSET(DAQDS__size);
318
319 if (start) {
320 start = 0;
321 play_banks_submitted = 0;
322 }
323
324 /* Get our digital audio queue struct */
325 DAQD = bank_num * DAQDS__size + chip->mappedbase +
326 DAPQ_DATA_BUFF;
327
328 /* Write size of this bank */
329 writew(chip->play_period_bytes, DAQD + DAQDS_wSize);
330 if (play_banks_submitted < 3)
331 ++play_banks_submitted;
332 else if (chip->playPeriods == 2) {
333 unsigned short offset = chip->play_period_bytes;
334
335 if (readw(DAQD + DAQDS_wStart) != PCTODSP_BASED(0x0))
336 offset = 0;
337
338 writew(PCTODSP_BASED(offset), DAQD + DAQDS_wStart);
339 }
340 ++nbanks;
341
342 /* Then advance the tail */
343 /*
344 if (protect)
345 snd_printd(KERN_INFO "B %X %lX\n",
346 bank_num, xtime.tv_usec);
347 */
348
349 DAPQ_tail = (++bank_num % 3) * PCTODSP_OFFSET(DAQDS__size);
350 writew(DAPQ_tail, chip->DAPQ + JQS_wTail);
351 /* Tell the DSP to play the bank */
352 snd_msnd_send_dsp_cmd(chip, HDEX_PLAY_START);
353 if (protect)
354 if (2 == bank_num)
355 break;
356 }
357 /*
358 if (protect)
359 snd_printd(KERN_INFO "%lX\n", xtime.tv_usec);
360 */
361 /* spin_unlock_irqrestore(&chip->lock, flags); not necessary */
362 return nbanks;
363}
364EXPORT_SYMBOL(snd_msnd_DAPQ);
365
366static void snd_msnd_play_reset_queue(struct snd_msnd *chip,
367 unsigned int pcm_periods,
368 unsigned int pcm_count)
369{
370 int n;
371 void *pDAQ = chip->mappedbase + DAPQ_DATA_BUFF;
372
373 chip->last_playbank = -1;
374 chip->playLimit = pcm_count * (pcm_periods - 1);
375 chip->playPeriods = pcm_periods;
376 writew(PCTODSP_OFFSET(0 * DAQDS__size), chip->DAPQ + JQS_wHead);
377 writew(PCTODSP_OFFSET(0 * DAQDS__size), chip->DAPQ + JQS_wTail);
378
379 chip->play_period_bytes = pcm_count;
380
381 for (n = 0; n < pcm_periods; ++n, pDAQ += DAQDS__size) {
382 writew(PCTODSP_BASED((u32)(pcm_count * n)),
383 pDAQ + DAQDS_wStart);
384 writew(0, pDAQ + DAQDS_wSize);
385 writew(1, pDAQ + DAQDS_wFormat);
386 writew(chip->play_sample_size, pDAQ + DAQDS_wSampleSize);
387 writew(chip->play_channels, pDAQ + DAQDS_wChannels);
388 writew(chip->play_sample_rate, pDAQ + DAQDS_wSampleRate);
389 writew(HIMT_PLAY_DONE * 0x100 + n, pDAQ + DAQDS_wIntMsg);
390 writew(n, pDAQ + DAQDS_wFlags);
391 }
392}
393
394static void snd_msnd_capture_reset_queue(struct snd_msnd *chip,
395 unsigned int pcm_periods,
396 unsigned int pcm_count)
397{
398 int n;
399 void *pDAQ;
400 /* unsigned long flags; */
401
402 /* snd_msnd_init_queue(chip->DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE); */
403
404 chip->last_recbank = 2;
405 chip->captureLimit = pcm_count * (pcm_periods - 1);
406 chip->capturePeriods = pcm_periods;
407 writew(PCTODSP_OFFSET(0 * DAQDS__size), chip->DARQ + JQS_wHead);
408 writew(PCTODSP_OFFSET(chip->last_recbank * DAQDS__size),
409 chip->DARQ + JQS_wTail);
410
411#if 0 /* Critical section: bank 1 access. this is how the OSS driver does it:*/
412 spin_lock_irqsave(&chip->lock, flags);
413 outb(HPBLKSEL_1, chip->io + HP_BLKS);
414 memset_io(chip->mappedbase, 0, DAR_BUFF_SIZE * 3);
415 outb(HPBLKSEL_0, chip->io + HP_BLKS);
416 spin_unlock_irqrestore(&chip->lock, flags);
417#endif
418
419 chip->capturePeriodBytes = pcm_count;
420 snd_printdd("snd_msnd_capture_reset_queue() %i\n", pcm_count);
421
422 pDAQ = chip->mappedbase + DARQ_DATA_BUFF;
423
424 for (n = 0; n < pcm_periods; ++n, pDAQ += DAQDS__size) {
425 u32 tmp = pcm_count * n;
426
427 writew(PCTODSP_BASED(tmp + 0x3000), pDAQ + DAQDS_wStart);
428 writew(pcm_count, pDAQ + DAQDS_wSize);
429 writew(1, pDAQ + DAQDS_wFormat);
430 writew(chip->capture_sample_size, pDAQ + DAQDS_wSampleSize);
431 writew(chip->capture_channels, pDAQ + DAQDS_wChannels);
432 writew(chip->capture_sample_rate, pDAQ + DAQDS_wSampleRate);
433 writew(HIMT_RECORD_DONE * 0x100 + n, pDAQ + DAQDS_wIntMsg);
434 writew(n, pDAQ + DAQDS_wFlags);
435 }
436}
437
438static struct snd_pcm_hardware snd_msnd_playback = {
439 .info = SNDRV_PCM_INFO_MMAP |
440 SNDRV_PCM_INFO_INTERLEAVED |
441 SNDRV_PCM_INFO_MMAP_VALID,
442 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
443 .rates = SNDRV_PCM_RATE_8000_48000,
444 .rate_min = 8000,
445 .rate_max = 48000,
446 .channels_min = 1,
447 .channels_max = 2,
448 .buffer_bytes_max = 0x3000,
449 .period_bytes_min = 0x40,
450 .period_bytes_max = 0x1800,
451 .periods_min = 2,
452 .periods_max = 3,
453 .fifo_size = 0,
454};
455
456static struct snd_pcm_hardware snd_msnd_capture = {
457 .info = SNDRV_PCM_INFO_MMAP |
458 SNDRV_PCM_INFO_INTERLEAVED |
459 SNDRV_PCM_INFO_MMAP_VALID,
460 .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
461 .rates = SNDRV_PCM_RATE_8000_48000,
462 .rate_min = 8000,
463 .rate_max = 48000,
464 .channels_min = 1,
465 .channels_max = 2,
466 .buffer_bytes_max = 0x3000,
467 .period_bytes_min = 0x40,
468 .period_bytes_max = 0x1800,
469 .periods_min = 2,
470 .periods_max = 3,
471 .fifo_size = 0,
472};
473
474
475static int snd_msnd_playback_open(struct snd_pcm_substream *substream)
476{
477 struct snd_pcm_runtime *runtime = substream->runtime;
478 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
479
480 set_bit(F_AUDIO_WRITE_INUSE, &chip->flags);
481 clear_bit(F_WRITING, &chip->flags);
482 snd_msnd_enable_irq(chip);
483
484 runtime->dma_area = chip->mappedbase;
485 runtime->dma_bytes = 0x3000;
486
487 chip->playback_substream = substream;
488 runtime->hw = snd_msnd_playback;
489 return 0;
490}
491
492static int snd_msnd_playback_close(struct snd_pcm_substream *substream)
493{
494 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
495
496 snd_msnd_disable_irq(chip);
497 clear_bit(F_AUDIO_WRITE_INUSE, &chip->flags);
498 return 0;
499}
500
501
502static int snd_msnd_playback_hw_params(struct snd_pcm_substream *substream,
503 struct snd_pcm_hw_params *params)
504{
505 int i;
506 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
507 void *pDAQ = chip->mappedbase + DAPQ_DATA_BUFF;
508
509 chip->play_sample_size = snd_pcm_format_width(params_format(params));
510 chip->play_channels = params_channels(params);
511 chip->play_sample_rate = params_rate(params);
512
513 for (i = 0; i < 3; ++i, pDAQ += DAQDS__size) {
514 writew(chip->play_sample_size, pDAQ + DAQDS_wSampleSize);
515 writew(chip->play_channels, pDAQ + DAQDS_wChannels);
516 writew(chip->play_sample_rate, pDAQ + DAQDS_wSampleRate);
517 }
518 /* dont do this here:
519 * snd_msnd_calibrate_adc(chip->play_sample_rate);
520 */
521
522 return 0;
523}
524
525static int snd_msnd_playback_prepare(struct snd_pcm_substream *substream)
526{
527 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
528 unsigned int pcm_size = snd_pcm_lib_buffer_bytes(substream);
529 unsigned int pcm_count = snd_pcm_lib_period_bytes(substream);
530 unsigned int pcm_periods = pcm_size / pcm_count;
531
532 snd_msnd_play_reset_queue(chip, pcm_periods, pcm_count);
533 chip->playDMAPos = 0;
534 return 0;
535}
536
537static int snd_msnd_playback_trigger(struct snd_pcm_substream *substream,
538 int cmd)
539{
540 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
541 int result = 0;
542
543 if (cmd == SNDRV_PCM_TRIGGER_START) {
544 snd_printdd("snd_msnd_playback_trigger(START)\n");
545 chip->banksPlayed = 0;
546 set_bit(F_WRITING, &chip->flags);
547 snd_msnd_DAPQ(chip, 1);
548 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
549 snd_printdd("snd_msnd_playback_trigger(STop)\n");
550 /* interrupt diagnostic, comment this out later */
551 clear_bit(F_WRITING, &chip->flags);
552 snd_msnd_send_dsp_cmd(chip, HDEX_PLAY_STOP);
553 } else {
554 snd_printd(KERN_ERR "snd_msnd_playback_trigger(?????)\n");
555 result = -EINVAL;
556 }
557
558 snd_printdd("snd_msnd_playback_trigger() ENDE\n");
559 return result;
560}
561
562static snd_pcm_uframes_t
563snd_msnd_playback_pointer(struct snd_pcm_substream *substream)
564{
565 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
566
567 return bytes_to_frames(substream->runtime, chip->playDMAPos);
568}
569
570
571static struct snd_pcm_ops snd_msnd_playback_ops = {
572 .open = snd_msnd_playback_open,
573 .close = snd_msnd_playback_close,
574 .ioctl = snd_pcm_lib_ioctl,
575 .hw_params = snd_msnd_playback_hw_params,
576 .prepare = snd_msnd_playback_prepare,
577 .trigger = snd_msnd_playback_trigger,
578 .pointer = snd_msnd_playback_pointer,
579};
580
581static int snd_msnd_capture_open(struct snd_pcm_substream *substream)
582{
583 struct snd_pcm_runtime *runtime = substream->runtime;
584 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
585
586 set_bit(F_AUDIO_READ_INUSE, &chip->flags);
587 snd_msnd_enable_irq(chip);
588 runtime->dma_area = chip->mappedbase + 0x3000;
589 runtime->dma_bytes = 0x3000;
590 memset(runtime->dma_area, 0, runtime->dma_bytes);
591 chip->capture_substream = substream;
592 runtime->hw = snd_msnd_capture;
593 return 0;
594}
595
596static int snd_msnd_capture_close(struct snd_pcm_substream *substream)
597{
598 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
599
600 snd_msnd_disable_irq(chip);
601 clear_bit(F_AUDIO_READ_INUSE, &chip->flags);
602 return 0;
603}
604
605static int snd_msnd_capture_prepare(struct snd_pcm_substream *substream)
606{
607 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
608 unsigned int pcm_size = snd_pcm_lib_buffer_bytes(substream);
609 unsigned int pcm_count = snd_pcm_lib_period_bytes(substream);
610 unsigned int pcm_periods = pcm_size / pcm_count;
611
612 snd_msnd_capture_reset_queue(chip, pcm_periods, pcm_count);
613 chip->captureDMAPos = 0;
614 return 0;
615}
616
617static int snd_msnd_capture_trigger(struct snd_pcm_substream *substream,
618 int cmd)
619{
620 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
621
622 if (cmd == SNDRV_PCM_TRIGGER_START) {
623 chip->last_recbank = -1;
624 set_bit(F_READING, &chip->flags);
625 if (snd_msnd_send_dsp_cmd(chip, HDEX_RECORD_START) == 0)
626 return 0;
627
628 clear_bit(F_READING, &chip->flags);
629 } else if (cmd == SNDRV_PCM_TRIGGER_STOP) {
630 clear_bit(F_READING, &chip->flags);
631 snd_msnd_send_dsp_cmd(chip, HDEX_RECORD_STOP);
632 return 0;
633 }
634 return -EINVAL;
635}
636
637
638static snd_pcm_uframes_t
639snd_msnd_capture_pointer(struct snd_pcm_substream *substream)
640{
641 struct snd_pcm_runtime *runtime = substream->runtime;
642 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
643
644 return bytes_to_frames(runtime, chip->captureDMAPos);
645}
646
647
648static int snd_msnd_capture_hw_params(struct snd_pcm_substream *substream,
649 struct snd_pcm_hw_params *params)
650{
651 int i;
652 struct snd_msnd *chip = snd_pcm_substream_chip(substream);
653 void *pDAQ = chip->mappedbase + DARQ_DATA_BUFF;
654
655 chip->capture_sample_size = snd_pcm_format_width(params_format(params));
656 chip->capture_channels = params_channels(params);
657 chip->capture_sample_rate = params_rate(params);
658
659 for (i = 0; i < 3; ++i, pDAQ += DAQDS__size) {
660 writew(chip->capture_sample_size, pDAQ + DAQDS_wSampleSize);
661 writew(chip->capture_channels, pDAQ + DAQDS_wChannels);
662 writew(chip->capture_sample_rate, pDAQ + DAQDS_wSampleRate);
663 }
664 return 0;
665}
666
667
668static struct snd_pcm_ops snd_msnd_capture_ops = {
669 .open = snd_msnd_capture_open,
670 .close = snd_msnd_capture_close,
671 .ioctl = snd_pcm_lib_ioctl,
672 .hw_params = snd_msnd_capture_hw_params,
673 .prepare = snd_msnd_capture_prepare,
674 .trigger = snd_msnd_capture_trigger,
675 .pointer = snd_msnd_capture_pointer,
676};
677
678
679int snd_msnd_pcm(struct snd_card *card, int device,
680 struct snd_pcm **rpcm)
681{
682 struct snd_msnd *chip = card->private_data;
683 struct snd_pcm *pcm;
684 int err;
685
686 err = snd_pcm_new(card, "MSNDPINNACLE", device, 1, 1, &pcm);
687 if (err < 0)
688 return err;
689
690 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_msnd_playback_ops);
691 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_msnd_capture_ops);
692
693 pcm->private_data = chip;
694 strcpy(pcm->name, "Hurricane");
695
696
697 if (rpcm)
698 *rpcm = pcm;
699 return 0;
700}
701EXPORT_SYMBOL(snd_msnd_pcm);
702
703MODULE_DESCRIPTION("Common routines for Turtle Beach Multisound drivers");
704MODULE_LICENSE("GPL");
705
diff --git a/sound/isa/msnd/msnd.h b/sound/isa/msnd/msnd.h
new file mode 100644
index 000000000000..3773e242b58e
--- /dev/null
+++ b/sound/isa/msnd/msnd.h
@@ -0,0 +1,308 @@
1/*********************************************************************
2 *
3 * msnd.h
4 *
5 * Turtle Beach MultiSound Sound Card Driver for Linux
6 *
7 * Some parts of this header file were derived from the Turtle Beach
8 * MultiSound Driver Development Kit.
9 *
10 * Copyright (C) 1998 Andrew Veliath
11 * Copyright (C) 1993 Turtle Beach Systems, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 ********************************************************************/
28#ifndef __MSND_H
29#define __MSND_H
30
31#define DEFSAMPLERATE 44100
32#define DEFSAMPLESIZE SNDRV_PCM_FORMAT_S16
33#define DEFCHANNELS 1
34
35#define SRAM_BANK_SIZE 0x8000
36#define SRAM_CNTL_START 0x7F00
37#define SMA_STRUCT_START 0x7F40
38
39#define DSP_BASE_ADDR 0x4000
40#define DSP_BANK_BASE 0x4000
41
42#define AGND 0x01
43#define SIGNAL 0x02
44
45#define EXT_DSP_BIT_DCAL 0x0001
46#define EXT_DSP_BIT_MIDI_CON 0x0002
47
48#define BUFFSIZE 0x8000
49#define HOSTQ_SIZE 0x40
50
51#define DAP_BUFF_SIZE 0x2400
52
53#define DAPQ_STRUCT_SIZE 0x10
54#define DARQ_STRUCT_SIZE 0x10
55#define DAPQ_BUFF_SIZE (3 * 0x10)
56#define DARQ_BUFF_SIZE (3 * 0x10)
57#define MODQ_BUFF_SIZE 0x400
58
59#define DAPQ_DATA_BUFF 0x6C00
60#define DARQ_DATA_BUFF 0x6C30
61#define MODQ_DATA_BUFF 0x6C60
62#define MIDQ_DATA_BUFF 0x7060
63
64#define DAPQ_OFFSET SRAM_CNTL_START
65#define DARQ_OFFSET (SRAM_CNTL_START + 0x08)
66#define MODQ_OFFSET (SRAM_CNTL_START + 0x10)
67#define MIDQ_OFFSET (SRAM_CNTL_START + 0x18)
68#define DSPQ_OFFSET (SRAM_CNTL_START + 0x20)
69
70#define HP_ICR 0x00
71#define HP_CVR 0x01
72#define HP_ISR 0x02
73#define HP_IVR 0x03
74#define HP_NU 0x04
75#define HP_INFO 0x04
76#define HP_TXH 0x05
77#define HP_RXH 0x05
78#define HP_TXM 0x06
79#define HP_RXM 0x06
80#define HP_TXL 0x07
81#define HP_RXL 0x07
82
83#define HP_ICR_DEF 0x00
84#define HP_CVR_DEF 0x12
85#define HP_ISR_DEF 0x06
86#define HP_IVR_DEF 0x0f
87#define HP_NU_DEF 0x00
88
89#define HP_IRQM 0x09
90
91#define HPR_BLRC 0x08
92#define HPR_SPR1 0x09
93#define HPR_SPR2 0x0A
94#define HPR_TCL0 0x0B
95#define HPR_TCL1 0x0C
96#define HPR_TCL2 0x0D
97#define HPR_TCL3 0x0E
98#define HPR_TCL4 0x0F
99
100#define HPICR_INIT 0x80
101#define HPICR_HM1 0x40
102#define HPICR_HM0 0x20
103#define HPICR_HF1 0x10
104#define HPICR_HF0 0x08
105#define HPICR_TREQ 0x02
106#define HPICR_RREQ 0x01
107
108#define HPCVR_HC 0x80
109
110#define HPISR_HREQ 0x80
111#define HPISR_DMA 0x40
112#define HPISR_HF3 0x10
113#define HPISR_HF2 0x08
114#define HPISR_TRDY 0x04
115#define HPISR_TXDE 0x02
116#define HPISR_RXDF 0x01
117
118#define HPIO_290 0
119#define HPIO_260 1
120#define HPIO_250 2
121#define HPIO_240 3
122#define HPIO_230 4
123#define HPIO_220 5
124#define HPIO_210 6
125#define HPIO_3E0 7
126
127#define HPMEM_NONE 0
128#define HPMEM_B000 1
129#define HPMEM_C800 2
130#define HPMEM_D000 3
131#define HPMEM_D400 4
132#define HPMEM_D800 5
133#define HPMEM_E000 6
134#define HPMEM_E800 7
135
136#define HPIRQ_NONE 0
137#define HPIRQ_5 1
138#define HPIRQ_7 2
139#define HPIRQ_9 3
140#define HPIRQ_10 4
141#define HPIRQ_11 5
142#define HPIRQ_12 6
143#define HPIRQ_15 7
144
145#define HIMT_PLAY_DONE 0x00
146#define HIMT_RECORD_DONE 0x01
147#define HIMT_MIDI_EOS 0x02
148#define HIMT_MIDI_OUT 0x03
149
150#define HIMT_MIDI_IN_UCHAR 0x0E
151#define HIMT_DSP 0x0F
152
153#define HDEX_BASE 0x92
154#define HDEX_PLAY_START (0 + HDEX_BASE)
155#define HDEX_PLAY_STOP (1 + HDEX_BASE)
156#define HDEX_PLAY_PAUSE (2 + HDEX_BASE)
157#define HDEX_PLAY_RESUME (3 + HDEX_BASE)
158#define HDEX_RECORD_START (4 + HDEX_BASE)
159#define HDEX_RECORD_STOP (5 + HDEX_BASE)
160#define HDEX_MIDI_IN_START (6 + HDEX_BASE)
161#define HDEX_MIDI_IN_STOP (7 + HDEX_BASE)
162#define HDEX_MIDI_OUT_START (8 + HDEX_BASE)
163#define HDEX_MIDI_OUT_STOP (9 + HDEX_BASE)
164#define HDEX_AUX_REQ (10 + HDEX_BASE)
165
166#define HDEXAR_CLEAR_PEAKS 1
167#define HDEXAR_IN_SET_POTS 2
168#define HDEXAR_AUX_SET_POTS 3
169#define HDEXAR_CAL_A_TO_D 4
170#define HDEXAR_RD_EXT_DSP_BITS 5
171
172/* Pinnacle only HDEXAR defs */
173#define HDEXAR_SET_ANA_IN 0
174#define HDEXAR_SET_SYNTH_IN 4
175#define HDEXAR_READ_DAT_IN 5
176#define HDEXAR_MIC_SET_POTS 6
177#define HDEXAR_SET_DAT_IN 7
178
179#define HDEXAR_SET_SYNTH_48 8
180#define HDEXAR_SET_SYNTH_44 9
181
182#define HIWORD(l) ((u16)((((u32)(l)) >> 16) & 0xFFFF))
183#define LOWORD(l) ((u16)(u32)(l))
184#define HIBYTE(w) ((u8)(((u16)(w) >> 8) & 0xFF))
185#define LOBYTE(w) ((u8)(w))
186#define MAKELONG(low, hi) ((long)(((u16)(low))|(((u32)((u16)(hi)))<<16)))
187#define MAKEWORD(low, hi) ((u16)(((u8)(low))|(((u16)((u8)(hi)))<<8)))
188
189#define PCTODSP_OFFSET(w) (u16)((w)/2)
190#define PCTODSP_BASED(w) (u16)(((w)/2) + DSP_BASE_ADDR)
191#define DSPTOPC_BASED(w) (((w) - DSP_BASE_ADDR) * 2)
192
193#ifdef SLOWIO
194# undef outb
195# undef inb
196# define outb outb_p
197# define inb inb_p
198#endif
199
200/* JobQueueStruct */
201#define JQS_wStart 0x00
202#define JQS_wSize 0x02
203#define JQS_wHead 0x04
204#define JQS_wTail 0x06
205#define JQS__size 0x08
206
207/* DAQueueDataStruct */
208#define DAQDS_wStart 0x00
209#define DAQDS_wSize 0x02
210#define DAQDS_wFormat 0x04
211#define DAQDS_wSampleSize 0x06
212#define DAQDS_wChannels 0x08
213#define DAQDS_wSampleRate 0x0A
214#define DAQDS_wIntMsg 0x0C
215#define DAQDS_wFlags 0x0E
216#define DAQDS__size 0x10
217
218#include <sound/pcm.h>
219
220struct snd_msnd {
221 void __iomem *mappedbase;
222 int play_period_bytes;
223 int playLimit;
224 int playPeriods;
225 int playDMAPos;
226 int banksPlayed;
227 int captureDMAPos;
228 int capturePeriodBytes;
229 int captureLimit;
230 int capturePeriods;
231 struct snd_card *card;
232 void *msndmidi_mpu;
233 struct snd_rawmidi *rmidi;
234
235 /* Hardware resources */
236 long io;
237 int memid, irqid;
238 int irq, irq_ref;
239 unsigned long base;
240
241 /* Motorola 56k DSP SMA */
242 void __iomem *SMA;
243 void __iomem *DAPQ;
244 void __iomem *DARQ;
245 void __iomem *MODQ;
246 void __iomem *MIDQ;
247 void __iomem *DSPQ;
248 int dspq_data_buff, dspq_buff_size;
249
250 /* State variables */
251 enum { msndClassic, msndPinnacle } type;
252 mode_t mode;
253 unsigned long flags;
254#define F_RESETTING 0
255#define F_HAVEDIGITAL 1
256#define F_AUDIO_WRITE_INUSE 2
257#define F_WRITING 3
258#define F_WRITEBLOCK 4
259#define F_WRITEFLUSH 5
260#define F_AUDIO_READ_INUSE 6
261#define F_READING 7
262#define F_READBLOCK 8
263#define F_EXT_MIDI_INUSE 9
264#define F_HDR_MIDI_INUSE 10
265#define F_DISABLE_WRITE_NDELAY 11
266 spinlock_t lock;
267 spinlock_t mixer_lock;
268 int nresets;
269 unsigned recsrc;
270#define LEVEL_ENTRIES 32
271 int left_levels[LEVEL_ENTRIES];
272 int right_levels[LEVEL_ENTRIES];
273 int calibrate_signal;
274 int play_sample_size, play_sample_rate, play_channels;
275 int play_ndelay;
276 int capture_sample_size, capture_sample_rate, capture_channels;
277 int capture_ndelay;
278 u8 bCurrentMidiPatch;
279
280 int last_playbank, last_recbank;
281 struct snd_pcm_substream *playback_substream;
282 struct snd_pcm_substream *capture_substream;
283
284};
285
286void snd_msnd_init_queue(void *base, int start, int size);
287
288int snd_msnd_send_dsp_cmd(struct snd_msnd *chip, u8 cmd);
289int snd_msnd_send_word(struct snd_msnd *chip,
290 unsigned char high,
291 unsigned char mid,
292 unsigned char low);
293int snd_msnd_upload_host(struct snd_msnd *chip,
294 const u8 *bin, int len);
295int snd_msnd_enable_irq(struct snd_msnd *chip);
296int snd_msnd_disable_irq(struct snd_msnd *chip);
297void snd_msnd_dsp_halt(struct snd_msnd *chip, struct file *file);
298int snd_msnd_DAPQ(struct snd_msnd *chip, int start);
299int snd_msnd_DARQ(struct snd_msnd *chip, int start);
300int snd_msnd_pcm(struct snd_card *card, int device, struct snd_pcm **rpcm);
301
302int snd_msndmidi_new(struct snd_card *card, int device);
303void snd_msndmidi_input_read(void *mpu);
304
305void snd_msndmix_setup(struct snd_msnd *chip);
306int __devinit snd_msndmix_new(struct snd_card *card);
307int snd_msndmix_force_recsrc(struct snd_msnd *chip, int recsrc);
308#endif /* __MSND_H */
diff --git a/sound/isa/msnd/msnd_classic.c b/sound/isa/msnd/msnd_classic.c
new file mode 100644
index 000000000000..3b23a096fa4e
--- /dev/null
+++ b/sound/isa/msnd/msnd_classic.c
@@ -0,0 +1,3 @@
1/* The work is in msnd_pinnacle.c, just define MSND_CLASSIC before it. */
2#define MSND_CLASSIC
3#include "msnd_pinnacle.c"
diff --git a/sound/isa/msnd/msnd_classic.h b/sound/isa/msnd/msnd_classic.h
new file mode 100644
index 000000000000..f18d5fa5baf4
--- /dev/null
+++ b/sound/isa/msnd/msnd_classic.h
@@ -0,0 +1,129 @@
1/*********************************************************************
2 *
3 * msnd_classic.h
4 *
5 * Turtle Beach MultiSound Sound Card Driver for Linux
6 *
7 * Some parts of this header file were derived from the Turtle Beach
8 * MultiSound Driver Development Kit.
9 *
10 * Copyright (C) 1998 Andrew Veliath
11 * Copyright (C) 1993 Turtle Beach Systems, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 ********************************************************************/
28#ifndef __MSND_CLASSIC_H
29#define __MSND_CLASSIC_H
30
31#define DSP_NUMIO 0x10
32
33#define HP_MEMM 0x08
34
35#define HP_BITM 0x0E
36#define HP_WAIT 0x0D
37#define HP_DSPR 0x0A
38#define HP_PROR 0x0B
39#define HP_BLKS 0x0C
40
41#define HPPRORESET_OFF 0
42#define HPPRORESET_ON 1
43
44#define HPDSPRESET_OFF 0
45#define HPDSPRESET_ON 1
46
47#define HPBLKSEL_0 0
48#define HPBLKSEL_1 1
49
50#define HPWAITSTATE_0 0
51#define HPWAITSTATE_1 1
52
53#define HPBITMODE_16 0
54#define HPBITMODE_8 1
55
56#define HIDSP_INT_PLAY_UNDER 0x00
57#define HIDSP_INT_RECORD_OVER 0x01
58#define HIDSP_INPUT_CLIPPING 0x02
59#define HIDSP_MIDI_IN_OVER 0x10
60#define HIDSP_MIDI_OVERRUN_ERR 0x13
61
62#define TIME_PRO_RESET_DONE 0x028A
63#define TIME_PRO_SYSEX 0x0040
64#define TIME_PRO_RESET 0x0032
65
66#define DAR_BUFF_SIZE 0x2000
67
68#define MIDQ_BUFF_SIZE 0x200
69#define DSPQ_BUFF_SIZE 0x40
70
71#define DSPQ_DATA_BUFF 0x7260
72
73#define MOP_SYNTH 0x10
74#define MOP_EXTOUT 0x32
75#define MOP_EXTTHRU 0x02
76#define MOP_OUTMASK 0x01
77
78#define MIP_EXTIN 0x01
79#define MIP_SYNTH 0x00
80#define MIP_INMASK 0x32
81
82/* Classic SMA Common Data */
83#define SMA_wCurrPlayBytes 0x0000
84#define SMA_wCurrRecordBytes 0x0002
85#define SMA_wCurrPlayVolLeft 0x0004
86#define SMA_wCurrPlayVolRight 0x0006
87#define SMA_wCurrInVolLeft 0x0008
88#define SMA_wCurrInVolRight 0x000a
89#define SMA_wUser_3 0x000c
90#define SMA_wUser_4 0x000e
91#define SMA_dwUser_5 0x0010
92#define SMA_dwUser_6 0x0014
93#define SMA_wUser_7 0x0018
94#define SMA_wReserved_A 0x001a
95#define SMA_wReserved_B 0x001c
96#define SMA_wReserved_C 0x001e
97#define SMA_wReserved_D 0x0020
98#define SMA_wReserved_E 0x0022
99#define SMA_wReserved_F 0x0024
100#define SMA_wReserved_G 0x0026
101#define SMA_wReserved_H 0x0028
102#define SMA_wCurrDSPStatusFlags 0x002a
103#define SMA_wCurrHostStatusFlags 0x002c
104#define SMA_wCurrInputTagBits 0x002e
105#define SMA_wCurrLeftPeak 0x0030
106#define SMA_wCurrRightPeak 0x0032
107#define SMA_wExtDSPbits 0x0034
108#define SMA_bExtHostbits 0x0036
109#define SMA_bBoardLevel 0x0037
110#define SMA_bInPotPosRight 0x0038
111#define SMA_bInPotPosLeft 0x0039
112#define SMA_bAuxPotPosRight 0x003a
113#define SMA_bAuxPotPosLeft 0x003b
114#define SMA_wCurrMastVolLeft 0x003c
115#define SMA_wCurrMastVolRight 0x003e
116#define SMA_bUser_12 0x0040
117#define SMA_bUser_13 0x0041
118#define SMA_wUser_14 0x0042
119#define SMA_wUser_15 0x0044
120#define SMA_wCalFreqAtoD 0x0046
121#define SMA_wUser_16 0x0048
122#define SMA_wUser_17 0x004a
123#define SMA__size 0x004c
124
125#define INITCODEFILE "turtlebeach/msndinit.bin"
126#define PERMCODEFILE "turtlebeach/msndperm.bin"
127#define LONGNAME "MultiSound (Classic/Monterey/Tahiti)"
128
129#endif /* __MSND_CLASSIC_H */
diff --git a/sound/isa/msnd/msnd_midi.c b/sound/isa/msnd/msnd_midi.c
new file mode 100644
index 000000000000..cb9aa4c4edd0
--- /dev/null
+++ b/sound/isa/msnd/msnd_midi.c
@@ -0,0 +1,180 @@
1/*
2 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
3 * Copyright (c) 2009 by Krzysztof Helt
4 * Routines for control of MPU-401 in UART mode
5 *
6 * MPU-401 supports UART mode which is not capable generate transmit
7 * interrupts thus output is done via polling. Also, if irq < 0, then
8 * input is done also via polling. Do not expect good performance.
9 *
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
26
27#include <linux/io.h>
28#include <linux/delay.h>
29#include <linux/ioport.h>
30#include <linux/errno.h>
31#include <sound/core.h>
32#include <sound/rawmidi.h>
33
34#include "msnd.h"
35
36#define MSNDMIDI_MODE_BIT_INPUT 0
37#define MSNDMIDI_MODE_BIT_OUTPUT 1
38#define MSNDMIDI_MODE_BIT_INPUT_TRIGGER 2
39#define MSNDMIDI_MODE_BIT_OUTPUT_TRIGGER 3
40
41struct snd_msndmidi {
42 struct snd_msnd *dev;
43
44 unsigned long mode; /* MSNDMIDI_MODE_XXXX */
45
46 struct snd_rawmidi_substream *substream_input;
47
48 spinlock_t input_lock;
49};
50
51/*
52 * input/output open/close - protected by open_mutex in rawmidi.c
53 */
54static int snd_msndmidi_input_open(struct snd_rawmidi_substream *substream)
55{
56 struct snd_msndmidi *mpu;
57
58 snd_printdd("snd_msndmidi_input_open()\n");
59
60 mpu = substream->rmidi->private_data;
61
62 mpu->substream_input = substream;
63
64 snd_msnd_enable_irq(mpu->dev);
65
66 snd_msnd_send_dsp_cmd(mpu->dev, HDEX_MIDI_IN_START);
67 set_bit(MSNDMIDI_MODE_BIT_INPUT, &mpu->mode);
68 return 0;
69}
70
71static int snd_msndmidi_input_close(struct snd_rawmidi_substream *substream)
72{
73 struct snd_msndmidi *mpu;
74
75 mpu = substream->rmidi->private_data;
76 snd_msnd_send_dsp_cmd(mpu->dev, HDEX_MIDI_IN_STOP);
77 clear_bit(MSNDMIDI_MODE_BIT_INPUT, &mpu->mode);
78 mpu->substream_input = NULL;
79 snd_msnd_disable_irq(mpu->dev);
80 return 0;
81}
82
83static void snd_msndmidi_input_drop(struct snd_msndmidi *mpu)
84{
85 u16 tail;
86
87 tail = readw(mpu->dev->MIDQ + JQS_wTail);
88 writew(tail, mpu->dev->MIDQ + JQS_wHead);
89}
90
91/*
92 * trigger input
93 */
94static void snd_msndmidi_input_trigger(struct snd_rawmidi_substream *substream,
95 int up)
96{
97 unsigned long flags;
98 struct snd_msndmidi *mpu;
99
100 snd_printdd("snd_msndmidi_input_trigger(, %i)\n", up);
101
102 mpu = substream->rmidi->private_data;
103 spin_lock_irqsave(&mpu->input_lock, flags);
104 if (up) {
105 if (!test_and_set_bit(MSNDMIDI_MODE_BIT_INPUT_TRIGGER,
106 &mpu->mode))
107 snd_msndmidi_input_drop(mpu);
108 } else {
109 clear_bit(MSNDMIDI_MODE_BIT_INPUT_TRIGGER, &mpu->mode);
110 }
111 spin_unlock_irqrestore(&mpu->input_lock, flags);
112 if (up)
113 snd_msndmidi_input_read(mpu);
114}
115
116void snd_msndmidi_input_read(void *mpuv)
117{
118 unsigned long flags;
119 struct snd_msndmidi *mpu = mpuv;
120 void *pwMIDQData = mpu->dev->mappedbase + MIDQ_DATA_BUFF;
121
122 spin_lock_irqsave(&mpu->input_lock, flags);
123 while (readw(mpu->dev->MIDQ + JQS_wTail) !=
124 readw(mpu->dev->MIDQ + JQS_wHead)) {
125 u16 wTmp, val;
126 val = readw(pwMIDQData + 2 * readw(mpu->dev->MIDQ + JQS_wHead));
127
128 if (test_bit(MSNDMIDI_MODE_BIT_INPUT_TRIGGER,
129 &mpu->mode))
130 snd_rawmidi_receive(mpu->substream_input,
131 (unsigned char *)&val, 1);
132
133 wTmp = readw(mpu->dev->MIDQ + JQS_wHead) + 1;
134 if (wTmp > readw(mpu->dev->MIDQ + JQS_wSize))
135 writew(0, mpu->dev->MIDQ + JQS_wHead);
136 else
137 writew(wTmp, mpu->dev->MIDQ + JQS_wHead);
138 }
139 spin_unlock_irqrestore(&mpu->input_lock, flags);
140}
141EXPORT_SYMBOL(snd_msndmidi_input_read);
142
143static struct snd_rawmidi_ops snd_msndmidi_input = {
144 .open = snd_msndmidi_input_open,
145 .close = snd_msndmidi_input_close,
146 .trigger = snd_msndmidi_input_trigger,
147};
148
149static void snd_msndmidi_free(struct snd_rawmidi *rmidi)
150{
151 struct snd_msndmidi *mpu = rmidi->private_data;
152 kfree(mpu);
153}
154
155int snd_msndmidi_new(struct snd_card *card, int device)
156{
157 struct snd_msnd *chip = card->private_data;
158 struct snd_msndmidi *mpu;
159 struct snd_rawmidi *rmidi;
160 int err;
161
162 err = snd_rawmidi_new(card, "MSND-MIDI", device, 1, 1, &rmidi);
163 if (err < 0)
164 return err;
165 mpu = kcalloc(1, sizeof(*mpu), GFP_KERNEL);
166 if (mpu == NULL) {
167 snd_device_free(card, rmidi);
168 return -ENOMEM;
169 }
170 mpu->dev = chip;
171 chip->msndmidi_mpu = mpu;
172 rmidi->private_data = mpu;
173 rmidi->private_free = snd_msndmidi_free;
174 spin_lock_init(&mpu->input_lock);
175 strcpy(rmidi->name, "MSND MIDI");
176 snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT,
177 &snd_msndmidi_input);
178 rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
179 return 0;
180}
diff --git a/sound/isa/msnd/msnd_pinnacle.c b/sound/isa/msnd/msnd_pinnacle.c
new file mode 100644
index 000000000000..60b6abd71612
--- /dev/null
+++ b/sound/isa/msnd/msnd_pinnacle.c
@@ -0,0 +1,1238 @@
1/*********************************************************************
2 *
3 * Linux multisound pinnacle/fiji driver for ALSA.
4 *
5 * 2002/06/30 Karsten Wiese:
6 * for now this is only used to build a pinnacle / fiji driver.
7 * the OSS parent of this code is designed to also support
8 * the multisound classic via the file msnd_classic.c.
9 * to make it easier for some brave heart to implemt classic
10 * support in alsa, i left all the MSND_CLASSIC tokens in this file.
11 * but for now this untested & undone.
12 *
13 *
14 * ripped from linux kernel 2.4.18 by Karsten Wiese.
15 *
16 * the following is a copy of the 2.4.18 OSS FREE file-heading comment:
17 *
18 * Turtle Beach MultiSound Sound Card Driver for Linux
19 * msnd_pinnacle.c / msnd_classic.c
20 *
21 * -- If MSND_CLASSIC is defined:
22 *
23 * -> driver for Turtle Beach Classic/Monterey/Tahiti
24 *
25 * -- Else
26 *
27 * -> driver for Turtle Beach Pinnacle/Fiji
28 *
29 * 12-3-2000 Modified IO port validation Steve Sycamore
30 *
31 * Copyright (C) 1998 Andrew Veliath
32 *
33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of the GNU General Public License as published by
35 * the Free Software Foundation; either version 2 of the License, or
36 * (at your option) any later version.
37 *
38 * This program is distributed in the hope that it will be useful,
39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41 * GNU General Public License for more details.
42 *
43 * You should have received a copy of the GNU General Public License
44 * along with this program; if not, write to the Free Software
45 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
46 *
47 ********************************************************************/
48
49#include <linux/kernel.h>
50#include <linux/module.h>
51#include <linux/interrupt.h>
52#include <linux/types.h>
53#include <linux/delay.h>
54#include <linux/ioport.h>
55#include <linux/firmware.h>
56#include <linux/isa.h>
57#include <linux/isapnp.h>
58#include <linux/irq.h>
59#include <linux/io.h>
60
61#include <sound/core.h>
62#include <sound/initval.h>
63#include <sound/asound.h>
64#include <sound/pcm.h>
65#include <sound/mpu401.h>
66
67#ifdef MSND_CLASSIC
68# ifndef __alpha__
69# define SLOWIO
70# endif
71#endif
72#include "msnd.h"
73#ifdef MSND_CLASSIC
74# include "msnd_classic.h"
75# define LOGNAME "msnd_classic"
76#else
77# include "msnd_pinnacle.h"
78# define LOGNAME "snd_msnd_pinnacle"
79#endif
80
81static void __devinit set_default_audio_parameters(struct snd_msnd *chip)
82{
83 chip->play_sample_size = DEFSAMPLESIZE;
84 chip->play_sample_rate = DEFSAMPLERATE;
85 chip->play_channels = DEFCHANNELS;
86 chip->capture_sample_size = DEFSAMPLESIZE;
87 chip->capture_sample_rate = DEFSAMPLERATE;
88 chip->capture_channels = DEFCHANNELS;
89}
90
91static void snd_msnd_eval_dsp_msg(struct snd_msnd *chip, u16 wMessage)
92{
93 switch (HIBYTE(wMessage)) {
94 case HIMT_PLAY_DONE: {
95 if (chip->banksPlayed < 3)
96 snd_printdd("%08X: HIMT_PLAY_DONE: %i\n",
97 (unsigned)jiffies, LOBYTE(wMessage));
98
99 if (chip->last_playbank == LOBYTE(wMessage)) {
100 snd_printdd("chip.last_playbank == LOBYTE(wMessage)\n");
101 break;
102 }
103 chip->banksPlayed++;
104
105 if (test_bit(F_WRITING, &chip->flags))
106 snd_msnd_DAPQ(chip, 0);
107
108 chip->last_playbank = LOBYTE(wMessage);
109 chip->playDMAPos += chip->play_period_bytes;
110 if (chip->playDMAPos > chip->playLimit)
111 chip->playDMAPos = 0;
112 snd_pcm_period_elapsed(chip->playback_substream);
113
114 break;
115 }
116 case HIMT_RECORD_DONE:
117 if (chip->last_recbank == LOBYTE(wMessage))
118 break;
119 chip->last_recbank = LOBYTE(wMessage);
120 chip->captureDMAPos += chip->capturePeriodBytes;
121 if (chip->captureDMAPos > (chip->captureLimit))
122 chip->captureDMAPos = 0;
123
124 if (test_bit(F_READING, &chip->flags))
125 snd_msnd_DARQ(chip, chip->last_recbank);
126
127 snd_pcm_period_elapsed(chip->capture_substream);
128 break;
129
130 case HIMT_DSP:
131 switch (LOBYTE(wMessage)) {
132#ifndef MSND_CLASSIC
133 case HIDSP_PLAY_UNDER:
134#endif
135 case HIDSP_INT_PLAY_UNDER:
136 snd_printd(KERN_WARNING LOGNAME ": Play underflow %i\n",
137 chip->banksPlayed);
138 if (chip->banksPlayed > 2)
139 clear_bit(F_WRITING, &chip->flags);
140 break;
141
142 case HIDSP_INT_RECORD_OVER:
143 snd_printd(KERN_WARNING LOGNAME ": Record overflow\n");
144 clear_bit(F_READING, &chip->flags);
145 break;
146
147 default:
148 snd_printd(KERN_WARNING LOGNAME
149 ": DSP message %d 0x%02x\n",
150 LOBYTE(wMessage), LOBYTE(wMessage));
151 break;
152 }
153 break;
154
155 case HIMT_MIDI_IN_UCHAR:
156 if (chip->msndmidi_mpu)
157 snd_msndmidi_input_read(chip->msndmidi_mpu);
158 break;
159
160 default:
161 snd_printd(KERN_WARNING LOGNAME ": HIMT message %d 0x%02x\n",
162 HIBYTE(wMessage), HIBYTE(wMessage));
163 break;
164 }
165}
166
167static irqreturn_t snd_msnd_interrupt(int irq, void *dev_id)
168{
169 struct snd_msnd *chip = dev_id;
170 void *pwDSPQData = chip->mappedbase + DSPQ_DATA_BUFF;
171
172 /* Send ack to DSP */
173 /* inb(chip->io + HP_RXL); */
174
175 /* Evaluate queued DSP messages */
176 while (readw(chip->DSPQ + JQS_wTail) != readw(chip->DSPQ + JQS_wHead)) {
177 u16 wTmp;
178
179 snd_msnd_eval_dsp_msg(chip,
180 readw(pwDSPQData + 2 * readw(chip->DSPQ + JQS_wHead)));
181
182 wTmp = readw(chip->DSPQ + JQS_wHead) + 1;
183 if (wTmp > readw(chip->DSPQ + JQS_wSize))
184 writew(0, chip->DSPQ + JQS_wHead);
185 else
186 writew(wTmp, chip->DSPQ + JQS_wHead);
187 }
188 /* Send ack to DSP */
189 inb(chip->io + HP_RXL);
190 return IRQ_HANDLED;
191}
192
193
194static int snd_msnd_reset_dsp(long io, unsigned char *info)
195{
196 int timeout = 100;
197
198 outb(HPDSPRESET_ON, io + HP_DSPR);
199 msleep(1);
200#ifndef MSND_CLASSIC
201 if (info)
202 *info = inb(io + HP_INFO);
203#endif
204 outb(HPDSPRESET_OFF, io + HP_DSPR);
205 msleep(1);
206 while (timeout-- > 0) {
207 if (inb(io + HP_CVR) == HP_CVR_DEF)
208 return 0;
209 msleep(1);
210 }
211 snd_printk(KERN_ERR LOGNAME ": Cannot reset DSP\n");
212
213 return -EIO;
214}
215
216static int __devinit snd_msnd_probe(struct snd_card *card)
217{
218 struct snd_msnd *chip = card->private_data;
219 unsigned char info;
220#ifndef MSND_CLASSIC
221 char *xv, *rev = NULL;
222 char *pin = "TB Pinnacle", *fiji = "TB Fiji";
223 char *pinfiji = "TB Pinnacle/Fiji";
224#endif
225
226 if (!request_region(chip->io, DSP_NUMIO, "probing")) {
227 snd_printk(KERN_ERR LOGNAME ": I/O port conflict\n");
228 return -ENODEV;
229 }
230
231 if (snd_msnd_reset_dsp(chip->io, &info) < 0) {
232 release_region(chip->io, DSP_NUMIO);
233 return -ENODEV;
234 }
235
236#ifdef MSND_CLASSIC
237 strcpy(card->shortname, "Classic/Tahiti/Monterey");
238 strcpy(card->longname, "Turtle Beach Multisound");
239 printk(KERN_INFO LOGNAME ": %s, "
240 "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
241 card->shortname,
242 chip->io, chip->io + DSP_NUMIO - 1,
243 chip->irq,
244 chip->base, chip->base + 0x7fff);
245#else
246 switch (info >> 4) {
247 case 0xf:
248 xv = "<= 1.15";
249 break;
250 case 0x1:
251 xv = "1.18/1.2";
252 break;
253 case 0x2:
254 xv = "1.3";
255 break;
256 case 0x3:
257 xv = "1.4";
258 break;
259 default:
260 xv = "unknown";
261 break;
262 }
263
264 switch (info & 0x7) {
265 case 0x0:
266 rev = "I";
267 strcpy(card->shortname, pin);
268 break;
269 case 0x1:
270 rev = "F";
271 strcpy(card->shortname, pin);
272 break;
273 case 0x2:
274 rev = "G";
275 strcpy(card->shortname, pin);
276 break;
277 case 0x3:
278 rev = "H";
279 strcpy(card->shortname, pin);
280 break;
281 case 0x4:
282 rev = "E";
283 strcpy(card->shortname, fiji);
284 break;
285 case 0x5:
286 rev = "C";
287 strcpy(card->shortname, fiji);
288 break;
289 case 0x6:
290 rev = "D";
291 strcpy(card->shortname, fiji);
292 break;
293 case 0x7:
294 rev = "A-B (Fiji) or A-E (Pinnacle)";
295 strcpy(card->shortname, pinfiji);
296 break;
297 }
298 strcpy(card->longname, "Turtle Beach Multisound Pinnacle");
299 printk(KERN_INFO LOGNAME ": %s revision %s, Xilinx version %s, "
300 "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
301 card->shortname,
302 rev, xv,
303 chip->io, chip->io + DSP_NUMIO - 1,
304 chip->irq,
305 chip->base, chip->base + 0x7fff);
306#endif
307
308 release_region(chip->io, DSP_NUMIO);
309 return 0;
310}
311
312static int snd_msnd_init_sma(struct snd_msnd *chip)
313{
314 static int initted;
315 u16 mastVolLeft, mastVolRight;
316 unsigned long flags;
317
318#ifdef MSND_CLASSIC
319 outb(chip->memid, chip->io + HP_MEMM);
320#endif
321 outb(HPBLKSEL_0, chip->io + HP_BLKS);
322 /* Motorola 56k shared memory base */
323 chip->SMA = chip->mappedbase + SMA_STRUCT_START;
324
325 if (initted) {
326 mastVolLeft = readw(chip->SMA + SMA_wCurrMastVolLeft);
327 mastVolRight = readw(chip->SMA + SMA_wCurrMastVolRight);
328 } else
329 mastVolLeft = mastVolRight = 0;
330 memset_io(chip->mappedbase, 0, 0x8000);
331
332 /* Critical section: bank 1 access */
333 spin_lock_irqsave(&chip->lock, flags);
334 outb(HPBLKSEL_1, chip->io + HP_BLKS);
335 memset_io(chip->mappedbase, 0, 0x8000);
336 outb(HPBLKSEL_0, chip->io + HP_BLKS);
337 spin_unlock_irqrestore(&chip->lock, flags);
338
339 /* Digital audio play queue */
340 chip->DAPQ = chip->mappedbase + DAPQ_OFFSET;
341 snd_msnd_init_queue(chip->DAPQ, DAPQ_DATA_BUFF, DAPQ_BUFF_SIZE);
342
343 /* Digital audio record queue */
344 chip->DARQ = chip->mappedbase + DARQ_OFFSET;
345 snd_msnd_init_queue(chip->DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE);
346
347 /* MIDI out queue */
348 chip->MODQ = chip->mappedbase + MODQ_OFFSET;
349 snd_msnd_init_queue(chip->MODQ, MODQ_DATA_BUFF, MODQ_BUFF_SIZE);
350
351 /* MIDI in queue */
352 chip->MIDQ = chip->mappedbase + MIDQ_OFFSET;
353 snd_msnd_init_queue(chip->MIDQ, MIDQ_DATA_BUFF, MIDQ_BUFF_SIZE);
354
355 /* DSP -> host message queue */
356 chip->DSPQ = chip->mappedbase + DSPQ_OFFSET;
357 snd_msnd_init_queue(chip->DSPQ, DSPQ_DATA_BUFF, DSPQ_BUFF_SIZE);
358
359 /* Setup some DSP values */
360#ifndef MSND_CLASSIC
361 writew(1, chip->SMA + SMA_wCurrPlayFormat);
362 writew(chip->play_sample_size, chip->SMA + SMA_wCurrPlaySampleSize);
363 writew(chip->play_channels, chip->SMA + SMA_wCurrPlayChannels);
364 writew(chip->play_sample_rate, chip->SMA + SMA_wCurrPlaySampleRate);
365#endif
366 writew(chip->play_sample_rate, chip->SMA + SMA_wCalFreqAtoD);
367 writew(mastVolLeft, chip->SMA + SMA_wCurrMastVolLeft);
368 writew(mastVolRight, chip->SMA + SMA_wCurrMastVolRight);
369#ifndef MSND_CLASSIC
370 writel(0x00010000, chip->SMA + SMA_dwCurrPlayPitch);
371 writel(0x00000001, chip->SMA + SMA_dwCurrPlayRate);
372#endif
373 writew(0x303, chip->SMA + SMA_wCurrInputTagBits);
374
375 initted = 1;
376
377 return 0;
378}
379
380
381static int upload_dsp_code(struct snd_card *card)
382{
383 struct snd_msnd *chip = card->private_data;
384 const struct firmware *init_fw = NULL, *perm_fw = NULL;
385 int err;
386
387 outb(HPBLKSEL_0, chip->io + HP_BLKS);
388
389 err = request_firmware(&init_fw, INITCODEFILE, card->dev);
390 if (err < 0) {
391 printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE);
392 goto cleanup1;
393 }
394 err = request_firmware(&perm_fw, PERMCODEFILE, card->dev);
395 if (err < 0) {
396 printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE);
397 goto cleanup;
398 }
399
400 memcpy_toio(chip->mappedbase, perm_fw->data, perm_fw->size);
401 if (snd_msnd_upload_host(chip, init_fw->data, init_fw->size) < 0) {
402 printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n");
403 err = -ENODEV;
404 goto cleanup;
405 }
406 printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n");
407 err = 0;
408
409cleanup:
410 release_firmware(perm_fw);
411cleanup1:
412 release_firmware(init_fw);
413 return err;
414}
415
416#ifdef MSND_CLASSIC
417static void reset_proteus(struct snd_msnd *chip)
418{
419 outb(HPPRORESET_ON, chip->io + HP_PROR);
420 msleep(TIME_PRO_RESET);
421 outb(HPPRORESET_OFF, chip->io + HP_PROR);
422 msleep(TIME_PRO_RESET_DONE);
423}
424#endif
425
426static int snd_msnd_initialize(struct snd_card *card)
427{
428 struct snd_msnd *chip = card->private_data;
429 int err, timeout;
430
431#ifdef MSND_CLASSIC
432 outb(HPWAITSTATE_0, chip->io + HP_WAIT);
433 outb(HPBITMODE_16, chip->io + HP_BITM);
434
435 reset_proteus(chip);
436#endif
437 err = snd_msnd_init_sma(chip);
438 if (err < 0) {
439 printk(KERN_WARNING LOGNAME ": Cannot initialize SMA\n");
440 return err;
441 }
442
443 err = snd_msnd_reset_dsp(chip->io, NULL);
444 if (err < 0)
445 return err;
446
447 err = upload_dsp_code(card);
448 if (err < 0) {
449 printk(KERN_WARNING LOGNAME ": Cannot upload DSP code\n");
450 return err;
451 }
452
453 timeout = 200;
454
455 while (readw(chip->mappedbase)) {
456 msleep(1);
457 if (!timeout--) {
458 snd_printd(KERN_ERR LOGNAME ": DSP reset timeout\n");
459 return -EIO;
460 }
461 }
462
463 snd_msndmix_setup(chip);
464 return 0;
465}
466
467static int snd_msnd_dsp_full_reset(struct snd_card *card)
468{
469 struct snd_msnd *chip = card->private_data;
470 int rv;
471
472 if (test_bit(F_RESETTING, &chip->flags) || ++chip->nresets > 10)
473 return 0;
474
475 set_bit(F_RESETTING, &chip->flags);
476 snd_msnd_dsp_halt(chip, NULL); /* Unconditionally halt */
477
478 rv = snd_msnd_initialize(card);
479 if (rv)
480 printk(KERN_WARNING LOGNAME ": DSP reset failed\n");
481 snd_msndmix_force_recsrc(chip, 0);
482 clear_bit(F_RESETTING, &chip->flags);
483 return rv;
484}
485
486static int snd_msnd_dev_free(struct snd_device *device)
487{
488 snd_printdd("snd_msnd_chip_free()\n");
489 return 0;
490}
491
492static int snd_msnd_send_dsp_cmd_chk(struct snd_msnd *chip, u8 cmd)
493{
494 if (snd_msnd_send_dsp_cmd(chip, cmd) == 0)
495 return 0;
496 snd_msnd_dsp_full_reset(chip->card);
497 return snd_msnd_send_dsp_cmd(chip, cmd);
498}
499
500static int __devinit snd_msnd_calibrate_adc(struct snd_msnd *chip, u16 srate)
501{
502 snd_printdd("snd_msnd_calibrate_adc(%i)\n", srate);
503 writew(srate, chip->SMA + SMA_wCalFreqAtoD);
504 if (chip->calibrate_signal == 0)
505 writew(readw(chip->SMA + SMA_wCurrHostStatusFlags)
506 | 0x0001, chip->SMA + SMA_wCurrHostStatusFlags);
507 else
508 writew(readw(chip->SMA + SMA_wCurrHostStatusFlags)
509 & ~0x0001, chip->SMA + SMA_wCurrHostStatusFlags);
510 if (snd_msnd_send_word(chip, 0, 0, HDEXAR_CAL_A_TO_D) == 0 &&
511 snd_msnd_send_dsp_cmd_chk(chip, HDEX_AUX_REQ) == 0) {
512 schedule_timeout_interruptible(msecs_to_jiffies(333));
513 return 0;
514 }
515 printk(KERN_WARNING LOGNAME ": ADC calibration failed\n");
516 return -EIO;
517}
518
519/*
520 * ALSA callback function, called when attempting to open the MIDI device.
521 */
522static int snd_msnd_mpu401_open(struct snd_mpu401 *mpu)
523{
524 snd_msnd_enable_irq(mpu->private_data);
525 snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_START);
526 return 0;
527}
528
529static void snd_msnd_mpu401_close(struct snd_mpu401 *mpu)
530{
531 snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_STOP);
532 snd_msnd_disable_irq(mpu->private_data);
533}
534
535static long mpu_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
536static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
537
538static int __devinit snd_msnd_attach(struct snd_card *card)
539{
540 struct snd_msnd *chip = card->private_data;
541 int err;
542 static struct snd_device_ops ops = {
543 .dev_free = snd_msnd_dev_free,
544 };
545
546 err = request_irq(chip->irq, snd_msnd_interrupt, 0, card->shortname,
547 chip);
548 if (err < 0) {
549 printk(KERN_ERR LOGNAME ": Couldn't grab IRQ %d\n", chip->irq);
550 return err;
551 }
552 request_region(chip->io, DSP_NUMIO, card->shortname);
553
554 if (!request_mem_region(chip->base, BUFFSIZE, card->shortname)) {
555 printk(KERN_ERR LOGNAME
556 ": unable to grab memory region 0x%lx-0x%lx\n",
557 chip->base, chip->base + BUFFSIZE - 1);
558 release_region(chip->io, DSP_NUMIO);
559 free_irq(chip->irq, chip);
560 return -EBUSY;
561 }
562 chip->mappedbase = ioremap_nocache(chip->base, 0x8000);
563 if (!chip->mappedbase) {
564 printk(KERN_ERR LOGNAME
565 ": unable to map memory region 0x%lx-0x%lx\n",
566 chip->base, chip->base + BUFFSIZE - 1);
567 err = -EIO;
568 goto err_release_region;
569 }
570
571 err = snd_msnd_dsp_full_reset(card);
572 if (err < 0)
573 goto err_release_region;
574
575 /* Register device */
576 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
577 if (err < 0)
578 goto err_release_region;
579
580 err = snd_msnd_pcm(card, 0, NULL);
581 if (err < 0) {
582 printk(KERN_ERR LOGNAME ": error creating new PCM device\n");
583 goto err_release_region;
584 }
585
586 err = snd_msndmix_new(card);
587 if (err < 0) {
588 printk(KERN_ERR LOGNAME ": error creating new Mixer device\n");
589 goto err_release_region;
590 }
591
592
593 if (mpu_io[0] != SNDRV_AUTO_PORT) {
594 struct snd_mpu401 *mpu;
595
596 err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
597 mpu_io[0],
598 MPU401_MODE_INPUT |
599 MPU401_MODE_OUTPUT,
600 mpu_irq[0], IRQF_DISABLED,
601 &chip->rmidi);
602 if (err < 0) {
603 printk(KERN_ERR LOGNAME
604 ": error creating new Midi device\n");
605 goto err_release_region;
606 }
607 mpu = chip->rmidi->private_data;
608
609 mpu->open_input = snd_msnd_mpu401_open;
610 mpu->close_input = snd_msnd_mpu401_close;
611 mpu->private_data = chip;
612 }
613
614 disable_irq(chip->irq);
615 snd_msnd_calibrate_adc(chip, chip->play_sample_rate);
616 snd_msndmix_force_recsrc(chip, 0);
617
618 err = snd_card_register(card);
619 if (err < 0)
620 goto err_release_region;
621
622 return 0;
623
624err_release_region:
625 if (chip->mappedbase)
626 iounmap(chip->mappedbase);
627 release_mem_region(chip->base, BUFFSIZE);
628 release_region(chip->io, DSP_NUMIO);
629 free_irq(chip->irq, chip);
630 return err;
631}
632
633
634static void __devexit snd_msnd_unload(struct snd_card *card)
635{
636 struct snd_msnd *chip = card->private_data;
637
638 iounmap(chip->mappedbase);
639 release_mem_region(chip->base, BUFFSIZE);
640 release_region(chip->io, DSP_NUMIO);
641 free_irq(chip->irq, chip);
642 snd_card_free(card);
643}
644
645#ifndef MSND_CLASSIC
646
647/* Pinnacle/Fiji Logical Device Configuration */
648
649static int __devinit snd_msnd_write_cfg(int cfg, int reg, int value)
650{
651 outb(reg, cfg);
652 outb(value, cfg + 1);
653 if (value != inb(cfg + 1)) {
654 printk(KERN_ERR LOGNAME ": snd_msnd_write_cfg: I/O error\n");
655 return -EIO;
656 }
657 return 0;
658}
659
660static int __devinit snd_msnd_write_cfg_io0(int cfg, int num, u16 io)
661{
662 if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
663 return -EIO;
664 if (snd_msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
665 return -EIO;
666 if (snd_msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
667 return -EIO;
668 return 0;
669}
670
671static int __devinit snd_msnd_write_cfg_io1(int cfg, int num, u16 io)
672{
673 if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
674 return -EIO;
675 if (snd_msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
676 return -EIO;
677 if (snd_msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
678 return -EIO;
679 return 0;
680}
681
682static int __devinit snd_msnd_write_cfg_irq(int cfg, int num, u16 irq)
683{
684 if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
685 return -EIO;
686 if (snd_msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
687 return -EIO;
688 if (snd_msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
689 return -EIO;
690 return 0;
691}
692
693static int __devinit snd_msnd_write_cfg_mem(int cfg, int num, int mem)
694{
695 u16 wmem;
696
697 mem >>= 8;
698 wmem = (u16)(mem & 0xfff);
699 if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
700 return -EIO;
701 if (snd_msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
702 return -EIO;
703 if (snd_msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
704 return -EIO;
705 if (wmem && snd_msnd_write_cfg(cfg, IREG_MEMCONTROL,
706 MEMTYPE_HIADDR | MEMTYPE_16BIT))
707 return -EIO;
708 return 0;
709}
710
711static int __devinit snd_msnd_activate_logical(int cfg, int num)
712{
713 if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
714 return -EIO;
715 if (snd_msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
716 return -EIO;
717 return 0;
718}
719
720static int __devinit snd_msnd_write_cfg_logical(int cfg, int num, u16 io0,
721 u16 io1, u16 irq, int mem)
722{
723 if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
724 return -EIO;
725 if (snd_msnd_write_cfg_io0(cfg, num, io0))
726 return -EIO;
727 if (snd_msnd_write_cfg_io1(cfg, num, io1))
728 return -EIO;
729 if (snd_msnd_write_cfg_irq(cfg, num, irq))
730 return -EIO;
731 if (snd_msnd_write_cfg_mem(cfg, num, mem))
732 return -EIO;
733 if (snd_msnd_activate_logical(cfg, num))
734 return -EIO;
735 return 0;
736}
737
738static int __devinit snd_msnd_pinnacle_cfg_reset(int cfg)
739{
740 int i;
741
742 /* Reset devices if told to */
743 printk(KERN_INFO LOGNAME ": Resetting all devices\n");
744 for (i = 0; i < 4; ++i)
745 if (snd_msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
746 return -EIO;
747
748 return 0;
749}
750#endif
751
752static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
753static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
754
755module_param_array(index, int, NULL, S_IRUGO);
756MODULE_PARM_DESC(index, "Index value for msnd_pinnacle soundcard.");
757module_param_array(id, charp, NULL, S_IRUGO);
758MODULE_PARM_DESC(id, "ID string for msnd_pinnacle soundcard.");
759
760static long io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
761static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
762static long mem[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
763
764static long cfg[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
765
766#ifndef MSND_CLASSIC
767/* Extra Peripheral Configuration (Default: Disable) */
768static long ide_io0[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
769static long ide_io1[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
770static int ide_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
771
772static long joystick_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
773/* If we have the digital daugherboard... */
774static int digital[SNDRV_CARDS];
775
776/* Extra Peripheral Configuration */
777static int reset[SNDRV_CARDS];
778#endif
779
780static int write_ndelay[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 1 };
781
782static int calibrate_signal;
783
784#ifdef CONFIG_PNP
785static int isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
786module_param_array(isapnp, bool, NULL, 0444);
787MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
788#define has_isapnp(x) isapnp[x]
789#else
790#define has_isapnp(x) 0
791#endif
792
793MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>");
794MODULE_DESCRIPTION("Turtle Beach " LONGNAME " Linux Driver");
795MODULE_LICENSE("GPL");
796MODULE_FIRMWARE(INITCODEFILE);
797MODULE_FIRMWARE(PERMCODEFILE);
798
799module_param_array(io, long, NULL, S_IRUGO);
800MODULE_PARM_DESC(io, "IO port #");
801module_param_array(irq, int, NULL, S_IRUGO);
802module_param_array(mem, long, NULL, S_IRUGO);
803module_param_array(write_ndelay, int, NULL, S_IRUGO);
804module_param(calibrate_signal, int, S_IRUGO);
805#ifndef MSND_CLASSIC
806module_param_array(digital, int, NULL, S_IRUGO);
807module_param_array(cfg, long, NULL, S_IRUGO);
808module_param_array(reset, int, 0, S_IRUGO);
809module_param_array(mpu_io, long, NULL, S_IRUGO);
810module_param_array(mpu_irq, int, NULL, S_IRUGO);
811module_param_array(ide_io0, long, NULL, S_IRUGO);
812module_param_array(ide_io1, long, NULL, S_IRUGO);
813module_param_array(ide_irq, int, NULL, S_IRUGO);
814module_param_array(joystick_io, long, NULL, S_IRUGO);
815#endif
816
817
818static int __devinit snd_msnd_isa_match(struct device *pdev, unsigned int i)
819{
820 if (io[i] == SNDRV_AUTO_PORT)
821 return 0;
822
823 if (irq[i] == SNDRV_AUTO_PORT || mem[i] == SNDRV_AUTO_PORT) {
824 printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n");
825 return 0;
826 }
827
828#ifdef MSND_CLASSIC
829 if (!(io[i] == 0x290 ||
830 io[i] == 0x260 ||
831 io[i] == 0x250 ||
832 io[i] == 0x240 ||
833 io[i] == 0x230 ||
834 io[i] == 0x220 ||
835 io[i] == 0x210 ||
836 io[i] == 0x3e0)) {
837 printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set "
838 " to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, "
839 "or 0x3E0\n");
840 return 0;
841 }
842#else
843 if (io[i] < 0x100 || io[i] > 0x3e0 || (io[i] % 0x10) != 0) {
844 printk(KERN_ERR LOGNAME
845 ": \"io\" - DSP I/O base must within the range 0x100 "
846 "to 0x3E0 and must be evenly divisible by 0x10\n");
847 return 0;
848 }
849#endif /* MSND_CLASSIC */
850
851 if (!(irq[i] == 5 ||
852 irq[i] == 7 ||
853 irq[i] == 9 ||
854 irq[i] == 10 ||
855 irq[i] == 11 ||
856 irq[i] == 12)) {
857 printk(KERN_ERR LOGNAME
858 ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
859 return 0;
860 }
861
862 if (!(mem[i] == 0xb0000 ||
863 mem[i] == 0xc8000 ||
864 mem[i] == 0xd0000 ||
865 mem[i] == 0xd8000 ||
866 mem[i] == 0xe0000 ||
867 mem[i] == 0xe8000)) {
868 printk(KERN_ERR LOGNAME ": \"mem\" - must be set to "
869 "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or "
870 "0xe8000\n");
871 return 0;
872 }
873
874#ifndef MSND_CLASSIC
875 if (cfg[i] == SNDRV_AUTO_PORT) {
876 printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
877 } else if (cfg[i] != 0x250 && cfg[i] != 0x260 && cfg[i] != 0x270) {
878 printk(KERN_INFO LOGNAME
879 ": Config port must be 0x250, 0x260 or 0x270 "
880 "(or unspecified for PnP mode)\n");
881 return 0;
882 }
883#endif /* MSND_CLASSIC */
884
885 return 1;
886}
887
888static int __devinit snd_msnd_isa_probe(struct device *pdev, unsigned int idx)
889{
890 int err;
891 struct snd_card *card;
892 struct snd_msnd *chip;
893
894 if (has_isapnp(idx) || cfg[idx] == SNDRV_AUTO_PORT) {
895 printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
896 return -ENODEV;
897 }
898
899 err = snd_card_create(index[idx], id[idx], THIS_MODULE,
900 sizeof(struct snd_msnd), &card);
901 if (err < 0)
902 return err;
903
904 snd_card_set_dev(card, pdev);
905 chip = card->private_data;
906 chip->card = card;
907
908#ifdef MSND_CLASSIC
909 switch (irq[idx]) {
910 case 5:
911 chip->irqid = HPIRQ_5; break;
912 case 7:
913 chip->irqid = HPIRQ_7; break;
914 case 9:
915 chip->irqid = HPIRQ_9; break;
916 case 10:
917 chip->irqid = HPIRQ_10; break;
918 case 11:
919 chip->irqid = HPIRQ_11; break;
920 case 12:
921 chip->irqid = HPIRQ_12; break;
922 }
923
924 switch (mem[idx]) {
925 case 0xb0000:
926 chip->memid = HPMEM_B000; break;
927 case 0xc8000:
928 chip->memid = HPMEM_C800; break;
929 case 0xd0000:
930 chip->memid = HPMEM_D000; break;
931 case 0xd8000:
932 chip->memid = HPMEM_D800; break;
933 case 0xe0000:
934 chip->memid = HPMEM_E000; break;
935 case 0xe8000:
936 chip->memid = HPMEM_E800; break;
937 }
938#else
939 printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%lx\n",
940 cfg[idx]);
941
942 if (!request_region(cfg[idx], 2, "Pinnacle/Fiji Config")) {
943 printk(KERN_ERR LOGNAME ": Config port 0x%lx conflict\n",
944 cfg[idx]);
945 snd_card_free(card);
946 return -EIO;
947 }
948 if (reset[idx])
949 if (snd_msnd_pinnacle_cfg_reset(cfg[idx])) {
950 err = -EIO;
951 goto cfg_error;
952 }
953
954 /* DSP */
955 err = snd_msnd_write_cfg_logical(cfg[idx], 0,
956 io[idx], 0,
957 irq[idx], mem[idx]);
958
959 if (err)
960 goto cfg_error;
961
962 /* The following are Pinnacle specific */
963
964 /* MPU */
965 if (mpu_io[idx] != SNDRV_AUTO_PORT
966 && mpu_irq[idx] != SNDRV_AUTO_IRQ) {
967 printk(KERN_INFO LOGNAME
968 ": Configuring MPU to I/O 0x%lx IRQ %d\n",
969 mpu_io[idx], mpu_irq[idx]);
970 err = snd_msnd_write_cfg_logical(cfg[idx], 1,
971 mpu_io[idx], 0,
972 mpu_irq[idx], 0);
973
974 if (err)
975 goto cfg_error;
976 }
977
978 /* IDE */
979 if (ide_io0[idx] != SNDRV_AUTO_PORT
980 && ide_io1[idx] != SNDRV_AUTO_PORT
981 && ide_irq[idx] != SNDRV_AUTO_IRQ) {
982 printk(KERN_INFO LOGNAME
983 ": Configuring IDE to I/O 0x%lx, 0x%lx IRQ %d\n",
984 ide_io0[idx], ide_io1[idx], ide_irq[idx]);
985 err = snd_msnd_write_cfg_logical(cfg[idx], 2,
986 ide_io0[idx], ide_io1[idx],
987 ide_irq[idx], 0);
988
989 if (err)
990 goto cfg_error;
991 }
992
993 /* Joystick */
994 if (joystick_io[idx] != SNDRV_AUTO_PORT) {
995 printk(KERN_INFO LOGNAME
996 ": Configuring joystick to I/O 0x%lx\n",
997 joystick_io[idx]);
998 err = snd_msnd_write_cfg_logical(cfg[idx], 3,
999 joystick_io[idx], 0,
1000 0, 0);
1001
1002 if (err)
1003 goto cfg_error;
1004 }
1005 release_region(cfg[idx], 2);
1006
1007#endif /* MSND_CLASSIC */
1008
1009 set_default_audio_parameters(chip);
1010#ifdef MSND_CLASSIC
1011 chip->type = msndClassic;
1012#else
1013 chip->type = msndPinnacle;
1014#endif
1015 chip->io = io[idx];
1016 chip->irq = irq[idx];
1017 chip->base = mem[idx];
1018
1019 chip->calibrate_signal = calibrate_signal ? 1 : 0;
1020 chip->recsrc = 0;
1021 chip->dspq_data_buff = DSPQ_DATA_BUFF;
1022 chip->dspq_buff_size = DSPQ_BUFF_SIZE;
1023 if (write_ndelay[idx])
1024 clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1025 else
1026 set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1027#ifndef MSND_CLASSIC
1028 if (digital[idx])
1029 set_bit(F_HAVEDIGITAL, &chip->flags);
1030#endif
1031 spin_lock_init(&chip->lock);
1032 err = snd_msnd_probe(card);
1033 if (err < 0) {
1034 printk(KERN_ERR LOGNAME ": Probe failed\n");
1035 snd_card_free(card);
1036 return err;
1037 }
1038
1039 err = snd_msnd_attach(card);
1040 if (err < 0) {
1041 printk(KERN_ERR LOGNAME ": Attach failed\n");
1042 snd_card_free(card);
1043 return err;
1044 }
1045 dev_set_drvdata(pdev, card);
1046
1047 return 0;
1048
1049#ifndef MSND_CLASSIC
1050cfg_error:
1051 release_region(cfg[idx], 2);
1052 snd_card_free(card);
1053 return err;
1054#endif
1055}
1056
1057static int __devexit snd_msnd_isa_remove(struct device *pdev, unsigned int dev)
1058{
1059 snd_msnd_unload(dev_get_drvdata(pdev));
1060 dev_set_drvdata(pdev, NULL);
1061 return 0;
1062}
1063
1064#define DEV_NAME "msnd-pinnacle"
1065
1066static struct isa_driver snd_msnd_driver = {
1067 .match = snd_msnd_isa_match,
1068 .probe = snd_msnd_isa_probe,
1069 .remove = __devexit_p(snd_msnd_isa_remove),
1070 /* FIXME: suspend, resume */
1071 .driver = {
1072 .name = DEV_NAME
1073 },
1074};
1075
1076#ifdef CONFIG_PNP
1077static int __devinit snd_msnd_pnp_detect(struct pnp_card_link *pcard,
1078 const struct pnp_card_device_id *pid)
1079{
1080 static int idx;
1081 struct pnp_dev *pnp_dev;
1082 struct pnp_dev *mpu_dev;
1083 struct snd_card *card;
1084 struct snd_msnd *chip;
1085 int ret;
1086
1087 for ( ; idx < SNDRV_CARDS; idx++) {
1088 if (has_isapnp(idx))
1089 break;
1090 }
1091 if (idx >= SNDRV_CARDS)
1092 return -ENODEV;
1093
1094 /*
1095 * Check that we still have room for another sound card ...
1096 */
1097 pnp_dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
1098 if (!pnp_dev)
1099 return -ENODEV;
1100
1101 mpu_dev = pnp_request_card_device(pcard, pid->devs[1].id, NULL);
1102 if (!mpu_dev)
1103 return -ENODEV;
1104
1105 if (!pnp_is_active(pnp_dev) && pnp_activate_dev(pnp_dev) < 0) {
1106 printk(KERN_INFO "msnd_pinnacle: device is inactive\n");
1107 return -EBUSY;
1108 }
1109
1110 if (!pnp_is_active(mpu_dev) && pnp_activate_dev(mpu_dev) < 0) {
1111 printk(KERN_INFO "msnd_pinnacle: MPU device is inactive\n");
1112 return -EBUSY;
1113 }
1114
1115 /*
1116 * Create a new ALSA sound card entry, in anticipation
1117 * of detecting our hardware ...
1118 */
1119 ret = snd_card_create(index[idx], id[idx], THIS_MODULE,
1120 sizeof(struct snd_msnd), &card);
1121 if (ret < 0)
1122 return ret;
1123
1124 chip = card->private_data;
1125 chip->card = card;
1126 snd_card_set_dev(card, &pcard->card->dev);
1127
1128 /*
1129 * Read the correct parameters off the ISA PnP bus ...
1130 */
1131 io[idx] = pnp_port_start(pnp_dev, 0);
1132 irq[idx] = pnp_irq(pnp_dev, 0);
1133 mem[idx] = pnp_mem_start(pnp_dev, 0);
1134 mpu_io[idx] = pnp_port_start(mpu_dev, 0);
1135 mpu_irq[idx] = pnp_irq(mpu_dev, 0);
1136
1137 set_default_audio_parameters(chip);
1138#ifdef MSND_CLASSIC
1139 chip->type = msndClassic;
1140#else
1141 chip->type = msndPinnacle;
1142#endif
1143 chip->io = io[idx];
1144 chip->irq = irq[idx];
1145 chip->base = mem[idx];
1146
1147 chip->calibrate_signal = calibrate_signal ? 1 : 0;
1148 chip->recsrc = 0;
1149 chip->dspq_data_buff = DSPQ_DATA_BUFF;
1150 chip->dspq_buff_size = DSPQ_BUFF_SIZE;
1151 if (write_ndelay[idx])
1152 clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1153 else
1154 set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
1155#ifndef MSND_CLASSIC
1156 if (digital[idx])
1157 set_bit(F_HAVEDIGITAL, &chip->flags);
1158#endif
1159 spin_lock_init(&chip->lock);
1160 ret = snd_msnd_probe(card);
1161 if (ret < 0) {
1162 printk(KERN_ERR LOGNAME ": Probe failed\n");
1163 goto _release_card;
1164 }
1165
1166 ret = snd_msnd_attach(card);
1167 if (ret < 0) {
1168 printk(KERN_ERR LOGNAME ": Attach failed\n");
1169 goto _release_card;
1170 }
1171
1172 pnp_set_card_drvdata(pcard, card);
1173 ++idx;
1174 return 0;
1175
1176_release_card:
1177 snd_card_free(card);
1178 return ret;
1179}
1180
1181static void __devexit snd_msnd_pnp_remove(struct pnp_card_link *pcard)
1182{
1183 snd_msnd_unload(pnp_get_card_drvdata(pcard));
1184 pnp_set_card_drvdata(pcard, NULL);
1185}
1186
1187static int isa_registered;
1188static int pnp_registered;
1189
1190static struct pnp_card_device_id msnd_pnpids[] = {
1191 /* Pinnacle PnP */
1192 { .id = "BVJ0440", .devs = { { "TBS0000" }, { "TBS0001" } } },
1193 { .id = "" } /* end */
1194};
1195
1196MODULE_DEVICE_TABLE(pnp_card, msnd_pnpids);
1197
1198static struct pnp_card_driver msnd_pnpc_driver = {
1199 .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
1200 .name = "msnd_pinnacle",
1201 .id_table = msnd_pnpids,
1202 .probe = snd_msnd_pnp_detect,
1203 .remove = __devexit_p(snd_msnd_pnp_remove),
1204};
1205#endif /* CONFIG_PNP */
1206
1207static int __init snd_msnd_init(void)
1208{
1209 int err;
1210
1211 err = isa_register_driver(&snd_msnd_driver, SNDRV_CARDS);
1212#ifdef CONFIG_PNP
1213 if (!err)
1214 isa_registered = 1;
1215
1216 err = pnp_register_card_driver(&msnd_pnpc_driver);
1217 if (!err)
1218 pnp_registered = 1;
1219
1220 if (isa_registered)
1221 err = 0;
1222#endif
1223 return err;
1224}
1225
1226static void __exit snd_msnd_exit(void)
1227{
1228#ifdef CONFIG_PNP
1229 if (pnp_registered)
1230 pnp_unregister_card_driver(&msnd_pnpc_driver);
1231 if (isa_registered)
1232#endif
1233 isa_unregister_driver(&snd_msnd_driver);
1234}
1235
1236module_init(snd_msnd_init);
1237module_exit(snd_msnd_exit);
1238
diff --git a/sound/isa/msnd/msnd_pinnacle.h b/sound/isa/msnd/msnd_pinnacle.h
new file mode 100644
index 000000000000..48318d1ee340
--- /dev/null
+++ b/sound/isa/msnd/msnd_pinnacle.h
@@ -0,0 +1,181 @@
1/*********************************************************************
2 *
3 * msnd_pinnacle.h
4 *
5 * Turtle Beach MultiSound Sound Card Driver for Linux
6 *
7 * Some parts of this header file were derived from the Turtle Beach
8 * MultiSound Driver Development Kit.
9 *
10 * Copyright (C) 1998 Andrew Veliath
11 * Copyright (C) 1993 Turtle Beach Systems, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *
27 ********************************************************************/
28#ifndef __MSND_PINNACLE_H
29#define __MSND_PINNACLE_H
30
31#define DSP_NUMIO 0x08
32
33#define IREG_LOGDEVICE 0x07
34#define IREG_ACTIVATE 0x30
35#define LD_ACTIVATE 0x01
36#define LD_DISACTIVATE 0x00
37#define IREG_EECONTROL 0x3F
38#define IREG_MEMBASEHI 0x40
39#define IREG_MEMBASELO 0x41
40#define IREG_MEMCONTROL 0x42
41#define IREG_MEMRANGEHI 0x43
42#define IREG_MEMRANGELO 0x44
43#define MEMTYPE_8BIT 0x00
44#define MEMTYPE_16BIT 0x02
45#define MEMTYPE_RANGE 0x00
46#define MEMTYPE_HIADDR 0x01
47#define IREG_IO0_BASEHI 0x60
48#define IREG_IO0_BASELO 0x61
49#define IREG_IO1_BASEHI 0x62
50#define IREG_IO1_BASELO 0x63
51#define IREG_IRQ_NUMBER 0x70
52#define IREG_IRQ_TYPE 0x71
53#define IRQTYPE_HIGH 0x02
54#define IRQTYPE_LOW 0x00
55#define IRQTYPE_LEVEL 0x01
56#define IRQTYPE_EDGE 0x00
57
58#define HP_DSPR 0x04
59#define HP_BLKS 0x04
60
61#define HPDSPRESET_OFF 2
62#define HPDSPRESET_ON 0
63
64#define HPBLKSEL_0 2
65#define HPBLKSEL_1 3
66
67#define HIMT_DAT_OFF 0x03
68
69#define HIDSP_PLAY_UNDER 0x00
70#define HIDSP_INT_PLAY_UNDER 0x01
71#define HIDSP_SSI_TX_UNDER 0x02
72#define HIDSP_RECQ_OVERFLOW 0x08
73#define HIDSP_INT_RECORD_OVER 0x09
74#define HIDSP_SSI_RX_OVERFLOW 0x0a
75
76#define HIDSP_MIDI_IN_OVER 0x10
77
78#define HIDSP_MIDI_FRAME_ERR 0x11
79#define HIDSP_MIDI_PARITY_ERR 0x12
80#define HIDSP_MIDI_OVERRUN_ERR 0x13
81
82#define HIDSP_INPUT_CLIPPING 0x20
83#define HIDSP_MIX_CLIPPING 0x30
84#define HIDSP_DAT_IN_OFF 0x21
85
86#define TIME_PRO_RESET_DONE 0x028A
87#define TIME_PRO_SYSEX 0x001E
88#define TIME_PRO_RESET 0x0032
89
90#define DAR_BUFF_SIZE 0x1000
91
92#define MIDQ_BUFF_SIZE 0x800
93#define DSPQ_BUFF_SIZE 0x5A0
94
95#define DSPQ_DATA_BUFF 0x7860
96
97#define MOP_WAVEHDR 0
98#define MOP_EXTOUT 1
99#define MOP_HWINIT 0xfe
100#define MOP_NONE 0xff
101#define MOP_MAX 1
102
103#define MIP_EXTIN 0
104#define MIP_WAVEHDR 1
105#define MIP_HWINIT 0xfe
106#define MIP_MAX 1
107
108/* Pinnacle/Fiji SMA Common Data */
109#define SMA_wCurrPlayBytes 0x0000
110#define SMA_wCurrRecordBytes 0x0002
111#define SMA_wCurrPlayVolLeft 0x0004
112#define SMA_wCurrPlayVolRight 0x0006
113#define SMA_wCurrInVolLeft 0x0008
114#define SMA_wCurrInVolRight 0x000a
115#define SMA_wCurrMHdrVolLeft 0x000c
116#define SMA_wCurrMHdrVolRight 0x000e
117#define SMA_dwCurrPlayPitch 0x0010
118#define SMA_dwCurrPlayRate 0x0014
119#define SMA_wCurrMIDIIOPatch 0x0018
120#define SMA_wCurrPlayFormat 0x001a
121#define SMA_wCurrPlaySampleSize 0x001c
122#define SMA_wCurrPlayChannels 0x001e
123#define SMA_wCurrPlaySampleRate 0x0020
124#define SMA_wCurrRecordFormat 0x0022
125#define SMA_wCurrRecordSampleSize 0x0024
126#define SMA_wCurrRecordChannels 0x0026
127#define SMA_wCurrRecordSampleRate 0x0028
128#define SMA_wCurrDSPStatusFlags 0x002a
129#define SMA_wCurrHostStatusFlags 0x002c
130#define SMA_wCurrInputTagBits 0x002e
131#define SMA_wCurrLeftPeak 0x0030
132#define SMA_wCurrRightPeak 0x0032
133#define SMA_bMicPotPosLeft 0x0034
134#define SMA_bMicPotPosRight 0x0035
135#define SMA_bMicPotMaxLeft 0x0036
136#define SMA_bMicPotMaxRight 0x0037
137#define SMA_bInPotPosLeft 0x0038
138#define SMA_bInPotPosRight 0x0039
139#define SMA_bAuxPotPosLeft 0x003a
140#define SMA_bAuxPotPosRight 0x003b
141#define SMA_bInPotMaxLeft 0x003c
142#define SMA_bInPotMaxRight 0x003d
143#define SMA_bAuxPotMaxLeft 0x003e
144#define SMA_bAuxPotMaxRight 0x003f
145#define SMA_bInPotMaxMethod 0x0040
146#define SMA_bAuxPotMaxMethod 0x0041
147#define SMA_wCurrMastVolLeft 0x0042
148#define SMA_wCurrMastVolRight 0x0044
149#define SMA_wCalFreqAtoD 0x0046
150#define SMA_wCurrAuxVolLeft 0x0048
151#define SMA_wCurrAuxVolRight 0x004a
152#define SMA_wCurrPlay1VolLeft 0x004c
153#define SMA_wCurrPlay1VolRight 0x004e
154#define SMA_wCurrPlay2VolLeft 0x0050
155#define SMA_wCurrPlay2VolRight 0x0052
156#define SMA_wCurrPlay3VolLeft 0x0054
157#define SMA_wCurrPlay3VolRight 0x0056
158#define SMA_wCurrPlay4VolLeft 0x0058
159#define SMA_wCurrPlay4VolRight 0x005a
160#define SMA_wCurrPlay1PeakLeft 0x005c
161#define SMA_wCurrPlay1PeakRight 0x005e
162#define SMA_wCurrPlay2PeakLeft 0x0060
163#define SMA_wCurrPlay2PeakRight 0x0062
164#define SMA_wCurrPlay3PeakLeft 0x0064
165#define SMA_wCurrPlay3PeakRight 0x0066
166#define SMA_wCurrPlay4PeakLeft 0x0068
167#define SMA_wCurrPlay4PeakRight 0x006a
168#define SMA_wCurrPlayPeakLeft 0x006c
169#define SMA_wCurrPlayPeakRight 0x006e
170#define SMA_wCurrDATSR 0x0070
171#define SMA_wCurrDATRXCHNL 0x0072
172#define SMA_wCurrDATTXCHNL 0x0074
173#define SMA_wCurrDATRXRate 0x0076
174#define SMA_dwDSPPlayCount 0x0078
175#define SMA__size 0x007c
176
177#define INITCODEFILE "turtlebeach/pndspini.bin"
178#define PERMCODEFILE "turtlebeach/pndsperm.bin"
179#define LONGNAME "MultiSound (Pinnacle/Fiji)"
180
181#endif /* __MSND_PINNACLE_H */
diff --git a/sound/isa/msnd/msnd_pinnacle_mixer.c b/sound/isa/msnd/msnd_pinnacle_mixer.c
new file mode 100644
index 000000000000..494058a1a502
--- /dev/null
+++ b/sound/isa/msnd/msnd_pinnacle_mixer.c
@@ -0,0 +1,343 @@
1/***************************************************************************
2 msnd_pinnacle_mixer.c - description
3 -------------------
4 begin : Fre Jun 7 2002
5 copyright : (C) 2002 by karsten wiese
6 email : annabellesgarden@yahoo.de
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include <linux/io.h>
19
20#include <sound/core.h>
21#include <sound/control.h>
22#include "msnd.h"
23#include "msnd_pinnacle.h"
24
25
26#define MSND_MIXER_VOLUME 0
27#define MSND_MIXER_PCM 1
28#define MSND_MIXER_AUX 2 /* Input source 1 (aux1) */
29#define MSND_MIXER_IMIX 3 /* Recording monitor */
30#define MSND_MIXER_SYNTH 4
31#define MSND_MIXER_SPEAKER 5
32#define MSND_MIXER_LINE 6
33#define MSND_MIXER_MIC 7
34#define MSND_MIXER_RECLEV 11 /* Recording level */
35#define MSND_MIXER_IGAIN 12 /* Input gain */
36#define MSND_MIXER_OGAIN 13 /* Output gain */
37#define MSND_MIXER_DIGITAL 17 /* Digital (input) 1 */
38
39/* Device mask bits */
40
41#define MSND_MASK_VOLUME (1 << MSND_MIXER_VOLUME)
42#define MSND_MASK_SYNTH (1 << MSND_MIXER_SYNTH)
43#define MSND_MASK_PCM (1 << MSND_MIXER_PCM)
44#define MSND_MASK_SPEAKER (1 << MSND_MIXER_SPEAKER)
45#define MSND_MASK_LINE (1 << MSND_MIXER_LINE)
46#define MSND_MASK_MIC (1 << MSND_MIXER_MIC)
47#define MSND_MASK_IMIX (1 << MSND_MIXER_IMIX)
48#define MSND_MASK_RECLEV (1 << MSND_MIXER_RECLEV)
49#define MSND_MASK_IGAIN (1 << MSND_MIXER_IGAIN)
50#define MSND_MASK_OGAIN (1 << MSND_MIXER_OGAIN)
51#define MSND_MASK_AUX (1 << MSND_MIXER_AUX)
52#define MSND_MASK_DIGITAL (1 << MSND_MIXER_DIGITAL)
53
54static int snd_msndmix_info_mux(struct snd_kcontrol *kcontrol,
55 struct snd_ctl_elem_info *uinfo)
56{
57 static char *texts[3] = {
58 "Analog", "MASS", "SPDIF",
59 };
60 struct snd_msnd *chip = snd_kcontrol_chip(kcontrol);
61 unsigned items = test_bit(F_HAVEDIGITAL, &chip->flags) ? 3 : 2;
62
63 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
64 uinfo->count = 1;
65 uinfo->value.enumerated.items = items;
66 if (uinfo->value.enumerated.item >= items)
67 uinfo->value.enumerated.item = items - 1;
68 strcpy(uinfo->value.enumerated.name,
69 texts[uinfo->value.enumerated.item]);
70 return 0;
71}
72
73static int snd_msndmix_get_mux(struct snd_kcontrol *kcontrol,
74 struct snd_ctl_elem_value *ucontrol)
75{
76 struct snd_msnd *chip = snd_kcontrol_chip(kcontrol);
77 /* MSND_MASK_IMIX is the default */
78 ucontrol->value.enumerated.item[0] = 0;
79
80 if (chip->recsrc & MSND_MASK_SYNTH) {
81 ucontrol->value.enumerated.item[0] = 1;
82 } else if ((chip->recsrc & MSND_MASK_DIGITAL) &&
83 test_bit(F_HAVEDIGITAL, &chip->flags)) {
84 ucontrol->value.enumerated.item[0] = 2;
85 }
86
87
88 return 0;
89}
90
91static int snd_msndmix_set_mux(struct snd_msnd *chip, int val)
92{
93 unsigned newrecsrc;
94 int change;
95 unsigned char msndbyte;
96
97 switch (val) {
98 case 0:
99 newrecsrc = MSND_MASK_IMIX;
100 msndbyte = HDEXAR_SET_ANA_IN;
101 break;
102 case 1:
103 newrecsrc = MSND_MASK_SYNTH;
104 msndbyte = HDEXAR_SET_SYNTH_IN;
105 break;
106 case 2:
107 newrecsrc = MSND_MASK_DIGITAL;
108 msndbyte = HDEXAR_SET_DAT_IN;
109 break;
110 default:
111 return -EINVAL;
112 }
113 change = newrecsrc != chip->recsrc;
114 if (change) {
115 change = 0;
116 if (!snd_msnd_send_word(chip, 0, 0, msndbyte))
117 if (!snd_msnd_send_dsp_cmd(chip, HDEX_AUX_REQ)) {
118 chip->recsrc = newrecsrc;
119 change = 1;
120 }
121 }
122 return change;
123}
124
125static int snd_msndmix_put_mux(struct snd_kcontrol *kcontrol,
126 struct snd_ctl_elem_value *ucontrol)
127{
128 struct snd_msnd *msnd = snd_kcontrol_chip(kcontrol);
129 return snd_msndmix_set_mux(msnd, ucontrol->value.enumerated.item[0]);
130}
131
132
133static int snd_msndmix_volume_info(struct snd_kcontrol *kcontrol,
134 struct snd_ctl_elem_info *uinfo)
135{
136 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
137 uinfo->count = 2;
138 uinfo->value.integer.min = 0;
139 uinfo->value.integer.max = 100;
140 return 0;
141}
142
143static int snd_msndmix_volume_get(struct snd_kcontrol *kcontrol,
144 struct snd_ctl_elem_value *ucontrol)
145{
146 struct snd_msnd *msnd = snd_kcontrol_chip(kcontrol);
147 int addr = kcontrol->private_value;
148 unsigned long flags;
149
150 spin_lock_irqsave(&msnd->mixer_lock, flags);
151 ucontrol->value.integer.value[0] = msnd->left_levels[addr] * 100;
152 ucontrol->value.integer.value[0] /= 0xFFFF;
153 ucontrol->value.integer.value[1] = msnd->right_levels[addr] * 100;
154 ucontrol->value.integer.value[1] /= 0xFFFF;
155 spin_unlock_irqrestore(&msnd->mixer_lock, flags);
156 return 0;
157}
158
159#define update_volm(a, b) \
160 do { \
161 writew((dev->left_levels[a] >> 1) * \
162 readw(dev->SMA + SMA_wCurrMastVolLeft) / 0xffff, \
163 dev->SMA + SMA_##b##Left); \
164 writew((dev->right_levels[a] >> 1) * \
165 readw(dev->SMA + SMA_wCurrMastVolRight) / 0xffff, \
166 dev->SMA + SMA_##b##Right); \
167 } while (0);
168
169#define update_potm(d, s, ar) \
170 do { \
171 writeb((dev->left_levels[d] >> 8) * \
172 readw(dev->SMA + SMA_wCurrMastVolLeft) / 0xffff, \
173 dev->SMA + SMA_##s##Left); \
174 writeb((dev->right_levels[d] >> 8) * \
175 readw(dev->SMA + SMA_wCurrMastVolRight) / 0xffff, \
176 dev->SMA + SMA_##s##Right); \
177 if (snd_msnd_send_word(dev, 0, 0, ar) == 0) \
178 snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ); \
179 } while (0);
180
181#define update_pot(d, s, ar) \
182 do { \
183 writeb(dev->left_levels[d] >> 8, \
184 dev->SMA + SMA_##s##Left); \
185 writeb(dev->right_levels[d] >> 8, \
186 dev->SMA + SMA_##s##Right); \
187 if (snd_msnd_send_word(dev, 0, 0, ar) == 0) \
188 snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ); \
189 } while (0);
190
191
192static int snd_msndmix_set(struct snd_msnd *dev, int d, int left, int right)
193{
194 int bLeft, bRight;
195 int wLeft, wRight;
196 int updatemaster = 0;
197
198 if (d >= LEVEL_ENTRIES)
199 return -EINVAL;
200
201 bLeft = left * 0xff / 100;
202 wLeft = left * 0xffff / 100;
203
204 bRight = right * 0xff / 100;
205 wRight = right * 0xffff / 100;
206
207 dev->left_levels[d] = wLeft;
208 dev->right_levels[d] = wRight;
209
210 switch (d) {
211 /* master volume unscaled controls */
212 case MSND_MIXER_LINE: /* line pot control */
213 /* scaled by IMIX in digital mix */
214 writeb(bLeft, dev->SMA + SMA_bInPotPosLeft);
215 writeb(bRight, dev->SMA + SMA_bInPotPosRight);
216 if (snd_msnd_send_word(dev, 0, 0, HDEXAR_IN_SET_POTS) == 0)
217 snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ);
218 break;
219 case MSND_MIXER_MIC: /* mic pot control */
220 if (dev->type == msndClassic)
221 return -EINVAL;
222 /* scaled by IMIX in digital mix */
223 writeb(bLeft, dev->SMA + SMA_bMicPotPosLeft);
224 writeb(bRight, dev->SMA + SMA_bMicPotPosRight);
225 if (snd_msnd_send_word(dev, 0, 0, HDEXAR_MIC_SET_POTS) == 0)
226 snd_msnd_send_dsp_cmd(dev, HDEX_AUX_REQ);
227 break;
228 case MSND_MIXER_VOLUME: /* master volume */
229 writew(wLeft, dev->SMA + SMA_wCurrMastVolLeft);
230 writew(wRight, dev->SMA + SMA_wCurrMastVolRight);
231 /* fall through */
232
233 case MSND_MIXER_AUX: /* aux pot control */
234 /* scaled by master volume */
235 /* fall through */
236
237 /* digital controls */
238 case MSND_MIXER_SYNTH: /* synth vol (dsp mix) */
239 case MSND_MIXER_PCM: /* pcm vol (dsp mix) */
240 case MSND_MIXER_IMIX: /* input monitor (dsp mix) */
241 /* scaled by master volume */
242 updatemaster = 1;
243 break;
244
245 default:
246 return -EINVAL;
247 }
248
249 if (updatemaster) {
250 /* update master volume scaled controls */
251 update_volm(MSND_MIXER_PCM, wCurrPlayVol);
252 update_volm(MSND_MIXER_IMIX, wCurrInVol);
253 if (dev->type == msndPinnacle)
254 update_volm(MSND_MIXER_SYNTH, wCurrMHdrVol);
255 update_potm(MSND_MIXER_AUX, bAuxPotPos, HDEXAR_AUX_SET_POTS);
256 }
257
258 return 0;
259}
260
261static int snd_msndmix_volume_put(struct snd_kcontrol *kcontrol,
262 struct snd_ctl_elem_value *ucontrol)
263{
264 struct snd_msnd *msnd = snd_kcontrol_chip(kcontrol);
265 int change, addr = kcontrol->private_value;
266 int left, right;
267 unsigned long flags;
268
269 left = ucontrol->value.integer.value[0] % 101;
270 right = ucontrol->value.integer.value[1] % 101;
271 spin_lock_irqsave(&msnd->mixer_lock, flags);
272 change = msnd->left_levels[addr] != left
273 || msnd->right_levels[addr] != right;
274 snd_msndmix_set(msnd, addr, left, right);
275 spin_unlock_irqrestore(&msnd->mixer_lock, flags);
276 return change;
277}
278
279
280#define DUMMY_VOLUME(xname, xindex, addr) \
281{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
282 .info = snd_msndmix_volume_info, \
283 .get = snd_msndmix_volume_get, .put = snd_msndmix_volume_put, \
284 .private_value = addr }
285
286
287static struct snd_kcontrol_new snd_msnd_controls[] = {
288DUMMY_VOLUME("Master Volume", 0, MSND_MIXER_VOLUME),
289DUMMY_VOLUME("PCM Volume", 0, MSND_MIXER_PCM),
290DUMMY_VOLUME("Aux Volume", 0, MSND_MIXER_AUX),
291DUMMY_VOLUME("Line Volume", 0, MSND_MIXER_LINE),
292DUMMY_VOLUME("Mic Volume", 0, MSND_MIXER_MIC),
293DUMMY_VOLUME("Monitor", 0, MSND_MIXER_IMIX),
294{
295 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
296 .name = "Capture Source",
297 .info = snd_msndmix_info_mux,
298 .get = snd_msndmix_get_mux,
299 .put = snd_msndmix_put_mux,
300}
301};
302
303
304int __devinit snd_msndmix_new(struct snd_card *card)
305{
306 struct snd_msnd *chip = card->private_data;
307 unsigned int idx;
308 int err;
309
310 if (snd_BUG_ON(!chip))
311 return -EINVAL;
312 spin_lock_init(&chip->mixer_lock);
313 strcpy(card->mixername, "MSND Pinnacle Mixer");
314
315 for (idx = 0; idx < ARRAY_SIZE(snd_msnd_controls); idx++)
316 err = snd_ctl_add(card,
317 snd_ctl_new1(snd_msnd_controls + idx, chip));
318 if (err < 0)
319 return err;
320
321 return 0;
322}
323EXPORT_SYMBOL(snd_msndmix_new);
324
325void snd_msndmix_setup(struct snd_msnd *dev)
326{
327 update_pot(MSND_MIXER_LINE, bInPotPos, HDEXAR_IN_SET_POTS);
328 update_potm(MSND_MIXER_AUX, bAuxPotPos, HDEXAR_AUX_SET_POTS);
329 update_volm(MSND_MIXER_PCM, wCurrPlayVol);
330 update_volm(MSND_MIXER_IMIX, wCurrInVol);
331 if (dev->type == msndPinnacle) {
332 update_pot(MSND_MIXER_MIC, bMicPotPos, HDEXAR_MIC_SET_POTS);
333 update_volm(MSND_MIXER_SYNTH, wCurrMHdrVol);
334 }
335}
336EXPORT_SYMBOL(snd_msndmix_setup);
337
338int snd_msndmix_force_recsrc(struct snd_msnd *dev, int recsrc)
339{
340 dev->recsrc = -1;
341 return snd_msndmix_set_mux(dev, recsrc);
342}
343EXPORT_SYMBOL(snd_msndmix_force_recsrc);
diff --git a/sound/isa/opl3sa2.c b/sound/isa/opl3sa2.c
index b848d1001864..ef95279da7a3 100644
--- a/sound/isa/opl3sa2.c
+++ b/sound/isa/opl3sa2.c
@@ -179,12 +179,13 @@ static unsigned char __snd_opl3sa2_read(struct snd_opl3sa2 *chip, unsigned char
179 unsigned char result; 179 unsigned char result;
180#if 0 180#if 0
181 outb(0x1d, port); /* password */ 181 outb(0x1d, port); /* password */
182 printk("read [0x%lx] = 0x%x\n", port, inb(port)); 182 printk(KERN_DEBUG "read [0x%lx] = 0x%x\n", port, inb(port));
183#endif 183#endif
184 outb(reg, chip->port); /* register */ 184 outb(reg, chip->port); /* register */
185 result = inb(chip->port + 1); 185 result = inb(chip->port + 1);
186#if 0 186#if 0
187 printk("read [0x%lx] = 0x%x [0x%x]\n", port, result, inb(port)); 187 printk(KERN_DEBUG "read [0x%lx] = 0x%x [0x%x]\n",
188 port, result, inb(port));
188#endif 189#endif
189 return result; 190 return result;
190} 191}
@@ -233,7 +234,10 @@ static int __devinit snd_opl3sa2_detect(struct snd_card *card)
233 snd_printk(KERN_ERR PFX "can't grab port 0x%lx\n", port); 234 snd_printk(KERN_ERR PFX "can't grab port 0x%lx\n", port);
234 return -EBUSY; 235 return -EBUSY;
235 } 236 }
236 // snd_printk("REG 0A = 0x%x\n", snd_opl3sa2_read(chip, 0x0a)); 237 /*
238 snd_printk(KERN_DEBUG "REG 0A = 0x%x\n",
239 snd_opl3sa2_read(chip, 0x0a));
240 */
237 chip->version = 0; 241 chip->version = 0;
238 tmp = snd_opl3sa2_read(chip, OPL3SA2_MISC); 242 tmp = snd_opl3sa2_read(chip, OPL3SA2_MISC);
239 if (tmp == 0xff) { 243 if (tmp == 0xff) {
@@ -619,25 +623,28 @@ static void snd_opl3sa2_free(struct snd_card *card)
619{ 623{
620 struct snd_opl3sa2 *chip = card->private_data; 624 struct snd_opl3sa2 *chip = card->private_data;
621 if (chip->irq >= 0) 625 if (chip->irq >= 0)
622 free_irq(chip->irq, (void *)chip); 626 free_irq(chip->irq, card);
623 release_and_free_resource(chip->res_port); 627 release_and_free_resource(chip->res_port);
624} 628}
625 629
626static struct snd_card *snd_opl3sa2_card_new(int dev) 630static int snd_opl3sa2_card_new(int dev, struct snd_card **cardp)
627{ 631{
628 struct snd_card *card; 632 struct snd_card *card;
629 struct snd_opl3sa2 *chip; 633 struct snd_opl3sa2 *chip;
634 int err;
630 635
631 card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct snd_opl3sa2)); 636 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
632 if (card == NULL) 637 sizeof(struct snd_opl3sa2), &card);
633 return NULL; 638 if (err < 0)
639 return err;
634 strcpy(card->driver, "OPL3SA2"); 640 strcpy(card->driver, "OPL3SA2");
635 strcpy(card->shortname, "Yamaha OPL3-SA2"); 641 strcpy(card->shortname, "Yamaha OPL3-SA");
636 chip = card->private_data; 642 chip = card->private_data;
637 spin_lock_init(&chip->reg_lock); 643 spin_lock_init(&chip->reg_lock);
638 chip->irq = -1; 644 chip->irq = -1;
639 card->private_free = snd_opl3sa2_free; 645 card->private_free = snd_opl3sa2_free;
640 return card; 646 *cardp = card;
647 return 0;
641} 648}
642 649
643static int __devinit snd_opl3sa2_probe(struct snd_card *card, int dev) 650static int __devinit snd_opl3sa2_probe(struct snd_card *card, int dev)
@@ -729,9 +736,9 @@ static int __devinit snd_opl3sa2_pnp_detect(struct pnp_dev *pdev,
729 if (dev >= SNDRV_CARDS) 736 if (dev >= SNDRV_CARDS)
730 return -ENODEV; 737 return -ENODEV;
731 738
732 card = snd_opl3sa2_card_new(dev); 739 err = snd_opl3sa2_card_new(dev, &card);
733 if (! card) 740 if (err < 0)
734 return -ENOMEM; 741 return err;
735 if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) { 742 if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) {
736 snd_card_free(card); 743 snd_card_free(card);
737 return err; 744 return err;
@@ -795,9 +802,9 @@ static int __devinit snd_opl3sa2_pnp_cdetect(struct pnp_card_link *pcard,
795 if (dev >= SNDRV_CARDS) 802 if (dev >= SNDRV_CARDS)
796 return -ENODEV; 803 return -ENODEV;
797 804
798 card = snd_opl3sa2_card_new(dev); 805 err = snd_opl3sa2_card_new(dev, &card);
799 if (! card) 806 if (err < 0)
800 return -ENOMEM; 807 return err;
801 if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) { 808 if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) {
802 snd_card_free(card); 809 snd_card_free(card);
803 return err; 810 return err;
@@ -876,9 +883,9 @@ static int __devinit snd_opl3sa2_isa_probe(struct device *pdev,
876 struct snd_card *card; 883 struct snd_card *card;
877 int err; 884 int err;
878 885
879 card = snd_opl3sa2_card_new(dev); 886 err = snd_opl3sa2_card_new(dev, &card);
880 if (! card) 887 if (err < 0)
881 return -ENOMEM; 888 return err;
882 snd_card_set_dev(card, pdev); 889 snd_card_set_dev(card, pdev);
883 if ((err = snd_opl3sa2_probe(card, dev)) < 0) { 890 if ((err = snd_opl3sa2_probe(card, dev)) < 0) {
884 snd_card_free(card); 891 snd_card_free(card);
diff --git a/sound/isa/opti9xx/miro.c b/sound/isa/opti9xx/miro.c
index 440755cc0013..02e30d7c6a93 100644
--- a/sound/isa/opti9xx/miro.c
+++ b/sound/isa/opti9xx/miro.c
@@ -1228,9 +1228,10 @@ static int __devinit snd_miro_probe(struct device *devptr, unsigned int n)
1228 struct snd_pcm *pcm; 1228 struct snd_pcm *pcm;
1229 struct snd_rawmidi *rmidi; 1229 struct snd_rawmidi *rmidi;
1230 1230
1231 if (!(card = snd_card_new(index, id, THIS_MODULE, 1231 error = snd_card_create(index, id, THIS_MODULE,
1232 sizeof(struct snd_miro)))) 1232 sizeof(struct snd_miro), &card);
1233 return -ENOMEM; 1233 if (error < 0)
1234 return error;
1234 1235
1235 card->private_free = snd_card_miro_free; 1236 card->private_free = snd_card_miro_free;
1236 miro = card->private_data; 1237 miro = card->private_data;
diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c
index 19706b0d8497..5cd555325b9d 100644
--- a/sound/isa/opti9xx/opti92x-ad1848.c
+++ b/sound/isa/opti9xx/opti92x-ad1848.c
@@ -252,7 +252,7 @@ static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip,
252#endif /* OPTi93X */ 252#endif /* OPTi93X */
253 253
254 default: 254 default:
255 snd_printk("chip %d not supported\n", hardware); 255 snd_printk(KERN_ERR "chip %d not supported\n", hardware);
256 return -ENODEV; 256 return -ENODEV;
257 } 257 }
258 return 0; 258 return 0;
@@ -294,7 +294,7 @@ static unsigned char snd_opti9xx_read(struct snd_opti9xx *chip,
294#endif /* OPTi93X */ 294#endif /* OPTi93X */
295 295
296 default: 296 default:
297 snd_printk("chip %d not supported\n", chip->hardware); 297 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
298 } 298 }
299 299
300 spin_unlock_irqrestore(&chip->lock, flags); 300 spin_unlock_irqrestore(&chip->lock, flags);
@@ -336,7 +336,7 @@ static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
336#endif /* OPTi93X */ 336#endif /* OPTi93X */
337 337
338 default: 338 default:
339 snd_printk("chip %d not supported\n", chip->hardware); 339 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
340 } 340 }
341 341
342 spin_unlock_irqrestore(&chip->lock, flags); 342 spin_unlock_irqrestore(&chip->lock, flags);
@@ -412,7 +412,7 @@ static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
412#endif /* OPTi93X */ 412#endif /* OPTi93X */
413 413
414 default: 414 default:
415 snd_printk("chip %d not supported\n", chip->hardware); 415 snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
416 return -EINVAL; 416 return -EINVAL;
417 } 417 }
418 418
@@ -430,7 +430,8 @@ static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
430 wss_base_bits = 0x02; 430 wss_base_bits = 0x02;
431 break; 431 break;
432 default: 432 default:
433 snd_printk("WSS port 0x%lx not valid\n", chip->wss_base); 433 snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n",
434 chip->wss_base);
434 goto __skip_base; 435 goto __skip_base;
435 } 436 }
436 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30); 437 snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
@@ -455,7 +456,7 @@ __skip_base:
455 irq_bits = 0x04; 456 irq_bits = 0x04;
456 break; 457 break;
457 default: 458 default:
458 snd_printk("WSS irq # %d not valid\n", chip->irq); 459 snd_printk(KERN_WARNING "WSS irq # %d not valid\n", chip->irq);
459 goto __skip_resources; 460 goto __skip_resources;
460 } 461 }
461 462
@@ -470,13 +471,14 @@ __skip_base:
470 dma_bits = 0x03; 471 dma_bits = 0x03;
471 break; 472 break;
472 default: 473 default:
473 snd_printk("WSS dma1 # %d not valid\n", chip->dma1); 474 snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n",
475 chip->dma1);
474 goto __skip_resources; 476 goto __skip_resources;
475 } 477 }
476 478
477#if defined(CS4231) || defined(OPTi93X) 479#if defined(CS4231) || defined(OPTi93X)
478 if (chip->dma1 == chip->dma2) { 480 if (chip->dma1 == chip->dma2) {
479 snd_printk("don't want to share dmas\n"); 481 snd_printk(KERN_ERR "don't want to share dmas\n");
480 return -EBUSY; 482 return -EBUSY;
481 } 483 }
482 484
@@ -485,7 +487,8 @@ __skip_base:
485 case 1: 487 case 1:
486 break; 488 break;
487 default: 489 default:
488 snd_printk("WSS dma2 # %d not valid\n", chip->dma2); 490 snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n",
491 chip->dma2);
489 goto __skip_resources; 492 goto __skip_resources;
490 } 493 }
491 dma_bits |= 0x04; 494 dma_bits |= 0x04;
@@ -516,7 +519,8 @@ __skip_resources:
516 mpu_port_bits = 0x00; 519 mpu_port_bits = 0x00;
517 break; 520 break;
518 default: 521 default:
519 snd_printk("MPU-401 port 0x%lx not valid\n", 522 snd_printk(KERN_WARNING
523 "MPU-401 port 0x%lx not valid\n",
520 chip->mpu_port); 524 chip->mpu_port);
521 goto __skip_mpu; 525 goto __skip_mpu;
522 } 526 }
@@ -535,7 +539,7 @@ __skip_resources:
535 mpu_irq_bits = 0x01; 539 mpu_irq_bits = 0x01;
536 break; 540 break;
537 default: 541 default:
538 snd_printk("MPU-401 irq # %d not valid\n", 542 snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n",
539 chip->mpu_irq); 543 chip->mpu_irq);
540 goto __skip_mpu; 544 goto __skip_mpu;
541 } 545 }
@@ -726,7 +730,7 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
726 if (chip->wss_base == SNDRV_AUTO_PORT) { 730 if (chip->wss_base == SNDRV_AUTO_PORT) {
727 chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4); 731 chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4);
728 if (chip->wss_base < 0) { 732 if (chip->wss_base < 0) {
729 snd_printk("unable to find a free WSS port\n"); 733 snd_printk(KERN_ERR "unable to find a free WSS port\n");
730 return -EBUSY; 734 return -EBUSY;
731 } 735 }
732 } 736 }
@@ -815,14 +819,8 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
815 chip->fm_port, chip->fm_port + 4 - 1); 819 chip->fm_port, chip->fm_port + 4 - 1);
816 } 820 }
817 if (opl3) { 821 if (opl3) {
818#ifdef CS4231 822 error = snd_opl3_hwdep_new(opl3, 0, 1, &synth);
819 const int t1dev = 1; 823 if (error < 0)
820#else
821 const int t1dev = 0;
822#endif
823 if ((error = snd_opl3_timer_new(opl3, t1dev, t1dev+1)) < 0)
824 return error;
825 if ((error = snd_opl3_hwdep_new(opl3, 0, 1, &synth)) < 0)
826 return error; 824 return error;
827 } 825 }
828 } 826 }
@@ -830,15 +828,18 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
830 return snd_card_register(card); 828 return snd_card_register(card);
831} 829}
832 830
833static struct snd_card *snd_opti9xx_card_new(void) 831static int snd_opti9xx_card_new(struct snd_card **cardp)
834{ 832{
835 struct snd_card *card; 833 struct snd_card *card;
834 int err;
836 835
837 card = snd_card_new(index, id, THIS_MODULE, sizeof(struct snd_opti9xx)); 836 err = snd_card_create(index, id, THIS_MODULE,
838 if (! card) 837 sizeof(struct snd_opti9xx), &card);
839 return NULL; 838 if (err < 0)
839 return err;
840 card->private_free = snd_card_opti9xx_free; 840 card->private_free = snd_card_opti9xx_free;
841 return card; 841 *cardp = card;
842 return 0;
842} 843}
843 844
844static int __devinit snd_opti9xx_isa_match(struct device *devptr, 845static int __devinit snd_opti9xx_isa_match(struct device *devptr,
@@ -897,15 +898,15 @@ static int __devinit snd_opti9xx_isa_probe(struct device *devptr,
897#if defined(CS4231) || defined(OPTi93X) 898#if defined(CS4231) || defined(OPTi93X)
898 if (dma2 == SNDRV_AUTO_DMA) { 899 if (dma2 == SNDRV_AUTO_DMA) {
899 if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) { 900 if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) {
900 snd_printk("unable to find a free DMA2\n"); 901 snd_printk(KERN_ERR "unable to find a free DMA2\n");
901 return -EBUSY; 902 return -EBUSY;
902 } 903 }
903 } 904 }
904#endif 905#endif
905 906
906 card = snd_opti9xx_card_new(); 907 error = snd_opti9xx_card_new(&card);
907 if (! card) 908 if (error < 0)
908 return -ENOMEM; 909 return error;
909 910
910 if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) { 911 if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) {
911 snd_card_free(card); 912 snd_card_free(card);
@@ -950,9 +951,9 @@ static int __devinit snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
950 return -EBUSY; 951 return -EBUSY;
951 if (! isapnp) 952 if (! isapnp)
952 return -ENODEV; 953 return -ENODEV;
953 card = snd_opti9xx_card_new(); 954 error = snd_opti9xx_card_new(&card);
954 if (! card) 955 if (error < 0)
955 return -ENOMEM; 956 return error;
956 chip = card->private_data; 957 chip = card->private_data;
957 958
958 hw = snd_card_opti9xx_pnp(chip, pcard, pid); 959 hw = snd_card_opti9xx_pnp(chip, pcard, pid);
diff --git a/sound/isa/sb/es968.c b/sound/isa/sb/es968.c
index c8c8e214c843..cafc3a7316a8 100644
--- a/sound/isa/sb/es968.c
+++ b/sound/isa/sb/es968.c
@@ -108,9 +108,10 @@ static int __devinit snd_card_es968_probe(int dev,
108 struct snd_card *card; 108 struct snd_card *card;
109 struct snd_card_es968 *acard; 109 struct snd_card_es968 *acard;
110 110
111 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE, 111 error = snd_card_create(index[dev], id[dev], THIS_MODULE,
112 sizeof(struct snd_card_es968))) == NULL) 112 sizeof(struct snd_card_es968), &card);
113 return -ENOMEM; 113 if (error < 0)
114 return error;
114 acard = card->private_data; 115 acard = card->private_data;
115 if ((error = snd_card_es968_pnp(dev, acard, pcard, pid))) { 116 if ((error = snd_card_es968_pnp(dev, acard, pcard, pid))) {
116 snd_card_free(card); 117 snd_card_free(card);
diff --git a/sound/isa/sb/sb16.c b/sound/isa/sb/sb16.c
index 2c201f78ce50..519c36346dec 100644
--- a/sound/isa/sb/sb16.c
+++ b/sound/isa/sb/sb16.c
@@ -324,14 +324,18 @@ static void snd_sb16_free(struct snd_card *card)
324#define is_isapnp_selected(dev) 0 324#define is_isapnp_selected(dev) 0
325#endif 325#endif
326 326
327static struct snd_card *snd_sb16_card_new(int dev) 327static int snd_sb16_card_new(int dev, struct snd_card **cardp)
328{ 328{
329 struct snd_card *card = snd_card_new(index[dev], id[dev], THIS_MODULE, 329 struct snd_card *card;
330 sizeof(struct snd_card_sb16)); 330 int err;
331 if (card == NULL) 331
332 return NULL; 332 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
333 sizeof(struct snd_card_sb16), &card);
334 if (err < 0)
335 return err;
333 card->private_free = snd_sb16_free; 336 card->private_free = snd_sb16_free;
334 return card; 337 *cardp = card;
338 return 0;
335} 339}
336 340
337static int __devinit snd_sb16_probe(struct snd_card *card, int dev) 341static int __devinit snd_sb16_probe(struct snd_card *card, int dev)
@@ -489,9 +493,9 @@ static int __devinit snd_sb16_isa_probe1(int dev, struct device *pdev)
489 struct snd_card *card; 493 struct snd_card *card;
490 int err; 494 int err;
491 495
492 card = snd_sb16_card_new(dev); 496 err = snd_sb16_card_new(dev, &card);
493 if (! card) 497 if (err < 0)
494 return -ENOMEM; 498 return err;
495 499
496 acard = card->private_data; 500 acard = card->private_data;
497 /* non-PnP FM port address is hardwired with base port address */ 501 /* non-PnP FM port address is hardwired with base port address */
@@ -610,9 +614,9 @@ static int __devinit snd_sb16_pnp_detect(struct pnp_card_link *pcard,
610 for ( ; dev < SNDRV_CARDS; dev++) { 614 for ( ; dev < SNDRV_CARDS; dev++) {
611 if (!enable[dev] || !isapnp[dev]) 615 if (!enable[dev] || !isapnp[dev])
612 continue; 616 continue;
613 card = snd_sb16_card_new(dev); 617 res = snd_sb16_card_new(dev, &card);
614 if (! card) 618 if (res < 0)
615 return -ENOMEM; 619 return res;
616 snd_card_set_dev(card, &pcard->card->dev); 620 snd_card_set_dev(card, &pcard->card->dev);
617 if ((res = snd_card_sb16_pnp(dev, card->private_data, pcard, pid)) < 0 || 621 if ((res = snd_card_sb16_pnp(dev, card->private_data, pcard, pid)) < 0 ||
618 (res = snd_sb16_probe(card, dev)) < 0) { 622 (res = snd_sb16_probe(card, dev)) < 0) {
diff --git a/sound/isa/sb/sb8.c b/sound/isa/sb/sb8.c
index ea06877be4b1..3cd57ee54660 100644
--- a/sound/isa/sb/sb8.c
+++ b/sound/isa/sb/sb8.c
@@ -103,10 +103,10 @@ static int __devinit snd_sb8_probe(struct device *pdev, unsigned int dev)
103 struct snd_opl3 *opl3; 103 struct snd_opl3 *opl3;
104 int err; 104 int err;
105 105
106 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 106 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
107 sizeof(struct snd_sb8)); 107 sizeof(struct snd_sb8), &card);
108 if (card == NULL) 108 if (err < 0)
109 return -ENOMEM; 109 return err;
110 acard = card->private_data; 110 acard = card->private_data;
111 card->private_free = snd_sb8_free; 111 card->private_free = snd_sb8_free;
112 112
diff --git a/sound/isa/sb/sb_mixer.c b/sound/isa/sb/sb_mixer.c
index 406a431af91e..475220bbcc96 100644
--- a/sound/isa/sb/sb_mixer.c
+++ b/sound/isa/sb/sb_mixer.c
@@ -182,7 +182,7 @@ static int snd_sbmixer_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_
182 182
183static int snd_dt019x_input_sw_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 183static int snd_dt019x_input_sw_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
184{ 184{
185 static char *texts[5] = { 185 static const char *texts[5] = {
186 "CD", "Mic", "Line", "Synth", "Master" 186 "CD", "Mic", "Line", "Synth", "Master"
187 }; 187 };
188 188
@@ -269,12 +269,73 @@ static int snd_dt019x_input_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl
269} 269}
270 270
271/* 271/*
272 * ALS4000 mono recording control switch
273 */
274
275static int snd_als4k_mono_capture_route_info(struct snd_kcontrol *kcontrol,
276 struct snd_ctl_elem_info *uinfo)
277{
278 static const char *texts[3] = {
279 "L chan only", "R chan only", "L ch/2 + R ch/2"
280 };
281
282 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
283 uinfo->count = 1;
284 uinfo->value.enumerated.items = 3;
285 if (uinfo->value.enumerated.item > 2)
286 uinfo->value.enumerated.item = 2;
287 strcpy(uinfo->value.enumerated.name,
288 texts[uinfo->value.enumerated.item]);
289 return 0;
290}
291
292static int snd_als4k_mono_capture_route_get(struct snd_kcontrol *kcontrol,
293 struct snd_ctl_elem_value *ucontrol)
294{
295 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
296 unsigned long flags;
297 unsigned char oval;
298
299 spin_lock_irqsave(&sb->mixer_lock, flags);
300 oval = snd_sbmixer_read(sb, SB_ALS4000_MONO_IO_CTRL);
301 spin_unlock_irqrestore(&sb->mixer_lock, flags);
302 oval >>= 6;
303 if (oval > 2)
304 oval = 2;
305
306 ucontrol->value.enumerated.item[0] = oval;
307 return 0;
308}
309
310static int snd_als4k_mono_capture_route_put(struct snd_kcontrol *kcontrol,
311 struct snd_ctl_elem_value *ucontrol)
312{
313 struct snd_sb *sb = snd_kcontrol_chip(kcontrol);
314 unsigned long flags;
315 int change;
316 unsigned char nval, oval;
317
318 if (ucontrol->value.enumerated.item[0] > 2)
319 return -EINVAL;
320 spin_lock_irqsave(&sb->mixer_lock, flags);
321 oval = snd_sbmixer_read(sb, SB_ALS4000_MONO_IO_CTRL);
322
323 nval = (oval & ~(3 << 6))
324 | (ucontrol->value.enumerated.item[0] << 6);
325 change = nval != oval;
326 if (change)
327 snd_sbmixer_write(sb, SB_ALS4000_MONO_IO_CTRL, nval);
328 spin_unlock_irqrestore(&sb->mixer_lock, flags);
329 return change;
330}
331
332/*
272 * SBPRO input multiplexer 333 * SBPRO input multiplexer
273 */ 334 */
274 335
275static int snd_sb8mixer_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 336static int snd_sb8mixer_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
276{ 337{
277 static char *texts[3] = { 338 static const char *texts[3] = {
278 "Mic", "CD", "Line" 339 "Mic", "CD", "Line"
279 }; 340 };
280 341
@@ -442,6 +503,12 @@ int snd_sbmixer_add_ctl(struct snd_sb *chip, const char *name, int index, int ty
442 .get = snd_dt019x_input_sw_get, 503 .get = snd_dt019x_input_sw_get,
443 .put = snd_dt019x_input_sw_put, 504 .put = snd_dt019x_input_sw_put,
444 }, 505 },
506 [SB_MIX_MONO_CAPTURE_ALS4K] = {
507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
508 .info = snd_als4k_mono_capture_route_info,
509 .get = snd_als4k_mono_capture_route_get,
510 .put = snd_als4k_mono_capture_route_put,
511 },
445 }; 512 };
446 struct snd_kcontrol *ctl; 513 struct snd_kcontrol *ctl;
447 int err; 514 int err;
@@ -636,6 +703,8 @@ static struct sbmix_elem snd_dt019x_ctl_capture_source =
636 }; 703 };
637 704
638static struct sbmix_elem *snd_dt019x_controls[] = { 705static struct sbmix_elem *snd_dt019x_controls[] = {
706 /* ALS4000 below has some parts which we might be lacking,
707 * e.g. snd_als4000_ctl_mono_playback_switch - check it! */
639 &snd_dt019x_ctl_master_play_vol, 708 &snd_dt019x_ctl_master_play_vol,
640 &snd_dt019x_ctl_pcm_play_vol, 709 &snd_dt019x_ctl_pcm_play_vol,
641 &snd_dt019x_ctl_synth_play_vol, 710 &snd_dt019x_ctl_synth_play_vol,
@@ -666,18 +735,21 @@ static unsigned char snd_dt019x_init_values[][2] = {
666/* 735/*
667 * ALS4000 specific mixer elements 736 * ALS4000 specific mixer elements
668 */ 737 */
669/* FIXME: SB_ALS4000_MONO_IO_CTRL needs output select ctrl! */
670static struct sbmix_elem snd_als4000_ctl_master_mono_playback_switch = 738static struct sbmix_elem snd_als4000_ctl_master_mono_playback_switch =
671 SB_SINGLE("Master Mono Playback Switch", SB_ALS4000_MONO_IO_CTRL, 5, 1); 739 SB_SINGLE("Master Mono Playback Switch", SB_ALS4000_MONO_IO_CTRL, 5, 1);
672static struct sbmix_elem snd_als4000_ctl_master_mono_capture_route = 740static struct sbmix_elem snd_als4k_ctl_master_mono_capture_route = {
673 SB_SINGLE("Master Mono Capture Route", SB_ALS4000_MONO_IO_CTRL, 6, 0x03); 741 .name = "Master Mono Capture Route",
674/* FIXME: mono playback switch also available on DT019X? */ 742 .type = SB_MIX_MONO_CAPTURE_ALS4K
743 };
675static struct sbmix_elem snd_als4000_ctl_mono_playback_switch = 744static struct sbmix_elem snd_als4000_ctl_mono_playback_switch =
676 SB_SINGLE("Mono Playback Switch", SB_DT019X_OUTPUT_SW2, 0, 1); 745 SB_SINGLE("Mono Playback Switch", SB_DT019X_OUTPUT_SW2, 0, 1);
677static struct sbmix_elem snd_als4000_ctl_mic_20db_boost = 746static struct sbmix_elem snd_als4000_ctl_mic_20db_boost =
678 SB_SINGLE("Mic Boost (+20dB)", SB_ALS4000_MIC_IN_GAIN, 0, 0x03); 747 SB_SINGLE("Mic Boost (+20dB)", SB_ALS4000_MIC_IN_GAIN, 0, 0x03);
679static struct sbmix_elem snd_als4000_ctl_mixer_loopback = 748static struct sbmix_elem snd_als4000_ctl_mixer_analog_loopback =
680 SB_SINGLE("Analog Loopback", SB_ALS4000_MIC_IN_GAIN, 7, 0x01); 749 SB_SINGLE("Analog Loopback Switch", SB_ALS4000_MIC_IN_GAIN, 7, 0x01);
750static struct sbmix_elem snd_als4000_ctl_mixer_digital_loopback =
751 SB_SINGLE("Digital Loopback Switch",
752 SB_ALS4000_CR3_CONFIGURATION, 7, 0x01);
681/* FIXME: functionality of 3D controls might be swapped, I didn't find 753/* FIXME: functionality of 3D controls might be swapped, I didn't find
682 * a description of how to identify what is supposed to be what */ 754 * a description of how to identify what is supposed to be what */
683static struct sbmix_elem snd_als4000_3d_control_switch = 755static struct sbmix_elem snd_als4000_3d_control_switch =
@@ -694,6 +766,9 @@ static struct sbmix_elem snd_als4000_3d_control_delay =
694 SB_SINGLE("3D Control - Wide", SB_ALS4000_3D_TIME_DELAY, 0, 0x0f); 766 SB_SINGLE("3D Control - Wide", SB_ALS4000_3D_TIME_DELAY, 0, 0x0f);
695static struct sbmix_elem snd_als4000_3d_control_poweroff_switch = 767static struct sbmix_elem snd_als4000_3d_control_poweroff_switch =
696 SB_SINGLE("3D PowerOff Switch", SB_ALS4000_3D_TIME_DELAY, 4, 0x01); 768 SB_SINGLE("3D PowerOff Switch", SB_ALS4000_3D_TIME_DELAY, 4, 0x01);
769static struct sbmix_elem snd_als4000_ctl_3db_freq_control_switch =
770 SB_SINGLE("Master Playback 8kHz / 20kHz LPF Switch",
771 SB_ALS4000_FMDAC, 5, 0x01);
697#ifdef NOT_AVAILABLE 772#ifdef NOT_AVAILABLE
698static struct sbmix_elem snd_als4000_ctl_fmdac = 773static struct sbmix_elem snd_als4000_ctl_fmdac =
699 SB_SINGLE("FMDAC Switch (Option ?)", SB_ALS4000_FMDAC, 0, 0x01); 774 SB_SINGLE("FMDAC Switch (Option ?)", SB_ALS4000_FMDAC, 0, 0x01);
@@ -702,35 +777,37 @@ static struct sbmix_elem snd_als4000_ctl_qsound =
702#endif 777#endif
703 778
704static struct sbmix_elem *snd_als4000_controls[] = { 779static struct sbmix_elem *snd_als4000_controls[] = {
705 &snd_sb16_ctl_master_play_vol, 780 /* ALS4000a.PDF regs page */
706 &snd_dt019x_ctl_pcm_play_switch, 781 &snd_sb16_ctl_master_play_vol, /* MX30/31 12 */
707 &snd_sb16_ctl_pcm_play_vol, 782 &snd_dt019x_ctl_pcm_play_switch, /* MX4C 16 */
708 &snd_sb16_ctl_synth_capture_route, 783 &snd_sb16_ctl_pcm_play_vol, /* MX32/33 12 */
709 &snd_dt019x_ctl_synth_play_switch, 784 &snd_sb16_ctl_synth_capture_route, /* MX3D/3E 14 */
710 &snd_sb16_ctl_synth_play_vol, 785 &snd_dt019x_ctl_synth_play_switch, /* MX4C 16 */
711 &snd_sb16_ctl_cd_capture_route, 786 &snd_sb16_ctl_synth_play_vol, /* MX34/35 12/13 */
712 &snd_sb16_ctl_cd_play_switch, 787 &snd_sb16_ctl_cd_capture_route, /* MX3D/3E 14 */
713 &snd_sb16_ctl_cd_play_vol, 788 &snd_sb16_ctl_cd_play_switch, /* MX3C 14 */
714 &snd_sb16_ctl_line_capture_route, 789 &snd_sb16_ctl_cd_play_vol, /* MX36/37 13 */
715 &snd_sb16_ctl_line_play_switch, 790 &snd_sb16_ctl_line_capture_route, /* MX3D/3E 14 */
716 &snd_sb16_ctl_line_play_vol, 791 &snd_sb16_ctl_line_play_switch, /* MX3C 14 */
717 &snd_sb16_ctl_mic_capture_route, 792 &snd_sb16_ctl_line_play_vol, /* MX38/39 13 */
718 &snd_als4000_ctl_mic_20db_boost, 793 &snd_sb16_ctl_mic_capture_route, /* MX3D/3E 14 */
719 &snd_sb16_ctl_auto_mic_gain, 794 &snd_als4000_ctl_mic_20db_boost, /* MX4D 16 */
720 &snd_sb16_ctl_mic_play_switch, 795 &snd_sb16_ctl_mic_play_switch, /* MX3C 14 */
721 &snd_sb16_ctl_mic_play_vol, 796 &snd_sb16_ctl_mic_play_vol, /* MX3A 13 */
722 &snd_sb16_ctl_pc_speaker_vol, 797 &snd_sb16_ctl_pc_speaker_vol, /* MX3B 14 */
723 &snd_sb16_ctl_capture_vol, 798 &snd_sb16_ctl_capture_vol, /* MX3F/40 15 */
724 &snd_sb16_ctl_play_vol, 799 &snd_sb16_ctl_play_vol, /* MX41/42 15 */
725 &snd_als4000_ctl_master_mono_playback_switch, 800 &snd_als4000_ctl_master_mono_playback_switch, /* MX4C 16 */
726 &snd_als4000_ctl_master_mono_capture_route, 801 &snd_als4k_ctl_master_mono_capture_route, /* MX4B 16 */
727 &snd_als4000_ctl_mono_playback_switch, 802 &snd_als4000_ctl_mono_playback_switch, /* MX4C 16 */
728 &snd_als4000_ctl_mixer_loopback, 803 &snd_als4000_ctl_mixer_analog_loopback, /* MX4D 16 */
729 &snd_als4000_3d_control_switch, 804 &snd_als4000_ctl_mixer_digital_loopback, /* CR3 21 */
730 &snd_als4000_3d_control_ratio, 805 &snd_als4000_3d_control_switch, /* MX50 17 */
731 &snd_als4000_3d_control_freq, 806 &snd_als4000_3d_control_ratio, /* MX50 17 */
732 &snd_als4000_3d_control_delay, 807 &snd_als4000_3d_control_freq, /* MX50 17 */
733 &snd_als4000_3d_control_poweroff_switch, 808 &snd_als4000_3d_control_delay, /* MX51 18 */
809 &snd_als4000_3d_control_poweroff_switch, /* MX51 18 */
810 &snd_als4000_ctl_3db_freq_control_switch, /* MX4F 17 */
734#ifdef NOT_AVAILABLE 811#ifdef NOT_AVAILABLE
735 &snd_als4000_ctl_fmdac, 812 &snd_als4000_ctl_fmdac,
736 &snd_als4000_ctl_qsound, 813 &snd_als4000_ctl_qsound,
@@ -905,13 +982,14 @@ static unsigned char dt019x_saved_regs[] = {
905}; 982};
906 983
907static unsigned char als4000_saved_regs[] = { 984static unsigned char als4000_saved_regs[] = {
985 /* please verify in dsheet whether regs to be added
986 are actually real H/W or just dummy */
908 SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1, 987 SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1,
909 SB_DSP4_OUTPUT_SW, 988 SB_DSP4_OUTPUT_SW,
910 SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1, 989 SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1,
911 SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 990 SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT,
912 SB_DSP4_SYNTH_DEV, SB_DSP4_SYNTH_DEV + 1, 991 SB_DSP4_SYNTH_DEV, SB_DSP4_SYNTH_DEV + 1,
913 SB_DSP4_CD_DEV, SB_DSP4_CD_DEV + 1, 992 SB_DSP4_CD_DEV, SB_DSP4_CD_DEV + 1,
914 SB_DSP4_MIC_AGC,
915 SB_DSP4_MIC_DEV, 993 SB_DSP4_MIC_DEV,
916 SB_DSP4_SPEAKER_DEV, 994 SB_DSP4_SPEAKER_DEV,
917 SB_DSP4_IGAIN_DEV, SB_DSP4_IGAIN_DEV + 1, 995 SB_DSP4_IGAIN_DEV, SB_DSP4_IGAIN_DEV + 1,
@@ -919,8 +997,10 @@ static unsigned char als4000_saved_regs[] = {
919 SB_DT019X_OUTPUT_SW2, 997 SB_DT019X_OUTPUT_SW2,
920 SB_ALS4000_MONO_IO_CTRL, 998 SB_ALS4000_MONO_IO_CTRL,
921 SB_ALS4000_MIC_IN_GAIN, 999 SB_ALS4000_MIC_IN_GAIN,
1000 SB_ALS4000_FMDAC,
922 SB_ALS4000_3D_SND_FX, 1001 SB_ALS4000_3D_SND_FX,
923 SB_ALS4000_3D_TIME_DELAY, 1002 SB_ALS4000_3D_TIME_DELAY,
1003 SB_ALS4000_CR3_CONFIGURATION,
924}; 1004};
925 1005
926static void save_mixer(struct snd_sb *chip, unsigned char *regs, int num_regs) 1006static void save_mixer(struct snd_sb *chip, unsigned char *regs, int num_regs)
diff --git a/sound/isa/sc6000.c b/sound/isa/sc6000.c
index ca35924dc3b3..782010608ef4 100644
--- a/sound/isa/sc6000.c
+++ b/sound/isa/sc6000.c
@@ -489,9 +489,9 @@ static int __devinit snd_sc6000_probe(struct device *devptr, unsigned int dev)
489 char __iomem *vmss_port; 489 char __iomem *vmss_port;
490 490
491 491
492 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 492 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
493 if (!card) 493 if (err < 0)
494 return -ENOMEM; 494 return err;
495 495
496 if (xirq == SNDRV_AUTO_IRQ) { 496 if (xirq == SNDRV_AUTO_IRQ) {
497 xirq = snd_legacy_find_free_irq(possible_irqs); 497 xirq = snd_legacy_find_free_irq(possible_irqs);
@@ -576,10 +576,6 @@ static int __devinit snd_sc6000_probe(struct device *devptr, unsigned int dev)
576 snd_printk(KERN_ERR PFX "no OPL device at 0x%x-0x%x ?\n", 576 snd_printk(KERN_ERR PFX "no OPL device at 0x%x-0x%x ?\n",
577 0x388, 0x388 + 2); 577 0x388, 0x388 + 2);
578 } else { 578 } else {
579 err = snd_opl3_timer_new(opl3, 0, 1);
580 if (err < 0)
581 goto err_unmap2;
582
583 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL); 579 err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
584 if (err < 0) 580 if (err < 0)
585 goto err_unmap2; 581 goto err_unmap2;
diff --git a/sound/isa/sgalaxy.c b/sound/isa/sgalaxy.c
index 2c7503bf1271..6fe27b9d9440 100644
--- a/sound/isa/sgalaxy.c
+++ b/sound/isa/sgalaxy.c
@@ -243,9 +243,9 @@ static int __devinit snd_sgalaxy_probe(struct device *devptr, unsigned int dev)
243 struct snd_card *card; 243 struct snd_card *card;
244 struct snd_wss *chip; 244 struct snd_wss *chip;
245 245
246 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 246 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
247 if (card == NULL) 247 if (err < 0)
248 return -ENOMEM; 248 return err;
249 249
250 xirq = irq[dev]; 250 xirq = irq[dev];
251 if (xirq == SNDRV_AUTO_IRQ) { 251 if (xirq == SNDRV_AUTO_IRQ) {
diff --git a/sound/isa/sscape.c b/sound/isa/sscape.c
index 48a16d865834..66187122377c 100644
--- a/sound/isa/sscape.c
+++ b/sound/isa/sscape.c
@@ -89,9 +89,6 @@ MODULE_DEVICE_TABLE(pnp_card, sscape_pnpids);
89#endif 89#endif
90 90
91 91
92#define MPU401_IO(i) ((i) + 0)
93#define MIDI_DATA_IO(i) ((i) + 0)
94#define MIDI_CTRL_IO(i) ((i) + 1)
95#define HOST_CTRL_IO(i) ((i) + 2) 92#define HOST_CTRL_IO(i) ((i) + 2)
96#define HOST_DATA_IO(i) ((i) + 3) 93#define HOST_DATA_IO(i) ((i) + 3)
97#define ODIE_ADDR_IO(i) ((i) + 4) 94#define ODIE_ADDR_IO(i) ((i) + 4)
@@ -129,9 +126,6 @@ enum GA_REG {
129#define DMA_8BIT 0x80 126#define DMA_8BIT 0x80
130 127
131 128
132#define AD1845_FREQ_SEL_MSB 0x16
133#define AD1845_FREQ_SEL_LSB 0x17
134
135enum card_type { 129enum card_type {
136 SSCAPE, 130 SSCAPE,
137 SSCAPE_PNP, 131 SSCAPE_PNP,
@@ -141,8 +135,6 @@ enum card_type {
141struct soundscape { 135struct soundscape {
142 spinlock_t lock; 136 spinlock_t lock;
143 unsigned io_base; 137 unsigned io_base;
144 unsigned wss_base;
145 int codec_type;
146 int ic_type; 138 int ic_type;
147 enum card_type type; 139 enum card_type type;
148 struct resource *io_res; 140 struct resource *io_res;
@@ -330,7 +322,7 @@ static int host_write_ctrl_unsafe(unsigned io_base, unsigned char data,
330 */ 322 */
331static inline int verify_mpu401(const struct snd_mpu401 * mpu) 323static inline int verify_mpu401(const struct snd_mpu401 * mpu)
332{ 324{
333 return ((inb(MIDI_CTRL_IO(mpu->port)) & 0xc0) == 0x80); 325 return ((inb(MPU401C(mpu)) & 0xc0) == 0x80);
334} 326}
335 327
336/* 328/*
@@ -338,7 +330,7 @@ static inline int verify_mpu401(const struct snd_mpu401 * mpu)
338 */ 330 */
339static inline void initialise_mpu401(const struct snd_mpu401 * mpu) 331static inline void initialise_mpu401(const struct snd_mpu401 * mpu)
340{ 332{
341 outb(0, MIDI_DATA_IO(mpu->port)); 333 outb(0, MPU401D(mpu));
342} 334}
343 335
344/* 336/*
@@ -396,20 +388,20 @@ static int sscape_wait_dma_unsafe(unsigned io_base, enum GA_REG reg, unsigned ti
396 */ 388 */
397static int obp_startup_ack(struct soundscape *s, unsigned timeout) 389static int obp_startup_ack(struct soundscape *s, unsigned timeout)
398{ 390{
399 while (timeout != 0) { 391 unsigned long end_time = jiffies + msecs_to_jiffies(timeout);
392
393 do {
400 unsigned long flags; 394 unsigned long flags;
401 unsigned char x; 395 unsigned char x;
402 396
403 schedule_timeout_uninterruptible(1);
404
405 spin_lock_irqsave(&s->lock, flags); 397 spin_lock_irqsave(&s->lock, flags);
406 x = inb(HOST_DATA_IO(s->io_base)); 398 x = inb(HOST_DATA_IO(s->io_base));
407 spin_unlock_irqrestore(&s->lock, flags); 399 spin_unlock_irqrestore(&s->lock, flags);
408 if ((x & 0xfe) == 0xfe) 400 if ((x & 0xfe) == 0xfe)
409 return 1; 401 return 1;
410 402
411 --timeout; 403 msleep(10);
412 } /* while */ 404 } while (time_before(jiffies, end_time));
413 405
414 return 0; 406 return 0;
415} 407}
@@ -423,20 +415,20 @@ static int obp_startup_ack(struct soundscape *s, unsigned timeout)
423 */ 415 */
424static int host_startup_ack(struct soundscape *s, unsigned timeout) 416static int host_startup_ack(struct soundscape *s, unsigned timeout)
425{ 417{
426 while (timeout != 0) { 418 unsigned long end_time = jiffies + msecs_to_jiffies(timeout);
419
420 do {
427 unsigned long flags; 421 unsigned long flags;
428 unsigned char x; 422 unsigned char x;
429 423
430 schedule_timeout_uninterruptible(1);
431
432 spin_lock_irqsave(&s->lock, flags); 424 spin_lock_irqsave(&s->lock, flags);
433 x = inb(HOST_DATA_IO(s->io_base)); 425 x = inb(HOST_DATA_IO(s->io_base));
434 spin_unlock_irqrestore(&s->lock, flags); 426 spin_unlock_irqrestore(&s->lock, flags);
435 if (x == 0xfe) 427 if (x == 0xfe)
436 return 1; 428 return 1;
437 429
438 --timeout; 430 msleep(10);
439 } /* while */ 431 } while (time_before(jiffies, end_time));
440 432
441 return 0; 433 return 0;
442} 434}
@@ -532,10 +524,10 @@ static int upload_dma_data(struct soundscape *s,
532 * give it 5 seconds (max) ... 524 * give it 5 seconds (max) ...
533 */ 525 */
534 ret = 0; 526 ret = 0;
535 if (!obp_startup_ack(s, 5)) { 527 if (!obp_startup_ack(s, 5000)) {
536 snd_printk(KERN_ERR "sscape: No response from on-board processor after upload\n"); 528 snd_printk(KERN_ERR "sscape: No response from on-board processor after upload\n");
537 ret = -EAGAIN; 529 ret = -EAGAIN;
538 } else if (!host_startup_ack(s, 5)) { 530 } else if (!host_startup_ack(s, 5000)) {
539 snd_printk(KERN_ERR "sscape: SoundScape failed to initialise\n"); 531 snd_printk(KERN_ERR "sscape: SoundScape failed to initialise\n");
540 ret = -EAGAIN; 532 ret = -EAGAIN;
541 } 533 }
@@ -732,13 +724,7 @@ static int sscape_midi_get(struct snd_kcontrol *kctl,
732 unsigned long flags; 724 unsigned long flags;
733 725
734 spin_lock_irqsave(&s->lock, flags); 726 spin_lock_irqsave(&s->lock, flags);
735 set_host_mode_unsafe(s->io_base); 727 uctl->value.integer.value[0] = s->midi_vol;
736
737 if (host_write_ctrl_unsafe(s->io_base, CMD_GET_MIDI_VOL, 100)) {
738 uctl->value.integer.value[0] = host_read_ctrl_unsafe(s->io_base, 100);
739 }
740
741 set_midi_mode_unsafe(s->io_base);
742 spin_unlock_irqrestore(&s->lock, flags); 728 spin_unlock_irqrestore(&s->lock, flags);
743 return 0; 729 return 0;
744} 730}
@@ -773,6 +759,7 @@ static int sscape_midi_put(struct snd_kcontrol *kctl,
773 change = (host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100) 759 change = (host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100)
774 && host_write_ctrl_unsafe(s->io_base, ((unsigned char) uctl->value.integer. value[0]) & 127, 100) 760 && host_write_ctrl_unsafe(s->io_base, ((unsigned char) uctl->value.integer. value[0]) & 127, 100)
775 && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100)); 761 && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100));
762 s->midi_vol = (unsigned char) uctl->value.integer.value[0] & 127;
776 __skip_change: 763 __skip_change:
777 764
778 /* 765 /*
@@ -815,12 +802,11 @@ static unsigned __devinit get_irq_config(int irq)
815 * Perform certain arcane port-checks to see whether there 802 * Perform certain arcane port-checks to see whether there
816 * is a SoundScape board lurking behind the given ports. 803 * is a SoundScape board lurking behind the given ports.
817 */ 804 */
818static int __devinit detect_sscape(struct soundscape *s) 805static int __devinit detect_sscape(struct soundscape *s, long wss_io)
819{ 806{
820 unsigned long flags; 807 unsigned long flags;
821 unsigned d; 808 unsigned d;
822 int retval = 0; 809 int retval = 0;
823 int codec = s->wss_base;
824 810
825 spin_lock_irqsave(&s->lock, flags); 811 spin_lock_irqsave(&s->lock, flags);
826 812
@@ -836,13 +822,11 @@ static int __devinit detect_sscape(struct soundscape *s)
836 if ((d & 0x80) != 0) 822 if ((d & 0x80) != 0)
837 goto _done; 823 goto _done;
838 824
839 if (d == 0) { 825 if (d == 0)
840 s->codec_type = 1;
841 s->ic_type = IC_ODIE; 826 s->ic_type = IC_ODIE;
842 } else if ((d & 0x60) != 0) { 827 else if ((d & 0x60) != 0)
843 s->codec_type = 2;
844 s->ic_type = IC_OPUS; 828 s->ic_type = IC_OPUS;
845 } else 829 else
846 goto _done; 830 goto _done;
847 831
848 outb(0xfa, ODIE_ADDR_IO(s->io_base)); 832 outb(0xfa, ODIE_ADDR_IO(s->io_base));
@@ -862,10 +846,10 @@ static int __devinit detect_sscape(struct soundscape *s)
862 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0); 846 sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0);
863 847
864 if (s->type == SSCAPE_VIVO) 848 if (s->type == SSCAPE_VIVO)
865 codec += 4; 849 wss_io += 4;
866 /* wait for WSS codec */ 850 /* wait for WSS codec */
867 for (d = 0; d < 500; d++) { 851 for (d = 0; d < 500; d++) {
868 if ((inb(codec) & 0x80) == 0) 852 if ((inb(wss_io) & 0x80) == 0)
869 break; 853 break;
870 spin_unlock_irqrestore(&s->lock, flags); 854 spin_unlock_irqrestore(&s->lock, flags);
871 msleep(1); 855 msleep(1);
@@ -955,82 +939,6 @@ static int __devinit create_mpu401(struct snd_card *card, int devnum, unsigned l
955 939
956 940
957/* 941/*
958 * Override for the CS4231 playback format function.
959 * The AD1845 has much simpler format and rate selection.
960 */
961static void ad1845_playback_format(struct snd_wss *chip,
962 struct snd_pcm_hw_params *params,
963 unsigned char format)
964{
965 unsigned long flags;
966 unsigned rate = params_rate(params);
967
968 /*
969 * The AD1845 can't handle sample frequencies
970 * outside of 4 kHZ to 50 kHZ
971 */
972 if (rate > 50000)
973 rate = 50000;
974 else if (rate < 4000)
975 rate = 4000;
976
977 spin_lock_irqsave(&chip->reg_lock, flags);
978
979 /*
980 * Program the AD1845 correctly for the playback stream.
981 * Note that we do NOT need to toggle the MCE bit because
982 * the PLAYBACK_ENABLE bit of the Interface Configuration
983 * register is set.
984 *
985 * NOTE: We seem to need to write to the MSB before the LSB
986 * to get the correct sample frequency.
987 */
988 snd_wss_out(chip, CS4231_PLAYBK_FORMAT, (format & 0xf0));
989 snd_wss_out(chip, AD1845_FREQ_SEL_MSB, (unsigned char) (rate >> 8));
990 snd_wss_out(chip, AD1845_FREQ_SEL_LSB, (unsigned char) rate);
991
992 spin_unlock_irqrestore(&chip->reg_lock, flags);
993}
994
995/*
996 * Override for the CS4231 capture format function.
997 * The AD1845 has much simpler format and rate selection.
998 */
999static void ad1845_capture_format(struct snd_wss *chip,
1000 struct snd_pcm_hw_params *params,
1001 unsigned char format)
1002{
1003 unsigned long flags;
1004 unsigned rate = params_rate(params);
1005
1006 /*
1007 * The AD1845 can't handle sample frequencies
1008 * outside of 4 kHZ to 50 kHZ
1009 */
1010 if (rate > 50000)
1011 rate = 50000;
1012 else if (rate < 4000)
1013 rate = 4000;
1014
1015 spin_lock_irqsave(&chip->reg_lock, flags);
1016
1017 /*
1018 * Program the AD1845 correctly for the playback stream.
1019 * Note that we do NOT need to toggle the MCE bit because
1020 * the CAPTURE_ENABLE bit of the Interface Configuration
1021 * register is set.
1022 *
1023 * NOTE: We seem to need to write to the MSB before the LSB
1024 * to get the correct sample frequency.
1025 */
1026 snd_wss_out(chip, CS4231_REC_FORMAT, (format & 0xf0));
1027 snd_wss_out(chip, AD1845_FREQ_SEL_MSB, (unsigned char) (rate >> 8));
1028 snd_wss_out(chip, AD1845_FREQ_SEL_LSB, (unsigned char) rate);
1029
1030 spin_unlock_irqrestore(&chip->reg_lock, flags);
1031}
1032
1033/*
1034 * Create an AD1845 PCM subdevice on the SoundScape. The AD1845 942 * Create an AD1845 PCM subdevice on the SoundScape. The AD1845
1035 * is very much like a CS4231, with a few extra bits. We will 943 * is very much like a CS4231, with a few extra bits. We will
1036 * try to support at least some of the extra bits by overriding 944 * try to support at least some of the extra bits by overriding
@@ -1055,11 +963,6 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
1055 unsigned long flags; 963 unsigned long flags;
1056 struct snd_pcm *pcm; 964 struct snd_pcm *pcm;
1057 965
1058#define AD1845_FREQ_SEL_ENABLE 0x08
1059
1060#define AD1845_PWR_DOWN_CTRL 0x1b
1061#define AD1845_CRYS_CLOCK_SEL 0x1d
1062
1063/* 966/*
1064 * It turns out that the PLAYBACK_ENABLE bit is set 967 * It turns out that the PLAYBACK_ENABLE bit is set
1065 * by the lowlevel driver ... 968 * by the lowlevel driver ...
@@ -1074,7 +977,6 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
1074 */ 977 */
1075 978
1076 if (sscape->type != SSCAPE_VIVO) { 979 if (sscape->type != SSCAPE_VIVO) {
1077 int val;
1078 /* 980 /*
1079 * The input clock frequency on the SoundScape must 981 * The input clock frequency on the SoundScape must
1080 * be 14.31818 MHz, because we must set this register 982 * be 14.31818 MHz, because we must set this register
@@ -1082,22 +984,10 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
1082 */ 984 */
1083 snd_wss_mce_up(chip); 985 snd_wss_mce_up(chip);
1084 spin_lock_irqsave(&chip->reg_lock, flags); 986 spin_lock_irqsave(&chip->reg_lock, flags);
1085 snd_wss_out(chip, AD1845_CRYS_CLOCK_SEL, 0x20); 987 snd_wss_out(chip, AD1845_CLOCK, 0x20);
1086 spin_unlock_irqrestore(&chip->reg_lock, flags); 988 spin_unlock_irqrestore(&chip->reg_lock, flags);
1087 snd_wss_mce_down(chip); 989 snd_wss_mce_down(chip);
1088 990
1089 /*
1090 * More custom configuration:
1091 * a) select "mode 2" and provide a current drive of 8mA
1092 * b) enable frequency selection (for capture/playback)
1093 */
1094 spin_lock_irqsave(&chip->reg_lock, flags);
1095 snd_wss_out(chip, CS4231_MISC_INFO,
1096 CS4231_MODE2 | 0x10);
1097 val = snd_wss_in(chip, AD1845_PWR_DOWN_CTRL);
1098 snd_wss_out(chip, AD1845_PWR_DOWN_CTRL,
1099 val | AD1845_FREQ_SEL_ENABLE);
1100 spin_unlock_irqrestore(&chip->reg_lock, flags);
1101 } 991 }
1102 992
1103 err = snd_wss_pcm(chip, 0, &pcm); 993 err = snd_wss_pcm(chip, 0, &pcm);
@@ -1113,11 +1003,13 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
1113 "for AD1845 chip\n"); 1003 "for AD1845 chip\n");
1114 goto _error; 1004 goto _error;
1115 } 1005 }
1116 err = snd_wss_timer(chip, 0, NULL); 1006 if (chip->hardware != WSS_HW_AD1848) {
1117 if (err < 0) { 1007 err = snd_wss_timer(chip, 0, NULL);
1118 snd_printk(KERN_ERR "sscape: No timer device " 1008 if (err < 0) {
1119 "for AD1845 chip\n"); 1009 snd_printk(KERN_ERR "sscape: No timer device "
1120 goto _error; 1010 "for AD1845 chip\n");
1011 goto _error;
1012 }
1121 } 1013 }
1122 1014
1123 if (sscape->type != SSCAPE_VIVO) { 1015 if (sscape->type != SSCAPE_VIVO) {
@@ -1128,8 +1020,6 @@ static int __devinit create_ad1845(struct snd_card *card, unsigned port,
1128 "MIDI mixer control\n"); 1020 "MIDI mixer control\n");
1129 goto _error; 1021 goto _error;
1130 } 1022 }
1131 chip->set_playback_format = ad1845_playback_format;
1132 chip->set_capture_format = ad1845_capture_format;
1133 } 1023 }
1134 1024
1135 strcpy(card->driver, "SoundScape"); 1025 strcpy(card->driver, "SoundScape");
@@ -1157,7 +1047,6 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1157 unsigned dma_cfg; 1047 unsigned dma_cfg;
1158 unsigned irq_cfg; 1048 unsigned irq_cfg;
1159 unsigned mpu_irq_cfg; 1049 unsigned mpu_irq_cfg;
1160 unsigned xport;
1161 struct resource *io_res; 1050 struct resource *io_res;
1162 struct resource *wss_res; 1051 struct resource *wss_res;
1163 unsigned long flags; 1052 unsigned long flags;
@@ -1177,15 +1066,15 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1177 printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]); 1066 printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]);
1178 return -ENXIO; 1067 return -ENXIO;
1179 } 1068 }
1180 xport = port[dev];
1181 1069
1182 /* 1070 /*
1183 * Grab IO ports that we will need to probe so that we 1071 * Grab IO ports that we will need to probe so that we
1184 * can detect and control this hardware ... 1072 * can detect and control this hardware ...
1185 */ 1073 */
1186 io_res = request_region(xport, 8, "SoundScape"); 1074 io_res = request_region(port[dev], 8, "SoundScape");
1187 if (!io_res) { 1075 if (!io_res) {
1188 snd_printk(KERN_ERR "sscape: can't grab port 0x%x\n", xport); 1076 snd_printk(KERN_ERR
1077 "sscape: can't grab port 0x%lx\n", port[dev]);
1189 return -EBUSY; 1078 return -EBUSY;
1190 } 1079 }
1191 wss_res = NULL; 1080 wss_res = NULL;
@@ -1212,10 +1101,9 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1212 spin_lock_init(&sscape->fwlock); 1101 spin_lock_init(&sscape->fwlock);
1213 sscape->io_res = io_res; 1102 sscape->io_res = io_res;
1214 sscape->wss_res = wss_res; 1103 sscape->wss_res = wss_res;
1215 sscape->io_base = xport; 1104 sscape->io_base = port[dev];
1216 sscape->wss_base = wss_port[dev];
1217 1105
1218 if (!detect_sscape(sscape)) { 1106 if (!detect_sscape(sscape, wss_port[dev])) {
1219 printk(KERN_ERR "sscape: hardware not detected at 0x%x\n", sscape->io_base); 1107 printk(KERN_ERR "sscape: hardware not detected at 0x%x\n", sscape->io_base);
1220 err = -ENODEV; 1108 err = -ENODEV;
1221 goto _release_dma; 1109 goto _release_dma;
@@ -1288,12 +1176,11 @@ static int __devinit create_sscape(int dev, struct snd_card *card)
1288 } 1176 }
1289#define MIDI_DEVNUM 0 1177#define MIDI_DEVNUM 0
1290 if (sscape->type != SSCAPE_VIVO) { 1178 if (sscape->type != SSCAPE_VIVO) {
1291 err = create_mpu401(card, MIDI_DEVNUM, 1179 err = create_mpu401(card, MIDI_DEVNUM, port[dev], mpu_irq[dev]);
1292 MPU401_IO(xport), mpu_irq[dev]);
1293 if (err < 0) { 1180 if (err < 0) {
1294 printk(KERN_ERR "sscape: Failed to create " 1181 printk(KERN_ERR "sscape: Failed to create "
1295 "MPU-401 device at 0x%x\n", 1182 "MPU-401 device at 0x%lx\n",
1296 MPU401_IO(xport)); 1183 port[dev]);
1297 goto _release_dma; 1184 goto _release_dma;
1298 } 1185 }
1299 1186
@@ -1357,10 +1244,10 @@ static int __devinit snd_sscape_probe(struct device *pdev, unsigned int dev)
1357 struct soundscape *sscape; 1244 struct soundscape *sscape;
1358 int ret; 1245 int ret;
1359 1246
1360 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 1247 ret = snd_card_create(index[dev], id[dev], THIS_MODULE,
1361 sizeof(struct soundscape)); 1248 sizeof(struct soundscape), &card);
1362 if (!card) 1249 if (ret < 0)
1363 return -ENOMEM; 1250 return ret;
1364 1251
1365 sscape = get_card_soundscape(card); 1252 sscape = get_card_soundscape(card);
1366 sscape->type = SSCAPE; 1253 sscape->type = SSCAPE;
@@ -1462,10 +1349,10 @@ static int __devinit sscape_pnp_detect(struct pnp_card_link *pcard,
1462 * Create a new ALSA sound card entry, in anticipation 1349 * Create a new ALSA sound card entry, in anticipation
1463 * of detecting our hardware ... 1350 * of detecting our hardware ...
1464 */ 1351 */
1465 card = snd_card_new(index[idx], id[idx], THIS_MODULE, 1352 ret = snd_card_create(index[idx], id[idx], THIS_MODULE,
1466 sizeof(struct soundscape)); 1353 sizeof(struct soundscape), &card);
1467 if (!card) 1354 if (ret < 0)
1468 return -ENOMEM; 1355 return ret;
1469 1356
1470 sscape = get_card_soundscape(card); 1357 sscape = get_card_soundscape(card);
1471 1358
diff --git a/sound/isa/wavefront/wavefront.c b/sound/isa/wavefront/wavefront.c
index 4c095bc7c729..a34ae7b1f7d0 100644
--- a/sound/isa/wavefront/wavefront.c
+++ b/sound/isa/wavefront/wavefront.c
@@ -338,15 +338,16 @@ snd_wavefront_free(struct snd_card *card)
338 } 338 }
339} 339}
340 340
341static struct snd_card *snd_wavefront_card_new(int dev) 341static int snd_wavefront_card_new(int dev, struct snd_card **cardp)
342{ 342{
343 struct snd_card *card; 343 struct snd_card *card;
344 snd_wavefront_card_t *acard; 344 snd_wavefront_card_t *acard;
345 int err;
345 346
346 card = snd_card_new (index[dev], id[dev], THIS_MODULE, 347 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
347 sizeof(snd_wavefront_card_t)); 348 sizeof(snd_wavefront_card_t), &card);
348 if (card == NULL) 349 if (err < 0)
349 return NULL; 350 return err;
350 351
351 acard = card->private_data; 352 acard = card->private_data;
352 acard->wavefront.irq = -1; 353 acard->wavefront.irq = -1;
@@ -357,7 +358,8 @@ static struct snd_card *snd_wavefront_card_new(int dev)
357 acard->wavefront.card = card; 358 acard->wavefront.card = card;
358 card->private_free = snd_wavefront_free; 359 card->private_free = snd_wavefront_free;
359 360
360 return card; 361 *cardp = card;
362 return 0;
361} 363}
362 364
363static int __devinit 365static int __devinit
@@ -551,11 +553,11 @@ static int __devinit snd_wavefront_isa_match(struct device *pdev,
551 return 0; 553 return 0;
552#endif 554#endif
553 if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) { 555 if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) {
554 snd_printk("specify CS4232 port\n"); 556 snd_printk(KERN_ERR "specify CS4232 port\n");
555 return 0; 557 return 0;
556 } 558 }
557 if (ics2115_port[dev] == SNDRV_AUTO_PORT) { 559 if (ics2115_port[dev] == SNDRV_AUTO_PORT) {
558 snd_printk("specify ICS2115 port\n"); 560 snd_printk(KERN_ERR "specify ICS2115 port\n");
559 return 0; 561 return 0;
560 } 562 }
561 return 1; 563 return 1;
@@ -567,9 +569,9 @@ static int __devinit snd_wavefront_isa_probe(struct device *pdev,
567 struct snd_card *card; 569 struct snd_card *card;
568 int err; 570 int err;
569 571
570 card = snd_wavefront_card_new(dev); 572 err = snd_wavefront_card_new(dev, &card);
571 if (! card) 573 if (err < 0)
572 return -ENOMEM; 574 return err;
573 snd_card_set_dev(card, pdev); 575 snd_card_set_dev(card, pdev);
574 if ((err = snd_wavefront_probe(card, dev)) < 0) { 576 if ((err = snd_wavefront_probe(card, dev)) < 0) {
575 snd_card_free(card); 577 snd_card_free(card);
@@ -616,9 +618,9 @@ static int __devinit snd_wavefront_pnp_detect(struct pnp_card_link *pcard,
616 if (dev >= SNDRV_CARDS) 618 if (dev >= SNDRV_CARDS)
617 return -ENODEV; 619 return -ENODEV;
618 620
619 card = snd_wavefront_card_new(dev); 621 res = snd_wavefront_card_new(dev, &card);
620 if (! card) 622 if (res < 0)
621 return -ENOMEM; 623 return res;
622 624
623 if (snd_wavefront_pnp (dev, card->private_data, pcard, pid) < 0) { 625 if (snd_wavefront_pnp (dev, card->private_data, pcard, pid) < 0) {
624 if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) { 626 if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) {
diff --git a/sound/isa/wavefront/wavefront_synth.c b/sound/isa/wavefront/wavefront_synth.c
index 4c410820a994..beb312cca75b 100644
--- a/sound/isa/wavefront/wavefront_synth.c
+++ b/sound/isa/wavefront/wavefront_synth.c
@@ -633,7 +633,7 @@ wavefront_get_sample_status (snd_wavefront_t *dev, int assume_rom)
633 wbuf[1] = i >> 7; 633 wbuf[1] = i >> 7;
634 634
635 if (snd_wavefront_cmd (dev, WFC_IDENTIFY_SAMPLE_TYPE, rbuf, wbuf)) { 635 if (snd_wavefront_cmd (dev, WFC_IDENTIFY_SAMPLE_TYPE, rbuf, wbuf)) {
636 snd_printk("cannot identify sample " 636 snd_printk(KERN_WARNING "cannot identify sample "
637 "type of slot %d\n", i); 637 "type of slot %d\n", i);
638 dev->sample_status[i] = WF_ST_EMPTY; 638 dev->sample_status[i] = WF_ST_EMPTY;
639 continue; 639 continue;
diff --git a/sound/isa/wss/wss_lib.c b/sound/isa/wss/wss_lib.c
index 3d6c5f2838af..5d2ba1b749ab 100644
--- a/sound/isa/wss/wss_lib.c
+++ b/sound/isa/wss/wss_lib.c
@@ -181,25 +181,6 @@ static void snd_wss_wait(struct snd_wss *chip)
181 udelay(100); 181 udelay(100);
182} 182}
183 183
184static void snd_wss_outm(struct snd_wss *chip, unsigned char reg,
185 unsigned char mask, unsigned char value)
186{
187 unsigned char tmp = (chip->image[reg] & mask) | value;
188
189 snd_wss_wait(chip);
190#ifdef CONFIG_SND_DEBUG
191 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
192 snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
193#endif
194 chip->image[reg] = tmp;
195 if (!chip->calibrate_mute) {
196 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
197 wmb();
198 wss_outb(chip, CS4231P(REG), tmp);
199 mb();
200 }
201}
202
203static void snd_wss_dout(struct snd_wss *chip, unsigned char reg, 184static void snd_wss_dout(struct snd_wss *chip, unsigned char reg,
204 unsigned char value) 185 unsigned char value)
205{ 186{
@@ -219,7 +200,8 @@ void snd_wss_out(struct snd_wss *chip, unsigned char reg, unsigned char value)
219 snd_wss_wait(chip); 200 snd_wss_wait(chip);
220#ifdef CONFIG_SND_DEBUG 201#ifdef CONFIG_SND_DEBUG
221 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) 202 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
222 snd_printk("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value); 203 snd_printk(KERN_DEBUG "out: auto calibration time out "
204 "- reg = 0x%x, value = 0x%x\n", reg, value);
223#endif 205#endif
224 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg); 206 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
225 wss_outb(chip, CS4231P(REG), value); 207 wss_outb(chip, CS4231P(REG), value);
@@ -235,7 +217,8 @@ unsigned char snd_wss_in(struct snd_wss *chip, unsigned char reg)
235 snd_wss_wait(chip); 217 snd_wss_wait(chip);
236#ifdef CONFIG_SND_DEBUG 218#ifdef CONFIG_SND_DEBUG
237 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) 219 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
238 snd_printk("in: auto calibration time out - reg = 0x%x\n", reg); 220 snd_printk(KERN_DEBUG "in: auto calibration time out "
221 "- reg = 0x%x\n", reg);
239#endif 222#endif
240 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg); 223 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
241 mb(); 224 mb();
@@ -252,7 +235,7 @@ void snd_cs4236_ext_out(struct snd_wss *chip, unsigned char reg,
252 wss_outb(chip, CS4231P(REG), val); 235 wss_outb(chip, CS4231P(REG), val);
253 chip->eimage[CS4236_REG(reg)] = val; 236 chip->eimage[CS4236_REG(reg)] = val;
254#if 0 237#if 0
255 printk("ext out : reg = 0x%x, val = 0x%x\n", reg, val); 238 printk(KERN_DEBUG "ext out : reg = 0x%x, val = 0x%x\n", reg, val);
256#endif 239#endif
257} 240}
258EXPORT_SYMBOL(snd_cs4236_ext_out); 241EXPORT_SYMBOL(snd_cs4236_ext_out);
@@ -268,7 +251,8 @@ unsigned char snd_cs4236_ext_in(struct snd_wss *chip, unsigned char reg)
268 { 251 {
269 unsigned char res; 252 unsigned char res;
270 res = wss_inb(chip, CS4231P(REG)); 253 res = wss_inb(chip, CS4231P(REG));
271 printk("ext in : reg = 0x%x, val = 0x%x\n", reg, res); 254 printk(KERN_DEBUG "ext in : reg = 0x%x, val = 0x%x\n",
255 reg, res);
272 return res; 256 return res;
273 } 257 }
274#endif 258#endif
@@ -394,13 +378,16 @@ void snd_wss_mce_up(struct snd_wss *chip)
394 snd_wss_wait(chip); 378 snd_wss_wait(chip);
395#ifdef CONFIG_SND_DEBUG 379#ifdef CONFIG_SND_DEBUG
396 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) 380 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
397 snd_printk("mce_up - auto calibration time out (0)\n"); 381 snd_printk(KERN_DEBUG
382 "mce_up - auto calibration time out (0)\n");
398#endif 383#endif
399 spin_lock_irqsave(&chip->reg_lock, flags); 384 spin_lock_irqsave(&chip->reg_lock, flags);
400 chip->mce_bit |= CS4231_MCE; 385 chip->mce_bit |= CS4231_MCE;
401 timeout = wss_inb(chip, CS4231P(REGSEL)); 386 timeout = wss_inb(chip, CS4231P(REGSEL));
402 if (timeout == 0x80) 387 if (timeout == 0x80)
403 snd_printk("mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port); 388 snd_printk(KERN_DEBUG "mce_up [0x%lx]: "
389 "serious init problem - codec still busy\n",
390 chip->port);
404 if (!(timeout & CS4231_MCE)) 391 if (!(timeout & CS4231_MCE))
405 wss_outb(chip, CS4231P(REGSEL), 392 wss_outb(chip, CS4231P(REGSEL),
406 chip->mce_bit | (timeout & 0x1f)); 393 chip->mce_bit | (timeout & 0x1f));
@@ -419,7 +406,9 @@ void snd_wss_mce_down(struct snd_wss *chip)
419 406
420#ifdef CONFIG_SND_DEBUG 407#ifdef CONFIG_SND_DEBUG
421 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) 408 if (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
422 snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", (long)CS4231P(REGSEL)); 409 snd_printk(KERN_DEBUG "mce_down [0x%lx] - "
410 "auto calibration time out (0)\n",
411 (long)CS4231P(REGSEL));
423#endif 412#endif
424 spin_lock_irqsave(&chip->reg_lock, flags); 413 spin_lock_irqsave(&chip->reg_lock, flags);
425 chip->mce_bit &= ~CS4231_MCE; 414 chip->mce_bit &= ~CS4231_MCE;
@@ -427,7 +416,9 @@ void snd_wss_mce_down(struct snd_wss *chip)
427 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f)); 416 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
428 spin_unlock_irqrestore(&chip->reg_lock, flags); 417 spin_unlock_irqrestore(&chip->reg_lock, flags);
429 if (timeout == 0x80) 418 if (timeout == 0x80)
430 snd_printk("mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port); 419 snd_printk(KERN_DEBUG "mce_down [0x%lx]: "
420 "serious init problem - codec still busy\n",
421 chip->port);
431 if ((timeout & CS4231_MCE) == 0 || !(chip->hardware & hw_mask)) 422 if ((timeout & CS4231_MCE) == 0 || !(chip->hardware & hw_mask))
432 return; 423 return;
433 424
@@ -565,7 +556,7 @@ static unsigned char snd_wss_get_format(struct snd_wss *chip,
565 if (channels > 1) 556 if (channels > 1)
566 rformat |= CS4231_STEREO; 557 rformat |= CS4231_STEREO;
567#if 0 558#if 0
568 snd_printk("get_format: 0x%x (mode=0x%x)\n", format, mode); 559 snd_printk(KERN_DEBUG "get_format: 0x%x (mode=0x%x)\n", format, mode);
569#endif 560#endif
570 return rformat; 561 return rformat;
571} 562}
@@ -587,7 +578,15 @@ static void snd_wss_calibrate_mute(struct snd_wss *chip, int mute)
587 chip->image[CS4231_RIGHT_INPUT]); 578 chip->image[CS4231_RIGHT_INPUT]);
588 snd_wss_dout(chip, CS4231_LOOPBACK, 579 snd_wss_dout(chip, CS4231_LOOPBACK,
589 chip->image[CS4231_LOOPBACK]); 580 chip->image[CS4231_LOOPBACK]);
581 } else {
582 snd_wss_dout(chip, CS4231_LEFT_INPUT,
583 0);
584 snd_wss_dout(chip, CS4231_RIGHT_INPUT,
585 0);
586 snd_wss_dout(chip, CS4231_LOOPBACK,
587 0xfd);
590 } 588 }
589
591 snd_wss_dout(chip, CS4231_AUX1_LEFT_INPUT, 590 snd_wss_dout(chip, CS4231_AUX1_LEFT_INPUT,
592 mute | chip->image[CS4231_AUX1_LEFT_INPUT]); 591 mute | chip->image[CS4231_AUX1_LEFT_INPUT]);
593 snd_wss_dout(chip, CS4231_AUX1_RIGHT_INPUT, 592 snd_wss_dout(chip, CS4231_AUX1_RIGHT_INPUT,
@@ -630,7 +629,6 @@ static void snd_wss_playback_format(struct snd_wss *chip,
630 int full_calib = 1; 629 int full_calib = 1;
631 630
632 mutex_lock(&chip->mce_mutex); 631 mutex_lock(&chip->mce_mutex);
633 snd_wss_calibrate_mute(chip, 1);
634 if (chip->hardware == WSS_HW_CS4231A || 632 if (chip->hardware == WSS_HW_CS4231A ||
635 (chip->hardware & WSS_HW_CS4232_MASK)) { 633 (chip->hardware & WSS_HW_CS4232_MASK)) {
636 spin_lock_irqsave(&chip->reg_lock, flags); 634 spin_lock_irqsave(&chip->reg_lock, flags);
@@ -646,6 +644,24 @@ static void snd_wss_playback_format(struct snd_wss *chip,
646 full_calib = 0; 644 full_calib = 0;
647 } 645 }
648 spin_unlock_irqrestore(&chip->reg_lock, flags); 646 spin_unlock_irqrestore(&chip->reg_lock, flags);
647 } else if (chip->hardware == WSS_HW_AD1845) {
648 unsigned rate = params_rate(params);
649
650 /*
651 * Program the AD1845 correctly for the playback stream.
652 * Note that we do NOT need to toggle the MCE bit because
653 * the PLAYBACK_ENABLE bit of the Interface Configuration
654 * register is set.
655 *
656 * NOTE: We seem to need to write to the MSB before the LSB
657 * to get the correct sample frequency.
658 */
659 spin_lock_irqsave(&chip->reg_lock, flags);
660 snd_wss_out(chip, CS4231_PLAYBK_FORMAT, (pdfr & 0xf0));
661 snd_wss_out(chip, AD1845_UPR_FREQ_SEL, (rate >> 8) & 0xff);
662 snd_wss_out(chip, AD1845_LWR_FREQ_SEL, rate & 0xff);
663 full_calib = 0;
664 spin_unlock_irqrestore(&chip->reg_lock, flags);
649 } 665 }
650 if (full_calib) { 666 if (full_calib) {
651 snd_wss_mce_up(chip); 667 snd_wss_mce_up(chip);
@@ -663,7 +679,6 @@ static void snd_wss_playback_format(struct snd_wss *chip,
663 udelay(100); /* this seems to help */ 679 udelay(100); /* this seems to help */
664 snd_wss_mce_down(chip); 680 snd_wss_mce_down(chip);
665 } 681 }
666 snd_wss_calibrate_mute(chip, 0);
667 mutex_unlock(&chip->mce_mutex); 682 mutex_unlock(&chip->mce_mutex);
668} 683}
669 684
@@ -675,7 +690,6 @@ static void snd_wss_capture_format(struct snd_wss *chip,
675 int full_calib = 1; 690 int full_calib = 1;
676 691
677 mutex_lock(&chip->mce_mutex); 692 mutex_lock(&chip->mce_mutex);
678 snd_wss_calibrate_mute(chip, 1);
679 if (chip->hardware == WSS_HW_CS4231A || 693 if (chip->hardware == WSS_HW_CS4231A ||
680 (chip->hardware & WSS_HW_CS4232_MASK)) { 694 (chip->hardware & WSS_HW_CS4232_MASK)) {
681 spin_lock_irqsave(&chip->reg_lock, flags); 695 spin_lock_irqsave(&chip->reg_lock, flags);
@@ -690,6 +704,24 @@ static void snd_wss_capture_format(struct snd_wss *chip,
690 full_calib = 0; 704 full_calib = 0;
691 } 705 }
692 spin_unlock_irqrestore(&chip->reg_lock, flags); 706 spin_unlock_irqrestore(&chip->reg_lock, flags);
707 } else if (chip->hardware == WSS_HW_AD1845) {
708 unsigned rate = params_rate(params);
709
710 /*
711 * Program the AD1845 correctly for the capture stream.
712 * Note that we do NOT need to toggle the MCE bit because
713 * the PLAYBACK_ENABLE bit of the Interface Configuration
714 * register is set.
715 *
716 * NOTE: We seem to need to write to the MSB before the LSB
717 * to get the correct sample frequency.
718 */
719 spin_lock_irqsave(&chip->reg_lock, flags);
720 snd_wss_out(chip, CS4231_REC_FORMAT, (cdfr & 0xf0));
721 snd_wss_out(chip, AD1845_UPR_FREQ_SEL, (rate >> 8) & 0xff);
722 snd_wss_out(chip, AD1845_LWR_FREQ_SEL, rate & 0xff);
723 full_calib = 0;
724 spin_unlock_irqrestore(&chip->reg_lock, flags);
693 } 725 }
694 if (full_calib) { 726 if (full_calib) {
695 snd_wss_mce_up(chip); 727 snd_wss_mce_up(chip);
@@ -714,7 +746,6 @@ static void snd_wss_capture_format(struct snd_wss *chip,
714 spin_unlock_irqrestore(&chip->reg_lock, flags); 746 spin_unlock_irqrestore(&chip->reg_lock, flags);
715 snd_wss_mce_down(chip); 747 snd_wss_mce_down(chip);
716 } 748 }
717 snd_wss_calibrate_mute(chip, 0);
718 mutex_unlock(&chip->mce_mutex); 749 mutex_unlock(&chip->mce_mutex);
719} 750}
720 751
@@ -771,10 +802,11 @@ static void snd_wss_init(struct snd_wss *chip)
771{ 802{
772 unsigned long flags; 803 unsigned long flags;
773 804
805 snd_wss_calibrate_mute(chip, 1);
774 snd_wss_mce_down(chip); 806 snd_wss_mce_down(chip);
775 807
776#ifdef SNDRV_DEBUG_MCE 808#ifdef SNDRV_DEBUG_MCE
777 snd_printk("init: (1)\n"); 809 snd_printk(KERN_DEBUG "init: (1)\n");
778#endif 810#endif
779 snd_wss_mce_up(chip); 811 snd_wss_mce_up(chip);
780 spin_lock_irqsave(&chip->reg_lock, flags); 812 spin_lock_irqsave(&chip->reg_lock, flags);
@@ -789,18 +821,20 @@ static void snd_wss_init(struct snd_wss *chip)
789 snd_wss_mce_down(chip); 821 snd_wss_mce_down(chip);
790 822
791#ifdef SNDRV_DEBUG_MCE 823#ifdef SNDRV_DEBUG_MCE
792 snd_printk("init: (2)\n"); 824 snd_printk(KERN_DEBUG "init: (2)\n");
793#endif 825#endif
794 826
795 snd_wss_mce_up(chip); 827 snd_wss_mce_up(chip);
796 spin_lock_irqsave(&chip->reg_lock, flags); 828 spin_lock_irqsave(&chip->reg_lock, flags);
829 chip->image[CS4231_IFACE_CTRL] &= ~CS4231_AUTOCALIB;
830 snd_wss_out(chip, CS4231_IFACE_CTRL, chip->image[CS4231_IFACE_CTRL]);
797 snd_wss_out(chip, 831 snd_wss_out(chip,
798 CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1]); 832 CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1]);
799 spin_unlock_irqrestore(&chip->reg_lock, flags); 833 spin_unlock_irqrestore(&chip->reg_lock, flags);
800 snd_wss_mce_down(chip); 834 snd_wss_mce_down(chip);
801 835
802#ifdef SNDRV_DEBUG_MCE 836#ifdef SNDRV_DEBUG_MCE
803 snd_printk("init: (3) - afei = 0x%x\n", 837 snd_printk(KERN_DEBUG "init: (3) - afei = 0x%x\n",
804 chip->image[CS4231_ALT_FEATURE_1]); 838 chip->image[CS4231_ALT_FEATURE_1]);
805#endif 839#endif
806 840
@@ -817,7 +851,7 @@ static void snd_wss_init(struct snd_wss *chip)
817 snd_wss_mce_down(chip); 851 snd_wss_mce_down(chip);
818 852
819#ifdef SNDRV_DEBUG_MCE 853#ifdef SNDRV_DEBUG_MCE
820 snd_printk("init: (4)\n"); 854 snd_printk(KERN_DEBUG "init: (4)\n");
821#endif 855#endif
822 856
823 snd_wss_mce_up(chip); 857 snd_wss_mce_up(chip);
@@ -827,9 +861,10 @@ static void snd_wss_init(struct snd_wss *chip)
827 chip->image[CS4231_REC_FORMAT]); 861 chip->image[CS4231_REC_FORMAT]);
828 spin_unlock_irqrestore(&chip->reg_lock, flags); 862 spin_unlock_irqrestore(&chip->reg_lock, flags);
829 snd_wss_mce_down(chip); 863 snd_wss_mce_down(chip);
864 snd_wss_calibrate_mute(chip, 0);
830 865
831#ifdef SNDRV_DEBUG_MCE 866#ifdef SNDRV_DEBUG_MCE
832 snd_printk("init: (5)\n"); 867 snd_printk(KERN_DEBUG "init: (5)\n");
833#endif 868#endif
834} 869}
835 870
@@ -885,8 +920,6 @@ static void snd_wss_close(struct snd_wss *chip, unsigned int mode)
885 mutex_unlock(&chip->open_mutex); 920 mutex_unlock(&chip->open_mutex);
886 return; 921 return;
887 } 922 }
888 snd_wss_calibrate_mute(chip, 1);
889
890 /* disable IRQ */ 923 /* disable IRQ */
891 spin_lock_irqsave(&chip->reg_lock, flags); 924 spin_lock_irqsave(&chip->reg_lock, flags);
892 if (!(chip->hardware & WSS_HW_AD1848_MASK)) 925 if (!(chip->hardware & WSS_HW_AD1848_MASK))
@@ -919,8 +952,6 @@ static void snd_wss_close(struct snd_wss *chip, unsigned int mode)
919 wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */ 952 wss_outb(chip, CS4231P(STATUS), 0); /* clear IRQ */
920 spin_unlock_irqrestore(&chip->reg_lock, flags); 953 spin_unlock_irqrestore(&chip->reg_lock, flags);
921 954
922 snd_wss_calibrate_mute(chip, 0);
923
924 chip->mode = 0; 955 chip->mode = 0;
925 mutex_unlock(&chip->open_mutex); 956 mutex_unlock(&chip->open_mutex);
926} 957}
@@ -1113,7 +1144,7 @@ irqreturn_t snd_wss_interrupt(int irq, void *dev_id)
1113 if (chip->hardware & WSS_HW_AD1848_MASK) 1144 if (chip->hardware & WSS_HW_AD1848_MASK)
1114 wss_outb(chip, CS4231P(STATUS), 0); 1145 wss_outb(chip, CS4231P(STATUS), 0);
1115 else 1146 else
1116 snd_wss_outm(chip, CS4231_IRQ_STATUS, status, 0); 1147 snd_wss_out(chip, CS4231_IRQ_STATUS, status);
1117 spin_unlock(&chip->reg_lock); 1148 spin_unlock(&chip->reg_lock);
1118 return IRQ_HANDLED; 1149 return IRQ_HANDLED;
1119} 1150}
@@ -1278,7 +1309,8 @@ static int snd_wss_probe(struct snd_wss *chip)
1278 } else if (rev == 0x03) { 1309 } else if (rev == 0x03) {
1279 chip->hardware = WSS_HW_CS4236B; 1310 chip->hardware = WSS_HW_CS4236B;
1280 } else { 1311 } else {
1281 snd_printk("unknown CS chip with version 0x%x\n", rev); 1312 snd_printk(KERN_ERR
1313 "unknown CS chip with version 0x%x\n", rev);
1282 return -ENODEV; /* unknown CS4231 chip? */ 1314 return -ENODEV; /* unknown CS4231 chip? */
1283 } 1315 }
1284 } 1316 }
@@ -1314,6 +1346,10 @@ static int snd_wss_probe(struct snd_wss *chip)
1314 chip->image[CS4231_ALT_FEATURE_2] = 1346 chip->image[CS4231_ALT_FEATURE_2] =
1315 chip->hardware == WSS_HW_INTERWAVE ? 0xc2 : 0x01; 1347 chip->hardware == WSS_HW_INTERWAVE ? 0xc2 : 0x01;
1316 } 1348 }
1349 /* enable fine grained frequency selection */
1350 if (chip->hardware == WSS_HW_AD1845)
1351 chip->image[AD1845_PWR_DOWN] = 8;
1352
1317 ptr = (unsigned char *) &chip->image; 1353 ptr = (unsigned char *) &chip->image;
1318 regnum = (chip->hardware & WSS_HW_AD1848_MASK) ? 16 : 32; 1354 regnum = (chip->hardware & WSS_HW_AD1848_MASK) ? 16 : 32;
1319 snd_wss_mce_down(chip); 1355 snd_wss_mce_down(chip);
@@ -1342,7 +1378,10 @@ static int snd_wss_probe(struct snd_wss *chip)
1342 case 6: 1378 case 6:
1343 break; 1379 break;
1344 default: 1380 default:
1345 snd_printk("unknown CS4235 chip (enhanced version = 0x%x)\n", id); 1381 snd_printk(KERN_WARNING
1382 "unknown CS4235 chip "
1383 "(enhanced version = 0x%x)\n",
1384 id);
1346 } 1385 }
1347 } else if ((id & 0x1f) == 0x0b) { /* CS4236/B */ 1386 } else if ((id & 0x1f) == 0x0b) { /* CS4236/B */
1348 switch (id >> 5) { 1387 switch (id >> 5) {
@@ -1353,7 +1392,10 @@ static int snd_wss_probe(struct snd_wss *chip)
1353 chip->hardware = WSS_HW_CS4236B; 1392 chip->hardware = WSS_HW_CS4236B;
1354 break; 1393 break;
1355 default: 1394 default:
1356 snd_printk("unknown CS4236 chip (enhanced version = 0x%x)\n", id); 1395 snd_printk(KERN_WARNING
1396 "unknown CS4236 chip "
1397 "(enhanced version = 0x%x)\n",
1398 id);
1357 } 1399 }
1358 } else if ((id & 0x1f) == 0x08) { /* CS4237B */ 1400 } else if ((id & 0x1f) == 0x08) { /* CS4237B */
1359 chip->hardware = WSS_HW_CS4237B; 1401 chip->hardware = WSS_HW_CS4237B;
@@ -1364,7 +1406,10 @@ static int snd_wss_probe(struct snd_wss *chip)
1364 case 7: 1406 case 7:
1365 break; 1407 break;
1366 default: 1408 default:
1367 snd_printk("unknown CS4237B chip (enhanced version = 0x%x)\n", id); 1409 snd_printk(KERN_WARNING
1410 "unknown CS4237B chip "
1411 "(enhanced version = 0x%x)\n",
1412 id);
1368 } 1413 }
1369 } else if ((id & 0x1f) == 0x09) { /* CS4238B */ 1414 } else if ((id & 0x1f) == 0x09) { /* CS4238B */
1370 chip->hardware = WSS_HW_CS4238B; 1415 chip->hardware = WSS_HW_CS4238B;
@@ -1374,7 +1419,10 @@ static int snd_wss_probe(struct snd_wss *chip)
1374 case 7: 1419 case 7:
1375 break; 1420 break;
1376 default: 1421 default:
1377 snd_printk("unknown CS4238B chip (enhanced version = 0x%x)\n", id); 1422 snd_printk(KERN_WARNING
1423 "unknown CS4238B chip "
1424 "(enhanced version = 0x%x)\n",
1425 id);
1378 } 1426 }
1379 } else if ((id & 0x1f) == 0x1e) { /* CS4239 */ 1427 } else if ((id & 0x1f) == 0x1e) { /* CS4239 */
1380 chip->hardware = WSS_HW_CS4239; 1428 chip->hardware = WSS_HW_CS4239;
@@ -1384,10 +1432,15 @@ static int snd_wss_probe(struct snd_wss *chip)
1384 case 6: 1432 case 6:
1385 break; 1433 break;
1386 default: 1434 default:
1387 snd_printk("unknown CS4239 chip (enhanced version = 0x%x)\n", id); 1435 snd_printk(KERN_WARNING
1436 "unknown CS4239 chip "
1437 "(enhanced version = 0x%x)\n",
1438 id);
1388 } 1439 }
1389 } else { 1440 } else {
1390 snd_printk("unknown CS4236/CS423xB chip (enhanced version = 0x%x)\n", id); 1441 snd_printk(KERN_WARNING
1442 "unknown CS4236/CS423xB chip "
1443 "(enhanced version = 0x%x)\n", id);
1391 } 1444 }
1392 } 1445 }
1393 } 1446 }
@@ -1618,7 +1671,8 @@ static void snd_wss_resume(struct snd_wss *chip)
1618 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f)); 1671 wss_outb(chip, CS4231P(REGSEL), chip->mce_bit | (timeout & 0x1f));
1619 spin_unlock_irqrestore(&chip->reg_lock, flags); 1672 spin_unlock_irqrestore(&chip->reg_lock, flags);
1620 if (timeout == 0x80) 1673 if (timeout == 0x80)
1621 snd_printk("down [0x%lx]: serious init problem - codec still busy\n", chip->port); 1674 snd_printk(KERN_ERR "down [0x%lx]: serious init problem "
1675 "- codec still busy\n", chip->port);
1622 if ((timeout & CS4231_MCE) == 0 || 1676 if ((timeout & CS4231_MCE) == 0 ||
1623 !(chip->hardware & (WSS_HW_CS4231_MASK | WSS_HW_CS4232_MASK))) { 1677 !(chip->hardware & (WSS_HW_CS4231_MASK | WSS_HW_CS4232_MASK))) {
1624 return; 1678 return;
@@ -1628,7 +1682,7 @@ static void snd_wss_resume(struct snd_wss *chip)
1628} 1682}
1629#endif /* CONFIG_PM */ 1683#endif /* CONFIG_PM */
1630 1684
1631static int snd_wss_free(struct snd_wss *chip) 1685int snd_wss_free(struct snd_wss *chip)
1632{ 1686{
1633 release_and_free_resource(chip->res_port); 1687 release_and_free_resource(chip->res_port);
1634 release_and_free_resource(chip->res_cport); 1688 release_and_free_resource(chip->res_cport);
@@ -1651,6 +1705,7 @@ static int snd_wss_free(struct snd_wss *chip)
1651 kfree(chip); 1705 kfree(chip);
1652 return 0; 1706 return 0;
1653} 1707}
1708EXPORT_SYMBOL(snd_wss_free);
1654 1709
1655static int snd_wss_dev_free(struct snd_device *device) 1710static int snd_wss_dev_free(struct snd_device *device)
1656{ 1711{
@@ -1820,7 +1875,8 @@ int snd_wss_create(struct snd_card *card,
1820#if 0 1875#if 0
1821 if (chip->hardware & WSS_HW_CS4232_MASK) { 1876 if (chip->hardware & WSS_HW_CS4232_MASK) {
1822 if (chip->res_cport == NULL) 1877 if (chip->res_cport == NULL)
1823 snd_printk("CS4232 control port features are not accessible\n"); 1878 snd_printk(KERN_ERR "CS4232 control port features are "
1879 "not accessible\n");
1824 } 1880 }
1825#endif 1881#endif
1826 1882
diff --git a/sound/mips/au1x00.c b/sound/mips/au1x00.c
index 1881cec11e78..3e763d6a5d67 100644
--- a/sound/mips/au1x00.c
+++ b/sound/mips/au1x00.c
@@ -636,9 +636,10 @@ au1000_init(void)
636 struct snd_card *card; 636 struct snd_card *card;
637 struct snd_au1000 *au1000; 637 struct snd_au1000 *au1000;
638 638
639 card = snd_card_new(-1, "AC97", THIS_MODULE, sizeof(struct snd_au1000)); 639 err = snd_card_create(-1, "AC97", THIS_MODULE,
640 if (card == NULL) 640 sizeof(struct snd_au1000), &card);
641 return -ENOMEM; 641 if (err < 0)
642 return err;
642 643
643 card->private_free = snd_au1000_free; 644 card->private_free = snd_au1000_free;
644 au1000 = card->private_data; 645 au1000 = card->private_data;
@@ -678,7 +679,7 @@ au1000_init(void)
678 return err; 679 return err;
679 } 680 }
680 681
681 printk( KERN_INFO "ALSA AC97: Driver Initialized\n" ); 682 printk(KERN_INFO "ALSA AC97: Driver Initialized\n");
682 au1000_card = card; 683 au1000_card = card;
683 return 0; 684 return 0;
684} 685}
diff --git a/sound/mips/hal2.c b/sound/mips/hal2.c
index db495be01861..c52691c2fc46 100644
--- a/sound/mips/hal2.c
+++ b/sound/mips/hal2.c
@@ -878,9 +878,9 @@ static int __devinit hal2_probe(struct platform_device *pdev)
878 struct snd_hal2 *chip; 878 struct snd_hal2 *chip;
879 int err; 879 int err;
880 880
881 card = snd_card_new(index, id, THIS_MODULE, 0); 881 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
882 if (card == NULL) 882 if (err < 0)
883 return -ENOMEM; 883 return err;
884 884
885 err = hal2_create(card, &chip); 885 err = hal2_create(card, &chip);
886 if (err < 0) { 886 if (err < 0) {
diff --git a/sound/mips/sgio2audio.c b/sound/mips/sgio2audio.c
index 4c63504348dc..66f3b48ceafc 100644
--- a/sound/mips/sgio2audio.c
+++ b/sound/mips/sgio2audio.c
@@ -936,9 +936,9 @@ static int __devinit snd_sgio2audio_probe(struct platform_device *pdev)
936 struct snd_sgio2audio *chip; 936 struct snd_sgio2audio *chip;
937 int err; 937 int err;
938 938
939 card = snd_card_new(index, id, THIS_MODULE, 0); 939 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
940 if (card == NULL) 940 if (err < 0)
941 return -ENOMEM; 941 return err;
942 942
943 err = snd_sgio2audio_create(card, &chip); 943 err = snd_sgio2audio_create(card, &chip);
944 if (err < 0) { 944 if (err < 0) {
diff --git a/sound/oss/ad1848.c b/sound/oss/ad1848.c
index 7cf9913a47b2..d12bd98a37ba 100644
--- a/sound/oss/ad1848.c
+++ b/sound/oss/ad1848.c
@@ -280,7 +280,7 @@ static void wait_for_calibration(ad1848_info * devc)
280 while (timeout > 0 && (ad_read(devc, 11) & 0x20)) 280 while (timeout > 0 && (ad_read(devc, 11) & 0x20))
281 timeout--; 281 timeout--;
282 if (ad_read(devc, 11) & 0x20) 282 if (ad_read(devc, 11) & 0x20)
283 if ( (devc->model != MD_1845) || (devc->model != MD_1845_SSCAPE)) 283 if ((devc->model != MD_1845) && (devc->model != MD_1845_SSCAPE))
284 printk(KERN_WARNING "ad1848: Auto calibration timed out(3).\n"); 284 printk(KERN_WARNING "ad1848: Auto calibration timed out(3).\n");
285} 285}
286 286
@@ -2107,7 +2107,7 @@ int ad1848_control(int cmd, int arg)
2107 switch (cmd) 2107 switch (cmd)
2108 { 2108 {
2109 case AD1848_SET_XTAL: /* Change clock frequency of AD1845 (only ) */ 2109 case AD1848_SET_XTAL: /* Change clock frequency of AD1845 (only ) */
2110 if (devc->model != MD_1845 || devc->model != MD_1845_SSCAPE) 2110 if (devc->model != MD_1845 && devc->model != MD_1845_SSCAPE)
2111 return -EINVAL; 2111 return -EINVAL;
2112 spin_lock_irqsave(&devc->lock,flags); 2112 spin_lock_irqsave(&devc->lock,flags);
2113 ad_enter_MCE(devc); 2113 ad_enter_MCE(devc);
diff --git a/sound/oss/dmabuf.c b/sound/oss/dmabuf.c
index 1e90d769b62e..1bfcf7e88546 100644
--- a/sound/oss/dmabuf.c
+++ b/sound/oss/dmabuf.c
@@ -439,7 +439,7 @@ int DMAbuf_sync(int dev)
439 DMAbuf_launch_output(dev, dmap); 439 DMAbuf_launch_output(dev, dmap);
440 adev->dmap_out->flags |= DMA_SYNCING; 440 adev->dmap_out->flags |= DMA_SYNCING;
441 adev->dmap_out->underrun_count = 0; 441 adev->dmap_out->underrun_count = 0;
442 while (!signal_pending(current) && n++ <= adev->dmap_out->nbufs && 442 while (!signal_pending(current) && n++ < adev->dmap_out->nbufs &&
443 adev->dmap_out->qlen && adev->dmap_out->underrun_count == 0) { 443 adev->dmap_out->qlen && adev->dmap_out->underrun_count == 0) {
444 long t = dmabuf_timeout(dmap); 444 long t = dmabuf_timeout(dmap);
445 spin_unlock_irqrestore(&dmap->lock,flags); 445 spin_unlock_irqrestore(&dmap->lock,flags);
diff --git a/sound/oss/pas2_card.c b/sound/oss/pas2_card.c
index 25f3a22c52ee..7f377ec3486d 100644
--- a/sound/oss/pas2_card.c
+++ b/sound/oss/pas2_card.c
@@ -156,9 +156,7 @@ static int __init config_pas_hw(struct address_info *hw_config)
156 * 0x80 156 * 0x80
157 */ , 0xB88); 157 */ , 0xB88);
158 158
159 pas_write(0x80 159 pas_write(0x80 | (joystick ? 0x40 : 0), 0xF388);
160 | joystick?0x40:0
161 ,0xF388);
162 160
163 if (pas_irq < 0 || pas_irq > 15) 161 if (pas_irq < 0 || pas_irq > 15)
164 { 162 {
diff --git a/sound/oss/pss.c b/sound/oss/pss.c
index 16ed06950dc1..16517a5a1301 100644
--- a/sound/oss/pss.c
+++ b/sound/oss/pss.c
@@ -457,10 +457,9 @@ static void pss_mixer_reset(pss_confdata *devc)
457 } 457 }
458} 458}
459 459
460static int set_volume_mono(unsigned __user *p, int *aleft) 460static int set_volume_mono(unsigned __user *p, unsigned int *aleft)
461{ 461{
462 int left; 462 unsigned int left, volume;
463 unsigned volume;
464 if (get_user(volume, p)) 463 if (get_user(volume, p))
465 return -EFAULT; 464 return -EFAULT;
466 465
@@ -471,10 +470,11 @@ static int set_volume_mono(unsigned __user *p, int *aleft)
471 return 0; 470 return 0;
472} 471}
473 472
474static int set_volume_stereo(unsigned __user *p, int *aleft, int *aright) 473static int set_volume_stereo(unsigned __user *p,
474 unsigned int *aleft,
475 unsigned int *aright)
475{ 476{
476 int left, right; 477 unsigned int left, right, volume;
477 unsigned volume;
478 if (get_user(volume, p)) 478 if (get_user(volume, p))
479 return -EFAULT; 479 return -EFAULT;
480 480
diff --git a/sound/oss/sequencer.c b/sound/oss/sequencer.c
index 5c215f787ca9..c79874696bec 100644
--- a/sound/oss/sequencer.c
+++ b/sound/oss/sequencer.c
@@ -212,7 +212,6 @@ int sequencer_write(int dev, struct file *file, const char __user *buf, int coun
212{ 212{
213 unsigned char event_rec[EV_SZ], ev_code; 213 unsigned char event_rec[EV_SZ], ev_code;
214 int p = 0, c, ev_size; 214 int p = 0, c, ev_size;
215 int err;
216 int mode = translate_mode(file); 215 int mode = translate_mode(file);
217 216
218 dev = dev >> 4; 217 dev = dev >> 4;
@@ -285,7 +284,7 @@ int sequencer_write(int dev, struct file *file, const char __user *buf, int coun
285 { 284 {
286 if (!midi_opened[event_rec[2]]) 285 if (!midi_opened[event_rec[2]])
287 { 286 {
288 int mode; 287 int err, mode;
289 int dev = event_rec[2]; 288 int dev = event_rec[2];
290 289
291 if (dev >= max_mididev || midi_devs[dev]==NULL) 290 if (dev >= max_mididev || midi_devs[dev]==NULL)
diff --git a/sound/parisc/harmony.c b/sound/parisc/harmony.c
index 41f870f8a11d..6055fd6d3b38 100644
--- a/sound/parisc/harmony.c
+++ b/sound/parisc/harmony.c
@@ -975,9 +975,9 @@ snd_harmony_probe(struct parisc_device *padev)
975 struct snd_card *card; 975 struct snd_card *card;
976 struct snd_harmony *h; 976 struct snd_harmony *h;
977 977
978 card = snd_card_new(index, id, THIS_MODULE, 0); 978 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
979 if (card == NULL) 979 if (err < 0)
980 return -ENOMEM; 980 return err;
981 981
982 err = snd_harmony_create(card, padev, &h); 982 err = snd_harmony_create(card, padev, &h);
983 if (err < 0) 983 if (err < 0)
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 82b9bddcdcd6..ca25e6179d76 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -400,6 +400,26 @@ config SND_INDIGODJ
400 To compile this driver as a module, choose M here: the module 400 To compile this driver as a module, choose M here: the module
401 will be called snd-indigodj 401 will be called snd-indigodj
402 402
403config SND_INDIGOIOX
404 tristate "(Echoaudio) Indigo IOx"
405 select FW_LOADER
406 select SND_PCM
407 help
408 Say 'Y' or 'M' to include support for Echoaudio Indigo IOx.
409
410 To compile this driver as a module, choose M here: the module
411 will be called snd-indigoiox
412
413config SND_INDIGODJX
414 tristate "(Echoaudio) Indigo DJx"
415 select FW_LOADER
416 select SND_PCM
417 help
418 Say 'Y' or 'M' to include support for Echoaudio Indigo DJx.
419
420 To compile this driver as a module, choose M here: the module
421 will be called snd-indigodjx
422
403config SND_EMU10K1 423config SND_EMU10K1
404 tristate "Emu10k1 (SB Live!, Audigy, E-mu APS)" 424 tristate "Emu10k1 (SB Live!, Audigy, E-mu APS)"
405 select FW_LOADER 425 select FW_LOADER
@@ -744,7 +764,8 @@ config SND_VIRTUOSO
744 select SND_OXYGEN_LIB 764 select SND_OXYGEN_LIB
745 help 765 help
746 Say Y here to include support for sound cards based on the 766 Say Y here to include support for sound cards based on the
747 Asus AV100/AV200 chips, i.e., Xonar D1, DX, D2 and D2X. 767 Asus AV100/AV200 chips, i.e., Xonar D1, DX, D2, D2X, and
768 Essence STX.
748 Support for the HDAV1.3 (Deluxe) is very experimental. 769 Support for the HDAV1.3 (Deluxe) is very experimental.
749 770
750 To compile this driver as a module, choose M here: the module 771 To compile this driver as a module, choose M here: the module
diff --git a/sound/pci/ac97/ac97_codec.c b/sound/pci/ac97/ac97_codec.c
index e2b843b4f9d0..97ee127ac33d 100644
--- a/sound/pci/ac97/ac97_codec.c
+++ b/sound/pci/ac97/ac97_codec.c
@@ -143,6 +143,7 @@ static const struct ac97_codec_id snd_ac97_codec_ids[] = {
143{ 0x43525970, 0xfffffff8, "CS4202", NULL, NULL }, 143{ 0x43525970, 0xfffffff8, "CS4202", NULL, NULL },
144{ 0x43585421, 0xffffffff, "HSD11246", NULL, NULL }, // SmartMC II 144{ 0x43585421, 0xffffffff, "HSD11246", NULL, NULL }, // SmartMC II
145{ 0x43585428, 0xfffffff8, "Cx20468", patch_conexant, NULL }, // SmartAMC fixme: the mask might be different 145{ 0x43585428, 0xfffffff8, "Cx20468", patch_conexant, NULL }, // SmartAMC fixme: the mask might be different
146{ 0x43585430, 0xffffffff, "Cx20468-31", patch_conexant, NULL },
146{ 0x43585431, 0xffffffff, "Cx20551", patch_cx20551, NULL }, 147{ 0x43585431, 0xffffffff, "Cx20551", patch_cx20551, NULL },
147{ 0x44543031, 0xfffffff0, "DT0398", NULL, NULL }, 148{ 0x44543031, 0xfffffff0, "DT0398", NULL, NULL },
148{ 0x454d4328, 0xffffffff, "EM28028", NULL, NULL }, // same as TR28028? 149{ 0x454d4328, 0xffffffff, "EM28028", NULL, NULL }, // same as TR28028?
@@ -383,7 +384,7 @@ int snd_ac97_update_bits(struct snd_ac97 *ac97, unsigned short reg, unsigned sho
383 384
384EXPORT_SYMBOL(snd_ac97_update_bits); 385EXPORT_SYMBOL(snd_ac97_update_bits);
385 386
386/* no lock version - see snd_ac97_updat_bits() */ 387/* no lock version - see snd_ac97_update_bits() */
387int snd_ac97_update_bits_nolock(struct snd_ac97 *ac97, unsigned short reg, 388int snd_ac97_update_bits_nolock(struct snd_ac97 *ac97, unsigned short reg,
388 unsigned short mask, unsigned short value) 389 unsigned short mask, unsigned short value)
389{ 390{
@@ -1643,7 +1644,10 @@ static int snd_ac97_modem_build(struct snd_card *card, struct snd_ac97 * ac97)
1643{ 1644{
1644 int err, idx; 1645 int err, idx;
1645 1646
1646 //printk("AC97_GPIO_CFG = %x\n",snd_ac97_read(ac97,AC97_GPIO_CFG)); 1647 /*
1648 printk(KERN_DEBUG "AC97_GPIO_CFG = %x\n",
1649 snd_ac97_read(ac97,AC97_GPIO_CFG));
1650 */
1647 snd_ac97_write(ac97, AC97_GPIO_CFG, 0xffff & ~(AC97_GPIO_LINE1_OH)); 1651 snd_ac97_write(ac97, AC97_GPIO_CFG, 0xffff & ~(AC97_GPIO_LINE1_OH));
1648 snd_ac97_write(ac97, AC97_GPIO_POLARITY, 0xffff & ~(AC97_GPIO_LINE1_OH)); 1652 snd_ac97_write(ac97, AC97_GPIO_POLARITY, 0xffff & ~(AC97_GPIO_LINE1_OH));
1649 snd_ac97_write(ac97, AC97_GPIO_STICKY, 0xffff); 1653 snd_ac97_write(ac97, AC97_GPIO_STICKY, 0xffff);
diff --git a/sound/pci/ac97/ac97_proc.c b/sound/pci/ac97/ac97_proc.c
index 060ea59d5f02..73b17d526c8b 100644
--- a/sound/pci/ac97/ac97_proc.c
+++ b/sound/pci/ac97/ac97_proc.c
@@ -125,6 +125,8 @@ static void snd_ac97_proc_read_main(struct snd_ac97 *ac97, struct snd_info_buffe
125 snd_iprintf(buffer, "PCI Subsys Device: 0x%04x\n\n", 125 snd_iprintf(buffer, "PCI Subsys Device: 0x%04x\n\n",
126 ac97->subsystem_device); 126 ac97->subsystem_device);
127 127
128 snd_iprintf(buffer, "Flags: %x\n", ac97->flags);
129
128 if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) { 130 if ((ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23) {
129 val = snd_ac97_read(ac97, AC97_INT_PAGING); 131 val = snd_ac97_read(ac97, AC97_INT_PAGING);
130 snd_ac97_update_bits(ac97, AC97_INT_PAGING, 132 snd_ac97_update_bits(ac97, AC97_INT_PAGING,
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c
index a7f38e63303f..d1f242bd0ac5 100644
--- a/sound/pci/ad1889.c
+++ b/sound/pci/ad1889.c
@@ -995,10 +995,10 @@ snd_ad1889_probe(struct pci_dev *pci,
995 } 995 }
996 996
997 /* (2) */ 997 /* (2) */
998 card = snd_card_new(index[devno], id[devno], THIS_MODULE, 0); 998 err = snd_card_create(index[devno], id[devno], THIS_MODULE, 0, &card);
999 /* XXX REVISIT: we can probably allocate chip in this call */ 999 /* XXX REVISIT: we can probably allocate chip in this call */
1000 if (card == NULL) 1000 if (err < 0)
1001 return -ENOMEM; 1001 return err;
1002 1002
1003 strcpy(card->driver, "AD1889"); 1003 strcpy(card->driver, "AD1889");
1004 strcpy(card->shortname, "Analog Devices AD1889"); 1004 strcpy(card->shortname, "Analog Devices AD1889");
diff --git a/sound/pci/ak4531_codec.c b/sound/pci/ak4531_codec.c
index 0f819ddb3ebf..fd135e3d8a84 100644
--- a/sound/pci/ak4531_codec.c
+++ b/sound/pci/ak4531_codec.c
@@ -51,7 +51,8 @@ static void snd_ak4531_dump(struct snd_ak4531 *ak4531)
51 int idx; 51 int idx;
52 52
53 for (idx = 0; idx < 0x19; idx++) 53 for (idx = 0; idx < 0x19; idx++)
54 printk("ak4531 0x%x: 0x%x\n", idx, ak4531->regs[idx]); 54 printk(KERN_DEBUG "ak4531 0x%x: 0x%x\n",
55 idx, ak4531->regs[idx]);
55} 56}
56 57
57#endif 58#endif
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index 1a0fd65ec280..4edf270a7809 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -2142,7 +2142,7 @@ static int __devinit snd_ali_resources(struct snd_ali *codec)
2142{ 2142{
2143 int err; 2143 int err;
2144 2144
2145 snd_ali_printk("resouces allocation ...\n"); 2145 snd_ali_printk("resources allocation ...\n");
2146 err = pci_request_regions(codec->pci, "ALI 5451"); 2146 err = pci_request_regions(codec->pci, "ALI 5451");
2147 if (err < 0) 2147 if (err < 0)
2148 return err; 2148 return err;
@@ -2154,7 +2154,7 @@ static int __devinit snd_ali_resources(struct snd_ali *codec)
2154 return -EBUSY; 2154 return -EBUSY;
2155 } 2155 }
2156 codec->irq = codec->pci->irq; 2156 codec->irq = codec->pci->irq;
2157 snd_ali_printk("resouces allocated.\n"); 2157 snd_ali_printk("resources allocated.\n");
2158 return 0; 2158 return 0;
2159} 2159}
2160static int snd_ali_dev_free(struct snd_device *device) 2160static int snd_ali_dev_free(struct snd_device *device)
@@ -2307,9 +2307,9 @@ static int __devinit snd_ali_probe(struct pci_dev *pci,
2307 2307
2308 snd_ali_printk("probe ...\n"); 2308 snd_ali_printk("probe ...\n");
2309 2309
2310 card = snd_card_new(index, id, THIS_MODULE, 0); 2310 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
2311 if (!card) 2311 if (err < 0)
2312 return -ENOMEM; 2312 return err;
2313 2313
2314 err = snd_ali_create(card, pci, pcm_channels, spdif, &codec); 2314 err = snd_ali_create(card, pci, pcm_channels, spdif, &codec);
2315 if (err < 0) 2315 if (err < 0)
diff --git a/sound/pci/als300.c b/sound/pci/als300.c
index 8df6824b51cd..009b4c8225a5 100644
--- a/sound/pci/als300.c
+++ b/sound/pci/als300.c
@@ -91,7 +91,7 @@
91#define DEBUG_PLAY_REC 0 91#define DEBUG_PLAY_REC 0
92 92
93#if DEBUG_CALLS 93#if DEBUG_CALLS
94#define snd_als300_dbgcalls(format, args...) printk(format, ##args) 94#define snd_als300_dbgcalls(format, args...) printk(KERN_DEBUG format, ##args)
95#define snd_als300_dbgcallenter() printk(KERN_ERR "--> %s\n", __func__) 95#define snd_als300_dbgcallenter() printk(KERN_ERR "--> %s\n", __func__)
96#define snd_als300_dbgcallleave() printk(KERN_ERR "<-- %s\n", __func__) 96#define snd_als300_dbgcallleave() printk(KERN_ERR "<-- %s\n", __func__)
97#else 97#else
@@ -812,10 +812,10 @@ static int __devinit snd_als300_probe(struct pci_dev *pci,
812 return -ENOENT; 812 return -ENOENT;
813 } 813 }
814 814
815 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 815 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
816 816
817 if (card == NULL) 817 if (err < 0)
818 return -ENOMEM; 818 return err;
819 819
820 chip_type = pci_id->driver_data; 820 chip_type = pci_id->driver_data;
821 821
diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c
index ba570053d4d5..542a0c65a92c 100644
--- a/sound/pci/als4000.c
+++ b/sound/pci/als4000.c
@@ -889,12 +889,13 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
889 pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO); 889 pci_write_config_word(pci, PCI_COMMAND, word | PCI_COMMAND_IO);
890 pci_set_master(pci); 890 pci_set_master(pci);
891 891
892 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 892 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
893 sizeof(*acard) /* private_data: acard */); 893 sizeof(*acard) /* private_data: acard */,
894 if (card == NULL) { 894 &card);
895 if (err < 0) {
895 pci_release_regions(pci); 896 pci_release_regions(pci);
896 pci_disable_device(pci); 897 pci_disable_device(pci);
897 return -ENOMEM; 898 return err;
898 } 899 }
899 900
900 acard = card->private_data; 901 acard = card->private_data;
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index 226fe8237d31..9ce8548c03e4 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -1645,9 +1645,9 @@ static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1645 struct atiixp *chip; 1645 struct atiixp *chip;
1646 int err; 1646 int err;
1647 1647
1648 card = snd_card_new(index, id, THIS_MODULE, 0); 1648 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
1649 if (card == NULL) 1649 if (err < 0)
1650 return -ENOMEM; 1650 return err;
1651 1651
1652 strcpy(card->driver, spdif_aclink ? "ATIIXP" : "ATIIXP-SPDMA"); 1652 strcpy(card->driver, spdif_aclink ? "ATIIXP" : "ATIIXP-SPDMA");
1653 strcpy(card->shortname, "ATI IXP"); 1653 strcpy(card->shortname, "ATI IXP");
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c
index 0e6e5cc1c501..c3136cccc559 100644
--- a/sound/pci/atiixp_modem.c
+++ b/sound/pci/atiixp_modem.c
@@ -1288,9 +1288,9 @@ static int __devinit snd_atiixp_probe(struct pci_dev *pci,
1288 struct atiixp_modem *chip; 1288 struct atiixp_modem *chip;
1289 int err; 1289 int err;
1290 1290
1291 card = snd_card_new(index, id, THIS_MODULE, 0); 1291 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
1292 if (card == NULL) 1292 if (err < 0)
1293 return -ENOMEM; 1293 return err;
1294 1294
1295 strcpy(card->driver, "ATIIXP-MODEM"); 1295 strcpy(card->driver, "ATIIXP-MODEM");
1296 strcpy(card->shortname, "ATI IXP Modem"); 1296 strcpy(card->shortname, "ATI IXP Modem");
diff --git a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c
index a36d4d1fd419..9ec122383eef 100644
--- a/sound/pci/au88x0/au88x0.c
+++ b/sound/pci/au88x0/au88x0.c
@@ -250,9 +250,9 @@ snd_vortex_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
250 return -ENOENT; 250 return -ENOENT;
251 } 251 }
252 // (2) 252 // (2)
253 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 253 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
254 if (card == NULL) 254 if (err < 0)
255 return -ENOMEM; 255 return err;
256 256
257 // (3) 257 // (3)
258 if ((err = snd_vortex_create(card, pci, &chip)) < 0) { 258 if ((err = snd_vortex_create(card, pci, &chip)) < 0) {
diff --git a/sound/pci/au88x0/au88x0_a3d.c b/sound/pci/au88x0/au88x0_a3d.c
index 649849e540d3..f4aa8ff6f5f9 100644
--- a/sound/pci/au88x0/au88x0_a3d.c
+++ b/sound/pci/au88x0/au88x0_a3d.c
@@ -462,9 +462,10 @@ static void a3dsrc_ZeroSliceIO(a3dsrc_t * a)
462/* Reset Single A3D source. */ 462/* Reset Single A3D source. */
463static void a3dsrc_ZeroState(a3dsrc_t * a) 463static void a3dsrc_ZeroState(a3dsrc_t * a)
464{ 464{
465 465 /*
466 //printk("vortex: ZeroState slice: %d, source %d\n", a->slice, a->source); 466 printk(KERN_DEBUG "vortex: ZeroState slice: %d, source %d\n",
467 467 a->slice, a->source);
468 */
468 a3dsrc_SetAtmosState(a, 0, 0, 0, 0); 469 a3dsrc_SetAtmosState(a, 0, 0, 0, 0);
469 a3dsrc_SetHrtfState(a, A3dHrirZeros, A3dHrirZeros); 470 a3dsrc_SetHrtfState(a, A3dHrirZeros, A3dHrirZeros);
470 a3dsrc_SetItdDline(a, A3dItdDlineZeros); 471 a3dsrc_SetItdDline(a, A3dItdDlineZeros);
diff --git a/sound/pci/au88x0/au88x0_core.c b/sound/pci/au88x0/au88x0_core.c
index b070e5714514..3906f5afe27a 100644
--- a/sound/pci/au88x0/au88x0_core.c
+++ b/sound/pci/au88x0/au88x0_core.c
@@ -1135,7 +1135,10 @@ vortex_adbdma_setbuffers(vortex_t * vortex, int adbdma,
1135 snd_pcm_sgbuf_get_addr(dma->substream, 0)); 1135 snd_pcm_sgbuf_get_addr(dma->substream, 0));
1136 break; 1136 break;
1137 } 1137 }
1138 //printk("vortex: cfg0 = 0x%x\nvortex: cfg1=0x%x\n", dma->cfg0, dma->cfg1); 1138 /*
1139 printk(KERN_DEBUG "vortex: cfg0 = 0x%x\nvortex: cfg1=0x%x\n",
1140 dma->cfg0, dma->cfg1);
1141 */
1139 hwwrite(vortex->mmio, VORTEX_ADBDMA_BUFCFG0 + (adbdma << 3), dma->cfg0); 1142 hwwrite(vortex->mmio, VORTEX_ADBDMA_BUFCFG0 + (adbdma << 3), dma->cfg0);
1140 hwwrite(vortex->mmio, VORTEX_ADBDMA_BUFCFG1 + (adbdma << 3), dma->cfg1); 1143 hwwrite(vortex->mmio, VORTEX_ADBDMA_BUFCFG1 + (adbdma << 3), dma->cfg1);
1141 1144
@@ -1959,7 +1962,7 @@ vortex_connect_codecplay(vortex_t * vortex, int en, unsigned char mixers[])
1959 ADB_CODECOUT(0 + 4)); 1962 ADB_CODECOUT(0 + 4));
1960 vortex_connection_mix_adb(vortex, en, 0x11, mixers[3], 1963 vortex_connection_mix_adb(vortex, en, 0x11, mixers[3],
1961 ADB_CODECOUT(1 + 4)); 1964 ADB_CODECOUT(1 + 4));
1962 //printk("SDAC detected "); 1965 /* printk(KERN_DEBUG "SDAC detected "); */
1963 } 1966 }
1964#else 1967#else
1965 // Use plain direct output to codec. 1968 // Use plain direct output to codec.
@@ -2013,7 +2016,11 @@ vortex_adb_checkinout(vortex_t * vortex, int resmap[], int out, int restype)
2013 resmap[restype] |= (1 << i); 2016 resmap[restype] |= (1 << i);
2014 else 2017 else
2015 vortex->dma_adb[i].resources[restype] |= (1 << i); 2018 vortex->dma_adb[i].resources[restype] |= (1 << i);
2016 //printk("vortex: ResManager: type %d out %d\n", restype, i); 2019 /*
2020 printk(KERN_DEBUG
2021 "vortex: ResManager: type %d out %d\n",
2022 restype, i);
2023 */
2017 return i; 2024 return i;
2018 } 2025 }
2019 } 2026 }
@@ -2024,7 +2031,11 @@ vortex_adb_checkinout(vortex_t * vortex, int resmap[], int out, int restype)
2024 for (i = 0; i < qty; i++) { 2031 for (i = 0; i < qty; i++) {
2025 if (resmap[restype] & (1 << i)) { 2032 if (resmap[restype] & (1 << i)) {
2026 resmap[restype] &= ~(1 << i); 2033 resmap[restype] &= ~(1 << i);
2027 //printk("vortex: ResManager: type %d in %d\n",restype, i); 2034 /*
2035 printk(KERN_DEBUG
2036 "vortex: ResManager: type %d in %d\n",
2037 restype, i);
2038 */
2028 return i; 2039 return i;
2029 } 2040 }
2030 } 2041 }
@@ -2789,7 +2800,7 @@ vortex_translateformat(vortex_t * vortex, char bits, char nch, int encod)
2789{ 2800{
2790 int a, this_194; 2801 int a, this_194;
2791 2802
2792 if ((bits != 8) || (bits != 16)) 2803 if ((bits != 8) && (bits != 16))
2793 return -1; 2804 return -1;
2794 2805
2795 switch (encod) { 2806 switch (encod) {
diff --git a/sound/pci/au88x0/au88x0_synth.c b/sound/pci/au88x0/au88x0_synth.c
index 978b856f5621..2805e34bd41d 100644
--- a/sound/pci/au88x0/au88x0_synth.c
+++ b/sound/pci/au88x0/au88x0_synth.c
@@ -213,38 +213,59 @@ vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
213 switch (reg) { 213 switch (reg) {
214 /* Voice specific parameters */ 214 /* Voice specific parameters */
215 case 0: /* running */ 215 case 0: /* running */
216 //printk("vortex: WT SetReg(0x%x) = 0x%08x\n", WT_RUN(wt), (int)val); 216 /*
217 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
218 WT_RUN(wt), (int)val);
219 */
217 hwwrite(vortex->mmio, WT_RUN(wt), val); 220 hwwrite(vortex->mmio, WT_RUN(wt), val);
218 return 0xc; 221 return 0xc;
219 break; 222 break;
220 case 1: /* param 0 */ 223 case 1: /* param 0 */
221 //printk("vortex: WT SetReg(0x%x) = 0x%08x\n", WT_PARM(wt,0), (int)val); 224 /*
225 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
226 WT_PARM(wt,0), (int)val);
227 */
222 hwwrite(vortex->mmio, WT_PARM(wt, 0), val); 228 hwwrite(vortex->mmio, WT_PARM(wt, 0), val);
223 return 0xc; 229 return 0xc;
224 break; 230 break;
225 case 2: /* param 1 */ 231 case 2: /* param 1 */
226 //printk("vortex: WT SetReg(0x%x) = 0x%08x\n", WT_PARM(wt,1), (int)val); 232 /*
233 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
234 WT_PARM(wt,1), (int)val);
235 */
227 hwwrite(vortex->mmio, WT_PARM(wt, 1), val); 236 hwwrite(vortex->mmio, WT_PARM(wt, 1), val);
228 return 0xc; 237 return 0xc;
229 break; 238 break;
230 case 3: /* param 2 */ 239 case 3: /* param 2 */
231 //printk("vortex: WT SetReg(0x%x) = 0x%08x\n", WT_PARM(wt,2), (int)val); 240 /*
241 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
242 WT_PARM(wt,2), (int)val);
243 */
232 hwwrite(vortex->mmio, WT_PARM(wt, 2), val); 244 hwwrite(vortex->mmio, WT_PARM(wt, 2), val);
233 return 0xc; 245 return 0xc;
234 break; 246 break;
235 case 4: /* param 3 */ 247 case 4: /* param 3 */
236 //printk("vortex: WT SetReg(0x%x) = 0x%08x\n", WT_PARM(wt,3), (int)val); 248 /*
249 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
250 WT_PARM(wt,3), (int)val);
251 */
237 hwwrite(vortex->mmio, WT_PARM(wt, 3), val); 252 hwwrite(vortex->mmio, WT_PARM(wt, 3), val);
238 return 0xc; 253 return 0xc;
239 break; 254 break;
240 case 6: /* mute */ 255 case 6: /* mute */
241 //printk("vortex: WT SetReg(0x%x) = 0x%08x\n", WT_MUTE(wt), (int)val); 256 /*
257 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
258 WT_MUTE(wt), (int)val);
259 */
242 hwwrite(vortex->mmio, WT_MUTE(wt), val); 260 hwwrite(vortex->mmio, WT_MUTE(wt), val);
243 return 0xc; 261 return 0xc;
244 break; 262 break;
245 case 0xb: 263 case 0xb:
246 { /* delay */ 264 { /* delay */
247 //printk("vortex: WT SetReg(0x%x) = 0x%08x\n", WT_DELAY(wt,0), (int)val); 265 /*
266 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n",
267 WT_DELAY(wt,0), (int)val);
268 */
248 hwwrite(vortex->mmio, WT_DELAY(wt, 3), val); 269 hwwrite(vortex->mmio, WT_DELAY(wt, 3), val);
249 hwwrite(vortex->mmio, WT_DELAY(wt, 2), val); 270 hwwrite(vortex->mmio, WT_DELAY(wt, 2), val);
250 hwwrite(vortex->mmio, WT_DELAY(wt, 1), val); 271 hwwrite(vortex->mmio, WT_DELAY(wt, 1), val);
@@ -272,7 +293,9 @@ vortex_wt_SetReg(vortex_t * vortex, unsigned char reg, int wt,
272 return 0; 293 return 0;
273 break; 294 break;
274 } 295 }
275 //printk("vortex: WT SetReg(0x%x) = 0x%08x\n", ecx, (int)val); 296 /*
297 printk(KERN_DEBUG "vortex: WT SetReg(0x%x) = 0x%08x\n", ecx, (int)val);
298 */
276 hwwrite(vortex->mmio, ecx, val); 299 hwwrite(vortex->mmio, ecx, val);
277 return 1; 300 return 1;
278} 301}
diff --git a/sound/pci/aw2/aw2-alsa.c b/sound/pci/aw2/aw2-alsa.c
index c7c54e7748e9..8eea29fc42fe 100644
--- a/sound/pci/aw2/aw2-alsa.c
+++ b/sound/pci/aw2/aw2-alsa.c
@@ -368,9 +368,9 @@ static int __devinit snd_aw2_probe(struct pci_dev *pci,
368 } 368 }
369 369
370 /* (2) Create card instance */ 370 /* (2) Create card instance */
371 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 371 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
372 if (card == NULL) 372 if (err < 0)
373 return -ENOMEM; 373 return err;
374 374
375 /* (3) Create main component */ 375 /* (3) Create main component */
376 err = snd_aw2_create(card, pci, &chip); 376 err = snd_aw2_create(card, pci, &chip);
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index 333007c523a1..e9e9b5821d41 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -211,25 +211,25 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
211#endif 211#endif
212 212
213#if DEBUG_MIXER 213#if DEBUG_MIXER
214#define snd_azf3328_dbgmixer(format, args...) printk(format, ##args) 214#define snd_azf3328_dbgmixer(format, args...) printk(KERN_DEBUG format, ##args)
215#else 215#else
216#define snd_azf3328_dbgmixer(format, args...) 216#define snd_azf3328_dbgmixer(format, args...)
217#endif 217#endif
218 218
219#if DEBUG_PLAY_REC 219#if DEBUG_PLAY_REC
220#define snd_azf3328_dbgplay(format, args...) printk(KERN_ERR format, ##args) 220#define snd_azf3328_dbgplay(format, args...) printk(KERN_DEBUG format, ##args)
221#else 221#else
222#define snd_azf3328_dbgplay(format, args...) 222#define snd_azf3328_dbgplay(format, args...)
223#endif 223#endif
224 224
225#if DEBUG_MISC 225#if DEBUG_MISC
226#define snd_azf3328_dbgtimer(format, args...) printk(KERN_ERR format, ##args) 226#define snd_azf3328_dbgtimer(format, args...) printk(KERN_DEBUG format, ##args)
227#else 227#else
228#define snd_azf3328_dbgtimer(format, args...) 228#define snd_azf3328_dbgtimer(format, args...)
229#endif 229#endif
230 230
231#if DEBUG_GAME 231#if DEBUG_GAME
232#define snd_azf3328_dbggame(format, args...) printk(KERN_ERR format, ##args) 232#define snd_azf3328_dbggame(format, args...) printk(KERN_DEBUG format, ##args)
233#else 233#else
234#define snd_azf3328_dbggame(format, args...) 234#define snd_azf3328_dbggame(format, args...)
235#endif 235#endif
@@ -2216,9 +2216,9 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2216 return -ENOENT; 2216 return -ENOENT;
2217 } 2217 }
2218 2218
2219 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 2219 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2220 if (card == NULL) 2220 if (err < 0)
2221 return -ENOMEM; 2221 return err;
2222 2222
2223 strcpy(card->driver, "AZF3328"); 2223 strcpy(card->driver, "AZF3328");
2224 strcpy(card->shortname, "Aztech AZF3328 (PCI168)"); 2224 strcpy(card->shortname, "Aztech AZF3328 (PCI168)");
diff --git a/sound/pci/bt87x.c b/sound/pci/bt87x.c
index 1aa1c0402540..a299340519df 100644
--- a/sound/pci/bt87x.c
+++ b/sound/pci/bt87x.c
@@ -888,9 +888,9 @@ static int __devinit snd_bt87x_probe(struct pci_dev *pci,
888 return -ENOENT; 888 return -ENOENT;
889 } 889 }
890 890
891 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 891 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
892 if (!card) 892 if (err < 0)
893 return -ENOMEM; 893 return err;
894 894
895 err = snd_bt87x_create(card, pci, &chip); 895 err = snd_bt87x_create(card, pci, &chip);
896 if (err < 0) 896 if (err < 0)
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index 0e62205d4081..df757575798a 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -255,6 +255,14 @@ static struct snd_ca0106_details ca0106_chip_details[] = {
255 .gpio_type = 2, 255 .gpio_type = 2,
256 .i2c_adc = 1, 256 .i2c_adc = 1,
257 .spi_dac = 1 } , 257 .spi_dac = 1 } ,
258 /* Giga-byte GA-G1975X mobo
259 * Novell bnc#395807
260 */
261 /* FIXME: the GPIO and I2C setting aren't tested well */
262 { .serial = 0x1458a006,
263 .name = "Giga-byte GA-G1975X",
264 .gpio_type = 1,
265 .i2c_adc = 1 },
258 /* Shuttle XPC SD31P which has an onboard Creative Labs 266 /* Shuttle XPC SD31P which has an onboard Creative Labs
259 * Sound Blaster Live! 24-bit EAX 267 * Sound Blaster Live! 24-bit EAX
260 * high-definition 7.1 audio processor". 268 * high-definition 7.1 audio processor".
@@ -404,7 +412,9 @@ int snd_ca0106_i2c_write(struct snd_ca0106 *emu,
404 } 412 }
405 413
406 tmp = reg << 25 | value << 16; 414 tmp = reg << 25 | value << 16;
407 // snd_printk("I2C-write:reg=0x%x, value=0x%x\n", reg, value); 415 /*
416 snd_printk(KERN_DEBUG "I2C-write:reg=0x%x, value=0x%x\n", reg, value);
417 */
408 /* Not sure what this I2C channel controls. */ 418 /* Not sure what this I2C channel controls. */
409 /* snd_ca0106_ptr_write(emu, I2C_D0, 0, tmp); */ 419 /* snd_ca0106_ptr_write(emu, I2C_D0, 0, tmp); */
410 420
@@ -422,7 +432,7 @@ int snd_ca0106_i2c_write(struct snd_ca0106 *emu,
422 /* Wait till the transaction ends */ 432 /* Wait till the transaction ends */
423 while (1) { 433 while (1) {
424 status = snd_ca0106_ptr_read(emu, I2C_A, 0); 434 status = snd_ca0106_ptr_read(emu, I2C_A, 0);
425 //snd_printk("I2C:status=0x%x\n", status); 435 /*snd_printk(KERN_DEBUG "I2C:status=0x%x\n", status);*/
426 timeout++; 436 timeout++;
427 if ((status & I2C_A_ADC_START) == 0) 437 if ((status & I2C_A_ADC_START) == 0)
428 break; 438 break;
@@ -521,7 +531,10 @@ static int snd_ca0106_pcm_open_playback_channel(struct snd_pcm_substream *substr
521 channel->number = channel_id; 531 channel->number = channel_id;
522 532
523 channel->use = 1; 533 channel->use = 1;
524 //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel); 534 /*
535 printk(KERN_DEBUG "open:channel_id=%d, chip=%p, channel=%p\n",
536 channel_id, chip, channel);
537 */
525 //channel->interrupt = snd_ca0106_pcm_channel_interrupt; 538 //channel->interrupt = snd_ca0106_pcm_channel_interrupt;
526 channel->epcm = epcm; 539 channel->epcm = epcm;
527 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 540 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
@@ -614,7 +627,10 @@ static int snd_ca0106_pcm_open_capture_channel(struct snd_pcm_substream *substre
614 channel->number = channel_id; 627 channel->number = channel_id;
615 628
616 channel->use = 1; 629 channel->use = 1;
617 //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel); 630 /*
631 printk(KERN_DEBUG "open:channel_id=%d, chip=%p, channel=%p\n",
632 channel_id, chip, channel);
633 */
618 //channel->interrupt = snd_ca0106_pcm_channel_interrupt; 634 //channel->interrupt = snd_ca0106_pcm_channel_interrupt;
619 channel->epcm = epcm; 635 channel->epcm = epcm;
620 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 636 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
@@ -705,9 +721,20 @@ static int snd_ca0106_pcm_prepare_playback(struct snd_pcm_substream *substream)
705 u32 reg71; 721 u32 reg71;
706 int i; 722 int i;
707 723
708 //snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1)); 724#if 0 /* debug */
709 //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base); 725 snd_printk(KERN_DEBUG
710 //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes); 726 "prepare:channel_number=%d, rate=%d, format=0x%x, "
727 "channels=%d, buffer_size=%ld, period_size=%ld, "
728 "periods=%u, frames_to_bytes=%d\n",
729 channel, runtime->rate, runtime->format,
730 runtime->channels, runtime->buffer_size,
731 runtime->period_size, runtime->periods,
732 frames_to_bytes(runtime, 1));
733 snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, table_base=%p\n",
734 runtime->dma_addr, runtime->dma_area, table_base);
735 snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",
736 emu->buffer.addr, emu->buffer.area, emu->buffer.bytes);
737#endif /* debug */
711 /* Rate can be set per channel. */ 738 /* Rate can be set per channel. */
712 /* reg40 control host to fifo */ 739 /* reg40 control host to fifo */
713 /* reg71 controls DAC rate. */ 740 /* reg71 controls DAC rate. */
@@ -799,9 +826,20 @@ static int snd_ca0106_pcm_prepare_capture(struct snd_pcm_substream *substream)
799 u32 reg71_set = 0; 826 u32 reg71_set = 0;
800 u32 reg71; 827 u32 reg71;
801 828
802 //snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1)); 829#if 0 /* debug */
803 //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base); 830 snd_printk(KERN_DEBUG
804 //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->buffer.addr, emu->buffer.area, emu->buffer.bytes); 831 "prepare:channel_number=%d, rate=%d, format=0x%x, "
832 "channels=%d, buffer_size=%ld, period_size=%ld, "
833 "periods=%u, frames_to_bytes=%d\n",
834 channel, runtime->rate, runtime->format,
835 runtime->channels, runtime->buffer_size,
836 runtime->period_size, runtime->periods,
837 frames_to_bytes(runtime, 1));
838 snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, table_base=%p\n",
839 runtime->dma_addr, runtime->dma_area, table_base);
840 snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",
841 emu->buffer.addr, emu->buffer.area, emu->buffer.bytes);
842#endif /* debug */
805 /* reg71 controls ADC rate. */ 843 /* reg71 controls ADC rate. */
806 switch (runtime->rate) { 844 switch (runtime->rate) {
807 case 44100: 845 case 44100:
@@ -846,7 +884,14 @@ static int snd_ca0106_pcm_prepare_capture(struct snd_pcm_substream *substream)
846 } 884 }
847 885
848 886
849 //printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, frames_to_bytes(runtime, 1)); 887 /*
888 printk(KERN_DEBUG
889 "prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, "
890 "buffer_size=%ld, period_size=%ld, frames_to_bytes=%d\n",
891 channel, runtime->rate, runtime->format, runtime->channels,
892 runtime->buffer_size, runtime->period_size,
893 frames_to_bytes(runtime, 1));
894 */
850 snd_ca0106_ptr_write(emu, 0x13, channel, 0); 895 snd_ca0106_ptr_write(emu, 0x13, channel, 0);
851 snd_ca0106_ptr_write(emu, CAPTURE_DMA_ADDR, channel, runtime->dma_addr); 896 snd_ca0106_ptr_write(emu, CAPTURE_DMA_ADDR, channel, runtime->dma_addr);
852 snd_ca0106_ptr_write(emu, CAPTURE_BUFFER_SIZE, channel, frames_to_bytes(runtime, runtime->buffer_size)<<16); // buffer size in bytes 897 snd_ca0106_ptr_write(emu, CAPTURE_BUFFER_SIZE, channel, frames_to_bytes(runtime, runtime->buffer_size)<<16); // buffer size in bytes
@@ -888,13 +933,13 @@ static int snd_ca0106_pcm_trigger_playback(struct snd_pcm_substream *substream,
888 runtime = s->runtime; 933 runtime = s->runtime;
889 epcm = runtime->private_data; 934 epcm = runtime->private_data;
890 channel = epcm->channel_id; 935 channel = epcm->channel_id;
891 /* snd_printk("channel=%d\n",channel); */ 936 /* snd_printk(KERN_DEBUG "channel=%d\n", channel); */
892 epcm->running = running; 937 epcm->running = running;
893 basic |= (0x1 << channel); 938 basic |= (0x1 << channel);
894 extended |= (0x10 << channel); 939 extended |= (0x10 << channel);
895 snd_pcm_trigger_done(s, substream); 940 snd_pcm_trigger_done(s, substream);
896 } 941 }
897 /* snd_printk("basic=0x%x, extended=0x%x\n",basic, extended); */ 942 /* snd_printk(KERN_DEBUG "basic=0x%x, extended=0x%x\n",basic, extended); */
898 943
899 switch (cmd) { 944 switch (cmd) {
900 case SNDRV_PCM_TRIGGER_START: 945 case SNDRV_PCM_TRIGGER_START:
@@ -972,8 +1017,13 @@ snd_ca0106_pcm_pointer_playback(struct snd_pcm_substream *substream)
972 ptr=ptr2; 1017 ptr=ptr2;
973 if (ptr >= runtime->buffer_size) 1018 if (ptr >= runtime->buffer_size)
974 ptr -= runtime->buffer_size; 1019 ptr -= runtime->buffer_size;
975 //printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate); 1020 /*
976 1021 printk(KERN_DEBUG "ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, "
1022 "buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n",
1023 ptr1, ptr2, ptr, (int)runtime->buffer_size,
1024 (int)runtime->period_size, (int)runtime->frame_bits,
1025 (int)runtime->rate);
1026 */
977 return ptr; 1027 return ptr;
978} 1028}
979 1029
@@ -995,8 +1045,13 @@ snd_ca0106_pcm_pointer_capture(struct snd_pcm_substream *substream)
995 ptr=ptr2; 1045 ptr=ptr2;
996 if (ptr >= runtime->buffer_size) 1046 if (ptr >= runtime->buffer_size)
997 ptr -= runtime->buffer_size; 1047 ptr -= runtime->buffer_size;
998 //printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate); 1048 /*
999 1049 printk(KERN_DEBUG "ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, "
1050 "buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n",
1051 ptr1, ptr2, ptr, (int)runtime->buffer_size,
1052 (int)runtime->period_size, (int)runtime->frame_bits,
1053 (int)runtime->rate);
1054 */
1000 return ptr; 1055 return ptr;
1001} 1056}
1002 1057
@@ -1181,8 +1236,12 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id)
1181 return IRQ_NONE; 1236 return IRQ_NONE;
1182 1237
1183 stat76 = snd_ca0106_ptr_read(chip, EXTENDED_INT, 0); 1238 stat76 = snd_ca0106_ptr_read(chip, EXTENDED_INT, 0);
1184 //snd_printk("interrupt status = 0x%08x, stat76=0x%08x\n", status, stat76); 1239 /*
1185 //snd_printk("ptr=0x%08x\n",snd_ca0106_ptr_read(chip, PLAYBACK_POINTER, 0)); 1240 snd_printk(KERN_DEBUG "interrupt status = 0x%08x, stat76=0x%08x\n",
1241 status, stat76);
1242 snd_printk(KERN_DEBUG "ptr=0x%08x\n",
1243 snd_ca0106_ptr_read(chip, PLAYBACK_POINTER, 0));
1244 */
1186 mask = 0x11; /* 0x1 for one half, 0x10 for the other half period. */ 1245 mask = 0x11; /* 0x1 for one half, 0x10 for the other half period. */
1187 for(i = 0; i < 4; i++) { 1246 for(i = 0; i < 4; i++) {
1188 pchannel = &(chip->playback_channels[i]); 1247 pchannel = &(chip->playback_channels[i]);
@@ -1470,7 +1529,7 @@ static void ca0106_init_chip(struct snd_ca0106 *chip, int resume)
1470 int size, n; 1529 int size, n;
1471 1530
1472 size = ARRAY_SIZE(i2c_adc_init); 1531 size = ARRAY_SIZE(i2c_adc_init);
1473 /* snd_printk("I2C:array size=0x%x\n", size); */ 1532 /* snd_printk(KERN_DEBUG "I2C:array size=0x%x\n", size); */
1474 for (n = 0; n < size; n++) 1533 for (n = 0; n < size; n++)
1475 snd_ca0106_i2c_write(chip, i2c_adc_init[n][0], 1534 snd_ca0106_i2c_write(chip, i2c_adc_init[n][0],
1476 i2c_adc_init[n][1]); 1535 i2c_adc_init[n][1]);
@@ -1707,9 +1766,9 @@ static int __devinit snd_ca0106_probe(struct pci_dev *pci,
1707 return -ENOENT; 1766 return -ENOENT;
1708 } 1767 }
1709 1768
1710 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 1769 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
1711 if (card == NULL) 1770 if (err < 0)
1712 return -ENOMEM; 1771 return err;
1713 1772
1714 err = snd_ca0106_create(dev, card, pci, &chip); 1773 err = snd_ca0106_create(dev, card, pci, &chip);
1715 if (err < 0) 1774 if (err < 0)
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 1a74ca62c314..c7899c32aba1 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -3272,9 +3272,9 @@ static int __devinit snd_cmipci_probe(struct pci_dev *pci,
3272 return -ENOENT; 3272 return -ENOENT;
3273 } 3273 }
3274 3274
3275 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 3275 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
3276 if (card == NULL) 3276 if (err < 0)
3277 return -ENOMEM; 3277 return err;
3278 3278
3279 switch (pci->device) { 3279 switch (pci->device) {
3280 case PCI_DEVICE_ID_CMEDIA_CM8738: 3280 case PCI_DEVICE_ID_CMEDIA_CM8738:
diff --git a/sound/pci/cs4281.c b/sound/pci/cs4281.c
index 192e7842e181..f6286f84a221 100644
--- a/sound/pci/cs4281.c
+++ b/sound/pci/cs4281.c
@@ -834,7 +834,11 @@ static snd_pcm_uframes_t snd_cs4281_pointer(struct snd_pcm_substream *substream)
834 struct cs4281_dma *dma = runtime->private_data; 834 struct cs4281_dma *dma = runtime->private_data;
835 struct cs4281 *chip = snd_pcm_substream_chip(substream); 835 struct cs4281 *chip = snd_pcm_substream_chip(substream);
836 836
837 // printk("DCC = 0x%x, buffer_size = 0x%x, jiffies = %li\n", snd_cs4281_peekBA0(chip, dma->regDCC), runtime->buffer_size, jiffies); 837 /*
838 printk(KERN_DEBUG "DCC = 0x%x, buffer_size = 0x%x, jiffies = %li\n",
839 snd_cs4281_peekBA0(chip, dma->regDCC), runtime->buffer_size,
840 jiffies);
841 */
838 return runtime->buffer_size - 842 return runtime->buffer_size -
839 snd_cs4281_peekBA0(chip, dma->regDCC) - 1; 843 snd_cs4281_peekBA0(chip, dma->regDCC) - 1;
840} 844}
@@ -1925,9 +1929,9 @@ static int __devinit snd_cs4281_probe(struct pci_dev *pci,
1925 return -ENOENT; 1929 return -ENOENT;
1926 } 1930 }
1927 1931
1928 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 1932 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
1929 if (card == NULL) 1933 if (err < 0)
1930 return -ENOMEM; 1934 return err;
1931 1935
1932 if ((err = snd_cs4281_create(card, pci, &chip, dual_codec[dev])) < 0) { 1936 if ((err = snd_cs4281_create(card, pci, &chip, dual_codec[dev])) < 0) {
1933 snd_card_free(card); 1937 snd_card_free(card);
diff --git a/sound/pci/cs46xx/cs46xx.c b/sound/pci/cs46xx/cs46xx.c
index e876b3263e46..c9b3e3d48cbc 100644
--- a/sound/pci/cs46xx/cs46xx.c
+++ b/sound/pci/cs46xx/cs46xx.c
@@ -88,9 +88,9 @@ static int __devinit snd_card_cs46xx_probe(struct pci_dev *pci,
88 return -ENOENT; 88 return -ENOENT;
89 } 89 }
90 90
91 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 91 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
92 if (card == NULL) 92 if (err < 0)
93 return -ENOMEM; 93 return err;
94 if ((err = snd_cs46xx_create(card, pci, 94 if ((err = snd_cs46xx_create(card, pci,
95 external_amp[dev], thinkpad[dev], 95 external_amp[dev], thinkpad[dev],
96 &chip)) < 0) { 96 &chip)) < 0) {
diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c
index 8ab07aa63652..1be96ead4244 100644
--- a/sound/pci/cs46xx/cs46xx_lib.c
+++ b/sound/pci/cs46xx/cs46xx_lib.c
@@ -194,7 +194,7 @@ static unsigned short snd_cs46xx_codec_read(struct snd_cs46xx *chip,
194 * ACSDA = Status Data Register = 474h 194 * ACSDA = Status Data Register = 474h
195 */ 195 */
196#if 0 196#if 0
197 printk("e) reg = 0x%x, val = 0x%x, BA0_ACCAD = 0x%x\n", reg, 197 printk(KERN_DEBUG "e) reg = 0x%x, val = 0x%x, BA0_ACCAD = 0x%x\n", reg,
198 snd_cs46xx_peekBA0(chip, BA0_ACSDA), 198 snd_cs46xx_peekBA0(chip, BA0_ACSDA),
199 snd_cs46xx_peekBA0(chip, BA0_ACCAD)); 199 snd_cs46xx_peekBA0(chip, BA0_ACCAD));
200#endif 200#endif
@@ -428,8 +428,8 @@ static int cs46xx_wait_for_fifo(struct snd_cs46xx * chip,int retry_timeout)
428 } 428 }
429 429
430 if(status & SERBST_WBSY) { 430 if(status & SERBST_WBSY) {
431 snd_printk( KERN_ERR "cs46xx: failure waiting for FIFO command to complete\n"); 431 snd_printk(KERN_ERR "cs46xx: failure waiting for "
432 432 "FIFO command to complete\n");
433 return -EINVAL; 433 return -EINVAL;
434 } 434 }
435 435
diff --git a/sound/pci/cs46xx/cs46xx_lib.h b/sound/pci/cs46xx/cs46xx_lib.h
index 018a7de56017..4eb55aa33612 100644
--- a/sound/pci/cs46xx/cs46xx_lib.h
+++ b/sound/pci/cs46xx/cs46xx_lib.h
@@ -62,7 +62,11 @@ static inline void snd_cs46xx_poke(struct snd_cs46xx *chip, unsigned long reg, u
62 unsigned int bank = reg >> 16; 62 unsigned int bank = reg >> 16;
63 unsigned int offset = reg & 0xffff; 63 unsigned int offset = reg & 0xffff;
64 64
65 /*if (bank == 0) printk("snd_cs46xx_poke: %04X - %08X\n",reg >> 2,val); */ 65 /*
66 if (bank == 0)
67 printk(KERN_DEBUG "snd_cs46xx_poke: %04X - %08X\n",
68 reg >> 2,val);
69 */
66 writel(val, chip->region.idx[bank+1].remap_addr + offset); 70 writel(val, chip->region.idx[bank+1].remap_addr + offset);
67} 71}
68 72
diff --git a/sound/pci/cs5530.c b/sound/pci/cs5530.c
index 6dea5b5cc774..dc464321d0f3 100644
--- a/sound/pci/cs5530.c
+++ b/sound/pci/cs5530.c
@@ -258,10 +258,10 @@ static int __devinit snd_cs5530_probe(struct pci_dev *pci,
258 return -ENOENT; 258 return -ENOENT;
259 } 259 }
260 260
261 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 261 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
262 262
263 if (card == NULL) 263 if (err < 0)
264 return -ENOMEM; 264 return err;
265 265
266 err = snd_cs5530_create(card, pci, &chip); 266 err = snd_cs5530_create(card, pci, &chip);
267 if (err < 0) { 267 if (err < 0) {
diff --git a/sound/pci/cs5535audio/cs5535audio.c b/sound/pci/cs5535audio/cs5535audio.c
index 826e6dec2e97..c89ed1f5bc2b 100644
--- a/sound/pci/cs5535audio/cs5535audio.c
+++ b/sound/pci/cs5535audio/cs5535audio.c
@@ -312,7 +312,7 @@ static int __devinit snd_cs5535audio_create(struct snd_card *card,
312 312
313 if (request_irq(pci->irq, snd_cs5535audio_interrupt, 313 if (request_irq(pci->irq, snd_cs5535audio_interrupt,
314 IRQF_SHARED, "CS5535 Audio", cs5535au)) { 314 IRQF_SHARED, "CS5535 Audio", cs5535au)) {
315 snd_printk("unable to grab IRQ %d\n", pci->irq); 315 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
316 err = -EBUSY; 316 err = -EBUSY;
317 goto sndfail; 317 goto sndfail;
318 } 318 }
@@ -353,9 +353,9 @@ static int __devinit snd_cs5535audio_probe(struct pci_dev *pci,
353 return -ENOENT; 353 return -ENOENT;
354 } 354 }
355 355
356 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 356 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
357 if (card == NULL) 357 if (err < 0)
358 return -ENOMEM; 358 return err;
359 359
360 if ((err = snd_cs5535audio_create(card, pci, &cs5535au)) < 0) 360 if ((err = snd_cs5535audio_create(card, pci, &cs5535au)) < 0)
361 goto probefail_out; 361 goto probefail_out;
diff --git a/sound/pci/echoaudio/Makefile b/sound/pci/echoaudio/Makefile
index 7b576aeb3f8d..1361de77e0cd 100644
--- a/sound/pci/echoaudio/Makefile
+++ b/sound/pci/echoaudio/Makefile
@@ -15,6 +15,8 @@ snd-echo3g-objs := echo3g.o
15snd-indigo-objs := indigo.o 15snd-indigo-objs := indigo.o
16snd-indigoio-objs := indigoio.o 16snd-indigoio-objs := indigoio.o
17snd-indigodj-objs := indigodj.o 17snd-indigodj-objs := indigodj.o
18snd-indigoiox-objs := indigoiox.o
19snd-indigodjx-objs := indigodjx.o
18 20
19obj-$(CONFIG_SND_DARLA20) += snd-darla20.o 21obj-$(CONFIG_SND_DARLA20) += snd-darla20.o
20obj-$(CONFIG_SND_GINA20) += snd-gina20.o 22obj-$(CONFIG_SND_GINA20) += snd-gina20.o
@@ -28,3 +30,5 @@ obj-$(CONFIG_SND_ECHO3G) += snd-echo3g.o
28obj-$(CONFIG_SND_INDIGO) += snd-indigo.o 30obj-$(CONFIG_SND_INDIGO) += snd-indigo.o
29obj-$(CONFIG_SND_INDIGOIO) += snd-indigoio.o 31obj-$(CONFIG_SND_INDIGOIO) += snd-indigoio.o
30obj-$(CONFIG_SND_INDIGODJ) += snd-indigodj.o 32obj-$(CONFIG_SND_INDIGODJ) += snd-indigodj.o
33obj-$(CONFIG_SND_INDIGOIOX) += snd-indigoiox.o
34obj-$(CONFIG_SND_INDIGODJX) += snd-indigodjx.o
diff --git a/sound/pci/echoaudio/echo3g_dsp.c b/sound/pci/echoaudio/echo3g_dsp.c
index 417e25add82b..57967e580571 100644
--- a/sound/pci/echoaudio/echo3g_dsp.c
+++ b/sound/pci/echoaudio/echo3g_dsp.c
@@ -56,7 +56,7 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
56 } 56 }
57 57
58 chip->comm_page->e3g_frq_register = 58 chip->comm_page->e3g_frq_register =
59 __constant_cpu_to_le32((E3G_MAGIC_NUMBER / 48000) - 2); 59 cpu_to_le32((E3G_MAGIC_NUMBER / 48000) - 2);
60 chip->device_id = device_id; 60 chip->device_id = device_id;
61 chip->subdevice_id = subdevice_id; 61 chip->subdevice_id = subdevice_id;
62 chip->bad_board = TRUE; 62 chip->bad_board = TRUE;
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index 8dbc5c4ba421..da2065cd2c0d 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -950,6 +950,8 @@ static int __devinit snd_echo_new_pcm(struct echoaudio *chip)
950 Control interface 950 Control interface
951******************************************************************************/ 951******************************************************************************/
952 952
953#ifndef ECHOCARD_HAS_VMIXER
954
953/******************* PCM output volume *******************/ 955/******************* PCM output volume *******************/
954static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol, 956static int snd_echo_output_gain_info(struct snd_kcontrol *kcontrol,
955 struct snd_ctl_elem_info *uinfo) 957 struct snd_ctl_elem_info *uinfo)
@@ -1001,18 +1003,6 @@ static int snd_echo_output_gain_put(struct snd_kcontrol *kcontrol,
1001 return changed; 1003 return changed;
1002} 1004}
1003 1005
1004#ifdef ECHOCARD_HAS_VMIXER
1005/* On Vmixer cards this one controls the line-out volume */
1006static struct snd_kcontrol_new snd_echo_line_output_gain __devinitdata = {
1007 .name = "Line Playback Volume",
1008 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1009 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,
1010 .info = snd_echo_output_gain_info,
1011 .get = snd_echo_output_gain_get,
1012 .put = snd_echo_output_gain_put,
1013 .tlv = {.p = db_scale_output_gain},
1014};
1015#else
1016static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata = { 1006static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata = {
1017 .name = "PCM Playback Volume", 1007 .name = "PCM Playback Volume",
1018 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1008 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -1022,6 +1012,7 @@ static struct snd_kcontrol_new snd_echo_pcm_output_gain __devinitdata = {
1022 .put = snd_echo_output_gain_put, 1012 .put = snd_echo_output_gain_put,
1023 .tlv = {.p = db_scale_output_gain}, 1013 .tlv = {.p = db_scale_output_gain},
1024}; 1014};
1015
1025#endif 1016#endif
1026 1017
1027 1018
@@ -1997,9 +1988,9 @@ static int __devinit snd_echo_probe(struct pci_dev *pci,
1997 1988
1998 DE_INIT(("Echoaudio driver starting...\n")); 1989 DE_INIT(("Echoaudio driver starting...\n"));
1999 i = 0; 1990 i = 0;
2000 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 1991 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2001 if (card == NULL) 1992 if (err < 0)
2002 return -ENOMEM; 1993 return err;
2003 1994
2004 snd_card_set_dev(card, &pci->dev); 1995 snd_card_set_dev(card, &pci->dev);
2005 1996
@@ -2037,8 +2028,6 @@ static int __devinit snd_echo_probe(struct pci_dev *pci,
2037 2028
2038#ifdef ECHOCARD_HAS_VMIXER 2029#ifdef ECHOCARD_HAS_VMIXER
2039 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip); 2030 snd_echo_vmixer.count = num_pipes_out(chip) * num_busses_out(chip);
2040 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_line_output_gain, chip))) < 0)
2041 goto ctl_error;
2042 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0) 2031 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_echo_vmixer, chip))) < 0)
2043 goto ctl_error; 2032 goto ctl_error;
2044#else 2033#else
diff --git a/sound/pci/echoaudio/echoaudio.h b/sound/pci/echoaudio/echoaudio.h
index 1c88e051abf2..f9490ae36c2e 100644
--- a/sound/pci/echoaudio/echoaudio.h
+++ b/sound/pci/echoaudio/echoaudio.h
@@ -189,6 +189,9 @@
189#define INDIGO 0x0090 189#define INDIGO 0x0090
190#define INDIGO_IO 0x00a0 190#define INDIGO_IO 0x00a0
191#define INDIGO_DJ 0x00b0 191#define INDIGO_DJ 0x00b0
192#define DC8 0x00c0
193#define INDIGO_IOX 0x00d0
194#define INDIGO_DJX 0x00e0
192#define ECHO3G 0x0100 195#define ECHO3G 0x0100
193 196
194 197
diff --git a/sound/pci/echoaudio/echoaudio_3g.c b/sound/pci/echoaudio/echoaudio_3g.c
index c3736bbd819e..e32a74897921 100644
--- a/sound/pci/echoaudio/echoaudio_3g.c
+++ b/sound/pci/echoaudio/echoaudio_3g.c
@@ -40,8 +40,7 @@ static int check_asic_status(struct echoaudio *chip)
40 if (wait_handshake(chip)) 40 if (wait_handshake(chip))
41 return -EIO; 41 return -EIO;
42 42
43 chip->comm_page->ext_box_status = 43 chip->comm_page->ext_box_status = cpu_to_le32(E3G_ASIC_NOT_LOADED);
44 __constant_cpu_to_le32(E3G_ASIC_NOT_LOADED);
45 chip->asic_loaded = FALSE; 44 chip->asic_loaded = FALSE;
46 clear_handshake(chip); 45 clear_handshake(chip);
47 send_vector(chip, DSP_VC_TEST_ASIC); 46 send_vector(chip, DSP_VC_TEST_ASIC);
diff --git a/sound/pci/echoaudio/echoaudio_dsp.c b/sound/pci/echoaudio/echoaudio_dsp.c
index be0e18192de3..4df51ef5e095 100644
--- a/sound/pci/echoaudio/echoaudio_dsp.c
+++ b/sound/pci/echoaudio/echoaudio_dsp.c
@@ -926,11 +926,11 @@ static int init_dsp_comm_page(struct echoaudio *chip)
926 926
927 /* Init the comm page */ 927 /* Init the comm page */
928 chip->comm_page->comm_size = 928 chip->comm_page->comm_size =
929 __constant_cpu_to_le32(sizeof(struct comm_page)); 929 cpu_to_le32(sizeof(struct comm_page));
930 chip->comm_page->handshake = 0xffffffff; 930 chip->comm_page->handshake = 0xffffffff;
931 chip->comm_page->midi_out_free_count = 931 chip->comm_page->midi_out_free_count =
932 __constant_cpu_to_le32(DSP_MIDI_OUT_FIFO_SIZE); 932 cpu_to_le32(DSP_MIDI_OUT_FIFO_SIZE);
933 chip->comm_page->sample_rate = __constant_cpu_to_le32(44100); 933 chip->comm_page->sample_rate = cpu_to_le32(44100);
934 chip->sample_rate = 44100; 934 chip->sample_rate = 44100;
935 935
936 /* Set line levels so we don't blast any inputs on startup */ 936 /* Set line levels so we don't blast any inputs on startup */
diff --git a/sound/pci/echoaudio/echoaudio_dsp.h b/sound/pci/echoaudio/echoaudio_dsp.h
index e352f3ae292c..cb7d75a0a503 100644
--- a/sound/pci/echoaudio/echoaudio_dsp.h
+++ b/sound/pci/echoaudio/echoaudio_dsp.h
@@ -576,8 +576,13 @@ SET_LAYLA24_FREQUENCY_REG command.
576#define E3G_ASIC_NOT_LOADED 0xffff 576#define E3G_ASIC_NOT_LOADED 0xffff
577#define E3G_BOX_TYPE_MASK 0xf0 577#define E3G_BOX_TYPE_MASK 0xf0
578 578
579#define EXT_3GBOX_NC 0x01 579/* Indigo express control register values */
580#define EXT_3GBOX_NOT_SET 0x02 580#define INDIGO_EXPRESS_32000 0x02
581#define INDIGO_EXPRESS_44100 0x01
582#define INDIGO_EXPRESS_48000 0x00
583#define INDIGO_EXPRESS_DOUBLE_SPEED 0x10
584#define INDIGO_EXPRESS_QUAD_SPEED 0x04
585#define INDIGO_EXPRESS_CLOCK_MASK 0x17
581 586
582 587
583/* 588/*
diff --git a/sound/pci/echoaudio/gina20_dsp.c b/sound/pci/echoaudio/gina20_dsp.c
index db6c952e9d7f..3f1e7475faea 100644
--- a/sound/pci/echoaudio/gina20_dsp.c
+++ b/sound/pci/echoaudio/gina20_dsp.c
@@ -208,10 +208,10 @@ static int set_professional_spdif(struct echoaudio *chip, char prof)
208 DE_ACT(("set_professional_spdif %d\n", prof)); 208 DE_ACT(("set_professional_spdif %d\n", prof));
209 if (prof) 209 if (prof)
210 chip->comm_page->flags |= 210 chip->comm_page->flags |=
211 __constant_cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF); 211 cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
212 else 212 else
213 chip->comm_page->flags &= 213 chip->comm_page->flags &=
214 ~__constant_cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF); 214 ~cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
215 chip->professional_spdif = prof; 215 chip->professional_spdif = prof;
216 return update_flags(chip); 216 return update_flags(chip);
217} 217}
diff --git a/sound/pci/echoaudio/indigo_dsp.c b/sound/pci/echoaudio/indigo_dsp.c
index f05e39f7aad9..0b2cd9c86277 100644
--- a/sound/pci/echoaudio/indigo_dsp.c
+++ b/sound/pci/echoaudio/indigo_dsp.c
@@ -63,18 +63,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
63 if ((err = init_line_levels(chip)) < 0) 63 if ((err = init_line_levels(chip)) < 0)
64 return err; 64 return err;
65 65
66 /* Default routing of the virtual channels: all vchannels are routed
67 to the stereo output */
68 set_vmixer_gain(chip, 0, 0, 0);
69 set_vmixer_gain(chip, 1, 1, 0);
70 set_vmixer_gain(chip, 0, 2, 0);
71 set_vmixer_gain(chip, 1, 3, 0);
72 set_vmixer_gain(chip, 0, 4, 0);
73 set_vmixer_gain(chip, 1, 5, 0);
74 set_vmixer_gain(chip, 0, 6, 0);
75 set_vmixer_gain(chip, 1, 7, 0);
76 err = update_vmixer_level(chip);
77
78 DE_INIT(("init_hw done\n")); 66 DE_INIT(("init_hw done\n"));
79 return err; 67 return err;
80} 68}
diff --git a/sound/pci/echoaudio/indigo_express_dsp.c b/sound/pci/echoaudio/indigo_express_dsp.c
new file mode 100644
index 000000000000..9ab625e15652
--- /dev/null
+++ b/sound/pci/echoaudio/indigo_express_dsp.c
@@ -0,0 +1,119 @@
1/************************************************************************
2
3This file is part of Echo Digital Audio's generic driver library.
4Copyright Echo Digital Audio Corporation (c) 1998 - 2005
5All rights reserved
6www.echoaudio.com
7
8This library is free software; you can redistribute it and/or
9modify it under the terms of the GNU Lesser General Public
10License as published by the Free Software Foundation; either
11version 2.1 of the License, or (at your option) any later version.
12
13This library is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public
19License along with this library; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22*************************************************************************
23
24 Translation from C++ and adaptation for use in ALSA-Driver
25 were made by Giuliano Pochini <pochini@shiny.it>
26
27*************************************************************************/
28
29static int set_sample_rate(struct echoaudio *chip, u32 rate)
30{
31 u32 clock, control_reg, old_control_reg;
32
33 if (wait_handshake(chip))
34 return -EIO;
35
36 old_control_reg = le32_to_cpu(chip->comm_page->control_register);
37 control_reg = old_control_reg & ~INDIGO_EXPRESS_CLOCK_MASK;
38
39 switch (rate) {
40 case 32000:
41 clock = INDIGO_EXPRESS_32000;
42 break;
43 case 44100:
44 clock = INDIGO_EXPRESS_44100;
45 break;
46 case 48000:
47 clock = INDIGO_EXPRESS_48000;
48 break;
49 case 64000:
50 clock = INDIGO_EXPRESS_32000|INDIGO_EXPRESS_DOUBLE_SPEED;
51 break;
52 case 88200:
53 clock = INDIGO_EXPRESS_44100|INDIGO_EXPRESS_DOUBLE_SPEED;
54 break;
55 case 96000:
56 clock = INDIGO_EXPRESS_48000|INDIGO_EXPRESS_DOUBLE_SPEED;
57 break;
58 default:
59 return -EINVAL;
60 }
61
62 control_reg |= clock;
63 if (control_reg != old_control_reg) {
64 chip->comm_page->control_register = cpu_to_le32(control_reg);
65 chip->sample_rate = rate;
66 clear_handshake(chip);
67 return send_vector(chip, DSP_VC_UPDATE_CLOCKS);
68 }
69 return 0;
70}
71
72
73
74/* This function routes the sound from a virtual channel to a real output */
75static int set_vmixer_gain(struct echoaudio *chip, u16 output, u16 pipe,
76 int gain)
77{
78 int index;
79
80 if (snd_BUG_ON(pipe >= num_pipes_out(chip) ||
81 output >= num_busses_out(chip)))
82 return -EINVAL;
83
84 if (wait_handshake(chip))
85 return -EIO;
86
87 chip->vmixer_gain[output][pipe] = gain;
88 index = output * num_pipes_out(chip) + pipe;
89 chip->comm_page->vmixer[index] = gain;
90
91 DE_ACT(("set_vmixer_gain: pipe %d, out %d = %d\n", pipe, output, gain));
92 return 0;
93}
94
95
96
97/* Tell the DSP to read and update virtual mixer levels in comm page. */
98static int update_vmixer_level(struct echoaudio *chip)
99{
100 if (wait_handshake(chip))
101 return -EIO;
102 clear_handshake(chip);
103 return send_vector(chip, DSP_VC_SET_VMIXER_GAIN);
104}
105
106
107
108static u32 detect_input_clocks(const struct echoaudio *chip)
109{
110 return ECHO_CLOCK_BIT_INTERNAL;
111}
112
113
114
115/* The IndigoIO has no ASIC. Just do nothing */
116static int load_asic(struct echoaudio *chip)
117{
118 return 0;
119}
diff --git a/sound/pci/echoaudio/indigodj_dsp.c b/sound/pci/echoaudio/indigodj_dsp.c
index 90730a5ecb42..08392916691e 100644
--- a/sound/pci/echoaudio/indigodj_dsp.c
+++ b/sound/pci/echoaudio/indigodj_dsp.c
@@ -63,18 +63,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
63 if ((err = init_line_levels(chip)) < 0) 63 if ((err = init_line_levels(chip)) < 0)
64 return err; 64 return err;
65 65
66 /* Default routing of the virtual channels: vchannels 0-3 and
67 vchannels 4-7 are routed to real channels 0-4 */
68 set_vmixer_gain(chip, 0, 0, 0);
69 set_vmixer_gain(chip, 1, 1, 0);
70 set_vmixer_gain(chip, 2, 2, 0);
71 set_vmixer_gain(chip, 3, 3, 0);
72 set_vmixer_gain(chip, 0, 4, 0);
73 set_vmixer_gain(chip, 1, 5, 0);
74 set_vmixer_gain(chip, 2, 6, 0);
75 set_vmixer_gain(chip, 3, 7, 0);
76 err = update_vmixer_level(chip);
77
78 DE_INIT(("init_hw done\n")); 66 DE_INIT(("init_hw done\n"));
79 return err; 67 return err;
80} 68}
diff --git a/sound/pci/echoaudio/indigodjx.c b/sound/pci/echoaudio/indigodjx.c
new file mode 100644
index 000000000000..3482ef69f491
--- /dev/null
+++ b/sound/pci/echoaudio/indigodjx.c
@@ -0,0 +1,107 @@
1/*
2 * ALSA driver for Echoaudio soundcards.
3 * Copyright (C) 2009 Giuliano Pochini <pochini@shiny.it>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#define INDIGO_FAMILY
20#define ECHOCARD_INDIGO_DJX
21#define ECHOCARD_NAME "Indigo DJx"
22#define ECHOCARD_HAS_SUPER_INTERLEAVE
23#define ECHOCARD_HAS_VMIXER
24#define ECHOCARD_HAS_STEREO_BIG_ENDIAN32
25
26/* Pipe indexes */
27#define PX_ANALOG_OUT 0 /* 8 */
28#define PX_DIGITAL_OUT 8 /* 0 */
29#define PX_ANALOG_IN 8 /* 0 */
30#define PX_DIGITAL_IN 8 /* 0 */
31#define PX_NUM 8
32
33/* Bus indexes */
34#define BX_ANALOG_OUT 0 /* 4 */
35#define BX_DIGITAL_OUT 4 /* 0 */
36#define BX_ANALOG_IN 4 /* 0 */
37#define BX_DIGITAL_IN 4 /* 0 */
38#define BX_NUM 4
39
40
41#include <linux/delay.h>
42#include <linux/init.h>
43#include <linux/interrupt.h>
44#include <linux/pci.h>
45#include <linux/slab.h>
46#include <linux/moduleparam.h>
47#include <linux/firmware.h>
48#include <linux/io.h>
49#include <sound/core.h>
50#include <sound/info.h>
51#include <sound/control.h>
52#include <sound/tlv.h>
53#include <sound/pcm.h>
54#include <sound/pcm_params.h>
55#include <sound/asoundef.h>
56#include <sound/initval.h>
57#include <asm/atomic.h>
58#include "echoaudio.h"
59
60MODULE_FIRMWARE("ea/loader_dsp.fw");
61MODULE_FIRMWARE("ea/indigo_djx_dsp.fw");
62
63#define FW_361_LOADER 0
64#define FW_INDIGO_DJX_DSP 1
65
66static const struct firmware card_fw[] = {
67 {0, "loader_dsp.fw"},
68 {0, "indigo_djx_dsp.fw"}
69};
70
71static struct pci_device_id snd_echo_ids[] = {
72 {0x1057, 0x3410, 0xECC0, 0x00E0, 0, 0, 0}, /* Indigo DJx*/
73 {0,}
74};
75
76static struct snd_pcm_hardware pcm_hardware_skel = {
77 .info = SNDRV_PCM_INFO_MMAP |
78 SNDRV_PCM_INFO_INTERLEAVED |
79 SNDRV_PCM_INFO_BLOCK_TRANSFER |
80 SNDRV_PCM_INFO_MMAP_VALID |
81 SNDRV_PCM_INFO_PAUSE |
82 SNDRV_PCM_INFO_SYNC_START,
83 .formats = SNDRV_PCM_FMTBIT_U8 |
84 SNDRV_PCM_FMTBIT_S16_LE |
85 SNDRV_PCM_FMTBIT_S24_3LE |
86 SNDRV_PCM_FMTBIT_S32_LE |
87 SNDRV_PCM_FMTBIT_S32_BE,
88 .rates = SNDRV_PCM_RATE_32000 |
89 SNDRV_PCM_RATE_44100 |
90 SNDRV_PCM_RATE_48000 |
91 SNDRV_PCM_RATE_88200 |
92 SNDRV_PCM_RATE_96000,
93 .rate_min = 32000,
94 .rate_max = 96000,
95 .channels_min = 1,
96 .channels_max = 4,
97 .buffer_bytes_max = 262144,
98 .period_bytes_min = 32,
99 .period_bytes_max = 131072,
100 .periods_min = 2,
101 .periods_max = 220,
102};
103
104#include "indigodjx_dsp.c"
105#include "indigo_express_dsp.c"
106#include "echoaudio_dsp.c"
107#include "echoaudio.c"
diff --git a/sound/pci/echoaudio/indigodjx_dsp.c b/sound/pci/echoaudio/indigodjx_dsp.c
new file mode 100644
index 000000000000..f591fc2ed960
--- /dev/null
+++ b/sound/pci/echoaudio/indigodjx_dsp.c
@@ -0,0 +1,68 @@
1/************************************************************************
2
3This file is part of Echo Digital Audio's generic driver library.
4Copyright Echo Digital Audio Corporation (c) 1998 - 2005
5All rights reserved
6www.echoaudio.com
7
8This library is free software; you can redistribute it and/or
9modify it under the terms of the GNU Lesser General Public
10License as published by the Free Software Foundation; either
11version 2.1 of the License, or (at your option) any later version.
12
13This library is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public
19License along with this library; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22*************************************************************************
23
24 Translation from C++ and adaptation for use in ALSA-Driver
25 were made by Giuliano Pochini <pochini@shiny.it>
26
27*************************************************************************/
28
29static int update_vmixer_level(struct echoaudio *chip);
30static int set_vmixer_gain(struct echoaudio *chip, u16 output,
31 u16 pipe, int gain);
32
33
34static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
35{
36 int err;
37
38 DE_INIT(("init_hw() - Indigo DJx\n"));
39 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_DJX))
40 return -ENODEV;
41
42 err = init_dsp_comm_page(chip);
43 if (err < 0) {
44 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
45 return err;
46 }
47
48 chip->device_id = device_id;
49 chip->subdevice_id = subdevice_id;
50 chip->bad_board = TRUE;
51 chip->dsp_code_to_load = &card_fw[FW_INDIGO_DJX_DSP];
52 /* Since this card has no ASIC, mark it as loaded so everything
53 works OK */
54 chip->asic_loaded = TRUE;
55 chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL;
56
57 err = load_firmware(chip);
58 if (err < 0)
59 return err;
60 chip->bad_board = FALSE;
61
62 err = init_line_levels(chip);
63 if (err < 0)
64 return err;
65
66 DE_INIT(("init_hw done\n"));
67 return err;
68}
diff --git a/sound/pci/echoaudio/indigoio_dsp.c b/sound/pci/echoaudio/indigoio_dsp.c
index a7e09ec21079..0604c8a85223 100644
--- a/sound/pci/echoaudio/indigoio_dsp.c
+++ b/sound/pci/echoaudio/indigoio_dsp.c
@@ -63,18 +63,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
63 if ((err = init_line_levels(chip)) < 0) 63 if ((err = init_line_levels(chip)) < 0)
64 return err; 64 return err;
65 65
66 /* Default routing of the virtual channels: all vchannels are routed
67 to the stereo output */
68 set_vmixer_gain(chip, 0, 0, 0);
69 set_vmixer_gain(chip, 1, 1, 0);
70 set_vmixer_gain(chip, 0, 2, 0);
71 set_vmixer_gain(chip, 1, 3, 0);
72 set_vmixer_gain(chip, 0, 4, 0);
73 set_vmixer_gain(chip, 1, 5, 0);
74 set_vmixer_gain(chip, 0, 6, 0);
75 set_vmixer_gain(chip, 1, 7, 0);
76 err = update_vmixer_level(chip);
77
78 DE_INIT(("init_hw done\n")); 66 DE_INIT(("init_hw done\n"));
79 return err; 67 return err;
80} 68}
diff --git a/sound/pci/echoaudio/indigoiox.c b/sound/pci/echoaudio/indigoiox.c
new file mode 100644
index 000000000000..aebee27a40ff
--- /dev/null
+++ b/sound/pci/echoaudio/indigoiox.c
@@ -0,0 +1,109 @@
1/*
2 * ALSA driver for Echoaudio soundcards.
3 * Copyright (C) 2009 Giuliano Pochini <pochini@shiny.it>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#define INDIGO_FAMILY
20#define ECHOCARD_INDIGO_IOX
21#define ECHOCARD_NAME "Indigo IOx"
22#define ECHOCARD_HAS_MONITOR
23#define ECHOCARD_HAS_SUPER_INTERLEAVE
24#define ECHOCARD_HAS_VMIXER
25#define ECHOCARD_HAS_STEREO_BIG_ENDIAN32
26
27/* Pipe indexes */
28#define PX_ANALOG_OUT 0 /* 8 */
29#define PX_DIGITAL_OUT 8 /* 0 */
30#define PX_ANALOG_IN 8 /* 2 */
31#define PX_DIGITAL_IN 10 /* 0 */
32#define PX_NUM 10
33
34/* Bus indexes */
35#define BX_ANALOG_OUT 0 /* 2 */
36#define BX_DIGITAL_OUT 2 /* 0 */
37#define BX_ANALOG_IN 2 /* 2 */
38#define BX_DIGITAL_IN 4 /* 0 */
39#define BX_NUM 4
40
41
42#include <linux/delay.h>
43#include <linux/init.h>
44#include <linux/interrupt.h>
45#include <linux/pci.h>
46#include <linux/slab.h>
47#include <linux/moduleparam.h>
48#include <linux/firmware.h>
49#include <linux/io.h>
50#include <sound/core.h>
51#include <sound/info.h>
52#include <sound/control.h>
53#include <sound/tlv.h>
54#include <sound/pcm.h>
55#include <sound/pcm_params.h>
56#include <sound/asoundef.h>
57#include <sound/initval.h>
58#include <asm/atomic.h>
59#include "echoaudio.h"
60
61MODULE_FIRMWARE("ea/loader_dsp.fw");
62MODULE_FIRMWARE("ea/indigo_iox_dsp.fw");
63
64#define FW_361_LOADER 0
65#define FW_INDIGO_IOX_DSP 1
66
67static const struct firmware card_fw[] = {
68 {0, "loader_dsp.fw"},
69 {0, "indigo_iox_dsp.fw"}
70};
71
72static struct pci_device_id snd_echo_ids[] = {
73 {0x1057, 0x3410, 0xECC0, 0x00D0, 0, 0, 0}, /* Indigo IOx */
74 {0,}
75};
76
77static struct snd_pcm_hardware pcm_hardware_skel = {
78 .info = SNDRV_PCM_INFO_MMAP |
79 SNDRV_PCM_INFO_INTERLEAVED |
80 SNDRV_PCM_INFO_BLOCK_TRANSFER |
81 SNDRV_PCM_INFO_MMAP_VALID |
82 SNDRV_PCM_INFO_PAUSE |
83 SNDRV_PCM_INFO_SYNC_START,
84 .formats = SNDRV_PCM_FMTBIT_U8 |
85 SNDRV_PCM_FMTBIT_S16_LE |
86 SNDRV_PCM_FMTBIT_S24_3LE |
87 SNDRV_PCM_FMTBIT_S32_LE |
88 SNDRV_PCM_FMTBIT_S32_BE,
89 .rates = SNDRV_PCM_RATE_32000 |
90 SNDRV_PCM_RATE_44100 |
91 SNDRV_PCM_RATE_48000 |
92 SNDRV_PCM_RATE_88200 |
93 SNDRV_PCM_RATE_96000,
94 .rate_min = 32000,
95 .rate_max = 96000,
96 .channels_min = 1,
97 .channels_max = 8,
98 .buffer_bytes_max = 262144,
99 .period_bytes_min = 32,
100 .period_bytes_max = 131072,
101 .periods_min = 2,
102 .periods_max = 220,
103};
104
105#include "indigoiox_dsp.c"
106#include "indigo_express_dsp.c"
107#include "echoaudio_dsp.c"
108#include "echoaudio.c"
109
diff --git a/sound/pci/echoaudio/indigoiox_dsp.c b/sound/pci/echoaudio/indigoiox_dsp.c
new file mode 100644
index 000000000000..f357521c79e6
--- /dev/null
+++ b/sound/pci/echoaudio/indigoiox_dsp.c
@@ -0,0 +1,68 @@
1/************************************************************************
2
3This file is part of Echo Digital Audio's generic driver library.
4Copyright Echo Digital Audio Corporation (c) 1998 - 2005
5All rights reserved
6www.echoaudio.com
7
8This library is free software; you can redistribute it and/or
9modify it under the terms of the GNU Lesser General Public
10License as published by the Free Software Foundation; either
11version 2.1 of the License, or (at your option) any later version.
12
13This library is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16Lesser General Public License for more details.
17
18You should have received a copy of the GNU Lesser General Public
19License along with this library; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
22*************************************************************************
23
24 Translation from C++ and adaptation for use in ALSA-Driver
25 were made by Giuliano Pochini <pochini@shiny.it>
26
27*************************************************************************/
28
29static int update_vmixer_level(struct echoaudio *chip);
30static int set_vmixer_gain(struct echoaudio *chip, u16 output,
31 u16 pipe, int gain);
32
33
34static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
35{
36 int err;
37
38 DE_INIT(("init_hw() - Indigo IOx\n"));
39 if (snd_BUG_ON((subdevice_id & 0xfff0) != INDIGO_IOX))
40 return -ENODEV;
41
42 err = init_dsp_comm_page(chip);
43 if (err < 0) {
44 DE_INIT(("init_hw - could not initialize DSP comm page\n"));
45 return err;
46 }
47
48 chip->device_id = device_id;
49 chip->subdevice_id = subdevice_id;
50 chip->bad_board = TRUE;
51 chip->dsp_code_to_load = &card_fw[FW_INDIGO_IOX_DSP];
52 /* Since this card has no ASIC, mark it as loaded so everything
53 works OK */
54 chip->asic_loaded = TRUE;
55 chip->input_clock_types = ECHO_CLOCK_BIT_INTERNAL;
56
57 err = load_firmware(chip);
58 if (err < 0)
59 return err;
60 chip->bad_board = FALSE;
61
62 err = init_line_levels(chip);
63 if (err < 0)
64 return err;
65
66 DE_INIT(("init_hw done\n"));
67 return err;
68}
diff --git a/sound/pci/echoaudio/layla20_dsp.c b/sound/pci/echoaudio/layla20_dsp.c
index ede75c6ca0fb..83750e9fd7b4 100644
--- a/sound/pci/echoaudio/layla20_dsp.c
+++ b/sound/pci/echoaudio/layla20_dsp.c
@@ -284,10 +284,10 @@ static int set_professional_spdif(struct echoaudio *chip, char prof)
284 DE_ACT(("set_professional_spdif %d\n", prof)); 284 DE_ACT(("set_professional_spdif %d\n", prof));
285 if (prof) 285 if (prof)
286 chip->comm_page->flags |= 286 chip->comm_page->flags |=
287 __constant_cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF); 287 cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
288 else 288 else
289 chip->comm_page->flags &= 289 chip->comm_page->flags &=
290 ~__constant_cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF); 290 ~cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
291 chip->professional_spdif = prof; 291 chip->professional_spdif = prof;
292 return update_flags(chip); 292 return update_flags(chip);
293} 293}
diff --git a/sound/pci/echoaudio/mia_dsp.c b/sound/pci/echoaudio/mia_dsp.c
index 227386602f9b..551405114cbc 100644
--- a/sound/pci/echoaudio/mia_dsp.c
+++ b/sound/pci/echoaudio/mia_dsp.c
@@ -69,18 +69,6 @@ static int init_hw(struct echoaudio *chip, u16 device_id, u16 subdevice_id)
69 if ((err = init_line_levels(chip))) 69 if ((err = init_line_levels(chip)))
70 return err; 70 return err;
71 71
72 /* Default routing of the virtual channels: vchannels 0-3 go to analog
73 outputs and vchannels 4-7 go to S/PDIF outputs */
74 set_vmixer_gain(chip, 0, 0, 0);
75 set_vmixer_gain(chip, 1, 1, 0);
76 set_vmixer_gain(chip, 0, 2, 0);
77 set_vmixer_gain(chip, 1, 3, 0);
78 set_vmixer_gain(chip, 2, 4, 0);
79 set_vmixer_gain(chip, 3, 5, 0);
80 set_vmixer_gain(chip, 2, 6, 0);
81 set_vmixer_gain(chip, 3, 7, 0);
82 err = update_vmixer_level(chip);
83
84 DE_INIT(("init_hw done\n")); 72 DE_INIT(("init_hw done\n"));
85 return err; 73 return err;
86} 74}
@@ -222,10 +210,10 @@ static int set_professional_spdif(struct echoaudio *chip, char prof)
222 DE_ACT(("set_professional_spdif %d\n", prof)); 210 DE_ACT(("set_professional_spdif %d\n", prof));
223 if (prof) 211 if (prof)
224 chip->comm_page->flags |= 212 chip->comm_page->flags |=
225 __constant_cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF); 213 cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
226 else 214 else
227 chip->comm_page->flags &= 215 chip->comm_page->flags &=
228 ~__constant_cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF); 216 ~cpu_to_le32(DSP_FLAG_PROFESSIONAL_SPDIF);
229 chip->professional_spdif = prof; 217 chip->professional_spdif = prof;
230 return update_flags(chip); 218 return update_flags(chip);
231} 219}
diff --git a/sound/pci/echoaudio/midi.c b/sound/pci/echoaudio/midi.c
index 77bf2a83d997..a953d142cb4b 100644
--- a/sound/pci/echoaudio/midi.c
+++ b/sound/pci/echoaudio/midi.c
@@ -44,10 +44,10 @@ static int enable_midi_input(struct echoaudio *chip, char enable)
44 if (enable) { 44 if (enable) {
45 chip->mtc_state = MIDI_IN_STATE_NORMAL; 45 chip->mtc_state = MIDI_IN_STATE_NORMAL;
46 chip->comm_page->flags |= 46 chip->comm_page->flags |=
47 __constant_cpu_to_le32(DSP_FLAG_MIDI_INPUT); 47 cpu_to_le32(DSP_FLAG_MIDI_INPUT);
48 } else 48 } else
49 chip->comm_page->flags &= 49 chip->comm_page->flags &=
50 ~__constant_cpu_to_le32(DSP_FLAG_MIDI_INPUT); 50 ~cpu_to_le32(DSP_FLAG_MIDI_INPUT);
51 51
52 clear_handshake(chip); 52 clear_handshake(chip);
53 return send_vector(chip, DSP_VC_UPDATE_FLAGS); 53 return send_vector(chip, DSP_VC_UPDATE_FLAGS);
diff --git a/sound/pci/emu10k1/emu10k1.c b/sound/pci/emu10k1/emu10k1.c
index 8354c1a83312..c7f3b994101c 100644
--- a/sound/pci/emu10k1/emu10k1.c
+++ b/sound/pci/emu10k1/emu10k1.c
@@ -114,9 +114,9 @@ static int __devinit snd_card_emu10k1_probe(struct pci_dev *pci,
114 return -ENOENT; 114 return -ENOENT;
115 } 115 }
116 116
117 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 117 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
118 if (card == NULL) 118 if (err < 0)
119 return -ENOMEM; 119 return err;
120 if (max_buffer_size[dev] < 32) 120 if (max_buffer_size[dev] < 32)
121 max_buffer_size[dev] = 32; 121 max_buffer_size[dev] = 32;
122 else if (max_buffer_size[dev] > 1024) 122 else if (max_buffer_size[dev] > 1024)
diff --git a/sound/pci/emu10k1/emu10k1_callback.c b/sound/pci/emu10k1/emu10k1_callback.c
index 0e649dcdbf64..7ef949d99a50 100644
--- a/sound/pci/emu10k1/emu10k1_callback.c
+++ b/sound/pci/emu10k1/emu10k1_callback.c
@@ -103,7 +103,10 @@ snd_emu10k1_synth_get_voice(struct snd_emu10k1 *hw)
103 int ch; 103 int ch;
104 vp = &emu->voices[best[i].voice]; 104 vp = &emu->voices[best[i].voice];
105 if ((ch = vp->ch) < 0) { 105 if ((ch = vp->ch) < 0) {
106 //printk("synth_get_voice: ch < 0 (%d) ??", i); 106 /*
107 printk(KERN_WARNING
108 "synth_get_voice: ch < 0 (%d) ??", i);
109 */
107 continue; 110 continue;
108 } 111 }
109 vp->emu->num_voices--; 112 vp->emu->num_voices--;
@@ -335,7 +338,7 @@ start_voice(struct snd_emux_voice *vp)
335 return -EINVAL; 338 return -EINVAL;
336 emem->map_locked++; 339 emem->map_locked++;
337 if (snd_emu10k1_memblk_map(hw, emem) < 0) { 340 if (snd_emu10k1_memblk_map(hw, emem) < 0) {
338 // printk("emu: cannot map!\n"); 341 /* printk(KERN_ERR "emu: cannot map!\n"); */
339 return -ENOMEM; 342 return -ENOMEM;
340 } 343 }
341 mapped_offset = snd_emu10k1_memblk_offset(emem) >> 1; 344 mapped_offset = snd_emu10k1_memblk_offset(emem) >> 1;
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 101a1c13a20d..f18bd6207c50 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -711,8 +711,7 @@ static int snd_emu1010_load_firmware(struct snd_emu10k1 *emu, const char *filena
711static int emu1010_firmware_thread(void *data) 711static int emu1010_firmware_thread(void *data)
712{ 712{
713 struct snd_emu10k1 *emu = data; 713 struct snd_emu10k1 *emu = data;
714 int tmp, tmp2; 714 u32 tmp, tmp2, reg;
715 int reg;
716 int err; 715 int err;
717 716
718 for (;;) { 717 for (;;) {
@@ -758,7 +757,8 @@ static int emu1010_firmware_thread(void *data)
758 snd_printk(KERN_INFO "emu1010: Audio Dock Firmware loaded\n"); 757 snd_printk(KERN_INFO "emu1010: Audio Dock Firmware loaded\n");
759 snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp); 758 snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp);
760 snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2); 759 snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2);
761 snd_printk("Audio Dock ver:%d.%d\n", tmp, tmp2); 760 snd_printk(KERN_INFO "Audio Dock ver: %u.%u\n",
761 tmp, tmp2);
762 /* Sync clocking between 1010 and Dock */ 762 /* Sync clocking between 1010 and Dock */
763 /* Allow DLL to settle */ 763 /* Allow DLL to settle */
764 msleep(10); 764 msleep(10);
@@ -804,8 +804,7 @@ static int emu1010_firmware_thread(void *data)
804static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu) 804static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
805{ 805{
806 unsigned int i; 806 unsigned int i;
807 int tmp, tmp2; 807 u32 tmp, tmp2, reg;
808 int reg;
809 int err; 808 int err;
810 const char *filename = NULL; 809 const char *filename = NULL;
811 810
@@ -887,7 +886,7 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
887 snd_printk(KERN_INFO "emu1010: Hana Firmware loaded\n"); 886 snd_printk(KERN_INFO "emu1010: Hana Firmware loaded\n");
888 snd_emu1010_fpga_read(emu, EMU_HANA_MAJOR_REV, &tmp); 887 snd_emu1010_fpga_read(emu, EMU_HANA_MAJOR_REV, &tmp);
889 snd_emu1010_fpga_read(emu, EMU_HANA_MINOR_REV, &tmp2); 888 snd_emu1010_fpga_read(emu, EMU_HANA_MINOR_REV, &tmp2);
890 snd_printk("emu1010: Hana version: %d.%d\n", tmp, tmp2); 889 snd_printk(KERN_INFO "emu1010: Hana version: %u.%u\n", tmp, tmp2);
891 /* Enable 48Volt power to Audio Dock */ 890 /* Enable 48Volt power to Audio Dock */
892 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, EMU_HANA_DOCK_PWR_ON); 891 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, EMU_HANA_DOCK_PWR_ON);
893 892
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index 5ff4dbb62dad..31542adc6b7e 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -1544,9 +1544,9 @@ static int __devinit snd_emu10k1x_probe(struct pci_dev *pci,
1544 return -ENOENT; 1544 return -ENOENT;
1545 } 1545 }
1546 1546
1547 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 1547 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
1548 if (card == NULL) 1548 if (err < 0)
1549 return -ENOMEM; 1549 return err;
1550 1550
1551 if ((err = snd_emu10k1x_create(card, pci, &chip)) < 0) { 1551 if ((err = snd_emu10k1x_create(card, pci, &chip)) < 0) {
1552 snd_card_free(card); 1552 snd_card_free(card);
diff --git a/sound/pci/emu10k1/emufx.c b/sound/pci/emu10k1/emufx.c
index 7dba08f0ab8e..191e1cd9997d 100644
--- a/sound/pci/emu10k1/emufx.c
+++ b/sound/pci/emu10k1/emufx.c
@@ -1519,7 +1519,7 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))
1519 /* A_PUT_STEREO_OUTPUT(A_EXTOUT_FRONT_L, A_EXTOUT_FRONT_R, playback + SND_EMU10K1_PLAYBACK_CHANNELS); */ 1519 /* A_PUT_STEREO_OUTPUT(A_EXTOUT_FRONT_L, A_EXTOUT_FRONT_R, playback + SND_EMU10K1_PLAYBACK_CHANNELS); */
1520 if (emu->card_capabilities->emu_model) { 1520 if (emu->card_capabilities->emu_model) {
1521 /* EMU1010 Outputs from PCM Front, Rear, Center, LFE, Side */ 1521 /* EMU1010 Outputs from PCM Front, Rear, Center, LFE, Side */
1522 snd_printk("EMU outputs on\n"); 1522 snd_printk(KERN_INFO "EMU outputs on\n");
1523 for (z = 0; z < 8; z++) { 1523 for (z = 0; z < 8; z++) {
1524 if (emu->card_capabilities->ca0108_chip) { 1524 if (emu->card_capabilities->ca0108_chip) {
1525 A_OP(icode, &ptr, iACC3, A3_EMU32OUT(z), A_GPR(playback + SND_EMU10K1_PLAYBACK_CHANNELS + z), A_C_00000000, A_C_00000000); 1525 A_OP(icode, &ptr, iACC3, A3_EMU32OUT(z), A_GPR(playback + SND_EMU10K1_PLAYBACK_CHANNELS + z), A_C_00000000, A_C_00000000);
@@ -1567,7 +1567,7 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))
1567 1567
1568 if (emu->card_capabilities->emu_model) { 1568 if (emu->card_capabilities->emu_model) {
1569 if (emu->card_capabilities->ca0108_chip) { 1569 if (emu->card_capabilities->ca0108_chip) {
1570 snd_printk("EMU2 inputs on\n"); 1570 snd_printk(KERN_INFO "EMU2 inputs on\n");
1571 for (z = 0; z < 0x10; z++) { 1571 for (z = 0; z < 0x10; z++) {
1572 snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp, 1572 snd_emu10k1_audigy_dsp_convert_32_to_2x16( icode, &ptr, tmp,
1573 bit_shifter16, 1573 bit_shifter16,
@@ -1575,10 +1575,13 @@ A_OP(icode, &ptr, iMAC0, A_GPR(var), A_GPR(var), A_GPR(vol), A_EXTIN(input))
1575 A_FXBUS2(z*2) ); 1575 A_FXBUS2(z*2) );
1576 } 1576 }
1577 } else { 1577 } else {
1578 snd_printk("EMU inputs on\n"); 1578 snd_printk(KERN_INFO "EMU inputs on\n");
1579 /* Capture 16 (originally 8) channels of S32_LE sound */ 1579 /* Capture 16 (originally 8) channels of S32_LE sound */
1580 1580
1581 /* printk("emufx.c: gpr=0x%x, tmp=0x%x\n",gpr, tmp); */ 1581 /*
1582 printk(KERN_DEBUG "emufx.c: gpr=0x%x, tmp=0x%x\n",
1583 gpr, tmp);
1584 */
1582 /* For the EMU1010: How to get 32bit values from the DSP. High 16bits into L, low 16bits into R. */ 1585 /* For the EMU1010: How to get 32bit values from the DSP. High 16bits into L, low 16bits into R. */
1583 /* A_P16VIN(0) is delayed by one sample, 1586 /* A_P16VIN(0) is delayed by one sample,
1584 * so all other A_P16VIN channels will need to also be delayed 1587 * so all other A_P16VIN channels will need to also be delayed
diff --git a/sound/pci/emu10k1/emupcm.c b/sound/pci/emu10k1/emupcm.c
index cf9276ddad42..78f62fd404c2 100644
--- a/sound/pci/emu10k1/emupcm.c
+++ b/sound/pci/emu10k1/emupcm.c
@@ -44,7 +44,7 @@ static void snd_emu10k1_pcm_interrupt(struct snd_emu10k1 *emu,
44 if (epcm->substream == NULL) 44 if (epcm->substream == NULL)
45 return; 45 return;
46#if 0 46#if 0
47 printk("IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n", 47 printk(KERN_DEBUG "IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
48 epcm->substream->runtime->hw->pointer(emu, epcm->substream), 48 epcm->substream->runtime->hw->pointer(emu, epcm->substream),
49 snd_pcm_lib_period_bytes(epcm->substream), 49 snd_pcm_lib_period_bytes(epcm->substream),
50 snd_pcm_lib_buffer_bytes(epcm->substream)); 50 snd_pcm_lib_buffer_bytes(epcm->substream));
@@ -146,7 +146,11 @@ static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm * epcm, int voic
146 1, 146 1,
147 &epcm->extra); 147 &epcm->extra);
148 if (err < 0) { 148 if (err < 0) {
149 /* printk("pcm_channel_alloc: failed extra: voices=%d, frame=%d\n", voices, frame); */ 149 /*
150 printk(KERN_DEBUG "pcm_channel_alloc: "
151 "failed extra: voices=%d, frame=%d\n",
152 voices, frame);
153 */
150 for (i = 0; i < voices; i++) { 154 for (i = 0; i < voices; i++) {
151 snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]); 155 snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
152 epcm->voices[i] = NULL; 156 epcm->voices[i] = NULL;
@@ -737,7 +741,10 @@ static int snd_emu10k1_playback_trigger(struct snd_pcm_substream *substream,
737 struct snd_emu10k1_pcm_mixer *mix; 741 struct snd_emu10k1_pcm_mixer *mix;
738 int result = 0; 742 int result = 0;
739 743
740 /* printk("trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n", (int)emu, cmd, substream->ops->pointer(substream)); */ 744 /*
745 printk(KERN_DEBUG "trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n",
746 (int)emu, cmd, substream->ops->pointer(substream))
747 */
741 spin_lock(&emu->reg_lock); 748 spin_lock(&emu->reg_lock);
742 switch (cmd) { 749 switch (cmd) {
743 case SNDRV_PCM_TRIGGER_START: 750 case SNDRV_PCM_TRIGGER_START:
@@ -786,7 +793,10 @@ static int snd_emu10k1_capture_trigger(struct snd_pcm_substream *substream,
786 /* hmm this should cause full and half full interrupt to be raised? */ 793 /* hmm this should cause full and half full interrupt to be raised? */
787 outl(epcm->capture_ipr, emu->port + IPR); 794 outl(epcm->capture_ipr, emu->port + IPR);
788 snd_emu10k1_intr_enable(emu, epcm->capture_inte); 795 snd_emu10k1_intr_enable(emu, epcm->capture_inte);
789 /* printk("adccr = 0x%x, adcbs = 0x%x\n", epcm->adccr, epcm->adcbs); */ 796 /*
797 printk(KERN_DEBUG "adccr = 0x%x, adcbs = 0x%x\n",
798 epcm->adccr, epcm->adcbs);
799 */
790 switch (epcm->type) { 800 switch (epcm->type) {
791 case CAPTURE_AC97ADC: 801 case CAPTURE_AC97ADC:
792 snd_emu10k1_ptr_write(emu, ADCCR, 0, epcm->capture_cr_val); 802 snd_emu10k1_ptr_write(emu, ADCCR, 0, epcm->capture_cr_val);
@@ -857,7 +867,11 @@ static snd_pcm_uframes_t snd_emu10k1_playback_pointer(struct snd_pcm_substream *
857 ptr -= runtime->buffer_size; 867 ptr -= runtime->buffer_size;
858 } 868 }
859#endif 869#endif
860 /* printk("ptr = 0x%x, buffer_size = 0x%x, period_size = 0x%x\n", ptr, runtime->buffer_size, runtime->period_size); */ 870 /*
871 printk(KERN_DEBUG
872 "ptr = 0x%x, buffer_size = 0x%x, period_size = 0x%x\n",
873 ptr, runtime->buffer_size, runtime->period_size);
874 */
861 return ptr; 875 return ptr;
862} 876}
863 877
@@ -1546,7 +1560,11 @@ static void snd_emu10k1_fx8010_playback_tram_poke1(unsigned short *dst_left,
1546 unsigned int count, 1560 unsigned int count,
1547 unsigned int tram_shift) 1561 unsigned int tram_shift)
1548{ 1562{
1549 /* printk("tram_poke1: dst_left = 0x%p, dst_right = 0x%p, src = 0x%p, count = 0x%x\n", dst_left, dst_right, src, count); */ 1563 /*
1564 printk(KERN_DEBUG "tram_poke1: dst_left = 0x%p, dst_right = 0x%p, "
1565 "src = 0x%p, count = 0x%x\n",
1566 dst_left, dst_right, src, count);
1567 */
1550 if ((tram_shift & 1) == 0) { 1568 if ((tram_shift & 1) == 0) {
1551 while (count--) { 1569 while (count--) {
1552 *dst_left-- = *src++; 1570 *dst_left-- = *src++;
@@ -1623,7 +1641,12 @@ static int snd_emu10k1_fx8010_playback_prepare(struct snd_pcm_substream *substre
1623 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number]; 1641 struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
1624 unsigned int i; 1642 unsigned int i;
1625 1643
1626 /* printk("prepare: etram_pages = 0x%p, dma_area = 0x%x, buffer_size = 0x%x (0x%x)\n", emu->fx8010.etram_pages, runtime->dma_area, runtime->buffer_size, runtime->buffer_size << 2); */ 1644 /*
1645 printk(KERN_DEBUG "prepare: etram_pages = 0x%p, dma_area = 0x%x, "
1646 "buffer_size = 0x%x (0x%x)\n",
1647 emu->fx8010.etram_pages, runtime->dma_area,
1648 runtime->buffer_size, runtime->buffer_size << 2);
1649 */
1627 memset(&pcm->pcm_rec, 0, sizeof(pcm->pcm_rec)); 1650 memset(&pcm->pcm_rec, 0, sizeof(pcm->pcm_rec));
1628 pcm->pcm_rec.hw_buffer_size = pcm->buffer_size * 2; /* byte size */ 1651 pcm->pcm_rec.hw_buffer_size = pcm->buffer_size * 2; /* byte size */
1629 pcm->pcm_rec.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream); 1652 pcm->pcm_rec.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
diff --git a/sound/pci/emu10k1/io.c b/sound/pci/emu10k1/io.c
index b5a802bdeb7c..4bfc31d1b281 100644
--- a/sound/pci/emu10k1/io.c
+++ b/sound/pci/emu10k1/io.c
@@ -226,7 +226,9 @@ int snd_emu10k1_i2c_write(struct snd_emu10k1 *emu,
226 break; 226 break;
227 227
228 if (timeout > 1000) { 228 if (timeout > 1000) {
229 snd_printk("emu10k1:I2C:timeout status=0x%x\n", status); 229 snd_printk(KERN_WARNING
230 "emu10k1:I2C:timeout status=0x%x\n",
231 status);
230 break; 232 break;
231 } 233 }
232 } 234 }
diff --git a/sound/pci/emu10k1/p16v.c b/sound/pci/emu10k1/p16v.c
index 749a21b6bd06..e617acaf10e3 100644
--- a/sound/pci/emu10k1/p16v.c
+++ b/sound/pci/emu10k1/p16v.c
@@ -168,7 +168,7 @@ static void snd_p16v_pcm_free_substream(struct snd_pcm_runtime *runtime)
168 struct snd_emu10k1_pcm *epcm = runtime->private_data; 168 struct snd_emu10k1_pcm *epcm = runtime->private_data;
169 169
170 if (epcm) { 170 if (epcm) {
171 //snd_printk("epcm free: %p\n", epcm); 171 /* snd_printk(KERN_DEBUG "epcm free: %p\n", epcm); */
172 kfree(epcm); 172 kfree(epcm);
173 } 173 }
174} 174}
@@ -183,14 +183,16 @@ static int snd_p16v_pcm_open_playback_channel(struct snd_pcm_substream *substrea
183 int err; 183 int err;
184 184
185 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); 185 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
186 //snd_printk("epcm kcalloc: %p\n", epcm); 186 /* snd_printk(KERN_DEBUG "epcm kcalloc: %p\n", epcm); */
187 187
188 if (epcm == NULL) 188 if (epcm == NULL)
189 return -ENOMEM; 189 return -ENOMEM;
190 epcm->emu = emu; 190 epcm->emu = emu;
191 epcm->substream = substream; 191 epcm->substream = substream;
192 //snd_printk("epcm device=%d, channel_id=%d\n", substream->pcm->device, channel_id); 192 /*
193 193 snd_printk(KERN_DEBUG "epcm device=%d, channel_id=%d\n",
194 substream->pcm->device, channel_id);
195 */
194 runtime->private_data = epcm; 196 runtime->private_data = epcm;
195 runtime->private_free = snd_p16v_pcm_free_substream; 197 runtime->private_free = snd_p16v_pcm_free_substream;
196 198
@@ -200,10 +202,15 @@ static int snd_p16v_pcm_open_playback_channel(struct snd_pcm_substream *substrea
200 channel->number = channel_id; 202 channel->number = channel_id;
201 203
202 channel->use=1; 204 channel->use=1;
203 //snd_printk("p16v: open channel_id=%d, channel=%p, use=0x%x\n", channel_id, channel, channel->use); 205#if 0 /* debug */
204 //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel); 206 snd_printk(KERN_DEBUG
205 //channel->interrupt = snd_p16v_pcm_channel_interrupt; 207 "p16v: open channel_id=%d, channel=%p, use=0x%x\n",
206 channel->epcm=epcm; 208 channel_id, channel, channel->use);
209 printk(KERN_DEBUG "open:channel_id=%d, chip=%p, channel=%p\n",
210 channel_id, chip, channel);
211#endif /* debug */
212 /* channel->interrupt = snd_p16v_pcm_channel_interrupt; */
213 channel->epcm = epcm;
207 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 214 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
208 return err; 215 return err;
209 216
@@ -224,14 +231,16 @@ static int snd_p16v_pcm_open_capture_channel(struct snd_pcm_substream *substream
224 int err; 231 int err;
225 232
226 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL); 233 epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
227 //snd_printk("epcm kcalloc: %p\n", epcm); 234 /* snd_printk(KERN_DEBUG "epcm kcalloc: %p\n", epcm); */
228 235
229 if (epcm == NULL) 236 if (epcm == NULL)
230 return -ENOMEM; 237 return -ENOMEM;
231 epcm->emu = emu; 238 epcm->emu = emu;
232 epcm->substream = substream; 239 epcm->substream = substream;
233 //snd_printk("epcm device=%d, channel_id=%d\n", substream->pcm->device, channel_id); 240 /*
234 241 snd_printk(KERN_DEBUG "epcm device=%d, channel_id=%d\n",
242 substream->pcm->device, channel_id);
243 */
235 runtime->private_data = epcm; 244 runtime->private_data = epcm;
236 runtime->private_free = snd_p16v_pcm_free_substream; 245 runtime->private_free = snd_p16v_pcm_free_substream;
237 246
@@ -241,10 +250,15 @@ static int snd_p16v_pcm_open_capture_channel(struct snd_pcm_substream *substream
241 channel->number = channel_id; 250 channel->number = channel_id;
242 251
243 channel->use=1; 252 channel->use=1;
244 //snd_printk("p16v: open channel_id=%d, channel=%p, use=0x%x\n", channel_id, channel, channel->use); 253#if 0 /* debug */
245 //printk("open:channel_id=%d, chip=%p, channel=%p\n",channel_id, chip, channel); 254 snd_printk(KERN_DEBUG
246 //channel->interrupt = snd_p16v_pcm_channel_interrupt; 255 "p16v: open channel_id=%d, channel=%p, use=0x%x\n",
247 channel->epcm=epcm; 256 channel_id, channel, channel->use);
257 printk(KERN_DEBUG "open:channel_id=%d, chip=%p, channel=%p\n",
258 channel_id, chip, channel);
259#endif /* debug */
260 /* channel->interrupt = snd_p16v_pcm_channel_interrupt; */
261 channel->epcm = epcm;
248 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 262 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
249 return err; 263 return err;
250 264
@@ -334,9 +348,19 @@ static int snd_p16v_pcm_prepare_playback(struct snd_pcm_substream *substream)
334 int i; 348 int i;
335 u32 tmp; 349 u32 tmp;
336 350
337 //snd_printk("prepare:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, periods=%u, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, runtime->periods, frames_to_bytes(runtime, 1)); 351#if 0 /* debug */
338 //snd_printk("dma_addr=%x, dma_area=%p, table_base=%p\n",runtime->dma_addr, runtime->dma_area, table_base); 352 snd_printk(KERN_DEBUG "prepare:channel_number=%d, rate=%d, "
339 //snd_printk("dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",emu->p16v_buffer.addr, emu->p16v_buffer.area, emu->p16v_buffer.bytes); 353 "format=0x%x, channels=%d, buffer_size=%ld, "
354 "period_size=%ld, periods=%u, frames_to_bytes=%d\n",
355 channel, runtime->rate, runtime->format, runtime->channels,
356 runtime->buffer_size, runtime->period_size,
357 runtime->periods, frames_to_bytes(runtime, 1));
358 snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, table_base=%p\n",
359 runtime->dma_addr, runtime->dma_area, table_base);
360 snd_printk(KERN_DEBUG "dma_addr=%x, dma_area=%p, dma_bytes(size)=%x\n",
361 emu->p16v_buffer.addr, emu->p16v_buffer.area,
362 emu->p16v_buffer.bytes);
363#endif /* debug */
340 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, channel); 364 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, channel);
341 switch (runtime->rate) { 365 switch (runtime->rate) {
342 case 44100: 366 case 44100:
@@ -379,7 +403,15 @@ static int snd_p16v_pcm_prepare_capture(struct snd_pcm_substream *substream)
379 struct snd_pcm_runtime *runtime = substream->runtime; 403 struct snd_pcm_runtime *runtime = substream->runtime;
380 int channel = substream->pcm->device - emu->p16v_device_offset; 404 int channel = substream->pcm->device - emu->p16v_device_offset;
381 u32 tmp; 405 u32 tmp;
382 //printk("prepare capture:channel_number=%d, rate=%d, format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, frames_to_bytes=%d\n",channel, runtime->rate, runtime->format, runtime->channels, runtime->buffer_size, runtime->period_size, frames_to_bytes(runtime, 1)); 406
407 /*
408 printk(KERN_DEBUG "prepare capture:channel_number=%d, rate=%d, "
409 "format=0x%x, channels=%d, buffer_size=%ld, period_size=%ld, "
410 "frames_to_bytes=%d\n",
411 channel, runtime->rate, runtime->format, runtime->channels,
412 runtime->buffer_size, runtime->period_size,
413 frames_to_bytes(runtime, 1));
414 */
383 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, channel); 415 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, channel);
384 switch (runtime->rate) { 416 switch (runtime->rate) {
385 case 44100: 417 case 44100:
@@ -459,13 +491,13 @@ static int snd_p16v_pcm_trigger_playback(struct snd_pcm_substream *substream,
459 runtime = s->runtime; 491 runtime = s->runtime;
460 epcm = runtime->private_data; 492 epcm = runtime->private_data;
461 channel = substream->pcm->device-emu->p16v_device_offset; 493 channel = substream->pcm->device-emu->p16v_device_offset;
462 //snd_printk("p16v channel=%d\n",channel); 494 /* snd_printk(KERN_DEBUG "p16v channel=%d\n", channel); */
463 epcm->running = running; 495 epcm->running = running;
464 basic |= (0x1<<channel); 496 basic |= (0x1<<channel);
465 inte |= (INTE2_PLAYBACK_CH_0_LOOP<<channel); 497 inte |= (INTE2_PLAYBACK_CH_0_LOOP<<channel);
466 snd_pcm_trigger_done(s, substream); 498 snd_pcm_trigger_done(s, substream);
467 } 499 }
468 //snd_printk("basic=0x%x, inte=0x%x\n",basic, inte); 500 /* snd_printk(KERN_DEBUG "basic=0x%x, inte=0x%x\n", basic, inte); */
469 501
470 switch (cmd) { 502 switch (cmd) {
471 case SNDRV_PCM_TRIGGER_START: 503 case SNDRV_PCM_TRIGGER_START:
@@ -558,8 +590,13 @@ snd_p16v_pcm_pointer_capture(struct snd_pcm_substream *substream)
558 ptr -= runtime->buffer_size; 590 ptr -= runtime->buffer_size;
559 printk(KERN_WARNING "buffer capture limited!\n"); 591 printk(KERN_WARNING "buffer capture limited!\n");
560 } 592 }
561 //printk("ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n", ptr1, ptr2, ptr, (int)runtime->buffer_size, (int)runtime->period_size, (int)runtime->frame_bits, (int)runtime->rate); 593 /*
562 594 printk(KERN_DEBUG "ptr1 = 0x%lx, ptr2=0x%lx, ptr=0x%lx, "
595 "buffer_size = 0x%x, period_size = 0x%x, bits=%d, rate=%d\n",
596 ptr1, ptr2, ptr, (int)runtime->buffer_size,
597 (int)runtime->period_size, (int)runtime->frame_bits,
598 (int)runtime->rate);
599 */
563 return ptr; 600 return ptr;
564} 601}
565 602
@@ -592,7 +629,10 @@ int snd_p16v_free(struct snd_emu10k1 *chip)
592 // release the data 629 // release the data
593 if (chip->p16v_buffer.area) { 630 if (chip->p16v_buffer.area) {
594 snd_dma_free_pages(&chip->p16v_buffer); 631 snd_dma_free_pages(&chip->p16v_buffer);
595 //snd_printk("period lables free: %p\n", &chip->p16v_buffer); 632 /*
633 snd_printk(KERN_DEBUG "period lables free: %p\n",
634 &chip->p16v_buffer);
635 */
596 } 636 }
597 return 0; 637 return 0;
598} 638}
@@ -604,7 +644,7 @@ int __devinit snd_p16v_pcm(struct snd_emu10k1 *emu, int device, struct snd_pcm *
604 int err; 644 int err;
605 int capture=1; 645 int capture=1;
606 646
607 //snd_printk("snd_p16v_pcm called. device=%d\n", device); 647 /* snd_printk("KERN_DEBUG snd_p16v_pcm called. device=%d\n", device); */
608 emu->p16v_device_offset = device; 648 emu->p16v_device_offset = device;
609 if (rpcm) 649 if (rpcm)
610 *rpcm = NULL; 650 *rpcm = NULL;
@@ -631,7 +671,10 @@ int __devinit snd_p16v_pcm(struct snd_emu10k1 *emu, int device, struct snd_pcm *
631 snd_dma_pci_data(emu->pci), 671 snd_dma_pci_data(emu->pci),
632 ((65536 - 64) * 8), ((65536 - 64) * 8))) < 0) 672 ((65536 - 64) * 8), ((65536 - 64) * 8))) < 0)
633 return err; 673 return err;
634 //snd_printk("preallocate playback substream: err=%d\n", err); 674 /*
675 snd_printk(KERN_DEBUG
676 "preallocate playback substream: err=%d\n", err);
677 */
635 } 678 }
636 679
637 for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; 680 for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
@@ -642,7 +685,10 @@ int __devinit snd_p16v_pcm(struct snd_emu10k1 *emu, int device, struct snd_pcm *
642 snd_dma_pci_data(emu->pci), 685 snd_dma_pci_data(emu->pci),
643 65536 - 64, 65536 - 64)) < 0) 686 65536 - 64, 65536 - 64)) < 0)
644 return err; 687 return err;
645 //snd_printk("preallocate capture substream: err=%d\n", err); 688 /*
689 snd_printk(KERN_DEBUG
690 "preallocate capture substream: err=%d\n", err);
691 */
646 } 692 }
647 693
648 if (rpcm) 694 if (rpcm)
diff --git a/sound/pci/emu10k1/voice.c b/sound/pci/emu10k1/voice.c
index d7300a1aa262..20b8da250bd0 100644
--- a/sound/pci/emu10k1/voice.c
+++ b/sound/pci/emu10k1/voice.c
@@ -53,7 +53,10 @@ static int voice_alloc(struct snd_emu10k1 *emu, int type, int number,
53 *rvoice = NULL; 53 *rvoice = NULL;
54 first_voice = last_voice = 0; 54 first_voice = last_voice = 0;
55 for (i = emu->next_free_voice, j = 0; j < NUM_G ; i += number, j += number) { 55 for (i = emu->next_free_voice, j = 0; j < NUM_G ; i += number, j += number) {
56 // printk("i %d j %d next free %d!\n", i, j, emu->next_free_voice); 56 /*
57 printk(KERN_DEBUG "i %d j %d next free %d!\n",
58 i, j, emu->next_free_voice);
59 */
57 i %= NUM_G; 60 i %= NUM_G;
58 61
59 /* stereo voices must be even/odd */ 62 /* stereo voices must be even/odd */
@@ -71,7 +74,7 @@ static int voice_alloc(struct snd_emu10k1 *emu, int type, int number,
71 } 74 }
72 } 75 }
73 if (!skip) { 76 if (!skip) {
74 // printk("allocated voice %d\n", i); 77 /* printk(KERN_DEBUG "allocated voice %d\n", i); */
75 first_voice = i; 78 first_voice = i;
76 last_voice = (i + number) % NUM_G; 79 last_voice = (i + number) % NUM_G;
77 emu->next_free_voice = last_voice; 80 emu->next_free_voice = last_voice;
@@ -84,7 +87,10 @@ static int voice_alloc(struct snd_emu10k1 *emu, int type, int number,
84 87
85 for (i = 0; i < number; i++) { 88 for (i = 0; i < number; i++) {
86 voice = &emu->voices[(first_voice + i) % NUM_G]; 89 voice = &emu->voices[(first_voice + i) % NUM_G];
87 // printk("voice alloc - %i, %i of %i\n", voice->number, idx-first_voice+1, number); 90 /*
91 printk(kERN_DEBUG "voice alloc - %i, %i of %i\n",
92 voice->number, idx-first_voice+1, number);
93 */
88 voice->use = 1; 94 voice->use = 1;
89 switch (type) { 95 switch (type) {
90 case EMU10K1_PCM: 96 case EMU10K1_PCM:
diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c
index 9bf95367c882..18f4d1e98c46 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -584,7 +584,8 @@ static void snd_es1370_codec_write(struct snd_ak4531 *ak4531,
584 unsigned long end_time = jiffies + HZ / 10; 584 unsigned long end_time = jiffies + HZ / 10;
585 585
586#if 0 586#if 0
587 printk("CODEC WRITE: reg = 0x%x, val = 0x%x (0x%x), creg = 0x%x\n", 587 printk(KERN_DEBUG
588 "CODEC WRITE: reg = 0x%x, val = 0x%x (0x%x), creg = 0x%x\n",
588 reg, val, ES_1370_CODEC_WRITE(reg, val), ES_REG(ensoniq, 1370_CODEC)); 589 reg, val, ES_1370_CODEC_WRITE(reg, val), ES_REG(ensoniq, 1370_CODEC));
589#endif 590#endif
590 do { 591 do {
@@ -2409,9 +2410,9 @@ static int __devinit snd_audiopci_probe(struct pci_dev *pci,
2409 return -ENOENT; 2410 return -ENOENT;
2410 } 2411 }
2411 2412
2412 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 2413 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2413 if (card == NULL) 2414 if (err < 0)
2414 return -ENOMEM; 2415 return err;
2415 2416
2416 if ((err = snd_ensoniq_create(card, pci, &ensoniq)) < 0) { 2417 if ((err = snd_ensoniq_create(card, pci, &ensoniq)) < 0) {
2417 snd_card_free(card); 2418 snd_card_free(card);
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 4cd9a1faaecc..dd63b132fb8e 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -1673,18 +1673,22 @@ static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id)
1673 1673
1674 status = inb(SLIO_REG(chip, IRQCONTROL)); 1674 status = inb(SLIO_REG(chip, IRQCONTROL));
1675#if 0 1675#if 0
1676 printk("Es1938debug - interrupt status: =0x%x\n", status); 1676 printk(KERN_DEBUG "Es1938debug - interrupt status: =0x%x\n", status);
1677#endif 1677#endif
1678 1678
1679 /* AUDIO 1 */ 1679 /* AUDIO 1 */
1680 if (status & 0x10) { 1680 if (status & 0x10) {
1681#if 0 1681#if 0
1682 printk("Es1938debug - AUDIO channel 1 interrupt\n"); 1682 printk(KERN_DEBUG
1683 printk("Es1938debug - AUDIO channel 1 DMAC DMA count: %u\n", 1683 "Es1938debug - AUDIO channel 1 interrupt\n");
1684 printk(KERN_DEBUG
1685 "Es1938debug - AUDIO channel 1 DMAC DMA count: %u\n",
1684 inw(SLDM_REG(chip, DMACOUNT))); 1686 inw(SLDM_REG(chip, DMACOUNT)));
1685 printk("Es1938debug - AUDIO channel 1 DMAC DMA base: %u\n", 1687 printk(KERN_DEBUG
1688 "Es1938debug - AUDIO channel 1 DMAC DMA base: %u\n",
1686 inl(SLDM_REG(chip, DMAADDR))); 1689 inl(SLDM_REG(chip, DMAADDR)));
1687 printk("Es1938debug - AUDIO channel 1 DMAC DMA status: 0x%x\n", 1690 printk(KERN_DEBUG
1691 "Es1938debug - AUDIO channel 1 DMAC DMA status: 0x%x\n",
1688 inl(SLDM_REG(chip, DMASTATUS))); 1692 inl(SLDM_REG(chip, DMASTATUS)));
1689#endif 1693#endif
1690 /* clear irq */ 1694 /* clear irq */
@@ -1699,10 +1703,13 @@ static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id)
1699 /* AUDIO 2 */ 1703 /* AUDIO 2 */
1700 if (status & 0x20) { 1704 if (status & 0x20) {
1701#if 0 1705#if 0
1702 printk("Es1938debug - AUDIO channel 2 interrupt\n"); 1706 printk(KERN_DEBUG
1703 printk("Es1938debug - AUDIO channel 2 DMAC DMA count: %u\n", 1707 "Es1938debug - AUDIO channel 2 interrupt\n");
1708 printk(KERN_DEBUG
1709 "Es1938debug - AUDIO channel 2 DMAC DMA count: %u\n",
1704 inw(SLIO_REG(chip, AUDIO2DMACOUNT))); 1710 inw(SLIO_REG(chip, AUDIO2DMACOUNT)));
1705 printk("Es1938debug - AUDIO channel 2 DMAC DMA base: %u\n", 1711 printk(KERN_DEBUG
1712 "Es1938debug - AUDIO channel 2 DMAC DMA base: %u\n",
1706 inl(SLIO_REG(chip, AUDIO2DMAADDR))); 1713 inl(SLIO_REG(chip, AUDIO2DMAADDR)));
1707 1714
1708#endif 1715#endif
@@ -1799,9 +1806,9 @@ static int __devinit snd_es1938_probe(struct pci_dev *pci,
1799 return -ENOENT; 1806 return -ENOENT;
1800 } 1807 }
1801 1808
1802 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 1809 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
1803 if (card == NULL) 1810 if (err < 0)
1804 return -ENOMEM; 1811 return err;
1805 for (idx = 0; idx < 5; idx++) { 1812 for (idx = 0; idx < 5; idx++) {
1806 if (pci_resource_start(pci, idx) == 0 || 1813 if (pci_resource_start(pci, idx) == 0 ||
1807 !(pci_resource_flags(pci, idx) & IORESOURCE_IO)) { 1814 !(pci_resource_flags(pci, idx) & IORESOURCE_IO)) {
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index e9c3794bbcb8..dc97e8116141 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -2645,9 +2645,9 @@ static int __devinit snd_es1968_probe(struct pci_dev *pci,
2645 return -ENOENT; 2645 return -ENOENT;
2646 } 2646 }
2647 2647
2648 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 2648 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2649 if (!card) 2649 if (err < 0)
2650 return -ENOMEM; 2650 return err;
2651 2651
2652 if (total_bufsize[dev] < 128) 2652 if (total_bufsize[dev] < 128)
2653 total_bufsize[dev] = 128; 2653 total_bufsize[dev] = 128;
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index c129f9e2072c..60cdb9e0b68d 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -1468,9 +1468,9 @@ static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
1468 return -ENOENT; 1468 return -ENOENT;
1469 } 1469 }
1470 1470
1471 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 1471 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
1472 if (card == NULL) 1472 if (err < 0)
1473 return -ENOMEM; 1473 return err;
1474 if ((err = snd_fm801_create(card, pci, tea575x_tuner[dev], &chip)) < 0) { 1474 if ((err = snd_fm801_create(card, pci, tea575x_tuner[dev], &chip)) < 0) {
1475 snd_card_free(card); 1475 snd_card_free(card);
1476 return err; 1476 return err;
diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c
index 960fd7970384..4de5bacd3929 100644
--- a/sound/pci/hda/hda_beep.c
+++ b/sound/pci/hda/hda_beep.c
@@ -138,6 +138,7 @@ void snd_hda_detach_beep_device(struct hda_codec *codec)
138 138
139 input_unregister_device(beep->dev); 139 input_unregister_device(beep->dev);
140 kfree(beep); 140 kfree(beep);
141 codec->beep = NULL;
141 } 142 }
142} 143}
143EXPORT_SYMBOL_HDA(snd_hda_detach_beep_device); 144EXPORT_SYMBOL_HDA(snd_hda_detach_beep_device);
diff --git a/sound/pci/hda/hda_beep.h b/sound/pci/hda/hda_beep.h
index b9679f081cae..51bf6a5daf39 100644
--- a/sound/pci/hda/hda_beep.h
+++ b/sound/pci/hda/hda_beep.h
@@ -39,7 +39,7 @@ struct hda_beep {
39int snd_hda_attach_beep_device(struct hda_codec *codec, int nid); 39int snd_hda_attach_beep_device(struct hda_codec *codec, int nid);
40void snd_hda_detach_beep_device(struct hda_codec *codec); 40void snd_hda_detach_beep_device(struct hda_codec *codec);
41#else 41#else
42#define snd_hda_attach_beep_device(...) 42#define snd_hda_attach_beep_device(...) 0
43#define snd_hda_detach_beep_device(...) 43#define snd_hda_detach_beep_device(...)
44#endif 44#endif
45#endif 45#endif
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index d03f99298be9..a4e5e5952115 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -647,9 +647,9 @@ static void /*__devinit*/ setup_fg_nodes(struct hda_codec *codec)
647 647
648 total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid); 648 total_nodes = snd_hda_get_sub_nodes(codec, AC_NODE_ROOT, &nid);
649 for (i = 0; i < total_nodes; i++, nid++) { 649 for (i = 0; i < total_nodes; i++, nid++) {
650 unsigned int func; 650 codec->function_id = snd_hda_param_read(codec, nid,
651 func = snd_hda_param_read(codec, nid, AC_PAR_FUNCTION_TYPE); 651 AC_PAR_FUNCTION_TYPE) & 0xff;
652 switch (func & 0xff) { 652 switch (codec->function_id) {
653 case AC_GRP_AUDIO_FUNCTION: 653 case AC_GRP_AUDIO_FUNCTION:
654 codec->afg = nid; 654 codec->afg = nid;
655 break; 655 break;
@@ -682,11 +682,140 @@ static int read_widget_caps(struct hda_codec *codec, hda_nid_t fg_node)
682 return 0; 682 return 0;
683} 683}
684 684
685/* read all pin default configurations and save codec->init_pins */
686static int read_pin_defaults(struct hda_codec *codec)
687{
688 int i;
689 hda_nid_t nid = codec->start_nid;
690
691 for (i = 0; i < codec->num_nodes; i++, nid++) {
692 struct hda_pincfg *pin;
693 unsigned int wcaps = get_wcaps(codec, nid);
694 unsigned int wid_type = (wcaps & AC_WCAP_TYPE) >>
695 AC_WCAP_TYPE_SHIFT;
696 if (wid_type != AC_WID_PIN)
697 continue;
698 pin = snd_array_new(&codec->init_pins);
699 if (!pin)
700 return -ENOMEM;
701 pin->nid = nid;
702 pin->cfg = snd_hda_codec_read(codec, nid, 0,
703 AC_VERB_GET_CONFIG_DEFAULT, 0);
704 }
705 return 0;
706}
707
708/* look up the given pin config list and return the item matching with NID */
709static struct hda_pincfg *look_up_pincfg(struct hda_codec *codec,
710 struct snd_array *array,
711 hda_nid_t nid)
712{
713 int i;
714 for (i = 0; i < array->used; i++) {
715 struct hda_pincfg *pin = snd_array_elem(array, i);
716 if (pin->nid == nid)
717 return pin;
718 }
719 return NULL;
720}
721
722/* write a config value for the given NID */
723static void set_pincfg(struct hda_codec *codec, hda_nid_t nid,
724 unsigned int cfg)
725{
726 int i;
727 for (i = 0; i < 4; i++) {
728 snd_hda_codec_write(codec, nid, 0,
729 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
730 cfg & 0xff);
731 cfg >>= 8;
732 }
733}
734
735/* set the current pin config value for the given NID.
736 * the value is cached, and read via snd_hda_codec_get_pincfg()
737 */
738int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
739 hda_nid_t nid, unsigned int cfg)
740{
741 struct hda_pincfg *pin;
742 unsigned int oldcfg;
743
744 oldcfg = snd_hda_codec_get_pincfg(codec, nid);
745 pin = look_up_pincfg(codec, list, nid);
746 if (!pin) {
747 pin = snd_array_new(list);
748 if (!pin)
749 return -ENOMEM;
750 pin->nid = nid;
751 }
752 pin->cfg = cfg;
753
754 /* change only when needed; e.g. if the pincfg is already present
755 * in user_pins[], don't write it
756 */
757 cfg = snd_hda_codec_get_pincfg(codec, nid);
758 if (oldcfg != cfg)
759 set_pincfg(codec, nid, cfg);
760 return 0;
761}
762
763int snd_hda_codec_set_pincfg(struct hda_codec *codec,
764 hda_nid_t nid, unsigned int cfg)
765{
766 return snd_hda_add_pincfg(codec, &codec->driver_pins, nid, cfg);
767}
768EXPORT_SYMBOL_HDA(snd_hda_codec_set_pincfg);
769
770/* get the current pin config value of the given pin NID */
771unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid)
772{
773 struct hda_pincfg *pin;
774
775#ifdef CONFIG_SND_HDA_HWDEP
776 pin = look_up_pincfg(codec, &codec->user_pins, nid);
777 if (pin)
778 return pin->cfg;
779#endif
780 pin = look_up_pincfg(codec, &codec->driver_pins, nid);
781 if (pin)
782 return pin->cfg;
783 pin = look_up_pincfg(codec, &codec->init_pins, nid);
784 if (pin)
785 return pin->cfg;
786 return 0;
787}
788EXPORT_SYMBOL_HDA(snd_hda_codec_get_pincfg);
789
790/* restore all current pin configs */
791static void restore_pincfgs(struct hda_codec *codec)
792{
793 int i;
794 for (i = 0; i < codec->init_pins.used; i++) {
795 struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
796 set_pincfg(codec, pin->nid,
797 snd_hda_codec_get_pincfg(codec, pin->nid));
798 }
799}
685 800
686static void init_hda_cache(struct hda_cache_rec *cache, 801static void init_hda_cache(struct hda_cache_rec *cache,
687 unsigned int record_size); 802 unsigned int record_size);
688static void free_hda_cache(struct hda_cache_rec *cache); 803static void free_hda_cache(struct hda_cache_rec *cache);
689 804
805/* restore the initial pin cfgs and release all pincfg lists */
806static void restore_init_pincfgs(struct hda_codec *codec)
807{
808 /* first free driver_pins and user_pins, then call restore_pincfg
809 * so that only the values in init_pins are restored
810 */
811 snd_array_free(&codec->driver_pins);
812#ifdef CONFIG_SND_HDA_HWDEP
813 snd_array_free(&codec->user_pins);
814#endif
815 restore_pincfgs(codec);
816 snd_array_free(&codec->init_pins);
817}
818
690/* 819/*
691 * codec destructor 820 * codec destructor
692 */ 821 */
@@ -694,6 +823,7 @@ static void snd_hda_codec_free(struct hda_codec *codec)
694{ 823{
695 if (!codec) 824 if (!codec)
696 return; 825 return;
826 restore_init_pincfgs(codec);
697#ifdef CONFIG_SND_HDA_POWER_SAVE 827#ifdef CONFIG_SND_HDA_POWER_SAVE
698 cancel_delayed_work(&codec->power_work); 828 cancel_delayed_work(&codec->power_work);
699 flush_workqueue(codec->bus->workq); 829 flush_workqueue(codec->bus->workq);
@@ -712,6 +842,9 @@ static void snd_hda_codec_free(struct hda_codec *codec)
712 kfree(codec); 842 kfree(codec);
713} 843}
714 844
845static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
846 unsigned int power_state);
847
715/** 848/**
716 * snd_hda_codec_new - create a HDA codec 849 * snd_hda_codec_new - create a HDA codec
717 * @bus: the bus to assign 850 * @bus: the bus to assign
@@ -751,6 +884,8 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
751 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); 884 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
752 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); 885 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
753 snd_array_init(&codec->mixers, sizeof(struct snd_kcontrol *), 32); 886 snd_array_init(&codec->mixers, sizeof(struct snd_kcontrol *), 32);
887 snd_array_init(&codec->init_pins, sizeof(struct hda_pincfg), 16);
888 snd_array_init(&codec->driver_pins, sizeof(struct hda_pincfg), 16);
754 if (codec->bus->modelname) { 889 if (codec->bus->modelname) {
755 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL); 890 codec->modelname = kstrdup(codec->bus->modelname, GFP_KERNEL);
756 if (!codec->modelname) { 891 if (!codec->modelname) {
@@ -787,15 +922,18 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
787 setup_fg_nodes(codec); 922 setup_fg_nodes(codec);
788 if (!codec->afg && !codec->mfg) { 923 if (!codec->afg && !codec->mfg) {
789 snd_printdd("hda_codec: no AFG or MFG node found\n"); 924 snd_printdd("hda_codec: no AFG or MFG node found\n");
790 snd_hda_codec_free(codec); 925 err = -ENODEV;
791 return -ENODEV; 926 goto error;
792 } 927 }
793 928
794 if (read_widget_caps(codec, codec->afg ? codec->afg : codec->mfg) < 0) { 929 err = read_widget_caps(codec, codec->afg ? codec->afg : codec->mfg);
930 if (err < 0) {
795 snd_printk(KERN_ERR "hda_codec: cannot malloc\n"); 931 snd_printk(KERN_ERR "hda_codec: cannot malloc\n");
796 snd_hda_codec_free(codec); 932 goto error;
797 return -ENOMEM;
798 } 933 }
934 err = read_pin_defaults(codec);
935 if (err < 0)
936 goto error;
799 937
800 if (!codec->subsystem_id) { 938 if (!codec->subsystem_id) {
801 hda_nid_t nid = codec->afg ? codec->afg : codec->mfg; 939 hda_nid_t nid = codec->afg ? codec->afg : codec->mfg;
@@ -806,12 +944,15 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
806 if (bus->modelname) 944 if (bus->modelname)
807 codec->modelname = kstrdup(bus->modelname, GFP_KERNEL); 945 codec->modelname = kstrdup(bus->modelname, GFP_KERNEL);
808 946
947 /* power-up all before initialization */
948 hda_set_power_state(codec,
949 codec->afg ? codec->afg : codec->mfg,
950 AC_PWRST_D0);
951
809 if (do_init) { 952 if (do_init) {
810 err = snd_hda_codec_configure(codec); 953 err = snd_hda_codec_configure(codec);
811 if (err < 0) { 954 if (err < 0)
812 snd_hda_codec_free(codec); 955 goto error;
813 return err;
814 }
815 } 956 }
816 snd_hda_codec_proc_new(codec); 957 snd_hda_codec_proc_new(codec);
817 958
@@ -824,6 +965,10 @@ int /*__devinit*/ snd_hda_codec_new(struct hda_bus *bus, unsigned int codec_addr
824 if (codecp) 965 if (codecp)
825 *codecp = codec; 966 *codecp = codec;
826 return 0; 967 return 0;
968
969 error:
970 snd_hda_codec_free(codec);
971 return err;
827} 972}
828EXPORT_SYMBOL_HDA(snd_hda_codec_new); 973EXPORT_SYMBOL_HDA(snd_hda_codec_new);
829 974
@@ -907,6 +1052,7 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_cleanup_stream);
907 1052
908/* FIXME: more better hash key? */ 1053/* FIXME: more better hash key? */
909#define HDA_HASH_KEY(nid,dir,idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24)) 1054#define HDA_HASH_KEY(nid,dir,idx) (u32)((nid) + ((idx) << 16) + ((dir) << 24))
1055#define HDA_HASH_PINCAP_KEY(nid) (u32)((nid) + (0x02 << 24))
910#define INFO_AMP_CAPS (1<<0) 1056#define INFO_AMP_CAPS (1<<0)
911#define INFO_AMP_VOL(ch) (1 << (1 + (ch))) 1057#define INFO_AMP_VOL(ch) (1 << (1 + (ch)))
912 1058
@@ -997,6 +1143,21 @@ int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
997} 1143}
998EXPORT_SYMBOL_HDA(snd_hda_override_amp_caps); 1144EXPORT_SYMBOL_HDA(snd_hda_override_amp_caps);
999 1145
1146u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1147{
1148 struct hda_amp_info *info;
1149
1150 info = get_alloc_amp_hash(codec, HDA_HASH_PINCAP_KEY(nid));
1151 if (!info)
1152 return 0;
1153 if (!info->head.val) {
1154 info->amp_caps = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
1155 info->head.val |= INFO_AMP_CAPS;
1156 }
1157 return info->amp_caps;
1158}
1159EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps);
1160
1000/* 1161/*
1001 * read the current volume to info 1162 * read the current volume to info
1002 * if the cache exists, read the cache value. 1163 * if the cache exists, read the cache value.
@@ -1120,6 +1281,7 @@ int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
1120 u16 nid = get_amp_nid(kcontrol); 1281 u16 nid = get_amp_nid(kcontrol);
1121 u8 chs = get_amp_channels(kcontrol); 1282 u8 chs = get_amp_channels(kcontrol);
1122 int dir = get_amp_direction(kcontrol); 1283 int dir = get_amp_direction(kcontrol);
1284 unsigned int ofs = get_amp_offset(kcontrol);
1123 u32 caps; 1285 u32 caps;
1124 1286
1125 caps = query_amp_caps(codec, nid, dir); 1287 caps = query_amp_caps(codec, nid, dir);
@@ -1131,6 +1293,8 @@ int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
1131 kcontrol->id.name); 1293 kcontrol->id.name);
1132 return -EINVAL; 1294 return -EINVAL;
1133 } 1295 }
1296 if (ofs < caps)
1297 caps -= ofs;
1134 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 1298 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1135 uinfo->count = chs == 3 ? 2 : 1; 1299 uinfo->count = chs == 3 ? 2 : 1;
1136 uinfo->value.integer.min = 0; 1300 uinfo->value.integer.min = 0;
@@ -1139,6 +1303,32 @@ int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
1139} 1303}
1140EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_info); 1304EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_info);
1141 1305
1306
1307static inline unsigned int
1308read_amp_value(struct hda_codec *codec, hda_nid_t nid,
1309 int ch, int dir, int idx, unsigned int ofs)
1310{
1311 unsigned int val;
1312 val = snd_hda_codec_amp_read(codec, nid, ch, dir, idx);
1313 val &= HDA_AMP_VOLMASK;
1314 if (val >= ofs)
1315 val -= ofs;
1316 else
1317 val = 0;
1318 return val;
1319}
1320
1321static inline int
1322update_amp_value(struct hda_codec *codec, hda_nid_t nid,
1323 int ch, int dir, int idx, unsigned int ofs,
1324 unsigned int val)
1325{
1326 if (val > 0)
1327 val += ofs;
1328 return snd_hda_codec_amp_update(codec, nid, ch, dir, idx,
1329 HDA_AMP_VOLMASK, val);
1330}
1331
1142int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol, 1332int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1143 struct snd_ctl_elem_value *ucontrol) 1333 struct snd_ctl_elem_value *ucontrol)
1144{ 1334{
@@ -1147,14 +1337,13 @@ int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
1147 int chs = get_amp_channels(kcontrol); 1337 int chs = get_amp_channels(kcontrol);
1148 int dir = get_amp_direction(kcontrol); 1338 int dir = get_amp_direction(kcontrol);
1149 int idx = get_amp_index(kcontrol); 1339 int idx = get_amp_index(kcontrol);
1340 unsigned int ofs = get_amp_offset(kcontrol);
1150 long *valp = ucontrol->value.integer.value; 1341 long *valp = ucontrol->value.integer.value;
1151 1342
1152 if (chs & 1) 1343 if (chs & 1)
1153 *valp++ = snd_hda_codec_amp_read(codec, nid, 0, dir, idx) 1344 *valp++ = read_amp_value(codec, nid, 0, dir, idx, ofs);
1154 & HDA_AMP_VOLMASK;
1155 if (chs & 2) 1345 if (chs & 2)
1156 *valp = snd_hda_codec_amp_read(codec, nid, 1, dir, idx) 1346 *valp = read_amp_value(codec, nid, 1, dir, idx, ofs);
1157 & HDA_AMP_VOLMASK;
1158 return 0; 1347 return 0;
1159} 1348}
1160EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get); 1349EXPORT_SYMBOL_HDA(snd_hda_mixer_amp_volume_get);
@@ -1167,18 +1356,17 @@ int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
1167 int chs = get_amp_channels(kcontrol); 1356 int chs = get_amp_channels(kcontrol);
1168 int dir = get_amp_direction(kcontrol); 1357 int dir = get_amp_direction(kcontrol);
1169 int idx = get_amp_index(kcontrol); 1358 int idx = get_amp_index(kcontrol);
1359 unsigned int ofs = get_amp_offset(kcontrol);
1170 long *valp = ucontrol->value.integer.value; 1360 long *valp = ucontrol->value.integer.value;
1171 int change = 0; 1361 int change = 0;
1172 1362
1173 snd_hda_power_up(codec); 1363 snd_hda_power_up(codec);
1174 if (chs & 1) { 1364 if (chs & 1) {
1175 change = snd_hda_codec_amp_update(codec, nid, 0, dir, idx, 1365 change = update_amp_value(codec, nid, 0, dir, idx, ofs, *valp);
1176 0x7f, *valp);
1177 valp++; 1366 valp++;
1178 } 1367 }
1179 if (chs & 2) 1368 if (chs & 2)
1180 change |= snd_hda_codec_amp_update(codec, nid, 1, dir, idx, 1369 change |= update_amp_value(codec, nid, 1, dir, idx, ofs, *valp);
1181 0x7f, *valp);
1182 snd_hda_power_down(codec); 1370 snd_hda_power_down(codec);
1183 return change; 1371 return change;
1184} 1372}
@@ -1190,6 +1378,7 @@ int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1190 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 1378 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1191 hda_nid_t nid = get_amp_nid(kcontrol); 1379 hda_nid_t nid = get_amp_nid(kcontrol);
1192 int dir = get_amp_direction(kcontrol); 1380 int dir = get_amp_direction(kcontrol);
1381 unsigned int ofs = get_amp_offset(kcontrol);
1193 u32 caps, val1, val2; 1382 u32 caps, val1, val2;
1194 1383
1195 if (size < 4 * sizeof(unsigned int)) 1384 if (size < 4 * sizeof(unsigned int))
@@ -1198,6 +1387,7 @@ int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1198 val2 = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT; 1387 val2 = (caps & AC_AMPCAP_STEP_SIZE) >> AC_AMPCAP_STEP_SIZE_SHIFT;
1199 val2 = (val2 + 1) * 25; 1388 val2 = (val2 + 1) * 25;
1200 val1 = -((caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT); 1389 val1 = -((caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT);
1390 val1 += ofs;
1201 val1 = ((int)val1) * ((int)val2); 1391 val1 = ((int)val1) * ((int)val2);
1202 if (put_user(SNDRV_CTL_TLVT_DB_SCALE, _tlv)) 1392 if (put_user(SNDRV_CTL_TLVT_DB_SCALE, _tlv))
1203 return -EFAULT; 1393 return -EFAULT;
@@ -1268,7 +1458,6 @@ int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl)
1268} 1458}
1269EXPORT_SYMBOL_HDA(snd_hda_ctl_add); 1459EXPORT_SYMBOL_HDA(snd_hda_ctl_add);
1270 1460
1271#ifdef CONFIG_SND_HDA_RECONFIG
1272/* Clear all controls assigned to the given codec */ 1461/* Clear all controls assigned to the given codec */
1273void snd_hda_ctls_clear(struct hda_codec *codec) 1462void snd_hda_ctls_clear(struct hda_codec *codec)
1274{ 1463{
@@ -1279,9 +1468,52 @@ void snd_hda_ctls_clear(struct hda_codec *codec)
1279 snd_array_free(&codec->mixers); 1468 snd_array_free(&codec->mixers);
1280} 1469}
1281 1470
1282void snd_hda_codec_reset(struct hda_codec *codec) 1471/* pseudo device locking
1472 * toggle card->shutdown to allow/disallow the device access (as a hack)
1473 */
1474static int hda_lock_devices(struct snd_card *card)
1283{ 1475{
1284 int i; 1476 spin_lock(&card->files_lock);
1477 if (card->shutdown) {
1478 spin_unlock(&card->files_lock);
1479 return -EINVAL;
1480 }
1481 card->shutdown = 1;
1482 spin_unlock(&card->files_lock);
1483 return 0;
1484}
1485
1486static void hda_unlock_devices(struct snd_card *card)
1487{
1488 spin_lock(&card->files_lock);
1489 card->shutdown = 0;
1490 spin_unlock(&card->files_lock);
1491}
1492
1493int snd_hda_codec_reset(struct hda_codec *codec)
1494{
1495 struct snd_card *card = codec->bus->card;
1496 int i, pcm;
1497
1498 if (hda_lock_devices(card) < 0)
1499 return -EBUSY;
1500 /* check whether the codec isn't used by any mixer or PCM streams */
1501 if (!list_empty(&card->ctl_files)) {
1502 hda_unlock_devices(card);
1503 return -EBUSY;
1504 }
1505 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
1506 struct hda_pcm *cpcm = &codec->pcm_info[pcm];
1507 if (!cpcm->pcm)
1508 continue;
1509 if (cpcm->pcm->streams[0].substream_opened ||
1510 cpcm->pcm->streams[1].substream_opened) {
1511 hda_unlock_devices(card);
1512 return -EBUSY;
1513 }
1514 }
1515
1516 /* OK, let it free */
1285 1517
1286#ifdef CONFIG_SND_HDA_POWER_SAVE 1518#ifdef CONFIG_SND_HDA_POWER_SAVE
1287 cancel_delayed_work(&codec->power_work); 1519 cancel_delayed_work(&codec->power_work);
@@ -1291,8 +1523,7 @@ void snd_hda_codec_reset(struct hda_codec *codec)
1291 /* relase PCMs */ 1523 /* relase PCMs */
1292 for (i = 0; i < codec->num_pcms; i++) { 1524 for (i = 0; i < codec->num_pcms; i++) {
1293 if (codec->pcm_info[i].pcm) { 1525 if (codec->pcm_info[i].pcm) {
1294 snd_device_free(codec->bus->card, 1526 snd_device_free(card, codec->pcm_info[i].pcm);
1295 codec->pcm_info[i].pcm);
1296 clear_bit(codec->pcm_info[i].device, 1527 clear_bit(codec->pcm_info[i].device,
1297 codec->bus->pcm_dev_bits); 1528 codec->bus->pcm_dev_bits);
1298 } 1529 }
@@ -1305,13 +1536,22 @@ void snd_hda_codec_reset(struct hda_codec *codec)
1305 free_hda_cache(&codec->cmd_cache); 1536 free_hda_cache(&codec->cmd_cache);
1306 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info)); 1537 init_hda_cache(&codec->amp_cache, sizeof(struct hda_amp_info));
1307 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head)); 1538 init_hda_cache(&codec->cmd_cache, sizeof(struct hda_cache_head));
1539 /* free only driver_pins so that init_pins + user_pins are restored */
1540 snd_array_free(&codec->driver_pins);
1541 restore_pincfgs(codec);
1308 codec->num_pcms = 0; 1542 codec->num_pcms = 0;
1309 codec->pcm_info = NULL; 1543 codec->pcm_info = NULL;
1310 codec->preset = NULL; 1544 codec->preset = NULL;
1545 memset(&codec->patch_ops, 0, sizeof(codec->patch_ops));
1546 codec->slave_dig_outs = NULL;
1547 codec->spdif_status_reset = 0;
1311 module_put(codec->owner); 1548 module_put(codec->owner);
1312 codec->owner = NULL; 1549 codec->owner = NULL;
1550
1551 /* allow device access again */
1552 hda_unlock_devices(card);
1553 return 0;
1313} 1554}
1314#endif /* CONFIG_SND_HDA_RECONFIG */
1315 1555
1316/* create a virtual master control and add slaves */ 1556/* create a virtual master control and add slaves */
1317int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 1557int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
@@ -1336,15 +1576,20 @@ int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1336 1576
1337 for (s = slaves; *s; s++) { 1577 for (s = slaves; *s; s++) {
1338 struct snd_kcontrol *sctl; 1578 struct snd_kcontrol *sctl;
1339 1579 int i = 0;
1340 sctl = snd_hda_find_mixer_ctl(codec, *s); 1580 for (;;) {
1341 if (!sctl) { 1581 sctl = _snd_hda_find_mixer_ctl(codec, *s, i);
1342 snd_printdd("Cannot find slave %s, skipped\n", *s); 1582 if (!sctl) {
1343 continue; 1583 if (!i)
1584 snd_printdd("Cannot find slave %s, "
1585 "skipped\n", *s);
1586 break;
1587 }
1588 err = snd_ctl_add_slave(kctl, sctl);
1589 if (err < 0)
1590 return err;
1591 i++;
1344 } 1592 }
1345 err = snd_ctl_add_slave(kctl, sctl);
1346 if (err < 0)
1347 return err;
1348 } 1593 }
1349 return 0; 1594 return 0;
1350} 1595}
@@ -1955,6 +2200,8 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
1955 } 2200 }
1956 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) { 2201 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
1957 kctl = snd_ctl_new1(dig_mix, codec); 2202 kctl = snd_ctl_new1(dig_mix, codec);
2203 if (!kctl)
2204 return -ENOMEM;
1958 kctl->private_value = nid; 2205 kctl->private_value = nid;
1959 err = snd_hda_ctl_add(codec, kctl); 2206 err = snd_hda_ctl_add(codec, kctl);
1960 if (err < 0) 2207 if (err < 0)
@@ -2074,8 +2321,7 @@ static void hda_set_power_state(struct hda_codec *codec, hda_nid_t fg,
2074 * don't power down the widget if it controls 2321 * don't power down the widget if it controls
2075 * eapd and EAPD_BTLENABLE is set. 2322 * eapd and EAPD_BTLENABLE is set.
2076 */ 2323 */
2077 pincap = snd_hda_param_read(codec, nid, 2324 pincap = snd_hda_query_pin_caps(codec, nid);
2078 AC_PAR_PIN_CAP);
2079 if (pincap & AC_PINCAP_EAPD) { 2325 if (pincap & AC_PINCAP_EAPD) {
2080 int eapd = snd_hda_codec_read(codec, 2326 int eapd = snd_hda_codec_read(codec,
2081 nid, 0, 2327 nid, 0,
@@ -2144,6 +2390,7 @@ static void hda_call_codec_resume(struct hda_codec *codec)
2144 hda_set_power_state(codec, 2390 hda_set_power_state(codec,
2145 codec->afg ? codec->afg : codec->mfg, 2391 codec->afg ? codec->afg : codec->mfg,
2146 AC_PWRST_D0); 2392 AC_PWRST_D0);
2393 restore_pincfgs(codec); /* restore all current pin configs */
2147 hda_exec_init_verbs(codec); 2394 hda_exec_init_verbs(codec);
2148 if (codec->patch_ops.resume) 2395 if (codec->patch_ops.resume)
2149 codec->patch_ops.resume(codec); 2396 codec->patch_ops.resume(codec);
@@ -2171,8 +2418,16 @@ int /*__devinit*/ snd_hda_build_controls(struct hda_bus *bus)
2171 2418
2172 list_for_each_entry(codec, &bus->codec_list, list) { 2419 list_for_each_entry(codec, &bus->codec_list, list) {
2173 int err = snd_hda_codec_build_controls(codec); 2420 int err = snd_hda_codec_build_controls(codec);
2174 if (err < 0) 2421 if (err < 0) {
2175 return err; 2422 printk(KERN_ERR "hda_codec: cannot build controls"
2423 "for #%d (error %d)\n", codec->addr, err);
2424 err = snd_hda_codec_reset(codec);
2425 if (err < 0) {
2426 printk(KERN_ERR
2427 "hda_codec: cannot revert codec\n");
2428 return err;
2429 }
2430 }
2176 } 2431 }
2177 return 0; 2432 return 0;
2178} 2433}
@@ -2181,19 +2436,12 @@ EXPORT_SYMBOL_HDA(snd_hda_build_controls);
2181int snd_hda_codec_build_controls(struct hda_codec *codec) 2436int snd_hda_codec_build_controls(struct hda_codec *codec)
2182{ 2437{
2183 int err = 0; 2438 int err = 0;
2184 /* fake as if already powered-on */
2185 hda_keep_power_on(codec);
2186 /* then fire up */
2187 hda_set_power_state(codec,
2188 codec->afg ? codec->afg : codec->mfg,
2189 AC_PWRST_D0);
2190 hda_exec_init_verbs(codec); 2439 hda_exec_init_verbs(codec);
2191 /* continue to initialize... */ 2440 /* continue to initialize... */
2192 if (codec->patch_ops.init) 2441 if (codec->patch_ops.init)
2193 err = codec->patch_ops.init(codec); 2442 err = codec->patch_ops.init(codec);
2194 if (!err && codec->patch_ops.build_controls) 2443 if (!err && codec->patch_ops.build_controls)
2195 err = codec->patch_ops.build_controls(codec); 2444 err = codec->patch_ops.build_controls(codec);
2196 snd_hda_power_down(codec);
2197 if (err < 0) 2445 if (err < 0)
2198 return err; 2446 return err;
2199 return 0; 2447 return 0;
@@ -2306,12 +2554,11 @@ EXPORT_SYMBOL_HDA(snd_hda_calc_stream_format);
2306static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid, 2554static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
2307 u32 *ratesp, u64 *formatsp, unsigned int *bpsp) 2555 u32 *ratesp, u64 *formatsp, unsigned int *bpsp)
2308{ 2556{
2309 int i; 2557 unsigned int i, val, wcaps;
2310 unsigned int val, streams;
2311 2558
2312 val = 0; 2559 val = 0;
2313 if (nid != codec->afg && 2560 wcaps = get_wcaps(codec, nid);
2314 (get_wcaps(codec, nid) & AC_WCAP_FORMAT_OVRD)) { 2561 if (nid != codec->afg && (wcaps & AC_WCAP_FORMAT_OVRD)) {
2315 val = snd_hda_param_read(codec, nid, AC_PAR_PCM); 2562 val = snd_hda_param_read(codec, nid, AC_PAR_PCM);
2316 if (val == -1) 2563 if (val == -1)
2317 return -EIO; 2564 return -EIO;
@@ -2325,15 +2572,20 @@ static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
2325 if (val & (1 << i)) 2572 if (val & (1 << i))
2326 rates |= rate_bits[i].alsa_bits; 2573 rates |= rate_bits[i].alsa_bits;
2327 } 2574 }
2575 if (rates == 0) {
2576 snd_printk(KERN_ERR "hda_codec: rates == 0 "
2577 "(nid=0x%x, val=0x%x, ovrd=%i)\n",
2578 nid, val,
2579 (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0);
2580 return -EIO;
2581 }
2328 *ratesp = rates; 2582 *ratesp = rates;
2329 } 2583 }
2330 2584
2331 if (formatsp || bpsp) { 2585 if (formatsp || bpsp) {
2332 u64 formats = 0; 2586 u64 formats = 0;
2333 unsigned int bps; 2587 unsigned int streams, bps;
2334 unsigned int wcaps;
2335 2588
2336 wcaps = get_wcaps(codec, nid);
2337 streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM); 2589 streams = snd_hda_param_read(codec, nid, AC_PAR_STREAM);
2338 if (streams == -1) 2590 if (streams == -1)
2339 return -EIO; 2591 return -EIO;
@@ -2386,6 +2638,15 @@ static int snd_hda_query_supported_pcm(struct hda_codec *codec, hda_nid_t nid,
2386 formats |= SNDRV_PCM_FMTBIT_U8; 2638 formats |= SNDRV_PCM_FMTBIT_U8;
2387 bps = 8; 2639 bps = 8;
2388 } 2640 }
2641 if (formats == 0) {
2642 snd_printk(KERN_ERR "hda_codec: formats == 0 "
2643 "(nid=0x%x, val=0x%x, ovrd=%i, "
2644 "streams=0x%x)\n",
2645 nid, val,
2646 (wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0,
2647 streams);
2648 return -EIO;
2649 }
2389 if (formatsp) 2650 if (formatsp)
2390 *formatsp = formats; 2651 *formatsp = formats;
2391 if (bpsp) 2652 if (bpsp)
@@ -2501,12 +2762,16 @@ static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo,
2501static int set_pcm_default_values(struct hda_codec *codec, 2762static int set_pcm_default_values(struct hda_codec *codec,
2502 struct hda_pcm_stream *info) 2763 struct hda_pcm_stream *info)
2503{ 2764{
2765 int err;
2766
2504 /* query support PCM information from the given NID */ 2767 /* query support PCM information from the given NID */
2505 if (info->nid && (!info->rates || !info->formats)) { 2768 if (info->nid && (!info->rates || !info->formats)) {
2506 snd_hda_query_supported_pcm(codec, info->nid, 2769 err = snd_hda_query_supported_pcm(codec, info->nid,
2507 info->rates ? NULL : &info->rates, 2770 info->rates ? NULL : &info->rates,
2508 info->formats ? NULL : &info->formats, 2771 info->formats ? NULL : &info->formats,
2509 info->maxbps ? NULL : &info->maxbps); 2772 info->maxbps ? NULL : &info->maxbps);
2773 if (err < 0)
2774 return err;
2510 } 2775 }
2511 if (info->ops.open == NULL) 2776 if (info->ops.open == NULL)
2512 info->ops.open = hda_pcm_default_open_close; 2777 info->ops.open = hda_pcm_default_open_close;
@@ -2549,13 +2814,10 @@ static int get_empty_pcm_device(struct hda_bus *bus, int type)
2549 for (i = 0; i < ARRAY_SIZE(audio_idx); i++) { 2814 for (i = 0; i < ARRAY_SIZE(audio_idx); i++) {
2550 dev = audio_idx[i]; 2815 dev = audio_idx[i];
2551 if (!test_bit(dev, bus->pcm_dev_bits)) 2816 if (!test_bit(dev, bus->pcm_dev_bits))
2552 break; 2817 goto ok;
2553 }
2554 if (i >= ARRAY_SIZE(audio_idx)) {
2555 snd_printk(KERN_WARNING "Too many audio devices\n");
2556 return -EAGAIN;
2557 } 2818 }
2558 break; 2819 snd_printk(KERN_WARNING "Too many audio devices\n");
2820 return -EAGAIN;
2559 case HDA_PCM_TYPE_SPDIF: 2821 case HDA_PCM_TYPE_SPDIF:
2560 case HDA_PCM_TYPE_HDMI: 2822 case HDA_PCM_TYPE_HDMI:
2561 case HDA_PCM_TYPE_MODEM: 2823 case HDA_PCM_TYPE_MODEM:
@@ -2570,6 +2832,7 @@ static int get_empty_pcm_device(struct hda_bus *bus, int type)
2570 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type); 2832 snd_printk(KERN_WARNING "Invalid PCM type %d\n", type);
2571 return -EINVAL; 2833 return -EINVAL;
2572 } 2834 }
2835 ok:
2573 set_bit(dev, bus->pcm_dev_bits); 2836 set_bit(dev, bus->pcm_dev_bits);
2574 return dev; 2837 return dev;
2575} 2838}
@@ -2606,24 +2869,36 @@ int snd_hda_codec_build_pcms(struct hda_codec *codec)
2606 if (!codec->patch_ops.build_pcms) 2869 if (!codec->patch_ops.build_pcms)
2607 return 0; 2870 return 0;
2608 err = codec->patch_ops.build_pcms(codec); 2871 err = codec->patch_ops.build_pcms(codec);
2609 if (err < 0) 2872 if (err < 0) {
2610 return err; 2873 printk(KERN_ERR "hda_codec: cannot build PCMs"
2874 "for #%d (error %d)\n", codec->addr, err);
2875 err = snd_hda_codec_reset(codec);
2876 if (err < 0) {
2877 printk(KERN_ERR
2878 "hda_codec: cannot revert codec\n");
2879 return err;
2880 }
2881 }
2611 } 2882 }
2612 for (pcm = 0; pcm < codec->num_pcms; pcm++) { 2883 for (pcm = 0; pcm < codec->num_pcms; pcm++) {
2613 struct hda_pcm *cpcm = &codec->pcm_info[pcm]; 2884 struct hda_pcm *cpcm = &codec->pcm_info[pcm];
2614 int dev; 2885 int dev;
2615 2886
2616 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams) 2887 if (!cpcm->stream[0].substreams && !cpcm->stream[1].substreams)
2617 return 0; /* no substreams assigned */ 2888 continue; /* no substreams assigned */
2618 2889
2619 if (!cpcm->pcm) { 2890 if (!cpcm->pcm) {
2620 dev = get_empty_pcm_device(codec->bus, cpcm->pcm_type); 2891 dev = get_empty_pcm_device(codec->bus, cpcm->pcm_type);
2621 if (dev < 0) 2892 if (dev < 0)
2622 return 0; 2893 continue; /* no fatal error */
2623 cpcm->device = dev; 2894 cpcm->device = dev;
2624 err = snd_hda_attach_pcm(codec, cpcm); 2895 err = snd_hda_attach_pcm(codec, cpcm);
2625 if (err < 0) 2896 if (err < 0) {
2626 return err; 2897 printk(KERN_ERR "hda_codec: cannot attach "
2898 "PCM stream %d for codec #%d\n",
2899 dev, codec->addr);
2900 continue; /* no fatal error */
2901 }
2627 } 2902 }
2628 } 2903 }
2629 return 0; 2904 return 0;
@@ -3324,8 +3599,7 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
3324 if (ignore_nids && is_in_nid_list(nid, ignore_nids)) 3599 if (ignore_nids && is_in_nid_list(nid, ignore_nids))
3325 continue; 3600 continue;
3326 3601
3327 def_conf = snd_hda_codec_read(codec, nid, 0, 3602 def_conf = snd_hda_codec_get_pincfg(codec, nid);
3328 AC_VERB_GET_CONFIG_DEFAULT, 0);
3329 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) 3603 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3330 continue; 3604 continue;
3331 loc = get_defcfg_location(def_conf); 3605 loc = get_defcfg_location(def_conf);
@@ -3401,10 +3675,22 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
3401 cfg->input_pins[AUTO_PIN_AUX] = nid; 3675 cfg->input_pins[AUTO_PIN_AUX] = nid;
3402 break; 3676 break;
3403 case AC_JACK_SPDIF_OUT: 3677 case AC_JACK_SPDIF_OUT:
3404 cfg->dig_out_pin = nid; 3678 case AC_JACK_DIG_OTHER_OUT:
3679 if (cfg->dig_outs >= ARRAY_SIZE(cfg->dig_out_pins))
3680 continue;
3681 cfg->dig_out_pins[cfg->dig_outs] = nid;
3682 cfg->dig_out_type[cfg->dig_outs] =
3683 (loc == AC_JACK_LOC_HDMI) ?
3684 HDA_PCM_TYPE_HDMI : HDA_PCM_TYPE_SPDIF;
3685 cfg->dig_outs++;
3405 break; 3686 break;
3406 case AC_JACK_SPDIF_IN: 3687 case AC_JACK_SPDIF_IN:
3688 case AC_JACK_DIG_OTHER_IN:
3407 cfg->dig_in_pin = nid; 3689 cfg->dig_in_pin = nid;
3690 if (loc == AC_JACK_LOC_HDMI)
3691 cfg->dig_in_type = HDA_PCM_TYPE_HDMI;
3692 else
3693 cfg->dig_in_type = HDA_PCM_TYPE_SPDIF;
3408 break; 3694 break;
3409 } 3695 }
3410 } 3696 }
@@ -3510,6 +3796,9 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
3510 cfg->hp_pins[1], cfg->hp_pins[2], 3796 cfg->hp_pins[1], cfg->hp_pins[2],
3511 cfg->hp_pins[3], cfg->hp_pins[4]); 3797 cfg->hp_pins[3], cfg->hp_pins[4]);
3512 snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin); 3798 snd_printd(" mono: mono_out=0x%x\n", cfg->mono_out_pin);
3799 if (cfg->dig_outs)
3800 snd_printd(" dig-out=0x%x/0x%x\n",
3801 cfg->dig_out_pins[0], cfg->dig_out_pins[1]);
3513 snd_printd(" inputs: mic=0x%x, fmic=0x%x, line=0x%x, fline=0x%x," 3802 snd_printd(" inputs: mic=0x%x, fmic=0x%x, line=0x%x, fline=0x%x,"
3514 " cd=0x%x, aux=0x%x\n", 3803 " cd=0x%x, aux=0x%x\n",
3515 cfg->input_pins[AUTO_PIN_MIC], 3804 cfg->input_pins[AUTO_PIN_MIC],
@@ -3518,6 +3807,8 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
3518 cfg->input_pins[AUTO_PIN_FRONT_LINE], 3807 cfg->input_pins[AUTO_PIN_FRONT_LINE],
3519 cfg->input_pins[AUTO_PIN_CD], 3808 cfg->input_pins[AUTO_PIN_CD],
3520 cfg->input_pins[AUTO_PIN_AUX]); 3809 cfg->input_pins[AUTO_PIN_AUX]);
3810 if (cfg->dig_in_pin)
3811 snd_printd(" dig-in=0x%x\n", cfg->dig_in_pin);
3521 3812
3522 return 0; 3813 return 0;
3523} 3814}
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index 09a332ada0c6..2fdecf4b0eb6 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -739,6 +739,7 @@ struct hda_codec {
739 hda_nid_t mfg; /* MFG node id */ 739 hda_nid_t mfg; /* MFG node id */
740 740
741 /* ids */ 741 /* ids */
742 u32 function_id;
742 u32 vendor_id; 743 u32 vendor_id;
743 u32 subsystem_id; 744 u32 subsystem_id;
744 u32 revision_id; 745 u32 revision_id;
@@ -778,11 +779,14 @@ struct hda_codec {
778 unsigned short spdif_ctls; /* SPDIF control bits */ 779 unsigned short spdif_ctls; /* SPDIF control bits */
779 unsigned int spdif_in_enable; /* SPDIF input enable? */ 780 unsigned int spdif_in_enable; /* SPDIF input enable? */
780 hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */ 781 hda_nid_t *slave_dig_outs; /* optional digital out slave widgets */
782 struct snd_array init_pins; /* initial (BIOS) pin configurations */
783 struct snd_array driver_pins; /* pin configs set by codec parser */
781 784
782#ifdef CONFIG_SND_HDA_HWDEP 785#ifdef CONFIG_SND_HDA_HWDEP
783 struct snd_hwdep *hwdep; /* assigned hwdep device */ 786 struct snd_hwdep *hwdep; /* assigned hwdep device */
784 struct snd_array init_verbs; /* additional init verbs */ 787 struct snd_array init_verbs; /* additional init verbs */
785 struct snd_array hints; /* additional hints */ 788 struct snd_array hints; /* additional hints */
789 struct snd_array user_pins; /* default pin configs to override */
786#endif 790#endif
787 791
788 /* misc flags */ 792 /* misc flags */
@@ -790,6 +794,9 @@ struct hda_codec {
790 * status change 794 * status change
791 * (e.g. Realtek codecs) 795 * (e.g. Realtek codecs)
792 */ 796 */
797 unsigned int pin_amp_workaround:1; /* pin out-amp takes index
798 * (e.g. Conexant codecs)
799 */
793#ifdef CONFIG_SND_HDA_POWER_SAVE 800#ifdef CONFIG_SND_HDA_POWER_SAVE
794 unsigned int power_on :1; /* current (global) power-state */ 801 unsigned int power_on :1; /* current (global) power-state */
795 unsigned int power_transition :1; /* power-state in transition */ 802 unsigned int power_transition :1; /* power-state in transition */
@@ -855,6 +862,18 @@ void snd_hda_codec_resume_cache(struct hda_codec *codec);
855#define snd_hda_sequence_write_cache snd_hda_sequence_write 862#define snd_hda_sequence_write_cache snd_hda_sequence_write
856#endif 863#endif
857 864
865/* the struct for codec->pin_configs */
866struct hda_pincfg {
867 hda_nid_t nid;
868 unsigned int cfg;
869};
870
871unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid);
872int snd_hda_codec_set_pincfg(struct hda_codec *codec, hda_nid_t nid,
873 unsigned int cfg);
874int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
875 hda_nid_t nid, unsigned int cfg); /* for hwdep */
876
858/* 877/*
859 * Mixer 878 * Mixer
860 */ 879 */
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index 65745e96dc70..1d5797a96682 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -144,9 +144,9 @@ static int add_new_node(struct hda_codec *codec, struct hda_gspec *spec, hda_nid
144 node->type = (node->wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 144 node->type = (node->wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
145 145
146 if (node->type == AC_WID_PIN) { 146 if (node->type == AC_WID_PIN) {
147 node->pin_caps = snd_hda_param_read(codec, node->nid, AC_PAR_PIN_CAP); 147 node->pin_caps = snd_hda_query_pin_caps(codec, node->nid);
148 node->pin_ctl = snd_hda_codec_read(codec, node->nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 148 node->pin_ctl = snd_hda_codec_read(codec, node->nid, 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
149 node->def_cfg = snd_hda_codec_read(codec, node->nid, 0, AC_VERB_GET_CONFIG_DEFAULT, 0); 149 node->def_cfg = snd_hda_codec_get_pincfg(codec, node->nid);
150 } 150 }
151 151
152 if (node->wid_caps & AC_WCAP_OUT_AMP) { 152 if (node->wid_caps & AC_WCAP_OUT_AMP) {
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index 4ae51dcb81af..1c57505c2874 100644
--- a/sound/pci/hda/hda_hwdep.c
+++ b/sound/pci/hda/hda_hwdep.c
@@ -30,6 +30,12 @@
30#include <sound/hda_hwdep.h> 30#include <sound/hda_hwdep.h>
31#include <sound/minors.h> 31#include <sound/minors.h>
32 32
33/* hint string pair */
34struct hda_hint {
35 const char *key;
36 const char *val; /* contained in the same alloc as key */
37};
38
33/* 39/*
34 * write/read an out-of-bound verb 40 * write/read an out-of-bound verb
35 */ 41 */
@@ -99,16 +105,17 @@ static int hda_hwdep_open(struct snd_hwdep *hw, struct file *file)
99 105
100static void clear_hwdep_elements(struct hda_codec *codec) 106static void clear_hwdep_elements(struct hda_codec *codec)
101{ 107{
102 char **head;
103 int i; 108 int i;
104 109
105 /* clear init verbs */ 110 /* clear init verbs */
106 snd_array_free(&codec->init_verbs); 111 snd_array_free(&codec->init_verbs);
107 /* clear hints */ 112 /* clear hints */
108 head = codec->hints.list; 113 for (i = 0; i < codec->hints.used; i++) {
109 for (i = 0; i < codec->hints.used; i++, head++) 114 struct hda_hint *hint = snd_array_elem(&codec->hints, i);
110 kfree(*head); 115 kfree(hint->key); /* we don't need to free hint->val */
116 }
111 snd_array_free(&codec->hints); 117 snd_array_free(&codec->hints);
118 snd_array_free(&codec->user_pins);
112} 119}
113 120
114static void hwdep_free(struct snd_hwdep *hwdep) 121static void hwdep_free(struct snd_hwdep *hwdep)
@@ -140,7 +147,8 @@ int /*__devinit*/ snd_hda_create_hwdep(struct hda_codec *codec)
140#endif 147#endif
141 148
142 snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32); 149 snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32);
143 snd_array_init(&codec->hints, sizeof(char *), 32); 150 snd_array_init(&codec->hints, sizeof(struct hda_hint), 32);
151 snd_array_init(&codec->user_pins, sizeof(struct hda_pincfg), 16);
144 152
145 return 0; 153 return 0;
146} 154}
@@ -153,7 +161,13 @@ int /*__devinit*/ snd_hda_create_hwdep(struct hda_codec *codec)
153 161
154static int clear_codec(struct hda_codec *codec) 162static int clear_codec(struct hda_codec *codec)
155{ 163{
156 snd_hda_codec_reset(codec); 164 int err;
165
166 err = snd_hda_codec_reset(codec);
167 if (err < 0) {
168 snd_printk(KERN_ERR "The codec is being used, can't free.\n");
169 return err;
170 }
157 clear_hwdep_elements(codec); 171 clear_hwdep_elements(codec);
158 return 0; 172 return 0;
159} 173}
@@ -162,20 +176,29 @@ static int reconfig_codec(struct hda_codec *codec)
162{ 176{
163 int err; 177 int err;
164 178
179 snd_hda_power_up(codec);
165 snd_printk(KERN_INFO "hda-codec: reconfiguring\n"); 180 snd_printk(KERN_INFO "hda-codec: reconfiguring\n");
166 snd_hda_codec_reset(codec); 181 err = snd_hda_codec_reset(codec);
182 if (err < 0) {
183 snd_printk(KERN_ERR
184 "The codec is being used, can't reconfigure.\n");
185 goto error;
186 }
167 err = snd_hda_codec_configure(codec); 187 err = snd_hda_codec_configure(codec);
168 if (err < 0) 188 if (err < 0)
169 return err; 189 goto error;
170 /* rebuild PCMs */ 190 /* rebuild PCMs */
171 err = snd_hda_codec_build_pcms(codec); 191 err = snd_hda_codec_build_pcms(codec);
172 if (err < 0) 192 if (err < 0)
173 return err; 193 goto error;
174 /* rebuild mixers */ 194 /* rebuild mixers */
175 err = snd_hda_codec_build_controls(codec); 195 err = snd_hda_codec_build_controls(codec);
176 if (err < 0) 196 if (err < 0)
177 return err; 197 goto error;
178 return snd_card_register(codec->bus->card); 198 err = snd_card_register(codec->bus->card);
199 error:
200 snd_hda_power_down(codec);
201 return err;
179} 202}
180 203
181/* 204/*
@@ -271,6 +294,22 @@ static ssize_t type##_store(struct device *dev, \
271CODEC_ACTION_STORE(reconfig); 294CODEC_ACTION_STORE(reconfig);
272CODEC_ACTION_STORE(clear); 295CODEC_ACTION_STORE(clear);
273 296
297static ssize_t init_verbs_show(struct device *dev,
298 struct device_attribute *attr,
299 char *buf)
300{
301 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
302 struct hda_codec *codec = hwdep->private_data;
303 int i, len = 0;
304 for (i = 0; i < codec->init_verbs.used; i++) {
305 struct hda_verb *v = snd_array_elem(&codec->init_verbs, i);
306 len += snprintf(buf + len, PAGE_SIZE - len,
307 "0x%02x 0x%03x 0x%04x\n",
308 v->nid, v->verb, v->param);
309 }
310 return len;
311}
312
274static ssize_t init_verbs_store(struct device *dev, 313static ssize_t init_verbs_store(struct device *dev,
275 struct device_attribute *attr, 314 struct device_attribute *attr,
276 const char *buf, size_t count) 315 const char *buf, size_t count)
@@ -293,26 +332,157 @@ static ssize_t init_verbs_store(struct device *dev,
293 return count; 332 return count;
294} 333}
295 334
335static ssize_t hints_show(struct device *dev,
336 struct device_attribute *attr,
337 char *buf)
338{
339 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
340 struct hda_codec *codec = hwdep->private_data;
341 int i, len = 0;
342 for (i = 0; i < codec->hints.used; i++) {
343 struct hda_hint *hint = snd_array_elem(&codec->hints, i);
344 len += snprintf(buf + len, PAGE_SIZE - len,
345 "%s = %s\n", hint->key, hint->val);
346 }
347 return len;
348}
349
350static struct hda_hint *get_hint(struct hda_codec *codec, const char *key)
351{
352 int i;
353
354 for (i = 0; i < codec->hints.used; i++) {
355 struct hda_hint *hint = snd_array_elem(&codec->hints, i);
356 if (!strcmp(hint->key, key))
357 return hint;
358 }
359 return NULL;
360}
361
362static void remove_trail_spaces(char *str)
363{
364 char *p;
365 if (!*str)
366 return;
367 p = str + strlen(str) - 1;
368 for (; isspace(*p); p--) {
369 *p = 0;
370 if (p == str)
371 return;
372 }
373}
374
375#define MAX_HINTS 1024
376
296static ssize_t hints_store(struct device *dev, 377static ssize_t hints_store(struct device *dev,
297 struct device_attribute *attr, 378 struct device_attribute *attr,
298 const char *buf, size_t count) 379 const char *buf, size_t count)
299{ 380{
300 struct snd_hwdep *hwdep = dev_get_drvdata(dev); 381 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
301 struct hda_codec *codec = hwdep->private_data; 382 struct hda_codec *codec = hwdep->private_data;
302 char *p; 383 char *key, *val;
303 char **hint; 384 struct hda_hint *hint;
304 385
305 if (!*buf || isspace(*buf) || *buf == '#' || *buf == '\n') 386 while (isspace(*buf))
387 buf++;
388 if (!*buf || *buf == '#' || *buf == '\n')
306 return count; 389 return count;
307 p = kstrndup_noeol(buf, 1024); 390 if (*buf == '=')
308 if (!p) 391 return -EINVAL;
392 key = kstrndup_noeol(buf, 1024);
393 if (!key)
309 return -ENOMEM; 394 return -ENOMEM;
310 hint = snd_array_new(&codec->hints); 395 /* extract key and val */
396 val = strchr(key, '=');
397 if (!val) {
398 kfree(key);
399 return -EINVAL;
400 }
401 *val++ = 0;
402 while (isspace(*val))
403 val++;
404 remove_trail_spaces(key);
405 remove_trail_spaces(val);
406 hint = get_hint(codec, key);
407 if (hint) {
408 /* replace */
409 kfree(hint->key);
410 hint->key = key;
411 hint->val = val;
412 return count;
413 }
414 /* allocate a new hint entry */
415 if (codec->hints.used >= MAX_HINTS)
416 hint = NULL;
417 else
418 hint = snd_array_new(&codec->hints);
311 if (!hint) { 419 if (!hint) {
312 kfree(p); 420 kfree(key);
313 return -ENOMEM; 421 return -ENOMEM;
314 } 422 }
315 *hint = p; 423 hint->key = key;
424 hint->val = val;
425 return count;
426}
427
428static ssize_t pin_configs_show(struct hda_codec *codec,
429 struct snd_array *list,
430 char *buf)
431{
432 int i, len = 0;
433 for (i = 0; i < list->used; i++) {
434 struct hda_pincfg *pin = snd_array_elem(list, i);
435 len += sprintf(buf + len, "0x%02x 0x%08x\n",
436 pin->nid, pin->cfg);
437 }
438 return len;
439}
440
441static ssize_t init_pin_configs_show(struct device *dev,
442 struct device_attribute *attr,
443 char *buf)
444{
445 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
446 struct hda_codec *codec = hwdep->private_data;
447 return pin_configs_show(codec, &codec->init_pins, buf);
448}
449
450static ssize_t user_pin_configs_show(struct device *dev,
451 struct device_attribute *attr,
452 char *buf)
453{
454 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
455 struct hda_codec *codec = hwdep->private_data;
456 return pin_configs_show(codec, &codec->user_pins, buf);
457}
458
459static ssize_t driver_pin_configs_show(struct device *dev,
460 struct device_attribute *attr,
461 char *buf)
462{
463 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
464 struct hda_codec *codec = hwdep->private_data;
465 return pin_configs_show(codec, &codec->driver_pins, buf);
466}
467
468#define MAX_PIN_CONFIGS 32
469
470static ssize_t user_pin_configs_store(struct device *dev,
471 struct device_attribute *attr,
472 const char *buf, size_t count)
473{
474 struct snd_hwdep *hwdep = dev_get_drvdata(dev);
475 struct hda_codec *codec = hwdep->private_data;
476 int nid, cfg;
477 int err;
478
479 if (sscanf(buf, "%i %i", &nid, &cfg) != 2)
480 return -EINVAL;
481 if (!nid)
482 return -EINVAL;
483 err = snd_hda_add_pincfg(codec, &codec->user_pins, nid, cfg);
484 if (err < 0)
485 return err;
316 return count; 486 return count;
317} 487}
318 488
@@ -331,8 +501,11 @@ static struct device_attribute codec_attrs[] = {
331 CODEC_ATTR_RO(mfg), 501 CODEC_ATTR_RO(mfg),
332 CODEC_ATTR_RW(name), 502 CODEC_ATTR_RW(name),
333 CODEC_ATTR_RW(modelname), 503 CODEC_ATTR_RW(modelname),
334 CODEC_ATTR_WO(init_verbs), 504 CODEC_ATTR_RW(init_verbs),
335 CODEC_ATTR_WO(hints), 505 CODEC_ATTR_RW(hints),
506 CODEC_ATTR_RO(init_pin_configs),
507 CODEC_ATTR_RW(user_pin_configs),
508 CODEC_ATTR_RO(driver_pin_configs),
336 CODEC_ATTR_WO(reconfig), 509 CODEC_ATTR_WO(reconfig),
337 CODEC_ATTR_WO(clear), 510 CODEC_ATTR_WO(clear),
338}; 511};
@@ -351,4 +524,29 @@ int snd_hda_hwdep_add_sysfs(struct hda_codec *codec)
351 return 0; 524 return 0;
352} 525}
353 526
527/*
528 * Look for hint string
529 */
530const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
531{
532 struct hda_hint *hint = get_hint(codec, key);
533 return hint ? hint->val : NULL;
534}
535EXPORT_SYMBOL_HDA(snd_hda_get_hint);
536
537int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
538{
539 const char *p = snd_hda_get_hint(codec, key);
540 if (!p || !*p)
541 return -ENOENT;
542 switch (toupper(*p)) {
543 case 'T': /* true */
544 case 'Y': /* yes */
545 case '1':
546 return 1;
547 }
548 return 0;
549}
550EXPORT_SYMBOL_HDA(snd_hda_get_bool_hint);
551
354#endif /* CONFIG_SND_HDA_RECONFIG */ 552#endif /* CONFIG_SND_HDA_RECONFIG */
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index f3b5723c2859..30829ee920c3 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -381,6 +381,7 @@ struct azx {
381 381
382 /* HD codec */ 382 /* HD codec */
383 unsigned short codec_mask; 383 unsigned short codec_mask;
384 int codec_probe_mask; /* copied from probe_mask option */
384 struct hda_bus *bus; 385 struct hda_bus *bus;
385 386
386 /* CORB/RIRB */ 387 /* CORB/RIRB */
@@ -858,13 +859,18 @@ static void azx_stream_start(struct azx *chip, struct azx_dev *azx_dev)
858 SD_CTL_DMA_START | SD_INT_MASK); 859 SD_CTL_DMA_START | SD_INT_MASK);
859} 860}
860 861
861/* stop a stream */ 862/* stop DMA */
862static void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev) 863static void azx_stream_clear(struct azx *chip, struct azx_dev *azx_dev)
863{ 864{
864 /* stop DMA */
865 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) & 865 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) &
866 ~(SD_CTL_DMA_START | SD_INT_MASK)); 866 ~(SD_CTL_DMA_START | SD_INT_MASK));
867 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */ 867 azx_sd_writeb(azx_dev, SD_STS, SD_INT_MASK); /* to be sure */
868}
869
870/* stop a stream */
871static void azx_stream_stop(struct azx *chip, struct azx_dev *azx_dev)
872{
873 azx_stream_clear(chip, azx_dev);
868 /* disable SIE */ 874 /* disable SIE */
869 azx_writeb(chip, INTCTL, 875 azx_writeb(chip, INTCTL,
870 azx_readb(chip, INTCTL) & ~(1 << azx_dev->index)); 876 azx_readb(chip, INTCTL) & ~(1 << azx_dev->index));
@@ -1075,8 +1081,7 @@ static int azx_setup_periods(struct azx *chip,
1075 azx_sd_writel(azx_dev, SD_BDLPL, 0); 1081 azx_sd_writel(azx_dev, SD_BDLPL, 0);
1076 azx_sd_writel(azx_dev, SD_BDLPU, 0); 1082 azx_sd_writel(azx_dev, SD_BDLPU, 0);
1077 1083
1078 period_bytes = snd_pcm_lib_period_bytes(substream); 1084 period_bytes = azx_dev->period_bytes;
1079 azx_dev->period_bytes = period_bytes;
1080 periods = azx_dev->bufsize / period_bytes; 1085 periods = azx_dev->bufsize / period_bytes;
1081 1086
1082 /* program the initial BDL entries */ 1087 /* program the initial BDL entries */
@@ -1123,24 +1128,17 @@ static int azx_setup_periods(struct azx *chip,
1123 error: 1128 error:
1124 snd_printk(KERN_ERR "Too many BDL entries: buffer=%d, period=%d\n", 1129 snd_printk(KERN_ERR "Too many BDL entries: buffer=%d, period=%d\n",
1125 azx_dev->bufsize, period_bytes); 1130 azx_dev->bufsize, period_bytes);
1126 /* reset */
1127 azx_sd_writel(azx_dev, SD_BDLPL, 0);
1128 azx_sd_writel(azx_dev, SD_BDLPU, 0);
1129 return -EINVAL; 1131 return -EINVAL;
1130} 1132}
1131 1133
1132/* 1134/* reset stream */
1133 * set up the SD for streaming 1135static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev)
1134 */
1135static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
1136{ 1136{
1137 unsigned char val; 1137 unsigned char val;
1138 int timeout; 1138 int timeout;
1139 1139
1140 /* make sure the run bit is zero for SD */ 1140 azx_stream_clear(chip, azx_dev);
1141 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) & 1141
1142 ~SD_CTL_DMA_START);
1143 /* reset stream */
1144 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) | 1142 azx_sd_writeb(azx_dev, SD_CTL, azx_sd_readb(azx_dev, SD_CTL) |
1145 SD_CTL_STREAM_RESET); 1143 SD_CTL_STREAM_RESET);
1146 udelay(3); 1144 udelay(3);
@@ -1157,7 +1155,15 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
1157 while (((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) && 1155 while (((val = azx_sd_readb(azx_dev, SD_CTL)) & SD_CTL_STREAM_RESET) &&
1158 --timeout) 1156 --timeout)
1159 ; 1157 ;
1158}
1160 1159
1160/*
1161 * set up the SD for streaming
1162 */
1163static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
1164{
1165 /* make sure the run bit is zero for SD */
1166 azx_stream_clear(chip, azx_dev);
1161 /* program the stream_tag */ 1167 /* program the stream_tag */
1162 azx_sd_writel(azx_dev, SD_CTL, 1168 azx_sd_writel(azx_dev, SD_CTL,
1163 (azx_sd_readl(azx_dev, SD_CTL) & ~SD_CTL_STREAM_TAG_MASK)| 1169 (azx_sd_readl(azx_dev, SD_CTL) & ~SD_CTL_STREAM_TAG_MASK)|
@@ -1228,7 +1234,6 @@ static unsigned int azx_max_codecs[AZX_NUM_DRIVERS] __devinitdata = {
1228}; 1234};
1229 1235
1230static int __devinit azx_codec_create(struct azx *chip, const char *model, 1236static int __devinit azx_codec_create(struct azx *chip, const char *model,
1231 unsigned int codec_probe_mask,
1232 int no_init) 1237 int no_init)
1233{ 1238{
1234 struct hda_bus_template bus_temp; 1239 struct hda_bus_template bus_temp;
@@ -1261,7 +1266,7 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model,
1261 1266
1262 /* First try to probe all given codec slots */ 1267 /* First try to probe all given codec slots */
1263 for (c = 0; c < max_slots; c++) { 1268 for (c = 0; c < max_slots; c++) {
1264 if ((chip->codec_mask & (1 << c)) & codec_probe_mask) { 1269 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
1265 if (probe_codec(chip, c) < 0) { 1270 if (probe_codec(chip, c) < 0) {
1266 /* Some BIOSen give you wrong codec addresses 1271 /* Some BIOSen give you wrong codec addresses
1267 * that don't exist 1272 * that don't exist
@@ -1285,7 +1290,7 @@ static int __devinit azx_codec_create(struct azx *chip, const char *model,
1285 1290
1286 /* Then create codec instances */ 1291 /* Then create codec instances */
1287 for (c = 0; c < max_slots; c++) { 1292 for (c = 0; c < max_slots; c++) {
1288 if ((chip->codec_mask & (1 << c)) & codec_probe_mask) { 1293 if ((chip->codec_mask & (1 << c)) & chip->codec_probe_mask) {
1289 struct hda_codec *codec; 1294 struct hda_codec *codec;
1290 err = snd_hda_codec_new(chip->bus, c, !no_init, &codec); 1295 err = snd_hda_codec_new(chip->bus, c, !no_init, &codec);
1291 if (err < 0) 1296 if (err < 0)
@@ -1403,6 +1408,8 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
1403 runtime->private_data = azx_dev; 1408 runtime->private_data = azx_dev;
1404 snd_pcm_set_sync(substream); 1409 snd_pcm_set_sync(substream);
1405 mutex_unlock(&chip->open_mutex); 1410 mutex_unlock(&chip->open_mutex);
1411
1412 azx_stream_reset(chip, azx_dev);
1406 return 0; 1413 return 0;
1407} 1414}
1408 1415
@@ -1429,6 +1436,11 @@ static int azx_pcm_close(struct snd_pcm_substream *substream)
1429static int azx_pcm_hw_params(struct snd_pcm_substream *substream, 1436static int azx_pcm_hw_params(struct snd_pcm_substream *substream,
1430 struct snd_pcm_hw_params *hw_params) 1437 struct snd_pcm_hw_params *hw_params)
1431{ 1438{
1439 struct azx_dev *azx_dev = get_azx_dev(substream);
1440
1441 azx_dev->bufsize = 0;
1442 azx_dev->period_bytes = 0;
1443 azx_dev->format_val = 0;
1432 return snd_pcm_lib_malloc_pages(substream, 1444 return snd_pcm_lib_malloc_pages(substream,
1433 params_buffer_bytes(hw_params)); 1445 params_buffer_bytes(hw_params));
1434} 1446}
@@ -1443,6 +1455,9 @@ static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
1443 azx_sd_writel(azx_dev, SD_BDLPL, 0); 1455 azx_sd_writel(azx_dev, SD_BDLPL, 0);
1444 azx_sd_writel(azx_dev, SD_BDLPU, 0); 1456 azx_sd_writel(azx_dev, SD_BDLPU, 0);
1445 azx_sd_writel(azx_dev, SD_CTL, 0); 1457 azx_sd_writel(azx_dev, SD_CTL, 0);
1458 azx_dev->bufsize = 0;
1459 azx_dev->period_bytes = 0;
1460 azx_dev->format_val = 0;
1446 1461
1447 hinfo->ops.cleanup(hinfo, apcm->codec, substream); 1462 hinfo->ops.cleanup(hinfo, apcm->codec, substream);
1448 1463
@@ -1456,23 +1471,37 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1456 struct azx_dev *azx_dev = get_azx_dev(substream); 1471 struct azx_dev *azx_dev = get_azx_dev(substream);
1457 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 1472 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
1458 struct snd_pcm_runtime *runtime = substream->runtime; 1473 struct snd_pcm_runtime *runtime = substream->runtime;
1474 unsigned int bufsize, period_bytes, format_val;
1475 int err;
1459 1476
1460 azx_dev->bufsize = snd_pcm_lib_buffer_bytes(substream); 1477 format_val = snd_hda_calc_stream_format(runtime->rate,
1461 azx_dev->format_val = snd_hda_calc_stream_format(runtime->rate, 1478 runtime->channels,
1462 runtime->channels, 1479 runtime->format,
1463 runtime->format, 1480 hinfo->maxbps);
1464 hinfo->maxbps); 1481 if (!format_val) {
1465 if (!azx_dev->format_val) {
1466 snd_printk(KERN_ERR SFX 1482 snd_printk(KERN_ERR SFX
1467 "invalid format_val, rate=%d, ch=%d, format=%d\n", 1483 "invalid format_val, rate=%d, ch=%d, format=%d\n",
1468 runtime->rate, runtime->channels, runtime->format); 1484 runtime->rate, runtime->channels, runtime->format);
1469 return -EINVAL; 1485 return -EINVAL;
1470 } 1486 }
1471 1487
1488 bufsize = snd_pcm_lib_buffer_bytes(substream);
1489 period_bytes = snd_pcm_lib_period_bytes(substream);
1490
1472 snd_printdd("azx_pcm_prepare: bufsize=0x%x, format=0x%x\n", 1491 snd_printdd("azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
1473 azx_dev->bufsize, azx_dev->format_val); 1492 bufsize, format_val);
1474 if (azx_setup_periods(chip, substream, azx_dev) < 0) 1493
1475 return -EINVAL; 1494 if (bufsize != azx_dev->bufsize ||
1495 period_bytes != azx_dev->period_bytes ||
1496 format_val != azx_dev->format_val) {
1497 azx_dev->bufsize = bufsize;
1498 azx_dev->period_bytes = period_bytes;
1499 azx_dev->format_val = format_val;
1500 err = azx_setup_periods(chip, substream, azx_dev);
1501 if (err < 0)
1502 return err;
1503 }
1504
1476 azx_setup_controller(chip, azx_dev); 1505 azx_setup_controller(chip, azx_dev);
1477 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 1506 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1478 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1; 1507 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;
@@ -2100,25 +2129,36 @@ static struct snd_pci_quirk probe_mask_list[] __devinitdata = {
2100 SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01), 2129 SND_PCI_QUIRK(0x1028, 0x20ac, "Dell Studio Desktop", 0x01),
2101 /* including bogus ALC268 in slot#2 that conflicts with ALC888 */ 2130 /* including bogus ALC268 in slot#2 that conflicts with ALC888 */
2102 SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01), 2131 SND_PCI_QUIRK(0x17c0, 0x4085, "Medion MD96630", 0x01),
2103 /* conflict of ALC268 in slot#3 (digital I/O); a temporary fix */ 2132 /* forced codec slots */
2104 SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba laptop", 0x03), 2133 SND_PCI_QUIRK(0x1046, 0x1262, "ASUS W5F", 0x103),
2105 {} 2134 {}
2106}; 2135};
2107 2136
2137#define AZX_FORCE_CODEC_MASK 0x100
2138
2108static void __devinit check_probe_mask(struct azx *chip, int dev) 2139static void __devinit check_probe_mask(struct azx *chip, int dev)
2109{ 2140{
2110 const struct snd_pci_quirk *q; 2141 const struct snd_pci_quirk *q;
2111 2142
2112 if (probe_mask[dev] == -1) { 2143 chip->codec_probe_mask = probe_mask[dev];
2144 if (chip->codec_probe_mask == -1) {
2113 q = snd_pci_quirk_lookup(chip->pci, probe_mask_list); 2145 q = snd_pci_quirk_lookup(chip->pci, probe_mask_list);
2114 if (q) { 2146 if (q) {
2115 printk(KERN_INFO 2147 printk(KERN_INFO
2116 "hda_intel: probe_mask set to 0x%x " 2148 "hda_intel: probe_mask set to 0x%x "
2117 "for device %04x:%04x\n", 2149 "for device %04x:%04x\n",
2118 q->value, q->subvendor, q->subdevice); 2150 q->value, q->subvendor, q->subdevice);
2119 probe_mask[dev] = q->value; 2151 chip->codec_probe_mask = q->value;
2120 } 2152 }
2121 } 2153 }
2154
2155 /* check forced option */
2156 if (chip->codec_probe_mask != -1 &&
2157 (chip->codec_probe_mask & AZX_FORCE_CODEC_MASK)) {
2158 chip->codec_mask = chip->codec_probe_mask & 0xff;
2159 printk(KERN_INFO "hda_intel: codec_mask forced to 0x%x\n",
2160 chip->codec_mask);
2161 }
2122} 2162}
2123 2163
2124 2164
@@ -2347,10 +2387,10 @@ static int __devinit azx_probe(struct pci_dev *pci,
2347 return -ENOENT; 2387 return -ENOENT;
2348 } 2388 }
2349 2389
2350 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 2390 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2351 if (!card) { 2391 if (err < 0) {
2352 snd_printk(KERN_ERR SFX "Error creating card!\n"); 2392 snd_printk(KERN_ERR SFX "Error creating card!\n");
2353 return -ENOMEM; 2393 return err;
2354 } 2394 }
2355 2395
2356 err = azx_create(card, pci, dev, pci_id->driver_data, &chip); 2396 err = azx_create(card, pci, dev, pci_id->driver_data, &chip);
@@ -2359,8 +2399,7 @@ static int __devinit azx_probe(struct pci_dev *pci,
2359 card->private_data = chip; 2399 card->private_data = chip;
2360 2400
2361 /* create codec instances */ 2401 /* create codec instances */
2362 err = azx_codec_create(chip, model[dev], probe_mask[dev], 2402 err = azx_codec_create(chip, model[dev], probe_only[dev]);
2363 probe_only[dev]);
2364 if (err < 0) 2403 if (err < 0)
2365 goto out_free; 2404 goto out_free;
2366 2405
@@ -2457,10 +2496,10 @@ static struct pci_device_id azx_ids[] = {
2457 { PCI_DEVICE(0x10de, 0x0ac1), .driver_data = AZX_DRIVER_NVIDIA }, 2496 { PCI_DEVICE(0x10de, 0x0ac1), .driver_data = AZX_DRIVER_NVIDIA },
2458 { PCI_DEVICE(0x10de, 0x0ac2), .driver_data = AZX_DRIVER_NVIDIA }, 2497 { PCI_DEVICE(0x10de, 0x0ac2), .driver_data = AZX_DRIVER_NVIDIA },
2459 { PCI_DEVICE(0x10de, 0x0ac3), .driver_data = AZX_DRIVER_NVIDIA }, 2498 { PCI_DEVICE(0x10de, 0x0ac3), .driver_data = AZX_DRIVER_NVIDIA },
2460 { PCI_DEVICE(0x10de, 0x0bd4), .driver_data = AZX_DRIVER_NVIDIA }, 2499 { PCI_DEVICE(0x10de, 0x0d94), .driver_data = AZX_DRIVER_NVIDIA },
2461 { PCI_DEVICE(0x10de, 0x0bd5), .driver_data = AZX_DRIVER_NVIDIA }, 2500 { PCI_DEVICE(0x10de, 0x0d95), .driver_data = AZX_DRIVER_NVIDIA },
2462 { PCI_DEVICE(0x10de, 0x0bd6), .driver_data = AZX_DRIVER_NVIDIA }, 2501 { PCI_DEVICE(0x10de, 0x0d96), .driver_data = AZX_DRIVER_NVIDIA },
2463 { PCI_DEVICE(0x10de, 0x0bd7), .driver_data = AZX_DRIVER_NVIDIA }, 2502 { PCI_DEVICE(0x10de, 0x0d97), .driver_data = AZX_DRIVER_NVIDIA },
2464 /* Teradici */ 2503 /* Teradici */
2465 { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA }, 2504 { PCI_DEVICE(0x6549, 0x1200), .driver_data = AZX_DRIVER_TERA },
2466 /* AMD Generic, PCI class code and Vendor ID for HD Audio */ 2505 /* AMD Generic, PCI class code and Vendor ID for HD Audio */
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 44f189cb97ae..83349013b4df 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -26,8 +26,10 @@
26/* 26/*
27 * for mixer controls 27 * for mixer controls
28 */ 28 */
29#define HDA_COMPOSE_AMP_VAL_OFS(nid,chs,idx,dir,ofs) \
30 ((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19) | ((ofs)<<23))
29#define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) \ 31#define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) \
30 ((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19)) 32 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, idx, dir, 0)
31/* mono volume with index (index=0,1,...) (channel=1,2) */ 33/* mono volume with index (index=0,1,...) (channel=1,2) */
32#define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \ 34#define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
33 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \ 35 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
@@ -96,7 +98,7 @@ struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
96 const char *name); 98 const char *name);
97int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 99int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
98 unsigned int *tlv, const char **slaves); 100 unsigned int *tlv, const char **slaves);
99void snd_hda_codec_reset(struct hda_codec *codec); 101int snd_hda_codec_reset(struct hda_codec *codec);
100int snd_hda_codec_configure(struct hda_codec *codec); 102int snd_hda_codec_configure(struct hda_codec *codec);
101 103
102/* amp value bits */ 104/* amp value bits */
@@ -134,7 +136,7 @@ extern struct hda_ctl_ops snd_hda_bind_sw; /* for bind-switch */
134 136
135struct hda_bind_ctls { 137struct hda_bind_ctls {
136 struct hda_ctl_ops *ops; 138 struct hda_ctl_ops *ops;
137 long values[]; 139 unsigned long values[];
138}; 140};
139 141
140int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol, 142int snd_hda_mixer_bind_ctls_info(struct snd_kcontrol *kcontrol,
@@ -227,6 +229,7 @@ struct hda_multi_out {
227 hda_nid_t hp_nid; /* optional DAC for HP, 0 when not exists */ 229 hda_nid_t hp_nid; /* optional DAC for HP, 0 when not exists */
228 hda_nid_t extra_out_nid[3]; /* optional DACs, 0 when not exists */ 230 hda_nid_t extra_out_nid[3]; /* optional DACs, 0 when not exists */
229 hda_nid_t dig_out_nid; /* digital out audio widget */ 231 hda_nid_t dig_out_nid; /* digital out audio widget */
232 hda_nid_t *slave_dig_outs;
230 int max_channels; /* currently supported analog channels */ 233 int max_channels; /* currently supported analog channels */
231 int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */ 234 int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */
232 int no_share_stream; /* don't share a stream with multiple pins */ 235 int no_share_stream; /* don't share a stream with multiple pins */
@@ -354,9 +357,12 @@ struct auto_pin_cfg {
354 int line_out_type; /* AUTO_PIN_XXX_OUT */ 357 int line_out_type; /* AUTO_PIN_XXX_OUT */
355 hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS]; 358 hda_nid_t hp_pins[AUTO_CFG_MAX_OUTS];
356 hda_nid_t input_pins[AUTO_PIN_LAST]; 359 hda_nid_t input_pins[AUTO_PIN_LAST];
357 hda_nid_t dig_out_pin; 360 int dig_outs;
361 hda_nid_t dig_out_pins[2];
358 hda_nid_t dig_in_pin; 362 hda_nid_t dig_in_pin;
359 hda_nid_t mono_out_pin; 363 hda_nid_t mono_out_pin;
364 int dig_out_type[2]; /* HDA_PCM_TYPE_XXX */
365 int dig_in_type; /* HDA_PCM_TYPE_XXX */
360}; 366};
361 367
362#define get_defcfg_connect(cfg) \ 368#define get_defcfg_connect(cfg) \
@@ -405,6 +411,7 @@ static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
405u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction); 411u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
406int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 412int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
407 unsigned int caps); 413 unsigned int caps);
414u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
408 415
409int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl); 416int snd_hda_ctl_add(struct hda_codec *codec, struct snd_kcontrol *kctl);
410void snd_hda_ctls_clear(struct hda_codec *codec); 417void snd_hda_ctls_clear(struct hda_codec *codec);
@@ -427,6 +434,23 @@ static inline int snd_hda_hwdep_add_sysfs(struct hda_codec *codec)
427} 434}
428#endif 435#endif
429 436
437#ifdef CONFIG_SND_HDA_RECONFIG
438const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
439int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key);
440#else
441static inline
442const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
443{
444 return NULL;
445}
446
447static inline
448int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
449{
450 return -ENOENT;
451}
452#endif
453
430/* 454/*
431 * power-management 455 * power-management
432 */ 456 */
@@ -458,6 +482,7 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
458#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3) 482#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
459#define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1) 483#define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1)
460#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf) 484#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf)
485#define get_amp_offset(kc) (((kc)->private_value >> 23) & 0x3f)
461 486
462/* 487/*
463 * CEA Short Audio Descriptor data 488 * CEA Short Audio Descriptor data
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index 144b85276d5a..93d7499350c6 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -399,8 +399,10 @@ static void print_conn_list(struct snd_info_buffer *buffer,
399{ 399{
400 int c, curr = -1; 400 int c, curr = -1;
401 401
402 if (conn_len > 1 && wid_type != AC_WID_AUD_MIX && 402 if (conn_len > 1 &&
403 wid_type != AC_WID_VOL_KNB) 403 wid_type != AC_WID_AUD_MIX &&
404 wid_type != AC_WID_VOL_KNB &&
405 wid_type != AC_WID_POWER)
404 curr = snd_hda_codec_read(codec, nid, 0, 406 curr = snd_hda_codec_read(codec, nid, 0,
405 AC_VERB_GET_CONNECT_SEL, 0); 407 AC_VERB_GET_CONNECT_SEL, 0);
406 snd_iprintf(buffer, " Connection: %d\n", conn_len); 408 snd_iprintf(buffer, " Connection: %d\n", conn_len);
@@ -467,8 +469,9 @@ static void print_codec_info(struct snd_info_entry *entry,
467 snd_iprintf(buffer, "Codec: %s\n", 469 snd_iprintf(buffer, "Codec: %s\n",
468 codec->name ? codec->name : "Not Set"); 470 codec->name ? codec->name : "Not Set");
469 snd_iprintf(buffer, "Address: %d\n", codec->addr); 471 snd_iprintf(buffer, "Address: %d\n", codec->addr);
470 snd_iprintf(buffer, "Vendor Id: 0x%x\n", codec->vendor_id); 472 snd_iprintf(buffer, "Function Id: 0x%x\n", codec->function_id);
471 snd_iprintf(buffer, "Subsystem Id: 0x%x\n", codec->subsystem_id); 473 snd_iprintf(buffer, "Vendor Id: 0x%08x\n", codec->vendor_id);
474 snd_iprintf(buffer, "Subsystem Id: 0x%08x\n", codec->subsystem_id);
472 snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id); 475 snd_iprintf(buffer, "Revision Id: 0x%x\n", codec->revision_id);
473 476
474 if (codec->mfg) 477 if (codec->mfg)
@@ -554,8 +557,14 @@ static void print_codec_info(struct snd_info_entry *entry,
554 snd_iprintf(buffer, " Amp-Out caps: "); 557 snd_iprintf(buffer, " Amp-Out caps: ");
555 print_amp_caps(buffer, codec, nid, HDA_OUTPUT); 558 print_amp_caps(buffer, codec, nid, HDA_OUTPUT);
556 snd_iprintf(buffer, " Amp-Out vals: "); 559 snd_iprintf(buffer, " Amp-Out vals: ");
557 print_amp_vals(buffer, codec, nid, HDA_OUTPUT, 560 if (wid_type == AC_WID_PIN &&
558 wid_caps & AC_WCAP_STEREO, 1); 561 codec->pin_amp_workaround)
562 print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
563 wid_caps & AC_WCAP_STEREO,
564 conn_len);
565 else
566 print_amp_vals(buffer, codec, nid, HDA_OUTPUT,
567 wid_caps & AC_WCAP_STEREO, 1);
559 } 568 }
560 569
561 switch (wid_type) { 570 switch (wid_type) {
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index e48612323aa0..5bb48ee8b6c6 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -27,11 +27,12 @@
27#include <sound/core.h> 27#include <sound/core.h>
28#include "hda_codec.h" 28#include "hda_codec.h"
29#include "hda_local.h" 29#include "hda_local.h"
30#include "hda_beep.h"
30 31
31struct ad198x_spec { 32struct ad198x_spec {
32 struct snd_kcontrol_new *mixers[5]; 33 struct snd_kcontrol_new *mixers[5];
33 int num_mixers; 34 int num_mixers;
34 35 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
35 const struct hda_verb *init_verbs[5]; /* initialization verbs 36 const struct hda_verb *init_verbs[5]; /* initialization verbs
36 * don't forget NULL termination! 37 * don't forget NULL termination!
37 */ 38 */
@@ -154,6 +155,16 @@ static const char *ad_slave_sws[] = {
154 155
155static void ad198x_free_kctls(struct hda_codec *codec); 156static void ad198x_free_kctls(struct hda_codec *codec);
156 157
158/* additional beep mixers; the actual parameters are overwritten at build */
159static struct snd_kcontrol_new ad_beep_mixer[] = {
160 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
161 HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_OUTPUT),
162 { } /* end */
163};
164
165#define set_beep_amp(spec, nid, idx, dir) \
166 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
167
157static int ad198x_build_controls(struct hda_codec *codec) 168static int ad198x_build_controls(struct hda_codec *codec)
158{ 169{
159 struct ad198x_spec *spec = codec->spec; 170 struct ad198x_spec *spec = codec->spec;
@@ -181,6 +192,21 @@ static int ad198x_build_controls(struct hda_codec *codec)
181 return err; 192 return err;
182 } 193 }
183 194
195 /* create beep controls if needed */
196 if (spec->beep_amp) {
197 struct snd_kcontrol_new *knew;
198 for (knew = ad_beep_mixer; knew->name; knew++) {
199 struct snd_kcontrol *kctl;
200 kctl = snd_ctl_new1(knew, codec);
201 if (!kctl)
202 return -ENOMEM;
203 kctl->private_value = spec->beep_amp;
204 err = snd_hda_ctl_add(codec, kctl);
205 if (err < 0)
206 return err;
207 }
208 }
209
184 /* if we have no master control, let's create it */ 210 /* if we have no master control, let's create it */
185 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 211 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
186 unsigned int vmaster_tlv[4]; 212 unsigned int vmaster_tlv[4];
@@ -406,7 +432,8 @@ static void ad198x_free(struct hda_codec *codec)
406 return; 432 return;
407 433
408 ad198x_free_kctls(codec); 434 ad198x_free_kctls(codec);
409 kfree(codec->spec); 435 kfree(spec);
436 snd_hda_detach_beep_device(codec);
410} 437}
411 438
412static struct hda_codec_ops ad198x_patch_ops = { 439static struct hda_codec_ops ad198x_patch_ops = {
@@ -545,8 +572,6 @@ static struct snd_kcontrol_new ad1986a_mixers[] = {
545 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), 572 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
546 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT), 573 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
547 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT), 574 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
548 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT),
549 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
550 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT), 575 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
551 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), 576 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
552 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT), 577 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
@@ -610,8 +635,7 @@ static struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
610 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), 635 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
611 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT), 636 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
612 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT), 637 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
613 /* HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x18, 0x0, HDA_OUTPUT), 638 /*
614 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x18, 0x0, HDA_OUTPUT),
615 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT), 639 HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
616 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */ 640 HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
617 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT), 641 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
@@ -809,8 +833,6 @@ static struct snd_kcontrol_new ad1986a_laptop_automute_mixers[] = {
809 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), 833 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
810 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT), 834 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
811 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT), 835 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
812 HDA_CODEC_VOLUME("Beep Playback Volume", 0x18, 0x0, HDA_OUTPUT),
813 HDA_CODEC_MUTE("Beep Playback Switch", 0x18, 0x0, HDA_OUTPUT),
814 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT), 836 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
815 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT), 837 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
816 { 838 {
@@ -1002,10 +1024,8 @@ static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
1002 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD), 1024 SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
1003 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK), 1025 SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
1004 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP), 1026 SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
1005 SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_SAMSUNG),
1006 SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_SAMSUNG),
1007 SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_SAMSUNG),
1008 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA), 1027 SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
1028 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
1009 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK), 1029 SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
1010 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP), 1030 SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
1011 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK), 1031 SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
@@ -1027,15 +1047,14 @@ static struct hda_amp_list ad1986a_loopbacks[] = {
1027 1047
1028static int is_jack_available(struct hda_codec *codec, hda_nid_t nid) 1048static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
1029{ 1049{
1030 unsigned int conf = snd_hda_codec_read(codec, nid, 0, 1050 unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
1031 AC_VERB_GET_CONFIG_DEFAULT, 0);
1032 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE; 1051 return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
1033} 1052}
1034 1053
1035static int patch_ad1986a(struct hda_codec *codec) 1054static int patch_ad1986a(struct hda_codec *codec)
1036{ 1055{
1037 struct ad198x_spec *spec; 1056 struct ad198x_spec *spec;
1038 int board_config; 1057 int err, board_config;
1039 1058
1040 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1059 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1041 if (spec == NULL) 1060 if (spec == NULL)
@@ -1043,6 +1062,13 @@ static int patch_ad1986a(struct hda_codec *codec)
1043 1062
1044 codec->spec = spec; 1063 codec->spec = spec;
1045 1064
1065 err = snd_hda_attach_beep_device(codec, 0x19);
1066 if (err < 0) {
1067 ad198x_free(codec);
1068 return err;
1069 }
1070 set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
1071
1046 spec->multiout.max_channels = 6; 1072 spec->multiout.max_channels = 6;
1047 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids); 1073 spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
1048 spec->multiout.dac_nids = ad1986a_dac_nids; 1074 spec->multiout.dac_nids = ad1986a_dac_nids;
@@ -1222,8 +1248,6 @@ static struct snd_kcontrol_new ad1983_mixers[] = {
1222 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT), 1248 HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
1223 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT), 1249 HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1224 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT), 1250 HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1225 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x10, 1, 0x0, HDA_OUTPUT),
1226 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x10, 1, 0x0, HDA_OUTPUT),
1227 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT), 1251 HDA_CODEC_VOLUME("Mic Boost", 0x0c, 0x0, HDA_OUTPUT),
1228 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT), 1252 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
1229 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT), 1253 HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
@@ -1294,6 +1318,7 @@ static struct hda_amp_list ad1983_loopbacks[] = {
1294static int patch_ad1983(struct hda_codec *codec) 1318static int patch_ad1983(struct hda_codec *codec)
1295{ 1319{
1296 struct ad198x_spec *spec; 1320 struct ad198x_spec *spec;
1321 int err;
1297 1322
1298 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1323 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1299 if (spec == NULL) 1324 if (spec == NULL)
@@ -1301,6 +1326,13 @@ static int patch_ad1983(struct hda_codec *codec)
1301 1326
1302 codec->spec = spec; 1327 codec->spec = spec;
1303 1328
1329 err = snd_hda_attach_beep_device(codec, 0x10);
1330 if (err < 0) {
1331 ad198x_free(codec);
1332 return err;
1333 }
1334 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
1335
1304 spec->multiout.max_channels = 2; 1336 spec->multiout.max_channels = 2;
1305 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids); 1337 spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
1306 spec->multiout.dac_nids = ad1983_dac_nids; 1338 spec->multiout.dac_nids = ad1983_dac_nids;
@@ -1370,8 +1402,6 @@ static struct snd_kcontrol_new ad1981_mixers[] = {
1370 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT), 1402 HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
1371 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT), 1403 HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
1372 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT), 1404 HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
1373 HDA_CODEC_VOLUME_MONO("PC Speaker Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
1374 HDA_CODEC_MUTE_MONO("PC Speaker Playback Switch", 0x0d, 1, 0x0, HDA_OUTPUT),
1375 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT), 1405 HDA_CODEC_VOLUME("Front Mic Boost", 0x08, 0x0, HDA_INPUT),
1376 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT), 1406 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0x0, HDA_INPUT),
1377 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT), 1407 HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
@@ -1416,8 +1446,8 @@ static struct hda_verb ad1981_init_verbs[] = {
1416 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 1446 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
1417 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 1447 {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
1418 /* Mic boost: 0dB */ 1448 /* Mic boost: 0dB */
1419 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 1449 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1420 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000}, 1450 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
1421 /* Record selector: Front mic */ 1451 /* Record selector: Front mic */
1422 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0}, 1452 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
1423 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080}, 1453 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
@@ -1682,10 +1712,10 @@ static struct snd_pci_quirk ad1981_cfg_tbl[] = {
1682 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD), 1712 SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
1683 SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD), 1713 SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
1684 /* All HP models */ 1714 /* All HP models */
1685 SND_PCI_QUIRK(0x103c, 0, "HP nx", AD1981_HP), 1715 SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
1686 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA), 1716 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
1687 /* Lenovo Thinkpad T60/X60/Z6xx */ 1717 /* Lenovo Thinkpad T60/X60/Z6xx */
1688 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1981_THINKPAD), 1718 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1981_THINKPAD),
1689 /* HP nx6320 (reversed SSID, H/W bug) */ 1719 /* HP nx6320 (reversed SSID, H/W bug) */
1690 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP), 1720 SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
1691 {} 1721 {}
@@ -1694,7 +1724,7 @@ static struct snd_pci_quirk ad1981_cfg_tbl[] = {
1694static int patch_ad1981(struct hda_codec *codec) 1724static int patch_ad1981(struct hda_codec *codec)
1695{ 1725{
1696 struct ad198x_spec *spec; 1726 struct ad198x_spec *spec;
1697 int board_config; 1727 int err, board_config;
1698 1728
1699 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 1729 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
1700 if (spec == NULL) 1730 if (spec == NULL)
@@ -1702,6 +1732,13 @@ static int patch_ad1981(struct hda_codec *codec)
1702 1732
1703 codec->spec = spec; 1733 codec->spec = spec;
1704 1734
1735 err = snd_hda_attach_beep_device(codec, 0x10);
1736 if (err < 0) {
1737 ad198x_free(codec);
1738 return err;
1739 }
1740 set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
1741
1705 spec->multiout.max_channels = 2; 1742 spec->multiout.max_channels = 2;
1706 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids); 1743 spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
1707 spec->multiout.dac_nids = ad1981_dac_nids; 1744 spec->multiout.dac_nids = ad1981_dac_nids;
@@ -1988,9 +2025,6 @@ static struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
1988 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT), 2025 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
1989 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT), 2026 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
1990 2027
1991 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
1992 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
1993
1994 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT), 2028 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
1995 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT), 2029 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
1996 2030
@@ -2034,9 +2068,6 @@ static struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
2034 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT), 2068 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
2035 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT), 2069 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
2036 2070
2037 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
2038 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
2039
2040 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT), 2071 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2041 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT), 2072 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2042 2073
@@ -2066,9 +2097,6 @@ static struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2066 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT), 2097 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
2067 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT), 2098 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
2068 2099
2069 HDA_CODEC_VOLUME("Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
2070 HDA_CODEC_MUTE("Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
2071
2072 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT), 2100 HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
2073 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT), 2101 HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
2074 2102
@@ -2297,10 +2325,6 @@ static struct hda_verb ad1988_capture_init_verbs[] = {
2297 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1}, 2325 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2298 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1}, 2326 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2299 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1}, 2327 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2300 /* ADCs; muted */
2301 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2302 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2303 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2304 2328
2305 { } 2329 { }
2306}; 2330};
@@ -2408,10 +2432,6 @@ static struct hda_verb ad1988_3stack_init_verbs[] = {
2408 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1}, 2432 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2409 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1}, 2433 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2410 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1}, 2434 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2411 /* ADCs; muted */
2412 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2413 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2414 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2415 /* Analog Mix output amp */ 2435 /* Analog Mix output amp */
2416 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */ 2436 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2417 { } 2437 { }
@@ -2483,10 +2503,6 @@ static struct hda_verb ad1988_laptop_init_verbs[] = {
2483 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1}, 2503 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
2484 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1}, 2504 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
2485 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1}, 2505 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
2486 /* ADCs; muted */
2487 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2488 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2489 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
2490 /* Analog Mix output amp */ 2506 /* Analog Mix output amp */
2491 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */ 2507 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
2492 { } 2508 { }
@@ -2890,7 +2906,7 @@ static int ad1988_parse_auto_config(struct hda_codec *codec)
2890 2906
2891 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 2907 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2892 2908
2893 if (spec->autocfg.dig_out_pin) 2909 if (spec->autocfg.dig_outs)
2894 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT; 2910 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
2895 if (spec->autocfg.dig_in_pin) 2911 if (spec->autocfg.dig_in_pin)
2896 spec->dig_in_nid = AD1988_SPDIF_IN; 2912 spec->dig_in_nid = AD1988_SPDIF_IN;
@@ -2940,7 +2956,7 @@ static struct snd_pci_quirk ad1988_cfg_tbl[] = {
2940static int patch_ad1988(struct hda_codec *codec) 2956static int patch_ad1988(struct hda_codec *codec)
2941{ 2957{
2942 struct ad198x_spec *spec; 2958 struct ad198x_spec *spec;
2943 int board_config; 2959 int err, board_config;
2944 2960
2945 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 2961 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
2946 if (spec == NULL) 2962 if (spec == NULL)
@@ -2960,7 +2976,7 @@ static int patch_ad1988(struct hda_codec *codec)
2960 2976
2961 if (board_config == AD1988_AUTO) { 2977 if (board_config == AD1988_AUTO) {
2962 /* automatic parse from the BIOS config */ 2978 /* automatic parse from the BIOS config */
2963 int err = ad1988_parse_auto_config(codec); 2979 err = ad1988_parse_auto_config(codec);
2964 if (err < 0) { 2980 if (err < 0) {
2965 ad198x_free(codec); 2981 ad198x_free(codec);
2966 return err; 2982 return err;
@@ -2970,6 +2986,13 @@ static int patch_ad1988(struct hda_codec *codec)
2970 } 2986 }
2971 } 2987 }
2972 2988
2989 err = snd_hda_attach_beep_device(codec, 0x10);
2990 if (err < 0) {
2991 ad198x_free(codec);
2992 return err;
2993 }
2994 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
2995
2973 switch (board_config) { 2996 switch (board_config) {
2974 case AD1988_6STACK: 2997 case AD1988_6STACK:
2975 case AD1988_6STACK_DIG: 2998 case AD1988_6STACK_DIG:
@@ -3126,12 +3149,6 @@ static struct snd_kcontrol_new ad1884_base_mixers[] = {
3126 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT), 3149 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3127 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT), 3150 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3128 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT), 3151 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3129 /*
3130 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
3131 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
3132 HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0x10, 0x0, HDA_OUTPUT),
3133 HDA_CODEC_MUTE("Digital Beep Playback Switch", 0x10, 0x0, HDA_OUTPUT),
3134 */
3135 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT), 3152 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3136 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT), 3153 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3137 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 3154 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
@@ -3204,10 +3221,10 @@ static struct hda_verb ad1884_init_verbs[] = {
3204 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1}, 3221 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
3205 /* Port-B (front mic) pin */ 3222 /* Port-B (front mic) pin */
3206 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 3223 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3207 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 3224 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3208 /* Port-C (rear mic) pin */ 3225 /* Port-C (rear mic) pin */
3209 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 3226 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3210 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 3227 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3211 /* Analog mixer; mute as default */ 3228 /* Analog mixer; mute as default */
3212 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 3229 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3213 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 3230 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
@@ -3240,7 +3257,7 @@ static const char *ad1884_slave_vols[] = {
3240 "CD Playback Volume", 3257 "CD Playback Volume",
3241 "Internal Mic Playback Volume", 3258 "Internal Mic Playback Volume",
3242 "Docking Mic Playback Volume" 3259 "Docking Mic Playback Volume"
3243 "Beep Playback Volume", 3260 /* "Beep Playback Volume", */
3244 "IEC958 Playback Volume", 3261 "IEC958 Playback Volume",
3245 NULL 3262 NULL
3246}; 3263};
@@ -3248,6 +3265,7 @@ static const char *ad1884_slave_vols[] = {
3248static int patch_ad1884(struct hda_codec *codec) 3265static int patch_ad1884(struct hda_codec *codec)
3249{ 3266{
3250 struct ad198x_spec *spec; 3267 struct ad198x_spec *spec;
3268 int err;
3251 3269
3252 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3270 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3253 if (spec == NULL) 3271 if (spec == NULL)
@@ -3255,6 +3273,13 @@ static int patch_ad1884(struct hda_codec *codec)
3255 3273
3256 codec->spec = spec; 3274 codec->spec = spec;
3257 3275
3276 err = snd_hda_attach_beep_device(codec, 0x10);
3277 if (err < 0) {
3278 ad198x_free(codec);
3279 return err;
3280 }
3281 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3282
3258 spec->multiout.max_channels = 2; 3283 spec->multiout.max_channels = 2;
3259 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids); 3284 spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
3260 spec->multiout.dac_nids = ad1884_dac_nids; 3285 spec->multiout.dac_nids = ad1884_dac_nids;
@@ -3321,8 +3346,6 @@ static struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
3321 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT), 3346 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3322 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT), 3347 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3323 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT), 3348 HDA_CODEC_VOLUME("Docking Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3324 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3325 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3326 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 3349 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3327 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT), 3350 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3328 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT), 3351 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
@@ -3358,7 +3381,7 @@ static struct hda_verb ad1984_thinkpad_init_verbs[] = {
3358 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 3381 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3359 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 3382 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3360 /* docking mic boost */ 3383 /* docking mic boost */
3361 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 3384 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
3362 /* Analog mixer - docking mic; mute as default */ 3385 /* Analog mixer - docking mic; mute as default */
3363 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, 3386 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3364 /* enable EAPD bit */ 3387 /* enable EAPD bit */
@@ -3379,10 +3402,6 @@ static struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
3379 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT), 3402 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3380 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT), 3403 HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
3381 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT), 3404 HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
3382 /*
3383 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x20, 0x03, HDA_INPUT),
3384 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x20, 0x03, HDA_INPUT),
3385 */
3386 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT), 3405 HDA_CODEC_VOLUME("Line-In Boost", 0x15, 0x0, HDA_INPUT),
3387 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT), 3406 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3388 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 3407 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
@@ -3468,7 +3487,7 @@ static const char *ad1984_models[AD1984_MODELS] = {
3468 3487
3469static struct snd_pci_quirk ad1984_cfg_tbl[] = { 3488static struct snd_pci_quirk ad1984_cfg_tbl[] = {
3470 /* Lenovo Thinkpad T61/X61 */ 3489 /* Lenovo Thinkpad T61/X61 */
3471 SND_PCI_QUIRK(0x17aa, 0, "Lenovo Thinkpad", AD1984_THINKPAD), 3490 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1984_THINKPAD),
3472 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP), 3491 SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
3473 {} 3492 {}
3474}; 3493};
@@ -3561,8 +3580,6 @@ static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3561 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT), 3580 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3562 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT), 3581 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3563 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT), 3582 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3564 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3565 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3566 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT), 3583 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3567 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT), 3584 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3568 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT), 3585 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
@@ -3622,10 +3639,10 @@ static struct hda_verb ad1884a_init_verbs[] = {
3622 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 3639 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3623 /* Port-B (front mic) pin */ 3640 /* Port-B (front mic) pin */
3624 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 3641 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3625 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 3642 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3626 /* Port-C (rear line-in) pin */ 3643 /* Port-C (rear line-in) pin */
3627 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 3644 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3628 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 3645 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
3629 /* Port-E (rear mic) pin */ 3646 /* Port-E (rear mic) pin */
3630 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 3647 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3631 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 3648 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
@@ -3695,8 +3712,6 @@ static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3695 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT), 3712 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3696 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT), 3713 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3697 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT), 3714 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3698 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3699 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3700 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT), 3715 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3701 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT), 3716 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3702 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT), 3717 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
@@ -3724,8 +3739,6 @@ static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3724 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT), 3739 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3725 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT), 3740 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3726 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT), 3741 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3727 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3728 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3729 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT), 3742 HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
3730 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT), 3743 HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
3731 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 3744 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
@@ -3836,8 +3849,6 @@ static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3836 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT), 3849 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3837 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT), 3850 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3838 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT), 3851 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3839 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3840 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3841 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT), 3852 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3842 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT), 3853 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
3843 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT), 3854 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
@@ -3911,9 +3922,9 @@ static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3911 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE), 3922 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
3912 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP), 3923 SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
3913 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE), 3924 SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
3914 SND_PCI_QUIRK(0x103c, 0x30e6, "HP 6730b", AD1884A_LAPTOP), 3925 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
3915 SND_PCI_QUIRK(0x103c, 0x30e7, "HP EliteBook 8530p", AD1884A_LAPTOP), 3926 SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
3916 SND_PCI_QUIRK(0x103c, 0x3614, "HP 6730s", AD1884A_LAPTOP), 3927 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
3917 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD), 3928 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
3918 {} 3929 {}
3919}; 3930};
@@ -3921,7 +3932,7 @@ static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3921static int patch_ad1884a(struct hda_codec *codec) 3932static int patch_ad1884a(struct hda_codec *codec)
3922{ 3933{
3923 struct ad198x_spec *spec; 3934 struct ad198x_spec *spec;
3924 int board_config; 3935 int err, board_config;
3925 3936
3926 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 3937 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3927 if (spec == NULL) 3938 if (spec == NULL)
@@ -3929,6 +3940,13 @@ static int patch_ad1884a(struct hda_codec *codec)
3929 3940
3930 codec->spec = spec; 3941 codec->spec = spec;
3931 3942
3943 err = snd_hda_attach_beep_device(codec, 0x10);
3944 if (err < 0) {
3945 ad198x_free(codec);
3946 return err;
3947 }
3948 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3949
3932 spec->multiout.max_channels = 2; 3950 spec->multiout.max_channels = 2;
3933 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids); 3951 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
3934 spec->multiout.dac_nids = ad1884a_dac_nids; 3952 spec->multiout.dac_nids = ad1884a_dac_nids;
@@ -3966,6 +3984,14 @@ static int patch_ad1884a(struct hda_codec *codec)
3966 spec->multiout.dig_out_nid = 0; 3984 spec->multiout.dig_out_nid = 0;
3967 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event; 3985 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3968 codec->patch_ops.init = ad1884a_hp_init; 3986 codec->patch_ops.init = ad1884a_hp_init;
3987 /* set the upper-limit for mixer amp to 0dB for avoiding the
3988 * possible damage by overloading
3989 */
3990 snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
3991 (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
3992 (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
3993 (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
3994 (1 << AC_AMPCAP_MUTE_SHIFT));
3969 break; 3995 break;
3970 case AD1884A_THINKPAD: 3996 case AD1884A_THINKPAD:
3971 spec->mixers[0] = ad1984a_thinkpad_mixers; 3997 spec->mixers[0] = ad1984a_thinkpad_mixers;
@@ -4083,8 +4109,6 @@ static struct snd_kcontrol_new ad1882_loopback_mixers[] = {
4083 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT), 4109 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
4084 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT), 4110 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4085 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT), 4111 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4086 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
4087 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
4088 { } /* end */ 4112 { } /* end */
4089}; 4113};
4090 4114
@@ -4097,8 +4121,6 @@ static struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
4097 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT), 4121 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
4098 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT), 4122 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
4099 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT), 4123 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
4100 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x07, HDA_INPUT),
4101 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x07, HDA_INPUT),
4102 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT), 4124 HDA_CODEC_VOLUME("Digital Mic Boost", 0x1f, 0x0, HDA_INPUT),
4103 { } /* end */ 4125 { } /* end */
4104}; 4126};
@@ -4257,7 +4279,7 @@ static const char *ad1882_models[AD1986A_MODELS] = {
4257static int patch_ad1882(struct hda_codec *codec) 4279static int patch_ad1882(struct hda_codec *codec)
4258{ 4280{
4259 struct ad198x_spec *spec; 4281 struct ad198x_spec *spec;
4260 int board_config; 4282 int err, board_config;
4261 4283
4262 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4284 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4263 if (spec == NULL) 4285 if (spec == NULL)
@@ -4265,6 +4287,13 @@ static int patch_ad1882(struct hda_codec *codec)
4265 4287
4266 codec->spec = spec; 4288 codec->spec = spec;
4267 4289
4290 err = snd_hda_attach_beep_device(codec, 0x10);
4291 if (err < 0) {
4292 ad198x_free(codec);
4293 return err;
4294 }
4295 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
4296
4268 spec->multiout.max_channels = 6; 4297 spec->multiout.max_channels = 6;
4269 spec->multiout.num_dacs = 3; 4298 spec->multiout.num_dacs = 3;
4270 spec->multiout.dac_nids = ad1882_dac_nids; 4299 spec->multiout.dac_nids = ad1882_dac_nids;
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index f3ebe837f2d5..c921264bbd71 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -680,13 +680,13 @@ static int patch_cmi9880(struct hda_codec *codec)
680 struct auto_pin_cfg cfg; 680 struct auto_pin_cfg cfg;
681 681
682 /* collect pin default configuration */ 682 /* collect pin default configuration */
683 port_e = snd_hda_codec_read(codec, 0x0f, 0, AC_VERB_GET_CONFIG_DEFAULT, 0); 683 port_e = snd_hda_codec_get_pincfg(codec, 0x0f);
684 port_f = snd_hda_codec_read(codec, 0x10, 0, AC_VERB_GET_CONFIG_DEFAULT, 0); 684 port_f = snd_hda_codec_get_pincfg(codec, 0x10);
685 spec->front_panel = 1; 685 spec->front_panel = 1;
686 if (get_defcfg_connect(port_e) == AC_JACK_PORT_NONE || 686 if (get_defcfg_connect(port_e) == AC_JACK_PORT_NONE ||
687 get_defcfg_connect(port_f) == AC_JACK_PORT_NONE) { 687 get_defcfg_connect(port_f) == AC_JACK_PORT_NONE) {
688 port_g = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_CONFIG_DEFAULT, 0); 688 port_g = snd_hda_codec_get_pincfg(codec, 0x1f);
689 port_h = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_CONFIG_DEFAULT, 0); 689 port_h = snd_hda_codec_get_pincfg(codec, 0x20);
690 spec->channel_modes = cmi9880_channel_modes; 690 spec->channel_modes = cmi9880_channel_modes;
691 /* no front panel */ 691 /* no front panel */
692 if (get_defcfg_connect(port_g) == AC_JACK_PORT_NONE || 692 if (get_defcfg_connect(port_g) == AC_JACK_PORT_NONE ||
@@ -703,8 +703,8 @@ static int patch_cmi9880(struct hda_codec *codec)
703 spec->multiout.max_channels = cmi9880_channel_modes[0].channels; 703 spec->multiout.max_channels = cmi9880_channel_modes[0].channels;
704 } else { 704 } else {
705 spec->input_mux = &cmi9880_basic_mux; 705 spec->input_mux = &cmi9880_basic_mux;
706 port_spdifi = snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONFIG_DEFAULT, 0); 706 port_spdifi = snd_hda_codec_get_pincfg(codec, 0x13);
707 port_spdifo = snd_hda_codec_read(codec, 0x12, 0, AC_VERB_GET_CONFIG_DEFAULT, 0); 707 port_spdifo = snd_hda_codec_get_pincfg(codec, 0x12);
708 if (get_defcfg_connect(port_spdifo) != AC_JACK_PORT_NONE) 708 if (get_defcfg_connect(port_spdifo) != AC_JACK_PORT_NONE)
709 spec->multiout.dig_out_nid = CMI_DIG_OUT_NID; 709 spec->multiout.dig_out_nid = CMI_DIG_OUT_NID;
710 if (get_defcfg_connect(port_spdifi) != AC_JACK_PORT_NONE) 710 if (get_defcfg_connect(port_spdifi) != AC_JACK_PORT_NONE)
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 0177ef8f4c9e..1f2ad76ca94b 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -58,6 +58,7 @@ struct conexant_spec {
58 58
59 struct snd_kcontrol_new *mixers[5]; 59 struct snd_kcontrol_new *mixers[5];
60 int num_mixers; 60 int num_mixers;
61 hda_nid_t vmaster_nid;
61 62
62 const struct hda_verb *init_verbs[5]; /* initialization verbs 63 const struct hda_verb *init_verbs[5]; /* initialization verbs
63 * don't forget NULL 64 * don't forget NULL
@@ -72,6 +73,7 @@ struct conexant_spec {
72 */ 73 */
73 unsigned int cur_eapd; 74 unsigned int cur_eapd;
74 unsigned int hp_present; 75 unsigned int hp_present;
76 unsigned int no_auto_mic;
75 unsigned int need_dac_fix; 77 unsigned int need_dac_fix;
76 78
77 /* capture */ 79 /* capture */
@@ -461,6 +463,29 @@ static void conexant_free(struct hda_codec *codec)
461 kfree(codec->spec); 463 kfree(codec->spec);
462} 464}
463 465
466static struct snd_kcontrol_new cxt_capture_mixers[] = {
467 {
468 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
469 .name = "Capture Source",
470 .info = conexant_mux_enum_info,
471 .get = conexant_mux_enum_get,
472 .put = conexant_mux_enum_put
473 },
474 {}
475};
476
477static const char *slave_vols[] = {
478 "Headphone Playback Volume",
479 "Speaker Playback Volume",
480 NULL
481};
482
483static const char *slave_sws[] = {
484 "Headphone Playback Switch",
485 "Speaker Playback Switch",
486 NULL
487};
488
464static int conexant_build_controls(struct hda_codec *codec) 489static int conexant_build_controls(struct hda_codec *codec)
465{ 490{
466 struct conexant_spec *spec = codec->spec; 491 struct conexant_spec *spec = codec->spec;
@@ -488,6 +513,32 @@ static int conexant_build_controls(struct hda_codec *codec)
488 if (err < 0) 513 if (err < 0)
489 return err; 514 return err;
490 } 515 }
516
517 /* if we have no master control, let's create it */
518 if (spec->vmaster_nid &&
519 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
520 unsigned int vmaster_tlv[4];
521 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
522 HDA_OUTPUT, vmaster_tlv);
523 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
524 vmaster_tlv, slave_vols);
525 if (err < 0)
526 return err;
527 }
528 if (spec->vmaster_nid &&
529 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
530 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
531 NULL, slave_sws);
532 if (err < 0)
533 return err;
534 }
535
536 if (spec->input_mux) {
537 err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
538 if (err < 0)
539 return err;
540 }
541
491 return 0; 542 return 0;
492} 543}
493 544
@@ -719,13 +770,6 @@ static void cxt5045_hp_unsol_event(struct hda_codec *codec,
719} 770}
720 771
721static struct snd_kcontrol_new cxt5045_mixers[] = { 772static struct snd_kcontrol_new cxt5045_mixers[] = {
722 {
723 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
724 .name = "Capture Source",
725 .info = conexant_mux_enum_info,
726 .get = conexant_mux_enum_get,
727 .put = conexant_mux_enum_put
728 },
729 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 773 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
730 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT), 774 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
731 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 775 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
@@ -759,13 +803,6 @@ static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
759}; 803};
760 804
761static struct snd_kcontrol_new cxt5045_mixers_hp530[] = { 805static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
762 {
763 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
764 .name = "Capture Source",
765 .info = conexant_mux_enum_info,
766 .get = conexant_mux_enum_get,
767 .put = conexant_mux_enum_put
768 },
769 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT), 806 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
770 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT), 807 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
771 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT), 808 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
@@ -1002,15 +1039,9 @@ static const char *cxt5045_models[CXT5045_MODELS] = {
1002}; 1039};
1003 1040
1004static struct snd_pci_quirk cxt5045_cfg_tbl[] = { 1041static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1005 SND_PCI_QUIRK(0x103c, 0x30a5, "HP", CXT5045_LAPTOP_HPSENSE),
1006 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
1007 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2120", CXT5045_LAPTOP_HPSENSE),
1008 SND_PCI_QUIRK(0x103c, 0x30b7, "HP DV6000Z", CXT5045_LAPTOP_HPSENSE),
1009 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
1010 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
1011 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
1012 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530), 1042 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
1013 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE), 1043 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1044 CXT5045_LAPTOP_HPSENSE),
1014 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE), 1045 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
1015 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 1046 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
1016 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 1047 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
@@ -1020,8 +1051,8 @@ static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
1020 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1051 SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1021 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1052 SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1022 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE), 1053 SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
1023 SND_PCI_QUIRK(0x1631, 0xc106, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE), 1054 SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
1024 SND_PCI_QUIRK(0x1631, 0xc107, "Packard Bell", CXT5045_LAPTOP_HPMICSENSE), 1055 CXT5045_LAPTOP_HPMICSENSE),
1025 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE), 1056 SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
1026 {} 1057 {}
1027}; 1058};
@@ -1035,6 +1066,7 @@ static int patch_cxt5045(struct hda_codec *codec)
1035 if (!spec) 1066 if (!spec)
1036 return -ENOMEM; 1067 return -ENOMEM;
1037 codec->spec = spec; 1068 codec->spec = spec;
1069 codec->pin_amp_workaround = 1;
1038 1070
1039 spec->multiout.max_channels = 2; 1071 spec->multiout.max_channels = 2;
1040 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids); 1072 spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
@@ -1134,7 +1166,7 @@ static int patch_cxt5045(struct hda_codec *codec)
1134/* Conexant 5047 specific */ 1166/* Conexant 5047 specific */
1135#define CXT5047_SPDIF_OUT 0x11 1167#define CXT5047_SPDIF_OUT 0x11
1136 1168
1137static hda_nid_t cxt5047_dac_nids[2] = { 0x10, 0x1c }; 1169static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
1138static hda_nid_t cxt5047_adc_nids[1] = { 0x12 }; 1170static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
1139static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a }; 1171static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
1140 1172
@@ -1142,20 +1174,6 @@ static struct hda_channel_mode cxt5047_modes[1] = {
1142 { 2, NULL }, 1174 { 2, NULL },
1143}; 1175};
1144 1176
1145static struct hda_input_mux cxt5047_capture_source = {
1146 .num_items = 1,
1147 .items = {
1148 { "Mic", 0x2 },
1149 }
1150};
1151
1152static struct hda_input_mux cxt5047_hp_capture_source = {
1153 .num_items = 1,
1154 .items = {
1155 { "ExtMic", 0x2 },
1156 }
1157};
1158
1159static struct hda_input_mux cxt5047_toshiba_capture_source = { 1177static struct hda_input_mux cxt5047_toshiba_capture_source = {
1160 .num_items = 2, 1178 .num_items = 2,
1161 .items = { 1179 .items = {
@@ -1179,7 +1197,11 @@ static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1179 * the headphone jack 1197 * the headphone jack
1180 */ 1198 */
1181 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE; 1199 bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
1182 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, 1200 /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
1201 * pin widgets unlike other codecs. In this case, we need to
1202 * set index 0x01 for the volume from the mixer amp 0x19.
1203 */
1204 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1183 HDA_AMP_MUTE, bits); 1205 HDA_AMP_MUTE, bits);
1184 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE; 1206 bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
1185 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0, 1207 snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
@@ -1187,16 +1209,6 @@ static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1187 return 1; 1209 return 1;
1188} 1210}
1189 1211
1190/* bind volumes of both NID 0x13 (Headphones) and 0x1d (Speakers) */
1191static struct hda_bind_ctls cxt5047_bind_master_vol = {
1192 .ops = &snd_hda_bind_vol,
1193 .values = {
1194 HDA_COMPOSE_AMP_VAL(0x13, 3, 0, HDA_OUTPUT),
1195 HDA_COMPOSE_AMP_VAL(0x1d, 3, 0, HDA_OUTPUT),
1196 0
1197 },
1198};
1199
1200/* mute internal speaker if HP is plugged */ 1212/* mute internal speaker if HP is plugged */
1201static void cxt5047_hp_automute(struct hda_codec *codec) 1213static void cxt5047_hp_automute(struct hda_codec *codec)
1202{ 1214{
@@ -1207,27 +1219,8 @@ static void cxt5047_hp_automute(struct hda_codec *codec)
1207 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1219 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1208 1220
1209 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0; 1221 bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
1210 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0, 1222 /* See the note in cxt5047_hp_master_sw_put */
1211 HDA_AMP_MUTE, bits); 1223 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
1212 /* Mute/Unmute PCM 2 for good measure - some systems need this */
1213 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1214 HDA_AMP_MUTE, bits);
1215}
1216
1217/* mute internal speaker if HP is plugged */
1218static void cxt5047_hp2_automute(struct hda_codec *codec)
1219{
1220 struct conexant_spec *spec = codec->spec;
1221 unsigned int bits;
1222
1223 spec->hp_present = snd_hda_codec_read(codec, 0x13, 0,
1224 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1225
1226 bits = spec->hp_present ? HDA_AMP_MUTE : 0;
1227 snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0,
1228 HDA_AMP_MUTE, bits);
1229 /* Mute/Unmute PCM 2 for good measure - some systems need this */
1230 snd_hda_codec_amp_stereo(codec, 0x1c, HDA_OUTPUT, 0,
1231 HDA_AMP_MUTE, bits); 1224 HDA_AMP_MUTE, bits);
1232} 1225}
1233 1226
@@ -1268,55 +1261,14 @@ static void cxt5047_hp_unsol_event(struct hda_codec *codec,
1268 } 1261 }
1269} 1262}
1270 1263
1271/* unsolicited event for HP jack sensing - non-EAPD systems */ 1264static struct snd_kcontrol_new cxt5047_base_mixers[] = {
1272static void cxt5047_hp2_unsol_event(struct hda_codec *codec, 1265 HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
1273 unsigned int res) 1266 HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
1274{ 1267 HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
1275 res >>= 26;
1276 switch (res) {
1277 case CONEXANT_HP_EVENT:
1278 cxt5047_hp2_automute(codec);
1279 break;
1280 case CONEXANT_MIC_EVENT:
1281 cxt5047_hp_automic(codec);
1282 break;
1283 }
1284}
1285
1286static struct snd_kcontrol_new cxt5047_mixers[] = {
1287 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1288 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1289 HDA_CODEC_VOLUME("Mic Gain Volume", 0x1a, 0x0, HDA_OUTPUT),
1290 HDA_CODEC_MUTE("Mic Gain Switch", 0x1a, 0x0, HDA_OUTPUT),
1291 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT), 1268 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1292 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT), 1269 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1293 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT), 1270 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1294 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT), 1271 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1295 HDA_CODEC_VOLUME("PCM-2 Volume", 0x1c, 0x00, HDA_OUTPUT),
1296 HDA_CODEC_MUTE("PCM-2 Switch", 0x1c, 0x00, HDA_OUTPUT),
1297 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x00, HDA_OUTPUT),
1298 HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x00, HDA_OUTPUT),
1299 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1300 HDA_CODEC_MUTE("Headphone Playback Switch", 0x13, 0x00, HDA_OUTPUT),
1301
1302 {}
1303};
1304
1305static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1306 {
1307 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1308 .name = "Capture Source",
1309 .info = conexant_mux_enum_info,
1310 .get = conexant_mux_enum_get,
1311 .put = conexant_mux_enum_put
1312 },
1313 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1314 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19, 0x02, HDA_INPUT),
1315 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1316 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1317 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1318 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1319 HDA_BIND_VOL("Master Playback Volume", &cxt5047_bind_master_vol),
1320 { 1272 {
1321 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1273 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1322 .name = "Master Playback Switch", 1274 .name = "Master Playback Switch",
@@ -1329,29 +1281,15 @@ static struct snd_kcontrol_new cxt5047_toshiba_mixers[] = {
1329 {} 1281 {}
1330}; 1282};
1331 1283
1332static struct snd_kcontrol_new cxt5047_hp_mixers[] = { 1284static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
1333 { 1285 /* See the note in cxt5047_hp_master_sw_put */
1334 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1286 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
1335 .name = "Capture Source", 1287 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1336 .info = conexant_mux_enum_info, 1288 {}
1337 .get = conexant_mux_enum_get, 1289};
1338 .put = conexant_mux_enum_put 1290
1339 }, 1291static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
1340 HDA_CODEC_VOLUME("Mic Bypass Capture Volume", 0x19, 0x02, HDA_INPUT),
1341 HDA_CODEC_MUTE("Mic Bypass Capture Switch", 0x19,0x02,HDA_INPUT),
1342 HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
1343 HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
1344 HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
1345 HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
1346 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT), 1292 HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
1347 {
1348 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1349 .name = "Master Playback Switch",
1350 .info = cxt_eapd_info,
1351 .get = cxt_eapd_get,
1352 .put = cxt5047_hp_master_sw_put,
1353 .private_value = 0x13,
1354 },
1355 { } /* end */ 1293 { } /* end */
1356}; 1294};
1357 1295
@@ -1362,8 +1300,8 @@ static struct hda_verb cxt5047_init_verbs[] = {
1362 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 }, 1300 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
1363 /* HP, Speaker */ 1301 /* HP, Speaker */
1364 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, 1302 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
1365 {0x13, AC_VERB_SET_CONNECT_SEL,0x1}, 1303 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
1366 {0x1d, AC_VERB_SET_CONNECT_SEL,0x0}, 1304 {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
1367 /* Record selector: Mic */ 1305 /* Record selector: Mic */
1368 {0x12, AC_VERB_SET_CONNECT_SEL,0x03}, 1306 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1369 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 1307 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
@@ -1383,30 +1321,7 @@ static struct hda_verb cxt5047_init_verbs[] = {
1383 1321
1384/* configuration for Toshiba Laptops */ 1322/* configuration for Toshiba Laptops */
1385static struct hda_verb cxt5047_toshiba_init_verbs[] = { 1323static struct hda_verb cxt5047_toshiba_init_verbs[] = {
1386 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0 }, /* default on */ 1324 {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
1387 /* pin sensing on HP and Mic jacks */
1388 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1389 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
1390 /* Speaker routing */
1391 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1392 {}
1393};
1394
1395/* configuration for HP Laptops */
1396static struct hda_verb cxt5047_hp_init_verbs[] = {
1397 /* pin sensing on HP jack */
1398 {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
1399 /* 0x13 is actually shared by both HP and speaker;
1400 * setting the connection to 0 (=0x19) makes the master volume control
1401 * working mysteriouslly...
1402 */
1403 {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
1404 /* Record selector: Ext Mic */
1405 {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
1406 {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
1407 AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
1408 /* Speaker routing */
1409 {0x1d, AC_VERB_SET_CONNECT_SEL,0x1},
1410 {} 1325 {}
1411}; 1326};
1412 1327
@@ -1571,11 +1486,9 @@ static const char *cxt5047_models[CXT5047_MODELS] = {
1571}; 1486};
1572 1487
1573static struct snd_pci_quirk cxt5047_cfg_tbl[] = { 1488static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
1574 SND_PCI_QUIRK(0x103c, 0x30a0, "HP DV1000", CXT5047_LAPTOP),
1575 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP), 1489 SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
1576 SND_PCI_QUIRK(0x103c, 0x30b2, "HP DV2000T/DV3000T", CXT5047_LAPTOP), 1490 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
1577 SND_PCI_QUIRK(0x103c, 0x30b5, "HP DV2000Z", CXT5047_LAPTOP), 1491 CXT5047_LAPTOP),
1578 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6700", CXT5047_LAPTOP),
1579 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD), 1492 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
1580 {} 1493 {}
1581}; 1494};
@@ -1589,6 +1502,7 @@ static int patch_cxt5047(struct hda_codec *codec)
1589 if (!spec) 1502 if (!spec)
1590 return -ENOMEM; 1503 return -ENOMEM;
1591 codec->spec = spec; 1504 codec->spec = spec;
1505 codec->pin_amp_workaround = 1;
1592 1506
1593 spec->multiout.max_channels = 2; 1507 spec->multiout.max_channels = 2;
1594 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids); 1508 spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
@@ -1597,9 +1511,8 @@ static int patch_cxt5047(struct hda_codec *codec)
1597 spec->num_adc_nids = 1; 1511 spec->num_adc_nids = 1;
1598 spec->adc_nids = cxt5047_adc_nids; 1512 spec->adc_nids = cxt5047_adc_nids;
1599 spec->capsrc_nids = cxt5047_capsrc_nids; 1513 spec->capsrc_nids = cxt5047_capsrc_nids;
1600 spec->input_mux = &cxt5047_capture_source;
1601 spec->num_mixers = 1; 1514 spec->num_mixers = 1;
1602 spec->mixers[0] = cxt5047_mixers; 1515 spec->mixers[0] = cxt5047_base_mixers;
1603 spec->num_init_verbs = 1; 1516 spec->num_init_verbs = 1;
1604 spec->init_verbs[0] = cxt5047_init_verbs; 1517 spec->init_verbs[0] = cxt5047_init_verbs;
1605 spec->spdif_route = 0; 1518 spec->spdif_route = 0;
@@ -1613,21 +1526,22 @@ static int patch_cxt5047(struct hda_codec *codec)
1613 cxt5047_cfg_tbl); 1526 cxt5047_cfg_tbl);
1614 switch (board_config) { 1527 switch (board_config) {
1615 case CXT5047_LAPTOP: 1528 case CXT5047_LAPTOP:
1616 codec->patch_ops.unsol_event = cxt5047_hp2_unsol_event; 1529 spec->num_mixers = 2;
1530 spec->mixers[1] = cxt5047_hp_spk_mixers;
1531 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1617 break; 1532 break;
1618 case CXT5047_LAPTOP_HP: 1533 case CXT5047_LAPTOP_HP:
1619 spec->input_mux = &cxt5047_hp_capture_source; 1534 spec->num_mixers = 2;
1620 spec->num_init_verbs = 2; 1535 spec->mixers[1] = cxt5047_hp_only_mixers;
1621 spec->init_verbs[1] = cxt5047_hp_init_verbs;
1622 spec->mixers[0] = cxt5047_hp_mixers;
1623 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1536 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1624 codec->patch_ops.init = cxt5047_hp_init; 1537 codec->patch_ops.init = cxt5047_hp_init;
1625 break; 1538 break;
1626 case CXT5047_LAPTOP_EAPD: 1539 case CXT5047_LAPTOP_EAPD:
1627 spec->input_mux = &cxt5047_toshiba_capture_source; 1540 spec->input_mux = &cxt5047_toshiba_capture_source;
1541 spec->num_mixers = 2;
1542 spec->mixers[1] = cxt5047_hp_spk_mixers;
1628 spec->num_init_verbs = 2; 1543 spec->num_init_verbs = 2;
1629 spec->init_verbs[1] = cxt5047_toshiba_init_verbs; 1544 spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
1630 spec->mixers[0] = cxt5047_toshiba_mixers;
1631 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1545 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1632 break; 1546 break;
1633#ifdef CONFIG_SND_DEBUG 1547#ifdef CONFIG_SND_DEBUG
@@ -1638,6 +1552,7 @@ static int patch_cxt5047(struct hda_codec *codec)
1638 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event; 1552 codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
1639#endif 1553#endif
1640 } 1554 }
1555 spec->vmaster_nid = 0x13;
1641 return 0; 1556 return 0;
1642} 1557}
1643 1558
@@ -1673,8 +1588,11 @@ static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1673/* toggle input of built-in and mic jack appropriately */ 1588/* toggle input of built-in and mic jack appropriately */
1674static void cxt5051_portb_automic(struct hda_codec *codec) 1589static void cxt5051_portb_automic(struct hda_codec *codec)
1675{ 1590{
1591 struct conexant_spec *spec = codec->spec;
1676 unsigned int present; 1592 unsigned int present;
1677 1593
1594 if (spec->no_auto_mic)
1595 return;
1678 present = snd_hda_codec_read(codec, 0x17, 0, 1596 present = snd_hda_codec_read(codec, 0x17, 0,
1679 AC_VERB_GET_PIN_SENSE, 0) & 1597 AC_VERB_GET_PIN_SENSE, 0) &
1680 AC_PINSENSE_PRESENCE; 1598 AC_PINSENSE_PRESENCE;
@@ -1690,6 +1608,8 @@ static void cxt5051_portc_automic(struct hda_codec *codec)
1690 unsigned int present; 1608 unsigned int present;
1691 hda_nid_t new_adc; 1609 hda_nid_t new_adc;
1692 1610
1611 if (spec->no_auto_mic)
1612 return;
1693 present = snd_hda_codec_read(codec, 0x18, 0, 1613 present = snd_hda_codec_read(codec, 0x18, 0,
1694 AC_VERB_GET_PIN_SENSE, 0) & 1614 AC_VERB_GET_PIN_SENSE, 0) &
1695 AC_PINSENSE_PRESENCE; 1615 AC_PINSENSE_PRESENCE;
@@ -1776,6 +1696,22 @@ static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
1776 {} 1696 {}
1777}; 1697};
1778 1698
1699static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
1700 HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x00, HDA_INPUT),
1701 HDA_CODEC_MUTE("Mic Switch", 0x14, 0x00, HDA_INPUT),
1702 HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
1703 {
1704 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1705 .name = "Master Playback Switch",
1706 .info = cxt_eapd_info,
1707 .get = cxt_eapd_get,
1708 .put = cxt5051_hp_master_sw_put,
1709 .private_value = 0x1a,
1710 },
1711
1712 {}
1713};
1714
1779static struct hda_verb cxt5051_init_verbs[] = { 1715static struct hda_verb cxt5051_init_verbs[] = {
1780 /* Line in, Mic */ 1716 /* Line in, Mic */
1781 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1717 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
@@ -1806,6 +1742,66 @@ static struct hda_verb cxt5051_init_verbs[] = {
1806 { } /* end */ 1742 { } /* end */
1807}; 1743};
1808 1744
1745static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1746 /* Line in, Mic */
1747 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1748 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1749 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1750 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
1751 /* SPK */
1752 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1753 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1754 /* HP, Amp */
1755 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1756 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1757 /* DAC1 */
1758 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1759 /* Record selector: Int mic */
1760 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1761 {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
1762 /* SPDIF route: PCM */
1763 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1764 /* EAPD */
1765 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1766 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1767 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1768 { } /* end */
1769};
1770
1771static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1772 /* Line in, Mic */
1773 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1774 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1775 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1776 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1777 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1778 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1779 /* SPK */
1780 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1781 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1782 /* HP, Amp */
1783 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1784 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1785 /* Docking HP */
1786 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1787 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1788 /* DAC1 */
1789 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1790 /* Record selector: Int mic */
1791 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1792 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1793 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1794 /* SPDIF route: PCM */
1795 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1796 /* EAPD */
1797 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1798 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1799 {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTB_EVENT},
1800 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CXT5051_PORTC_EVENT},
1801 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1802 { } /* end */
1803};
1804
1809/* initialize jack-sensing, too */ 1805/* initialize jack-sensing, too */
1810static int cxt5051_init(struct hda_codec *codec) 1806static int cxt5051_init(struct hda_codec *codec)
1811{ 1807{
@@ -1823,18 +1819,24 @@ static int cxt5051_init(struct hda_codec *codec)
1823enum { 1819enum {
1824 CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1820 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1825 CXT5051_HP, /* no docking */ 1821 CXT5051_HP, /* no docking */
1822 CXT5051_HP_DV6736, /* HP without mic switch */
1823 CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
1826 CXT5051_MODELS 1824 CXT5051_MODELS
1827}; 1825};
1828 1826
1829static const char *cxt5051_models[CXT5051_MODELS] = { 1827static const char *cxt5051_models[CXT5051_MODELS] = {
1830 [CXT5051_LAPTOP] = "laptop", 1828 [CXT5051_LAPTOP] = "laptop",
1831 [CXT5051_HP] = "hp", 1829 [CXT5051_HP] = "hp",
1830 [CXT5051_HP_DV6736] = "hp-dv6736",
1831 [CXT5051_LENOVO_X200] = "lenovo-x200",
1832}; 1832};
1833 1833
1834static struct snd_pci_quirk cxt5051_cfg_tbl[] = { 1834static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1835 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
1835 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1836 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1836 CXT5051_LAPTOP), 1837 CXT5051_LAPTOP),
1837 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 1838 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1839 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1838 {} 1840 {}
1839}; 1841};
1840 1842
@@ -1847,6 +1849,7 @@ static int patch_cxt5051(struct hda_codec *codec)
1847 if (!spec) 1849 if (!spec)
1848 return -ENOMEM; 1850 return -ENOMEM;
1849 codec->spec = spec; 1851 codec->spec = spec;
1852 codec->pin_amp_workaround = 1;
1850 1853
1851 codec->patch_ops = conexant_patch_ops; 1854 codec->patch_ops = conexant_patch_ops;
1852 codec->patch_ops.init = cxt5051_init; 1855 codec->patch_ops.init = cxt5051_init;
@@ -1867,17 +1870,22 @@ static int patch_cxt5051(struct hda_codec *codec)
1867 spec->cur_adc = 0; 1870 spec->cur_adc = 0;
1868 spec->cur_adc_idx = 0; 1871 spec->cur_adc_idx = 0;
1869 1872
1873 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1874
1870 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS, 1875 board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
1871 cxt5051_models, 1876 cxt5051_models,
1872 cxt5051_cfg_tbl); 1877 cxt5051_cfg_tbl);
1873 switch (board_config) { 1878 switch (board_config) {
1874 case CXT5051_HP: 1879 case CXT5051_HP:
1875 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
1876 spec->mixers[0] = cxt5051_hp_mixers; 1880 spec->mixers[0] = cxt5051_hp_mixers;
1877 break; 1881 break;
1878 default: 1882 case CXT5051_HP_DV6736:
1879 case CXT5051_LAPTOP: 1883 spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
1880 codec->patch_ops.unsol_event = cxt5051_hp_unsol_event; 1884 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
1885 spec->no_auto_mic = 1;
1886 break;
1887 case CXT5051_LENOVO_X200:
1888 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
1881 break; 1889 break;
1882 } 1890 }
1883 1891
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 6c26afcb8262..82097790f6f3 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -30,6 +30,7 @@
30#include <sound/core.h> 30#include <sound/core.h>
31#include "hda_codec.h" 31#include "hda_codec.h"
32#include "hda_local.h" 32#include "hda_local.h"
33#include "hda_beep.h"
33 34
34#define ALC880_FRONT_EVENT 0x01 35#define ALC880_FRONT_EVENT 0x01
35#define ALC880_DCVOL_EVENT 0x02 36#define ALC880_DCVOL_EVENT 0x02
@@ -77,6 +78,7 @@ enum {
77 ALC260_ACER, 78 ALC260_ACER,
78 ALC260_WILL, 79 ALC260_WILL,
79 ALC260_REPLACER_672V, 80 ALC260_REPLACER_672V,
81 ALC260_FAVORIT100,
80#ifdef CONFIG_SND_DEBUG 82#ifdef CONFIG_SND_DEBUG
81 ALC260_TEST, 83 ALC260_TEST,
82#endif 84#endif
@@ -103,6 +105,7 @@ enum {
103 ALC262_NEC, 105 ALC262_NEC,
104 ALC262_TOSHIBA_S06, 106 ALC262_TOSHIBA_S06,
105 ALC262_TOSHIBA_RX1, 107 ALC262_TOSHIBA_RX1,
108 ALC262_TYAN,
106 ALC262_AUTO, 109 ALC262_AUTO,
107 ALC262_MODEL_LAST /* last tag */ 110 ALC262_MODEL_LAST /* last tag */
108}; 111};
@@ -238,6 +241,13 @@ enum {
238 ALC883_MODEL_LAST, 241 ALC883_MODEL_LAST,
239}; 242};
240 243
244/* styles of capture selection */
245enum {
246 CAPT_MUX = 0, /* only mux based */
247 CAPT_MIX, /* only mixer based */
248 CAPT_1MUX_MIX, /* first mux and other mixers */
249};
250
241/* for GPIO Poll */ 251/* for GPIO Poll */
242#define GPIO_MASK 0x03 252#define GPIO_MASK 0x03
243 253
@@ -246,6 +256,7 @@ struct alc_spec {
246 struct snd_kcontrol_new *mixers[5]; /* mixer arrays */ 256 struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
247 unsigned int num_mixers; 257 unsigned int num_mixers;
248 struct snd_kcontrol_new *cap_mixer; /* capture mixer */ 258 struct snd_kcontrol_new *cap_mixer; /* capture mixer */
259 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
249 260
250 const struct hda_verb *init_verbs[5]; /* initialization verbs 261 const struct hda_verb *init_verbs[5]; /* initialization verbs
251 * don't forget NULL 262 * don't forget NULL
@@ -269,13 +280,15 @@ struct alc_spec {
269 * dig_out_nid and hp_nid are optional 280 * dig_out_nid and hp_nid are optional
270 */ 281 */
271 hda_nid_t alt_dac_nid; 282 hda_nid_t alt_dac_nid;
283 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
284 int dig_out_type;
272 285
273 /* capture */ 286 /* capture */
274 unsigned int num_adc_nids; 287 unsigned int num_adc_nids;
275 hda_nid_t *adc_nids; 288 hda_nid_t *adc_nids;
276 hda_nid_t *capsrc_nids; 289 hda_nid_t *capsrc_nids;
277 hda_nid_t dig_in_nid; /* digital-in NID; optional */ 290 hda_nid_t dig_in_nid; /* digital-in NID; optional */
278 unsigned char is_mix_capture; /* matrix-style capture (non-mux) */ 291 int capture_style; /* capture style (CAPT_*) */
279 292
280 /* capture source */ 293 /* capture source */
281 unsigned int num_mux_defs; 294 unsigned int num_mux_defs;
@@ -293,7 +306,7 @@ struct alc_spec {
293 /* dynamic controls, init_verbs and input_mux */ 306 /* dynamic controls, init_verbs and input_mux */
294 struct auto_pin_cfg autocfg; 307 struct auto_pin_cfg autocfg;
295 struct snd_array kctls; 308 struct snd_array kctls;
296 struct hda_input_mux private_imux; 309 struct hda_input_mux private_imux[3];
297 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS]; 310 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
298 311
299 /* hooks */ 312 /* hooks */
@@ -305,6 +318,9 @@ struct alc_spec {
305 unsigned int jack_present: 1; 318 unsigned int jack_present: 1;
306 unsigned int master_sw: 1; 319 unsigned int master_sw: 1;
307 320
321 /* other flags */
322 unsigned int no_analog :1; /* digital I/O only */
323
308 /* for virtual master */ 324 /* for virtual master */
309 hda_nid_t vmaster_nid; 325 hda_nid_t vmaster_nid;
310#ifdef CONFIG_SND_HDA_POWER_SAVE 326#ifdef CONFIG_SND_HDA_POWER_SAVE
@@ -314,13 +330,6 @@ struct alc_spec {
314 /* for PLL fix */ 330 /* for PLL fix */
315 hda_nid_t pll_nid; 331 hda_nid_t pll_nid;
316 unsigned int pll_coef_idx, pll_coef_bit; 332 unsigned int pll_coef_idx, pll_coef_bit;
317
318#ifdef SND_HDA_NEEDS_RESUME
319#define ALC_MAX_PINS 16
320 unsigned int num_pins;
321 hda_nid_t pin_nids[ALC_MAX_PINS];
322 unsigned int pin_cfgs[ALC_MAX_PINS];
323#endif
324}; 333};
325 334
326/* 335/*
@@ -336,6 +345,7 @@ struct alc_config_preset {
336 hda_nid_t *dac_nids; 345 hda_nid_t *dac_nids;
337 hda_nid_t dig_out_nid; /* optional */ 346 hda_nid_t dig_out_nid; /* optional */
338 hda_nid_t hp_nid; /* optional */ 347 hda_nid_t hp_nid; /* optional */
348 hda_nid_t *slave_dig_outs;
339 unsigned int num_adc_nids; 349 unsigned int num_adc_nids;
340 hda_nid_t *adc_nids; 350 hda_nid_t *adc_nids;
341 hda_nid_t *capsrc_nids; 351 hda_nid_t *capsrc_nids;
@@ -392,7 +402,8 @@ static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
392 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; 402 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
393 imux = &spec->input_mux[mux_idx]; 403 imux = &spec->input_mux[mux_idx];
394 404
395 if (spec->is_mix_capture) { 405 if (spec->capture_style &&
406 !(spec->capture_style == CAPT_1MUX_MIX && !adc_idx)) {
396 /* Matrix-mixer style (e.g. ALC882) */ 407 /* Matrix-mixer style (e.g. ALC882) */
397 unsigned int *cur_val = &spec->cur_mux[adc_idx]; 408 unsigned int *cur_val = &spec->cur_mux[adc_idx];
398 unsigned int i, idx; 409 unsigned int i, idx;
@@ -750,6 +761,24 @@ static int alc_eapd_ctrl_put(struct snd_kcontrol *kcontrol,
750#endif /* CONFIG_SND_DEBUG */ 761#endif /* CONFIG_SND_DEBUG */
751 762
752/* 763/*
764 * set up the input pin config (depending on the given auto-pin type)
765 */
766static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
767 int auto_pin_type)
768{
769 unsigned int val = PIN_IN;
770
771 if (auto_pin_type <= AUTO_PIN_FRONT_MIC) {
772 unsigned int pincap;
773 pincap = snd_hda_query_pin_caps(codec, nid);
774 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
775 if (pincap & AC_PINCAP_VREF_80)
776 val = PIN_VREF80;
777 }
778 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
779}
780
781/*
753 */ 782 */
754static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix) 783static void add_mixer(struct alc_spec *spec, struct snd_kcontrol_new *mix)
755{ 784{
@@ -810,6 +839,7 @@ static void setup_preset(struct alc_spec *spec,
810 spec->multiout.num_dacs = preset->num_dacs; 839 spec->multiout.num_dacs = preset->num_dacs;
811 spec->multiout.dac_nids = preset->dac_nids; 840 spec->multiout.dac_nids = preset->dac_nids;
812 spec->multiout.dig_out_nid = preset->dig_out_nid; 841 spec->multiout.dig_out_nid = preset->dig_out_nid;
842 spec->multiout.slave_dig_outs = preset->slave_dig_outs;
813 spec->multiout.hp_nid = preset->hp_nid; 843 spec->multiout.hp_nid = preset->hp_nid;
814 844
815 spec->num_mux_defs = preset->num_mux_defs; 845 spec->num_mux_defs = preset->num_mux_defs;
@@ -921,7 +951,7 @@ static void alc_mic_automute(struct hda_codec *codec)
921 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0); 951 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
922} 952}
923#else 953#else
924#define alc_mic_automute(codec) /* NOP */ 954#define alc_mic_automute(codec) do {} while(0) /* NOP */
925#endif /* disabled */ 955#endif /* disabled */
926 956
927/* unsolicited event for HP jack sensing */ 957/* unsolicited event for HP jack sensing */
@@ -952,7 +982,7 @@ static void alc888_coef_init(struct hda_codec *codec)
952 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0); 982 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
953 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0); 983 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
954 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7); 984 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
955 if ((tmp & 0xf0) == 2) 985 if ((tmp & 0xf0) == 0x20)
956 /* alc888S-VC */ 986 /* alc888S-VC */
957 snd_hda_codec_read(codec, 0x20, 0, 987 snd_hda_codec_read(codec, 0x20, 0,
958 AC_VERB_SET_PROC_COEF, 0x830); 988 AC_VERB_SET_PROC_COEF, 0x830);
@@ -991,8 +1021,7 @@ static void alc_subsystem_id(struct hda_codec *codec,
991 nid = 0x1d; 1021 nid = 0x1d;
992 if (codec->vendor_id == 0x10ec0260) 1022 if (codec->vendor_id == 0x10ec0260)
993 nid = 0x17; 1023 nid = 0x17;
994 ass = snd_hda_codec_read(codec, nid, 0, 1024 ass = snd_hda_codec_get_pincfg(codec, nid);
995 AC_VERB_GET_CONFIG_DEFAULT, 0);
996 if (!(ass & 1) && !(ass & 0x100000)) 1025 if (!(ass & 1) && !(ass & 0x100000))
997 return; 1026 return;
998 if ((ass >> 30) != 1) /* no physical connection */ 1027 if ((ass >> 30) != 1) /* no physical connection */
@@ -1166,16 +1195,8 @@ static void alc_fix_pincfg(struct hda_codec *codec,
1166 return; 1195 return;
1167 1196
1168 cfg = pinfix[quirk->value]; 1197 cfg = pinfix[quirk->value];
1169 for (; cfg->nid; cfg++) { 1198 for (; cfg->nid; cfg++)
1170 int i; 1199 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1171 u32 val = cfg->val;
1172 for (i = 0; i < 4; i++) {
1173 snd_hda_codec_write(codec, cfg->nid, 0,
1174 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0 + i,
1175 val & 0xff);
1176 val >>= 8;
1177 }
1178 }
1179} 1200}
1180 1201
1181/* 1202/*
@@ -1375,8 +1396,6 @@ static struct snd_kcontrol_new alc888_base_mixer[] = {
1375 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 1396 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
1376 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 1397 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
1377 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 1398 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1378 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1379 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1380 { } /* end */ 1399 { } /* end */
1381}; 1400};
1382 1401
@@ -1483,8 +1502,6 @@ static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
1483 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 1502 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1484 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT), 1503 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
1485 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT), 1504 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
1486 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1487 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1488 HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT), 1505 HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
1489 { 1506 {
1490 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1507 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -1578,8 +1595,7 @@ static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1578 snd_hda_mixer_amp_switch_put); 1595 snd_hda_mixer_amp_switch_put);
1579} 1596}
1580 1597
1581#define DEFINE_CAPMIX(num) \ 1598#define _DEFINE_CAPMIX(num) \
1582static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1583 { \ 1599 { \
1584 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 1600 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1585 .name = "Capture Switch", \ 1601 .name = "Capture Switch", \
@@ -1600,7 +1616,9 @@ static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1600 .get = alc_cap_vol_get, \ 1616 .get = alc_cap_vol_get, \
1601 .put = alc_cap_vol_put, \ 1617 .put = alc_cap_vol_put, \
1602 .tlv = { .c = alc_cap_vol_tlv }, \ 1618 .tlv = { .c = alc_cap_vol_tlv }, \
1603 }, \ 1619 }
1620
1621#define _DEFINE_CAPSRC(num) \
1604 { \ 1622 { \
1605 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 1623 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1606 /* .name = "Capture Source", */ \ 1624 /* .name = "Capture Source", */ \
@@ -1609,15 +1627,28 @@ static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1609 .info = alc_mux_enum_info, \ 1627 .info = alc_mux_enum_info, \
1610 .get = alc_mux_enum_get, \ 1628 .get = alc_mux_enum_get, \
1611 .put = alc_mux_enum_put, \ 1629 .put = alc_mux_enum_put, \
1612 }, \ 1630 }
1613 { } /* end */ \ 1631
1632#define DEFINE_CAPMIX(num) \
1633static struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
1634 _DEFINE_CAPMIX(num), \
1635 _DEFINE_CAPSRC(num), \
1636 { } /* end */ \
1637}
1638
1639#define DEFINE_CAPMIX_NOSRC(num) \
1640static struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
1641 _DEFINE_CAPMIX(num), \
1642 { } /* end */ \
1614} 1643}
1615 1644
1616/* up to three ADCs */ 1645/* up to three ADCs */
1617DEFINE_CAPMIX(1); 1646DEFINE_CAPMIX(1);
1618DEFINE_CAPMIX(2); 1647DEFINE_CAPMIX(2);
1619DEFINE_CAPMIX(3); 1648DEFINE_CAPMIX(3);
1620 1649DEFINE_CAPMIX_NOSRC(1);
1650DEFINE_CAPMIX_NOSRC(2);
1651DEFINE_CAPMIX_NOSRC(3);
1621 1652
1622/* 1653/*
1623 * ALC880 5-stack model 1654 * ALC880 5-stack model
@@ -1706,8 +1737,6 @@ static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
1706 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 1737 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1707 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 1738 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1708 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 1739 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1709 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1710 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1711 { 1740 {
1712 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1741 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1713 .name = "Channel Mode", 1742 .name = "Channel Mode",
@@ -1884,13 +1913,6 @@ static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
1884 { } /* end */ 1913 { } /* end */
1885}; 1914};
1886 1915
1887/* additional mixers to alc880_asus_mixer */
1888static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
1889 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1890 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1891 { } /* end */
1892};
1893
1894/* TCL S700 */ 1916/* TCL S700 */
1895static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = { 1917static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
1896 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 1918 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
@@ -1923,8 +1945,6 @@ static struct snd_kcontrol_new alc880_uniwill_mixer[] = {
1923 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 1945 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
1924 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 1946 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1925 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 1947 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1926 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
1927 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
1928 { 1948 {
1929 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1949 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1930 .name = "Channel Mode", 1950 .name = "Channel Mode",
@@ -1999,6 +2019,13 @@ static const char *alc_slave_sws[] = {
1999 2019
2000static void alc_free_kctls(struct hda_codec *codec); 2020static void alc_free_kctls(struct hda_codec *codec);
2001 2021
2022/* additional beep mixers; the actual parameters are overwritten at build */
2023static struct snd_kcontrol_new alc_beep_mixer[] = {
2024 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
2025 HDA_CODEC_MUTE("Beep Playback Switch", 0, 0, HDA_INPUT),
2026 { } /* end */
2027};
2028
2002static int alc_build_controls(struct hda_codec *codec) 2029static int alc_build_controls(struct hda_codec *codec)
2003{ 2030{
2004 struct alc_spec *spec = codec->spec; 2031 struct alc_spec *spec = codec->spec;
@@ -2020,11 +2047,13 @@ static int alc_build_controls(struct hda_codec *codec)
2020 spec->multiout.dig_out_nid); 2047 spec->multiout.dig_out_nid);
2021 if (err < 0) 2048 if (err < 0)
2022 return err; 2049 return err;
2023 err = snd_hda_create_spdif_share_sw(codec, 2050 if (!spec->no_analog) {
2024 &spec->multiout); 2051 err = snd_hda_create_spdif_share_sw(codec,
2025 if (err < 0) 2052 &spec->multiout);
2026 return err; 2053 if (err < 0)
2027 spec->multiout.share_spdif = 1; 2054 return err;
2055 spec->multiout.share_spdif = 1;
2056 }
2028 } 2057 }
2029 if (spec->dig_in_nid) { 2058 if (spec->dig_in_nid) {
2030 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 2059 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -2032,8 +2061,24 @@ static int alc_build_controls(struct hda_codec *codec)
2032 return err; 2061 return err;
2033 } 2062 }
2034 2063
2064 /* create beep controls if needed */
2065 if (spec->beep_amp) {
2066 struct snd_kcontrol_new *knew;
2067 for (knew = alc_beep_mixer; knew->name; knew++) {
2068 struct snd_kcontrol *kctl;
2069 kctl = snd_ctl_new1(knew, codec);
2070 if (!kctl)
2071 return -ENOMEM;
2072 kctl->private_value = spec->beep_amp;
2073 err = snd_hda_ctl_add(codec, kctl);
2074 if (err < 0)
2075 return err;
2076 }
2077 }
2078
2035 /* if we have no master control, let's create it */ 2079 /* if we have no master control, let's create it */
2036 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 2080 if (!spec->no_analog &&
2081 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
2037 unsigned int vmaster_tlv[4]; 2082 unsigned int vmaster_tlv[4];
2038 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 2083 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
2039 HDA_OUTPUT, vmaster_tlv); 2084 HDA_OUTPUT, vmaster_tlv);
@@ -2042,7 +2087,8 @@ static int alc_build_controls(struct hda_codec *codec)
2042 if (err < 0) 2087 if (err < 0)
2043 return err; 2088 return err;
2044 } 2089 }
2045 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) { 2090 if (!spec->no_analog &&
2091 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
2046 err = snd_hda_add_vmaster(codec, "Master Playback Switch", 2092 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2047 NULL, alc_slave_sws); 2093 NULL, alc_slave_sws);
2048 if (err < 0) 2094 if (err < 0)
@@ -2951,6 +2997,14 @@ static int alc880_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
2951 stream_tag, format, substream); 2997 stream_tag, format, substream);
2952} 2998}
2953 2999
3000static int alc880_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
3001 struct hda_codec *codec,
3002 struct snd_pcm_substream *substream)
3003{
3004 struct alc_spec *spec = codec->spec;
3005 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
3006}
3007
2954static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo, 3008static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
2955 struct hda_codec *codec, 3009 struct hda_codec *codec,
2956 struct snd_pcm_substream *substream) 3010 struct snd_pcm_substream *substream)
@@ -3034,7 +3088,8 @@ static struct hda_pcm_stream alc880_pcm_digital_playback = {
3034 .ops = { 3088 .ops = {
3035 .open = alc880_dig_playback_pcm_open, 3089 .open = alc880_dig_playback_pcm_open,
3036 .close = alc880_dig_playback_pcm_close, 3090 .close = alc880_dig_playback_pcm_close,
3037 .prepare = alc880_dig_playback_pcm_prepare 3091 .prepare = alc880_dig_playback_pcm_prepare,
3092 .cleanup = alc880_dig_playback_pcm_cleanup
3038 }, 3093 },
3039}; 3094};
3040 3095
@@ -3061,6 +3116,9 @@ static int alc_build_pcms(struct hda_codec *codec)
3061 codec->num_pcms = 1; 3116 codec->num_pcms = 1;
3062 codec->pcm_info = info; 3117 codec->pcm_info = info;
3063 3118
3119 if (spec->no_analog)
3120 goto skip_analog;
3121
3064 info->name = spec->stream_name_analog; 3122 info->name = spec->stream_name_analog;
3065 if (spec->stream_analog_playback) { 3123 if (spec->stream_analog_playback) {
3066 if (snd_BUG_ON(!spec->multiout.dac_nids)) 3124 if (snd_BUG_ON(!spec->multiout.dac_nids))
@@ -3084,12 +3142,17 @@ static int alc_build_pcms(struct hda_codec *codec)
3084 } 3142 }
3085 } 3143 }
3086 3144
3145 skip_analog:
3087 /* SPDIF for stream index #1 */ 3146 /* SPDIF for stream index #1 */
3088 if (spec->multiout.dig_out_nid || spec->dig_in_nid) { 3147 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
3089 codec->num_pcms = 2; 3148 codec->num_pcms = 2;
3149 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
3090 info = spec->pcm_rec + 1; 3150 info = spec->pcm_rec + 1;
3091 info->name = spec->stream_name_digital; 3151 info->name = spec->stream_name_digital;
3092 info->pcm_type = HDA_PCM_TYPE_SPDIF; 3152 if (spec->dig_out_type)
3153 info->pcm_type = spec->dig_out_type;
3154 else
3155 info->pcm_type = HDA_PCM_TYPE_SPDIF;
3093 if (spec->multiout.dig_out_nid && 3156 if (spec->multiout.dig_out_nid &&
3094 spec->stream_digital_playback) { 3157 spec->stream_digital_playback) {
3095 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback); 3158 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
@@ -3104,6 +3167,9 @@ static int alc_build_pcms(struct hda_codec *codec)
3104 codec->spdif_status_reset = 1; 3167 codec->spdif_status_reset = 1;
3105 } 3168 }
3106 3169
3170 if (spec->no_analog)
3171 return 0;
3172
3107 /* If the use of more than one ADC is requested for the current 3173 /* If the use of more than one ADC is requested for the current
3108 * model, configure a second analog capture-only PCM. 3174 * model, configure a second analog capture-only PCM.
3109 */ 3175 */
@@ -3162,65 +3228,17 @@ static void alc_free(struct hda_codec *codec)
3162 3228
3163 alc_free_kctls(codec); 3229 alc_free_kctls(codec);
3164 kfree(spec); 3230 kfree(spec);
3165 codec->spec = NULL; /* to be sure */ 3231 snd_hda_detach_beep_device(codec);
3166} 3232}
3167 3233
3168#ifdef SND_HDA_NEEDS_RESUME 3234#ifdef SND_HDA_NEEDS_RESUME
3169static void store_pin_configs(struct hda_codec *codec)
3170{
3171 struct alc_spec *spec = codec->spec;
3172 hda_nid_t nid, end_nid;
3173
3174 end_nid = codec->start_nid + codec->num_nodes;
3175 for (nid = codec->start_nid; nid < end_nid; nid++) {
3176 unsigned int wid_caps = get_wcaps(codec, nid);
3177 unsigned int wid_type =
3178 (wid_caps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
3179 if (wid_type != AC_WID_PIN)
3180 continue;
3181 if (spec->num_pins >= ARRAY_SIZE(spec->pin_nids))
3182 break;
3183 spec->pin_nids[spec->num_pins] = nid;
3184 spec->pin_cfgs[spec->num_pins] =
3185 snd_hda_codec_read(codec, nid, 0,
3186 AC_VERB_GET_CONFIG_DEFAULT, 0);
3187 spec->num_pins++;
3188 }
3189}
3190
3191static void resume_pin_configs(struct hda_codec *codec)
3192{
3193 struct alc_spec *spec = codec->spec;
3194 int i;
3195
3196 for (i = 0; i < spec->num_pins; i++) {
3197 hda_nid_t pin_nid = spec->pin_nids[i];
3198 unsigned int pin_config = spec->pin_cfgs[i];
3199 snd_hda_codec_write(codec, pin_nid, 0,
3200 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
3201 pin_config & 0x000000ff);
3202 snd_hda_codec_write(codec, pin_nid, 0,
3203 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
3204 (pin_config & 0x0000ff00) >> 8);
3205 snd_hda_codec_write(codec, pin_nid, 0,
3206 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
3207 (pin_config & 0x00ff0000) >> 16);
3208 snd_hda_codec_write(codec, pin_nid, 0,
3209 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
3210 pin_config >> 24);
3211 }
3212}
3213
3214static int alc_resume(struct hda_codec *codec) 3235static int alc_resume(struct hda_codec *codec)
3215{ 3236{
3216 resume_pin_configs(codec);
3217 codec->patch_ops.init(codec); 3237 codec->patch_ops.init(codec);
3218 snd_hda_codec_resume_amp(codec); 3238 snd_hda_codec_resume_amp(codec);
3219 snd_hda_codec_resume_cache(codec); 3239 snd_hda_codec_resume_cache(codec);
3220 return 0; 3240 return 0;
3221} 3241}
3222#else
3223#define store_pin_configs(codec)
3224#endif 3242#endif
3225 3243
3226/* 3244/*
@@ -3559,7 +3577,7 @@ static struct snd_pci_quirk alc880_cfg_tbl[] = {
3559 SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG), 3577 SND_PCI_QUIRK(0x1043, 0x8181, "ASUS P4GPL", ALC880_ASUS_DIG),
3560 SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST), 3578 SND_PCI_QUIRK(0x1043, 0x8196, "ASUS P5GD1", ALC880_6ST),
3561 SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST), 3579 SND_PCI_QUIRK(0x1043, 0x81b4, "ASUS", ALC880_6ST),
3562 SND_PCI_QUIRK(0x1043, 0, "ASUS", ALC880_ASUS), /* default ASUS */ 3580 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_ASUS), /* default ASUS */
3563 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST), 3581 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_3ST),
3564 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST), 3582 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_3ST),
3565 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST), 3583 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_5ST),
@@ -3602,7 +3620,8 @@ static struct snd_pci_quirk alc880_cfg_tbl[] = {
3602 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG), 3620 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_5ST_DIG),
3603 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG), 3621 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_5ST_DIG),
3604 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG), 3622 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_5ST_DIG),
3605 SND_PCI_QUIRK(0x8086, 0, "Intel mobo", ALC880_3ST), /* default Intel */ 3623 /* default Intel */
3624 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_3ST),
3606 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG), 3625 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_5ST_DIG),
3607 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG), 3626 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_6ST_DIG),
3608 {} 3627 {}
@@ -3782,7 +3801,7 @@ static struct alc_config_preset alc880_presets[] = {
3782 .input_mux = &alc880_capture_source, 3801 .input_mux = &alc880_capture_source,
3783 }, 3802 },
3784 [ALC880_UNIWILL_DIG] = { 3803 [ALC880_UNIWILL_DIG] = {
3785 .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer }, 3804 .mixers = { alc880_asus_mixer },
3786 .init_verbs = { alc880_volume_init_verbs, 3805 .init_verbs = { alc880_volume_init_verbs,
3787 alc880_pin_asus_init_verbs }, 3806 alc880_pin_asus_init_verbs },
3788 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids), 3807 .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
@@ -3820,8 +3839,7 @@ static struct alc_config_preset alc880_presets[] = {
3820 .init_hook = alc880_uniwill_p53_hp_automute, 3839 .init_hook = alc880_uniwill_p53_hp_automute,
3821 }, 3840 },
3822 [ALC880_FUJITSU] = { 3841 [ALC880_FUJITSU] = {
3823 .mixers = { alc880_fujitsu_mixer, 3842 .mixers = { alc880_fujitsu_mixer },
3824 alc880_pcbeep_mixer, },
3825 .init_verbs = { alc880_volume_init_verbs, 3843 .init_verbs = { alc880_volume_init_verbs,
3826 alc880_uniwill_p53_init_verbs, 3844 alc880_uniwill_p53_init_verbs,
3827 alc880_beep_init_verbs }, 3845 alc880_beep_init_verbs },
@@ -4114,7 +4132,7 @@ static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
4114static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec, 4132static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
4115 const struct auto_pin_cfg *cfg) 4133 const struct auto_pin_cfg *cfg)
4116{ 4134{
4117 struct hda_input_mux *imux = &spec->private_imux; 4135 struct hda_input_mux *imux = &spec->private_imux[0];
4118 int i, err, idx; 4136 int i, err, idx;
4119 4137
4120 for (i = 0; i < AUTO_PIN_LAST; i++) { 4138 for (i = 0; i < AUTO_PIN_LAST; i++) {
@@ -4202,11 +4220,9 @@ static void alc880_auto_init_analog_input(struct hda_codec *codec)
4202 for (i = 0; i < AUTO_PIN_LAST; i++) { 4220 for (i = 0; i < AUTO_PIN_LAST; i++) {
4203 hda_nid_t nid = spec->autocfg.input_pins[i]; 4221 hda_nid_t nid = spec->autocfg.input_pins[i];
4204 if (alc880_is_input_pin(nid)) { 4222 if (alc880_is_input_pin(nid)) {
4205 snd_hda_codec_write(codec, nid, 0, 4223 alc_set_input_pin(codec, nid, i);
4206 AC_VERB_SET_PIN_WIDGET_CONTROL, 4224 if (nid != ALC880_PIN_CD_NID &&
4207 i <= AUTO_PIN_FRONT_MIC ? 4225 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
4208 PIN_VREF80 : PIN_IN);
4209 if (nid != ALC880_PIN_CD_NID)
4210 snd_hda_codec_write(codec, nid, 0, 4226 snd_hda_codec_write(codec, nid, 0,
4211 AC_VERB_SET_AMP_GAIN_MUTE, 4227 AC_VERB_SET_AMP_GAIN_MUTE,
4212 AMP_OUT_MUTE); 4228 AMP_OUT_MUTE);
@@ -4221,7 +4237,7 @@ static void alc880_auto_init_analog_input(struct hda_codec *codec)
4221static int alc880_parse_auto_config(struct hda_codec *codec) 4237static int alc880_parse_auto_config(struct hda_codec *codec)
4222{ 4238{
4223 struct alc_spec *spec = codec->spec; 4239 struct alc_spec *spec = codec->spec;
4224 int err; 4240 int i, err;
4225 static hda_nid_t alc880_ignore[] = { 0x1d, 0 }; 4241 static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4226 4242
4227 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, 4243 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
@@ -4252,8 +4268,23 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
4252 4268
4253 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 4269 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4254 4270
4255 if (spec->autocfg.dig_out_pin) 4271 /* check multiple SPDIF-out (for recent codecs) */
4256 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID; 4272 for (i = 0; i < spec->autocfg.dig_outs; i++) {
4273 hda_nid_t dig_nid;
4274 err = snd_hda_get_connections(codec,
4275 spec->autocfg.dig_out_pins[i],
4276 &dig_nid, 1);
4277 if (err < 0)
4278 continue;
4279 if (!i)
4280 spec->multiout.dig_out_nid = dig_nid;
4281 else {
4282 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
4283 spec->slave_dig_outs[i - 1] = dig_nid;
4284 if (i == ARRAY_SIZE(spec->slave_dig_outs) - 1)
4285 break;
4286 }
4287 }
4257 if (spec->autocfg.dig_in_pin) 4288 if (spec->autocfg.dig_in_pin)
4258 spec->dig_in_nid = ALC880_DIGIN_NID; 4289 spec->dig_in_nid = ALC880_DIGIN_NID;
4259 4290
@@ -4263,9 +4294,8 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
4263 add_verb(spec, alc880_volume_init_verbs); 4294 add_verb(spec, alc880_volume_init_verbs);
4264 4295
4265 spec->num_mux_defs = 1; 4296 spec->num_mux_defs = 1;
4266 spec->input_mux = &spec->private_imux; 4297 spec->input_mux = &spec->private_imux[0];
4267 4298
4268 store_pin_configs(codec);
4269 return 1; 4299 return 1;
4270} 4300}
4271 4301
@@ -4280,21 +4310,33 @@ static void alc880_auto_init(struct hda_codec *codec)
4280 alc_inithook(codec); 4310 alc_inithook(codec);
4281} 4311}
4282 4312
4283/*
4284 * OK, here we have finally the patch for ALC880
4285 */
4286
4287static void set_capture_mixer(struct alc_spec *spec) 4313static void set_capture_mixer(struct alc_spec *spec)
4288{ 4314{
4289 static struct snd_kcontrol_new *caps[3] = { 4315 static struct snd_kcontrol_new *caps[2][3] = {
4290 alc_capture_mixer1, 4316 { alc_capture_mixer_nosrc1,
4291 alc_capture_mixer2, 4317 alc_capture_mixer_nosrc2,
4292 alc_capture_mixer3, 4318 alc_capture_mixer_nosrc3 },
4319 { alc_capture_mixer1,
4320 alc_capture_mixer2,
4321 alc_capture_mixer3 },
4293 }; 4322 };
4294 if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) 4323 if (spec->num_adc_nids > 0 && spec->num_adc_nids <= 3) {
4295 spec->cap_mixer = caps[spec->num_adc_nids - 1]; 4324 int mux;
4325 if (spec->input_mux && spec->input_mux->num_items > 1)
4326 mux = 1;
4327 else
4328 mux = 0;
4329 spec->cap_mixer = caps[mux][spec->num_adc_nids - 1];
4330 }
4296} 4331}
4297 4332
4333#define set_beep_amp(spec, nid, idx, dir) \
4334 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4335
4336/*
4337 * OK, here we have finally the patch for ALC880
4338 */
4339
4298static int patch_alc880(struct hda_codec *codec) 4340static int patch_alc880(struct hda_codec *codec)
4299{ 4341{
4300 struct alc_spec *spec; 4342 struct alc_spec *spec;
@@ -4330,6 +4372,12 @@ static int patch_alc880(struct hda_codec *codec)
4330 } 4372 }
4331 } 4373 }
4332 4374
4375 err = snd_hda_attach_beep_device(codec, 0x1);
4376 if (err < 0) {
4377 alc_free(codec);
4378 return err;
4379 }
4380
4333 if (board_config != ALC880_AUTO) 4381 if (board_config != ALC880_AUTO)
4334 setup_preset(spec, &alc880_presets[board_config]); 4382 setup_preset(spec, &alc880_presets[board_config]);
4335 4383
@@ -4356,6 +4404,7 @@ static int patch_alc880(struct hda_codec *codec)
4356 } 4404 }
4357 } 4405 }
4358 set_capture_mixer(spec); 4406 set_capture_mixer(spec);
4407 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4359 4408
4360 spec->vmaster_nid = 0x0c; 4409 spec->vmaster_nid = 0x0c;
4361 4410
@@ -4463,6 +4512,26 @@ static struct hda_input_mux alc260_acer_capture_sources[2] = {
4463 }, 4512 },
4464 }, 4513 },
4465}; 4514};
4515
4516/* Maxdata Favorit 100XS */
4517static struct hda_input_mux alc260_favorit100_capture_sources[2] = {
4518 {
4519 .num_items = 2,
4520 .items = {
4521 { "Line/Mic", 0x0 },
4522 { "CD", 0x4 },
4523 },
4524 },
4525 {
4526 .num_items = 3,
4527 .items = {
4528 { "Line/Mic", 0x0 },
4529 { "CD", 0x4 },
4530 { "Mixer", 0x5 },
4531 },
4532 },
4533};
4534
4466/* 4535/*
4467 * This is just place-holder, so there's something for alc_build_pcms to look 4536 * This is just place-holder, so there's something for alc_build_pcms to look
4468 * at when it calculates the maximum number of channels. ALC260 has no mixer 4537 * at when it calculates the maximum number of channels. ALC260 has no mixer
@@ -4505,12 +4574,6 @@ static struct snd_kcontrol_new alc260_input_mixer[] = {
4505 { } /* end */ 4574 { } /* end */
4506}; 4575};
4507 4576
4508static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
4509 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
4510 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
4511 { } /* end */
4512};
4513
4514/* update HP, line and mono out pins according to the master switch */ 4577/* update HP, line and mono out pins according to the master switch */
4515static void alc260_hp_master_update(struct hda_codec *codec, 4578static void alc260_hp_master_update(struct hda_codec *codec,
4516 hda_nid_t hp, hda_nid_t line, 4579 hda_nid_t hp, hda_nid_t line,
@@ -4702,8 +4765,6 @@ static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
4702 HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT), 4765 HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
4703 HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT), 4766 HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
4704 ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN), 4767 ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
4705 HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4706 HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4707 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT), 4768 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
4708 HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT), 4769 HDA_BIND_MUTE("Speaker Playback Switch", 0x09, 2, HDA_INPUT),
4709 { } /* end */ 4770 { } /* end */
@@ -4748,8 +4809,18 @@ static struct snd_kcontrol_new alc260_acer_mixer[] = {
4748 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT), 4809 HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
4749 HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT), 4810 HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
4750 ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT), 4811 ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4751 HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT), 4812 { } /* end */
4752 HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT), 4813};
4814
4815/* Maxdata Favorit 100XS: one output and one input (0x12) jack
4816 */
4817static struct snd_kcontrol_new alc260_favorit100_mixer[] = {
4818 HDA_CODEC_VOLUME("Master Playback Volume", 0x08, 0x0, HDA_OUTPUT),
4819 HDA_BIND_MUTE("Master Playback Switch", 0x08, 2, HDA_INPUT),
4820 ALC_PIN_MODE("Output Jack Mode", 0x0f, ALC_PIN_DIR_INOUT),
4821 HDA_CODEC_VOLUME("Line/Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
4822 HDA_CODEC_MUTE("Line/Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
4823 ALC_PIN_MODE("Line/Mic Jack Mode", 0x12, ALC_PIN_DIR_IN),
4753 { } /* end */ 4824 { } /* end */
4754}; 4825};
4755 4826
@@ -4767,8 +4838,6 @@ static struct snd_kcontrol_new alc260_will_mixer[] = {
4767 ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT), 4838 ALC_PIN_MODE("Line Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
4768 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT), 4839 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
4769 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT), 4840 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
4770 HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
4771 HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
4772 { } /* end */ 4841 { } /* end */
4773}; 4842};
4774 4843
@@ -5126,6 +5195,89 @@ static struct hda_verb alc260_acer_init_verbs[] = {
5126 { } 5195 { }
5127}; 5196};
5128 5197
5198/* Initialisation sequence for Maxdata Favorit 100XS
5199 * (adapted from Acer init verbs).
5200 */
5201static struct hda_verb alc260_favorit100_init_verbs[] = {
5202 /* GPIO 0 enables the output jack.
5203 * Turn this on and rely on the standard mute
5204 * methods whenever the user wants to turn these outputs off.
5205 */
5206 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
5207 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5208 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5209 /* Line/Mic input jack is connected to Mic1 pin */
5210 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
5211 /* Ensure all other unused pins are disabled and muted. */
5212 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5213 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5214 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5215 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5216 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5217 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5218 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5219 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5220 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
5221 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5222 /* Disable digital (SPDIF) pins */
5223 {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
5224 {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
5225
5226 /* Ensure Mic1 and Line1 pin widgets take input from the OUT1 sum
5227 * bus when acting as outputs.
5228 */
5229 {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
5230 {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
5231
5232 /* Start with output sum widgets muted and their output gains at min */
5233 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5234 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5235 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5236 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5237 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5238 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5239 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5240 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5241 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
5242
5243 /* Unmute Line-out pin widget amp left and right
5244 * (no equiv mixer ctrl)
5245 */
5246 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
5247 /* Unmute Mic1 and Line1 pin widget input buffers since they start as
5248 * inputs. If the pin mode is changed by the user the pin mode control
5249 * will take care of enabling the pin's input/output buffers as needed.
5250 * Therefore there's no need to enable the input buffer at this
5251 * stage.
5252 */
5253 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5254
5255 /* Mute capture amp left and right */
5256 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5257 /* Set ADC connection select to match default mixer setting - mic
5258 * (on mic1 pin)
5259 */
5260 {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
5261
5262 /* Do similar with the second ADC: mute capture input amp and
5263 * set ADC connection to mic to match ALSA's default state.
5264 */
5265 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
5266 {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
5267
5268 /* Mute all inputs to mixer widget (even unconnected ones) */
5269 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
5270 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
5271 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
5272 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
5273 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
5274 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
5275 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
5276 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
5277
5278 { }
5279};
5280
5129static struct hda_verb alc260_will_verbs[] = { 5281static struct hda_verb alc260_will_verbs[] = {
5130 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 5282 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
5131 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00}, 5283 {0x0b, AC_VERB_SET_CONNECT_SEL, 0x00},
@@ -5272,8 +5424,6 @@ static struct snd_kcontrol_new alc260_test_mixer[] = {
5272 HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT), 5424 HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
5273 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT), 5425 HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
5274 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT), 5426 HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
5275 HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
5276 HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
5277 HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT), 5427 HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
5278 HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT), 5428 HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
5279 HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT), 5429 HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
@@ -5471,7 +5621,7 @@ static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
5471static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec, 5621static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
5472 const struct auto_pin_cfg *cfg) 5622 const struct auto_pin_cfg *cfg)
5473{ 5623{
5474 struct hda_input_mux *imux = &spec->private_imux; 5624 struct hda_input_mux *imux = &spec->private_imux[0];
5475 int i, err, idx; 5625 int i, err, idx;
5476 5626
5477 for (i = 0; i < AUTO_PIN_LAST; i++) { 5627 for (i = 0; i < AUTO_PIN_LAST; i++) {
@@ -5546,11 +5696,9 @@ static void alc260_auto_init_analog_input(struct hda_codec *codec)
5546 for (i = 0; i < AUTO_PIN_LAST; i++) { 5696 for (i = 0; i < AUTO_PIN_LAST; i++) {
5547 hda_nid_t nid = spec->autocfg.input_pins[i]; 5697 hda_nid_t nid = spec->autocfg.input_pins[i];
5548 if (nid >= 0x12) { 5698 if (nid >= 0x12) {
5549 snd_hda_codec_write(codec, nid, 0, 5699 alc_set_input_pin(codec, nid, i);
5550 AC_VERB_SET_PIN_WIDGET_CONTROL, 5700 if (nid != ALC260_PIN_CD_NID &&
5551 i <= AUTO_PIN_FRONT_MIC ? 5701 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
5552 PIN_VREF80 : PIN_IN);
5553 if (nid != ALC260_PIN_CD_NID)
5554 snd_hda_codec_write(codec, nid, 0, 5702 snd_hda_codec_write(codec, nid, 0,
5555 AC_VERB_SET_AMP_GAIN_MUTE, 5703 AC_VERB_SET_AMP_GAIN_MUTE,
5556 AMP_OUT_MUTE); 5704 AMP_OUT_MUTE);
@@ -5623,7 +5771,7 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
5623 5771
5624 spec->multiout.max_channels = 2; 5772 spec->multiout.max_channels = 2;
5625 5773
5626 if (spec->autocfg.dig_out_pin) 5774 if (spec->autocfg.dig_outs)
5627 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID; 5775 spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
5628 if (spec->kctls.list) 5776 if (spec->kctls.list)
5629 add_mixer(spec, spec->kctls.list); 5777 add_mixer(spec, spec->kctls.list);
@@ -5631,9 +5779,8 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
5631 add_verb(spec, alc260_volume_init_verbs); 5779 add_verb(spec, alc260_volume_init_verbs);
5632 5780
5633 spec->num_mux_defs = 1; 5781 spec->num_mux_defs = 1;
5634 spec->input_mux = &spec->private_imux; 5782 spec->input_mux = &spec->private_imux[0];
5635 5783
5636 store_pin_configs(codec);
5637 return 1; 5784 return 1;
5638} 5785}
5639 5786
@@ -5670,6 +5817,7 @@ static const char *alc260_models[ALC260_MODEL_LAST] = {
5670 [ALC260_ACER] = "acer", 5817 [ALC260_ACER] = "acer",
5671 [ALC260_WILL] = "will", 5818 [ALC260_WILL] = "will",
5672 [ALC260_REPLACER_672V] = "replacer", 5819 [ALC260_REPLACER_672V] = "replacer",
5820 [ALC260_FAVORIT100] = "favorit100",
5673#ifdef CONFIG_SND_DEBUG 5821#ifdef CONFIG_SND_DEBUG
5674 [ALC260_TEST] = "test", 5822 [ALC260_TEST] = "test",
5675#endif 5823#endif
@@ -5679,6 +5827,7 @@ static const char *alc260_models[ALC260_MODEL_LAST] = {
5679static struct snd_pci_quirk alc260_cfg_tbl[] = { 5827static struct snd_pci_quirk alc260_cfg_tbl[] = {
5680 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER), 5828 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_ACER),
5681 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER), 5829 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
5830 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
5682 SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013), 5831 SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
5683 SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013), 5832 SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_HP_3013),
5684 SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013), 5833 SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
@@ -5701,8 +5850,7 @@ static struct snd_pci_quirk alc260_cfg_tbl[] = {
5701static struct alc_config_preset alc260_presets[] = { 5850static struct alc_config_preset alc260_presets[] = {
5702 [ALC260_BASIC] = { 5851 [ALC260_BASIC] = {
5703 .mixers = { alc260_base_output_mixer, 5852 .mixers = { alc260_base_output_mixer,
5704 alc260_input_mixer, 5853 alc260_input_mixer },
5705 alc260_pc_beep_mixer },
5706 .init_verbs = { alc260_init_verbs }, 5854 .init_verbs = { alc260_init_verbs },
5707 .num_dacs = ARRAY_SIZE(alc260_dac_nids), 5855 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5708 .dac_nids = alc260_dac_nids, 5856 .dac_nids = alc260_dac_nids,
@@ -5781,6 +5929,18 @@ static struct alc_config_preset alc260_presets[] = {
5781 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources), 5929 .num_mux_defs = ARRAY_SIZE(alc260_acer_capture_sources),
5782 .input_mux = alc260_acer_capture_sources, 5930 .input_mux = alc260_acer_capture_sources,
5783 }, 5931 },
5932 [ALC260_FAVORIT100] = {
5933 .mixers = { alc260_favorit100_mixer },
5934 .init_verbs = { alc260_favorit100_init_verbs },
5935 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
5936 .dac_nids = alc260_dac_nids,
5937 .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
5938 .adc_nids = alc260_dual_adc_nids,
5939 .num_channel_mode = ARRAY_SIZE(alc260_modes),
5940 .channel_mode = alc260_modes,
5941 .num_mux_defs = ARRAY_SIZE(alc260_favorit100_capture_sources),
5942 .input_mux = alc260_favorit100_capture_sources,
5943 },
5784 [ALC260_WILL] = { 5944 [ALC260_WILL] = {
5785 .mixers = { alc260_will_mixer }, 5945 .mixers = { alc260_will_mixer },
5786 .init_verbs = { alc260_init_verbs, alc260_will_verbs }, 5946 .init_verbs = { alc260_init_verbs, alc260_will_verbs },
@@ -5857,6 +6017,12 @@ static int patch_alc260(struct hda_codec *codec)
5857 } 6017 }
5858 } 6018 }
5859 6019
6020 err = snd_hda_attach_beep_device(codec, 0x1);
6021 if (err < 0) {
6022 alc_free(codec);
6023 return err;
6024 }
6025
5860 if (board_config != ALC260_AUTO) 6026 if (board_config != ALC260_AUTO)
5861 setup_preset(spec, &alc260_presets[board_config]); 6027 setup_preset(spec, &alc260_presets[board_config]);
5862 6028
@@ -5882,6 +6048,7 @@ static int patch_alc260(struct hda_codec *codec)
5882 } 6048 }
5883 } 6049 }
5884 set_capture_mixer(spec); 6050 set_capture_mixer(spec);
6051 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5885 6052
5886 spec->vmaster_nid = 0x08; 6053 spec->vmaster_nid = 0x08;
5887 6054
@@ -6053,8 +6220,6 @@ static struct snd_kcontrol_new alc882_base_mixer[] = {
6053 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 6220 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6054 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 6221 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6055 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 6222 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6056 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6057 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6058 { } /* end */ 6223 { } /* end */
6059}; 6224};
6060 6225
@@ -6081,8 +6246,6 @@ static struct snd_kcontrol_new alc882_w2jc_mixer[] = {
6081 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 6246 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6082 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 6247 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6083 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 6248 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6084 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6085 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6086 { } /* end */ 6249 { } /* end */
6087}; 6250};
6088 6251
@@ -6134,8 +6297,6 @@ static struct snd_kcontrol_new alc882_asus_a7m_mixer[] = {
6134 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 6297 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6135 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 6298 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6136 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 6299 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6137 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6138 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6139 { } /* end */ 6300 { } /* end */
6140}; 6301};
6141 6302
@@ -6244,8 +6405,10 @@ static struct snd_kcontrol_new alc882_macpro_mixer[] = {
6244 HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT), 6405 HDA_CODEC_MUTE("Headphone Playback Switch", 0x18, 0x0, HDA_OUTPUT),
6245 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT), 6406 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
6246 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT), 6407 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
6408 /* FIXME: this looks suspicious...
6247 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT), 6409 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x02, HDA_INPUT),
6248 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT), 6410 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x02, HDA_INPUT),
6411 */
6249 { } /* end */ 6412 { } /* end */
6250}; 6413};
6251 6414
@@ -6877,19 +7040,9 @@ static void alc882_auto_init_analog_input(struct hda_codec *codec)
6877 7040
6878 for (i = 0; i < AUTO_PIN_LAST; i++) { 7041 for (i = 0; i < AUTO_PIN_LAST; i++) {
6879 hda_nid_t nid = spec->autocfg.input_pins[i]; 7042 hda_nid_t nid = spec->autocfg.input_pins[i];
6880 unsigned int vref;
6881 if (!nid) 7043 if (!nid)
6882 continue; 7044 continue;
6883 vref = PIN_IN; 7045 alc_set_input_pin(codec, nid, AUTO_PIN_FRONT_MIC /*i*/);
6884 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6885 unsigned int pincap;
6886 pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
6887 if ((pincap >> AC_PINCAP_VREF_SHIFT) &
6888 AC_PINCAP_VREF_80)
6889 vref = PIN_VREF80;
6890 }
6891 snd_hda_codec_write(codec, nid, 0,
6892 AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6893 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP) 7046 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6894 snd_hda_codec_write(codec, nid, 0, 7047 snd_hda_codec_write(codec, nid, 0,
6895 AC_VERB_SET_AMP_GAIN_MUTE, 7048 AC_VERB_SET_AMP_GAIN_MUTE,
@@ -6900,18 +7053,21 @@ static void alc882_auto_init_analog_input(struct hda_codec *codec)
6900static void alc882_auto_init_input_src(struct hda_codec *codec) 7053static void alc882_auto_init_input_src(struct hda_codec *codec)
6901{ 7054{
6902 struct alc_spec *spec = codec->spec; 7055 struct alc_spec *spec = codec->spec;
6903 const struct hda_input_mux *imux = spec->input_mux;
6904 int c; 7056 int c;
6905 7057
6906 for (c = 0; c < spec->num_adc_nids; c++) { 7058 for (c = 0; c < spec->num_adc_nids; c++) {
6907 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS]; 7059 hda_nid_t conn_list[HDA_MAX_NUM_INPUTS];
6908 hda_nid_t nid = spec->capsrc_nids[c]; 7060 hda_nid_t nid = spec->capsrc_nids[c];
7061 unsigned int mux_idx;
7062 const struct hda_input_mux *imux;
6909 int conns, mute, idx, item; 7063 int conns, mute, idx, item;
6910 7064
6911 conns = snd_hda_get_connections(codec, nid, conn_list, 7065 conns = snd_hda_get_connections(codec, nid, conn_list,
6912 ARRAY_SIZE(conn_list)); 7066 ARRAY_SIZE(conn_list));
6913 if (conns < 0) 7067 if (conns < 0)
6914 continue; 7068 continue;
7069 mux_idx = c >= spec->num_mux_defs ? 0 : c;
7070 imux = &spec->input_mux[mux_idx];
6915 for (idx = 0; idx < conns; idx++) { 7071 for (idx = 0; idx < conns; idx++) {
6916 /* if the current connection is the selected one, 7072 /* if the current connection is the selected one,
6917 * unmute it as default - otherwise mute it 7073 * unmute it as default - otherwise mute it
@@ -6924,8 +7080,20 @@ static void alc882_auto_init_input_src(struct hda_codec *codec)
6924 break; 7080 break;
6925 } 7081 }
6926 } 7082 }
6927 snd_hda_codec_write(codec, nid, 0, 7083 /* check if we have a selector or mixer
6928 AC_VERB_SET_AMP_GAIN_MUTE, mute); 7084 * we could check for the widget type instead, but
7085 * just check for Amp-In presence (in case of mixer
7086 * without amp-in there is something wrong, this
7087 * function shouldn't be used or capsrc nid is wrong)
7088 */
7089 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
7090 snd_hda_codec_write(codec, nid, 0,
7091 AC_VERB_SET_AMP_GAIN_MUTE,
7092 mute);
7093 else if (mute != AMP_IN_MUTE(idx))
7094 snd_hda_codec_write(codec, nid, 0,
7095 AC_VERB_SET_CONNECT_SEL,
7096 idx);
6929 } 7097 }
6930 } 7098 }
6931} 7099}
@@ -7054,6 +7222,12 @@ static int patch_alc882(struct hda_codec *codec)
7054 } 7222 }
7055 } 7223 }
7056 7224
7225 err = snd_hda_attach_beep_device(codec, 0x1);
7226 if (err < 0) {
7227 alc_free(codec);
7228 return err;
7229 }
7230
7057 if (board_config != ALC882_AUTO) 7231 if (board_config != ALC882_AUTO)
7058 setup_preset(spec, &alc882_presets[board_config]); 7232 setup_preset(spec, &alc882_presets[board_config]);
7059 7233
@@ -7074,7 +7248,7 @@ static int patch_alc882(struct hda_codec *codec)
7074 spec->stream_digital_playback = &alc882_pcm_digital_playback; 7248 spec->stream_digital_playback = &alc882_pcm_digital_playback;
7075 spec->stream_digital_capture = &alc882_pcm_digital_capture; 7249 spec->stream_digital_capture = &alc882_pcm_digital_capture;
7076 7250
7077 spec->is_mix_capture = 1; /* matrix-style capture */ 7251 spec->capture_style = CAPT_MIX; /* matrix-style capture */
7078 if (!spec->adc_nids && spec->input_mux) { 7252 if (!spec->adc_nids && spec->input_mux) {
7079 /* check whether NID 0x07 is valid */ 7253 /* check whether NID 0x07 is valid */
7080 unsigned int wcap = get_wcaps(codec, 0x07); 7254 unsigned int wcap = get_wcaps(codec, 0x07);
@@ -7091,6 +7265,7 @@ static int patch_alc882(struct hda_codec *codec)
7091 } 7265 }
7092 } 7266 }
7093 set_capture_mixer(spec); 7267 set_capture_mixer(spec);
7268 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
7094 7269
7095 spec->vmaster_nid = 0x0c; 7270 spec->vmaster_nid = 0x0c;
7096 7271
@@ -7142,10 +7317,14 @@ static hda_nid_t alc883_adc_nids_rev[2] = {
7142 0x09, 0x08 7317 0x09, 0x08
7143}; 7318};
7144 7319
7320#define alc889_adc_nids alc880_adc_nids
7321
7145static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 }; 7322static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
7146 7323
7147static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 }; 7324static hda_nid_t alc883_capsrc_nids_rev[2] = { 0x22, 0x23 };
7148 7325
7326#define alc889_capsrc_nids alc882_capsrc_nids
7327
7149/* input MUX */ 7328/* input MUX */
7150/* FIXME: should be a matrix-type input source selection */ 7329/* FIXME: should be a matrix-type input source selection */
7151 7330
@@ -7363,8 +7542,6 @@ static struct snd_kcontrol_new alc883_base_mixer[] = {
7363 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 7542 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7364 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 7543 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7365 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7544 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7366 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7367 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7368 { } /* end */ 7545 { } /* end */
7369}; 7546};
7370 7547
@@ -7427,8 +7604,6 @@ static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
7427 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 7604 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7428 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 7605 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7429 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7606 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7430 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7431 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7432 { } /* end */ 7607 { } /* end */
7433}; 7608};
7434 7609
@@ -7452,8 +7627,6 @@ static struct snd_kcontrol_new alc883_3ST_6ch_mixer[] = {
7452 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 7627 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7453 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 7628 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7454 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7629 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7455 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7456 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7457 { } /* end */ 7630 { } /* end */
7458}; 7631};
7459 7632
@@ -7478,8 +7651,6 @@ static struct snd_kcontrol_new alc883_3ST_6ch_intel_mixer[] = {
7478 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 7651 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
7479 HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT), 7652 HDA_CODEC_VOLUME("Front Mic Boost", 0x18, 0, HDA_INPUT),
7480 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 7653 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
7481 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7482 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7483 { } /* end */ 7654 { } /* end */
7484}; 7655};
7485 7656
@@ -7503,8 +7674,6 @@ static struct snd_kcontrol_new alc883_fivestack_mixer[] = {
7503 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 7674 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
7504 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 7675 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
7505 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 7676 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
7506 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
7507 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
7508 { } /* end */ 7677 { } /* end */
7509}; 7678};
7510 7679
@@ -7912,36 +8081,83 @@ static struct hda_verb alc888_lenovo_sky_verbs[] = {
7912 { } /* end */ 8081 { } /* end */
7913}; 8082};
7914 8083
8084static struct hda_verb alc888_6st_dell_verbs[] = {
8085 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
8086 { }
8087};
8088
8089static void alc888_3st_hp_front_automute(struct hda_codec *codec)
8090{
8091 unsigned int present, bits;
8092
8093 present = snd_hda_codec_read(codec, 0x1b, 0,
8094 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
8095 bits = present ? HDA_AMP_MUTE : 0;
8096 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8097 HDA_AMP_MUTE, bits);
8098 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8099 HDA_AMP_MUTE, bits);
8100 snd_hda_codec_amp_stereo(codec, 0x18, HDA_OUTPUT, 0,
8101 HDA_AMP_MUTE, bits);
8102}
8103
8104static void alc888_3st_hp_unsol_event(struct hda_codec *codec,
8105 unsigned int res)
8106{
8107 switch (res >> 26) {
8108 case ALC880_HP_EVENT:
8109 alc888_3st_hp_front_automute(codec);
8110 break;
8111 }
8112}
8113
7915static struct hda_verb alc888_3st_hp_verbs[] = { 8114static struct hda_verb alc888_3st_hp_verbs[] = {
7916 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */ 8115 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */
7917 {0x16, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Rear : output 1 (0x0d) */ 8116 {0x16, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Rear : output 1 (0x0d) */
7918 {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* CLFE : output 2 (0x0e) */ 8117 {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* CLFE : output 2 (0x0e) */
7919 { }
7920};
7921
7922static struct hda_verb alc888_6st_dell_verbs[] = {
7923 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, 8118 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7924 { } 8119 { } /* end */
7925}; 8120};
7926 8121
8122/*
8123 * 2ch mode
8124 */
7927static struct hda_verb alc888_3st_hp_2ch_init[] = { 8125static struct hda_verb alc888_3st_hp_2ch_init[] = {
7928 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, 8126 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
7929 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 8127 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7930 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 8128 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
7931 { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE }, 8129 { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
7932 { } 8130 { } /* end */
8131};
8132
8133/*
8134 * 4ch mode
8135 */
8136static struct hda_verb alc888_3st_hp_4ch_init[] = {
8137 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
8138 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
8139 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
8140 { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8141 { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8142 { } /* end */
7933}; 8143};
7934 8144
8145/*
8146 * 6ch mode
8147 */
7935static struct hda_verb alc888_3st_hp_6ch_init[] = { 8148static struct hda_verb alc888_3st_hp_6ch_init[] = {
7936 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, 8149 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7937 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, 8150 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
8151 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
7938 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, 8152 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
7939 { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, 8153 { 0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
7940 { } 8154 { 0x16, AC_VERB_SET_CONNECT_SEL, 0x01 },
8155 { } /* end */
7941}; 8156};
7942 8157
7943static struct hda_channel_mode alc888_3st_hp_modes[2] = { 8158static struct hda_channel_mode alc888_3st_hp_modes[3] = {
7944 { 2, alc888_3st_hp_2ch_init }, 8159 { 2, alc888_3st_hp_2ch_init },
8160 { 4, alc888_3st_hp_4ch_init },
7945 { 6, alc888_3st_hp_6ch_init }, 8161 { 6, alc888_3st_hp_6ch_init },
7946}; 8162};
7947 8163
@@ -8202,7 +8418,7 @@ static void alc888_6st_dell_unsol_event(struct hda_codec *codec,
8202{ 8418{
8203 switch (res >> 26) { 8419 switch (res >> 26) {
8204 case ALC880_HP_EVENT: 8420 case ALC880_HP_EVENT:
8205 printk("hp_event\n"); 8421 /* printk(KERN_DEBUG "hp_event\n"); */
8206 alc888_6st_dell_front_automute(codec); 8422 alc888_6st_dell_front_automute(codec);
8207 break; 8423 break;
8208 } 8424 }
@@ -8461,6 +8677,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
8461 SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG), 8677 SND_PCI_QUIRK(0x1019, 0x6668, "ECS", ALC883_3ST_6ch_DIG),
8462 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE), 8678 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_ACER_ASPIRE),
8463 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE), 8679 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_ACER_ASPIRE),
8680 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_ACER_ASPIRE),
8464 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE), 8681 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_ACER_ASPIRE),
8465 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE), 8682 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_ACER_ASPIRE),
8466 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE), 8683 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_ACER_ASPIRE),
@@ -8468,17 +8685,21 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
8468 ALC888_ACER_ASPIRE_4930G), 8685 ALC888_ACER_ASPIRE_4930G),
8469 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G", 8686 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
8470 ALC888_ACER_ASPIRE_4930G), 8687 ALC888_ACER_ASPIRE_4930G),
8688 SND_PCI_QUIRK(0x1025, 0x0157, "Acer X3200", ALC883_AUTO),
8689 SND_PCI_QUIRK(0x1025, 0x0158, "Acer AX1700-U3700A", ALC883_AUTO),
8471 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G", 8690 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
8472 ALC888_ACER_ASPIRE_4930G), 8691 ALC888_ACER_ASPIRE_4930G),
8473 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G", 8692 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
8474 ALC888_ACER_ASPIRE_4930G), 8693 ALC888_ACER_ASPIRE_4930G),
8475 SND_PCI_QUIRK(0x1025, 0, "Acer laptop", ALC883_ACER), /* default Acer */ 8694 /* default Acer */
8695 SND_PCI_QUIRK_VENDOR(0x1025, "Acer laptop", ALC883_ACER),
8476 SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL), 8696 SND_PCI_QUIRK(0x1028, 0x020d, "Dell Inspiron 530", ALC888_6ST_DELL),
8477 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG), 8697 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
8478 SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP), 8698 SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
8479 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP), 8699 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
8480 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG), 8700 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
8481 SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP), 8701 SND_PCI_QUIRK(0x103c, 0x2a66, "HP Acacia", ALC888_3ST_HP),
8702 SND_PCI_QUIRK(0x103c, 0x2a72, "HP Educ.ar", ALC888_3ST_HP),
8482 SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V), 8703 SND_PCI_QUIRK(0x1043, 0x1873, "Asus M90V", ALC888_ASUS_M90V),
8483 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG), 8704 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
8484 SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG), 8705 SND_PCI_QUIRK(0x1043, 0x8284, "Asus Z37E", ALC883_6ST_DIG),
@@ -8518,7 +8739,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
8518 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG), 8739 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
8519 SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720), 8740 SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
8520 SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720), 8741 SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
8521 SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD), 8742 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC883_LAPTOP_EAPD),
8522 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch), 8743 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
8523 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION), 8744 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
8524 SND_PCI_QUIRK(0x1734, 0x1107, "FSC AMILO Xi2550", 8745 SND_PCI_QUIRK(0x1734, 0x1107, "FSC AMILO Xi2550",
@@ -8543,6 +8764,10 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
8543 {} 8764 {}
8544}; 8765};
8545 8766
8767static hda_nid_t alc1200_slave_dig_outs[] = {
8768 ALC883_DIGOUT_NID, 0,
8769};
8770
8546static struct alc_config_preset alc883_presets[] = { 8771static struct alc_config_preset alc883_presets[] = {
8547 [ALC883_3ST_2ch_DIG] = { 8772 [ALC883_3ST_2ch_DIG] = {
8548 .mixers = { alc883_3ST_2ch_mixer }, 8773 .mixers = { alc883_3ST_2ch_mixer },
@@ -8778,6 +9003,8 @@ static struct alc_config_preset alc883_presets[] = {
8778 .channel_mode = alc888_3st_hp_modes, 9003 .channel_mode = alc888_3st_hp_modes,
8779 .need_dac_fix = 1, 9004 .need_dac_fix = 1,
8780 .input_mux = &alc883_capture_source, 9005 .input_mux = &alc883_capture_source,
9006 .unsol_event = alc888_3st_hp_unsol_event,
9007 .init_hook = alc888_3st_hp_front_automute,
8781 }, 9008 },
8782 [ALC888_6ST_DELL] = { 9009 [ALC888_6ST_DELL] = {
8783 .mixers = { alc883_base_mixer, alc883_chmode_mixer }, 9010 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
@@ -8883,6 +9110,7 @@ static struct alc_config_preset alc883_presets[] = {
8883 .dac_nids = alc883_dac_nids, 9110 .dac_nids = alc883_dac_nids,
8884 .dig_out_nid = ALC1200_DIGOUT_NID, 9111 .dig_out_nid = ALC1200_DIGOUT_NID,
8885 .dig_in_nid = ALC883_DIGIN_NID, 9112 .dig_in_nid = ALC883_DIGIN_NID,
9113 .slave_dig_outs = alc1200_slave_dig_outs,
8886 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 9114 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
8887 .channel_mode = alc883_sixstack_modes, 9115 .channel_mode = alc883_sixstack_modes,
8888 .input_mux = &alc883_capture_source, 9116 .input_mux = &alc883_capture_source,
@@ -8950,11 +9178,9 @@ static void alc883_auto_init_analog_input(struct hda_codec *codec)
8950 for (i = 0; i < AUTO_PIN_LAST; i++) { 9178 for (i = 0; i < AUTO_PIN_LAST; i++) {
8951 hda_nid_t nid = spec->autocfg.input_pins[i]; 9179 hda_nid_t nid = spec->autocfg.input_pins[i];
8952 if (alc883_is_input_pin(nid)) { 9180 if (alc883_is_input_pin(nid)) {
8953 snd_hda_codec_write(codec, nid, 0, 9181 alc_set_input_pin(codec, nid, i);
8954 AC_VERB_SET_PIN_WIDGET_CONTROL, 9182 if (nid != ALC883_PIN_CD_NID &&
8955 (i <= AUTO_PIN_FRONT_MIC ? 9183 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
8956 PIN_VREF80 : PIN_IN));
8957 if (nid != ALC883_PIN_CD_NID)
8958 snd_hda_codec_write(codec, nid, 0, 9184 snd_hda_codec_write(codec, nid, 0,
8959 AC_VERB_SET_AMP_GAIN_MUTE, 9185 AC_VERB_SET_AMP_GAIN_MUTE,
8960 AMP_OUT_MUTE); 9186 AMP_OUT_MUTE);
@@ -8969,6 +9195,8 @@ static int alc883_parse_auto_config(struct hda_codec *codec)
8969{ 9195{
8970 struct alc_spec *spec = codec->spec; 9196 struct alc_spec *spec = codec->spec;
8971 int err = alc880_parse_auto_config(codec); 9197 int err = alc880_parse_auto_config(codec);
9198 struct auto_pin_cfg *cfg = &spec->autocfg;
9199 int i;
8972 9200
8973 if (err < 0) 9201 if (err < 0)
8974 return err; 9202 return err;
@@ -8982,6 +9210,26 @@ static int alc883_parse_auto_config(struct hda_codec *codec)
8982 /* hack - override the init verbs */ 9210 /* hack - override the init verbs */
8983 spec->init_verbs[0] = alc883_auto_init_verbs; 9211 spec->init_verbs[0] = alc883_auto_init_verbs;
8984 9212
9213 /* setup input_mux for ALC889 */
9214 if (codec->vendor_id == 0x10ec0889) {
9215 /* digital-mic input pin is excluded in alc880_auto_create..()
9216 * because it's under 0x18
9217 */
9218 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
9219 cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
9220 struct hda_input_mux *imux = &spec->private_imux[0];
9221 for (i = 1; i < 3; i++)
9222 memcpy(&spec->private_imux[i],
9223 &spec->private_imux[0],
9224 sizeof(spec->private_imux[0]));
9225 imux->items[imux->num_items].label = "Int DMic";
9226 imux->items[imux->num_items].index = 0x0b;
9227 imux->num_items++;
9228 spec->num_mux_defs = 3;
9229 spec->input_mux = spec->private_imux;
9230 }
9231 }
9232
8985 return 1; /* config found */ 9233 return 1; /* config found */
8986} 9234}
8987 9235
@@ -9033,6 +9281,12 @@ static int patch_alc883(struct hda_codec *codec)
9033 } 9281 }
9034 } 9282 }
9035 9283
9284 err = snd_hda_attach_beep_device(codec, 0x1);
9285 if (err < 0) {
9286 alc_free(codec);
9287 return err;
9288 }
9289
9036 if (board_config != ALC883_AUTO) 9290 if (board_config != ALC883_AUTO)
9037 setup_preset(spec, &alc883_presets[board_config]); 9291 setup_preset(spec, &alc883_presets[board_config]);
9038 9292
@@ -9045,14 +9299,36 @@ static int patch_alc883(struct hda_codec *codec)
9045 spec->stream_name_analog = "ALC888 Analog"; 9299 spec->stream_name_analog = "ALC888 Analog";
9046 spec->stream_name_digital = "ALC888 Digital"; 9300 spec->stream_name_digital = "ALC888 Digital";
9047 } 9301 }
9302 if (!spec->num_adc_nids) {
9303 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9304 spec->adc_nids = alc883_adc_nids;
9305 }
9306 if (!spec->capsrc_nids)
9307 spec->capsrc_nids = alc883_capsrc_nids;
9308 spec->capture_style = CAPT_MIX; /* matrix-style capture */
9048 break; 9309 break;
9049 case 0x10ec0889: 9310 case 0x10ec0889:
9050 spec->stream_name_analog = "ALC889 Analog"; 9311 spec->stream_name_analog = "ALC889 Analog";
9051 spec->stream_name_digital = "ALC889 Digital"; 9312 spec->stream_name_digital = "ALC889 Digital";
9313 if (!spec->num_adc_nids) {
9314 spec->num_adc_nids = ARRAY_SIZE(alc889_adc_nids);
9315 spec->adc_nids = alc889_adc_nids;
9316 }
9317 if (!spec->capsrc_nids)
9318 spec->capsrc_nids = alc889_capsrc_nids;
9319 spec->capture_style = CAPT_1MUX_MIX; /* 1mux/Nmix-style
9320 capture */
9052 break; 9321 break;
9053 default: 9322 default:
9054 spec->stream_name_analog = "ALC883 Analog"; 9323 spec->stream_name_analog = "ALC883 Analog";
9055 spec->stream_name_digital = "ALC883 Digital"; 9324 spec->stream_name_digital = "ALC883 Digital";
9325 if (!spec->num_adc_nids) {
9326 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9327 spec->adc_nids = alc883_adc_nids;
9328 }
9329 if (!spec->capsrc_nids)
9330 spec->capsrc_nids = alc883_capsrc_nids;
9331 spec->capture_style = CAPT_MIX; /* matrix-style capture */
9056 break; 9332 break;
9057 } 9333 }
9058 9334
@@ -9063,15 +9339,9 @@ static int patch_alc883(struct hda_codec *codec)
9063 spec->stream_digital_playback = &alc883_pcm_digital_playback; 9339 spec->stream_digital_playback = &alc883_pcm_digital_playback;
9064 spec->stream_digital_capture = &alc883_pcm_digital_capture; 9340 spec->stream_digital_capture = &alc883_pcm_digital_capture;
9065 9341
9066 if (!spec->num_adc_nids) {
9067 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
9068 spec->adc_nids = alc883_adc_nids;
9069 }
9070 if (!spec->capsrc_nids)
9071 spec->capsrc_nids = alc883_capsrc_nids;
9072 spec->is_mix_capture = 1; /* matrix-style capture */
9073 if (!spec->cap_mixer) 9342 if (!spec->cap_mixer)
9074 set_capture_mixer(spec); 9343 set_capture_mixer(spec);
9344 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
9075 9345
9076 spec->vmaster_nid = 0x0c; 9346 spec->vmaster_nid = 0x0c;
9077 9347
@@ -9124,8 +9394,6 @@ static struct snd_kcontrol_new alc262_base_mixer[] = {
9124 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 9394 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9125 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 9395 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9126 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 9396 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9127 /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9128 HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9129 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT), 9397 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
9130 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT), 9398 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9131 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT), 9399 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
@@ -9146,8 +9414,6 @@ static struct snd_kcontrol_new alc262_hippo1_mixer[] = {
9146 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 9414 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9147 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 9415 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9148 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT), 9416 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9149 /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9150 HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT), */
9151 /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/ 9417 /*HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),*/
9152 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 9418 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
9153 { } /* end */ 9419 { } /* end */
@@ -9256,8 +9522,6 @@ static struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
9256 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 9522 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9257 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 9523 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9258 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 9524 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9259 HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9260 HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9261 HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT), 9525 HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
9262 HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT), 9526 HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
9263 { } /* end */ 9527 { } /* end */
@@ -9286,8 +9550,6 @@ static struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
9286 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT), 9550 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
9287 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 9551 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9288 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 9552 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9289 HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
9290 HDA_CODEC_MUTE("PC Beep Playback Switch", 0x0b, 0x05, HDA_INPUT),
9291 { } /* end */ 9553 { } /* end */
9292}; 9554};
9293 9555
@@ -9435,6 +9697,67 @@ static struct snd_kcontrol_new alc262_benq_t31_mixer[] = {
9435 { } /* end */ 9697 { } /* end */
9436}; 9698};
9437 9699
9700static struct snd_kcontrol_new alc262_tyan_mixer[] = {
9701 HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
9702 HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
9703 HDA_CODEC_VOLUME("Aux Playback Volume", 0x0b, 0x06, HDA_INPUT),
9704 HDA_CODEC_MUTE("Aux Playback Switch", 0x0b, 0x06, HDA_INPUT),
9705 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
9706 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
9707 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9708 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
9709 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9710 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
9711 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
9712 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
9713 { } /* end */
9714};
9715
9716static struct hda_verb alc262_tyan_verbs[] = {
9717 /* Headphone automute */
9718 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
9719 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9720 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
9721
9722 /* P11 AUX_IN, white 4-pin connector */
9723 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9724 {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_1, 0xe1},
9725 {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_2, 0x93},
9726 {0x14, AC_VERB_SET_CONFIG_DEFAULT_BYTES_3, 0x19},
9727
9728 {}
9729};
9730
9731/* unsolicited event for HP jack sensing */
9732static void alc262_tyan_automute(struct hda_codec *codec)
9733{
9734 unsigned int mute;
9735 unsigned int present;
9736
9737 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
9738 present = snd_hda_codec_read(codec, 0x1b, 0,
9739 AC_VERB_GET_PIN_SENSE, 0);
9740 present = (present & 0x80000000) != 0;
9741 if (present) {
9742 /* mute line output on ATX panel */
9743 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9744 HDA_AMP_MUTE, HDA_AMP_MUTE);
9745 } else {
9746 /* unmute line output if necessary */
9747 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
9748 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
9749 HDA_AMP_MUTE, mute);
9750 }
9751}
9752
9753static void alc262_tyan_unsol_event(struct hda_codec *codec,
9754 unsigned int res)
9755{
9756 if ((res >> 26) != ALC880_HP_EVENT)
9757 return;
9758 alc262_tyan_automute(codec);
9759}
9760
9438#define alc262_capture_mixer alc882_capture_mixer 9761#define alc262_capture_mixer alc882_capture_mixer
9439#define alc262_capture_alt_mixer alc882_capture_alt_mixer 9762#define alc262_capture_alt_mixer alc882_capture_alt_mixer
9440 9763
@@ -9901,8 +10224,6 @@ static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
9901 }, 10224 },
9902 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 10225 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
9903 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 10226 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
9904 HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
9905 HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
9906 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 10227 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
9907 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 10228 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
9908 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 10229 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
@@ -10474,8 +10795,14 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
10474 alc262_ignore); 10795 alc262_ignore);
10475 if (err < 0) 10796 if (err < 0)
10476 return err; 10797 return err;
10477 if (!spec->autocfg.line_outs) 10798 if (!spec->autocfg.line_outs) {
10799 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
10800 spec->multiout.max_channels = 2;
10801 spec->no_analog = 1;
10802 goto dig_only;
10803 }
10478 return 0; /* can't find valid BIOS pin config */ 10804 return 0; /* can't find valid BIOS pin config */
10805 }
10479 err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg); 10806 err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg);
10480 if (err < 0) 10807 if (err < 0)
10481 return err; 10808 return err;
@@ -10485,8 +10812,11 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
10485 10812
10486 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 10813 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
10487 10814
10488 if (spec->autocfg.dig_out_pin) 10815 dig_only:
10816 if (spec->autocfg.dig_outs) {
10489 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID; 10817 spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
10818 spec->dig_out_type = spec->autocfg.dig_out_type[0];
10819 }
10490 if (spec->autocfg.dig_in_pin) 10820 if (spec->autocfg.dig_in_pin)
10491 spec->dig_in_nid = ALC262_DIGIN_NID; 10821 spec->dig_in_nid = ALC262_DIGIN_NID;
10492 10822
@@ -10495,13 +10825,12 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
10495 10825
10496 add_verb(spec, alc262_volume_init_verbs); 10826 add_verb(spec, alc262_volume_init_verbs);
10497 spec->num_mux_defs = 1; 10827 spec->num_mux_defs = 1;
10498 spec->input_mux = &spec->private_imux; 10828 spec->input_mux = &spec->private_imux[0];
10499 10829
10500 err = alc_auto_add_mic_boost(codec); 10830 err = alc_auto_add_mic_boost(codec);
10501 if (err < 0) 10831 if (err < 0)
10502 return err; 10832 return err;
10503 10833
10504 store_pin_configs(codec);
10505 return 1; 10834 return 1;
10506} 10835}
10507 10836
@@ -10543,21 +10872,19 @@ static const char *alc262_models[ALC262_MODEL_LAST] = {
10543 [ALC262_ULTRA] = "ultra", 10872 [ALC262_ULTRA] = "ultra",
10544 [ALC262_LENOVO_3000] = "lenovo-3000", 10873 [ALC262_LENOVO_3000] = "lenovo-3000",
10545 [ALC262_NEC] = "nec", 10874 [ALC262_NEC] = "nec",
10875 [ALC262_TYAN] = "tyan",
10546 [ALC262_AUTO] = "auto", 10876 [ALC262_AUTO] = "auto",
10547}; 10877};
10548 10878
10549static struct snd_pci_quirk alc262_cfg_tbl[] = { 10879static struct snd_pci_quirk alc262_cfg_tbl[] = {
10550 SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO), 10880 SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
10551 SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC), 10881 SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
10552 SND_PCI_QUIRK(0x103c, 0x12fe, "HP xw9400", ALC262_HP_BPC), 10882 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
10553 SND_PCI_QUIRK(0x103c, 0x12ff, "HP xw4550", ALC262_HP_BPC), 10883 ALC262_HP_BPC),
10554 SND_PCI_QUIRK(0x103c, 0x1306, "HP xw8600", ALC262_HP_BPC), 10884 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
10555 SND_PCI_QUIRK(0x103c, 0x1307, "HP xw6600", ALC262_HP_BPC), 10885 ALC262_HP_BPC),
10556 SND_PCI_QUIRK(0x103c, 0x1308, "HP xw4600", ALC262_HP_BPC), 10886 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
10557 SND_PCI_QUIRK(0x103c, 0x1309, "HP xw4*00", ALC262_HP_BPC), 10887 ALC262_HP_BPC),
10558 SND_PCI_QUIRK(0x103c, 0x130a, "HP xw6*00", ALC262_HP_BPC),
10559 SND_PCI_QUIRK(0x103c, 0x130b, "HP xw8*00", ALC262_HP_BPC),
10560 SND_PCI_QUIRK(0x103c, 0x170b, "HP xw*", ALC262_HP_BPC),
10561 SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL), 10888 SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
10562 SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF), 10889 SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
10563 SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL), 10890 SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
@@ -10575,17 +10902,17 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = {
10575 SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD), 10902 SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10576 SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO), 10903 SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
10577 SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD), 10904 SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
10578 SND_PCI_QUIRK(0x104d, 0x900e, "Sony ASSAMD", ALC262_SONY_ASSAMD), 10905 SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
10579 SND_PCI_QUIRK(0x104d, 0x9015, "Sony 0x9015", ALC262_SONY_ASSAMD), 10906 SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
10580 SND_PCI_QUIRK(0x104d, 0x9033, "Sony VAIO VGN-SR19XN", 10907 ALC262_SONY_ASSAMD),
10581 ALC262_SONY_ASSAMD),
10582 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1", 10908 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
10583 ALC262_TOSHIBA_RX1), 10909 ALC262_TOSHIBA_RX1),
10584 SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06), 10910 SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
10585 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU), 10911 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
10586 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU), 10912 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
10587 SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA), 10913 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_TYAN),
10588 SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA), 10914 SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc032, "Samsung Q1",
10915 ALC262_ULTRA),
10589 SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO), 10916 SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
10590 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000), 10917 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
10591 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8), 10918 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
@@ -10802,6 +11129,19 @@ static struct alc_config_preset alc262_presets[] = {
10802 .unsol_event = alc262_hippo_unsol_event, 11129 .unsol_event = alc262_hippo_unsol_event,
10803 .init_hook = alc262_hippo_automute, 11130 .init_hook = alc262_hippo_automute,
10804 }, 11131 },
11132 [ALC262_TYAN] = {
11133 .mixers = { alc262_tyan_mixer },
11134 .init_verbs = { alc262_init_verbs, alc262_tyan_verbs},
11135 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
11136 .dac_nids = alc262_dac_nids,
11137 .hp_nid = 0x02,
11138 .dig_out_nid = ALC262_DIGOUT_NID,
11139 .num_channel_mode = ARRAY_SIZE(alc262_modes),
11140 .channel_mode = alc262_modes,
11141 .input_mux = &alc262_capture_source,
11142 .unsol_event = alc262_tyan_unsol_event,
11143 .init_hook = alc262_tyan_automute,
11144 },
10805}; 11145};
10806 11146
10807static int patch_alc262(struct hda_codec *codec) 11147static int patch_alc262(struct hda_codec *codec)
@@ -10854,6 +11194,14 @@ static int patch_alc262(struct hda_codec *codec)
10854 } 11194 }
10855 } 11195 }
10856 11196
11197 if (!spec->no_analog) {
11198 err = snd_hda_attach_beep_device(codec, 0x1);
11199 if (err < 0) {
11200 alc_free(codec);
11201 return err;
11202 }
11203 }
11204
10857 if (board_config != ALC262_AUTO) 11205 if (board_config != ALC262_AUTO)
10858 setup_preset(spec, &alc262_presets[board_config]); 11206 setup_preset(spec, &alc262_presets[board_config]);
10859 11207
@@ -10865,7 +11213,7 @@ static int patch_alc262(struct hda_codec *codec)
10865 spec->stream_digital_playback = &alc262_pcm_digital_playback; 11213 spec->stream_digital_playback = &alc262_pcm_digital_playback;
10866 spec->stream_digital_capture = &alc262_pcm_digital_capture; 11214 spec->stream_digital_capture = &alc262_pcm_digital_capture;
10867 11215
10868 spec->is_mix_capture = 1; 11216 spec->capture_style = CAPT_MIX;
10869 if (!spec->adc_nids && spec->input_mux) { 11217 if (!spec->adc_nids && spec->input_mux) {
10870 /* check whether NID 0x07 is valid */ 11218 /* check whether NID 0x07 is valid */
10871 unsigned int wcap = get_wcaps(codec, 0x07); 11219 unsigned int wcap = get_wcaps(codec, 0x07);
@@ -10882,8 +11230,10 @@ static int patch_alc262(struct hda_codec *codec)
10882 spec->capsrc_nids = alc262_capsrc_nids; 11230 spec->capsrc_nids = alc262_capsrc_nids;
10883 } 11231 }
10884 } 11232 }
10885 if (!spec->cap_mixer) 11233 if (!spec->cap_mixer && !spec->no_analog)
10886 set_capture_mixer(spec); 11234 set_capture_mixer(spec);
11235 if (!spec->no_analog)
11236 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
10887 11237
10888 spec->vmaster_nid = 0x0c; 11238 spec->vmaster_nid = 0x0c;
10889 11239
@@ -11263,19 +11613,13 @@ static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
11263static struct hda_verb alc268_base_init_verbs[] = { 11613static struct hda_verb alc268_base_init_verbs[] = {
11264 /* Unmute DAC0-1 and set vol = 0 */ 11614 /* Unmute DAC0-1 and set vol = 0 */
11265 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 11615 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11266 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11267 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11268 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, 11616 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11269 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11270 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11271 11617
11272 /* 11618 /*
11273 * Set up output mixers (0x0c - 0x0e) 11619 * Set up output mixers (0x0c - 0x0e)
11274 */ 11620 */
11275 /* set vol=0 to output mixers */ 11621 /* set vol=0 to output mixers */
11276 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 11622 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11277 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11278 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11279 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00}, 11623 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
11280 11624
11281 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 11625 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
@@ -11294,9 +11638,7 @@ static struct hda_verb alc268_base_init_verbs[] = {
11294 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 11638 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11295 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 11639 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11296 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 11640 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11297 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11298 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 11641 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11299 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11300 11642
11301 /* set PCBEEP vol = 0, mute connections */ 11643 /* set PCBEEP vol = 0, mute connections */
11302 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 11644 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
@@ -11318,10 +11660,8 @@ static struct hda_verb alc268_base_init_verbs[] = {
11318 */ 11660 */
11319static struct hda_verb alc268_volume_init_verbs[] = { 11661static struct hda_verb alc268_volume_init_verbs[] = {
11320 /* set output DAC */ 11662 /* set output DAC */
11321 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 11663 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11322 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 11664 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11323 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11324 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11325 11665
11326 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24}, 11666 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
11327 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24}, 11667 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
@@ -11329,16 +11669,12 @@ static struct hda_verb alc268_volume_init_verbs[] = {
11329 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, 11669 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11330 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20}, 11670 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
11331 11671
11332 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
11333 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 11672 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11334 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
11335 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 11673 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11336 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 11674 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
11337 11675
11338 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 11676 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11339 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11340 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 11677 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11341 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
11342 11678
11343 /* set PCBEEP vol = 0, mute connections */ 11679 /* set PCBEEP vol = 0, mute connections */
11344 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 11680 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
@@ -11537,7 +11873,7 @@ static int alc268_auto_create_multi_out_ctls(struct alc_spec *spec,
11537static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec, 11873static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
11538 const struct auto_pin_cfg *cfg) 11874 const struct auto_pin_cfg *cfg)
11539{ 11875{
11540 struct hda_input_mux *imux = &spec->private_imux; 11876 struct hda_input_mux *imux = &spec->private_imux[0];
11541 int i, idx1; 11877 int i, idx1;
11542 11878
11543 for (i = 0; i < AUTO_PIN_LAST; i++) { 11879 for (i = 0; i < AUTO_PIN_LAST; i++) {
@@ -11631,9 +11967,14 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
11631 alc268_ignore); 11967 alc268_ignore);
11632 if (err < 0) 11968 if (err < 0)
11633 return err; 11969 return err;
11634 if (!spec->autocfg.line_outs) 11970 if (!spec->autocfg.line_outs) {
11971 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
11972 spec->multiout.max_channels = 2;
11973 spec->no_analog = 1;
11974 goto dig_only;
11975 }
11635 return 0; /* can't find valid BIOS pin config */ 11976 return 0; /* can't find valid BIOS pin config */
11636 11977 }
11637 err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg); 11978 err = alc268_auto_create_multi_out_ctls(spec, &spec->autocfg);
11638 if (err < 0) 11979 if (err < 0)
11639 return err; 11980 return err;
@@ -11643,25 +11984,26 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
11643 11984
11644 spec->multiout.max_channels = 2; 11985 spec->multiout.max_channels = 2;
11645 11986
11987 dig_only:
11646 /* digital only support output */ 11988 /* digital only support output */
11647 if (spec->autocfg.dig_out_pin) 11989 if (spec->autocfg.dig_outs) {
11648 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID; 11990 spec->multiout.dig_out_nid = ALC268_DIGOUT_NID;
11649 11991 spec->dig_out_type = spec->autocfg.dig_out_type[0];
11992 }
11650 if (spec->kctls.list) 11993 if (spec->kctls.list)
11651 add_mixer(spec, spec->kctls.list); 11994 add_mixer(spec, spec->kctls.list);
11652 11995
11653 if (spec->autocfg.speaker_pins[0] != 0x1d) 11996 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d)
11654 add_mixer(spec, alc268_beep_mixer); 11997 add_mixer(spec, alc268_beep_mixer);
11655 11998
11656 add_verb(spec, alc268_volume_init_verbs); 11999 add_verb(spec, alc268_volume_init_verbs);
11657 spec->num_mux_defs = 1; 12000 spec->num_mux_defs = 1;
11658 spec->input_mux = &spec->private_imux; 12001 spec->input_mux = &spec->private_imux[0];
11659 12002
11660 err = alc_auto_add_mic_boost(codec); 12003 err = alc_auto_add_mic_boost(codec);
11661 if (err < 0) 12004 if (err < 0)
11662 return err; 12005 return err;
11663 12006
11664 store_pin_configs(codec);
11665 return 1; 12007 return 1;
11666} 12008}
11667 12009
@@ -11723,7 +12065,7 @@ static struct snd_pci_quirk alc268_cfg_tbl[] = {
11723 12065
11724static struct alc_config_preset alc268_presets[] = { 12066static struct alc_config_preset alc268_presets[] = {
11725 [ALC267_QUANTA_IL1] = { 12067 [ALC267_QUANTA_IL1] = {
11726 .mixers = { alc267_quanta_il1_mixer }, 12068 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer },
11727 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 12069 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11728 alc267_quanta_il1_verbs }, 12070 alc267_quanta_il1_verbs },
11729 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 12071 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
@@ -11805,7 +12147,8 @@ static struct alc_config_preset alc268_presets[] = {
11805 }, 12147 },
11806 [ALC268_ACER_ASPIRE_ONE] = { 12148 [ALC268_ACER_ASPIRE_ONE] = {
11807 .mixers = { alc268_acer_aspire_one_mixer, 12149 .mixers = { alc268_acer_aspire_one_mixer,
11808 alc268_capture_alt_mixer }, 12150 alc268_beep_mixer,
12151 alc268_capture_alt_mixer },
11809 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 12152 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
11810 alc268_acer_aspire_one_verbs }, 12153 alc268_acer_aspire_one_verbs },
11811 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 12154 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
@@ -11874,7 +12217,7 @@ static int patch_alc268(struct hda_codec *codec)
11874{ 12217{
11875 struct alc_spec *spec; 12218 struct alc_spec *spec;
11876 int board_config; 12219 int board_config;
11877 int err; 12220 int i, has_beep, err;
11878 12221
11879 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL); 12222 spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
11880 if (spec == NULL) 12223 if (spec == NULL)
@@ -11923,15 +12266,30 @@ static int patch_alc268(struct hda_codec *codec)
11923 12266
11924 spec->stream_digital_playback = &alc268_pcm_digital_playback; 12267 spec->stream_digital_playback = &alc268_pcm_digital_playback;
11925 12268
11926 if (!query_amp_caps(codec, 0x1d, HDA_INPUT)) 12269 has_beep = 0;
11927 /* override the amp caps for beep generator */ 12270 for (i = 0; i < spec->num_mixers; i++) {
11928 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT, 12271 if (spec->mixers[i] == alc268_beep_mixer) {
12272 has_beep = 1;
12273 break;
12274 }
12275 }
12276
12277 if (has_beep) {
12278 err = snd_hda_attach_beep_device(codec, 0x1);
12279 if (err < 0) {
12280 alc_free(codec);
12281 return err;
12282 }
12283 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
12284 /* override the amp caps for beep generator */
12285 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
11929 (0x0c << AC_AMPCAP_OFFSET_SHIFT) | 12286 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
11930 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) | 12287 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
11931 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) | 12288 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
11932 (0 << AC_AMPCAP_MUTE_SHIFT)); 12289 (0 << AC_AMPCAP_MUTE_SHIFT));
12290 }
11933 12291
11934 if (!spec->adc_nids && spec->input_mux) { 12292 if (!spec->no_analog && !spec->adc_nids && spec->input_mux) {
11935 /* check whether NID 0x07 is valid */ 12293 /* check whether NID 0x07 is valid */
11936 unsigned int wcap = get_wcaps(codec, 0x07); 12294 unsigned int wcap = get_wcaps(codec, 0x07);
11937 int i; 12295 int i;
@@ -12012,8 +12370,6 @@ static struct snd_kcontrol_new alc269_base_mixer[] = {
12012 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT), 12370 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
12013 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 12371 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12014 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 12372 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12015 HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12016 HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12017 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 12373 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
12018 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 12374 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12019 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 12375 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
@@ -12040,8 +12396,6 @@ static struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
12040 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 12396 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
12041 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 12397 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
12042 HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT), 12398 HDA_CODEC_VOLUME("Internal Mic Boost", 0x19, 0, HDA_INPUT),
12043 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12044 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12045 { } 12399 { }
12046}; 12400};
12047 12401
@@ -12065,8 +12419,6 @@ static struct snd_kcontrol_new alc269_lifebook_mixer[] = {
12065 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT), 12419 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
12066 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT), 12420 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
12067 HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT), 12421 HDA_CODEC_VOLUME("Dock Mic Boost", 0x1b, 0, HDA_INPUT),
12068 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x04, HDA_INPUT),
12069 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x04, HDA_INPUT),
12070 { } 12422 { }
12071}; 12423};
12072 12424
@@ -12103,13 +12455,6 @@ static struct snd_kcontrol_new alc269_fujitsu_mixer[] = {
12103 { } /* end */ 12455 { } /* end */
12104}; 12456};
12105 12457
12106/* beep control */
12107static struct snd_kcontrol_new alc269_beep_mixer[] = {
12108 HDA_CODEC_VOLUME("Beep Playback Volume", 0x0b, 0x4, HDA_INPUT),
12109 HDA_CODEC_MUTE("Beep Playback Switch", 0x0b, 0x4, HDA_INPUT),
12110 { } /* end */
12111};
12112
12113static struct hda_verb alc269_quanta_fl1_verbs[] = { 12458static struct hda_verb alc269_quanta_fl1_verbs[] = {
12114 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, 12459 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
12115 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 12460 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
@@ -12509,7 +12854,7 @@ static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12509 */ 12854 */
12510 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 || 12855 if (cfg->input_pins[AUTO_PIN_MIC] == 0x12 ||
12511 cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) { 12856 cfg->input_pins[AUTO_PIN_FRONT_MIC] == 0x12) {
12512 struct hda_input_mux *imux = &spec->private_imux; 12857 struct hda_input_mux *imux = &spec->private_imux[0];
12513 imux->items[imux->num_items].label = "Int Mic"; 12858 imux->items[imux->num_items].label = "Int Mic";
12514 imux->items[imux->num_items].index = 0x05; 12859 imux->items[imux->num_items].index = 0x05;
12515 imux->num_items++; 12860 imux->num_items++;
@@ -12527,13 +12872,34 @@ static int alc269_auto_create_analog_input_ctls(struct alc_spec *spec,
12527#define alc269_pcm_digital_playback alc880_pcm_digital_playback 12872#define alc269_pcm_digital_playback alc880_pcm_digital_playback
12528#define alc269_pcm_digital_capture alc880_pcm_digital_capture 12873#define alc269_pcm_digital_capture alc880_pcm_digital_capture
12529 12874
12875static struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
12876 .substreams = 1,
12877 .channels_min = 2,
12878 .channels_max = 8,
12879 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
12880 /* NID is set in alc_build_pcms */
12881 .ops = {
12882 .open = alc880_playback_pcm_open,
12883 .prepare = alc880_playback_pcm_prepare,
12884 .cleanup = alc880_playback_pcm_cleanup
12885 },
12886};
12887
12888static struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
12889 .substreams = 1,
12890 .channels_min = 2,
12891 .channels_max = 2,
12892 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
12893 /* NID is set in alc_build_pcms */
12894};
12895
12530/* 12896/*
12531 * BIOS auto configuration 12897 * BIOS auto configuration
12532 */ 12898 */
12533static int alc269_parse_auto_config(struct hda_codec *codec) 12899static int alc269_parse_auto_config(struct hda_codec *codec)
12534{ 12900{
12535 struct alc_spec *spec = codec->spec; 12901 struct alc_spec *spec = codec->spec;
12536 int i, err; 12902 int err;
12537 static hda_nid_t alc269_ignore[] = { 0x1d, 0 }; 12903 static hda_nid_t alc269_ignore[] = { 0x1d, 0 };
12538 12904
12539 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, 12905 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
@@ -12550,22 +12916,15 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
12550 12916
12551 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 12917 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
12552 12918
12553 if (spec->autocfg.dig_out_pin) 12919 if (spec->autocfg.dig_outs)
12554 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID; 12920 spec->multiout.dig_out_nid = ALC269_DIGOUT_NID;
12555 12921
12556 if (spec->kctls.list) 12922 if (spec->kctls.list)
12557 add_mixer(spec, spec->kctls.list); 12923 add_mixer(spec, spec->kctls.list);
12558 12924
12559 /* create a beep mixer control if the pin 0x1d isn't assigned */
12560 for (i = 0; i < ARRAY_SIZE(spec->autocfg.input_pins); i++)
12561 if (spec->autocfg.input_pins[i] == 0x1d)
12562 break;
12563 if (i >= ARRAY_SIZE(spec->autocfg.input_pins))
12564 add_mixer(spec, alc269_beep_mixer);
12565
12566 add_verb(spec, alc269_init_verbs); 12925 add_verb(spec, alc269_init_verbs);
12567 spec->num_mux_defs = 1; 12926 spec->num_mux_defs = 1;
12568 spec->input_mux = &spec->private_imux; 12927 spec->input_mux = &spec->private_imux[0];
12569 /* set default input source */ 12928 /* set default input source */
12570 snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0], 12929 snd_hda_codec_write_cache(codec, alc269_capsrc_nids[0],
12571 0, AC_VERB_SET_CONNECT_SEL, 12930 0, AC_VERB_SET_CONNECT_SEL,
@@ -12575,10 +12934,9 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
12575 if (err < 0) 12934 if (err < 0)
12576 return err; 12935 return err;
12577 12936
12578 if (!spec->cap_mixer) 12937 if (!spec->cap_mixer && !spec->no_analog)
12579 set_capture_mixer(spec); 12938 set_capture_mixer(spec);
12580 12939
12581 store_pin_configs(codec);
12582 return 1; 12940 return 1;
12583} 12941}
12584 12942
@@ -12675,7 +13033,7 @@ static struct alc_config_preset alc269_presets[] = {
12675 .init_hook = alc269_eeepc_dmic_inithook, 13033 .init_hook = alc269_eeepc_dmic_inithook,
12676 }, 13034 },
12677 [ALC269_FUJITSU] = { 13035 [ALC269_FUJITSU] = {
12678 .mixers = { alc269_fujitsu_mixer, alc269_beep_mixer }, 13036 .mixers = { alc269_fujitsu_mixer },
12679 .cap_mixer = alc269_epc_capture_mixer, 13037 .cap_mixer = alc269_epc_capture_mixer,
12680 .init_verbs = { alc269_init_verbs, 13038 .init_verbs = { alc269_init_verbs,
12681 alc269_eeepc_dmic_init_verbs }, 13039 alc269_eeepc_dmic_init_verbs },
@@ -12740,13 +13098,26 @@ static int patch_alc269(struct hda_codec *codec)
12740 } 13098 }
12741 } 13099 }
12742 13100
13101 err = snd_hda_attach_beep_device(codec, 0x1);
13102 if (err < 0) {
13103 alc_free(codec);
13104 return err;
13105 }
13106
12743 if (board_config != ALC269_AUTO) 13107 if (board_config != ALC269_AUTO)
12744 setup_preset(spec, &alc269_presets[board_config]); 13108 setup_preset(spec, &alc269_presets[board_config]);
12745 13109
12746 spec->stream_name_analog = "ALC269 Analog"; 13110 spec->stream_name_analog = "ALC269 Analog";
12747 spec->stream_analog_playback = &alc269_pcm_analog_playback; 13111 if (codec->subsystem_id == 0x17aa3bf8) {
12748 spec->stream_analog_capture = &alc269_pcm_analog_capture; 13112 /* Due to a hardware problem on Lenovo Ideadpad, we need to
12749 13113 * fix the sample rate of analog I/O to 44.1kHz
13114 */
13115 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
13116 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
13117 } else {
13118 spec->stream_analog_playback = &alc269_pcm_analog_playback;
13119 spec->stream_analog_capture = &alc269_pcm_analog_capture;
13120 }
12750 spec->stream_name_digital = "ALC269 Digital"; 13121 spec->stream_name_digital = "ALC269 Digital";
12751 spec->stream_digital_playback = &alc269_pcm_digital_playback; 13122 spec->stream_digital_playback = &alc269_pcm_digital_playback;
12752 spec->stream_digital_capture = &alc269_pcm_digital_capture; 13123 spec->stream_digital_capture = &alc269_pcm_digital_capture;
@@ -12756,6 +13127,7 @@ static int patch_alc269(struct hda_codec *codec)
12756 spec->capsrc_nids = alc269_capsrc_nids; 13127 spec->capsrc_nids = alc269_capsrc_nids;
12757 if (!spec->cap_mixer) 13128 if (!spec->cap_mixer)
12758 set_capture_mixer(spec); 13129 set_capture_mixer(spec);
13130 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
12759 13131
12760 codec->patch_ops = alc_patch_ops; 13132 codec->patch_ops = alc_patch_ops;
12761 if (board_config == ALC269_AUTO) 13133 if (board_config == ALC269_AUTO)
@@ -13006,8 +13378,6 @@ static struct snd_kcontrol_new alc861_asus_mixer[] = {
13006static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = { 13378static struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
13007 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT), 13379 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
13008 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT), 13380 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
13009 HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x23, 0x0, HDA_OUTPUT),
13010 HDA_CODEC_MUTE("PC Beep Playback Switch", 0x23, 0x0, HDA_OUTPUT),
13011 { } 13381 { }
13012}; 13382};
13013 13383
@@ -13481,7 +13851,7 @@ static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
13481static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec, 13851static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec,
13482 const struct auto_pin_cfg *cfg) 13852 const struct auto_pin_cfg *cfg)
13483{ 13853{
13484 struct hda_input_mux *imux = &spec->private_imux; 13854 struct hda_input_mux *imux = &spec->private_imux[0];
13485 int i, err, idx, idx1; 13855 int i, err, idx, idx1;
13486 13856
13487 for (i = 0; i < AUTO_PIN_LAST; i++) { 13857 for (i = 0; i < AUTO_PIN_LAST; i++) {
@@ -13568,12 +13938,8 @@ static void alc861_auto_init_analog_input(struct hda_codec *codec)
13568 13938
13569 for (i = 0; i < AUTO_PIN_LAST; i++) { 13939 for (i = 0; i < AUTO_PIN_LAST; i++) {
13570 hda_nid_t nid = spec->autocfg.input_pins[i]; 13940 hda_nid_t nid = spec->autocfg.input_pins[i];
13571 if (nid >= 0x0c && nid <= 0x11) { 13941 if (nid >= 0x0c && nid <= 0x11)
13572 snd_hda_codec_write(codec, nid, 0, 13942 alc_set_input_pin(codec, nid, i);
13573 AC_VERB_SET_PIN_WIDGET_CONTROL,
13574 i <= AUTO_PIN_FRONT_MIC ?
13575 PIN_VREF80 : PIN_IN);
13576 }
13577 } 13943 }
13578} 13944}
13579 13945
@@ -13609,7 +13975,7 @@ static int alc861_parse_auto_config(struct hda_codec *codec)
13609 13975
13610 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 13976 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
13611 13977
13612 if (spec->autocfg.dig_out_pin) 13978 if (spec->autocfg.dig_outs)
13613 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID; 13979 spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
13614 13980
13615 if (spec->kctls.list) 13981 if (spec->kctls.list)
@@ -13618,13 +13984,12 @@ static int alc861_parse_auto_config(struct hda_codec *codec)
13618 add_verb(spec, alc861_auto_init_verbs); 13984 add_verb(spec, alc861_auto_init_verbs);
13619 13985
13620 spec->num_mux_defs = 1; 13986 spec->num_mux_defs = 1;
13621 spec->input_mux = &spec->private_imux; 13987 spec->input_mux = &spec->private_imux[0];
13622 13988
13623 spec->adc_nids = alc861_adc_nids; 13989 spec->adc_nids = alc861_adc_nids;
13624 spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids); 13990 spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
13625 set_capture_mixer(spec); 13991 set_capture_mixer(spec);
13626 13992
13627 store_pin_configs(codec);
13628 return 1; 13993 return 1;
13629} 13994}
13630 13995
@@ -13833,6 +14198,12 @@ static int patch_alc861(struct hda_codec *codec)
13833 } 14198 }
13834 } 14199 }
13835 14200
14201 err = snd_hda_attach_beep_device(codec, 0x23);
14202 if (err < 0) {
14203 alc_free(codec);
14204 return err;
14205 }
14206
13836 if (board_config != ALC861_AUTO) 14207 if (board_config != ALC861_AUTO)
13837 setup_preset(spec, &alc861_presets[board_config]); 14208 setup_preset(spec, &alc861_presets[board_config]);
13838 14209
@@ -13844,6 +14215,8 @@ static int patch_alc861(struct hda_codec *codec)
13844 spec->stream_digital_playback = &alc861_pcm_digital_playback; 14215 spec->stream_digital_playback = &alc861_pcm_digital_playback;
13845 spec->stream_digital_capture = &alc861_pcm_digital_capture; 14216 spec->stream_digital_capture = &alc861_pcm_digital_capture;
13846 14217
14218 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
14219
13847 spec->vmaster_nid = 0x03; 14220 spec->vmaster_nid = 0x03;
13848 14221
13849 codec->patch_ops = alc_patch_ops; 14222 codec->patch_ops = alc_patch_ops;
@@ -14000,9 +14373,6 @@ static struct snd_kcontrol_new alc861vd_6st_mixer[] = {
14000 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 14373 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14001 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 14374 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14002 14375
14003 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14004 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14005
14006 { } /* end */ 14376 { } /* end */
14007}; 14377};
14008 14378
@@ -14026,9 +14396,6 @@ static struct snd_kcontrol_new alc861vd_3st_mixer[] = {
14026 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 14396 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
14027 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 14397 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
14028 14398
14029 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14030 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14031
14032 { } /* end */ 14399 { } /* end */
14033}; 14400};
14034 14401
@@ -14067,8 +14434,6 @@ static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
14067 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT), 14434 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
14068 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 14435 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14069 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 14436 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14070 HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
14071 HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
14072 { } /* end */ 14437 { } /* end */
14073}; 14438};
14074 14439
@@ -14379,9 +14744,7 @@ static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
14379 SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO), 14744 SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
14380 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS), 14745 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
14381 SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG), 14746 SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
14382 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO), 14747 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
14383 SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
14384 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 N200", ALC861VD_LENOVO),
14385 SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG), 14748 SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
14386 {} 14749 {}
14387}; 14750};
@@ -14543,11 +14906,9 @@ static void alc861vd_auto_init_analog_input(struct hda_codec *codec)
14543 for (i = 0; i < AUTO_PIN_LAST; i++) { 14906 for (i = 0; i < AUTO_PIN_LAST; i++) {
14544 hda_nid_t nid = spec->autocfg.input_pins[i]; 14907 hda_nid_t nid = spec->autocfg.input_pins[i];
14545 if (alc861vd_is_input_pin(nid)) { 14908 if (alc861vd_is_input_pin(nid)) {
14546 snd_hda_codec_write(codec, nid, 0, 14909 alc_set_input_pin(codec, nid, i);
14547 AC_VERB_SET_PIN_WIDGET_CONTROL, 14910 if (nid != ALC861VD_PIN_CD_NID &&
14548 i <= AUTO_PIN_FRONT_MIC ? 14911 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
14549 PIN_VREF80 : PIN_IN);
14550 if (nid != ALC861VD_PIN_CD_NID)
14551 snd_hda_codec_write(codec, nid, 0, 14912 snd_hda_codec_write(codec, nid, 0,
14552 AC_VERB_SET_AMP_GAIN_MUTE, 14913 AC_VERB_SET_AMP_GAIN_MUTE,
14553 AMP_OUT_MUTE); 14914 AMP_OUT_MUTE);
@@ -14713,7 +15074,7 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
14713 15074
14714 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 15075 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
14715 15076
14716 if (spec->autocfg.dig_out_pin) 15077 if (spec->autocfg.dig_outs)
14717 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID; 15078 spec->multiout.dig_out_nid = ALC861VD_DIGOUT_NID;
14718 15079
14719 if (spec->kctls.list) 15080 if (spec->kctls.list)
@@ -14722,13 +15083,12 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
14722 add_verb(spec, alc861vd_volume_init_verbs); 15083 add_verb(spec, alc861vd_volume_init_verbs);
14723 15084
14724 spec->num_mux_defs = 1; 15085 spec->num_mux_defs = 1;
14725 spec->input_mux = &spec->private_imux; 15086 spec->input_mux = &spec->private_imux[0];
14726 15087
14727 err = alc_auto_add_mic_boost(codec); 15088 err = alc_auto_add_mic_boost(codec);
14728 if (err < 0) 15089 if (err < 0)
14729 return err; 15090 return err;
14730 15091
14731 store_pin_configs(codec);
14732 return 1; 15092 return 1;
14733} 15093}
14734 15094
@@ -14779,6 +15139,12 @@ static int patch_alc861vd(struct hda_codec *codec)
14779 } 15139 }
14780 } 15140 }
14781 15141
15142 err = snd_hda_attach_beep_device(codec, 0x23);
15143 if (err < 0) {
15144 alc_free(codec);
15145 return err;
15146 }
15147
14782 if (board_config != ALC861VD_AUTO) 15148 if (board_config != ALC861VD_AUTO)
14783 setup_preset(spec, &alc861vd_presets[board_config]); 15149 setup_preset(spec, &alc861vd_presets[board_config]);
14784 15150
@@ -14801,9 +15167,10 @@ static int patch_alc861vd(struct hda_codec *codec)
14801 spec->adc_nids = alc861vd_adc_nids; 15167 spec->adc_nids = alc861vd_adc_nids;
14802 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids); 15168 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
14803 spec->capsrc_nids = alc861vd_capsrc_nids; 15169 spec->capsrc_nids = alc861vd_capsrc_nids;
14804 spec->is_mix_capture = 1; 15170 spec->capture_style = CAPT_MIX;
14805 15171
14806 set_capture_mixer(spec); 15172 set_capture_mixer(spec);
15173 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
14807 15174
14808 spec->vmaster_nid = 0x02; 15175 spec->vmaster_nid = 0x02;
14809 15176
@@ -14992,8 +15359,6 @@ static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
14992 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 15359 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
14993 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 15360 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
14994 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 15361 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
14995 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
14996 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
14997 { } /* end */ 15362 { } /* end */
14998}; 15363};
14999 15364
@@ -15015,8 +15380,6 @@ static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
15015 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 15380 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
15016 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 15381 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
15017 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 15382 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
15018 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
15019 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
15020 { } /* end */ 15383 { } /* end */
15021}; 15384};
15022 15385
@@ -15992,56 +16355,55 @@ static const char *alc662_models[ALC662_MODEL_LAST] = {
15992}; 16355};
15993 16356
15994static struct snd_pci_quirk alc662_cfg_tbl[] = { 16357static struct snd_pci_quirk alc662_cfg_tbl[] = {
15995 SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA), 16358 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
15996 SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
15997 SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
15998 SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
15999 SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16000 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16001 SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),
16002 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1), 16359 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
16003 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1), 16360 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
16004 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1), 16361 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16005 SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),
16006 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1), 16362 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
16363 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
16007 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1), 16364 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
16008 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16009 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16010 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16011 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2), 16365 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
16012 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2), 16366 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
16013 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2), 16367 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
16368 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
16369 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
16370 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
16014 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2), 16371 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
16015 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2), 16372 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
16016 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2), 16373 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
16374 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
16017 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2), 16375 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
16018 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2), 16376 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
16019 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2), 16377 SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
16020 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2), 16378 /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
16021 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16022 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3), 16379 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
16023 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
16024 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16025 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3), 16380 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
16026 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3), 16381 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
16382 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
16383 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
16384 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
16385 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
16386 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
16387 SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
16388 /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
16389 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
16390 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
16391 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
16027 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4), 16392 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
16028 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5), 16393 SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
16029 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6), 16394 SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
16030 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6), 16395 SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
16031 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6), 16396 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16032 SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K", 16397 SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
16033 ALC662_3ST_6ch_DIG), 16398 ALC662_3ST_6ch_DIG),
16034 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16035 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
16036 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
16037 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L", 16399 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
16038 ALC662_3ST_6ch_DIG), 16400 ALC662_3ST_6ch_DIG),
16039 SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG), 16401 SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
16402 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
16040 SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0", 16403 SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
16041 ALC662_3ST_6ch_DIG), 16404 ALC662_3ST_6ch_DIG),
16042 SND_PCI_QUIRK(0x1854, 0x2000, "ASUS H13-2000", ALC663_ASUS_H13), 16405 SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
16043 SND_PCI_QUIRK(0x1854, 0x2001, "ASUS H13-2001", ALC663_ASUS_H13), 16406 ALC663_ASUS_H13),
16044 SND_PCI_QUIRK(0x1854, 0x2002, "ASUS H13-2002", ALC663_ASUS_H13),
16045 {} 16407 {}
16046}; 16408};
16047 16409
@@ -16361,7 +16723,7 @@ static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16361 16723
16362 if (alc880_is_fixed_pin(pin)) { 16724 if (alc880_is_fixed_pin(pin)) {
16363 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin)); 16725 nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
16364 /* printk("DAC nid=%x\n",nid); */ 16726 /* printk(KERN_DEBUG "DAC nid=%x\n",nid); */
16365 /* specify the DAC as the extra output */ 16727 /* specify the DAC as the extra output */
16366 if (!spec->multiout.hp_nid) 16728 if (!spec->multiout.hp_nid)
16367 spec->multiout.hp_nid = nid; 16729 spec->multiout.hp_nid = nid;
@@ -16391,26 +16753,58 @@ static int alc662_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
16391 return 0; 16753 return 0;
16392} 16754}
16393 16755
16756/* return the index of the src widget from the connection list of the nid.
16757 * return -1 if not found
16758 */
16759static int alc662_input_pin_idx(struct hda_codec *codec, hda_nid_t nid,
16760 hda_nid_t src)
16761{
16762 hda_nid_t conn_list[HDA_MAX_CONNECTIONS];
16763 int i, conns;
16764
16765 conns = snd_hda_get_connections(codec, nid, conn_list,
16766 ARRAY_SIZE(conn_list));
16767 if (conns < 0)
16768 return -1;
16769 for (i = 0; i < conns; i++)
16770 if (conn_list[i] == src)
16771 return i;
16772 return -1;
16773}
16774
16775static int alc662_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
16776{
16777 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
16778 return (pincap & AC_PINCAP_IN) != 0;
16779}
16780
16394/* create playback/capture controls for input pins */ 16781/* create playback/capture controls for input pins */
16395static int alc662_auto_create_analog_input_ctls(struct alc_spec *spec, 16782static int alc662_auto_create_analog_input_ctls(struct hda_codec *codec,
16396 const struct auto_pin_cfg *cfg) 16783 const struct auto_pin_cfg *cfg)
16397{ 16784{
16398 struct hda_input_mux *imux = &spec->private_imux; 16785 struct alc_spec *spec = codec->spec;
16786 struct hda_input_mux *imux = &spec->private_imux[0];
16399 int i, err, idx; 16787 int i, err, idx;
16400 16788
16401 for (i = 0; i < AUTO_PIN_LAST; i++) { 16789 for (i = 0; i < AUTO_PIN_LAST; i++) {
16402 if (alc880_is_input_pin(cfg->input_pins[i])) { 16790 if (alc662_is_input_pin(codec, cfg->input_pins[i])) {
16403 idx = alc880_input_pin_idx(cfg->input_pins[i]); 16791 idx = alc662_input_pin_idx(codec, 0x0b,
16404 err = new_analog_input(spec, cfg->input_pins[i], 16792 cfg->input_pins[i]);
16405 auto_pin_cfg_labels[i], 16793 if (idx >= 0) {
16406 idx, 0x0b); 16794 err = new_analog_input(spec, cfg->input_pins[i],
16407 if (err < 0) 16795 auto_pin_cfg_labels[i],
16408 return err; 16796 idx, 0x0b);
16409 imux->items[imux->num_items].label = 16797 if (err < 0)
16410 auto_pin_cfg_labels[i]; 16798 return err;
16411 imux->items[imux->num_items].index = 16799 }
16412 alc880_input_pin_idx(cfg->input_pins[i]); 16800 idx = alc662_input_pin_idx(codec, 0x22,
16413 imux->num_items++; 16801 cfg->input_pins[i]);
16802 if (idx >= 0) {
16803 imux->items[imux->num_items].label =
16804 auto_pin_cfg_labels[i];
16805 imux->items[imux->num_items].index = idx;
16806 imux->num_items++;
16807 }
16414 } 16808 }
16415 } 16809 }
16416 return 0; 16810 return 0;
@@ -16460,7 +16854,6 @@ static void alc662_auto_init_hp_out(struct hda_codec *codec)
16460 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0); 16854 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
16461} 16855}
16462 16856
16463#define alc662_is_input_pin(nid) alc880_is_input_pin(nid)
16464#define ALC662_PIN_CD_NID ALC880_PIN_CD_NID 16857#define ALC662_PIN_CD_NID ALC880_PIN_CD_NID
16465 16858
16466static void alc662_auto_init_analog_input(struct hda_codec *codec) 16859static void alc662_auto_init_analog_input(struct hda_codec *codec)
@@ -16470,12 +16863,10 @@ static void alc662_auto_init_analog_input(struct hda_codec *codec)
16470 16863
16471 for (i = 0; i < AUTO_PIN_LAST; i++) { 16864 for (i = 0; i < AUTO_PIN_LAST; i++) {
16472 hda_nid_t nid = spec->autocfg.input_pins[i]; 16865 hda_nid_t nid = spec->autocfg.input_pins[i];
16473 if (alc662_is_input_pin(nid)) { 16866 if (alc662_is_input_pin(codec, nid)) {
16474 snd_hda_codec_write(codec, nid, 0, 16867 alc_set_input_pin(codec, nid, i);
16475 AC_VERB_SET_PIN_WIDGET_CONTROL, 16868 if (nid != ALC662_PIN_CD_NID &&
16476 (i <= AUTO_PIN_FRONT_MIC ? 16869 (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
16477 PIN_VREF80 : PIN_IN));
16478 if (nid != ALC662_PIN_CD_NID)
16479 snd_hda_codec_write(codec, nid, 0, 16870 snd_hda_codec_write(codec, nid, 0,
16480 AC_VERB_SET_AMP_GAIN_MUTE, 16871 AC_VERB_SET_AMP_GAIN_MUTE,
16481 AMP_OUT_MUTE); 16872 AMP_OUT_MUTE);
@@ -16513,20 +16904,20 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
16513 "Headphone"); 16904 "Headphone");
16514 if (err < 0) 16905 if (err < 0)
16515 return err; 16906 return err;
16516 err = alc662_auto_create_analog_input_ctls(spec, &spec->autocfg); 16907 err = alc662_auto_create_analog_input_ctls(codec, &spec->autocfg);
16517 if (err < 0) 16908 if (err < 0)
16518 return err; 16909 return err;
16519 16910
16520 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 16911 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
16521 16912
16522 if (spec->autocfg.dig_out_pin) 16913 if (spec->autocfg.dig_outs)
16523 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID; 16914 spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
16524 16915
16525 if (spec->kctls.list) 16916 if (spec->kctls.list)
16526 add_mixer(spec, spec->kctls.list); 16917 add_mixer(spec, spec->kctls.list);
16527 16918
16528 spec->num_mux_defs = 1; 16919 spec->num_mux_defs = 1;
16529 spec->input_mux = &spec->private_imux; 16920 spec->input_mux = &spec->private_imux[0];
16530 16921
16531 add_verb(spec, alc662_auto_init_verbs); 16922 add_verb(spec, alc662_auto_init_verbs);
16532 if (codec->vendor_id == 0x10ec0663) 16923 if (codec->vendor_id == 0x10ec0663)
@@ -16536,7 +16927,6 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
16536 if (err < 0) 16927 if (err < 0)
16537 return err; 16928 return err;
16538 16929
16539 store_pin_configs(codec);
16540 return 1; 16930 return 1;
16541} 16931}
16542 16932
@@ -16588,6 +16978,12 @@ static int patch_alc662(struct hda_codec *codec)
16588 } 16978 }
16589 } 16979 }
16590 16980
16981 err = snd_hda_attach_beep_device(codec, 0x1);
16982 if (err < 0) {
16983 alc_free(codec);
16984 return err;
16985 }
16986
16591 if (board_config != ALC662_AUTO) 16987 if (board_config != ALC662_AUTO)
16592 setup_preset(spec, &alc662_presets[board_config]); 16988 setup_preset(spec, &alc662_presets[board_config]);
16593 16989
@@ -16611,10 +17007,14 @@ static int patch_alc662(struct hda_codec *codec)
16611 spec->adc_nids = alc662_adc_nids; 17007 spec->adc_nids = alc662_adc_nids;
16612 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids); 17008 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
16613 spec->capsrc_nids = alc662_capsrc_nids; 17009 spec->capsrc_nids = alc662_capsrc_nids;
16614 spec->is_mix_capture = 1; 17010 spec->capture_style = CAPT_MIX;
16615 17011
16616 if (!spec->cap_mixer) 17012 if (!spec->cap_mixer)
16617 set_capture_mixer(spec); 17013 set_capture_mixer(spec);
17014 if (codec->vendor_id == 0x10ec0662)
17015 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
17016 else
17017 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
16618 17018
16619 spec->vmaster_nid = 0x02; 17019 spec->vmaster_nid = 0x02;
16620 17020
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 6094344fb223..b5e108aa8f63 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -43,6 +43,7 @@ enum {
43}; 43};
44 44
45enum { 45enum {
46 STAC_AUTO,
46 STAC_REF, 47 STAC_REF,
47 STAC_9200_OQO, 48 STAC_9200_OQO,
48 STAC_9200_DELL_D21, 49 STAC_9200_DELL_D21,
@@ -62,14 +63,17 @@ enum {
62}; 63};
63 64
64enum { 65enum {
66 STAC_9205_AUTO,
65 STAC_9205_REF, 67 STAC_9205_REF,
66 STAC_9205_DELL_M42, 68 STAC_9205_DELL_M42,
67 STAC_9205_DELL_M43, 69 STAC_9205_DELL_M43,
68 STAC_9205_DELL_M44, 70 STAC_9205_DELL_M44,
71 STAC_9205_EAPD,
69 STAC_9205_MODELS 72 STAC_9205_MODELS
70}; 73};
71 74
72enum { 75enum {
76 STAC_92HD73XX_AUTO,
73 STAC_92HD73XX_NO_JD, /* no jack-detection */ 77 STAC_92HD73XX_NO_JD, /* no jack-detection */
74 STAC_92HD73XX_REF, 78 STAC_92HD73XX_REF,
75 STAC_DELL_M6_AMIC, 79 STAC_DELL_M6_AMIC,
@@ -80,22 +84,27 @@ enum {
80}; 84};
81 85
82enum { 86enum {
87 STAC_92HD83XXX_AUTO,
83 STAC_92HD83XXX_REF, 88 STAC_92HD83XXX_REF,
84 STAC_92HD83XXX_PWR_REF, 89 STAC_92HD83XXX_PWR_REF,
90 STAC_DELL_S14,
85 STAC_92HD83XXX_MODELS 91 STAC_92HD83XXX_MODELS
86}; 92};
87 93
88enum { 94enum {
95 STAC_92HD71BXX_AUTO,
89 STAC_92HD71BXX_REF, 96 STAC_92HD71BXX_REF,
90 STAC_DELL_M4_1, 97 STAC_DELL_M4_1,
91 STAC_DELL_M4_2, 98 STAC_DELL_M4_2,
92 STAC_DELL_M4_3, 99 STAC_DELL_M4_3,
93 STAC_HP_M4, 100 STAC_HP_M4,
94 STAC_HP_DV5, 101 STAC_HP_DV5,
102 STAC_HP_HDX,
95 STAC_92HD71BXX_MODELS 103 STAC_92HD71BXX_MODELS
96}; 104};
97 105
98enum { 106enum {
107 STAC_925x_AUTO,
99 STAC_925x_REF, 108 STAC_925x_REF,
100 STAC_M1, 109 STAC_M1,
101 STAC_M1_2, 110 STAC_M1_2,
@@ -108,6 +117,7 @@ enum {
108}; 117};
109 118
110enum { 119enum {
120 STAC_922X_AUTO,
111 STAC_D945_REF, 121 STAC_D945_REF,
112 STAC_D945GTP3, 122 STAC_D945GTP3,
113 STAC_D945GTP5, 123 STAC_D945GTP5,
@@ -135,6 +145,7 @@ enum {
135}; 145};
136 146
137enum { 147enum {
148 STAC_927X_AUTO,
138 STAC_D965_REF_NO_JD, /* no jack-detection */ 149 STAC_D965_REF_NO_JD, /* no jack-detection */
139 STAC_D965_REF, 150 STAC_D965_REF,
140 STAC_D965_3ST, 151 STAC_D965_3ST,
@@ -144,6 +155,12 @@ enum {
144 STAC_927X_MODELS 155 STAC_927X_MODELS
145}; 156};
146 157
158enum {
159 STAC_9872_AUTO,
160 STAC_9872_VAIO,
161 STAC_9872_MODELS
162};
163
147struct sigmatel_event { 164struct sigmatel_event {
148 hda_nid_t nid; 165 hda_nid_t nid;
149 unsigned char type; 166 unsigned char type;
@@ -167,6 +184,7 @@ struct sigmatel_spec {
167 unsigned int alt_switch: 1; 184 unsigned int alt_switch: 1;
168 unsigned int hp_detect: 1; 185 unsigned int hp_detect: 1;
169 unsigned int spdif_mute: 1; 186 unsigned int spdif_mute: 1;
187 unsigned int check_volume_offset:1;
170 188
171 /* gpio lines */ 189 /* gpio lines */
172 unsigned int eapd_mask; 190 unsigned int eapd_mask;
@@ -179,6 +197,7 @@ struct sigmatel_spec {
179 unsigned int stream_delay; 197 unsigned int stream_delay;
180 198
181 /* analog loopback */ 199 /* analog loopback */
200 struct snd_kcontrol_new *aloopback_ctl;
182 unsigned char aloopback_mask; 201 unsigned char aloopback_mask;
183 unsigned char aloopback_shift; 202 unsigned char aloopback_shift;
184 203
@@ -203,6 +222,8 @@ struct sigmatel_spec {
203 hda_nid_t hp_dacs[5]; 222 hda_nid_t hp_dacs[5];
204 hda_nid_t speaker_dacs[5]; 223 hda_nid_t speaker_dacs[5];
205 224
225 int volume_offset;
226
206 /* capture */ 227 /* capture */
207 hda_nid_t *adc_nids; 228 hda_nid_t *adc_nids;
208 unsigned int num_adcs; 229 unsigned int num_adcs;
@@ -224,7 +245,6 @@ struct sigmatel_spec {
224 /* pin widgets */ 245 /* pin widgets */
225 hda_nid_t *pin_nids; 246 hda_nid_t *pin_nids;
226 unsigned int num_pins; 247 unsigned int num_pins;
227 unsigned int *pin_configs;
228 248
229 /* codec specific stuff */ 249 /* codec specific stuff */
230 struct hda_verb *init; 250 struct hda_verb *init;
@@ -400,6 +420,10 @@ static hda_nid_t stac922x_mux_nids[2] = {
400 0x12, 0x13, 420 0x12, 0x13,
401}; 421};
402 422
423static hda_nid_t stac927x_slave_dig_outs[2] = {
424 0x1f, 0,
425};
426
403static hda_nid_t stac927x_adc_nids[3] = { 427static hda_nid_t stac927x_adc_nids[3] = {
404 0x07, 0x08, 0x09 428 0x07, 0x08, 0x09
405}; 429};
@@ -472,15 +496,21 @@ static hda_nid_t stac92hd73xx_pin_nids[13] = {
472 0x14, 0x22, 0x23 496 0x14, 0x22, 0x23
473}; 497};
474 498
475static hda_nid_t stac92hd83xxx_pin_nids[14] = { 499static hda_nid_t stac92hd83xxx_pin_nids[10] = {
476 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 500 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
477 0x0f, 0x10, 0x11, 0x12, 0x13, 501 0x0f, 0x10, 0x11, 0x1f, 0x20,
478 0x1d, 0x1e, 0x1f, 0x20 502};
503
504#define STAC92HD71BXX_NUM_PINS 13
505static hda_nid_t stac92hd71bxx_pin_nids_4port[STAC92HD71BXX_NUM_PINS] = {
506 0x0a, 0x0b, 0x0c, 0x0d, 0x00,
507 0x00, 0x14, 0x18, 0x19, 0x1e,
508 0x1f, 0x20, 0x27
479}; 509};
480static hda_nid_t stac92hd71bxx_pin_nids[11] = { 510static hda_nid_t stac92hd71bxx_pin_nids_6port[STAC92HD71BXX_NUM_PINS] = {
481 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 511 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
482 0x0f, 0x14, 0x18, 0x19, 0x1e, 512 0x0f, 0x14, 0x18, 0x19, 0x1e,
483 0x1f, 513 0x1f, 0x20, 0x27
484}; 514};
485 515
486static hda_nid_t stac927x_pin_nids[14] = { 516static hda_nid_t stac927x_pin_nids[14] = {
@@ -842,9 +872,9 @@ static struct hda_verb stac92hd73xx_10ch_core_init[] = {
842}; 872};
843 873
844static struct hda_verb stac92hd83xxx_core_init[] = { 874static struct hda_verb stac92hd83xxx_core_init[] = {
845 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x0}, 875 { 0xa, AC_VERB_SET_CONNECT_SEL, 0x1},
846 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x0}, 876 { 0xb, AC_VERB_SET_CONNECT_SEL, 0x1},
847 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x1}, 877 { 0xd, AC_VERB_SET_CONNECT_SEL, 0x0},
848 878
849 /* power state controls amps */ 879 /* power state controls amps */
850 { 0x01, AC_VERB_SET_EAPD, 1 << 2}, 880 { 0x01, AC_VERB_SET_EAPD, 1 << 2},
@@ -854,26 +884,25 @@ static struct hda_verb stac92hd83xxx_core_init[] = {
854static struct hda_verb stac92hd71bxx_core_init[] = { 884static struct hda_verb stac92hd71bxx_core_init[] = {
855 /* set master volume and direct control */ 885 /* set master volume and direct control */
856 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 886 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
857 /* unmute right and left channels for nodes 0x0a, 0xd, 0x0f */
858 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
859 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
860 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
861 {} 887 {}
862}; 888};
863 889
864#define HD_DISABLE_PORTF 2 890#define HD_DISABLE_PORTF 1
865static struct hda_verb stac92hd71bxx_analog_core_init[] = { 891static struct hda_verb stac92hd71bxx_analog_core_init[] = {
866 /* start of config #1 */ 892 /* start of config #1 */
867 893
868 /* connect port 0f to audio mixer */ 894 /* connect port 0f to audio mixer */
869 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2}, 895 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2},
870 /* unmute right and left channels for node 0x0f */
871 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
872 /* start of config #2 */ 896 /* start of config #2 */
873 897
874 /* set master volume and direct control */ 898 /* set master volume and direct control */
875 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 899 { 0x28, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
876 /* unmute right and left channels for nodes 0x0a, 0xd */ 900 {}
901};
902
903static struct hda_verb stac92hd71bxx_unmute_core_init[] = {
904 /* unmute right and left channels for nodes 0x0f, 0xa, 0x0d */
905 { 0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
877 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 906 { 0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
878 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 907 { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
879 {} 908 {}
@@ -954,16 +983,6 @@ static struct hda_verb stac9205_core_init[] = {
954 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \ 983 .private_value = HDA_COMPOSE_AMP_VAL(nid, chs, idx, dir) \
955 } 984 }
956 985
957#define STAC_INPUT_SOURCE(cnt) \
958 { \
959 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
960 .name = "Input Source", \
961 .count = cnt, \
962 .info = stac92xx_mux_enum_info, \
963 .get = stac92xx_mux_enum_get, \
964 .put = stac92xx_mux_enum_put, \
965 }
966
967#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \ 986#define STAC_ANALOG_LOOPBACK(verb_read, verb_write, cnt) \
968 { \ 987 { \
969 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 988 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -978,7 +997,6 @@ static struct hda_verb stac9205_core_init[] = {
978static struct snd_kcontrol_new stac9200_mixer[] = { 997static struct snd_kcontrol_new stac9200_mixer[] = {
979 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT), 998 HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
980 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT), 999 HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
981 STAC_INPUT_SOURCE(1),
982 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT), 1000 HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
983 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT), 1001 HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
984 { } /* end */ 1002 { } /* end */
@@ -1003,8 +1021,6 @@ static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
1003 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT), 1021 HDA_CODEC_VOLUME("DAC Mixer Capture Volume", 0x1d, 0x3, HDA_INPUT),
1004 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT), 1022 HDA_CODEC_MUTE("DAC Mixer Capture Switch", 0x1d, 0x3, HDA_INPUT),
1005 1023
1006 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1007
1008 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT), 1024 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1009 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT), 1025 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1010 1026
@@ -1014,9 +1030,22 @@ static struct snd_kcontrol_new stac92hd73xx_6ch_mixer[] = {
1014 { } /* end */ 1030 { } /* end */
1015}; 1031};
1016 1032
1017static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = { 1033static struct snd_kcontrol_new stac92hd73xx_6ch_loopback[] = {
1034 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 3),
1035 {}
1036};
1037
1038static struct snd_kcontrol_new stac92hd73xx_8ch_loopback[] = {
1018 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4), 1039 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 4),
1040 {}
1041};
1019 1042
1043static struct snd_kcontrol_new stac92hd73xx_10ch_loopback[] = {
1044 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1045 {}
1046};
1047
1048static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
1020 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT), 1049 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1021 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT), 1050 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1022 1051
@@ -1041,8 +1070,6 @@ static struct snd_kcontrol_new stac92hd73xx_8ch_mixer[] = {
1041}; 1070};
1042 1071
1043static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = { 1072static struct snd_kcontrol_new stac92hd73xx_10ch_mixer[] = {
1044 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A1, 5),
1045
1046 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT), 1073 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x20, 0x0, HDA_OUTPUT),
1047 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT), 1074 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x20, 0x0, HDA_OUTPUT),
1048 1075
@@ -1094,9 +1121,6 @@ static struct snd_kcontrol_new stac92hd83xxx_mixer[] = {
1094}; 1121};
1095 1122
1096static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = { 1123static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
1097 STAC_INPUT_SOURCE(2),
1098 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2),
1099
1100 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT), 1124 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1101 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT), 1125 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1102 1126
@@ -1122,10 +1146,11 @@ static struct snd_kcontrol_new stac92hd71bxx_analog_mixer[] = {
1122 { } /* end */ 1146 { } /* end */
1123}; 1147};
1124 1148
1125static struct snd_kcontrol_new stac92hd71bxx_mixer[] = { 1149static struct snd_kcontrol_new stac92hd71bxx_loopback[] = {
1126 STAC_INPUT_SOURCE(2), 1150 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2)
1127 STAC_ANALOG_LOOPBACK(0xFA0, 0x7A0, 2), 1151};
1128 1152
1153static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
1129 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT), 1154 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1130 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT), 1155 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1c, 0x0, HDA_OUTPUT),
1131 1156
@@ -1137,16 +1162,12 @@ static struct snd_kcontrol_new stac92hd71bxx_mixer[] = {
1137static struct snd_kcontrol_new stac925x_mixer[] = { 1162static struct snd_kcontrol_new stac925x_mixer[] = {
1138 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT), 1163 HDA_CODEC_VOLUME("Master Playback Volume", 0x0e, 0, HDA_OUTPUT),
1139 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT), 1164 HDA_CODEC_MUTE("Master Playback Switch", 0x0e, 0, HDA_OUTPUT),
1140 STAC_INPUT_SOURCE(1),
1141 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT), 1165 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
1142 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT), 1166 HDA_CODEC_MUTE("Capture Switch", 0x14, 0, HDA_OUTPUT),
1143 { } /* end */ 1167 { } /* end */
1144}; 1168};
1145 1169
1146static struct snd_kcontrol_new stac9205_mixer[] = { 1170static struct snd_kcontrol_new stac9205_mixer[] = {
1147 STAC_INPUT_SOURCE(2),
1148 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1149
1150 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT), 1171 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
1151 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT), 1172 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
1152 1173
@@ -1155,9 +1176,13 @@ static struct snd_kcontrol_new stac9205_mixer[] = {
1155 { } /* end */ 1176 { } /* end */
1156}; 1177};
1157 1178
1179static struct snd_kcontrol_new stac9205_loopback[] = {
1180 STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0, 1),
1181 {}
1182};
1183
1158/* This needs to be generated dynamically based on sequence */ 1184/* This needs to be generated dynamically based on sequence */
1159static struct snd_kcontrol_new stac922x_mixer[] = { 1185static struct snd_kcontrol_new stac922x_mixer[] = {
1160 STAC_INPUT_SOURCE(2),
1161 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT), 1186 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
1162 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT), 1187 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
1163 1188
@@ -1168,9 +1193,6 @@ static struct snd_kcontrol_new stac922x_mixer[] = {
1168 1193
1169 1194
1170static struct snd_kcontrol_new stac927x_mixer[] = { 1195static struct snd_kcontrol_new stac927x_mixer[] = {
1171 STAC_INPUT_SOURCE(3),
1172 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1173
1174 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT), 1196 HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
1175 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT), 1197 HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
1176 1198
@@ -1182,6 +1204,11 @@ static struct snd_kcontrol_new stac927x_mixer[] = {
1182 { } /* end */ 1204 { } /* end */
1183}; 1205};
1184 1206
1207static struct snd_kcontrol_new stac927x_loopback[] = {
1208 STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB, 1),
1209 {}
1210};
1211
1185static struct snd_kcontrol_new stac_dmux_mixer = { 1212static struct snd_kcontrol_new stac_dmux_mixer = {
1186 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 1213 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1187 .name = "Digital Input Source", 1214 .name = "Digital Input Source",
@@ -1207,10 +1234,7 @@ static const char *slave_vols[] = {
1207 "LFE Playback Volume", 1234 "LFE Playback Volume",
1208 "Side Playback Volume", 1235 "Side Playback Volume",
1209 "Headphone Playback Volume", 1236 "Headphone Playback Volume",
1210 "Headphone2 Playback Volume",
1211 "Speaker Playback Volume", 1237 "Speaker Playback Volume",
1212 "External Speaker Playback Volume",
1213 "Speaker2 Playback Volume",
1214 NULL 1238 NULL
1215}; 1239};
1216 1240
@@ -1221,10 +1245,7 @@ static const char *slave_sws[] = {
1221 "LFE Playback Switch", 1245 "LFE Playback Switch",
1222 "Side Playback Switch", 1246 "Side Playback Switch",
1223 "Headphone Playback Switch", 1247 "Headphone Playback Switch",
1224 "Headphone2 Playback Switch",
1225 "Speaker Playback Switch", 1248 "Speaker Playback Switch",
1226 "External Speaker Playback Switch",
1227 "Speaker2 Playback Switch",
1228 "IEC958 Playback Switch", 1249 "IEC958 Playback Switch",
1229 NULL 1250 NULL
1230}; 1251};
@@ -1294,6 +1315,8 @@ static int stac92xx_build_controls(struct hda_codec *codec)
1294 unsigned int vmaster_tlv[4]; 1315 unsigned int vmaster_tlv[4];
1295 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0], 1316 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
1296 HDA_OUTPUT, vmaster_tlv); 1317 HDA_OUTPUT, vmaster_tlv);
1318 /* correct volume offset */
1319 vmaster_tlv[2] += vmaster_tlv[3] * spec->volume_offset;
1297 err = snd_hda_add_vmaster(codec, "Master Playback Volume", 1320 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1298 vmaster_tlv, slave_vols); 1321 vmaster_tlv, slave_vols);
1299 if (err < 0) 1322 if (err < 0)
@@ -1306,6 +1329,13 @@ static int stac92xx_build_controls(struct hda_codec *codec)
1306 return err; 1329 return err;
1307 } 1330 }
1308 1331
1332 if (spec->aloopback_ctl &&
1333 snd_hda_get_bool_hint(codec, "loopback") == 1) {
1334 err = snd_hda_add_new_ctls(codec, spec->aloopback_ctl);
1335 if (err < 0)
1336 return err;
1337 }
1338
1309 stac92xx_free_kctls(codec); /* no longer needed */ 1339 stac92xx_free_kctls(codec); /* no longer needed */
1310 1340
1311 /* create jack input elements */ 1341 /* create jack input elements */
@@ -1490,6 +1520,7 @@ static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1490}; 1520};
1491 1521
1492static const char *stac9200_models[STAC_9200_MODELS] = { 1522static const char *stac9200_models[STAC_9200_MODELS] = {
1523 [STAC_AUTO] = "auto",
1493 [STAC_REF] = "ref", 1524 [STAC_REF] = "ref",
1494 [STAC_9200_OQO] = "oqo", 1525 [STAC_9200_OQO] = "oqo",
1495 [STAC_9200_DELL_D21] = "dell-d21", 1526 [STAC_9200_DELL_D21] = "dell-d21",
@@ -1511,6 +1542,8 @@ static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1511 /* SigmaTel reference board */ 1542 /* SigmaTel reference board */
1512 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1543 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1513 "DFI LanParty", STAC_REF), 1544 "DFI LanParty", STAC_REF),
1545 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1546 "DFI LanParty", STAC_REF),
1514 /* Dell laptops have BIOS problem */ 1547 /* Dell laptops have BIOS problem */
1515 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8, 1548 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
1516 "unknown Dell", STAC_9200_DELL_D21), 1549 "unknown Dell", STAC_9200_DELL_D21),
@@ -1633,6 +1666,7 @@ static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
1633}; 1666};
1634 1667
1635static const char *stac925x_models[STAC_925x_MODELS] = { 1668static const char *stac925x_models[STAC_925x_MODELS] = {
1669 [STAC_925x_AUTO] = "auto",
1636 [STAC_REF] = "ref", 1670 [STAC_REF] = "ref",
1637 [STAC_M1] = "m1", 1671 [STAC_M1] = "m1",
1638 [STAC_M1_2] = "m1-2", 1672 [STAC_M1_2] = "m1-2",
@@ -1660,6 +1694,7 @@ static struct snd_pci_quirk stac925x_codec_id_cfg_tbl[] = {
1660static struct snd_pci_quirk stac925x_cfg_tbl[] = { 1694static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1661 /* SigmaTel reference board */ 1695 /* SigmaTel reference board */
1662 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF), 1696 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
1697 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101, "DFI LanParty", STAC_REF),
1663 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF), 1698 SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
1664 1699
1665 /* Default table for unknown ID */ 1700 /* Default table for unknown ID */
@@ -1691,6 +1726,7 @@ static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1691}; 1726};
1692 1727
1693static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = { 1728static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1729 [STAC_92HD73XX_AUTO] = "auto",
1694 [STAC_92HD73XX_NO_JD] = "no-jd", 1730 [STAC_92HD73XX_NO_JD] = "no-jd",
1695 [STAC_92HD73XX_REF] = "ref", 1731 [STAC_92HD73XX_REF] = "ref",
1696 [STAC_DELL_M6_AMIC] = "dell-m6-amic", 1732 [STAC_DELL_M6_AMIC] = "dell-m6-amic",
@@ -1703,6 +1739,8 @@ static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1703 /* SigmaTel reference board */ 1739 /* SigmaTel reference board */
1704 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1740 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1705 "DFI LanParty", STAC_92HD73XX_REF), 1741 "DFI LanParty", STAC_92HD73XX_REF),
1742 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1743 "DFI LanParty", STAC_92HD73XX_REF),
1706 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254, 1744 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1707 "Dell Studio 1535", STAC_DELL_M6_DMIC), 1745 "Dell Studio 1535", STAC_DELL_M6_DMIC),
1708 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255, 1746 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
@@ -1726,52 +1764,68 @@ static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1726 {} /* terminator */ 1764 {} /* terminator */
1727}; 1765};
1728 1766
1729static unsigned int ref92hd83xxx_pin_configs[14] = { 1767static unsigned int ref92hd83xxx_pin_configs[10] = {
1730 0x02214030, 0x02211010, 0x02a19020, 0x02170130, 1768 0x02214030, 0x02211010, 0x02a19020, 0x02170130,
1731 0x01014050, 0x01819040, 0x01014020, 0x90a3014e, 1769 0x01014050, 0x01819040, 0x01014020, 0x90a3014e,
1732 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x40f000f0,
1733 0x01451160, 0x98560170, 1770 0x01451160, 0x98560170,
1734}; 1771};
1735 1772
1773static unsigned int dell_s14_pin_configs[10] = {
1774 0x02214030, 0x02211010, 0x02a19020, 0x01014050,
1775 0x40f000f0, 0x01819040, 0x40f000f0, 0x90a60160,
1776 0x40f000f0, 0x40f000f0,
1777};
1778
1736static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = { 1779static unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1737 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs, 1780 [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1738 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs, 1781 [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1782 [STAC_DELL_S14] = dell_s14_pin_configs,
1739}; 1783};
1740 1784
1741static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = { 1785static const char *stac92hd83xxx_models[STAC_92HD83XXX_MODELS] = {
1786 [STAC_92HD83XXX_AUTO] = "auto",
1742 [STAC_92HD83XXX_REF] = "ref", 1787 [STAC_92HD83XXX_REF] = "ref",
1743 [STAC_92HD83XXX_PWR_REF] = "mic-ref", 1788 [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1789 [STAC_DELL_S14] = "dell-s14",
1744}; 1790};
1745 1791
1746static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = { 1792static struct snd_pci_quirk stac92hd83xxx_cfg_tbl[] = {
1747 /* SigmaTel reference board */ 1793 /* SigmaTel reference board */
1748 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1794 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1749 "DFI LanParty", STAC_92HD83XXX_REF), 1795 "DFI LanParty", STAC_92HD83XXX_REF),
1796 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1797 "DFI LanParty", STAC_92HD83XXX_REF),
1798 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1799 "unknown Dell", STAC_DELL_S14),
1750 {} /* terminator */ 1800 {} /* terminator */
1751}; 1801};
1752 1802
1753static unsigned int ref92hd71bxx_pin_configs[11] = { 1803static unsigned int ref92hd71bxx_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1754 0x02214030, 0x02a19040, 0x01a19020, 0x01014010, 1804 0x02214030, 0x02a19040, 0x01a19020, 0x01014010,
1755 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0, 1805 0x0181302e, 0x01014010, 0x01019020, 0x90a000f0,
1756 0x90a000f0, 0x01452050, 0x01452050, 1806 0x90a000f0, 0x01452050, 0x01452050, 0x00000000,
1807 0x00000000
1757}; 1808};
1758 1809
1759static unsigned int dell_m4_1_pin_configs[11] = { 1810static unsigned int dell_m4_1_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1760 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110, 1811 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1761 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0, 1812 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1762 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 1813 0x40f000f0, 0x4f0000f0, 0x4f0000f0, 0x00000000,
1814 0x00000000
1763}; 1815};
1764 1816
1765static unsigned int dell_m4_2_pin_configs[11] = { 1817static unsigned int dell_m4_2_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1766 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110, 1818 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1767 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0, 1819 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1768 0x40f000f0, 0x044413b0, 0x044413b0, 1820 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1821 0x00000000
1769}; 1822};
1770 1823
1771static unsigned int dell_m4_3_pin_configs[11] = { 1824static unsigned int dell_m4_3_pin_configs[STAC92HD71BXX_NUM_PINS] = {
1772 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110, 1825 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1773 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0, 1826 0x40f000f0, 0x40f000f0, 0x40f000f0, 0x90a000f0,
1774 0x40f000f0, 0x044413b0, 0x044413b0, 1827 0x40f000f0, 0x044413b0, 0x044413b0, 0x00000000,
1828 0x00000000
1775}; 1829};
1776 1830
1777static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = { 1831static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
@@ -1781,35 +1835,38 @@ static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1781 [STAC_DELL_M4_3] = dell_m4_3_pin_configs, 1835 [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
1782 [STAC_HP_M4] = NULL, 1836 [STAC_HP_M4] = NULL,
1783 [STAC_HP_DV5] = NULL, 1837 [STAC_HP_DV5] = NULL,
1838 [STAC_HP_HDX] = NULL,
1784}; 1839};
1785 1840
1786static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = { 1841static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1842 [STAC_92HD71BXX_AUTO] = "auto",
1787 [STAC_92HD71BXX_REF] = "ref", 1843 [STAC_92HD71BXX_REF] = "ref",
1788 [STAC_DELL_M4_1] = "dell-m4-1", 1844 [STAC_DELL_M4_1] = "dell-m4-1",
1789 [STAC_DELL_M4_2] = "dell-m4-2", 1845 [STAC_DELL_M4_2] = "dell-m4-2",
1790 [STAC_DELL_M4_3] = "dell-m4-3", 1846 [STAC_DELL_M4_3] = "dell-m4-3",
1791 [STAC_HP_M4] = "hp-m4", 1847 [STAC_HP_M4] = "hp-m4",
1792 [STAC_HP_DV5] = "hp-dv5", 1848 [STAC_HP_DV5] = "hp-dv5",
1849 [STAC_HP_HDX] = "hp-hdx",
1793}; 1850};
1794 1851
1795static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = { 1852static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1796 /* SigmaTel reference board */ 1853 /* SigmaTel reference board */
1797 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1854 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1798 "DFI LanParty", STAC_92HD71BXX_REF), 1855 "DFI LanParty", STAC_92HD71BXX_REF),
1799 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f2, 1856 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
1800 "HP dv5", STAC_HP_M4), 1857 "DFI LanParty", STAC_92HD71BXX_REF),
1801 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f4, 1858 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3080,
1802 "HP dv7", STAC_HP_DV5), 1859 "HP", STAC_HP_DV5),
1803 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30f7, 1860 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x30f0,
1804 "HP dv4", STAC_HP_DV5), 1861 "HP dv4-7", STAC_HP_DV5),
1805 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fc, 1862 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xfff0, 0x3600,
1806 "HP dv7", STAC_HP_M4), 1863 "HP dv4-7", STAC_HP_DV5),
1807 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3600, 1864 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3610,
1808 "HP dv5", STAC_HP_DV5), 1865 "HP HDX", STAC_HP_HDX), /* HDX18 */
1809 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3603,
1810 "HP dv5", STAC_HP_DV5),
1811 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a, 1866 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
1812 "unknown HP", STAC_HP_M4), 1867 "HP mini 1000", STAC_HP_M4),
1868 SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361b,
1869 "HP HDX", STAC_HP_HDX), /* HDX16 */
1813 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233, 1870 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1814 "unknown Dell", STAC_DELL_M4_1), 1871 "unknown Dell", STAC_DELL_M4_1),
1815 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234, 1872 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
@@ -1961,6 +2018,7 @@ static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
1961}; 2018};
1962 2019
1963static const char *stac922x_models[STAC_922X_MODELS] = { 2020static const char *stac922x_models[STAC_922X_MODELS] = {
2021 [STAC_922X_AUTO] = "auto",
1964 [STAC_D945_REF] = "ref", 2022 [STAC_D945_REF] = "ref",
1965 [STAC_D945GTP5] = "5stack", 2023 [STAC_D945GTP5] = "5stack",
1966 [STAC_D945GTP3] = "3stack", 2024 [STAC_D945GTP3] = "3stack",
@@ -1988,6 +2046,8 @@ static struct snd_pci_quirk stac922x_cfg_tbl[] = {
1988 /* SigmaTel reference board */ 2046 /* SigmaTel reference board */
1989 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 2047 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1990 "DFI LanParty", STAC_D945_REF), 2048 "DFI LanParty", STAC_D945_REF),
2049 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2050 "DFI LanParty", STAC_D945_REF),
1991 /* Intel 945G based systems */ 2051 /* Intel 945G based systems */
1992 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101, 2052 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
1993 "Intel D945G", STAC_D945GTP3), 2053 "Intel D945G", STAC_D945GTP3),
@@ -2041,6 +2101,9 @@ static struct snd_pci_quirk stac922x_cfg_tbl[] = {
2041 "Intel D945P", STAC_D945GTP3), 2101 "Intel D945P", STAC_D945GTP3),
2042 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707, 2102 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
2043 "Intel D945P", STAC_D945GTP5), 2103 "Intel D945P", STAC_D945GTP5),
2104 /* other intel */
2105 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0204,
2106 "Intel D945", STAC_D945_REF),
2044 /* other systems */ 2107 /* other systems */
2045 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */ 2108 /* Apple Intel Mac (Mac Mini, MacBook, MacBook Pro...) */
2046 SND_PCI_QUIRK(0x8384, 0x7680, 2109 SND_PCI_QUIRK(0x8384, 0x7680,
@@ -2065,31 +2128,7 @@ static struct snd_pci_quirk stac922x_cfg_tbl[] = {
2065 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7, 2128 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
2066 "Dell XPS M1210", STAC_922X_DELL_M82), 2129 "Dell XPS M1210", STAC_922X_DELL_M82),
2067 /* ECS/PC Chips boards */ 2130 /* ECS/PC Chips boards */
2068 SND_PCI_QUIRK(0x1019, 0x2144, 2131 SND_PCI_QUIRK_MASK(0x1019, 0xf000, 0x2000,
2069 "ECS/PC chips", STAC_ECS_202),
2070 SND_PCI_QUIRK(0x1019, 0x2608,
2071 "ECS/PC chips", STAC_ECS_202),
2072 SND_PCI_QUIRK(0x1019, 0x2633,
2073 "ECS/PC chips P17G/1333", STAC_ECS_202),
2074 SND_PCI_QUIRK(0x1019, 0x2811,
2075 "ECS/PC chips", STAC_ECS_202),
2076 SND_PCI_QUIRK(0x1019, 0x2812,
2077 "ECS/PC chips", STAC_ECS_202),
2078 SND_PCI_QUIRK(0x1019, 0x2813,
2079 "ECS/PC chips", STAC_ECS_202),
2080 SND_PCI_QUIRK(0x1019, 0x2814,
2081 "ECS/PC chips", STAC_ECS_202),
2082 SND_PCI_QUIRK(0x1019, 0x2815,
2083 "ECS/PC chips", STAC_ECS_202),
2084 SND_PCI_QUIRK(0x1019, 0x2816,
2085 "ECS/PC chips", STAC_ECS_202),
2086 SND_PCI_QUIRK(0x1019, 0x2817,
2087 "ECS/PC chips", STAC_ECS_202),
2088 SND_PCI_QUIRK(0x1019, 0x2818,
2089 "ECS/PC chips", STAC_ECS_202),
2090 SND_PCI_QUIRK(0x1019, 0x2819,
2091 "ECS/PC chips", STAC_ECS_202),
2092 SND_PCI_QUIRK(0x1019, 0x2820,
2093 "ECS/PC chips", STAC_ECS_202), 2132 "ECS/PC chips", STAC_ECS_202),
2094 {} /* terminator */ 2133 {} /* terminator */
2095}; 2134};
@@ -2132,6 +2171,7 @@ static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
2132}; 2171};
2133 2172
2134static const char *stac927x_models[STAC_927X_MODELS] = { 2173static const char *stac927x_models[STAC_927X_MODELS] = {
2174 [STAC_927X_AUTO] = "auto",
2135 [STAC_D965_REF_NO_JD] = "ref-no-jd", 2175 [STAC_D965_REF_NO_JD] = "ref-no-jd",
2136 [STAC_D965_REF] = "ref", 2176 [STAC_D965_REF] = "ref",
2137 [STAC_D965_3ST] = "3stack", 2177 [STAC_D965_3ST] = "3stack",
@@ -2144,26 +2184,16 @@ static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2144 /* SigmaTel reference board */ 2184 /* SigmaTel reference board */
2145 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 2185 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2146 "DFI LanParty", STAC_D965_REF), 2186 "DFI LanParty", STAC_D965_REF),
2187 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2188 "DFI LanParty", STAC_D965_REF),
2147 /* Intel 946 based systems */ 2189 /* Intel 946 based systems */
2148 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST), 2190 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
2149 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST), 2191 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
2150 /* 965 based 3 stack systems */ 2192 /* 965 based 3 stack systems */
2151 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST), 2193 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2100,
2152 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST), 2194 "Intel D965", STAC_D965_3ST),
2153 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST), 2195 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2000,
2154 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST), 2196 "Intel D965", STAC_D965_3ST),
2155 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
2156 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
2157 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
2158 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
2159 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
2160 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
2161 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
2162 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
2163 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
2164 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
2165 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
2166 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
2167 /* Dell 3 stack systems */ 2197 /* Dell 3 stack systems */
2168 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST), 2198 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f7, "Dell XPS M1730", STAC_DELL_3ST),
2169 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST), 2199 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
@@ -2179,15 +2209,10 @@ static struct snd_pci_quirk stac927x_cfg_tbl[] = {
2179 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS), 2209 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ff, "Dell ", STAC_DELL_BIOS),
2180 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS), 2210 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_DELL_BIOS),
2181 /* 965 based 5 stack systems */ 2211 /* 965 based 5 stack systems */
2182 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST), 2212 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2300,
2183 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST), 2213 "Intel D965", STAC_D965_5ST),
2184 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST), 2214 SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_INTEL, 0xff00, 0x2500,
2185 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST), 2215 "Intel D965", STAC_D965_5ST),
2186 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
2187 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
2188 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
2189 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
2190 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
2191 {} /* terminator */ 2216 {} /* terminator */
2192}; 2217};
2193 2218
@@ -2240,19 +2265,25 @@ static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
2240 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs, 2265 [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
2241 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs, 2266 [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
2242 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs, 2267 [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
2268 [STAC_9205_EAPD] = NULL,
2243}; 2269};
2244 2270
2245static const char *stac9205_models[STAC_9205_MODELS] = { 2271static const char *stac9205_models[STAC_9205_MODELS] = {
2272 [STAC_9205_AUTO] = "auto",
2246 [STAC_9205_REF] = "ref", 2273 [STAC_9205_REF] = "ref",
2247 [STAC_9205_DELL_M42] = "dell-m42", 2274 [STAC_9205_DELL_M42] = "dell-m42",
2248 [STAC_9205_DELL_M43] = "dell-m43", 2275 [STAC_9205_DELL_M43] = "dell-m43",
2249 [STAC_9205_DELL_M44] = "dell-m44", 2276 [STAC_9205_DELL_M44] = "dell-m44",
2277 [STAC_9205_EAPD] = "eapd",
2250}; 2278};
2251 2279
2252static struct snd_pci_quirk stac9205_cfg_tbl[] = { 2280static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2253 /* SigmaTel reference board */ 2281 /* SigmaTel reference board */
2254 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 2282 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
2255 "DFI LanParty", STAC_9205_REF), 2283 "DFI LanParty", STAC_9205_REF),
2284 SND_PCI_QUIRK(PCI_VENDOR_ID_DFI, 0x3101,
2285 "DFI LanParty", STAC_9205_REF),
2286 /* Dell */
2256 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1, 2287 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
2257 "unknown Dell", STAC_9205_DELL_M42), 2288 "unknown Dell", STAC_9205_DELL_M42),
2258 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2, 2289 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
@@ -2283,101 +2314,24 @@ static struct snd_pci_quirk stac9205_cfg_tbl[] = {
2283 "Dell Inspiron", STAC_9205_DELL_M44), 2314 "Dell Inspiron", STAC_9205_DELL_M44),
2284 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228, 2315 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0228,
2285 "Dell Vostro 1500", STAC_9205_DELL_M42), 2316 "Dell Vostro 1500", STAC_9205_DELL_M42),
2317 /* Gateway */
2318 SND_PCI_QUIRK(0x107b, 0x0565, "Gateway T1616", STAC_9205_EAPD),
2286 {} /* terminator */ 2319 {} /* terminator */
2287}; 2320};
2288 2321
2289static int stac92xx_save_bios_config_regs(struct hda_codec *codec) 2322static void stac92xx_set_config_regs(struct hda_codec *codec,
2323 unsigned int *pincfgs)
2290{ 2324{
2291 int i; 2325 int i;
2292 struct sigmatel_spec *spec = codec->spec; 2326 struct sigmatel_spec *spec = codec->spec;
2293
2294 kfree(spec->pin_configs);
2295 spec->pin_configs = kcalloc(spec->num_pins, sizeof(*spec->pin_configs),
2296 GFP_KERNEL);
2297 if (!spec->pin_configs)
2298 return -ENOMEM;
2299
2300 for (i = 0; i < spec->num_pins; i++) {
2301 hda_nid_t nid = spec->pin_nids[i];
2302 unsigned int pin_cfg;
2303
2304 pin_cfg = snd_hda_codec_read(codec, nid, 0,
2305 AC_VERB_GET_CONFIG_DEFAULT, 0x00);
2306 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
2307 nid, pin_cfg);
2308 spec->pin_configs[i] = pin_cfg;
2309 }
2310
2311 return 0;
2312}
2313 2327
2314static void stac92xx_set_config_reg(struct hda_codec *codec, 2328 if (!pincfgs)
2315 hda_nid_t pin_nid, unsigned int pin_config) 2329 return;
2316{
2317 int i;
2318 snd_hda_codec_write(codec, pin_nid, 0,
2319 AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
2320 pin_config & 0x000000ff);
2321 snd_hda_codec_write(codec, pin_nid, 0,
2322 AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
2323 (pin_config & 0x0000ff00) >> 8);
2324 snd_hda_codec_write(codec, pin_nid, 0,
2325 AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
2326 (pin_config & 0x00ff0000) >> 16);
2327 snd_hda_codec_write(codec, pin_nid, 0,
2328 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
2329 pin_config >> 24);
2330 i = snd_hda_codec_read(codec, pin_nid, 0,
2331 AC_VERB_GET_CONFIG_DEFAULT,
2332 0x00);
2333 snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
2334 pin_nid, i);
2335}
2336
2337static void stac92xx_set_config_regs(struct hda_codec *codec)
2338{
2339 int i;
2340 struct sigmatel_spec *spec = codec->spec;
2341
2342 if (!spec->pin_configs)
2343 return;
2344 2330
2345 for (i = 0; i < spec->num_pins; i++) 2331 for (i = 0; i < spec->num_pins; i++)
2346 stac92xx_set_config_reg(codec, spec->pin_nids[i], 2332 if (spec->pin_nids[i] && pincfgs[i])
2347 spec->pin_configs[i]); 2333 snd_hda_codec_set_pincfg(codec, spec->pin_nids[i],
2348} 2334 pincfgs[i]);
2349
2350static int stac_save_pin_cfgs(struct hda_codec *codec, unsigned int *pins)
2351{
2352 struct sigmatel_spec *spec = codec->spec;
2353
2354 if (!pins)
2355 return stac92xx_save_bios_config_regs(codec);
2356
2357 kfree(spec->pin_configs);
2358 spec->pin_configs = kmemdup(pins,
2359 spec->num_pins * sizeof(*pins),
2360 GFP_KERNEL);
2361 if (!spec->pin_configs)
2362 return -ENOMEM;
2363
2364 stac92xx_set_config_regs(codec);
2365 return 0;
2366}
2367
2368static void stac_change_pin_config(struct hda_codec *codec, hda_nid_t nid,
2369 unsigned int cfg)
2370{
2371 struct sigmatel_spec *spec = codec->spec;
2372 int i;
2373
2374 for (i = 0; i < spec->num_pins; i++) {
2375 if (spec->pin_nids[i] == nid) {
2376 spec->pin_configs[i] = cfg;
2377 stac92xx_set_config_reg(codec, nid, cfg);
2378 break;
2379 }
2380 }
2381} 2335}
2382 2336
2383/* 2337/*
@@ -2567,7 +2521,7 @@ static int stac92xx_build_pcms(struct hda_codec *codec)
2567 codec->num_pcms++; 2521 codec->num_pcms++;
2568 info++; 2522 info++;
2569 info->name = "STAC92xx Digital"; 2523 info->name = "STAC92xx Digital";
2570 info->pcm_type = HDA_PCM_TYPE_SPDIF; 2524 info->pcm_type = spec->autocfg.dig_out_type[0];
2571 if (spec->multiout.dig_out_nid) { 2525 if (spec->multiout.dig_out_nid) {
2572 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback; 2526 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
2573 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 2527 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
@@ -2583,8 +2537,7 @@ static int stac92xx_build_pcms(struct hda_codec *codec)
2583 2537
2584static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid) 2538static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
2585{ 2539{
2586 unsigned int pincap = snd_hda_param_read(codec, nid, 2540 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2587 AC_PAR_PIN_CAP);
2588 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT; 2541 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
2589 if (pincap & AC_PINCAP_VREF_100) 2542 if (pincap & AC_PINCAP_VREF_100)
2590 return AC_PINCTL_VREF_100; 2543 return AC_PINCTL_VREF_100;
@@ -2759,22 +2712,37 @@ static struct snd_kcontrol_new stac92xx_control_templates[] = {
2759}; 2712};
2760 2713
2761/* add dynamic controls */ 2714/* add dynamic controls */
2762static int stac92xx_add_control_temp(struct sigmatel_spec *spec, 2715static struct snd_kcontrol_new *
2763 struct snd_kcontrol_new *ktemp, 2716stac_control_new(struct sigmatel_spec *spec,
2764 int idx, const char *name, 2717 struct snd_kcontrol_new *ktemp,
2765 unsigned long val) 2718 const char *name)
2766{ 2719{
2767 struct snd_kcontrol_new *knew; 2720 struct snd_kcontrol_new *knew;
2768 2721
2769 snd_array_init(&spec->kctls, sizeof(*knew), 32); 2722 snd_array_init(&spec->kctls, sizeof(*knew), 32);
2770 knew = snd_array_new(&spec->kctls); 2723 knew = snd_array_new(&spec->kctls);
2771 if (!knew) 2724 if (!knew)
2772 return -ENOMEM; 2725 return NULL;
2773 *knew = *ktemp; 2726 *knew = *ktemp;
2774 knew->index = idx;
2775 knew->name = kstrdup(name, GFP_KERNEL); 2727 knew->name = kstrdup(name, GFP_KERNEL);
2776 if (!knew->name) 2728 if (!knew->name) {
2729 /* roolback */
2730 memset(knew, 0, sizeof(*knew));
2731 spec->kctls.alloced--;
2732 return NULL;
2733 }
2734 return knew;
2735}
2736
2737static int stac92xx_add_control_temp(struct sigmatel_spec *spec,
2738 struct snd_kcontrol_new *ktemp,
2739 int idx, const char *name,
2740 unsigned long val)
2741{
2742 struct snd_kcontrol_new *knew = stac_control_new(spec, ktemp, name);
2743 if (!knew)
2777 return -ENOMEM; 2744 return -ENOMEM;
2745 knew->index = idx;
2778 knew->private_value = val; 2746 knew->private_value = val;
2779 return 0; 2747 return 0;
2780} 2748}
@@ -2796,6 +2764,29 @@ static inline int stac92xx_add_control(struct sigmatel_spec *spec, int type,
2796 return stac92xx_add_control_idx(spec, type, 0, name, val); 2764 return stac92xx_add_control_idx(spec, type, 0, name, val);
2797} 2765}
2798 2766
2767static struct snd_kcontrol_new stac_input_src_temp = {
2768 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2769 .name = "Input Source",
2770 .info = stac92xx_mux_enum_info,
2771 .get = stac92xx_mux_enum_get,
2772 .put = stac92xx_mux_enum_put,
2773};
2774
2775static int stac92xx_add_input_source(struct sigmatel_spec *spec)
2776{
2777 struct snd_kcontrol_new *knew;
2778 struct hda_input_mux *imux = &spec->private_imux;
2779
2780 if (!spec->num_adcs || imux->num_items <= 1)
2781 return 0; /* no need for input source control */
2782 knew = stac_control_new(spec, &stac_input_src_temp,
2783 stac_input_src_temp.name);
2784 if (!knew)
2785 return -ENOMEM;
2786 knew->count = spec->num_adcs;
2787 return 0;
2788}
2789
2799/* check whether the line-input can be used as line-out */ 2790/* check whether the line-input can be used as line-out */
2800static hda_nid_t check_line_out_switch(struct hda_codec *codec) 2791static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2801{ 2792{
@@ -2807,7 +2798,7 @@ static hda_nid_t check_line_out_switch(struct hda_codec *codec)
2807 if (cfg->line_out_type != AUTO_PIN_LINE_OUT) 2798 if (cfg->line_out_type != AUTO_PIN_LINE_OUT)
2808 return 0; 2799 return 0;
2809 nid = cfg->input_pins[AUTO_PIN_LINE]; 2800 nid = cfg->input_pins[AUTO_PIN_LINE];
2810 pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 2801 pincap = snd_hda_query_pin_caps(codec, nid);
2811 if (pincap & AC_PINCAP_OUT) 2802 if (pincap & AC_PINCAP_OUT)
2812 return nid; 2803 return nid;
2813 return 0; 2804 return 0;
@@ -2826,12 +2817,11 @@ static hda_nid_t check_mic_out_switch(struct hda_codec *codec)
2826 mic_pin = AUTO_PIN_MIC; 2817 mic_pin = AUTO_PIN_MIC;
2827 for (;;) { 2818 for (;;) {
2828 hda_nid_t nid = cfg->input_pins[mic_pin]; 2819 hda_nid_t nid = cfg->input_pins[mic_pin];
2829 def_conf = snd_hda_codec_read(codec, nid, 0, 2820 def_conf = snd_hda_codec_get_pincfg(codec, nid);
2830 AC_VERB_GET_CONFIG_DEFAULT, 0);
2831 /* some laptops have an internal analog microphone 2821 /* some laptops have an internal analog microphone
2832 * which can't be used as a output */ 2822 * which can't be used as a output */
2833 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) { 2823 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
2834 pincap = snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP); 2824 pincap = snd_hda_query_pin_caps(codec, nid);
2835 if (pincap & AC_PINCAP_OUT) 2825 if (pincap & AC_PINCAP_OUT)
2836 return nid; 2826 return nid;
2837 } 2827 }
@@ -2879,8 +2869,7 @@ static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2879 conn_len = snd_hda_get_connections(codec, nid, conn, 2869 conn_len = snd_hda_get_connections(codec, nid, conn,
2880 HDA_MAX_CONNECTIONS); 2870 HDA_MAX_CONNECTIONS);
2881 for (j = 0; j < conn_len; j++) { 2871 for (j = 0; j < conn_len; j++) {
2882 wcaps = snd_hda_param_read(codec, conn[j], 2872 wcaps = get_wcaps(codec, conn[j]);
2883 AC_PAR_AUDIO_WIDGET_CAP);
2884 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 2873 wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
2885 /* we check only analog outputs */ 2874 /* we check only analog outputs */
2886 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL)) 2875 if (wtype != AC_WID_AUD_OUT || (wcaps & AC_WCAP_DIGITAL))
@@ -2895,6 +2884,16 @@ static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2895 return conn[j]; 2884 return conn[j];
2896 } 2885 }
2897 } 2886 }
2887 /* if all DACs are already assigned, connect to the primary DAC */
2888 if (conn_len > 1) {
2889 for (j = 0; j < conn_len; j++) {
2890 if (conn[j] == spec->multiout.dac_nids[0]) {
2891 snd_hda_codec_write_cache(codec, nid, 0,
2892 AC_VERB_SET_CONNECT_SEL, j);
2893 break;
2894 }
2895 }
2896 }
2898 return 0; 2897 return 0;
2899} 2898}
2900 2899
@@ -2935,6 +2934,26 @@ static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
2935 add_spec_dacs(spec, dac); 2934 add_spec_dacs(spec, dac);
2936 } 2935 }
2937 2936
2937 for (i = 0; i < cfg->hp_outs; i++) {
2938 nid = cfg->hp_pins[i];
2939 dac = get_unassigned_dac(codec, nid);
2940 if (dac) {
2941 if (!spec->multiout.hp_nid)
2942 spec->multiout.hp_nid = dac;
2943 else
2944 add_spec_extra_dacs(spec, dac);
2945 }
2946 spec->hp_dacs[i] = dac;
2947 }
2948
2949 for (i = 0; i < cfg->speaker_outs; i++) {
2950 nid = cfg->speaker_pins[i];
2951 dac = get_unassigned_dac(codec, nid);
2952 if (dac)
2953 add_spec_extra_dacs(spec, dac);
2954 spec->speaker_dacs[i] = dac;
2955 }
2956
2938 /* add line-in as output */ 2957 /* add line-in as output */
2939 nid = check_line_out_switch(codec); 2958 nid = check_line_out_switch(codec);
2940 if (nid) { 2959 if (nid) {
@@ -2962,26 +2981,6 @@ static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
2962 } 2981 }
2963 } 2982 }
2964 2983
2965 for (i = 0; i < cfg->hp_outs; i++) {
2966 nid = cfg->hp_pins[i];
2967 dac = get_unassigned_dac(codec, nid);
2968 if (dac) {
2969 if (!spec->multiout.hp_nid)
2970 spec->multiout.hp_nid = dac;
2971 else
2972 add_spec_extra_dacs(spec, dac);
2973 }
2974 spec->hp_dacs[i] = dac;
2975 }
2976
2977 for (i = 0; i < cfg->speaker_outs; i++) {
2978 nid = cfg->speaker_pins[i];
2979 dac = get_unassigned_dac(codec, nid);
2980 if (dac)
2981 add_spec_extra_dacs(spec, dac);
2982 spec->speaker_dacs[i] = dac;
2983 }
2984
2985 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n", 2984 snd_printd("stac92xx: dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
2986 spec->multiout.num_dacs, 2985 spec->multiout.num_dacs,
2987 spec->multiout.dac_nids[0], 2986 spec->multiout.dac_nids[0],
@@ -2994,24 +2993,47 @@ static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec)
2994} 2993}
2995 2994
2996/* create volume control/switch for the given prefx type */ 2995/* create volume control/switch for the given prefx type */
2997static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs) 2996static int create_controls_idx(struct hda_codec *codec, const char *pfx,
2997 int idx, hda_nid_t nid, int chs)
2998{ 2998{
2999 struct sigmatel_spec *spec = codec->spec;
2999 char name[32]; 3000 char name[32];
3000 int err; 3001 int err;
3001 3002
3003 if (!spec->check_volume_offset) {
3004 unsigned int caps, step, nums, db_scale;
3005 caps = query_amp_caps(codec, nid, HDA_OUTPUT);
3006 step = (caps & AC_AMPCAP_STEP_SIZE) >>
3007 AC_AMPCAP_STEP_SIZE_SHIFT;
3008 step = (step + 1) * 25; /* in .01dB unit */
3009 nums = (caps & AC_AMPCAP_NUM_STEPS) >>
3010 AC_AMPCAP_NUM_STEPS_SHIFT;
3011 db_scale = nums * step;
3012 /* if dB scale is over -64dB, and finer enough,
3013 * let's reduce it to half
3014 */
3015 if (db_scale > 6400 && nums >= 0x1f)
3016 spec->volume_offset = nums / 2;
3017 spec->check_volume_offset = 1;
3018 }
3019
3002 sprintf(name, "%s Playback Volume", pfx); 3020 sprintf(name, "%s Playback Volume", pfx);
3003 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name, 3021 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_VOL, idx, name,
3004 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); 3022 HDA_COMPOSE_AMP_VAL_OFS(nid, chs, 0, HDA_OUTPUT,
3023 spec->volume_offset));
3005 if (err < 0) 3024 if (err < 0)
3006 return err; 3025 return err;
3007 sprintf(name, "%s Playback Switch", pfx); 3026 sprintf(name, "%s Playback Switch", pfx);
3008 err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name, 3027 err = stac92xx_add_control_idx(spec, STAC_CTL_WIDGET_MUTE, idx, name,
3009 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); 3028 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
3010 if (err < 0) 3029 if (err < 0)
3011 return err; 3030 return err;
3012 return 0; 3031 return 0;
3013} 3032}
3014 3033
3034#define create_controls(codec, pfx, nid, chs) \
3035 create_controls_idx(codec, pfx, 0, nid, chs)
3036
3015static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid) 3037static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3016{ 3038{
3017 if (spec->multiout.num_dacs > 4) { 3039 if (spec->multiout.num_dacs > 4) {
@@ -3037,40 +3059,32 @@ static int add_spec_extra_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
3037 return 1; 3059 return 1;
3038} 3060}
3039 3061
3040static int is_unique_dac(struct sigmatel_spec *spec, hda_nid_t nid) 3062/* Create output controls
3041{ 3063 * The mixer elements are named depending on the given type (AUTO_PIN_XXX_OUT)
3042 int i; 3064 */
3043 3065static int create_multi_out_ctls(struct hda_codec *codec, int num_outs,
3044 if (spec->autocfg.line_outs != 1) 3066 const hda_nid_t *pins,
3045 return 0; 3067 const hda_nid_t *dac_nids,
3046 if (spec->multiout.hp_nid == nid) 3068 int type)
3047 return 0;
3048 for (i = 0; i < ARRAY_SIZE(spec->multiout.extra_out_nid); i++)
3049 if (spec->multiout.extra_out_nid[i] == nid)
3050 return 0;
3051 return 1;
3052}
3053
3054/* add playback controls from the parsed DAC table */
3055static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3056 const struct auto_pin_cfg *cfg)
3057{ 3069{
3058 struct sigmatel_spec *spec = codec->spec; 3070 struct sigmatel_spec *spec = codec->spec;
3059 static const char *chname[4] = { 3071 static const char *chname[4] = {
3060 "Front", "Surround", NULL /*CLFE*/, "Side" 3072 "Front", "Surround", NULL /*CLFE*/, "Side"
3061 }; 3073 };
3062 hda_nid_t nid = 0; 3074 hda_nid_t nid;
3063 int i, err; 3075 int i, err;
3064 unsigned int wid_caps; 3076 unsigned int wid_caps;
3065 3077
3066 for (i = 0; i < cfg->line_outs && spec->multiout.dac_nids[i]; i++) { 3078 for (i = 0; i < num_outs && i < ARRAY_SIZE(chname); i++) {
3067 nid = spec->multiout.dac_nids[i]; 3079 nid = dac_nids[i];
3068 if (i == 2) { 3080 if (!nid)
3081 continue;
3082 if (type != AUTO_PIN_HP_OUT && i == 2) {
3069 /* Center/LFE */ 3083 /* Center/LFE */
3070 err = create_controls(spec, "Center", nid, 1); 3084 err = create_controls(codec, "Center", nid, 1);
3071 if (err < 0) 3085 if (err < 0)
3072 return err; 3086 return err;
3073 err = create_controls(spec, "LFE", nid, 2); 3087 err = create_controls(codec, "LFE", nid, 2);
3074 if (err < 0) 3088 if (err < 0)
3075 return err; 3089 return err;
3076 3090
@@ -3086,23 +3100,47 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3086 } 3100 }
3087 3101
3088 } else { 3102 } else {
3089 const char *name = chname[i]; 3103 const char *name;
3090 /* if it's a single DAC, assign a better name */ 3104 int idx;
3091 if (!i && is_unique_dac(spec, nid)) { 3105 switch (type) {
3092 switch (cfg->line_out_type) { 3106 case AUTO_PIN_HP_OUT:
3093 case AUTO_PIN_HP_OUT: 3107 name = "Headphone";
3094 name = "Headphone"; 3108 idx = i;
3095 break; 3109 break;
3096 case AUTO_PIN_SPEAKER_OUT: 3110 case AUTO_PIN_SPEAKER_OUT:
3097 name = "Speaker"; 3111 name = "Speaker";
3098 break; 3112 idx = i;
3099 } 3113 break;
3114 default:
3115 name = chname[i];
3116 idx = 0;
3117 break;
3100 } 3118 }
3101 err = create_controls(spec, name, nid, 3); 3119 err = create_controls_idx(codec, name, idx, nid, 3);
3102 if (err < 0) 3120 if (err < 0)
3103 return err; 3121 return err;
3122 if (type == AUTO_PIN_HP_OUT && !spec->hp_detect) {
3123 wid_caps = get_wcaps(codec, pins[i]);
3124 if (wid_caps & AC_WCAP_UNSOL_CAP)
3125 spec->hp_detect = 1;
3126 }
3104 } 3127 }
3105 } 3128 }
3129 return 0;
3130}
3131
3132/* add playback controls from the parsed DAC table */
3133static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
3134 const struct auto_pin_cfg *cfg)
3135{
3136 struct sigmatel_spec *spec = codec->spec;
3137 int err;
3138
3139 err = create_multi_out_ctls(codec, cfg->line_outs, cfg->line_out_pins,
3140 spec->multiout.dac_nids,
3141 cfg->line_out_type);
3142 if (err < 0)
3143 return err;
3106 3144
3107 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) { 3145 if (cfg->hp_outs > 1 && cfg->line_out_type == AUTO_PIN_LINE_OUT) {
3108 err = stac92xx_add_control(spec, 3146 err = stac92xx_add_control(spec,
@@ -3137,40 +3175,18 @@ static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
3137 struct auto_pin_cfg *cfg) 3175 struct auto_pin_cfg *cfg)
3138{ 3176{
3139 struct sigmatel_spec *spec = codec->spec; 3177 struct sigmatel_spec *spec = codec->spec;
3140 hda_nid_t nid; 3178 int err;
3141 int i, err, nums; 3179
3180 err = create_multi_out_ctls(codec, cfg->hp_outs, cfg->hp_pins,
3181 spec->hp_dacs, AUTO_PIN_HP_OUT);
3182 if (err < 0)
3183 return err;
3184
3185 err = create_multi_out_ctls(codec, cfg->speaker_outs, cfg->speaker_pins,
3186 spec->speaker_dacs, AUTO_PIN_SPEAKER_OUT);
3187 if (err < 0)
3188 return err;
3142 3189
3143 nums = 0;
3144 for (i = 0; i < cfg->hp_outs; i++) {
3145 static const char *pfxs[] = {
3146 "Headphone", "Headphone2", "Headphone3",
3147 };
3148 unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
3149 if (wid_caps & AC_WCAP_UNSOL_CAP)
3150 spec->hp_detect = 1;
3151 if (nums >= ARRAY_SIZE(pfxs))
3152 continue;
3153 nid = spec->hp_dacs[i];
3154 if (!nid)
3155 continue;
3156 err = create_controls(spec, pfxs[nums++], nid, 3);
3157 if (err < 0)
3158 return err;
3159 }
3160 nums = 0;
3161 for (i = 0; i < cfg->speaker_outs; i++) {
3162 static const char *pfxs[] = {
3163 "Speaker", "External Speaker", "Speaker2",
3164 };
3165 if (nums >= ARRAY_SIZE(pfxs))
3166 continue;
3167 nid = spec->speaker_dacs[i];
3168 if (!nid)
3169 continue;
3170 err = create_controls(spec, pfxs[nums++], nid, 3);
3171 if (err < 0)
3172 return err;
3173 }
3174 return 0; 3190 return 0;
3175} 3191}
3176 3192
@@ -3379,11 +3395,7 @@ static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
3379 unsigned int wcaps; 3395 unsigned int wcaps;
3380 unsigned int def_conf; 3396 unsigned int def_conf;
3381 3397
3382 def_conf = snd_hda_codec_read(codec, 3398 def_conf = snd_hda_codec_get_pincfg(codec, spec->dmic_nids[i]);
3383 spec->dmic_nids[i],
3384 0,
3385 AC_VERB_GET_CONFIG_DEFAULT,
3386 0);
3387 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) 3399 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
3388 continue; 3400 continue;
3389 3401
@@ -3507,6 +3519,7 @@ static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
3507static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in) 3519static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
3508{ 3520{
3509 struct sigmatel_spec *spec = codec->spec; 3521 struct sigmatel_spec *spec = codec->spec;
3522 int hp_swap = 0;
3510 int err; 3523 int err;
3511 3524
3512 if ((err = snd_hda_parse_pin_def_config(codec, 3525 if ((err = snd_hda_parse_pin_def_config(codec,
@@ -3516,7 +3529,6 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3516 if (! spec->autocfg.line_outs) 3529 if (! spec->autocfg.line_outs)
3517 return 0; /* can't find valid pin config */ 3530 return 0; /* can't find valid pin config */
3518 3531
3519#if 0 /* FIXME: temporarily disabled */
3520 /* If we have no real line-out pin and multiple hp-outs, HPs should 3532 /* If we have no real line-out pin and multiple hp-outs, HPs should
3521 * be set up as multi-channel outputs. 3533 * be set up as multi-channel outputs.
3522 */ 3534 */
@@ -3535,8 +3547,8 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3535 spec->autocfg.line_outs = spec->autocfg.hp_outs; 3547 spec->autocfg.line_outs = spec->autocfg.hp_outs;
3536 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT; 3548 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3537 spec->autocfg.hp_outs = 0; 3549 spec->autocfg.hp_outs = 0;
3550 hp_swap = 1;
3538 } 3551 }
3539#endif /* FIXME: temporarily disabled */
3540 if (spec->autocfg.mono_out_pin) { 3552 if (spec->autocfg.mono_out_pin) {
3541 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) & 3553 int dir = get_wcaps(codec, spec->autocfg.mono_out_pin) &
3542 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP); 3554 (AC_WCAP_OUT_AMP | AC_WCAP_IN_AMP);
@@ -3629,12 +3641,19 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3629#endif 3641#endif
3630 3642
3631 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg); 3643 err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
3632
3633 if (err < 0) 3644 if (err < 0)
3634 return err; 3645 return err;
3635 3646
3636 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg); 3647 /* All output parsing done, now restore the swapped hp pins */
3648 if (hp_swap) {
3649 memcpy(spec->autocfg.hp_pins, spec->autocfg.line_out_pins,
3650 sizeof(spec->autocfg.hp_pins));
3651 spec->autocfg.hp_outs = spec->autocfg.line_outs;
3652 spec->autocfg.line_out_type = AUTO_PIN_HP_OUT;
3653 spec->autocfg.line_outs = 0;
3654 }
3637 3655
3656 err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
3638 if (err < 0) 3657 if (err < 0)
3639 return err; 3658 return err;
3640 3659
@@ -3663,11 +3682,15 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3663 return err; 3682 return err;
3664 } 3683 }
3665 3684
3685 err = stac92xx_add_input_source(spec);
3686 if (err < 0)
3687 return err;
3688
3666 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 3689 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3667 if (spec->multiout.max_channels > 2) 3690 if (spec->multiout.max_channels > 2)
3668 spec->surr_switch = 1; 3691 spec->surr_switch = 1;
3669 3692
3670 if (spec->autocfg.dig_out_pin) 3693 if (spec->autocfg.dig_outs)
3671 spec->multiout.dig_out_nid = dig_out; 3694 spec->multiout.dig_out_nid = dig_out;
3672 if (dig_in && spec->autocfg.dig_in_pin) 3695 if (dig_in && spec->autocfg.dig_in_pin)
3673 spec->dig_in_nid = dig_in; 3696 spec->dig_in_nid = dig_in;
@@ -3730,9 +3753,7 @@ static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3730 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) { 3753 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
3731 hda_nid_t pin = spec->autocfg.line_out_pins[i]; 3754 hda_nid_t pin = spec->autocfg.line_out_pins[i];
3732 unsigned int defcfg; 3755 unsigned int defcfg;
3733 defcfg = snd_hda_codec_read(codec, pin, 0, 3756 defcfg = snd_hda_codec_get_pincfg(codec, pin);
3734 AC_VERB_GET_CONFIG_DEFAULT,
3735 0x00);
3736 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) { 3757 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
3737 unsigned int wcaps = get_wcaps(codec, pin); 3758 unsigned int wcaps = get_wcaps(codec, pin);
3738 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP); 3759 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
@@ -3745,7 +3766,7 @@ static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
3745 } 3766 }
3746 3767
3747 if (lfe_pin) { 3768 if (lfe_pin) {
3748 err = create_controls(spec, "LFE", lfe_pin, 1); 3769 err = create_controls(codec, "LFE", lfe_pin, 1);
3749 if (err < 0) 3770 if (err < 0)
3750 return err; 3771 return err;
3751 } 3772 }
@@ -3776,7 +3797,11 @@ static int stac9200_parse_auto_config(struct hda_codec *codec)
3776 return err; 3797 return err;
3777 } 3798 }
3778 3799
3779 if (spec->autocfg.dig_out_pin) 3800 err = stac92xx_add_input_source(spec);
3801 if (err < 0)
3802 return err;
3803
3804 if (spec->autocfg.dig_outs)
3780 spec->multiout.dig_out_nid = 0x05; 3805 spec->multiout.dig_out_nid = 0x05;
3781 if (spec->autocfg.dig_in_pin) 3806 if (spec->autocfg.dig_in_pin)
3782 spec->dig_in_nid = 0x04; 3807 spec->dig_in_nid = 0x04;
@@ -3832,8 +3857,7 @@ static int stac92xx_add_jack(struct hda_codec *codec,
3832#ifdef CONFIG_SND_JACK 3857#ifdef CONFIG_SND_JACK
3833 struct sigmatel_spec *spec = codec->spec; 3858 struct sigmatel_spec *spec = codec->spec;
3834 struct sigmatel_jack *jack; 3859 struct sigmatel_jack *jack;
3835 int def_conf = snd_hda_codec_read(codec, nid, 3860 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
3836 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
3837 int connectivity = get_defcfg_connect(def_conf); 3861 int connectivity = get_defcfg_connect(def_conf);
3838 char name[32]; 3862 char name[32];
3839 3863
@@ -3948,6 +3972,36 @@ static void stac92xx_power_down(struct hda_codec *codec)
3948static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid, 3972static void stac_toggle_power_map(struct hda_codec *codec, hda_nid_t nid,
3949 int enable); 3973 int enable);
3950 3974
3975/* override some hints from the hwdep entry */
3976static void stac_store_hints(struct hda_codec *codec)
3977{
3978 struct sigmatel_spec *spec = codec->spec;
3979 const char *p;
3980 int val;
3981
3982 val = snd_hda_get_bool_hint(codec, "hp_detect");
3983 if (val >= 0)
3984 spec->hp_detect = val;
3985 p = snd_hda_get_hint(codec, "gpio_mask");
3986 if (p) {
3987 spec->gpio_mask = simple_strtoul(p, NULL, 0);
3988 spec->eapd_mask = spec->gpio_dir = spec->gpio_data =
3989 spec->gpio_mask;
3990 }
3991 p = snd_hda_get_hint(codec, "gpio_dir");
3992 if (p)
3993 spec->gpio_dir = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
3994 p = snd_hda_get_hint(codec, "gpio_data");
3995 if (p)
3996 spec->gpio_data = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
3997 p = snd_hda_get_hint(codec, "eapd_mask");
3998 if (p)
3999 spec->eapd_mask = simple_strtoul(p, NULL, 0) & spec->gpio_mask;
4000 val = snd_hda_get_bool_hint(codec, "eapd_switch");
4001 if (val >= 0)
4002 spec->eapd_switch = val;
4003}
4004
3951static int stac92xx_init(struct hda_codec *codec) 4005static int stac92xx_init(struct hda_codec *codec)
3952{ 4006{
3953 struct sigmatel_spec *spec = codec->spec; 4007 struct sigmatel_spec *spec = codec->spec;
@@ -3964,6 +4018,9 @@ static int stac92xx_init(struct hda_codec *codec)
3964 spec->adc_nids[i], 0, 4018 spec->adc_nids[i], 0,
3965 AC_VERB_SET_POWER_STATE, AC_PWRST_D3); 4019 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3966 4020
4021 /* override some hints */
4022 stac_store_hints(codec);
4023
3967 /* set up GPIO */ 4024 /* set up GPIO */
3968 gpio = spec->gpio_data; 4025 gpio = spec->gpio_data;
3969 /* turn on EAPD statically when spec->eapd_switch isn't set. 4026 /* turn on EAPD statically when spec->eapd_switch isn't set.
@@ -4013,8 +4070,7 @@ static int stac92xx_init(struct hda_codec *codec)
4013 pinctl); 4070 pinctl);
4014 } 4071 }
4015 } 4072 }
4016 conf = snd_hda_codec_read(codec, nid, 0, 4073 conf = snd_hda_codec_get_pincfg(codec, nid);
4017 AC_VERB_GET_CONFIG_DEFAULT, 0);
4018 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) { 4074 if (get_defcfg_connect(conf) != AC_JACK_PORT_FIXED) {
4019 enable_pin_detect(codec, nid, 4075 enable_pin_detect(codec, nid,
4020 STAC_INSERT_EVENT); 4076 STAC_INSERT_EVENT);
@@ -4026,8 +4082,8 @@ static int stac92xx_init(struct hda_codec *codec)
4026 for (i = 0; i < spec->num_dmics; i++) 4082 for (i = 0; i < spec->num_dmics; i++)
4027 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i], 4083 stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
4028 AC_PINCTL_IN_EN); 4084 AC_PINCTL_IN_EN);
4029 if (cfg->dig_out_pin) 4085 if (cfg->dig_out_pins[0])
4030 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin, 4086 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pins[0],
4031 AC_PINCTL_OUT_EN); 4087 AC_PINCTL_OUT_EN);
4032 if (cfg->dig_in_pin) 4088 if (cfg->dig_in_pin)
4033 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin, 4089 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
@@ -4055,8 +4111,7 @@ static int stac92xx_init(struct hda_codec *codec)
4055 stac_toggle_power_map(codec, nid, 1); 4111 stac_toggle_power_map(codec, nid, 1);
4056 continue; 4112 continue;
4057 } 4113 }
4058 def_conf = snd_hda_codec_read(codec, nid, 0, 4114 def_conf = snd_hda_codec_get_pincfg(codec, nid);
4059 AC_VERB_GET_CONFIG_DEFAULT, 0);
4060 def_conf = get_defcfg_connect(def_conf); 4115 def_conf = get_defcfg_connect(def_conf);
4061 /* skip any ports that don't have jacks since presence 4116 /* skip any ports that don't have jacks since presence
4062 * detection is useless */ 4117 * detection is useless */
@@ -4110,7 +4165,6 @@ static void stac92xx_free(struct hda_codec *codec)
4110 if (! spec) 4165 if (! spec)
4111 return; 4166 return;
4112 4167
4113 kfree(spec->pin_configs);
4114 stac92xx_free_jacks(codec); 4168 stac92xx_free_jacks(codec);
4115 snd_array_free(&spec->events); 4169 snd_array_free(&spec->events);
4116 4170
@@ -4121,7 +4175,9 @@ static void stac92xx_free(struct hda_codec *codec)
4121static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid, 4175static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4122 unsigned int flag) 4176 unsigned int flag)
4123{ 4177{
4124 unsigned int pin_ctl = snd_hda_codec_read(codec, nid, 4178 unsigned int old_ctl, pin_ctl;
4179
4180 pin_ctl = snd_hda_codec_read(codec, nid,
4125 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00); 4181 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4126 4182
4127 if (pin_ctl & AC_PINCTL_IN_EN) { 4183 if (pin_ctl & AC_PINCTL_IN_EN) {
@@ -4135,14 +4191,17 @@ static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
4135 return; 4191 return;
4136 } 4192 }
4137 4193
4194 old_ctl = pin_ctl;
4138 /* if setting pin direction bits, clear the current 4195 /* if setting pin direction bits, clear the current
4139 direction bits first */ 4196 direction bits first */
4140 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)) 4197 if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
4141 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN); 4198 pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
4142 4199
4143 snd_hda_codec_write_cache(codec, nid, 0, 4200 pin_ctl |= flag;
4144 AC_VERB_SET_PIN_WIDGET_CONTROL, 4201 if (old_ctl != pin_ctl)
4145 pin_ctl | flag); 4202 snd_hda_codec_write_cache(codec, nid, 0,
4203 AC_VERB_SET_PIN_WIDGET_CONTROL,
4204 pin_ctl);
4146} 4205}
4147 4206
4148static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid, 4207static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
@@ -4150,9 +4209,10 @@ static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
4150{ 4209{
4151 unsigned int pin_ctl = snd_hda_codec_read(codec, nid, 4210 unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
4152 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00); 4211 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
4153 snd_hda_codec_write_cache(codec, nid, 0, 4212 if (pin_ctl & flag)
4154 AC_VERB_SET_PIN_WIDGET_CONTROL, 4213 snd_hda_codec_write_cache(codec, nid, 0,
4155 pin_ctl & ~flag); 4214 AC_VERB_SET_PIN_WIDGET_CONTROL,
4215 pin_ctl & ~flag);
4156} 4216}
4157 4217
4158static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid) 4218static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
@@ -4415,7 +4475,6 @@ static int stac92xx_resume(struct hda_codec *codec)
4415{ 4475{
4416 struct sigmatel_spec *spec = codec->spec; 4476 struct sigmatel_spec *spec = codec->spec;
4417 4477
4418 stac92xx_set_config_regs(codec);
4419 stac92xx_init(codec); 4478 stac92xx_init(codec);
4420 snd_hda_codec_resume_amp(codec); 4479 snd_hda_codec_resume_amp(codec);
4421 snd_hda_codec_resume_cache(codec); 4480 snd_hda_codec_resume_cache(codec);
@@ -4426,6 +4485,37 @@ static int stac92xx_resume(struct hda_codec *codec)
4426 return 0; 4485 return 0;
4427} 4486}
4428 4487
4488
4489/*
4490 * using power check for controlling mute led of HP HDX notebooks
4491 * check for mute state only on Speakers (nid = 0x10)
4492 *
4493 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4494 * the LED is NOT working properly !
4495 */
4496
4497#ifdef CONFIG_SND_HDA_POWER_SAVE
4498static int stac92xx_hp_hdx_check_power_status(struct hda_codec *codec,
4499 hda_nid_t nid)
4500{
4501 struct sigmatel_spec *spec = codec->spec;
4502
4503 if (nid == 0x10) {
4504 if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
4505 HDA_AMP_MUTE)
4506 spec->gpio_data &= ~0x08; /* orange */
4507 else
4508 spec->gpio_data |= 0x08; /* white */
4509
4510 stac_gpio_set(codec, spec->gpio_mask,
4511 spec->gpio_dir,
4512 spec->gpio_data);
4513 }
4514
4515 return 0;
4516}
4517#endif
4518
4429static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state) 4519static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
4430{ 4520{
4431 struct sigmatel_spec *spec = codec->spec; 4521 struct sigmatel_spec *spec = codec->spec;
@@ -4464,16 +4554,11 @@ static int patch_stac9200(struct hda_codec *codec)
4464 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS, 4554 spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
4465 stac9200_models, 4555 stac9200_models,
4466 stac9200_cfg_tbl); 4556 stac9200_cfg_tbl);
4467 if (spec->board_config < 0) { 4557 if (spec->board_config < 0)
4468 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n"); 4558 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
4469 err = stac92xx_save_bios_config_regs(codec); 4559 else
4470 } else 4560 stac92xx_set_config_regs(codec,
4471 err = stac_save_pin_cfgs(codec,
4472 stac9200_brd_tbl[spec->board_config]); 4561 stac9200_brd_tbl[spec->board_config]);
4473 if (err < 0) {
4474 stac92xx_free(codec);
4475 return err;
4476 }
4477 4562
4478 spec->multiout.max_channels = 2; 4563 spec->multiout.max_channels = 2;
4479 spec->multiout.num_dacs = 1; 4564 spec->multiout.num_dacs = 1;
@@ -4541,17 +4626,12 @@ static int patch_stac925x(struct hda_codec *codec)
4541 stac925x_models, 4626 stac925x_models,
4542 stac925x_cfg_tbl); 4627 stac925x_cfg_tbl);
4543 again: 4628 again:
4544 if (spec->board_config < 0) { 4629 if (spec->board_config < 0)
4545 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x," 4630 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
4546 "using BIOS defaults\n"); 4631 "using BIOS defaults\n");
4547 err = stac92xx_save_bios_config_regs(codec); 4632 else
4548 } else 4633 stac92xx_set_config_regs(codec,
4549 err = stac_save_pin_cfgs(codec,
4550 stac925x_brd_tbl[spec->board_config]); 4634 stac925x_brd_tbl[spec->board_config]);
4551 if (err < 0) {
4552 stac92xx_free(codec);
4553 return err;
4554 }
4555 4635
4556 spec->multiout.max_channels = 2; 4636 spec->multiout.max_channels = 2;
4557 spec->multiout.num_dacs = 1; 4637 spec->multiout.num_dacs = 1;
@@ -4629,17 +4709,12 @@ static int patch_stac92hd73xx(struct hda_codec *codec)
4629 stac92hd73xx_models, 4709 stac92hd73xx_models,
4630 stac92hd73xx_cfg_tbl); 4710 stac92hd73xx_cfg_tbl);
4631again: 4711again:
4632 if (spec->board_config < 0) { 4712 if (spec->board_config < 0)
4633 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 4713 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4634 " STAC92HD73XX, using BIOS defaults\n"); 4714 " STAC92HD73XX, using BIOS defaults\n");
4635 err = stac92xx_save_bios_config_regs(codec); 4715 else
4636 } else 4716 stac92xx_set_config_regs(codec,
4637 err = stac_save_pin_cfgs(codec,
4638 stac92hd73xx_brd_tbl[spec->board_config]); 4717 stac92hd73xx_brd_tbl[spec->board_config]);
4639 if (err < 0) {
4640 stac92xx_free(codec);
4641 return err;
4642 }
4643 4718
4644 num_dacs = snd_hda_get_connections(codec, 0x0a, 4719 num_dacs = snd_hda_get_connections(codec, 0x0a,
4645 conn, STAC92HD73_DAC_COUNT + 2) - 1; 4720 conn, STAC92HD73_DAC_COUNT + 2) - 1;
@@ -4653,14 +4728,18 @@ again:
4653 case 0x3: /* 6 Channel */ 4728 case 0x3: /* 6 Channel */
4654 spec->mixer = stac92hd73xx_6ch_mixer; 4729 spec->mixer = stac92hd73xx_6ch_mixer;
4655 spec->init = stac92hd73xx_6ch_core_init; 4730 spec->init = stac92hd73xx_6ch_core_init;
4731 spec->aloopback_ctl = stac92hd73xx_6ch_loopback;
4656 break; 4732 break;
4657 case 0x4: /* 8 Channel */ 4733 case 0x4: /* 8 Channel */
4658 spec->mixer = stac92hd73xx_8ch_mixer; 4734 spec->mixer = stac92hd73xx_8ch_mixer;
4659 spec->init = stac92hd73xx_8ch_core_init; 4735 spec->init = stac92hd73xx_8ch_core_init;
4736 spec->aloopback_ctl = stac92hd73xx_8ch_loopback;
4660 break; 4737 break;
4661 case 0x5: /* 10 Channel */ 4738 case 0x5: /* 10 Channel */
4662 spec->mixer = stac92hd73xx_10ch_mixer; 4739 spec->mixer = stac92hd73xx_10ch_mixer;
4663 spec->init = stac92hd73xx_10ch_core_init; 4740 spec->init = stac92hd73xx_10ch_core_init;
4741 spec->aloopback_ctl = stac92hd73xx_10ch_loopback;
4742 break;
4664 } 4743 }
4665 spec->multiout.dac_nids = spec->dac_nids; 4744 spec->multiout.dac_nids = spec->dac_nids;
4666 4745
@@ -4699,18 +4778,18 @@ again:
4699 spec->init = dell_m6_core_init; 4778 spec->init = dell_m6_core_init;
4700 switch (spec->board_config) { 4779 switch (spec->board_config) {
4701 case STAC_DELL_M6_AMIC: /* Analog Mics */ 4780 case STAC_DELL_M6_AMIC: /* Analog Mics */
4702 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170); 4781 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
4703 spec->num_dmics = 0; 4782 spec->num_dmics = 0;
4704 spec->private_dimux.num_items = 1; 4783 spec->private_dimux.num_items = 1;
4705 break; 4784 break;
4706 case STAC_DELL_M6_DMIC: /* Digital Mics */ 4785 case STAC_DELL_M6_DMIC: /* Digital Mics */
4707 stac92xx_set_config_reg(codec, 0x13, 0x90A60160); 4786 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
4708 spec->num_dmics = 1; 4787 spec->num_dmics = 1;
4709 spec->private_dimux.num_items = 2; 4788 spec->private_dimux.num_items = 2;
4710 break; 4789 break;
4711 case STAC_DELL_M6_BOTH: /* Both */ 4790 case STAC_DELL_M6_BOTH: /* Both */
4712 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170); 4791 snd_hda_codec_set_pincfg(codec, 0x0b, 0x90A70170);
4713 stac92xx_set_config_reg(codec, 0x13, 0x90A60160); 4792 snd_hda_codec_set_pincfg(codec, 0x13, 0x90A60160);
4714 spec->num_dmics = 1; 4793 spec->num_dmics = 1;
4715 spec->private_dimux.num_items = 2; 4794 spec->private_dimux.num_items = 2;
4716 break; 4795 break;
@@ -4773,6 +4852,7 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
4773 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1]; 4852 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
4774 int err; 4853 int err;
4775 int num_dacs; 4854 int num_dacs;
4855 hda_nid_t nid;
4776 4856
4777 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4857 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4778 if (spec == NULL) 4858 if (spec == NULL)
@@ -4791,15 +4871,6 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
4791 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids); 4871 spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
4792 spec->multiout.dac_nids = spec->dac_nids; 4872 spec->multiout.dac_nids = spec->dac_nids;
4793 4873
4794
4795 /* set port 0xe to select the last DAC
4796 */
4797 num_dacs = snd_hda_get_connections(codec, 0x0e,
4798 conn, STAC92HD83_DAC_COUNT + 1) - 1;
4799
4800 snd_hda_codec_write_cache(codec, 0xe, 0,
4801 AC_VERB_SET_CONNECT_SEL, num_dacs);
4802
4803 spec->init = stac92hd83xxx_core_init; 4874 spec->init = stac92hd83xxx_core_init;
4804 spec->mixer = stac92hd83xxx_mixer; 4875 spec->mixer = stac92hd83xxx_mixer;
4805 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids); 4876 spec->num_pins = ARRAY_SIZE(stac92hd83xxx_pin_nids);
@@ -4814,17 +4885,12 @@ static int patch_stac92hd83xxx(struct hda_codec *codec)
4814 stac92hd83xxx_models, 4885 stac92hd83xxx_models,
4815 stac92hd83xxx_cfg_tbl); 4886 stac92hd83xxx_cfg_tbl);
4816again: 4887again:
4817 if (spec->board_config < 0) { 4888 if (spec->board_config < 0)
4818 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 4889 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4819 " STAC92HD83XXX, using BIOS defaults\n"); 4890 " STAC92HD83XXX, using BIOS defaults\n");
4820 err = stac92xx_save_bios_config_regs(codec); 4891 else
4821 } else 4892 stac92xx_set_config_regs(codec,
4822 err = stac_save_pin_cfgs(codec,
4823 stac92hd83xxx_brd_tbl[spec->board_config]); 4893 stac92hd83xxx_brd_tbl[spec->board_config]);
4824 if (err < 0) {
4825 stac92xx_free(codec);
4826 return err;
4827 }
4828 4894
4829 switch (codec->vendor_id) { 4895 switch (codec->vendor_id) {
4830 case 0x111d7604: 4896 case 0x111d7604:
@@ -4851,6 +4917,23 @@ again:
4851 return err; 4917 return err;
4852 } 4918 }
4853 4919
4920 switch (spec->board_config) {
4921 case STAC_DELL_S14:
4922 nid = 0xf;
4923 break;
4924 default:
4925 nid = 0xe;
4926 break;
4927 }
4928
4929 num_dacs = snd_hda_get_connections(codec, nid,
4930 conn, STAC92HD83_DAC_COUNT + 1) - 1;
4931
4932 /* set port X to select the last DAC
4933 */
4934 snd_hda_codec_write_cache(codec, nid, 0,
4935 AC_VERB_SET_CONNECT_SEL, num_dacs);
4936
4854 codec->patch_ops = stac92xx_patch_ops; 4937 codec->patch_ops = stac92xx_patch_ops;
4855 4938
4856 codec->proc_widget_hook = stac92hd_proc_hook; 4939 codec->proc_widget_hook = stac92hd_proc_hook;
@@ -4858,7 +4941,16 @@ again:
4858 return 0; 4941 return 0;
4859} 4942}
4860 4943
4861static struct hda_input_mux stac92hd71bxx_dmux = { 4944static struct hda_input_mux stac92hd71bxx_dmux_nomixer = {
4945 .num_items = 3,
4946 .items = {
4947 { "Analog Inputs", 0x00 },
4948 { "Digital Mic 1", 0x02 },
4949 { "Digital Mic 2", 0x03 },
4950 }
4951};
4952
4953static struct hda_input_mux stac92hd71bxx_dmux_amixer = {
4862 .num_items = 4, 4954 .num_items = 4,
4863 .items = { 4955 .items = {
4864 { "Analog Inputs", 0x00 }, 4956 { "Analog Inputs", 0x00 },
@@ -4868,10 +4960,67 @@ static struct hda_input_mux stac92hd71bxx_dmux = {
4868 } 4960 }
4869}; 4961};
4870 4962
4963/* get the pin connection (fixed, none, etc) */
4964static unsigned int stac_get_defcfg_connect(struct hda_codec *codec, int idx)
4965{
4966 struct sigmatel_spec *spec = codec->spec;
4967 unsigned int cfg;
4968
4969 cfg = snd_hda_codec_get_pincfg(codec, spec->pin_nids[idx]);
4970 return get_defcfg_connect(cfg);
4971}
4972
4973static int stac92hd71bxx_connected_ports(struct hda_codec *codec,
4974 hda_nid_t *nids, int num_nids)
4975{
4976 struct sigmatel_spec *spec = codec->spec;
4977 int idx, num;
4978 unsigned int def_conf;
4979
4980 for (num = 0; num < num_nids; num++) {
4981 for (idx = 0; idx < spec->num_pins; idx++)
4982 if (spec->pin_nids[idx] == nids[num])
4983 break;
4984 if (idx >= spec->num_pins)
4985 break;
4986 def_conf = stac_get_defcfg_connect(codec, idx);
4987 if (def_conf == AC_JACK_PORT_NONE)
4988 break;
4989 }
4990 return num;
4991}
4992
4993static int stac92hd71bxx_connected_smuxes(struct hda_codec *codec,
4994 hda_nid_t dig0pin)
4995{
4996 struct sigmatel_spec *spec = codec->spec;
4997 int idx;
4998
4999 for (idx = 0; idx < spec->num_pins; idx++)
5000 if (spec->pin_nids[idx] == dig0pin)
5001 break;
5002 if ((idx + 2) >= spec->num_pins)
5003 return 0;
5004
5005 /* dig1pin case */
5006 if (stac_get_defcfg_connect(codec, idx + 1) != AC_JACK_PORT_NONE)
5007 return 2;
5008
5009 /* dig0pin + dig2pin case */
5010 if (stac_get_defcfg_connect(codec, idx + 2) != AC_JACK_PORT_NONE)
5011 return 2;
5012 if (stac_get_defcfg_connect(codec, idx) != AC_JACK_PORT_NONE)
5013 return 1;
5014 else
5015 return 0;
5016}
5017
4871static int patch_stac92hd71bxx(struct hda_codec *codec) 5018static int patch_stac92hd71bxx(struct hda_codec *codec)
4872{ 5019{
4873 struct sigmatel_spec *spec; 5020 struct sigmatel_spec *spec;
5021 struct hda_verb *unmute_init = stac92hd71bxx_unmute_core_init;
4874 int err = 0; 5022 int err = 0;
5023 unsigned int ndmic_nids = 0;
4875 5024
4876 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5025 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4877 if (spec == NULL) 5026 if (spec == NULL)
@@ -4879,27 +5028,32 @@ static int patch_stac92hd71bxx(struct hda_codec *codec)
4879 5028
4880 codec->spec = spec; 5029 codec->spec = spec;
4881 codec->patch_ops = stac92xx_patch_ops; 5030 codec->patch_ops = stac92xx_patch_ops;
4882 spec->num_pins = ARRAY_SIZE(stac92hd71bxx_pin_nids); 5031 spec->num_pins = STAC92HD71BXX_NUM_PINS;
5032 switch (codec->vendor_id) {
5033 case 0x111d76b6:
5034 case 0x111d76b7:
5035 spec->pin_nids = stac92hd71bxx_pin_nids_4port;
5036 break;
5037 case 0x111d7603:
5038 case 0x111d7608:
5039 /* On 92HD75Bx 0x27 isn't a pin nid */
5040 spec->num_pins--;
5041 /* fallthrough */
5042 default:
5043 spec->pin_nids = stac92hd71bxx_pin_nids_6port;
5044 }
4883 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids); 5045 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
4884 spec->pin_nids = stac92hd71bxx_pin_nids;
4885 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux,
4886 sizeof(stac92hd71bxx_dmux));
4887 spec->board_config = snd_hda_check_board_config(codec, 5046 spec->board_config = snd_hda_check_board_config(codec,
4888 STAC_92HD71BXX_MODELS, 5047 STAC_92HD71BXX_MODELS,
4889 stac92hd71bxx_models, 5048 stac92hd71bxx_models,
4890 stac92hd71bxx_cfg_tbl); 5049 stac92hd71bxx_cfg_tbl);
4891again: 5050again:
4892 if (spec->board_config < 0) { 5051 if (spec->board_config < 0)
4893 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 5052 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
4894 " STAC92HD71BXX, using BIOS defaults\n"); 5053 " STAC92HD71BXX, using BIOS defaults\n");
4895 err = stac92xx_save_bios_config_regs(codec); 5054 else
4896 } else 5055 stac92xx_set_config_regs(codec,
4897 err = stac_save_pin_cfgs(codec,
4898 stac92hd71bxx_brd_tbl[spec->board_config]); 5056 stac92hd71bxx_brd_tbl[spec->board_config]);
4899 if (err < 0) {
4900 stac92xx_free(codec);
4901 return err;
4902 }
4903 5057
4904 if (spec->board_config > STAC_92HD71BXX_REF) { 5058 if (spec->board_config > STAC_92HD71BXX_REF) {
4905 /* GPIO0 = EAPD */ 5059 /* GPIO0 = EAPD */
@@ -4908,16 +5062,34 @@ again:
4908 spec->gpio_data = 0x01; 5062 spec->gpio_data = 0x01;
4909 } 5063 }
4910 5064
5065 spec->dmic_nids = stac92hd71bxx_dmic_nids;
5066 spec->dmux_nids = stac92hd71bxx_dmux_nids;
5067
4911 switch (codec->vendor_id) { 5068 switch (codec->vendor_id) {
4912 case 0x111d76b6: /* 4 Port without Analog Mixer */ 5069 case 0x111d76b6: /* 4 Port without Analog Mixer */
4913 case 0x111d76b7: 5070 case 0x111d76b7:
5071 unmute_init++;
5072 /* fallthru */
4914 case 0x111d76b4: /* 6 Port without Analog Mixer */ 5073 case 0x111d76b4: /* 6 Port without Analog Mixer */
4915 case 0x111d76b5: 5074 case 0x111d76b5:
5075 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_nomixer,
5076 sizeof(stac92hd71bxx_dmux_nomixer));
4916 spec->mixer = stac92hd71bxx_mixer; 5077 spec->mixer = stac92hd71bxx_mixer;
4917 spec->init = stac92hd71bxx_core_init; 5078 spec->init = stac92hd71bxx_core_init;
4918 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs; 5079 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5080 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5081 stac92hd71bxx_dmic_nids,
5082 STAC92HD71BXX_NUM_DMICS);
5083 if (spec->num_dmics) {
5084 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5085 spec->dinput_mux = &spec->private_dimux;
5086 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
5087 }
4919 break; 5088 break;
4920 case 0x111d7608: /* 5 Port with Analog Mixer */ 5089 case 0x111d7608: /* 5 Port with Analog Mixer */
5090 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5091 sizeof(stac92hd71bxx_dmux_amixer));
5092 spec->private_dimux.num_items--;
4921 switch (spec->board_config) { 5093 switch (spec->board_config) {
4922 case STAC_HP_M4: 5094 case STAC_HP_M4:
4923 /* Enable VREF power saving on GPIO1 detect */ 5095 /* Enable VREF power saving on GPIO1 detect */
@@ -4944,7 +5116,15 @@ again:
4944 5116
4945 /* disable VSW */ 5117 /* disable VSW */
4946 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF]; 5118 spec->init = &stac92hd71bxx_analog_core_init[HD_DISABLE_PORTF];
4947 stac_change_pin_config(codec, 0xf, 0x40f000f0); 5119 unmute_init++;
5120 snd_hda_codec_set_pincfg(codec, 0x0f, 0x40f000f0);
5121 snd_hda_codec_set_pincfg(codec, 0x19, 0x40f000f3);
5122 stac92hd71bxx_dmic_nids[STAC92HD71BXX_NUM_DMICS - 1] = 0;
5123 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5124 stac92hd71bxx_dmic_nids,
5125 STAC92HD71BXX_NUM_DMICS - 1);
5126 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5127 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 2;
4948 break; 5128 break;
4949 case 0x111d7603: /* 6 Port with Analog Mixer */ 5129 case 0x111d7603: /* 6 Port with Analog Mixer */
4950 if ((codec->revision_id & 0xf) == 1) 5130 if ((codec->revision_id & 0xf) == 1)
@@ -4954,12 +5134,23 @@ again:
4954 spec->num_pwrs = 0; 5134 spec->num_pwrs = 0;
4955 /* fallthru */ 5135 /* fallthru */
4956 default: 5136 default:
5137 memcpy(&spec->private_dimux, &stac92hd71bxx_dmux_amixer,
5138 sizeof(stac92hd71bxx_dmux_amixer));
4957 spec->dinput_mux = &spec->private_dimux; 5139 spec->dinput_mux = &spec->private_dimux;
4958 spec->mixer = stac92hd71bxx_analog_mixer; 5140 spec->mixer = stac92hd71bxx_analog_mixer;
4959 spec->init = stac92hd71bxx_analog_core_init; 5141 spec->init = stac92hd71bxx_analog_core_init;
4960 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs; 5142 codec->slave_dig_outs = stac92hd71bxx_slave_dig_outs;
5143 spec->num_dmics = stac92hd71bxx_connected_ports(codec,
5144 stac92hd71bxx_dmic_nids,
5145 STAC92HD71BXX_NUM_DMICS);
5146 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids);
5147 ndmic_nids = ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1;
4961 } 5148 }
4962 5149
5150 if (get_wcaps(codec, 0xa) & AC_WCAP_IN_AMP)
5151 snd_hda_sequence_write_cache(codec, unmute_init);
5152
5153 spec->aloopback_ctl = stac92hd71bxx_loopback;
4963 spec->aloopback_mask = 0x50; 5154 spec->aloopback_mask = 0x50;
4964 spec->aloopback_shift = 0; 5155 spec->aloopback_shift = 0;
4965 5156
@@ -4967,18 +5158,17 @@ again:
4967 spec->digbeep_nid = 0x26; 5158 spec->digbeep_nid = 0x26;
4968 spec->mux_nids = stac92hd71bxx_mux_nids; 5159 spec->mux_nids = stac92hd71bxx_mux_nids;
4969 spec->adc_nids = stac92hd71bxx_adc_nids; 5160 spec->adc_nids = stac92hd71bxx_adc_nids;
4970 spec->dmic_nids = stac92hd71bxx_dmic_nids;
4971 spec->dmux_nids = stac92hd71bxx_dmux_nids;
4972 spec->smux_nids = stac92hd71bxx_smux_nids; 5161 spec->smux_nids = stac92hd71bxx_smux_nids;
4973 spec->pwr_nids = stac92hd71bxx_pwr_nids; 5162 spec->pwr_nids = stac92hd71bxx_pwr_nids;
4974 5163
4975 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids); 5164 spec->num_muxes = ARRAY_SIZE(stac92hd71bxx_mux_nids);
4976 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids); 5165 spec->num_adcs = ARRAY_SIZE(stac92hd71bxx_adc_nids);
5166 spec->num_smuxes = stac92hd71bxx_connected_smuxes(codec, 0x1e);
4977 5167
4978 switch (spec->board_config) { 5168 switch (spec->board_config) {
4979 case STAC_HP_M4: 5169 case STAC_HP_M4:
4980 /* enable internal microphone */ 5170 /* enable internal microphone */
4981 stac_change_pin_config(codec, 0x0e, 0x01813040); 5171 snd_hda_codec_set_pincfg(codec, 0x0e, 0x01813040);
4982 stac92xx_auto_set_pinctl(codec, 0x0e, 5172 stac92xx_auto_set_pinctl(codec, 0x0e,
4983 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80); 5173 AC_PINCTL_IN_EN | AC_PINCTL_VREF_80);
4984 /* fallthru */ 5174 /* fallthru */
@@ -4993,19 +5183,36 @@ again:
4993 spec->num_smuxes = 0; 5183 spec->num_smuxes = 0;
4994 spec->num_dmuxes = 1; 5184 spec->num_dmuxes = 1;
4995 break; 5185 break;
4996 default: 5186 case STAC_HP_DV5:
4997 spec->num_dmics = STAC92HD71BXX_NUM_DMICS; 5187 snd_hda_codec_set_pincfg(codec, 0x0d, 0x90170010);
4998 spec->num_smuxes = ARRAY_SIZE(stac92hd71bxx_smux_nids); 5188 stac92xx_auto_set_pinctl(codec, 0x0d, AC_PINCTL_OUT_EN);
4999 spec->num_dmuxes = ARRAY_SIZE(stac92hd71bxx_dmux_nids); 5189 break;
5190 case STAC_HP_HDX:
5191 spec->num_dmics = 1;
5192 spec->num_dmuxes = 1;
5193 spec->num_smuxes = 1;
5194 /*
5195 * For controlling MUTE LED on HP HDX16/HDX18 notebooks,
5196 * the CONFIG_SND_HDA_POWER_SAVE is needed to be set.
5197 */
5198#ifdef CONFIG_SND_HDA_POWER_SAVE
5199 /* orange/white mute led on GPIO3, orange=0, white=1 */
5200 spec->gpio_mask |= 0x08;
5201 spec->gpio_dir |= 0x08;
5202 spec->gpio_data |= 0x08; /* set to white */
5203
5204 /* register check_power_status callback. */
5205 codec->patch_ops.check_power_status =
5206 stac92xx_hp_hdx_check_power_status;
5207#endif
5208 break;
5000 }; 5209 };
5001 5210
5002 spec->multiout.dac_nids = spec->dac_nids; 5211 spec->multiout.dac_nids = spec->dac_nids;
5003 if (spec->dinput_mux) 5212 if (spec->dinput_mux)
5004 spec->private_dimux.num_items += 5213 spec->private_dimux.num_items += spec->num_dmics - ndmic_nids;
5005 spec->num_dmics -
5006 (ARRAY_SIZE(stac92hd71bxx_dmic_nids) - 1);
5007 5214
5008 err = stac92xx_parse_auto_config(codec, 0x21, 0x23); 5215 err = stac92xx_parse_auto_config(codec, 0x21, 0);
5009 if (!err) { 5216 if (!err) {
5010 if (spec->board_config < 0) { 5217 if (spec->board_config < 0) {
5011 printk(KERN_WARNING "hda_codec: No auto-config is " 5218 printk(KERN_WARNING "hda_codec: No auto-config is "
@@ -5080,17 +5287,12 @@ static int patch_stac922x(struct hda_codec *codec)
5080 } 5287 }
5081 5288
5082 again: 5289 again:
5083 if (spec->board_config < 0) { 5290 if (spec->board_config < 0)
5084 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, " 5291 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
5085 "using BIOS defaults\n"); 5292 "using BIOS defaults\n");
5086 err = stac92xx_save_bios_config_regs(codec); 5293 else
5087 } else 5294 stac92xx_set_config_regs(codec,
5088 err = stac_save_pin_cfgs(codec,
5089 stac922x_brd_tbl[spec->board_config]); 5295 stac922x_brd_tbl[spec->board_config]);
5090 if (err < 0) {
5091 stac92xx_free(codec);
5092 return err;
5093 }
5094 5296
5095 spec->adc_nids = stac922x_adc_nids; 5297 spec->adc_nids = stac922x_adc_nids;
5096 spec->mux_nids = stac922x_mux_nids; 5298 spec->mux_nids = stac922x_mux_nids;
@@ -5141,24 +5343,19 @@ static int patch_stac927x(struct hda_codec *codec)
5141 return -ENOMEM; 5343 return -ENOMEM;
5142 5344
5143 codec->spec = spec; 5345 codec->spec = spec;
5346 codec->slave_dig_outs = stac927x_slave_dig_outs;
5144 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids); 5347 spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
5145 spec->pin_nids = stac927x_pin_nids; 5348 spec->pin_nids = stac927x_pin_nids;
5146 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS, 5349 spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
5147 stac927x_models, 5350 stac927x_models,
5148 stac927x_cfg_tbl); 5351 stac927x_cfg_tbl);
5149 again: 5352 again:
5150 if (spec->board_config < 0 || !stac927x_brd_tbl[spec->board_config]) { 5353 if (spec->board_config < 0)
5151 if (spec->board_config < 0) 5354 snd_printdd(KERN_INFO "hda_codec: Unknown model for"
5152 snd_printdd(KERN_INFO "hda_codec: Unknown model for" 5355 "STAC927x, using BIOS defaults\n");
5153 "STAC927x, using BIOS defaults\n"); 5356 else
5154 err = stac92xx_save_bios_config_regs(codec); 5357 stac92xx_set_config_regs(codec,
5155 } else
5156 err = stac_save_pin_cfgs(codec,
5157 stac927x_brd_tbl[spec->board_config]); 5358 stac927x_brd_tbl[spec->board_config]);
5158 if (err < 0) {
5159 stac92xx_free(codec);
5160 return err;
5161 }
5162 5359
5163 spec->digbeep_nid = 0x23; 5360 spec->digbeep_nid = 0x23;
5164 spec->adc_nids = stac927x_adc_nids; 5361 spec->adc_nids = stac927x_adc_nids;
@@ -5187,15 +5384,15 @@ static int patch_stac927x(struct hda_codec *codec)
5187 case 0x10280209: 5384 case 0x10280209:
5188 case 0x1028022e: 5385 case 0x1028022e:
5189 /* correct the device field to SPDIF out */ 5386 /* correct the device field to SPDIF out */
5190 stac_change_pin_config(codec, 0x21, 0x01442070); 5387 snd_hda_codec_set_pincfg(codec, 0x21, 0x01442070);
5191 break; 5388 break;
5192 }; 5389 };
5193 /* configure the analog microphone on some laptops */ 5390 /* configure the analog microphone on some laptops */
5194 stac_change_pin_config(codec, 0x0c, 0x90a79130); 5391 snd_hda_codec_set_pincfg(codec, 0x0c, 0x90a79130);
5195 /* correct the front output jack as a hp out */ 5392 /* correct the front output jack as a hp out */
5196 stac_change_pin_config(codec, 0x0f, 0x0227011f); 5393 snd_hda_codec_set_pincfg(codec, 0x0f, 0x0227011f);
5197 /* correct the front input jack as a mic */ 5394 /* correct the front input jack as a mic */
5198 stac_change_pin_config(codec, 0x0e, 0x02a79130); 5395 snd_hda_codec_set_pincfg(codec, 0x0e, 0x02a79130);
5199 /* fallthru */ 5396 /* fallthru */
5200 case STAC_DELL_3ST: 5397 case STAC_DELL_3ST:
5201 /* GPIO2 High = Enable EAPD */ 5398 /* GPIO2 High = Enable EAPD */
@@ -5222,6 +5419,7 @@ static int patch_stac927x(struct hda_codec *codec)
5222 } 5419 }
5223 5420
5224 spec->num_pwrs = 0; 5421 spec->num_pwrs = 0;
5422 spec->aloopback_ctl = stac927x_loopback;
5225 spec->aloopback_mask = 0x40; 5423 spec->aloopback_mask = 0x40;
5226 spec->aloopback_shift = 0; 5424 spec->aloopback_shift = 0;
5227 spec->eapd_switch = 1; 5425 spec->eapd_switch = 1;
@@ -5280,16 +5478,11 @@ static int patch_stac9205(struct hda_codec *codec)
5280 stac9205_models, 5478 stac9205_models,
5281 stac9205_cfg_tbl); 5479 stac9205_cfg_tbl);
5282 again: 5480 again:
5283 if (spec->board_config < 0) { 5481 if (spec->board_config < 0)
5284 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n"); 5482 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
5285 err = stac92xx_save_bios_config_regs(codec); 5483 else
5286 } else 5484 stac92xx_set_config_regs(codec,
5287 err = stac_save_pin_cfgs(codec,
5288 stac9205_brd_tbl[spec->board_config]); 5485 stac9205_brd_tbl[spec->board_config]);
5289 if (err < 0) {
5290 stac92xx_free(codec);
5291 return err;
5292 }
5293 5486
5294 spec->digbeep_nid = 0x23; 5487 spec->digbeep_nid = 0x23;
5295 spec->adc_nids = stac9205_adc_nids; 5488 spec->adc_nids = stac9205_adc_nids;
@@ -5306,17 +5499,20 @@ static int patch_stac9205(struct hda_codec *codec)
5306 5499
5307 spec->init = stac9205_core_init; 5500 spec->init = stac9205_core_init;
5308 spec->mixer = stac9205_mixer; 5501 spec->mixer = stac9205_mixer;
5502 spec->aloopback_ctl = stac9205_loopback;
5309 5503
5310 spec->aloopback_mask = 0x40; 5504 spec->aloopback_mask = 0x40;
5311 spec->aloopback_shift = 0; 5505 spec->aloopback_shift = 0;
5312 spec->eapd_switch = 1; 5506 /* Turn on/off EAPD per HP plugging */
5507 if (spec->board_config != STAC_9205_EAPD)
5508 spec->eapd_switch = 1;
5313 spec->multiout.dac_nids = spec->dac_nids; 5509 spec->multiout.dac_nids = spec->dac_nids;
5314 5510
5315 switch (spec->board_config){ 5511 switch (spec->board_config){
5316 case STAC_9205_DELL_M43: 5512 case STAC_9205_DELL_M43:
5317 /* Enable SPDIF in/out */ 5513 /* Enable SPDIF in/out */
5318 stac_change_pin_config(codec, 0x1f, 0x01441030); 5514 snd_hda_codec_set_pincfg(codec, 0x1f, 0x01441030);
5319 stac_change_pin_config(codec, 0x20, 0x1c410030); 5515 snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
5320 5516
5321 /* Enable unsol response for GPIO4/Dock HP connection */ 5517 /* Enable unsol response for GPIO4/Dock HP connection */
5322 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01); 5518 err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
@@ -5373,223 +5569,87 @@ static int patch_stac9205(struct hda_codec *codec)
5373 * STAC9872 hack 5569 * STAC9872 hack
5374 */ 5570 */
5375 5571
5376/* static config for Sony VAIO FE550G and Sony VAIO AR */ 5572static struct hda_verb stac9872_core_init[] = {
5377static hda_nid_t vaio_dacs[] = { 0x2 };
5378#define VAIO_HP_DAC 0x5
5379static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
5380static hda_nid_t vaio_mux_nids[] = { 0x15 };
5381
5382static struct hda_input_mux vaio_mux = {
5383 .num_items = 3,
5384 .items = {
5385 /* { "HP", 0x0 }, */
5386 { "Mic Jack", 0x1 },
5387 { "Internal Mic", 0x2 },
5388 { "PCM", 0x3 },
5389 }
5390};
5391
5392static struct hda_verb vaio_init[] = {
5393 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
5394 {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
5395 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5396 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5397 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5398 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
5399 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */ 5573 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
5400 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5401 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5402 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5403 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5404 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */ 5574 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5405 {} 5575 {}
5406}; 5576};
5407 5577
5408static struct hda_verb vaio_ar_init[] = { 5578static struct snd_kcontrol_new stac9872_mixer[] = {
5409 {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
5410 {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
5411 {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
5412 {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
5413/* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
5414 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
5415 {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
5416 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
5417 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
5418/* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
5419 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
5420 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
5421 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
5422 {}
5423};
5424
5425static struct snd_kcontrol_new vaio_mixer[] = {
5426 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT),
5427 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT),
5428 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5429 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
5430 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5431 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT), 5579 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5432 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT), 5580 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5433 { 5581 { } /* end */
5434 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5435 .name = "Capture Source",
5436 .count = 1,
5437 .info = stac92xx_mux_enum_info,
5438 .get = stac92xx_mux_enum_get,
5439 .put = stac92xx_mux_enum_put,
5440 },
5441 {}
5442}; 5582};
5443 5583
5444static struct snd_kcontrol_new vaio_ar_mixer[] = { 5584static hda_nid_t stac9872_pin_nids[] = {
5445 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x02, 0, HDA_OUTPUT), 5585 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
5446 HDA_CODEC_MUTE("Headphone Playback Switch", 0x02, 0, HDA_OUTPUT), 5586 0x11, 0x13, 0x14,
5447 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x05, 0, HDA_OUTPUT),
5448 HDA_CODEC_MUTE("Speaker Playback Switch", 0x05, 0, HDA_OUTPUT),
5449 /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
5450 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
5451 HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
5452 /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
5453 HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
5454 {
5455 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
5456 .name = "Capture Source",
5457 .count = 1,
5458 .info = stac92xx_mux_enum_info,
5459 .get = stac92xx_mux_enum_get,
5460 .put = stac92xx_mux_enum_put,
5461 },
5462 {}
5463}; 5587};
5464 5588
5465static struct hda_codec_ops stac9872_patch_ops = { 5589static hda_nid_t stac9872_adc_nids[] = {
5466 .build_controls = stac92xx_build_controls, 5590 0x8 /*,0x6*/
5467 .build_pcms = stac92xx_build_pcms,
5468 .init = stac92xx_init,
5469 .free = stac92xx_free,
5470#ifdef SND_HDA_NEEDS_RESUME
5471 .resume = stac92xx_resume,
5472#endif
5473}; 5591};
5474 5592
5475static int stac9872_vaio_init(struct hda_codec *codec) 5593static hda_nid_t stac9872_mux_nids[] = {
5476{ 5594 0x15
5477 int err;
5478
5479 err = stac92xx_init(codec);
5480 if (err < 0)
5481 return err;
5482 if (codec->patch_ops.unsol_event)
5483 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
5484 return 0;
5485}
5486
5487static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
5488{
5489 if (get_pin_presence(codec, 0x0a)) {
5490 stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5491 stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5492 } else {
5493 stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
5494 stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
5495 }
5496}
5497
5498static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
5499{
5500 switch (res >> 26) {
5501 case STAC_HP_EVENT:
5502 stac9872_vaio_hp_detect(codec, res);
5503 break;
5504 }
5505}
5506
5507static struct hda_codec_ops stac9872_vaio_patch_ops = {
5508 .build_controls = stac92xx_build_controls,
5509 .build_pcms = stac92xx_build_pcms,
5510 .init = stac9872_vaio_init,
5511 .free = stac92xx_free,
5512 .unsol_event = stac9872_vaio_unsol_event,
5513#ifdef CONFIG_PM
5514 .resume = stac92xx_resume,
5515#endif
5516}; 5595};
5517 5596
5518enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */ 5597static unsigned int stac9872_vaio_pin_configs[9] = {
5519 CXD9872RD_VAIO, 5598 0x03211020, 0x411111f0, 0x411111f0, 0x03a15030,
5520 /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */ 5599 0x411111f0, 0x90170110, 0x411111f0, 0x411111f0,
5521 STAC9872AK_VAIO, 5600 0x90a7013e
5522 /* Unknown. id=0x83847661 and subsys=0x104D1200. */
5523 STAC9872K_VAIO,
5524 /* AR Series. id=0x83847664 and subsys=104D1300 */
5525 CXD9872AKD_VAIO,
5526 STAC_9872_MODELS,
5527}; 5601};
5528 5602
5529static const char *stac9872_models[STAC_9872_MODELS] = { 5603static const char *stac9872_models[STAC_9872_MODELS] = {
5530 [CXD9872RD_VAIO] = "vaio", 5604 [STAC_9872_AUTO] = "auto",
5531 [CXD9872AKD_VAIO] = "vaio-ar", 5605 [STAC_9872_VAIO] = "vaio",
5606};
5607
5608static unsigned int *stac9872_brd_tbl[STAC_9872_MODELS] = {
5609 [STAC_9872_VAIO] = stac9872_vaio_pin_configs,
5532}; 5610};
5533 5611
5534static struct snd_pci_quirk stac9872_cfg_tbl[] = { 5612static struct snd_pci_quirk stac9872_cfg_tbl[] = {
5535 SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO), 5613 {} /* terminator */
5536 SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
5537 SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
5538 SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
5539 {}
5540}; 5614};
5541 5615
5542static int patch_stac9872(struct hda_codec *codec) 5616static int patch_stac9872(struct hda_codec *codec)
5543{ 5617{
5544 struct sigmatel_spec *spec; 5618 struct sigmatel_spec *spec;
5545 int board_config; 5619 int err;
5546 5620
5547 board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5548 stac9872_models,
5549 stac9872_cfg_tbl);
5550 if (board_config < 0)
5551 /* unknown config, let generic-parser do its job... */
5552 return snd_hda_parse_generic_codec(codec);
5553
5554 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5621 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5555 if (spec == NULL) 5622 if (spec == NULL)
5556 return -ENOMEM; 5623 return -ENOMEM;
5557
5558 codec->spec = spec; 5624 codec->spec = spec;
5559 switch (board_config) {
5560 case CXD9872RD_VAIO:
5561 case STAC9872AK_VAIO:
5562 case STAC9872K_VAIO:
5563 spec->mixer = vaio_mixer;
5564 spec->init = vaio_init;
5565 spec->multiout.max_channels = 2;
5566 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5567 spec->multiout.dac_nids = vaio_dacs;
5568 spec->multiout.hp_nid = VAIO_HP_DAC;
5569 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
5570 spec->adc_nids = vaio_adcs;
5571 spec->num_pwrs = 0;
5572 spec->input_mux = &vaio_mux;
5573 spec->mux_nids = vaio_mux_nids;
5574 codec->patch_ops = stac9872_vaio_patch_ops;
5575 break;
5576
5577 case CXD9872AKD_VAIO:
5578 spec->mixer = vaio_ar_mixer;
5579 spec->init = vaio_ar_init;
5580 spec->multiout.max_channels = 2;
5581 spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
5582 spec->multiout.dac_nids = vaio_dacs;
5583 spec->multiout.hp_nid = VAIO_HP_DAC;
5584 spec->num_adcs = ARRAY_SIZE(vaio_adcs);
5585 spec->num_pwrs = 0;
5586 spec->adc_nids = vaio_adcs;
5587 spec->input_mux = &vaio_mux;
5588 spec->mux_nids = vaio_mux_nids;
5589 codec->patch_ops = stac9872_patch_ops;
5590 break;
5591 }
5592 5625
5626 spec->board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
5627 stac9872_models,
5628 stac9872_cfg_tbl);
5629 if (spec->board_config < 0)
5630 snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9872, "
5631 "using BIOS defaults\n");
5632 else
5633 stac92xx_set_config_regs(codec,
5634 stac9872_brd_tbl[spec->board_config]);
5635
5636 spec->num_pins = ARRAY_SIZE(stac9872_pin_nids);
5637 spec->pin_nids = stac9872_pin_nids;
5638 spec->multiout.dac_nids = spec->dac_nids;
5639 spec->num_adcs = ARRAY_SIZE(stac9872_adc_nids);
5640 spec->adc_nids = stac9872_adc_nids;
5641 spec->num_muxes = ARRAY_SIZE(stac9872_mux_nids);
5642 spec->mux_nids = stac9872_mux_nids;
5643 spec->mixer = stac9872_mixer;
5644 spec->init = stac9872_core_init;
5645
5646 err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
5647 if (err < 0) {
5648 stac92xx_free(codec);
5649 return -EINVAL;
5650 }
5651 spec->input_mux = &spec->private_imux;
5652 codec->patch_ops = stac92xx_patch_ops;
5593 return 0; 5653 return 0;
5594} 5654}
5595 5655
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index c761394cbe84..b25a5cc637d6 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -1308,16 +1308,13 @@ static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
1308 unsigned int def_conf; 1308 unsigned int def_conf;
1309 unsigned char seqassoc; 1309 unsigned char seqassoc;
1310 1310
1311 def_conf = snd_hda_codec_read(codec, nid, 0, 1311 def_conf = snd_hda_codec_get_pincfg(codec, nid);
1312 AC_VERB_GET_CONFIG_DEFAULT, 0);
1313 seqassoc = (unsigned char) get_defcfg_association(def_conf); 1312 seqassoc = (unsigned char) get_defcfg_association(def_conf);
1314 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf); 1313 seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
1315 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) { 1314 if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
1316 if (seqassoc == 0xff) { 1315 if (seqassoc == 0xff) {
1317 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30)); 1316 def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
1318 snd_hda_codec_write(codec, nid, 0, 1317 snd_hda_codec_set_pincfg(codec, nid, def_conf);
1319 AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
1320 def_conf >> 24);
1321 } 1318 }
1322 } 1319 }
1323 1320
@@ -1354,7 +1351,7 @@ static int vt1708_parse_auto_config(struct hda_codec *codec)
1354 1351
1355 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 1352 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1356 1353
1357 if (spec->autocfg.dig_out_pin) 1354 if (spec->autocfg.dig_outs)
1358 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID; 1355 spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
1359 if (spec->autocfg.dig_in_pin) 1356 if (spec->autocfg.dig_in_pin)
1360 spec->dig_in_nid = VT1708_DIGIN_NID; 1357 spec->dig_in_nid = VT1708_DIGIN_NID;
@@ -1827,7 +1824,7 @@ static int vt1709_parse_auto_config(struct hda_codec *codec)
1827 1824
1828 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 1825 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
1829 1826
1830 if (spec->autocfg.dig_out_pin) 1827 if (spec->autocfg.dig_outs)
1831 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID; 1828 spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
1832 if (spec->autocfg.dig_in_pin) 1829 if (spec->autocfg.dig_in_pin)
1833 spec->dig_in_nid = VT1709_DIGIN_NID; 1830 spec->dig_in_nid = VT1709_DIGIN_NID;
@@ -2371,7 +2368,7 @@ static int vt1708B_parse_auto_config(struct hda_codec *codec)
2371 2368
2372 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 2369 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2373 2370
2374 if (spec->autocfg.dig_out_pin) 2371 if (spec->autocfg.dig_outs)
2375 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID; 2372 spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
2376 if (spec->autocfg.dig_in_pin) 2373 if (spec->autocfg.dig_in_pin)
2377 spec->dig_in_nid = VT1708B_DIGIN_NID; 2374 spec->dig_in_nid = VT1708B_DIGIN_NID;
@@ -2836,7 +2833,7 @@ static int vt1708S_parse_auto_config(struct hda_codec *codec)
2836 2833
2837 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 2834 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
2838 2835
2839 if (spec->autocfg.dig_out_pin) 2836 if (spec->autocfg.dig_outs)
2840 spec->multiout.dig_out_nid = VT1708S_DIGOUT_NID; 2837 spec->multiout.dig_out_nid = VT1708S_DIGOUT_NID;
2841 2838
2842 spec->extra_dig_out_nid = 0x15; 2839 spec->extra_dig_out_nid = 0x15;
@@ -3155,7 +3152,7 @@ static int vt1702_parse_auto_config(struct hda_codec *codec)
3155 3152
3156 spec->multiout.max_channels = spec->multiout.num_dacs * 2; 3153 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3157 3154
3158 if (spec->autocfg.dig_out_pin) 3155 if (spec->autocfg.dig_outs)
3159 spec->multiout.dig_out_nid = VT1702_DIGOUT_NID; 3156 spec->multiout.dig_out_nid = VT1702_DIGOUT_NID;
3160 3157
3161 spec->extra_dig_out_nid = 0x1B; 3158 spec->extra_dig_out_nid = 0x1B;
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index 58d7cda03de5..3dd63f1cda53 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -458,7 +458,7 @@ static irqreturn_t snd_ice1712_interrupt(int irq, void *dev_id)
458 u16 pbkstatus; 458 u16 pbkstatus;
459 struct snd_pcm_substream *substream; 459 struct snd_pcm_substream *substream;
460 pbkstatus = inw(ICEDS(ice, INTSTAT)); 460 pbkstatus = inw(ICEDS(ice, INTSTAT));
461 /* printk("pbkstatus = 0x%x\n", pbkstatus); */ 461 /* printk(KERN_DEBUG "pbkstatus = 0x%x\n", pbkstatus); */
462 for (idx = 0; idx < 6; idx++) { 462 for (idx = 0; idx < 6; idx++) {
463 if ((pbkstatus & (3 << (idx * 2))) == 0) 463 if ((pbkstatus & (3 << (idx * 2))) == 0)
464 continue; 464 continue;
@@ -2648,9 +2648,9 @@ static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2648 return -ENOENT; 2648 return -ENOENT;
2649 } 2649 }
2650 2650
2651 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 2651 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2652 if (card == NULL) 2652 if (err < 0)
2653 return -ENOMEM; 2653 return err;
2654 2654
2655 strcpy(card->driver, "ICE1712"); 2655 strcpy(card->driver, "ICE1712");
2656 strcpy(card->shortname, "ICEnsemble ICE1712"); 2656 strcpy(card->shortname, "ICEnsemble ICE1712");
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index bb8d8c766b9d..128510e77a78 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -241,6 +241,8 @@ get_rawmidi_substream(struct snd_ice1712 *ice, unsigned int stream)
241 struct snd_rawmidi_substream, list); 241 struct snd_rawmidi_substream, list);
242} 242}
243 243
244static void enable_midi_irq(struct snd_ice1712 *ice, u8 flag, int enable);
245
244static void vt1724_midi_write(struct snd_ice1712 *ice) 246static void vt1724_midi_write(struct snd_ice1712 *ice)
245{ 247{
246 struct snd_rawmidi_substream *s; 248 struct snd_rawmidi_substream *s;
@@ -254,6 +256,11 @@ static void vt1724_midi_write(struct snd_ice1712 *ice)
254 for (i = 0; i < count; ++i) 256 for (i = 0; i < count; ++i)
255 outb(buffer[i], ICEREG1724(ice, MPU_DATA)); 257 outb(buffer[i], ICEREG1724(ice, MPU_DATA));
256 } 258 }
259 /* mask irq when all bytes have been transmitted.
260 * enabled again in output_trigger when the new data comes in.
261 */
262 enable_midi_irq(ice, VT1724_IRQ_MPU_TX,
263 !snd_rawmidi_transmit_empty(s));
257} 264}
258 265
259static void vt1724_midi_read(struct snd_ice1712 *ice) 266static void vt1724_midi_read(struct snd_ice1712 *ice)
@@ -272,31 +279,34 @@ static void vt1724_midi_read(struct snd_ice1712 *ice)
272 } 279 }
273} 280}
274 281
275static void vt1724_enable_midi_irq(struct snd_rawmidi_substream *substream, 282/* call with ice->reg_lock */
276 u8 flag, int enable) 283static void enable_midi_irq(struct snd_ice1712 *ice, u8 flag, int enable)
277{ 284{
278 struct snd_ice1712 *ice = substream->rmidi->private_data; 285 u8 mask = inb(ICEREG1724(ice, IRQMASK));
279 u8 mask;
280
281 spin_lock_irq(&ice->reg_lock);
282 mask = inb(ICEREG1724(ice, IRQMASK));
283 if (enable) 286 if (enable)
284 mask &= ~flag; 287 mask &= ~flag;
285 else 288 else
286 mask |= flag; 289 mask |= flag;
287 outb(mask, ICEREG1724(ice, IRQMASK)); 290 outb(mask, ICEREG1724(ice, IRQMASK));
291}
292
293static void vt1724_enable_midi_irq(struct snd_rawmidi_substream *substream,
294 u8 flag, int enable)
295{
296 struct snd_ice1712 *ice = substream->rmidi->private_data;
297
298 spin_lock_irq(&ice->reg_lock);
299 enable_midi_irq(ice, flag, enable);
288 spin_unlock_irq(&ice->reg_lock); 300 spin_unlock_irq(&ice->reg_lock);
289} 301}
290 302
291static int vt1724_midi_output_open(struct snd_rawmidi_substream *s) 303static int vt1724_midi_output_open(struct snd_rawmidi_substream *s)
292{ 304{
293 vt1724_enable_midi_irq(s, VT1724_IRQ_MPU_TX, 1);
294 return 0; 305 return 0;
295} 306}
296 307
297static int vt1724_midi_output_close(struct snd_rawmidi_substream *s) 308static int vt1724_midi_output_close(struct snd_rawmidi_substream *s)
298{ 309{
299 vt1724_enable_midi_irq(s, VT1724_IRQ_MPU_TX, 0);
300 return 0; 310 return 0;
301} 311}
302 312
@@ -311,6 +321,7 @@ static void vt1724_midi_output_trigger(struct snd_rawmidi_substream *s, int up)
311 vt1724_midi_write(ice); 321 vt1724_midi_write(ice);
312 } else { 322 } else {
313 ice->midi_output = 0; 323 ice->midi_output = 0;
324 enable_midi_irq(ice, VT1724_IRQ_MPU_TX, 0);
314 } 325 }
315 spin_unlock_irqrestore(&ice->reg_lock, flags); 326 spin_unlock_irqrestore(&ice->reg_lock, flags);
316} 327}
@@ -320,6 +331,7 @@ static void vt1724_midi_output_drain(struct snd_rawmidi_substream *s)
320 struct snd_ice1712 *ice = s->rmidi->private_data; 331 struct snd_ice1712 *ice = s->rmidi->private_data;
321 unsigned long timeout; 332 unsigned long timeout;
322 333
334 vt1724_enable_midi_irq(s, VT1724_IRQ_MPU_TX, 0);
323 /* 32 bytes should be transmitted in less than about 12 ms */ 335 /* 32 bytes should be transmitted in less than about 12 ms */
324 timeout = jiffies + msecs_to_jiffies(15); 336 timeout = jiffies + msecs_to_jiffies(15);
325 do { 337 do {
@@ -389,24 +401,24 @@ static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
389 status &= status_mask; 401 status &= status_mask;
390 if (status == 0) 402 if (status == 0)
391 break; 403 break;
404 spin_lock(&ice->reg_lock);
392 if (++timeout > 10) { 405 if (++timeout > 10) {
393 status = inb(ICEREG1724(ice, IRQSTAT)); 406 status = inb(ICEREG1724(ice, IRQSTAT));
394 printk(KERN_ERR "ice1724: Too long irq loop, " 407 printk(KERN_ERR "ice1724: Too long irq loop, "
395 "status = 0x%x\n", status); 408 "status = 0x%x\n", status);
396 if (status & VT1724_IRQ_MPU_TX) { 409 if (status & VT1724_IRQ_MPU_TX) {
397 printk(KERN_ERR "ice1724: Disabling MPU_TX\n"); 410 printk(KERN_ERR "ice1724: Disabling MPU_TX\n");
398 outb(inb(ICEREG1724(ice, IRQMASK)) | 411 enable_midi_irq(ice, VT1724_IRQ_MPU_TX, 0);
399 VT1724_IRQ_MPU_TX,
400 ICEREG1724(ice, IRQMASK));
401 } 412 }
413 spin_unlock(&ice->reg_lock);
402 break; 414 break;
403 } 415 }
404 handled = 1; 416 handled = 1;
405 if (status & VT1724_IRQ_MPU_TX) { 417 if (status & VT1724_IRQ_MPU_TX) {
406 spin_lock(&ice->reg_lock);
407 if (ice->midi_output) 418 if (ice->midi_output)
408 vt1724_midi_write(ice); 419 vt1724_midi_write(ice);
409 spin_unlock(&ice->reg_lock); 420 else
421 enable_midi_irq(ice, VT1724_IRQ_MPU_TX, 0);
410 /* Due to mysterical reasons, MPU_TX is always 422 /* Due to mysterical reasons, MPU_TX is always
411 * generated (and can't be cleared) when a PCM 423 * generated (and can't be cleared) when a PCM
412 * playback is going. So let's ignore at the 424 * playback is going. So let's ignore at the
@@ -415,15 +427,14 @@ static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
415 status_mask &= ~VT1724_IRQ_MPU_TX; 427 status_mask &= ~VT1724_IRQ_MPU_TX;
416 } 428 }
417 if (status & VT1724_IRQ_MPU_RX) { 429 if (status & VT1724_IRQ_MPU_RX) {
418 spin_lock(&ice->reg_lock);
419 if (ice->midi_input) 430 if (ice->midi_input)
420 vt1724_midi_read(ice); 431 vt1724_midi_read(ice);
421 else 432 else
422 vt1724_midi_clear_rx(ice); 433 vt1724_midi_clear_rx(ice);
423 spin_unlock(&ice->reg_lock);
424 } 434 }
425 /* ack MPU irq */ 435 /* ack MPU irq */
426 outb(status, ICEREG1724(ice, IRQSTAT)); 436 outb(status, ICEREG1724(ice, IRQSTAT));
437 spin_unlock(&ice->reg_lock);
427 if (status & VT1724_IRQ_MTPCM) { 438 if (status & VT1724_IRQ_MTPCM) {
428 /* 439 /*
429 * Multi-track PCM 440 * Multi-track PCM
@@ -745,7 +756,14 @@ static int snd_vt1724_playback_pro_prepare(struct snd_pcm_substream *substream)
745 756
746 spin_unlock_irq(&ice->reg_lock); 757 spin_unlock_irq(&ice->reg_lock);
747 758
748 /* printk("pro prepare: ch = %d, addr = 0x%x, buffer = 0x%x, period = 0x%x\n", substream->runtime->channels, (unsigned int)substream->runtime->dma_addr, snd_pcm_lib_buffer_bytes(substream), snd_pcm_lib_period_bytes(substream)); */ 759 /*
760 printk(KERN_DEBUG "pro prepare: ch = %d, addr = 0x%x, "
761 "buffer = 0x%x, period = 0x%x\n",
762 substream->runtime->channels,
763 (unsigned int)substream->runtime->dma_addr,
764 snd_pcm_lib_buffer_bytes(substream),
765 snd_pcm_lib_period_bytes(substream));
766 */
749 return 0; 767 return 0;
750} 768}
751 769
@@ -2122,7 +2140,9 @@ unsigned char snd_vt1724_read_i2c(struct snd_ice1712 *ice,
2122 wait_i2c_busy(ice); 2140 wait_i2c_busy(ice);
2123 val = inb(ICEREG1724(ice, I2C_DATA)); 2141 val = inb(ICEREG1724(ice, I2C_DATA));
2124 mutex_unlock(&ice->i2c_mutex); 2142 mutex_unlock(&ice->i2c_mutex);
2125 /* printk("i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val); */ 2143 /*
2144 printk(KERN_DEBUG "i2c_read: [0x%x,0x%x] = 0x%x\n", dev, addr, val);
2145 */
2126 return val; 2146 return val;
2127} 2147}
2128 2148
@@ -2131,7 +2151,9 @@ void snd_vt1724_write_i2c(struct snd_ice1712 *ice,
2131{ 2151{
2132 mutex_lock(&ice->i2c_mutex); 2152 mutex_lock(&ice->i2c_mutex);
2133 wait_i2c_busy(ice); 2153 wait_i2c_busy(ice);
2134 /* printk("i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data); */ 2154 /*
2155 printk(KERN_DEBUG "i2c_write: [0x%x,0x%x] = 0x%x\n", dev, addr, data);
2156 */
2135 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR)); 2157 outb(addr, ICEREG1724(ice, I2C_BYTE_ADDR));
2136 outb(data, ICEREG1724(ice, I2C_DATA)); 2158 outb(data, ICEREG1724(ice, I2C_DATA));
2137 outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR)); 2159 outb(dev | VT1724_I2C_WRITE, ICEREG1724(ice, I2C_DEV_ADDR));
@@ -2456,9 +2478,9 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2456 return -ENOENT; 2478 return -ENOENT;
2457 } 2479 }
2458 2480
2459 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 2481 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2460 if (card == NULL) 2482 if (err < 0)
2461 return -ENOMEM; 2483 return err;
2462 2484
2463 strcpy(card->driver, "ICE1724"); 2485 strcpy(card->driver, "ICE1724");
2464 strcpy(card->shortname, "ICEnsemble ICE1724"); 2486 strcpy(card->shortname, "ICEnsemble ICE1724");
diff --git a/sound/pci/ice1712/juli.c b/sound/pci/ice1712/juli.c
index c51659b9caf6..fd948bfd9aef 100644
--- a/sound/pci/ice1712/juli.c
+++ b/sound/pci/ice1712/juli.c
@@ -345,8 +345,9 @@ static int juli_mute_put(struct snd_kcontrol *kcontrol,
345 new_gpio = old_gpio & 345 new_gpio = old_gpio &
346 ~((unsigned int) kcontrol->private_value); 346 ~((unsigned int) kcontrol->private_value);
347 } 347 }
348 /* printk("JULI - mute/unmute: control_value: 0x%x, old_gpio: 0x%x, \ 348 /* printk(KERN_DEBUG
349 new_gpio 0x%x\n", 349 "JULI - mute/unmute: control_value: 0x%x, old_gpio: 0x%x, "
350 "new_gpio 0x%x\n",
350 (unsigned int)ucontrol->value.integer.value[0], old_gpio, 351 (unsigned int)ucontrol->value.integer.value[0], old_gpio,
351 new_gpio); */ 352 new_gpio); */
352 if (old_gpio != new_gpio) { 353 if (old_gpio != new_gpio) {
diff --git a/sound/pci/ice1712/prodigy192.c b/sound/pci/ice1712/prodigy192.c
index 48d3679292a7..2a8e5cd8f2d8 100644
--- a/sound/pci/ice1712/prodigy192.c
+++ b/sound/pci/ice1712/prodigy192.c
@@ -133,8 +133,10 @@ static int stac9460_dac_mute_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
133 idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME; 133 idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + STAC946X_LF_VOLUME;
134 /* due to possible conflicts with stac9460_set_rate_val, mutexing */ 134 /* due to possible conflicts with stac9460_set_rate_val, mutexing */
135 mutex_lock(&spec->mute_mutex); 135 mutex_lock(&spec->mute_mutex);
136 /*printk("Mute put: reg 0x%02x, ctrl value: 0x%02x\n", idx, 136 /*
137 ucontrol->value.integer.value[0]);*/ 137 printk(KERN_DEBUG "Mute put: reg 0x%02x, ctrl value: 0x%02x\n", idx,
138 ucontrol->value.integer.value[0]);
139 */
138 change = stac9460_dac_mute(ice, idx, ucontrol->value.integer.value[0]); 140 change = stac9460_dac_mute(ice, idx, ucontrol->value.integer.value[0]);
139 mutex_unlock(&spec->mute_mutex); 141 mutex_unlock(&spec->mute_mutex);
140 return change; 142 return change;
@@ -185,7 +187,10 @@ static int stac9460_dac_vol_put(struct snd_kcontrol *kcontrol, struct snd_ctl_el
185 change = (ovol != nvol); 187 change = (ovol != nvol);
186 if (change) { 188 if (change) {
187 ovol = (0x7f - nvol) | (tmp & 0x80); 189 ovol = (0x7f - nvol) | (tmp & 0x80);
188 /*printk("DAC Volume: reg 0x%02x: 0x%02x\n", idx, ovol);*/ 190 /*
191 printk(KERN_DEBUG "DAC Volume: reg 0x%02x: 0x%02x\n",
192 idx, ovol);
193 */
189 stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80)); 194 stac9460_put(ice, idx, (0x7f - nvol) | (tmp & 0x80));
190 } 195 }
191 return change; 196 return change;
@@ -344,7 +349,7 @@ static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)
344 for (idx = 0; idx < 7 ; ++idx) 349 for (idx = 0; idx < 7 ; ++idx)
345 changed[idx] = stac9460_dac_mute(ice, 350 changed[idx] = stac9460_dac_mute(ice,
346 STAC946X_MASTER_VOLUME + idx, 0); 351 STAC946X_MASTER_VOLUME + idx, 0);
347 /*printk("Rate change: %d, new MC: 0x%02x\n", rate, new);*/ 352 /*printk(KERN_DEBUG "Rate change: %d, new MC: 0x%02x\n", rate, new);*/
348 stac9460_put(ice, STAC946X_MASTER_CLOCKING, new); 353 stac9460_put(ice, STAC946X_MASTER_CLOCKING, new);
349 udelay(10); 354 udelay(10);
350 /* unmuting - only originally unmuted dacs - 355 /* unmuting - only originally unmuted dacs -
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index e900cdc84849..57648810eaf1 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -689,7 +689,7 @@ static void snd_intel8x0_setup_periods(struct intel8x0 *chip, struct ichdev *ich
689 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */ 689 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
690 ichdev->fragsize >> ichdev->pos_shift); 690 ichdev->fragsize >> ichdev->pos_shift);
691#if 0 691#if 0
692 printk("bdbar[%i] = 0x%x [0x%x]\n", 692 printk(KERN_DEBUG "bdbar[%i] = 0x%x [0x%x]\n",
693 idx + 0, bdbar[idx + 0], bdbar[idx + 1]); 693 idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
694#endif 694#endif
695 } 695 }
@@ -701,8 +701,10 @@ static void snd_intel8x0_setup_periods(struct intel8x0 *chip, struct ichdev *ich
701 ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags; 701 ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags;
702 ichdev->position = 0; 702 ichdev->position = 0;
703#if 0 703#if 0
704 printk("lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n", 704 printk(KERN_DEBUG "lvi_frag = %i, frags = %i, period_size = 0x%x, "
705 ichdev->lvi_frag, ichdev->frags, ichdev->fragsize, ichdev->fragsize1); 705 "period_size1 = 0x%x\n",
706 ichdev->lvi_frag, ichdev->frags, ichdev->fragsize,
707 ichdev->fragsize1);
706#endif 708#endif
707 /* clear interrupts */ 709 /* clear interrupts */
708 iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI); 710 iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
@@ -768,7 +770,8 @@ static inline void snd_intel8x0_update(struct intel8x0 *chip, struct ichdev *ich
768 ichdev->lvi_frag %= ichdev->frags; 770 ichdev->lvi_frag %= ichdev->frags;
769 ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1); 771 ichdev->bdbar[ichdev->lvi * 2] = cpu_to_le32(ichdev->physbuf + ichdev->lvi_frag * ichdev->fragsize1);
770#if 0 772#if 0
771 printk("new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n", 773 printk(KERN_DEBUG "new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, "
774 "all = 0x%x, 0x%x\n",
772 ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2], 775 ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2],
773 ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port), 776 ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port),
774 inl(port + 4), inb(port + ICH_REG_OFF_CR)); 777 inl(port + 4), inb(port + ICH_REG_OFF_CR));
@@ -2287,23 +2290,23 @@ static void do_ali_reset(struct intel8x0 *chip)
2287 iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000); 2290 iputdword(chip, ICHREG(ALI_INTERRUPTSR), 0x00000000);
2288} 2291}
2289 2292
2290static int snd_intel8x0_ich_chip_init(struct intel8x0 *chip, int probing) 2293#ifdef CONFIG_SND_AC97_POWER_SAVE
2291{ 2294static struct snd_pci_quirk ich_chip_reset_mode[] = {
2292 unsigned long end_time; 2295 SND_PCI_QUIRK(0x1014, 0x051f, "Thinkpad R32", 1),
2293 unsigned int cnt, status, nstatus; 2296 { } /* end */
2294 2297};
2295 /* put logic to right state */
2296 /* first clear status bits */
2297 status = ICH_RCS | ICH_MCINT | ICH_POINT | ICH_PIINT;
2298 if (chip->device_type == DEVICE_NFORCE)
2299 status |= ICH_NVSPINT;
2300 cnt = igetdword(chip, ICHREG(GLOB_STA));
2301 iputdword(chip, ICHREG(GLOB_STA), cnt & status);
2302 2298
2299static int snd_intel8x0_ich_chip_cold_reset(struct intel8x0 *chip)
2300{
2301 unsigned int cnt;
2303 /* ACLink on, 2 channels */ 2302 /* ACLink on, 2 channels */
2303
2304 if (snd_pci_quirk_lookup(chip->pci, ich_chip_reset_mode))
2305 return -EIO;
2306
2304 cnt = igetdword(chip, ICHREG(GLOB_CNT)); 2307 cnt = igetdword(chip, ICHREG(GLOB_CNT));
2305 cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK); 2308 cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
2306#ifdef CONFIG_SND_AC97_POWER_SAVE 2309
2307 /* do cold reset - the full ac97 powerdown may leave the controller 2310 /* do cold reset - the full ac97 powerdown may leave the controller
2308 * in a warm state but actually it cannot communicate with the codec. 2311 * in a warm state but actually it cannot communicate with the codec.
2309 */ 2312 */
@@ -2312,22 +2315,58 @@ static int snd_intel8x0_ich_chip_init(struct intel8x0 *chip, int probing)
2312 udelay(10); 2315 udelay(10);
2313 iputdword(chip, ICHREG(GLOB_CNT), cnt | ICH_AC97COLD); 2316 iputdword(chip, ICHREG(GLOB_CNT), cnt | ICH_AC97COLD);
2314 msleep(1); 2317 msleep(1);
2318 return 0;
2319}
2320#define snd_intel8x0_ich_chip_can_cold_reset(chip) \
2321 (!snd_pci_quirk_lookup(chip->pci, ich_chip_reset_mode))
2315#else 2322#else
2323#define snd_intel8x0_ich_chip_cold_reset(chip) 0
2324#define snd_intel8x0_ich_chip_can_cold_reset(chip) (0)
2325#endif
2326
2327static int snd_intel8x0_ich_chip_reset(struct intel8x0 *chip)
2328{
2329 unsigned long end_time;
2330 unsigned int cnt;
2331 /* ACLink on, 2 channels */
2332 cnt = igetdword(chip, ICHREG(GLOB_CNT));
2333 cnt &= ~(ICH_ACLINK | ICH_PCM_246_MASK);
2316 /* finish cold or do warm reset */ 2334 /* finish cold or do warm reset */
2317 cnt |= (cnt & ICH_AC97COLD) == 0 ? ICH_AC97COLD : ICH_AC97WARM; 2335 cnt |= (cnt & ICH_AC97COLD) == 0 ? ICH_AC97COLD : ICH_AC97WARM;
2318 iputdword(chip, ICHREG(GLOB_CNT), cnt); 2336 iputdword(chip, ICHREG(GLOB_CNT), cnt);
2319 end_time = (jiffies + (HZ / 4)) + 1; 2337 end_time = (jiffies + (HZ / 4)) + 1;
2320 do { 2338 do {
2321 if ((igetdword(chip, ICHREG(GLOB_CNT)) & ICH_AC97WARM) == 0) 2339 if ((igetdword(chip, ICHREG(GLOB_CNT)) & ICH_AC97WARM) == 0)
2322 goto __ok; 2340 return 0;
2323 schedule_timeout_uninterruptible(1); 2341 schedule_timeout_uninterruptible(1);
2324 } while (time_after_eq(end_time, jiffies)); 2342 } while (time_after_eq(end_time, jiffies));
2325 snd_printk(KERN_ERR "AC'97 warm reset still in progress? [0x%x]\n", 2343 snd_printk(KERN_ERR "AC'97 warm reset still in progress? [0x%x]\n",
2326 igetdword(chip, ICHREG(GLOB_CNT))); 2344 igetdword(chip, ICHREG(GLOB_CNT)));
2327 return -EIO; 2345 return -EIO;
2346}
2347
2348static int snd_intel8x0_ich_chip_init(struct intel8x0 *chip, int probing)
2349{
2350 unsigned long end_time;
2351 unsigned int status, nstatus;
2352 unsigned int cnt;
2353 int err;
2354
2355 /* put logic to right state */
2356 /* first clear status bits */
2357 status = ICH_RCS | ICH_MCINT | ICH_POINT | ICH_PIINT;
2358 if (chip->device_type == DEVICE_NFORCE)
2359 status |= ICH_NVSPINT;
2360 cnt = igetdword(chip, ICHREG(GLOB_STA));
2361 iputdword(chip, ICHREG(GLOB_STA), cnt & status);
2362
2363 if (snd_intel8x0_ich_chip_can_cold_reset(chip))
2364 err = snd_intel8x0_ich_chip_cold_reset(chip);
2365 else
2366 err = snd_intel8x0_ich_chip_reset(chip);
2367 if (err < 0)
2368 return err;
2328 2369
2329 __ok:
2330#endif
2331 if (probing) { 2370 if (probing) {
2332 /* wait for any codec ready status. 2371 /* wait for any codec ready status.
2333 * Once it becomes ready it should remain ready 2372 * Once it becomes ready it should remain ready
@@ -3058,9 +3097,9 @@ static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
3058 int err; 3097 int err;
3059 struct shortname_table *name; 3098 struct shortname_table *name;
3060 3099
3061 card = snd_card_new(index, id, THIS_MODULE, 0); 3100 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
3062 if (card == NULL) 3101 if (err < 0)
3063 return -ENOMEM; 3102 return err;
3064 3103
3065 if (spdif_aclink < 0) 3104 if (spdif_aclink < 0)
3066 spdif_aclink = check_default_spdif_aclink(pci); 3105 spdif_aclink = check_default_spdif_aclink(pci);
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
index 93449e464566..6ec0fc50d6be 100644
--- a/sound/pci/intel8x0m.c
+++ b/sound/pci/intel8x0m.c
@@ -411,7 +411,10 @@ static void snd_intel8x0_setup_periods(struct intel8x0m *chip, struct ichdev *ic
411 bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf + (((idx >> 1) * ichdev->fragsize) % ichdev->size)); 411 bdbar[idx + 0] = cpu_to_le32(ichdev->physbuf + (((idx >> 1) * ichdev->fragsize) % ichdev->size));
412 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */ 412 bdbar[idx + 1] = cpu_to_le32(0x80000000 | /* interrupt on completion */
413 ichdev->fragsize >> chip->pcm_pos_shift); 413 ichdev->fragsize >> chip->pcm_pos_shift);
414 // printk("bdbar[%i] = 0x%x [0x%x]\n", idx + 0, bdbar[idx + 0], bdbar[idx + 1]); 414 /*
415 printk(KERN_DEBUG "bdbar[%i] = 0x%x [0x%x]\n",
416 idx + 0, bdbar[idx + 0], bdbar[idx + 1]);
417 */
415 } 418 }
416 ichdev->frags = ichdev->size / ichdev->fragsize; 419 ichdev->frags = ichdev->size / ichdev->fragsize;
417 } 420 }
@@ -421,8 +424,10 @@ static void snd_intel8x0_setup_periods(struct intel8x0m *chip, struct ichdev *ic
421 ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags; 424 ichdev->lvi_frag = ICH_REG_LVI_MASK % ichdev->frags;
422 ichdev->position = 0; 425 ichdev->position = 0;
423#if 0 426#if 0
424 printk("lvi_frag = %i, frags = %i, period_size = 0x%x, period_size1 = 0x%x\n", 427 printk(KERN_DEBUG "lvi_frag = %i, frags = %i, period_size = 0x%x, "
425 ichdev->lvi_frag, ichdev->frags, ichdev->fragsize, ichdev->fragsize1); 428 "period_size1 = 0x%x\n",
429 ichdev->lvi_frag, ichdev->frags, ichdev->fragsize,
430 ichdev->fragsize1);
426#endif 431#endif
427 /* clear interrupts */ 432 /* clear interrupts */
428 iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI); 433 iputbyte(chip, port + ichdev->roff_sr, ICH_FIFOE | ICH_BCIS | ICH_LVBCI);
@@ -465,7 +470,8 @@ static inline void snd_intel8x0_update(struct intel8x0m *chip, struct ichdev *ic
465 ichdev->lvi_frag * 470 ichdev->lvi_frag *
466 ichdev->fragsize1); 471 ichdev->fragsize1);
467#if 0 472#if 0
468 printk("new: bdbar[%i] = 0x%x [0x%x], prefetch = %i, all = 0x%x, 0x%x\n", 473 printk(KERN_DEBUG "new: bdbar[%i] = 0x%x [0x%x], "
474 "prefetch = %i, all = 0x%x, 0x%x\n",
469 ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2], 475 ichdev->lvi * 2, ichdev->bdbar[ichdev->lvi * 2],
470 ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port), 476 ichdev->bdbar[ichdev->lvi * 2 + 1], inb(ICH_REG_OFF_PIV + port),
471 inl(port + 4), inb(port + ICH_REG_OFF_CR)); 477 inl(port + 4), inb(port + ICH_REG_OFF_CR));
@@ -1269,9 +1275,9 @@ static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
1269 int err; 1275 int err;
1270 struct shortname_table *name; 1276 struct shortname_table *name;
1271 1277
1272 card = snd_card_new(index, id, THIS_MODULE, 0); 1278 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
1273 if (card == NULL) 1279 if (err < 0)
1274 return -ENOMEM; 1280 return err;
1275 1281
1276 strcpy(card->driver, "ICH-MODEM"); 1282 strcpy(card->driver, "ICH-MODEM");
1277 strcpy(card->shortname, "Intel ICH"); 1283 strcpy(card->shortname, "Intel ICH");
diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
index 5f8006b42750..8b79969034be 100644
--- a/sound/pci/korg1212/korg1212.c
+++ b/sound/pci/korg1212/korg1212.c
@@ -2443,9 +2443,9 @@ snd_korg1212_probe(struct pci_dev *pci,
2443 dev++; 2443 dev++;
2444 return -ENOENT; 2444 return -ENOENT;
2445 } 2445 }
2446 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 2446 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2447 if (card == NULL) 2447 if (err < 0)
2448 return -ENOMEM; 2448 return err;
2449 2449
2450 if ((err = snd_korg1212_create(card, pci, &korg1212)) < 0) { 2450 if ((err = snd_korg1212_create(card, pci, &korg1212)) < 0) {
2451 snd_card_free(card); 2451 snd_card_free(card);
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index 59bbaf8f3e5b..70141548f251 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -2691,9 +2691,9 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2691 return -ENOENT; 2691 return -ENOENT;
2692 } 2692 }
2693 2693
2694 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 2694 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2695 if (card == NULL) 2695 if (err < 0)
2696 return -ENOMEM; 2696 return err;
2697 2697
2698 switch (pci->device) { 2698 switch (pci->device) {
2699 case PCI_DEVICE_ID_ESS_ALLEGRO: 2699 case PCI_DEVICE_ID_ESS_ALLEGRO:
diff --git a/sound/pci/mixart/mixart.c b/sound/pci/mixart/mixart.c
index bb162507fe6c..c1eb84a14c42 100644
--- a/sound/pci/mixart/mixart.c
+++ b/sound/pci/mixart/mixart.c
@@ -1366,12 +1366,12 @@ static int __devinit snd_mixart_probe(struct pci_dev *pci,
1366 else 1366 else
1367 idx = index[dev] + i; 1367 idx = index[dev] + i;
1368 snprintf(tmpid, sizeof(tmpid), "%s-%d", id[dev] ? id[dev] : "MIXART", i); 1368 snprintf(tmpid, sizeof(tmpid), "%s-%d", id[dev] ? id[dev] : "MIXART", i);
1369 card = snd_card_new(idx, tmpid, THIS_MODULE, 0); 1369 err = snd_card_create(idx, tmpid, THIS_MODULE, 0, &card);
1370 1370
1371 if (! card) { 1371 if (err < 0) {
1372 snd_printk(KERN_ERR "cannot allocate the card %d\n", i); 1372 snd_printk(KERN_ERR "cannot allocate the card %d\n", i);
1373 snd_mixart_free(mgr); 1373 snd_mixart_free(mgr);
1374 return -ENOMEM; 1374 return err;
1375 } 1375 }
1376 1376
1377 strcpy(card->driver, CARD_NAME); 1377 strcpy(card->driver, CARD_NAME);
diff --git a/sound/pci/mixart/mixart_hwdep.c b/sound/pci/mixart/mixart_hwdep.c
index 3782b52bc0e8..4cf4cd8c939c 100644
--- a/sound/pci/mixart/mixart_hwdep.c
+++ b/sound/pci/mixart/mixart_hwdep.c
@@ -345,8 +345,8 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
345 status_daught = readl_be( MIXART_MEM( mgr,MIXART_PSEUDOREG_DXLX_STATUS_OFFSET )); 345 status_daught = readl_be( MIXART_MEM( mgr,MIXART_PSEUDOREG_DXLX_STATUS_OFFSET ));
346 346
347 /* motherboard xilinx status 5 will say that the board is performing a reset */ 347 /* motherboard xilinx status 5 will say that the board is performing a reset */
348 if( status_xilinx == 5 ) { 348 if (status_xilinx == 5) {
349 snd_printk( KERN_ERR "miXart is resetting !\n"); 349 snd_printk(KERN_ERR "miXart is resetting !\n");
350 return -EAGAIN; /* try again later */ 350 return -EAGAIN; /* try again later */
351 } 351 }
352 352
@@ -354,13 +354,14 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
354 case MIXART_MOTHERBOARD_XLX_INDEX: 354 case MIXART_MOTHERBOARD_XLX_INDEX:
355 355
356 /* xilinx already loaded ? */ 356 /* xilinx already loaded ? */
357 if( status_xilinx == 4 ) { 357 if (status_xilinx == 4) {
358 snd_printk( KERN_DEBUG "xilinx is already loaded !\n"); 358 snd_printk(KERN_DEBUG "xilinx is already loaded !\n");
359 return 0; 359 return 0;
360 } 360 }
361 /* the status should be 0 == "idle" */ 361 /* the status should be 0 == "idle" */
362 if( status_xilinx != 0 ) { 362 if (status_xilinx != 0) {
363 snd_printk( KERN_ERR "xilinx load error ! status = %d\n", status_xilinx); 363 snd_printk(KERN_ERR "xilinx load error ! status = %d\n",
364 status_xilinx);
364 return -EIO; /* modprob -r may help ? */ 365 return -EIO; /* modprob -r may help ? */
365 } 366 }
366 367
@@ -389,21 +390,23 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
389 390
390 case MIXART_MOTHERBOARD_ELF_INDEX: 391 case MIXART_MOTHERBOARD_ELF_INDEX:
391 392
392 if( status_elf == 4 ) { 393 if (status_elf == 4) {
393 snd_printk( KERN_DEBUG "elf file already loaded !\n"); 394 snd_printk(KERN_DEBUG "elf file already loaded !\n");
394 return 0; 395 return 0;
395 } 396 }
396 397
397 /* the status should be 0 == "idle" */ 398 /* the status should be 0 == "idle" */
398 if( status_elf != 0 ) { 399 if (status_elf != 0) {
399 snd_printk( KERN_ERR "elf load error ! status = %d\n", status_elf); 400 snd_printk(KERN_ERR "elf load error ! status = %d\n",
401 status_elf);
400 return -EIO; /* modprob -r may help ? */ 402 return -EIO; /* modprob -r may help ? */
401 } 403 }
402 404
403 /* wait for xilinx status == 4 */ 405 /* wait for xilinx status == 4 */
404 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET, 1, 4, 500); /* 5sec */ 406 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_MXLX_STATUS_OFFSET, 1, 4, 500); /* 5sec */
405 if (err < 0) { 407 if (err < 0) {
406 snd_printk( KERN_ERR "xilinx was not loaded or could not be started\n"); 408 snd_printk(KERN_ERR "xilinx was not loaded or "
409 "could not be started\n");
407 return err; 410 return err;
408 } 411 }
409 412
@@ -424,7 +427,7 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
424 /* wait for elf status == 4 */ 427 /* wait for elf status == 4 */
425 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET, 1, 4, 300); /* 3sec */ 428 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_ELF_STATUS_OFFSET, 1, 4, 300); /* 3sec */
426 if (err < 0) { 429 if (err < 0) {
427 snd_printk( KERN_ERR "elf could not be started\n"); 430 snd_printk(KERN_ERR "elf could not be started\n");
428 return err; 431 return err;
429 } 432 }
430 433
@@ -437,15 +440,16 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
437 default: 440 default:
438 441
439 /* elf and xilinx should be loaded */ 442 /* elf and xilinx should be loaded */
440 if( (status_elf != 4) || (status_xilinx != 4) ) { 443 if (status_elf != 4 || status_xilinx != 4) {
441 printk( KERN_ERR "xilinx or elf not successfully loaded\n"); 444 printk(KERN_ERR "xilinx or elf not "
445 "successfully loaded\n");
442 return -EIO; /* modprob -r may help ? */ 446 return -EIO; /* modprob -r may help ? */
443 } 447 }
444 448
445 /* wait for daughter detection != 0 */ 449 /* wait for daughter detection != 0 */
446 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DBRD_PRESENCE_OFFSET, 0, 0, 30); /* 300msec */ 450 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DBRD_PRESENCE_OFFSET, 0, 0, 30); /* 300msec */
447 if (err < 0) { 451 if (err < 0) {
448 snd_printk( KERN_ERR "error starting elf file\n"); 452 snd_printk(KERN_ERR "error starting elf file\n");
449 return err; 453 return err;
450 } 454 }
451 455
@@ -460,8 +464,9 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
460 return -EINVAL; 464 return -EINVAL;
461 465
462 /* daughter should be idle */ 466 /* daughter should be idle */
463 if( status_daught != 0 ) { 467 if (status_daught != 0) {
464 printk( KERN_ERR "daughter load error ! status = %d\n", status_daught); 468 printk(KERN_ERR "daughter load error ! status = %d\n",
469 status_daught);
465 return -EIO; /* modprob -r may help ? */ 470 return -EIO; /* modprob -r may help ? */
466 } 471 }
467 472
@@ -480,7 +485,7 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
480 /* wait for status == 2 */ 485 /* wait for status == 2 */
481 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 2, 30); /* 300msec */ 486 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 2, 30); /* 300msec */
482 if (err < 0) { 487 if (err < 0) {
483 snd_printk( KERN_ERR "daughter board load error\n"); 488 snd_printk(KERN_ERR "daughter board load error\n");
484 return err; 489 return err;
485 } 490 }
486 491
@@ -502,7 +507,8 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
502 /* wait for daughter status == 3 */ 507 /* wait for daughter status == 3 */
503 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 3, 300); /* 3sec */ 508 err = mixart_wait_nice_for_register_value( mgr, MIXART_PSEUDOREG_DXLX_STATUS_OFFSET, 1, 3, 300); /* 3sec */
504 if (err < 0) { 509 if (err < 0) {
505 snd_printk( KERN_ERR "daughter board could not be initialised\n"); 510 snd_printk(KERN_ERR
511 "daughter board could not be initialised\n");
506 return err; 512 return err;
507 } 513 }
508 514
@@ -512,7 +518,7 @@ static int mixart_dsp_load(struct mixart_mgr* mgr, int index, const struct firmw
512 /* first communication with embedded */ 518 /* first communication with embedded */
513 err = mixart_first_init(mgr); 519 err = mixart_first_init(mgr);
514 if (err < 0) { 520 if (err < 0) {
515 snd_printk( KERN_ERR "miXart could not be set up\n"); 521 snd_printk(KERN_ERR "miXart could not be set up\n");
516 return err; 522 return err;
517 } 523 }
518 524
@@ -581,16 +587,6 @@ MODULE_FIRMWARE("mixart/miXart8AES.xlx");
581/* miXart hwdep interface id string */ 587/* miXart hwdep interface id string */
582#define SND_MIXART_HWDEP_ID "miXart Loader" 588#define SND_MIXART_HWDEP_ID "miXart Loader"
583 589
584static int mixart_hwdep_open(struct snd_hwdep *hw, struct file *file)
585{
586 return 0;
587}
588
589static int mixart_hwdep_release(struct snd_hwdep *hw, struct file *file)
590{
591 return 0;
592}
593
594static int mixart_hwdep_dsp_status(struct snd_hwdep *hw, 590static int mixart_hwdep_dsp_status(struct snd_hwdep *hw,
595 struct snd_hwdep_dsp_status *info) 591 struct snd_hwdep_dsp_status *info)
596{ 592{
@@ -643,8 +639,6 @@ int snd_mixart_setup_firmware(struct mixart_mgr *mgr)
643 639
644 hw->iface = SNDRV_HWDEP_IFACE_MIXART; 640 hw->iface = SNDRV_HWDEP_IFACE_MIXART;
645 hw->private_data = mgr; 641 hw->private_data = mgr;
646 hw->ops.open = mixart_hwdep_open;
647 hw->ops.release = mixart_hwdep_release;
648 hw->ops.dsp_status = mixart_hwdep_dsp_status; 642 hw->ops.dsp_status = mixart_hwdep_dsp_status;
649 hw->ops.dsp_load = mixart_hwdep_dsp_load; 643 hw->ops.dsp_load = mixart_hwdep_dsp_load;
650 hw->exclusive = 1; 644 hw->exclusive = 1;
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index 50c9f8a05082..522a040855d4 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -1668,9 +1668,9 @@ static int __devinit snd_nm256_probe(struct pci_dev *pci,
1668 } 1668 }
1669 } 1669 }
1670 1670
1671 card = snd_card_new(index, id, THIS_MODULE, 0); 1671 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
1672 if (card == NULL) 1672 if (err < 0)
1673 return -ENOMEM; 1673 return err;
1674 1674
1675 switch (pci->device) { 1675 switch (pci->device) {
1676 case PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO: 1676 case PCI_DEVICE_ID_NEOMAGIC_NM256AV_AUDIO:
diff --git a/sound/pci/oxygen/hifier.c b/sound/pci/oxygen/hifier.c
index 1ab833f843eb..84ef13183419 100644
--- a/sound/pci/oxygen/hifier.c
+++ b/sound/pci/oxygen/hifier.c
@@ -45,6 +45,7 @@ MODULE_PARM_DESC(enable, "enable card");
45static struct pci_device_id hifier_ids[] __devinitdata = { 45static struct pci_device_id hifier_ids[] __devinitdata = {
46 { OXYGEN_PCI_SUBID(0x14c3, 0x1710) }, 46 { OXYGEN_PCI_SUBID(0x14c3, 0x1710) },
47 { OXYGEN_PCI_SUBID(0x14c3, 0x1711) }, 47 { OXYGEN_PCI_SUBID(0x14c3, 0x1711) },
48 { OXYGEN_PCI_SUBID_BROKEN_EEPROM },
48 { } 49 { }
49}; 50};
50MODULE_DEVICE_TABLE(pci, hifier_ids); 51MODULE_DEVICE_TABLE(pci, hifier_ids);
@@ -151,7 +152,6 @@ static const struct oxygen_model model_hifier = {
151 .shortname = "C-Media CMI8787", 152 .shortname = "C-Media CMI8787",
152 .longname = "C-Media Oxygen HD Audio", 153 .longname = "C-Media Oxygen HD Audio",
153 .chip = "CMI8788", 154 .chip = "CMI8788",
154 .owner = THIS_MODULE,
155 .init = hifier_init, 155 .init = hifier_init,
156 .control_filter = hifier_control_filter, 156 .control_filter = hifier_control_filter,
157 .cleanup = hifier_cleanup, 157 .cleanup = hifier_cleanup,
@@ -173,6 +173,13 @@ static const struct oxygen_model model_hifier = {
173 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 173 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
174}; 174};
175 175
176static int __devinit get_hifier_model(struct oxygen *chip,
177 const struct pci_device_id *id)
178{
179 chip->model = model_hifier;
180 return 0;
181}
182
176static int __devinit hifier_probe(struct pci_dev *pci, 183static int __devinit hifier_probe(struct pci_dev *pci,
177 const struct pci_device_id *pci_id) 184 const struct pci_device_id *pci_id)
178{ 185{
@@ -185,7 +192,8 @@ static int __devinit hifier_probe(struct pci_dev *pci,
185 ++dev; 192 ++dev;
186 return -ENOENT; 193 return -ENOENT;
187 } 194 }
188 err = oxygen_pci_probe(pci, index[dev], id[dev], &model_hifier, 0); 195 err = oxygen_pci_probe(pci, index[dev], id[dev], THIS_MODULE,
196 hifier_ids, get_hifier_model);
189 if (err >= 0) 197 if (err >= 0)
190 ++dev; 198 ++dev;
191 return err; 199 return err;
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c
index de999c6d6dd3..72db4c39007f 100644
--- a/sound/pci/oxygen/oxygen.c
+++ b/sound/pci/oxygen/oxygen.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * C-Media CMI8788 driver for C-Media's reference design and for the X-Meridian 2 * C-Media CMI8788 driver for C-Media's reference design and similar models
3 * 3 *
4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de> 4 * Copyright (c) Clemens Ladisch <clemens@ladisch.de>
5 * 5 *
@@ -26,6 +26,7 @@
26 * 26 *
27 * GPIO 0 -> DFS0 of AK5385 27 * GPIO 0 -> DFS0 of AK5385
28 * GPIO 1 -> DFS1 of AK5385 28 * GPIO 1 -> DFS1 of AK5385
29 * GPIO 8 -> enable headphone amplifier on HT-Omega models
29 */ 30 */
30 31
31#include <linux/delay.h> 32#include <linux/delay.h>
@@ -61,7 +62,8 @@ MODULE_PARM_DESC(enable, "enable card");
61enum { 62enum {
62 MODEL_CMEDIA_REF, /* C-Media's reference design */ 63 MODEL_CMEDIA_REF, /* C-Media's reference design */
63 MODEL_MERIDIAN, /* AuzenTech X-Meridian */ 64 MODEL_MERIDIAN, /* AuzenTech X-Meridian */
64 MODEL_HALO, /* HT-Omega Claro halo */ 65 MODEL_CLARO, /* HT-Omega Claro */
66 MODEL_CLARO_HALO, /* HT-Omega Claro halo */
65}; 67};
66 68
67static struct pci_device_id oxygen_ids[] __devinitdata = { 69static struct pci_device_id oxygen_ids[] __devinitdata = {
@@ -74,8 +76,8 @@ static struct pci_device_id oxygen_ids[] __devinitdata = {
74 { OXYGEN_PCI_SUBID(0x147a, 0xa017), .driver_data = MODEL_CMEDIA_REF }, 76 { OXYGEN_PCI_SUBID(0x147a, 0xa017), .driver_data = MODEL_CMEDIA_REF },
75 { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF }, 77 { OXYGEN_PCI_SUBID(0x1a58, 0x0910), .driver_data = MODEL_CMEDIA_REF },
76 { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = MODEL_MERIDIAN }, 78 { OXYGEN_PCI_SUBID(0x415a, 0x5431), .driver_data = MODEL_MERIDIAN },
77 { OXYGEN_PCI_SUBID(0x7284, 0x9761), .driver_data = MODEL_CMEDIA_REF }, 79 { OXYGEN_PCI_SUBID(0x7284, 0x9761), .driver_data = MODEL_CLARO },
78 { OXYGEN_PCI_SUBID(0x7284, 0x9781), .driver_data = MODEL_HALO }, 80 { OXYGEN_PCI_SUBID(0x7284, 0x9781), .driver_data = MODEL_CLARO_HALO },
79 { } 81 { }
80}; 82};
81MODULE_DEVICE_TABLE(pci, oxygen_ids); 83MODULE_DEVICE_TABLE(pci, oxygen_ids);
@@ -86,6 +88,8 @@ MODULE_DEVICE_TABLE(pci, oxygen_ids);
86#define GPIO_AK5385_DFS_DOUBLE 0x0001 88#define GPIO_AK5385_DFS_DOUBLE 0x0001
87#define GPIO_AK5385_DFS_QUAD 0x0002 89#define GPIO_AK5385_DFS_QUAD 0x0002
88 90
91#define GPIO_CLARO_HP 0x0100
92
89struct generic_data { 93struct generic_data {
90 u8 ak4396_ctl2; 94 u8 ak4396_ctl2;
91 u16 saved_wm8785_registers[2]; 95 u16 saved_wm8785_registers[2];
@@ -196,10 +200,46 @@ static void meridian_init(struct oxygen *chip)
196 ak5385_init(chip); 200 ak5385_init(chip);
197} 201}
198 202
203static void claro_enable_hp(struct oxygen *chip)
204{
205 msleep(300);
206 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CLARO_HP);
207 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_HP);
208}
209
210static void claro_init(struct oxygen *chip)
211{
212 ak4396_init(chip);
213 wm8785_init(chip);
214 claro_enable_hp(chip);
215}
216
217static void claro_halo_init(struct oxygen *chip)
218{
219 ak4396_init(chip);
220 ak5385_init(chip);
221 claro_enable_hp(chip);
222}
223
199static void generic_cleanup(struct oxygen *chip) 224static void generic_cleanup(struct oxygen *chip)
200{ 225{
201} 226}
202 227
228static void claro_disable_hp(struct oxygen *chip)
229{
230 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_CLARO_HP);
231}
232
233static void claro_cleanup(struct oxygen *chip)
234{
235 claro_disable_hp(chip);
236}
237
238static void claro_suspend(struct oxygen *chip)
239{
240 claro_disable_hp(chip);
241}
242
203static void generic_resume(struct oxygen *chip) 243static void generic_resume(struct oxygen *chip)
204{ 244{
205 ak4396_registers_init(chip); 245 ak4396_registers_init(chip);
@@ -211,6 +251,12 @@ static void meridian_resume(struct oxygen *chip)
211 ak4396_registers_init(chip); 251 ak4396_registers_init(chip);
212} 252}
213 253
254static void claro_resume(struct oxygen *chip)
255{
256 ak4396_registers_init(chip);
257 claro_enable_hp(chip);
258}
259
214static void set_ak4396_params(struct oxygen *chip, 260static void set_ak4396_params(struct oxygen *chip,
215 struct snd_pcm_hw_params *params) 261 struct snd_pcm_hw_params *params)
216{ 262{
@@ -293,30 +339,10 @@ static void set_ak5385_params(struct oxygen *chip,
293 339
294static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); 340static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
295 341
296static int generic_probe(struct oxygen *chip, unsigned long driver_data)
297{
298 if (driver_data == MODEL_MERIDIAN) {
299 chip->model.init = meridian_init;
300 chip->model.resume = meridian_resume;
301 chip->model.set_adc_params = set_ak5385_params;
302 chip->model.device_config = PLAYBACK_0_TO_I2S |
303 PLAYBACK_1_TO_SPDIF |
304 CAPTURE_0_FROM_I2S_2 |
305 CAPTURE_1_FROM_SPDIF;
306 }
307 if (driver_data == MODEL_MERIDIAN || driver_data == MODEL_HALO) {
308 chip->model.misc_flags = OXYGEN_MISC_MIDI;
309 chip->model.device_config |= MIDI_OUTPUT | MIDI_INPUT;
310 }
311 return 0;
312}
313
314static const struct oxygen_model model_generic = { 342static const struct oxygen_model model_generic = {
315 .shortname = "C-Media CMI8788", 343 .shortname = "C-Media CMI8788",
316 .longname = "C-Media Oxygen HD Audio", 344 .longname = "C-Media Oxygen HD Audio",
317 .chip = "CMI8788", 345 .chip = "CMI8788",
318 .owner = THIS_MODULE,
319 .probe = generic_probe,
320 .init = generic_init, 346 .init = generic_init,
321 .cleanup = generic_cleanup, 347 .cleanup = generic_cleanup,
322 .resume = generic_resume, 348 .resume = generic_resume,
@@ -341,6 +367,42 @@ static const struct oxygen_model model_generic = {
341 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 367 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
342}; 368};
343 369
370static int __devinit get_oxygen_model(struct oxygen *chip,
371 const struct pci_device_id *id)
372{
373 chip->model = model_generic;
374 switch (id->driver_data) {
375 case MODEL_MERIDIAN:
376 chip->model.init = meridian_init;
377 chip->model.resume = meridian_resume;
378 chip->model.set_adc_params = set_ak5385_params;
379 chip->model.device_config = PLAYBACK_0_TO_I2S |
380 PLAYBACK_1_TO_SPDIF |
381 CAPTURE_0_FROM_I2S_2 |
382 CAPTURE_1_FROM_SPDIF;
383 break;
384 case MODEL_CLARO:
385 chip->model.init = claro_init;
386 chip->model.cleanup = claro_cleanup;
387 chip->model.suspend = claro_suspend;
388 chip->model.resume = claro_resume;
389 break;
390 case MODEL_CLARO_HALO:
391 chip->model.init = claro_halo_init;
392 chip->model.cleanup = claro_cleanup;
393 chip->model.suspend = claro_suspend;
394 chip->model.resume = claro_resume;
395 chip->model.set_adc_params = set_ak5385_params;
396 break;
397 }
398 if (id->driver_data == MODEL_MERIDIAN ||
399 id->driver_data == MODEL_CLARO_HALO) {
400 chip->model.misc_flags = OXYGEN_MISC_MIDI;
401 chip->model.device_config |= MIDI_OUTPUT | MIDI_INPUT;
402 }
403 return 0;
404}
405
344static int __devinit generic_oxygen_probe(struct pci_dev *pci, 406static int __devinit generic_oxygen_probe(struct pci_dev *pci,
345 const struct pci_device_id *pci_id) 407 const struct pci_device_id *pci_id)
346{ 408{
@@ -353,8 +415,8 @@ static int __devinit generic_oxygen_probe(struct pci_dev *pci,
353 ++dev; 415 ++dev;
354 return -ENOENT; 416 return -ENOENT;
355 } 417 }
356 err = oxygen_pci_probe(pci, index[dev], id[dev], 418 err = oxygen_pci_probe(pci, index[dev], id[dev], THIS_MODULE,
357 &model_generic, pci_id->driver_data); 419 oxygen_ids, get_oxygen_model);
358 if (err >= 0) 420 if (err >= 0)
359 ++dev; 421 ++dev;
360 return err; 422 return err;
diff --git a/sound/pci/oxygen/oxygen.h b/sound/pci/oxygen/oxygen.h
index 19107c6307e5..bd615dbffadb 100644
--- a/sound/pci/oxygen/oxygen.h
+++ b/sound/pci/oxygen/oxygen.h
@@ -18,6 +18,8 @@
18 18
19#define OXYGEN_IO_SIZE 0x100 19#define OXYGEN_IO_SIZE 0x100
20 20
21#define OXYGEN_EEPROM_ID 0x434d /* "CM" */
22
21/* model-specific configuration of outputs/inputs */ 23/* model-specific configuration of outputs/inputs */
22#define PLAYBACK_0_TO_I2S 0x0001 24#define PLAYBACK_0_TO_I2S 0x0001
23 /* PLAYBACK_0_TO_AC97_0 not implemented */ 25 /* PLAYBACK_0_TO_AC97_0 not implemented */
@@ -49,7 +51,13 @@ enum {
49 .subvendor = sv, \ 51 .subvendor = sv, \
50 .subdevice = sd 52 .subdevice = sd
51 53
54#define BROKEN_EEPROM_DRIVER_DATA ((unsigned long)-1)
55#define OXYGEN_PCI_SUBID_BROKEN_EEPROM \
56 OXYGEN_PCI_SUBID(PCI_VENDOR_ID_CMEDIA, 0x8788), \
57 .driver_data = BROKEN_EEPROM_DRIVER_DATA
58
52struct pci_dev; 59struct pci_dev;
60struct pci_device_id;
53struct snd_card; 61struct snd_card;
54struct snd_pcm_substream; 62struct snd_pcm_substream;
55struct snd_pcm_hardware; 63struct snd_pcm_hardware;
@@ -62,8 +70,6 @@ struct oxygen_model {
62 const char *shortname; 70 const char *shortname;
63 const char *longname; 71 const char *longname;
64 const char *chip; 72 const char *chip;
65 struct module *owner;
66 int (*probe)(struct oxygen *chip, unsigned long driver_data);
67 void (*init)(struct oxygen *chip); 73 void (*init)(struct oxygen *chip);
68 int (*control_filter)(struct snd_kcontrol_new *template); 74 int (*control_filter)(struct snd_kcontrol_new *template);
69 int (*mixer_init)(struct oxygen *chip); 75 int (*mixer_init)(struct oxygen *chip);
@@ -83,6 +89,7 @@ struct oxygen_model {
83 void (*ac97_switch)(struct oxygen *chip, 89 void (*ac97_switch)(struct oxygen *chip,
84 unsigned int reg, unsigned int mute); 90 unsigned int reg, unsigned int mute);
85 const unsigned int *dac_tlv; 91 const unsigned int *dac_tlv;
92 unsigned long private_data;
86 size_t model_data_size; 93 size_t model_data_size;
87 unsigned int device_config; 94 unsigned int device_config;
88 u8 dac_channels; 95 u8 dac_channels;
@@ -134,8 +141,12 @@ struct oxygen {
134/* oxygen_lib.c */ 141/* oxygen_lib.c */
135 142
136int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, 143int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
137 const struct oxygen_model *model, 144 struct module *owner,
138 unsigned long driver_data); 145 const struct pci_device_id *ids,
146 int (*get_model)(struct oxygen *chip,
147 const struct pci_device_id *id
148 )
149 );
139void oxygen_pci_remove(struct pci_dev *pci); 150void oxygen_pci_remove(struct pci_dev *pci);
140#ifdef CONFIG_PM 151#ifdef CONFIG_PM
141int oxygen_pci_suspend(struct pci_dev *pci, pm_message_t state); 152int oxygen_pci_suspend(struct pci_dev *pci, pm_message_t state);
@@ -180,6 +191,9 @@ void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data);
180void oxygen_reset_uart(struct oxygen *chip); 191void oxygen_reset_uart(struct oxygen *chip);
181void oxygen_write_uart(struct oxygen *chip, u8 data); 192void oxygen_write_uart(struct oxygen *chip, u8 data);
182 193
194u16 oxygen_read_eeprom(struct oxygen *chip, unsigned int index);
195void oxygen_write_eeprom(struct oxygen *chip, unsigned int index, u16 value);
196
183static inline void oxygen_set_bits8(struct oxygen *chip, 197static inline void oxygen_set_bits8(struct oxygen *chip,
184 unsigned int reg, u8 value) 198 unsigned int reg, u8 value)
185{ 199{
diff --git a/sound/pci/oxygen/oxygen_io.c b/sound/pci/oxygen/oxygen_io.c
index 3126c4b403dd..c1eb923f2ac9 100644
--- a/sound/pci/oxygen/oxygen_io.c
+++ b/sound/pci/oxygen/oxygen_io.c
@@ -254,3 +254,34 @@ void oxygen_write_uart(struct oxygen *chip, u8 data)
254 _write_uart(chip, 0, data); 254 _write_uart(chip, 0, data);
255} 255}
256EXPORT_SYMBOL(oxygen_write_uart); 256EXPORT_SYMBOL(oxygen_write_uart);
257
258u16 oxygen_read_eeprom(struct oxygen *chip, unsigned int index)
259{
260 unsigned int timeout;
261
262 oxygen_write8(chip, OXYGEN_EEPROM_CONTROL,
263 index | OXYGEN_EEPROM_DIR_READ);
264 for (timeout = 0; timeout < 100; ++timeout) {
265 udelay(1);
266 if (!(oxygen_read8(chip, OXYGEN_EEPROM_STATUS)
267 & OXYGEN_EEPROM_BUSY))
268 break;
269 }
270 return oxygen_read16(chip, OXYGEN_EEPROM_DATA);
271}
272
273void oxygen_write_eeprom(struct oxygen *chip, unsigned int index, u16 value)
274{
275 unsigned int timeout;
276
277 oxygen_write16(chip, OXYGEN_EEPROM_DATA, value);
278 oxygen_write8(chip, OXYGEN_EEPROM_CONTROL,
279 index | OXYGEN_EEPROM_DIR_WRITE);
280 for (timeout = 0; timeout < 10; ++timeout) {
281 msleep(1);
282 if (!(oxygen_read8(chip, OXYGEN_EEPROM_STATUS)
283 & OXYGEN_EEPROM_BUSY))
284 return;
285 }
286 snd_printk(KERN_ERR "EEPROM write timeout\n");
287}
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index 84f481d41efa..312251d39696 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -34,6 +34,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
34MODULE_DESCRIPTION("C-Media CMI8788 helper library"); 34MODULE_DESCRIPTION("C-Media CMI8788 helper library");
35MODULE_LICENSE("GPL v2"); 35MODULE_LICENSE("GPL v2");
36 36
37#define DRIVER "oxygen"
37 38
38static inline int oxygen_uart_input_ready(struct oxygen *chip) 39static inline int oxygen_uart_input_ready(struct oxygen *chip)
39{ 40{
@@ -243,6 +244,62 @@ static void oxygen_proc_init(struct oxygen *chip)
243#define oxygen_proc_init(chip) 244#define oxygen_proc_init(chip)
244#endif 245#endif
245 246
247static const struct pci_device_id *
248oxygen_search_pci_id(struct oxygen *chip, const struct pci_device_id ids[])
249{
250 u16 subdevice;
251
252 /*
253 * Make sure the EEPROM pins are available, i.e., not used for SPI.
254 * (This function is called before we initialize or use SPI.)
255 */
256 oxygen_clear_bits8(chip, OXYGEN_FUNCTION,
257 OXYGEN_FUNCTION_ENABLE_SPI_4_5);
258 /*
259 * Read the subsystem device ID directly from the EEPROM, because the
260 * chip didn't if the first EEPROM word was overwritten.
261 */
262 subdevice = oxygen_read_eeprom(chip, 2);
263 /*
264 * We use only the subsystem device ID for searching because it is
265 * unique even without the subsystem vendor ID, which may have been
266 * overwritten in the EEPROM.
267 */
268 for (; ids->vendor; ++ids)
269 if (ids->subdevice == subdevice &&
270 ids->driver_data != BROKEN_EEPROM_DRIVER_DATA)
271 return ids;
272 return NULL;
273}
274
275static void oxygen_restore_eeprom(struct oxygen *chip,
276 const struct pci_device_id *id)
277{
278 if (oxygen_read_eeprom(chip, 0) != OXYGEN_EEPROM_ID) {
279 /*
280 * This function gets called only when a known card model has
281 * been detected, i.e., we know there is a valid subsystem
282 * product ID at index 2 in the EEPROM. Therefore, we have
283 * been able to deduce the correct subsystem vendor ID, and
284 * this is enough information to restore the original EEPROM
285 * contents.
286 */
287 oxygen_write_eeprom(chip, 1, id->subvendor);
288 oxygen_write_eeprom(chip, 0, OXYGEN_EEPROM_ID);
289
290 oxygen_set_bits8(chip, OXYGEN_MISC,
291 OXYGEN_MISC_WRITE_PCI_SUBID);
292 pci_write_config_word(chip->pci, PCI_SUBSYSTEM_VENDOR_ID,
293 id->subvendor);
294 pci_write_config_word(chip->pci, PCI_SUBSYSTEM_ID,
295 id->subdevice);
296 oxygen_clear_bits8(chip, OXYGEN_MISC,
297 OXYGEN_MISC_WRITE_PCI_SUBID);
298
299 snd_printk(KERN_INFO "EEPROM ID restored\n");
300 }
301}
302
246static void oxygen_init(struct oxygen *chip) 303static void oxygen_init(struct oxygen *chip)
247{ 304{
248 unsigned int i; 305 unsigned int i;
@@ -446,30 +503,33 @@ static void oxygen_card_free(struct snd_card *card)
446 free_irq(chip->irq, chip); 503 free_irq(chip->irq, chip);
447 flush_scheduled_work(); 504 flush_scheduled_work();
448 chip->model.cleanup(chip); 505 chip->model.cleanup(chip);
506 kfree(chip->model_data);
449 mutex_destroy(&chip->mutex); 507 mutex_destroy(&chip->mutex);
450 pci_release_regions(chip->pci); 508 pci_release_regions(chip->pci);
451 pci_disable_device(chip->pci); 509 pci_disable_device(chip->pci);
452} 510}
453 511
454int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, 512int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
455 const struct oxygen_model *model, 513 struct module *owner,
456 unsigned long driver_data) 514 const struct pci_device_id *ids,
515 int (*get_model)(struct oxygen *chip,
516 const struct pci_device_id *id
517 )
518 )
457{ 519{
458 struct snd_card *card; 520 struct snd_card *card;
459 struct oxygen *chip; 521 struct oxygen *chip;
522 const struct pci_device_id *pci_id;
460 int err; 523 int err;
461 524
462 card = snd_card_new(index, id, model->owner, 525 err = snd_card_create(index, id, owner, sizeof(*chip), &card);
463 sizeof *chip + model->model_data_size); 526 if (err < 0)
464 if (!card) 527 return err;
465 return -ENOMEM;
466 528
467 chip = card->private_data; 529 chip = card->private_data;
468 chip->card = card; 530 chip->card = card;
469 chip->pci = pci; 531 chip->pci = pci;
470 chip->irq = -1; 532 chip->irq = -1;
471 chip->model = *model;
472 chip->model_data = chip + 1;
473 spin_lock_init(&chip->reg_lock); 533 spin_lock_init(&chip->reg_lock);
474 mutex_init(&chip->mutex); 534 mutex_init(&chip->mutex);
475 INIT_WORK(&chip->spdif_input_bits_work, 535 INIT_WORK(&chip->spdif_input_bits_work,
@@ -481,7 +541,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
481 if (err < 0) 541 if (err < 0)
482 goto err_card; 542 goto err_card;
483 543
484 err = pci_request_regions(pci, model->chip); 544 err = pci_request_regions(pci, DRIVER);
485 if (err < 0) { 545 if (err < 0) {
486 snd_printk(KERN_ERR "cannot reserve PCI resources\n"); 546 snd_printk(KERN_ERR "cannot reserve PCI resources\n");
487 goto err_pci_enable; 547 goto err_pci_enable;
@@ -495,20 +555,34 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
495 } 555 }
496 chip->addr = pci_resource_start(pci, 0); 556 chip->addr = pci_resource_start(pci, 0);
497 557
558 pci_id = oxygen_search_pci_id(chip, ids);
559 if (!pci_id) {
560 err = -ENODEV;
561 goto err_pci_regions;
562 }
563 oxygen_restore_eeprom(chip, pci_id);
564 err = get_model(chip, pci_id);
565 if (err < 0)
566 goto err_pci_regions;
567
568 if (chip->model.model_data_size) {
569 chip->model_data = kzalloc(chip->model.model_data_size,
570 GFP_KERNEL);
571 if (!chip->model_data) {
572 err = -ENOMEM;
573 goto err_pci_regions;
574 }
575 }
576
498 pci_set_master(pci); 577 pci_set_master(pci);
499 snd_card_set_dev(card, &pci->dev); 578 snd_card_set_dev(card, &pci->dev);
500 card->private_free = oxygen_card_free; 579 card->private_free = oxygen_card_free;
501 580
502 if (chip->model.probe) {
503 err = chip->model.probe(chip, driver_data);
504 if (err < 0)
505 goto err_card;
506 }
507 oxygen_init(chip); 581 oxygen_init(chip);
508 chip->model.init(chip); 582 chip->model.init(chip);
509 583
510 err = request_irq(pci->irq, oxygen_interrupt, IRQF_SHARED, 584 err = request_irq(pci->irq, oxygen_interrupt, IRQF_SHARED,
511 chip->model.chip, chip); 585 DRIVER, chip);
512 if (err < 0) { 586 if (err < 0) {
513 snd_printk(KERN_ERR "cannot grab interrupt %d\n", pci->irq); 587 snd_printk(KERN_ERR "cannot grab interrupt %d\n", pci->irq);
514 goto err_card; 588 goto err_card;
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c
index 6c870c12a177..bc5ce11c8b14 100644
--- a/sound/pci/oxygen/virtuoso.c
+++ b/sound/pci/oxygen/virtuoso.c
@@ -112,6 +112,34 @@
112 * CS4362A: AD0 <- 0 112 * CS4362A: AD0 <- 0
113 */ 113 */
114 114
115/*
116 * Xonar Essence STX
117 * -----------------
118 *
119 * CMI8788:
120 *
121 * I²C <-> PCM1792A
122 *
123 * GPI 0 <- external power present
124 *
125 * GPIO 0 -> enable output to speakers
126 * GPIO 1 -> route HP to front panel (0) or rear jack (1)
127 * GPIO 2 -> M0 of CS5381
128 * GPIO 3 -> M1 of CS5381
129 * GPIO 7 -> route output to speaker jacks (0) or HP (1)
130 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
131 *
132 * PCM1792A:
133 *
134 * AD0 <- 0
135 *
136 * H6 daughterboard
137 * ----------------
138 *
139 * GPIO 4 <- 0
140 * GPIO 5 <- 0
141 */
142
115#include <linux/pci.h> 143#include <linux/pci.h>
116#include <linux/delay.h> 144#include <linux/delay.h>
117#include <linux/mutex.h> 145#include <linux/mutex.h>
@@ -152,6 +180,7 @@ enum {
152 MODEL_DX, 180 MODEL_DX,
153 MODEL_HDAV, /* without daughterboard */ 181 MODEL_HDAV, /* without daughterboard */
154 MODEL_HDAV_H6, /* with H6 daughterboard */ 182 MODEL_HDAV_H6, /* with H6 daughterboard */
183 MODEL_STX,
155}; 184};
156 185
157static struct pci_device_id xonar_ids[] __devinitdata = { 186static struct pci_device_id xonar_ids[] __devinitdata = {
@@ -160,6 +189,8 @@ static struct pci_device_id xonar_ids[] __devinitdata = {
160 { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X }, 189 { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X },
161 { OXYGEN_PCI_SUBID(0x1043, 0x8314), .driver_data = MODEL_HDAV }, 190 { OXYGEN_PCI_SUBID(0x1043, 0x8314), .driver_data = MODEL_HDAV },
162 { OXYGEN_PCI_SUBID(0x1043, 0x834f), .driver_data = MODEL_D1 }, 191 { OXYGEN_PCI_SUBID(0x1043, 0x834f), .driver_data = MODEL_D1 },
192 { OXYGEN_PCI_SUBID(0x1043, 0x835c), .driver_data = MODEL_STX },
193 { OXYGEN_PCI_SUBID_BROKEN_EEPROM },
163 { } 194 { }
164}; 195};
165MODULE_DEVICE_TABLE(pci, xonar_ids); 196MODULE_DEVICE_TABLE(pci, xonar_ids);
@@ -183,12 +214,14 @@ MODULE_DEVICE_TABLE(pci, xonar_ids);
183#define GPIO_HDAV_DB_H6 0x0000 214#define GPIO_HDAV_DB_H6 0x0000
184#define GPIO_HDAV_DB_XX 0x0020 215#define GPIO_HDAV_DB_XX 0x0020
185 216
217#define GPIO_ST_HP_REAR 0x0002
218#define GPIO_ST_HP 0x0080
219
186#define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ADx=i, /W=0 */ 220#define I2C_DEVICE_PCM1796(i) (0x98 + ((i) << 1)) /* 10011, ADx=i, /W=0 */
187#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */ 221#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */
188#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */ 222#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */
189 223
190struct xonar_data { 224struct xonar_data {
191 unsigned int model;
192 unsigned int anti_pop_delay; 225 unsigned int anti_pop_delay;
193 unsigned int dacs; 226 unsigned int dacs;
194 u16 output_enable_bit; 227 u16 output_enable_bit;
@@ -334,15 +367,9 @@ static void xonar_d2_init(struct oxygen *chip)
334 struct xonar_data *data = chip->model_data; 367 struct xonar_data *data = chip->model_data;
335 368
336 data->anti_pop_delay = 300; 369 data->anti_pop_delay = 300;
370 data->dacs = 4;
337 data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE; 371 data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
338 data->pcm1796_oversampling = PCM1796_OS_64; 372 data->pcm1796_oversampling = PCM1796_OS_64;
339 if (data->model == MODEL_D2X) {
340 data->ext_power_reg = OXYGEN_GPIO_DATA;
341 data->ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
342 data->ext_power_bit = GPIO_D2X_EXT_POWER;
343 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL,
344 GPIO_D2X_EXT_POWER);
345 }
346 373
347 pcm1796_init(chip); 374 pcm1796_init(chip);
348 375
@@ -355,6 +382,18 @@ static void xonar_d2_init(struct oxygen *chip)
355 snd_component_add(chip->card, "CS5381"); 382 snd_component_add(chip->card, "CS5381");
356} 383}
357 384
385static void xonar_d2x_init(struct oxygen *chip)
386{
387 struct xonar_data *data = chip->model_data;
388
389 data->ext_power_reg = OXYGEN_GPIO_DATA;
390 data->ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
391 data->ext_power_bit = GPIO_D2X_EXT_POWER;
392 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
393
394 xonar_d2_init(chip);
395}
396
358static void update_cs4362a_volumes(struct oxygen *chip) 397static void update_cs4362a_volumes(struct oxygen *chip)
359{ 398{
360 u8 mute; 399 u8 mute;
@@ -422,11 +461,6 @@ static void xonar_d1_init(struct oxygen *chip)
422 data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST; 461 data->cs4398_fm = CS4398_FM_SINGLE | CS4398_DEM_NONE | CS4398_DIF_LJUST;
423 data->cs4362a_fm = CS4362A_FM_SINGLE | 462 data->cs4362a_fm = CS4362A_FM_SINGLE |
424 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L; 463 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
425 if (data->model == MODEL_DX) {
426 data->ext_power_reg = OXYGEN_GPI_DATA;
427 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
428 data->ext_power_bit = GPI_DX_EXT_POWER;
429 }
430 464
431 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS, 465 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
432 OXYGEN_2WIRE_LENGTH_8 | 466 OXYGEN_2WIRE_LENGTH_8 |
@@ -447,6 +481,17 @@ static void xonar_d1_init(struct oxygen *chip)
447 snd_component_add(chip->card, "CS5361"); 481 snd_component_add(chip->card, "CS5361");
448} 482}
449 483
484static void xonar_dx_init(struct oxygen *chip)
485{
486 struct xonar_data *data = chip->model_data;
487
488 data->ext_power_reg = OXYGEN_GPI_DATA;
489 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
490 data->ext_power_bit = GPI_DX_EXT_POWER;
491
492 xonar_d1_init(chip);
493}
494
450static void xonar_hdav_init(struct oxygen *chip) 495static void xonar_hdav_init(struct oxygen *chip)
451{ 496{
452 struct xonar_data *data = chip->model_data; 497 struct xonar_data *data = chip->model_data;
@@ -458,6 +503,7 @@ static void xonar_hdav_init(struct oxygen *chip)
458 OXYGEN_2WIRE_SPEED_FAST); 503 OXYGEN_2WIRE_SPEED_FAST);
459 504
460 data->anti_pop_delay = 100; 505 data->anti_pop_delay = 100;
506 data->dacs = chip->model.private_data == MODEL_HDAV_H6 ? 4 : 1;
461 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE; 507 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
462 data->ext_power_reg = OXYGEN_GPI_DATA; 508 data->ext_power_reg = OXYGEN_GPI_DATA;
463 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK; 509 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
@@ -484,6 +530,36 @@ static void xonar_hdav_init(struct oxygen *chip)
484 snd_component_add(chip->card, "CS5381"); 530 snd_component_add(chip->card, "CS5381");
485} 531}
486 532
533static void xonar_stx_init(struct oxygen *chip)
534{
535 struct xonar_data *data = chip->model_data;
536
537 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
538 OXYGEN_2WIRE_LENGTH_8 |
539 OXYGEN_2WIRE_INTERRUPT_MASK |
540 OXYGEN_2WIRE_SPEED_FAST);
541
542 data->anti_pop_delay = 100;
543 data->dacs = 1;
544 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
545 data->ext_power_reg = OXYGEN_GPI_DATA;
546 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
547 data->ext_power_bit = GPI_DX_EXT_POWER;
548 data->pcm1796_oversampling = PCM1796_OS_64;
549
550 pcm1796_init(chip);
551
552 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
553 GPIO_DX_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
554 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
555 GPIO_DX_INPUT_ROUTE | GPIO_ST_HP_REAR | GPIO_ST_HP);
556
557 xonar_common_init(chip);
558
559 snd_component_add(chip->card, "PCM1792A");
560 snd_component_add(chip->card, "CS5381");
561}
562
487static void xonar_disable_output(struct oxygen *chip) 563static void xonar_disable_output(struct oxygen *chip)
488{ 564{
489 struct xonar_data *data = chip->model_data; 565 struct xonar_data *data = chip->model_data;
@@ -511,6 +587,11 @@ static void xonar_hdav_cleanup(struct oxygen *chip)
511 xonar_disable_output(chip); 587 xonar_disable_output(chip);
512} 588}
513 589
590static void xonar_st_cleanup(struct oxygen *chip)
591{
592 xonar_disable_output(chip);
593}
594
514static void xonar_d2_suspend(struct oxygen *chip) 595static void xonar_d2_suspend(struct oxygen *chip)
515{ 596{
516 xonar_d2_cleanup(chip); 597 xonar_d2_cleanup(chip);
@@ -527,6 +608,11 @@ static void xonar_hdav_suspend(struct oxygen *chip)
527 msleep(2); 608 msleep(2);
528} 609}
529 610
611static void xonar_st_suspend(struct oxygen *chip)
612{
613 xonar_st_cleanup(chip);
614}
615
530static void xonar_d2_resume(struct oxygen *chip) 616static void xonar_d2_resume(struct oxygen *chip)
531{ 617{
532 pcm1796_init(chip); 618 pcm1796_init(chip);
@@ -554,6 +640,12 @@ static void xonar_hdav_resume(struct oxygen *chip)
554 xonar_enable_output(chip); 640 xonar_enable_output(chip);
555} 641}
556 642
643static void xonar_st_resume(struct oxygen *chip)
644{
645 pcm1796_init(chip);
646 xonar_enable_output(chip);
647}
648
557static void xonar_hdav_pcm_hardware_filter(unsigned int channel, 649static void xonar_hdav_pcm_hardware_filter(unsigned int channel,
558 struct snd_pcm_hardware *hardware) 650 struct snd_pcm_hardware *hardware)
559{ 651{
@@ -733,6 +825,72 @@ static const struct snd_kcontrol_new front_panel_switch = {
733 .private_value = GPIO_DX_FRONT_PANEL, 825 .private_value = GPIO_DX_FRONT_PANEL,
734}; 826};
735 827
828static int st_output_switch_info(struct snd_kcontrol *ctl,
829 struct snd_ctl_elem_info *info)
830{
831 static const char *const names[3] = {
832 "Speakers", "Headphones", "FP Headphones"
833 };
834
835 info->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
836 info->count = 1;
837 info->value.enumerated.items = 3;
838 if (info->value.enumerated.item >= 3)
839 info->value.enumerated.item = 2;
840 strcpy(info->value.enumerated.name, names[info->value.enumerated.item]);
841 return 0;
842}
843
844static int st_output_switch_get(struct snd_kcontrol *ctl,
845 struct snd_ctl_elem_value *value)
846{
847 struct oxygen *chip = ctl->private_data;
848 u16 gpio;
849
850 gpio = oxygen_read16(chip, OXYGEN_GPIO_DATA);
851 if (!(gpio & GPIO_ST_HP))
852 value->value.enumerated.item[0] = 0;
853 else if (gpio & GPIO_ST_HP_REAR)
854 value->value.enumerated.item[0] = 1;
855 else
856 value->value.enumerated.item[0] = 2;
857 return 0;
858}
859
860
861static int st_output_switch_put(struct snd_kcontrol *ctl,
862 struct snd_ctl_elem_value *value)
863{
864 struct oxygen *chip = ctl->private_data;
865 u16 gpio_old, gpio;
866
867 mutex_lock(&chip->mutex);
868 gpio_old = oxygen_read16(chip, OXYGEN_GPIO_DATA);
869 gpio = gpio_old;
870 switch (value->value.enumerated.item[0]) {
871 case 0:
872 gpio &= ~(GPIO_ST_HP | GPIO_ST_HP_REAR);
873 break;
874 case 1:
875 gpio |= GPIO_ST_HP | GPIO_ST_HP_REAR;
876 break;
877 case 2:
878 gpio = (gpio | GPIO_ST_HP) & ~GPIO_ST_HP_REAR;
879 break;
880 }
881 oxygen_write16(chip, OXYGEN_GPIO_DATA, gpio);
882 mutex_unlock(&chip->mutex);
883 return gpio != gpio_old;
884}
885
886static const struct snd_kcontrol_new st_output_switch = {
887 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
888 .name = "Analog Output",
889 .info = st_output_switch_info,
890 .get = st_output_switch_get,
891 .put = st_output_switch_put,
892};
893
736static void xonar_line_mic_ac97_switch(struct oxygen *chip, 894static void xonar_line_mic_ac97_switch(struct oxygen *chip,
737 unsigned int reg, unsigned int mute) 895 unsigned int reg, unsigned int mute)
738{ 896{
@@ -745,8 +903,8 @@ static void xonar_line_mic_ac97_switch(struct oxygen *chip,
745 } 903 }
746} 904}
747 905
748static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -12000, 50, 0); 906static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -6000, 50, 0);
749static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -12700, 100, 0); 907static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -6000, 100, 0);
750 908
751static int xonar_d2_control_filter(struct snd_kcontrol_new *template) 909static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
752{ 910{
@@ -763,6 +921,15 @@ static int xonar_d1_control_filter(struct snd_kcontrol_new *template)
763 return 0; 921 return 0;
764} 922}
765 923
924static int xonar_st_control_filter(struct snd_kcontrol_new *template)
925{
926 if (!strncmp(template->name, "CD Capture ", 11))
927 return 1; /* no CD input */
928 if (!strcmp(template->name, "Stereo Upmixing"))
929 return 1; /* stereo only - we don't need upmixing */
930 return 0;
931}
932
766static int xonar_d2_mixer_init(struct oxygen *chip) 933static int xonar_d2_mixer_init(struct oxygen *chip)
767{ 934{
768 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip)); 935 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
@@ -773,51 +940,14 @@ static int xonar_d1_mixer_init(struct oxygen *chip)
773 return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip)); 940 return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip));
774} 941}
775 942
776static int xonar_model_probe(struct oxygen *chip, unsigned long driver_data) 943static int xonar_st_mixer_init(struct oxygen *chip)
777{ 944{
778 static const char *const names[] = { 945 return snd_ctl_add(chip->card, snd_ctl_new1(&st_output_switch, chip));
779 [MODEL_D1] = "Xonar D1",
780 [MODEL_DX] = "Xonar DX",
781 [MODEL_D2] = "Xonar D2",
782 [MODEL_D2X] = "Xonar D2X",
783 [MODEL_HDAV] = "Xonar HDAV1.3",
784 [MODEL_HDAV_H6] = "Xonar HDAV1.3+H6",
785 };
786 static const u8 dacs[] = {
787 [MODEL_D1] = 2,
788 [MODEL_DX] = 2,
789 [MODEL_D2] = 4,
790 [MODEL_D2X] = 4,
791 [MODEL_HDAV] = 1,
792 [MODEL_HDAV_H6] = 4,
793 };
794 struct xonar_data *data = chip->model_data;
795
796 data->model = driver_data;
797 if (data->model == MODEL_HDAV) {
798 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL,
799 GPIO_HDAV_DB_MASK);
800 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) &
801 GPIO_HDAV_DB_MASK) {
802 case GPIO_HDAV_DB_H6:
803 data->model = MODEL_HDAV_H6;
804 break;
805 case GPIO_HDAV_DB_XX:
806 snd_printk(KERN_ERR "unknown daughterboard\n");
807 return -ENODEV;
808 }
809 }
810
811 data->dacs = dacs[data->model];
812 chip->model.shortname = names[data->model];
813 return 0;
814} 946}
815 947
816static const struct oxygen_model model_xonar_d2 = { 948static const struct oxygen_model model_xonar_d2 = {
817 .longname = "Asus Virtuoso 200", 949 .longname = "Asus Virtuoso 200",
818 .chip = "AV200", 950 .chip = "AV200",
819 .owner = THIS_MODULE,
820 .probe = xonar_model_probe,
821 .init = xonar_d2_init, 951 .init = xonar_d2_init,
822 .control_filter = xonar_d2_control_filter, 952 .control_filter = xonar_d2_control_filter,
823 .mixer_init = xonar_d2_mixer_init, 953 .mixer_init = xonar_d2_mixer_init,
@@ -837,8 +967,8 @@ static const struct oxygen_model model_xonar_d2 = {
837 MIDI_OUTPUT | 967 MIDI_OUTPUT |
838 MIDI_INPUT, 968 MIDI_INPUT,
839 .dac_channels = 8, 969 .dac_channels = 8,
840 .dac_volume_min = 0x0f, 970 .dac_volume_min = 255 - 2*60,
841 .dac_volume_max = 0xff, 971 .dac_volume_max = 255,
842 .misc_flags = OXYGEN_MISC_MIDI, 972 .misc_flags = OXYGEN_MISC_MIDI,
843 .function_flags = OXYGEN_FUNCTION_SPI | 973 .function_flags = OXYGEN_FUNCTION_SPI |
844 OXYGEN_FUNCTION_ENABLE_SPI_4_5, 974 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
@@ -849,8 +979,6 @@ static const struct oxygen_model model_xonar_d2 = {
849static const struct oxygen_model model_xonar_d1 = { 979static const struct oxygen_model model_xonar_d1 = {
850 .longname = "Asus Virtuoso 100", 980 .longname = "Asus Virtuoso 100",
851 .chip = "AV200", 981 .chip = "AV200",
852 .owner = THIS_MODULE,
853 .probe = xonar_model_probe,
854 .init = xonar_d1_init, 982 .init = xonar_d1_init,
855 .control_filter = xonar_d1_control_filter, 983 .control_filter = xonar_d1_control_filter,
856 .mixer_init = xonar_d1_mixer_init, 984 .mixer_init = xonar_d1_mixer_init,
@@ -868,7 +996,7 @@ static const struct oxygen_model model_xonar_d1 = {
868 PLAYBACK_1_TO_SPDIF | 996 PLAYBACK_1_TO_SPDIF |
869 CAPTURE_0_FROM_I2S_2, 997 CAPTURE_0_FROM_I2S_2,
870 .dac_channels = 8, 998 .dac_channels = 8,
871 .dac_volume_min = 0, 999 .dac_volume_min = 127 - 60,
872 .dac_volume_max = 127, 1000 .dac_volume_max = 127,
873 .function_flags = OXYGEN_FUNCTION_2WIRE, 1001 .function_flags = OXYGEN_FUNCTION_2WIRE,
874 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 1002 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
@@ -878,8 +1006,6 @@ static const struct oxygen_model model_xonar_d1 = {
878static const struct oxygen_model model_xonar_hdav = { 1006static const struct oxygen_model model_xonar_hdav = {
879 .longname = "Asus Virtuoso 200", 1007 .longname = "Asus Virtuoso 200",
880 .chip = "AV200", 1008 .chip = "AV200",
881 .owner = THIS_MODULE,
882 .probe = xonar_model_probe,
883 .init = xonar_hdav_init, 1009 .init = xonar_hdav_init,
884 .cleanup = xonar_hdav_cleanup, 1010 .cleanup = xonar_hdav_cleanup,
885 .suspend = xonar_hdav_suspend, 1011 .suspend = xonar_hdav_suspend,
@@ -897,16 +1023,43 @@ static const struct oxygen_model model_xonar_hdav = {
897 PLAYBACK_1_TO_SPDIF | 1023 PLAYBACK_1_TO_SPDIF |
898 CAPTURE_0_FROM_I2S_2, 1024 CAPTURE_0_FROM_I2S_2,
899 .dac_channels = 8, 1025 .dac_channels = 8,
900 .dac_volume_min = 0x0f, 1026 .dac_volume_min = 255 - 2*60,
901 .dac_volume_max = 0xff, 1027 .dac_volume_max = 255,
902 .misc_flags = OXYGEN_MISC_MIDI, 1028 .misc_flags = OXYGEN_MISC_MIDI,
903 .function_flags = OXYGEN_FUNCTION_2WIRE, 1029 .function_flags = OXYGEN_FUNCTION_2WIRE,
904 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 1030 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
905 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 1031 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
906}; 1032};
907 1033
908static int __devinit xonar_probe(struct pci_dev *pci, 1034static const struct oxygen_model model_xonar_st = {
909 const struct pci_device_id *pci_id) 1035 .longname = "Asus Virtuoso 100",
1036 .chip = "AV200",
1037 .init = xonar_stx_init,
1038 .control_filter = xonar_st_control_filter,
1039 .mixer_init = xonar_st_mixer_init,
1040 .cleanup = xonar_st_cleanup,
1041 .suspend = xonar_st_suspend,
1042 .resume = xonar_st_resume,
1043 .set_dac_params = set_pcm1796_params,
1044 .set_adc_params = set_cs53x1_params,
1045 .update_dac_volume = update_pcm1796_volume,
1046 .update_dac_mute = update_pcm1796_mute,
1047 .ac97_switch = xonar_line_mic_ac97_switch,
1048 .dac_tlv = pcm1796_db_scale,
1049 .model_data_size = sizeof(struct xonar_data),
1050 .device_config = PLAYBACK_0_TO_I2S |
1051 PLAYBACK_1_TO_SPDIF |
1052 CAPTURE_0_FROM_I2S_2,
1053 .dac_channels = 2,
1054 .dac_volume_min = 255 - 2*60,
1055 .dac_volume_max = 255,
1056 .function_flags = OXYGEN_FUNCTION_2WIRE,
1057 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1058 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
1059};
1060
1061static int __devinit get_xonar_model(struct oxygen *chip,
1062 const struct pci_device_id *id)
910{ 1063{
911 static const struct oxygen_model *const models[] = { 1064 static const struct oxygen_model *const models[] = {
912 [MODEL_D1] = &model_xonar_d1, 1065 [MODEL_D1] = &model_xonar_d1,
@@ -914,7 +1067,57 @@ static int __devinit xonar_probe(struct pci_dev *pci,
914 [MODEL_D2] = &model_xonar_d2, 1067 [MODEL_D2] = &model_xonar_d2,
915 [MODEL_D2X] = &model_xonar_d2, 1068 [MODEL_D2X] = &model_xonar_d2,
916 [MODEL_HDAV] = &model_xonar_hdav, 1069 [MODEL_HDAV] = &model_xonar_hdav,
1070 [MODEL_STX] = &model_xonar_st,
917 }; 1071 };
1072 static const char *const names[] = {
1073 [MODEL_D1] = "Xonar D1",
1074 [MODEL_DX] = "Xonar DX",
1075 [MODEL_D2] = "Xonar D2",
1076 [MODEL_D2X] = "Xonar D2X",
1077 [MODEL_HDAV] = "Xonar HDAV1.3",
1078 [MODEL_HDAV_H6] = "Xonar HDAV1.3+H6",
1079 [MODEL_STX] = "Xonar Essence STX",
1080 };
1081 unsigned int model = id->driver_data;
1082
1083 if (model >= ARRAY_SIZE(models) || !models[model])
1084 return -EINVAL;
1085 chip->model = *models[model];
1086
1087 switch (model) {
1088 case MODEL_D2X:
1089 chip->model.init = xonar_d2x_init;
1090 break;
1091 case MODEL_DX:
1092 chip->model.init = xonar_dx_init;
1093 break;
1094 case MODEL_HDAV:
1095 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL,
1096 GPIO_HDAV_DB_MASK);
1097 switch (oxygen_read16(chip, OXYGEN_GPIO_DATA) &
1098 GPIO_HDAV_DB_MASK) {
1099 case GPIO_HDAV_DB_H6:
1100 model = MODEL_HDAV_H6;
1101 break;
1102 case GPIO_HDAV_DB_XX:
1103 snd_printk(KERN_ERR "unknown daughterboard\n");
1104 return -ENODEV;
1105 }
1106 break;
1107 case MODEL_STX:
1108 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL,
1109 GPIO_HDAV_DB_MASK);
1110 break;
1111 }
1112
1113 chip->model.shortname = names[model];
1114 chip->model.private_data = model;
1115 return 0;
1116}
1117
1118static int __devinit xonar_probe(struct pci_dev *pci,
1119 const struct pci_device_id *pci_id)
1120{
918 static int dev; 1121 static int dev;
919 int err; 1122 int err;
920 1123
@@ -924,10 +1127,8 @@ static int __devinit xonar_probe(struct pci_dev *pci,
924 ++dev; 1127 ++dev;
925 return -ENOENT; 1128 return -ENOENT;
926 } 1129 }
927 BUG_ON(pci_id->driver_data >= ARRAY_SIZE(models)); 1130 err = oxygen_pci_probe(pci, index[dev], id[dev], THIS_MODULE,
928 err = oxygen_pci_probe(pci, index[dev], id[dev], 1131 xonar_ids, get_xonar_model);
929 models[pci_id->driver_data],
930 pci_id->driver_data);
931 if (err >= 0) 1132 if (err >= 0)
932 ++dev; 1133 ++dev;
933 return err; 1134 return err;
diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c
index 27cf2c28d113..80e064a3efff 100644
--- a/sound/pci/pcxhr/pcxhr.c
+++ b/sound/pci/pcxhr/pcxhr.c
@@ -1334,6 +1334,40 @@ static void pcxhr_proc_sync(struct snd_info_entry *entry,
1334 snd_iprintf(buffer, "\n"); 1334 snd_iprintf(buffer, "\n");
1335} 1335}
1336 1336
1337static void pcxhr_proc_gpio_read(struct snd_info_entry *entry,
1338 struct snd_info_buffer *buffer)
1339{
1340 struct snd_pcxhr *chip = entry->private_data;
1341 struct pcxhr_mgr *mgr = chip->mgr;
1342 /* commands available when embedded DSP is running */
1343 if (mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX)) {
1344 /* gpio ports on stereo boards only available */
1345 int value = 0;
1346 hr222_read_gpio(mgr, 1, &value); /* GPI */
1347 snd_iprintf(buffer, "GPI: 0x%x\n", value);
1348 hr222_read_gpio(mgr, 0, &value); /* GP0 */
1349 snd_iprintf(buffer, "GPO: 0x%x\n", value);
1350 } else
1351 snd_iprintf(buffer, "no firmware loaded\n");
1352 snd_iprintf(buffer, "\n");
1353}
1354static void pcxhr_proc_gpo_write(struct snd_info_entry *entry,
1355 struct snd_info_buffer *buffer)
1356{
1357 struct snd_pcxhr *chip = entry->private_data;
1358 struct pcxhr_mgr *mgr = chip->mgr;
1359 char line[64];
1360 int value;
1361 /* commands available when embedded DSP is running */
1362 if (!(mgr->dsp_loaded & (1 << PCXHR_FIRMWARE_DSP_MAIN_INDEX)))
1363 return;
1364 while (!snd_info_get_line(buffer, line, sizeof(line))) {
1365 if (sscanf(line, "GPO: 0x%x", &value) != 1)
1366 continue;
1367 hr222_write_gpo(mgr, value); /* GP0 */
1368 }
1369}
1370
1337static void __devinit pcxhr_proc_init(struct snd_pcxhr *chip) 1371static void __devinit pcxhr_proc_init(struct snd_pcxhr *chip)
1338{ 1372{
1339 struct snd_info_entry *entry; 1373 struct snd_info_entry *entry;
@@ -1342,6 +1376,13 @@ static void __devinit pcxhr_proc_init(struct snd_pcxhr *chip)
1342 snd_info_set_text_ops(entry, chip, pcxhr_proc_info); 1376 snd_info_set_text_ops(entry, chip, pcxhr_proc_info);
1343 if (! snd_card_proc_new(chip->card, "sync", &entry)) 1377 if (! snd_card_proc_new(chip->card, "sync", &entry))
1344 snd_info_set_text_ops(entry, chip, pcxhr_proc_sync); 1378 snd_info_set_text_ops(entry, chip, pcxhr_proc_sync);
1379 /* gpio available on stereo sound cards only */
1380 if (chip->mgr->is_hr_stereo &&
1381 !snd_card_proc_new(chip->card, "gpio", &entry)) {
1382 snd_info_set_text_ops(entry, chip, pcxhr_proc_gpio_read);
1383 entry->c.text.write = pcxhr_proc_gpo_write;
1384 entry->mode |= S_IWUSR;
1385 }
1345} 1386}
1346/* end of proc interface */ 1387/* end of proc interface */
1347 1388
@@ -1510,12 +1551,12 @@ static int __devinit pcxhr_probe(struct pci_dev *pci,
1510 1551
1511 snprintf(tmpid, sizeof(tmpid), "%s-%d", 1552 snprintf(tmpid, sizeof(tmpid), "%s-%d",
1512 id[dev] ? id[dev] : card_name, i); 1553 id[dev] ? id[dev] : card_name, i);
1513 card = snd_card_new(idx, tmpid, THIS_MODULE, 0); 1554 err = snd_card_create(idx, tmpid, THIS_MODULE, 0, &card);
1514 1555
1515 if (! card) { 1556 if (err < 0) {
1516 snd_printk(KERN_ERR "cannot allocate the card %d\n", i); 1557 snd_printk(KERN_ERR "cannot allocate the card %d\n", i);
1517 pcxhr_free(mgr); 1558 pcxhr_free(mgr);
1518 return -ENOMEM; 1559 return err;
1519 } 1560 }
1520 1561
1521 strcpy(card->driver, DRIVER_NAME); 1562 strcpy(card->driver, DRIVER_NAME);
diff --git a/sound/pci/pcxhr/pcxhr.h b/sound/pci/pcxhr/pcxhr.h
index 69d87dee6995..bda776c49884 100644
--- a/sound/pci/pcxhr/pcxhr.h
+++ b/sound/pci/pcxhr/pcxhr.h
@@ -27,8 +27,8 @@
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <sound/pcm.h> 28#include <sound/pcm.h>
29 29
30#define PCXHR_DRIVER_VERSION 0x000905 /* 0.9.5 */ 30#define PCXHR_DRIVER_VERSION 0x000906 /* 0.9.6 */
31#define PCXHR_DRIVER_VERSION_STRING "0.9.5" /* 0.9.5 */ 31#define PCXHR_DRIVER_VERSION_STRING "0.9.6" /* 0.9.6 */
32 32
33 33
34#define PCXHR_MAX_CARDS 6 34#define PCXHR_MAX_CARDS 6
@@ -124,6 +124,7 @@ struct pcxhr_mgr {
124 124
125 unsigned char xlx_cfg; /* copy of PCXHR_XLX_CFG register */ 125 unsigned char xlx_cfg; /* copy of PCXHR_XLX_CFG register */
126 unsigned char xlx_selmic; /* copy of PCXHR_XLX_SELMIC register */ 126 unsigned char xlx_selmic; /* copy of PCXHR_XLX_SELMIC register */
127 unsigned char dsp_reset; /* copy of PCXHR_DSP_RESET register */
127}; 128};
128 129
129 130
diff --git a/sound/pci/pcxhr/pcxhr_core.h b/sound/pci/pcxhr/pcxhr_core.h
index bbbd66d13a64..be0173796cdb 100644
--- a/sound/pci/pcxhr/pcxhr_core.h
+++ b/sound/pci/pcxhr/pcxhr_core.h
@@ -1,7 +1,7 @@
1/* 1/*
2 * Driver for Digigram pcxhr compatible soundcards 2 * Driver for Digigram pcxhr compatible soundcards
3 * 3 *
4 * low level interface with interrupt ans message handling 4 * low level interface with interrupt and message handling
5 * 5 *
6 * Copyright (c) 2004 by Digigram <alsa@digigram.com> 6 * Copyright (c) 2004 by Digigram <alsa@digigram.com>
7 * 7 *
diff --git a/sound/pci/pcxhr/pcxhr_hwdep.c b/sound/pci/pcxhr/pcxhr_hwdep.c
index 592743a298b0..17cb1233a903 100644
--- a/sound/pci/pcxhr/pcxhr_hwdep.c
+++ b/sound/pci/pcxhr/pcxhr_hwdep.c
@@ -471,16 +471,6 @@ static int pcxhr_hwdep_dsp_load(struct snd_hwdep *hw,
471 return 0; 471 return 0;
472} 472}
473 473
474static int pcxhr_hwdep_open(struct snd_hwdep *hw, struct file *file)
475{
476 return 0;
477}
478
479static int pcxhr_hwdep_release(struct snd_hwdep *hw, struct file *file)
480{
481 return 0;
482}
483
484int pcxhr_setup_firmware(struct pcxhr_mgr *mgr) 474int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
485{ 475{
486 int err; 476 int err;
@@ -495,8 +485,6 @@ int pcxhr_setup_firmware(struct pcxhr_mgr *mgr)
495 485
496 hw->iface = SNDRV_HWDEP_IFACE_PCXHR; 486 hw->iface = SNDRV_HWDEP_IFACE_PCXHR;
497 hw->private_data = mgr; 487 hw->private_data = mgr;
498 hw->ops.open = pcxhr_hwdep_open;
499 hw->ops.release = pcxhr_hwdep_release;
500 hw->ops.dsp_status = pcxhr_hwdep_dsp_status; 488 hw->ops.dsp_status = pcxhr_hwdep_dsp_status;
501 hw->ops.dsp_load = pcxhr_hwdep_dsp_load; 489 hw->ops.dsp_load = pcxhr_hwdep_dsp_load;
502 hw->exclusive = 1; 490 hw->exclusive = 1;
diff --git a/sound/pci/pcxhr/pcxhr_mix22.c b/sound/pci/pcxhr/pcxhr_mix22.c
index ff019126b672..1cb82c0a9cb3 100644
--- a/sound/pci/pcxhr/pcxhr_mix22.c
+++ b/sound/pci/pcxhr/pcxhr_mix22.c
@@ -53,6 +53,8 @@
53#define PCXHR_DSP_RESET_DSP 0x01 53#define PCXHR_DSP_RESET_DSP 0x01
54#define PCXHR_DSP_RESET_MUTE 0x02 54#define PCXHR_DSP_RESET_MUTE 0x02
55#define PCXHR_DSP_RESET_CODEC 0x08 55#define PCXHR_DSP_RESET_CODEC 0x08
56#define PCXHR_DSP_RESET_GPO_OFFSET 5
57#define PCXHR_DSP_RESET_GPO_MASK 0x60
56 58
57/* values for PCHR_XLX_CFG register */ 59/* values for PCHR_XLX_CFG register */
58#define PCXHR_CFG_SYNCDSP_MASK 0x80 60#define PCXHR_CFG_SYNCDSP_MASK 0x80
@@ -81,6 +83,8 @@
81/* values for PCHR_XLX_STATUS register - READ */ 83/* values for PCHR_XLX_STATUS register - READ */
82#define PCXHR_STAT_SRC_LOCK 0x01 84#define PCXHR_STAT_SRC_LOCK 0x01
83#define PCXHR_STAT_LEVEL_IN 0x02 85#define PCXHR_STAT_LEVEL_IN 0x02
86#define PCXHR_STAT_GPI_OFFSET 2
87#define PCXHR_STAT_GPI_MASK 0x0C
84#define PCXHR_STAT_MIC_CAPS 0x10 88#define PCXHR_STAT_MIC_CAPS 0x10
85/* values for PCHR_XLX_STATUS register - WRITE */ 89/* values for PCHR_XLX_STATUS register - WRITE */
86#define PCXHR_STAT_FREQ_SYNC_MASK 0x01 90#define PCXHR_STAT_FREQ_SYNC_MASK 0x01
@@ -291,10 +295,11 @@ int hr222_sub_init(struct pcxhr_mgr *mgr)
291 PCXHR_OUTPB(mgr, PCXHR_DSP_RESET, 295 PCXHR_OUTPB(mgr, PCXHR_DSP_RESET,
292 PCXHR_DSP_RESET_DSP); 296 PCXHR_DSP_RESET_DSP);
293 msleep(5); 297 msleep(5);
294 PCXHR_OUTPB(mgr, PCXHR_DSP_RESET, 298 mgr->dsp_reset = PCXHR_DSP_RESET_DSP |
295 PCXHR_DSP_RESET_DSP | 299 PCXHR_DSP_RESET_MUTE |
296 PCXHR_DSP_RESET_MUTE | 300 PCXHR_DSP_RESET_CODEC;
297 PCXHR_DSP_RESET_CODEC); 301 PCXHR_OUTPB(mgr, PCXHR_DSP_RESET, mgr->dsp_reset);
302 /* hr222_write_gpo(mgr, 0); does the same */
298 msleep(5); 303 msleep(5);
299 304
300 /* config AKM */ 305 /* config AKM */
@@ -496,6 +501,33 @@ int hr222_get_external_clock(struct pcxhr_mgr *mgr,
496} 501}
497 502
498 503
504int hr222_read_gpio(struct pcxhr_mgr *mgr, int is_gpi, int *value)
505{
506 if (is_gpi) {
507 unsigned char reg = PCXHR_INPB(mgr, PCXHR_XLX_STATUS);
508 *value = (int)(reg & PCXHR_STAT_GPI_MASK) >>
509 PCXHR_STAT_GPI_OFFSET;
510 } else {
511 *value = (int)(mgr->dsp_reset & PCXHR_DSP_RESET_GPO_MASK) >>
512 PCXHR_DSP_RESET_GPO_OFFSET;
513 }
514 return 0;
515}
516
517
518int hr222_write_gpo(struct pcxhr_mgr *mgr, int value)
519{
520 unsigned char reg = mgr->dsp_reset & ~PCXHR_DSP_RESET_GPO_MASK;
521
522 reg |= (unsigned char)(value << PCXHR_DSP_RESET_GPO_OFFSET) &
523 PCXHR_DSP_RESET_GPO_MASK;
524
525 PCXHR_OUTPB(mgr, PCXHR_DSP_RESET, reg);
526 mgr->dsp_reset = reg;
527 return 0;
528}
529
530
499int hr222_update_analog_audio_level(struct snd_pcxhr *chip, 531int hr222_update_analog_audio_level(struct snd_pcxhr *chip,
500 int is_capture, int channel) 532 int is_capture, int channel)
501{ 533{
diff --git a/sound/pci/pcxhr/pcxhr_mix22.h b/sound/pci/pcxhr/pcxhr_mix22.h
index 6b318b2f0100..5a37a0007e8f 100644
--- a/sound/pci/pcxhr/pcxhr_mix22.h
+++ b/sound/pci/pcxhr/pcxhr_mix22.h
@@ -32,6 +32,9 @@ int hr222_get_external_clock(struct pcxhr_mgr *mgr,
32 enum pcxhr_clock_type clock_type, 32 enum pcxhr_clock_type clock_type,
33 int *sample_rate); 33 int *sample_rate);
34 34
35int hr222_read_gpio(struct pcxhr_mgr *mgr, int is_gpi, int *value);
36int hr222_write_gpo(struct pcxhr_mgr *mgr, int value);
37
35#define HR222_LINE_PLAYBACK_LEVEL_MIN 0 /* -25.5 dB */ 38#define HR222_LINE_PLAYBACK_LEVEL_MIN 0 /* -25.5 dB */
36#define HR222_LINE_PLAYBACK_ZERO_LEVEL 51 /* 0.0 dB */ 39#define HR222_LINE_PLAYBACK_ZERO_LEVEL 51 /* 0.0 dB */
37#define HR222_LINE_PLAYBACK_LEVEL_MAX 99 /* +24.0 dB */ 40#define HR222_LINE_PLAYBACK_LEVEL_MAX 99 /* +24.0 dB */
diff --git a/sound/pci/pcxhr/pcxhr_mixer.c b/sound/pci/pcxhr/pcxhr_mixer.c
index 2436e374586f..fec049344621 100644
--- a/sound/pci/pcxhr/pcxhr_mixer.c
+++ b/sound/pci/pcxhr/pcxhr_mixer.c
@@ -789,11 +789,15 @@ static int pcxhr_clock_type_put(struct snd_kcontrol *kcontrol,
789 if (mgr->use_clock_type != ucontrol->value.enumerated.item[0]) { 789 if (mgr->use_clock_type != ucontrol->value.enumerated.item[0]) {
790 mutex_lock(&mgr->setup_mutex); 790 mutex_lock(&mgr->setup_mutex);
791 mgr->use_clock_type = ucontrol->value.enumerated.item[0]; 791 mgr->use_clock_type = ucontrol->value.enumerated.item[0];
792 if (mgr->use_clock_type) 792 rate = 0;
793 if (mgr->use_clock_type != PCXHR_CLOCK_TYPE_INTERNAL) {
793 pcxhr_get_external_clock(mgr, mgr->use_clock_type, 794 pcxhr_get_external_clock(mgr, mgr->use_clock_type,
794 &rate); 795 &rate);
795 else 796 } else {
796 rate = mgr->sample_rate; 797 rate = mgr->sample_rate;
798 if (!rate)
799 rate = 48000;
800 }
797 if (rate) { 801 if (rate) {
798 pcxhr_set_clock(mgr, rate); 802 pcxhr_set_clock(mgr, rate);
799 if (mgr->sample_rate) 803 if (mgr->sample_rate)
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index 3caacfb9d8e0..6f1034417a02 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -2102,9 +2102,9 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2102 return -ENOENT; 2102 return -ENOENT;
2103 } 2103 }
2104 2104
2105 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 2105 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2106 if (card == NULL) 2106 if (err < 0)
2107 return -ENOMEM; 2107 return err;
2108 if ((err = snd_riptide_create(card, pci, &chip)) < 0) { 2108 if ((err = snd_riptide_create(card, pci, &chip)) < 0) {
2109 snd_card_free(card); 2109 snd_card_free(card);
2110 return err; 2110 return err;
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index e7ef3a1a25a8..d7b966e7c4cf 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -1941,9 +1941,10 @@ snd_rme32_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
1941 return -ENOENT; 1941 return -ENOENT;
1942 } 1942 }
1943 1943
1944 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE, 1944 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
1945 sizeof(struct rme32))) == NULL) 1945 sizeof(struct rme32), &card);
1946 return -ENOMEM; 1946 if (err < 0)
1947 return err;
1947 card->private_free = snd_rme32_card_free; 1948 card->private_free = snd_rme32_card_free;
1948 rme32 = (struct rme32 *) card->private_data; 1949 rme32 = (struct rme32 *) card->private_data;
1949 rme32->card = card; 1950 rme32->card = card;
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index 3fdd488d0975..55fb1c131f58 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -2348,9 +2348,10 @@ snd_rme96_probe(struct pci_dev *pci,
2348 dev++; 2348 dev++;
2349 return -ENOENT; 2349 return -ENOENT;
2350 } 2350 }
2351 if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE, 2351 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
2352 sizeof(struct rme96))) == NULL) 2352 sizeof(struct rme96), &card);
2353 return -ENOMEM; 2353 if (err < 0)
2354 return err;
2354 card->private_free = snd_rme96_card_free; 2355 card->private_free = snd_rme96_card_free;
2355 rme96 = (struct rme96 *)card->private_data; 2356 rme96 = (struct rme96 *)card->private_data;
2356 rme96->card = card; 2357 rme96->card = card;
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 44d0c15e2b71..314e73531bd1 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -113,7 +113,7 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
113 113
114/* the meters are regular i/o-mapped registers, but offset 114/* the meters are regular i/o-mapped registers, but offset
115 considerably from the rest. the peak registers are reset 115 considerably from the rest. the peak registers are reset
116 when read; the least-significant 4 bits are full-scale counters; 116 when read; the least-significant 4 bits are full-scale counters;
117 the actual peak value is in the most-significant 24 bits. 117 the actual peak value is in the most-significant 24 bits.
118*/ 118*/
119 119
@@ -131,7 +131,7 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
131 26*3 values are read in ss mode 131 26*3 values are read in ss mode
132 14*3 in ds mode, with no gap between values 132 14*3 in ds mode, with no gap between values
133*/ 133*/
134#define HDSP_9652_peakBase 7164 134#define HDSP_9652_peakBase 7164
135#define HDSP_9652_rmsBase 4096 135#define HDSP_9652_rmsBase 4096
136 136
137/* c.f. the hdsp_9632_meters_t struct */ 137/* c.f. the hdsp_9632_meters_t struct */
@@ -173,12 +173,12 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
173#define HDSP_SPDIFEmphasis (1<<10) /* 0=none, 1=on */ 173#define HDSP_SPDIFEmphasis (1<<10) /* 0=none, 1=on */
174#define HDSP_SPDIFNonAudio (1<<11) /* 0=off, 1=on */ 174#define HDSP_SPDIFNonAudio (1<<11) /* 0=off, 1=on */
175#define HDSP_SPDIFOpticalOut (1<<12) /* 1=use 1st ADAT connector for SPDIF, 0=do not */ 175#define HDSP_SPDIFOpticalOut (1<<12) /* 1=use 1st ADAT connector for SPDIF, 0=do not */
176#define HDSP_SyncRef2 (1<<13) 176#define HDSP_SyncRef2 (1<<13)
177#define HDSP_SPDIFInputSelect0 (1<<14) 177#define HDSP_SPDIFInputSelect0 (1<<14)
178#define HDSP_SPDIFInputSelect1 (1<<15) 178#define HDSP_SPDIFInputSelect1 (1<<15)
179#define HDSP_SyncRef0 (1<<16) 179#define HDSP_SyncRef0 (1<<16)
180#define HDSP_SyncRef1 (1<<17) 180#define HDSP_SyncRef1 (1<<17)
181#define HDSP_AnalogExtensionBoard (1<<18) /* For H9632 cards */ 181#define HDSP_AnalogExtensionBoard (1<<18) /* For H9632 cards */
182#define HDSP_XLRBreakoutCable (1<<20) /* For H9632 cards */ 182#define HDSP_XLRBreakoutCable (1<<20) /* For H9632 cards */
183#define HDSP_Midi0InterruptEnable (1<<22) 183#define HDSP_Midi0InterruptEnable (1<<22)
184#define HDSP_Midi1InterruptEnable (1<<23) 184#define HDSP_Midi1InterruptEnable (1<<23)
@@ -314,7 +314,7 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
314#define HDSP_TimecodeSync (1<<27) 314#define HDSP_TimecodeSync (1<<27)
315#define HDSP_AEBO (1<<28) /* H9632 specific Analog Extension Boards */ 315#define HDSP_AEBO (1<<28) /* H9632 specific Analog Extension Boards */
316#define HDSP_AEBI (1<<29) /* 0 = present, 1 = absent */ 316#define HDSP_AEBI (1<<29) /* 0 = present, 1 = absent */
317#define HDSP_midi0IRQPending (1<<30) 317#define HDSP_midi0IRQPending (1<<30)
318#define HDSP_midi1IRQPending (1<<31) 318#define HDSP_midi1IRQPending (1<<31)
319 319
320#define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2) 320#define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
@@ -391,7 +391,7 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
391#define HDSP_CHANNEL_BUFFER_BYTES (4*HDSP_CHANNEL_BUFFER_SAMPLES) 391#define HDSP_CHANNEL_BUFFER_BYTES (4*HDSP_CHANNEL_BUFFER_SAMPLES)
392 392
393/* the size of the area we need to allocate for DMA transfers. the 393/* the size of the area we need to allocate for DMA transfers. the
394 size is the same regardless of the number of channels - the 394 size is the same regardless of the number of channels - the
395 Multiface still uses the same memory area. 395 Multiface still uses the same memory area.
396 396
397 Note that we allocate 1 more channel than is apparently needed 397 Note that we allocate 1 more channel than is apparently needed
@@ -460,7 +460,7 @@ struct hdsp {
460 unsigned char qs_in_channels; /* quad speed mode for H9632 */ 460 unsigned char qs_in_channels; /* quad speed mode for H9632 */
461 unsigned char ds_in_channels; 461 unsigned char ds_in_channels;
462 unsigned char ss_in_channels; /* different for multiface/digiface */ 462 unsigned char ss_in_channels; /* different for multiface/digiface */
463 unsigned char qs_out_channels; 463 unsigned char qs_out_channels;
464 unsigned char ds_out_channels; 464 unsigned char ds_out_channels;
465 unsigned char ss_out_channels; 465 unsigned char ss_out_channels;
466 466
@@ -502,9 +502,9 @@ static char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
502 502
503static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */ 503static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
504 /* Analog */ 504 /* Analog */
505 0, 1, 2, 3, 4, 5, 6, 7, 505 0, 1, 2, 3, 4, 5, 6, 7,
506 /* ADAT 2 */ 506 /* ADAT 2 */
507 16, 17, 18, 19, 20, 21, 22, 23, 507 16, 17, 18, 19, 20, 21, 22, 23,
508 /* SPDIF */ 508 /* SPDIF */
509 24, 25, 509 24, 25,
510 -1, -1, -1, -1, -1, -1, -1, -1 510 -1, -1, -1, -1, -1, -1, -1, -1
@@ -525,11 +525,11 @@ static char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
525 /* SPDIF */ 525 /* SPDIF */
526 8, 9, 526 8, 9,
527 /* Analog */ 527 /* Analog */
528 10, 11, 528 10, 11,
529 /* AO4S-192 and AI4S-192 extension boards */ 529 /* AO4S-192 and AI4S-192 extension boards */
530 12, 13, 14, 15, 530 12, 13, 14, 15,
531 /* others don't exist */ 531 /* others don't exist */
532 -1, -1, -1, -1, -1, -1, -1, -1, 532 -1, -1, -1, -1, -1, -1, -1, -1,
533 -1, -1 533 -1, -1
534}; 534};
535 535
@@ -539,7 +539,7 @@ static char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
539 /* SPDIF */ 539 /* SPDIF */
540 8, 9, 540 8, 9,
541 /* Analog */ 541 /* Analog */
542 10, 11, 542 10, 11,
543 /* AO4S-192 and AI4S-192 extension boards */ 543 /* AO4S-192 and AI4S-192 extension boards */
544 12, 13, 14, 15, 544 12, 13, 14, 15,
545 /* others don't exist */ 545 /* others don't exist */
@@ -587,7 +587,7 @@ static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_d
587static struct pci_device_id snd_hdsp_ids[] = { 587static struct pci_device_id snd_hdsp_ids[] = {
588 { 588 {
589 .vendor = PCI_VENDOR_ID_XILINX, 589 .vendor = PCI_VENDOR_ID_XILINX,
590 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP, 590 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
591 .subvendor = PCI_ANY_ID, 591 .subvendor = PCI_ANY_ID,
592 .subdevice = PCI_ANY_ID, 592 .subdevice = PCI_ANY_ID,
593 }, /* RME Hammerfall-DSP */ 593 }, /* RME Hammerfall-DSP */
@@ -653,7 +653,6 @@ static unsigned int hdsp_read(struct hdsp *hdsp, int reg)
653 653
654static int hdsp_check_for_iobox (struct hdsp *hdsp) 654static int hdsp_check_for_iobox (struct hdsp *hdsp)
655{ 655{
656
657 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0; 656 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
658 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) { 657 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
659 snd_printk ("Hammerfall-DSP: no Digiface or Multiface connected!\n"); 658 snd_printk ("Hammerfall-DSP: no Digiface or Multiface connected!\n");
@@ -661,7 +660,29 @@ static int hdsp_check_for_iobox (struct hdsp *hdsp)
661 return -EIO; 660 return -EIO;
662 } 661 }
663 return 0; 662 return 0;
663}
664 664
665static int hdsp_wait_for_iobox(struct hdsp *hdsp, unsigned int loops,
666 unsigned int delay)
667{
668 unsigned int i;
669
670 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
671 return 0;
672
673 for (i = 0; i != loops; ++i) {
674 if (hdsp_read(hdsp, HDSP_statusRegister) & HDSP_ConfigError)
675 msleep(delay);
676 else {
677 snd_printd("Hammerfall-DSP: iobox found after %ums!\n",
678 i * delay);
679 return 0;
680 }
681 }
682
683 snd_printk("Hammerfall-DSP: no Digiface or Multiface connected!\n");
684 hdsp->state &= ~HDSP_FirmwareLoaded;
685 return -EIO;
665} 686}
666 687
667static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) { 688static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
@@ -670,19 +691,19 @@ static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
670 unsigned long flags; 691 unsigned long flags;
671 692
672 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { 693 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
673 694
674 snd_printk ("Hammerfall-DSP: loading firmware\n"); 695 snd_printk ("Hammerfall-DSP: loading firmware\n");
675 696
676 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM); 697 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
677 hdsp_write (hdsp, HDSP_fifoData, 0); 698 hdsp_write (hdsp, HDSP_fifoData, 0);
678 699
679 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) { 700 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
680 snd_printk ("Hammerfall-DSP: timeout waiting for download preparation\n"); 701 snd_printk ("Hammerfall-DSP: timeout waiting for download preparation\n");
681 return -EIO; 702 return -EIO;
682 } 703 }
683 704
684 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD); 705 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
685 706
686 for (i = 0; i < 24413; ++i) { 707 for (i = 0; i < 24413; ++i) {
687 hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]); 708 hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);
688 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) { 709 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
@@ -692,7 +713,7 @@ static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
692 } 713 }
693 714
694 ssleep(3); 715 ssleep(3);
695 716
696 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) { 717 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
697 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n"); 718 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n");
698 return -EIO; 719 return -EIO;
@@ -705,15 +726,15 @@ static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
705#endif 726#endif
706 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register); 727 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
707 snd_printk ("Hammerfall-DSP: finished firmware loading\n"); 728 snd_printk ("Hammerfall-DSP: finished firmware loading\n");
708 729
709 } 730 }
710 if (hdsp->state & HDSP_InitializationComplete) { 731 if (hdsp->state & HDSP_InitializationComplete) {
711 snd_printk(KERN_INFO "Hammerfall-DSP: firmware loaded from cache, restoring defaults\n"); 732 snd_printk(KERN_INFO "Hammerfall-DSP: firmware loaded from cache, restoring defaults\n");
712 spin_lock_irqsave(&hdsp->lock, flags); 733 spin_lock_irqsave(&hdsp->lock, flags);
713 snd_hdsp_set_defaults(hdsp); 734 snd_hdsp_set_defaults(hdsp);
714 spin_unlock_irqrestore(&hdsp->lock, flags); 735 spin_unlock_irqrestore(&hdsp->lock, flags);
715 } 736 }
716 737
717 hdsp->state |= HDSP_FirmwareLoaded; 738 hdsp->state |= HDSP_FirmwareLoaded;
718 739
719 return 0; 740 return 0;
@@ -722,7 +743,7 @@ static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
722static int hdsp_get_iobox_version (struct hdsp *hdsp) 743static int hdsp_get_iobox_version (struct hdsp *hdsp)
723{ 744{
724 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) { 745 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
725 746
726 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM); 747 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
727 hdsp_write (hdsp, HDSP_fifoData, 0); 748 hdsp_write (hdsp, HDSP_fifoData, 0);
728 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) 749 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0)
@@ -738,7 +759,7 @@ static int hdsp_get_iobox_version (struct hdsp *hdsp)
738 hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT); 759 hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
739 } else { 760 } else {
740 hdsp->io_type = Digiface; 761 hdsp->io_type = Digiface;
741 } 762 }
742 } else { 763 } else {
743 /* firmware was already loaded, get iobox type */ 764 /* firmware was already loaded, get iobox type */
744 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) 765 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
@@ -786,13 +807,13 @@ static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand)
786 807
787 808
788static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout) 809static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout)
789{ 810{
790 int i; 811 int i;
791 812
792 /* the fifoStatus registers reports on how many words 813 /* the fifoStatus registers reports on how many words
793 are available in the command FIFO. 814 are available in the command FIFO.
794 */ 815 */
795 816
796 for (i = 0; i < timeout; i++) { 817 for (i = 0; i < timeout; i++) {
797 818
798 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count) 819 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
@@ -824,11 +845,11 @@ static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned short
824 845
825 if (addr >= HDSP_MATRIX_MIXER_SIZE) 846 if (addr >= HDSP_MATRIX_MIXER_SIZE)
826 return -1; 847 return -1;
827 848
828 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) { 849 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
829 850
830 /* from martin bjornsen: 851 /* from martin bjornsen:
831 852
832 "You can only write dwords to the 853 "You can only write dwords to the
833 mixer memory which contain two 854 mixer memory which contain two
834 mixer values in the low and high 855 mixer values in the low and high
@@ -847,7 +868,7 @@ static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned short
847 868
848 hdsp->mixer_matrix[addr] = data; 869 hdsp->mixer_matrix[addr] = data;
849 870
850 871
851 /* `addr' addresses a 16-bit wide address, but 872 /* `addr' addresses a 16-bit wide address, but
852 the address space accessed via hdsp_write 873 the address space accessed via hdsp_write
853 uses byte offsets. put another way, addr 874 uses byte offsets. put another way, addr
@@ -856,17 +877,17 @@ static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned short
856 to access 0 to 2703 ... 877 to access 0 to 2703 ...
857 */ 878 */
858 ad = addr/2; 879 ad = addr/2;
859 880
860 hdsp_write (hdsp, 4096 + (ad*4), 881 hdsp_write (hdsp, 4096 + (ad*4),
861 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) + 882 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
862 hdsp->mixer_matrix[addr&0x7fe]); 883 hdsp->mixer_matrix[addr&0x7fe]);
863 884
864 return 0; 885 return 0;
865 886
866 } else { 887 } else {
867 888
868 ad = (addr << 16) + data; 889 ad = (addr << 16) + data;
869 890
870 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) 891 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT))
871 return -1; 892 return -1;
872 893
@@ -902,7 +923,7 @@ static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
902 923
903 if (status & HDSP_SPDIFErrorFlag) 924 if (status & HDSP_SPDIFErrorFlag)
904 return 0; 925 return 0;
905 926
906 switch (rate_bits) { 927 switch (rate_bits) {
907 case HDSP_spdifFrequency32KHz: return 32000; 928 case HDSP_spdifFrequency32KHz: return 32000;
908 case HDSP_spdifFrequency44_1KHz: return 44100; 929 case HDSP_spdifFrequency44_1KHz: return 44100;
@@ -910,13 +931,13 @@ static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
910 case HDSP_spdifFrequency64KHz: return 64000; 931 case HDSP_spdifFrequency64KHz: return 64000;
911 case HDSP_spdifFrequency88_2KHz: return 88200; 932 case HDSP_spdifFrequency88_2KHz: return 88200;
912 case HDSP_spdifFrequency96KHz: return 96000; 933 case HDSP_spdifFrequency96KHz: return 96000;
913 case HDSP_spdifFrequency128KHz: 934 case HDSP_spdifFrequency128KHz:
914 if (hdsp->io_type == H9632) return 128000; 935 if (hdsp->io_type == H9632) return 128000;
915 break; 936 break;
916 case HDSP_spdifFrequency176_4KHz: 937 case HDSP_spdifFrequency176_4KHz:
917 if (hdsp->io_type == H9632) return 176400; 938 if (hdsp->io_type == H9632) return 176400;
918 break; 939 break;
919 case HDSP_spdifFrequency192KHz: 940 case HDSP_spdifFrequency192KHz:
920 if (hdsp->io_type == H9632) return 192000; 941 if (hdsp->io_type == H9632) return 192000;
921 break; 942 break;
922 default: 943 default:
@@ -1027,7 +1048,7 @@ static void hdsp_set_dds_value(struct hdsp *hdsp, int rate)
1027{ 1048{
1028 u64 n; 1049 u64 n;
1029 u32 r; 1050 u32 r;
1030 1051
1031 if (rate >= 112000) 1052 if (rate >= 112000)
1032 rate /= 4; 1053 rate /= 4;
1033 else if (rate >= 56000) 1054 else if (rate >= 56000)
@@ -1053,35 +1074,35 @@ static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1053 there is no need for it (e.g. during module 1074 there is no need for it (e.g. during module
1054 initialization). 1075 initialization).
1055 */ 1076 */
1056 1077
1057 if (!(hdsp->control_register & HDSP_ClockModeMaster)) { 1078 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
1058 if (called_internally) { 1079 if (called_internally) {
1059 /* request from ctl or card initialization */ 1080 /* request from ctl or card initialization */
1060 snd_printk(KERN_ERR "Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n"); 1081 snd_printk(KERN_ERR "Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n");
1061 return -1; 1082 return -1;
1062 } else { 1083 } else {
1063 /* hw_param request while in AutoSync mode */ 1084 /* hw_param request while in AutoSync mode */
1064 int external_freq = hdsp_external_sample_rate(hdsp); 1085 int external_freq = hdsp_external_sample_rate(hdsp);
1065 int spdif_freq = hdsp_spdif_sample_rate(hdsp); 1086 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1066 1087
1067 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) 1088 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1068 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in double speed mode\n"); 1089 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in double speed mode\n");
1069 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) 1090 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1070 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in quad speed mode\n"); 1091 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in quad speed mode\n");
1071 else if (rate != external_freq) { 1092 else if (rate != external_freq) {
1072 snd_printk(KERN_INFO "Hammerfall-DSP: No AutoSync source for requested rate\n"); 1093 snd_printk(KERN_INFO "Hammerfall-DSP: No AutoSync source for requested rate\n");
1073 return -1; 1094 return -1;
1074 } 1095 }
1075 } 1096 }
1076 } 1097 }
1077 1098
1078 current_rate = hdsp->system_sample_rate; 1099 current_rate = hdsp->system_sample_rate;
1079 1100
1080 /* Changing from a "single speed" to a "double speed" rate is 1101 /* Changing from a "single speed" to a "double speed" rate is
1081 not allowed if any substreams are open. This is because 1102 not allowed if any substreams are open. This is because
1082 such a change causes a shift in the location of 1103 such a change causes a shift in the location of
1083 the DMA buffers and a reduction in the number of available 1104 the DMA buffers and a reduction in the number of available
1084 buffers. 1105 buffers.
1085 1106
1086 Note that a similar but essentially insoluble problem 1107 Note that a similar but essentially insoluble problem
1087 exists for externally-driven rate changes. All we can do 1108 exists for externally-driven rate changes. All we can do
@@ -1089,7 +1110,7 @@ static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1089 1110
1090 if (rate > 96000 && hdsp->io_type != H9632) 1111 if (rate > 96000 && hdsp->io_type != H9632)
1091 return -EINVAL; 1112 return -EINVAL;
1092 1113
1093 switch (rate) { 1114 switch (rate) {
1094 case 32000: 1115 case 32000:
1095 if (current_rate > 48000) 1116 if (current_rate > 48000)
@@ -1179,7 +1200,7 @@ static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1179 break; 1200 break;
1180 } 1201 }
1181 } 1202 }
1182 1203
1183 hdsp->system_sample_rate = rate; 1204 hdsp->system_sample_rate = rate;
1184 1205
1185 return 0; 1206 return 0;
@@ -1245,16 +1266,16 @@ static int snd_hdsp_midi_output_write (struct hdsp_midi *hmidi)
1245 unsigned char buf[128]; 1266 unsigned char buf[128];
1246 1267
1247 /* Output is not interrupt driven */ 1268 /* Output is not interrupt driven */
1248 1269
1249 spin_lock_irqsave (&hmidi->lock, flags); 1270 spin_lock_irqsave (&hmidi->lock, flags);
1250 if (hmidi->output) { 1271 if (hmidi->output) {
1251 if (!snd_rawmidi_transmit_empty (hmidi->output)) { 1272 if (!snd_rawmidi_transmit_empty (hmidi->output)) {
1252 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) { 1273 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
1253 if (n_pending > (int)sizeof (buf)) 1274 if (n_pending > (int)sizeof (buf))
1254 n_pending = sizeof (buf); 1275 n_pending = sizeof (buf);
1255 1276
1256 if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) { 1277 if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) {
1257 for (i = 0; i < to_write; ++i) 1278 for (i = 0; i < to_write; ++i)
1258 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]); 1279 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1259 } 1280 }
1260 } 1281 }
@@ -1325,14 +1346,14 @@ static void snd_hdsp_midi_output_timer(unsigned long data)
1325{ 1346{
1326 struct hdsp_midi *hmidi = (struct hdsp_midi *) data; 1347 struct hdsp_midi *hmidi = (struct hdsp_midi *) data;
1327 unsigned long flags; 1348 unsigned long flags;
1328 1349
1329 snd_hdsp_midi_output_write(hmidi); 1350 snd_hdsp_midi_output_write(hmidi);
1330 spin_lock_irqsave (&hmidi->lock, flags); 1351 spin_lock_irqsave (&hmidi->lock, flags);
1331 1352
1332 /* this does not bump hmidi->istimer, because the 1353 /* this does not bump hmidi->istimer, because the
1333 kernel automatically removed the timer when it 1354 kernel automatically removed the timer when it
1334 expired, and we are now adding it back, thus 1355 expired, and we are now adding it back, thus
1335 leaving istimer wherever it was set before. 1356 leaving istimer wherever it was set before.
1336 */ 1357 */
1337 1358
1338 if (hmidi->istimer) { 1359 if (hmidi->istimer) {
@@ -1501,7 +1522,7 @@ static int snd_hdsp_control_spdif_info(struct snd_kcontrol *kcontrol, struct snd
1501static int snd_hdsp_control_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1522static int snd_hdsp_control_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1502{ 1523{
1503 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1524 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1504 1525
1505 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif); 1526 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1506 return 0; 1527 return 0;
1507} 1528}
@@ -1511,7 +1532,7 @@ static int snd_hdsp_control_spdif_put(struct snd_kcontrol *kcontrol, struct snd_
1511 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1532 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1512 int change; 1533 int change;
1513 u32 val; 1534 u32 val;
1514 1535
1515 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958); 1536 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1516 spin_lock_irq(&hdsp->lock); 1537 spin_lock_irq(&hdsp->lock);
1517 change = val != hdsp->creg_spdif; 1538 change = val != hdsp->creg_spdif;
@@ -1530,7 +1551,7 @@ static int snd_hdsp_control_spdif_stream_info(struct snd_kcontrol *kcontrol, str
1530static int snd_hdsp_control_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1551static int snd_hdsp_control_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1531{ 1552{
1532 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1553 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1533 1554
1534 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream); 1555 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1535 return 0; 1556 return 0;
1536} 1557}
@@ -1540,7 +1561,7 @@ static int snd_hdsp_control_spdif_stream_put(struct snd_kcontrol *kcontrol, stru
1540 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1561 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1541 int change; 1562 int change;
1542 u32 val; 1563 u32 val;
1543 1564
1544 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958); 1565 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1545 spin_lock_irq(&hdsp->lock); 1566 spin_lock_irq(&hdsp->lock);
1546 change = val != hdsp->creg_spdif_stream; 1567 change = val != hdsp->creg_spdif_stream;
@@ -1602,7 +1623,7 @@ static int snd_hdsp_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_
1602static int snd_hdsp_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1623static int snd_hdsp_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1603{ 1624{
1604 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1625 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1605 1626
1606 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp); 1627 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1607 return 0; 1628 return 0;
1608} 1629}
@@ -1612,7 +1633,7 @@ static int snd_hdsp_put_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_e
1612 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1633 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1613 int change; 1634 int change;
1614 unsigned int val; 1635 unsigned int val;
1615 1636
1616 if (!snd_hdsp_use_is_exclusive(hdsp)) 1637 if (!snd_hdsp_use_is_exclusive(hdsp))
1617 return -EBUSY; 1638 return -EBUSY;
1618 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3); 1639 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
@@ -1649,7 +1670,7 @@ static int hdsp_set_spdif_output(struct hdsp *hdsp, int out)
1649static int snd_hdsp_get_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1670static int snd_hdsp_get_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1650{ 1671{
1651 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1672 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1652 1673
1653 ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp); 1674 ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
1654 return 0; 1675 return 0;
1655} 1676}
@@ -1659,7 +1680,7 @@ static int snd_hdsp_put_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_
1659 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1680 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1660 int change; 1681 int change;
1661 unsigned int val; 1682 unsigned int val;
1662 1683
1663 if (!snd_hdsp_use_is_exclusive(hdsp)) 1684 if (!snd_hdsp_use_is_exclusive(hdsp))
1664 return -EBUSY; 1685 return -EBUSY;
1665 val = ucontrol->value.integer.value[0] & 1; 1686 val = ucontrol->value.integer.value[0] & 1;
@@ -1693,7 +1714,7 @@ static int hdsp_set_spdif_professional(struct hdsp *hdsp, int val)
1693static int snd_hdsp_get_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1714static int snd_hdsp_get_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1694{ 1715{
1695 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1716 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1696 1717
1697 ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp); 1718 ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
1698 return 0; 1719 return 0;
1699} 1720}
@@ -1703,7 +1724,7 @@ static int snd_hdsp_put_spdif_professional(struct snd_kcontrol *kcontrol, struct
1703 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1724 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1704 int change; 1725 int change;
1705 unsigned int val; 1726 unsigned int val;
1706 1727
1707 if (!snd_hdsp_use_is_exclusive(hdsp)) 1728 if (!snd_hdsp_use_is_exclusive(hdsp))
1708 return -EBUSY; 1729 return -EBUSY;
1709 val = ucontrol->value.integer.value[0] & 1; 1730 val = ucontrol->value.integer.value[0] & 1;
@@ -1737,7 +1758,7 @@ static int hdsp_set_spdif_emphasis(struct hdsp *hdsp, int val)
1737static int snd_hdsp_get_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1758static int snd_hdsp_get_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1738{ 1759{
1739 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1760 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1740 1761
1741 ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp); 1762 ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
1742 return 0; 1763 return 0;
1743} 1764}
@@ -1747,7 +1768,7 @@ static int snd_hdsp_put_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd
1747 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1768 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1748 int change; 1769 int change;
1749 unsigned int val; 1770 unsigned int val;
1750 1771
1751 if (!snd_hdsp_use_is_exclusive(hdsp)) 1772 if (!snd_hdsp_use_is_exclusive(hdsp))
1752 return -EBUSY; 1773 return -EBUSY;
1753 val = ucontrol->value.integer.value[0] & 1; 1774 val = ucontrol->value.integer.value[0] & 1;
@@ -1781,7 +1802,7 @@ static int hdsp_set_spdif_nonaudio(struct hdsp *hdsp, int val)
1781static int snd_hdsp_get_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1802static int snd_hdsp_get_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1782{ 1803{
1783 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1804 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1784 1805
1785 ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp); 1806 ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
1786 return 0; 1807 return 0;
1787} 1808}
@@ -1791,7 +1812,7 @@ static int snd_hdsp_put_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd
1791 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1812 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1792 int change; 1813 int change;
1793 unsigned int val; 1814 unsigned int val;
1794 1815
1795 if (!snd_hdsp_use_is_exclusive(hdsp)) 1816 if (!snd_hdsp_use_is_exclusive(hdsp))
1796 return -EBUSY; 1817 return -EBUSY;
1797 val = ucontrol->value.integer.value[0] & 1; 1818 val = ucontrol->value.integer.value[0] & 1;
@@ -1828,7 +1849,7 @@ static int snd_hdsp_info_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct
1828static int snd_hdsp_get_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1849static int snd_hdsp_get_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1829{ 1850{
1830 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1851 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1831 1852
1832 switch (hdsp_spdif_sample_rate(hdsp)) { 1853 switch (hdsp_spdif_sample_rate(hdsp)) {
1833 case 32000: 1854 case 32000:
1834 ucontrol->value.enumerated.item[0] = 0; 1855 ucontrol->value.enumerated.item[0] = 0;
@@ -1858,7 +1879,7 @@ static int snd_hdsp_get_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct
1858 ucontrol->value.enumerated.item[0] = 9; 1879 ucontrol->value.enumerated.item[0] = 9;
1859 break; 1880 break;
1860 default: 1881 default:
1861 ucontrol->value.enumerated.item[0] = 6; 1882 ucontrol->value.enumerated.item[0] = 6;
1862 } 1883 }
1863 return 0; 1884 return 0;
1864} 1885}
@@ -1882,7 +1903,7 @@ static int snd_hdsp_info_system_sample_rate(struct snd_kcontrol *kcontrol, struc
1882static int snd_hdsp_get_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1903static int snd_hdsp_get_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1883{ 1904{
1884 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1905 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1885 1906
1886 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate; 1907 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1887 return 0; 1908 return 0;
1888} 1909}
@@ -1899,7 +1920,7 @@ static int snd_hdsp_get_system_sample_rate(struct snd_kcontrol *kcontrol, struct
1899static int snd_hdsp_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1920static int snd_hdsp_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1900{ 1921{
1901 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1922 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1902 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"}; 1923 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1903 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1924 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1904 uinfo->count = 1; 1925 uinfo->count = 1;
1905 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ; 1926 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ;
@@ -1912,7 +1933,7 @@ static int snd_hdsp_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, str
1912static int snd_hdsp_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1933static int snd_hdsp_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1913{ 1934{
1914 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 1935 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1915 1936
1916 switch (hdsp_external_sample_rate(hdsp)) { 1937 switch (hdsp_external_sample_rate(hdsp)) {
1917 case 32000: 1938 case 32000:
1918 ucontrol->value.enumerated.item[0] = 0; 1939 ucontrol->value.enumerated.item[0] = 0;
@@ -1940,9 +1961,9 @@ static int snd_hdsp_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, stru
1940 break; 1961 break;
1941 case 192000: 1962 case 192000:
1942 ucontrol->value.enumerated.item[0] = 9; 1963 ucontrol->value.enumerated.item[0] = 9;
1943 break; 1964 break;
1944 default: 1965 default:
1945 ucontrol->value.enumerated.item[0] = 6; 1966 ucontrol->value.enumerated.item[0] = 6;
1946 } 1967 }
1947 return 0; 1968 return 0;
1948} 1969}
@@ -1968,7 +1989,7 @@ static int hdsp_system_clock_mode(struct hdsp *hdsp)
1968static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 1989static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1969{ 1990{
1970 static char *texts[] = {"Master", "Slave" }; 1991 static char *texts[] = {"Master", "Slave" };
1971 1992
1972 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1993 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1973 uinfo->count = 1; 1994 uinfo->count = 1;
1974 uinfo->value.enumerated.items = 2; 1995 uinfo->value.enumerated.items = 2;
@@ -1981,7 +2002,7 @@ static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct
1981static int snd_hdsp_get_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2002static int snd_hdsp_get_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1982{ 2003{
1983 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2004 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1984 2005
1985 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp); 2006 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
1986 return 0; 2007 return 0;
1987} 2008}
@@ -2018,7 +2039,7 @@ static int hdsp_clock_source(struct hdsp *hdsp)
2018 case 192000: 2039 case 192000:
2019 return 9; 2040 return 9;
2020 default: 2041 default:
2021 return 3; 2042 return 3;
2022 } 2043 }
2023 } else { 2044 } else {
2024 return 0; 2045 return 0;
@@ -2032,7 +2053,7 @@ static int hdsp_set_clock_source(struct hdsp *hdsp, int mode)
2032 case HDSP_CLOCK_SOURCE_AUTOSYNC: 2053 case HDSP_CLOCK_SOURCE_AUTOSYNC:
2033 if (hdsp_external_sample_rate(hdsp) != 0) { 2054 if (hdsp_external_sample_rate(hdsp) != 0) {
2034 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) { 2055 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
2035 hdsp->control_register &= ~HDSP_ClockModeMaster; 2056 hdsp->control_register &= ~HDSP_ClockModeMaster;
2036 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 2057 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2037 return 0; 2058 return 0;
2038 } 2059 }
@@ -2043,7 +2064,7 @@ static int hdsp_set_clock_source(struct hdsp *hdsp, int mode)
2043 break; 2064 break;
2044 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ: 2065 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
2045 rate = 44100; 2066 rate = 44100;
2046 break; 2067 break;
2047 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ: 2068 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
2048 rate = 48000; 2069 rate = 48000;
2049 break; 2070 break;
@@ -2078,13 +2099,13 @@ static int snd_hdsp_info_clock_source(struct snd_kcontrol *kcontrol, struct snd_
2078{ 2099{
2079 static char *texts[] = {"AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz", "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz", "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz", "Internal 192.0 KHz" }; 2100 static char *texts[] = {"AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz", "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz", "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz", "Internal 192.0 KHz" };
2080 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2101 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2081 2102
2082 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2103 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2083 uinfo->count = 1; 2104 uinfo->count = 1;
2084 if (hdsp->io_type == H9632) 2105 if (hdsp->io_type == H9632)
2085 uinfo->value.enumerated.items = 10; 2106 uinfo->value.enumerated.items = 10;
2086 else 2107 else
2087 uinfo->value.enumerated.items = 7; 2108 uinfo->value.enumerated.items = 7;
2088 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2109 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2089 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 2110 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2090 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2111 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
@@ -2094,7 +2115,7 @@ static int snd_hdsp_info_clock_source(struct snd_kcontrol *kcontrol, struct snd_
2094static int snd_hdsp_get_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2115static int snd_hdsp_get_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2095{ 2116{
2096 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2117 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2097 2118
2098 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp); 2119 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2099 return 0; 2120 return 0;
2100} 2121}
@@ -2104,7 +2125,7 @@ static int snd_hdsp_put_clock_source(struct snd_kcontrol *kcontrol, struct snd_c
2104 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2125 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2105 int change; 2126 int change;
2106 int val; 2127 int val;
2107 2128
2108 if (!snd_hdsp_use_is_exclusive(hdsp)) 2129 if (!snd_hdsp_use_is_exclusive(hdsp))
2109 return -EBUSY; 2130 return -EBUSY;
2110 val = ucontrol->value.enumerated.item[0]; 2131 val = ucontrol->value.enumerated.item[0];
@@ -2130,7 +2151,7 @@ static int snd_hdsp_put_clock_source(struct snd_kcontrol *kcontrol, struct snd_c
2130static int snd_hdsp_get_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2151static int snd_hdsp_get_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2131{ 2152{
2132 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2153 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2133 2154
2134 ucontrol->value.integer.value[0] = hdsp->clock_source_locked; 2155 ucontrol->value.integer.value[0] = hdsp->clock_source_locked;
2135 return 0; 2156 return 0;
2136} 2157}
@@ -2165,7 +2186,7 @@ static int hdsp_da_gain(struct hdsp *hdsp)
2165 case HDSP_DAGainMinus10dBV: 2186 case HDSP_DAGainMinus10dBV:
2166 return 2; 2187 return 2;
2167 default: 2188 default:
2168 return 1; 2189 return 1;
2169 } 2190 }
2170} 2191}
2171 2192
@@ -2180,8 +2201,8 @@ static int hdsp_set_da_gain(struct hdsp *hdsp, int mode)
2180 hdsp->control_register |= HDSP_DAGainPlus4dBu; 2201 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2181 break; 2202 break;
2182 case 2: 2203 case 2:
2183 hdsp->control_register |= HDSP_DAGainMinus10dBV; 2204 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2184 break; 2205 break;
2185 default: 2206 default:
2186 return -1; 2207 return -1;
2187 2208
@@ -2193,7 +2214,7 @@ static int hdsp_set_da_gain(struct hdsp *hdsp, int mode)
2193static int snd_hdsp_info_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2214static int snd_hdsp_info_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2194{ 2215{
2195 static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"}; 2216 static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
2196 2217
2197 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2218 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2198 uinfo->count = 1; 2219 uinfo->count = 1;
2199 uinfo->value.enumerated.items = 3; 2220 uinfo->value.enumerated.items = 3;
@@ -2206,7 +2227,7 @@ static int snd_hdsp_info_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_e
2206static int snd_hdsp_get_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2227static int snd_hdsp_get_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2207{ 2228{
2208 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2229 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2209 2230
2210 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp); 2231 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2211 return 0; 2232 return 0;
2212} 2233}
@@ -2216,7 +2237,7 @@ static int snd_hdsp_put_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_el
2216 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2237 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2217 int change; 2238 int change;
2218 int val; 2239 int val;
2219 2240
2220 if (!snd_hdsp_use_is_exclusive(hdsp)) 2241 if (!snd_hdsp_use_is_exclusive(hdsp))
2221 return -EBUSY; 2242 return -EBUSY;
2222 val = ucontrol->value.enumerated.item[0]; 2243 val = ucontrol->value.enumerated.item[0];
@@ -2250,7 +2271,7 @@ static int hdsp_ad_gain(struct hdsp *hdsp)
2250 case HDSP_ADGainLowGain: 2271 case HDSP_ADGainLowGain:
2251 return 2; 2272 return 2;
2252 default: 2273 default:
2253 return 1; 2274 return 1;
2254 } 2275 }
2255} 2276}
2256 2277
@@ -2262,11 +2283,11 @@ static int hdsp_set_ad_gain(struct hdsp *hdsp, int mode)
2262 hdsp->control_register |= HDSP_ADGainMinus10dBV; 2283 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2263 break; 2284 break;
2264 case 1: 2285 case 1:
2265 hdsp->control_register |= HDSP_ADGainPlus4dBu; 2286 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2266 break; 2287 break;
2267 case 2: 2288 case 2:
2268 hdsp->control_register |= HDSP_ADGainLowGain; 2289 hdsp->control_register |= HDSP_ADGainLowGain;
2269 break; 2290 break;
2270 default: 2291 default:
2271 return -1; 2292 return -1;
2272 2293
@@ -2278,7 +2299,7 @@ static int hdsp_set_ad_gain(struct hdsp *hdsp, int mode)
2278static int snd_hdsp_info_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2299static int snd_hdsp_info_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2279{ 2300{
2280 static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"}; 2301 static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
2281 2302
2282 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2303 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2283 uinfo->count = 1; 2304 uinfo->count = 1;
2284 uinfo->value.enumerated.items = 3; 2305 uinfo->value.enumerated.items = 3;
@@ -2291,7 +2312,7 @@ static int snd_hdsp_info_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_e
2291static int snd_hdsp_get_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2312static int snd_hdsp_get_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2292{ 2313{
2293 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2314 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2294 2315
2295 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp); 2316 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2296 return 0; 2317 return 0;
2297} 2318}
@@ -2301,7 +2322,7 @@ static int snd_hdsp_put_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_el
2301 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2322 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2302 int change; 2323 int change;
2303 int val; 2324 int val;
2304 2325
2305 if (!snd_hdsp_use_is_exclusive(hdsp)) 2326 if (!snd_hdsp_use_is_exclusive(hdsp))
2306 return -EBUSY; 2327 return -EBUSY;
2307 val = ucontrol->value.enumerated.item[0]; 2328 val = ucontrol->value.enumerated.item[0];
@@ -2335,7 +2356,7 @@ static int hdsp_phone_gain(struct hdsp *hdsp)
2335 case HDSP_PhoneGainMinus12dB: 2356 case HDSP_PhoneGainMinus12dB:
2336 return 2; 2357 return 2;
2337 default: 2358 default:
2338 return 0; 2359 return 0;
2339 } 2360 }
2340} 2361}
2341 2362
@@ -2347,11 +2368,11 @@ static int hdsp_set_phone_gain(struct hdsp *hdsp, int mode)
2347 hdsp->control_register |= HDSP_PhoneGain0dB; 2368 hdsp->control_register |= HDSP_PhoneGain0dB;
2348 break; 2369 break;
2349 case 1: 2370 case 1:
2350 hdsp->control_register |= HDSP_PhoneGainMinus6dB; 2371 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2351 break; 2372 break;
2352 case 2: 2373 case 2:
2353 hdsp->control_register |= HDSP_PhoneGainMinus12dB; 2374 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2354 break; 2375 break;
2355 default: 2376 default:
2356 return -1; 2377 return -1;
2357 2378
@@ -2363,7 +2384,7 @@ static int hdsp_set_phone_gain(struct hdsp *hdsp, int mode)
2363static int snd_hdsp_info_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2384static int snd_hdsp_info_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2364{ 2385{
2365 static char *texts[] = {"0 dB", "-6 dB", "-12 dB"}; 2386 static char *texts[] = {"0 dB", "-6 dB", "-12 dB"};
2366 2387
2367 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2388 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2368 uinfo->count = 1; 2389 uinfo->count = 1;
2369 uinfo->value.enumerated.items = 3; 2390 uinfo->value.enumerated.items = 3;
@@ -2376,7 +2397,7 @@ static int snd_hdsp_info_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ct
2376static int snd_hdsp_get_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2397static int snd_hdsp_get_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2377{ 2398{
2378 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2399 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2379 2400
2380 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp); 2401 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2381 return 0; 2402 return 0;
2382} 2403}
@@ -2386,7 +2407,7 @@ static int snd_hdsp_put_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl
2386 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2407 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2387 int change; 2408 int change;
2388 int val; 2409 int val;
2389 2410
2390 if (!snd_hdsp_use_is_exclusive(hdsp)) 2411 if (!snd_hdsp_use_is_exclusive(hdsp))
2391 return -EBUSY; 2412 return -EBUSY;
2392 val = ucontrol->value.enumerated.item[0]; 2413 val = ucontrol->value.enumerated.item[0];
@@ -2432,7 +2453,7 @@ static int hdsp_set_xlr_breakout_cable(struct hdsp *hdsp, int mode)
2432static int snd_hdsp_get_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2453static int snd_hdsp_get_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2433{ 2454{
2434 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2455 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2435 2456
2436 ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp); 2457 ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
2437 return 0; 2458 return 0;
2438} 2459}
@@ -2442,7 +2463,7 @@ static int snd_hdsp_put_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct
2442 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2463 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2443 int change; 2464 int change;
2444 int val; 2465 int val;
2445 2466
2446 if (!snd_hdsp_use_is_exclusive(hdsp)) 2467 if (!snd_hdsp_use_is_exclusive(hdsp))
2447 return -EBUSY; 2468 return -EBUSY;
2448 val = ucontrol->value.integer.value[0] & 1; 2469 val = ucontrol->value.integer.value[0] & 1;
@@ -2488,7 +2509,7 @@ static int hdsp_set_aeb(struct hdsp *hdsp, int mode)
2488static int snd_hdsp_get_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2509static int snd_hdsp_get_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2489{ 2510{
2490 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2511 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2491 2512
2492 ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp); 2513 ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);
2493 return 0; 2514 return 0;
2494} 2515}
@@ -2498,7 +2519,7 @@ static int snd_hdsp_put_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v
2498 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2519 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2499 int change; 2520 int change;
2500 int val; 2521 int val;
2501 2522
2502 if (!snd_hdsp_use_is_exclusive(hdsp)) 2523 if (!snd_hdsp_use_is_exclusive(hdsp))
2503 return -EBUSY; 2524 return -EBUSY;
2504 val = ucontrol->value.integer.value[0] & 1; 2525 val = ucontrol->value.integer.value[0] & 1;
@@ -2576,7 +2597,7 @@ static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd
2576{ 2597{
2577 static char *texts[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" }; 2598 static char *texts[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" };
2578 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2599 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2579 2600
2580 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2601 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2581 uinfo->count = 1; 2602 uinfo->count = 1;
2582 2603
@@ -2595,7 +2616,7 @@ static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd
2595 uinfo->value.enumerated.items = 0; 2616 uinfo->value.enumerated.items = 0;
2596 break; 2617 break;
2597 } 2618 }
2598 2619
2599 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 2620 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2600 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 2621 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2601 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); 2622 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
@@ -2605,7 +2626,7 @@ static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd
2605static int snd_hdsp_get_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2626static int snd_hdsp_get_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2606{ 2627{
2607 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2628 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2608 2629
2609 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp); 2630 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2610 return 0; 2631 return 0;
2611} 2632}
@@ -2615,7 +2636,7 @@ static int snd_hdsp_put_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_
2615 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2636 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2616 int change, max; 2637 int change, max;
2617 unsigned int val; 2638 unsigned int val;
2618 2639
2619 if (!snd_hdsp_use_is_exclusive(hdsp)) 2640 if (!snd_hdsp_use_is_exclusive(hdsp))
2620 return -EBUSY; 2641 return -EBUSY;
2621 2642
@@ -2664,7 +2685,7 @@ static int hdsp_autosync_ref(struct hdsp *hdsp)
2664 case HDSP_SelSyncRef_SPDIF: 2685 case HDSP_SelSyncRef_SPDIF:
2665 return HDSP_AUTOSYNC_FROM_SPDIF; 2686 return HDSP_AUTOSYNC_FROM_SPDIF;
2666 case HDSP_SelSyncRefMask: 2687 case HDSP_SelSyncRefMask:
2667 return HDSP_AUTOSYNC_FROM_NONE; 2688 return HDSP_AUTOSYNC_FROM_NONE;
2668 case HDSP_SelSyncRef_ADAT1: 2689 case HDSP_SelSyncRef_ADAT1:
2669 return HDSP_AUTOSYNC_FROM_ADAT1; 2690 return HDSP_AUTOSYNC_FROM_ADAT1;
2670 case HDSP_SelSyncRef_ADAT2: 2691 case HDSP_SelSyncRef_ADAT2:
@@ -2680,7 +2701,7 @@ static int hdsp_autosync_ref(struct hdsp *hdsp)
2680static int snd_hdsp_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2701static int snd_hdsp_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2681{ 2702{
2682 static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" }; 2703 static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
2683 2704
2684 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2705 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2685 uinfo->count = 1; 2706 uinfo->count = 1;
2686 uinfo->value.enumerated.items = 7; 2707 uinfo->value.enumerated.items = 7;
@@ -2693,7 +2714,7 @@ static int snd_hdsp_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_
2693static int snd_hdsp_get_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2714static int snd_hdsp_get_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2694{ 2715{
2695 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2716 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2696 2717
2697 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp); 2718 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
2698 return 0; 2719 return 0;
2699} 2720}
@@ -2727,7 +2748,7 @@ static int hdsp_set_line_output(struct hdsp *hdsp, int out)
2727static int snd_hdsp_get_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2748static int snd_hdsp_get_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2728{ 2749{
2729 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2750 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2730 2751
2731 spin_lock_irq(&hdsp->lock); 2752 spin_lock_irq(&hdsp->lock);
2732 ucontrol->value.integer.value[0] = hdsp_line_out(hdsp); 2753 ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);
2733 spin_unlock_irq(&hdsp->lock); 2754 spin_unlock_irq(&hdsp->lock);
@@ -2739,7 +2760,7 @@ static int snd_hdsp_put_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_e
2739 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2760 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2740 int change; 2761 int change;
2741 unsigned int val; 2762 unsigned int val;
2742 2763
2743 if (!snd_hdsp_use_is_exclusive(hdsp)) 2764 if (!snd_hdsp_use_is_exclusive(hdsp))
2744 return -EBUSY; 2765 return -EBUSY;
2745 val = ucontrol->value.integer.value[0] & 1; 2766 val = ucontrol->value.integer.value[0] & 1;
@@ -2773,7 +2794,7 @@ static int hdsp_set_precise_pointer(struct hdsp *hdsp, int precise)
2773static int snd_hdsp_get_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2794static int snd_hdsp_get_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2774{ 2795{
2775 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2796 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2776 2797
2777 spin_lock_irq(&hdsp->lock); 2798 spin_lock_irq(&hdsp->lock);
2778 ucontrol->value.integer.value[0] = hdsp->precise_ptr; 2799 ucontrol->value.integer.value[0] = hdsp->precise_ptr;
2779 spin_unlock_irq(&hdsp->lock); 2800 spin_unlock_irq(&hdsp->lock);
@@ -2785,7 +2806,7 @@ static int snd_hdsp_put_precise_pointer(struct snd_kcontrol *kcontrol, struct sn
2785 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2806 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2786 int change; 2807 int change;
2787 unsigned int val; 2808 unsigned int val;
2788 2809
2789 if (!snd_hdsp_use_is_exclusive(hdsp)) 2810 if (!snd_hdsp_use_is_exclusive(hdsp))
2790 return -EBUSY; 2811 return -EBUSY;
2791 val = ucontrol->value.integer.value[0] & 1; 2812 val = ucontrol->value.integer.value[0] & 1;
@@ -2819,7 +2840,7 @@ static int hdsp_set_use_midi_tasklet(struct hdsp *hdsp, int use_tasklet)
2819static int snd_hdsp_get_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2840static int snd_hdsp_get_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2820{ 2841{
2821 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2842 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2822 2843
2823 spin_lock_irq(&hdsp->lock); 2844 spin_lock_irq(&hdsp->lock);
2824 ucontrol->value.integer.value[0] = hdsp->use_midi_tasklet; 2845 ucontrol->value.integer.value[0] = hdsp->use_midi_tasklet;
2825 spin_unlock_irq(&hdsp->lock); 2846 spin_unlock_irq(&hdsp->lock);
@@ -2831,7 +2852,7 @@ static int snd_hdsp_put_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct s
2831 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 2852 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2832 int change; 2853 int change;
2833 unsigned int val; 2854 unsigned int val;
2834 2855
2835 if (!snd_hdsp_use_is_exclusive(hdsp)) 2856 if (!snd_hdsp_use_is_exclusive(hdsp))
2836 return -EBUSY; 2857 return -EBUSY;
2837 val = ucontrol->value.integer.value[0] & 1; 2858 val = ucontrol->value.integer.value[0] & 1;
@@ -2873,12 +2894,12 @@ static int snd_hdsp_get_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
2873 2894
2874 source = ucontrol->value.integer.value[0]; 2895 source = ucontrol->value.integer.value[0];
2875 destination = ucontrol->value.integer.value[1]; 2896 destination = ucontrol->value.integer.value[1];
2876 2897
2877 if (source >= hdsp->max_channels) 2898 if (source >= hdsp->max_channels)
2878 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination); 2899 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2879 else 2900 else
2880 addr = hdsp_input_to_output_key(hdsp,source, destination); 2901 addr = hdsp_input_to_output_key(hdsp,source, destination);
2881 2902
2882 spin_lock_irq(&hdsp->lock); 2903 spin_lock_irq(&hdsp->lock);
2883 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr); 2904 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2884 spin_unlock_irq(&hdsp->lock); 2905 spin_unlock_irq(&hdsp->lock);
@@ -2926,7 +2947,7 @@ static int snd_hdsp_put_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem
2926 2947
2927static int snd_hdsp_info_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 2948static int snd_hdsp_info_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2928{ 2949{
2929 static char *texts[] = {"No Lock", "Lock", "Sync" }; 2950 static char *texts[] = {"No Lock", "Lock", "Sync" };
2930 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 2951 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2931 uinfo->count = 1; 2952 uinfo->count = 1;
2932 uinfo->value.enumerated.items = 3; 2953 uinfo->value.enumerated.items = 3;
@@ -2971,7 +2992,7 @@ static int hdsp_spdif_sync_check(struct hdsp *hdsp)
2971 int status = hdsp_read(hdsp, HDSP_statusRegister); 2992 int status = hdsp_read(hdsp, HDSP_statusRegister);
2972 if (status & HDSP_SPDIFErrorFlag) 2993 if (status & HDSP_SPDIFErrorFlag)
2973 return 0; 2994 return 0;
2974 else { 2995 else {
2975 if (status & HDSP_SPDIFSync) 2996 if (status & HDSP_SPDIFSync)
2976 return 2; 2997 return 2;
2977 else 2998 else
@@ -3007,7 +3028,7 @@ static int hdsp_adatsync_sync_check(struct hdsp *hdsp)
3007 return 1; 3028 return 1;
3008 } else 3029 } else
3009 return 0; 3030 return 0;
3010} 3031}
3011 3032
3012static int snd_hdsp_get_adatsync_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 3033static int snd_hdsp_get_adatsync_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3013{ 3034{
@@ -3025,17 +3046,17 @@ static int snd_hdsp_get_adatsync_sync_check(struct snd_kcontrol *kcontrol, struc
3025} 3046}
3026 3047
3027static int hdsp_adat_sync_check(struct hdsp *hdsp, int idx) 3048static int hdsp_adat_sync_check(struct hdsp *hdsp, int idx)
3028{ 3049{
3029 int status = hdsp_read(hdsp, HDSP_statusRegister); 3050 int status = hdsp_read(hdsp, HDSP_statusRegister);
3030 3051
3031 if (status & (HDSP_Lock0>>idx)) { 3052 if (status & (HDSP_Lock0>>idx)) {
3032 if (status & (HDSP_Sync0>>idx)) 3053 if (status & (HDSP_Sync0>>idx))
3033 return 2; 3054 return 2;
3034 else 3055 else
3035 return 1; 3056 return 1;
3036 } else 3057 } else
3037 return 0; 3058 return 0;
3038} 3059}
3039 3060
3040static int snd_hdsp_get_adat_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 3061static int snd_hdsp_get_adat_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3041{ 3062{
@@ -3053,7 +3074,7 @@ static int snd_hdsp_get_adat_sync_check(struct snd_kcontrol *kcontrol, struct sn
3053 break; 3074 break;
3054 case Multiface: 3075 case Multiface:
3055 case H9632: 3076 case H9632:
3056 if (offset >= 1) 3077 if (offset >= 1)
3057 return -EINVAL; 3078 return -EINVAL;
3058 break; 3079 break;
3059 default: 3080 default:
@@ -3115,7 +3136,7 @@ static int snd_hdsp_info_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ct
3115static int snd_hdsp_get_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 3136static int snd_hdsp_get_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3116{ 3137{
3117 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 3138 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3118 3139
3119 ucontrol->value.enumerated.item[0] = hdsp_dds_offset(hdsp); 3140 ucontrol->value.enumerated.item[0] = hdsp_dds_offset(hdsp);
3120 return 0; 3141 return 0;
3121} 3142}
@@ -3125,7 +3146,7 @@ static int snd_hdsp_put_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl
3125 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol); 3146 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3126 int change; 3147 int change;
3127 int val; 3148 int val;
3128 3149
3129 if (!snd_hdsp_use_is_exclusive(hdsp)) 3150 if (!snd_hdsp_use_is_exclusive(hdsp))
3130 return -EBUSY; 3151 return -EBUSY;
3131 val = ucontrol->value.enumerated.item[0]; 3152 val = ucontrol->value.enumerated.item[0];
@@ -3170,7 +3191,7 @@ static struct snd_kcontrol_new snd_hdsp_controls[] = {
3170 .get = snd_hdsp_control_spdif_mask_get, 3191 .get = snd_hdsp_control_spdif_mask_get,
3171 .private_value = IEC958_AES0_NONAUDIO | 3192 .private_value = IEC958_AES0_NONAUDIO |
3172 IEC958_AES0_PROFESSIONAL | 3193 IEC958_AES0_PROFESSIONAL |
3173 IEC958_AES0_CON_EMPHASIS, 3194 IEC958_AES0_CON_EMPHASIS,
3174}, 3195},
3175{ 3196{
3176 .access = SNDRV_CTL_ELEM_ACCESS_READ, 3197 .access = SNDRV_CTL_ELEM_ACCESS_READ,
@@ -3188,7 +3209,7 @@ HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0),
3188HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0), 3209HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),
3189HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0), 3210HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),
3190HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0), 3211HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
3191/* 'Sample Clock Source' complies with the alsa control naming scheme */ 3212/* 'Sample Clock Source' complies with the alsa control naming scheme */
3192HDSP_CLOCK_SOURCE("Sample Clock Source", 0), 3213HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
3193{ 3214{
3194 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 3215 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -3240,7 +3261,7 @@ static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp)
3240 return err; 3261 return err;
3241 } 3262 }
3242 } 3263 }
3243 3264
3244 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */ 3265 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3245 if (hdsp->io_type == H9632) { 3266 if (hdsp->io_type == H9632) {
3246 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) { 3267 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
@@ -3259,7 +3280,7 @@ static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp)
3259} 3280}
3260 3281
3261/*------------------------------------------------------------ 3282/*------------------------------------------------------------
3262 /proc interface 3283 /proc interface
3263 ------------------------------------------------------------*/ 3284 ------------------------------------------------------------*/
3264 3285
3265static void 3286static void
@@ -3298,7 +3319,7 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3298 } 3319 }
3299 } 3320 }
3300 } 3321 }
3301 3322
3302 status = hdsp_read(hdsp, HDSP_statusRegister); 3323 status = hdsp_read(hdsp, HDSP_statusRegister);
3303 status2 = hdsp_read(hdsp, HDSP_status2Register); 3324 status2 = hdsp_read(hdsp, HDSP_status2Register);
3304 3325
@@ -3362,17 +3383,17 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3362 break; 3383 break;
3363 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ: 3384 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
3364 clock_source = "Internal 192 kHz"; 3385 clock_source = "Internal 192 kHz";
3365 break; 3386 break;
3366 default: 3387 default:
3367 clock_source = "Error"; 3388 clock_source = "Error";
3368 } 3389 }
3369 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source); 3390 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
3370 3391
3371 if (hdsp_system_clock_mode(hdsp)) 3392 if (hdsp_system_clock_mode(hdsp))
3372 system_clock_mode = "Slave"; 3393 system_clock_mode = "Slave";
3373 else 3394 else
3374 system_clock_mode = "Master"; 3395 system_clock_mode = "Master";
3375 3396
3376 switch (hdsp_pref_sync_ref (hdsp)) { 3397 switch (hdsp_pref_sync_ref (hdsp)) {
3377 case HDSP_SYNC_FROM_WORD: 3398 case HDSP_SYNC_FROM_WORD:
3378 pref_sync_ref = "Word Clock"; 3399 pref_sync_ref = "Word Clock";
@@ -3397,7 +3418,7 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3397 break; 3418 break;
3398 } 3419 }
3399 snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref); 3420 snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref);
3400 3421
3401 switch (hdsp_autosync_ref (hdsp)) { 3422 switch (hdsp_autosync_ref (hdsp)) {
3402 case HDSP_AUTOSYNC_FROM_WORD: 3423 case HDSP_AUTOSYNC_FROM_WORD:
3403 autosync_ref = "Word Clock"; 3424 autosync_ref = "Word Clock";
@@ -3410,7 +3431,7 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3410 break; 3431 break;
3411 case HDSP_AUTOSYNC_FROM_NONE: 3432 case HDSP_AUTOSYNC_FROM_NONE:
3412 autosync_ref = "None"; 3433 autosync_ref = "None";
3413 break; 3434 break;
3414 case HDSP_AUTOSYNC_FROM_ADAT1: 3435 case HDSP_AUTOSYNC_FROM_ADAT1:
3415 autosync_ref = "ADAT1"; 3436 autosync_ref = "ADAT1";
3416 break; 3437 break;
@@ -3425,14 +3446,14 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3425 break; 3446 break;
3426 } 3447 }
3427 snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref); 3448 snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref);
3428 3449
3429 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp)); 3450 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3430 3451
3431 snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode); 3452 snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode);
3432 3453
3433 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate); 3454 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
3434 snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No"); 3455 snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No");
3435 3456
3436 snd_iprintf(buffer, "\n"); 3457 snd_iprintf(buffer, "\n");
3437 3458
3438 switch (hdsp_spdif_in(hdsp)) { 3459 switch (hdsp_spdif_in(hdsp)) {
@@ -3452,7 +3473,7 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3452 snd_iprintf(buffer, "IEC958 input: ???\n"); 3473 snd_iprintf(buffer, "IEC958 input: ???\n");
3453 break; 3474 break;
3454 } 3475 }
3455 3476
3456 if (hdsp->control_register & HDSP_SPDIFOpticalOut) 3477 if (hdsp->control_register & HDSP_SPDIFOpticalOut)
3457 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n"); 3478 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
3458 else 3479 else
@@ -3510,13 +3531,13 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3510 snd_iprintf (buffer, "SPDIF: No Lock\n"); 3531 snd_iprintf (buffer, "SPDIF: No Lock\n");
3511 else 3532 else
3512 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock"); 3533 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
3513 3534
3514 x = status2 & HDSP_wc_sync; 3535 x = status2 & HDSP_wc_sync;
3515 if (status2 & HDSP_wc_lock) 3536 if (status2 & HDSP_wc_lock)
3516 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock"); 3537 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
3517 else 3538 else
3518 snd_iprintf (buffer, "Word Clock: No Lock\n"); 3539 snd_iprintf (buffer, "Word Clock: No Lock\n");
3519 3540
3520 x = status & HDSP_TimecodeSync; 3541 x = status & HDSP_TimecodeSync;
3521 if (status & HDSP_TimecodeLock) 3542 if (status & HDSP_TimecodeLock)
3522 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock"); 3543 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
@@ -3524,11 +3545,11 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3524 snd_iprintf(buffer, "ADAT Sync: No Lock\n"); 3545 snd_iprintf(buffer, "ADAT Sync: No Lock\n");
3525 3546
3526 snd_iprintf(buffer, "\n"); 3547 snd_iprintf(buffer, "\n");
3527 3548
3528 /* Informations about H9632 specific controls */ 3549 /* Informations about H9632 specific controls */
3529 if (hdsp->io_type == H9632) { 3550 if (hdsp->io_type == H9632) {
3530 char *tmp; 3551 char *tmp;
3531 3552
3532 switch (hdsp_ad_gain(hdsp)) { 3553 switch (hdsp_ad_gain(hdsp)) {
3533 case 0: 3554 case 0:
3534 tmp = "-10 dBV"; 3555 tmp = "-10 dBV";
@@ -3554,7 +3575,7 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3554 break; 3575 break;
3555 } 3576 }
3556 snd_iprintf(buffer, "DA Gain : %s\n", tmp); 3577 snd_iprintf(buffer, "DA Gain : %s\n", tmp);
3557 3578
3558 switch (hdsp_phone_gain(hdsp)) { 3579 switch (hdsp_phone_gain(hdsp)) {
3559 case 0: 3580 case 0:
3560 tmp = "0 dB"; 3581 tmp = "0 dB";
@@ -3568,8 +3589,8 @@ snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3568 } 3589 }
3569 snd_iprintf(buffer, "Phones Gain : %s\n", tmp); 3590 snd_iprintf(buffer, "Phones Gain : %s\n", tmp);
3570 3591
3571 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no"); 3592 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no");
3572 3593
3573 if (hdsp->control_register & HDSP_AnalogExtensionBoard) 3594 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
3574 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n"); 3595 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n");
3575 else 3596 else
@@ -3632,18 +3653,18 @@ static int snd_hdsp_set_defaults(struct hdsp *hdsp)
3632 3653
3633 /* set defaults: 3654 /* set defaults:
3634 3655
3635 SPDIF Input via Coax 3656 SPDIF Input via Coax
3636 Master clock mode 3657 Master clock mode
3637 maximum latency (7 => 2^7 = 8192 samples, 64Kbyte buffer, 3658 maximum latency (7 => 2^7 = 8192 samples, 64Kbyte buffer,
3638 which implies 2 4096 sample, 32Kbyte periods). 3659 which implies 2 4096 sample, 32Kbyte periods).
3639 Enable line out. 3660 Enable line out.
3640 */ 3661 */
3641 3662
3642 hdsp->control_register = HDSP_ClockModeMaster | 3663 hdsp->control_register = HDSP_ClockModeMaster |
3643 HDSP_SPDIFInputCoaxial | 3664 HDSP_SPDIFInputCoaxial |
3644 hdsp_encode_latency(7) | 3665 hdsp_encode_latency(7) |
3645 HDSP_LineOut; 3666 HDSP_LineOut;
3646 3667
3647 3668
3648 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register); 3669 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3649 3670
@@ -3661,7 +3682,7 @@ static int snd_hdsp_set_defaults(struct hdsp *hdsp)
3661 hdsp_compute_period_size(hdsp); 3682 hdsp_compute_period_size(hdsp);
3662 3683
3663 /* silence everything */ 3684 /* silence everything */
3664 3685
3665 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i) 3686 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i)
3666 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN; 3687 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3667 3688
@@ -3669,7 +3690,7 @@ static int snd_hdsp_set_defaults(struct hdsp *hdsp)
3669 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN)) 3690 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN))
3670 return -EIO; 3691 return -EIO;
3671 } 3692 }
3672 3693
3673 /* H9632 specific defaults */ 3694 /* H9632 specific defaults */
3674 if (hdsp->io_type == H9632) { 3695 if (hdsp->io_type == H9632) {
3675 hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB); 3696 hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB);
@@ -3687,12 +3708,12 @@ static int snd_hdsp_set_defaults(struct hdsp *hdsp)
3687static void hdsp_midi_tasklet(unsigned long arg) 3708static void hdsp_midi_tasklet(unsigned long arg)
3688{ 3709{
3689 struct hdsp *hdsp = (struct hdsp *)arg; 3710 struct hdsp *hdsp = (struct hdsp *)arg;
3690 3711
3691 if (hdsp->midi[0].pending) 3712 if (hdsp->midi[0].pending)
3692 snd_hdsp_midi_input_read (&hdsp->midi[0]); 3713 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3693 if (hdsp->midi[1].pending) 3714 if (hdsp->midi[1].pending)
3694 snd_hdsp_midi_input_read (&hdsp->midi[1]); 3715 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3695} 3716}
3696 3717
3697static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id) 3718static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id)
3698{ 3719{
@@ -3704,7 +3725,7 @@ static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id)
3704 unsigned int midi0status; 3725 unsigned int midi0status;
3705 unsigned int midi1status; 3726 unsigned int midi1status;
3706 int schedule = 0; 3727 int schedule = 0;
3707 3728
3708 status = hdsp_read(hdsp, HDSP_statusRegister); 3729 status = hdsp_read(hdsp, HDSP_statusRegister);
3709 3730
3710 audio = status & HDSP_audioIRQPending; 3731 audio = status & HDSP_audioIRQPending;
@@ -3718,15 +3739,18 @@ static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id)
3718 3739
3719 midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff; 3740 midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
3720 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff; 3741 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3721 3742
3743 if (!(hdsp->state & HDSP_InitializationComplete))
3744 return IRQ_HANDLED;
3745
3722 if (audio) { 3746 if (audio) {
3723 if (hdsp->capture_substream) 3747 if (hdsp->capture_substream)
3724 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream); 3748 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3725 3749
3726 if (hdsp->playback_substream) 3750 if (hdsp->playback_substream)
3727 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream); 3751 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3728 } 3752 }
3729 3753
3730 if (midi0 && midi0status) { 3754 if (midi0 && midi0status) {
3731 if (hdsp->use_midi_tasklet) { 3755 if (hdsp->use_midi_tasklet) {
3732 /* we disable interrupts for this input until processing is done */ 3756 /* we disable interrupts for this input until processing is done */
@@ -3769,10 +3793,10 @@ static char *hdsp_channel_buffer_location(struct hdsp *hdsp,
3769 3793
3770 if (snd_BUG_ON(channel < 0 || channel >= hdsp->max_channels)) 3794 if (snd_BUG_ON(channel < 0 || channel >= hdsp->max_channels))
3771 return NULL; 3795 return NULL;
3772 3796
3773 if ((mapped_channel = hdsp->channel_map[channel]) < 0) 3797 if ((mapped_channel = hdsp->channel_map[channel]) < 0)
3774 return NULL; 3798 return NULL;
3775 3799
3776 if (stream == SNDRV_PCM_STREAM_CAPTURE) 3800 if (stream == SNDRV_PCM_STREAM_CAPTURE)
3777 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES); 3801 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3778 else 3802 else
@@ -3965,7 +3989,7 @@ static int snd_hdsp_trigger(struct snd_pcm_substream *substream, int cmd)
3965 struct hdsp *hdsp = snd_pcm_substream_chip(substream); 3989 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3966 struct snd_pcm_substream *other; 3990 struct snd_pcm_substream *other;
3967 int running; 3991 int running;
3968 3992
3969 if (hdsp_check_for_iobox (hdsp)) 3993 if (hdsp_check_for_iobox (hdsp))
3970 return -EIO; 3994 return -EIO;
3971 3995
@@ -4059,10 +4083,10 @@ static struct snd_pcm_hardware snd_hdsp_playback_subinfo =
4059 .formats = SNDRV_PCM_FMTBIT_S32_LE, 4083 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4060#endif 4084#endif
4061 .rates = (SNDRV_PCM_RATE_32000 | 4085 .rates = (SNDRV_PCM_RATE_32000 |
4062 SNDRV_PCM_RATE_44100 | 4086 SNDRV_PCM_RATE_44100 |
4063 SNDRV_PCM_RATE_48000 | 4087 SNDRV_PCM_RATE_48000 |
4064 SNDRV_PCM_RATE_64000 | 4088 SNDRV_PCM_RATE_64000 |
4065 SNDRV_PCM_RATE_88200 | 4089 SNDRV_PCM_RATE_88200 |
4066 SNDRV_PCM_RATE_96000), 4090 SNDRV_PCM_RATE_96000),
4067 .rate_min = 32000, 4091 .rate_min = 32000,
4068 .rate_max = 96000, 4092 .rate_max = 96000,
@@ -4088,10 +4112,10 @@ static struct snd_pcm_hardware snd_hdsp_capture_subinfo =
4088 .formats = SNDRV_PCM_FMTBIT_S32_LE, 4112 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4089#endif 4113#endif
4090 .rates = (SNDRV_PCM_RATE_32000 | 4114 .rates = (SNDRV_PCM_RATE_32000 |
4091 SNDRV_PCM_RATE_44100 | 4115 SNDRV_PCM_RATE_44100 |
4092 SNDRV_PCM_RATE_48000 | 4116 SNDRV_PCM_RATE_48000 |
4093 SNDRV_PCM_RATE_64000 | 4117 SNDRV_PCM_RATE_64000 |
4094 SNDRV_PCM_RATE_88200 | 4118 SNDRV_PCM_RATE_88200 |
4095 SNDRV_PCM_RATE_96000), 4119 SNDRV_PCM_RATE_96000),
4096 .rate_min = 32000, 4120 .rate_min = 32000,
4097 .rate_max = 96000, 4121 .rate_max = 96000,
@@ -4170,7 +4194,7 @@ static int snd_hdsp_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
4170 .max = hdsp->qs_in_channels, 4194 .max = hdsp->qs_in_channels,
4171 .integer = 1, 4195 .integer = 1,
4172 }; 4196 };
4173 return snd_interval_refine(c, &t); 4197 return snd_interval_refine(c, &t);
4174 } else if (r->min > 48000 && r->max <= 96000) { 4198 } else if (r->min > 48000 && r->max <= 96000) {
4175 struct snd_interval t = { 4199 struct snd_interval t = {
4176 .min = hdsp->ds_in_channels, 4200 .min = hdsp->ds_in_channels,
@@ -4201,7 +4225,7 @@ static int snd_hdsp_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params,
4201 .max = hdsp->qs_out_channels, 4225 .max = hdsp->qs_out_channels,
4202 .integer = 1, 4226 .integer = 1,
4203 }; 4227 };
4204 return snd_interval_refine(c, &t); 4228 return snd_interval_refine(c, &t);
4205 } else if (r->min > 48000 && r->max <= 96000) { 4229 } else if (r->min > 48000 && r->max <= 96000) {
4206 struct snd_interval t = { 4230 struct snd_interval t = {
4207 .min = hdsp->ds_out_channels, 4231 .min = hdsp->ds_out_channels,
@@ -4318,8 +4342,8 @@ static int snd_hdsp_playback_open(struct snd_pcm_substream *substream)
4318 if (hdsp->io_type == H9632) { 4342 if (hdsp->io_type == H9632) {
4319 runtime->hw.channels_min = hdsp->qs_out_channels; 4343 runtime->hw.channels_min = hdsp->qs_out_channels;
4320 runtime->hw.channels_max = hdsp->ss_out_channels; 4344 runtime->hw.channels_max = hdsp->ss_out_channels;
4321 } 4345 }
4322 4346
4323 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 4347 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4324 snd_hdsp_hw_rule_out_channels, hdsp, 4348 snd_hdsp_hw_rule_out_channels, hdsp,
4325 SNDRV_PCM_HW_PARAM_CHANNELS, -1); 4349 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
@@ -4413,13 +4437,6 @@ static int snd_hdsp_capture_release(struct snd_pcm_substream *substream)
4413 return 0; 4437 return 0;
4414} 4438}
4415 4439
4416static int snd_hdsp_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file)
4417{
4418 /* we have nothing to initialize but the call is required */
4419 return 0;
4420}
4421
4422
4423/* helper functions for copying meter values */ 4440/* helper functions for copying meter values */
4424static inline int copy_u32_le(void __user *dest, void __iomem *src) 4441static inline int copy_u32_le(void __user *dest, void __iomem *src)
4425{ 4442{
@@ -4536,7 +4553,7 @@ static int hdsp_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rm
4536 hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4, 4553 hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4,
4537 hdsp->iobase + HDSP_playbackRmsLevel + i * 8)) 4554 hdsp->iobase + HDSP_playbackRmsLevel + i * 8))
4538 return -EFAULT; 4555 return -EFAULT;
4539 if (copy_u64_le(&peak_rms->input_rms[i], 4556 if (copy_u64_le(&peak_rms->input_rms[i],
4540 hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4, 4557 hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4,
4541 hdsp->iobase + HDSP_inputRmsLevel + i * 8)) 4558 hdsp->iobase + HDSP_inputRmsLevel + i * 8))
4542 return -EFAULT; 4559 return -EFAULT;
@@ -4546,7 +4563,7 @@ static int hdsp_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rm
4546 4563
4547static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigned int cmd, unsigned long arg) 4564static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigned int cmd, unsigned long arg)
4548{ 4565{
4549 struct hdsp *hdsp = (struct hdsp *)hw->private_data; 4566 struct hdsp *hdsp = (struct hdsp *)hw->private_data;
4550 void __user *argp = (void __user *)arg; 4567 void __user *argp = (void __user *)arg;
4551 int err; 4568 int err;
4552 4569
@@ -4580,7 +4597,7 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
4580 struct hdsp_config_info info; 4597 struct hdsp_config_info info;
4581 unsigned long flags; 4598 unsigned long flags;
4582 int i; 4599 int i;
4583 4600
4584 err = hdsp_check_for_iobox(hdsp); 4601 err = hdsp_check_for_iobox(hdsp);
4585 if (err < 0) 4602 if (err < 0)
4586 return err; 4603 return err;
@@ -4614,7 +4631,7 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
4614 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp); 4631 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
4615 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp); 4632 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
4616 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp); 4633 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
4617 4634
4618 } 4635 }
4619 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) 4636 if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
4620 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp); 4637 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
@@ -4625,7 +4642,7 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
4625 } 4642 }
4626 case SNDRV_HDSP_IOCTL_GET_9632_AEB: { 4643 case SNDRV_HDSP_IOCTL_GET_9632_AEB: {
4627 struct hdsp_9632_aeb h9632_aeb; 4644 struct hdsp_9632_aeb h9632_aeb;
4628 4645
4629 if (hdsp->io_type != H9632) return -EINVAL; 4646 if (hdsp->io_type != H9632) return -EINVAL;
4630 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS; 4647 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS;
4631 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS; 4648 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS;
@@ -4636,7 +4653,7 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
4636 case SNDRV_HDSP_IOCTL_GET_VERSION: { 4653 case SNDRV_HDSP_IOCTL_GET_VERSION: {
4637 struct hdsp_version hdsp_version; 4654 struct hdsp_version hdsp_version;
4638 int err; 4655 int err;
4639 4656
4640 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL; 4657 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4641 if (hdsp->io_type == Undefined) { 4658 if (hdsp->io_type == Undefined) {
4642 if ((err = hdsp_get_iobox_version(hdsp)) < 0) 4659 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
@@ -4652,7 +4669,7 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
4652 struct hdsp_firmware __user *firmware; 4669 struct hdsp_firmware __user *firmware;
4653 u32 __user *firmware_data; 4670 u32 __user *firmware_data;
4654 int err; 4671 int err;
4655 4672
4656 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL; 4673 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4657 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */ 4674 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */
4658 if (hdsp->io_type == Undefined) return -EINVAL; 4675 if (hdsp->io_type == Undefined) return -EINVAL;
@@ -4665,25 +4682,25 @@ static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigne
4665 4682
4666 if (get_user(firmware_data, &firmware->firmware_data)) 4683 if (get_user(firmware_data, &firmware->firmware_data))
4667 return -EFAULT; 4684 return -EFAULT;
4668 4685
4669 if (hdsp_check_for_iobox (hdsp)) 4686 if (hdsp_check_for_iobox (hdsp))
4670 return -EIO; 4687 return -EIO;
4671 4688
4672 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0) 4689 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0)
4673 return -EFAULT; 4690 return -EFAULT;
4674 4691
4675 hdsp->state |= HDSP_FirmwareCached; 4692 hdsp->state |= HDSP_FirmwareCached;
4676 4693
4677 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0) 4694 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4678 return err; 4695 return err;
4679 4696
4680 if (!(hdsp->state & HDSP_InitializationComplete)) { 4697 if (!(hdsp->state & HDSP_InitializationComplete)) {
4681 if ((err = snd_hdsp_enable_io(hdsp)) < 0) 4698 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4682 return err; 4699 return err;
4683 4700
4684 snd_hdsp_initialize_channels(hdsp); 4701 snd_hdsp_initialize_channels(hdsp);
4685 snd_hdsp_initialize_midi_flush(hdsp); 4702 snd_hdsp_initialize_midi_flush(hdsp);
4686 4703
4687 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) { 4704 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4688 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n"); 4705 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n");
4689 return err; 4706 return err;
@@ -4730,18 +4747,16 @@ static int snd_hdsp_create_hwdep(struct snd_card *card, struct hdsp *hdsp)
4730{ 4747{
4731 struct snd_hwdep *hw; 4748 struct snd_hwdep *hw;
4732 int err; 4749 int err;
4733 4750
4734 if ((err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw)) < 0) 4751 if ((err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw)) < 0)
4735 return err; 4752 return err;
4736 4753
4737 hdsp->hwdep = hw; 4754 hdsp->hwdep = hw;
4738 hw->private_data = hdsp; 4755 hw->private_data = hdsp;
4739 strcpy(hw->name, "HDSP hwdep interface"); 4756 strcpy(hw->name, "HDSP hwdep interface");
4740 4757
4741 hw->ops.open = snd_hdsp_hwdep_dummy_op;
4742 hw->ops.ioctl = snd_hdsp_hwdep_ioctl; 4758 hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
4743 hw->ops.release = snd_hdsp_hwdep_dummy_op; 4759
4744
4745 return 0; 4760 return 0;
4746} 4761}
4747 4762
@@ -4774,24 +4789,24 @@ static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp)
4774static int snd_hdsp_enable_io (struct hdsp *hdsp) 4789static int snd_hdsp_enable_io (struct hdsp *hdsp)
4775{ 4790{
4776 int i; 4791 int i;
4777 4792
4778 if (hdsp_fifo_wait (hdsp, 0, 100)) { 4793 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4779 snd_printk(KERN_ERR "Hammerfall-DSP: enable_io fifo_wait failed\n"); 4794 snd_printk(KERN_ERR "Hammerfall-DSP: enable_io fifo_wait failed\n");
4780 return -EIO; 4795 return -EIO;
4781 } 4796 }
4782 4797
4783 for (i = 0; i < hdsp->max_channels; ++i) { 4798 for (i = 0; i < hdsp->max_channels; ++i) {
4784 hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1); 4799 hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
4785 hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1); 4800 hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
4786 } 4801 }
4787 4802
4788 return 0; 4803 return 0;
4789} 4804}
4790 4805
4791static void snd_hdsp_initialize_channels(struct hdsp *hdsp) 4806static void snd_hdsp_initialize_channels(struct hdsp *hdsp)
4792{ 4807{
4793 int status, aebi_channels, aebo_channels; 4808 int status, aebi_channels, aebo_channels;
4794 4809
4795 switch (hdsp->io_type) { 4810 switch (hdsp->io_type) {
4796 case Digiface: 4811 case Digiface:
4797 hdsp->card_name = "RME Hammerfall DSP + Digiface"; 4812 hdsp->card_name = "RME Hammerfall DSP + Digiface";
@@ -4804,7 +4819,7 @@ static void snd_hdsp_initialize_channels(struct hdsp *hdsp)
4804 hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS; 4819 hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS;
4805 hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS; 4820 hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS;
4806 break; 4821 break;
4807 4822
4808 case H9632: 4823 case H9632:
4809 status = hdsp_read(hdsp, HDSP_statusRegister); 4824 status = hdsp_read(hdsp, HDSP_statusRegister);
4810 /* HDSP_AEBx bits are low when AEB are connected */ 4825 /* HDSP_AEBx bits are low when AEB are connected */
@@ -4824,7 +4839,7 @@ static void snd_hdsp_initialize_channels(struct hdsp *hdsp)
4824 hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS; 4839 hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS;
4825 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS; 4840 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
4826 break; 4841 break;
4827 4842
4828 default: 4843 default:
4829 /* should never get here */ 4844 /* should never get here */
4830 break; 4845 break;
@@ -4840,12 +4855,12 @@ static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp)
4840static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp) 4855static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp)
4841{ 4856{
4842 int err; 4857 int err;
4843 4858
4844 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) { 4859 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
4845 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating pcm interface\n"); 4860 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating pcm interface\n");
4846 return err; 4861 return err;
4847 } 4862 }
4848 4863
4849 4864
4850 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) { 4865 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
4851 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating first midi interface\n"); 4866 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating first midi interface\n");
@@ -4876,19 +4891,19 @@ static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp
4876 snd_printk(KERN_ERR "Hammerfall-DSP: Error setting default values\n"); 4891 snd_printk(KERN_ERR "Hammerfall-DSP: Error setting default values\n");
4877 return err; 4892 return err;
4878 } 4893 }
4879 4894
4880 if (!(hdsp->state & HDSP_InitializationComplete)) { 4895 if (!(hdsp->state & HDSP_InitializationComplete)) {
4881 strcpy(card->shortname, "Hammerfall DSP"); 4896 strcpy(card->shortname, "Hammerfall DSP");
4882 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name, 4897 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
4883 hdsp->port, hdsp->irq); 4898 hdsp->port, hdsp->irq);
4884 4899
4885 if ((err = snd_card_register(card)) < 0) { 4900 if ((err = snd_card_register(card)) < 0) {
4886 snd_printk(KERN_ERR "Hammerfall-DSP: error registering card\n"); 4901 snd_printk(KERN_ERR "Hammerfall-DSP: error registering card\n");
4887 return err; 4902 return err;
4888 } 4903 }
4889 hdsp->state |= HDSP_InitializationComplete; 4904 hdsp->state |= HDSP_InitializationComplete;
4890 } 4905 }
4891 4906
4892 return 0; 4907 return 0;
4893} 4908}
4894 4909
@@ -4899,7 +4914,7 @@ static int hdsp_request_fw_loader(struct hdsp *hdsp)
4899 const char *fwfile; 4914 const char *fwfile;
4900 const struct firmware *fw; 4915 const struct firmware *fw;
4901 int err; 4916 int err;
4902 4917
4903 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) 4918 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
4904 return 0; 4919 return 0;
4905 if (hdsp->io_type == Undefined) { 4920 if (hdsp->io_type == Undefined) {
@@ -4908,7 +4923,7 @@ static int hdsp_request_fw_loader(struct hdsp *hdsp)
4908 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) 4923 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
4909 return 0; 4924 return 0;
4910 } 4925 }
4911 4926
4912 /* caution: max length of firmware filename is 30! */ 4927 /* caution: max length of firmware filename is 30! */
4913 switch (hdsp->io_type) { 4928 switch (hdsp->io_type) {
4914 case Multiface: 4929 case Multiface:
@@ -4942,12 +4957,12 @@ static int hdsp_request_fw_loader(struct hdsp *hdsp)
4942 memcpy(hdsp->firmware_cache, fw->data, sizeof(hdsp->firmware_cache)); 4957 memcpy(hdsp->firmware_cache, fw->data, sizeof(hdsp->firmware_cache));
4943 4958
4944 release_firmware(fw); 4959 release_firmware(fw);
4945 4960
4946 hdsp->state |= HDSP_FirmwareCached; 4961 hdsp->state |= HDSP_FirmwareCached;
4947 4962
4948 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0) 4963 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4949 return err; 4964 return err;
4950 4965
4951 if (!(hdsp->state & HDSP_InitializationComplete)) { 4966 if (!(hdsp->state & HDSP_InitializationComplete)) {
4952 if ((err = snd_hdsp_enable_io(hdsp)) < 0) 4967 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4953 return err; 4968 return err;
@@ -4994,14 +5009,14 @@ static int __devinit snd_hdsp_create(struct snd_card *card,
4994 hdsp->max_channels = 26; 5009 hdsp->max_channels = 26;
4995 5010
4996 hdsp->card = card; 5011 hdsp->card = card;
4997 5012
4998 spin_lock_init(&hdsp->lock); 5013 spin_lock_init(&hdsp->lock);
4999 5014
5000 tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp); 5015 tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
5001 5016
5002 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev); 5017 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
5003 hdsp->firmware_rev &= 0xff; 5018 hdsp->firmware_rev &= 0xff;
5004 5019
5005 /* From Martin Bjoernsen : 5020 /* From Martin Bjoernsen :
5006 "It is important that the card's latency timer register in 5021 "It is important that the card's latency timer register in
5007 the PCI configuration space is set to a value much larger 5022 the PCI configuration space is set to a value much larger
@@ -5010,7 +5025,7 @@ static int __devinit snd_hdsp_create(struct snd_card *card,
5010 to its maximum 255 to avoid problems with some computers." 5025 to its maximum 255 to avoid problems with some computers."
5011 */ 5026 */
5012 pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF); 5027 pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF);
5013 5028
5014 strcpy(card->driver, "H-DSP"); 5029 strcpy(card->driver, "H-DSP");
5015 strcpy(card->mixername, "Xilinx FPGA"); 5030 strcpy(card->mixername, "Xilinx FPGA");
5016 5031
@@ -5024,7 +5039,7 @@ static int __devinit snd_hdsp_create(struct snd_card *card,
5024 } else { 5039 } else {
5025 hdsp->card_name = "RME HDSP 9632"; 5040 hdsp->card_name = "RME HDSP 9632";
5026 hdsp->max_channels = 16; 5041 hdsp->max_channels = 16;
5027 is_9632 = 1; 5042 is_9632 = 1;
5028 } 5043 }
5029 5044
5030 if ((err = pci_enable_device(pci)) < 0) 5045 if ((err = pci_enable_device(pci)) < 0)
@@ -5053,12 +5068,12 @@ static int __devinit snd_hdsp_create(struct snd_card *card,
5053 5068
5054 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0) 5069 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
5055 return err; 5070 return err;
5056 5071
5057 if (!is_9652 && !is_9632) { 5072 if (!is_9652 && !is_9632) {
5058 /* we wait 2 seconds to let freshly inserted cardbus cards do their hardware init */ 5073 /* we wait a maximum of 10 seconds to let freshly
5059 ssleep(2); 5074 * inserted cardbus cards do their hardware init */
5075 err = hdsp_wait_for_iobox(hdsp, 1000, 10);
5060 5076
5061 err = hdsp_check_for_iobox(hdsp);
5062 if (err < 0) 5077 if (err < 0)
5063 return err; 5078 return err;
5064 5079
@@ -5080,35 +5095,35 @@ static int __devinit snd_hdsp_create(struct snd_card *card,
5080 return err; 5095 return err;
5081 return 0; 5096 return 0;
5082 } else { 5097 } else {
5083 snd_printk(KERN_INFO "Hammerfall-DSP: Firmware already present, initializing card.\n"); 5098 snd_printk(KERN_INFO "Hammerfall-DSP: Firmware already present, initializing card.\n");
5084 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) 5099 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5085 hdsp->io_type = Multiface; 5100 hdsp->io_type = Multiface;
5086 else 5101 else
5087 hdsp->io_type = Digiface; 5102 hdsp->io_type = Digiface;
5088 } 5103 }
5089 } 5104 }
5090 5105
5091 if ((err = snd_hdsp_enable_io(hdsp)) != 0) 5106 if ((err = snd_hdsp_enable_io(hdsp)) != 0)
5092 return err; 5107 return err;
5093 5108
5094 if (is_9652) 5109 if (is_9652)
5095 hdsp->io_type = H9652; 5110 hdsp->io_type = H9652;
5096 5111
5097 if (is_9632) 5112 if (is_9632)
5098 hdsp->io_type = H9632; 5113 hdsp->io_type = H9632;
5099 5114
5100 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) 5115 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5101 return err; 5116 return err;
5102 5117
5103 snd_hdsp_initialize_channels(hdsp); 5118 snd_hdsp_initialize_channels(hdsp);
5104 snd_hdsp_initialize_midi_flush(hdsp); 5119 snd_hdsp_initialize_midi_flush(hdsp);
5105 5120
5106 hdsp->state |= HDSP_FirmwareLoaded; 5121 hdsp->state |= HDSP_FirmwareLoaded;
5107 5122
5108 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0) 5123 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0)
5109 return err; 5124 return err;
5110 5125
5111 return 0; 5126 return 0;
5112} 5127}
5113 5128
5114static int snd_hdsp_free(struct hdsp *hdsp) 5129static int snd_hdsp_free(struct hdsp *hdsp)
@@ -5124,13 +5139,13 @@ static int snd_hdsp_free(struct hdsp *hdsp)
5124 free_irq(hdsp->irq, (void *)hdsp); 5139 free_irq(hdsp->irq, (void *)hdsp);
5125 5140
5126 snd_hdsp_free_buffers(hdsp); 5141 snd_hdsp_free_buffers(hdsp);
5127 5142
5128 if (hdsp->iobase) 5143 if (hdsp->iobase)
5129 iounmap(hdsp->iobase); 5144 iounmap(hdsp->iobase);
5130 5145
5131 if (hdsp->port) 5146 if (hdsp->port)
5132 pci_release_regions(hdsp->pci); 5147 pci_release_regions(hdsp->pci);
5133 5148
5134 pci_disable_device(hdsp->pci); 5149 pci_disable_device(hdsp->pci);
5135 return 0; 5150 return 0;
5136} 5151}
@@ -5158,8 +5173,10 @@ static int __devinit snd_hdsp_probe(struct pci_dev *pci,
5158 return -ENOENT; 5173 return -ENOENT;
5159 } 5174 }
5160 5175
5161 if (!(card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct hdsp)))) 5176 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
5162 return -ENOMEM; 5177 sizeof(struct hdsp), &card);
5178 if (err < 0)
5179 return err;
5163 5180
5164 hdsp = (struct hdsp *) card->private_data; 5181 hdsp = (struct hdsp *) card->private_data;
5165 card->private_free = snd_hdsp_card_free; 5182 card->private_free = snd_hdsp_card_free;
@@ -5173,7 +5190,7 @@ static int __devinit snd_hdsp_probe(struct pci_dev *pci,
5173 } 5190 }
5174 5191
5175 strcpy(card->shortname, "Hammerfall DSP"); 5192 strcpy(card->shortname, "Hammerfall DSP");
5176 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name, 5193 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5177 hdsp->port, hdsp->irq); 5194 hdsp->port, hdsp->irq);
5178 5195
5179 if ((err = snd_card_register(card)) < 0) { 5196 if ((err = snd_card_register(card)) < 0) {
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 71231cf1b2b0..bac2dc0c5d85 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -4100,13 +4100,6 @@ static int snd_hdspm_capture_release(struct snd_pcm_substream *substream)
4100 return 0; 4100 return 0;
4101} 4101}
4102 4102
4103static int snd_hdspm_hwdep_dummy_op(struct snd_hwdep * hw, struct file *file)
4104{
4105 /* we have nothing to initialize but the call is required */
4106 return 0;
4107}
4108
4109
4110static int snd_hdspm_hwdep_ioctl(struct snd_hwdep * hw, struct file *file, 4103static int snd_hdspm_hwdep_ioctl(struct snd_hwdep * hw, struct file *file,
4111 unsigned int cmd, unsigned long arg) 4104 unsigned int cmd, unsigned long arg)
4112{ 4105{
@@ -4213,9 +4206,7 @@ static int __devinit snd_hdspm_create_hwdep(struct snd_card *card,
4213 hw->private_data = hdspm; 4206 hw->private_data = hdspm;
4214 strcpy(hw->name, "HDSPM hwdep interface"); 4207 strcpy(hw->name, "HDSPM hwdep interface");
4215 4208
4216 hw->ops.open = snd_hdspm_hwdep_dummy_op;
4217 hw->ops.ioctl = snd_hdspm_hwdep_ioctl; 4209 hw->ops.ioctl = snd_hdspm_hwdep_ioctl;
4218 hw->ops.release = snd_hdspm_hwdep_dummy_op;
4219 4210
4220 return 0; 4211 return 0;
4221} 4212}
@@ -4503,10 +4494,10 @@ static int __devinit snd_hdspm_probe(struct pci_dev *pci,
4503 return -ENOENT; 4494 return -ENOENT;
4504 } 4495 }
4505 4496
4506 card = snd_card_new(index[dev], id[dev], 4497 err = snd_card_create(index[dev], id[dev],
4507 THIS_MODULE, sizeof(struct hdspm)); 4498 THIS_MODULE, sizeof(struct hdspm), &card);
4508 if (!card) 4499 if (err < 0)
4509 return -ENOMEM; 4500 return err;
4510 4501
4511 hdspm = card->private_data; 4502 hdspm = card->private_data;
4512 card->private_free = snd_hdspm_card_free; 4503 card->private_free = snd_hdspm_card_free;
diff --git a/sound/pci/rme9652/rme9652.c b/sound/pci/rme9652/rme9652.c
index 2570907134d7..bc539abb2105 100644
--- a/sound/pci/rme9652/rme9652.c
+++ b/sound/pci/rme9652/rme9652.c
@@ -2594,11 +2594,11 @@ static int __devinit snd_rme9652_probe(struct pci_dev *pci,
2594 return -ENOENT; 2594 return -ENOENT;
2595 } 2595 }
2596 2596
2597 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 2597 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
2598 sizeof(struct snd_rme9652)); 2598 sizeof(struct snd_rme9652), &card);
2599 2599
2600 if (!card) 2600 if (err < 0)
2601 return -ENOMEM; 2601 return err;
2602 2602
2603 rme9652 = (struct snd_rme9652 *) card->private_data; 2603 rme9652 = (struct snd_rme9652 *) card->private_data;
2604 card->private_free = snd_rme9652_card_free; 2604 card->private_free = snd_rme9652_card_free;
diff --git a/sound/pci/sis7019.c b/sound/pci/sis7019.c
index df2007e3be7c..baf6d8e3dabc 100644
--- a/sound/pci/sis7019.c
+++ b/sound/pci/sis7019.c
@@ -1387,9 +1387,8 @@ static int __devinit snd_sis7019_probe(struct pci_dev *pci,
1387 if (!enable) 1387 if (!enable)
1388 goto error_out; 1388 goto error_out;
1389 1389
1390 rc = -ENOMEM; 1390 rc = snd_card_create(index, id, THIS_MODULE, sizeof(*sis), &card);
1391 card = snd_card_new(index, id, THIS_MODULE, sizeof(*sis)); 1391 if (rc < 0)
1392 if (!card)
1393 goto error_out; 1392 goto error_out;
1394 1393
1395 strcpy(card->driver, "SiS7019"); 1394 strcpy(card->driver, "SiS7019");
diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
index cd408b86c839..d989215f3556 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -273,7 +273,8 @@ static inline void snd_sonicvibes_setdmaa(struct sonicvibes * sonic,
273 outl(count, sonic->dmaa_port + SV_DMA_COUNT0); 273 outl(count, sonic->dmaa_port + SV_DMA_COUNT0);
274 outb(0x18, sonic->dmaa_port + SV_DMA_MODE); 274 outb(0x18, sonic->dmaa_port + SV_DMA_MODE);
275#if 0 275#if 0
276 printk("program dmaa: addr = 0x%x, paddr = 0x%x\n", addr, inl(sonic->dmaa_port + SV_DMA_ADDR0)); 276 printk(KERN_DEBUG "program dmaa: addr = 0x%x, paddr = 0x%x\n",
277 addr, inl(sonic->dmaa_port + SV_DMA_ADDR0));
277#endif 278#endif
278} 279}
279 280
@@ -288,7 +289,8 @@ static inline void snd_sonicvibes_setdmac(struct sonicvibes * sonic,
288 outl(count, sonic->dmac_port + SV_DMA_COUNT0); 289 outl(count, sonic->dmac_port + SV_DMA_COUNT0);
289 outb(0x14, sonic->dmac_port + SV_DMA_MODE); 290 outb(0x14, sonic->dmac_port + SV_DMA_MODE);
290#if 0 291#if 0
291 printk("program dmac: addr = 0x%x, paddr = 0x%x\n", addr, inl(sonic->dmac_port + SV_DMA_ADDR0)); 292 printk(KERN_DEBUG "program dmac: addr = 0x%x, paddr = 0x%x\n",
293 addr, inl(sonic->dmac_port + SV_DMA_ADDR0));
292#endif 294#endif
293} 295}
294 296
@@ -355,71 +357,104 @@ static unsigned char snd_sonicvibes_in(struct sonicvibes * sonic, unsigned char
355#if 0 357#if 0
356static void snd_sonicvibes_debug(struct sonicvibes * sonic) 358static void snd_sonicvibes_debug(struct sonicvibes * sonic)
357{ 359{
358 printk("SV REGS: INDEX = 0x%02x ", inb(SV_REG(sonic, INDEX))); 360 printk(KERN_DEBUG
361 "SV REGS: INDEX = 0x%02x ", inb(SV_REG(sonic, INDEX)));
359 printk(" STATUS = 0x%02x\n", inb(SV_REG(sonic, STATUS))); 362 printk(" STATUS = 0x%02x\n", inb(SV_REG(sonic, STATUS)));
360 printk(" 0x00: left input = 0x%02x ", snd_sonicvibes_in(sonic, 0x00)); 363 printk(KERN_DEBUG
364 " 0x00: left input = 0x%02x ", snd_sonicvibes_in(sonic, 0x00));
361 printk(" 0x20: synth rate low = 0x%02x\n", snd_sonicvibes_in(sonic, 0x20)); 365 printk(" 0x20: synth rate low = 0x%02x\n", snd_sonicvibes_in(sonic, 0x20));
362 printk(" 0x01: right input = 0x%02x ", snd_sonicvibes_in(sonic, 0x01)); 366 printk(KERN_DEBUG
367 " 0x01: right input = 0x%02x ", snd_sonicvibes_in(sonic, 0x01));
363 printk(" 0x21: synth rate high = 0x%02x\n", snd_sonicvibes_in(sonic, 0x21)); 368 printk(" 0x21: synth rate high = 0x%02x\n", snd_sonicvibes_in(sonic, 0x21));
364 printk(" 0x02: left AUX1 = 0x%02x ", snd_sonicvibes_in(sonic, 0x02)); 369 printk(KERN_DEBUG
370 " 0x02: left AUX1 = 0x%02x ", snd_sonicvibes_in(sonic, 0x02));
365 printk(" 0x22: ADC clock = 0x%02x\n", snd_sonicvibes_in(sonic, 0x22)); 371 printk(" 0x22: ADC clock = 0x%02x\n", snd_sonicvibes_in(sonic, 0x22));
366 printk(" 0x03: right AUX1 = 0x%02x ", snd_sonicvibes_in(sonic, 0x03)); 372 printk(KERN_DEBUG
373 " 0x03: right AUX1 = 0x%02x ", snd_sonicvibes_in(sonic, 0x03));
367 printk(" 0x23: ADC alt rate = 0x%02x\n", snd_sonicvibes_in(sonic, 0x23)); 374 printk(" 0x23: ADC alt rate = 0x%02x\n", snd_sonicvibes_in(sonic, 0x23));
368 printk(" 0x04: left CD = 0x%02x ", snd_sonicvibes_in(sonic, 0x04)); 375 printk(KERN_DEBUG
376 " 0x04: left CD = 0x%02x ", snd_sonicvibes_in(sonic, 0x04));
369 printk(" 0x24: ADC pll M = 0x%02x\n", snd_sonicvibes_in(sonic, 0x24)); 377 printk(" 0x24: ADC pll M = 0x%02x\n", snd_sonicvibes_in(sonic, 0x24));
370 printk(" 0x05: right CD = 0x%02x ", snd_sonicvibes_in(sonic, 0x05)); 378 printk(KERN_DEBUG
379 " 0x05: right CD = 0x%02x ", snd_sonicvibes_in(sonic, 0x05));
371 printk(" 0x25: ADC pll N = 0x%02x\n", snd_sonicvibes_in(sonic, 0x25)); 380 printk(" 0x25: ADC pll N = 0x%02x\n", snd_sonicvibes_in(sonic, 0x25));
372 printk(" 0x06: left line = 0x%02x ", snd_sonicvibes_in(sonic, 0x06)); 381 printk(KERN_DEBUG
382 " 0x06: left line = 0x%02x ", snd_sonicvibes_in(sonic, 0x06));
373 printk(" 0x26: Synth pll M = 0x%02x\n", snd_sonicvibes_in(sonic, 0x26)); 383 printk(" 0x26: Synth pll M = 0x%02x\n", snd_sonicvibes_in(sonic, 0x26));
374 printk(" 0x07: right line = 0x%02x ", snd_sonicvibes_in(sonic, 0x07)); 384 printk(KERN_DEBUG
385 " 0x07: right line = 0x%02x ", snd_sonicvibes_in(sonic, 0x07));
375 printk(" 0x27: Synth pll N = 0x%02x\n", snd_sonicvibes_in(sonic, 0x27)); 386 printk(" 0x27: Synth pll N = 0x%02x\n", snd_sonicvibes_in(sonic, 0x27));
376 printk(" 0x08: MIC = 0x%02x ", snd_sonicvibes_in(sonic, 0x08)); 387 printk(KERN_DEBUG
388 " 0x08: MIC = 0x%02x ", snd_sonicvibes_in(sonic, 0x08));
377 printk(" 0x28: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x28)); 389 printk(" 0x28: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x28));
378 printk(" 0x09: Game port = 0x%02x ", snd_sonicvibes_in(sonic, 0x09)); 390 printk(KERN_DEBUG
391 " 0x09: Game port = 0x%02x ", snd_sonicvibes_in(sonic, 0x09));
379 printk(" 0x29: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x29)); 392 printk(" 0x29: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x29));
380 printk(" 0x0a: left synth = 0x%02x ", snd_sonicvibes_in(sonic, 0x0a)); 393 printk(KERN_DEBUG
394 " 0x0a: left synth = 0x%02x ", snd_sonicvibes_in(sonic, 0x0a));
381 printk(" 0x2a: MPU401 = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2a)); 395 printk(" 0x2a: MPU401 = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2a));
382 printk(" 0x0b: right synth = 0x%02x ", snd_sonicvibes_in(sonic, 0x0b)); 396 printk(KERN_DEBUG
397 " 0x0b: right synth = 0x%02x ", snd_sonicvibes_in(sonic, 0x0b));
383 printk(" 0x2b: drive ctrl = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2b)); 398 printk(" 0x2b: drive ctrl = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2b));
384 printk(" 0x0c: left AUX2 = 0x%02x ", snd_sonicvibes_in(sonic, 0x0c)); 399 printk(KERN_DEBUG
400 " 0x0c: left AUX2 = 0x%02x ", snd_sonicvibes_in(sonic, 0x0c));
385 printk(" 0x2c: SRS space = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2c)); 401 printk(" 0x2c: SRS space = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2c));
386 printk(" 0x0d: right AUX2 = 0x%02x ", snd_sonicvibes_in(sonic, 0x0d)); 402 printk(KERN_DEBUG
403 " 0x0d: right AUX2 = 0x%02x ", snd_sonicvibes_in(sonic, 0x0d));
387 printk(" 0x2d: SRS center = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2d)); 404 printk(" 0x2d: SRS center = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2d));
388 printk(" 0x0e: left analog = 0x%02x ", snd_sonicvibes_in(sonic, 0x0e)); 405 printk(KERN_DEBUG
406 " 0x0e: left analog = 0x%02x ", snd_sonicvibes_in(sonic, 0x0e));
389 printk(" 0x2e: wave source = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2e)); 407 printk(" 0x2e: wave source = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2e));
390 printk(" 0x0f: right analog = 0x%02x ", snd_sonicvibes_in(sonic, 0x0f)); 408 printk(KERN_DEBUG
409 " 0x0f: right analog = 0x%02x ", snd_sonicvibes_in(sonic, 0x0f));
391 printk(" 0x2f: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2f)); 410 printk(" 0x2f: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x2f));
392 printk(" 0x10: left PCM = 0x%02x ", snd_sonicvibes_in(sonic, 0x10)); 411 printk(KERN_DEBUG
412 " 0x10: left PCM = 0x%02x ", snd_sonicvibes_in(sonic, 0x10));
393 printk(" 0x30: analog power = 0x%02x\n", snd_sonicvibes_in(sonic, 0x30)); 413 printk(" 0x30: analog power = 0x%02x\n", snd_sonicvibes_in(sonic, 0x30));
394 printk(" 0x11: right PCM = 0x%02x ", snd_sonicvibes_in(sonic, 0x11)); 414 printk(KERN_DEBUG
415 " 0x11: right PCM = 0x%02x ", snd_sonicvibes_in(sonic, 0x11));
395 printk(" 0x31: analog power = 0x%02x\n", snd_sonicvibes_in(sonic, 0x31)); 416 printk(" 0x31: analog power = 0x%02x\n", snd_sonicvibes_in(sonic, 0x31));
396 printk(" 0x12: DMA data format = 0x%02x ", snd_sonicvibes_in(sonic, 0x12)); 417 printk(KERN_DEBUG
418 " 0x12: DMA data format = 0x%02x ", snd_sonicvibes_in(sonic, 0x12));
397 printk(" 0x32: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x32)); 419 printk(" 0x32: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x32));
398 printk(" 0x13: P/C enable = 0x%02x ", snd_sonicvibes_in(sonic, 0x13)); 420 printk(KERN_DEBUG
421 " 0x13: P/C enable = 0x%02x ", snd_sonicvibes_in(sonic, 0x13));
399 printk(" 0x33: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x33)); 422 printk(" 0x33: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x33));
400 printk(" 0x14: U/D button = 0x%02x ", snd_sonicvibes_in(sonic, 0x14)); 423 printk(KERN_DEBUG
424 " 0x14: U/D button = 0x%02x ", snd_sonicvibes_in(sonic, 0x14));
401 printk(" 0x34: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x34)); 425 printk(" 0x34: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x34));
402 printk(" 0x15: revision = 0x%02x ", snd_sonicvibes_in(sonic, 0x15)); 426 printk(KERN_DEBUG
427 " 0x15: revision = 0x%02x ", snd_sonicvibes_in(sonic, 0x15));
403 printk(" 0x35: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x35)); 428 printk(" 0x35: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x35));
404 printk(" 0x16: ADC output ctrl = 0x%02x ", snd_sonicvibes_in(sonic, 0x16)); 429 printk(KERN_DEBUG
430 " 0x16: ADC output ctrl = 0x%02x ", snd_sonicvibes_in(sonic, 0x16));
405 printk(" 0x36: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x36)); 431 printk(" 0x36: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x36));
406 printk(" 0x17: --- = 0x%02x ", snd_sonicvibes_in(sonic, 0x17)); 432 printk(KERN_DEBUG
433 " 0x17: --- = 0x%02x ", snd_sonicvibes_in(sonic, 0x17));
407 printk(" 0x37: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x37)); 434 printk(" 0x37: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x37));
408 printk(" 0x18: DMA A upper cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x18)); 435 printk(KERN_DEBUG
436 " 0x18: DMA A upper cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x18));
409 printk(" 0x38: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x38)); 437 printk(" 0x38: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x38));
410 printk(" 0x19: DMA A lower cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x19)); 438 printk(KERN_DEBUG
439 " 0x19: DMA A lower cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x19));
411 printk(" 0x39: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x39)); 440 printk(" 0x39: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x39));
412 printk(" 0x1a: --- = 0x%02x ", snd_sonicvibes_in(sonic, 0x1a)); 441 printk(KERN_DEBUG
442 " 0x1a: --- = 0x%02x ", snd_sonicvibes_in(sonic, 0x1a));
413 printk(" 0x3a: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3a)); 443 printk(" 0x3a: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3a));
414 printk(" 0x1b: --- = 0x%02x ", snd_sonicvibes_in(sonic, 0x1b)); 444 printk(KERN_DEBUG
445 " 0x1b: --- = 0x%02x ", snd_sonicvibes_in(sonic, 0x1b));
415 printk(" 0x3b: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3b)); 446 printk(" 0x3b: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3b));
416 printk(" 0x1c: DMA C upper cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x1c)); 447 printk(KERN_DEBUG
448 " 0x1c: DMA C upper cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x1c));
417 printk(" 0x3c: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3c)); 449 printk(" 0x3c: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3c));
418 printk(" 0x1d: DMA C upper cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x1d)); 450 printk(KERN_DEBUG
451 " 0x1d: DMA C upper cnt = 0x%02x ", snd_sonicvibes_in(sonic, 0x1d));
419 printk(" 0x3d: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3d)); 452 printk(" 0x3d: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3d));
420 printk(" 0x1e: PCM rate low = 0x%02x ", snd_sonicvibes_in(sonic, 0x1e)); 453 printk(KERN_DEBUG
454 " 0x1e: PCM rate low = 0x%02x ", snd_sonicvibes_in(sonic, 0x1e));
421 printk(" 0x3e: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3e)); 455 printk(" 0x3e: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3e));
422 printk(" 0x1f: PCM rate high = 0x%02x ", snd_sonicvibes_in(sonic, 0x1f)); 456 printk(KERN_DEBUG
457 " 0x1f: PCM rate high = 0x%02x ", snd_sonicvibes_in(sonic, 0x1f));
423 printk(" 0x3f: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3f)); 458 printk(" 0x3f: --- = 0x%02x\n", snd_sonicvibes_in(sonic, 0x3f));
424} 459}
425 460
@@ -476,8 +511,8 @@ static void snd_sonicvibes_pll(unsigned int rate,
476 *res_m = m; 511 *res_m = m;
477 *res_n = n; 512 *res_n = n;
478#if 0 513#if 0
479 printk("metric = %i, xm = %i, xn = %i\n", metric, xm, xn); 514 printk(KERN_DEBUG "metric = %i, xm = %i, xn = %i\n", metric, xm, xn);
480 printk("pll: m = 0x%x, r = 0x%x, n = 0x%x\n", reg, m, r, n); 515 printk(KERN_DEBUG "pll: m = 0x%x, r = 0x%x, n = 0x%x\n", reg, m, r, n);
481#endif 516#endif
482} 517}
483 518
@@ -1423,9 +1458,9 @@ static int __devinit snd_sonic_probe(struct pci_dev *pci,
1423 return -ENOENT; 1458 return -ENOENT;
1424 } 1459 }
1425 1460
1426 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 1461 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
1427 if (card == NULL) 1462 if (err < 0)
1428 return -ENOMEM; 1463 return err;
1429 for (idx = 0; idx < 5; idx++) { 1464 for (idx = 0; idx < 5; idx++) {
1430 if (pci_resource_start(pci, idx) == 0 || 1465 if (pci_resource_start(pci, idx) == 0 ||
1431 !(pci_resource_flags(pci, idx) & IORESOURCE_IO)) { 1466 !(pci_resource_flags(pci, idx) & IORESOURCE_IO)) {
diff --git a/sound/pci/trident/trident.c b/sound/pci/trident/trident.c
index d94b16ffb385..21cef97d478d 100644
--- a/sound/pci/trident/trident.c
+++ b/sound/pci/trident/trident.c
@@ -89,9 +89,9 @@ static int __devinit snd_trident_probe(struct pci_dev *pci,
89 return -ENOENT; 89 return -ENOENT;
90 } 90 }
91 91
92 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 92 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
93 if (card == NULL) 93 if (err < 0)
94 return -ENOMEM; 94 return err;
95 95
96 if ((err = snd_trident_create(card, pci, 96 if ((err = snd_trident_create(card, pci,
97 pcm_channels[dev], 97 pcm_channels[dev],
diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
index c612b435ca2b..a9da9c184660 100644
--- a/sound/pci/trident/trident_main.c
+++ b/sound/pci/trident/trident_main.c
@@ -68,40 +68,40 @@ static void snd_trident_print_voice_regs(struct snd_trident *trident, int voice)
68{ 68{
69 unsigned int val, tmp; 69 unsigned int val, tmp;
70 70
71 printk("Trident voice %i:\n", voice); 71 printk(KERN_DEBUG "Trident voice %i:\n", voice);
72 outb(voice, TRID_REG(trident, T4D_LFO_GC_CIR)); 72 outb(voice, TRID_REG(trident, T4D_LFO_GC_CIR));
73 val = inl(TRID_REG(trident, CH_LBA)); 73 val = inl(TRID_REG(trident, CH_LBA));
74 printk("LBA: 0x%x\n", val); 74 printk(KERN_DEBUG "LBA: 0x%x\n", val);
75 val = inl(TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC)); 75 val = inl(TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC));
76 printk("GVSel: %i\n", val >> 31); 76 printk(KERN_DEBUG "GVSel: %i\n", val >> 31);
77 printk("Pan: 0x%x\n", (val >> 24) & 0x7f); 77 printk(KERN_DEBUG "Pan: 0x%x\n", (val >> 24) & 0x7f);
78 printk("Vol: 0x%x\n", (val >> 16) & 0xff); 78 printk(KERN_DEBUG "Vol: 0x%x\n", (val >> 16) & 0xff);
79 printk("CTRL: 0x%x\n", (val >> 12) & 0x0f); 79 printk(KERN_DEBUG "CTRL: 0x%x\n", (val >> 12) & 0x0f);
80 printk("EC: 0x%x\n", val & 0x0fff); 80 printk(KERN_DEBUG "EC: 0x%x\n", val & 0x0fff);
81 if (trident->device != TRIDENT_DEVICE_ID_NX) { 81 if (trident->device != TRIDENT_DEVICE_ID_NX) {
82 val = inl(TRID_REG(trident, CH_DX_CSO_ALPHA_FMS)); 82 val = inl(TRID_REG(trident, CH_DX_CSO_ALPHA_FMS));
83 printk("CSO: 0x%x\n", val >> 16); 83 printk(KERN_DEBUG "CSO: 0x%x\n", val >> 16);
84 printk("Alpha: 0x%x\n", (val >> 4) & 0x0fff); 84 printk("Alpha: 0x%x\n", (val >> 4) & 0x0fff);
85 printk("FMS: 0x%x\n", val & 0x0f); 85 printk(KERN_DEBUG "FMS: 0x%x\n", val & 0x0f);
86 val = inl(TRID_REG(trident, CH_DX_ESO_DELTA)); 86 val = inl(TRID_REG(trident, CH_DX_ESO_DELTA));
87 printk("ESO: 0x%x\n", val >> 16); 87 printk(KERN_DEBUG "ESO: 0x%x\n", val >> 16);
88 printk("Delta: 0x%x\n", val & 0xffff); 88 printk(KERN_DEBUG "Delta: 0x%x\n", val & 0xffff);
89 val = inl(TRID_REG(trident, CH_DX_FMC_RVOL_CVOL)); 89 val = inl(TRID_REG(trident, CH_DX_FMC_RVOL_CVOL));
90 } else { // TRIDENT_DEVICE_ID_NX 90 } else { // TRIDENT_DEVICE_ID_NX
91 val = inl(TRID_REG(trident, CH_NX_DELTA_CSO)); 91 val = inl(TRID_REG(trident, CH_NX_DELTA_CSO));
92 tmp = (val >> 24) & 0xff; 92 tmp = (val >> 24) & 0xff;
93 printk("CSO: 0x%x\n", val & 0x00ffffff); 93 printk(KERN_DEBUG "CSO: 0x%x\n", val & 0x00ffffff);
94 val = inl(TRID_REG(trident, CH_NX_DELTA_ESO)); 94 val = inl(TRID_REG(trident, CH_NX_DELTA_ESO));
95 tmp |= (val >> 16) & 0xff00; 95 tmp |= (val >> 16) & 0xff00;
96 printk("Delta: 0x%x\n", tmp); 96 printk(KERN_DEBUG "Delta: 0x%x\n", tmp);
97 printk("ESO: 0x%x\n", val & 0x00ffffff); 97 printk(KERN_DEBUG "ESO: 0x%x\n", val & 0x00ffffff);
98 val = inl(TRID_REG(trident, CH_NX_ALPHA_FMS_FMC_RVOL_CVOL)); 98 val = inl(TRID_REG(trident, CH_NX_ALPHA_FMS_FMC_RVOL_CVOL));
99 printk("Alpha: 0x%x\n", val >> 20); 99 printk(KERN_DEBUG "Alpha: 0x%x\n", val >> 20);
100 printk("FMS: 0x%x\n", (val >> 16) & 0x0f); 100 printk(KERN_DEBUG "FMS: 0x%x\n", (val >> 16) & 0x0f);
101 } 101 }
102 printk("FMC: 0x%x\n", (val >> 14) & 3); 102 printk(KERN_DEBUG "FMC: 0x%x\n", (val >> 14) & 3);
103 printk("RVol: 0x%x\n", (val >> 7) & 0x7f); 103 printk(KERN_DEBUG "RVol: 0x%x\n", (val >> 7) & 0x7f);
104 printk("CVol: 0x%x\n", val & 0x7f); 104 printk(KERN_DEBUG "CVol: 0x%x\n", val & 0x7f);
105} 105}
106#endif 106#endif
107 107
@@ -496,12 +496,17 @@ void snd_trident_write_voice_regs(struct snd_trident * trident,
496 outl(regs[4], TRID_REG(trident, CH_START + 16)); 496 outl(regs[4], TRID_REG(trident, CH_START + 16));
497 497
498#if 0 498#if 0
499 printk("written %i channel:\n", voice->number); 499 printk(KERN_DEBUG "written %i channel:\n", voice->number);
500 printk(" regs[0] = 0x%x/0x%x\n", regs[0], inl(TRID_REG(trident, CH_START + 0))); 500 printk(KERN_DEBUG " regs[0] = 0x%x/0x%x\n",
501 printk(" regs[1] = 0x%x/0x%x\n", regs[1], inl(TRID_REG(trident, CH_START + 4))); 501 regs[0], inl(TRID_REG(trident, CH_START + 0)));
502 printk(" regs[2] = 0x%x/0x%x\n", regs[2], inl(TRID_REG(trident, CH_START + 8))); 502 printk(KERN_DEBUG " regs[1] = 0x%x/0x%x\n",
503 printk(" regs[3] = 0x%x/0x%x\n", regs[3], inl(TRID_REG(trident, CH_START + 12))); 503 regs[1], inl(TRID_REG(trident, CH_START + 4)));
504 printk(" regs[4] = 0x%x/0x%x\n", regs[4], inl(TRID_REG(trident, CH_START + 16))); 504 printk(KERN_DEBUG " regs[2] = 0x%x/0x%x\n",
505 regs[2], inl(TRID_REG(trident, CH_START + 8)));
506 printk(KERN_DEBUG " regs[3] = 0x%x/0x%x\n",
507 regs[3], inl(TRID_REG(trident, CH_START + 12)));
508 printk(KERN_DEBUG " regs[4] = 0x%x/0x%x\n",
509 regs[4], inl(TRID_REG(trident, CH_START + 16)));
505#endif 510#endif
506} 511}
507 512
@@ -583,7 +588,7 @@ static void snd_trident_write_vol_reg(struct snd_trident * trident,
583 outb(voice->Vol >> 2, TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC + 2)); 588 outb(voice->Vol >> 2, TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC + 2));
584 break; 589 break;
585 case TRIDENT_DEVICE_ID_SI7018: 590 case TRIDENT_DEVICE_ID_SI7018:
586 // printk("voice->Vol = 0x%x\n", voice->Vol); 591 /* printk(KERN_DEBUG "voice->Vol = 0x%x\n", voice->Vol); */
587 outw((voice->CTRL << 12) | voice->Vol, 592 outw((voice->CTRL << 12) | voice->Vol,
588 TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC)); 593 TRID_REG(trident, CH_GVSEL_PAN_VOL_CTRL_EC));
589 break; 594 break;
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index 1aafe956ee2b..809b233dd4a3 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -466,7 +466,10 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
466 flag = VIA_TBL_BIT_FLAG; /* period boundary */ 466 flag = VIA_TBL_BIT_FLAG; /* period boundary */
467 } else 467 } else
468 flag = 0; /* period continues to the next */ 468 flag = 0; /* period continues to the next */
469 // printk("via: tbl %d: at %d size %d (rest %d)\n", idx, ofs, r, rest); 469 /*
470 printk(KERN_DEBUG "via: tbl %d: at %d size %d "
471 "(rest %d)\n", idx, ofs, r, rest);
472 */
470 ((u32 *)dev->table.area)[(idx<<1) + 1] = cpu_to_le32(r | flag); 473 ((u32 *)dev->table.area)[(idx<<1) + 1] = cpu_to_le32(r | flag);
471 dev->idx_table[idx].offset = ofs; 474 dev->idx_table[idx].offset = ofs;
472 dev->idx_table[idx].size = r; 475 dev->idx_table[idx].size = r;
@@ -2360,14 +2363,14 @@ static struct snd_pci_quirk dxs_whitelist[] __devinitdata = {
2360 SND_PCI_QUIRK(0x1019, 0x0996, "ESC Mobo", VIA_DXS_48K), 2363 SND_PCI_QUIRK(0x1019, 0x0996, "ESC Mobo", VIA_DXS_48K),
2361 SND_PCI_QUIRK(0x1019, 0x0a81, "ECS K7VTA3 v8.0", VIA_DXS_NO_VRA), 2364 SND_PCI_QUIRK(0x1019, 0x0a81, "ECS K7VTA3 v8.0", VIA_DXS_NO_VRA),
2362 SND_PCI_QUIRK(0x1019, 0x0a85, "ECS L7VMM2", VIA_DXS_NO_VRA), 2365 SND_PCI_QUIRK(0x1019, 0x0a85, "ECS L7VMM2", VIA_DXS_NO_VRA),
2363 SND_PCI_QUIRK(0x1019, 0, "ESC K8", VIA_DXS_SRC), 2366 SND_PCI_QUIRK_VENDOR(0x1019, "ESC K8", VIA_DXS_SRC),
2364 SND_PCI_QUIRK(0x1019, 0xaa01, "ESC K8T890-A", VIA_DXS_SRC), 2367 SND_PCI_QUIRK(0x1019, 0xaa01, "ESC K8T890-A", VIA_DXS_SRC),
2365 SND_PCI_QUIRK(0x1025, 0x0033, "Acer Inspire 1353LM", VIA_DXS_NO_VRA), 2368 SND_PCI_QUIRK(0x1025, 0x0033, "Acer Inspire 1353LM", VIA_DXS_NO_VRA),
2366 SND_PCI_QUIRK(0x1025, 0x0046, "Acer Aspire 1524 WLMi", VIA_DXS_SRC), 2369 SND_PCI_QUIRK(0x1025, 0x0046, "Acer Aspire 1524 WLMi", VIA_DXS_SRC),
2367 SND_PCI_QUIRK(0x1043, 0, "ASUS A7/A8", VIA_DXS_NO_VRA), 2370 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS A7/A8", VIA_DXS_NO_VRA),
2368 SND_PCI_QUIRK(0x1071, 0, "Diverse Notebook", VIA_DXS_NO_VRA), 2371 SND_PCI_QUIRK_VENDOR(0x1071, "Diverse Notebook", VIA_DXS_NO_VRA),
2369 SND_PCI_QUIRK(0x10cf, 0x118e, "FSC Laptop", VIA_DXS_ENABLE), 2372 SND_PCI_QUIRK(0x10cf, 0x118e, "FSC Laptop", VIA_DXS_ENABLE),
2370 SND_PCI_QUIRK(0x1106, 0, "ASRock", VIA_DXS_SRC), 2373 SND_PCI_QUIRK_VENDOR(0x1106, "ASRock", VIA_DXS_SRC),
2371 SND_PCI_QUIRK(0x1297, 0xa231, "Shuttle AK31v2", VIA_DXS_SRC), 2374 SND_PCI_QUIRK(0x1297, 0xa231, "Shuttle AK31v2", VIA_DXS_SRC),
2372 SND_PCI_QUIRK(0x1297, 0xa232, "Shuttle", VIA_DXS_SRC), 2375 SND_PCI_QUIRK(0x1297, 0xa232, "Shuttle", VIA_DXS_SRC),
2373 SND_PCI_QUIRK(0x1297, 0xc160, "Shuttle Sk41G", VIA_DXS_SRC), 2376 SND_PCI_QUIRK(0x1297, 0xc160, "Shuttle Sk41G", VIA_DXS_SRC),
@@ -2375,7 +2378,7 @@ static struct snd_pci_quirk dxs_whitelist[] __devinitdata = {
2375 SND_PCI_QUIRK(0x1462, 0x3800, "MSI KT266", VIA_DXS_ENABLE), 2378 SND_PCI_QUIRK(0x1462, 0x3800, "MSI KT266", VIA_DXS_ENABLE),
2376 SND_PCI_QUIRK(0x1462, 0x7120, "MSI KT4V", VIA_DXS_ENABLE), 2379 SND_PCI_QUIRK(0x1462, 0x7120, "MSI KT4V", VIA_DXS_ENABLE),
2377 SND_PCI_QUIRK(0x1462, 0x7142, "MSI K8MM-V", VIA_DXS_ENABLE), 2380 SND_PCI_QUIRK(0x1462, 0x7142, "MSI K8MM-V", VIA_DXS_ENABLE),
2378 SND_PCI_QUIRK(0x1462, 0, "MSI Mobo", VIA_DXS_SRC), 2381 SND_PCI_QUIRK_VENDOR(0x1462, "MSI Mobo", VIA_DXS_SRC),
2379 SND_PCI_QUIRK(0x147b, 0x1401, "ABIT KD7(-RAID)", VIA_DXS_ENABLE), 2382 SND_PCI_QUIRK(0x147b, 0x1401, "ABIT KD7(-RAID)", VIA_DXS_ENABLE),
2380 SND_PCI_QUIRK(0x147b, 0x1411, "ABIT VA-20", VIA_DXS_ENABLE), 2383 SND_PCI_QUIRK(0x147b, 0x1411, "ABIT VA-20", VIA_DXS_ENABLE),
2381 SND_PCI_QUIRK(0x147b, 0x1413, "ABIT KV8 Pro", VIA_DXS_ENABLE), 2384 SND_PCI_QUIRK(0x147b, 0x1413, "ABIT KV8 Pro", VIA_DXS_ENABLE),
@@ -2389,11 +2392,11 @@ static struct snd_pci_quirk dxs_whitelist[] __devinitdata = {
2389 SND_PCI_QUIRK(0x161f, 0x2032, "m680x machines", VIA_DXS_48K), 2392 SND_PCI_QUIRK(0x161f, 0x2032, "m680x machines", VIA_DXS_48K),
2390 SND_PCI_QUIRK(0x1631, 0xe004, "PB EasyNote 3174", VIA_DXS_ENABLE), 2393 SND_PCI_QUIRK(0x1631, 0xe004, "PB EasyNote 3174", VIA_DXS_ENABLE),
2391 SND_PCI_QUIRK(0x1695, 0x3005, "EPoX EP-8K9A", VIA_DXS_ENABLE), 2394 SND_PCI_QUIRK(0x1695, 0x3005, "EPoX EP-8K9A", VIA_DXS_ENABLE),
2392 SND_PCI_QUIRK(0x1695, 0, "EPoX mobo", VIA_DXS_SRC), 2395 SND_PCI_QUIRK_VENDOR(0x1695, "EPoX mobo", VIA_DXS_SRC),
2393 SND_PCI_QUIRK(0x16f3, 0, "Jetway K8", VIA_DXS_SRC), 2396 SND_PCI_QUIRK_VENDOR(0x16f3, "Jetway K8", VIA_DXS_SRC),
2394 SND_PCI_QUIRK(0x1734, 0, "FSC Laptop", VIA_DXS_SRC), 2397 SND_PCI_QUIRK_VENDOR(0x1734, "FSC Laptop", VIA_DXS_SRC),
2395 SND_PCI_QUIRK(0x1849, 0x3059, "ASRock K7VM2", VIA_DXS_NO_VRA), 2398 SND_PCI_QUIRK(0x1849, 0x3059, "ASRock K7VM2", VIA_DXS_NO_VRA),
2396 SND_PCI_QUIRK(0x1849, 0, "ASRock mobo", VIA_DXS_SRC), 2399 SND_PCI_QUIRK_VENDOR(0x1849, "ASRock mobo", VIA_DXS_SRC),
2397 SND_PCI_QUIRK(0x1919, 0x200a, "Soltek SL-K8", VIA_DXS_NO_VRA), 2400 SND_PCI_QUIRK(0x1919, 0x200a, "Soltek SL-K8", VIA_DXS_NO_VRA),
2398 SND_PCI_QUIRK(0x4005, 0x4710, "MSI K7T266", VIA_DXS_SRC), 2401 SND_PCI_QUIRK(0x4005, 0x4710, "MSI K7T266", VIA_DXS_SRC),
2399 { } /* terminator */ 2402 { } /* terminator */
@@ -2433,9 +2436,9 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
2433 unsigned int i; 2436 unsigned int i;
2434 int err; 2437 int err;
2435 2438
2436 card = snd_card_new(index, id, THIS_MODULE, 0); 2439 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
2437 if (card == NULL) 2440 if (err < 0)
2438 return -ENOMEM; 2441 return err;
2439 2442
2440 card_type = pci_id->driver_data; 2443 card_type = pci_id->driver_data;
2441 switch (card_type) { 2444 switch (card_type) {
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c
index 5bd79d2a5a15..0d54e3503c1e 100644
--- a/sound/pci/via82xx_modem.c
+++ b/sound/pci/via82xx_modem.c
@@ -328,7 +328,10 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
328 flag = VIA_TBL_BIT_FLAG; /* period boundary */ 328 flag = VIA_TBL_BIT_FLAG; /* period boundary */
329 } else 329 } else
330 flag = 0; /* period continues to the next */ 330 flag = 0; /* period continues to the next */
331 // printk("via: tbl %d: at %d size %d (rest %d)\n", idx, ofs, r, rest); 331 /*
332 printk(KERN_DEBUG "via: tbl %d: at %d size %d "
333 "(rest %d)\n", idx, ofs, r, rest);
334 */
332 ((u32 *)dev->table.area)[(idx<<1) + 1] = cpu_to_le32(r | flag); 335 ((u32 *)dev->table.area)[(idx<<1) + 1] = cpu_to_le32(r | flag);
333 dev->idx_table[idx].offset = ofs; 336 dev->idx_table[idx].offset = ofs;
334 dev->idx_table[idx].size = r; 337 dev->idx_table[idx].size = r;
@@ -1167,9 +1170,9 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
1167 unsigned int i; 1170 unsigned int i;
1168 int err; 1171 int err;
1169 1172
1170 card = snd_card_new(index, id, THIS_MODULE, 0); 1173 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
1171 if (card == NULL) 1174 if (err < 0)
1172 return -ENOMEM; 1175 return err;
1173 1176
1174 card_type = pci_id->driver_data; 1177 card_type = pci_id->driver_data;
1175 switch (card_type) { 1178 switch (card_type) {
diff --git a/sound/pci/vx222/vx222.c b/sound/pci/vx222/vx222.c
index acc352f4a441..fc9136c3e0d7 100644
--- a/sound/pci/vx222/vx222.c
+++ b/sound/pci/vx222/vx222.c
@@ -204,9 +204,9 @@ static int __devinit snd_vx222_probe(struct pci_dev *pci,
204 return -ENOENT; 204 return -ENOENT;
205 } 205 }
206 206
207 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 207 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
208 if (card == NULL) 208 if (err < 0)
209 return -ENOMEM; 209 return err;
210 210
211 switch ((int)pci_id->driver_data) { 211 switch ((int)pci_id->driver_data) {
212 case VX_PCI_VX222_OLD: 212 case VX_PCI_VX222_OLD:
diff --git a/sound/pci/vx222/vx222_ops.c b/sound/pci/vx222/vx222_ops.c
index 7e87f398ff0b..c0efe4491116 100644
--- a/sound/pci/vx222/vx222_ops.c
+++ b/sound/pci/vx222/vx222_ops.c
@@ -107,7 +107,9 @@ static unsigned char vx2_inb(struct vx_core *chip, int offset)
107static void vx2_outb(struct vx_core *chip, int offset, unsigned char val) 107static void vx2_outb(struct vx_core *chip, int offset, unsigned char val)
108{ 108{
109 outb(val, vx2_reg_addr(chip, offset)); 109 outb(val, vx2_reg_addr(chip, offset));
110 //printk("outb: %x -> %x\n", val, vx2_reg_addr(chip, offset)); 110 /*
111 printk(KERN_DEBUG "outb: %x -> %x\n", val, vx2_reg_addr(chip, offset));
112 */
111} 113}
112 114
113/** 115/**
@@ -126,7 +128,9 @@ static unsigned int vx2_inl(struct vx_core *chip, int offset)
126 */ 128 */
127static void vx2_outl(struct vx_core *chip, int offset, unsigned int val) 129static void vx2_outl(struct vx_core *chip, int offset, unsigned int val)
128{ 130{
129 // printk("outl: %x -> %x\n", val, vx2_reg_addr(chip, offset)); 131 /*
132 printk(KERN_DEBUG "outl: %x -> %x\n", val, vx2_reg_addr(chip, offset));
133 */
130 outl(val, vx2_reg_addr(chip, offset)); 134 outl(val, vx2_reg_addr(chip, offset));
131} 135}
132 136
diff --git a/sound/pci/ymfpci/ymfpci.c b/sound/pci/ymfpci/ymfpci.c
index 2631a554845e..4af66661f9b0 100644
--- a/sound/pci/ymfpci/ymfpci.c
+++ b/sound/pci/ymfpci/ymfpci.c
@@ -187,9 +187,9 @@ static int __devinit snd_card_ymfpci_probe(struct pci_dev *pci,
187 return -ENOENT; 187 return -ENOENT;
188 } 188 }
189 189
190 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); 190 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
191 if (card == NULL) 191 if (err < 0)
192 return -ENOMEM; 192 return err;
193 193
194 switch (pci_id->device) { 194 switch (pci_id->device) {
195 case 0x0004: str = "YMF724"; model = "DS-1"; break; 195 case 0x0004: str = "YMF724"; model = "DS-1"; break;
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index 90d0d62bd0b4..2f0925236a1b 100644
--- a/sound/pci/ymfpci/ymfpci_main.c
+++ b/sound/pci/ymfpci/ymfpci_main.c
@@ -318,7 +318,12 @@ static void snd_ymfpci_pcm_interrupt(struct snd_ymfpci *chip, struct snd_ymfpci_
318 ypcm->period_pos += delta; 318 ypcm->period_pos += delta;
319 ypcm->last_pos = pos; 319 ypcm->last_pos = pos;
320 if (ypcm->period_pos >= ypcm->period_size) { 320 if (ypcm->period_pos >= ypcm->period_size) {
321 // printk("done - active_bank = 0x%x, start = 0x%x\n", chip->active_bank, voice->bank[chip->active_bank].start); 321 /*
322 printk(KERN_DEBUG
323 "done - active_bank = 0x%x, start = 0x%x\n",
324 chip->active_bank,
325 voice->bank[chip->active_bank].start);
326 */
322 ypcm->period_pos %= ypcm->period_size; 327 ypcm->period_pos %= ypcm->period_size;
323 spin_unlock(&chip->reg_lock); 328 spin_unlock(&chip->reg_lock);
324 snd_pcm_period_elapsed(ypcm->substream); 329 snd_pcm_period_elapsed(ypcm->substream);
@@ -366,7 +371,12 @@ static void snd_ymfpci_pcm_capture_interrupt(struct snd_pcm_substream *substream
366 ypcm->last_pos = pos; 371 ypcm->last_pos = pos;
367 if (ypcm->period_pos >= ypcm->period_size) { 372 if (ypcm->period_pos >= ypcm->period_size) {
368 ypcm->period_pos %= ypcm->period_size; 373 ypcm->period_pos %= ypcm->period_size;
369 // printk("done - active_bank = 0x%x, start = 0x%x\n", chip->active_bank, voice->bank[chip->active_bank].start); 374 /*
375 printk(KERN_DEBUG
376 "done - active_bank = 0x%x, start = 0x%x\n",
377 chip->active_bank,
378 voice->bank[chip->active_bank].start);
379 */
370 spin_unlock(&chip->reg_lock); 380 spin_unlock(&chip->reg_lock);
371 snd_pcm_period_elapsed(substream); 381 snd_pcm_period_elapsed(substream);
372 spin_lock(&chip->reg_lock); 382 spin_lock(&chip->reg_lock);
diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf.c b/sound/pcmcia/pdaudiocf/pdaudiocf.c
index 819aaaac432f..7dea74b71cf1 100644
--- a/sound/pcmcia/pdaudiocf/pdaudiocf.c
+++ b/sound/pcmcia/pdaudiocf/pdaudiocf.c
@@ -91,7 +91,7 @@ static int snd_pdacf_dev_free(struct snd_device *device)
91 */ 91 */
92static int snd_pdacf_probe(struct pcmcia_device *link) 92static int snd_pdacf_probe(struct pcmcia_device *link)
93{ 93{
94 int i; 94 int i, err;
95 struct snd_pdacf *pdacf; 95 struct snd_pdacf *pdacf;
96 struct snd_card *card; 96 struct snd_card *card;
97 static struct snd_device_ops ops = { 97 static struct snd_device_ops ops = {
@@ -112,20 +112,23 @@ static int snd_pdacf_probe(struct pcmcia_device *link)
112 return -ENODEV; /* disabled explicitly */ 112 return -ENODEV; /* disabled explicitly */
113 113
114 /* ok, create a card instance */ 114 /* ok, create a card instance */
115 card = snd_card_new(index[i], id[i], THIS_MODULE, 0); 115 err = snd_card_create(index[i], id[i], THIS_MODULE, 0, &card);
116 if (card == NULL) { 116 if (err < 0) {
117 snd_printk(KERN_ERR "pdacf: cannot create a card instance\n"); 117 snd_printk(KERN_ERR "pdacf: cannot create a card instance\n");
118 return -ENOMEM; 118 return err;
119 } 119 }
120 120
121 pdacf = snd_pdacf_create(card); 121 pdacf = snd_pdacf_create(card);
122 if (! pdacf) 122 if (!pdacf) {
123 return -EIO; 123 snd_card_free(card);
124 return -ENOMEM;
125 }
124 126
125 if (snd_device_new(card, SNDRV_DEV_LOWLEVEL, pdacf, &ops) < 0) { 127 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, pdacf, &ops);
128 if (err < 0) {
126 kfree(pdacf); 129 kfree(pdacf);
127 snd_card_free(card); 130 snd_card_free(card);
128 return -ENODEV; 131 return err;
129 } 132 }
130 133
131 snd_card_set_dev(card, &handle_to_dev(link)); 134 snd_card_set_dev(card, &handle_to_dev(link));
diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf_core.c b/sound/pcmcia/pdaudiocf/pdaudiocf_core.c
index dfa40b0ed86d..5d2afa0b0ce4 100644
--- a/sound/pcmcia/pdaudiocf/pdaudiocf_core.c
+++ b/sound/pcmcia/pdaudiocf/pdaudiocf_core.c
@@ -82,14 +82,21 @@ static void pdacf_ak4117_write(void *private_data, unsigned char reg, unsigned c
82#if 0 82#if 0
83void pdacf_dump(struct snd_pdacf *chip) 83void pdacf_dump(struct snd_pdacf *chip)
84{ 84{
85 printk("PDAUDIOCF DUMP (0x%lx):\n", chip->port); 85 printk(KERN_DEBUG "PDAUDIOCF DUMP (0x%lx):\n", chip->port);
86 printk("WPD : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_WDP)); 86 printk(KERN_DEBUG "WPD : 0x%x\n",
87 printk("RDP : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_RDP)); 87 inw(chip->port + PDAUDIOCF_REG_WDP));
88 printk("TCR : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_TCR)); 88 printk(KERN_DEBUG "RDP : 0x%x\n",
89 printk("SCR : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_SCR)); 89 inw(chip->port + PDAUDIOCF_REG_RDP));
90 printk("ISR : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_ISR)); 90 printk(KERN_DEBUG "TCR : 0x%x\n",
91 printk("IER : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_IER)); 91 inw(chip->port + PDAUDIOCF_REG_TCR));
92 printk("AK_IFR : 0x%x\n", inw(chip->port + PDAUDIOCF_REG_AK_IFR)); 92 printk(KERN_DEBUG "SCR : 0x%x\n",
93 inw(chip->port + PDAUDIOCF_REG_SCR));
94 printk(KERN_DEBUG "ISR : 0x%x\n",
95 inw(chip->port + PDAUDIOCF_REG_ISR));
96 printk(KERN_DEBUG "IER : 0x%x\n",
97 inw(chip->port + PDAUDIOCF_REG_IER));
98 printk(KERN_DEBUG "AK_IFR : 0x%x\n",
99 inw(chip->port + PDAUDIOCF_REG_AK_IFR));
93} 100}
94#endif 101#endif
95 102
diff --git a/sound/pcmcia/pdaudiocf/pdaudiocf_irq.c b/sound/pcmcia/pdaudiocf/pdaudiocf_irq.c
index ea903c8e90dd..dcd32201bc8c 100644
--- a/sound/pcmcia/pdaudiocf/pdaudiocf_irq.c
+++ b/sound/pcmcia/pdaudiocf/pdaudiocf_irq.c
@@ -269,7 +269,7 @@ void pdacf_tasklet(unsigned long private_data)
269 269
270 rdp = inw(chip->port + PDAUDIOCF_REG_RDP); 270 rdp = inw(chip->port + PDAUDIOCF_REG_RDP);
271 wdp = inw(chip->port + PDAUDIOCF_REG_WDP); 271 wdp = inw(chip->port + PDAUDIOCF_REG_WDP);
272 // printk("TASKLET: rdp = %x, wdp = %x\n", rdp, wdp); 272 /* printk(KERN_DEBUG "TASKLET: rdp = %x, wdp = %x\n", rdp, wdp); */
273 size = wdp - rdp; 273 size = wdp - rdp;
274 if (size < 0) 274 if (size < 0)
275 size += 0x10000; 275 size += 0x10000;
@@ -321,5 +321,5 @@ void pdacf_tasklet(unsigned long private_data)
321 spin_lock(&chip->reg_lock); 321 spin_lock(&chip->reg_lock);
322 } 322 }
323 spin_unlock(&chip->reg_lock); 323 spin_unlock(&chip->reg_lock);
324 // printk("TASKLET: end\n"); 324 /* printk(KERN_DEBUG "TASKLET: end\n"); */
325} 325}
diff --git a/sound/pcmcia/vx/vxpocket.c b/sound/pcmcia/vx/vxpocket.c
index 706602a40600..7445cc8a47d3 100644
--- a/sound/pcmcia/vx/vxpocket.c
+++ b/sound/pcmcia/vx/vxpocket.c
@@ -130,23 +130,26 @@ static struct snd_vx_hardware vxp440_hw = {
130/* 130/*
131 * create vxpocket instance 131 * create vxpocket instance
132 */ 132 */
133static struct snd_vxpocket *snd_vxpocket_new(struct snd_card *card, int ibl, 133static int snd_vxpocket_new(struct snd_card *card, int ibl,
134 struct pcmcia_device *link) 134 struct pcmcia_device *link,
135 struct snd_vxpocket **chip_ret)
135{ 136{
136 struct vx_core *chip; 137 struct vx_core *chip;
137 struct snd_vxpocket *vxp; 138 struct snd_vxpocket *vxp;
138 static struct snd_device_ops ops = { 139 static struct snd_device_ops ops = {
139 .dev_free = snd_vxpocket_dev_free, 140 .dev_free = snd_vxpocket_dev_free,
140 }; 141 };
142 int err;
141 143
142 chip = snd_vx_create(card, &vxpocket_hw, &snd_vxpocket_ops, 144 chip = snd_vx_create(card, &vxpocket_hw, &snd_vxpocket_ops,
143 sizeof(struct snd_vxpocket) - sizeof(struct vx_core)); 145 sizeof(struct snd_vxpocket) - sizeof(struct vx_core));
144 if (! chip) 146 if (!chip)
145 return NULL; 147 return -ENOMEM;
146 148
147 if (snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops) < 0) { 149 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
150 if (err < 0) {
148 kfree(chip); 151 kfree(chip);
149 return NULL; 152 return err;
150 } 153 }
151 chip->ibl.size = ibl; 154 chip->ibl.size = ibl;
152 155
@@ -169,7 +172,8 @@ static struct snd_vxpocket *snd_vxpocket_new(struct snd_card *card, int ibl,
169 link->conf.ConfigIndex = 1; 172 link->conf.ConfigIndex = 1;
170 link->conf.Present = PRESENT_OPTION; 173 link->conf.Present = PRESENT_OPTION;
171 174
172 return vxp; 175 *chip_ret = vxp;
176 return 0;
173} 177}
174 178
175 179
@@ -292,7 +296,7 @@ static int vxpocket_probe(struct pcmcia_device *p_dev)
292{ 296{
293 struct snd_card *card; 297 struct snd_card *card;
294 struct snd_vxpocket *vxp; 298 struct snd_vxpocket *vxp;
295 int i; 299 int i, err;
296 300
297 /* find an empty slot from the card list */ 301 /* find an empty slot from the card list */
298 for (i = 0; i < SNDRV_CARDS; i++) { 302 for (i = 0; i < SNDRV_CARDS; i++) {
@@ -307,16 +311,16 @@ static int vxpocket_probe(struct pcmcia_device *p_dev)
307 return -ENODEV; /* disabled explicitly */ 311 return -ENODEV; /* disabled explicitly */
308 312
309 /* ok, create a card instance */ 313 /* ok, create a card instance */
310 card = snd_card_new(index[i], id[i], THIS_MODULE, 0); 314 err = snd_card_create(index[i], id[i], THIS_MODULE, 0, &card);
311 if (card == NULL) { 315 if (err < 0) {
312 snd_printk(KERN_ERR "vxpocket: cannot create a card instance\n"); 316 snd_printk(KERN_ERR "vxpocket: cannot create a card instance\n");
313 return -ENOMEM; 317 return err;
314 } 318 }
315 319
316 vxp = snd_vxpocket_new(card, ibl[i], p_dev); 320 err = snd_vxpocket_new(card, ibl[i], p_dev, &vxp);
317 if (! vxp) { 321 if (err < 0) {
318 snd_card_free(card); 322 snd_card_free(card);
319 return -ENODEV; 323 return err;
320 } 324 }
321 card->private_data = vxp; 325 card->private_data = vxp;
322 326
diff --git a/sound/ppc/Kconfig b/sound/ppc/Kconfig
index 777de2b17178..bd2338ab2ced 100644
--- a/sound/ppc/Kconfig
+++ b/sound/ppc/Kconfig
@@ -13,6 +13,7 @@ config SND_POWERMAC
13 tristate "PowerMac (AWACS, DACA, Burgundy, Tumbler, Keywest)" 13 tristate "PowerMac (AWACS, DACA, Burgundy, Tumbler, Keywest)"
14 depends on I2C && INPUT && PPC_PMAC 14 depends on I2C && INPUT && PPC_PMAC
15 select SND_PCM 15 select SND_PCM
16 select SND_VMASTER
16 help 17 help
17 Say Y here to include support for the integrated sound device. 18 Say Y here to include support for the integrated sound device.
18 19
diff --git a/sound/ppc/awacs.c b/sound/ppc/awacs.c
index 7bd33e6552ab..80df9b1f651e 100644
--- a/sound/ppc/awacs.c
+++ b/sound/ppc/awacs.c
@@ -608,9 +608,12 @@ static struct snd_kcontrol_new snd_pmac_screamer_mixers_beige[] __initdata = {
608 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_LINE, 0), 608 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_LINE, 0),
609}; 609};
610 610
611static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] __initdata = { 611static struct snd_kcontrol_new snd_pmac_screamer_mixers_lo[] __initdata = {
612 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1), 612 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
613 AWACS_VOLUME("Master Playback Volume", 5, 6, 1), 613};
614
615static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] __initdata = {
616 AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1),
614 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0), 617 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
615}; 618};
616 619
@@ -627,6 +630,10 @@ static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] __initdata = {
627 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0), 630 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
628}; 631};
629 632
633static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac5500[] __initdata = {
634 AWACS_VOLUME("Headphone Playback Volume", 2, 6, 1),
635};
636
630static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] __initdata = { 637static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] __initdata = {
631 AWACS_VOLUME("Master Playback Volume", 2, 6, 1), 638 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
632 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0), 639 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
@@ -645,12 +652,19 @@ static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] __initdata = {
645 AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_LINE, 0), 652 AWACS_SWITCH("Mic Capture Switch", 0, SHIFT_MUX_LINE, 0),
646}; 653};
647 654
655static struct snd_kcontrol_new snd_pmac_awacs_mixers2_pmac5500[] __initdata = {
656 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
657};
658
648static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata = 659static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata =
649AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1); 660AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1);
650 661
651static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac __initdata = 662static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac __initdata =
652AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1); 663AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1);
653 664
665static struct snd_kcontrol_new snd_pmac_awacs_master_sw_pmac5500 __initdata =
666AWACS_SWITCH("Headphone Playback Switch", 1, SHIFT_HDMUTE, 1);
667
654static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = { 668static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = {
655 AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0), 669 AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
656}; 670};
@@ -766,12 +780,16 @@ static void snd_pmac_awacs_resume(struct snd_pmac *chip)
766} 780}
767#endif /* CONFIG_PM */ 781#endif /* CONFIG_PM */
768 782
769#define IS_PM7500 (machine_is_compatible("AAPL,7500")) 783#define IS_PM7500 (machine_is_compatible("AAPL,7500") \
784 || machine_is_compatible("AAPL,8500") \
785 || machine_is_compatible("AAPL,9500"))
786#define IS_PM5500 (machine_is_compatible("AAPL,e411"))
770#define IS_BEIGE (machine_is_compatible("AAPL,Gossamer")) 787#define IS_BEIGE (machine_is_compatible("AAPL,Gossamer"))
771#define IS_IMAC1 (machine_is_compatible("PowerMac2,1")) 788#define IS_IMAC1 (machine_is_compatible("PowerMac2,1"))
772#define IS_IMAC2 (machine_is_compatible("PowerMac2,2") \ 789#define IS_IMAC2 (machine_is_compatible("PowerMac2,2") \
773 || machine_is_compatible("PowerMac4,1")) 790 || machine_is_compatible("PowerMac4,1"))
774#define IS_G4AGP (machine_is_compatible("PowerMac3,1")) 791#define IS_G4AGP (machine_is_compatible("PowerMac3,1"))
792#define IS_LOMBARD (machine_is_compatible("PowerBook1,1"))
775 793
776static int imac1, imac2; 794static int imac1, imac2;
777 795
@@ -858,10 +876,14 @@ int __init
858snd_pmac_awacs_init(struct snd_pmac *chip) 876snd_pmac_awacs_init(struct snd_pmac *chip)
859{ 877{
860 int pm7500 = IS_PM7500; 878 int pm7500 = IS_PM7500;
879 int pm5500 = IS_PM5500;
861 int beige = IS_BEIGE; 880 int beige = IS_BEIGE;
862 int g4agp = IS_G4AGP; 881 int g4agp = IS_G4AGP;
882 int lombard = IS_LOMBARD;
863 int imac; 883 int imac;
864 int err, vol; 884 int err, vol;
885 struct snd_kcontrol *vmaster_sw, *vmaster_vol;
886 struct snd_kcontrol *master_vol, *speaker_vol;
865 887
866 imac1 = IS_IMAC1; 888 imac1 = IS_IMAC1;
867 imac2 = IS_IMAC2; 889 imac2 = IS_IMAC2;
@@ -915,7 +937,7 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
915 /* set headphone-jack detection bit */ 937 /* set headphone-jack detection bit */
916 switch (chip->model) { 938 switch (chip->model) {
917 case PMAC_AWACS: 939 case PMAC_AWACS:
918 chip->hp_stat_mask = pm7500 ? MASK_HDPCONN 940 chip->hp_stat_mask = pm7500 || pm5500 ? MASK_HDPCONN
919 : MASK_LOCONN; 941 : MASK_LOCONN;
920 break; 942 break;
921 case PMAC_SCREAMER: 943 case PMAC_SCREAMER:
@@ -954,7 +976,7 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
954 return err; 976 return err;
955 if (beige || g4agp) 977 if (beige || g4agp)
956 ; 978 ;
957 else if (chip->model == PMAC_SCREAMER) 979 else if (chip->model == PMAC_SCREAMER || pm5500)
958 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2), 980 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2),
959 snd_pmac_screamer_mixers2); 981 snd_pmac_screamer_mixers2);
960 else if (!pm7500) 982 else if (!pm7500)
@@ -962,19 +984,35 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
962 snd_pmac_awacs_mixers2); 984 snd_pmac_awacs_mixers2);
963 if (err < 0) 985 if (err < 0)
964 return err; 986 return err;
987 if (pm5500) {
988 err = build_mixers(chip,
989 ARRAY_SIZE(snd_pmac_awacs_mixers2_pmac5500),
990 snd_pmac_awacs_mixers2_pmac5500);
991 if (err < 0)
992 return err;
993 }
965 if (pm7500) 994 if (pm7500)
966 err = build_mixers(chip, 995 err = build_mixers(chip,
967 ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500), 996 ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500),
968 snd_pmac_awacs_mixers_pmac7500); 997 snd_pmac_awacs_mixers_pmac7500);
998 else if (pm5500)
999 err = snd_ctl_add(chip->card,
1000 (master_vol = snd_ctl_new1(snd_pmac_awacs_mixers_pmac5500,
1001 chip)));
969 else if (beige) 1002 else if (beige)
970 err = build_mixers(chip, 1003 err = build_mixers(chip,
971 ARRAY_SIZE(snd_pmac_screamer_mixers_beige), 1004 ARRAY_SIZE(snd_pmac_screamer_mixers_beige),
972 snd_pmac_screamer_mixers_beige); 1005 snd_pmac_screamer_mixers_beige);
973 else if (imac) 1006 else if (imac || lombard) {
1007 err = snd_ctl_add(chip->card,
1008 (master_vol = snd_ctl_new1(snd_pmac_screamer_mixers_lo,
1009 chip)));
1010 if (err < 0)
1011 return err;
974 err = build_mixers(chip, 1012 err = build_mixers(chip,
975 ARRAY_SIZE(snd_pmac_screamer_mixers_imac), 1013 ARRAY_SIZE(snd_pmac_screamer_mixers_imac),
976 snd_pmac_screamer_mixers_imac); 1014 snd_pmac_screamer_mixers_imac);
977 else if (g4agp) 1015 } else if (g4agp)
978 err = build_mixers(chip, 1016 err = build_mixers(chip,
979 ARRAY_SIZE(snd_pmac_screamer_mixers_g4agp), 1017 ARRAY_SIZE(snd_pmac_screamer_mixers_g4agp),
980 snd_pmac_screamer_mixers_g4agp); 1018 snd_pmac_screamer_mixers_g4agp);
@@ -984,8 +1022,10 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
984 snd_pmac_awacs_mixers_pmac); 1022 snd_pmac_awacs_mixers_pmac);
985 if (err < 0) 1023 if (err < 0)
986 return err; 1024 return err;
987 chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac || g4agp) 1025 chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac || g4agp || lombard)
988 ? &snd_pmac_awacs_master_sw_imac 1026 ? &snd_pmac_awacs_master_sw_imac
1027 : pm5500
1028 ? &snd_pmac_awacs_master_sw_pmac5500
989 : &snd_pmac_awacs_master_sw, chip); 1029 : &snd_pmac_awacs_master_sw, chip);
990 err = snd_ctl_add(chip->card, chip->master_sw_ctl); 1030 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
991 if (err < 0) 1031 if (err < 0)
@@ -1017,8 +1057,9 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
1017#endif /* PMAC_AMP_AVAIL */ 1057#endif /* PMAC_AMP_AVAIL */
1018 { 1058 {
1019 /* route A = headphone, route C = speaker */ 1059 /* route A = headphone, route C = speaker */
1020 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol), 1060 err = snd_ctl_add(chip->card,
1021 snd_pmac_awacs_speaker_vol); 1061 (speaker_vol = snd_ctl_new1(snd_pmac_awacs_speaker_vol,
1062 chip)));
1022 if (err < 0) 1063 if (err < 0)
1023 return err; 1064 return err;
1024 chip->speaker_sw_ctl = snd_ctl_new1(imac1 1065 chip->speaker_sw_ctl = snd_ctl_new1(imac1
@@ -1031,6 +1072,33 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
1031 return err; 1072 return err;
1032 } 1073 }
1033 1074
1075 if (pm5500 || imac || lombard) {
1076 vmaster_sw = snd_ctl_make_virtual_master(
1077 "Master Playback Switch", (unsigned int *) NULL);
1078 err = snd_ctl_add_slave_uncached(vmaster_sw,
1079 chip->master_sw_ctl);
1080 if (err < 0)
1081 return err;
1082 err = snd_ctl_add_slave_uncached(vmaster_sw,
1083 chip->speaker_sw_ctl);
1084 if (err < 0)
1085 return err;
1086 err = snd_ctl_add(chip->card, vmaster_sw);
1087 if (err < 0)
1088 return err;
1089 vmaster_vol = snd_ctl_make_virtual_master(
1090 "Master Playback Volume", (unsigned int *) NULL);
1091 err = snd_ctl_add_slave(vmaster_vol, master_vol);
1092 if (err < 0)
1093 return err;
1094 err = snd_ctl_add_slave(vmaster_vol, speaker_vol);
1095 if (err < 0)
1096 return err;
1097 err = snd_ctl_add(chip->card, vmaster_vol);
1098 if (err < 0)
1099 return err;
1100 }
1101
1034 if (beige || g4agp) 1102 if (beige || g4agp)
1035 err = build_mixers(chip, 1103 err = build_mixers(chip,
1036 ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige), 1104 ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige),
diff --git a/sound/ppc/burgundy.c b/sound/ppc/burgundy.c
index f860d39af36b..45a76297c38d 100644
--- a/sound/ppc/burgundy.c
+++ b/sound/ppc/burgundy.c
@@ -35,7 +35,7 @@ snd_pmac_burgundy_busy_wait(struct snd_pmac *chip)
35 int timeout = 50; 35 int timeout = 50;
36 while ((in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) && timeout--) 36 while ((in_le32(&chip->awacs->codec_ctrl) & MASK_NEWECMD) && timeout--)
37 udelay(1); 37 udelay(1);
38 if (! timeout) 38 if (timeout < 0)
39 printk(KERN_DEBUG "burgundy_busy_wait: timeout\n"); 39 printk(KERN_DEBUG "burgundy_busy_wait: timeout\n");
40} 40}
41 41
diff --git a/sound/ppc/daca.c b/sound/ppc/daca.c
index 8a5b29031933..f8d478c2da62 100644
--- a/sound/ppc/daca.c
+++ b/sound/ppc/daca.c
@@ -82,7 +82,7 @@ static int daca_set_volume(struct pmac_daca *mix)
82 data[1] |= mix->deemphasis ? 0x40 : 0; 82 data[1] |= mix->deemphasis ? 0x40 : 0;
83 if (i2c_smbus_write_block_data(mix->i2c.client, DACA_REG_AVOL, 83 if (i2c_smbus_write_block_data(mix->i2c.client, DACA_REG_AVOL,
84 2, data) < 0) { 84 2, data) < 0) {
85 snd_printk("failed to set volume \n"); 85 snd_printk(KERN_ERR "failed to set volume \n");
86 return -EINVAL; 86 return -EINVAL;
87 } 87 }
88 return 0; 88 return 0;
diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index af76ee862d27..9b4e9c316695 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -299,7 +299,7 @@ static int snd_pmac_pcm_trigger(struct snd_pmac *chip, struct pmac_stream *rec,
299 case SNDRV_PCM_TRIGGER_SUSPEND: 299 case SNDRV_PCM_TRIGGER_SUSPEND:
300 spin_lock(&chip->reg_lock); 300 spin_lock(&chip->reg_lock);
301 rec->running = 0; 301 rec->running = 0;
302 /*printk("stopped!!\n");*/ 302 /*printk(KERN_DEBUG "stopped!!\n");*/
303 snd_pmac_dma_stop(rec); 303 snd_pmac_dma_stop(rec);
304 for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++) 304 for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++)
305 out_le16(&cp->command, DBDMA_STOP); 305 out_le16(&cp->command, DBDMA_STOP);
@@ -334,7 +334,7 @@ static snd_pcm_uframes_t snd_pmac_pcm_pointer(struct snd_pmac *chip,
334 } 334 }
335#endif 335#endif
336 count += rec->cur_period * rec->period_size; 336 count += rec->cur_period * rec->period_size;
337 /*printk("pointer=%d\n", count);*/ 337 /*printk(KERN_DEBUG "pointer=%d\n", count);*/
338 return bytes_to_frames(subs->runtime, count); 338 return bytes_to_frames(subs->runtime, count);
339} 339}
340 340
@@ -486,7 +486,7 @@ static void snd_pmac_pcm_update(struct snd_pmac *chip, struct pmac_stream *rec)
486 if (! (stat & ACTIVE)) 486 if (! (stat & ACTIVE))
487 break; 487 break;
488 488
489 /*printk("update frag %d\n", rec->cur_period);*/ 489 /*printk(KERN_DEBUG "update frag %d\n", rec->cur_period);*/
490 st_le16(&cp->xfer_status, 0); 490 st_le16(&cp->xfer_status, 0);
491 st_le16(&cp->req_count, rec->period_size); 491 st_le16(&cp->req_count, rec->period_size);
492 /*st_le16(&cp->res_count, 0);*/ 492 /*st_le16(&cp->res_count, 0);*/
@@ -806,7 +806,7 @@ snd_pmac_ctrl_intr(int irq, void *devid)
806 struct snd_pmac *chip = devid; 806 struct snd_pmac *chip = devid;
807 int ctrl = in_le32(&chip->awacs->control); 807 int ctrl = in_le32(&chip->awacs->control);
808 808
809 /*printk("pmac: control interrupt.. 0x%x\n", ctrl);*/ 809 /*printk(KERN_DEBUG "pmac: control interrupt.. 0x%x\n", ctrl);*/
810 if (ctrl & MASK_PORTCHG) { 810 if (ctrl & MASK_PORTCHG) {
811 /* do something when headphone is plugged/unplugged? */ 811 /* do something when headphone is plugged/unplugged? */
812 if (chip->update_automute) 812 if (chip->update_automute)
@@ -1033,7 +1033,8 @@ static int __init snd_pmac_detect(struct snd_pmac *chip)
1033 } 1033 }
1034 if (of_device_is_compatible(sound, "tumbler")) { 1034 if (of_device_is_compatible(sound, "tumbler")) {
1035 chip->model = PMAC_TUMBLER; 1035 chip->model = PMAC_TUMBLER;
1036 chip->can_capture = machine_is_compatible("PowerMac4,2"); 1036 chip->can_capture = machine_is_compatible("PowerMac4,2")
1037 || machine_is_compatible("PowerBook4,1");
1037 chip->can_duplex = 0; 1038 chip->can_duplex = 0;
1038 // chip->can_byte_swap = 0; /* FIXME: check this */ 1039 // chip->can_byte_swap = 0; /* FIXME: check this */
1039 chip->num_freqs = ARRAY_SIZE(tumbler_freqs); 1040 chip->num_freqs = ARRAY_SIZE(tumbler_freqs);
diff --git a/sound/ppc/powermac.c b/sound/ppc/powermac.c
index c936225771ba..5a929069dce9 100644
--- a/sound/ppc/powermac.c
+++ b/sound/ppc/powermac.c
@@ -58,9 +58,9 @@ static int __init snd_pmac_probe(struct platform_device *devptr)
58 char *name_ext; 58 char *name_ext;
59 int err; 59 int err;
60 60
61 card = snd_card_new(index, id, THIS_MODULE, 0); 61 err = snd_card_create(index, id, THIS_MODULE, 0, &card);
62 if (card == NULL) 62 if (err < 0)
63 return -ENOMEM; 63 return err;
64 64
65 if ((err = snd_pmac_new(card, &chip)) < 0) 65 if ((err = snd_pmac_new(card, &chip)) < 0)
66 goto __error; 66 goto __error;
@@ -110,7 +110,7 @@ static int __init snd_pmac_probe(struct platform_device *devptr)
110 goto __error; 110 goto __error;
111 break; 111 break;
112 default: 112 default:
113 snd_printk("unsupported hardware %d\n", chip->model); 113 snd_printk(KERN_ERR "unsupported hardware %d\n", chip->model);
114 err = -EINVAL; 114 err = -EINVAL;
115 goto __error; 115 goto __error;
116 } 116 }
diff --git a/sound/ppc/snd_ps3.c b/sound/ppc/snd_ps3.c
index ff321110ec02..f361c26506aa 100644
--- a/sound/ppc/snd_ps3.c
+++ b/sound/ppc/snd_ps3.c
@@ -969,11 +969,9 @@ static int __init snd_ps3_driver_probe(struct ps3_system_bus_device *dev)
969 } 969 }
970 970
971 /* create card instance */ 971 /* create card instance */
972 the_card.card = snd_card_new(index, id, THIS_MODULE, 0); 972 ret = snd_card_create(index, id, THIS_MODULE, 0, &the_card.card);
973 if (!the_card.card) { 973 if (ret < 0)
974 ret = -ENXIO;
975 goto clean_irq; 974 goto clean_irq;
976 }
977 975
978 strcpy(the_card.card->driver, "PS3"); 976 strcpy(the_card.card->driver, "PS3");
979 strcpy(the_card.card->shortname, "PS3"); 977 strcpy(the_card.card->shortname, "PS3");
diff --git a/sound/ppc/tumbler.c b/sound/ppc/tumbler.c
index 3eb223385416..40222fcc0878 100644
--- a/sound/ppc/tumbler.c
+++ b/sound/ppc/tumbler.c
@@ -41,7 +41,7 @@
41#undef DEBUG 41#undef DEBUG
42 42
43#ifdef DEBUG 43#ifdef DEBUG
44#define DBG(fmt...) printk(fmt) 44#define DBG(fmt...) printk(KERN_DEBUG fmt)
45#else 45#else
46#define DBG(fmt...) 46#define DBG(fmt...)
47#endif 47#endif
@@ -240,7 +240,7 @@ static int tumbler_set_master_volume(struct pmac_tumbler *mix)
240 240
241 if (i2c_smbus_write_i2c_block_data(mix->i2c.client, TAS_REG_VOL, 6, 241 if (i2c_smbus_write_i2c_block_data(mix->i2c.client, TAS_REG_VOL, 6,
242 block) < 0) { 242 block) < 0) {
243 snd_printk("failed to set volume \n"); 243 snd_printk(KERN_ERR "failed to set volume \n");
244 return -EINVAL; 244 return -EINVAL;
245 } 245 }
246 return 0; 246 return 0;
@@ -350,7 +350,7 @@ static int tumbler_set_drc(struct pmac_tumbler *mix)
350 350
351 if (i2c_smbus_write_i2c_block_data(mix->i2c.client, TAS_REG_DRC, 351 if (i2c_smbus_write_i2c_block_data(mix->i2c.client, TAS_REG_DRC,
352 2, val) < 0) { 352 2, val) < 0) {
353 snd_printk("failed to set DRC\n"); 353 snd_printk(KERN_ERR "failed to set DRC\n");
354 return -EINVAL; 354 return -EINVAL;
355 } 355 }
356 return 0; 356 return 0;
@@ -386,7 +386,7 @@ static int snapper_set_drc(struct pmac_tumbler *mix)
386 386
387 if (i2c_smbus_write_i2c_block_data(mix->i2c.client, TAS_REG_DRC, 387 if (i2c_smbus_write_i2c_block_data(mix->i2c.client, TAS_REG_DRC,
388 6, val) < 0) { 388 6, val) < 0) {
389 snd_printk("failed to set DRC\n"); 389 snd_printk(KERN_ERR "failed to set DRC\n");
390 return -EINVAL; 390 return -EINVAL;
391 } 391 }
392 return 0; 392 return 0;
@@ -506,7 +506,8 @@ static int tumbler_set_mono_volume(struct pmac_tumbler *mix,
506 block[i] = (vol >> ((info->bytes - i - 1) * 8)) & 0xff; 506 block[i] = (vol >> ((info->bytes - i - 1) * 8)) & 0xff;
507 if (i2c_smbus_write_i2c_block_data(mix->i2c.client, info->reg, 507 if (i2c_smbus_write_i2c_block_data(mix->i2c.client, info->reg,
508 info->bytes, block) < 0) { 508 info->bytes, block) < 0) {
509 snd_printk("failed to set mono volume %d\n", info->index); 509 snd_printk(KERN_ERR "failed to set mono volume %d\n",
510 info->index);
510 return -EINVAL; 511 return -EINVAL;
511 } 512 }
512 return 0; 513 return 0;
@@ -643,7 +644,7 @@ static int snapper_set_mix_vol1(struct pmac_tumbler *mix, int idx, int ch, int r
643 } 644 }
644 if (i2c_smbus_write_i2c_block_data(mix->i2c.client, reg, 645 if (i2c_smbus_write_i2c_block_data(mix->i2c.client, reg,
645 9, block) < 0) { 646 9, block) < 0) {
646 snd_printk("failed to set mono volume %d\n", reg); 647 snd_printk(KERN_ERR "failed to set mono volume %d\n", reg);
647 return -EINVAL; 648 return -EINVAL;
648 } 649 }
649 return 0; 650 return 0;
diff --git a/sound/sh/Kconfig b/sound/sh/Kconfig
index cfc143985802..aed0f90c3919 100644
--- a/sound/sh/Kconfig
+++ b/sound/sh/Kconfig
@@ -15,6 +15,7 @@ config SND_AICA
15 tristate "Dreamcast Yamaha AICA sound" 15 tristate "Dreamcast Yamaha AICA sound"
16 depends on SH_DREAMCAST 16 depends on SH_DREAMCAST
17 select SND_PCM 17 select SND_PCM
18 select G2_DMA
18 help 19 help
19 ALSA Sound driver for the SEGA Dreamcast console. 20 ALSA Sound driver for the SEGA Dreamcast console.
20 21
diff --git a/sound/sh/aica.c b/sound/sh/aica.c
index 7c920f3e7fe3..f551233c5a08 100644
--- a/sound/sh/aica.c
+++ b/sound/sh/aica.c
@@ -609,11 +609,11 @@ static int __devinit snd_aica_probe(struct platform_device *devptr)
609 dreamcastcard = kmalloc(sizeof(struct snd_card_aica), GFP_KERNEL); 609 dreamcastcard = kmalloc(sizeof(struct snd_card_aica), GFP_KERNEL);
610 if (unlikely(!dreamcastcard)) 610 if (unlikely(!dreamcastcard))
611 return -ENOMEM; 611 return -ENOMEM;
612 dreamcastcard->card = 612 err = snd_card_create(index, SND_AICA_DRIVER, THIS_MODULE, 0,
613 snd_card_new(index, SND_AICA_DRIVER, THIS_MODULE, 0); 613 &dreamcastcard->card);
614 if (unlikely(!dreamcastcard->card)) { 614 if (unlikely(err < 0)) {
615 kfree(dreamcastcard); 615 kfree(dreamcastcard);
616 return -ENODEV; 616 return err;
617 } 617 }
618 strcpy(dreamcastcard->card->driver, "snd_aica"); 618 strcpy(dreamcastcard->card->driver, "snd_aica");
619 strcpy(dreamcastcard->card->shortname, SND_AICA_DRIVER); 619 strcpy(dreamcastcard->card->shortname, SND_AICA_DRIVER);
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig
index ef025c66cc66..3d2bb6fc6dcc 100644
--- a/sound/soc/Kconfig
+++ b/sound/soc/Kconfig
@@ -6,6 +6,7 @@ menuconfig SND_SOC
6 tristate "ALSA for SoC audio support" 6 tristate "ALSA for SoC audio support"
7 select SND_PCM 7 select SND_PCM
8 select AC97_BUS if SND_SOC_AC97_BUS 8 select AC97_BUS if SND_SOC_AC97_BUS
9 select SND_JACK if INPUT=y || INPUT=SND
9 ---help--- 10 ---help---
10 11
11 If you want ASoC support, you should say Y here and also to the 12 If you want ASoC support, you should say Y here and also to the
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index 86a9b1f5b0f3..0237879fd412 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -1,4 +1,4 @@
1snd-soc-core-objs := soc-core.o soc-dapm.o 1snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o
2 2
3obj-$(CONFIG_SND_SOC) += snd-soc-core.o 3obj-$(CONFIG_SND_SOC) += snd-soc-core.o
4obj-$(CONFIG_SND_SOC) += codecs/ 4obj-$(CONFIG_SND_SOC) += codecs/
diff --git a/sound/soc/atmel/atmel-pcm.c b/sound/soc/atmel/atmel-pcm.c
index 3dcdc4e3cfa0..9ef6b96373f5 100644
--- a/sound/soc/atmel/atmel-pcm.c
+++ b/sound/soc/atmel/atmel-pcm.c
@@ -347,7 +347,7 @@ static int atmel_pcm_mmap(struct snd_pcm_substream *substream,
347 vma->vm_end - vma->vm_start, vma->vm_page_prot); 347 vma->vm_end - vma->vm_start, vma->vm_page_prot);
348} 348}
349 349
350struct snd_pcm_ops atmel_pcm_ops = { 350static struct snd_pcm_ops atmel_pcm_ops = {
351 .open = atmel_pcm_open, 351 .open = atmel_pcm_open,
352 .close = atmel_pcm_close, 352 .close = atmel_pcm_close,
353 .ioctl = snd_pcm_lib_ioctl, 353 .ioctl = snd_pcm_lib_ioctl,
diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
index ff0054b76502..e588e63f18d2 100644
--- a/sound/soc/atmel/atmel_ssc_dai.c
+++ b/sound/soc/atmel/atmel_ssc_dai.c
@@ -697,6 +697,15 @@ static int atmel_ssc_resume(struct snd_soc_dai *cpu_dai)
697#define ATMEL_SSC_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\ 697#define ATMEL_SSC_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |\
698 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 698 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
699 699
700static struct snd_soc_dai_ops atmel_ssc_dai_ops = {
701 .startup = atmel_ssc_startup,
702 .shutdown = atmel_ssc_shutdown,
703 .prepare = atmel_ssc_prepare,
704 .hw_params = atmel_ssc_hw_params,
705 .set_fmt = atmel_ssc_set_dai_fmt,
706 .set_clkdiv = atmel_ssc_set_dai_clkdiv,
707};
708
700struct snd_soc_dai atmel_ssc_dai[NUM_SSC_DEVICES] = { 709struct snd_soc_dai atmel_ssc_dai[NUM_SSC_DEVICES] = {
701 { .name = "atmel-ssc0", 710 { .name = "atmel-ssc0",
702 .id = 0, 711 .id = 0,
@@ -712,13 +721,7 @@ struct snd_soc_dai atmel_ssc_dai[NUM_SSC_DEVICES] = {
712 .channels_max = 2, 721 .channels_max = 2,
713 .rates = ATMEL_SSC_RATES, 722 .rates = ATMEL_SSC_RATES,
714 .formats = ATMEL_SSC_FORMATS,}, 723 .formats = ATMEL_SSC_FORMATS,},
715 .ops = { 724 .ops = &atmel_ssc_dai_ops,
716 .startup = atmel_ssc_startup,
717 .shutdown = atmel_ssc_shutdown,
718 .prepare = atmel_ssc_prepare,
719 .hw_params = atmel_ssc_hw_params,
720 .set_fmt = atmel_ssc_set_dai_fmt,
721 .set_clkdiv = atmel_ssc_set_dai_clkdiv,},
722 .private_data = &ssc_info[0], 725 .private_data = &ssc_info[0],
723 }, 726 },
724#if NUM_SSC_DEVICES == 3 727#if NUM_SSC_DEVICES == 3
@@ -736,13 +739,7 @@ struct snd_soc_dai atmel_ssc_dai[NUM_SSC_DEVICES] = {
736 .channels_max = 2, 739 .channels_max = 2,
737 .rates = ATMEL_SSC_RATES, 740 .rates = ATMEL_SSC_RATES,
738 .formats = ATMEL_SSC_FORMATS,}, 741 .formats = ATMEL_SSC_FORMATS,},
739 .ops = { 742 .ops = &atmel_ssc_dai_ops,
740 .startup = atmel_ssc_startup,
741 .shutdown = atmel_ssc_shutdown,
742 .prepare = atmel_ssc_prepare,
743 .hw_params = atmel_ssc_hw_params,
744 .set_fmt = atmel_ssc_set_dai_fmt,
745 .set_clkdiv = atmel_ssc_set_dai_clkdiv,},
746 .private_data = &ssc_info[1], 743 .private_data = &ssc_info[1],
747 }, 744 },
748 { .name = "atmel-ssc2", 745 { .name = "atmel-ssc2",
@@ -759,13 +756,7 @@ struct snd_soc_dai atmel_ssc_dai[NUM_SSC_DEVICES] = {
759 .channels_max = 2, 756 .channels_max = 2,
760 .rates = ATMEL_SSC_RATES, 757 .rates = ATMEL_SSC_RATES,
761 .formats = ATMEL_SSC_FORMATS,}, 758 .formats = ATMEL_SSC_FORMATS,},
762 .ops = { 759 .ops = &atmel_ssc_dai_ops,
763 .startup = atmel_ssc_startup,
764 .shutdown = atmel_ssc_shutdown,
765 .prepare = atmel_ssc_prepare,
766 .hw_params = atmel_ssc_hw_params,
767 .set_fmt = atmel_ssc_set_dai_fmt,
768 .set_clkdiv = atmel_ssc_set_dai_clkdiv,},
769 .private_data = &ssc_info[2], 760 .private_data = &ssc_info[2],
770 }, 761 },
771#endif 762#endif
diff --git a/sound/soc/atmel/playpaq_wm8510.c b/sound/soc/atmel/playpaq_wm8510.c
index 43dd8cee83c6..70657534e6b1 100644
--- a/sound/soc/atmel/playpaq_wm8510.c
+++ b/sound/soc/atmel/playpaq_wm8510.c
@@ -164,38 +164,38 @@ static int playpaq_wm8510_hw_params(struct snd_pcm_substream *substream,
164 */ 164 */
165 switch (params_rate(params)) { 165 switch (params_rate(params)) {
166 case 48000: 166 case 48000:
167 pll_out = 12288000; 167 pll_out = 24576000;
168 mclk_div = WM8510_MCLKDIV_1; 168 mclk_div = WM8510_MCLKDIV_2;
169 bclk = WM8510_BCLKDIV_8; 169 bclk = WM8510_BCLKDIV_8;
170 break; 170 break;
171 171
172 case 44100: 172 case 44100:
173 pll_out = 11289600; 173 pll_out = 22579200;
174 mclk_div = WM8510_MCLKDIV_1; 174 mclk_div = WM8510_MCLKDIV_2;
175 bclk = WM8510_BCLKDIV_8; 175 bclk = WM8510_BCLKDIV_8;
176 break; 176 break;
177 177
178 case 22050: 178 case 22050:
179 pll_out = 11289600; 179 pll_out = 22579200;
180 mclk_div = WM8510_MCLKDIV_2; 180 mclk_div = WM8510_MCLKDIV_4;
181 bclk = WM8510_BCLKDIV_8; 181 bclk = WM8510_BCLKDIV_8;
182 break; 182 break;
183 183
184 case 16000: 184 case 16000:
185 pll_out = 12288000; 185 pll_out = 24576000;
186 mclk_div = WM8510_MCLKDIV_3; 186 mclk_div = WM8510_MCLKDIV_6;
187 bclk = WM8510_BCLKDIV_8; 187 bclk = WM8510_BCLKDIV_8;
188 break; 188 break;
189 189
190 case 11025: 190 case 11025:
191 pll_out = 11289600; 191 pll_out = 22579200;
192 mclk_div = WM8510_MCLKDIV_4; 192 mclk_div = WM8510_MCLKDIV_8;
193 bclk = WM8510_BCLKDIV_8; 193 bclk = WM8510_BCLKDIV_8;
194 break; 194 break;
195 195
196 case 8000: 196 case 8000:
197 pll_out = 12288000; 197 pll_out = 24576000;
198 mclk_div = WM8510_MCLKDIV_6; 198 mclk_div = WM8510_MCLKDIV_12;
199 bclk = WM8510_BCLKDIV_8; 199 bclk = WM8510_BCLKDIV_8;
200 break; 200 break;
201 201
diff --git a/sound/soc/atmel/sam9g20_wm8731.c b/sound/soc/atmel/sam9g20_wm8731.c
index 6ea04be911d0..173a239a541c 100644
--- a/sound/soc/atmel/sam9g20_wm8731.c
+++ b/sound/soc/atmel/sam9g20_wm8731.c
@@ -36,6 +36,7 @@
36#include <linux/timer.h> 36#include <linux/timer.h>
37#include <linux/interrupt.h> 37#include <linux/interrupt.h>
38#include <linux/platform_device.h> 38#include <linux/platform_device.h>
39#include <linux/i2c.h>
39 40
40#include <linux/atmel-ssc.h> 41#include <linux/atmel-ssc.h>
41 42
@@ -45,6 +46,7 @@
45#include <sound/soc.h> 46#include <sound/soc.h>
46#include <sound/soc-dapm.h> 47#include <sound/soc-dapm.h>
47 48
49#include <asm/mach-types.h>
48#include <mach/hardware.h> 50#include <mach/hardware.h>
49#include <mach/gpio.h> 51#include <mach/gpio.h>
50 52
@@ -52,6 +54,9 @@
52#include "atmel-pcm.h" 54#include "atmel-pcm.h"
53#include "atmel_ssc_dai.h" 55#include "atmel_ssc_dai.h"
54 56
57#define MCLK_RATE 12000000
58
59static struct clk *mclk;
55 60
56static int at91sam9g20ek_startup(struct snd_pcm_substream *substream) 61static int at91sam9g20ek_startup(struct snd_pcm_substream *substream)
57{ 62{
@@ -59,11 +64,12 @@ static int at91sam9g20ek_startup(struct snd_pcm_substream *substream)
59 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; 64 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
60 int ret; 65 int ret;
61 66
62 /* codec system clock is supplied by PCK0, set to 12MHz */
63 ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK, 67 ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK,
64 12000000, SND_SOC_CLOCK_IN); 68 MCLK_RATE, SND_SOC_CLOCK_IN);
65 if (ret < 0) 69 if (ret < 0) {
70 clk_disable(mclk);
66 return ret; 71 return ret;
72 }
67 73
68 return 0; 74 return 0;
69} 75}
@@ -189,6 +195,31 @@ static struct snd_soc_ops at91sam9g20ek_ops = {
189 .shutdown = at91sam9g20ek_shutdown, 195 .shutdown = at91sam9g20ek_shutdown,
190}; 196};
191 197
198static int at91sam9g20ek_set_bias_level(struct snd_soc_card *card,
199 enum snd_soc_bias_level level)
200{
201 static int mclk_on;
202 int ret = 0;
203
204 switch (level) {
205 case SND_SOC_BIAS_ON:
206 case SND_SOC_BIAS_PREPARE:
207 if (!mclk_on)
208 ret = clk_enable(mclk);
209 if (ret == 0)
210 mclk_on = 1;
211 break;
212
213 case SND_SOC_BIAS_OFF:
214 case SND_SOC_BIAS_STANDBY:
215 if (mclk_on)
216 clk_disable(mclk);
217 mclk_on = 0;
218 break;
219 }
220
221 return ret;
222}
192 223
193static const struct snd_soc_dapm_widget at91sam9g20ek_dapm_widgets[] = { 224static const struct snd_soc_dapm_widget at91sam9g20ek_dapm_widgets[] = {
194 SND_SOC_DAPM_MIC("Int Mic", NULL), 225 SND_SOC_DAPM_MIC("Int Mic", NULL),
@@ -243,21 +274,48 @@ static struct snd_soc_dai_link at91sam9g20ek_dai = {
243}; 274};
244 275
245static struct snd_soc_card snd_soc_at91sam9g20ek = { 276static struct snd_soc_card snd_soc_at91sam9g20ek = {
246 .name = "WM8731", 277 .name = "AT91SAMG20-EK",
247 .platform = &atmel_soc_platform, 278 .platform = &atmel_soc_platform,
248 .dai_link = &at91sam9g20ek_dai, 279 .dai_link = &at91sam9g20ek_dai,
249 .num_links = 1, 280 .num_links = 1,
281 .set_bias_level = at91sam9g20ek_set_bias_level,
250}; 282};
251 283
252static struct wm8731_setup_data at91sam9g20ek_wm8731_setup = { 284/*
253 .i2c_bus = 0, 285 * FIXME: This is a temporary bodge to avoid cross-tree merge issues.
254 .i2c_address = 0x1b, 286 * New drivers should register the wm8731 I2C device in the machine
255}; 287 * setup code (under arch/arm for ARM systems).
288 */
289static int wm8731_i2c_register(void)
290{
291 struct i2c_board_info info;
292 struct i2c_adapter *adapter;
293 struct i2c_client *client;
294
295 memset(&info, 0, sizeof(struct i2c_board_info));
296 info.addr = 0x1b;
297 strlcpy(info.type, "wm8731", I2C_NAME_SIZE);
298
299 adapter = i2c_get_adapter(0);
300 if (!adapter) {
301 printk(KERN_ERR "can't get i2c adapter 0\n");
302 return -ENODEV;
303 }
304
305 client = i2c_new_device(adapter, &info);
306 i2c_put_adapter(adapter);
307 if (!client) {
308 printk(KERN_ERR "can't add i2c device at 0x%x\n",
309 (unsigned int)info.addr);
310 return -ENODEV;
311 }
312
313 return 0;
314}
256 315
257static struct snd_soc_device at91sam9g20ek_snd_devdata = { 316static struct snd_soc_device at91sam9g20ek_snd_devdata = {
258 .card = &snd_soc_at91sam9g20ek, 317 .card = &snd_soc_at91sam9g20ek,
259 .codec_dev = &soc_codec_dev_wm8731, 318 .codec_dev = &soc_codec_dev_wm8731,
260 .codec_data = &at91sam9g20ek_wm8731_setup,
261}; 319};
262 320
263static struct platform_device *at91sam9g20ek_snd_device; 321static struct platform_device *at91sam9g20ek_snd_device;
@@ -266,23 +324,56 @@ static int __init at91sam9g20ek_init(void)
266{ 324{
267 struct atmel_ssc_info *ssc_p = at91sam9g20ek_dai.cpu_dai->private_data; 325 struct atmel_ssc_info *ssc_p = at91sam9g20ek_dai.cpu_dai->private_data;
268 struct ssc_device *ssc = NULL; 326 struct ssc_device *ssc = NULL;
327 struct clk *pllb;
269 int ret; 328 int ret;
270 329
330 if (!machine_is_at91sam9g20ek())
331 return -ENODEV;
332
333 /*
334 * Codec MCLK is supplied by PCK0 - set it up.
335 */
336 mclk = clk_get(NULL, "pck0");
337 if (IS_ERR(mclk)) {
338 printk(KERN_ERR "ASoC: Failed to get MCLK\n");
339 ret = PTR_ERR(mclk);
340 goto err;
341 }
342
343 pllb = clk_get(NULL, "pllb");
344 if (IS_ERR(mclk)) {
345 printk(KERN_ERR "ASoC: Failed to get PLLB\n");
346 ret = PTR_ERR(mclk);
347 goto err_mclk;
348 }
349 ret = clk_set_parent(mclk, pllb);
350 clk_put(pllb);
351 if (ret != 0) {
352 printk(KERN_ERR "ASoC: Failed to set MCLK parent\n");
353 goto err_mclk;
354 }
355
356 clk_set_rate(mclk, MCLK_RATE);
357
271 /* 358 /*
272 * Request SSC device 359 * Request SSC device
273 */ 360 */
274 ssc = ssc_request(0); 361 ssc = ssc_request(0);
275 if (IS_ERR(ssc)) { 362 if (IS_ERR(ssc)) {
363 printk(KERN_ERR "ASoC: Failed to request SSC 0\n");
276 ret = PTR_ERR(ssc); 364 ret = PTR_ERR(ssc);
277 ssc = NULL; 365 ssc = NULL;
278 goto err_ssc; 366 goto err_ssc;
279 } 367 }
280 ssc_p->ssc = ssc; 368 ssc_p->ssc = ssc;
281 369
370 ret = wm8731_i2c_register();
371 if (ret != 0)
372 goto err_ssc;
373
282 at91sam9g20ek_snd_device = platform_device_alloc("soc-audio", -1); 374 at91sam9g20ek_snd_device = platform_device_alloc("soc-audio", -1);
283 if (!at91sam9g20ek_snd_device) { 375 if (!at91sam9g20ek_snd_device) {
284 printk(KERN_DEBUG 376 printk(KERN_ERR "ASoC: Platform device allocation failed\n");
285 "platform device allocation failed\n");
286 ret = -ENOMEM; 377 ret = -ENOMEM;
287 } 378 }
288 379
@@ -292,14 +383,19 @@ static int __init at91sam9g20ek_init(void)
292 383
293 ret = platform_device_add(at91sam9g20ek_snd_device); 384 ret = platform_device_add(at91sam9g20ek_snd_device);
294 if (ret) { 385 if (ret) {
295 printk(KERN_DEBUG 386 printk(KERN_ERR "ASoC: Platform device allocation failed\n");
296 "platform device allocation failed\n");
297 platform_device_put(at91sam9g20ek_snd_device); 387 platform_device_put(at91sam9g20ek_snd_device);
298 } 388 }
299 389
300 return ret; 390 return ret;
301 391
302err_ssc: 392err_ssc:
393 ssc_free(ssc);
394 ssc_p->ssc = NULL;
395err_mclk:
396 clk_put(mclk);
397 mclk = NULL;
398err:
303 return ret; 399 return ret;
304} 400}
305 401
@@ -317,6 +413,8 @@ static void __exit at91sam9g20ek_exit(void)
317 413
318 platform_device_unregister(at91sam9g20ek_snd_device); 414 platform_device_unregister(at91sam9g20ek_snd_device);
319 at91sam9g20ek_snd_device = NULL; 415 at91sam9g20ek_snd_device = NULL;
416 clk_put(mclk);
417 mclk = NULL;
320} 418}
321 419
322module_init(at91sam9g20ek_init); 420module_init(at91sam9g20ek_init);
diff --git a/sound/soc/au1x/dbdma2.c b/sound/soc/au1x/dbdma2.c
index bc8d654576c0..30490a259148 100644
--- a/sound/soc/au1x/dbdma2.c
+++ b/sound/soc/au1x/dbdma2.c
@@ -305,7 +305,7 @@ static int au1xpsc_pcm_close(struct snd_pcm_substream *substream)
305 return 0; 305 return 0;
306} 306}
307 307
308struct snd_pcm_ops au1xpsc_pcm_ops = { 308static struct snd_pcm_ops au1xpsc_pcm_ops = {
309 .open = au1xpsc_pcm_open, 309 .open = au1xpsc_pcm_open,
310 .close = au1xpsc_pcm_close, 310 .close = au1xpsc_pcm_close,
311 .ioctl = snd_pcm_lib_ioctl, 311 .ioctl = snd_pcm_lib_ioctl,
diff --git a/sound/soc/au1x/psc-ac97.c b/sound/soc/au1x/psc-ac97.c
index f0e30aec7f23..479d7bdf1865 100644
--- a/sound/soc/au1x/psc-ac97.c
+++ b/sound/soc/au1x/psc-ac97.c
@@ -342,6 +342,11 @@ static int au1xpsc_ac97_resume(struct snd_soc_dai *dai)
342 return 0; 342 return 0;
343} 343}
344 344
345static struct snd_soc_dai_ops au1xpsc_ac97_dai_ops = {
346 .trigger = au1xpsc_ac97_trigger,
347 .hw_params = au1xpsc_ac97_hw_params,
348};
349
345struct snd_soc_dai au1xpsc_ac97_dai = { 350struct snd_soc_dai au1xpsc_ac97_dai = {
346 .name = "au1xpsc_ac97", 351 .name = "au1xpsc_ac97",
347 .ac97_control = 1, 352 .ac97_control = 1,
@@ -361,10 +366,7 @@ struct snd_soc_dai au1xpsc_ac97_dai = {
361 .channels_min = 2, 366 .channels_min = 2,
362 .channels_max = 2, 367 .channels_max = 2,
363 }, 368 },
364 .ops = { 369 .ops = &au1xpsc_ac97_dai_ops,
365 .trigger = au1xpsc_ac97_trigger,
366 .hw_params = au1xpsc_ac97_hw_params,
367 },
368}; 370};
369EXPORT_SYMBOL_GPL(au1xpsc_ac97_dai); 371EXPORT_SYMBOL_GPL(au1xpsc_ac97_dai);
370 372
diff --git a/sound/soc/au1x/psc-i2s.c b/sound/soc/au1x/psc-i2s.c
index f916de4400ed..bb589327ee32 100644
--- a/sound/soc/au1x/psc-i2s.c
+++ b/sound/soc/au1x/psc-i2s.c
@@ -367,6 +367,12 @@ static int au1xpsc_i2s_resume(struct snd_soc_dai *cpu_dai)
367 return 0; 367 return 0;
368} 368}
369 369
370static struct snd_soc_dai_ops au1xpsc_i2s_dai_ops = {
371 .trigger = au1xpsc_i2s_trigger,
372 .hw_params = au1xpsc_i2s_hw_params,
373 .set_fmt = au1xpsc_i2s_set_fmt,
374};
375
370struct snd_soc_dai au1xpsc_i2s_dai = { 376struct snd_soc_dai au1xpsc_i2s_dai = {
371 .name = "au1xpsc_i2s", 377 .name = "au1xpsc_i2s",
372 .probe = au1xpsc_i2s_probe, 378 .probe = au1xpsc_i2s_probe,
@@ -385,11 +391,7 @@ struct snd_soc_dai au1xpsc_i2s_dai = {
385 .channels_min = 2, 391 .channels_min = 2,
386 .channels_max = 8, /* 2 without external help */ 392 .channels_max = 8, /* 2 without external help */
387 }, 393 },
388 .ops = { 394 .ops = &au1xpsc_i2s_dai_ops,
389 .trigger = au1xpsc_i2s_trigger,
390 .hw_params = au1xpsc_i2s_hw_params,
391 .set_fmt = au1xpsc_i2s_set_fmt,
392 },
393}; 395};
394EXPORT_SYMBOL(au1xpsc_i2s_dai); 396EXPORT_SYMBOL(au1xpsc_i2s_dai);
395 397
diff --git a/sound/soc/blackfin/bf5xx-ac97-pcm.c b/sound/soc/blackfin/bf5xx-ac97-pcm.c
index 8067cfafa3a7..8cfed1a5dcbe 100644
--- a/sound/soc/blackfin/bf5xx-ac97-pcm.c
+++ b/sound/soc/blackfin/bf5xx-ac97-pcm.c
@@ -297,7 +297,7 @@ static int bf5xx_pcm_copy(struct snd_pcm_substream *substream, int channel,
297} 297}
298#endif 298#endif
299 299
300struct snd_pcm_ops bf5xx_pcm_ac97_ops = { 300static struct snd_pcm_ops bf5xx_pcm_ac97_ops = {
301 .open = bf5xx_pcm_open, 301 .open = bf5xx_pcm_open,
302 .ioctl = snd_pcm_lib_ioctl, 302 .ioctl = snd_pcm_lib_ioctl,
303 .hw_params = bf5xx_pcm_hw_params, 303 .hw_params = bf5xx_pcm_hw_params,
diff --git a/sound/soc/blackfin/bf5xx-ac97.c b/sound/soc/blackfin/bf5xx-ac97.c
index 3be2be60576d..8a935f2d1767 100644
--- a/sound/soc/blackfin/bf5xx-ac97.c
+++ b/sound/soc/blackfin/bf5xx-ac97.c
@@ -31,72 +31,46 @@
31#include "bf5xx-sport.h" 31#include "bf5xx-sport.h"
32#include "bf5xx-ac97.h" 32#include "bf5xx-ac97.h"
33 33
34#if defined(CONFIG_BF54x)
35#define PIN_REQ_SPORT_0 {P_SPORT0_TFS, P_SPORT0_DTPRI, P_SPORT0_TSCLK, \
36 P_SPORT0_RFS, P_SPORT0_DRPRI, P_SPORT0_RSCLK, 0}
37
38#define PIN_REQ_SPORT_1 {P_SPORT1_TFS, P_SPORT1_DTPRI, P_SPORT1_TSCLK, \
39 P_SPORT1_RFS, P_SPORT1_DRPRI, P_SPORT1_RSCLK, 0}
40
41#define PIN_REQ_SPORT_2 {P_SPORT2_TFS, P_SPORT2_DTPRI, P_SPORT2_TSCLK, \
42 P_SPORT2_RFS, P_SPORT2_DRPRI, P_SPORT2_RSCLK, 0}
43
44#define PIN_REQ_SPORT_3 {P_SPORT3_TFS, P_SPORT3_DTPRI, P_SPORT3_TSCLK, \
45 P_SPORT3_RFS, P_SPORT3_DRPRI, P_SPORT3_RSCLK, 0}
46#else
47#define PIN_REQ_SPORT_0 {P_SPORT0_DTPRI, P_SPORT0_TSCLK, P_SPORT0_RFS, \
48 P_SPORT0_DRPRI, P_SPORT0_RSCLK, 0}
49
50#define PIN_REQ_SPORT_1 {P_SPORT1_DTPRI, P_SPORT1_TSCLK, P_SPORT1_RFS, \
51 P_SPORT1_DRPRI, P_SPORT1_RSCLK, 0}
52#endif
53
54static int *cmd_count; 34static int *cmd_count;
55static int sport_num = CONFIG_SND_BF5XX_SPORT_NUM; 35static int sport_num = CONFIG_SND_BF5XX_SPORT_NUM;
56 36
37#define SPORT_REQ(x) \
38 [x] = {P_SPORT##x##_TFS, P_SPORT##x##_DTPRI, P_SPORT##x##_TSCLK, \
39 P_SPORT##x##_RFS, P_SPORT##x##_DRPRI, P_SPORT##x##_RSCLK, 0}
57static u16 sport_req[][7] = { 40static u16 sport_req[][7] = {
58 PIN_REQ_SPORT_0, 41#ifdef SPORT0_TCR1
59#ifdef PIN_REQ_SPORT_1 42 SPORT_REQ(0),
60 PIN_REQ_SPORT_1, 43#endif
44#ifdef SPORT1_TCR1
45 SPORT_REQ(1),
61#endif 46#endif
62#ifdef PIN_REQ_SPORT_2 47#ifdef SPORT2_TCR1
63 PIN_REQ_SPORT_2, 48 SPORT_REQ(2),
64#endif 49#endif
65#ifdef PIN_REQ_SPORT_3 50#ifdef SPORT3_TCR1
66 PIN_REQ_SPORT_3, 51 SPORT_REQ(3),
67#endif 52#endif
68 }; 53};
69 54
55#define SPORT_PARAMS(x) \
56 [x] = { \
57 .dma_rx_chan = CH_SPORT##x##_RX, \
58 .dma_tx_chan = CH_SPORT##x##_TX, \
59 .err_irq = IRQ_SPORT##x##_ERROR, \
60 .regs = (struct sport_register *)SPORT##x##_TCR1, \
61 }
70static struct sport_param sport_params[4] = { 62static struct sport_param sport_params[4] = {
71 { 63#ifdef SPORT0_TCR1
72 .dma_rx_chan = CH_SPORT0_RX, 64 SPORT_PARAMS(0),
73 .dma_tx_chan = CH_SPORT0_TX,
74 .err_irq = IRQ_SPORT0_ERROR,
75 .regs = (struct sport_register *)SPORT0_TCR1,
76 },
77#ifdef PIN_REQ_SPORT_1
78 {
79 .dma_rx_chan = CH_SPORT1_RX,
80 .dma_tx_chan = CH_SPORT1_TX,
81 .err_irq = IRQ_SPORT1_ERROR,
82 .regs = (struct sport_register *)SPORT1_TCR1,
83 },
84#endif 65#endif
85#ifdef PIN_REQ_SPORT_2 66#ifdef SPORT1_TCR1
86 { 67 SPORT_PARAMS(1),
87 .dma_rx_chan = CH_SPORT2_RX,
88 .dma_tx_chan = CH_SPORT2_TX,
89 .err_irq = IRQ_SPORT2_ERROR,
90 .regs = (struct sport_register *)SPORT2_TCR1,
91 },
92#endif 68#endif
93#ifdef PIN_REQ_SPORT_3 69#ifdef SPORT2_TCR1
94 { 70 SPORT_PARAMS(2),
95 .dma_rx_chan = CH_SPORT3_RX, 71#endif
96 .dma_tx_chan = CH_SPORT3_TX, 72#ifdef SPORT3_TCR1
97 .err_irq = IRQ_SPORT3_ERROR, 73 SPORT_PARAMS(3),
98 .regs = (struct sport_register *)SPORT3_TCR1,
99 }
100#endif 74#endif
101}; 75};
102 76
@@ -332,11 +306,11 @@ static int bf5xx_ac97_probe(struct platform_device *pdev,
332 if (cmd_count == NULL) 306 if (cmd_count == NULL)
333 return -ENOMEM; 307 return -ENOMEM;
334 308
335 if (peripheral_request_list(&sport_req[sport_num][0], "soc-audio")) { 309 if (peripheral_request_list(sport_req[sport_num], "soc-audio")) {
336 pr_err("Requesting Peripherals failed\n"); 310 pr_err("Requesting Peripherals failed\n");
337 ret = -EFAULT; 311 ret = -EFAULT;
338 goto peripheral_err; 312 goto peripheral_err;
339 } 313 }
340 314
341#ifdef CONFIG_SND_BF5XX_HAVE_COLD_RESET 315#ifdef CONFIG_SND_BF5XX_HAVE_COLD_RESET
342 /* Request PB3 as reset pin */ 316 /* Request PB3 as reset pin */
@@ -383,9 +357,9 @@ sport_config_err:
383sport_err: 357sport_err:
384#ifdef CONFIG_SND_BF5XX_HAVE_COLD_RESET 358#ifdef CONFIG_SND_BF5XX_HAVE_COLD_RESET
385 gpio_free(CONFIG_SND_BF5XX_RESET_GPIO_NUM); 359 gpio_free(CONFIG_SND_BF5XX_RESET_GPIO_NUM);
386#endif
387gpio_err: 360gpio_err:
388 peripheral_free_list(&sport_req[sport_num][0]); 361#endif
362 peripheral_free_list(sport_req[sport_num]);
389peripheral_err: 363peripheral_err:
390 free_page((unsigned long)cmd_count); 364 free_page((unsigned long)cmd_count);
391 cmd_count = NULL; 365 cmd_count = NULL;
@@ -398,7 +372,7 @@ static void bf5xx_ac97_remove(struct platform_device *pdev,
398{ 372{
399 free_page((unsigned long)cmd_count); 373 free_page((unsigned long)cmd_count);
400 cmd_count = NULL; 374 cmd_count = NULL;
401 peripheral_free_list(&sport_req[sport_num][0]); 375 peripheral_free_list(sport_req[sport_num]);
402#ifdef CONFIG_SND_BF5XX_HAVE_COLD_RESET 376#ifdef CONFIG_SND_BF5XX_HAVE_COLD_RESET
403 gpio_free(CONFIG_SND_BF5XX_RESET_GPIO_NUM); 377 gpio_free(CONFIG_SND_BF5XX_RESET_GPIO_NUM);
404#endif 378#endif
diff --git a/sound/soc/blackfin/bf5xx-ad73311.c b/sound/soc/blackfin/bf5xx-ad73311.c
index 7f2a5e199075..edfbdc024e66 100644
--- a/sound/soc/blackfin/bf5xx-ad73311.c
+++ b/sound/soc/blackfin/bf5xx-ad73311.c
@@ -114,7 +114,7 @@ static int snd_ad73311_configure(void)
114 SSYNC(); 114 SSYNC();
115 115
116 /* When TUVF is set, the data is already send out */ 116 /* When TUVF is set, the data is already send out */
117 while (!(status & TUVF) && count++ < 10000) { 117 while (!(status & TUVF) && ++count < 10000) {
118 udelay(1); 118 udelay(1);
119 status = bfin_read_SPORT_STAT(); 119 status = bfin_read_SPORT_STAT();
120 SSYNC(); 120 SSYNC();
@@ -123,7 +123,7 @@ static int snd_ad73311_configure(void)
123 SSYNC(); 123 SSYNC();
124 local_irq_enable(); 124 local_irq_enable();
125 125
126 if (count == 10000) { 126 if (count >= 10000) {
127 printk(KERN_ERR "ad73311: failed to configure codec\n"); 127 printk(KERN_ERR "ad73311: failed to configure codec\n");
128 return -1; 128 return -1;
129 } 129 }
diff --git a/sound/soc/blackfin/bf5xx-i2s-pcm.c b/sound/soc/blackfin/bf5xx-i2s-pcm.c
index 53d290b3ea47..1318c4f627b7 100644
--- a/sound/soc/blackfin/bf5xx-i2s-pcm.c
+++ b/sound/soc/blackfin/bf5xx-i2s-pcm.c
@@ -184,7 +184,7 @@ static int bf5xx_pcm_mmap(struct snd_pcm_substream *substream,
184 return 0 ; 184 return 0 ;
185} 185}
186 186
187struct snd_pcm_ops bf5xx_pcm_i2s_ops = { 187static struct snd_pcm_ops bf5xx_pcm_i2s_ops = {
188 .open = bf5xx_pcm_open, 188 .open = bf5xx_pcm_open,
189 .ioctl = snd_pcm_lib_ioctl, 189 .ioctl = snd_pcm_lib_ioctl,
190 .hw_params = bf5xx_pcm_hw_params, 190 .hw_params = bf5xx_pcm_hw_params,
diff --git a/sound/soc/blackfin/bf5xx-i2s.c b/sound/soc/blackfin/bf5xx-i2s.c
index d1d95d2393fe..964824419678 100644
--- a/sound/soc/blackfin/bf5xx-i2s.c
+++ b/sound/soc/blackfin/bf5xx-i2s.c
@@ -287,6 +287,13 @@ static int bf5xx_i2s_resume(struct platform_device *pdev,
287#define BF5XX_I2S_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |\ 287#define BF5XX_I2S_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE |\
288 SNDRV_PCM_FMTBIT_S32_LE) 288 SNDRV_PCM_FMTBIT_S32_LE)
289 289
290static struct snd_soc_dai_ops bf5xx_i2s_dai_ops = {
291 .startup = bf5xx_i2s_startup,
292 .shutdown = bf5xx_i2s_shutdown,
293 .hw_params = bf5xx_i2s_hw_params,
294 .set_fmt = bf5xx_i2s_set_dai_fmt,
295};
296
290struct snd_soc_dai bf5xx_i2s_dai = { 297struct snd_soc_dai bf5xx_i2s_dai = {
291 .name = "bf5xx-i2s", 298 .name = "bf5xx-i2s",
292 .id = 0, 299 .id = 0,
@@ -304,12 +311,7 @@ struct snd_soc_dai bf5xx_i2s_dai = {
304 .channels_max = 2, 311 .channels_max = 2,
305 .rates = BF5XX_I2S_RATES, 312 .rates = BF5XX_I2S_RATES,
306 .formats = BF5XX_I2S_FORMATS,}, 313 .formats = BF5XX_I2S_FORMATS,},
307 .ops = { 314 .ops = &bf5xx_i2s_dai_ops,
308 .startup = bf5xx_i2s_startup,
309 .shutdown = bf5xx_i2s_shutdown,
310 .hw_params = bf5xx_i2s_hw_params,
311 .set_fmt = bf5xx_i2s_set_dai_fmt,
312 },
313}; 315};
314EXPORT_SYMBOL_GPL(bf5xx_i2s_dai); 316EXPORT_SYMBOL_GPL(bf5xx_i2s_dai);
315 317
diff --git a/sound/soc/blackfin/bf5xx-sport.c b/sound/soc/blackfin/bf5xx-sport.c
index 3b99e484d555..b7953c8cf838 100644
--- a/sound/soc/blackfin/bf5xx-sport.c
+++ b/sound/soc/blackfin/bf5xx-sport.c
@@ -133,7 +133,7 @@ static void setup_desc(struct dmasg *desc, void *buf, int fragcount,
133 int i; 133 int i;
134 134
135 for (i = 0; i < fragcount; ++i) { 135 for (i = 0; i < fragcount; ++i) {
136 desc[i].next_desc_addr = (unsigned long)&(desc[i + 1]); 136 desc[i].next_desc_addr = &(desc[i + 1]);
137 desc[i].start_addr = (unsigned long)buf + i*fragsize; 137 desc[i].start_addr = (unsigned long)buf + i*fragsize;
138 desc[i].cfg = cfg; 138 desc[i].cfg = cfg;
139 desc[i].x_count = x_count; 139 desc[i].x_count = x_count;
@@ -143,12 +143,12 @@ static void setup_desc(struct dmasg *desc, void *buf, int fragcount,
143 } 143 }
144 144
145 /* make circular */ 145 /* make circular */
146 desc[fragcount-1].next_desc_addr = (unsigned long)desc; 146 desc[fragcount-1].next_desc_addr = desc;
147 147
148 pr_debug("setup desc: desc0=%p, next0=%lx, desc1=%p," 148 pr_debug("setup desc: desc0=%p, next0=%p, desc1=%p,"
149 "next1=%lx\nx_count=%x,y_count=%x,addr=0x%lx,cfs=0x%x\n", 149 "next1=%p\nx_count=%x,y_count=%x,addr=0x%lx,cfs=0x%x\n",
150 &(desc[0]), desc[0].next_desc_addr, 150 desc, desc[0].next_desc_addr,
151 &(desc[1]), desc[1].next_desc_addr, 151 desc+1, desc[1].next_desc_addr,
152 desc[0].x_count, desc[0].y_count, 152 desc[0].x_count, desc[0].y_count,
153 desc[0].start_addr, desc[0].cfg); 153 desc[0].start_addr, desc[0].cfg);
154} 154}
@@ -184,22 +184,20 @@ static inline int sport_hook_rx_dummy(struct sport_device *sport)
184 BUG_ON(sport->curr_rx_desc == sport->dummy_rx_desc); 184 BUG_ON(sport->curr_rx_desc == sport->dummy_rx_desc);
185 185
186 /* Maybe the dummy buffer descriptor ring is damaged */ 186 /* Maybe the dummy buffer descriptor ring is damaged */
187 sport->dummy_rx_desc->next_desc_addr = \ 187 sport->dummy_rx_desc->next_desc_addr = sport->dummy_rx_desc + 1;
188 (unsigned long)(sport->dummy_rx_desc+1);
189 188
190 local_irq_save(flags); 189 local_irq_save(flags);
191 desc = (struct dmasg *)get_dma_next_desc_ptr(sport->dma_rx_chan); 190 desc = get_dma_next_desc_ptr(sport->dma_rx_chan);
192 /* Copy the descriptor which will be damaged to backup */ 191 /* Copy the descriptor which will be damaged to backup */
193 temp_desc = *desc; 192 temp_desc = *desc;
194 desc->x_count = 0xa; 193 desc->x_count = 0xa;
195 desc->y_count = 0; 194 desc->y_count = 0;
196 desc->next_desc_addr = (unsigned long)(sport->dummy_rx_desc); 195 desc->next_desc_addr = sport->dummy_rx_desc;
197 local_irq_restore(flags); 196 local_irq_restore(flags);
198 /* Waiting for dummy buffer descriptor is already hooked*/ 197 /* Waiting for dummy buffer descriptor is already hooked*/
199 while ((get_dma_curr_desc_ptr(sport->dma_rx_chan) - 198 while ((get_dma_curr_desc_ptr(sport->dma_rx_chan) -
200 sizeof(struct dmasg)) != 199 sizeof(struct dmasg)) != sport->dummy_rx_desc)
201 (unsigned long)sport->dummy_rx_desc) 200 continue;
202 ;
203 sport->curr_rx_desc = sport->dummy_rx_desc; 201 sport->curr_rx_desc = sport->dummy_rx_desc;
204 /* Restore the damaged descriptor */ 202 /* Restore the damaged descriptor */
205 *desc = temp_desc; 203 *desc = temp_desc;
@@ -210,14 +208,12 @@ static inline int sport_hook_rx_dummy(struct sport_device *sport)
210static inline int sport_rx_dma_start(struct sport_device *sport, int dummy) 208static inline int sport_rx_dma_start(struct sport_device *sport, int dummy)
211{ 209{
212 if (dummy) { 210 if (dummy) {
213 sport->dummy_rx_desc->next_desc_addr = \ 211 sport->dummy_rx_desc->next_desc_addr = sport->dummy_rx_desc;
214 (unsigned long) sport->dummy_rx_desc;
215 sport->curr_rx_desc = sport->dummy_rx_desc; 212 sport->curr_rx_desc = sport->dummy_rx_desc;
216 } else 213 } else
217 sport->curr_rx_desc = sport->dma_rx_desc; 214 sport->curr_rx_desc = sport->dma_rx_desc;
218 215
219 set_dma_next_desc_addr(sport->dma_rx_chan, \ 216 set_dma_next_desc_addr(sport->dma_rx_chan, sport->curr_rx_desc);
220 (unsigned long)(sport->curr_rx_desc));
221 set_dma_x_count(sport->dma_rx_chan, 0); 217 set_dma_x_count(sport->dma_rx_chan, 0);
222 set_dma_x_modify(sport->dma_rx_chan, 0); 218 set_dma_x_modify(sport->dma_rx_chan, 0);
223 set_dma_config(sport->dma_rx_chan, (DMAFLOW_LARGE | NDSIZE_9 | \ 219 set_dma_config(sport->dma_rx_chan, (DMAFLOW_LARGE | NDSIZE_9 | \
@@ -231,14 +227,12 @@ static inline int sport_rx_dma_start(struct sport_device *sport, int dummy)
231static inline int sport_tx_dma_start(struct sport_device *sport, int dummy) 227static inline int sport_tx_dma_start(struct sport_device *sport, int dummy)
232{ 228{
233 if (dummy) { 229 if (dummy) {
234 sport->dummy_tx_desc->next_desc_addr = \ 230 sport->dummy_tx_desc->next_desc_addr = sport->dummy_tx_desc;
235 (unsigned long) sport->dummy_tx_desc;
236 sport->curr_tx_desc = sport->dummy_tx_desc; 231 sport->curr_tx_desc = sport->dummy_tx_desc;
237 } else 232 } else
238 sport->curr_tx_desc = sport->dma_tx_desc; 233 sport->curr_tx_desc = sport->dma_tx_desc;
239 234
240 set_dma_next_desc_addr(sport->dma_tx_chan, \ 235 set_dma_next_desc_addr(sport->dma_tx_chan, sport->curr_tx_desc);
241 (unsigned long)(sport->curr_tx_desc));
242 set_dma_x_count(sport->dma_tx_chan, 0); 236 set_dma_x_count(sport->dma_tx_chan, 0);
243 set_dma_x_modify(sport->dma_tx_chan, 0); 237 set_dma_x_modify(sport->dma_tx_chan, 0);
244 set_dma_config(sport->dma_tx_chan, 238 set_dma_config(sport->dma_tx_chan,
@@ -261,11 +255,9 @@ int sport_rx_start(struct sport_device *sport)
261 BUG_ON(sport->curr_rx_desc != sport->dummy_rx_desc); 255 BUG_ON(sport->curr_rx_desc != sport->dummy_rx_desc);
262 local_irq_save(flags); 256 local_irq_save(flags);
263 while ((get_dma_curr_desc_ptr(sport->dma_rx_chan) - 257 while ((get_dma_curr_desc_ptr(sport->dma_rx_chan) -
264 sizeof(struct dmasg)) != 258 sizeof(struct dmasg)) != sport->dummy_rx_desc)
265 (unsigned long)sport->dummy_rx_desc) 259 continue;
266 ; 260 sport->dummy_rx_desc->next_desc_addr = sport->dma_rx_desc;
267 sport->dummy_rx_desc->next_desc_addr =
268 (unsigned long)(sport->dma_rx_desc);
269 local_irq_restore(flags); 261 local_irq_restore(flags);
270 sport->curr_rx_desc = sport->dma_rx_desc; 262 sport->curr_rx_desc = sport->dma_rx_desc;
271 } else { 263 } else {
@@ -310,23 +302,21 @@ static inline int sport_hook_tx_dummy(struct sport_device *sport)
310 BUG_ON(sport->dummy_tx_desc == NULL); 302 BUG_ON(sport->dummy_tx_desc == NULL);
311 BUG_ON(sport->curr_tx_desc == sport->dummy_tx_desc); 303 BUG_ON(sport->curr_tx_desc == sport->dummy_tx_desc);
312 304
313 sport->dummy_tx_desc->next_desc_addr = \ 305 sport->dummy_tx_desc->next_desc_addr = sport->dummy_tx_desc + 1;
314 (unsigned long)(sport->dummy_tx_desc+1);
315 306
316 /* Shorten the time on last normal descriptor */ 307 /* Shorten the time on last normal descriptor */
317 local_irq_save(flags); 308 local_irq_save(flags);
318 desc = (struct dmasg *)get_dma_next_desc_ptr(sport->dma_tx_chan); 309 desc = get_dma_next_desc_ptr(sport->dma_tx_chan);
319 /* Store the descriptor which will be damaged */ 310 /* Store the descriptor which will be damaged */
320 temp_desc = *desc; 311 temp_desc = *desc;
321 desc->x_count = 0xa; 312 desc->x_count = 0xa;
322 desc->y_count = 0; 313 desc->y_count = 0;
323 desc->next_desc_addr = (unsigned long)(sport->dummy_tx_desc); 314 desc->next_desc_addr = sport->dummy_tx_desc;
324 local_irq_restore(flags); 315 local_irq_restore(flags);
325 /* Waiting for dummy buffer descriptor is already hooked*/ 316 /* Waiting for dummy buffer descriptor is already hooked*/
326 while ((get_dma_curr_desc_ptr(sport->dma_tx_chan) - \ 317 while ((get_dma_curr_desc_ptr(sport->dma_tx_chan) - \
327 sizeof(struct dmasg)) != \ 318 sizeof(struct dmasg)) != sport->dummy_tx_desc)
328 (unsigned long)sport->dummy_tx_desc) 319 continue;
329 ;
330 sport->curr_tx_desc = sport->dummy_tx_desc; 320 sport->curr_tx_desc = sport->dummy_tx_desc;
331 /* Restore the damaged descriptor */ 321 /* Restore the damaged descriptor */
332 *desc = temp_desc; 322 *desc = temp_desc;
@@ -347,11 +337,9 @@ int sport_tx_start(struct sport_device *sport)
347 /* Hook the normal buffer descriptor */ 337 /* Hook the normal buffer descriptor */
348 local_irq_save(flags); 338 local_irq_save(flags);
349 while ((get_dma_curr_desc_ptr(sport->dma_tx_chan) - 339 while ((get_dma_curr_desc_ptr(sport->dma_tx_chan) -
350 sizeof(struct dmasg)) != 340 sizeof(struct dmasg)) != sport->dummy_tx_desc)
351 (unsigned long)sport->dummy_tx_desc) 341 continue;
352 ; 342 sport->dummy_tx_desc->next_desc_addr = sport->dma_tx_desc;
353 sport->dummy_tx_desc->next_desc_addr =
354 (unsigned long)(sport->dma_tx_desc);
355 local_irq_restore(flags); 343 local_irq_restore(flags);
356 sport->curr_tx_desc = sport->dma_tx_desc; 344 sport->curr_tx_desc = sport->dma_tx_desc;
357 } else { 345 } else {
@@ -536,19 +524,17 @@ static int sport_config_rx_dummy(struct sport_device *sport)
536 unsigned config; 524 unsigned config;
537 525
538 pr_debug("%s entered\n", __func__); 526 pr_debug("%s entered\n", __func__);
539#if L1_DATA_A_LENGTH != 0 527 if (L1_DATA_A_LENGTH)
540 desc = (struct dmasg *) l1_data_sram_alloc(2 * sizeof(*desc)); 528 desc = l1_data_sram_zalloc(2 * sizeof(*desc));
541#else 529 else {
542 {
543 dma_addr_t addr; 530 dma_addr_t addr;
544 desc = dma_alloc_coherent(NULL, 2 * sizeof(*desc), &addr, 0); 531 desc = dma_alloc_coherent(NULL, 2 * sizeof(*desc), &addr, 0);
532 memset(desc, 0, 2 * sizeof(*desc));
545 } 533 }
546#endif
547 if (desc == NULL) { 534 if (desc == NULL) {
548 pr_err("Failed to allocate memory for dummy rx desc\n"); 535 pr_err("Failed to allocate memory for dummy rx desc\n");
549 return -ENOMEM; 536 return -ENOMEM;
550 } 537 }
551 memset(desc, 0, 2 * sizeof(*desc));
552 sport->dummy_rx_desc = desc; 538 sport->dummy_rx_desc = desc;
553 desc->start_addr = (unsigned long)sport->dummy_buf; 539 desc->start_addr = (unsigned long)sport->dummy_buf;
554 config = DMAFLOW_LARGE | NDSIZE_9 | compute_wdsize(sport->wdsize) 540 config = DMAFLOW_LARGE | NDSIZE_9 | compute_wdsize(sport->wdsize)
@@ -559,8 +545,8 @@ static int sport_config_rx_dummy(struct sport_device *sport)
559 desc->y_count = 0; 545 desc->y_count = 0;
560 desc->y_modify = 0; 546 desc->y_modify = 0;
561 memcpy(desc+1, desc, sizeof(*desc)); 547 memcpy(desc+1, desc, sizeof(*desc));
562 desc->next_desc_addr = (unsigned long)(desc+1); 548 desc->next_desc_addr = desc + 1;
563 desc[1].next_desc_addr = (unsigned long)desc; 549 desc[1].next_desc_addr = desc;
564 return 0; 550 return 0;
565} 551}
566 552
@@ -571,19 +557,17 @@ static int sport_config_tx_dummy(struct sport_device *sport)
571 557
572 pr_debug("%s entered\n", __func__); 558 pr_debug("%s entered\n", __func__);
573 559
574#if L1_DATA_A_LENGTH != 0 560 if (L1_DATA_A_LENGTH)
575 desc = (struct dmasg *) l1_data_sram_alloc(2 * sizeof(*desc)); 561 desc = l1_data_sram_zalloc(2 * sizeof(*desc));
576#else 562 else {
577 {
578 dma_addr_t addr; 563 dma_addr_t addr;
579 desc = dma_alloc_coherent(NULL, 2 * sizeof(*desc), &addr, 0); 564 desc = dma_alloc_coherent(NULL, 2 * sizeof(*desc), &addr, 0);
565 memset(desc, 0, 2 * sizeof(*desc));
580 } 566 }
581#endif
582 if (!desc) { 567 if (!desc) {
583 pr_err("Failed to allocate memory for dummy tx desc\n"); 568 pr_err("Failed to allocate memory for dummy tx desc\n");
584 return -ENOMEM; 569 return -ENOMEM;
585 } 570 }
586 memset(desc, 0, 2 * sizeof(*desc));
587 sport->dummy_tx_desc = desc; 571 sport->dummy_tx_desc = desc;
588 desc->start_addr = (unsigned long)sport->dummy_buf + \ 572 desc->start_addr = (unsigned long)sport->dummy_buf + \
589 sport->dummy_count; 573 sport->dummy_count;
@@ -595,8 +579,8 @@ static int sport_config_tx_dummy(struct sport_device *sport)
595 desc->y_count = 0; 579 desc->y_count = 0;
596 desc->y_modify = 0; 580 desc->y_modify = 0;
597 memcpy(desc+1, desc, sizeof(*desc)); 581 memcpy(desc+1, desc, sizeof(*desc));
598 desc->next_desc_addr = (unsigned long)(desc+1); 582 desc->next_desc_addr = desc + 1;
599 desc[1].next_desc_addr = (unsigned long)desc; 583 desc[1].next_desc_addr = desc;
600 return 0; 584 return 0;
601} 585}
602 586
@@ -872,17 +856,15 @@ struct sport_device *sport_init(struct sport_param *param, unsigned wdsize,
872 sport->wdsize = wdsize; 856 sport->wdsize = wdsize;
873 sport->dummy_count = dummy_count; 857 sport->dummy_count = dummy_count;
874 858
875#if L1_DATA_A_LENGTH != 0 859 if (L1_DATA_A_LENGTH)
876 sport->dummy_buf = l1_data_sram_alloc(dummy_count * 2); 860 sport->dummy_buf = l1_data_sram_zalloc(dummy_count * 2);
877#else 861 else
878 sport->dummy_buf = kmalloc(dummy_count * 2, GFP_KERNEL); 862 sport->dummy_buf = kzalloc(dummy_count * 2, GFP_KERNEL);
879#endif
880 if (sport->dummy_buf == NULL) { 863 if (sport->dummy_buf == NULL) {
881 pr_err("Failed to allocate dummy buffer\n"); 864 pr_err("Failed to allocate dummy buffer\n");
882 goto __error; 865 goto __error;
883 } 866 }
884 867
885 memset(sport->dummy_buf, 0, dummy_count * 2);
886 ret = sport_config_rx_dummy(sport); 868 ret = sport_config_rx_dummy(sport);
887 if (ret) { 869 if (ret) {
888 pr_err("Failed to config rx dummy ring\n"); 870 pr_err("Failed to config rx dummy ring\n");
@@ -939,6 +921,7 @@ void sport_done(struct sport_device *sport)
939 sport = NULL; 921 sport = NULL;
940} 922}
941EXPORT_SYMBOL(sport_done); 923EXPORT_SYMBOL(sport_done);
924
942/* 925/*
943* It is only used to send several bytes when dma is not enabled 926* It is only used to send several bytes when dma is not enabled
944 * sport controller is configured but not enabled. 927 * sport controller is configured but not enabled.
@@ -1029,4 +1012,3 @@ EXPORT_SYMBOL(sport_send_and_recv);
1029MODULE_AUTHOR("Roy Huang"); 1012MODULE_AUTHOR("Roy Huang");
1030MODULE_DESCRIPTION("SPORT driver for ADI Blackfin"); 1013MODULE_DESCRIPTION("SPORT driver for ADI Blackfin");
1031MODULE_LICENSE("GPL"); 1014MODULE_LICENSE("GPL");
1032
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index d0e0d691ae51..b6c7f7a01cb0 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -10,9 +10,11 @@ config SND_SOC_I2C_AND_SPI
10 10
11config SND_SOC_ALL_CODECS 11config SND_SOC_ALL_CODECS
12 tristate "Build all ASoC CODEC drivers" 12 tristate "Build all ASoC CODEC drivers"
13 select SND_SOC_L3
13 select SND_SOC_AC97_CODEC if SND_SOC_AC97_BUS 14 select SND_SOC_AC97_CODEC if SND_SOC_AC97_BUS
14 select SND_SOC_AD1980 if SND_SOC_AC97_BUS 15 select SND_SOC_AD1980 if SND_SOC_AC97_BUS
15 select SND_SOC_AD73311 if I2C 16 select SND_SOC_AD73311 if I2C
17 select SND_SOC_AK4104 if SPI_MASTER
16 select SND_SOC_AK4535 if I2C 18 select SND_SOC_AK4535 if I2C
17 select SND_SOC_CS4270 if I2C 19 select SND_SOC_CS4270 if I2C
18 select SND_SOC_PCM3008 20 select SND_SOC_PCM3008
@@ -24,6 +26,7 @@ config SND_SOC_ALL_CODECS
24 select SND_SOC_UDA134X 26 select SND_SOC_UDA134X
25 select SND_SOC_UDA1380 if I2C 27 select SND_SOC_UDA1380 if I2C
26 select SND_SOC_WM8350 if MFD_WM8350 28 select SND_SOC_WM8350 if MFD_WM8350
29 select SND_SOC_WM8400 if MFD_WM8400
27 select SND_SOC_WM8510 if SND_SOC_I2C_AND_SPI 30 select SND_SOC_WM8510 if SND_SOC_I2C_AND_SPI
28 select SND_SOC_WM8580 if I2C 31 select SND_SOC_WM8580 if I2C
29 select SND_SOC_WM8728 if SND_SOC_I2C_AND_SPI 32 select SND_SOC_WM8728 if SND_SOC_I2C_AND_SPI
@@ -34,6 +37,7 @@ config SND_SOC_ALL_CODECS
34 select SND_SOC_WM8903 if I2C 37 select SND_SOC_WM8903 if I2C
35 select SND_SOC_WM8971 if I2C 38 select SND_SOC_WM8971 if I2C
36 select SND_SOC_WM8990 if I2C 39 select SND_SOC_WM8990 if I2C
40 select SND_SOC_WM9705 if SND_SOC_AC97_BUS
37 select SND_SOC_WM9712 if SND_SOC_AC97_BUS 41 select SND_SOC_WM9712 if SND_SOC_AC97_BUS
38 select SND_SOC_WM9713 if SND_SOC_AC97_BUS 42 select SND_SOC_WM9713 if SND_SOC_AC97_BUS
39 help 43 help
@@ -58,6 +62,9 @@ config SND_SOC_AD1980
58config SND_SOC_AD73311 62config SND_SOC_AD73311
59 tristate 63 tristate
60 64
65config SND_SOC_AK4104
66 tristate
67
61config SND_SOC_AK4535 68config SND_SOC_AK4535
62 tristate 69 tristate
63 70
@@ -65,12 +72,6 @@ config SND_SOC_AK4535
65config SND_SOC_CS4270 72config SND_SOC_CS4270
66 tristate 73 tristate
67 74
68# Cirrus Logic CS4270 Codec Hardware Mute Support
69# Select if you have external muting circuitry attached to your CS4270.
70config SND_SOC_CS4270_HWMUTE
71 bool
72 depends on SND_SOC_CS4270
73
74# Cirrus Logic CS4270 Codec VD = 3.3V Errata 75# Cirrus Logic CS4270 Codec VD = 3.3V Errata
75# Select if you are affected by the errata where the part will not function 76# Select if you are affected by the errata where the part will not function
76# if MCLK divide-by-1.5 is selected and VD is set to 3.3V. The driver will 77# if MCLK divide-by-1.5 is selected and VD is set to 3.3V. The driver will
@@ -90,7 +91,6 @@ config SND_SOC_SSM2602
90 91
91config SND_SOC_TLV320AIC23 92config SND_SOC_TLV320AIC23
92 tristate 93 tristate
93 depends on I2C
94 94
95config SND_SOC_TLV320AIC26 95config SND_SOC_TLV320AIC26
96 tristate "TI TLV320AIC26 Codec support" if SND_SOC_OF_SIMPLE 96 tristate "TI TLV320AIC26 Codec support" if SND_SOC_OF_SIMPLE
@@ -98,15 +98,12 @@ config SND_SOC_TLV320AIC26
98 98
99config SND_SOC_TLV320AIC3X 99config SND_SOC_TLV320AIC3X
100 tristate 100 tristate
101 depends on I2C
102 101
103config SND_SOC_TWL4030 102config SND_SOC_TWL4030
104 tristate 103 tristate
105 depends on TWL4030_CORE
106 104
107config SND_SOC_UDA134X 105config SND_SOC_UDA134X
108 tristate 106 tristate
109 select SND_SOC_L3
110 107
111config SND_SOC_UDA1380 108config SND_SOC_UDA1380
112 tristate 109 tristate
@@ -114,6 +111,9 @@ config SND_SOC_UDA1380
114config SND_SOC_WM8350 111config SND_SOC_WM8350
115 tristate 112 tristate
116 113
114config SND_SOC_WM8400
115 tristate
116
117config SND_SOC_WM8510 117config SND_SOC_WM8510
118 tristate 118 tristate
119 119
@@ -144,6 +144,9 @@ config SND_SOC_WM8971
144config SND_SOC_WM8990 144config SND_SOC_WM8990
145 tristate 145 tristate
146 146
147config SND_SOC_WM9705
148 tristate
149
147config SND_SOC_WM9712 150config SND_SOC_WM9712
148 tristate 151 tristate
149 152
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index c4ddc9aa2bbd..030d2454725f 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -1,6 +1,7 @@
1snd-soc-ac97-objs := ac97.o 1snd-soc-ac97-objs := ac97.o
2snd-soc-ad1980-objs := ad1980.o 2snd-soc-ad1980-objs := ad1980.o
3snd-soc-ad73311-objs := ad73311.o 3snd-soc-ad73311-objs := ad73311.o
4snd-soc-ak4104-objs := ak4104.o
4snd-soc-ak4535-objs := ak4535.o 5snd-soc-ak4535-objs := ak4535.o
5snd-soc-cs4270-objs := cs4270.o 6snd-soc-cs4270-objs := cs4270.o
6snd-soc-l3-objs := l3.o 7snd-soc-l3-objs := l3.o
@@ -13,6 +14,7 @@ snd-soc-twl4030-objs := twl4030.o
13snd-soc-uda134x-objs := uda134x.o 14snd-soc-uda134x-objs := uda134x.o
14snd-soc-uda1380-objs := uda1380.o 15snd-soc-uda1380-objs := uda1380.o
15snd-soc-wm8350-objs := wm8350.o 16snd-soc-wm8350-objs := wm8350.o
17snd-soc-wm8400-objs := wm8400.o
16snd-soc-wm8510-objs := wm8510.o 18snd-soc-wm8510-objs := wm8510.o
17snd-soc-wm8580-objs := wm8580.o 19snd-soc-wm8580-objs := wm8580.o
18snd-soc-wm8728-objs := wm8728.o 20snd-soc-wm8728-objs := wm8728.o
@@ -23,12 +25,14 @@ snd-soc-wm8900-objs := wm8900.o
23snd-soc-wm8903-objs := wm8903.o 25snd-soc-wm8903-objs := wm8903.o
24snd-soc-wm8971-objs := wm8971.o 26snd-soc-wm8971-objs := wm8971.o
25snd-soc-wm8990-objs := wm8990.o 27snd-soc-wm8990-objs := wm8990.o
28snd-soc-wm9705-objs := wm9705.o
26snd-soc-wm9712-objs := wm9712.o 29snd-soc-wm9712-objs := wm9712.o
27snd-soc-wm9713-objs := wm9713.o 30snd-soc-wm9713-objs := wm9713.o
28 31
29obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o 32obj-$(CONFIG_SND_SOC_AC97_CODEC) += snd-soc-ac97.o
30obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o 33obj-$(CONFIG_SND_SOC_AD1980) += snd-soc-ad1980.o
31obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o 34obj-$(CONFIG_SND_SOC_AD73311) += snd-soc-ad73311.o
35obj-$(CONFIG_SND_SOC_AK4104) += snd-soc-ak4104.o
32obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o 36obj-$(CONFIG_SND_SOC_AK4535) += snd-soc-ak4535.o
33obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o 37obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
34obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o 38obj-$(CONFIG_SND_SOC_L3) += snd-soc-l3.o
@@ -41,6 +45,7 @@ obj-$(CONFIG_SND_SOC_TWL4030) += snd-soc-twl4030.o
41obj-$(CONFIG_SND_SOC_UDA134X) += snd-soc-uda134x.o 45obj-$(CONFIG_SND_SOC_UDA134X) += snd-soc-uda134x.o
42obj-$(CONFIG_SND_SOC_UDA1380) += snd-soc-uda1380.o 46obj-$(CONFIG_SND_SOC_UDA1380) += snd-soc-uda1380.o
43obj-$(CONFIG_SND_SOC_WM8350) += snd-soc-wm8350.o 47obj-$(CONFIG_SND_SOC_WM8350) += snd-soc-wm8350.o
48obj-$(CONFIG_SND_SOC_WM8400) += snd-soc-wm8400.o
44obj-$(CONFIG_SND_SOC_WM8510) += snd-soc-wm8510.o 49obj-$(CONFIG_SND_SOC_WM8510) += snd-soc-wm8510.o
45obj-$(CONFIG_SND_SOC_WM8580) += snd-soc-wm8580.o 50obj-$(CONFIG_SND_SOC_WM8580) += snd-soc-wm8580.o
46obj-$(CONFIG_SND_SOC_WM8728) += snd-soc-wm8728.o 51obj-$(CONFIG_SND_SOC_WM8728) += snd-soc-wm8728.o
@@ -51,5 +56,7 @@ obj-$(CONFIG_SND_SOC_WM8900) += snd-soc-wm8900.o
51obj-$(CONFIG_SND_SOC_WM8903) += snd-soc-wm8903.o 56obj-$(CONFIG_SND_SOC_WM8903) += snd-soc-wm8903.o
52obj-$(CONFIG_SND_SOC_WM8971) += snd-soc-wm8971.o 57obj-$(CONFIG_SND_SOC_WM8971) += snd-soc-wm8971.o
53obj-$(CONFIG_SND_SOC_WM8990) += snd-soc-wm8990.o 58obj-$(CONFIG_SND_SOC_WM8990) += snd-soc-wm8990.o
59obj-$(CONFIG_SND_SOC_WM8991) += snd-soc-wm8991.o
60obj-$(CONFIG_SND_SOC_WM9705) += snd-soc-wm9705.o
54obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o 61obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o
55obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o 62obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c
index fb53e6511af2..b0d4af145b87 100644
--- a/sound/soc/codecs/ac97.c
+++ b/sound/soc/codecs/ac97.c
@@ -30,7 +30,7 @@ static int ac97_prepare(struct snd_pcm_substream *substream,
30 struct snd_pcm_runtime *runtime = substream->runtime; 30 struct snd_pcm_runtime *runtime = substream->runtime;
31 struct snd_soc_pcm_runtime *rtd = substream->private_data; 31 struct snd_soc_pcm_runtime *rtd = substream->private_data;
32 struct snd_soc_device *socdev = rtd->socdev; 32 struct snd_soc_device *socdev = rtd->socdev;
33 struct snd_soc_codec *codec = socdev->codec; 33 struct snd_soc_codec *codec = socdev->card->codec;
34 34
35 int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ? 35 int reg = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
36 AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE; 36 AC97_PCM_FRONT_DAC_RATE : AC97_PCM_LR_ADC_RATE;
@@ -41,6 +41,10 @@ static int ac97_prepare(struct snd_pcm_substream *substream,
41 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\ 41 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
42 SNDRV_PCM_RATE_48000) 42 SNDRV_PCM_RATE_48000)
43 43
44static struct snd_soc_dai_ops ac97_dai_ops = {
45 .prepare = ac97_prepare,
46};
47
44struct snd_soc_dai ac97_dai = { 48struct snd_soc_dai ac97_dai = {
45 .name = "AC97 HiFi", 49 .name = "AC97 HiFi",
46 .ac97_control = 1, 50 .ac97_control = 1,
@@ -56,8 +60,7 @@ struct snd_soc_dai ac97_dai = {
56 .channels_max = 2, 60 .channels_max = 2,
57 .rates = STD_AC97_RATES, 61 .rates = STD_AC97_RATES,
58 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 62 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
59 .ops = { 63 .ops = &ac97_dai_ops,
60 .prepare = ac97_prepare,},
61}; 64};
62EXPORT_SYMBOL_GPL(ac97_dai); 65EXPORT_SYMBOL_GPL(ac97_dai);
63 66
@@ -84,10 +87,10 @@ static int ac97_soc_probe(struct platform_device *pdev)
84 87
85 printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION); 88 printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION);
86 89
87 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 90 socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
88 if (!socdev->codec) 91 if (!socdev->card->codec)
89 return -ENOMEM; 92 return -ENOMEM;
90 codec = socdev->codec; 93 codec = socdev->card->codec;
91 mutex_init(&codec->mutex); 94 mutex_init(&codec->mutex);
92 95
93 codec->name = "AC97"; 96 codec->name = "AC97";
@@ -123,23 +126,21 @@ bus_err:
123 snd_soc_free_pcms(socdev); 126 snd_soc_free_pcms(socdev);
124 127
125err: 128err:
126 kfree(socdev->codec->reg_cache); 129 kfree(socdev->card->codec);
127 kfree(socdev->codec); 130 socdev->card->codec = NULL;
128 socdev->codec = NULL;
129 return ret; 131 return ret;
130} 132}
131 133
132static int ac97_soc_remove(struct platform_device *pdev) 134static int ac97_soc_remove(struct platform_device *pdev)
133{ 135{
134 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 136 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
135 struct snd_soc_codec *codec = socdev->codec; 137 struct snd_soc_codec *codec = socdev->card->codec;
136 138
137 if (!codec) 139 if (!codec)
138 return 0; 140 return 0;
139 141
140 snd_soc_free_pcms(socdev); 142 snd_soc_free_pcms(socdev);
141 kfree(socdev->codec->reg_cache); 143 kfree(socdev->card->codec);
142 kfree(socdev->codec);
143 144
144 return 0; 145 return 0;
145} 146}
@@ -149,7 +150,7 @@ static int ac97_soc_suspend(struct platform_device *pdev, pm_message_t msg)
149{ 150{
150 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 151 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
151 152
152 snd_ac97_suspend(socdev->codec->ac97); 153 snd_ac97_suspend(socdev->card->codec->ac97);
153 154
154 return 0; 155 return 0;
155} 156}
@@ -158,7 +159,7 @@ static int ac97_soc_resume(struct platform_device *pdev)
158{ 159{
159 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 160 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
160 161
161 snd_ac97_resume(socdev->codec->ac97); 162 snd_ac97_resume(socdev->card->codec->ac97);
162 163
163 return 0; 164 return 0;
164} 165}
diff --git a/sound/soc/codecs/ad1980.c b/sound/soc/codecs/ad1980.c
index 73fdbb4d4a3d..ddb3b08ac23c 100644
--- a/sound/soc/codecs/ad1980.c
+++ b/sound/soc/codecs/ad1980.c
@@ -93,20 +93,6 @@ SOC_ENUM("Capture Source", ad1980_cap_src),
93SOC_SINGLE("Mic Boost Switch", AC97_MIC, 6, 1, 0), 93SOC_SINGLE("Mic Boost Switch", AC97_MIC, 6, 1, 0),
94}; 94};
95 95
96/* add non dapm controls */
97static int ad1980_add_controls(struct snd_soc_codec *codec)
98{
99 int err, i;
100
101 for (i = 0; i < ARRAY_SIZE(ad1980_snd_ac97_controls); i++) {
102 err = snd_ctl_add(codec->card, snd_soc_cnew(
103 &ad1980_snd_ac97_controls[i], codec, NULL));
104 if (err < 0)
105 return err;
106 }
107 return 0;
108}
109
110static unsigned int ac97_read(struct snd_soc_codec *codec, 96static unsigned int ac97_read(struct snd_soc_codec *codec,
111 unsigned int reg) 97 unsigned int reg)
112{ 98{
@@ -123,7 +109,7 @@ static unsigned int ac97_read(struct snd_soc_codec *codec,
123 default: 109 default:
124 reg = reg >> 1; 110 reg = reg >> 1;
125 111
126 if (reg >= (ARRAY_SIZE(ad1980_reg))) 112 if (reg >= ARRAY_SIZE(ad1980_reg))
127 return -EINVAL; 113 return -EINVAL;
128 114
129 return cache[reg]; 115 return cache[reg];
@@ -137,7 +123,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
137 123
138 soc_ac97_ops.write(codec->ac97, reg, val); 124 soc_ac97_ops.write(codec->ac97, reg, val);
139 reg = reg >> 1; 125 reg = reg >> 1;
140 if (reg < (ARRAY_SIZE(ad1980_reg))) 126 if (reg < ARRAY_SIZE(ad1980_reg))
141 cache[reg] = val; 127 cache[reg] = val;
142 128
143 return 0; 129 return 0;
@@ -200,10 +186,10 @@ static int ad1980_soc_probe(struct platform_device *pdev)
200 186
201 printk(KERN_INFO "AD1980 SoC Audio Codec\n"); 187 printk(KERN_INFO "AD1980 SoC Audio Codec\n");
202 188
203 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 189 socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
204 if (socdev->codec == NULL) 190 if (socdev->card->codec == NULL)
205 return -ENOMEM; 191 return -ENOMEM;
206 codec = socdev->codec; 192 codec = socdev->card->codec;
207 mutex_init(&codec->mutex); 193 mutex_init(&codec->mutex);
208 194
209 codec->reg_cache = 195 codec->reg_cache =
@@ -269,7 +255,8 @@ static int ad1980_soc_probe(struct platform_device *pdev)
269 ext_status = ac97_read(codec, AC97_EXTENDED_STATUS); 255 ext_status = ac97_read(codec, AC97_EXTENDED_STATUS);
270 ac97_write(codec, AC97_EXTENDED_STATUS, ext_status&~0x3800); 256 ac97_write(codec, AC97_EXTENDED_STATUS, ext_status&~0x3800);
271 257
272 ad1980_add_controls(codec); 258 snd_soc_add_controls(codec, ad1980_snd_ac97_controls,
259 ARRAY_SIZE(ad1980_snd_ac97_controls));
273 ret = snd_soc_init_card(socdev); 260 ret = snd_soc_init_card(socdev);
274 if (ret < 0) { 261 if (ret < 0) {
275 printk(KERN_ERR "ad1980: failed to register card\n"); 262 printk(KERN_ERR "ad1980: failed to register card\n");
@@ -288,15 +275,15 @@ codec_err:
288 kfree(codec->reg_cache); 275 kfree(codec->reg_cache);
289 276
290cache_err: 277cache_err:
291 kfree(socdev->codec); 278 kfree(socdev->card->codec);
292 socdev->codec = NULL; 279 socdev->card->codec = NULL;
293 return ret; 280 return ret;
294} 281}
295 282
296static int ad1980_soc_remove(struct platform_device *pdev) 283static int ad1980_soc_remove(struct platform_device *pdev)
297{ 284{
298 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 285 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
299 struct snd_soc_codec *codec = socdev->codec; 286 struct snd_soc_codec *codec = socdev->card->codec;
300 287
301 if (codec == NULL) 288 if (codec == NULL)
302 return 0; 289 return 0;
diff --git a/sound/soc/codecs/ad73311.c b/sound/soc/codecs/ad73311.c
index b09289a1e55a..e61dac5e7b8f 100644
--- a/sound/soc/codecs/ad73311.c
+++ b/sound/soc/codecs/ad73311.c
@@ -53,7 +53,7 @@ static int ad73311_soc_probe(struct platform_device *pdev)
53 codec->owner = THIS_MODULE; 53 codec->owner = THIS_MODULE;
54 codec->dai = &ad73311_dai; 54 codec->dai = &ad73311_dai;
55 codec->num_dai = 1; 55 codec->num_dai = 1;
56 socdev->codec = codec; 56 socdev->card->codec = codec;
57 INIT_LIST_HEAD(&codec->dapm_widgets); 57 INIT_LIST_HEAD(&codec->dapm_widgets);
58 INIT_LIST_HEAD(&codec->dapm_paths); 58 INIT_LIST_HEAD(&codec->dapm_paths);
59 59
@@ -75,15 +75,15 @@ static int ad73311_soc_probe(struct platform_device *pdev)
75register_err: 75register_err:
76 snd_soc_free_pcms(socdev); 76 snd_soc_free_pcms(socdev);
77pcm_err: 77pcm_err:
78 kfree(socdev->codec); 78 kfree(socdev->card->codec);
79 socdev->codec = NULL; 79 socdev->card->codec = NULL;
80 return ret; 80 return ret;
81} 81}
82 82
83static int ad73311_soc_remove(struct platform_device *pdev) 83static int ad73311_soc_remove(struct platform_device *pdev)
84{ 84{
85 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 85 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
86 struct snd_soc_codec *codec = socdev->codec; 86 struct snd_soc_codec *codec = socdev->card->codec;
87 87
88 if (codec == NULL) 88 if (codec == NULL)
89 return 0; 89 return 0;
diff --git a/sound/soc/codecs/ad73311.h b/sound/soc/codecs/ad73311.h
index 507ce0c30edf..569573d2d4d7 100644
--- a/sound/soc/codecs/ad73311.h
+++ b/sound/soc/codecs/ad73311.h
@@ -70,7 +70,7 @@
70#define REGD_IGS(x) (x & 0x7) 70#define REGD_IGS(x) (x & 0x7)
71#define REGD_RMOD (1 << 3) 71#define REGD_RMOD (1 << 3)
72#define REGD_OGS(x) ((x & 0x7) << 4) 72#define REGD_OGS(x) ((x & 0x7) << 4)
73#define REGD_MUTE (x << 7) 73#define REGD_MUTE (1 << 7)
74 74
75/* Control register E */ 75/* Control register E */
76#define CTRL_REG_E (4 << 8) 76#define CTRL_REG_E (4 << 8)
diff --git a/sound/soc/codecs/ak4104.c b/sound/soc/codecs/ak4104.c
new file mode 100644
index 000000000000..4d47bc4f7428
--- /dev/null
+++ b/sound/soc/codecs/ak4104.c
@@ -0,0 +1,365 @@
1/*
2 * AK4104 ALSA SoC (ASoC) driver
3 *
4 * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include <linux/module.h>
13#include <sound/core.h>
14#include <sound/soc.h>
15#include <sound/initval.h>
16#include <linux/spi/spi.h>
17#include <sound/asoundef.h>
18
19#include "ak4104.h"
20
21/* AK4104 registers addresses */
22#define AK4104_REG_CONTROL1 0x00
23#define AK4104_REG_RESERVED 0x01
24#define AK4104_REG_CONTROL2 0x02
25#define AK4104_REG_TX 0x03
26#define AK4104_REG_CHN_STATUS(x) ((x) + 0x04)
27#define AK4104_NUM_REGS 10
28
29#define AK4104_REG_MASK 0x1f
30#define AK4104_READ 0xc0
31#define AK4104_WRITE 0xe0
32#define AK4104_RESERVED_VAL 0x5b
33
34/* Bit masks for AK4104 registers */
35#define AK4104_CONTROL1_RSTN (1 << 0)
36#define AK4104_CONTROL1_PW (1 << 1)
37#define AK4104_CONTROL1_DIF0 (1 << 2)
38#define AK4104_CONTROL1_DIF1 (1 << 3)
39
40#define AK4104_CONTROL2_SEL0 (1 << 0)
41#define AK4104_CONTROL2_SEL1 (1 << 1)
42#define AK4104_CONTROL2_MODE (1 << 2)
43
44#define AK4104_TX_TXE (1 << 0)
45#define AK4104_TX_V (1 << 1)
46
47#define DRV_NAME "ak4104"
48
49struct ak4104_private {
50 struct snd_soc_codec codec;
51 u8 reg_cache[AK4104_NUM_REGS];
52};
53
54static int ak4104_fill_cache(struct snd_soc_codec *codec)
55{
56 int i;
57 u8 *reg_cache = codec->reg_cache;
58 struct spi_device *spi = codec->control_data;
59
60 for (i = 0; i < codec->reg_cache_size; i++) {
61 int ret = spi_w8r8(spi, i | AK4104_READ);
62 if (ret < 0) {
63 dev_err(&spi->dev, "SPI write failure\n");
64 return ret;
65 }
66
67 reg_cache[i] = ret;
68 }
69
70 return 0;
71}
72
73static unsigned int ak4104_read_reg_cache(struct snd_soc_codec *codec,
74 unsigned int reg)
75{
76 u8 *reg_cache = codec->reg_cache;
77
78 if (reg >= codec->reg_cache_size)
79 return -EINVAL;
80
81 return reg_cache[reg];
82}
83
84static int ak4104_spi_write(struct snd_soc_codec *codec, unsigned int reg,
85 unsigned int value)
86{
87 u8 *cache = codec->reg_cache;
88 struct spi_device *spi = codec->control_data;
89
90 if (reg >= codec->reg_cache_size)
91 return -EINVAL;
92
93 reg &= AK4104_REG_MASK;
94 reg |= AK4104_WRITE;
95
96 /* only write to the hardware if value has changed */
97 if (cache[reg] != value) {
98 u8 tmp[2] = { reg, value };
99 if (spi_write(spi, tmp, sizeof(tmp))) {
100 dev_err(&spi->dev, "SPI write failed\n");
101 return -EIO;
102 }
103
104 cache[reg] = value;
105 }
106
107 return 0;
108}
109
110static int ak4104_set_dai_fmt(struct snd_soc_dai *codec_dai,
111 unsigned int format)
112{
113 struct snd_soc_codec *codec = codec_dai->codec;
114 int val = 0;
115
116 val = ak4104_read_reg_cache(codec, AK4104_REG_CONTROL1);
117 if (val < 0)
118 return val;
119
120 val &= ~(AK4104_CONTROL1_DIF0 | AK4104_CONTROL1_DIF1);
121
122 /* set DAI format */
123 switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
124 case SND_SOC_DAIFMT_RIGHT_J:
125 break;
126 case SND_SOC_DAIFMT_LEFT_J:
127 val |= AK4104_CONTROL1_DIF0;
128 break;
129 case SND_SOC_DAIFMT_I2S:
130 val |= AK4104_CONTROL1_DIF0 | AK4104_CONTROL1_DIF1;
131 break;
132 default:
133 dev_err(codec->dev, "invalid dai format\n");
134 return -EINVAL;
135 }
136
137 /* This device can only be slave */
138 if ((format & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS)
139 return -EINVAL;
140
141 return ak4104_spi_write(codec, AK4104_REG_CONTROL1, val);
142}
143
144static int ak4104_hw_params(struct snd_pcm_substream *substream,
145 struct snd_pcm_hw_params *params,
146 struct snd_soc_dai *dai)
147{
148 struct snd_soc_pcm_runtime *rtd = substream->private_data;
149 struct snd_soc_device *socdev = rtd->socdev;
150 struct snd_soc_codec *codec = socdev->card->codec;
151 int val = 0;
152
153 /* set the IEC958 bits: consumer mode, no copyright bit */
154 val |= IEC958_AES0_CON_NOT_COPYRIGHT;
155 ak4104_spi_write(codec, AK4104_REG_CHN_STATUS(0), val);
156
157 val = 0;
158
159 switch (params_rate(params)) {
160 case 44100:
161 val |= IEC958_AES3_CON_FS_44100;
162 break;
163 case 48000:
164 val |= IEC958_AES3_CON_FS_48000;
165 break;
166 case 32000:
167 val |= IEC958_AES3_CON_FS_32000;
168 break;
169 default:
170 dev_err(codec->dev, "unsupported sampling rate\n");
171 return -EINVAL;
172 }
173
174 return ak4104_spi_write(codec, AK4104_REG_CHN_STATUS(3), val);
175}
176
177static struct snd_soc_dai_ops ak4101_dai_ops = {
178 .hw_params = ak4104_hw_params,
179 .set_fmt = ak4104_set_dai_fmt,
180};
181
182struct snd_soc_dai ak4104_dai = {
183 .name = DRV_NAME,
184 .playback = {
185 .stream_name = "Playback",
186 .channels_min = 2,
187 .channels_max = 2,
188 .rates = SNDRV_PCM_RATE_44100 |
189 SNDRV_PCM_RATE_48000 |
190 SNDRV_PCM_RATE_32000,
191 .formats = SNDRV_PCM_FMTBIT_S16_LE |
192 SNDRV_PCM_FMTBIT_S24_3LE |
193 SNDRV_PCM_FMTBIT_S24_LE
194 },
195 .ops = &ak4101_dai_ops,
196};
197
198static struct snd_soc_codec *ak4104_codec;
199
200static int ak4104_spi_probe(struct spi_device *spi)
201{
202 struct snd_soc_codec *codec;
203 struct ak4104_private *ak4104;
204 int ret, val;
205
206 spi->bits_per_word = 8;
207 spi->mode = SPI_MODE_0;
208 ret = spi_setup(spi);
209 if (ret < 0)
210 return ret;
211
212 ak4104 = kzalloc(sizeof(struct ak4104_private), GFP_KERNEL);
213 if (!ak4104) {
214 dev_err(&spi->dev, "could not allocate codec\n");
215 return -ENOMEM;
216 }
217
218 codec = &ak4104->codec;
219 mutex_init(&codec->mutex);
220 INIT_LIST_HEAD(&codec->dapm_widgets);
221 INIT_LIST_HEAD(&codec->dapm_paths);
222
223 codec->dev = &spi->dev;
224 codec->name = DRV_NAME;
225 codec->owner = THIS_MODULE;
226 codec->dai = &ak4104_dai;
227 codec->num_dai = 1;
228 codec->private_data = ak4104;
229 codec->control_data = spi;
230 codec->reg_cache = ak4104->reg_cache;
231 codec->reg_cache_size = AK4104_NUM_REGS;
232
233 /* read all regs and fill the cache */
234 ret = ak4104_fill_cache(codec);
235 if (ret < 0) {
236 dev_err(&spi->dev, "failed to fill register cache\n");
237 return ret;
238 }
239
240 /* read the 'reserved' register - according to the datasheet, it
241 * should contain 0x5b. Not a good way to verify the presence of
242 * the device, but there is no hardware ID register. */
243 if (ak4104_read_reg_cache(codec, AK4104_REG_RESERVED) !=
244 AK4104_RESERVED_VAL) {
245 ret = -ENODEV;
246 goto error_free_codec;
247 }
248
249 /* set power-up and non-reset bits */
250 val = ak4104_read_reg_cache(codec, AK4104_REG_CONTROL1);
251 val |= AK4104_CONTROL1_PW | AK4104_CONTROL1_RSTN;
252 ret = ak4104_spi_write(codec, AK4104_REG_CONTROL1, val);
253 if (ret < 0)
254 goto error_free_codec;
255
256 /* enable transmitter */
257 val = ak4104_read_reg_cache(codec, AK4104_REG_TX);
258 val |= AK4104_TX_TXE;
259 ret = ak4104_spi_write(codec, AK4104_REG_TX, val);
260 if (ret < 0)
261 goto error_free_codec;
262
263 ak4104_codec = codec;
264 ret = snd_soc_register_dai(&ak4104_dai);
265 if (ret < 0) {
266 dev_err(&spi->dev, "failed to register DAI\n");
267 goto error_free_codec;
268 }
269
270 spi_set_drvdata(spi, ak4104);
271 dev_info(&spi->dev, "SPI device initialized\n");
272 return 0;
273
274error_free_codec:
275 kfree(ak4104);
276 ak4104_dai.dev = NULL;
277 return ret;
278}
279
280static int __devexit ak4104_spi_remove(struct spi_device *spi)
281{
282 int ret, val;
283 struct ak4104_private *ak4104 = spi_get_drvdata(spi);
284
285 val = ak4104_read_reg_cache(&ak4104->codec, AK4104_REG_CONTROL1);
286 if (val < 0)
287 return val;
288
289 /* clear power-up and non-reset bits */
290 val &= ~(AK4104_CONTROL1_PW | AK4104_CONTROL1_RSTN);
291 ret = ak4104_spi_write(&ak4104->codec, AK4104_REG_CONTROL1, val);
292 if (ret < 0)
293 return ret;
294
295 ak4104_codec = NULL;
296 kfree(ak4104);
297 return 0;
298}
299
300static int ak4104_probe(struct platform_device *pdev)
301{
302 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
303 struct snd_soc_codec *codec = ak4104_codec;
304 int ret;
305
306 /* Connect the codec to the socdev. snd_soc_new_pcms() needs this. */
307 socdev->card->codec = codec;
308
309 /* Register PCMs */
310 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
311 if (ret < 0) {
312 dev_err(codec->dev, "failed to create pcms\n");
313 return ret;
314 }
315
316 /* Register the socdev */
317 ret = snd_soc_init_card(socdev);
318 if (ret < 0) {
319 dev_err(codec->dev, "failed to register card\n");
320 snd_soc_free_pcms(socdev);
321 return ret;
322 }
323
324 return 0;
325}
326
327static int ak4104_remove(struct platform_device *pdev)
328{
329 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
330 snd_soc_free_pcms(socdev);
331 return 0;
332};
333
334struct snd_soc_codec_device soc_codec_device_ak4104 = {
335 .probe = ak4104_probe,
336 .remove = ak4104_remove
337};
338EXPORT_SYMBOL_GPL(soc_codec_device_ak4104);
339
340static struct spi_driver ak4104_spi_driver = {
341 .driver = {
342 .name = DRV_NAME,
343 .owner = THIS_MODULE,
344 },
345 .probe = ak4104_spi_probe,
346 .remove = __devexit_p(ak4104_spi_remove),
347};
348
349static int __init ak4104_init(void)
350{
351 pr_info("Asahi Kasei AK4104 ALSA SoC Codec Driver\n");
352 return spi_register_driver(&ak4104_spi_driver);
353}
354module_init(ak4104_init);
355
356static void __exit ak4104_exit(void)
357{
358 spi_unregister_driver(&ak4104_spi_driver);
359}
360module_exit(ak4104_exit);
361
362MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
363MODULE_DESCRIPTION("Asahi Kasei AK4104 ALSA SoC driver");
364MODULE_LICENSE("GPL");
365
diff --git a/sound/soc/codecs/ak4104.h b/sound/soc/codecs/ak4104.h
new file mode 100644
index 000000000000..eb88fe7e4def
--- /dev/null
+++ b/sound/soc/codecs/ak4104.h
@@ -0,0 +1,7 @@
1#ifndef _AK4104_H
2#define _AK4104_H
3
4extern struct snd_soc_dai ak4104_dai;
5extern struct snd_soc_codec_device soc_codec_device_ak4104;
6
7#endif
diff --git a/sound/soc/codecs/ak4535.c b/sound/soc/codecs/ak4535.c
index 81300d8d42ca..1f63d387a2f4 100644
--- a/sound/soc/codecs/ak4535.c
+++ b/sound/soc/codecs/ak4535.c
@@ -155,21 +155,6 @@ static const struct snd_kcontrol_new ak4535_snd_controls[] = {
155 SOC_SINGLE("Mic Sidetone Volume", AK4535_VOL, 4, 7, 0), 155 SOC_SINGLE("Mic Sidetone Volume", AK4535_VOL, 4, 7, 0),
156}; 156};
157 157
158/* add non dapm controls */
159static int ak4535_add_controls(struct snd_soc_codec *codec)
160{
161 int err, i;
162
163 for (i = 0; i < ARRAY_SIZE(ak4535_snd_controls); i++) {
164 err = snd_ctl_add(codec->card,
165 snd_soc_cnew(&ak4535_snd_controls[i], codec, NULL));
166 if (err < 0)
167 return err;
168 }
169
170 return 0;
171}
172
173/* Mono 1 Mixer */ 158/* Mono 1 Mixer */
174static const struct snd_kcontrol_new ak4535_mono1_mixer_controls[] = { 159static const struct snd_kcontrol_new ak4535_mono1_mixer_controls[] = {
175 SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG1, 4, 1, 0), 160 SOC_DAPM_SINGLE("Mic Sidetone Switch", AK4535_SIG1, 4, 1, 0),
@@ -344,7 +329,7 @@ static int ak4535_hw_params(struct snd_pcm_substream *substream,
344{ 329{
345 struct snd_soc_pcm_runtime *rtd = substream->private_data; 330 struct snd_soc_pcm_runtime *rtd = substream->private_data;
346 struct snd_soc_device *socdev = rtd->socdev; 331 struct snd_soc_device *socdev = rtd->socdev;
347 struct snd_soc_codec *codec = socdev->codec; 332 struct snd_soc_codec *codec = socdev->card->codec;
348 struct ak4535_priv *ak4535 = codec->private_data; 333 struct ak4535_priv *ak4535 = codec->private_data;
349 u8 mode2 = ak4535_read_reg_cache(codec, AK4535_MODE2) & ~(0x3 << 5); 334 u8 mode2 = ak4535_read_reg_cache(codec, AK4535_MODE2) & ~(0x3 << 5);
350 int rate = params_rate(params), fs = 256; 335 int rate = params_rate(params), fs = 256;
@@ -436,6 +421,13 @@ static int ak4535_set_bias_level(struct snd_soc_codec *codec,
436 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ 421 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
437 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) 422 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
438 423
424static struct snd_soc_dai_ops ak4535_dai_ops = {
425 .hw_params = ak4535_hw_params,
426 .set_fmt = ak4535_set_dai_fmt,
427 .digital_mute = ak4535_mute,
428 .set_sysclk = ak4535_set_dai_sysclk,
429};
430
439struct snd_soc_dai ak4535_dai = { 431struct snd_soc_dai ak4535_dai = {
440 .name = "AK4535", 432 .name = "AK4535",
441 .playback = { 433 .playback = {
@@ -450,19 +442,14 @@ struct snd_soc_dai ak4535_dai = {
450 .channels_max = 2, 442 .channels_max = 2,
451 .rates = AK4535_RATES, 443 .rates = AK4535_RATES,
452 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 444 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
453 .ops = { 445 .ops = &ak4535_dai_ops,
454 .hw_params = ak4535_hw_params,
455 .set_fmt = ak4535_set_dai_fmt,
456 .digital_mute = ak4535_mute,
457 .set_sysclk = ak4535_set_dai_sysclk,
458 },
459}; 446};
460EXPORT_SYMBOL_GPL(ak4535_dai); 447EXPORT_SYMBOL_GPL(ak4535_dai);
461 448
462static int ak4535_suspend(struct platform_device *pdev, pm_message_t state) 449static int ak4535_suspend(struct platform_device *pdev, pm_message_t state)
463{ 450{
464 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 451 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
465 struct snd_soc_codec *codec = socdev->codec; 452 struct snd_soc_codec *codec = socdev->card->codec;
466 453
467 ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF); 454 ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF);
468 return 0; 455 return 0;
@@ -471,7 +458,7 @@ static int ak4535_suspend(struct platform_device *pdev, pm_message_t state)
471static int ak4535_resume(struct platform_device *pdev) 458static int ak4535_resume(struct platform_device *pdev)
472{ 459{
473 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 460 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
474 struct snd_soc_codec *codec = socdev->codec; 461 struct snd_soc_codec *codec = socdev->card->codec;
475 ak4535_sync(codec); 462 ak4535_sync(codec);
476 ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 463 ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
477 ak4535_set_bias_level(codec, codec->suspend_bias_level); 464 ak4535_set_bias_level(codec, codec->suspend_bias_level);
@@ -484,7 +471,7 @@ static int ak4535_resume(struct platform_device *pdev)
484 */ 471 */
485static int ak4535_init(struct snd_soc_device *socdev) 472static int ak4535_init(struct snd_soc_device *socdev)
486{ 473{
487 struct snd_soc_codec *codec = socdev->codec; 474 struct snd_soc_codec *codec = socdev->card->codec;
488 int ret = 0; 475 int ret = 0;
489 476
490 codec->name = "AK4535"; 477 codec->name = "AK4535";
@@ -510,7 +497,8 @@ static int ak4535_init(struct snd_soc_device *socdev)
510 /* power on device */ 497 /* power on device */
511 ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 498 ak4535_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
512 499
513 ak4535_add_controls(codec); 500 snd_soc_add_controls(codec, ak4535_snd_controls,
501 ARRAY_SIZE(ak4535_snd_controls));
514 ak4535_add_widgets(codec); 502 ak4535_add_widgets(codec);
515 ret = snd_soc_init_card(socdev); 503 ret = snd_soc_init_card(socdev);
516 if (ret < 0) { 504 if (ret < 0) {
@@ -537,7 +525,7 @@ static int ak4535_i2c_probe(struct i2c_client *i2c,
537 const struct i2c_device_id *id) 525 const struct i2c_device_id *id)
538{ 526{
539 struct snd_soc_device *socdev = ak4535_socdev; 527 struct snd_soc_device *socdev = ak4535_socdev;
540 struct snd_soc_codec *codec = socdev->codec; 528 struct snd_soc_codec *codec = socdev->card->codec;
541 int ret; 529 int ret;
542 530
543 i2c_set_clientdata(i2c, codec); 531 i2c_set_clientdata(i2c, codec);
@@ -636,7 +624,7 @@ static int ak4535_probe(struct platform_device *pdev)
636 } 624 }
637 625
638 codec->private_data = ak4535; 626 codec->private_data = ak4535;
639 socdev->codec = codec; 627 socdev->card->codec = codec;
640 mutex_init(&codec->mutex); 628 mutex_init(&codec->mutex);
641 INIT_LIST_HEAD(&codec->dapm_widgets); 629 INIT_LIST_HEAD(&codec->dapm_widgets);
642 INIT_LIST_HEAD(&codec->dapm_paths); 630 INIT_LIST_HEAD(&codec->dapm_paths);
@@ -663,7 +651,7 @@ static int ak4535_probe(struct platform_device *pdev)
663static int ak4535_remove(struct platform_device *pdev) 651static int ak4535_remove(struct platform_device *pdev)
664{ 652{
665 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 653 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
666 struct snd_soc_codec *codec = socdev->codec; 654 struct snd_soc_codec *codec = socdev->card->codec;
667 655
668 if (codec->control_data) 656 if (codec->control_data)
669 ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF); 657 ak4535_set_bias_level(codec, SND_SOC_BIAS_OFF);
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index f1aa0c34421c..7fa09a387622 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -3,27 +3,22 @@
3 * 3 *
4 * Author: Timur Tabi <timur@freescale.com> 4 * Author: Timur Tabi <timur@freescale.com>
5 * 5 *
6 * Copyright 2007 Freescale Semiconductor, Inc. This file is licensed under 6 * Copyright 2007-2009 Freescale Semiconductor, Inc. This file is licensed
7 * the terms of the GNU General Public License version 2. This program 7 * under the terms of the GNU General Public License version 2. This
8 * is licensed "as is" without any warranty of any kind, whether express 8 * program is licensed "as is" without any warranty of any kind, whether
9 * or implied. 9 * express or implied.
10 * 10 *
11 * This is an ASoC device driver for the Cirrus Logic CS4270 codec. 11 * This is an ASoC device driver for the Cirrus Logic CS4270 codec.
12 * 12 *
13 * Current features/limitations: 13 * Current features/limitations:
14 * 14 *
15 * 1) Software mode is supported. Stand-alone mode is automatically 15 * - Software mode is supported. Stand-alone mode is not supported.
16 * selected if I2C is disabled or if a CS4270 is not found on the I2C 16 * - Only I2C is supported, not SPI
17 * bus. However, stand-alone mode is only partially implemented because 17 * - Support for master and slave mode
18 * there is no mechanism yet for this driver and the machine driver to 18 * - The machine driver's 'startup' function must call
19 * communicate the values of the M0, M1, MCLK1, and MCLK2 pins. 19 * cs4270_set_dai_sysclk() with the value of MCLK.
20 * 2) Only I2C is supported, not SPI 20 * - Only I2S and left-justified modes are supported
21 * 3) Only Master mode is supported, not Slave. 21 * - Power management is not supported
22 * 4) The machine driver's 'startup' function must call
23 * cs4270_set_dai_sysclk() with the value of MCLK.
24 * 5) Only I2S and left-justified modes are supported
25 * 6) Power management is not supported
26 * 7) The only supported control is volume and hardware mute (if enabled)
27 */ 22 */
28 23
29#include <linux/module.h> 24#include <linux/module.h>
@@ -35,18 +30,6 @@
35 30
36#include "cs4270.h" 31#include "cs4270.h"
37 32
38/* If I2C is defined, then we support software mode. However, if we're
39 not compiled as module but I2C is, then we can't use I2C calls. */
40#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
41#define USE_I2C
42#endif
43
44/* Private data for the CS4270 */
45struct cs4270_private {
46 unsigned int mclk; /* Input frequency of the MCLK pin */
47 unsigned int mode; /* The mode (I2S or left-justified) */
48};
49
50/* 33/*
51 * The codec isn't really big-endian or little-endian, since the I2S 34 * The codec isn't really big-endian or little-endian, since the I2S
52 * interface requires data to be sent serially with the MSbit first. 35 * interface requires data to be sent serially with the MSbit first.
@@ -60,8 +43,6 @@ struct cs4270_private {
60 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \ 43 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \
61 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE) 44 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE)
62 45
63#ifdef USE_I2C
64
65/* CS4270 registers addresses */ 46/* CS4270 registers addresses */
66#define CS4270_CHIPID 0x01 /* Chip ID */ 47#define CS4270_CHIPID 0x01 /* Chip ID */
67#define CS4270_PWRCTL 0x02 /* Power Control */ 48#define CS4270_PWRCTL 0x02 /* Power Control */
@@ -121,8 +102,22 @@ struct cs4270_private {
121#define CS4270_MUTE_DAC_A 0x01 102#define CS4270_MUTE_DAC_A 0x01
122#define CS4270_MUTE_DAC_B 0x02 103#define CS4270_MUTE_DAC_B 0x02
123 104
124/* 105/* Private data for the CS4270 */
125 * Clock Ratio Selection for Master Mode with I2C enabled 106struct cs4270_private {
107 struct snd_soc_codec codec;
108 u8 reg_cache[CS4270_NUMREGS];
109 unsigned int mclk; /* Input frequency of the MCLK pin */
110 unsigned int mode; /* The mode (I2S or left-justified) */
111 unsigned int slave_mode;
112};
113
114/**
115 * struct cs4270_mode_ratios - clock ratio tables
116 * @ratio: the ratio of MCLK to the sample rate
117 * @speed_mode: the Speed Mode bits to set in the Mode Control register for
118 * this ratio
119 * @mclk: the Ratio Select bits to set in the Mode Control register for this
120 * ratio
126 * 121 *
127 * The data for this chart is taken from Table 5 of the CS4270 reference 122 * The data for this chart is taken from Table 5 of the CS4270 reference
128 * manual. 123 * manual.
@@ -131,31 +126,30 @@ struct cs4270_private {
131 * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling 126 * It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling
132 * rates the CS4270 currently supports. 127 * rates the CS4270 currently supports.
133 * 128 *
134 * Each element in this array corresponds to the ratios in mclk_ratios[]. 129 * @speed_mode is the corresponding bit pattern to be written to the
135 * These two arrays need to be in sync.
136 *
137 * 'speed_mode' is the corresponding bit pattern to be written to the
138 * MODE bits of the Mode Control Register 130 * MODE bits of the Mode Control Register
139 * 131 *
140 * 'mclk' is the corresponding bit pattern to be wirten to the MCLK bits of 132 * @mclk is the corresponding bit pattern to be wirten to the MCLK bits of
141 * the Mode Control Register. 133 * the Mode Control Register.
142 * 134 *
143 * In situations where a single ratio is represented by multiple speed 135 * In situations where a single ratio is represented by multiple speed
144 * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick 136 * modes, we favor the slowest speed. E.g, for a ratio of 128, we pick
145 * double-speed instead of quad-speed. However, the CS4270 errata states 137 * double-speed instead of quad-speed. However, the CS4270 errata states
146 * that Divide-By-1.5 can cause failures, so we avoid that mode where 138 * that divide-By-1.5 can cause failures, so we avoid that mode where
147 * possible. 139 * possible.
148 * 140 *
149 * ERRATA: There is an errata for the CS4270 where divide-by-1.5 does not 141 * Errata: There is an errata for the CS4270 where divide-by-1.5 does not
150 * work if VD = 3.3V. If this effects you, select the 142 * work if Vd is 3.3V. If this effects you, select the
151 * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will 143 * CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will
152 * never select any sample rates that require divide-by-1.5. 144 * never select any sample rates that require divide-by-1.5.
153 */ 145 */
154static struct { 146struct cs4270_mode_ratios {
155 unsigned int ratio; 147 unsigned int ratio;
156 u8 speed_mode; 148 u8 speed_mode;
157 u8 mclk; 149 u8 mclk;
158} cs4270_mode_ratios[] = { 150};
151
152static struct cs4270_mode_ratios cs4270_mode_ratios[] = {
159 {64, CS4270_MODE_4X, CS4270_MODE_DIV1}, 153 {64, CS4270_MODE_4X, CS4270_MODE_DIV1},
160#ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA 154#ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA
161 {96, CS4270_MODE_4X, CS4270_MODE_DIV15}, 155 {96, CS4270_MODE_4X, CS4270_MODE_DIV15},
@@ -172,34 +166,27 @@ static struct {
172/* The number of MCLK/LRCK ratios supported by the CS4270 */ 166/* The number of MCLK/LRCK ratios supported by the CS4270 */
173#define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios) 167#define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios)
174 168
175/* 169/**
176 * Determine the CS4270 samples rates. 170 * cs4270_set_dai_sysclk - determine the CS4270 samples rates.
171 * @codec_dai: the codec DAI
172 * @clk_id: the clock ID (ignored)
173 * @freq: the MCLK input frequency
174 * @dir: the clock direction (ignored)
177 * 175 *
178 * 'freq' is the input frequency to MCLK. The other parameters are ignored. 176 * This function is used to tell the codec driver what the input MCLK
177 * frequency is.
179 * 178 *
180 * The value of MCLK is used to determine which sample rates are supported 179 * The value of MCLK is used to determine which sample rates are supported
181 * by the CS4270. The ratio of MCLK / Fs must be equal to one of nine 180 * by the CS4270. The ratio of MCLK / Fs must be equal to one of nine
182 * support values: 64, 96, 128, 192, 256, 384, 512, 768, and 1024. 181 * supported values - 64, 96, 128, 192, 256, 384, 512, 768, and 1024.
183 * 182 *
184 * This function calculates the nine ratios and determines which ones match 183 * This function calculates the nine ratios and determines which ones match
185 * a standard sample rate. If there's a match, then it is added to the list 184 * a standard sample rate. If there's a match, then it is added to the list
186 * of support sample rates. 185 * of supported sample rates.
187 * 186 *
188 * This function must be called by the machine driver's 'startup' function, 187 * This function must be called by the machine driver's 'startup' function,
189 * otherwise the list of supported sample rates will not be available in 188 * otherwise the list of supported sample rates will not be available in
190 * time for ALSA. 189 * time for ALSA.
191 *
192 * Note that in stand-alone mode, the sample rate is determined by input
193 * pins M0, M1, MDIV1, and MDIV2. Also in stand-alone mode, divide-by-3
194 * is not a programmable option. However, divide-by-3 is not an available
195 * option in stand-alone mode. This cases two problems: a ratio of 768 is
196 * not available (it requires divide-by-3) and B) ratios 192 and 384 can
197 * only be selected with divide-by-1.5, but there is an errate that make
198 * this selection difficult.
199 *
200 * In addition, there is no mechanism for communicating with the machine
201 * driver what the input settings can be. This would need to be implemented
202 * for stand-alone mode to work.
203 */ 190 */
204static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai, 191static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai,
205 int clk_id, unsigned int freq, int dir) 192 int clk_id, unsigned int freq, int dir)
@@ -225,7 +212,7 @@ static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai,
225 rates &= ~SNDRV_PCM_RATE_KNOT; 212 rates &= ~SNDRV_PCM_RATE_KNOT;
226 213
227 if (!rates) { 214 if (!rates) {
228 printk(KERN_ERR "cs4270: could not find a valid sample rate\n"); 215 dev_err(codec->dev, "could not find a valid sample rate\n");
229 return -EINVAL; 216 return -EINVAL;
230 } 217 }
231 218
@@ -240,8 +227,10 @@ static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai,
240 return 0; 227 return 0;
241} 228}
242 229
243/* 230/**
244 * Configure the codec for the selected audio format 231 * cs4270_set_dai_fmt - configure the codec for the selected audio format
232 * @codec_dai: the codec DAI
233 * @format: a SND_SOC_DAIFMT_x value indicating the data format
245 * 234 *
246 * This function takes a bitmask of SND_SOC_DAIFMT_x bits and programs the 235 * This function takes a bitmask of SND_SOC_DAIFMT_x bits and programs the
247 * codec accordingly. 236 * codec accordingly.
@@ -258,32 +247,43 @@ static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai,
258 struct cs4270_private *cs4270 = codec->private_data; 247 struct cs4270_private *cs4270 = codec->private_data;
259 int ret = 0; 248 int ret = 0;
260 249
250 /* set DAI format */
261 switch (format & SND_SOC_DAIFMT_FORMAT_MASK) { 251 switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
262 case SND_SOC_DAIFMT_I2S: 252 case SND_SOC_DAIFMT_I2S:
263 case SND_SOC_DAIFMT_LEFT_J: 253 case SND_SOC_DAIFMT_LEFT_J:
264 cs4270->mode = format & SND_SOC_DAIFMT_FORMAT_MASK; 254 cs4270->mode = format & SND_SOC_DAIFMT_FORMAT_MASK;
265 break; 255 break;
266 default: 256 default:
267 printk(KERN_ERR "cs4270: invalid DAI format\n"); 257 dev_err(codec->dev, "invalid dai format\n");
258 ret = -EINVAL;
259 }
260
261 /* set master/slave audio interface */
262 switch (format & SND_SOC_DAIFMT_MASTER_MASK) {
263 case SND_SOC_DAIFMT_CBS_CFS:
264 cs4270->slave_mode = 1;
265 break;
266 case SND_SOC_DAIFMT_CBM_CFM:
267 cs4270->slave_mode = 0;
268 break;
269 default:
270 /* all other modes are unsupported by the hardware */
268 ret = -EINVAL; 271 ret = -EINVAL;
269 } 272 }
270 273
271 return ret; 274 return ret;
272} 275}
273 276
274/* 277/**
275 * A list of addresses on which this CS4270 could use. I2C addresses are 278 * cs4270_fill_cache - pre-fill the CS4270 register cache.
276 * 7 bits. For the CS4270, the upper four bits are always 1001, and the 279 * @codec: the codec for this CS4270
277 * lower three bits are determined via the AD2, AD1, and AD0 pins 280 *
278 * (respectively). 281 * This function fills in the CS4270 register cache by reading the register
279 */ 282 * values from the hardware.
280static const unsigned short normal_i2c[] = { 283 *
281 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, I2C_CLIENT_END 284 * This CS4270 registers are cached to avoid excessive I2C I/O operations.
282}; 285 * After the initial read to pre-fill the cache, the CS4270 never updates
283I2C_CLIENT_INSMOD; 286 * the register values, so we won't have a cache coherency problem.
284
285/*
286 * Pre-fill the CS4270 register cache.
287 * 287 *
288 * We use the auto-increment feature of the CS4270 to read all registers in 288 * We use the auto-increment feature of the CS4270 to read all registers in
289 * one shot. 289 * one shot.
@@ -298,7 +298,7 @@ static int cs4270_fill_cache(struct snd_soc_codec *codec)
298 CS4270_FIRSTREG | 0x80, CS4270_NUMREGS, cache); 298 CS4270_FIRSTREG | 0x80, CS4270_NUMREGS, cache);
299 299
300 if (length != CS4270_NUMREGS) { 300 if (length != CS4270_NUMREGS) {
301 printk(KERN_ERR "cs4270: I2C read failure, addr=0x%x\n", 301 dev_err(codec->dev, "i2c read failure, addr=0x%x\n",
302 i2c_client->addr); 302 i2c_client->addr);
303 return -EIO; 303 return -EIO;
304 } 304 }
@@ -306,12 +306,17 @@ static int cs4270_fill_cache(struct snd_soc_codec *codec)
306 return 0; 306 return 0;
307} 307}
308 308
309/* 309/**
310 * Read from the CS4270 register cache. 310 * cs4270_read_reg_cache - read from the CS4270 register cache.
311 * @codec: the codec for this CS4270
312 * @reg: the register to read
313 *
314 * This function returns the value for a given register. It reads only from
315 * the register cache, not the hardware itself.
311 * 316 *
312 * This CS4270 registers are cached to avoid excessive I2C I/O operations. 317 * This CS4270 registers are cached to avoid excessive I2C I/O operations.
313 * After the initial read to pre-fill the cache, the CS4270 never updates 318 * After the initial read to pre-fill the cache, the CS4270 never updates
314 * the register values, so we won't have a cache coherncy problem. 319 * the register values, so we won't have a cache coherency problem.
315 */ 320 */
316static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec, 321static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec,
317 unsigned int reg) 322 unsigned int reg)
@@ -324,8 +329,11 @@ static unsigned int cs4270_read_reg_cache(struct snd_soc_codec *codec,
324 return cache[reg - CS4270_FIRSTREG]; 329 return cache[reg - CS4270_FIRSTREG];
325} 330}
326 331
327/* 332/**
328 * Write to a CS4270 register via the I2C bus. 333 * cs4270_i2c_write - write to a CS4270 register via the I2C bus.
334 * @codec: the codec for this CS4270
335 * @reg: the register to write
336 * @value: the value to write to the register
329 * 337 *
330 * This function writes the given value to the given CS4270 register, and 338 * This function writes the given value to the given CS4270 register, and
331 * also updates the register cache. 339 * also updates the register cache.
@@ -346,7 +354,7 @@ static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg,
346 if (cache[reg - CS4270_FIRSTREG] != value) { 354 if (cache[reg - CS4270_FIRSTREG] != value) {
347 struct i2c_client *client = codec->control_data; 355 struct i2c_client *client = codec->control_data;
348 if (i2c_smbus_write_byte_data(client, reg, value)) { 356 if (i2c_smbus_write_byte_data(client, reg, value)) {
349 printk(KERN_ERR "cs4270: I2C write failed\n"); 357 dev_err(codec->dev, "i2c write failed\n");
350 return -EIO; 358 return -EIO;
351 } 359 }
352 360
@@ -357,11 +365,17 @@ static int cs4270_i2c_write(struct snd_soc_codec *codec, unsigned int reg,
357 return 0; 365 return 0;
358} 366}
359 367
360/* 368/**
361 * Program the CS4270 with the given hardware parameters. 369 * cs4270_hw_params - program the CS4270 with the given hardware parameters.
370 * @substream: the audio stream
371 * @params: the hardware parameters to set
372 * @dai: the SOC DAI (ignored)
373 *
374 * This function programs the hardware with the values provided.
375 * Specifically, the sample rate and the data format.
362 * 376 *
363 * The .ops functions are used to provide board-specific data, like 377 * The .ops functions are used to provide board-specific data, like input
364 * input frequencies, to this driver. This function takes that information, 378 * frequencies, to this driver. This function takes that information,
365 * combines it with the hardware parameters provided, and programs the 379 * combines it with the hardware parameters provided, and programs the
366 * hardware accordingly. 380 * hardware accordingly.
367 */ 381 */
@@ -371,7 +385,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream,
371{ 385{
372 struct snd_soc_pcm_runtime *rtd = substream->private_data; 386 struct snd_soc_pcm_runtime *rtd = substream->private_data;
373 struct snd_soc_device *socdev = rtd->socdev; 387 struct snd_soc_device *socdev = rtd->socdev;
374 struct snd_soc_codec *codec = socdev->codec; 388 struct snd_soc_codec *codec = socdev->card->codec;
375 struct cs4270_private *cs4270 = codec->private_data; 389 struct cs4270_private *cs4270 = codec->private_data;
376 int ret; 390 int ret;
377 unsigned int i; 391 unsigned int i;
@@ -391,33 +405,28 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream,
391 405
392 if (i == NUM_MCLK_RATIOS) { 406 if (i == NUM_MCLK_RATIOS) {
393 /* We did not find a matching ratio */ 407 /* We did not find a matching ratio */
394 printk(KERN_ERR "cs4270: could not find matching ratio\n"); 408 dev_err(codec->dev, "could not find matching ratio\n");
395 return -EINVAL; 409 return -EINVAL;
396 } 410 }
397 411
398 /* Freeze and power-down the codec */ 412 /* Set the sample rate */
399
400 ret = snd_soc_write(codec, CS4270_PWRCTL, CS4270_PWRCTL_FREEZE |
401 CS4270_PWRCTL_PDN_ADC | CS4270_PWRCTL_PDN_DAC |
402 CS4270_PWRCTL_PDN);
403 if (ret < 0) {
404 printk(KERN_ERR "cs4270: I2C write failed\n");
405 return ret;
406 }
407
408 /* Program the mode control register */
409 413
410 reg = snd_soc_read(codec, CS4270_MODE); 414 reg = snd_soc_read(codec, CS4270_MODE);
411 reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK); 415 reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK);
412 reg |= cs4270_mode_ratios[i].speed_mode | cs4270_mode_ratios[i].mclk; 416 reg |= cs4270_mode_ratios[i].mclk;
417
418 if (cs4270->slave_mode)
419 reg |= CS4270_MODE_SLAVE;
420 else
421 reg |= cs4270_mode_ratios[i].speed_mode;
413 422
414 ret = snd_soc_write(codec, CS4270_MODE, reg); 423 ret = snd_soc_write(codec, CS4270_MODE, reg);
415 if (ret < 0) { 424 if (ret < 0) {
416 printk(KERN_ERR "cs4270: I2C write failed\n"); 425 dev_err(codec->dev, "i2c write failed\n");
417 return ret; 426 return ret;
418 } 427 }
419 428
420 /* Program the format register */ 429 /* Set the DAI format */
421 430
422 reg = snd_soc_read(codec, CS4270_FORMAT); 431 reg = snd_soc_read(codec, CS4270_FORMAT);
423 reg &= ~(CS4270_FORMAT_DAC_MASK | CS4270_FORMAT_ADC_MASK); 432 reg &= ~(CS4270_FORMAT_DAC_MASK | CS4270_FORMAT_ADC_MASK);
@@ -430,55 +439,23 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream,
430 reg |= CS4270_FORMAT_DAC_LJ | CS4270_FORMAT_ADC_LJ; 439 reg |= CS4270_FORMAT_DAC_LJ | CS4270_FORMAT_ADC_LJ;
431 break; 440 break;
432 default: 441 default:
433 printk(KERN_ERR "cs4270: unknown format\n"); 442 dev_err(codec->dev, "unknown dai format\n");
434 return -EINVAL; 443 return -EINVAL;
435 } 444 }
436 445
437 ret = snd_soc_write(codec, CS4270_FORMAT, reg); 446 ret = snd_soc_write(codec, CS4270_FORMAT, reg);
438 if (ret < 0) { 447 if (ret < 0) {
439 printk(KERN_ERR "cs4270: I2C write failed\n"); 448 dev_err(codec->dev, "i2c write failed\n");
440 return ret;
441 }
442
443 /* Disable auto-mute. This feature appears to be buggy, because in
444 some situations, auto-mute will not deactivate when it should. */
445
446 reg = snd_soc_read(codec, CS4270_MUTE);
447 reg &= ~CS4270_MUTE_AUTO;
448 ret = snd_soc_write(codec, CS4270_MUTE, reg);
449 if (ret < 0) {
450 printk(KERN_ERR "cs4270: I2C write failed\n");
451 return ret;
452 }
453
454 /* Disable automatic volume control. It's enabled by default, and
455 * it causes volume change commands to be delayed, sometimes until
456 * after playback has started.
457 */
458
459 reg = cs4270_read_reg_cache(codec, CS4270_TRANS);
460 reg &= ~(CS4270_TRANS_SOFT | CS4270_TRANS_ZERO);
461 ret = cs4270_i2c_write(codec, CS4270_TRANS, reg);
462 if (ret < 0) {
463 printk(KERN_ERR "I2C write failed\n");
464 return ret;
465 }
466
467 /* Thaw and power-up the codec */
468
469 ret = snd_soc_write(codec, CS4270_PWRCTL, 0);
470 if (ret < 0) {
471 printk(KERN_ERR "cs4270: I2C write failed\n");
472 return ret; 449 return ret;
473 } 450 }
474 451
475 return ret; 452 return ret;
476} 453}
477 454
478#ifdef CONFIG_SND_SOC_CS4270_HWMUTE 455/**
479 456 * cs4270_mute - enable/disable the CS4270 external mute
480/* 457 * @dai: the SOC DAI
481 * Set the CS4270 external mute 458 * @mute: 0 = disable mute, 1 = enable mute
482 * 459 *
483 * This function toggles the mute bits in the MUTE register. The CS4270's 460 * This function toggles the mute bits in the MUTE register. The CS4270's
484 * mute capability is intended for external muting circuitry, so if the 461 * mute capability is intended for external muting circuitry, so if the
@@ -493,276 +470,306 @@ static int cs4270_mute(struct snd_soc_dai *dai, int mute)
493 reg6 = snd_soc_read(codec, CS4270_MUTE); 470 reg6 = snd_soc_read(codec, CS4270_MUTE);
494 471
495 if (mute) 472 if (mute)
496 reg6 |= CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B | 473 reg6 |= CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B;
497 CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B;
498 else 474 else
499 reg6 &= ~(CS4270_MUTE_ADC_A | CS4270_MUTE_ADC_B | 475 reg6 &= ~(CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B);
500 CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B);
501 476
502 return snd_soc_write(codec, CS4270_MUTE, reg6); 477 return snd_soc_write(codec, CS4270_MUTE, reg6);
503} 478}
504 479
505#endif
506
507static int cs4270_i2c_probe(struct i2c_client *, const struct i2c_device_id *);
508
509/* A list of non-DAPM controls that the CS4270 supports */ 480/* A list of non-DAPM controls that the CS4270 supports */
510static const struct snd_kcontrol_new cs4270_snd_controls[] = { 481static const struct snd_kcontrol_new cs4270_snd_controls[] = {
511 SOC_DOUBLE_R("Master Playback Volume", 482 SOC_DOUBLE_R("Master Playback Volume",
512 CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1) 483 CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1),
513}; 484 SOC_SINGLE("Digital Sidetone Switch", CS4270_FORMAT, 5, 1, 0),
514 485 SOC_SINGLE("Soft Ramp Switch", CS4270_TRANS, 6, 1, 0),
515static const struct i2c_device_id cs4270_id[] = { 486 SOC_SINGLE("Zero Cross Switch", CS4270_TRANS, 5, 1, 0),
516 {"cs4270", 0}, 487 SOC_SINGLE("Popguard Switch", CS4270_MODE, 0, 1, 1),
517 {} 488 SOC_SINGLE("Auto-Mute Switch", CS4270_MUTE, 5, 1, 0),
518}; 489 SOC_DOUBLE("Master Capture Switch", CS4270_MUTE, 3, 4, 1, 0)
519MODULE_DEVICE_TABLE(i2c, cs4270_id);
520
521static struct i2c_driver cs4270_i2c_driver = {
522 .driver = {
523 .name = "CS4270 I2C",
524 .owner = THIS_MODULE,
525 },
526 .id_table = cs4270_id,
527 .probe = cs4270_i2c_probe,
528}; 490};
529 491
530/* 492/*
531 * Global variable to store socdev for i2c probe function. 493 * cs4270_codec - global variable to store codec for the ASoC probe function
532 * 494 *
533 * If struct i2c_driver had a private_data field, we wouldn't need to use 495 * If struct i2c_driver had a private_data field, we wouldn't need to use
534 * cs4270_socdec. This is the only way to pass the socdev structure to 496 * cs4270_codec. This is the only way to pass the codec structure from
535 * cs4270_i2c_probe(). 497 * cs4270_i2c_probe() to cs4270_probe(). Unfortunately, there is no good
536 * 498 * way to synchronize these two functions. cs4270_i2c_probe() can be called
537 * The real solution to cs4270_socdev is to create a mechanism 499 * multiple times before cs4270_probe() is called even once. So for now, we
538 * that maps I2C addresses to snd_soc_device structures. Perhaps the 500 * also only allow cs4270_i2c_probe() to be run once. That means that we do
539 * creation of the snd_soc_device object should be moved out of 501 * not support more than one cs4270 device in the system, at least for now.
540 * cs4270_probe() and into cs4270_i2c_probe(), but that would make this
541 * driver dependent on I2C. The CS4270 supports "stand-alone" mode, whereby
542 * the chip is *not* connected to the I2C bus, but is instead configured via
543 * input pins.
544 */ 502 */
545static struct snd_soc_device *cs4270_socdev; 503static struct snd_soc_codec *cs4270_codec;
546 504
547/* 505static struct snd_soc_dai_ops cs4270_dai_ops = {
548 * Initialize the I2C interface of the CS4270 506 .hw_params = cs4270_hw_params,
549 * 507 .set_sysclk = cs4270_set_dai_sysclk,
550 * This function is called for whenever the I2C subsystem finds a device 508 .set_fmt = cs4270_set_dai_fmt,
551 * at a particular address. 509 .digital_mute = cs4270_mute,
510};
511
512struct snd_soc_dai cs4270_dai = {
513 .name = "cs4270",
514 .playback = {
515 .stream_name = "Playback",
516 .channels_min = 1,
517 .channels_max = 2,
518 .rates = 0,
519 .formats = CS4270_FORMATS,
520 },
521 .capture = {
522 .stream_name = "Capture",
523 .channels_min = 1,
524 .channels_max = 2,
525 .rates = 0,
526 .formats = CS4270_FORMATS,
527 },
528 .ops = &cs4270_dai_ops,
529};
530EXPORT_SYMBOL_GPL(cs4270_dai);
531
532/**
533 * cs4270_probe - ASoC probe function
534 * @pdev: platform device
552 * 535 *
553 * Note: snd_soc_new_pcms() must be called before this function can be called, 536 * This function is called when ASoC has all the pieces it needs to
554 * because of snd_ctl_add(). 537 * instantiate a sound driver.
555 */ 538 */
556static int cs4270_i2c_probe(struct i2c_client *i2c_client, 539static int cs4270_probe(struct platform_device *pdev)
557 const struct i2c_device_id *id)
558{ 540{
559 struct snd_soc_device *socdev = cs4270_socdev; 541 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
560 struct snd_soc_codec *codec = socdev->codec; 542 struct snd_soc_codec *codec = cs4270_codec;
561 int i; 543 int ret;
562 int ret = 0;
563
564 /* Probing all possible addresses has one drawback: if there are
565 multiple CS4270s on the bus, then you cannot specify which
566 socdev is matched with which CS4270. For now, we just reject
567 this I2C device if the socdev already has one attached. */
568 if (codec->control_data)
569 return -ENODEV;
570
571 /* Note: codec_dai->codec is NULL here */
572
573 codec->reg_cache = kzalloc(CS4270_NUMREGS, GFP_KERNEL);
574 if (!codec->reg_cache) {
575 printk(KERN_ERR "cs4270: could not allocate register cache\n");
576 ret = -ENOMEM;
577 goto error;
578 }
579 544
580 /* Verify that we have a CS4270 */ 545 /* Connect the codec to the socdev. snd_soc_new_pcms() needs this. */
546 socdev->card->codec = codec;
581 547
582 ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID); 548 /* Register PCMs */
549 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
583 if (ret < 0) { 550 if (ret < 0) {
584 printk(KERN_ERR "cs4270: failed to read I2C\n"); 551 dev_err(codec->dev, "failed to create pcms\n");
585 goto error; 552 return ret;
586 }
587 /* The top four bits of the chip ID should be 1100. */
588 if ((ret & 0xF0) != 0xC0) {
589 /* The device at this address is not a CS4270 codec */
590 ret = -ENODEV;
591 goto error;
592 } 553 }
593 554
594 printk(KERN_INFO "cs4270: found device at I2C address %X\n", 555 /* Add the non-DAPM controls */
595 i2c_client->addr); 556 ret = snd_soc_add_controls(codec, cs4270_snd_controls,
596 printk(KERN_INFO "cs4270: hardware revision %X\n", ret & 0xF); 557 ARRAY_SIZE(cs4270_snd_controls));
597
598 codec->control_data = i2c_client;
599 codec->read = cs4270_read_reg_cache;
600 codec->write = cs4270_i2c_write;
601 codec->reg_cache_size = CS4270_NUMREGS;
602
603 /* The I2C interface is set up, so pre-fill our register cache */
604
605 ret = cs4270_fill_cache(codec);
606 if (ret < 0) { 558 if (ret < 0) {
607 printk(KERN_ERR "cs4270: failed to fill register cache\n"); 559 dev_err(codec->dev, "failed to add controls\n");
608 goto error; 560 goto error_free_pcms;
609 } 561 }
610 562
611 /* Add the non-DAPM controls */ 563 /* And finally, register the socdev */
612 564 ret = snd_soc_init_card(socdev);
613 for (i = 0; i < ARRAY_SIZE(cs4270_snd_controls); i++) { 565 if (ret < 0) {
614 struct snd_kcontrol *kctrl = 566 dev_err(codec->dev, "failed to register card\n");
615 snd_soc_cnew(&cs4270_snd_controls[i], codec, NULL); 567 goto error_free_pcms;
616
617 ret = snd_ctl_add(codec->card, kctrl);
618 if (ret < 0)
619 goto error;
620 } 568 }
621 569
622 i2c_set_clientdata(i2c_client, codec);
623
624 return 0; 570 return 0;
625 571
626error: 572error_free_pcms:
627 codec->control_data = NULL; 573 snd_soc_free_pcms(socdev);
628
629 kfree(codec->reg_cache);
630 codec->reg_cache = NULL;
631 codec->reg_cache_size = 0;
632 574
633 return ret; 575 return ret;
634} 576}
635 577
636#endif /* USE_I2C*/ 578/**
579 * cs4270_remove - ASoC remove function
580 * @pdev: platform device
581 *
582 * This function is the counterpart to cs4270_probe().
583 */
584static int cs4270_remove(struct platform_device *pdev)
585{
586 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
637 587
638struct snd_soc_dai cs4270_dai = { 588 snd_soc_free_pcms(socdev);
639 .name = "CS4270", 589
640 .playback = { 590 return 0;
641 .stream_name = "Playback",
642 .channels_min = 1,
643 .channels_max = 2,
644 .rates = 0,
645 .formats = CS4270_FORMATS,
646 },
647 .capture = {
648 .stream_name = "Capture",
649 .channels_min = 1,
650 .channels_max = 2,
651 .rates = 0,
652 .formats = CS4270_FORMATS,
653 },
654}; 591};
655EXPORT_SYMBOL_GPL(cs4270_dai);
656 592
657/* 593/**
658 * ASoC probe function 594 * cs4270_i2c_probe - initialize the I2C interface of the CS4270
595 * @i2c_client: the I2C client object
596 * @id: the I2C device ID (ignored)
659 * 597 *
660 * This function is called when the machine driver calls 598 * This function is called whenever the I2C subsystem finds a device that
661 * platform_device_add(). 599 * matches the device ID given via a prior call to i2c_add_driver().
662 */ 600 */
663static int cs4270_probe(struct platform_device *pdev) 601static int cs4270_i2c_probe(struct i2c_client *i2c_client,
602 const struct i2c_device_id *id)
664{ 603{
665 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
666 struct snd_soc_codec *codec; 604 struct snd_soc_codec *codec;
667 int ret = 0; 605 struct cs4270_private *cs4270;
606 unsigned int reg;
607 int ret;
668 608
669 printk(KERN_INFO "CS4270 ALSA SoC Codec\n"); 609 /* For now, we only support one cs4270 device in the system. See the
610 * comment for cs4270_codec.
611 */
612 if (cs4270_codec) {
613 dev_err(&i2c_client->dev, "ignoring CS4270 at addr %X\n",
614 i2c_client->addr);
615 dev_err(&i2c_client->dev, "only one per board allowed\n");
616 /* Should we return something other than ENODEV here? */
617 return -ENODEV;
618 }
619
620 /* Verify that we have a CS4270 */
621
622 ret = i2c_smbus_read_byte_data(i2c_client, CS4270_CHIPID);
623 if (ret < 0) {
624 dev_err(&i2c_client->dev, "failed to read i2c at addr %X\n",
625 i2c_client->addr);
626 return ret;
627 }
628 /* The top four bits of the chip ID should be 1100. */
629 if ((ret & 0xF0) != 0xC0) {
630 dev_err(&i2c_client->dev, "device at addr %X is not a CS4270\n",
631 i2c_client->addr);
632 return -ENODEV;
633 }
634
635 dev_info(&i2c_client->dev, "found device at i2c address %X\n",
636 i2c_client->addr);
637 dev_info(&i2c_client->dev, "hardware revision %X\n", ret & 0xF);
670 638
671 /* Allocate enough space for the snd_soc_codec structure 639 /* Allocate enough space for the snd_soc_codec structure
672 and our private data together. */ 640 and our private data together. */
673 codec = kzalloc(ALIGN(sizeof(struct snd_soc_codec), 4) + 641 cs4270 = kzalloc(sizeof(struct cs4270_private), GFP_KERNEL);
674 sizeof(struct cs4270_private), GFP_KERNEL); 642 if (!cs4270) {
675 if (!codec) { 643 dev_err(&i2c_client->dev, "could not allocate codec\n");
676 printk(KERN_ERR "cs4270: Could not allocate codec structure\n");
677 return -ENOMEM; 644 return -ENOMEM;
678 } 645 }
646 codec = &cs4270->codec;
679 647
680 mutex_init(&codec->mutex); 648 mutex_init(&codec->mutex);
681 INIT_LIST_HEAD(&codec->dapm_widgets); 649 INIT_LIST_HEAD(&codec->dapm_widgets);
682 INIT_LIST_HEAD(&codec->dapm_paths); 650 INIT_LIST_HEAD(&codec->dapm_paths);
683 651
652 codec->dev = &i2c_client->dev;
684 codec->name = "CS4270"; 653 codec->name = "CS4270";
685 codec->owner = THIS_MODULE; 654 codec->owner = THIS_MODULE;
686 codec->dai = &cs4270_dai; 655 codec->dai = &cs4270_dai;
687 codec->num_dai = 1; 656 codec->num_dai = 1;
688 codec->private_data = (void *) codec + 657 codec->private_data = cs4270;
689 ALIGN(sizeof(struct snd_soc_codec), 4); 658 codec->control_data = i2c_client;
690 659 codec->read = cs4270_read_reg_cache;
691 socdev->codec = codec; 660 codec->write = cs4270_i2c_write;
661 codec->reg_cache = cs4270->reg_cache;
662 codec->reg_cache_size = CS4270_NUMREGS;
692 663
693 /* Register PCMs */ 664 /* The I2C interface is set up, so pre-fill our register cache */
694 665
695 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 666 ret = cs4270_fill_cache(codec);
696 if (ret < 0) { 667 if (ret < 0) {
697 printk(KERN_ERR "cs4270: failed to create PCMs\n"); 668 dev_err(&i2c_client->dev, "failed to fill register cache\n");
698 goto error_free_codec; 669 goto error_free_codec;
699 } 670 }
700 671
701#ifdef USE_I2C 672 /* Disable auto-mute. This feature appears to be buggy. In some
702 cs4270_socdev = socdev; 673 * situations, auto-mute will not deactivate when it should, so we want
674 * this feature disabled by default. An application (e.g. alsactl) can
675 * re-enabled it by using the controls.
676 */
703 677
704 ret = i2c_add_driver(&cs4270_i2c_driver); 678 reg = cs4270_read_reg_cache(codec, CS4270_MUTE);
705 if (ret) { 679 reg &= ~CS4270_MUTE_AUTO;
706 printk(KERN_ERR "cs4270: failed to attach driver"); 680 ret = cs4270_i2c_write(codec, CS4270_MUTE, reg);
707 goto error_free_pcms; 681 if (ret < 0) {
682 dev_err(&i2c_client->dev, "i2c write failed\n");
683 return ret;
708 } 684 }
709 685
710 /* Did we find a CS4270 on the I2C bus? */ 686 /* Disable automatic volume control. The hardware enables, and it
711 if (codec->control_data) { 687 * causes volume change commands to be delayed, sometimes until after
712 /* Initialize codec ops */ 688 * playback has started. An application (e.g. alsactl) can
713 cs4270_dai.ops.hw_params = cs4270_hw_params; 689 * re-enabled it by using the controls.
714 cs4270_dai.ops.set_sysclk = cs4270_set_dai_sysclk; 690 */
715 cs4270_dai.ops.set_fmt = cs4270_set_dai_fmt;
716#ifdef CONFIG_SND_SOC_CS4270_HWMUTE
717 cs4270_dai.ops.digital_mute = cs4270_mute;
718#endif
719 } else
720 printk(KERN_INFO "cs4270: no I2C device found, "
721 "using stand-alone mode\n");
722#else
723 printk(KERN_INFO "cs4270: I2C disabled, using stand-alone mode\n");
724#endif
725 691
726 ret = snd_soc_init_card(socdev); 692 reg = cs4270_read_reg_cache(codec, CS4270_TRANS);
693 reg &= ~(CS4270_TRANS_SOFT | CS4270_TRANS_ZERO);
694 ret = cs4270_i2c_write(codec, CS4270_TRANS, reg);
727 if (ret < 0) { 695 if (ret < 0) {
728 printk(KERN_ERR "cs4270: failed to register card\n"); 696 dev_err(&i2c_client->dev, "i2c write failed\n");
729 goto error_del_driver; 697 return ret;
730 } 698 }
731 699
732 return 0; 700 /* Initialize the DAI. Normally, we'd prefer to have a kmalloc'd DAI
701 * structure for each CS4270 device, but the machine driver needs to
702 * have a pointer to the DAI structure, so for now it must be a global
703 * variable.
704 */
705 cs4270_dai.dev = &i2c_client->dev;
733 706
734error_del_driver: 707 /* Register the DAI. If all the other ASoC driver have already
735#ifdef USE_I2C 708 * registered, then this will call our probe function, so
736 i2c_del_driver(&cs4270_i2c_driver); 709 * cs4270_codec needs to be ready.
710 */
711 cs4270_codec = codec;
712 ret = snd_soc_register_dai(&cs4270_dai);
713 if (ret < 0) {
714 dev_err(&i2c_client->dev, "failed to register DAIe\n");
715 goto error_free_codec;
716 }
737 717
738error_free_pcms: 718 i2c_set_clientdata(i2c_client, cs4270);
739#endif 719
740 snd_soc_free_pcms(socdev); 720 return 0;
741 721
742error_free_codec: 722error_free_codec:
743 kfree(socdev->codec); 723 kfree(cs4270);
744 socdev->codec = NULL; 724 cs4270_codec = NULL;
725 cs4270_dai.dev = NULL;
745 726
746 return ret; 727 return ret;
747} 728}
748 729
749static int cs4270_remove(struct platform_device *pdev) 730/**
731 * cs4270_i2c_remove - remove an I2C device
732 * @i2c_client: the I2C client object
733 *
734 * This function is the counterpart to cs4270_i2c_probe().
735 */
736static int cs4270_i2c_remove(struct i2c_client *i2c_client)
750{ 737{
751 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 738 struct cs4270_private *cs4270 = i2c_get_clientdata(i2c_client);
752
753 snd_soc_free_pcms(socdev);
754
755#ifdef USE_I2C
756 i2c_del_driver(&cs4270_i2c_driver);
757#endif
758 739
759 kfree(socdev->codec); 740 kfree(cs4270);
760 socdev->codec = NULL; 741 cs4270_codec = NULL;
742 cs4270_dai.dev = NULL;
761 743
762 return 0; 744 return 0;
763} 745}
764 746
765/* 747/*
748 * cs4270_id - I2C device IDs supported by this driver
749 */
750static struct i2c_device_id cs4270_id[] = {
751 {"cs4270", 0},
752 {}
753};
754MODULE_DEVICE_TABLE(i2c, cs4270_id);
755
756/*
757 * cs4270_i2c_driver - I2C device identification
758 *
759 * This structure tells the I2C subsystem how to identify and support a
760 * given I2C device type.
761 */
762static struct i2c_driver cs4270_i2c_driver = {
763 .driver = {
764 .name = "cs4270",
765 .owner = THIS_MODULE,
766 },
767 .id_table = cs4270_id,
768 .probe = cs4270_i2c_probe,
769 .remove = cs4270_i2c_remove,
770};
771
772/*
766 * ASoC codec device structure 773 * ASoC codec device structure
767 * 774 *
768 * Assign this variable to the codec_dev field of the machine driver's 775 * Assign this variable to the codec_dev field of the machine driver's
@@ -776,13 +783,15 @@ EXPORT_SYMBOL_GPL(soc_codec_device_cs4270);
776 783
777static int __init cs4270_init(void) 784static int __init cs4270_init(void)
778{ 785{
779 return snd_soc_register_dai(&cs4270_dai); 786 pr_info("Cirrus Logic CS4270 ALSA SoC Codec Driver\n");
787
788 return i2c_add_driver(&cs4270_i2c_driver);
780} 789}
781module_init(cs4270_init); 790module_init(cs4270_init);
782 791
783static void __exit cs4270_exit(void) 792static void __exit cs4270_exit(void)
784{ 793{
785 snd_soc_unregister_dai(&cs4270_dai); 794 i2c_del_driver(&cs4270_i2c_driver);
786} 795}
787module_exit(cs4270_exit); 796module_exit(cs4270_exit);
788 797
diff --git a/sound/soc/codecs/pcm3008.c b/sound/soc/codecs/pcm3008.c
index 9a3e67e5319c..5cda9e6b5a74 100644
--- a/sound/soc/codecs/pcm3008.c
+++ b/sound/soc/codecs/pcm3008.c
@@ -67,11 +67,11 @@ static int pcm3008_soc_probe(struct platform_device *pdev)
67 67
68 printk(KERN_INFO "PCM3008 SoC Audio Codec %s\n", PCM3008_VERSION); 68 printk(KERN_INFO "PCM3008 SoC Audio Codec %s\n", PCM3008_VERSION);
69 69
70 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 70 socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
71 if (!socdev->codec) 71 if (!socdev->card->codec)
72 return -ENOMEM; 72 return -ENOMEM;
73 73
74 codec = socdev->codec; 74 codec = socdev->card->codec;
75 mutex_init(&codec->mutex); 75 mutex_init(&codec->mutex);
76 76
77 codec->name = "PCM3008"; 77 codec->name = "PCM3008";
@@ -139,7 +139,7 @@ gpio_err:
139card_err: 139card_err:
140 snd_soc_free_pcms(socdev); 140 snd_soc_free_pcms(socdev);
141pcm_err: 141pcm_err:
142 kfree(socdev->codec); 142 kfree(socdev->card->codec);
143 143
144 return ret; 144 return ret;
145} 145}
@@ -147,7 +147,7 @@ pcm_err:
147static int pcm3008_soc_remove(struct platform_device *pdev) 147static int pcm3008_soc_remove(struct platform_device *pdev)
148{ 148{
149 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 149 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
150 struct snd_soc_codec *codec = socdev->codec; 150 struct snd_soc_codec *codec = socdev->card->codec;
151 struct pcm3008_setup_data *setup = socdev->codec_data; 151 struct pcm3008_setup_data *setup = socdev->codec_data;
152 152
153 if (!codec) 153 if (!codec)
@@ -155,7 +155,7 @@ static int pcm3008_soc_remove(struct platform_device *pdev)
155 155
156 pcm3008_gpio_free(setup); 156 pcm3008_gpio_free(setup);
157 snd_soc_free_pcms(socdev); 157 snd_soc_free_pcms(socdev);
158 kfree(socdev->codec); 158 kfree(socdev->card->codec);
159 159
160 return 0; 160 return 0;
161} 161}
diff --git a/sound/soc/codecs/ssm2602.c b/sound/soc/codecs/ssm2602.c
index cac373616768..87f606c76822 100644
--- a/sound/soc/codecs/ssm2602.c
+++ b/sound/soc/codecs/ssm2602.c
@@ -151,21 +151,6 @@ SOC_ENUM("Capture Source", ssm2602_enum[0]),
151SOC_ENUM("Playback De-emphasis", ssm2602_enum[1]), 151SOC_ENUM("Playback De-emphasis", ssm2602_enum[1]),
152}; 152};
153 153
154/* add non dapm controls */
155static int ssm2602_add_controls(struct snd_soc_codec *codec)
156{
157 int err, i;
158
159 for (i = 0; i < ARRAY_SIZE(ssm2602_snd_controls); i++) {
160 err = snd_ctl_add(codec->card,
161 snd_soc_cnew(&ssm2602_snd_controls[i], codec, NULL));
162 if (err < 0)
163 return err;
164 }
165
166 return 0;
167}
168
169/* Output Mixer */ 154/* Output Mixer */
170static const struct snd_kcontrol_new ssm2602_output_mixer_controls[] = { 155static const struct snd_kcontrol_new ssm2602_output_mixer_controls[] = {
171SOC_DAPM_SINGLE("Line Bypass Switch", SSM2602_APANA, 3, 1, 0), 156SOC_DAPM_SINGLE("Line Bypass Switch", SSM2602_APANA, 3, 1, 0),
@@ -291,7 +276,7 @@ static int ssm2602_hw_params(struct snd_pcm_substream *substream,
291 u16 srate; 276 u16 srate;
292 struct snd_soc_pcm_runtime *rtd = substream->private_data; 277 struct snd_soc_pcm_runtime *rtd = substream->private_data;
293 struct snd_soc_device *socdev = rtd->socdev; 278 struct snd_soc_device *socdev = rtd->socdev;
294 struct snd_soc_codec *codec = socdev->codec; 279 struct snd_soc_codec *codec = socdev->card->codec;
295 struct ssm2602_priv *ssm2602 = codec->private_data; 280 struct ssm2602_priv *ssm2602 = codec->private_data;
296 struct i2c_client *i2c = codec->control_data; 281 struct i2c_client *i2c = codec->control_data;
297 u16 iface = ssm2602_read_reg_cache(codec, SSM2602_IFACE) & 0xfff3; 282 u16 iface = ssm2602_read_reg_cache(codec, SSM2602_IFACE) & 0xfff3;
@@ -336,7 +321,7 @@ static int ssm2602_startup(struct snd_pcm_substream *substream,
336{ 321{
337 struct snd_soc_pcm_runtime *rtd = substream->private_data; 322 struct snd_soc_pcm_runtime *rtd = substream->private_data;
338 struct snd_soc_device *socdev = rtd->socdev; 323 struct snd_soc_device *socdev = rtd->socdev;
339 struct snd_soc_codec *codec = socdev->codec; 324 struct snd_soc_codec *codec = socdev->card->codec;
340 struct ssm2602_priv *ssm2602 = codec->private_data; 325 struct ssm2602_priv *ssm2602 = codec->private_data;
341 struct i2c_client *i2c = codec->control_data; 326 struct i2c_client *i2c = codec->control_data;
342 struct snd_pcm_runtime *master_runtime; 327 struct snd_pcm_runtime *master_runtime;
@@ -373,7 +358,7 @@ static int ssm2602_pcm_prepare(struct snd_pcm_substream *substream,
373{ 358{
374 struct snd_soc_pcm_runtime *rtd = substream->private_data; 359 struct snd_soc_pcm_runtime *rtd = substream->private_data;
375 struct snd_soc_device *socdev = rtd->socdev; 360 struct snd_soc_device *socdev = rtd->socdev;
376 struct snd_soc_codec *codec = socdev->codec; 361 struct snd_soc_codec *codec = socdev->card->codec;
377 /* set active */ 362 /* set active */
378 ssm2602_write(codec, SSM2602_ACTIVE, ACTIVE_ACTIVATE_CODEC); 363 ssm2602_write(codec, SSM2602_ACTIVE, ACTIVE_ACTIVATE_CODEC);
379 364
@@ -385,7 +370,7 @@ static void ssm2602_shutdown(struct snd_pcm_substream *substream,
385{ 370{
386 struct snd_soc_pcm_runtime *rtd = substream->private_data; 371 struct snd_soc_pcm_runtime *rtd = substream->private_data;
387 struct snd_soc_device *socdev = rtd->socdev; 372 struct snd_soc_device *socdev = rtd->socdev;
388 struct snd_soc_codec *codec = socdev->codec; 373 struct snd_soc_codec *codec = socdev->card->codec;
389 struct ssm2602_priv *ssm2602 = codec->private_data; 374 struct ssm2602_priv *ssm2602 = codec->private_data;
390 /* deactivate */ 375 /* deactivate */
391 if (!codec->active) 376 if (!codec->active)
@@ -521,6 +506,16 @@ static int ssm2602_set_bias_level(struct snd_soc_codec *codec,
521#define SSM2602_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 506#define SSM2602_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
522 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 507 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
523 508
509static struct snd_soc_dai_ops ssm2602_dai_ops = {
510 .startup = ssm2602_startup,
511 .prepare = ssm2602_pcm_prepare,
512 .hw_params = ssm2602_hw_params,
513 .shutdown = ssm2602_shutdown,
514 .digital_mute = ssm2602_mute,
515 .set_sysclk = ssm2602_set_dai_sysclk,
516 .set_fmt = ssm2602_set_dai_fmt,
517};
518
524struct snd_soc_dai ssm2602_dai = { 519struct snd_soc_dai ssm2602_dai = {
525 .name = "SSM2602", 520 .name = "SSM2602",
526 .playback = { 521 .playback = {
@@ -535,22 +530,14 @@ struct snd_soc_dai ssm2602_dai = {
535 .channels_max = 2, 530 .channels_max = 2,
536 .rates = SSM2602_RATES, 531 .rates = SSM2602_RATES,
537 .formats = SSM2602_FORMATS,}, 532 .formats = SSM2602_FORMATS,},
538 .ops = { 533 .ops = &ssm2602_dai_ops,
539 .startup = ssm2602_startup,
540 .prepare = ssm2602_pcm_prepare,
541 .hw_params = ssm2602_hw_params,
542 .shutdown = ssm2602_shutdown,
543 .digital_mute = ssm2602_mute,
544 .set_sysclk = ssm2602_set_dai_sysclk,
545 .set_fmt = ssm2602_set_dai_fmt,
546 }
547}; 534};
548EXPORT_SYMBOL_GPL(ssm2602_dai); 535EXPORT_SYMBOL_GPL(ssm2602_dai);
549 536
550static int ssm2602_suspend(struct platform_device *pdev, pm_message_t state) 537static int ssm2602_suspend(struct platform_device *pdev, pm_message_t state)
551{ 538{
552 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 539 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
553 struct snd_soc_codec *codec = socdev->codec; 540 struct snd_soc_codec *codec = socdev->card->codec;
554 541
555 ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF); 542 ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF);
556 return 0; 543 return 0;
@@ -559,7 +546,7 @@ static int ssm2602_suspend(struct platform_device *pdev, pm_message_t state)
559static int ssm2602_resume(struct platform_device *pdev) 546static int ssm2602_resume(struct platform_device *pdev)
560{ 547{
561 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 548 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
562 struct snd_soc_codec *codec = socdev->codec; 549 struct snd_soc_codec *codec = socdev->card->codec;
563 int i; 550 int i;
564 u8 data[2]; 551 u8 data[2];
565 u16 *cache = codec->reg_cache; 552 u16 *cache = codec->reg_cache;
@@ -581,7 +568,7 @@ static int ssm2602_resume(struct platform_device *pdev)
581 */ 568 */
582static int ssm2602_init(struct snd_soc_device *socdev) 569static int ssm2602_init(struct snd_soc_device *socdev)
583{ 570{
584 struct snd_soc_codec *codec = socdev->codec; 571 struct snd_soc_codec *codec = socdev->card->codec;
585 int reg, ret = 0; 572 int reg, ret = 0;
586 573
587 codec->name = "SSM2602"; 574 codec->name = "SSM2602";
@@ -622,7 +609,8 @@ static int ssm2602_init(struct snd_soc_device *socdev)
622 APANA_ENABLE_MIC_BOOST); 609 APANA_ENABLE_MIC_BOOST);
623 ssm2602_write(codec, SSM2602_PWR, 0); 610 ssm2602_write(codec, SSM2602_PWR, 0);
624 611
625 ssm2602_add_controls(codec); 612 snd_soc_add_controls(codec, ssm2602_snd_controls,
613 ARRAY_SIZE(ssm2602_snd_controls));
626 ssm2602_add_widgets(codec); 614 ssm2602_add_widgets(codec);
627 ret = snd_soc_init_card(socdev); 615 ret = snd_soc_init_card(socdev);
628 if (ret < 0) { 616 if (ret < 0) {
@@ -653,7 +641,7 @@ static int ssm2602_i2c_probe(struct i2c_client *i2c,
653 const struct i2c_device_id *id) 641 const struct i2c_device_id *id)
654{ 642{
655 struct snd_soc_device *socdev = ssm2602_socdev; 643 struct snd_soc_device *socdev = ssm2602_socdev;
656 struct snd_soc_codec *codec = socdev->codec; 644 struct snd_soc_codec *codec = socdev->card->codec;
657 int ret; 645 int ret;
658 646
659 i2c_set_clientdata(i2c, codec); 647 i2c_set_clientdata(i2c, codec);
@@ -747,7 +735,7 @@ static int ssm2602_probe(struct platform_device *pdev)
747 } 735 }
748 736
749 codec->private_data = ssm2602; 737 codec->private_data = ssm2602;
750 socdev->codec = codec; 738 socdev->card->codec = codec;
751 mutex_init(&codec->mutex); 739 mutex_init(&codec->mutex);
752 INIT_LIST_HEAD(&codec->dapm_widgets); 740 INIT_LIST_HEAD(&codec->dapm_widgets);
753 INIT_LIST_HEAD(&codec->dapm_paths); 741 INIT_LIST_HEAD(&codec->dapm_paths);
@@ -768,7 +756,7 @@ static int ssm2602_probe(struct platform_device *pdev)
768static int ssm2602_remove(struct platform_device *pdev) 756static int ssm2602_remove(struct platform_device *pdev)
769{ 757{
770 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 758 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
771 struct snd_soc_codec *codec = socdev->codec; 759 struct snd_soc_codec *codec = socdev->card->codec;
772 760
773 if (codec->control_data) 761 if (codec->control_data)
774 ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF); 762 ssm2602_set_bias_level(codec, SND_SOC_BIAS_OFF);
diff --git a/sound/soc/codecs/tlv320aic23.c b/sound/soc/codecs/tlv320aic23.c
index cfdea007c4cb..c3f4afb5d017 100644
--- a/sound/soc/codecs/tlv320aic23.c
+++ b/sound/soc/codecs/tlv320aic23.c
@@ -183,24 +183,6 @@ static const struct snd_kcontrol_new tlv320aic23_snd_controls[] = {
183 SOC_ENUM("Playback De-emphasis", tlv320aic23_deemph), 183 SOC_ENUM("Playback De-emphasis", tlv320aic23_deemph),
184}; 184};
185 185
186/* add non dapm controls */
187static int tlv320aic23_add_controls(struct snd_soc_codec *codec)
188{
189
190 int err, i;
191
192 for (i = 0; i < ARRAY_SIZE(tlv320aic23_snd_controls); i++) {
193 err = snd_ctl_add(codec->card,
194 snd_soc_cnew(&tlv320aic23_snd_controls[i],
195 codec, NULL));
196 if (err < 0)
197 return err;
198 }
199
200 return 0;
201
202}
203
204/* PGA Mixer controls for Line and Mic switch */ 186/* PGA Mixer controls for Line and Mic switch */
205static const struct snd_kcontrol_new tlv320aic23_output_mixer_controls[] = { 187static const struct snd_kcontrol_new tlv320aic23_output_mixer_controls[] = {
206 SOC_DAPM_SINGLE("Line Bypass Switch", TLV320AIC23_ANLG, 3, 1, 0), 188 SOC_DAPM_SINGLE("Line Bypass Switch", TLV320AIC23_ANLG, 3, 1, 0),
@@ -423,7 +405,7 @@ static int tlv320aic23_hw_params(struct snd_pcm_substream *substream,
423{ 405{
424 struct snd_soc_pcm_runtime *rtd = substream->private_data; 406 struct snd_soc_pcm_runtime *rtd = substream->private_data;
425 struct snd_soc_device *socdev = rtd->socdev; 407 struct snd_soc_device *socdev = rtd->socdev;
426 struct snd_soc_codec *codec = socdev->codec; 408 struct snd_soc_codec *codec = socdev->card->codec;
427 u16 iface_reg; 409 u16 iface_reg;
428 int ret; 410 int ret;
429 struct aic23 *aic23 = container_of(codec, struct aic23, codec); 411 struct aic23 *aic23 = container_of(codec, struct aic23, codec);
@@ -471,7 +453,7 @@ static int tlv320aic23_pcm_prepare(struct snd_pcm_substream *substream,
471{ 453{
472 struct snd_soc_pcm_runtime *rtd = substream->private_data; 454 struct snd_soc_pcm_runtime *rtd = substream->private_data;
473 struct snd_soc_device *socdev = rtd->socdev; 455 struct snd_soc_device *socdev = rtd->socdev;
474 struct snd_soc_codec *codec = socdev->codec; 456 struct snd_soc_codec *codec = socdev->card->codec;
475 457
476 /* set active */ 458 /* set active */
477 tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0001); 459 tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0001);
@@ -484,7 +466,7 @@ static void tlv320aic23_shutdown(struct snd_pcm_substream *substream,
484{ 466{
485 struct snd_soc_pcm_runtime *rtd = substream->private_data; 467 struct snd_soc_pcm_runtime *rtd = substream->private_data;
486 struct snd_soc_device *socdev = rtd->socdev; 468 struct snd_soc_device *socdev = rtd->socdev;
487 struct snd_soc_codec *codec = socdev->codec; 469 struct snd_soc_codec *codec = socdev->card->codec;
488 struct aic23 *aic23 = container_of(codec, struct aic23, codec); 470 struct aic23 *aic23 = container_of(codec, struct aic23, codec);
489 471
490 /* deactivate */ 472 /* deactivate */
@@ -598,6 +580,15 @@ static int tlv320aic23_set_bias_level(struct snd_soc_codec *codec,
598#define AIC23_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 580#define AIC23_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
599 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) 581 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
600 582
583static struct snd_soc_dai_ops tlv320aic23_dai_ops = {
584 .prepare = tlv320aic23_pcm_prepare,
585 .hw_params = tlv320aic23_hw_params,
586 .shutdown = tlv320aic23_shutdown,
587 .digital_mute = tlv320aic23_mute,
588 .set_fmt = tlv320aic23_set_dai_fmt,
589 .set_sysclk = tlv320aic23_set_dai_sysclk,
590};
591
601struct snd_soc_dai tlv320aic23_dai = { 592struct snd_soc_dai tlv320aic23_dai = {
602 .name = "tlv320aic23", 593 .name = "tlv320aic23",
603 .playback = { 594 .playback = {
@@ -612,14 +603,7 @@ struct snd_soc_dai tlv320aic23_dai = {
612 .channels_max = 2, 603 .channels_max = 2,
613 .rates = AIC23_RATES, 604 .rates = AIC23_RATES,
614 .formats = AIC23_FORMATS,}, 605 .formats = AIC23_FORMATS,},
615 .ops = { 606 .ops = &tlv320aic23_dai_ops,
616 .prepare = tlv320aic23_pcm_prepare,
617 .hw_params = tlv320aic23_hw_params,
618 .shutdown = tlv320aic23_shutdown,
619 .digital_mute = tlv320aic23_mute,
620 .set_fmt = tlv320aic23_set_dai_fmt,
621 .set_sysclk = tlv320aic23_set_dai_sysclk,
622 }
623}; 607};
624EXPORT_SYMBOL_GPL(tlv320aic23_dai); 608EXPORT_SYMBOL_GPL(tlv320aic23_dai);
625 609
@@ -627,7 +611,7 @@ static int tlv320aic23_suspend(struct platform_device *pdev,
627 pm_message_t state) 611 pm_message_t state)
628{ 612{
629 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 613 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
630 struct snd_soc_codec *codec = socdev->codec; 614 struct snd_soc_codec *codec = socdev->card->codec;
631 615
632 tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0); 616 tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x0);
633 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_OFF); 617 tlv320aic23_set_bias_level(codec, SND_SOC_BIAS_OFF);
@@ -638,7 +622,7 @@ static int tlv320aic23_suspend(struct platform_device *pdev,
638static int tlv320aic23_resume(struct platform_device *pdev) 622static int tlv320aic23_resume(struct platform_device *pdev)
639{ 623{
640 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 624 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
641 struct snd_soc_codec *codec = socdev->codec; 625 struct snd_soc_codec *codec = socdev->card->codec;
642 int i; 626 int i;
643 u16 reg; 627 u16 reg;
644 628
@@ -660,7 +644,7 @@ static int tlv320aic23_resume(struct platform_device *pdev)
660 */ 644 */
661static int tlv320aic23_init(struct snd_soc_device *socdev) 645static int tlv320aic23_init(struct snd_soc_device *socdev)
662{ 646{
663 struct snd_soc_codec *codec = socdev->codec; 647 struct snd_soc_codec *codec = socdev->card->codec;
664 int ret = 0; 648 int ret = 0;
665 u16 reg; 649 u16 reg;
666 650
@@ -718,7 +702,8 @@ static int tlv320aic23_init(struct snd_soc_device *socdev)
718 702
719 tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x1); 703 tlv320aic23_write(codec, TLV320AIC23_ACTIVE, 0x1);
720 704
721 tlv320aic23_add_controls(codec); 705 snd_soc_add_controls(codec, tlv320aic23_snd_controls,
706 ARRAY_SIZE(tlv320aic23_snd_controls));
722 tlv320aic23_add_widgets(codec); 707 tlv320aic23_add_widgets(codec);
723 ret = snd_soc_init_card(socdev); 708 ret = snd_soc_init_card(socdev);
724 if (ret < 0) { 709 if (ret < 0) {
@@ -746,7 +731,7 @@ static int tlv320aic23_codec_probe(struct i2c_client *i2c,
746 const struct i2c_device_id *i2c_id) 731 const struct i2c_device_id *i2c_id)
747{ 732{
748 struct snd_soc_device *socdev = tlv320aic23_socdev; 733 struct snd_soc_device *socdev = tlv320aic23_socdev;
749 struct snd_soc_codec *codec = socdev->codec; 734 struct snd_soc_codec *codec = socdev->card->codec;
750 int ret; 735 int ret;
751 736
752 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 737 if (!i2c_check_functionality(i2c->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
@@ -804,7 +789,7 @@ static int tlv320aic23_probe(struct platform_device *pdev)
804 if (aic23 == NULL) 789 if (aic23 == NULL)
805 return -ENOMEM; 790 return -ENOMEM;
806 codec = &aic23->codec; 791 codec = &aic23->codec;
807 socdev->codec = codec; 792 socdev->card->codec = codec;
808 mutex_init(&codec->mutex); 793 mutex_init(&codec->mutex);
809 INIT_LIST_HEAD(&codec->dapm_widgets); 794 INIT_LIST_HEAD(&codec->dapm_widgets);
810 INIT_LIST_HEAD(&codec->dapm_paths); 795 INIT_LIST_HEAD(&codec->dapm_paths);
@@ -823,7 +808,7 @@ static int tlv320aic23_probe(struct platform_device *pdev)
823static int tlv320aic23_remove(struct platform_device *pdev) 808static int tlv320aic23_remove(struct platform_device *pdev)
824{ 809{
825 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 810 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
826 struct snd_soc_codec *codec = socdev->codec; 811 struct snd_soc_codec *codec = socdev->card->codec;
827 struct aic23 *aic23 = container_of(codec, struct aic23, codec); 812 struct aic23 *aic23 = container_of(codec, struct aic23, codec);
828 813
829 if (codec->control_data) 814 if (codec->control_data)
diff --git a/sound/soc/codecs/tlv320aic26.c b/sound/soc/codecs/tlv320aic26.c
index 29f2f1a017fd..3387d9e736ea 100644
--- a/sound/soc/codecs/tlv320aic26.c
+++ b/sound/soc/codecs/tlv320aic26.c
@@ -130,7 +130,7 @@ static int aic26_hw_params(struct snd_pcm_substream *substream,
130{ 130{
131 struct snd_soc_pcm_runtime *rtd = substream->private_data; 131 struct snd_soc_pcm_runtime *rtd = substream->private_data;
132 struct snd_soc_device *socdev = rtd->socdev; 132 struct snd_soc_device *socdev = rtd->socdev;
133 struct snd_soc_codec *codec = socdev->codec; 133 struct snd_soc_codec *codec = socdev->card->codec;
134 struct aic26 *aic26 = codec->private_data; 134 struct aic26 *aic26 = codec->private_data;
135 int fsref, divisor, wlen, pval, jval, dval, qval; 135 int fsref, divisor, wlen, pval, jval, dval, qval;
136 u16 reg; 136 u16 reg;
@@ -270,6 +270,13 @@ static int aic26_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
270#define AIC26_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_BE |\ 270#define AIC26_FORMATS (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_BE |\
271 SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S32_BE) 271 SNDRV_PCM_FMTBIT_S24_BE | SNDRV_PCM_FMTBIT_S32_BE)
272 272
273static struct snd_soc_dai_ops aic26_dai_ops = {
274 .hw_params = aic26_hw_params,
275 .digital_mute = aic26_mute,
276 .set_sysclk = aic26_set_sysclk,
277 .set_fmt = aic26_set_fmt,
278};
279
273struct snd_soc_dai aic26_dai = { 280struct snd_soc_dai aic26_dai = {
274 .name = "tlv320aic26", 281 .name = "tlv320aic26",
275 .playback = { 282 .playback = {
@@ -286,12 +293,7 @@ struct snd_soc_dai aic26_dai = {
286 .rates = AIC26_RATES, 293 .rates = AIC26_RATES,
287 .formats = AIC26_FORMATS, 294 .formats = AIC26_FORMATS,
288 }, 295 },
289 .ops = { 296 .ops = &aic26_dai_ops,
290 .hw_params = aic26_hw_params,
291 .digital_mute = aic26_mute,
292 .set_sysclk = aic26_set_sysclk,
293 .set_fmt = aic26_set_fmt,
294 },
295}; 297};
296EXPORT_SYMBOL_GPL(aic26_dai); 298EXPORT_SYMBOL_GPL(aic26_dai);
297 299
@@ -322,9 +324,8 @@ static int aic26_probe(struct platform_device *pdev)
322{ 324{
323 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 325 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
324 struct snd_soc_codec *codec; 326 struct snd_soc_codec *codec;
325 struct snd_kcontrol *kcontrol;
326 struct aic26 *aic26; 327 struct aic26 *aic26;
327 int i, ret, err; 328 int ret, err;
328 329
329 dev_info(&pdev->dev, "Probing AIC26 SoC CODEC driver\n"); 330 dev_info(&pdev->dev, "Probing AIC26 SoC CODEC driver\n");
330 dev_dbg(&pdev->dev, "socdev=%p\n", socdev); 331 dev_dbg(&pdev->dev, "socdev=%p\n", socdev);
@@ -338,7 +339,7 @@ static int aic26_probe(struct platform_device *pdev)
338 return -ENODEV; 339 return -ENODEV;
339 } 340 }
340 codec = &aic26->codec; 341 codec = &aic26->codec;
341 socdev->codec = codec; 342 socdev->card->codec = codec;
342 343
343 dev_dbg(&pdev->dev, "Registering PCMs, dev=%p, socdev->dev=%p\n", 344 dev_dbg(&pdev->dev, "Registering PCMs, dev=%p, socdev->dev=%p\n",
344 &pdev->dev, socdev->dev); 345 &pdev->dev, socdev->dev);
@@ -351,11 +352,9 @@ static int aic26_probe(struct platform_device *pdev)
351 352
352 /* register controls */ 353 /* register controls */
353 dev_dbg(&pdev->dev, "Registering controls\n"); 354 dev_dbg(&pdev->dev, "Registering controls\n");
354 for (i = 0; i < ARRAY_SIZE(aic26_snd_controls); i++) { 355 err = snd_soc_add_controls(codec, aic26_snd_controls,
355 kcontrol = snd_soc_cnew(&aic26_snd_controls[i], codec, NULL); 356 ARRAY_SIZE(aic26_snd_controls));
356 err = snd_ctl_add(codec->card, kcontrol); 357 WARN_ON(err < 0);
357 WARN_ON(err < 0);
358 }
359 358
360 /* CODEC is setup, we can register the card now */ 359 /* CODEC is setup, we can register the card now */
361 dev_dbg(&pdev->dev, "Registering card\n"); 360 dev_dbg(&pdev->dev, "Registering card\n");
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index aea0cb72d80a..ab099f482487 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -45,6 +45,7 @@
45#include <sound/soc.h> 45#include <sound/soc.h>
46#include <sound/soc-dapm.h> 46#include <sound/soc-dapm.h>
47#include <sound/initval.h> 47#include <sound/initval.h>
48#include <sound/tlv.h>
48 49
49#include "tlv320aic3x.h" 50#include "tlv320aic3x.h"
50 51
@@ -250,56 +251,86 @@ static const struct soc_enum aic3x_enum[] = {
250 SOC_ENUM_DOUBLE(AIC3X_CODEC_DFILT_CTRL, 6, 4, 4, aic3x_adc_hpf), 251 SOC_ENUM_DOUBLE(AIC3X_CODEC_DFILT_CTRL, 6, 4, 4, aic3x_adc_hpf),
251}; 252};
252 253
254/*
255 * DAC digital volumes. From -63.5 to 0 dB in 0.5 dB steps
256 */
257static DECLARE_TLV_DB_SCALE(dac_tlv, -6350, 50, 0);
258/* ADC PGA gain volumes. From 0 to 59.5 dB in 0.5 dB steps */
259static DECLARE_TLV_DB_SCALE(adc_tlv, 0, 50, 0);
260/*
261 * Output stage volumes. From -78.3 to 0 dB. Muted below -78.3 dB.
262 * Step size is approximately 0.5 dB over most of the scale but increasing
263 * near the very low levels.
264 * Define dB scale so that it is mostly correct for range about -55 to 0 dB
265 * but having increasing dB difference below that (and where it doesn't count
266 * so much). This setting shows -50 dB (actual is -50.3 dB) for register
267 * value 100 and -58.5 dB (actual is -78.3 dB) for register value 117.
268 */
269static DECLARE_TLV_DB_SCALE(output_stage_tlv, -5900, 50, 1);
270
253static const struct snd_kcontrol_new aic3x_snd_controls[] = { 271static const struct snd_kcontrol_new aic3x_snd_controls[] = {
254 /* Output */ 272 /* Output */
255 SOC_DOUBLE_R("PCM Playback Volume", LDAC_VOL, RDAC_VOL, 0, 0x7f, 1), 273 SOC_DOUBLE_R_TLV("PCM Playback Volume",
274 LDAC_VOL, RDAC_VOL, 0, 0x7f, 1, dac_tlv),
256 275
257 SOC_DOUBLE_R("Line DAC Playback Volume", DACL1_2_LLOPM_VOL, 276 SOC_DOUBLE_R_TLV("Line DAC Playback Volume",
258 DACR1_2_RLOPM_VOL, 0, 0x7f, 1), 277 DACL1_2_LLOPM_VOL, DACR1_2_RLOPM_VOL,
278 0, 118, 1, output_stage_tlv),
259 SOC_SINGLE("LineL Playback Switch", LLOPM_CTRL, 3, 0x01, 0), 279 SOC_SINGLE("LineL Playback Switch", LLOPM_CTRL, 3, 0x01, 0),
260 SOC_SINGLE("LineR Playback Switch", RLOPM_CTRL, 3, 0x01, 0), 280 SOC_SINGLE("LineR Playback Switch", RLOPM_CTRL, 3, 0x01, 0),
261 SOC_DOUBLE_R("LineL DAC Playback Volume", DACL1_2_LLOPM_VOL, 281 SOC_DOUBLE_R_TLV("LineL DAC Playback Volume",
262 DACR1_2_LLOPM_VOL, 0, 0x7f, 1), 282 DACL1_2_LLOPM_VOL, DACR1_2_LLOPM_VOL,
263 SOC_SINGLE("LineL Left PGA Bypass Playback Volume", PGAL_2_LLOPM_VOL, 283 0, 118, 1, output_stage_tlv),
264 0, 0x7f, 1), 284 SOC_SINGLE_TLV("LineL Left PGA Bypass Playback Volume",
265 SOC_SINGLE("LineR Right PGA Bypass Playback Volume", PGAR_2_RLOPM_VOL, 285 PGAL_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
266 0, 0x7f, 1), 286 SOC_SINGLE_TLV("LineR Right PGA Bypass Playback Volume",
267 SOC_DOUBLE_R("LineL Line2 Bypass Playback Volume", LINE2L_2_LLOPM_VOL, 287 PGAR_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
268 LINE2R_2_LLOPM_VOL, 0, 0x7f, 1), 288 SOC_DOUBLE_R_TLV("LineL Line2 Bypass Playback Volume",
269 SOC_DOUBLE_R("LineR Line2 Bypass Playback Volume", LINE2L_2_RLOPM_VOL, 289 LINE2L_2_LLOPM_VOL, LINE2R_2_LLOPM_VOL,
270 LINE2R_2_RLOPM_VOL, 0, 0x7f, 1), 290 0, 118, 1, output_stage_tlv),
271 291 SOC_DOUBLE_R_TLV("LineR Line2 Bypass Playback Volume",
272 SOC_DOUBLE_R("Mono DAC Playback Volume", DACL1_2_MONOLOPM_VOL, 292 LINE2L_2_RLOPM_VOL, LINE2R_2_RLOPM_VOL,
273 DACR1_2_MONOLOPM_VOL, 0, 0x7f, 1), 293 0, 118, 1, output_stage_tlv),
294
295 SOC_DOUBLE_R_TLV("Mono DAC Playback Volume",
296 DACL1_2_MONOLOPM_VOL, DACR1_2_MONOLOPM_VOL,
297 0, 118, 1, output_stage_tlv),
274 SOC_SINGLE("Mono DAC Playback Switch", MONOLOPM_CTRL, 3, 0x01, 0), 298 SOC_SINGLE("Mono DAC Playback Switch", MONOLOPM_CTRL, 3, 0x01, 0),
275 SOC_DOUBLE_R("Mono PGA Bypass Playback Volume", PGAL_2_MONOLOPM_VOL, 299 SOC_DOUBLE_R_TLV("Mono PGA Bypass Playback Volume",
276 PGAR_2_MONOLOPM_VOL, 0, 0x7f, 1), 300 PGAL_2_MONOLOPM_VOL, PGAR_2_MONOLOPM_VOL,
277 SOC_DOUBLE_R("Mono Line2 Bypass Playback Volume", LINE2L_2_MONOLOPM_VOL, 301 0, 118, 1, output_stage_tlv),
278 LINE2R_2_MONOLOPM_VOL, 0, 0x7f, 1), 302 SOC_DOUBLE_R_TLV("Mono Line2 Bypass Playback Volume",
279 303 LINE2L_2_MONOLOPM_VOL, LINE2R_2_MONOLOPM_VOL,
280 SOC_DOUBLE_R("HP DAC Playback Volume", DACL1_2_HPLOUT_VOL, 304 0, 118, 1, output_stage_tlv),
281 DACR1_2_HPROUT_VOL, 0, 0x7f, 1), 305
306 SOC_DOUBLE_R_TLV("HP DAC Playback Volume",
307 DACL1_2_HPLOUT_VOL, DACR1_2_HPROUT_VOL,
308 0, 118, 1, output_stage_tlv),
282 SOC_DOUBLE_R("HP DAC Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3, 309 SOC_DOUBLE_R("HP DAC Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3,
283 0x01, 0), 310 0x01, 0),
284 SOC_DOUBLE_R("HP Right PGA Bypass Playback Volume", PGAR_2_HPLOUT_VOL, 311 SOC_DOUBLE_R_TLV("HP Right PGA Bypass Playback Volume",
285 PGAR_2_HPROUT_VOL, 0, 0x7f, 1), 312 PGAR_2_HPLOUT_VOL, PGAR_2_HPROUT_VOL,
286 SOC_SINGLE("HPL PGA Bypass Playback Volume", PGAL_2_HPLOUT_VOL, 313 0, 118, 1, output_stage_tlv),
287 0, 0x7f, 1), 314 SOC_SINGLE_TLV("HPL PGA Bypass Playback Volume",
288 SOC_SINGLE("HPR PGA Bypass Playback Volume", PGAL_2_HPROUT_VOL, 315 PGAL_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
289 0, 0x7f, 1), 316 SOC_SINGLE_TLV("HPR PGA Bypass Playback Volume",
290 SOC_DOUBLE_R("HP Line2 Bypass Playback Volume", LINE2L_2_HPLOUT_VOL, 317 PGAL_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
291 LINE2R_2_HPROUT_VOL, 0, 0x7f, 1), 318 SOC_DOUBLE_R_TLV("HP Line2 Bypass Playback Volume",
292 319 LINE2L_2_HPLOUT_VOL, LINE2R_2_HPROUT_VOL,
293 SOC_DOUBLE_R("HPCOM DAC Playback Volume", DACL1_2_HPLCOM_VOL, 320 0, 118, 1, output_stage_tlv),
294 DACR1_2_HPRCOM_VOL, 0, 0x7f, 1), 321
322 SOC_DOUBLE_R_TLV("HPCOM DAC Playback Volume",
323 DACL1_2_HPLCOM_VOL, DACR1_2_HPRCOM_VOL,
324 0, 118, 1, output_stage_tlv),
295 SOC_DOUBLE_R("HPCOM DAC Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3, 325 SOC_DOUBLE_R("HPCOM DAC Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3,
296 0x01, 0), 326 0x01, 0),
297 SOC_SINGLE("HPLCOM PGA Bypass Playback Volume", PGAL_2_HPLCOM_VOL, 327 SOC_SINGLE_TLV("HPLCOM PGA Bypass Playback Volume",
298 0, 0x7f, 1), 328 PGAL_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
299 SOC_SINGLE("HPRCOM PGA Bypass Playback Volume", PGAL_2_HPRCOM_VOL, 329 SOC_SINGLE_TLV("HPRCOM PGA Bypass Playback Volume",
300 0, 0x7f, 1), 330 PGAL_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
301 SOC_DOUBLE_R("HPCOM Line2 Bypass Playback Volume", LINE2L_2_HPLCOM_VOL, 331 SOC_DOUBLE_R_TLV("HPCOM Line2 Bypass Playback Volume",
302 LINE2R_2_HPRCOM_VOL, 0, 0x7f, 1), 332 LINE2L_2_HPLCOM_VOL, LINE2R_2_HPRCOM_VOL,
333 0, 118, 1, output_stage_tlv),
303 334
304 /* 335 /*
305 * Note: enable Automatic input Gain Controller with care. It can 336 * Note: enable Automatic input Gain Controller with care. It can
@@ -308,28 +339,13 @@ static const struct snd_kcontrol_new aic3x_snd_controls[] = {
308 SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0), 339 SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0),
309 340
310 /* Input */ 341 /* Input */
311 SOC_DOUBLE_R("PGA Capture Volume", LADC_VOL, RADC_VOL, 0, 0x7f, 0), 342 SOC_DOUBLE_R_TLV("PGA Capture Volume", LADC_VOL, RADC_VOL,
343 0, 119, 0, adc_tlv),
312 SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1), 344 SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1),
313 345
314 SOC_ENUM("ADC HPF Cut-off", aic3x_enum[ADC_HPF_ENUM]), 346 SOC_ENUM("ADC HPF Cut-off", aic3x_enum[ADC_HPF_ENUM]),
315}; 347};
316 348
317/* add non dapm controls */
318static int aic3x_add_controls(struct snd_soc_codec *codec)
319{
320 int err, i;
321
322 for (i = 0; i < ARRAY_SIZE(aic3x_snd_controls); i++) {
323 err = snd_ctl_add(codec->card,
324 snd_soc_cnew(&aic3x_snd_controls[i],
325 codec, NULL));
326 if (err < 0)
327 return err;
328 }
329
330 return 0;
331}
332
333/* Left DAC Mux */ 349/* Left DAC Mux */
334static const struct snd_kcontrol_new aic3x_left_dac_mux_controls = 350static const struct snd_kcontrol_new aic3x_left_dac_mux_controls =
335SOC_DAPM_ENUM("Route", aic3x_enum[LDAC_ENUM]); 351SOC_DAPM_ENUM("Route", aic3x_enum[LDAC_ENUM]);
@@ -746,7 +762,7 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,
746{ 762{
747 struct snd_soc_pcm_runtime *rtd = substream->private_data; 763 struct snd_soc_pcm_runtime *rtd = substream->private_data;
748 struct snd_soc_device *socdev = rtd->socdev; 764 struct snd_soc_device *socdev = rtd->socdev;
749 struct snd_soc_codec *codec = socdev->codec; 765 struct snd_soc_codec *codec = socdev->card->codec;
750 struct aic3x_priv *aic3x = codec->private_data; 766 struct aic3x_priv *aic3x = codec->private_data;
751 int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0; 767 int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0;
752 u8 data, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1; 768 u8 data, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1;
@@ -1072,6 +1088,13 @@ EXPORT_SYMBOL_GPL(aic3x_button_pressed);
1072#define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 1088#define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1073 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE) 1089 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S32_LE)
1074 1090
1091static struct snd_soc_dai_ops aic3x_dai_ops = {
1092 .hw_params = aic3x_hw_params,
1093 .digital_mute = aic3x_mute,
1094 .set_sysclk = aic3x_set_dai_sysclk,
1095 .set_fmt = aic3x_set_dai_fmt,
1096};
1097
1075struct snd_soc_dai aic3x_dai = { 1098struct snd_soc_dai aic3x_dai = {
1076 .name = "tlv320aic3x", 1099 .name = "tlv320aic3x",
1077 .playback = { 1100 .playback = {
@@ -1086,19 +1109,14 @@ struct snd_soc_dai aic3x_dai = {
1086 .channels_max = 2, 1109 .channels_max = 2,
1087 .rates = AIC3X_RATES, 1110 .rates = AIC3X_RATES,
1088 .formats = AIC3X_FORMATS,}, 1111 .formats = AIC3X_FORMATS,},
1089 .ops = { 1112 .ops = &aic3x_dai_ops,
1090 .hw_params = aic3x_hw_params,
1091 .digital_mute = aic3x_mute,
1092 .set_sysclk = aic3x_set_dai_sysclk,
1093 .set_fmt = aic3x_set_dai_fmt,
1094 }
1095}; 1113};
1096EXPORT_SYMBOL_GPL(aic3x_dai); 1114EXPORT_SYMBOL_GPL(aic3x_dai);
1097 1115
1098static int aic3x_suspend(struct platform_device *pdev, pm_message_t state) 1116static int aic3x_suspend(struct platform_device *pdev, pm_message_t state)
1099{ 1117{
1100 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1118 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1101 struct snd_soc_codec *codec = socdev->codec; 1119 struct snd_soc_codec *codec = socdev->card->codec;
1102 1120
1103 aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF); 1121 aic3x_set_bias_level(codec, SND_SOC_BIAS_OFF);
1104 1122
@@ -1108,7 +1126,7 @@ static int aic3x_suspend(struct platform_device *pdev, pm_message_t state)
1108static int aic3x_resume(struct platform_device *pdev) 1126static int aic3x_resume(struct platform_device *pdev)
1109{ 1127{
1110 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1128 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1111 struct snd_soc_codec *codec = socdev->codec; 1129 struct snd_soc_codec *codec = socdev->card->codec;
1112 int i; 1130 int i;
1113 u8 data[2]; 1131 u8 data[2];
1114 u8 *cache = codec->reg_cache; 1132 u8 *cache = codec->reg_cache;
@@ -1131,7 +1149,7 @@ static int aic3x_resume(struct platform_device *pdev)
1131 */ 1149 */
1132static int aic3x_init(struct snd_soc_device *socdev) 1150static int aic3x_init(struct snd_soc_device *socdev)
1133{ 1151{
1134 struct snd_soc_codec *codec = socdev->codec; 1152 struct snd_soc_codec *codec = socdev->card->codec;
1135 struct aic3x_setup_data *setup = socdev->codec_data; 1153 struct aic3x_setup_data *setup = socdev->codec_data;
1136 int reg, ret = 0; 1154 int reg, ret = 0;
1137 1155
@@ -1227,7 +1245,8 @@ static int aic3x_init(struct snd_soc_device *socdev)
1227 aic3x_write(codec, AIC3X_GPIO1_REG, (setup->gpio_func[0] & 0xf) << 4); 1245 aic3x_write(codec, AIC3X_GPIO1_REG, (setup->gpio_func[0] & 0xf) << 4);
1228 aic3x_write(codec, AIC3X_GPIO2_REG, (setup->gpio_func[1] & 0xf) << 4); 1246 aic3x_write(codec, AIC3X_GPIO2_REG, (setup->gpio_func[1] & 0xf) << 4);
1229 1247
1230 aic3x_add_controls(codec); 1248 snd_soc_add_controls(codec, aic3x_snd_controls,
1249 ARRAY_SIZE(aic3x_snd_controls));
1231 aic3x_add_widgets(codec); 1250 aic3x_add_widgets(codec);
1232 ret = snd_soc_init_card(socdev); 1251 ret = snd_soc_init_card(socdev);
1233 if (ret < 0) { 1252 if (ret < 0) {
@@ -1261,7 +1280,7 @@ static int aic3x_i2c_probe(struct i2c_client *i2c,
1261 const struct i2c_device_id *id) 1280 const struct i2c_device_id *id)
1262{ 1281{
1263 struct snd_soc_device *socdev = aic3x_socdev; 1282 struct snd_soc_device *socdev = aic3x_socdev;
1264 struct snd_soc_codec *codec = socdev->codec; 1283 struct snd_soc_codec *codec = socdev->card->codec;
1265 int ret; 1284 int ret;
1266 1285
1267 i2c_set_clientdata(i2c, codec); 1286 i2c_set_clientdata(i2c, codec);
@@ -1366,7 +1385,7 @@ static int aic3x_probe(struct platform_device *pdev)
1366 } 1385 }
1367 1386
1368 codec->private_data = aic3x; 1387 codec->private_data = aic3x;
1369 socdev->codec = codec; 1388 socdev->card->codec = codec;
1370 mutex_init(&codec->mutex); 1389 mutex_init(&codec->mutex);
1371 INIT_LIST_HEAD(&codec->dapm_widgets); 1390 INIT_LIST_HEAD(&codec->dapm_widgets);
1372 INIT_LIST_HEAD(&codec->dapm_paths); 1391 INIT_LIST_HEAD(&codec->dapm_paths);
@@ -1392,7 +1411,7 @@ static int aic3x_probe(struct platform_device *pdev)
1392static int aic3x_remove(struct platform_device *pdev) 1411static int aic3x_remove(struct platform_device *pdev)
1393{ 1412{
1394 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1413 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1395 struct snd_soc_codec *codec = socdev->codec; 1414 struct snd_soc_codec *codec = socdev->card->codec;
1396 1415
1397 /* power down chip */ 1416 /* power down chip */
1398 if (codec->control_data) 1417 if (codec->control_data)
diff --git a/sound/soc/codecs/twl4030.c b/sound/soc/codecs/twl4030.c
index ea370a4f86d5..97738e2ece04 100644
--- a/sound/soc/codecs/twl4030.c
+++ b/sound/soc/codecs/twl4030.c
@@ -42,7 +42,7 @@
42 */ 42 */
43static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = { 43static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = {
44 0x00, /* this register not used */ 44 0x00, /* this register not used */
45 0x93, /* REG_CODEC_MODE (0x1) */ 45 0x91, /* REG_CODEC_MODE (0x1) */
46 0xc3, /* REG_OPTION (0x2) */ 46 0xc3, /* REG_OPTION (0x2) */
47 0x00, /* REG_UNKNOWN (0x3) */ 47 0x00, /* REG_UNKNOWN (0x3) */
48 0x00, /* REG_MICBIAS_CTL (0x4) */ 48 0x00, /* REG_MICBIAS_CTL (0x4) */
@@ -117,6 +117,13 @@ static const u8 twl4030_reg[TWL4030_CACHEREGNUM] = {
117 0x00, /* REG_MISC_SET_2 (0x49) */ 117 0x00, /* REG_MISC_SET_2 (0x49) */
118}; 118};
119 119
120/* codec private data */
121struct twl4030_priv {
122 unsigned int bypass_state;
123 unsigned int codec_powered;
124 unsigned int codec_muted;
125};
126
120/* 127/*
121 * read twl4030 register cache 128 * read twl4030 register cache
122 */ 129 */
@@ -125,6 +132,9 @@ static inline unsigned int twl4030_read_reg_cache(struct snd_soc_codec *codec,
125{ 132{
126 u8 *cache = codec->reg_cache; 133 u8 *cache = codec->reg_cache;
127 134
135 if (reg >= TWL4030_CACHEREGNUM)
136 return -EIO;
137
128 return cache[reg]; 138 return cache[reg];
129} 139}
130 140
@@ -151,26 +161,22 @@ static int twl4030_write(struct snd_soc_codec *codec,
151 return twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, value, reg); 161 return twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE, value, reg);
152} 162}
153 163
154static void twl4030_clear_codecpdz(struct snd_soc_codec *codec) 164static void twl4030_codec_enable(struct snd_soc_codec *codec, int enable)
155{ 165{
166 struct twl4030_priv *twl4030 = codec->private_data;
156 u8 mode; 167 u8 mode;
157 168
158 mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE); 169 if (enable == twl4030->codec_powered)
159 twl4030_write(codec, TWL4030_REG_CODEC_MODE, 170 return;
160 mode & ~TWL4030_CODECPDZ);
161
162 /* REVISIT: this delay is present in TI sample drivers */
163 /* but there seems to be no TRM requirement for it */
164 udelay(10);
165}
166
167static void twl4030_set_codecpdz(struct snd_soc_codec *codec)
168{
169 u8 mode;
170 171
171 mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE); 172 mode = twl4030_read_reg_cache(codec, TWL4030_REG_CODEC_MODE);
172 twl4030_write(codec, TWL4030_REG_CODEC_MODE, 173 if (enable)
173 mode | TWL4030_CODECPDZ); 174 mode |= TWL4030_CODECPDZ;
175 else
176 mode &= ~TWL4030_CODECPDZ;
177
178 twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
179 twl4030->codec_powered = enable;
174 180
175 /* REVISIT: this delay is present in TI sample drivers */ 181 /* REVISIT: this delay is present in TI sample drivers */
176 /* but there seems to be no TRM requirement for it */ 182 /* but there seems to be no TRM requirement for it */
@@ -182,7 +188,7 @@ static void twl4030_init_chip(struct snd_soc_codec *codec)
182 int i; 188 int i;
183 189
184 /* clear CODECPDZ prior to setting register defaults */ 190 /* clear CODECPDZ prior to setting register defaults */
185 twl4030_clear_codecpdz(codec); 191 twl4030_codec_enable(codec, 0);
186 192
187 /* set all audio section registers to reasonable defaults */ 193 /* set all audio section registers to reasonable defaults */
188 for (i = TWL4030_REG_OPTION; i <= TWL4030_REG_MISC_SET_2; i++) 194 for (i = TWL4030_REG_OPTION; i <= TWL4030_REG_MISC_SET_2; i++)
@@ -190,6 +196,122 @@ static void twl4030_init_chip(struct snd_soc_codec *codec)
190 196
191} 197}
192 198
199static void twl4030_codec_mute(struct snd_soc_codec *codec, int mute)
200{
201 struct twl4030_priv *twl4030 = codec->private_data;
202 u8 reg_val;
203
204 if (mute == twl4030->codec_muted)
205 return;
206
207 if (mute) {
208 /* Bypass the reg_cache and mute the volumes
209 * Headset mute is done in it's own event handler
210 * Things to mute: Earpiece, PreDrivL/R, CarkitL/R
211 */
212 reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_EAR_CTL);
213 twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
214 reg_val & (~TWL4030_EAR_GAIN),
215 TWL4030_REG_EAR_CTL);
216
217 reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_PREDL_CTL);
218 twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
219 reg_val & (~TWL4030_PREDL_GAIN),
220 TWL4030_REG_PREDL_CTL);
221 reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_PREDR_CTL);
222 twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
223 reg_val & (~TWL4030_PREDR_GAIN),
224 TWL4030_REG_PREDL_CTL);
225
226 reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_PRECKL_CTL);
227 twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
228 reg_val & (~TWL4030_PRECKL_GAIN),
229 TWL4030_REG_PRECKL_CTL);
230 reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_PRECKR_CTL);
231 twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
232 reg_val & (~TWL4030_PRECKL_GAIN),
233 TWL4030_REG_PRECKR_CTL);
234
235 /* Disable PLL */
236 reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_APLL_CTL);
237 reg_val &= ~TWL4030_APLL_EN;
238 twl4030_write(codec, TWL4030_REG_APLL_CTL, reg_val);
239 } else {
240 /* Restore the volumes
241 * Headset mute is done in it's own event handler
242 * Things to restore: Earpiece, PreDrivL/R, CarkitL/R
243 */
244 twl4030_write(codec, TWL4030_REG_EAR_CTL,
245 twl4030_read_reg_cache(codec, TWL4030_REG_EAR_CTL));
246
247 twl4030_write(codec, TWL4030_REG_PREDL_CTL,
248 twl4030_read_reg_cache(codec, TWL4030_REG_PREDL_CTL));
249 twl4030_write(codec, TWL4030_REG_PREDR_CTL,
250 twl4030_read_reg_cache(codec, TWL4030_REG_PREDR_CTL));
251
252 twl4030_write(codec, TWL4030_REG_PRECKL_CTL,
253 twl4030_read_reg_cache(codec, TWL4030_REG_PRECKL_CTL));
254 twl4030_write(codec, TWL4030_REG_PRECKR_CTL,
255 twl4030_read_reg_cache(codec, TWL4030_REG_PRECKR_CTL));
256
257 /* Enable PLL */
258 reg_val = twl4030_read_reg_cache(codec, TWL4030_REG_APLL_CTL);
259 reg_val |= TWL4030_APLL_EN;
260 twl4030_write(codec, TWL4030_REG_APLL_CTL, reg_val);
261 }
262
263 twl4030->codec_muted = mute;
264}
265
266static void twl4030_power_up(struct snd_soc_codec *codec)
267{
268 struct twl4030_priv *twl4030 = codec->private_data;
269 u8 anamicl, regmisc1, byte;
270 int i = 0;
271
272 if (twl4030->codec_powered)
273 return;
274
275 /* set CODECPDZ to turn on codec */
276 twl4030_codec_enable(codec, 1);
277
278 /* initiate offset cancellation */
279 anamicl = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICL);
280 twl4030_write(codec, TWL4030_REG_ANAMICL,
281 anamicl | TWL4030_CNCL_OFFSET_START);
282
283 /* wait for offset cancellation to complete */
284 do {
285 /* this takes a little while, so don't slam i2c */
286 udelay(2000);
287 twl4030_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte,
288 TWL4030_REG_ANAMICL);
289 } while ((i++ < 100) &&
290 ((byte & TWL4030_CNCL_OFFSET_START) ==
291 TWL4030_CNCL_OFFSET_START));
292
293 /* Make sure that the reg_cache has the same value as the HW */
294 twl4030_write_reg_cache(codec, TWL4030_REG_ANAMICL, byte);
295
296 /* anti-pop when changing analog gain */
297 regmisc1 = twl4030_read_reg_cache(codec, TWL4030_REG_MISC_SET_1);
298 twl4030_write(codec, TWL4030_REG_MISC_SET_1,
299 regmisc1 | TWL4030_SMOOTH_ANAVOL_EN);
300
301 /* toggle CODECPDZ as per TRM */
302 twl4030_codec_enable(codec, 0);
303 twl4030_codec_enable(codec, 1);
304}
305
306/*
307 * Unconditional power down
308 */
309static void twl4030_power_down(struct snd_soc_codec *codec)
310{
311 /* power down */
312 twl4030_codec_enable(codec, 0);
313}
314
193/* Earpiece */ 315/* Earpiece */
194static const char *twl4030_earpiece_texts[] = 316static const char *twl4030_earpiece_texts[] =
195 {"Off", "DACL1", "DACL2", "DACR1"}; 317 {"Off", "DACL1", "DACL2", "DACR1"};
@@ -366,6 +488,41 @@ static const struct soc_enum twl4030_micpathtx2_enum =
366static const struct snd_kcontrol_new twl4030_dapm_micpathtx2_control = 488static const struct snd_kcontrol_new twl4030_dapm_micpathtx2_control =
367SOC_DAPM_ENUM("Route", twl4030_micpathtx2_enum); 489SOC_DAPM_ENUM("Route", twl4030_micpathtx2_enum);
368 490
491/* Analog bypass for AudioR1 */
492static const struct snd_kcontrol_new twl4030_dapm_abypassr1_control =
493 SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXR1_APGA_CTL, 2, 1, 0);
494
495/* Analog bypass for AudioL1 */
496static const struct snd_kcontrol_new twl4030_dapm_abypassl1_control =
497 SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXL1_APGA_CTL, 2, 1, 0);
498
499/* Analog bypass for AudioR2 */
500static const struct snd_kcontrol_new twl4030_dapm_abypassr2_control =
501 SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXR2_APGA_CTL, 2, 1, 0);
502
503/* Analog bypass for AudioL2 */
504static const struct snd_kcontrol_new twl4030_dapm_abypassl2_control =
505 SOC_DAPM_SINGLE("Switch", TWL4030_REG_ARXL2_APGA_CTL, 2, 1, 0);
506
507/* Digital bypass gain, 0 mutes the bypass */
508static const unsigned int twl4030_dapm_dbypass_tlv[] = {
509 TLV_DB_RANGE_HEAD(2),
510 0, 3, TLV_DB_SCALE_ITEM(-2400, 0, 1),
511 4, 7, TLV_DB_SCALE_ITEM(-1800, 600, 0),
512};
513
514/* Digital bypass left (TX1L -> RX2L) */
515static const struct snd_kcontrol_new twl4030_dapm_dbypassl_control =
516 SOC_DAPM_SINGLE_TLV("Volume",
517 TWL4030_REG_ATX2ARXPGA, 3, 7, 0,
518 twl4030_dapm_dbypass_tlv);
519
520/* Digital bypass right (TX1R -> RX2R) */
521static const struct snd_kcontrol_new twl4030_dapm_dbypassr_control =
522 SOC_DAPM_SINGLE_TLV("Volume",
523 TWL4030_REG_ATX2ARXPGA, 0, 7, 0,
524 twl4030_dapm_dbypass_tlv);
525
369static int micpath_event(struct snd_soc_dapm_widget *w, 526static int micpath_event(struct snd_soc_dapm_widget *w,
370 struct snd_kcontrol *kcontrol, int event) 527 struct snd_kcontrol *kcontrol, int event)
371{ 528{
@@ -420,6 +577,79 @@ static int handsfree_event(struct snd_soc_dapm_widget *w,
420 return 0; 577 return 0;
421} 578}
422 579
580static int headsetl_event(struct snd_soc_dapm_widget *w,
581 struct snd_kcontrol *kcontrol, int event)
582{
583 unsigned char hs_gain, hs_pop;
584
585 /* Save the current volume */
586 hs_gain = twl4030_read_reg_cache(w->codec, TWL4030_REG_HS_GAIN_SET);
587 hs_pop = twl4030_read_reg_cache(w->codec, TWL4030_REG_HS_POPN_SET);
588
589 switch (event) {
590 case SND_SOC_DAPM_POST_PMU:
591 /* Do the anti-pop/bias ramp enable according to the TRM */
592 hs_pop |= TWL4030_VMID_EN;
593 twl4030_write(w->codec, TWL4030_REG_HS_POPN_SET, hs_pop);
594 /* Is this needed? Can we just use whatever gain here? */
595 twl4030_write(w->codec, TWL4030_REG_HS_GAIN_SET,
596 (hs_gain & (~0x0f)) | 0x0a);
597 hs_pop |= TWL4030_RAMP_EN;
598 twl4030_write(w->codec, TWL4030_REG_HS_POPN_SET, hs_pop);
599
600 /* Restore the original volume */
601 twl4030_write(w->codec, TWL4030_REG_HS_GAIN_SET, hs_gain);
602 break;
603 case SND_SOC_DAPM_POST_PMD:
604 /* Do the anti-pop/bias ramp disable according to the TRM */
605 hs_pop &= ~TWL4030_RAMP_EN;
606 twl4030_write(w->codec, TWL4030_REG_HS_POPN_SET, hs_pop);
607 /* Bypass the reg_cache to mute the headset */
608 twl4030_i2c_write_u8(TWL4030_MODULE_AUDIO_VOICE,
609 hs_gain & (~0x0f),
610 TWL4030_REG_HS_GAIN_SET);
611 hs_pop &= ~TWL4030_VMID_EN;
612 twl4030_write(w->codec, TWL4030_REG_HS_POPN_SET, hs_pop);
613 break;
614 }
615 return 0;
616}
617
618static int bypass_event(struct snd_soc_dapm_widget *w,
619 struct snd_kcontrol *kcontrol, int event)
620{
621 struct soc_mixer_control *m =
622 (struct soc_mixer_control *)w->kcontrols->private_value;
623 struct twl4030_priv *twl4030 = w->codec->private_data;
624 unsigned char reg;
625
626 reg = twl4030_read_reg_cache(w->codec, m->reg);
627
628 if (m->reg <= TWL4030_REG_ARXR2_APGA_CTL) {
629 /* Analog bypass */
630 if (reg & (1 << m->shift))
631 twl4030->bypass_state |=
632 (1 << (m->reg - TWL4030_REG_ARXL1_APGA_CTL));
633 else
634 twl4030->bypass_state &=
635 ~(1 << (m->reg - TWL4030_REG_ARXL1_APGA_CTL));
636 } else {
637 /* Digital bypass */
638 if (reg & (0x7 << m->shift))
639 twl4030->bypass_state |= (1 << (m->shift ? 5 : 4));
640 else
641 twl4030->bypass_state &= ~(1 << (m->shift ? 5 : 4));
642 }
643
644 if (w->codec->bias_level == SND_SOC_BIAS_STANDBY) {
645 if (twl4030->bypass_state)
646 twl4030_codec_mute(w->codec, 0);
647 else
648 twl4030_codec_mute(w->codec, 1);
649 }
650 return 0;
651}
652
423/* 653/*
424 * Some of the gain controls in TWL (mostly those which are associated with 654 * Some of the gain controls in TWL (mostly those which are associated with
425 * the outputs) are implemented in an interesting way: 655 * the outputs) are implemented in an interesting way:
@@ -614,6 +844,17 @@ static DECLARE_TLV_DB_SCALE(digital_capture_tlv, 0, 100, 0);
614 */ 844 */
615static DECLARE_TLV_DB_SCALE(input_gain_tlv, 0, 600, 0); 845static DECLARE_TLV_DB_SCALE(input_gain_tlv, 0, 600, 0);
616 846
847static const char *twl4030_rampdelay_texts[] = {
848 "27/20/14 ms", "55/40/27 ms", "109/81/55 ms", "218/161/109 ms",
849 "437/323/218 ms", "874/645/437 ms", "1748/1291/874 ms",
850 "3495/2581/1748 ms"
851};
852
853static const struct soc_enum twl4030_rampdelay_enum =
854 SOC_ENUM_SINGLE(TWL4030_REG_HS_POPN_SET, 2,
855 ARRAY_SIZE(twl4030_rampdelay_texts),
856 twl4030_rampdelay_texts);
857
617static const struct snd_kcontrol_new twl4030_snd_controls[] = { 858static const struct snd_kcontrol_new twl4030_snd_controls[] = {
618 /* Common playback gain controls */ 859 /* Common playback gain controls */
619 SOC_DOUBLE_R_TLV("DAC1 Digital Fine Playback Volume", 860 SOC_DOUBLE_R_TLV("DAC1 Digital Fine Playback Volume",
@@ -668,23 +909,9 @@ static const struct snd_kcontrol_new twl4030_snd_controls[] = {
668 909
669 SOC_DOUBLE_TLV("Analog Capture Volume", TWL4030_REG_ANAMIC_GAIN, 910 SOC_DOUBLE_TLV("Analog Capture Volume", TWL4030_REG_ANAMIC_GAIN,
670 0, 3, 5, 0, input_gain_tlv), 911 0, 3, 5, 0, input_gain_tlv),
671};
672
673/* add non dapm controls */
674static int twl4030_add_controls(struct snd_soc_codec *codec)
675{
676 int err, i;
677
678 for (i = 0; i < ARRAY_SIZE(twl4030_snd_controls); i++) {
679 err = snd_ctl_add(codec->card,
680 snd_soc_cnew(&twl4030_snd_controls[i],
681 codec, NULL));
682 if (err < 0)
683 return err;
684 }
685 912
686 return 0; 913 SOC_ENUM("HS ramp delay", twl4030_rampdelay_enum),
687} 914};
688 915
689static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = { 916static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
690 /* Left channel inputs */ 917 /* Left channel inputs */
@@ -714,13 +941,13 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
714 941
715 /* DACs */ 942 /* DACs */
716 SND_SOC_DAPM_DAC("DAC Right1", "Right Front Playback", 943 SND_SOC_DAPM_DAC("DAC Right1", "Right Front Playback",
717 TWL4030_REG_AVDAC_CTL, 0, 0), 944 SND_SOC_NOPM, 0, 0),
718 SND_SOC_DAPM_DAC("DAC Left1", "Left Front Playback", 945 SND_SOC_DAPM_DAC("DAC Left1", "Left Front Playback",
719 TWL4030_REG_AVDAC_CTL, 1, 0), 946 SND_SOC_NOPM, 0, 0),
720 SND_SOC_DAPM_DAC("DAC Right2", "Right Rear Playback", 947 SND_SOC_DAPM_DAC("DAC Right2", "Right Rear Playback",
721 TWL4030_REG_AVDAC_CTL, 2, 0), 948 SND_SOC_NOPM, 0, 0),
722 SND_SOC_DAPM_DAC("DAC Left2", "Left Rear Playback", 949 SND_SOC_DAPM_DAC("DAC Left2", "Left Rear Playback",
723 TWL4030_REG_AVDAC_CTL, 3, 0), 950 SND_SOC_NOPM, 0, 0),
724 951
725 /* Analog PGAs */ 952 /* Analog PGAs */
726 SND_SOC_DAPM_PGA("ARXR1_APGA", TWL4030_REG_ARXR1_APGA_CTL, 953 SND_SOC_DAPM_PGA("ARXR1_APGA", TWL4030_REG_ARXR1_APGA_CTL,
@@ -732,6 +959,37 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
732 SND_SOC_DAPM_PGA("ARXL2_APGA", TWL4030_REG_ARXL2_APGA_CTL, 959 SND_SOC_DAPM_PGA("ARXL2_APGA", TWL4030_REG_ARXL2_APGA_CTL,
733 0, 0, NULL, 0), 960 0, 0, NULL, 0),
734 961
962 /* Analog bypasses */
963 SND_SOC_DAPM_SWITCH_E("Right1 Analog Loopback", SND_SOC_NOPM, 0, 0,
964 &twl4030_dapm_abypassr1_control, bypass_event,
965 SND_SOC_DAPM_POST_REG),
966 SND_SOC_DAPM_SWITCH_E("Left1 Analog Loopback", SND_SOC_NOPM, 0, 0,
967 &twl4030_dapm_abypassl1_control,
968 bypass_event, SND_SOC_DAPM_POST_REG),
969 SND_SOC_DAPM_SWITCH_E("Right2 Analog Loopback", SND_SOC_NOPM, 0, 0,
970 &twl4030_dapm_abypassr2_control,
971 bypass_event, SND_SOC_DAPM_POST_REG),
972 SND_SOC_DAPM_SWITCH_E("Left2 Analog Loopback", SND_SOC_NOPM, 0, 0,
973 &twl4030_dapm_abypassl2_control,
974 bypass_event, SND_SOC_DAPM_POST_REG),
975
976 /* Digital bypasses */
977 SND_SOC_DAPM_SWITCH_E("Left Digital Loopback", SND_SOC_NOPM, 0, 0,
978 &twl4030_dapm_dbypassl_control, bypass_event,
979 SND_SOC_DAPM_POST_REG),
980 SND_SOC_DAPM_SWITCH_E("Right Digital Loopback", SND_SOC_NOPM, 0, 0,
981 &twl4030_dapm_dbypassr_control, bypass_event,
982 SND_SOC_DAPM_POST_REG),
983
984 SND_SOC_DAPM_MIXER("Analog R1 Playback Mixer", TWL4030_REG_AVDAC_CTL,
985 0, 0, NULL, 0),
986 SND_SOC_DAPM_MIXER("Analog L1 Playback Mixer", TWL4030_REG_AVDAC_CTL,
987 1, 0, NULL, 0),
988 SND_SOC_DAPM_MIXER("Analog R2 Playback Mixer", TWL4030_REG_AVDAC_CTL,
989 2, 0, NULL, 0),
990 SND_SOC_DAPM_MIXER("Analog L2 Playback Mixer", TWL4030_REG_AVDAC_CTL,
991 3, 0, NULL, 0),
992
735 /* Output MUX controls */ 993 /* Output MUX controls */
736 /* Earpiece */ 994 /* Earpiece */
737 SND_SOC_DAPM_VALUE_MUX("Earpiece Mux", SND_SOC_NOPM, 0, 0, 995 SND_SOC_DAPM_VALUE_MUX("Earpiece Mux", SND_SOC_NOPM, 0, 0,
@@ -742,8 +1000,9 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
742 SND_SOC_DAPM_VALUE_MUX("PredriveR Mux", SND_SOC_NOPM, 0, 0, 1000 SND_SOC_DAPM_VALUE_MUX("PredriveR Mux", SND_SOC_NOPM, 0, 0,
743 &twl4030_dapm_predriver_control), 1001 &twl4030_dapm_predriver_control),
744 /* HeadsetL/R */ 1002 /* HeadsetL/R */
745 SND_SOC_DAPM_MUX("HeadsetL Mux", SND_SOC_NOPM, 0, 0, 1003 SND_SOC_DAPM_MUX_E("HeadsetL Mux", SND_SOC_NOPM, 0, 0,
746 &twl4030_dapm_hsol_control), 1004 &twl4030_dapm_hsol_control, headsetl_event,
1005 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD),
747 SND_SOC_DAPM_MUX("HeadsetR Mux", SND_SOC_NOPM, 0, 0, 1006 SND_SOC_DAPM_MUX("HeadsetR Mux", SND_SOC_NOPM, 0, 0,
748 &twl4030_dapm_hsor_control), 1007 &twl4030_dapm_hsor_control),
749 /* CarkitL/R */ 1008 /* CarkitL/R */
@@ -782,16 +1041,16 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
782 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD| 1041 SND_SOC_DAPM_POST_PMU|SND_SOC_DAPM_POST_PMD|
783 SND_SOC_DAPM_POST_REG), 1042 SND_SOC_DAPM_POST_REG),
784 1043
785 /* Analog input muxes with power switch for the physical ADCL/R */ 1044 /* Analog input muxes with switch for the capture amplifiers */
786 SND_SOC_DAPM_VALUE_MUX("Analog Left Capture Route", 1045 SND_SOC_DAPM_VALUE_MUX("Analog Left Capture Route",
787 TWL4030_REG_AVADC_CTL, 3, 0, &twl4030_dapm_analoglmic_control), 1046 TWL4030_REG_ANAMICL, 4, 0, &twl4030_dapm_analoglmic_control),
788 SND_SOC_DAPM_VALUE_MUX("Analog Right Capture Route", 1047 SND_SOC_DAPM_VALUE_MUX("Analog Right Capture Route",
789 TWL4030_REG_AVADC_CTL, 1, 0, &twl4030_dapm_analogrmic_control), 1048 TWL4030_REG_ANAMICR, 4, 0, &twl4030_dapm_analogrmic_control),
790 1049
791 SND_SOC_DAPM_PGA("Analog Left Amplifier", 1050 SND_SOC_DAPM_PGA("ADC Physical Left",
792 TWL4030_REG_ANAMICL, 4, 0, NULL, 0), 1051 TWL4030_REG_AVADC_CTL, 3, 0, NULL, 0),
793 SND_SOC_DAPM_PGA("Analog Right Amplifier", 1052 SND_SOC_DAPM_PGA("ADC Physical Right",
794 TWL4030_REG_ANAMICR, 4, 0, NULL, 0), 1053 TWL4030_REG_AVADC_CTL, 1, 0, NULL, 0),
795 1054
796 SND_SOC_DAPM_PGA("Digimic0 Enable", 1055 SND_SOC_DAPM_PGA("Digimic0 Enable",
797 TWL4030_REG_ADCMICSEL, 1, 0, NULL, 0), 1056 TWL4030_REG_ADCMICSEL, 1, 0, NULL, 0),
@@ -801,13 +1060,19 @@ static const struct snd_soc_dapm_widget twl4030_dapm_widgets[] = {
801 SND_SOC_DAPM_MICBIAS("Mic Bias 1", TWL4030_REG_MICBIAS_CTL, 0, 0), 1060 SND_SOC_DAPM_MICBIAS("Mic Bias 1", TWL4030_REG_MICBIAS_CTL, 0, 0),
802 SND_SOC_DAPM_MICBIAS("Mic Bias 2", TWL4030_REG_MICBIAS_CTL, 1, 0), 1061 SND_SOC_DAPM_MICBIAS("Mic Bias 2", TWL4030_REG_MICBIAS_CTL, 1, 0),
803 SND_SOC_DAPM_MICBIAS("Headset Mic Bias", TWL4030_REG_MICBIAS_CTL, 2, 0), 1062 SND_SOC_DAPM_MICBIAS("Headset Mic Bias", TWL4030_REG_MICBIAS_CTL, 2, 0),
1063
804}; 1064};
805 1065
806static const struct snd_soc_dapm_route intercon[] = { 1066static const struct snd_soc_dapm_route intercon[] = {
807 {"ARXL1_APGA", NULL, "DAC Left1"}, 1067 {"Analog L1 Playback Mixer", NULL, "DAC Left1"},
808 {"ARXR1_APGA", NULL, "DAC Right1"}, 1068 {"Analog R1 Playback Mixer", NULL, "DAC Right1"},
809 {"ARXL2_APGA", NULL, "DAC Left2"}, 1069 {"Analog L2 Playback Mixer", NULL, "DAC Left2"},
810 {"ARXR2_APGA", NULL, "DAC Right2"}, 1070 {"Analog R2 Playback Mixer", NULL, "DAC Right2"},
1071
1072 {"ARXL1_APGA", NULL, "Analog L1 Playback Mixer"},
1073 {"ARXR1_APGA", NULL, "Analog R1 Playback Mixer"},
1074 {"ARXL2_APGA", NULL, "Analog L2 Playback Mixer"},
1075 {"ARXR2_APGA", NULL, "Analog R2 Playback Mixer"},
811 1076
812 /* Internal playback routings */ 1077 /* Internal playback routings */
813 /* Earpiece */ 1078 /* Earpiece */
@@ -865,23 +1130,23 @@ static const struct snd_soc_dapm_route intercon[] = {
865 {"Analog Right Capture Route", "Sub mic", "SUBMIC"}, 1130 {"Analog Right Capture Route", "Sub mic", "SUBMIC"},
866 {"Analog Right Capture Route", "AUXR", "AUXR"}, 1131 {"Analog Right Capture Route", "AUXR", "AUXR"},
867 1132
868 {"Analog Left Amplifier", NULL, "Analog Left Capture Route"}, 1133 {"ADC Physical Left", NULL, "Analog Left Capture Route"},
869 {"Analog Right Amplifier", NULL, "Analog Right Capture Route"}, 1134 {"ADC Physical Right", NULL, "Analog Right Capture Route"},
870 1135
871 {"Digimic0 Enable", NULL, "DIGIMIC0"}, 1136 {"Digimic0 Enable", NULL, "DIGIMIC0"},
872 {"Digimic1 Enable", NULL, "DIGIMIC1"}, 1137 {"Digimic1 Enable", NULL, "DIGIMIC1"},
873 1138
874 /* TX1 Left capture path */ 1139 /* TX1 Left capture path */
875 {"TX1 Capture Route", "Analog", "Analog Left Amplifier"}, 1140 {"TX1 Capture Route", "Analog", "ADC Physical Left"},
876 {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"}, 1141 {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"},
877 /* TX1 Right capture path */ 1142 /* TX1 Right capture path */
878 {"TX1 Capture Route", "Analog", "Analog Right Amplifier"}, 1143 {"TX1 Capture Route", "Analog", "ADC Physical Right"},
879 {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"}, 1144 {"TX1 Capture Route", "Digimic0", "Digimic0 Enable"},
880 /* TX2 Left capture path */ 1145 /* TX2 Left capture path */
881 {"TX2 Capture Route", "Analog", "Analog Left Amplifier"}, 1146 {"TX2 Capture Route", "Analog", "ADC Physical Left"},
882 {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"}, 1147 {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"},
883 /* TX2 Right capture path */ 1148 /* TX2 Right capture path */
884 {"TX2 Capture Route", "Analog", "Analog Right Amplifier"}, 1149 {"TX2 Capture Route", "Analog", "ADC Physical Right"},
885 {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"}, 1150 {"TX2 Capture Route", "Digimic1", "Digimic1 Enable"},
886 1151
887 {"ADC Virtual Left1", NULL, "TX1 Capture Route"}, 1152 {"ADC Virtual Left1", NULL, "TX1 Capture Route"},
@@ -889,6 +1154,24 @@ static const struct snd_soc_dapm_route intercon[] = {
889 {"ADC Virtual Left2", NULL, "TX2 Capture Route"}, 1154 {"ADC Virtual Left2", NULL, "TX2 Capture Route"},
890 {"ADC Virtual Right2", NULL, "TX2 Capture Route"}, 1155 {"ADC Virtual Right2", NULL, "TX2 Capture Route"},
891 1156
1157 /* Analog bypass routes */
1158 {"Right1 Analog Loopback", "Switch", "Analog Right Capture Route"},
1159 {"Left1 Analog Loopback", "Switch", "Analog Left Capture Route"},
1160 {"Right2 Analog Loopback", "Switch", "Analog Right Capture Route"},
1161 {"Left2 Analog Loopback", "Switch", "Analog Left Capture Route"},
1162
1163 {"Analog R1 Playback Mixer", NULL, "Right1 Analog Loopback"},
1164 {"Analog L1 Playback Mixer", NULL, "Left1 Analog Loopback"},
1165 {"Analog R2 Playback Mixer", NULL, "Right2 Analog Loopback"},
1166 {"Analog L2 Playback Mixer", NULL, "Left2 Analog Loopback"},
1167
1168 /* Digital bypass routes */
1169 {"Right Digital Loopback", "Volume", "TX1 Capture Route"},
1170 {"Left Digital Loopback", "Volume", "TX1 Capture Route"},
1171
1172 {"Analog R2 Playback Mixer", NULL, "Right Digital Loopback"},
1173 {"Analog L2 Playback Mixer", NULL, "Left Digital Loopback"},
1174
892}; 1175};
893 1176
894static int twl4030_add_widgets(struct snd_soc_codec *codec) 1177static int twl4030_add_widgets(struct snd_soc_codec *codec)
@@ -902,82 +1185,28 @@ static int twl4030_add_widgets(struct snd_soc_codec *codec)
902 return 0; 1185 return 0;
903} 1186}
904 1187
905static void twl4030_power_up(struct snd_soc_codec *codec)
906{
907 u8 anamicl, regmisc1, byte, popn;
908 int i = 0;
909
910 /* set CODECPDZ to turn on codec */
911 twl4030_set_codecpdz(codec);
912
913 /* initiate offset cancellation */
914 anamicl = twl4030_read_reg_cache(codec, TWL4030_REG_ANAMICL);
915 twl4030_write(codec, TWL4030_REG_ANAMICL,
916 anamicl | TWL4030_CNCL_OFFSET_START);
917
918
919 /* wait for offset cancellation to complete */
920 do {
921 /* this takes a little while, so don't slam i2c */
922 udelay(2000);
923 twl4030_i2c_read_u8(TWL4030_MODULE_AUDIO_VOICE, &byte,
924 TWL4030_REG_ANAMICL);
925 } while ((i++ < 100) &&
926 ((byte & TWL4030_CNCL_OFFSET_START) ==
927 TWL4030_CNCL_OFFSET_START));
928
929 /* anti-pop when changing analog gain */
930 regmisc1 = twl4030_read_reg_cache(codec, TWL4030_REG_MISC_SET_1);
931 twl4030_write(codec, TWL4030_REG_MISC_SET_1,
932 regmisc1 | TWL4030_SMOOTH_ANAVOL_EN);
933
934 /* toggle CODECPDZ as per TRM */
935 twl4030_clear_codecpdz(codec);
936 twl4030_set_codecpdz(codec);
937
938 /* program anti-pop with bias ramp delay */
939 popn = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET);
940 popn &= TWL4030_RAMP_DELAY;
941 popn |= TWL4030_RAMP_DELAY_645MS;
942 twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn);
943 popn |= TWL4030_VMID_EN;
944 twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn);
945
946 /* enable anti-pop ramp */
947 popn |= TWL4030_RAMP_EN;
948 twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn);
949}
950
951static void twl4030_power_down(struct snd_soc_codec *codec)
952{
953 u8 popn;
954
955 /* disable anti-pop ramp */
956 popn = twl4030_read_reg_cache(codec, TWL4030_REG_HS_POPN_SET);
957 popn &= ~TWL4030_RAMP_EN;
958 twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn);
959
960 /* disable bias out */
961 popn &= ~TWL4030_VMID_EN;
962 twl4030_write(codec, TWL4030_REG_HS_POPN_SET, popn);
963
964 /* power down */
965 twl4030_clear_codecpdz(codec);
966}
967
968static int twl4030_set_bias_level(struct snd_soc_codec *codec, 1188static int twl4030_set_bias_level(struct snd_soc_codec *codec,
969 enum snd_soc_bias_level level) 1189 enum snd_soc_bias_level level)
970{ 1190{
1191 struct twl4030_priv *twl4030 = codec->private_data;
1192
971 switch (level) { 1193 switch (level) {
972 case SND_SOC_BIAS_ON: 1194 case SND_SOC_BIAS_ON:
973 twl4030_power_up(codec); 1195 twl4030_codec_mute(codec, 0);
974 break; 1196 break;
975 case SND_SOC_BIAS_PREPARE: 1197 case SND_SOC_BIAS_PREPARE:
976 /* TODO: develop a twl4030_prepare function */ 1198 twl4030_power_up(codec);
1199 if (twl4030->bypass_state)
1200 twl4030_codec_mute(codec, 0);
1201 else
1202 twl4030_codec_mute(codec, 1);
977 break; 1203 break;
978 case SND_SOC_BIAS_STANDBY: 1204 case SND_SOC_BIAS_STANDBY:
979 /* TODO: develop a twl4030_standby function */ 1205 twl4030_power_up(codec);
980 twl4030_power_down(codec); 1206 if (twl4030->bypass_state)
1207 twl4030_codec_mute(codec, 0);
1208 else
1209 twl4030_codec_mute(codec, 1);
981 break; 1210 break;
982 case SND_SOC_BIAS_OFF: 1211 case SND_SOC_BIAS_OFF:
983 twl4030_power_down(codec); 1212 twl4030_power_down(codec);
@@ -994,10 +1223,9 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream,
994{ 1223{
995 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1224 struct snd_soc_pcm_runtime *rtd = substream->private_data;
996 struct snd_soc_device *socdev = rtd->socdev; 1225 struct snd_soc_device *socdev = rtd->socdev;
997 struct snd_soc_codec *codec = socdev->codec; 1226 struct snd_soc_codec *codec = socdev->card->codec;
998 u8 mode, old_mode, format, old_format; 1227 u8 mode, old_mode, format, old_format;
999 1228
1000
1001 /* bit rate */ 1229 /* bit rate */
1002 old_mode = twl4030_read_reg_cache(codec, 1230 old_mode = twl4030_read_reg_cache(codec,
1003 TWL4030_REG_CODEC_MODE) & ~TWL4030_CODECPDZ; 1231 TWL4030_REG_CODEC_MODE) & ~TWL4030_CODECPDZ;
@@ -1039,8 +1267,9 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream,
1039 1267
1040 if (mode != old_mode) { 1268 if (mode != old_mode) {
1041 /* change rate and set CODECPDZ */ 1269 /* change rate and set CODECPDZ */
1270 twl4030_codec_enable(codec, 0);
1042 twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode); 1271 twl4030_write(codec, TWL4030_REG_CODEC_MODE, mode);
1043 twl4030_set_codecpdz(codec); 1272 twl4030_codec_enable(codec, 1);
1044 } 1273 }
1045 1274
1046 /* sample size */ 1275 /* sample size */
@@ -1063,13 +1292,13 @@ static int twl4030_hw_params(struct snd_pcm_substream *substream,
1063 if (format != old_format) { 1292 if (format != old_format) {
1064 1293
1065 /* clear CODECPDZ before changing format (codec requirement) */ 1294 /* clear CODECPDZ before changing format (codec requirement) */
1066 twl4030_clear_codecpdz(codec); 1295 twl4030_codec_enable(codec, 0);
1067 1296
1068 /* change format */ 1297 /* change format */
1069 twl4030_write(codec, TWL4030_REG_AUDIO_IF, format); 1298 twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
1070 1299
1071 /* set CODECPDZ afterwards */ 1300 /* set CODECPDZ afterwards */
1072 twl4030_set_codecpdz(codec); 1301 twl4030_codec_enable(codec, 1);
1073 } 1302 }
1074 return 0; 1303 return 0;
1075} 1304}
@@ -1139,13 +1368,13 @@ static int twl4030_set_dai_fmt(struct snd_soc_dai *codec_dai,
1139 if (format != old_format) { 1368 if (format != old_format) {
1140 1369
1141 /* clear CODECPDZ before changing format (codec requirement) */ 1370 /* clear CODECPDZ before changing format (codec requirement) */
1142 twl4030_clear_codecpdz(codec); 1371 twl4030_codec_enable(codec, 0);
1143 1372
1144 /* change format */ 1373 /* change format */
1145 twl4030_write(codec, TWL4030_REG_AUDIO_IF, format); 1374 twl4030_write(codec, TWL4030_REG_AUDIO_IF, format);
1146 1375
1147 /* set CODECPDZ afterwards */ 1376 /* set CODECPDZ afterwards */
1148 twl4030_set_codecpdz(codec); 1377 twl4030_codec_enable(codec, 1);
1149 } 1378 }
1150 1379
1151 return 0; 1380 return 0;
@@ -1154,6 +1383,12 @@ static int twl4030_set_dai_fmt(struct snd_soc_dai *codec_dai,
1154#define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000) 1383#define TWL4030_RATES (SNDRV_PCM_RATE_8000_48000)
1155#define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_S24_LE) 1384#define TWL4030_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FORMAT_S24_LE)
1156 1385
1386static struct snd_soc_dai_ops twl4030_dai_ops = {
1387 .hw_params = twl4030_hw_params,
1388 .set_sysclk = twl4030_set_dai_sysclk,
1389 .set_fmt = twl4030_set_dai_fmt,
1390};
1391
1157struct snd_soc_dai twl4030_dai = { 1392struct snd_soc_dai twl4030_dai = {
1158 .name = "twl4030", 1393 .name = "twl4030",
1159 .playback = { 1394 .playback = {
@@ -1168,18 +1403,14 @@ struct snd_soc_dai twl4030_dai = {
1168 .channels_max = 2, 1403 .channels_max = 2,
1169 .rates = TWL4030_RATES, 1404 .rates = TWL4030_RATES,
1170 .formats = TWL4030_FORMATS,}, 1405 .formats = TWL4030_FORMATS,},
1171 .ops = { 1406 .ops = &twl4030_dai_ops,
1172 .hw_params = twl4030_hw_params,
1173 .set_sysclk = twl4030_set_dai_sysclk,
1174 .set_fmt = twl4030_set_dai_fmt,
1175 }
1176}; 1407};
1177EXPORT_SYMBOL_GPL(twl4030_dai); 1408EXPORT_SYMBOL_GPL(twl4030_dai);
1178 1409
1179static int twl4030_suspend(struct platform_device *pdev, pm_message_t state) 1410static int twl4030_suspend(struct platform_device *pdev, pm_message_t state)
1180{ 1411{
1181 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1412 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1182 struct snd_soc_codec *codec = socdev->codec; 1413 struct snd_soc_codec *codec = socdev->card->codec;
1183 1414
1184 twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF); 1415 twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
1185 1416
@@ -1189,7 +1420,7 @@ static int twl4030_suspend(struct platform_device *pdev, pm_message_t state)
1189static int twl4030_resume(struct platform_device *pdev) 1420static int twl4030_resume(struct platform_device *pdev)
1190{ 1421{
1191 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1422 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1192 struct snd_soc_codec *codec = socdev->codec; 1423 struct snd_soc_codec *codec = socdev->card->codec;
1193 1424
1194 twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1425 twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1195 twl4030_set_bias_level(codec, codec->suspend_bias_level); 1426 twl4030_set_bias_level(codec, codec->suspend_bias_level);
@@ -1203,7 +1434,7 @@ static int twl4030_resume(struct platform_device *pdev)
1203 1434
1204static int twl4030_init(struct snd_soc_device *socdev) 1435static int twl4030_init(struct snd_soc_device *socdev)
1205{ 1436{
1206 struct snd_soc_codec *codec = socdev->codec; 1437 struct snd_soc_codec *codec = socdev->card->codec;
1207 int ret = 0; 1438 int ret = 0;
1208 1439
1209 printk(KERN_INFO "TWL4030 Audio Codec init \n"); 1440 printk(KERN_INFO "TWL4030 Audio Codec init \n");
@@ -1233,7 +1464,8 @@ static int twl4030_init(struct snd_soc_device *socdev)
1233 /* power on device */ 1464 /* power on device */
1234 twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1465 twl4030_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1235 1466
1236 twl4030_add_controls(codec); 1467 snd_soc_add_controls(codec, twl4030_snd_controls,
1468 ARRAY_SIZE(twl4030_snd_controls));
1237 twl4030_add_widgets(codec); 1469 twl4030_add_widgets(codec);
1238 1470
1239 ret = snd_soc_init_card(socdev); 1471 ret = snd_soc_init_card(socdev);
@@ -1258,12 +1490,20 @@ static int twl4030_probe(struct platform_device *pdev)
1258{ 1490{
1259 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1491 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1260 struct snd_soc_codec *codec; 1492 struct snd_soc_codec *codec;
1493 struct twl4030_priv *twl4030;
1261 1494
1262 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 1495 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
1263 if (codec == NULL) 1496 if (codec == NULL)
1264 return -ENOMEM; 1497 return -ENOMEM;
1265 1498
1266 socdev->codec = codec; 1499 twl4030 = kzalloc(sizeof(struct twl4030_priv), GFP_KERNEL);
1500 if (twl4030 == NULL) {
1501 kfree(codec);
1502 return -ENOMEM;
1503 }
1504
1505 codec->private_data = twl4030;
1506 socdev->card->codec = codec;
1267 mutex_init(&codec->mutex); 1507 mutex_init(&codec->mutex);
1268 INIT_LIST_HEAD(&codec->dapm_widgets); 1508 INIT_LIST_HEAD(&codec->dapm_widgets);
1269 INIT_LIST_HEAD(&codec->dapm_paths); 1509 INIT_LIST_HEAD(&codec->dapm_paths);
@@ -1277,11 +1517,13 @@ static int twl4030_probe(struct platform_device *pdev)
1277static int twl4030_remove(struct platform_device *pdev) 1517static int twl4030_remove(struct platform_device *pdev)
1278{ 1518{
1279 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1519 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1280 struct snd_soc_codec *codec = socdev->codec; 1520 struct snd_soc_codec *codec = socdev->card->codec;
1281 1521
1282 printk(KERN_INFO "TWL4030 Audio Codec remove\n"); 1522 printk(KERN_INFO "TWL4030 Audio Codec remove\n");
1523 twl4030_set_bias_level(codec, SND_SOC_BIAS_OFF);
1283 snd_soc_free_pcms(socdev); 1524 snd_soc_free_pcms(socdev);
1284 snd_soc_dapm_free(socdev); 1525 snd_soc_dapm_free(socdev);
1526 kfree(codec->private_data);
1285 kfree(codec); 1527 kfree(codec);
1286 1528
1287 return 0; 1529 return 0;
diff --git a/sound/soc/codecs/twl4030.h b/sound/soc/codecs/twl4030.h
index 442e5a828617..33dbb144dad1 100644
--- a/sound/soc/codecs/twl4030.h
+++ b/sound/soc/codecs/twl4030.h
@@ -170,6 +170,9 @@
170#define TWL4030_CLK256FS_EN 0x02 170#define TWL4030_CLK256FS_EN 0x02
171#define TWL4030_AIF_EN 0x01 171#define TWL4030_AIF_EN 0x01
172 172
173/* EAR_CTL (0x21) */
174#define TWL4030_EAR_GAIN 0x30
175
173/* HS_GAIN_SET (0x23) Fields */ 176/* HS_GAIN_SET (0x23) Fields */
174 177
175#define TWL4030_HSR_GAIN 0x0C 178#define TWL4030_HSR_GAIN 0x0C
@@ -198,6 +201,18 @@
198#define TWL4030_RAMP_DELAY_2581MS 0x1C 201#define TWL4030_RAMP_DELAY_2581MS 0x1C
199#define TWL4030_RAMP_EN 0x02 202#define TWL4030_RAMP_EN 0x02
200 203
204/* PREDL_CTL (0x25) */
205#define TWL4030_PREDL_GAIN 0x30
206
207/* PREDR_CTL (0x26) */
208#define TWL4030_PREDR_GAIN 0x30
209
210/* PRECKL_CTL (0x27) */
211#define TWL4030_PRECKL_GAIN 0x30
212
213/* PRECKR_CTL (0x28) */
214#define TWL4030_PRECKR_GAIN 0x30
215
201/* HFL_CTL (0x29, 0x2A) Fields */ 216/* HFL_CTL (0x29, 0x2A) Fields */
202#define TWL4030_HF_CTL_HB_EN 0x04 217#define TWL4030_HF_CTL_HB_EN 0x04
203#define TWL4030_HF_CTL_LOOP_EN 0x08 218#define TWL4030_HF_CTL_LOOP_EN 0x08
diff --git a/sound/soc/codecs/uda134x.c b/sound/soc/codecs/uda134x.c
index a2c5064a774b..ddefb8f80145 100644
--- a/sound/soc/codecs/uda134x.c
+++ b/sound/soc/codecs/uda134x.c
@@ -173,7 +173,7 @@ static int uda134x_startup(struct snd_pcm_substream *substream,
173{ 173{
174 struct snd_soc_pcm_runtime *rtd = substream->private_data; 174 struct snd_soc_pcm_runtime *rtd = substream->private_data;
175 struct snd_soc_device *socdev = rtd->socdev; 175 struct snd_soc_device *socdev = rtd->socdev;
176 struct snd_soc_codec *codec = socdev->codec; 176 struct snd_soc_codec *codec = socdev->card->codec;
177 struct uda134x_priv *uda134x = codec->private_data; 177 struct uda134x_priv *uda134x = codec->private_data;
178 struct snd_pcm_runtime *master_runtime; 178 struct snd_pcm_runtime *master_runtime;
179 179
@@ -206,7 +206,7 @@ static void uda134x_shutdown(struct snd_pcm_substream *substream,
206{ 206{
207 struct snd_soc_pcm_runtime *rtd = substream->private_data; 207 struct snd_soc_pcm_runtime *rtd = substream->private_data;
208 struct snd_soc_device *socdev = rtd->socdev; 208 struct snd_soc_device *socdev = rtd->socdev;
209 struct snd_soc_codec *codec = socdev->codec; 209 struct snd_soc_codec *codec = socdev->card->codec;
210 struct uda134x_priv *uda134x = codec->private_data; 210 struct uda134x_priv *uda134x = codec->private_data;
211 211
212 if (uda134x->master_substream == substream) 212 if (uda134x->master_substream == substream)
@@ -221,7 +221,7 @@ static int uda134x_hw_params(struct snd_pcm_substream *substream,
221{ 221{
222 struct snd_soc_pcm_runtime *rtd = substream->private_data; 222 struct snd_soc_pcm_runtime *rtd = substream->private_data;
223 struct snd_soc_device *socdev = rtd->socdev; 223 struct snd_soc_device *socdev = rtd->socdev;
224 struct snd_soc_codec *codec = socdev->codec; 224 struct snd_soc_codec *codec = socdev->card->codec;
225 struct uda134x_priv *uda134x = codec->private_data; 225 struct uda134x_priv *uda134x = codec->private_data;
226 u8 hw_params; 226 u8 hw_params;
227 227
@@ -431,38 +431,14 @@ SOC_ENUM("PCM Playback De-emphasis", uda134x_mixer_enum[1]),
431SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0), 431SOC_SINGLE("DC Filter Enable Switch", UDA134X_STATUS0, 0, 1, 0),
432}; 432};
433 433
434static int uda134x_add_controls(struct snd_soc_codec *codec) 434static struct snd_soc_dai_ops uda134x_dai_ops = {
435{ 435 .startup = uda134x_startup,
436 int err, i, n; 436 .shutdown = uda134x_shutdown,
437 const struct snd_kcontrol_new *ctrls; 437 .hw_params = uda134x_hw_params,
438 struct uda134x_platform_data *pd = codec->control_data; 438 .digital_mute = uda134x_mute,
439 439 .set_sysclk = uda134x_set_dai_sysclk,
440 switch (pd->model) { 440 .set_fmt = uda134x_set_dai_fmt,
441 case UDA134X_UDA1340: 441};
442 case UDA134X_UDA1344:
443 n = ARRAY_SIZE(uda1340_snd_controls);
444 ctrls = uda1340_snd_controls;
445 break;
446 case UDA134X_UDA1341:
447 n = ARRAY_SIZE(uda1341_snd_controls);
448 ctrls = uda1341_snd_controls;
449 break;
450 default:
451 printk(KERN_ERR "%s unkown codec type: %d",
452 __func__, pd->model);
453 return -EINVAL;
454 }
455
456 for (i = 0; i < n; i++) {
457 err = snd_ctl_add(codec->card,
458 snd_soc_cnew(&ctrls[i],
459 codec, NULL));
460 if (err < 0)
461 return err;
462 }
463
464 return 0;
465}
466 442
467struct snd_soc_dai uda134x_dai = { 443struct snd_soc_dai uda134x_dai = {
468 .name = "UDA134X", 444 .name = "UDA134X",
@@ -483,14 +459,7 @@ struct snd_soc_dai uda134x_dai = {
483 .formats = UDA134X_FORMATS, 459 .formats = UDA134X_FORMATS,
484 }, 460 },
485 /* pcm operations */ 461 /* pcm operations */
486 .ops = { 462 .ops = &uda134x_dai_ops,
487 .startup = uda134x_startup,
488 .shutdown = uda134x_shutdown,
489 .hw_params = uda134x_hw_params,
490 .digital_mute = uda134x_mute,
491 .set_sysclk = uda134x_set_dai_sysclk,
492 .set_fmt = uda134x_set_dai_fmt,
493 }
494}; 463};
495EXPORT_SYMBOL(uda134x_dai); 464EXPORT_SYMBOL(uda134x_dai);
496 465
@@ -525,11 +494,11 @@ static int uda134x_soc_probe(struct platform_device *pdev)
525 return -EINVAL; 494 return -EINVAL;
526 } 495 }
527 496
528 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 497 socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
529 if (socdev->codec == NULL) 498 if (socdev->card->codec == NULL)
530 return ret; 499 return ret;
531 500
532 codec = socdev->codec; 501 codec = socdev->card->codec;
533 502
534 uda134x = kzalloc(sizeof(struct uda134x_priv), GFP_KERNEL); 503 uda134x = kzalloc(sizeof(struct uda134x_priv), GFP_KERNEL);
535 if (uda134x == NULL) 504 if (uda134x == NULL)
@@ -572,7 +541,22 @@ static int uda134x_soc_probe(struct platform_device *pdev)
572 goto pcm_err; 541 goto pcm_err;
573 } 542 }
574 543
575 ret = uda134x_add_controls(codec); 544 switch (pd->model) {
545 case UDA134X_UDA1340:
546 case UDA134X_UDA1344:
547 ret = snd_soc_add_controls(codec, uda1340_snd_controls,
548 ARRAY_SIZE(uda1340_snd_controls));
549 break;
550 case UDA134X_UDA1341:
551 ret = snd_soc_add_controls(codec, uda1341_snd_controls,
552 ARRAY_SIZE(uda1341_snd_controls));
553 break;
554 default:
555 printk(KERN_ERR "%s unkown codec type: %d",
556 __func__, pd->model);
557 return -EINVAL;
558 }
559
576 if (ret < 0) { 560 if (ret < 0) {
577 printk(KERN_ERR "UDA134X: failed to register controls\n"); 561 printk(KERN_ERR "UDA134X: failed to register controls\n");
578 goto pcm_err; 562 goto pcm_err;
@@ -602,7 +586,7 @@ priv_err:
602static int uda134x_soc_remove(struct platform_device *pdev) 586static int uda134x_soc_remove(struct platform_device *pdev)
603{ 587{
604 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 588 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
605 struct snd_soc_codec *codec = socdev->codec; 589 struct snd_soc_codec *codec = socdev->card->codec;
606 590
607 uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 591 uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
608 uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF); 592 uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF);
@@ -622,7 +606,7 @@ static int uda134x_soc_suspend(struct platform_device *pdev,
622 pm_message_t state) 606 pm_message_t state)
623{ 607{
624 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 608 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
625 struct snd_soc_codec *codec = socdev->codec; 609 struct snd_soc_codec *codec = socdev->card->codec;
626 610
627 uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 611 uda134x_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
628 uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF); 612 uda134x_set_bias_level(codec, SND_SOC_BIAS_OFF);
@@ -632,7 +616,7 @@ static int uda134x_soc_suspend(struct platform_device *pdev,
632static int uda134x_soc_resume(struct platform_device *pdev) 616static int uda134x_soc_resume(struct platform_device *pdev)
633{ 617{
634 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 618 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
635 struct snd_soc_codec *codec = socdev->codec; 619 struct snd_soc_codec *codec = socdev->card->codec;
636 620
637 uda134x_set_bias_level(codec, SND_SOC_BIAS_PREPARE); 621 uda134x_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
638 uda134x_set_bias_level(codec, SND_SOC_BIAS_ON); 622 uda134x_set_bias_level(codec, SND_SOC_BIAS_ON);
diff --git a/sound/soc/codecs/uda1380.c b/sound/soc/codecs/uda1380.c
index e6bf0844fbf3..5b21594e0e58 100644
--- a/sound/soc/codecs/uda1380.c
+++ b/sound/soc/codecs/uda1380.c
@@ -25,6 +25,7 @@
25#include <linux/ioctl.h> 25#include <linux/ioctl.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/workqueue.h>
28#include <sound/core.h> 29#include <sound/core.h>
29#include <sound/control.h> 30#include <sound/control.h>
30#include <sound/initval.h> 31#include <sound/initval.h>
@@ -35,7 +36,8 @@
35 36
36#include "uda1380.h" 37#include "uda1380.h"
37 38
38#define UDA1380_VERSION "0.6" 39static struct work_struct uda1380_work;
40static struct snd_soc_codec *uda1380_codec;
39 41
40/* 42/*
41 * uda1380 register cache 43 * uda1380 register cache
@@ -52,6 +54,8 @@ static const u16 uda1380_reg[UDA1380_CACHEREGNUM] = {
52 0x0000, 0x8000, 0x0002, 0x0000, 54 0x0000, 0x8000, 0x0002, 0x0000,
53}; 55};
54 56
57static unsigned long uda1380_cache_dirty;
58
55/* 59/*
56 * read uda1380 register cache 60 * read uda1380 register cache
57 */ 61 */
@@ -73,8 +77,11 @@ static inline void uda1380_write_reg_cache(struct snd_soc_codec *codec,
73 u16 reg, unsigned int value) 77 u16 reg, unsigned int value)
74{ 78{
75 u16 *cache = codec->reg_cache; 79 u16 *cache = codec->reg_cache;
80
76 if (reg >= UDA1380_CACHEREGNUM) 81 if (reg >= UDA1380_CACHEREGNUM)
77 return; 82 return;
83 if ((reg >= 0x10) && (cache[reg] != value))
84 set_bit(reg - 0x10, &uda1380_cache_dirty);
78 cache[reg] = value; 85 cache[reg] = value;
79} 86}
80 87
@@ -113,6 +120,8 @@ static int uda1380_write(struct snd_soc_codec *codec, unsigned int reg,
113 (data[0]<<8) | data[1]); 120 (data[0]<<8) | data[1]);
114 return -EIO; 121 return -EIO;
115 } 122 }
123 if (reg >= 0x10)
124 clear_bit(reg - 0x10, &uda1380_cache_dirty);
116 return 0; 125 return 0;
117 } else 126 } else
118 return -EIO; 127 return -EIO;
@@ -120,6 +129,20 @@ static int uda1380_write(struct snd_soc_codec *codec, unsigned int reg,
120 129
121#define uda1380_reset(c) uda1380_write(c, UDA1380_RESET, 0) 130#define uda1380_reset(c) uda1380_write(c, UDA1380_RESET, 0)
122 131
132static void uda1380_flush_work(struct work_struct *work)
133{
134 int bit, reg;
135
136 for_each_bit(bit, &uda1380_cache_dirty, UDA1380_CACHEREGNUM - 0x10) {
137 reg = 0x10 + bit;
138 pr_debug("uda1380: flush reg %x val %x:\n", reg,
139 uda1380_read_reg_cache(uda1380_codec, reg));
140 uda1380_write(uda1380_codec, reg,
141 uda1380_read_reg_cache(uda1380_codec, reg));
142 clear_bit(bit, &uda1380_cache_dirty);
143 }
144}
145
123/* declarations of ALSA reg_elem_REAL controls */ 146/* declarations of ALSA reg_elem_REAL controls */
124static const char *uda1380_deemp[] = { 147static const char *uda1380_deemp[] = {
125 "None", 148 "None",
@@ -254,7 +277,6 @@ static const struct snd_kcontrol_new uda1380_snd_controls[] = {
254 SOC_SINGLE("DAC Polarity inverting Switch", UDA1380_MIXER, 15, 1, 0), /* DA_POL_INV */ 277 SOC_SINGLE("DAC Polarity inverting Switch", UDA1380_MIXER, 15, 1, 0), /* DA_POL_INV */
255 SOC_ENUM("Noise Shaper", uda1380_sel_ns_enum), /* SEL_NS */ 278 SOC_ENUM("Noise Shaper", uda1380_sel_ns_enum), /* SEL_NS */
256 SOC_ENUM("Digital Mixer Signal Control", uda1380_mix_enum), /* MIX_POS, MIX */ 279 SOC_ENUM("Digital Mixer Signal Control", uda1380_mix_enum), /* MIX_POS, MIX */
257 SOC_SINGLE("Silence Switch", UDA1380_MIXER, 7, 1, 0), /* SILENCE, force DAC output to silence */
258 SOC_SINGLE("Silence Detector Switch", UDA1380_MIXER, 6, 1, 0), /* SDET_ON */ 280 SOC_SINGLE("Silence Detector Switch", UDA1380_MIXER, 6, 1, 0), /* SDET_ON */
259 SOC_ENUM("Silence Detector Setting", uda1380_sdet_enum), /* SD_VALUE */ 281 SOC_ENUM("Silence Detector Setting", uda1380_sdet_enum), /* SD_VALUE */
260 SOC_ENUM("Oversampling Input", uda1380_os_enum), /* OS */ 282 SOC_ENUM("Oversampling Input", uda1380_os_enum), /* OS */
@@ -271,21 +293,6 @@ static const struct snd_kcontrol_new uda1380_snd_controls[] = {
271 SOC_SINGLE("AGC Switch", UDA1380_AGC, 0, 1, 0), 293 SOC_SINGLE("AGC Switch", UDA1380_AGC, 0, 1, 0),
272}; 294};
273 295
274/* add non dapm controls */
275static int uda1380_add_controls(struct snd_soc_codec *codec)
276{
277 int err, i;
278
279 for (i = 0; i < ARRAY_SIZE(uda1380_snd_controls); i++) {
280 err = snd_ctl_add(codec->card,
281 snd_soc_cnew(&uda1380_snd_controls[i], codec, NULL));
282 if (err < 0)
283 return err;
284 }
285
286 return 0;
287}
288
289/* Input mux */ 296/* Input mux */
290static const struct snd_kcontrol_new uda1380_input_mux_control = 297static const struct snd_kcontrol_new uda1380_input_mux_control =
291 SOC_DAPM_ENUM("Route", uda1380_input_sel_enum); 298 SOC_DAPM_ENUM("Route", uda1380_input_sel_enum);
@@ -371,7 +378,7 @@ static int uda1380_add_widgets(struct snd_soc_codec *codec)
371 return 0; 378 return 0;
372} 379}
373 380
374static int uda1380_set_dai_fmt(struct snd_soc_dai *codec_dai, 381static int uda1380_set_dai_fmt_both(struct snd_soc_dai *codec_dai,
375 unsigned int fmt) 382 unsigned int fmt)
376{ 383{
377 struct snd_soc_codec *codec = codec_dai->codec; 384 struct snd_soc_codec *codec = codec_dai->codec;
@@ -381,61 +388,107 @@ static int uda1380_set_dai_fmt(struct snd_soc_dai *codec_dai,
381 iface = uda1380_read_reg_cache(codec, UDA1380_IFACE); 388 iface = uda1380_read_reg_cache(codec, UDA1380_IFACE);
382 iface &= ~(R01_SFORI_MASK | R01_SIM | R01_SFORO_MASK); 389 iface &= ~(R01_SFORI_MASK | R01_SIM | R01_SFORO_MASK);
383 390
384 /* FIXME: how to select I2S for DATAO and MSB for DATAI correctly? */
385 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 391 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
386 case SND_SOC_DAIFMT_I2S: 392 case SND_SOC_DAIFMT_I2S:
387 iface |= R01_SFORI_I2S | R01_SFORO_I2S; 393 iface |= R01_SFORI_I2S | R01_SFORO_I2S;
388 break; 394 break;
389 case SND_SOC_DAIFMT_LSB: 395 case SND_SOC_DAIFMT_LSB:
390 iface |= R01_SFORI_LSB16 | R01_SFORO_I2S; 396 iface |= R01_SFORI_LSB16 | R01_SFORO_LSB16;
391 break; 397 break;
392 case SND_SOC_DAIFMT_MSB: 398 case SND_SOC_DAIFMT_MSB:
393 iface |= R01_SFORI_MSB | R01_SFORO_I2S; 399 iface |= R01_SFORI_MSB | R01_SFORO_MSB;
394 } 400 }
395 401
396 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBM_CFM) 402 /* DATAI is slave only, so in single-link mode, this has to be slave */
397 iface |= R01_SIM; 403 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS)
404 return -EINVAL;
398 405
399 uda1380_write(codec, UDA1380_IFACE, iface); 406 uda1380_write(codec, UDA1380_IFACE, iface);
400 407
401 return 0; 408 return 0;
402} 409}
403 410
404/* 411static int uda1380_set_dai_fmt_playback(struct snd_soc_dai *codec_dai,
405 * Flush reg cache 412 unsigned int fmt)
406 * We can only write the interpolator and decimator registers
407 * when the DAI is being clocked by the CPU DAI. It's up to the
408 * machine and cpu DAI driver to do this before we are called.
409 */
410static int uda1380_pcm_prepare(struct snd_pcm_substream *substream,
411 struct snd_soc_dai *dai)
412{ 413{
413 struct snd_soc_pcm_runtime *rtd = substream->private_data; 414 struct snd_soc_codec *codec = codec_dai->codec;
414 struct snd_soc_device *socdev = rtd->socdev; 415 int iface;
415 struct snd_soc_codec *codec = socdev->codec; 416
416 int reg, reg_start, reg_end, clk; 417 /* set up DAI based upon fmt */
417 418 iface = uda1380_read_reg_cache(codec, UDA1380_IFACE);
418 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 419 iface &= ~R01_SFORI_MASK;
419 reg_start = UDA1380_MVOL; 420
420 reg_end = UDA1380_MIXER; 421 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
421 } else { 422 case SND_SOC_DAIFMT_I2S:
422 reg_start = UDA1380_DEC; 423 iface |= R01_SFORI_I2S;
423 reg_end = UDA1380_AGC; 424 break;
425 case SND_SOC_DAIFMT_LSB:
426 iface |= R01_SFORI_LSB16;
427 break;
428 case SND_SOC_DAIFMT_MSB:
429 iface |= R01_SFORI_MSB;
424 } 430 }
425 431
426 /* FIXME disable DAC_CLK */ 432 /* DATAI is slave only, so this has to be slave */
427 clk = uda1380_read_reg_cache(codec, UDA1380_CLK); 433 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBS_CFS)
428 uda1380_write(codec, UDA1380_CLK, clk & ~R00_DAC_CLK); 434 return -EINVAL;
435
436 uda1380_write(codec, UDA1380_IFACE, iface);
437
438 return 0;
439}
440
441static int uda1380_set_dai_fmt_capture(struct snd_soc_dai *codec_dai,
442 unsigned int fmt)
443{
444 struct snd_soc_codec *codec = codec_dai->codec;
445 int iface;
446
447 /* set up DAI based upon fmt */
448 iface = uda1380_read_reg_cache(codec, UDA1380_IFACE);
449 iface &= ~(R01_SIM | R01_SFORO_MASK);
429 450
430 for (reg = reg_start; reg <= reg_end; reg++) { 451 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
431 pr_debug("uda1380: flush reg %x val %x:", reg, 452 case SND_SOC_DAIFMT_I2S:
432 uda1380_read_reg_cache(codec, reg)); 453 iface |= R01_SFORO_I2S;
433 uda1380_write(codec, reg, uda1380_read_reg_cache(codec, reg)); 454 break;
455 case SND_SOC_DAIFMT_LSB:
456 iface |= R01_SFORO_LSB16;
457 break;
458 case SND_SOC_DAIFMT_MSB:
459 iface |= R01_SFORO_MSB;
434 } 460 }
435 461
436 /* FIXME enable DAC_CLK */ 462 if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBM_CFM)
437 uda1380_write(codec, UDA1380_CLK, clk | R00_DAC_CLK); 463 iface |= R01_SIM;
438 464
465 uda1380_write(codec, UDA1380_IFACE, iface);
466
467 return 0;
468}
469
470static int uda1380_trigger(struct snd_pcm_substream *substream, int cmd,
471 struct snd_soc_dai *dai)
472{
473 struct snd_soc_pcm_runtime *rtd = substream->private_data;
474 struct snd_soc_device *socdev = rtd->socdev;
475 struct snd_soc_codec *codec = socdev->card->codec;
476 int mixer = uda1380_read_reg_cache(codec, UDA1380_MIXER);
477
478 switch (cmd) {
479 case SNDRV_PCM_TRIGGER_START:
480 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
481 uda1380_write_reg_cache(codec, UDA1380_MIXER,
482 mixer & ~R14_SILENCE);
483 schedule_work(&uda1380_work);
484 break;
485 case SNDRV_PCM_TRIGGER_STOP:
486 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
487 uda1380_write_reg_cache(codec, UDA1380_MIXER,
488 mixer | R14_SILENCE);
489 schedule_work(&uda1380_work);
490 break;
491 }
439 return 0; 492 return 0;
440} 493}
441 494
@@ -445,7 +498,7 @@ static int uda1380_pcm_hw_params(struct snd_pcm_substream *substream,
445{ 498{
446 struct snd_soc_pcm_runtime *rtd = substream->private_data; 499 struct snd_soc_pcm_runtime *rtd = substream->private_data;
447 struct snd_soc_device *socdev = rtd->socdev; 500 struct snd_soc_device *socdev = rtd->socdev;
448 struct snd_soc_codec *codec = socdev->codec; 501 struct snd_soc_codec *codec = socdev->card->codec;
449 u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK); 502 u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK);
450 503
451 /* set WSPLL power and divider if running from this clock */ 504 /* set WSPLL power and divider if running from this clock */
@@ -484,7 +537,7 @@ static void uda1380_pcm_shutdown(struct snd_pcm_substream *substream,
484{ 537{
485 struct snd_soc_pcm_runtime *rtd = substream->private_data; 538 struct snd_soc_pcm_runtime *rtd = substream->private_data;
486 struct snd_soc_device *socdev = rtd->socdev; 539 struct snd_soc_device *socdev = rtd->socdev;
487 struct snd_soc_codec *codec = socdev->codec; 540 struct snd_soc_codec *codec = socdev->card->codec;
488 u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK); 541 u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK);
489 542
490 /* shut down WSPLL power if running from this clock */ 543 /* shut down WSPLL power if running from this clock */
@@ -501,24 +554,6 @@ static void uda1380_pcm_shutdown(struct snd_pcm_substream *substream,
501 uda1380_write(codec, UDA1380_CLK, clk); 554 uda1380_write(codec, UDA1380_CLK, clk);
502} 555}
503 556
504static int uda1380_mute(struct snd_soc_dai *codec_dai, int mute)
505{
506 struct snd_soc_codec *codec = codec_dai->codec;
507 u16 mute_reg = uda1380_read_reg_cache(codec, UDA1380_DEEMP) & ~R13_MTM;
508
509 /* FIXME: mute(codec,0) is called when the magician clock is already
510 * set to WSPLL, but for some unknown reason writing to interpolator
511 * registers works only when clocked by SYSCLK */
512 u16 clk = uda1380_read_reg_cache(codec, UDA1380_CLK);
513 uda1380_write(codec, UDA1380_CLK, ~R00_DAC_CLK & clk);
514 if (mute)
515 uda1380_write(codec, UDA1380_DEEMP, mute_reg | R13_MTM);
516 else
517 uda1380_write(codec, UDA1380_DEEMP, mute_reg);
518 uda1380_write(codec, UDA1380_CLK, clk);
519 return 0;
520}
521
522static int uda1380_set_bias_level(struct snd_soc_codec *codec, 557static int uda1380_set_bias_level(struct snd_soc_codec *codec,
523 enum snd_soc_bias_level level) 558 enum snd_soc_bias_level level)
524{ 559{
@@ -544,6 +579,27 @@ static int uda1380_set_bias_level(struct snd_soc_codec *codec,
544 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\ 579 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 |\
545 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) 580 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
546 581
582static struct snd_soc_dai_ops uda1380_dai_ops = {
583 .hw_params = uda1380_pcm_hw_params,
584 .shutdown = uda1380_pcm_shutdown,
585 .trigger = uda1380_trigger,
586 .set_fmt = uda1380_set_dai_fmt_both,
587};
588
589static struct snd_soc_dai_ops uda1380_dai_ops_playback = {
590 .hw_params = uda1380_pcm_hw_params,
591 .shutdown = uda1380_pcm_shutdown,
592 .trigger = uda1380_trigger,
593 .set_fmt = uda1380_set_dai_fmt_playback,
594};
595
596static struct snd_soc_dai_ops uda1380_dai_ops_capture = {
597 .hw_params = uda1380_pcm_hw_params,
598 .shutdown = uda1380_pcm_shutdown,
599 .trigger = uda1380_trigger,
600 .set_fmt = uda1380_set_dai_fmt_capture,
601};
602
547struct snd_soc_dai uda1380_dai[] = { 603struct snd_soc_dai uda1380_dai[] = {
548{ 604{
549 .name = "UDA1380", 605 .name = "UDA1380",
@@ -559,13 +615,7 @@ struct snd_soc_dai uda1380_dai[] = {
559 .channels_max = 2, 615 .channels_max = 2,
560 .rates = UDA1380_RATES, 616 .rates = UDA1380_RATES,
561 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 617 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
562 .ops = { 618 .ops = &uda1380_dai_ops,
563 .hw_params = uda1380_pcm_hw_params,
564 .shutdown = uda1380_pcm_shutdown,
565 .prepare = uda1380_pcm_prepare,
566 .digital_mute = uda1380_mute,
567 .set_fmt = uda1380_set_dai_fmt,
568 },
569}, 619},
570{ /* playback only - dual interface */ 620{ /* playback only - dual interface */
571 .name = "UDA1380", 621 .name = "UDA1380",
@@ -576,13 +626,7 @@ struct snd_soc_dai uda1380_dai[] = {
576 .rates = UDA1380_RATES, 626 .rates = UDA1380_RATES,
577 .formats = SNDRV_PCM_FMTBIT_S16_LE, 627 .formats = SNDRV_PCM_FMTBIT_S16_LE,
578 }, 628 },
579 .ops = { 629 .ops = &uda1380_dai_ops_playback,
580 .hw_params = uda1380_pcm_hw_params,
581 .shutdown = uda1380_pcm_shutdown,
582 .prepare = uda1380_pcm_prepare,
583 .digital_mute = uda1380_mute,
584 .set_fmt = uda1380_set_dai_fmt,
585 },
586}, 630},
587{ /* capture only - dual interface*/ 631{ /* capture only - dual interface*/
588 .name = "UDA1380", 632 .name = "UDA1380",
@@ -593,12 +637,7 @@ struct snd_soc_dai uda1380_dai[] = {
593 .rates = UDA1380_RATES, 637 .rates = UDA1380_RATES,
594 .formats = SNDRV_PCM_FMTBIT_S16_LE, 638 .formats = SNDRV_PCM_FMTBIT_S16_LE,
595 }, 639 },
596 .ops = { 640 .ops = &uda1380_dai_ops_capture,
597 .hw_params = uda1380_pcm_hw_params,
598 .shutdown = uda1380_pcm_shutdown,
599 .prepare = uda1380_pcm_prepare,
600 .set_fmt = uda1380_set_dai_fmt,
601 },
602}, 641},
603}; 642};
604EXPORT_SYMBOL_GPL(uda1380_dai); 643EXPORT_SYMBOL_GPL(uda1380_dai);
@@ -606,7 +645,7 @@ EXPORT_SYMBOL_GPL(uda1380_dai);
606static int uda1380_suspend(struct platform_device *pdev, pm_message_t state) 645static int uda1380_suspend(struct platform_device *pdev, pm_message_t state)
607{ 646{
608 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 647 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
609 struct snd_soc_codec *codec = socdev->codec; 648 struct snd_soc_codec *codec = socdev->card->codec;
610 649
611 uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF); 650 uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF);
612 return 0; 651 return 0;
@@ -615,7 +654,7 @@ static int uda1380_suspend(struct platform_device *pdev, pm_message_t state)
615static int uda1380_resume(struct platform_device *pdev) 654static int uda1380_resume(struct platform_device *pdev)
616{ 655{
617 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 656 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
618 struct snd_soc_codec *codec = socdev->codec; 657 struct snd_soc_codec *codec = socdev->card->codec;
619 int i; 658 int i;
620 u8 data[2]; 659 u8 data[2];
621 u16 *cache = codec->reg_cache; 660 u16 *cache = codec->reg_cache;
@@ -637,7 +676,7 @@ static int uda1380_resume(struct platform_device *pdev)
637 */ 676 */
638static int uda1380_init(struct snd_soc_device *socdev, int dac_clk) 677static int uda1380_init(struct snd_soc_device *socdev, int dac_clk)
639{ 678{
640 struct snd_soc_codec *codec = socdev->codec; 679 struct snd_soc_codec *codec = socdev->card->codec;
641 int ret = 0; 680 int ret = 0;
642 681
643 codec->name = "UDA1380"; 682 codec->name = "UDA1380";
@@ -655,6 +694,9 @@ static int uda1380_init(struct snd_soc_device *socdev, int dac_clk)
655 codec->reg_cache_step = 1; 694 codec->reg_cache_step = 1;
656 uda1380_reset(codec); 695 uda1380_reset(codec);
657 696
697 uda1380_codec = codec;
698 INIT_WORK(&uda1380_work, uda1380_flush_work);
699
658 /* register pcms */ 700 /* register pcms */
659 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 701 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
660 if (ret < 0) { 702 if (ret < 0) {
@@ -675,7 +717,8 @@ static int uda1380_init(struct snd_soc_device *socdev, int dac_clk)
675 } 717 }
676 718
677 /* uda1380 init */ 719 /* uda1380 init */
678 uda1380_add_controls(codec); 720 snd_soc_add_controls(codec, uda1380_snd_controls,
721 ARRAY_SIZE(uda1380_snd_controls));
679 uda1380_add_widgets(codec); 722 uda1380_add_widgets(codec);
680 ret = snd_soc_init_card(socdev); 723 ret = snd_soc_init_card(socdev);
681 if (ret < 0) { 724 if (ret < 0) {
@@ -702,7 +745,7 @@ static int uda1380_i2c_probe(struct i2c_client *i2c,
702{ 745{
703 struct snd_soc_device *socdev = uda1380_socdev; 746 struct snd_soc_device *socdev = uda1380_socdev;
704 struct uda1380_setup_data *setup = socdev->codec_data; 747 struct uda1380_setup_data *setup = socdev->codec_data;
705 struct snd_soc_codec *codec = socdev->codec; 748 struct snd_soc_codec *codec = socdev->card->codec;
706 int ret; 749 int ret;
707 750
708 i2c_set_clientdata(i2c, codec); 751 i2c_set_clientdata(i2c, codec);
@@ -786,14 +829,12 @@ static int uda1380_probe(struct platform_device *pdev)
786 struct snd_soc_codec *codec; 829 struct snd_soc_codec *codec;
787 int ret; 830 int ret;
788 831
789 pr_info("UDA1380 Audio Codec %s", UDA1380_VERSION);
790
791 setup = socdev->codec_data; 832 setup = socdev->codec_data;
792 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 833 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
793 if (codec == NULL) 834 if (codec == NULL)
794 return -ENOMEM; 835 return -ENOMEM;
795 836
796 socdev->codec = codec; 837 socdev->card->codec = codec;
797 mutex_init(&codec->mutex); 838 mutex_init(&codec->mutex);
798 INIT_LIST_HEAD(&codec->dapm_widgets); 839 INIT_LIST_HEAD(&codec->dapm_widgets);
799 INIT_LIST_HEAD(&codec->dapm_paths); 840 INIT_LIST_HEAD(&codec->dapm_paths);
@@ -817,7 +858,7 @@ static int uda1380_probe(struct platform_device *pdev)
817static int uda1380_remove(struct platform_device *pdev) 858static int uda1380_remove(struct platform_device *pdev)
818{ 859{
819 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 860 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
820 struct snd_soc_codec *codec = socdev->codec; 861 struct snd_soc_codec *codec = socdev->card->codec;
821 862
822 if (codec->control_data) 863 if (codec->control_data)
823 uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF); 864 uda1380_set_bias_level(codec, SND_SOC_BIAS_OFF);
diff --git a/sound/soc/codecs/wm8350.c b/sound/soc/codecs/wm8350.c
index 35d99750c383..3b1d0993bed9 100644
--- a/sound/soc/codecs/wm8350.c
+++ b/sound/soc/codecs/wm8350.c
@@ -51,10 +51,17 @@ struct wm8350_output {
51 u16 mute; 51 u16 mute;
52}; 52};
53 53
54struct wm8350_jack_data {
55 struct snd_soc_jack *jack;
56 int report;
57};
58
54struct wm8350_data { 59struct wm8350_data {
55 struct snd_soc_codec codec; 60 struct snd_soc_codec codec;
56 struct wm8350_output out1; 61 struct wm8350_output out1;
57 struct wm8350_output out2; 62 struct wm8350_output out2;
63 struct wm8350_jack_data hpl;
64 struct wm8350_jack_data hpr;
58 struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)]; 65 struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
59}; 66};
60 67
@@ -775,21 +782,6 @@ static const struct snd_soc_dapm_route audio_map[] = {
775 {"Beep", NULL, "IN3R PGA"}, 782 {"Beep", NULL, "IN3R PGA"},
776}; 783};
777 784
778static int wm8350_add_controls(struct snd_soc_codec *codec)
779{
780 int err, i;
781
782 for (i = 0; i < ARRAY_SIZE(wm8350_snd_controls); i++) {
783 err = snd_ctl_add(codec->card,
784 snd_soc_cnew(&wm8350_snd_controls[i],
785 codec, NULL));
786 if (err < 0)
787 return err;
788 }
789
790 return 0;
791}
792
793static int wm8350_add_widgets(struct snd_soc_codec *codec) 785static int wm8350_add_widgets(struct snd_soc_codec *codec)
794{ 786{
795 int ret; 787 int ret;
@@ -1309,7 +1301,7 @@ static int wm8350_set_bias_level(struct snd_soc_codec *codec,
1309static int wm8350_suspend(struct platform_device *pdev, pm_message_t state) 1301static int wm8350_suspend(struct platform_device *pdev, pm_message_t state)
1310{ 1302{
1311 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1303 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1312 struct snd_soc_codec *codec = socdev->codec; 1304 struct snd_soc_codec *codec = socdev->card->codec;
1313 1305
1314 wm8350_set_bias_level(codec, SND_SOC_BIAS_OFF); 1306 wm8350_set_bias_level(codec, SND_SOC_BIAS_OFF);
1315 return 0; 1307 return 0;
@@ -1318,7 +1310,7 @@ static int wm8350_suspend(struct platform_device *pdev, pm_message_t state)
1318static int wm8350_resume(struct platform_device *pdev) 1310static int wm8350_resume(struct platform_device *pdev)
1319{ 1311{
1320 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1312 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1321 struct snd_soc_codec *codec = socdev->codec; 1313 struct snd_soc_codec *codec = socdev->card->codec;
1322 1314
1323 wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1315 wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1324 1316
@@ -1328,6 +1320,95 @@ static int wm8350_resume(struct platform_device *pdev)
1328 return 0; 1320 return 0;
1329} 1321}
1330 1322
1323static void wm8350_hp_jack_handler(struct wm8350 *wm8350, int irq, void *data)
1324{
1325 struct wm8350_data *priv = data;
1326 u16 reg;
1327 int report;
1328 int mask;
1329 struct wm8350_jack_data *jack = NULL;
1330
1331 switch (irq) {
1332 case WM8350_IRQ_CODEC_JCK_DET_L:
1333 jack = &priv->hpl;
1334 mask = WM8350_JACK_L_LVL;
1335 break;
1336
1337 case WM8350_IRQ_CODEC_JCK_DET_R:
1338 jack = &priv->hpr;
1339 mask = WM8350_JACK_R_LVL;
1340 break;
1341
1342 default:
1343 BUG();
1344 }
1345
1346 if (!jack->jack) {
1347 dev_warn(wm8350->dev, "Jack interrupt called with no jack\n");
1348 return;
1349 }
1350
1351 /* Debounce */
1352 msleep(200);
1353
1354 reg = wm8350_reg_read(wm8350, WM8350_JACK_PIN_STATUS);
1355 if (reg & mask)
1356 report = jack->report;
1357 else
1358 report = 0;
1359
1360 snd_soc_jack_report(jack->jack, report, jack->report);
1361}
1362
1363/**
1364 * wm8350_hp_jack_detect - Enable headphone jack detection.
1365 *
1366 * @codec: WM8350 codec
1367 * @which: left or right jack detect signal
1368 * @jack: jack to report detection events on
1369 * @report: value to report
1370 *
1371 * Enables the headphone jack detection of the WM8350.
1372 */
1373int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which,
1374 struct snd_soc_jack *jack, int report)
1375{
1376 struct wm8350_data *priv = codec->private_data;
1377 struct wm8350 *wm8350 = codec->control_data;
1378 int irq;
1379 int ena;
1380
1381 switch (which) {
1382 case WM8350_JDL:
1383 priv->hpl.jack = jack;
1384 priv->hpl.report = report;
1385 irq = WM8350_IRQ_CODEC_JCK_DET_L;
1386 ena = WM8350_JDL_ENA;
1387 break;
1388
1389 case WM8350_JDR:
1390 priv->hpr.jack = jack;
1391 priv->hpr.report = report;
1392 irq = WM8350_IRQ_CODEC_JCK_DET_R;
1393 ena = WM8350_JDR_ENA;
1394 break;
1395
1396 default:
1397 return -EINVAL;
1398 }
1399
1400 wm8350_set_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA);
1401 wm8350_set_bits(wm8350, WM8350_JACK_DETECT, ena);
1402
1403 /* Sync status */
1404 wm8350_hp_jack_handler(wm8350, irq, priv);
1405
1406 wm8350_unmask_irq(wm8350, irq);
1407
1408 return 0;
1409}
1410EXPORT_SYMBOL_GPL(wm8350_hp_jack_detect);
1411
1331static struct snd_soc_codec *wm8350_codec; 1412static struct snd_soc_codec *wm8350_codec;
1332 1413
1333static int wm8350_probe(struct platform_device *pdev) 1414static int wm8350_probe(struct platform_device *pdev)
@@ -1342,8 +1423,8 @@ static int wm8350_probe(struct platform_device *pdev)
1342 1423
1343 BUG_ON(!wm8350_codec); 1424 BUG_ON(!wm8350_codec);
1344 1425
1345 socdev->codec = wm8350_codec; 1426 socdev->card->codec = wm8350_codec;
1346 codec = socdev->codec; 1427 codec = socdev->card->codec;
1347 wm8350 = codec->control_data; 1428 wm8350 = codec->control_data;
1348 priv = codec->private_data; 1429 priv = codec->private_data;
1349 1430
@@ -1381,13 +1462,21 @@ static int wm8350_probe(struct platform_device *pdev)
1381 wm8350_set_bits(wm8350, WM8350_ROUT2_VOLUME, 1462 wm8350_set_bits(wm8350, WM8350_ROUT2_VOLUME,
1382 WM8350_OUT2_VU | WM8350_OUT2R_MUTE); 1463 WM8350_OUT2_VU | WM8350_OUT2R_MUTE);
1383 1464
1465 wm8350_mask_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L);
1466 wm8350_mask_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R);
1467 wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L,
1468 wm8350_hp_jack_handler, priv);
1469 wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R,
1470 wm8350_hp_jack_handler, priv);
1471
1384 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 1472 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
1385 if (ret < 0) { 1473 if (ret < 0) {
1386 dev_err(&pdev->dev, "failed to create pcms\n"); 1474 dev_err(&pdev->dev, "failed to create pcms\n");
1387 return ret; 1475 return ret;
1388 } 1476 }
1389 1477
1390 wm8350_add_controls(codec); 1478 snd_soc_add_controls(codec, wm8350_snd_controls,
1479 ARRAY_SIZE(wm8350_snd_controls));
1391 wm8350_add_widgets(codec); 1480 wm8350_add_widgets(codec);
1392 1481
1393 wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1482 wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
@@ -1409,10 +1498,23 @@ card_err:
1409static int wm8350_remove(struct platform_device *pdev) 1498static int wm8350_remove(struct platform_device *pdev)
1410{ 1499{
1411 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1500 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1412 struct snd_soc_codec *codec = socdev->codec; 1501 struct snd_soc_codec *codec = socdev->card->codec;
1413 struct wm8350 *wm8350 = codec->control_data; 1502 struct wm8350 *wm8350 = codec->control_data;
1503 struct wm8350_data *priv = codec->private_data;
1414 int ret; 1504 int ret;
1415 1505
1506 wm8350_clear_bits(wm8350, WM8350_JACK_DETECT,
1507 WM8350_JDL_ENA | WM8350_JDR_ENA);
1508 wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA);
1509
1510 wm8350_mask_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L);
1511 wm8350_mask_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R);
1512 wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L);
1513 wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R);
1514
1515 priv->hpl.jack = NULL;
1516 priv->hpr.jack = NULL;
1517
1416 /* cancel any work waiting to be queued. */ 1518 /* cancel any work waiting to be queued. */
1417 ret = cancel_delayed_work(&codec->delayed_work); 1519 ret = cancel_delayed_work(&codec->delayed_work);
1418 1520
@@ -1436,6 +1538,16 @@ static int wm8350_remove(struct platform_device *pdev)
1436 SNDRV_PCM_FMTBIT_S20_3LE |\ 1538 SNDRV_PCM_FMTBIT_S20_3LE |\
1437 SNDRV_PCM_FMTBIT_S24_LE) 1539 SNDRV_PCM_FMTBIT_S24_LE)
1438 1540
1541static struct snd_soc_dai_ops wm8350_dai_ops = {
1542 .hw_params = wm8350_pcm_hw_params,
1543 .digital_mute = wm8350_mute,
1544 .trigger = wm8350_pcm_trigger,
1545 .set_fmt = wm8350_set_dai_fmt,
1546 .set_sysclk = wm8350_set_dai_sysclk,
1547 .set_pll = wm8350_set_fll,
1548 .set_clkdiv = wm8350_set_clkdiv,
1549};
1550
1439struct snd_soc_dai wm8350_dai = { 1551struct snd_soc_dai wm8350_dai = {
1440 .name = "WM8350", 1552 .name = "WM8350",
1441 .playback = { 1553 .playback = {
@@ -1452,15 +1564,7 @@ struct snd_soc_dai wm8350_dai = {
1452 .rates = WM8350_RATES, 1564 .rates = WM8350_RATES,
1453 .formats = WM8350_FORMATS, 1565 .formats = WM8350_FORMATS,
1454 }, 1566 },
1455 .ops = { 1567 .ops = &wm8350_dai_ops,
1456 .hw_params = wm8350_pcm_hw_params,
1457 .digital_mute = wm8350_mute,
1458 .trigger = wm8350_pcm_trigger,
1459 .set_fmt = wm8350_set_dai_fmt,
1460 .set_sysclk = wm8350_set_dai_sysclk,
1461 .set_pll = wm8350_set_fll,
1462 .set_clkdiv = wm8350_set_clkdiv,
1463 },
1464}; 1568};
1465EXPORT_SYMBOL_GPL(wm8350_dai); 1569EXPORT_SYMBOL_GPL(wm8350_dai);
1466 1570
@@ -1472,7 +1576,7 @@ struct snd_soc_codec_device soc_codec_dev_wm8350 = {
1472}; 1576};
1473EXPORT_SYMBOL_GPL(soc_codec_dev_wm8350); 1577EXPORT_SYMBOL_GPL(soc_codec_dev_wm8350);
1474 1578
1475static int wm8350_codec_probe(struct platform_device *pdev) 1579static __devinit int wm8350_codec_probe(struct platform_device *pdev)
1476{ 1580{
1477 struct wm8350 *wm8350 = platform_get_drvdata(pdev); 1581 struct wm8350 *wm8350 = platform_get_drvdata(pdev);
1478 struct wm8350_data *priv; 1582 struct wm8350_data *priv;
diff --git a/sound/soc/codecs/wm8350.h b/sound/soc/codecs/wm8350.h
index cc2887aa6c38..d11bd9288cf9 100644
--- a/sound/soc/codecs/wm8350.h
+++ b/sound/soc/codecs/wm8350.h
@@ -17,4 +17,12 @@
17extern struct snd_soc_dai wm8350_dai; 17extern struct snd_soc_dai wm8350_dai;
18extern struct snd_soc_codec_device soc_codec_dev_wm8350; 18extern struct snd_soc_codec_device soc_codec_dev_wm8350;
19 19
20enum wm8350_jack {
21 WM8350_JDL = 1,
22 WM8350_JDR = 2,
23};
24
25int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which,
26 struct snd_soc_jack *jack, int report);
27
20#endif 28#endif
diff --git a/sound/soc/codecs/wm8400.c b/sound/soc/codecs/wm8400.c
new file mode 100644
index 000000000000..510efa604008
--- /dev/null
+++ b/sound/soc/codecs/wm8400.c
@@ -0,0 +1,1582 @@
1/*
2 * wm8400.c -- WM8400 ALSA Soc Audio driver
3 *
4 * Copyright 2008, 2009 Wolfson Microelectronics PLC.
5 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/delay.h>
19#include <linux/pm.h>
20#include <linux/platform_device.h>
21#include <linux/regulator/consumer.h>
22#include <linux/mfd/wm8400-audio.h>
23#include <linux/mfd/wm8400-private.h>
24#include <sound/core.h>
25#include <sound/pcm.h>
26#include <sound/pcm_params.h>
27#include <sound/soc.h>
28#include <sound/soc-dapm.h>
29#include <sound/initval.h>
30#include <sound/tlv.h>
31
32#include "wm8400.h"
33
34/* Fake register for internal state */
35#define WM8400_INTDRIVBITS (WM8400_REGISTER_COUNT + 1)
36#define WM8400_INMIXL_PWR 0
37#define WM8400_AINLMUX_PWR 1
38#define WM8400_INMIXR_PWR 2
39#define WM8400_AINRMUX_PWR 3
40
41static struct regulator_bulk_data power[] = {
42 {
43 .supply = "I2S1VDD",
44 },
45 {
46 .supply = "I2S2VDD",
47 },
48 {
49 .supply = "DCVDD",
50 },
51 {
52 .supply = "AVDD",
53 },
54 {
55 .supply = "FLLVDD",
56 },
57 {
58 .supply = "HPVDD",
59 },
60 {
61 .supply = "SPKVDD",
62 },
63};
64
65/* codec private data */
66struct wm8400_priv {
67 struct snd_soc_codec codec;
68 struct wm8400 *wm8400;
69 u16 fake_register;
70 unsigned int sysclk;
71 unsigned int pcmclk;
72 struct work_struct work;
73 int fll_in, fll_out;
74};
75
76static inline unsigned int wm8400_read(struct snd_soc_codec *codec,
77 unsigned int reg)
78{
79 struct wm8400_priv *wm8400 = codec->private_data;
80
81 if (reg == WM8400_INTDRIVBITS)
82 return wm8400->fake_register;
83 else
84 return wm8400_reg_read(wm8400->wm8400, reg);
85}
86
87/*
88 * write to the wm8400 register space
89 */
90static int wm8400_write(struct snd_soc_codec *codec, unsigned int reg,
91 unsigned int value)
92{
93 struct wm8400_priv *wm8400 = codec->private_data;
94
95 if (reg == WM8400_INTDRIVBITS) {
96 wm8400->fake_register = value;
97 return 0;
98 } else
99 return wm8400_set_bits(wm8400->wm8400, reg, 0xffff, value);
100}
101
102static void wm8400_codec_reset(struct snd_soc_codec *codec)
103{
104 struct wm8400_priv *wm8400 = codec->private_data;
105
106 wm8400_reset_codec_reg_cache(wm8400->wm8400);
107}
108
109static const DECLARE_TLV_DB_LINEAR(rec_mix_tlv, -1500, 600);
110
111static const DECLARE_TLV_DB_LINEAR(in_pga_tlv, -1650, 3000);
112
113static const DECLARE_TLV_DB_LINEAR(out_mix_tlv, -2100, 0);
114
115static const DECLARE_TLV_DB_LINEAR(out_pga_tlv, -7300, 600);
116
117static const DECLARE_TLV_DB_LINEAR(out_omix_tlv, -600, 0);
118
119static const DECLARE_TLV_DB_LINEAR(out_dac_tlv, -7163, 0);
120
121static const DECLARE_TLV_DB_LINEAR(in_adc_tlv, -7163, 1763);
122
123static const DECLARE_TLV_DB_LINEAR(out_sidetone_tlv, -3600, 0);
124
125static int wm8400_outpga_put_volsw_vu(struct snd_kcontrol *kcontrol,
126 struct snd_ctl_elem_value *ucontrol)
127{
128 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
129 struct soc_mixer_control *mc =
130 (struct soc_mixer_control *)kcontrol->private_value;
131 int reg = mc->reg;
132 int ret;
133 u16 val;
134
135 ret = snd_soc_put_volsw(kcontrol, ucontrol);
136 if (ret < 0)
137 return ret;
138
139 /* now hit the volume update bits (always bit 8) */
140 val = wm8400_read(codec, reg);
141 return wm8400_write(codec, reg, val | 0x0100);
142}
143
144#define WM8400_OUTPGA_SINGLE_R_TLV(xname, reg, shift, max, invert, tlv_array) \
145{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
146 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
147 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
148 .tlv.p = (tlv_array), \
149 .info = snd_soc_info_volsw, \
150 .get = snd_soc_get_volsw, .put = wm8400_outpga_put_volsw_vu, \
151 .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
152
153
154static const char *wm8400_digital_sidetone[] =
155 {"None", "Left ADC", "Right ADC", "Reserved"};
156
157static const struct soc_enum wm8400_left_digital_sidetone_enum =
158SOC_ENUM_SINGLE(WM8400_DIGITAL_SIDE_TONE,
159 WM8400_ADC_TO_DACL_SHIFT, 2, wm8400_digital_sidetone);
160
161static const struct soc_enum wm8400_right_digital_sidetone_enum =
162SOC_ENUM_SINGLE(WM8400_DIGITAL_SIDE_TONE,
163 WM8400_ADC_TO_DACR_SHIFT, 2, wm8400_digital_sidetone);
164
165static const char *wm8400_adcmode[] =
166 {"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"};
167
168static const struct soc_enum wm8400_right_adcmode_enum =
169SOC_ENUM_SINGLE(WM8400_ADC_CTRL, WM8400_ADC_HPF_CUT_SHIFT, 3, wm8400_adcmode);
170
171static const struct snd_kcontrol_new wm8400_snd_controls[] = {
172/* INMIXL */
173SOC_SINGLE("LIN12 PGA Boost", WM8400_INPUT_MIXER3, WM8400_L12MNBST_SHIFT,
174 1, 0),
175SOC_SINGLE("LIN34 PGA Boost", WM8400_INPUT_MIXER3, WM8400_L34MNBST_SHIFT,
176 1, 0),
177/* INMIXR */
178SOC_SINGLE("RIN12 PGA Boost", WM8400_INPUT_MIXER3, WM8400_R12MNBST_SHIFT,
179 1, 0),
180SOC_SINGLE("RIN34 PGA Boost", WM8400_INPUT_MIXER3, WM8400_R34MNBST_SHIFT,
181 1, 0),
182
183/* LOMIX */
184SOC_SINGLE_TLV("LOMIX LIN3 Bypass Volume", WM8400_OUTPUT_MIXER3,
185 WM8400_LLI3LOVOL_SHIFT, 7, 0, out_mix_tlv),
186SOC_SINGLE_TLV("LOMIX RIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER3,
187 WM8400_LR12LOVOL_SHIFT, 7, 0, out_mix_tlv),
188SOC_SINGLE_TLV("LOMIX LIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER3,
189 WM8400_LL12LOVOL_SHIFT, 7, 0, out_mix_tlv),
190SOC_SINGLE_TLV("LOMIX RIN3 Bypass Volume", WM8400_OUTPUT_MIXER5,
191 WM8400_LRI3LOVOL_SHIFT, 7, 0, out_mix_tlv),
192SOC_SINGLE_TLV("LOMIX AINRMUX Bypass Volume", WM8400_OUTPUT_MIXER5,
193 WM8400_LRBLOVOL_SHIFT, 7, 0, out_mix_tlv),
194SOC_SINGLE_TLV("LOMIX AINLMUX Bypass Volume", WM8400_OUTPUT_MIXER5,
195 WM8400_LRBLOVOL_SHIFT, 7, 0, out_mix_tlv),
196
197/* ROMIX */
198SOC_SINGLE_TLV("ROMIX RIN3 Bypass Volume", WM8400_OUTPUT_MIXER4,
199 WM8400_RRI3ROVOL_SHIFT, 7, 0, out_mix_tlv),
200SOC_SINGLE_TLV("ROMIX LIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER4,
201 WM8400_RL12ROVOL_SHIFT, 7, 0, out_mix_tlv),
202SOC_SINGLE_TLV("ROMIX RIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER4,
203 WM8400_RR12ROVOL_SHIFT, 7, 0, out_mix_tlv),
204SOC_SINGLE_TLV("ROMIX LIN3 Bypass Volume", WM8400_OUTPUT_MIXER6,
205 WM8400_RLI3ROVOL_SHIFT, 7, 0, out_mix_tlv),
206SOC_SINGLE_TLV("ROMIX AINLMUX Bypass Volume", WM8400_OUTPUT_MIXER6,
207 WM8400_RLBROVOL_SHIFT, 7, 0, out_mix_tlv),
208SOC_SINGLE_TLV("ROMIX AINRMUX Bypass Volume", WM8400_OUTPUT_MIXER6,
209 WM8400_RRBROVOL_SHIFT, 7, 0, out_mix_tlv),
210
211/* LOUT */
212WM8400_OUTPGA_SINGLE_R_TLV("LOUT Volume", WM8400_LEFT_OUTPUT_VOLUME,
213 WM8400_LOUTVOL_SHIFT, WM8400_LOUTVOL_MASK, 0, out_pga_tlv),
214SOC_SINGLE("LOUT ZC", WM8400_LEFT_OUTPUT_VOLUME, WM8400_LOZC_SHIFT, 1, 0),
215
216/* ROUT */
217WM8400_OUTPGA_SINGLE_R_TLV("ROUT Volume", WM8400_RIGHT_OUTPUT_VOLUME,
218 WM8400_ROUTVOL_SHIFT, WM8400_ROUTVOL_MASK, 0, out_pga_tlv),
219SOC_SINGLE("ROUT ZC", WM8400_RIGHT_OUTPUT_VOLUME, WM8400_ROZC_SHIFT, 1, 0),
220
221/* LOPGA */
222WM8400_OUTPGA_SINGLE_R_TLV("LOPGA Volume", WM8400_LEFT_OPGA_VOLUME,
223 WM8400_LOPGAVOL_SHIFT, WM8400_LOPGAVOL_MASK, 0, out_pga_tlv),
224SOC_SINGLE("LOPGA ZC Switch", WM8400_LEFT_OPGA_VOLUME,
225 WM8400_LOPGAZC_SHIFT, 1, 0),
226
227/* ROPGA */
228WM8400_OUTPGA_SINGLE_R_TLV("ROPGA Volume", WM8400_RIGHT_OPGA_VOLUME,
229 WM8400_ROPGAVOL_SHIFT, WM8400_ROPGAVOL_MASK, 0, out_pga_tlv),
230SOC_SINGLE("ROPGA ZC Switch", WM8400_RIGHT_OPGA_VOLUME,
231 WM8400_ROPGAZC_SHIFT, 1, 0),
232
233SOC_SINGLE("LON Mute Switch", WM8400_LINE_OUTPUTS_VOLUME,
234 WM8400_LONMUTE_SHIFT, 1, 0),
235SOC_SINGLE("LOP Mute Switch", WM8400_LINE_OUTPUTS_VOLUME,
236 WM8400_LOPMUTE_SHIFT, 1, 0),
237SOC_SINGLE("LOP Attenuation Switch", WM8400_LINE_OUTPUTS_VOLUME,
238 WM8400_LOATTN_SHIFT, 1, 0),
239SOC_SINGLE("RON Mute Switch", WM8400_LINE_OUTPUTS_VOLUME,
240 WM8400_RONMUTE_SHIFT, 1, 0),
241SOC_SINGLE("ROP Mute Switch", WM8400_LINE_OUTPUTS_VOLUME,
242 WM8400_ROPMUTE_SHIFT, 1, 0),
243SOC_SINGLE("ROP Attenuation Switch", WM8400_LINE_OUTPUTS_VOLUME,
244 WM8400_ROATTN_SHIFT, 1, 0),
245
246SOC_SINGLE("OUT3 Mute Switch", WM8400_OUT3_4_VOLUME,
247 WM8400_OUT3MUTE_SHIFT, 1, 0),
248SOC_SINGLE("OUT3 Attenuation Switch", WM8400_OUT3_4_VOLUME,
249 WM8400_OUT3ATTN_SHIFT, 1, 0),
250
251SOC_SINGLE("OUT4 Mute Switch", WM8400_OUT3_4_VOLUME,
252 WM8400_OUT4MUTE_SHIFT, 1, 0),
253SOC_SINGLE("OUT4 Attenuation Switch", WM8400_OUT3_4_VOLUME,
254 WM8400_OUT4ATTN_SHIFT, 1, 0),
255
256SOC_SINGLE("Speaker Mode Switch", WM8400_CLASSD1,
257 WM8400_CDMODE_SHIFT, 1, 0),
258
259SOC_SINGLE("Speaker Output Attenuation Volume", WM8400_SPEAKER_VOLUME,
260 WM8400_SPKATTN_SHIFT, WM8400_SPKATTN_MASK, 0),
261SOC_SINGLE("Speaker DC Boost Volume", WM8400_CLASSD3,
262 WM8400_DCGAIN_SHIFT, 6, 0),
263SOC_SINGLE("Speaker AC Boost Volume", WM8400_CLASSD3,
264 WM8400_ACGAIN_SHIFT, 6, 0),
265
266WM8400_OUTPGA_SINGLE_R_TLV("Left DAC Digital Volume",
267 WM8400_LEFT_DAC_DIGITAL_VOLUME, WM8400_DACL_VOL_SHIFT,
268 127, 0, out_dac_tlv),
269
270WM8400_OUTPGA_SINGLE_R_TLV("Right DAC Digital Volume",
271 WM8400_RIGHT_DAC_DIGITAL_VOLUME, WM8400_DACR_VOL_SHIFT,
272 127, 0, out_dac_tlv),
273
274SOC_ENUM("Left Digital Sidetone", wm8400_left_digital_sidetone_enum),
275SOC_ENUM("Right Digital Sidetone", wm8400_right_digital_sidetone_enum),
276
277SOC_SINGLE_TLV("Left Digital Sidetone Volume", WM8400_DIGITAL_SIDE_TONE,
278 WM8400_ADCL_DAC_SVOL_SHIFT, 15, 0, out_sidetone_tlv),
279SOC_SINGLE_TLV("Right Digital Sidetone Volume", WM8400_DIGITAL_SIDE_TONE,
280 WM8400_ADCR_DAC_SVOL_SHIFT, 15, 0, out_sidetone_tlv),
281
282SOC_SINGLE("ADC Digital High Pass Filter Switch", WM8400_ADC_CTRL,
283 WM8400_ADC_HPF_ENA_SHIFT, 1, 0),
284
285SOC_ENUM("ADC HPF Mode", wm8400_right_adcmode_enum),
286
287WM8400_OUTPGA_SINGLE_R_TLV("Left ADC Digital Volume",
288 WM8400_LEFT_ADC_DIGITAL_VOLUME,
289 WM8400_ADCL_VOL_SHIFT,
290 WM8400_ADCL_VOL_MASK,
291 0,
292 in_adc_tlv),
293
294WM8400_OUTPGA_SINGLE_R_TLV("Right ADC Digital Volume",
295 WM8400_RIGHT_ADC_DIGITAL_VOLUME,
296 WM8400_ADCR_VOL_SHIFT,
297 WM8400_ADCR_VOL_MASK,
298 0,
299 in_adc_tlv),
300
301WM8400_OUTPGA_SINGLE_R_TLV("LIN12 Volume",
302 WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
303 WM8400_LIN12VOL_SHIFT,
304 WM8400_LIN12VOL_MASK,
305 0,
306 in_pga_tlv),
307
308SOC_SINGLE("LIN12 ZC Switch", WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
309 WM8400_LI12ZC_SHIFT, 1, 0),
310
311SOC_SINGLE("LIN12 Mute Switch", WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
312 WM8400_LI12MUTE_SHIFT, 1, 0),
313
314WM8400_OUTPGA_SINGLE_R_TLV("LIN34 Volume",
315 WM8400_LEFT_LINE_INPUT_3_4_VOLUME,
316 WM8400_LIN34VOL_SHIFT,
317 WM8400_LIN34VOL_MASK,
318 0,
319 in_pga_tlv),
320
321SOC_SINGLE("LIN34 ZC Switch", WM8400_LEFT_LINE_INPUT_3_4_VOLUME,
322 WM8400_LI34ZC_SHIFT, 1, 0),
323
324SOC_SINGLE("LIN34 Mute Switch", WM8400_LEFT_LINE_INPUT_3_4_VOLUME,
325 WM8400_LI34MUTE_SHIFT, 1, 0),
326
327WM8400_OUTPGA_SINGLE_R_TLV("RIN12 Volume",
328 WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
329 WM8400_RIN12VOL_SHIFT,
330 WM8400_RIN12VOL_MASK,
331 0,
332 in_pga_tlv),
333
334SOC_SINGLE("RIN12 ZC Switch", WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
335 WM8400_RI12ZC_SHIFT, 1, 0),
336
337SOC_SINGLE("RIN12 Mute Switch", WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
338 WM8400_RI12MUTE_SHIFT, 1, 0),
339
340WM8400_OUTPGA_SINGLE_R_TLV("RIN34 Volume",
341 WM8400_RIGHT_LINE_INPUT_3_4_VOLUME,
342 WM8400_RIN34VOL_SHIFT,
343 WM8400_RIN34VOL_MASK,
344 0,
345 in_pga_tlv),
346
347SOC_SINGLE("RIN34 ZC Switch", WM8400_RIGHT_LINE_INPUT_3_4_VOLUME,
348 WM8400_RI34ZC_SHIFT, 1, 0),
349
350SOC_SINGLE("RIN34 Mute Switch", WM8400_RIGHT_LINE_INPUT_3_4_VOLUME,
351 WM8400_RI34MUTE_SHIFT, 1, 0),
352
353};
354
355/* add non dapm controls */
356static int wm8400_add_controls(struct snd_soc_codec *codec)
357{
358 return snd_soc_add_controls(codec, wm8400_snd_controls,
359 ARRAY_SIZE(wm8400_snd_controls));
360}
361
362/*
363 * _DAPM_ Controls
364 */
365
366static int inmixer_event (struct snd_soc_dapm_widget *w,
367 struct snd_kcontrol *kcontrol, int event)
368{
369 u16 reg, fakepower;
370
371 reg = wm8400_read(w->codec, WM8400_POWER_MANAGEMENT_2);
372 fakepower = wm8400_read(w->codec, WM8400_INTDRIVBITS);
373
374 if (fakepower & ((1 << WM8400_INMIXL_PWR) |
375 (1 << WM8400_AINLMUX_PWR))) {
376 reg |= WM8400_AINL_ENA;
377 } else {
378 reg &= ~WM8400_AINL_ENA;
379 }
380
381 if (fakepower & ((1 << WM8400_INMIXR_PWR) |
382 (1 << WM8400_AINRMUX_PWR))) {
383 reg |= WM8400_AINR_ENA;
384 } else {
385 reg &= ~WM8400_AINL_ENA;
386 }
387 wm8400_write(w->codec, WM8400_POWER_MANAGEMENT_2, reg);
388
389 return 0;
390}
391
392static int outmixer_event (struct snd_soc_dapm_widget *w,
393 struct snd_kcontrol * kcontrol, int event)
394{
395 struct soc_mixer_control *mc =
396 (struct soc_mixer_control *)kcontrol->private_value;
397 u32 reg_shift = mc->shift;
398 int ret = 0;
399 u16 reg;
400
401 switch (reg_shift) {
402 case WM8400_SPEAKER_MIXER | (WM8400_LDSPK << 8) :
403 reg = wm8400_read(w->codec, WM8400_OUTPUT_MIXER1);
404 if (reg & WM8400_LDLO) {
405 printk(KERN_WARNING
406 "Cannot set as Output Mixer 1 LDLO Set\n");
407 ret = -1;
408 }
409 break;
410 case WM8400_SPEAKER_MIXER | (WM8400_RDSPK << 8):
411 reg = wm8400_read(w->codec, WM8400_OUTPUT_MIXER2);
412 if (reg & WM8400_RDRO) {
413 printk(KERN_WARNING
414 "Cannot set as Output Mixer 2 RDRO Set\n");
415 ret = -1;
416 }
417 break;
418 case WM8400_OUTPUT_MIXER1 | (WM8400_LDLO << 8):
419 reg = wm8400_read(w->codec, WM8400_SPEAKER_MIXER);
420 if (reg & WM8400_LDSPK) {
421 printk(KERN_WARNING
422 "Cannot set as Speaker Mixer LDSPK Set\n");
423 ret = -1;
424 }
425 break;
426 case WM8400_OUTPUT_MIXER2 | (WM8400_RDRO << 8):
427 reg = wm8400_read(w->codec, WM8400_SPEAKER_MIXER);
428 if (reg & WM8400_RDSPK) {
429 printk(KERN_WARNING
430 "Cannot set as Speaker Mixer RDSPK Set\n");
431 ret = -1;
432 }
433 break;
434 }
435
436 return ret;
437}
438
439/* INMIX dB values */
440static const unsigned int in_mix_tlv[] = {
441 TLV_DB_RANGE_HEAD(1),
442 0,7, TLV_DB_LINEAR_ITEM(-1200, 600),
443};
444
445/* Left In PGA Connections */
446static const struct snd_kcontrol_new wm8400_dapm_lin12_pga_controls[] = {
447SOC_DAPM_SINGLE("LIN1 Switch", WM8400_INPUT_MIXER2, WM8400_LMN1_SHIFT, 1, 0),
448SOC_DAPM_SINGLE("LIN2 Switch", WM8400_INPUT_MIXER2, WM8400_LMP2_SHIFT, 1, 0),
449};
450
451static const struct snd_kcontrol_new wm8400_dapm_lin34_pga_controls[] = {
452SOC_DAPM_SINGLE("LIN3 Switch", WM8400_INPUT_MIXER2, WM8400_LMN3_SHIFT, 1, 0),
453SOC_DAPM_SINGLE("LIN4 Switch", WM8400_INPUT_MIXER2, WM8400_LMP4_SHIFT, 1, 0),
454};
455
456/* Right In PGA Connections */
457static const struct snd_kcontrol_new wm8400_dapm_rin12_pga_controls[] = {
458SOC_DAPM_SINGLE("RIN1 Switch", WM8400_INPUT_MIXER2, WM8400_RMN1_SHIFT, 1, 0),
459SOC_DAPM_SINGLE("RIN2 Switch", WM8400_INPUT_MIXER2, WM8400_RMP2_SHIFT, 1, 0),
460};
461
462static const struct snd_kcontrol_new wm8400_dapm_rin34_pga_controls[] = {
463SOC_DAPM_SINGLE("RIN3 Switch", WM8400_INPUT_MIXER2, WM8400_RMN3_SHIFT, 1, 0),
464SOC_DAPM_SINGLE("RIN4 Switch", WM8400_INPUT_MIXER2, WM8400_RMP4_SHIFT, 1, 0),
465};
466
467/* INMIXL */
468static const struct snd_kcontrol_new wm8400_dapm_inmixl_controls[] = {
469SOC_DAPM_SINGLE_TLV("Record Left Volume", WM8400_INPUT_MIXER3,
470 WM8400_LDBVOL_SHIFT, WM8400_LDBVOL_MASK, 0, in_mix_tlv),
471SOC_DAPM_SINGLE_TLV("LIN2 Volume", WM8400_INPUT_MIXER5, WM8400_LI2BVOL_SHIFT,
472 7, 0, in_mix_tlv),
473SOC_DAPM_SINGLE("LINPGA12 Switch", WM8400_INPUT_MIXER3, WM8400_L12MNB_SHIFT,
474 1, 0),
475SOC_DAPM_SINGLE("LINPGA34 Switch", WM8400_INPUT_MIXER3, WM8400_L34MNB_SHIFT,
476 1, 0),
477};
478
479/* INMIXR */
480static const struct snd_kcontrol_new wm8400_dapm_inmixr_controls[] = {
481SOC_DAPM_SINGLE_TLV("Record Right Volume", WM8400_INPUT_MIXER4,
482 WM8400_RDBVOL_SHIFT, WM8400_RDBVOL_MASK, 0, in_mix_tlv),
483SOC_DAPM_SINGLE_TLV("RIN2 Volume", WM8400_INPUT_MIXER6, WM8400_RI2BVOL_SHIFT,
484 7, 0, in_mix_tlv),
485SOC_DAPM_SINGLE("RINPGA12 Switch", WM8400_INPUT_MIXER3, WM8400_L12MNB_SHIFT,
486 1, 0),
487SOC_DAPM_SINGLE("RINPGA34 Switch", WM8400_INPUT_MIXER3, WM8400_L34MNB_SHIFT,
488 1, 0),
489};
490
491/* AINLMUX */
492static const char *wm8400_ainlmux[] =
493 {"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"};
494
495static const struct soc_enum wm8400_ainlmux_enum =
496SOC_ENUM_SINGLE( WM8400_INPUT_MIXER1, WM8400_AINLMODE_SHIFT,
497 ARRAY_SIZE(wm8400_ainlmux), wm8400_ainlmux);
498
499static const struct snd_kcontrol_new wm8400_dapm_ainlmux_controls =
500SOC_DAPM_ENUM("Route", wm8400_ainlmux_enum);
501
502/* DIFFINL */
503
504/* AINRMUX */
505static const char *wm8400_ainrmux[] =
506 {"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"};
507
508static const struct soc_enum wm8400_ainrmux_enum =
509SOC_ENUM_SINGLE( WM8400_INPUT_MIXER1, WM8400_AINRMODE_SHIFT,
510 ARRAY_SIZE(wm8400_ainrmux), wm8400_ainrmux);
511
512static const struct snd_kcontrol_new wm8400_dapm_ainrmux_controls =
513SOC_DAPM_ENUM("Route", wm8400_ainrmux_enum);
514
515/* RXVOICE */
516static const struct snd_kcontrol_new wm8400_dapm_rxvoice_controls[] = {
517SOC_DAPM_SINGLE_TLV("LIN4/RXN", WM8400_INPUT_MIXER5, WM8400_LR4BVOL_SHIFT,
518 WM8400_LR4BVOL_MASK, 0, in_mix_tlv),
519SOC_DAPM_SINGLE_TLV("RIN4/RXP", WM8400_INPUT_MIXER6, WM8400_RL4BVOL_SHIFT,
520 WM8400_RL4BVOL_MASK, 0, in_mix_tlv),
521};
522
523/* LOMIX */
524static const struct snd_kcontrol_new wm8400_dapm_lomix_controls[] = {
525SOC_DAPM_SINGLE("LOMIX Right ADC Bypass Switch", WM8400_OUTPUT_MIXER1,
526 WM8400_LRBLO_SHIFT, 1, 0),
527SOC_DAPM_SINGLE("LOMIX Left ADC Bypass Switch", WM8400_OUTPUT_MIXER1,
528 WM8400_LLBLO_SHIFT, 1, 0),
529SOC_DAPM_SINGLE("LOMIX RIN3 Bypass Switch", WM8400_OUTPUT_MIXER1,
530 WM8400_LRI3LO_SHIFT, 1, 0),
531SOC_DAPM_SINGLE("LOMIX LIN3 Bypass Switch", WM8400_OUTPUT_MIXER1,
532 WM8400_LLI3LO_SHIFT, 1, 0),
533SOC_DAPM_SINGLE("LOMIX RIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER1,
534 WM8400_LR12LO_SHIFT, 1, 0),
535SOC_DAPM_SINGLE("LOMIX LIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER1,
536 WM8400_LL12LO_SHIFT, 1, 0),
537SOC_DAPM_SINGLE("LOMIX Left DAC Switch", WM8400_OUTPUT_MIXER1,
538 WM8400_LDLO_SHIFT, 1, 0),
539};
540
541/* ROMIX */
542static const struct snd_kcontrol_new wm8400_dapm_romix_controls[] = {
543SOC_DAPM_SINGLE("ROMIX Left ADC Bypass Switch", WM8400_OUTPUT_MIXER2,
544 WM8400_RLBRO_SHIFT, 1, 0),
545SOC_DAPM_SINGLE("ROMIX Right ADC Bypass Switch", WM8400_OUTPUT_MIXER2,
546 WM8400_RRBRO_SHIFT, 1, 0),
547SOC_DAPM_SINGLE("ROMIX LIN3 Bypass Switch", WM8400_OUTPUT_MIXER2,
548 WM8400_RLI3RO_SHIFT, 1, 0),
549SOC_DAPM_SINGLE("ROMIX RIN3 Bypass Switch", WM8400_OUTPUT_MIXER2,
550 WM8400_RRI3RO_SHIFT, 1, 0),
551SOC_DAPM_SINGLE("ROMIX LIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER2,
552 WM8400_RL12RO_SHIFT, 1, 0),
553SOC_DAPM_SINGLE("ROMIX RIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER2,
554 WM8400_RR12RO_SHIFT, 1, 0),
555SOC_DAPM_SINGLE("ROMIX Right DAC Switch", WM8400_OUTPUT_MIXER2,
556 WM8400_RDRO_SHIFT, 1, 0),
557};
558
559/* LONMIX */
560static const struct snd_kcontrol_new wm8400_dapm_lonmix_controls[] = {
561SOC_DAPM_SINGLE("LONMIX Left Mixer PGA Switch", WM8400_LINE_MIXER1,
562 WM8400_LLOPGALON_SHIFT, 1, 0),
563SOC_DAPM_SINGLE("LONMIX Right Mixer PGA Switch", WM8400_LINE_MIXER1,
564 WM8400_LROPGALON_SHIFT, 1, 0),
565SOC_DAPM_SINGLE("LONMIX Inverted LOP Switch", WM8400_LINE_MIXER1,
566 WM8400_LOPLON_SHIFT, 1, 0),
567};
568
569/* LOPMIX */
570static const struct snd_kcontrol_new wm8400_dapm_lopmix_controls[] = {
571SOC_DAPM_SINGLE("LOPMIX Right Mic Bypass Switch", WM8400_LINE_MIXER1,
572 WM8400_LR12LOP_SHIFT, 1, 0),
573SOC_DAPM_SINGLE("LOPMIX Left Mic Bypass Switch", WM8400_LINE_MIXER1,
574 WM8400_LL12LOP_SHIFT, 1, 0),
575SOC_DAPM_SINGLE("LOPMIX Left Mixer PGA Switch", WM8400_LINE_MIXER1,
576 WM8400_LLOPGALOP_SHIFT, 1, 0),
577};
578
579/* RONMIX */
580static const struct snd_kcontrol_new wm8400_dapm_ronmix_controls[] = {
581SOC_DAPM_SINGLE("RONMIX Right Mixer PGA Switch", WM8400_LINE_MIXER2,
582 WM8400_RROPGARON_SHIFT, 1, 0),
583SOC_DAPM_SINGLE("RONMIX Left Mixer PGA Switch", WM8400_LINE_MIXER2,
584 WM8400_RLOPGARON_SHIFT, 1, 0),
585SOC_DAPM_SINGLE("RONMIX Inverted ROP Switch", WM8400_LINE_MIXER2,
586 WM8400_ROPRON_SHIFT, 1, 0),
587};
588
589/* ROPMIX */
590static const struct snd_kcontrol_new wm8400_dapm_ropmix_controls[] = {
591SOC_DAPM_SINGLE("ROPMIX Left Mic Bypass Switch", WM8400_LINE_MIXER2,
592 WM8400_RL12ROP_SHIFT, 1, 0),
593SOC_DAPM_SINGLE("ROPMIX Right Mic Bypass Switch", WM8400_LINE_MIXER2,
594 WM8400_RR12ROP_SHIFT, 1, 0),
595SOC_DAPM_SINGLE("ROPMIX Right Mixer PGA Switch", WM8400_LINE_MIXER2,
596 WM8400_RROPGAROP_SHIFT, 1, 0),
597};
598
599/* OUT3MIX */
600static const struct snd_kcontrol_new wm8400_dapm_out3mix_controls[] = {
601SOC_DAPM_SINGLE("OUT3MIX LIN4/RXP Bypass Switch", WM8400_OUT3_4_MIXER,
602 WM8400_LI4O3_SHIFT, 1, 0),
603SOC_DAPM_SINGLE("OUT3MIX Left Out PGA Switch", WM8400_OUT3_4_MIXER,
604 WM8400_LPGAO3_SHIFT, 1, 0),
605};
606
607/* OUT4MIX */
608static const struct snd_kcontrol_new wm8400_dapm_out4mix_controls[] = {
609SOC_DAPM_SINGLE("OUT4MIX Right Out PGA Switch", WM8400_OUT3_4_MIXER,
610 WM8400_RPGAO4_SHIFT, 1, 0),
611SOC_DAPM_SINGLE("OUT4MIX RIN4/RXP Bypass Switch", WM8400_OUT3_4_MIXER,
612 WM8400_RI4O4_SHIFT, 1, 0),
613};
614
615/* SPKMIX */
616static const struct snd_kcontrol_new wm8400_dapm_spkmix_controls[] = {
617SOC_DAPM_SINGLE("SPKMIX LIN2 Bypass Switch", WM8400_SPEAKER_MIXER,
618 WM8400_LI2SPK_SHIFT, 1, 0),
619SOC_DAPM_SINGLE("SPKMIX LADC Bypass Switch", WM8400_SPEAKER_MIXER,
620 WM8400_LB2SPK_SHIFT, 1, 0),
621SOC_DAPM_SINGLE("SPKMIX Left Mixer PGA Switch", WM8400_SPEAKER_MIXER,
622 WM8400_LOPGASPK_SHIFT, 1, 0),
623SOC_DAPM_SINGLE("SPKMIX Left DAC Switch", WM8400_SPEAKER_MIXER,
624 WM8400_LDSPK_SHIFT, 1, 0),
625SOC_DAPM_SINGLE("SPKMIX Right DAC Switch", WM8400_SPEAKER_MIXER,
626 WM8400_RDSPK_SHIFT, 1, 0),
627SOC_DAPM_SINGLE("SPKMIX Right Mixer PGA Switch", WM8400_SPEAKER_MIXER,
628 WM8400_ROPGASPK_SHIFT, 1, 0),
629SOC_DAPM_SINGLE("SPKMIX RADC Bypass Switch", WM8400_SPEAKER_MIXER,
630 WM8400_RL12ROP_SHIFT, 1, 0),
631SOC_DAPM_SINGLE("SPKMIX RIN2 Bypass Switch", WM8400_SPEAKER_MIXER,
632 WM8400_RI2SPK_SHIFT, 1, 0),
633};
634
635static const struct snd_soc_dapm_widget wm8400_dapm_widgets[] = {
636/* Input Side */
637/* Input Lines */
638SND_SOC_DAPM_INPUT("LIN1"),
639SND_SOC_DAPM_INPUT("LIN2"),
640SND_SOC_DAPM_INPUT("LIN3"),
641SND_SOC_DAPM_INPUT("LIN4/RXN"),
642SND_SOC_DAPM_INPUT("RIN3"),
643SND_SOC_DAPM_INPUT("RIN4/RXP"),
644SND_SOC_DAPM_INPUT("RIN1"),
645SND_SOC_DAPM_INPUT("RIN2"),
646SND_SOC_DAPM_INPUT("Internal ADC Source"),
647
648/* DACs */
649SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8400_POWER_MANAGEMENT_2,
650 WM8400_ADCL_ENA_SHIFT, 0),
651SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8400_POWER_MANAGEMENT_2,
652 WM8400_ADCR_ENA_SHIFT, 0),
653
654/* Input PGAs */
655SND_SOC_DAPM_MIXER("LIN12 PGA", WM8400_POWER_MANAGEMENT_2,
656 WM8400_LIN12_ENA_SHIFT,
657 0, &wm8400_dapm_lin12_pga_controls[0],
658 ARRAY_SIZE(wm8400_dapm_lin12_pga_controls)),
659SND_SOC_DAPM_MIXER("LIN34 PGA", WM8400_POWER_MANAGEMENT_2,
660 WM8400_LIN34_ENA_SHIFT,
661 0, &wm8400_dapm_lin34_pga_controls[0],
662 ARRAY_SIZE(wm8400_dapm_lin34_pga_controls)),
663SND_SOC_DAPM_MIXER("RIN12 PGA", WM8400_POWER_MANAGEMENT_2,
664 WM8400_RIN12_ENA_SHIFT,
665 0, &wm8400_dapm_rin12_pga_controls[0],
666 ARRAY_SIZE(wm8400_dapm_rin12_pga_controls)),
667SND_SOC_DAPM_MIXER("RIN34 PGA", WM8400_POWER_MANAGEMENT_2,
668 WM8400_RIN34_ENA_SHIFT,
669 0, &wm8400_dapm_rin34_pga_controls[0],
670 ARRAY_SIZE(wm8400_dapm_rin34_pga_controls)),
671
672/* INMIXL */
673SND_SOC_DAPM_MIXER_E("INMIXL", WM8400_INTDRIVBITS, WM8400_INMIXL_PWR, 0,
674 &wm8400_dapm_inmixl_controls[0],
675 ARRAY_SIZE(wm8400_dapm_inmixl_controls),
676 inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
677
678/* AINLMUX */
679SND_SOC_DAPM_MUX_E("AILNMUX", WM8400_INTDRIVBITS, WM8400_AINLMUX_PWR, 0,
680 &wm8400_dapm_ainlmux_controls, inmixer_event,
681 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
682
683/* INMIXR */
684SND_SOC_DAPM_MIXER_E("INMIXR", WM8400_INTDRIVBITS, WM8400_INMIXR_PWR, 0,
685 &wm8400_dapm_inmixr_controls[0],
686 ARRAY_SIZE(wm8400_dapm_inmixr_controls),
687 inmixer_event, SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
688
689/* AINRMUX */
690SND_SOC_DAPM_MUX_E("AIRNMUX", WM8400_INTDRIVBITS, WM8400_AINRMUX_PWR, 0,
691 &wm8400_dapm_ainrmux_controls, inmixer_event,
692 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_POST_PMD),
693
694/* Output Side */
695/* DACs */
696SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8400_POWER_MANAGEMENT_3,
697 WM8400_DACL_ENA_SHIFT, 0),
698SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8400_POWER_MANAGEMENT_3,
699 WM8400_DACR_ENA_SHIFT, 0),
700
701/* LOMIX */
702SND_SOC_DAPM_MIXER_E("LOMIX", WM8400_POWER_MANAGEMENT_3,
703 WM8400_LOMIX_ENA_SHIFT,
704 0, &wm8400_dapm_lomix_controls[0],
705 ARRAY_SIZE(wm8400_dapm_lomix_controls),
706 outmixer_event, SND_SOC_DAPM_PRE_REG),
707
708/* LONMIX */
709SND_SOC_DAPM_MIXER("LONMIX", WM8400_POWER_MANAGEMENT_3, WM8400_LON_ENA_SHIFT,
710 0, &wm8400_dapm_lonmix_controls[0],
711 ARRAY_SIZE(wm8400_dapm_lonmix_controls)),
712
713/* LOPMIX */
714SND_SOC_DAPM_MIXER("LOPMIX", WM8400_POWER_MANAGEMENT_3, WM8400_LOP_ENA_SHIFT,
715 0, &wm8400_dapm_lopmix_controls[0],
716 ARRAY_SIZE(wm8400_dapm_lopmix_controls)),
717
718/* OUT3MIX */
719SND_SOC_DAPM_MIXER("OUT3MIX", WM8400_POWER_MANAGEMENT_1, WM8400_OUT3_ENA_SHIFT,
720 0, &wm8400_dapm_out3mix_controls[0],
721 ARRAY_SIZE(wm8400_dapm_out3mix_controls)),
722
723/* SPKMIX */
724SND_SOC_DAPM_MIXER_E("SPKMIX", WM8400_POWER_MANAGEMENT_1, WM8400_SPK_ENA_SHIFT,
725 0, &wm8400_dapm_spkmix_controls[0],
726 ARRAY_SIZE(wm8400_dapm_spkmix_controls), outmixer_event,
727 SND_SOC_DAPM_PRE_REG),
728
729/* OUT4MIX */
730SND_SOC_DAPM_MIXER("OUT4MIX", WM8400_POWER_MANAGEMENT_1, WM8400_OUT4_ENA_SHIFT,
731 0, &wm8400_dapm_out4mix_controls[0],
732 ARRAY_SIZE(wm8400_dapm_out4mix_controls)),
733
734/* ROPMIX */
735SND_SOC_DAPM_MIXER("ROPMIX", WM8400_POWER_MANAGEMENT_3, WM8400_ROP_ENA_SHIFT,
736 0, &wm8400_dapm_ropmix_controls[0],
737 ARRAY_SIZE(wm8400_dapm_ropmix_controls)),
738
739/* RONMIX */
740SND_SOC_DAPM_MIXER("RONMIX", WM8400_POWER_MANAGEMENT_3, WM8400_RON_ENA_SHIFT,
741 0, &wm8400_dapm_ronmix_controls[0],
742 ARRAY_SIZE(wm8400_dapm_ronmix_controls)),
743
744/* ROMIX */
745SND_SOC_DAPM_MIXER_E("ROMIX", WM8400_POWER_MANAGEMENT_3,
746 WM8400_ROMIX_ENA_SHIFT,
747 0, &wm8400_dapm_romix_controls[0],
748 ARRAY_SIZE(wm8400_dapm_romix_controls),
749 outmixer_event, SND_SOC_DAPM_PRE_REG),
750
751/* LOUT PGA */
752SND_SOC_DAPM_PGA("LOUT PGA", WM8400_POWER_MANAGEMENT_1, WM8400_LOUT_ENA_SHIFT,
753 0, NULL, 0),
754
755/* ROUT PGA */
756SND_SOC_DAPM_PGA("ROUT PGA", WM8400_POWER_MANAGEMENT_1, WM8400_ROUT_ENA_SHIFT,
757 0, NULL, 0),
758
759/* LOPGA */
760SND_SOC_DAPM_PGA("LOPGA", WM8400_POWER_MANAGEMENT_3, WM8400_LOPGA_ENA_SHIFT, 0,
761 NULL, 0),
762
763/* ROPGA */
764SND_SOC_DAPM_PGA("ROPGA", WM8400_POWER_MANAGEMENT_3, WM8400_ROPGA_ENA_SHIFT, 0,
765 NULL, 0),
766
767/* MICBIAS */
768SND_SOC_DAPM_MICBIAS("MICBIAS", WM8400_POWER_MANAGEMENT_1,
769 WM8400_MIC1BIAS_ENA_SHIFT, 0),
770
771SND_SOC_DAPM_OUTPUT("LON"),
772SND_SOC_DAPM_OUTPUT("LOP"),
773SND_SOC_DAPM_OUTPUT("OUT3"),
774SND_SOC_DAPM_OUTPUT("LOUT"),
775SND_SOC_DAPM_OUTPUT("SPKN"),
776SND_SOC_DAPM_OUTPUT("SPKP"),
777SND_SOC_DAPM_OUTPUT("ROUT"),
778SND_SOC_DAPM_OUTPUT("OUT4"),
779SND_SOC_DAPM_OUTPUT("ROP"),
780SND_SOC_DAPM_OUTPUT("RON"),
781
782SND_SOC_DAPM_OUTPUT("Internal DAC Sink"),
783};
784
785static const struct snd_soc_dapm_route audio_map[] = {
786 /* Make DACs turn on when playing even if not mixed into any outputs */
787 {"Internal DAC Sink", NULL, "Left DAC"},
788 {"Internal DAC Sink", NULL, "Right DAC"},
789
790 /* Make ADCs turn on when recording
791 * even if not mixed from any inputs */
792 {"Left ADC", NULL, "Internal ADC Source"},
793 {"Right ADC", NULL, "Internal ADC Source"},
794
795 /* Input Side */
796 /* LIN12 PGA */
797 {"LIN12 PGA", "LIN1 Switch", "LIN1"},
798 {"LIN12 PGA", "LIN2 Switch", "LIN2"},
799 /* LIN34 PGA */
800 {"LIN34 PGA", "LIN3 Switch", "LIN3"},
801 {"LIN34 PGA", "LIN4 Switch", "LIN4/RXN"},
802 /* INMIXL */
803 {"INMIXL", "Record Left Volume", "LOMIX"},
804 {"INMIXL", "LIN2 Volume", "LIN2"},
805 {"INMIXL", "LINPGA12 Switch", "LIN12 PGA"},
806 {"INMIXL", "LINPGA34 Switch", "LIN34 PGA"},
807 /* AILNMUX */
808 {"AILNMUX", "INMIXL Mix", "INMIXL"},
809 {"AILNMUX", "DIFFINL Mix", "LIN12 PGA"},
810 {"AILNMUX", "DIFFINL Mix", "LIN34 PGA"},
811 {"AILNMUX", "RXVOICE Mix", "LIN4/RXN"},
812 {"AILNMUX", "RXVOICE Mix", "RIN4/RXP"},
813 /* ADC */
814 {"Left ADC", NULL, "AILNMUX"},
815
816 /* RIN12 PGA */
817 {"RIN12 PGA", "RIN1 Switch", "RIN1"},
818 {"RIN12 PGA", "RIN2 Switch", "RIN2"},
819 /* RIN34 PGA */
820 {"RIN34 PGA", "RIN3 Switch", "RIN3"},
821 {"RIN34 PGA", "RIN4 Switch", "RIN4/RXP"},
822 /* INMIXL */
823 {"INMIXR", "Record Right Volume", "ROMIX"},
824 {"INMIXR", "RIN2 Volume", "RIN2"},
825 {"INMIXR", "RINPGA12 Switch", "RIN12 PGA"},
826 {"INMIXR", "RINPGA34 Switch", "RIN34 PGA"},
827 /* AIRNMUX */
828 {"AIRNMUX", "INMIXR Mix", "INMIXR"},
829 {"AIRNMUX", "DIFFINR Mix", "RIN12 PGA"},
830 {"AIRNMUX", "DIFFINR Mix", "RIN34 PGA"},
831 {"AIRNMUX", "RXVOICE Mix", "LIN4/RXN"},
832 {"AIRNMUX", "RXVOICE Mix", "RIN4/RXP"},
833 /* ADC */
834 {"Right ADC", NULL, "AIRNMUX"},
835
836 /* LOMIX */
837 {"LOMIX", "LOMIX RIN3 Bypass Switch", "RIN3"},
838 {"LOMIX", "LOMIX LIN3 Bypass Switch", "LIN3"},
839 {"LOMIX", "LOMIX LIN12 PGA Bypass Switch", "LIN12 PGA"},
840 {"LOMIX", "LOMIX RIN12 PGA Bypass Switch", "RIN12 PGA"},
841 {"LOMIX", "LOMIX Right ADC Bypass Switch", "AIRNMUX"},
842 {"LOMIX", "LOMIX Left ADC Bypass Switch", "AILNMUX"},
843 {"LOMIX", "LOMIX Left DAC Switch", "Left DAC"},
844
845 /* ROMIX */
846 {"ROMIX", "ROMIX RIN3 Bypass Switch", "RIN3"},
847 {"ROMIX", "ROMIX LIN3 Bypass Switch", "LIN3"},
848 {"ROMIX", "ROMIX LIN12 PGA Bypass Switch", "LIN12 PGA"},
849 {"ROMIX", "ROMIX RIN12 PGA Bypass Switch", "RIN12 PGA"},
850 {"ROMIX", "ROMIX Right ADC Bypass Switch", "AIRNMUX"},
851 {"ROMIX", "ROMIX Left ADC Bypass Switch", "AILNMUX"},
852 {"ROMIX", "ROMIX Right DAC Switch", "Right DAC"},
853
854 /* SPKMIX */
855 {"SPKMIX", "SPKMIX LIN2 Bypass Switch", "LIN2"},
856 {"SPKMIX", "SPKMIX RIN2 Bypass Switch", "RIN2"},
857 {"SPKMIX", "SPKMIX LADC Bypass Switch", "AILNMUX"},
858 {"SPKMIX", "SPKMIX RADC Bypass Switch", "AIRNMUX"},
859 {"SPKMIX", "SPKMIX Left Mixer PGA Switch", "LOPGA"},
860 {"SPKMIX", "SPKMIX Right Mixer PGA Switch", "ROPGA"},
861 {"SPKMIX", "SPKMIX Right DAC Switch", "Right DAC"},
862 {"SPKMIX", "SPKMIX Left DAC Switch", "Right DAC"},
863
864 /* LONMIX */
865 {"LONMIX", "LONMIX Left Mixer PGA Switch", "LOPGA"},
866 {"LONMIX", "LONMIX Right Mixer PGA Switch", "ROPGA"},
867 {"LONMIX", "LONMIX Inverted LOP Switch", "LOPMIX"},
868
869 /* LOPMIX */
870 {"LOPMIX", "LOPMIX Right Mic Bypass Switch", "RIN12 PGA"},
871 {"LOPMIX", "LOPMIX Left Mic Bypass Switch", "LIN12 PGA"},
872 {"LOPMIX", "LOPMIX Left Mixer PGA Switch", "LOPGA"},
873
874 /* OUT3MIX */
875 {"OUT3MIX", "OUT3MIX LIN4/RXP Bypass Switch", "LIN4/RXN"},
876 {"OUT3MIX", "OUT3MIX Left Out PGA Switch", "LOPGA"},
877
878 /* OUT4MIX */
879 {"OUT4MIX", "OUT4MIX Right Out PGA Switch", "ROPGA"},
880 {"OUT4MIX", "OUT4MIX RIN4/RXP Bypass Switch", "RIN4/RXP"},
881
882 /* RONMIX */
883 {"RONMIX", "RONMIX Right Mixer PGA Switch", "ROPGA"},
884 {"RONMIX", "RONMIX Left Mixer PGA Switch", "LOPGA"},
885 {"RONMIX", "RONMIX Inverted ROP Switch", "ROPMIX"},
886
887 /* ROPMIX */
888 {"ROPMIX", "ROPMIX Left Mic Bypass Switch", "LIN12 PGA"},
889 {"ROPMIX", "ROPMIX Right Mic Bypass Switch", "RIN12 PGA"},
890 {"ROPMIX", "ROPMIX Right Mixer PGA Switch", "ROPGA"},
891
892 /* Out Mixer PGAs */
893 {"LOPGA", NULL, "LOMIX"},
894 {"ROPGA", NULL, "ROMIX"},
895
896 {"LOUT PGA", NULL, "LOMIX"},
897 {"ROUT PGA", NULL, "ROMIX"},
898
899 /* Output Pins */
900 {"LON", NULL, "LONMIX"},
901 {"LOP", NULL, "LOPMIX"},
902 {"OUT3", NULL, "OUT3MIX"},
903 {"LOUT", NULL, "LOUT PGA"},
904 {"SPKN", NULL, "SPKMIX"},
905 {"ROUT", NULL, "ROUT PGA"},
906 {"OUT4", NULL, "OUT4MIX"},
907 {"ROP", NULL, "ROPMIX"},
908 {"RON", NULL, "RONMIX"},
909};
910
911static int wm8400_add_widgets(struct snd_soc_codec *codec)
912{
913 snd_soc_dapm_new_controls(codec, wm8400_dapm_widgets,
914 ARRAY_SIZE(wm8400_dapm_widgets));
915
916 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
917
918 snd_soc_dapm_new_widgets(codec);
919 return 0;
920}
921
922/*
923 * Clock after FLL and dividers
924 */
925static int wm8400_set_dai_sysclk(struct snd_soc_dai *codec_dai,
926 int clk_id, unsigned int freq, int dir)
927{
928 struct snd_soc_codec *codec = codec_dai->codec;
929 struct wm8400_priv *wm8400 = codec->private_data;
930
931 wm8400->sysclk = freq;
932 return 0;
933}
934
935struct fll_factors {
936 u16 n;
937 u16 k;
938 u16 outdiv;
939 u16 fratio;
940 u16 freq_ref;
941};
942
943#define FIXED_FLL_SIZE ((1 << 16) * 10)
944
945static int fll_factors(struct wm8400_priv *wm8400, struct fll_factors *factors,
946 unsigned int Fref, unsigned int Fout)
947{
948 u64 Kpart;
949 unsigned int K, Nmod, target;
950
951 factors->outdiv = 2;
952 while (Fout * factors->outdiv < 90000000 ||
953 Fout * factors->outdiv > 100000000) {
954 factors->outdiv *= 2;
955 if (factors->outdiv > 32) {
956 dev_err(wm8400->wm8400->dev,
957 "Unsupported FLL output frequency %dHz\n",
958 Fout);
959 return -EINVAL;
960 }
961 }
962 target = Fout * factors->outdiv;
963 factors->outdiv = factors->outdiv >> 2;
964
965 if (Fref < 48000)
966 factors->freq_ref = 1;
967 else
968 factors->freq_ref = 0;
969
970 if (Fref < 1000000)
971 factors->fratio = 9;
972 else
973 factors->fratio = 0;
974
975 /* Ensure we have a fractional part */
976 do {
977 if (Fref < 1000000)
978 factors->fratio--;
979 else
980 factors->fratio++;
981
982 if (factors->fratio < 1 || factors->fratio > 8) {
983 dev_err(wm8400->wm8400->dev,
984 "Unable to calculate FRATIO\n");
985 return -EINVAL;
986 }
987
988 factors->n = target / (Fref * factors->fratio);
989 Nmod = target % (Fref * factors->fratio);
990 } while (Nmod == 0);
991
992 /* Calculate fractional part - scale up so we can round. */
993 Kpart = FIXED_FLL_SIZE * (long long)Nmod;
994
995 do_div(Kpart, (Fref * factors->fratio));
996
997 K = Kpart & 0xFFFFFFFF;
998
999 if ((K % 10) >= 5)
1000 K += 5;
1001
1002 /* Move down to proper range now rounding is done */
1003 factors->k = K / 10;
1004
1005 dev_dbg(wm8400->wm8400->dev,
1006 "FLL: Fref=%d Fout=%d N=%x K=%x, FRATIO=%x OUTDIV=%x\n",
1007 Fref, Fout,
1008 factors->n, factors->k, factors->fratio, factors->outdiv);
1009
1010 return 0;
1011}
1012
1013static int wm8400_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
1014 unsigned int freq_in, unsigned int freq_out)
1015{
1016 struct snd_soc_codec *codec = codec_dai->codec;
1017 struct wm8400_priv *wm8400 = codec->private_data;
1018 struct fll_factors factors;
1019 int ret;
1020 u16 reg;
1021
1022 if (freq_in == wm8400->fll_in && freq_out == wm8400->fll_out)
1023 return 0;
1024
1025 if (freq_out != 0) {
1026 ret = fll_factors(wm8400, &factors, freq_in, freq_out);
1027 if (ret != 0)
1028 return ret;
1029 }
1030
1031 wm8400->fll_out = freq_out;
1032 wm8400->fll_in = freq_in;
1033
1034 /* We *must* disable the FLL before any changes */
1035 reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_2);
1036 reg &= ~WM8400_FLL_ENA;
1037 wm8400_write(codec, WM8400_POWER_MANAGEMENT_2, reg);
1038
1039 reg = wm8400_read(codec, WM8400_FLL_CONTROL_1);
1040 reg &= ~WM8400_FLL_OSC_ENA;
1041 wm8400_write(codec, WM8400_FLL_CONTROL_1, reg);
1042
1043 if (freq_out == 0)
1044 return 0;
1045
1046 reg &= ~(WM8400_FLL_REF_FREQ | WM8400_FLL_FRATIO_MASK);
1047 reg |= WM8400_FLL_FRAC | factors.fratio;
1048 reg |= factors.freq_ref << WM8400_FLL_REF_FREQ_SHIFT;
1049 wm8400_write(codec, WM8400_FLL_CONTROL_1, reg);
1050
1051 wm8400_write(codec, WM8400_FLL_CONTROL_2, factors.k);
1052 wm8400_write(codec, WM8400_FLL_CONTROL_3, factors.n);
1053
1054 reg = wm8400_read(codec, WM8400_FLL_CONTROL_4);
1055 reg &= WM8400_FLL_OUTDIV_MASK;
1056 reg |= factors.outdiv;
1057 wm8400_write(codec, WM8400_FLL_CONTROL_4, reg);
1058
1059 return 0;
1060}
1061
1062/*
1063 * Sets ADC and Voice DAC format.
1064 */
1065static int wm8400_set_dai_fmt(struct snd_soc_dai *codec_dai,
1066 unsigned int fmt)
1067{
1068 struct snd_soc_codec *codec = codec_dai->codec;
1069 u16 audio1, audio3;
1070
1071 audio1 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_1);
1072 audio3 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_3);
1073
1074 /* set master/slave audio interface */
1075 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
1076 case SND_SOC_DAIFMT_CBS_CFS:
1077 audio3 &= ~WM8400_AIF_MSTR1;
1078 break;
1079 case SND_SOC_DAIFMT_CBM_CFM:
1080 audio3 |= WM8400_AIF_MSTR1;
1081 break;
1082 default:
1083 return -EINVAL;
1084 }
1085
1086 audio1 &= ~WM8400_AIF_FMT_MASK;
1087
1088 /* interface format */
1089 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
1090 case SND_SOC_DAIFMT_I2S:
1091 audio1 |= WM8400_AIF_FMT_I2S;
1092 audio1 &= ~WM8400_AIF_LRCLK_INV;
1093 break;
1094 case SND_SOC_DAIFMT_RIGHT_J:
1095 audio1 |= WM8400_AIF_FMT_RIGHTJ;
1096 audio1 &= ~WM8400_AIF_LRCLK_INV;
1097 break;
1098 case SND_SOC_DAIFMT_LEFT_J:
1099 audio1 |= WM8400_AIF_FMT_LEFTJ;
1100 audio1 &= ~WM8400_AIF_LRCLK_INV;
1101 break;
1102 case SND_SOC_DAIFMT_DSP_A:
1103 audio1 |= WM8400_AIF_FMT_DSP;
1104 audio1 &= ~WM8400_AIF_LRCLK_INV;
1105 break;
1106 case SND_SOC_DAIFMT_DSP_B:
1107 audio1 |= WM8400_AIF_FMT_DSP | WM8400_AIF_LRCLK_INV;
1108 break;
1109 default:
1110 return -EINVAL;
1111 }
1112
1113 wm8400_write(codec, WM8400_AUDIO_INTERFACE_1, audio1);
1114 wm8400_write(codec, WM8400_AUDIO_INTERFACE_3, audio3);
1115 return 0;
1116}
1117
1118static int wm8400_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
1119 int div_id, int div)
1120{
1121 struct snd_soc_codec *codec = codec_dai->codec;
1122 u16 reg;
1123
1124 switch (div_id) {
1125 case WM8400_MCLK_DIV:
1126 reg = wm8400_read(codec, WM8400_CLOCKING_2) &
1127 ~WM8400_MCLK_DIV_MASK;
1128 wm8400_write(codec, WM8400_CLOCKING_2, reg | div);
1129 break;
1130 case WM8400_DACCLK_DIV:
1131 reg = wm8400_read(codec, WM8400_CLOCKING_2) &
1132 ~WM8400_DAC_CLKDIV_MASK;
1133 wm8400_write(codec, WM8400_CLOCKING_2, reg | div);
1134 break;
1135 case WM8400_ADCCLK_DIV:
1136 reg = wm8400_read(codec, WM8400_CLOCKING_2) &
1137 ~WM8400_ADC_CLKDIV_MASK;
1138 wm8400_write(codec, WM8400_CLOCKING_2, reg | div);
1139 break;
1140 case WM8400_BCLK_DIV:
1141 reg = wm8400_read(codec, WM8400_CLOCKING_1) &
1142 ~WM8400_BCLK_DIV_MASK;
1143 wm8400_write(codec, WM8400_CLOCKING_1, reg | div);
1144 break;
1145 default:
1146 return -EINVAL;
1147 }
1148
1149 return 0;
1150}
1151
1152/*
1153 * Set PCM DAI bit size and sample rate.
1154 */
1155static int wm8400_hw_params(struct snd_pcm_substream *substream,
1156 struct snd_pcm_hw_params *params,
1157 struct snd_soc_dai *dai)
1158{
1159 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1160 struct snd_soc_device *socdev = rtd->socdev;
1161 struct snd_soc_codec *codec = socdev->card->codec;
1162 u16 audio1 = wm8400_read(codec, WM8400_AUDIO_INTERFACE_1);
1163
1164 audio1 &= ~WM8400_AIF_WL_MASK;
1165 /* bit size */
1166 switch (params_format(params)) {
1167 case SNDRV_PCM_FORMAT_S16_LE:
1168 break;
1169 case SNDRV_PCM_FORMAT_S20_3LE:
1170 audio1 |= WM8400_AIF_WL_20BITS;
1171 break;
1172 case SNDRV_PCM_FORMAT_S24_LE:
1173 audio1 |= WM8400_AIF_WL_24BITS;
1174 break;
1175 case SNDRV_PCM_FORMAT_S32_LE:
1176 audio1 |= WM8400_AIF_WL_32BITS;
1177 break;
1178 }
1179
1180 wm8400_write(codec, WM8400_AUDIO_INTERFACE_1, audio1);
1181 return 0;
1182}
1183
1184static int wm8400_mute(struct snd_soc_dai *dai, int mute)
1185{
1186 struct snd_soc_codec *codec = dai->codec;
1187 u16 val = wm8400_read(codec, WM8400_DAC_CTRL) & ~WM8400_DAC_MUTE;
1188
1189 if (mute)
1190 wm8400_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE);
1191 else
1192 wm8400_write(codec, WM8400_DAC_CTRL, val);
1193
1194 return 0;
1195}
1196
1197/* TODO: set bias for best performance at standby */
1198static int wm8400_set_bias_level(struct snd_soc_codec *codec,
1199 enum snd_soc_bias_level level)
1200{
1201 struct wm8400_priv *wm8400 = codec->private_data;
1202 u16 val;
1203 int ret;
1204
1205 switch (level) {
1206 case SND_SOC_BIAS_ON:
1207 break;
1208
1209 case SND_SOC_BIAS_PREPARE:
1210 /* VMID=2*50k */
1211 val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1) &
1212 ~WM8400_VMID_MODE_MASK;
1213 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x2);
1214 break;
1215
1216 case SND_SOC_BIAS_STANDBY:
1217 if (codec->bias_level == SND_SOC_BIAS_OFF) {
1218 ret = regulator_bulk_enable(ARRAY_SIZE(power),
1219 &power[0]);
1220 if (ret != 0) {
1221 dev_err(wm8400->wm8400->dev,
1222 "Failed to enable regulators: %d\n",
1223 ret);
1224 return ret;
1225 }
1226
1227 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1,
1228 WM8400_CODEC_ENA | WM8400_SYSCLK_ENA);
1229
1230 /* Enable POBCTRL, SOFT_ST, VMIDTOG and BUFDCOPEN */
1231 wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
1232 WM8400_BUFDCOPEN | WM8400_POBCTRL);
1233
1234 msleep(50);
1235
1236 /* Enable VREF & VMID at 2x50k */
1237 val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1);
1238 val |= 0x2 | WM8400_VREF_ENA;
1239 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val);
1240
1241 /* Enable BUFIOEN */
1242 wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
1243 WM8400_BUFDCOPEN | WM8400_POBCTRL |
1244 WM8400_BUFIOEN);
1245
1246 /* disable POBCTRL, SOFT_ST and BUFDCOPEN */
1247 wm8400_write(codec, WM8400_ANTIPOP2, WM8400_BUFIOEN);
1248 }
1249
1250 /* VMID=2*300k */
1251 val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1) &
1252 ~WM8400_VMID_MODE_MASK;
1253 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val | 0x4);
1254 break;
1255
1256 case SND_SOC_BIAS_OFF:
1257 /* Enable POBCTRL and SOFT_ST */
1258 wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
1259 WM8400_POBCTRL | WM8400_BUFIOEN);
1260
1261 /* Enable POBCTRL, SOFT_ST and BUFDCOPEN */
1262 wm8400_write(codec, WM8400_ANTIPOP2, WM8400_SOFTST |
1263 WM8400_BUFDCOPEN | WM8400_POBCTRL |
1264 WM8400_BUFIOEN);
1265
1266 /* mute DAC */
1267 val = wm8400_read(codec, WM8400_DAC_CTRL);
1268 wm8400_write(codec, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE);
1269
1270 /* Enable any disabled outputs */
1271 val = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1);
1272 val |= WM8400_SPK_ENA | WM8400_OUT3_ENA |
1273 WM8400_OUT4_ENA | WM8400_LOUT_ENA |
1274 WM8400_ROUT_ENA;
1275 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val);
1276
1277 /* Disable VMID */
1278 val &= ~WM8400_VMID_MODE_MASK;
1279 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val);
1280
1281 msleep(300);
1282
1283 /* Enable all output discharge bits */
1284 wm8400_write(codec, WM8400_ANTIPOP1, WM8400_DIS_LLINE |
1285 WM8400_DIS_RLINE | WM8400_DIS_OUT3 |
1286 WM8400_DIS_OUT4 | WM8400_DIS_LOUT |
1287 WM8400_DIS_ROUT);
1288
1289 /* Disable VREF */
1290 val &= ~WM8400_VREF_ENA;
1291 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, val);
1292
1293 /* disable POBCTRL, SOFT_ST and BUFDCOPEN */
1294 wm8400_write(codec, WM8400_ANTIPOP2, 0x0);
1295
1296 ret = regulator_bulk_disable(ARRAY_SIZE(power),
1297 &power[0]);
1298 if (ret != 0)
1299 return ret;
1300
1301 break;
1302 }
1303
1304 codec->bias_level = level;
1305 return 0;
1306}
1307
1308#define WM8400_RATES SNDRV_PCM_RATE_8000_96000
1309
1310#define WM8400_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
1311 SNDRV_PCM_FMTBIT_S24_LE)
1312
1313static struct snd_soc_dai_ops wm8400_dai_ops = {
1314 .hw_params = wm8400_hw_params,
1315 .digital_mute = wm8400_mute,
1316 .set_fmt = wm8400_set_dai_fmt,
1317 .set_clkdiv = wm8400_set_dai_clkdiv,
1318 .set_sysclk = wm8400_set_dai_sysclk,
1319 .set_pll = wm8400_set_dai_pll,
1320};
1321
1322/*
1323 * The WM8400 supports 2 different and mutually exclusive DAI
1324 * configurations.
1325 *
1326 * 1. ADC/DAC on Primary Interface
1327 * 2. ADC on Primary Interface/DAC on secondary
1328 */
1329struct snd_soc_dai wm8400_dai = {
1330/* ADC/DAC on primary */
1331 .name = "WM8400 ADC/DAC Primary",
1332 .id = 1,
1333 .playback = {
1334 .stream_name = "Playback",
1335 .channels_min = 1,
1336 .channels_max = 2,
1337 .rates = WM8400_RATES,
1338 .formats = WM8400_FORMATS,
1339 },
1340 .capture = {
1341 .stream_name = "Capture",
1342 .channels_min = 1,
1343 .channels_max = 2,
1344 .rates = WM8400_RATES,
1345 .formats = WM8400_FORMATS,
1346 },
1347 .ops = &wm8400_dai_ops,
1348};
1349EXPORT_SYMBOL_GPL(wm8400_dai);
1350
1351static int wm8400_suspend(struct platform_device *pdev, pm_message_t state)
1352{
1353 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1354 struct snd_soc_codec *codec = socdev->card->codec;
1355
1356 wm8400_set_bias_level(codec, SND_SOC_BIAS_OFF);
1357
1358 return 0;
1359}
1360
1361static int wm8400_resume(struct platform_device *pdev)
1362{
1363 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1364 struct snd_soc_codec *codec = socdev->card->codec;
1365
1366 wm8400_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1367
1368 return 0;
1369}
1370
1371static struct snd_soc_codec *wm8400_codec;
1372
1373static int wm8400_probe(struct platform_device *pdev)
1374{
1375 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1376 struct snd_soc_codec *codec;
1377 int ret;
1378
1379 if (!wm8400_codec) {
1380 dev_err(&pdev->dev, "wm8400 not yet discovered\n");
1381 return -ENODEV;
1382 }
1383 codec = wm8400_codec;
1384
1385 socdev->card->codec = codec;
1386
1387 /* register pcms */
1388 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
1389 if (ret < 0) {
1390 dev_err(&pdev->dev, "failed to create pcms\n");
1391 goto pcm_err;
1392 }
1393
1394 wm8400_add_controls(codec);
1395 wm8400_add_widgets(codec);
1396
1397 ret = snd_soc_init_card(socdev);
1398 if (ret < 0) {
1399 dev_err(&pdev->dev, "failed to register card\n");
1400 goto card_err;
1401 }
1402
1403 return ret;
1404
1405card_err:
1406 snd_soc_free_pcms(socdev);
1407 snd_soc_dapm_free(socdev);
1408pcm_err:
1409 return ret;
1410}
1411
1412/* power down chip */
1413static int wm8400_remove(struct platform_device *pdev)
1414{
1415 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1416
1417 snd_soc_free_pcms(socdev);
1418 snd_soc_dapm_free(socdev);
1419
1420 return 0;
1421}
1422
1423struct snd_soc_codec_device soc_codec_dev_wm8400 = {
1424 .probe = wm8400_probe,
1425 .remove = wm8400_remove,
1426 .suspend = wm8400_suspend,
1427 .resume = wm8400_resume,
1428};
1429
1430static void wm8400_probe_deferred(struct work_struct *work)
1431{
1432 struct wm8400_priv *priv = container_of(work, struct wm8400_priv,
1433 work);
1434 struct snd_soc_codec *codec = &priv->codec;
1435 int ret;
1436
1437 /* charge output caps */
1438 wm8400_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1439
1440 /* We're done, tell the subsystem. */
1441 ret = snd_soc_register_codec(codec);
1442 if (ret != 0) {
1443 dev_err(priv->wm8400->dev,
1444 "Failed to register codec: %d\n", ret);
1445 goto err;
1446 }
1447
1448 ret = snd_soc_register_dai(&wm8400_dai);
1449 if (ret != 0) {
1450 dev_err(priv->wm8400->dev,
1451 "Failed to register DAI: %d\n", ret);
1452 goto err_codec;
1453 }
1454
1455 return;
1456
1457err_codec:
1458 snd_soc_unregister_codec(codec);
1459err:
1460 wm8400_set_bias_level(codec, SND_SOC_BIAS_OFF);
1461}
1462
1463static int wm8400_codec_probe(struct platform_device *dev)
1464{
1465 struct wm8400_priv *priv;
1466 int ret;
1467 u16 reg;
1468 struct snd_soc_codec *codec;
1469
1470 priv = kzalloc(sizeof(struct wm8400_priv), GFP_KERNEL);
1471 if (priv == NULL)
1472 return -ENOMEM;
1473
1474 codec = &priv->codec;
1475 codec->private_data = priv;
1476 codec->control_data = dev->dev.driver_data;
1477 priv->wm8400 = dev->dev.driver_data;
1478
1479 ret = regulator_bulk_get(priv->wm8400->dev,
1480 ARRAY_SIZE(power), &power[0]);
1481 if (ret != 0) {
1482 dev_err(&dev->dev, "Failed to get regulators: %d\n", ret);
1483 goto err;
1484 }
1485
1486 codec->dev = &dev->dev;
1487 wm8400_dai.dev = &dev->dev;
1488
1489 codec->name = "WM8400";
1490 codec->owner = THIS_MODULE;
1491 codec->read = wm8400_read;
1492 codec->write = wm8400_write;
1493 codec->bias_level = SND_SOC_BIAS_OFF;
1494 codec->set_bias_level = wm8400_set_bias_level;
1495 codec->dai = &wm8400_dai;
1496 codec->num_dai = 1;
1497 codec->reg_cache_size = WM8400_REGISTER_COUNT;
1498 mutex_init(&codec->mutex);
1499 INIT_LIST_HEAD(&codec->dapm_widgets);
1500 INIT_LIST_HEAD(&codec->dapm_paths);
1501 INIT_WORK(&priv->work, wm8400_probe_deferred);
1502
1503 wm8400_codec_reset(codec);
1504
1505 reg = wm8400_read(codec, WM8400_POWER_MANAGEMENT_1);
1506 wm8400_write(codec, WM8400_POWER_MANAGEMENT_1, reg | WM8400_CODEC_ENA);
1507
1508 /* Latch volume update bits */
1509 reg = wm8400_read(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME);
1510 wm8400_write(codec, WM8400_LEFT_LINE_INPUT_1_2_VOLUME,
1511 reg & WM8400_IPVU);
1512 reg = wm8400_read(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME);
1513 wm8400_write(codec, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME,
1514 reg & WM8400_IPVU);
1515
1516 wm8400_write(codec, WM8400_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8));
1517 wm8400_write(codec, WM8400_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8));
1518
1519 wm8400_codec = codec;
1520
1521 if (!schedule_work(&priv->work)) {
1522 ret = -EINVAL;
1523 goto err_regulator;
1524 }
1525
1526 return 0;
1527
1528err_regulator:
1529 wm8400_codec = NULL;
1530 regulator_bulk_free(ARRAY_SIZE(power), power);
1531err:
1532 kfree(priv);
1533 return ret;
1534}
1535
1536static int __exit wm8400_codec_remove(struct platform_device *dev)
1537{
1538 struct wm8400_priv *priv = wm8400_codec->private_data;
1539 u16 reg;
1540
1541 snd_soc_unregister_dai(&wm8400_dai);
1542 snd_soc_unregister_codec(wm8400_codec);
1543
1544 reg = wm8400_read(wm8400_codec, WM8400_POWER_MANAGEMENT_1);
1545 wm8400_write(wm8400_codec, WM8400_POWER_MANAGEMENT_1,
1546 reg & (~WM8400_CODEC_ENA));
1547
1548 regulator_bulk_free(ARRAY_SIZE(power), power);
1549 kfree(priv);
1550
1551 wm8400_codec = NULL;
1552
1553 return 0;
1554}
1555
1556static struct platform_driver wm8400_codec_driver = {
1557 .driver = {
1558 .name = "wm8400-codec",
1559 .owner = THIS_MODULE,
1560 },
1561 .probe = wm8400_codec_probe,
1562 .remove = __exit_p(wm8400_codec_remove),
1563};
1564
1565static int __init wm8400_codec_init(void)
1566{
1567 return platform_driver_register(&wm8400_codec_driver);
1568}
1569module_init(wm8400_codec_init);
1570
1571static void __exit wm8400_codec_exit(void)
1572{
1573 platform_driver_unregister(&wm8400_codec_driver);
1574}
1575module_exit(wm8400_codec_exit);
1576
1577EXPORT_SYMBOL_GPL(soc_codec_dev_wm8400);
1578
1579MODULE_DESCRIPTION("ASoC WM8400 driver");
1580MODULE_AUTHOR("Mark Brown");
1581MODULE_LICENSE("GPL");
1582MODULE_ALIAS("platform:wm8400-codec");
diff --git a/sound/soc/codecs/wm8400.h b/sound/soc/codecs/wm8400.h
new file mode 100644
index 000000000000..79c5934d4776
--- /dev/null
+++ b/sound/soc/codecs/wm8400.h
@@ -0,0 +1,62 @@
1/*
2 * wm8400.h -- audio driver for WM8400
3 *
4 * Copyright 2008 Wolfson Microelectronics PLC.
5 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
13
14#ifndef _WM8400_CODEC_H
15#define _WM8400_CODEC_H
16
17#define WM8400_MCLK_DIV 0
18#define WM8400_DACCLK_DIV 1
19#define WM8400_ADCCLK_DIV 2
20#define WM8400_BCLK_DIV 3
21
22#define WM8400_MCLK_DIV_1 0x400
23#define WM8400_MCLK_DIV_2 0x800
24
25#define WM8400_DAC_CLKDIV_1 0x00
26#define WM8400_DAC_CLKDIV_1_5 0x04
27#define WM8400_DAC_CLKDIV_2 0x08
28#define WM8400_DAC_CLKDIV_3 0x0c
29#define WM8400_DAC_CLKDIV_4 0x10
30#define WM8400_DAC_CLKDIV_5_5 0x14
31#define WM8400_DAC_CLKDIV_6 0x18
32
33#define WM8400_ADC_CLKDIV_1 0x00
34#define WM8400_ADC_CLKDIV_1_5 0x20
35#define WM8400_ADC_CLKDIV_2 0x40
36#define WM8400_ADC_CLKDIV_3 0x60
37#define WM8400_ADC_CLKDIV_4 0x80
38#define WM8400_ADC_CLKDIV_5_5 0xa0
39#define WM8400_ADC_CLKDIV_6 0xc0
40
41
42#define WM8400_BCLK_DIV_1 (0x0 << 1)
43#define WM8400_BCLK_DIV_1_5 (0x1 << 1)
44#define WM8400_BCLK_DIV_2 (0x2 << 1)
45#define WM8400_BCLK_DIV_3 (0x3 << 1)
46#define WM8400_BCLK_DIV_4 (0x4 << 1)
47#define WM8400_BCLK_DIV_5_5 (0x5 << 1)
48#define WM8400_BCLK_DIV_6 (0x6 << 1)
49#define WM8400_BCLK_DIV_8 (0x7 << 1)
50#define WM8400_BCLK_DIV_11 (0x8 << 1)
51#define WM8400_BCLK_DIV_12 (0x9 << 1)
52#define WM8400_BCLK_DIV_16 (0xA << 1)
53#define WM8400_BCLK_DIV_22 (0xB << 1)
54#define WM8400_BCLK_DIV_24 (0xC << 1)
55#define WM8400_BCLK_DIV_32 (0xD << 1)
56#define WM8400_BCLK_DIV_44 (0xE << 1)
57#define WM8400_BCLK_DIV_48 (0xF << 1)
58
59extern struct snd_soc_dai wm8400_dai;
60extern struct snd_soc_codec_device soc_codec_dev_wm8400;
61
62#endif
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c
index 40f8238df717..6a4cea09c45d 100644
--- a/sound/soc/codecs/wm8510.c
+++ b/sound/soc/codecs/wm8510.c
@@ -171,22 +171,6 @@ SOC_SINGLE("Capture Boost(+20dB)", WM8510_ADCBOOST, 8, 1, 0),
171SOC_SINGLE("Mono Playback Switch", WM8510_MONOMIX, 6, 1, 1), 171SOC_SINGLE("Mono Playback Switch", WM8510_MONOMIX, 6, 1, 1),
172}; 172};
173 173
174/* add non dapm controls */
175static int wm8510_add_controls(struct snd_soc_codec *codec)
176{
177 int err, i;
178
179 for (i = 0; i < ARRAY_SIZE(wm8510_snd_controls); i++) {
180 err = snd_ctl_add(codec->card,
181 snd_soc_cnew(&wm8510_snd_controls[i], codec,
182 NULL));
183 if (err < 0)
184 return err;
185 }
186
187 return 0;
188}
189
190/* Speaker Output Mixer */ 174/* Speaker Output Mixer */
191static const struct snd_kcontrol_new wm8510_speaker_mixer_controls[] = { 175static const struct snd_kcontrol_new wm8510_speaker_mixer_controls[] = {
192SOC_DAPM_SINGLE("Line Bypass Switch", WM8510_SPKMIX, 1, 1, 0), 176SOC_DAPM_SINGLE("Line Bypass Switch", WM8510_SPKMIX, 1, 1, 0),
@@ -352,7 +336,7 @@ static int wm8510_set_dai_pll(struct snd_soc_dai *codec_dai,
352 return 0; 336 return 0;
353 } 337 }
354 338
355 pll_factors(freq_out*8, freq_in); 339 pll_factors(freq_out*4, freq_in);
356 340
357 wm8510_write(codec, WM8510_PLLN, (pll_div.pre_div << 4) | pll_div.n); 341 wm8510_write(codec, WM8510_PLLN, (pll_div.pre_div << 4) | pll_div.n);
358 wm8510_write(codec, WM8510_PLLK1, pll_div.k >> 18); 342 wm8510_write(codec, WM8510_PLLK1, pll_div.k >> 18);
@@ -383,7 +367,7 @@ static int wm8510_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
383 wm8510_write(codec, WM8510_GPIO, reg | div); 367 wm8510_write(codec, WM8510_GPIO, reg | div);
384 break; 368 break;
385 case WM8510_MCLKDIV: 369 case WM8510_MCLKDIV:
386 reg = wm8510_read_reg_cache(codec, WM8510_CLOCK) & 0x1f; 370 reg = wm8510_read_reg_cache(codec, WM8510_CLOCK) & 0x11f;
387 wm8510_write(codec, WM8510_CLOCK, reg | div); 371 wm8510_write(codec, WM8510_CLOCK, reg | div);
388 break; 372 break;
389 case WM8510_ADCCLK: 373 case WM8510_ADCCLK:
@@ -468,7 +452,7 @@ static int wm8510_pcm_hw_params(struct snd_pcm_substream *substream,
468{ 452{
469 struct snd_soc_pcm_runtime *rtd = substream->private_data; 453 struct snd_soc_pcm_runtime *rtd = substream->private_data;
470 struct snd_soc_device *socdev = rtd->socdev; 454 struct snd_soc_device *socdev = rtd->socdev;
471 struct snd_soc_codec *codec = socdev->codec; 455 struct snd_soc_codec *codec = socdev->card->codec;
472 u16 iface = wm8510_read_reg_cache(codec, WM8510_IFACE) & 0x19f; 456 u16 iface = wm8510_read_reg_cache(codec, WM8510_IFACE) & 0x19f;
473 u16 adn = wm8510_read_reg_cache(codec, WM8510_ADD) & 0x1f1; 457 u16 adn = wm8510_read_reg_cache(codec, WM8510_ADD) & 0x1f1;
474 458
@@ -570,6 +554,14 @@ static int wm8510_set_bias_level(struct snd_soc_codec *codec,
570#define WM8510_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 554#define WM8510_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
571 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 555 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
572 556
557static struct snd_soc_dai_ops wm8510_dai_ops = {
558 .hw_params = wm8510_pcm_hw_params,
559 .digital_mute = wm8510_mute,
560 .set_fmt = wm8510_set_dai_fmt,
561 .set_clkdiv = wm8510_set_dai_clkdiv,
562 .set_pll = wm8510_set_dai_pll,
563};
564
573struct snd_soc_dai wm8510_dai = { 565struct snd_soc_dai wm8510_dai = {
574 .name = "WM8510 HiFi", 566 .name = "WM8510 HiFi",
575 .playback = { 567 .playback = {
@@ -584,20 +576,14 @@ struct snd_soc_dai wm8510_dai = {
584 .channels_max = 2, 576 .channels_max = 2,
585 .rates = WM8510_RATES, 577 .rates = WM8510_RATES,
586 .formats = WM8510_FORMATS,}, 578 .formats = WM8510_FORMATS,},
587 .ops = { 579 .ops = &wm8510_dai_ops,
588 .hw_params = wm8510_pcm_hw_params,
589 .digital_mute = wm8510_mute,
590 .set_fmt = wm8510_set_dai_fmt,
591 .set_clkdiv = wm8510_set_dai_clkdiv,
592 .set_pll = wm8510_set_dai_pll,
593 },
594}; 580};
595EXPORT_SYMBOL_GPL(wm8510_dai); 581EXPORT_SYMBOL_GPL(wm8510_dai);
596 582
597static int wm8510_suspend(struct platform_device *pdev, pm_message_t state) 583static int wm8510_suspend(struct platform_device *pdev, pm_message_t state)
598{ 584{
599 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 585 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
600 struct snd_soc_codec *codec = socdev->codec; 586 struct snd_soc_codec *codec = socdev->card->codec;
601 587
602 wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF); 588 wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF);
603 return 0; 589 return 0;
@@ -606,7 +592,7 @@ static int wm8510_suspend(struct platform_device *pdev, pm_message_t state)
606static int wm8510_resume(struct platform_device *pdev) 592static int wm8510_resume(struct platform_device *pdev)
607{ 593{
608 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 594 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
609 struct snd_soc_codec *codec = socdev->codec; 595 struct snd_soc_codec *codec = socdev->card->codec;
610 int i; 596 int i;
611 u8 data[2]; 597 u8 data[2];
612 u16 *cache = codec->reg_cache; 598 u16 *cache = codec->reg_cache;
@@ -628,7 +614,7 @@ static int wm8510_resume(struct platform_device *pdev)
628 */ 614 */
629static int wm8510_init(struct snd_soc_device *socdev) 615static int wm8510_init(struct snd_soc_device *socdev)
630{ 616{
631 struct snd_soc_codec *codec = socdev->codec; 617 struct snd_soc_codec *codec = socdev->card->codec;
632 int ret = 0; 618 int ret = 0;
633 619
634 codec->name = "WM8510"; 620 codec->name = "WM8510";
@@ -656,7 +642,8 @@ static int wm8510_init(struct snd_soc_device *socdev)
656 /* power on device */ 642 /* power on device */
657 codec->bias_level = SND_SOC_BIAS_OFF; 643 codec->bias_level = SND_SOC_BIAS_OFF;
658 wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 644 wm8510_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
659 wm8510_add_controls(codec); 645 snd_soc_add_controls(codec, wm8510_snd_controls,
646 ARRAY_SIZE(wm8510_snd_controls));
660 wm8510_add_widgets(codec); 647 wm8510_add_widgets(codec);
661 ret = snd_soc_init_card(socdev); 648 ret = snd_soc_init_card(socdev);
662 if (ret < 0) { 649 if (ret < 0) {
@@ -685,7 +672,7 @@ static int wm8510_i2c_probe(struct i2c_client *i2c,
685 const struct i2c_device_id *id) 672 const struct i2c_device_id *id)
686{ 673{
687 struct snd_soc_device *socdev = wm8510_socdev; 674 struct snd_soc_device *socdev = wm8510_socdev;
688 struct snd_soc_codec *codec = socdev->codec; 675 struct snd_soc_codec *codec = socdev->card->codec;
689 int ret; 676 int ret;
690 677
691 i2c_set_clientdata(i2c, codec); 678 i2c_set_clientdata(i2c, codec);
@@ -766,7 +753,7 @@ err_driver:
766static int __devinit wm8510_spi_probe(struct spi_device *spi) 753static int __devinit wm8510_spi_probe(struct spi_device *spi)
767{ 754{
768 struct snd_soc_device *socdev = wm8510_socdev; 755 struct snd_soc_device *socdev = wm8510_socdev;
769 struct snd_soc_codec *codec = socdev->codec; 756 struct snd_soc_codec *codec = socdev->card->codec;
770 int ret; 757 int ret;
771 758
772 codec->control_data = spi; 759 codec->control_data = spi;
@@ -832,7 +819,7 @@ static int wm8510_probe(struct platform_device *pdev)
832 if (codec == NULL) 819 if (codec == NULL)
833 return -ENOMEM; 820 return -ENOMEM;
834 821
835 socdev->codec = codec; 822 socdev->card->codec = codec;
836 mutex_init(&codec->mutex); 823 mutex_init(&codec->mutex);
837 INIT_LIST_HEAD(&codec->dapm_widgets); 824 INIT_LIST_HEAD(&codec->dapm_widgets);
838 INIT_LIST_HEAD(&codec->dapm_paths); 825 INIT_LIST_HEAD(&codec->dapm_paths);
@@ -862,7 +849,7 @@ static int wm8510_probe(struct platform_device *pdev)
862static int wm8510_remove(struct platform_device *pdev) 849static int wm8510_remove(struct platform_device *pdev)
863{ 850{
864 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 851 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
865 struct snd_soc_codec *codec = socdev->codec; 852 struct snd_soc_codec *codec = socdev->card->codec;
866 853
867 if (codec->control_data) 854 if (codec->control_data)
868 wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF); 855 wm8510_set_bias_level(codec, SND_SOC_BIAS_OFF);
diff --git a/sound/soc/codecs/wm8580.c b/sound/soc/codecs/wm8580.c
index d004e5845298..442ea6f160fc 100644
--- a/sound/soc/codecs/wm8580.c
+++ b/sound/soc/codecs/wm8580.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * wm8580.c -- WM8580 ALSA Soc Audio driver 2 * wm8580.c -- WM8580 ALSA Soc Audio driver
3 * 3 *
4 * Copyright 2008 Wolfson Microelectronics PLC. 4 * Copyright 2008, 2009 Wolfson Microelectronics PLC.
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify it 6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the 7 * under the terms of the GNU General Public License as published by the
@@ -35,19 +35,6 @@
35 35
36#include "wm8580.h" 36#include "wm8580.h"
37 37
38#define WM8580_VERSION "0.1"
39
40struct pll_state {
41 unsigned int in;
42 unsigned int out;
43};
44
45/* codec private data */
46struct wm8580_priv {
47 struct pll_state a;
48 struct pll_state b;
49};
50
51/* WM8580 register space */ 38/* WM8580 register space */
52#define WM8580_PLLA1 0x00 39#define WM8580_PLLA1 0x00
53#define WM8580_PLLA2 0x01 40#define WM8580_PLLA2 0x01
@@ -102,6 +89,8 @@ struct wm8580_priv {
102#define WM8580_READBACK 0x34 89#define WM8580_READBACK 0x34
103#define WM8580_RESET 0x35 90#define WM8580_RESET 0x35
104 91
92#define WM8580_MAX_REGISTER 0x35
93
105/* PLLB4 (register 7h) */ 94/* PLLB4 (register 7h) */
106#define WM8580_PLLB4_MCLKOUTSRC_MASK 0x60 95#define WM8580_PLLB4_MCLKOUTSRC_MASK 0x60
107#define WM8580_PLLB4_MCLKOUTSRC_PLLA 0x20 96#define WM8580_PLLB4_MCLKOUTSRC_PLLA 0x20
@@ -193,6 +182,20 @@ static const u16 wm8580_reg[] = {
193 0x0000, 0x0000 /*R53*/ 182 0x0000, 0x0000 /*R53*/
194}; 183};
195 184
185struct pll_state {
186 unsigned int in;
187 unsigned int out;
188};
189
190/* codec private data */
191struct wm8580_priv {
192 struct snd_soc_codec codec;
193 u16 reg_cache[WM8580_MAX_REGISTER + 1];
194 struct pll_state a;
195 struct pll_state b;
196};
197
198
196/* 199/*
197 * read wm8580 register cache 200 * read wm8580 register cache
198 */ 201 */
@@ -200,7 +203,7 @@ static inline unsigned int wm8580_read_reg_cache(struct snd_soc_codec *codec,
200 unsigned int reg) 203 unsigned int reg)
201{ 204{
202 u16 *cache = codec->reg_cache; 205 u16 *cache = codec->reg_cache;
203 BUG_ON(reg > ARRAY_SIZE(wm8580_reg)); 206 BUG_ON(reg >= ARRAY_SIZE(wm8580_reg));
204 return cache[reg]; 207 return cache[reg];
205} 208}
206 209
@@ -223,7 +226,7 @@ static int wm8580_write(struct snd_soc_codec *codec, unsigned int reg,
223{ 226{
224 u8 data[2]; 227 u8 data[2];
225 228
226 BUG_ON(reg > ARRAY_SIZE(wm8580_reg)); 229 BUG_ON(reg >= ARRAY_SIZE(wm8580_reg));
227 230
228 /* Registers are 9 bits wide */ 231 /* Registers are 9 bits wide */
229 value &= 0x1ff; 232 value &= 0x1ff;
@@ -330,20 +333,6 @@ SOC_DOUBLE("ADC Mute Switch", WM8580_ADC_CONTROL1, 0, 1, 1, 0),
330SOC_SINGLE("ADC High-Pass Filter Switch", WM8580_ADC_CONTROL1, 4, 1, 0), 333SOC_SINGLE("ADC High-Pass Filter Switch", WM8580_ADC_CONTROL1, 4, 1, 0),
331}; 334};
332 335
333/* Add non-DAPM controls */
334static int wm8580_add_controls(struct snd_soc_codec *codec)
335{
336 int err, i;
337
338 for (i = 0; i < ARRAY_SIZE(wm8580_snd_controls); i++) {
339 err = snd_ctl_add(codec->card,
340 snd_soc_cnew(&wm8580_snd_controls[i],
341 codec, NULL));
342 if (err < 0)
343 return err;
344 }
345 return 0;
346}
347static const struct snd_soc_dapm_widget wm8580_dapm_widgets[] = { 336static const struct snd_soc_dapm_widget wm8580_dapm_widgets[] = {
348SND_SOC_DAPM_DAC("DAC1", "Playback", WM8580_PWRDN1, 2, 1), 337SND_SOC_DAPM_DAC("DAC1", "Playback", WM8580_PWRDN1, 2, 1),
349SND_SOC_DAPM_DAC("DAC2", "Playback", WM8580_PWRDN1, 3, 1), 338SND_SOC_DAPM_DAC("DAC2", "Playback", WM8580_PWRDN1, 3, 1),
@@ -553,7 +542,7 @@ static int wm8580_paif_hw_params(struct snd_pcm_substream *substream,
553{ 542{
554 struct snd_soc_pcm_runtime *rtd = substream->private_data; 543 struct snd_soc_pcm_runtime *rtd = substream->private_data;
555 struct snd_soc_device *socdev = rtd->socdev; 544 struct snd_soc_device *socdev = rtd->socdev;
556 struct snd_soc_codec *codec = socdev->codec; 545 struct snd_soc_codec *codec = socdev->card->codec;
557 u16 paifb = wm8580_read(codec, WM8580_PAIF3 + dai->id); 546 u16 paifb = wm8580_read(codec, WM8580_PAIF3 + dai->id);
558 547
559 paifb &= ~WM8580_AIF_LENGTH_MASK; 548 paifb &= ~WM8580_AIF_LENGTH_MASK;
@@ -771,8 +760,22 @@ static int wm8580_set_bias_level(struct snd_soc_codec *codec,
771 switch (level) { 760 switch (level) {
772 case SND_SOC_BIAS_ON: 761 case SND_SOC_BIAS_ON:
773 case SND_SOC_BIAS_PREPARE: 762 case SND_SOC_BIAS_PREPARE:
763 break;
764
774 case SND_SOC_BIAS_STANDBY: 765 case SND_SOC_BIAS_STANDBY:
766 if (codec->bias_level == SND_SOC_BIAS_OFF) {
767 /* Power up and get individual control of the DACs */
768 reg = wm8580_read(codec, WM8580_PWRDN1);
769 reg &= ~(WM8580_PWRDN1_PWDN | WM8580_PWRDN1_ALLDACPD);
770 wm8580_write(codec, WM8580_PWRDN1, reg);
771
772 /* Make VMID high impedence */
773 reg = wm8580_read(codec, WM8580_ADC_CONTROL1);
774 reg &= ~0x100;
775 wm8580_write(codec, WM8580_ADC_CONTROL1, reg);
776 }
775 break; 777 break;
778
776 case SND_SOC_BIAS_OFF: 779 case SND_SOC_BIAS_OFF:
777 reg = wm8580_read(codec, WM8580_PWRDN1); 780 reg = wm8580_read(codec, WM8580_PWRDN1);
778 wm8580_write(codec, WM8580_PWRDN1, reg | WM8580_PWRDN1_PWDN); 781 wm8580_write(codec, WM8580_PWRDN1, reg | WM8580_PWRDN1_PWDN);
@@ -785,6 +788,21 @@ static int wm8580_set_bias_level(struct snd_soc_codec *codec,
785#define WM8580_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 788#define WM8580_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
786 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE) 789 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
787 790
791static struct snd_soc_dai_ops wm8580_dai_ops_playback = {
792 .hw_params = wm8580_paif_hw_params,
793 .set_fmt = wm8580_set_paif_dai_fmt,
794 .set_clkdiv = wm8580_set_dai_clkdiv,
795 .set_pll = wm8580_set_dai_pll,
796 .digital_mute = wm8580_digital_mute,
797};
798
799static struct snd_soc_dai_ops wm8580_dai_ops_capture = {
800 .hw_params = wm8580_paif_hw_params,
801 .set_fmt = wm8580_set_paif_dai_fmt,
802 .set_clkdiv = wm8580_set_dai_clkdiv,
803 .set_pll = wm8580_set_dai_pll,
804};
805
788struct snd_soc_dai wm8580_dai[] = { 806struct snd_soc_dai wm8580_dai[] = {
789 { 807 {
790 .name = "WM8580 PAIFRX", 808 .name = "WM8580 PAIFRX",
@@ -796,13 +814,7 @@ struct snd_soc_dai wm8580_dai[] = {
796 .rates = SNDRV_PCM_RATE_8000_192000, 814 .rates = SNDRV_PCM_RATE_8000_192000,
797 .formats = WM8580_FORMATS, 815 .formats = WM8580_FORMATS,
798 }, 816 },
799 .ops = { 817 .ops = &wm8580_dai_ops_playback,
800 .hw_params = wm8580_paif_hw_params,
801 .set_fmt = wm8580_set_paif_dai_fmt,
802 .set_clkdiv = wm8580_set_dai_clkdiv,
803 .set_pll = wm8580_set_dai_pll,
804 .digital_mute = wm8580_digital_mute,
805 },
806 }, 818 },
807 { 819 {
808 .name = "WM8580 PAIFTX", 820 .name = "WM8580 PAIFTX",
@@ -814,109 +826,168 @@ struct snd_soc_dai wm8580_dai[] = {
814 .rates = SNDRV_PCM_RATE_8000_192000, 826 .rates = SNDRV_PCM_RATE_8000_192000,
815 .formats = WM8580_FORMATS, 827 .formats = WM8580_FORMATS,
816 }, 828 },
817 .ops = { 829 .ops = &wm8580_dai_ops_capture,
818 .hw_params = wm8580_paif_hw_params,
819 .set_fmt = wm8580_set_paif_dai_fmt,
820 .set_clkdiv = wm8580_set_dai_clkdiv,
821 .set_pll = wm8580_set_dai_pll,
822 },
823 }, 830 },
824}; 831};
825EXPORT_SYMBOL_GPL(wm8580_dai); 832EXPORT_SYMBOL_GPL(wm8580_dai);
826 833
827/* 834static struct snd_soc_codec *wm8580_codec;
828 * initialise the WM8580 driver 835
829 * register the mixer and dsp interfaces with the kernel 836static int wm8580_probe(struct platform_device *pdev)
830 */
831static int wm8580_init(struct snd_soc_device *socdev)
832{ 837{
833 struct snd_soc_codec *codec = socdev->codec; 838 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
839 struct snd_soc_codec *codec;
834 int ret = 0; 840 int ret = 0;
835 841
836 codec->name = "WM8580"; 842 if (wm8580_codec == NULL) {
837 codec->owner = THIS_MODULE; 843 dev_err(&pdev->dev, "Codec device not registered\n");
838 codec->read = wm8580_read_reg_cache; 844 return -ENODEV;
839 codec->write = wm8580_write; 845 }
840 codec->set_bias_level = wm8580_set_bias_level;
841 codec->dai = wm8580_dai;
842 codec->num_dai = ARRAY_SIZE(wm8580_dai);
843 codec->reg_cache_size = ARRAY_SIZE(wm8580_reg);
844 codec->reg_cache = kmemdup(wm8580_reg, sizeof(wm8580_reg),
845 GFP_KERNEL);
846
847 if (codec->reg_cache == NULL)
848 return -ENOMEM;
849
850 /* Get the codec into a known state */
851 wm8580_write(codec, WM8580_RESET, 0);
852
853 /* Power up and get individual control of the DACs */
854 wm8580_write(codec, WM8580_PWRDN1, wm8580_read(codec, WM8580_PWRDN1) &
855 ~(WM8580_PWRDN1_PWDN | WM8580_PWRDN1_ALLDACPD));
856 846
857 /* Make VMID high impedence */ 847 socdev->card->codec = wm8580_codec;
858 wm8580_write(codec, WM8580_ADC_CONTROL1, 848 codec = wm8580_codec;
859 wm8580_read(codec, WM8580_ADC_CONTROL1) & ~0x100);
860 849
861 /* register pcms */ 850 /* register pcms */
862 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, 851 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
863 SNDRV_DEFAULT_STR1);
864 if (ret < 0) { 852 if (ret < 0) {
865 printk(KERN_ERR "wm8580: failed to create pcms\n"); 853 dev_err(codec->dev, "failed to create pcms: %d\n", ret);
866 goto pcm_err; 854 goto pcm_err;
867 } 855 }
868 856
869 wm8580_add_controls(codec); 857 snd_soc_add_controls(codec, wm8580_snd_controls,
858 ARRAY_SIZE(wm8580_snd_controls));
870 wm8580_add_widgets(codec); 859 wm8580_add_widgets(codec);
871
872 ret = snd_soc_init_card(socdev); 860 ret = snd_soc_init_card(socdev);
873 if (ret < 0) { 861 if (ret < 0) {
874 printk(KERN_ERR "wm8580: failed to register card\n"); 862 dev_err(codec->dev, "failed to register card: %d\n", ret);
875 goto card_err; 863 goto card_err;
876 } 864 }
865
877 return ret; 866 return ret;
878 867
879card_err: 868card_err:
880 snd_soc_free_pcms(socdev); 869 snd_soc_free_pcms(socdev);
881 snd_soc_dapm_free(socdev); 870 snd_soc_dapm_free(socdev);
882pcm_err: 871pcm_err:
883 kfree(codec->reg_cache);
884 return ret; 872 return ret;
885} 873}
886 874
887/* If the i2c layer weren't so broken, we could pass this kind of data 875/* power down chip */
888 around */ 876static int wm8580_remove(struct platform_device *pdev)
889static struct snd_soc_device *wm8580_socdev; 877{
878 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
879
880 snd_soc_free_pcms(socdev);
881 snd_soc_dapm_free(socdev);
890 882
891#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 883 return 0;
884}
892 885
893/* 886struct snd_soc_codec_device soc_codec_dev_wm8580 = {
894 * WM8580 2 wire address is determined by GPIO5 887 .probe = wm8580_probe,
895 * state during powerup. 888 .remove = wm8580_remove,
896 * low = 0x1a 889};
897 * high = 0x1b 890EXPORT_SYMBOL_GPL(soc_codec_dev_wm8580);
898 */ 891
892static int wm8580_register(struct wm8580_priv *wm8580)
893{
894 int ret, i;
895 struct snd_soc_codec *codec = &wm8580->codec;
896
897 if (wm8580_codec) {
898 dev_err(codec->dev, "Another WM8580 is registered\n");
899 ret = -EINVAL;
900 goto err;
901 }
902
903 mutex_init(&codec->mutex);
904 INIT_LIST_HEAD(&codec->dapm_widgets);
905 INIT_LIST_HEAD(&codec->dapm_paths);
899 906
907 codec->private_data = wm8580;
908 codec->name = "WM8580";
909 codec->owner = THIS_MODULE;
910 codec->read = wm8580_read_reg_cache;
911 codec->write = wm8580_write;
912 codec->bias_level = SND_SOC_BIAS_OFF;
913 codec->set_bias_level = wm8580_set_bias_level;
914 codec->dai = wm8580_dai;
915 codec->num_dai = ARRAY_SIZE(wm8580_dai);
916 codec->reg_cache_size = ARRAY_SIZE(wm8580->reg_cache);
917 codec->reg_cache = &wm8580->reg_cache;
918
919 memcpy(codec->reg_cache, wm8580_reg, sizeof(wm8580_reg));
920
921 /* Get the codec into a known state */
922 ret = wm8580_write(codec, WM8580_RESET, 0);
923 if (ret != 0) {
924 dev_err(codec->dev, "Failed to reset codec: %d\n", ret);
925 goto err;
926 }
927
928 for (i = 0; i < ARRAY_SIZE(wm8580_dai); i++)
929 wm8580_dai[i].dev = codec->dev;
930
931 wm8580_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
932
933 wm8580_codec = codec;
934
935 ret = snd_soc_register_codec(codec);
936 if (ret != 0) {
937 dev_err(codec->dev, "Failed to register codec: %d\n", ret);
938 goto err;
939 }
940
941 ret = snd_soc_register_dais(wm8580_dai, ARRAY_SIZE(wm8580_dai));
942 if (ret != 0) {
943 dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
944 goto err_codec;
945 }
946
947 return 0;
948
949err_codec:
950 snd_soc_unregister_codec(codec);
951err:
952 kfree(wm8580);
953 return ret;
954}
955
956static void wm8580_unregister(struct wm8580_priv *wm8580)
957{
958 wm8580_set_bias_level(&wm8580->codec, SND_SOC_BIAS_OFF);
959 snd_soc_unregister_dais(wm8580_dai, ARRAY_SIZE(wm8580_dai));
960 snd_soc_unregister_codec(&wm8580->codec);
961 kfree(wm8580);
962 wm8580_codec = NULL;
963}
964
965#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
900static int wm8580_i2c_probe(struct i2c_client *i2c, 966static int wm8580_i2c_probe(struct i2c_client *i2c,
901 const struct i2c_device_id *id) 967 const struct i2c_device_id *id)
902{ 968{
903 struct snd_soc_device *socdev = wm8580_socdev; 969 struct wm8580_priv *wm8580;
904 struct snd_soc_codec *codec = socdev->codec; 970 struct snd_soc_codec *codec;
905 int ret;
906 971
907 i2c_set_clientdata(i2c, codec); 972 wm8580 = kzalloc(sizeof(struct wm8580_priv), GFP_KERNEL);
973 if (wm8580 == NULL)
974 return -ENOMEM;
975
976 codec = &wm8580->codec;
977 codec->hw_write = (hw_write_t)i2c_master_send;
978
979 i2c_set_clientdata(i2c, wm8580);
908 codec->control_data = i2c; 980 codec->control_data = i2c;
909 981
910 ret = wm8580_init(socdev); 982 codec->dev = &i2c->dev;
911 if (ret < 0) 983
912 dev_err(&i2c->dev, "failed to initialise WM8580\n"); 984 return wm8580_register(wm8580);
913 return ret;
914} 985}
915 986
916static int wm8580_i2c_remove(struct i2c_client *client) 987static int wm8580_i2c_remove(struct i2c_client *client)
917{ 988{
918 struct snd_soc_codec *codec = i2c_get_clientdata(client); 989 struct wm8580_priv *wm8580 = i2c_get_clientdata(client);
919 kfree(codec->reg_cache); 990 wm8580_unregister(wm8580);
920 return 0; 991 return 0;
921} 992}
922 993
@@ -928,129 +999,35 @@ MODULE_DEVICE_TABLE(i2c, wm8580_i2c_id);
928 999
929static struct i2c_driver wm8580_i2c_driver = { 1000static struct i2c_driver wm8580_i2c_driver = {
930 .driver = { 1001 .driver = {
931 .name = "WM8580 I2C Codec", 1002 .name = "wm8580",
932 .owner = THIS_MODULE, 1003 .owner = THIS_MODULE,
933 }, 1004 },
934 .probe = wm8580_i2c_probe, 1005 .probe = wm8580_i2c_probe,
935 .remove = wm8580_i2c_remove, 1006 .remove = wm8580_i2c_remove,
936 .id_table = wm8580_i2c_id, 1007 .id_table = wm8580_i2c_id,
937}; 1008};
1009#endif
938 1010
939static int wm8580_add_i2c_device(struct platform_device *pdev, 1011static int __init wm8580_modinit(void)
940 const struct wm8580_setup_data *setup)
941{ 1012{
942 struct i2c_board_info info;
943 struct i2c_adapter *adapter;
944 struct i2c_client *client;
945 int ret; 1013 int ret;
946 1014
1015#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
947 ret = i2c_add_driver(&wm8580_i2c_driver); 1016 ret = i2c_add_driver(&wm8580_i2c_driver);
948 if (ret != 0) { 1017 if (ret != 0) {
949 dev_err(&pdev->dev, "can't add i2c driver\n"); 1018 pr_err("Failed to register WM8580 I2C driver: %d\n", ret);
950 return ret;
951 }
952
953 memset(&info, 0, sizeof(struct i2c_board_info));
954 info.addr = setup->i2c_address;
955 strlcpy(info.type, "wm8580", I2C_NAME_SIZE);
956
957 adapter = i2c_get_adapter(setup->i2c_bus);
958 if (!adapter) {
959 dev_err(&pdev->dev, "can't get i2c adapter %d\n",
960 setup->i2c_bus);
961 goto err_driver;
962 }
963
964 client = i2c_new_device(adapter, &info);
965 i2c_put_adapter(adapter);
966 if (!client) {
967 dev_err(&pdev->dev, "can't add i2c device at 0x%x\n",
968 (unsigned int)info.addr);
969 goto err_driver;
970 } 1019 }
971
972 return 0;
973
974err_driver:
975 i2c_del_driver(&wm8580_i2c_driver);
976 return -ENODEV;
977}
978#endif 1020#endif
979 1021
980static int wm8580_probe(struct platform_device *pdev)
981{
982 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
983 struct wm8580_setup_data *setup;
984 struct snd_soc_codec *codec;
985 struct wm8580_priv *wm8580;
986 int ret = 0;
987
988 pr_info("WM8580 Audio Codec %s\n", WM8580_VERSION);
989
990 setup = socdev->codec_data;
991 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
992 if (codec == NULL)
993 return -ENOMEM;
994
995 wm8580 = kzalloc(sizeof(struct wm8580_priv), GFP_KERNEL);
996 if (wm8580 == NULL) {
997 kfree(codec);
998 return -ENOMEM;
999 }
1000
1001 codec->private_data = wm8580;
1002 socdev->codec = codec;
1003 mutex_init(&codec->mutex);
1004 INIT_LIST_HEAD(&codec->dapm_widgets);
1005 INIT_LIST_HEAD(&codec->dapm_paths);
1006 wm8580_socdev = socdev;
1007
1008#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1009 if (setup->i2c_address) {
1010 codec->hw_write = (hw_write_t)i2c_master_send;
1011 ret = wm8580_add_i2c_device(pdev, setup);
1012 }
1013#else
1014 /* Add other interfaces here */
1015#endif
1016 return ret;
1017}
1018
1019/* power down chip */
1020static int wm8580_remove(struct platform_device *pdev)
1021{
1022 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1023 struct snd_soc_codec *codec = socdev->codec;
1024
1025 if (codec->control_data)
1026 wm8580_set_bias_level(codec, SND_SOC_BIAS_OFF);
1027 snd_soc_free_pcms(socdev);
1028 snd_soc_dapm_free(socdev);
1029#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1030 i2c_unregister_device(codec->control_data);
1031 i2c_del_driver(&wm8580_i2c_driver);
1032#endif
1033 kfree(codec->private_data);
1034 kfree(codec);
1035
1036 return 0; 1022 return 0;
1037} 1023}
1038
1039struct snd_soc_codec_device soc_codec_dev_wm8580 = {
1040 .probe = wm8580_probe,
1041 .remove = wm8580_remove,
1042};
1043EXPORT_SYMBOL_GPL(soc_codec_dev_wm8580);
1044
1045static int __init wm8580_modinit(void)
1046{
1047 return snd_soc_register_dais(wm8580_dai, ARRAY_SIZE(wm8580_dai));
1048}
1049module_init(wm8580_modinit); 1024module_init(wm8580_modinit);
1050 1025
1051static void __exit wm8580_exit(void) 1026static void __exit wm8580_exit(void)
1052{ 1027{
1053 snd_soc_unregister_dais(wm8580_dai, ARRAY_SIZE(wm8580_dai)); 1028#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1029 i2c_del_driver(&wm8580_i2c_driver);
1030#endif
1054} 1031}
1055module_exit(wm8580_exit); 1032module_exit(wm8580_exit);
1056 1033
diff --git a/sound/soc/codecs/wm8580.h b/sound/soc/codecs/wm8580.h
index 09e4422f6f2f..0dfb5ddde6a2 100644
--- a/sound/soc/codecs/wm8580.h
+++ b/sound/soc/codecs/wm8580.h
@@ -28,11 +28,6 @@
28#define WM8580_CLKSRC_OSC 4 28#define WM8580_CLKSRC_OSC 4
29#define WM8580_CLKSRC_NONE 5 29#define WM8580_CLKSRC_NONE 5
30 30
31struct wm8580_setup_data {
32 int i2c_bus;
33 unsigned short i2c_address;
34};
35
36#define WM8580_DAI_PAIFRX 0 31#define WM8580_DAI_PAIFRX 0
37#define WM8580_DAI_PAIFTX 1 32#define WM8580_DAI_PAIFTX 1
38 33
diff --git a/sound/soc/codecs/wm8728.c b/sound/soc/codecs/wm8728.c
index 80b11983e137..e7ff2121ede9 100644
--- a/sound/soc/codecs/wm8728.c
+++ b/sound/soc/codecs/wm8728.c
@@ -47,7 +47,7 @@ static inline unsigned int wm8728_read_reg_cache(struct snd_soc_codec *codec,
47 unsigned int reg) 47 unsigned int reg)
48{ 48{
49 u16 *cache = codec->reg_cache; 49 u16 *cache = codec->reg_cache;
50 BUG_ON(reg > ARRAY_SIZE(wm8728_reg_defaults)); 50 BUG_ON(reg >= ARRAY_SIZE(wm8728_reg_defaults));
51 return cache[reg]; 51 return cache[reg];
52} 52}
53 53
@@ -55,7 +55,7 @@ static inline void wm8728_write_reg_cache(struct snd_soc_codec *codec,
55 u16 reg, unsigned int value) 55 u16 reg, unsigned int value)
56{ 56{
57 u16 *cache = codec->reg_cache; 57 u16 *cache = codec->reg_cache;
58 BUG_ON(reg > ARRAY_SIZE(wm8728_reg_defaults)); 58 BUG_ON(reg >= ARRAY_SIZE(wm8728_reg_defaults));
59 cache[reg] = value; 59 cache[reg] = value;
60} 60}
61 61
@@ -92,21 +92,6 @@ SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8728_DACLVOL, WM8728_DACRVOL,
92SOC_SINGLE("Deemphasis", WM8728_DACCTL, 1, 1, 0), 92SOC_SINGLE("Deemphasis", WM8728_DACCTL, 1, 1, 0),
93}; 93};
94 94
95static int wm8728_add_controls(struct snd_soc_codec *codec)
96{
97 int err, i;
98
99 for (i = 0; i < ARRAY_SIZE(wm8728_snd_controls); i++) {
100 err = snd_ctl_add(codec->card,
101 snd_soc_cnew(&wm8728_snd_controls[i],
102 codec, NULL));
103 if (err < 0)
104 return err;
105 }
106
107 return 0;
108}
109
110/* 95/*
111 * DAPM controls. 96 * DAPM controls.
112 */ 97 */
@@ -152,7 +137,7 @@ static int wm8728_hw_params(struct snd_pcm_substream *substream,
152{ 137{
153 struct snd_soc_pcm_runtime *rtd = substream->private_data; 138 struct snd_soc_pcm_runtime *rtd = substream->private_data;
154 struct snd_soc_device *socdev = rtd->socdev; 139 struct snd_soc_device *socdev = rtd->socdev;
155 struct snd_soc_codec *codec = socdev->codec; 140 struct snd_soc_codec *codec = socdev->card->codec;
156 u16 dac = wm8728_read_reg_cache(codec, WM8728_DACCTL); 141 u16 dac = wm8728_read_reg_cache(codec, WM8728_DACCTL);
157 142
158 dac &= ~0x18; 143 dac &= ~0x18;
@@ -259,6 +244,12 @@ static int wm8728_set_bias_level(struct snd_soc_codec *codec,
259#define WM8728_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 244#define WM8728_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
260 SNDRV_PCM_FMTBIT_S24_LE) 245 SNDRV_PCM_FMTBIT_S24_LE)
261 246
247static struct snd_soc_dai_ops wm8728_dai_ops = {
248 .hw_params = wm8728_hw_params,
249 .digital_mute = wm8728_mute,
250 .set_fmt = wm8728_set_dai_fmt,
251};
252
262struct snd_soc_dai wm8728_dai = { 253struct snd_soc_dai wm8728_dai = {
263 .name = "WM8728", 254 .name = "WM8728",
264 .playback = { 255 .playback = {
@@ -268,18 +259,14 @@ struct snd_soc_dai wm8728_dai = {
268 .rates = WM8728_RATES, 259 .rates = WM8728_RATES,
269 .formats = WM8728_FORMATS, 260 .formats = WM8728_FORMATS,
270 }, 261 },
271 .ops = { 262 .ops = &wm8728_dai_ops,
272 .hw_params = wm8728_hw_params,
273 .digital_mute = wm8728_mute,
274 .set_fmt = wm8728_set_dai_fmt,
275 }
276}; 263};
277EXPORT_SYMBOL_GPL(wm8728_dai); 264EXPORT_SYMBOL_GPL(wm8728_dai);
278 265
279static int wm8728_suspend(struct platform_device *pdev, pm_message_t state) 266static int wm8728_suspend(struct platform_device *pdev, pm_message_t state)
280{ 267{
281 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 268 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
282 struct snd_soc_codec *codec = socdev->codec; 269 struct snd_soc_codec *codec = socdev->card->codec;
283 270
284 wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); 271 wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF);
285 272
@@ -289,7 +276,7 @@ static int wm8728_suspend(struct platform_device *pdev, pm_message_t state)
289static int wm8728_resume(struct platform_device *pdev) 276static int wm8728_resume(struct platform_device *pdev)
290{ 277{
291 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 278 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
292 struct snd_soc_codec *codec = socdev->codec; 279 struct snd_soc_codec *codec = socdev->card->codec;
293 280
294 wm8728_set_bias_level(codec, codec->suspend_bias_level); 281 wm8728_set_bias_level(codec, codec->suspend_bias_level);
295 282
@@ -302,7 +289,7 @@ static int wm8728_resume(struct platform_device *pdev)
302 */ 289 */
303static int wm8728_init(struct snd_soc_device *socdev) 290static int wm8728_init(struct snd_soc_device *socdev)
304{ 291{
305 struct snd_soc_codec *codec = socdev->codec; 292 struct snd_soc_codec *codec = socdev->card->codec;
306 int ret = 0; 293 int ret = 0;
307 294
308 codec->name = "WM8728"; 295 codec->name = "WM8728";
@@ -330,7 +317,8 @@ static int wm8728_init(struct snd_soc_device *socdev)
330 /* power on device */ 317 /* power on device */
331 wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 318 wm8728_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
332 319
333 wm8728_add_controls(codec); 320 snd_soc_add_controls(codec, wm8728_snd_controls,
321 ARRAY_SIZE(wm8728_snd_controls));
334 wm8728_add_widgets(codec); 322 wm8728_add_widgets(codec);
335 ret = snd_soc_init_card(socdev); 323 ret = snd_soc_init_card(socdev);
336 if (ret < 0) { 324 if (ret < 0) {
@@ -363,7 +351,7 @@ static int wm8728_i2c_probe(struct i2c_client *i2c,
363 const struct i2c_device_id *id) 351 const struct i2c_device_id *id)
364{ 352{
365 struct snd_soc_device *socdev = wm8728_socdev; 353 struct snd_soc_device *socdev = wm8728_socdev;
366 struct snd_soc_codec *codec = socdev->codec; 354 struct snd_soc_codec *codec = socdev->card->codec;
367 int ret; 355 int ret;
368 356
369 i2c_set_clientdata(i2c, codec); 357 i2c_set_clientdata(i2c, codec);
@@ -444,7 +432,7 @@ err_driver:
444static int __devinit wm8728_spi_probe(struct spi_device *spi) 432static int __devinit wm8728_spi_probe(struct spi_device *spi)
445{ 433{
446 struct snd_soc_device *socdev = wm8728_socdev; 434 struct snd_soc_device *socdev = wm8728_socdev;
447 struct snd_soc_codec *codec = socdev->codec; 435 struct snd_soc_codec *codec = socdev->card->codec;
448 int ret; 436 int ret;
449 437
450 codec->control_data = spi; 438 codec->control_data = spi;
@@ -508,7 +496,7 @@ static int wm8728_probe(struct platform_device *pdev)
508 if (codec == NULL) 496 if (codec == NULL)
509 return -ENOMEM; 497 return -ENOMEM;
510 498
511 socdev->codec = codec; 499 socdev->card->codec = codec;
512 mutex_init(&codec->mutex); 500 mutex_init(&codec->mutex);
513 INIT_LIST_HEAD(&codec->dapm_widgets); 501 INIT_LIST_HEAD(&codec->dapm_widgets);
514 INIT_LIST_HEAD(&codec->dapm_paths); 502 INIT_LIST_HEAD(&codec->dapm_paths);
@@ -541,7 +529,7 @@ static int wm8728_probe(struct platform_device *pdev)
541static int wm8728_remove(struct platform_device *pdev) 529static int wm8728_remove(struct platform_device *pdev)
542{ 530{
543 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 531 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
544 struct snd_soc_codec *codec = socdev->codec; 532 struct snd_soc_codec *codec = socdev->card->codec;
545 533
546 if (codec->control_data) 534 if (codec->control_data)
547 wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF); 535 wm8728_set_bias_level(codec, SND_SOC_BIAS_OFF);
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index c444b9f2701e..e043e3f60008 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -29,15 +29,20 @@
29 29
30#include "wm8731.h" 30#include "wm8731.h"
31 31
32#define WM8731_VERSION "0.13" 32static struct snd_soc_codec *wm8731_codec;
33
34struct snd_soc_codec_device soc_codec_dev_wm8731; 33struct snd_soc_codec_device soc_codec_dev_wm8731;
35 34
36/* codec private data */ 35/* codec private data */
37struct wm8731_priv { 36struct wm8731_priv {
37 struct snd_soc_codec codec;
38 u16 reg_cache[WM8731_CACHEREGNUM];
38 unsigned int sysclk; 39 unsigned int sysclk;
39}; 40};
40 41
42#ifdef CONFIG_SPI_MASTER
43static int wm8731_spi_write(struct spi_device *spi, const char *data, int len);
44#endif
45
41/* 46/*
42 * wm8731 register cache 47 * wm8731 register cache
43 * We can't read the WM8731 register space when we are 48 * We can't read the WM8731 register space when we are
@@ -129,22 +134,6 @@ SOC_SINGLE("Store DC Offset Switch", WM8731_APDIGI, 4, 1, 0),
129SOC_ENUM("Playback De-emphasis", wm8731_enum[1]), 134SOC_ENUM("Playback De-emphasis", wm8731_enum[1]),
130}; 135};
131 136
132/* add non dapm controls */
133static int wm8731_add_controls(struct snd_soc_codec *codec)
134{
135 int err, i;
136
137 for (i = 0; i < ARRAY_SIZE(wm8731_snd_controls); i++) {
138 err = snd_ctl_add(codec->card,
139 snd_soc_cnew(&wm8731_snd_controls[i],
140 codec, NULL));
141 if (err < 0)
142 return err;
143 }
144
145 return 0;
146}
147
148/* Output Mixer */ 137/* Output Mixer */
149static const struct snd_kcontrol_new wm8731_output_mixer_controls[] = { 138static const struct snd_kcontrol_new wm8731_output_mixer_controls[] = {
150SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0), 139SOC_DAPM_SINGLE("Line Bypass Switch", WM8731_APANA, 3, 1, 0),
@@ -269,7 +258,7 @@ static int wm8731_hw_params(struct snd_pcm_substream *substream,
269{ 258{
270 struct snd_soc_pcm_runtime *rtd = substream->private_data; 259 struct snd_soc_pcm_runtime *rtd = substream->private_data;
271 struct snd_soc_device *socdev = rtd->socdev; 260 struct snd_soc_device *socdev = rtd->socdev;
272 struct snd_soc_codec *codec = socdev->codec; 261 struct snd_soc_codec *codec = socdev->card->codec;
273 struct wm8731_priv *wm8731 = codec->private_data; 262 struct wm8731_priv *wm8731 = codec->private_data;
274 u16 iface = wm8731_read_reg_cache(codec, WM8731_IFACE) & 0xfff3; 263 u16 iface = wm8731_read_reg_cache(codec, WM8731_IFACE) & 0xfff3;
275 int i = get_coeff(wm8731->sysclk, params_rate(params)); 264 int i = get_coeff(wm8731->sysclk, params_rate(params));
@@ -299,7 +288,7 @@ static int wm8731_pcm_prepare(struct snd_pcm_substream *substream,
299{ 288{
300 struct snd_soc_pcm_runtime *rtd = substream->private_data; 289 struct snd_soc_pcm_runtime *rtd = substream->private_data;
301 struct snd_soc_device *socdev = rtd->socdev; 290 struct snd_soc_device *socdev = rtd->socdev;
302 struct snd_soc_codec *codec = socdev->codec; 291 struct snd_soc_codec *codec = socdev->card->codec;
303 292
304 /* set active */ 293 /* set active */
305 wm8731_write(codec, WM8731_ACTIVE, 0x0001); 294 wm8731_write(codec, WM8731_ACTIVE, 0x0001);
@@ -312,7 +301,7 @@ static void wm8731_shutdown(struct snd_pcm_substream *substream,
312{ 301{
313 struct snd_soc_pcm_runtime *rtd = substream->private_data; 302 struct snd_soc_pcm_runtime *rtd = substream->private_data;
314 struct snd_soc_device *socdev = rtd->socdev; 303 struct snd_soc_device *socdev = rtd->socdev;
315 struct snd_soc_codec *codec = socdev->codec; 304 struct snd_soc_codec *codec = socdev->card->codec;
316 305
317 /* deactivate */ 306 /* deactivate */
318 if (!codec->active) { 307 if (!codec->active) {
@@ -414,21 +403,19 @@ static int wm8731_set_dai_fmt(struct snd_soc_dai *codec_dai,
414static int wm8731_set_bias_level(struct snd_soc_codec *codec, 403static int wm8731_set_bias_level(struct snd_soc_codec *codec,
415 enum snd_soc_bias_level level) 404 enum snd_soc_bias_level level)
416{ 405{
417 u16 reg = wm8731_read_reg_cache(codec, WM8731_PWR) & 0xff7f; 406 u16 reg;
418 407
419 switch (level) { 408 switch (level) {
420 case SND_SOC_BIAS_ON: 409 case SND_SOC_BIAS_ON:
421 /* vref/mid, osc on, dac unmute */
422 wm8731_write(codec, WM8731_PWR, reg);
423 break; 410 break;
424 case SND_SOC_BIAS_PREPARE: 411 case SND_SOC_BIAS_PREPARE:
425 break; 412 break;
426 case SND_SOC_BIAS_STANDBY: 413 case SND_SOC_BIAS_STANDBY:
427 /* everything off except vref/vmid, */ 414 /* Clear PWROFF, gate CLKOUT, everything else as-is */
415 reg = wm8731_read_reg_cache(codec, WM8731_PWR) & 0xff7f;
428 wm8731_write(codec, WM8731_PWR, reg | 0x0040); 416 wm8731_write(codec, WM8731_PWR, reg | 0x0040);
429 break; 417 break;
430 case SND_SOC_BIAS_OFF: 418 case SND_SOC_BIAS_OFF:
431 /* everything off, dac mute, inactive */
432 wm8731_write(codec, WM8731_ACTIVE, 0x0); 419 wm8731_write(codec, WM8731_ACTIVE, 0x0);
433 wm8731_write(codec, WM8731_PWR, 0xffff); 420 wm8731_write(codec, WM8731_PWR, 0xffff);
434 break; 421 break;
@@ -446,6 +433,15 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
446#define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 433#define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
447 SNDRV_PCM_FMTBIT_S24_LE) 434 SNDRV_PCM_FMTBIT_S24_LE)
448 435
436static struct snd_soc_dai_ops wm8731_dai_ops = {
437 .prepare = wm8731_pcm_prepare,
438 .hw_params = wm8731_hw_params,
439 .shutdown = wm8731_shutdown,
440 .digital_mute = wm8731_mute,
441 .set_sysclk = wm8731_set_dai_sysclk,
442 .set_fmt = wm8731_set_dai_fmt,
443};
444
449struct snd_soc_dai wm8731_dai = { 445struct snd_soc_dai wm8731_dai = {
450 .name = "WM8731", 446 .name = "WM8731",
451 .playback = { 447 .playback = {
@@ -460,21 +456,14 @@ struct snd_soc_dai wm8731_dai = {
460 .channels_max = 2, 456 .channels_max = 2,
461 .rates = WM8731_RATES, 457 .rates = WM8731_RATES,
462 .formats = WM8731_FORMATS,}, 458 .formats = WM8731_FORMATS,},
463 .ops = { 459 .ops = &wm8731_dai_ops,
464 .prepare = wm8731_pcm_prepare,
465 .hw_params = wm8731_hw_params,
466 .shutdown = wm8731_shutdown,
467 .digital_mute = wm8731_mute,
468 .set_sysclk = wm8731_set_dai_sysclk,
469 .set_fmt = wm8731_set_dai_fmt,
470 }
471}; 460};
472EXPORT_SYMBOL_GPL(wm8731_dai); 461EXPORT_SYMBOL_GPL(wm8731_dai);
473 462
474static int wm8731_suspend(struct platform_device *pdev, pm_message_t state) 463static int wm8731_suspend(struct platform_device *pdev, pm_message_t state)
475{ 464{
476 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 465 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
477 struct snd_soc_codec *codec = socdev->codec; 466 struct snd_soc_codec *codec = socdev->card->codec;
478 467
479 wm8731_write(codec, WM8731_ACTIVE, 0x0); 468 wm8731_write(codec, WM8731_ACTIVE, 0x0);
480 wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF); 469 wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF);
@@ -484,7 +473,7 @@ static int wm8731_suspend(struct platform_device *pdev, pm_message_t state)
484static int wm8731_resume(struct platform_device *pdev) 473static int wm8731_resume(struct platform_device *pdev)
485{ 474{
486 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 475 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
487 struct snd_soc_codec *codec = socdev->codec; 476 struct snd_soc_codec *codec = socdev->card->codec;
488 int i; 477 int i;
489 u8 data[2]; 478 u8 data[2];
490 u16 *cache = codec->reg_cache; 479 u16 *cache = codec->reg_cache;
@@ -500,54 +489,33 @@ static int wm8731_resume(struct platform_device *pdev)
500 return 0; 489 return 0;
501} 490}
502 491
503/* 492static int wm8731_probe(struct platform_device *pdev)
504 * initialise the WM8731 driver
505 * register the mixer and dsp interfaces with the kernel
506 */
507static int wm8731_init(struct snd_soc_device *socdev)
508{ 493{
509 struct snd_soc_codec *codec = socdev->codec; 494 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
510 int reg, ret = 0; 495 struct snd_soc_codec *codec;
496 int ret = 0;
511 497
512 codec->name = "WM8731"; 498 if (wm8731_codec == NULL) {
513 codec->owner = THIS_MODULE; 499 dev_err(&pdev->dev, "Codec device not registered\n");
514 codec->read = wm8731_read_reg_cache; 500 return -ENODEV;
515 codec->write = wm8731_write; 501 }
516 codec->set_bias_level = wm8731_set_bias_level;
517 codec->dai = &wm8731_dai;
518 codec->num_dai = 1;
519 codec->reg_cache_size = ARRAY_SIZE(wm8731_reg);
520 codec->reg_cache = kmemdup(wm8731_reg, sizeof(wm8731_reg), GFP_KERNEL);
521 if (codec->reg_cache == NULL)
522 return -ENOMEM;
523 502
524 wm8731_reset(codec); 503 socdev->card->codec = wm8731_codec;
504 codec = wm8731_codec;
525 505
526 /* register pcms */ 506 /* register pcms */
527 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 507 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
528 if (ret < 0) { 508 if (ret < 0) {
529 printk(KERN_ERR "wm8731: failed to create pcms\n"); 509 dev_err(codec->dev, "failed to create pcms: %d\n", ret);
530 goto pcm_err; 510 goto pcm_err;
531 } 511 }
532 512
533 /* power on device */ 513 snd_soc_add_controls(codec, wm8731_snd_controls,
534 wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 514 ARRAY_SIZE(wm8731_snd_controls));
535
536 /* set the update bits */
537 reg = wm8731_read_reg_cache(codec, WM8731_LOUT1V);
538 wm8731_write(codec, WM8731_LOUT1V, reg & ~0x0100);
539 reg = wm8731_read_reg_cache(codec, WM8731_ROUT1V);
540 wm8731_write(codec, WM8731_ROUT1V, reg & ~0x0100);
541 reg = wm8731_read_reg_cache(codec, WM8731_LINVOL);
542 wm8731_write(codec, WM8731_LINVOL, reg & ~0x0100);
543 reg = wm8731_read_reg_cache(codec, WM8731_RINVOL);
544 wm8731_write(codec, WM8731_RINVOL, reg & ~0x0100);
545
546 wm8731_add_controls(codec);
547 wm8731_add_widgets(codec); 515 wm8731_add_widgets(codec);
548 ret = snd_soc_init_card(socdev); 516 ret = snd_soc_init_card(socdev);
549 if (ret < 0) { 517 if (ret < 0) {
550 printk(KERN_ERR "wm8731: failed to register card\n"); 518 dev_err(codec->dev, "failed to register card: %d\n", ret);
551 goto card_err; 519 goto card_err;
552 } 520 }
553 521
@@ -557,133 +525,109 @@ card_err:
557 snd_soc_free_pcms(socdev); 525 snd_soc_free_pcms(socdev);
558 snd_soc_dapm_free(socdev); 526 snd_soc_dapm_free(socdev);
559pcm_err: 527pcm_err:
560 kfree(codec->reg_cache);
561 return ret; 528 return ret;
562} 529}
563 530
564static struct snd_soc_device *wm8731_socdev; 531/* power down chip */
565 532static int wm8731_remove(struct platform_device *pdev)
566#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
567
568/*
569 * WM8731 2 wire address is determined by GPIO5
570 * state during powerup.
571 * low = 0x1a
572 * high = 0x1b
573 */
574
575static int wm8731_i2c_probe(struct i2c_client *i2c,
576 const struct i2c_device_id *id)
577{ 533{
578 struct snd_soc_device *socdev = wm8731_socdev; 534 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
579 struct snd_soc_codec *codec = socdev->codec;
580 int ret;
581
582 i2c_set_clientdata(i2c, codec);
583 codec->control_data = i2c;
584
585 ret = wm8731_init(socdev);
586 if (ret < 0)
587 pr_err("failed to initialise WM8731\n");
588 535
589 return ret; 536 snd_soc_free_pcms(socdev);
590} 537 snd_soc_dapm_free(socdev);
591 538
592static int wm8731_i2c_remove(struct i2c_client *client)
593{
594 struct snd_soc_codec *codec = i2c_get_clientdata(client);
595 kfree(codec->reg_cache);
596 return 0; 539 return 0;
597} 540}
598 541
599static const struct i2c_device_id wm8731_i2c_id[] = { 542struct snd_soc_codec_device soc_codec_dev_wm8731 = {
600 { "wm8731", 0 }, 543 .probe = wm8731_probe,
601 { } 544 .remove = wm8731_remove,
602}; 545 .suspend = wm8731_suspend,
603MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id); 546 .resume = wm8731_resume,
604
605static struct i2c_driver wm8731_i2c_driver = {
606 .driver = {
607 .name = "WM8731 I2C Codec",
608 .owner = THIS_MODULE,
609 },
610 .probe = wm8731_i2c_probe,
611 .remove = wm8731_i2c_remove,
612 .id_table = wm8731_i2c_id,
613}; 547};
548EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731);
614 549
615static int wm8731_add_i2c_device(struct platform_device *pdev, 550static int wm8731_register(struct wm8731_priv *wm8731)
616 const struct wm8731_setup_data *setup)
617{ 551{
618 struct i2c_board_info info;
619 struct i2c_adapter *adapter;
620 struct i2c_client *client;
621 int ret; 552 int ret;
553 struct snd_soc_codec *codec = &wm8731->codec;
554 u16 reg;
622 555
623 ret = i2c_add_driver(&wm8731_i2c_driver); 556 if (wm8731_codec) {
624 if (ret != 0) { 557 dev_err(codec->dev, "Another WM8731 is registered\n");
625 dev_err(&pdev->dev, "can't add i2c driver\n"); 558 return -EINVAL;
626 return ret;
627 } 559 }
628 560
629 memset(&info, 0, sizeof(struct i2c_board_info)); 561 mutex_init(&codec->mutex);
630 info.addr = setup->i2c_address; 562 INIT_LIST_HEAD(&codec->dapm_widgets);
631 strlcpy(info.type, "wm8731", I2C_NAME_SIZE); 563 INIT_LIST_HEAD(&codec->dapm_paths);
632 564
633 adapter = i2c_get_adapter(setup->i2c_bus); 565 codec->private_data = wm8731;
634 if (!adapter) { 566 codec->name = "WM8731";
635 dev_err(&pdev->dev, "can't get i2c adapter %d\n", 567 codec->owner = THIS_MODULE;
636 setup->i2c_bus); 568 codec->read = wm8731_read_reg_cache;
637 goto err_driver; 569 codec->write = wm8731_write;
638 } 570 codec->bias_level = SND_SOC_BIAS_OFF;
571 codec->set_bias_level = wm8731_set_bias_level;
572 codec->dai = &wm8731_dai;
573 codec->num_dai = 1;
574 codec->reg_cache_size = WM8731_CACHEREGNUM;
575 codec->reg_cache = &wm8731->reg_cache;
639 576
640 client = i2c_new_device(adapter, &info); 577 memcpy(codec->reg_cache, wm8731_reg, sizeof(wm8731_reg));
641 i2c_put_adapter(adapter); 578
642 if (!client) { 579 ret = wm8731_reset(codec);
643 dev_err(&pdev->dev, "can't add i2c device at 0x%x\n", 580 if (ret < 0) {
644 (unsigned int)info.addr); 581 dev_err(codec->dev, "Failed to issue reset\n");
645 goto err_driver; 582 return ret;
646 } 583 }
647 584
648 return 0; 585 wm8731_dai.dev = codec->dev;
649 586
650err_driver: 587 wm8731_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
651 i2c_del_driver(&wm8731_i2c_driver);
652 return -ENODEV;
653}
654#endif
655 588
656#if defined(CONFIG_SPI_MASTER) 589 /* Latch the update bits */
657static int __devinit wm8731_spi_probe(struct spi_device *spi) 590 reg = wm8731_read_reg_cache(codec, WM8731_LOUT1V);
658{ 591 wm8731_write(codec, WM8731_LOUT1V, reg & ~0x0100);
659 struct snd_soc_device *socdev = wm8731_socdev; 592 reg = wm8731_read_reg_cache(codec, WM8731_ROUT1V);
660 struct snd_soc_codec *codec = socdev->codec; 593 wm8731_write(codec, WM8731_ROUT1V, reg & ~0x0100);
661 int ret; 594 reg = wm8731_read_reg_cache(codec, WM8731_LINVOL);
595 wm8731_write(codec, WM8731_LINVOL, reg & ~0x0100);
596 reg = wm8731_read_reg_cache(codec, WM8731_RINVOL);
597 wm8731_write(codec, WM8731_RINVOL, reg & ~0x0100);
662 598
663 codec->control_data = spi; 599 /* Disable bypass path by default */
600 reg = wm8731_read_reg_cache(codec, WM8731_APANA);
601 wm8731_write(codec, WM8731_APANA, reg & ~0x4);
664 602
665 ret = wm8731_init(socdev); 603 wm8731_codec = codec;
666 if (ret < 0)
667 dev_err(&spi->dev, "failed to initialise WM8731\n");
668 604
669 return ret; 605 ret = snd_soc_register_codec(codec);
670} 606 if (ret != 0) {
607 dev_err(codec->dev, "Failed to register codec: %d\n", ret);
608 return ret;
609 }
610
611 ret = snd_soc_register_dai(&wm8731_dai);
612 if (ret != 0) {
613 dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
614 snd_soc_unregister_codec(codec);
615 return ret;
616 }
671 617
672static int __devexit wm8731_spi_remove(struct spi_device *spi)
673{
674 return 0; 618 return 0;
675} 619}
676 620
677static struct spi_driver wm8731_spi_driver = { 621static void wm8731_unregister(struct wm8731_priv *wm8731)
678 .driver = { 622{
679 .name = "wm8731", 623 wm8731_set_bias_level(&wm8731->codec, SND_SOC_BIAS_OFF);
680 .bus = &spi_bus_type, 624 snd_soc_unregister_dai(&wm8731_dai);
681 .owner = THIS_MODULE, 625 snd_soc_unregister_codec(&wm8731->codec);
682 }, 626 kfree(wm8731);
683 .probe = wm8731_spi_probe, 627 wm8731_codec = NULL;
684 .remove = __devexit_p(wm8731_spi_remove), 628}
685};
686 629
630#if defined(CONFIG_SPI_MASTER)
687static int wm8731_spi_write(struct spi_device *spi, const char *data, int len) 631static int wm8731_spi_write(struct spi_device *spi, const char *data, int len)
688{ 632{
689 struct spi_transfer t; 633 struct spi_transfer t;
@@ -707,101 +651,121 @@ static int wm8731_spi_write(struct spi_device *spi, const char *data, int len)
707 651
708 return len; 652 return len;
709} 653}
710#endif /* CONFIG_SPI_MASTER */
711 654
712static int wm8731_probe(struct platform_device *pdev) 655static int __devinit wm8731_spi_probe(struct spi_device *spi)
713{ 656{
714 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
715 struct wm8731_setup_data *setup;
716 struct snd_soc_codec *codec; 657 struct snd_soc_codec *codec;
717 struct wm8731_priv *wm8731; 658 struct wm8731_priv *wm8731;
718 int ret = 0;
719
720 pr_info("WM8731 Audio Codec %s", WM8731_VERSION);
721
722 setup = socdev->codec_data;
723 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
724 if (codec == NULL)
725 return -ENOMEM;
726 659
727 wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL); 660 wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL);
728 if (wm8731 == NULL) { 661 if (wm8731 == NULL)
729 kfree(codec);
730 return -ENOMEM; 662 return -ENOMEM;
731 }
732 663
733 codec->private_data = wm8731; 664 codec = &wm8731->codec;
734 socdev->codec = codec; 665 codec->control_data = spi;
735 mutex_init(&codec->mutex); 666 codec->hw_write = (hw_write_t)wm8731_spi_write;
736 INIT_LIST_HEAD(&codec->dapm_widgets); 667 codec->dev = &spi->dev;
737 INIT_LIST_HEAD(&codec->dapm_paths);
738 668
739 wm8731_socdev = socdev; 669 spi->dev.driver_data = wm8731;
740 ret = -ENODEV;
741 670
742#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 671 return wm8731_register(wm8731);
743 if (setup->i2c_address) {
744 codec->hw_write = (hw_write_t)i2c_master_send;
745 ret = wm8731_add_i2c_device(pdev, setup);
746 }
747#endif
748#if defined(CONFIG_SPI_MASTER)
749 if (setup->spi) {
750 codec->hw_write = (hw_write_t)wm8731_spi_write;
751 ret = spi_register_driver(&wm8731_spi_driver);
752 if (ret != 0)
753 printk(KERN_ERR "can't add spi driver");
754 }
755#endif
756
757 if (ret != 0) {
758 kfree(codec->private_data);
759 kfree(codec);
760 }
761 return ret;
762} 672}
763 673
764/* power down chip */ 674static int __devexit wm8731_spi_remove(struct spi_device *spi)
765static int wm8731_remove(struct platform_device *pdev)
766{ 675{
767 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 676 struct wm8731_priv *wm8731 = spi->dev.driver_data;
768 struct snd_soc_codec *codec = socdev->codec;
769 677
770 if (codec->control_data) 678 wm8731_unregister(wm8731);
771 wm8731_set_bias_level(codec, SND_SOC_BIAS_OFF); 679
680 return 0;
681}
682
683static struct spi_driver wm8731_spi_driver = {
684 .driver = {
685 .name = "wm8731",
686 .bus = &spi_bus_type,
687 .owner = THIS_MODULE,
688 },
689 .probe = wm8731_spi_probe,
690 .remove = __devexit_p(wm8731_spi_remove),
691};
692#endif /* CONFIG_SPI_MASTER */
772 693
773 snd_soc_free_pcms(socdev);
774 snd_soc_dapm_free(socdev);
775#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 694#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
776 i2c_unregister_device(codec->control_data); 695static __devinit int wm8731_i2c_probe(struct i2c_client *i2c,
777 i2c_del_driver(&wm8731_i2c_driver); 696 const struct i2c_device_id *id)
778#endif 697{
779#if defined(CONFIG_SPI_MASTER) 698 struct wm8731_priv *wm8731;
780 spi_unregister_driver(&wm8731_spi_driver); 699 struct snd_soc_codec *codec;
781#endif 700
782 kfree(codec->private_data); 701 wm8731 = kzalloc(sizeof(struct wm8731_priv), GFP_KERNEL);
783 kfree(codec); 702 if (wm8731 == NULL)
703 return -ENOMEM;
704
705 codec = &wm8731->codec;
706 codec->hw_write = (hw_write_t)i2c_master_send;
784 707
708 i2c_set_clientdata(i2c, wm8731);
709 codec->control_data = i2c;
710
711 codec->dev = &i2c->dev;
712
713 return wm8731_register(wm8731);
714}
715
716static __devexit int wm8731_i2c_remove(struct i2c_client *client)
717{
718 struct wm8731_priv *wm8731 = i2c_get_clientdata(client);
719 wm8731_unregister(wm8731);
785 return 0; 720 return 0;
786} 721}
787 722
788struct snd_soc_codec_device soc_codec_dev_wm8731 = { 723static const struct i2c_device_id wm8731_i2c_id[] = {
789 .probe = wm8731_probe, 724 { "wm8731", 0 },
790 .remove = wm8731_remove, 725 { }
791 .suspend = wm8731_suspend,
792 .resume = wm8731_resume,
793}; 726};
794EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); 727MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id);
728
729static struct i2c_driver wm8731_i2c_driver = {
730 .driver = {
731 .name = "WM8731 I2C Codec",
732 .owner = THIS_MODULE,
733 },
734 .probe = wm8731_i2c_probe,
735 .remove = __devexit_p(wm8731_i2c_remove),
736 .id_table = wm8731_i2c_id,
737};
738#endif
795 739
796static int __init wm8731_modinit(void) 740static int __init wm8731_modinit(void)
797{ 741{
798 return snd_soc_register_dai(&wm8731_dai); 742 int ret;
743#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
744 ret = i2c_add_driver(&wm8731_i2c_driver);
745 if (ret != 0) {
746 printk(KERN_ERR "Failed to register WM8731 I2C driver: %d\n",
747 ret);
748 }
749#endif
750#if defined(CONFIG_SPI_MASTER)
751 ret = spi_register_driver(&wm8731_spi_driver);
752 if (ret != 0) {
753 printk(KERN_ERR "Failed to register WM8731 SPI driver: %d\n",
754 ret);
755 }
756#endif
757 return 0;
799} 758}
800module_init(wm8731_modinit); 759module_init(wm8731_modinit);
801 760
802static void __exit wm8731_exit(void) 761static void __exit wm8731_exit(void)
803{ 762{
804 snd_soc_unregister_dai(&wm8731_dai); 763#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
764 i2c_del_driver(&wm8731_i2c_driver);
765#endif
766#if defined(CONFIG_SPI_MASTER)
767 spi_unregister_driver(&wm8731_spi_driver);
768#endif
805} 769}
806module_exit(wm8731_exit); 770module_exit(wm8731_exit);
807 771
diff --git a/sound/soc/codecs/wm8731.h b/sound/soc/codecs/wm8731.h
index 95190e9c0c14..cd7b806e8ad0 100644
--- a/sound/soc/codecs/wm8731.h
+++ b/sound/soc/codecs/wm8731.h
@@ -34,12 +34,6 @@
34#define WM8731_SYSCLK 0 34#define WM8731_SYSCLK 0
35#define WM8731_DAI 0 35#define WM8731_DAI 0
36 36
37struct wm8731_setup_data {
38 int spi;
39 int i2c_bus;
40 unsigned short i2c_address;
41};
42
43extern struct snd_soc_dai wm8731_dai; 37extern struct snd_soc_dai wm8731_dai;
44extern struct snd_soc_codec_device soc_codec_dev_wm8731; 38extern struct snd_soc_codec_device soc_codec_dev_wm8731;
45 39
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c
index 5997fa68e0d5..b64509b01a49 100644
--- a/sound/soc/codecs/wm8750.c
+++ b/sound/soc/codecs/wm8750.c
@@ -231,21 +231,6 @@ SOC_SINGLE("Mono Playback Volume", WM8750_MOUTV, 0, 127, 0),
231 231
232}; 232};
233 233
234/* add non dapm controls */
235static int wm8750_add_controls(struct snd_soc_codec *codec)
236{
237 int err, i;
238
239 for (i = 0; i < ARRAY_SIZE(wm8750_snd_controls); i++) {
240 err = snd_ctl_add(codec->card,
241 snd_soc_cnew(&wm8750_snd_controls[i],
242 codec, NULL));
243 if (err < 0)
244 return err;
245 }
246 return 0;
247}
248
249/* 234/*
250 * DAPM Controls 235 * DAPM Controls
251 */ 236 */
@@ -619,7 +604,7 @@ static int wm8750_pcm_hw_params(struct snd_pcm_substream *substream,
619{ 604{
620 struct snd_soc_pcm_runtime *rtd = substream->private_data; 605 struct snd_soc_pcm_runtime *rtd = substream->private_data;
621 struct snd_soc_device *socdev = rtd->socdev; 606 struct snd_soc_device *socdev = rtd->socdev;
622 struct snd_soc_codec *codec = socdev->codec; 607 struct snd_soc_codec *codec = socdev->card->codec;
623 struct wm8750_priv *wm8750 = codec->private_data; 608 struct wm8750_priv *wm8750 = codec->private_data;
624 u16 iface = wm8750_read_reg_cache(codec, WM8750_IFACE) & 0x1f3; 609 u16 iface = wm8750_read_reg_cache(codec, WM8750_IFACE) & 0x1f3;
625 u16 srate = wm8750_read_reg_cache(codec, WM8750_SRATE) & 0x1c0; 610 u16 srate = wm8750_read_reg_cache(codec, WM8750_SRATE) & 0x1c0;
@@ -694,6 +679,13 @@ static int wm8750_set_bias_level(struct snd_soc_codec *codec,
694#define WM8750_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 679#define WM8750_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
695 SNDRV_PCM_FMTBIT_S24_LE) 680 SNDRV_PCM_FMTBIT_S24_LE)
696 681
682static struct snd_soc_dai_ops wm8750_dai_ops = {
683 .hw_params = wm8750_pcm_hw_params,
684 .digital_mute = wm8750_mute,
685 .set_fmt = wm8750_set_dai_fmt,
686 .set_sysclk = wm8750_set_dai_sysclk,
687};
688
697struct snd_soc_dai wm8750_dai = { 689struct snd_soc_dai wm8750_dai = {
698 .name = "WM8750", 690 .name = "WM8750",
699 .playback = { 691 .playback = {
@@ -708,12 +700,7 @@ struct snd_soc_dai wm8750_dai = {
708 .channels_max = 2, 700 .channels_max = 2,
709 .rates = WM8750_RATES, 701 .rates = WM8750_RATES,
710 .formats = WM8750_FORMATS,}, 702 .formats = WM8750_FORMATS,},
711 .ops = { 703 .ops = &wm8750_dai_ops,
712 .hw_params = wm8750_pcm_hw_params,
713 .digital_mute = wm8750_mute,
714 .set_fmt = wm8750_set_dai_fmt,
715 .set_sysclk = wm8750_set_dai_sysclk,
716 },
717}; 704};
718EXPORT_SYMBOL_GPL(wm8750_dai); 705EXPORT_SYMBOL_GPL(wm8750_dai);
719 706
@@ -727,7 +714,7 @@ static void wm8750_work(struct work_struct *work)
727static int wm8750_suspend(struct platform_device *pdev, pm_message_t state) 714static int wm8750_suspend(struct platform_device *pdev, pm_message_t state)
728{ 715{
729 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 716 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
730 struct snd_soc_codec *codec = socdev->codec; 717 struct snd_soc_codec *codec = socdev->card->codec;
731 718
732 wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF); 719 wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF);
733 return 0; 720 return 0;
@@ -736,7 +723,7 @@ static int wm8750_suspend(struct platform_device *pdev, pm_message_t state)
736static int wm8750_resume(struct platform_device *pdev) 723static int wm8750_resume(struct platform_device *pdev)
737{ 724{
738 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 725 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
739 struct snd_soc_codec *codec = socdev->codec; 726 struct snd_soc_codec *codec = socdev->card->codec;
740 int i; 727 int i;
741 u8 data[2]; 728 u8 data[2];
742 u16 *cache = codec->reg_cache; 729 u16 *cache = codec->reg_cache;
@@ -769,7 +756,7 @@ static int wm8750_resume(struct platform_device *pdev)
769 */ 756 */
770static int wm8750_init(struct snd_soc_device *socdev) 757static int wm8750_init(struct snd_soc_device *socdev)
771{ 758{
772 struct snd_soc_codec *codec = socdev->codec; 759 struct snd_soc_codec *codec = socdev->card->codec;
773 int reg, ret = 0; 760 int reg, ret = 0;
774 761
775 codec->name = "WM8750"; 762 codec->name = "WM8750";
@@ -816,7 +803,8 @@ static int wm8750_init(struct snd_soc_device *socdev)
816 reg = wm8750_read_reg_cache(codec, WM8750_RINVOL); 803 reg = wm8750_read_reg_cache(codec, WM8750_RINVOL);
817 wm8750_write(codec, WM8750_RINVOL, reg | 0x0100); 804 wm8750_write(codec, WM8750_RINVOL, reg | 0x0100);
818 805
819 wm8750_add_controls(codec); 806 snd_soc_add_controls(codec, wm8750_snd_controls,
807 ARRAY_SIZE(wm8750_snd_controls));
820 wm8750_add_widgets(codec); 808 wm8750_add_widgets(codec);
821 ret = snd_soc_init_card(socdev); 809 ret = snd_soc_init_card(socdev);
822 if (ret < 0) { 810 if (ret < 0) {
@@ -850,7 +838,7 @@ static int wm8750_i2c_probe(struct i2c_client *i2c,
850 const struct i2c_device_id *id) 838 const struct i2c_device_id *id)
851{ 839{
852 struct snd_soc_device *socdev = wm8750_socdev; 840 struct snd_soc_device *socdev = wm8750_socdev;
853 struct snd_soc_codec *codec = socdev->codec; 841 struct snd_soc_codec *codec = socdev->card->codec;
854 int ret; 842 int ret;
855 843
856 i2c_set_clientdata(i2c, codec); 844 i2c_set_clientdata(i2c, codec);
@@ -931,7 +919,7 @@ err_driver:
931static int __devinit wm8750_spi_probe(struct spi_device *spi) 919static int __devinit wm8750_spi_probe(struct spi_device *spi)
932{ 920{
933 struct snd_soc_device *socdev = wm8750_socdev; 921 struct snd_soc_device *socdev = wm8750_socdev;
934 struct snd_soc_codec *codec = socdev->codec; 922 struct snd_soc_codec *codec = socdev->card->codec;
935 int ret; 923 int ret;
936 924
937 codec->control_data = spi; 925 codec->control_data = spi;
@@ -1003,7 +991,7 @@ static int wm8750_probe(struct platform_device *pdev)
1003 } 991 }
1004 992
1005 codec->private_data = wm8750; 993 codec->private_data = wm8750;
1006 socdev->codec = codec; 994 socdev->card->codec = codec;
1007 mutex_init(&codec->mutex); 995 mutex_init(&codec->mutex);
1008 INIT_LIST_HEAD(&codec->dapm_widgets); 996 INIT_LIST_HEAD(&codec->dapm_widgets);
1009 INIT_LIST_HEAD(&codec->dapm_paths); 997 INIT_LIST_HEAD(&codec->dapm_paths);
@@ -1057,7 +1045,7 @@ static int run_delayed_work(struct delayed_work *dwork)
1057static int wm8750_remove(struct platform_device *pdev) 1045static int wm8750_remove(struct platform_device *pdev)
1058{ 1046{
1059 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1047 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1060 struct snd_soc_codec *codec = socdev->codec; 1048 struct snd_soc_codec *codec = socdev->card->codec;
1061 1049
1062 if (codec->control_data) 1050 if (codec->control_data)
1063 wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF); 1051 wm8750_set_bias_level(codec, SND_SOC_BIAS_OFF);
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index 77620ab98756..a6e8f3f7f052 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -51,8 +51,6 @@
51 51
52#include "wm8753.h" 52#include "wm8753.h"
53 53
54#define WM8753_VERSION "0.16"
55
56static int caps_charge = 2000; 54static int caps_charge = 2000;
57module_param(caps_charge, int, 0); 55module_param(caps_charge, int, 0);
58MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)"); 56MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)");
@@ -60,12 +58,6 @@ MODULE_PARM_DESC(caps_charge, "WM8753 cap charge time (msecs)");
60static void wm8753_set_dai_mode(struct snd_soc_codec *codec, 58static void wm8753_set_dai_mode(struct snd_soc_codec *codec,
61 unsigned int mode); 59 unsigned int mode);
62 60
63/* codec private data */
64struct wm8753_priv {
65 unsigned int sysclk;
66 unsigned int pcmclk;
67};
68
69/* 61/*
70 * wm8753 register cache 62 * wm8753 register cache
71 * We can't read the WM8753 register space when we 63 * We can't read the WM8753 register space when we
@@ -90,6 +82,14 @@ static const u16 wm8753_reg[] = {
90 0x0000, 0x0000 82 0x0000, 0x0000
91}; 83};
92 84
85/* codec private data */
86struct wm8753_priv {
87 unsigned int sysclk;
88 unsigned int pcmclk;
89 struct snd_soc_codec codec;
90 u16 reg_cache[ARRAY_SIZE(wm8753_reg)];
91};
92
93/* 93/*
94 * read wm8753 register cache 94 * read wm8753 register cache
95 */ 95 */
@@ -97,7 +97,7 @@ static inline unsigned int wm8753_read_reg_cache(struct snd_soc_codec *codec,
97 unsigned int reg) 97 unsigned int reg)
98{ 98{
99 u16 *cache = codec->reg_cache; 99 u16 *cache = codec->reg_cache;
100 if (reg < 1 || reg > (ARRAY_SIZE(wm8753_reg) + 1)) 100 if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1))
101 return -1; 101 return -1;
102 return cache[reg - 1]; 102 return cache[reg - 1];
103} 103}
@@ -109,7 +109,7 @@ static inline void wm8753_write_reg_cache(struct snd_soc_codec *codec,
109 unsigned int reg, unsigned int value) 109 unsigned int reg, unsigned int value)
110{ 110{
111 u16 *cache = codec->reg_cache; 111 u16 *cache = codec->reg_cache;
112 if (reg < 1 || reg > 0x3f) 112 if (reg < 1 || reg >= (ARRAY_SIZE(wm8753_reg) + 1))
113 return; 113 return;
114 cache[reg - 1] = value; 114 cache[reg - 1] = value;
115} 115}
@@ -339,21 +339,6 @@ SOC_ENUM("ADC Data Select", wm8753_enum[27]),
339SOC_ENUM("ROUT2 Phase", wm8753_enum[28]), 339SOC_ENUM("ROUT2 Phase", wm8753_enum[28]),
340}; 340};
341 341
342/* add non dapm controls */
343static int wm8753_add_controls(struct snd_soc_codec *codec)
344{
345 int err, i;
346
347 for (i = 0; i < ARRAY_SIZE(wm8753_snd_controls); i++) {
348 err = snd_ctl_add(codec->card,
349 snd_soc_cnew(&wm8753_snd_controls[i],
350 codec, NULL));
351 if (err < 0)
352 return err;
353 }
354 return 0;
355}
356
357/* 342/*
358 * _DAPM_ Controls 343 * _DAPM_ Controls
359 */ 344 */
@@ -927,7 +912,7 @@ static int wm8753_pcm_hw_params(struct snd_pcm_substream *substream,
927{ 912{
928 struct snd_soc_pcm_runtime *rtd = substream->private_data; 913 struct snd_soc_pcm_runtime *rtd = substream->private_data;
929 struct snd_soc_device *socdev = rtd->socdev; 914 struct snd_soc_device *socdev = rtd->socdev;
930 struct snd_soc_codec *codec = socdev->codec; 915 struct snd_soc_codec *codec = socdev->card->codec;
931 struct wm8753_priv *wm8753 = codec->private_data; 916 struct wm8753_priv *wm8753 = codec->private_data;
932 u16 voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x01f3; 917 u16 voice = wm8753_read_reg_cache(codec, WM8753_PCM) & 0x01f3;
933 u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x017f; 918 u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x017f;
@@ -1161,7 +1146,7 @@ static int wm8753_i2s_hw_params(struct snd_pcm_substream *substream,
1161{ 1146{
1162 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1147 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1163 struct snd_soc_device *socdev = rtd->socdev; 1148 struct snd_soc_device *socdev = rtd->socdev;
1164 struct snd_soc_codec *codec = socdev->codec; 1149 struct snd_soc_codec *codec = socdev->card->codec;
1165 struct wm8753_priv *wm8753 = codec->private_data; 1150 struct wm8753_priv *wm8753 = codec->private_data;
1166 u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x01c0; 1151 u16 srate = wm8753_read_reg_cache(codec, WM8753_SRATE1) & 0x01c0;
1167 u16 hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x01f3; 1152 u16 hifi = wm8753_read_reg_cache(codec, WM8753_HIFI) & 0x01f3;
@@ -1316,6 +1301,51 @@ static int wm8753_set_bias_level(struct snd_soc_codec *codec,
1316 * 3. Voice disabled - HIFI over HIFI 1301 * 3. Voice disabled - HIFI over HIFI
1317 * 4. Voice disabled - HIFI over HIFI, uses voice DAI LRC for capture 1302 * 4. Voice disabled - HIFI over HIFI, uses voice DAI LRC for capture
1318 */ 1303 */
1304static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode1 = {
1305 .hw_params = wm8753_i2s_hw_params,
1306 .digital_mute = wm8753_mute,
1307 .set_fmt = wm8753_mode1h_set_dai_fmt,
1308 .set_clkdiv = wm8753_set_dai_clkdiv,
1309 .set_pll = wm8753_set_dai_pll,
1310 .set_sysclk = wm8753_set_dai_sysclk,
1311};
1312
1313static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode1 = {
1314 .hw_params = wm8753_pcm_hw_params,
1315 .digital_mute = wm8753_mute,
1316 .set_fmt = wm8753_mode1v_set_dai_fmt,
1317 .set_clkdiv = wm8753_set_dai_clkdiv,
1318 .set_pll = wm8753_set_dai_pll,
1319 .set_sysclk = wm8753_set_dai_sysclk,
1320};
1321
1322static struct snd_soc_dai_ops wm8753_dai_ops_voice_mode2 = {
1323 .hw_params = wm8753_pcm_hw_params,
1324 .digital_mute = wm8753_mute,
1325 .set_fmt = wm8753_mode2_set_dai_fmt,
1326 .set_clkdiv = wm8753_set_dai_clkdiv,
1327 .set_pll = wm8753_set_dai_pll,
1328 .set_sysclk = wm8753_set_dai_sysclk,
1329};
1330
1331static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode3 = {
1332 .hw_params = wm8753_i2s_hw_params,
1333 .digital_mute = wm8753_mute,
1334 .set_fmt = wm8753_mode3_4_set_dai_fmt,
1335 .set_clkdiv = wm8753_set_dai_clkdiv,
1336 .set_pll = wm8753_set_dai_pll,
1337 .set_sysclk = wm8753_set_dai_sysclk,
1338};
1339
1340static struct snd_soc_dai_ops wm8753_dai_ops_hifi_mode4 = {
1341 .hw_params = wm8753_i2s_hw_params,
1342 .digital_mute = wm8753_mute,
1343 .set_fmt = wm8753_mode3_4_set_dai_fmt,
1344 .set_clkdiv = wm8753_set_dai_clkdiv,
1345 .set_pll = wm8753_set_dai_pll,
1346 .set_sysclk = wm8753_set_dai_sysclk,
1347};
1348
1319static const struct snd_soc_dai wm8753_all_dai[] = { 1349static const struct snd_soc_dai wm8753_all_dai[] = {
1320/* DAI HiFi mode 1 */ 1350/* DAI HiFi mode 1 */
1321{ .name = "WM8753 HiFi", 1351{ .name = "WM8753 HiFi",
@@ -1332,14 +1362,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
1332 .channels_max = 2, 1362 .channels_max = 2,
1333 .rates = WM8753_RATES, 1363 .rates = WM8753_RATES,
1334 .formats = WM8753_FORMATS}, 1364 .formats = WM8753_FORMATS},
1335 .ops = { 1365 .ops = &wm8753_dai_ops_hifi_mode1,
1336 .hw_params = wm8753_i2s_hw_params,
1337 .digital_mute = wm8753_mute,
1338 .set_fmt = wm8753_mode1h_set_dai_fmt,
1339 .set_clkdiv = wm8753_set_dai_clkdiv,
1340 .set_pll = wm8753_set_dai_pll,
1341 .set_sysclk = wm8753_set_dai_sysclk,
1342 },
1343}, 1366},
1344/* DAI Voice mode 1 */ 1367/* DAI Voice mode 1 */
1345{ .name = "WM8753 Voice", 1368{ .name = "WM8753 Voice",
@@ -1356,14 +1379,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
1356 .channels_max = 2, 1379 .channels_max = 2,
1357 .rates = WM8753_RATES, 1380 .rates = WM8753_RATES,
1358 .formats = WM8753_FORMATS,}, 1381 .formats = WM8753_FORMATS,},
1359 .ops = { 1382 .ops = &wm8753_dai_ops_voice_mode1,
1360 .hw_params = wm8753_pcm_hw_params,
1361 .digital_mute = wm8753_mute,
1362 .set_fmt = wm8753_mode1v_set_dai_fmt,
1363 .set_clkdiv = wm8753_set_dai_clkdiv,
1364 .set_pll = wm8753_set_dai_pll,
1365 .set_sysclk = wm8753_set_dai_sysclk,
1366 },
1367}, 1383},
1368/* DAI HiFi mode 2 - dummy */ 1384/* DAI HiFi mode 2 - dummy */
1369{ .name = "WM8753 HiFi", 1385{ .name = "WM8753 HiFi",
@@ -1384,14 +1400,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
1384 .channels_max = 2, 1400 .channels_max = 2,
1385 .rates = WM8753_RATES, 1401 .rates = WM8753_RATES,
1386 .formats = WM8753_FORMATS,}, 1402 .formats = WM8753_FORMATS,},
1387 .ops = { 1403 .ops = &wm8753_dai_ops_voice_mode2,
1388 .hw_params = wm8753_pcm_hw_params,
1389 .digital_mute = wm8753_mute,
1390 .set_fmt = wm8753_mode2_set_dai_fmt,
1391 .set_clkdiv = wm8753_set_dai_clkdiv,
1392 .set_pll = wm8753_set_dai_pll,
1393 .set_sysclk = wm8753_set_dai_sysclk,
1394 },
1395}, 1404},
1396/* DAI HiFi mode 3 */ 1405/* DAI HiFi mode 3 */
1397{ .name = "WM8753 HiFi", 1406{ .name = "WM8753 HiFi",
@@ -1408,14 +1417,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
1408 .channels_max = 2, 1417 .channels_max = 2,
1409 .rates = WM8753_RATES, 1418 .rates = WM8753_RATES,
1410 .formats = WM8753_FORMATS,}, 1419 .formats = WM8753_FORMATS,},
1411 .ops = { 1420 .ops = &wm8753_dai_ops_hifi_mode3,
1412 .hw_params = wm8753_i2s_hw_params,
1413 .digital_mute = wm8753_mute,
1414 .set_fmt = wm8753_mode3_4_set_dai_fmt,
1415 .set_clkdiv = wm8753_set_dai_clkdiv,
1416 .set_pll = wm8753_set_dai_pll,
1417 .set_sysclk = wm8753_set_dai_sysclk,
1418 },
1419}, 1421},
1420/* DAI Voice mode 3 - dummy */ 1422/* DAI Voice mode 3 - dummy */
1421{ .name = "WM8753 Voice", 1423{ .name = "WM8753 Voice",
@@ -1436,14 +1438,7 @@ static const struct snd_soc_dai wm8753_all_dai[] = {
1436 .channels_max = 2, 1438 .channels_max = 2,
1437 .rates = WM8753_RATES, 1439 .rates = WM8753_RATES,
1438 .formats = WM8753_FORMATS,}, 1440 .formats = WM8753_FORMATS,},
1439 .ops = { 1441 .ops = &wm8753_dai_ops_hifi_mode4,
1440 .hw_params = wm8753_i2s_hw_params,
1441 .digital_mute = wm8753_mute,
1442 .set_fmt = wm8753_mode3_4_set_dai_fmt,
1443 .set_clkdiv = wm8753_set_dai_clkdiv,
1444 .set_pll = wm8753_set_dai_pll,
1445 .set_sysclk = wm8753_set_dai_sysclk,
1446 },
1447}, 1442},
1448/* DAI Voice mode 4 - dummy */ 1443/* DAI Voice mode 4 - dummy */
1449{ .name = "WM8753 Voice", 1444{ .name = "WM8753 Voice",
@@ -1466,30 +1461,35 @@ static void wm8753_set_dai_mode(struct snd_soc_codec *codec, unsigned int mode)
1466 if (mode < 4) { 1461 if (mode < 4) {
1467 int playback_active, capture_active, codec_active, pop_wait; 1462 int playback_active, capture_active, codec_active, pop_wait;
1468 void *private_data; 1463 void *private_data;
1464 struct list_head list;
1469 1465
1470 playback_active = wm8753_dai[0].playback.active; 1466 playback_active = wm8753_dai[0].playback.active;
1471 capture_active = wm8753_dai[0].capture.active; 1467 capture_active = wm8753_dai[0].capture.active;
1472 codec_active = wm8753_dai[0].active; 1468 codec_active = wm8753_dai[0].active;
1473 private_data = wm8753_dai[0].private_data; 1469 private_data = wm8753_dai[0].private_data;
1474 pop_wait = wm8753_dai[0].pop_wait; 1470 pop_wait = wm8753_dai[0].pop_wait;
1471 list = wm8753_dai[0].list;
1475 wm8753_dai[0] = wm8753_all_dai[mode << 1]; 1472 wm8753_dai[0] = wm8753_all_dai[mode << 1];
1476 wm8753_dai[0].playback.active = playback_active; 1473 wm8753_dai[0].playback.active = playback_active;
1477 wm8753_dai[0].capture.active = capture_active; 1474 wm8753_dai[0].capture.active = capture_active;
1478 wm8753_dai[0].active = codec_active; 1475 wm8753_dai[0].active = codec_active;
1479 wm8753_dai[0].private_data = private_data; 1476 wm8753_dai[0].private_data = private_data;
1480 wm8753_dai[0].pop_wait = pop_wait; 1477 wm8753_dai[0].pop_wait = pop_wait;
1478 wm8753_dai[0].list = list;
1481 1479
1482 playback_active = wm8753_dai[1].playback.active; 1480 playback_active = wm8753_dai[1].playback.active;
1483 capture_active = wm8753_dai[1].capture.active; 1481 capture_active = wm8753_dai[1].capture.active;
1484 codec_active = wm8753_dai[1].active; 1482 codec_active = wm8753_dai[1].active;
1485 private_data = wm8753_dai[1].private_data; 1483 private_data = wm8753_dai[1].private_data;
1486 pop_wait = wm8753_dai[1].pop_wait; 1484 pop_wait = wm8753_dai[1].pop_wait;
1485 list = wm8753_dai[1].list;
1487 wm8753_dai[1] = wm8753_all_dai[(mode << 1) + 1]; 1486 wm8753_dai[1] = wm8753_all_dai[(mode << 1) + 1];
1488 wm8753_dai[1].playback.active = playback_active; 1487 wm8753_dai[1].playback.active = playback_active;
1489 wm8753_dai[1].capture.active = capture_active; 1488 wm8753_dai[1].capture.active = capture_active;
1490 wm8753_dai[1].active = codec_active; 1489 wm8753_dai[1].active = codec_active;
1491 wm8753_dai[1].private_data = private_data; 1490 wm8753_dai[1].private_data = private_data;
1492 wm8753_dai[1].pop_wait = pop_wait; 1491 wm8753_dai[1].pop_wait = pop_wait;
1492 wm8753_dai[1].list = list;
1493 } 1493 }
1494 wm8753_dai[0].codec = codec; 1494 wm8753_dai[0].codec = codec;
1495 wm8753_dai[1].codec = codec; 1495 wm8753_dai[1].codec = codec;
@@ -1505,7 +1505,7 @@ static void wm8753_work(struct work_struct *work)
1505static int wm8753_suspend(struct platform_device *pdev, pm_message_t state) 1505static int wm8753_suspend(struct platform_device *pdev, pm_message_t state)
1506{ 1506{
1507 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1507 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1508 struct snd_soc_codec *codec = socdev->codec; 1508 struct snd_soc_codec *codec = socdev->card->codec;
1509 1509
1510 /* we only need to suspend if we are a valid card */ 1510 /* we only need to suspend if we are a valid card */
1511 if (!codec->card) 1511 if (!codec->card)
@@ -1518,7 +1518,7 @@ static int wm8753_suspend(struct platform_device *pdev, pm_message_t state)
1518static int wm8753_resume(struct platform_device *pdev) 1518static int wm8753_resume(struct platform_device *pdev)
1519{ 1519{
1520 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1520 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1521 struct snd_soc_codec *codec = socdev->codec; 1521 struct snd_soc_codec *codec = socdev->card->codec;
1522 int i; 1522 int i;
1523 u8 data[2]; 1523 u8 data[2];
1524 u16 *cache = codec->reg_cache; 1524 u16 *cache = codec->reg_cache;
@@ -1531,6 +1531,11 @@ static int wm8753_resume(struct platform_device *pdev)
1531 for (i = 0; i < ARRAY_SIZE(wm8753_reg); i++) { 1531 for (i = 0; i < ARRAY_SIZE(wm8753_reg); i++) {
1532 if (i + 1 == WM8753_RESET) 1532 if (i + 1 == WM8753_RESET)
1533 continue; 1533 continue;
1534
1535 /* No point in writing hardware default values back */
1536 if (cache[i] == wm8753_reg[i])
1537 continue;
1538
1534 data[0] = ((i + 1) << 1) | ((cache[i] >> 8) & 0x0001); 1539 data[0] = ((i + 1) << 1) | ((cache[i] >> 8) & 0x0001);
1535 data[1] = cache[i] & 0x00ff; 1540 data[1] = cache[i] & 0x00ff;
1536 codec->hw_write(codec->control_data, data, 2); 1541 codec->hw_write(codec->control_data, data, 2);
@@ -1549,44 +1554,129 @@ static int wm8753_resume(struct platform_device *pdev)
1549 return 0; 1554 return 0;
1550} 1555}
1551 1556
1557static struct snd_soc_codec *wm8753_codec;
1558
1559static int wm8753_probe(struct platform_device *pdev)
1560{
1561 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1562 struct snd_soc_codec *codec;
1563 int ret = 0;
1564
1565 if (!wm8753_codec) {
1566 dev_err(&pdev->dev, "WM8753 codec not yet registered\n");
1567 return -EINVAL;
1568 }
1569
1570 socdev->card->codec = wm8753_codec;
1571 codec = wm8753_codec;
1572
1573 wm8753_set_dai_mode(codec, 0);
1574
1575 /* register pcms */
1576 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
1577 if (ret < 0) {
1578 printk(KERN_ERR "wm8753: failed to create pcms\n");
1579 goto pcm_err;
1580 }
1581
1582 snd_soc_add_controls(codec, wm8753_snd_controls,
1583 ARRAY_SIZE(wm8753_snd_controls));
1584 wm8753_add_widgets(codec);
1585 ret = snd_soc_init_card(socdev);
1586 if (ret < 0) {
1587 printk(KERN_ERR "wm8753: failed to register card\n");
1588 goto card_err;
1589 }
1590
1591 return 0;
1592
1593card_err:
1594 snd_soc_free_pcms(socdev);
1595 snd_soc_dapm_free(socdev);
1596
1597pcm_err:
1598 return ret;
1599}
1600
1552/* 1601/*
1553 * initialise the WM8753 driver 1602 * This function forces any delayed work to be queued and run.
1554 * register the mixer and dsp interfaces with the kernel
1555 */ 1603 */
1556static int wm8753_init(struct snd_soc_device *socdev) 1604static int run_delayed_work(struct delayed_work *dwork)
1605{
1606 int ret;
1607
1608 /* cancel any work waiting to be queued. */
1609 ret = cancel_delayed_work(dwork);
1610
1611 /* if there was any work waiting then we run it now and
1612 * wait for it's completion */
1613 if (ret) {
1614 schedule_delayed_work(dwork, 0);
1615 flush_scheduled_work();
1616 }
1617 return ret;
1618}
1619
1620/* power down chip */
1621static int wm8753_remove(struct platform_device *pdev)
1557{ 1622{
1558 struct snd_soc_codec *codec = socdev->codec; 1623 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1559 int reg, ret = 0; 1624
1625 snd_soc_free_pcms(socdev);
1626 snd_soc_dapm_free(socdev);
1627
1628 return 0;
1629}
1630
1631struct snd_soc_codec_device soc_codec_dev_wm8753 = {
1632 .probe = wm8753_probe,
1633 .remove = wm8753_remove,
1634 .suspend = wm8753_suspend,
1635 .resume = wm8753_resume,
1636};
1637EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753);
1638
1639static int wm8753_register(struct wm8753_priv *wm8753)
1640{
1641 int ret, i;
1642 struct snd_soc_codec *codec = &wm8753->codec;
1643 u16 reg;
1644
1645 if (wm8753_codec) {
1646 dev_err(codec->dev, "Multiple WM8753 devices not supported\n");
1647 ret = -EINVAL;
1648 goto err;
1649 }
1650
1651 mutex_init(&codec->mutex);
1652 INIT_LIST_HEAD(&codec->dapm_widgets);
1653 INIT_LIST_HEAD(&codec->dapm_paths);
1560 1654
1561 codec->name = "WM8753"; 1655 codec->name = "WM8753";
1562 codec->owner = THIS_MODULE; 1656 codec->owner = THIS_MODULE;
1563 codec->read = wm8753_read_reg_cache; 1657 codec->read = wm8753_read_reg_cache;
1564 codec->write = wm8753_write; 1658 codec->write = wm8753_write;
1659 codec->bias_level = SND_SOC_BIAS_STANDBY;
1565 codec->set_bias_level = wm8753_set_bias_level; 1660 codec->set_bias_level = wm8753_set_bias_level;
1566 codec->dai = wm8753_dai; 1661 codec->dai = wm8753_dai;
1567 codec->num_dai = 2; 1662 codec->num_dai = 2;
1568 codec->reg_cache_size = ARRAY_SIZE(wm8753_reg); 1663 codec->reg_cache_size = ARRAY_SIZE(wm8753->reg_cache);
1569 codec->reg_cache = kmemdup(wm8753_reg, sizeof(wm8753_reg), GFP_KERNEL); 1664 codec->reg_cache = &wm8753->reg_cache;
1570 1665 codec->private_data = wm8753;
1571 if (codec->reg_cache == NULL)
1572 return -ENOMEM;
1573
1574 wm8753_set_dai_mode(codec, 0);
1575 1666
1576 wm8753_reset(codec); 1667 memcpy(codec->reg_cache, wm8753_reg, sizeof(codec->reg_cache));
1668 INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work);
1577 1669
1578 /* register pcms */ 1670 ret = wm8753_reset(codec);
1579 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
1580 if (ret < 0) { 1671 if (ret < 0) {
1581 printk(KERN_ERR "wm8753: failed to create pcms\n"); 1672 dev_err(codec->dev, "Failed to issue reset\n");
1582 goto pcm_err; 1673 goto err;
1583 } 1674 }
1584 1675
1585 /* charge output caps */ 1676 /* charge output caps */
1586 wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE); 1677 wm8753_set_bias_level(codec, SND_SOC_BIAS_PREPARE);
1587 codec->bias_level = SND_SOC_BIAS_STANDBY;
1588 schedule_delayed_work(&codec->delayed_work, 1678 schedule_delayed_work(&codec->delayed_work,
1589 msecs_to_jiffies(caps_charge)); 1679 msecs_to_jiffies(caps_charge));
1590 1680
1591 /* set the update bits */ 1681 /* set the update bits */
1592 reg = wm8753_read_reg_cache(codec, WM8753_LDAC); 1682 reg = wm8753_read_reg_cache(codec, WM8753_LDAC);
@@ -1610,59 +1700,70 @@ static int wm8753_init(struct snd_soc_device *socdev)
1610 reg = wm8753_read_reg_cache(codec, WM8753_RINVOL); 1700 reg = wm8753_read_reg_cache(codec, WM8753_RINVOL);
1611 wm8753_write(codec, WM8753_RINVOL, reg | 0x0100); 1701 wm8753_write(codec, WM8753_RINVOL, reg | 0x0100);
1612 1702
1613 wm8753_add_controls(codec); 1703 wm8753_codec = codec;
1614 wm8753_add_widgets(codec); 1704
1615 ret = snd_soc_init_card(socdev); 1705 for (i = 0; i < ARRAY_SIZE(wm8753_dai); i++)
1616 if (ret < 0) { 1706 wm8753_dai[i].dev = codec->dev;
1617 printk(KERN_ERR "wm8753: failed to register card\n"); 1707
1618 goto card_err; 1708 ret = snd_soc_register_codec(codec);
1709 if (ret != 0) {
1710 dev_err(codec->dev, "Failed to register codec: %d\n", ret);
1711 goto err;
1619 } 1712 }
1620 1713
1621 return ret; 1714 ret = snd_soc_register_dais(&wm8753_dai[0], ARRAY_SIZE(wm8753_dai));
1715 if (ret != 0) {
1716 dev_err(codec->dev, "Failed to register DAIs: %d\n", ret);
1717 goto err_codec;
1718 }
1622 1719
1623card_err: 1720 return 0;
1624 snd_soc_free_pcms(socdev); 1721
1625 snd_soc_dapm_free(socdev); 1722err_codec:
1626pcm_err: 1723 run_delayed_work(&codec->delayed_work);
1627 kfree(codec->reg_cache); 1724 snd_soc_unregister_codec(codec);
1725err:
1726 kfree(wm8753);
1628 return ret; 1727 return ret;
1629} 1728}
1630 1729
1631/* If the i2c layer weren't so broken, we could pass this kind of data 1730static void wm8753_unregister(struct wm8753_priv *wm8753)
1632 around */ 1731{
1633static struct snd_soc_device *wm8753_socdev; 1732 wm8753_set_bias_level(&wm8753->codec, SND_SOC_BIAS_OFF);
1733 run_delayed_work(&wm8753->codec.delayed_work);
1734 snd_soc_unregister_dais(&wm8753_dai[0], ARRAY_SIZE(wm8753_dai));
1735 snd_soc_unregister_codec(&wm8753->codec);
1736 kfree(wm8753);
1737 wm8753_codec = NULL;
1738}
1634 1739
1635#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1740#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1636 1741
1637/*
1638 * WM8753 2 wire address is determined by GPIO5
1639 * state during powerup.
1640 * low = 0x1a
1641 * high = 0x1b
1642 */
1643
1644static int wm8753_i2c_probe(struct i2c_client *i2c, 1742static int wm8753_i2c_probe(struct i2c_client *i2c,
1645 const struct i2c_device_id *id) 1743 const struct i2c_device_id *id)
1646{ 1744{
1647 struct snd_soc_device *socdev = wm8753_socdev; 1745 struct snd_soc_codec *codec;
1648 struct snd_soc_codec *codec = socdev->codec; 1746 struct wm8753_priv *wm8753;
1649 int ret;
1650 1747
1651 i2c_set_clientdata(i2c, codec); 1748 wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL);
1652 codec->control_data = i2c; 1749 if (wm8753 == NULL)
1750 return -ENOMEM;
1653 1751
1654 ret = wm8753_init(socdev); 1752 codec = &wm8753->codec;
1655 if (ret < 0) 1753 codec->hw_write = (hw_write_t)i2c_master_send;
1656 pr_err("failed to initialise WM8753\n"); 1754 codec->control_data = i2c;
1755 i2c_set_clientdata(i2c, wm8753);
1657 1756
1658 return ret; 1757 codec->dev = &i2c->dev;
1758
1759 return wm8753_register(wm8753);
1659} 1760}
1660 1761
1661static int wm8753_i2c_remove(struct i2c_client *client) 1762static int wm8753_i2c_remove(struct i2c_client *client)
1662{ 1763{
1663 struct snd_soc_codec *codec = i2c_get_clientdata(client); 1764 struct wm8753_priv *wm8753 = i2c_get_clientdata(client);
1664 kfree(codec->reg_cache); 1765 wm8753_unregister(wm8753);
1665 return 0; 1766 return 0;
1666} 1767}
1667 1768
1668static const struct i2c_device_id wm8753_i2c_id[] = { 1769static const struct i2c_device_id wm8753_i2c_id[] = {
@@ -1673,86 +1774,16 @@ MODULE_DEVICE_TABLE(i2c, wm8753_i2c_id);
1673 1774
1674static struct i2c_driver wm8753_i2c_driver = { 1775static struct i2c_driver wm8753_i2c_driver = {
1675 .driver = { 1776 .driver = {
1676 .name = "WM8753 I2C Codec", 1777 .name = "wm8753",
1677 .owner = THIS_MODULE, 1778 .owner = THIS_MODULE,
1678 }, 1779 },
1679 .probe = wm8753_i2c_probe, 1780 .probe = wm8753_i2c_probe,
1680 .remove = wm8753_i2c_remove, 1781 .remove = wm8753_i2c_remove,
1681 .id_table = wm8753_i2c_id, 1782 .id_table = wm8753_i2c_id,
1682}; 1783};
1683
1684static int wm8753_add_i2c_device(struct platform_device *pdev,
1685 const struct wm8753_setup_data *setup)
1686{
1687 struct i2c_board_info info;
1688 struct i2c_adapter *adapter;
1689 struct i2c_client *client;
1690 int ret;
1691
1692 ret = i2c_add_driver(&wm8753_i2c_driver);
1693 if (ret != 0) {
1694 dev_err(&pdev->dev, "can't add i2c driver\n");
1695 return ret;
1696 }
1697
1698 memset(&info, 0, sizeof(struct i2c_board_info));
1699 info.addr = setup->i2c_address;
1700 strlcpy(info.type, "wm8753", I2C_NAME_SIZE);
1701
1702 adapter = i2c_get_adapter(setup->i2c_bus);
1703 if (!adapter) {
1704 dev_err(&pdev->dev, "can't get i2c adapter %d\n",
1705 setup->i2c_bus);
1706 goto err_driver;
1707 }
1708
1709 client = i2c_new_device(adapter, &info);
1710 i2c_put_adapter(adapter);
1711 if (!client) {
1712 dev_err(&pdev->dev, "can't add i2c device at 0x%x\n",
1713 (unsigned int)info.addr);
1714 goto err_driver;
1715 }
1716
1717 return 0;
1718
1719err_driver:
1720 i2c_del_driver(&wm8753_i2c_driver);
1721 return -ENODEV;
1722}
1723#endif 1784#endif
1724 1785
1725#if defined(CONFIG_SPI_MASTER) 1786#if defined(CONFIG_SPI_MASTER)
1726static int __devinit wm8753_spi_probe(struct spi_device *spi)
1727{
1728 struct snd_soc_device *socdev = wm8753_socdev;
1729 struct snd_soc_codec *codec = socdev->codec;
1730 int ret;
1731
1732 codec->control_data = spi;
1733
1734 ret = wm8753_init(socdev);
1735 if (ret < 0)
1736 dev_err(&spi->dev, "failed to initialise WM8753\n");
1737
1738 return ret;
1739}
1740
1741static int __devexit wm8753_spi_remove(struct spi_device *spi)
1742{
1743 return 0;
1744}
1745
1746static struct spi_driver wm8753_spi_driver = {
1747 .driver = {
1748 .name = "wm8753",
1749 .bus = &spi_bus_type,
1750 .owner = THIS_MODULE,
1751 },
1752 .probe = wm8753_spi_probe,
1753 .remove = __devexit_p(wm8753_spi_remove),
1754};
1755
1756static int wm8753_spi_write(struct spi_device *spi, const char *data, int len) 1787static int wm8753_spi_write(struct spi_device *spi, const char *data, int len)
1757{ 1788{
1758 struct spi_transfer t; 1789 struct spi_transfer t;
@@ -1776,120 +1807,69 @@ static int wm8753_spi_write(struct spi_device *spi, const char *data, int len)
1776 1807
1777 return len; 1808 return len;
1778} 1809}
1779#endif
1780 1810
1781 1811static int __devinit wm8753_spi_probe(struct spi_device *spi)
1782static int wm8753_probe(struct platform_device *pdev)
1783{ 1812{
1784 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1785 struct wm8753_setup_data *setup;
1786 struct snd_soc_codec *codec; 1813 struct snd_soc_codec *codec;
1787 struct wm8753_priv *wm8753; 1814 struct wm8753_priv *wm8753;
1788 int ret = 0;
1789
1790 pr_info("WM8753 Audio Codec %s", WM8753_VERSION);
1791
1792 setup = socdev->codec_data;
1793 codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
1794 if (codec == NULL)
1795 return -ENOMEM;
1796 1815
1797 wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL); 1816 wm8753 = kzalloc(sizeof(struct wm8753_priv), GFP_KERNEL);
1798 if (wm8753 == NULL) { 1817 if (wm8753 == NULL)
1799 kfree(codec);
1800 return -ENOMEM; 1818 return -ENOMEM;
1801 }
1802 1819
1803 codec->private_data = wm8753; 1820 codec = &wm8753->codec;
1804 socdev->codec = codec; 1821 codec->control_data = spi;
1805 mutex_init(&codec->mutex); 1822 codec->hw_write = (hw_write_t)wm8753_spi_write;
1806 INIT_LIST_HEAD(&codec->dapm_widgets); 1823 codec->dev = &spi->dev;
1807 INIT_LIST_HEAD(&codec->dapm_paths);
1808 wm8753_socdev = socdev;
1809 INIT_DELAYED_WORK(&codec->delayed_work, wm8753_work);
1810 1824
1811#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1825 spi->dev.driver_data = wm8753;
1812 if (setup->i2c_address) {
1813 codec->hw_write = (hw_write_t)i2c_master_send;
1814 ret = wm8753_add_i2c_device(pdev, setup);
1815 }
1816#endif
1817#if defined(CONFIG_SPI_MASTER)
1818 if (setup->spi) {
1819 codec->hw_write = (hw_write_t)wm8753_spi_write;
1820 ret = spi_register_driver(&wm8753_spi_driver);
1821 if (ret != 0)
1822 printk(KERN_ERR "can't add spi driver");
1823 }
1824#endif
1825 1826
1826 if (ret != 0) { 1827 return wm8753_register(wm8753);
1827 kfree(codec->private_data);
1828 kfree(codec);
1829 }
1830 return ret;
1831} 1828}
1832 1829
1833/* 1830static int __devexit wm8753_spi_remove(struct spi_device *spi)
1834 * This function forces any delayed work to be queued and run.
1835 */
1836static int run_delayed_work(struct delayed_work *dwork)
1837{ 1831{
1838 int ret; 1832 struct wm8753_priv *wm8753 = spi->dev.driver_data;
1839 1833 wm8753_unregister(wm8753);
1840 /* cancel any work waiting to be queued. */ 1834 return 0;
1841 ret = cancel_delayed_work(dwork);
1842
1843 /* if there was any work waiting then we run it now and
1844 * wait for it's completion */
1845 if (ret) {
1846 schedule_delayed_work(dwork, 0);
1847 flush_scheduled_work();
1848 }
1849 return ret;
1850} 1835}
1851 1836
1852/* power down chip */ 1837static struct spi_driver wm8753_spi_driver = {
1853static int wm8753_remove(struct platform_device *pdev) 1838 .driver = {
1854{ 1839 .name = "wm8753",
1855 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1840 .bus = &spi_bus_type,
1856 struct snd_soc_codec *codec = socdev->codec; 1841 .owner = THIS_MODULE,
1842 },
1843 .probe = wm8753_spi_probe,
1844 .remove = __devexit_p(wm8753_spi_remove),
1845};
1846#endif
1857 1847
1858 if (codec->control_data) 1848static int __init wm8753_modinit(void)
1859 wm8753_set_bias_level(codec, SND_SOC_BIAS_OFF); 1849{
1860 run_delayed_work(&codec->delayed_work); 1850 int ret;
1861 snd_soc_free_pcms(socdev);
1862 snd_soc_dapm_free(socdev);
1863#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) 1851#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1864 i2c_unregister_device(codec->control_data); 1852 ret = i2c_add_driver(&wm8753_i2c_driver);
1865 i2c_del_driver(&wm8753_i2c_driver); 1853 if (ret != 0)
1854 pr_err("Failed to register WM8753 I2C driver: %d\n", ret);
1866#endif 1855#endif
1867#if defined(CONFIG_SPI_MASTER) 1856#if defined(CONFIG_SPI_MASTER)
1868 spi_unregister_driver(&wm8753_spi_driver); 1857 ret = spi_register_driver(&wm8753_spi_driver);
1858 if (ret != 0)
1859 pr_err("Failed to register WM8753 SPI driver: %d\n", ret);
1869#endif 1860#endif
1870 kfree(codec->private_data);
1871 kfree(codec);
1872
1873 return 0; 1861 return 0;
1874} 1862}
1875
1876struct snd_soc_codec_device soc_codec_dev_wm8753 = {
1877 .probe = wm8753_probe,
1878 .remove = wm8753_remove,
1879 .suspend = wm8753_suspend,
1880 .resume = wm8753_resume,
1881};
1882EXPORT_SYMBOL_GPL(soc_codec_dev_wm8753);
1883
1884static int __init wm8753_modinit(void)
1885{
1886 return snd_soc_register_dais(wm8753_dai, ARRAY_SIZE(wm8753_dai));
1887}
1888module_init(wm8753_modinit); 1863module_init(wm8753_modinit);
1889 1864
1890static void __exit wm8753_exit(void) 1865static void __exit wm8753_exit(void)
1891{ 1866{
1892 snd_soc_unregister_dais(wm8753_dai, ARRAY_SIZE(wm8753_dai)); 1867#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1868 i2c_del_driver(&wm8753_i2c_driver);
1869#endif
1870#if defined(CONFIG_SPI_MASTER)
1871 spi_unregister_driver(&wm8753_spi_driver);
1872#endif
1893} 1873}
1894module_exit(wm8753_exit); 1874module_exit(wm8753_exit);
1895 1875
diff --git a/sound/soc/codecs/wm8753.h b/sound/soc/codecs/wm8753.h
index f55704ce931b..57b2ba244040 100644
--- a/sound/soc/codecs/wm8753.h
+++ b/sound/soc/codecs/wm8753.h
@@ -77,12 +77,6 @@
77#define WM8753_BIASCTL 0x3d 77#define WM8753_BIASCTL 0x3d
78#define WM8753_ADCTL2 0x3f 78#define WM8753_ADCTL2 0x3f
79 79
80struct wm8753_setup_data {
81 int spi;
82 int i2c_bus;
83 unsigned short i2c_address;
84};
85
86#define WM8753_PLL1 0 80#define WM8753_PLL1 0
87#define WM8753_PLL2 1 81#define WM8753_PLL2 1
88 82
diff --git a/sound/soc/codecs/wm8900.c b/sound/soc/codecs/wm8900.c
index 6767de10ded0..46c5ea1ff921 100644
--- a/sound/soc/codecs/wm8900.c
+++ b/sound/soc/codecs/wm8900.c
@@ -517,22 +517,6 @@ SOC_SINGLE("LINEOUT2 LP -12dB", WM8900_REG_LOUTMIXCTL1,
517 517
518}; 518};
519 519
520/* add non dapm controls */
521static int wm8900_add_controls(struct snd_soc_codec *codec)
522{
523 int err, i;
524
525 for (i = 0; i < ARRAY_SIZE(wm8900_snd_controls); i++) {
526 err = snd_ctl_add(codec->card,
527 snd_soc_cnew(&wm8900_snd_controls[i],
528 codec, NULL));
529 if (err < 0)
530 return err;
531 }
532
533 return 0;
534}
535
536static const struct snd_kcontrol_new wm8900_dapm_loutput2_control = 520static const struct snd_kcontrol_new wm8900_dapm_loutput2_control =
537SOC_DAPM_SINGLE("LINEOUT2L Switch", WM8900_REG_POWER3, 6, 1, 0); 521SOC_DAPM_SINGLE("LINEOUT2L Switch", WM8900_REG_POWER3, 6, 1, 0);
538 522
@@ -736,7 +720,7 @@ static int wm8900_hw_params(struct snd_pcm_substream *substream,
736{ 720{
737 struct snd_soc_pcm_runtime *rtd = substream->private_data; 721 struct snd_soc_pcm_runtime *rtd = substream->private_data;
738 struct snd_soc_device *socdev = rtd->socdev; 722 struct snd_soc_device *socdev = rtd->socdev;
739 struct snd_soc_codec *codec = socdev->codec; 723 struct snd_soc_codec *codec = socdev->card->codec;
740 u16 reg; 724 u16 reg;
741 725
742 reg = wm8900_read(codec, WM8900_REG_AUDIO1) & ~0x60; 726 reg = wm8900_read(codec, WM8900_REG_AUDIO1) & ~0x60;
@@ -1104,6 +1088,14 @@ static int wm8900_digital_mute(struct snd_soc_dai *codec_dai, int mute)
1104 (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \ 1088 (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \
1105 SNDRV_PCM_FORMAT_S24_LE) 1089 SNDRV_PCM_FORMAT_S24_LE)
1106 1090
1091static struct snd_soc_dai_ops wm8900_dai_ops = {
1092 .hw_params = wm8900_hw_params,
1093 .set_clkdiv = wm8900_set_dai_clkdiv,
1094 .set_pll = wm8900_set_dai_pll,
1095 .set_fmt = wm8900_set_dai_fmt,
1096 .digital_mute = wm8900_digital_mute,
1097};
1098
1107struct snd_soc_dai wm8900_dai = { 1099struct snd_soc_dai wm8900_dai = {
1108 .name = "WM8900 HiFi", 1100 .name = "WM8900 HiFi",
1109 .playback = { 1101 .playback = {
@@ -1120,13 +1112,7 @@ struct snd_soc_dai wm8900_dai = {
1120 .rates = WM8900_RATES, 1112 .rates = WM8900_RATES,
1121 .formats = WM8900_PCM_FORMATS, 1113 .formats = WM8900_PCM_FORMATS,
1122 }, 1114 },
1123 .ops = { 1115 .ops = &wm8900_dai_ops,
1124 .hw_params = wm8900_hw_params,
1125 .set_clkdiv = wm8900_set_dai_clkdiv,
1126 .set_pll = wm8900_set_dai_pll,
1127 .set_fmt = wm8900_set_dai_fmt,
1128 .digital_mute = wm8900_digital_mute,
1129 },
1130}; 1116};
1131EXPORT_SYMBOL_GPL(wm8900_dai); 1117EXPORT_SYMBOL_GPL(wm8900_dai);
1132 1118
@@ -1226,7 +1212,7 @@ static int wm8900_set_bias_level(struct snd_soc_codec *codec,
1226static int wm8900_suspend(struct platform_device *pdev, pm_message_t state) 1212static int wm8900_suspend(struct platform_device *pdev, pm_message_t state)
1227{ 1213{
1228 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1214 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1229 struct snd_soc_codec *codec = socdev->codec; 1215 struct snd_soc_codec *codec = socdev->card->codec;
1230 struct wm8900_priv *wm8900 = codec->private_data; 1216 struct wm8900_priv *wm8900 = codec->private_data;
1231 int fll_out = wm8900->fll_out; 1217 int fll_out = wm8900->fll_out;
1232 int fll_in = wm8900->fll_in; 1218 int fll_in = wm8900->fll_in;
@@ -1250,7 +1236,7 @@ static int wm8900_suspend(struct platform_device *pdev, pm_message_t state)
1250static int wm8900_resume(struct platform_device *pdev) 1236static int wm8900_resume(struct platform_device *pdev)
1251{ 1237{
1252 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1238 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1253 struct snd_soc_codec *codec = socdev->codec; 1239 struct snd_soc_codec *codec = socdev->card->codec;
1254 struct wm8900_priv *wm8900 = codec->private_data; 1240 struct wm8900_priv *wm8900 = codec->private_data;
1255 u16 *cache; 1241 u16 *cache;
1256 int i, ret; 1242 int i, ret;
@@ -1288,8 +1274,8 @@ static int wm8900_resume(struct platform_device *pdev)
1288 1274
1289static struct snd_soc_codec *wm8900_codec; 1275static struct snd_soc_codec *wm8900_codec;
1290 1276
1291static int wm8900_i2c_probe(struct i2c_client *i2c, 1277static __devinit int wm8900_i2c_probe(struct i2c_client *i2c,
1292 const struct i2c_device_id *id) 1278 const struct i2c_device_id *id)
1293{ 1279{
1294 struct wm8900_priv *wm8900; 1280 struct wm8900_priv *wm8900;
1295 struct snd_soc_codec *codec; 1281 struct snd_soc_codec *codec;
@@ -1388,7 +1374,7 @@ err:
1388 return ret; 1374 return ret;
1389} 1375}
1390 1376
1391static int wm8900_i2c_remove(struct i2c_client *client) 1377static __devexit int wm8900_i2c_remove(struct i2c_client *client)
1392{ 1378{
1393 snd_soc_unregister_dai(&wm8900_dai); 1379 snd_soc_unregister_dai(&wm8900_dai);
1394 snd_soc_unregister_codec(wm8900_codec); 1380 snd_soc_unregister_codec(wm8900_codec);
@@ -1414,7 +1400,7 @@ static struct i2c_driver wm8900_i2c_driver = {
1414 .owner = THIS_MODULE, 1400 .owner = THIS_MODULE,
1415 }, 1401 },
1416 .probe = wm8900_i2c_probe, 1402 .probe = wm8900_i2c_probe,
1417 .remove = wm8900_i2c_remove, 1403 .remove = __devexit_p(wm8900_i2c_remove),
1418 .id_table = wm8900_i2c_id, 1404 .id_table = wm8900_i2c_id,
1419}; 1405};
1420 1406
@@ -1430,7 +1416,7 @@ static int wm8900_probe(struct platform_device *pdev)
1430 } 1416 }
1431 1417
1432 codec = wm8900_codec; 1418 codec = wm8900_codec;
1433 socdev->codec = codec; 1419 socdev->card->codec = codec;
1434 1420
1435 /* Register pcms */ 1421 /* Register pcms */
1436 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 1422 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
@@ -1439,7 +1425,8 @@ static int wm8900_probe(struct platform_device *pdev)
1439 goto pcm_err; 1425 goto pcm_err;
1440 } 1426 }
1441 1427
1442 wm8900_add_controls(codec); 1428 snd_soc_add_controls(codec, wm8900_snd_controls,
1429 ARRAY_SIZE(wm8900_snd_controls));
1443 wm8900_add_widgets(codec); 1430 wm8900_add_widgets(codec);
1444 1431
1445 ret = snd_soc_init_card(socdev); 1432 ret = snd_soc_init_card(socdev);
diff --git a/sound/soc/codecs/wm8903.c b/sound/soc/codecs/wm8903.c
index bde74546db4a..8cf571f1a803 100644
--- a/sound/soc/codecs/wm8903.c
+++ b/sound/soc/codecs/wm8903.c
@@ -744,21 +744,6 @@ SOC_DOUBLE_R_TLV("Speaker Volume",
744 0, 63, 0, out_tlv), 744 0, 63, 0, out_tlv),
745}; 745};
746 746
747static int wm8903_add_controls(struct snd_soc_codec *codec)
748{
749 int err, i;
750
751 for (i = 0; i < ARRAY_SIZE(wm8903_snd_controls); i++) {
752 err = snd_ctl_add(codec->card,
753 snd_soc_cnew(&wm8903_snd_controls[i],
754 codec, NULL));
755 if (err < 0)
756 return err;
757 }
758
759 return 0;
760}
761
762static const struct snd_kcontrol_new linput_mode_mux = 747static const struct snd_kcontrol_new linput_mode_mux =
763 SOC_DAPM_ENUM("Left Input Mode Mux", linput_mode_enum); 748 SOC_DAPM_ENUM("Left Input Mode Mux", linput_mode_enum);
764 749
@@ -1276,7 +1261,7 @@ static int wm8903_startup(struct snd_pcm_substream *substream,
1276{ 1261{
1277 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1262 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1278 struct snd_soc_device *socdev = rtd->socdev; 1263 struct snd_soc_device *socdev = rtd->socdev;
1279 struct snd_soc_codec *codec = socdev->codec; 1264 struct snd_soc_codec *codec = socdev->card->codec;
1280 struct wm8903_priv *wm8903 = codec->private_data; 1265 struct wm8903_priv *wm8903 = codec->private_data;
1281 struct i2c_client *i2c = codec->control_data; 1266 struct i2c_client *i2c = codec->control_data;
1282 struct snd_pcm_runtime *master_runtime; 1267 struct snd_pcm_runtime *master_runtime;
@@ -1318,7 +1303,7 @@ static void wm8903_shutdown(struct snd_pcm_substream *substream,
1318{ 1303{
1319 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1304 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1320 struct snd_soc_device *socdev = rtd->socdev; 1305 struct snd_soc_device *socdev = rtd->socdev;
1321 struct snd_soc_codec *codec = socdev->codec; 1306 struct snd_soc_codec *codec = socdev->card->codec;
1322 struct wm8903_priv *wm8903 = codec->private_data; 1307 struct wm8903_priv *wm8903 = codec->private_data;
1323 1308
1324 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 1309 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
@@ -1338,7 +1323,7 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
1338{ 1323{
1339 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1324 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1340 struct snd_soc_device *socdev = rtd->socdev; 1325 struct snd_soc_device *socdev = rtd->socdev;
1341 struct snd_soc_codec *codec = socdev->codec; 1326 struct snd_soc_codec *codec = socdev->card->codec;
1342 struct wm8903_priv *wm8903 = codec->private_data; 1327 struct wm8903_priv *wm8903 = codec->private_data;
1343 struct i2c_client *i2c = codec->control_data; 1328 struct i2c_client *i2c = codec->control_data;
1344 int fs = params_rate(params); 1329 int fs = params_rate(params);
@@ -1512,6 +1497,15 @@ static int wm8903_hw_params(struct snd_pcm_substream *substream,
1512 SNDRV_PCM_FMTBIT_S20_3LE |\ 1497 SNDRV_PCM_FMTBIT_S20_3LE |\
1513 SNDRV_PCM_FMTBIT_S24_LE) 1498 SNDRV_PCM_FMTBIT_S24_LE)
1514 1499
1500static struct snd_soc_dai_ops wm8903_dai_ops = {
1501 .startup = wm8903_startup,
1502 .shutdown = wm8903_shutdown,
1503 .hw_params = wm8903_hw_params,
1504 .digital_mute = wm8903_digital_mute,
1505 .set_fmt = wm8903_set_dai_fmt,
1506 .set_sysclk = wm8903_set_dai_sysclk,
1507};
1508
1515struct snd_soc_dai wm8903_dai = { 1509struct snd_soc_dai wm8903_dai = {
1516 .name = "WM8903", 1510 .name = "WM8903",
1517 .playback = { 1511 .playback = {
@@ -1528,21 +1522,14 @@ struct snd_soc_dai wm8903_dai = {
1528 .rates = WM8903_CAPTURE_RATES, 1522 .rates = WM8903_CAPTURE_RATES,
1529 .formats = WM8903_FORMATS, 1523 .formats = WM8903_FORMATS,
1530 }, 1524 },
1531 .ops = { 1525 .ops = &wm8903_dai_ops,
1532 .startup = wm8903_startup,
1533 .shutdown = wm8903_shutdown,
1534 .hw_params = wm8903_hw_params,
1535 .digital_mute = wm8903_digital_mute,
1536 .set_fmt = wm8903_set_dai_fmt,
1537 .set_sysclk = wm8903_set_dai_sysclk
1538 }
1539}; 1526};
1540EXPORT_SYMBOL_GPL(wm8903_dai); 1527EXPORT_SYMBOL_GPL(wm8903_dai);
1541 1528
1542static int wm8903_suspend(struct platform_device *pdev, pm_message_t state) 1529static int wm8903_suspend(struct platform_device *pdev, pm_message_t state)
1543{ 1530{
1544 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1531 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1545 struct snd_soc_codec *codec = socdev->codec; 1532 struct snd_soc_codec *codec = socdev->card->codec;
1546 1533
1547 wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF); 1534 wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF);
1548 1535
@@ -1552,7 +1539,7 @@ static int wm8903_suspend(struct platform_device *pdev, pm_message_t state)
1552static int wm8903_resume(struct platform_device *pdev) 1539static int wm8903_resume(struct platform_device *pdev)
1553{ 1540{
1554 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1541 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1555 struct snd_soc_codec *codec = socdev->codec; 1542 struct snd_soc_codec *codec = socdev->card->codec;
1556 struct i2c_client *i2c = codec->control_data; 1543 struct i2c_client *i2c = codec->control_data;
1557 int i; 1544 int i;
1558 u16 *reg_cache = codec->reg_cache; 1545 u16 *reg_cache = codec->reg_cache;
@@ -1577,8 +1564,8 @@ static int wm8903_resume(struct platform_device *pdev)
1577 1564
1578static struct snd_soc_codec *wm8903_codec; 1565static struct snd_soc_codec *wm8903_codec;
1579 1566
1580static int wm8903_i2c_probe(struct i2c_client *i2c, 1567static __devinit int wm8903_i2c_probe(struct i2c_client *i2c,
1581 const struct i2c_device_id *id) 1568 const struct i2c_device_id *id)
1582{ 1569{
1583 struct wm8903_priv *wm8903; 1570 struct wm8903_priv *wm8903;
1584 struct snd_soc_codec *codec; 1571 struct snd_soc_codec *codec;
@@ -1684,7 +1671,7 @@ err:
1684 return ret; 1671 return ret;
1685} 1672}
1686 1673
1687static int wm8903_i2c_remove(struct i2c_client *client) 1674static __devexit int wm8903_i2c_remove(struct i2c_client *client)
1688{ 1675{
1689 struct snd_soc_codec *codec = i2c_get_clientdata(client); 1676 struct snd_soc_codec *codec = i2c_get_clientdata(client);
1690 1677
@@ -1714,7 +1701,7 @@ static struct i2c_driver wm8903_i2c_driver = {
1714 .owner = THIS_MODULE, 1701 .owner = THIS_MODULE,
1715 }, 1702 },
1716 .probe = wm8903_i2c_probe, 1703 .probe = wm8903_i2c_probe,
1717 .remove = wm8903_i2c_remove, 1704 .remove = __devexit_p(wm8903_i2c_remove),
1718 .id_table = wm8903_i2c_id, 1705 .id_table = wm8903_i2c_id,
1719}; 1706};
1720 1707
@@ -1728,7 +1715,7 @@ static int wm8903_probe(struct platform_device *pdev)
1728 goto err; 1715 goto err;
1729 } 1716 }
1730 1717
1731 socdev->codec = wm8903_codec; 1718 socdev->card->codec = wm8903_codec;
1732 1719
1733 /* register pcms */ 1720 /* register pcms */
1734 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 1721 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
@@ -1737,8 +1724,9 @@ static int wm8903_probe(struct platform_device *pdev)
1737 goto err; 1724 goto err;
1738 } 1725 }
1739 1726
1740 wm8903_add_controls(socdev->codec); 1727 snd_soc_add_controls(socdev->card->codec, wm8903_snd_controls,
1741 wm8903_add_widgets(socdev->codec); 1728 ARRAY_SIZE(wm8903_snd_controls));
1729 wm8903_add_widgets(socdev->card->codec);
1742 1730
1743 ret = snd_soc_init_card(socdev); 1731 ret = snd_soc_init_card(socdev);
1744 if (ret < 0) { 1732 if (ret < 0) {
@@ -1759,7 +1747,7 @@ err:
1759static int wm8903_remove(struct platform_device *pdev) 1747static int wm8903_remove(struct platform_device *pdev)
1760{ 1748{
1761 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1749 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1762 struct snd_soc_codec *codec = socdev->codec; 1750 struct snd_soc_codec *codec = socdev->card->codec;
1763 1751
1764 if (codec->control_data) 1752 if (codec->control_data)
1765 wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF); 1753 wm8903_set_bias_level(codec, SND_SOC_BIAS_OFF);
diff --git a/sound/soc/codecs/wm8971.c b/sound/soc/codecs/wm8971.c
index 88ead7f8dd98..032dca22dbd3 100644
--- a/sound/soc/codecs/wm8971.c
+++ b/sound/soc/codecs/wm8971.c
@@ -195,21 +195,6 @@ static const struct snd_kcontrol_new wm8971_snd_controls[] = {
195 SOC_DOUBLE_R("Mic Boost", WM8971_LADCIN, WM8971_RADCIN, 4, 3, 0), 195 SOC_DOUBLE_R("Mic Boost", WM8971_LADCIN, WM8971_RADCIN, 4, 3, 0),
196}; 196};
197 197
198/* add non-DAPM controls */
199static int wm8971_add_controls(struct snd_soc_codec *codec)
200{
201 int err, i;
202
203 for (i = 0; i < ARRAY_SIZE(wm8971_snd_controls); i++) {
204 err = snd_ctl_add(codec->card,
205 snd_soc_cnew(&wm8971_snd_controls[i],
206 codec, NULL));
207 if (err < 0)
208 return err;
209 }
210 return 0;
211}
212
213/* 198/*
214 * DAPM Controls 199 * DAPM Controls
215 */ 200 */
@@ -546,7 +531,7 @@ static int wm8971_pcm_hw_params(struct snd_pcm_substream *substream,
546{ 531{
547 struct snd_soc_pcm_runtime *rtd = substream->private_data; 532 struct snd_soc_pcm_runtime *rtd = substream->private_data;
548 struct snd_soc_device *socdev = rtd->socdev; 533 struct snd_soc_device *socdev = rtd->socdev;
549 struct snd_soc_codec *codec = socdev->codec; 534 struct snd_soc_codec *codec = socdev->card->codec;
550 struct wm8971_priv *wm8971 = codec->private_data; 535 struct wm8971_priv *wm8971 = codec->private_data;
551 u16 iface = wm8971_read_reg_cache(codec, WM8971_IFACE) & 0x1f3; 536 u16 iface = wm8971_read_reg_cache(codec, WM8971_IFACE) & 0x1f3;
552 u16 srate = wm8971_read_reg_cache(codec, WM8971_SRATE) & 0x1c0; 537 u16 srate = wm8971_read_reg_cache(codec, WM8971_SRATE) & 0x1c0;
@@ -619,6 +604,13 @@ static int wm8971_set_bias_level(struct snd_soc_codec *codec,
619#define WM8971_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 604#define WM8971_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
620 SNDRV_PCM_FMTBIT_S24_LE) 605 SNDRV_PCM_FMTBIT_S24_LE)
621 606
607static struct snd_soc_dai_ops wm8971_dai_ops = {
608 .hw_params = wm8971_pcm_hw_params,
609 .digital_mute = wm8971_mute,
610 .set_fmt = wm8971_set_dai_fmt,
611 .set_sysclk = wm8971_set_dai_sysclk,
612};
613
622struct snd_soc_dai wm8971_dai = { 614struct snd_soc_dai wm8971_dai = {
623 .name = "WM8971", 615 .name = "WM8971",
624 .playback = { 616 .playback = {
@@ -633,12 +625,7 @@ struct snd_soc_dai wm8971_dai = {
633 .channels_max = 2, 625 .channels_max = 2,
634 .rates = WM8971_RATES, 626 .rates = WM8971_RATES,
635 .formats = WM8971_FORMATS,}, 627 .formats = WM8971_FORMATS,},
636 .ops = { 628 .ops = &wm8971_dai_ops,
637 .hw_params = wm8971_pcm_hw_params,
638 .digital_mute = wm8971_mute,
639 .set_fmt = wm8971_set_dai_fmt,
640 .set_sysclk = wm8971_set_dai_sysclk,
641 },
642}; 629};
643EXPORT_SYMBOL_GPL(wm8971_dai); 630EXPORT_SYMBOL_GPL(wm8971_dai);
644 631
@@ -652,7 +639,7 @@ static void wm8971_work(struct work_struct *work)
652static int wm8971_suspend(struct platform_device *pdev, pm_message_t state) 639static int wm8971_suspend(struct platform_device *pdev, pm_message_t state)
653{ 640{
654 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 641 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
655 struct snd_soc_codec *codec = socdev->codec; 642 struct snd_soc_codec *codec = socdev->card->codec;
656 643
657 wm8971_set_bias_level(codec, SND_SOC_BIAS_OFF); 644 wm8971_set_bias_level(codec, SND_SOC_BIAS_OFF);
658 return 0; 645 return 0;
@@ -661,7 +648,7 @@ static int wm8971_suspend(struct platform_device *pdev, pm_message_t state)
661static int wm8971_resume(struct platform_device *pdev) 648static int wm8971_resume(struct platform_device *pdev)
662{ 649{
663 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 650 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
664 struct snd_soc_codec *codec = socdev->codec; 651 struct snd_soc_codec *codec = socdev->card->codec;
665 int i; 652 int i;
666 u8 data[2]; 653 u8 data[2];
667 u16 *cache = codec->reg_cache; 654 u16 *cache = codec->reg_cache;
@@ -692,7 +679,7 @@ static int wm8971_resume(struct platform_device *pdev)
692 679
693static int wm8971_init(struct snd_soc_device *socdev) 680static int wm8971_init(struct snd_soc_device *socdev)
694{ 681{
695 struct snd_soc_codec *codec = socdev->codec; 682 struct snd_soc_codec *codec = socdev->card->codec;
696 int reg, ret = 0; 683 int reg, ret = 0;
697 684
698 codec->name = "WM8971"; 685 codec->name = "WM8971";
@@ -745,7 +732,8 @@ static int wm8971_init(struct snd_soc_device *socdev)
745 reg = wm8971_read_reg_cache(codec, WM8971_RINVOL); 732 reg = wm8971_read_reg_cache(codec, WM8971_RINVOL);
746 wm8971_write(codec, WM8971_RINVOL, reg | 0x0100); 733 wm8971_write(codec, WM8971_RINVOL, reg | 0x0100);
747 734
748 wm8971_add_controls(codec); 735 snd_soc_add_controls(codec, wm8971_snd_controls,
736 ARRAY_SIZE(wm8971_snd_controls));
749 wm8971_add_widgets(codec); 737 wm8971_add_widgets(codec);
750 ret = snd_soc_init_card(socdev); 738 ret = snd_soc_init_card(socdev);
751 if (ret < 0) { 739 if (ret < 0) {
@@ -772,7 +760,7 @@ static int wm8971_i2c_probe(struct i2c_client *i2c,
772 const struct i2c_device_id *id) 760 const struct i2c_device_id *id)
773{ 761{
774 struct snd_soc_device *socdev = wm8971_socdev; 762 struct snd_soc_device *socdev = wm8971_socdev;
775 struct snd_soc_codec *codec = socdev->codec; 763 struct snd_soc_codec *codec = socdev->card->codec;
776 int ret; 764 int ret;
777 765
778 i2c_set_clientdata(i2c, codec); 766 i2c_set_clientdata(i2c, codec);
@@ -873,7 +861,7 @@ static int wm8971_probe(struct platform_device *pdev)
873 } 861 }
874 862
875 codec->private_data = wm8971; 863 codec->private_data = wm8971;
876 socdev->codec = codec; 864 socdev->card->codec = codec;
877 mutex_init(&codec->mutex); 865 mutex_init(&codec->mutex);
878 INIT_LIST_HEAD(&codec->dapm_widgets); 866 INIT_LIST_HEAD(&codec->dapm_widgets);
879 INIT_LIST_HEAD(&codec->dapm_paths); 867 INIT_LIST_HEAD(&codec->dapm_paths);
@@ -908,7 +896,7 @@ static int wm8971_probe(struct platform_device *pdev)
908static int wm8971_remove(struct platform_device *pdev) 896static int wm8971_remove(struct platform_device *pdev)
909{ 897{
910 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 898 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
911 struct snd_soc_codec *codec = socdev->codec; 899 struct snd_soc_codec *codec = socdev->card->codec;
912 900
913 if (codec->control_data) 901 if (codec->control_data)
914 wm8971_set_bias_level(codec, SND_SOC_BIAS_OFF); 902 wm8971_set_bias_level(codec, SND_SOC_BIAS_OFF);
diff --git a/sound/soc/codecs/wm8990.c b/sound/soc/codecs/wm8990.c
index a5731faa150c..c518c3e5aa3f 100644
--- a/sound/soc/codecs/wm8990.c
+++ b/sound/soc/codecs/wm8990.c
@@ -115,7 +115,7 @@ static inline unsigned int wm8990_read_reg_cache(struct snd_soc_codec *codec,
115 unsigned int reg) 115 unsigned int reg)
116{ 116{
117 u16 *cache = codec->reg_cache; 117 u16 *cache = codec->reg_cache;
118 BUG_ON(reg > (ARRAY_SIZE(wm8990_reg)) - 1); 118 BUG_ON(reg >= ARRAY_SIZE(wm8990_reg));
119 return cache[reg]; 119 return cache[reg];
120} 120}
121 121
@@ -128,7 +128,7 @@ static inline void wm8990_write_reg_cache(struct snd_soc_codec *codec,
128 u16 *cache = codec->reg_cache; 128 u16 *cache = codec->reg_cache;
129 129
130 /* Reset register and reserved registers are uncached */ 130 /* Reset register and reserved registers are uncached */
131 if (reg == 0 || reg > ARRAY_SIZE(wm8990_reg) - 1) 131 if (reg == 0 || reg >= ARRAY_SIZE(wm8990_reg))
132 return; 132 return;
133 133
134 cache[reg] = value; 134 cache[reg] = value;
@@ -418,21 +418,6 @@ SOC_SINGLE("RIN34 Mute Switch", WM8990_RIGHT_LINE_INPUT_3_4_VOLUME,
418 418
419}; 419};
420 420
421/* add non dapm controls */
422static int wm8990_add_controls(struct snd_soc_codec *codec)
423{
424 int err, i;
425
426 for (i = 0; i < ARRAY_SIZE(wm8990_snd_controls); i++) {
427 err = snd_ctl_add(codec->card,
428 snd_soc_cnew(&wm8990_snd_controls[i], codec,
429 NULL));
430 if (err < 0)
431 return err;
432 }
433 return 0;
434}
435
436/* 421/*
437 * _DAPM_ Controls 422 * _DAPM_ Controls
438 */ 423 */
@@ -1178,7 +1163,7 @@ static int wm8990_hw_params(struct snd_pcm_substream *substream,
1178{ 1163{
1179 struct snd_soc_pcm_runtime *rtd = substream->private_data; 1164 struct snd_soc_pcm_runtime *rtd = substream->private_data;
1180 struct snd_soc_device *socdev = rtd->socdev; 1165 struct snd_soc_device *socdev = rtd->socdev;
1181 struct snd_soc_codec *codec = socdev->codec; 1166 struct snd_soc_codec *codec = socdev->card->codec;
1182 u16 audio1 = wm8990_read_reg_cache(codec, WM8990_AUDIO_INTERFACE_1); 1167 u16 audio1 = wm8990_read_reg_cache(codec, WM8990_AUDIO_INTERFACE_1);
1183 1168
1184 audio1 &= ~WM8990_AIF_WL_MASK; 1169 audio1 &= ~WM8990_AIF_WL_MASK;
@@ -1347,6 +1332,15 @@ static int wm8990_set_bias_level(struct snd_soc_codec *codec,
1347 * 1. ADC/DAC on Primary Interface 1332 * 1. ADC/DAC on Primary Interface
1348 * 2. ADC on Primary Interface/DAC on secondary 1333 * 2. ADC on Primary Interface/DAC on secondary
1349 */ 1334 */
1335static struct snd_soc_dai_ops wm8990_dai_ops = {
1336 .hw_params = wm8990_hw_params,
1337 .digital_mute = wm8990_mute,
1338 .set_fmt = wm8990_set_dai_fmt,
1339 .set_clkdiv = wm8990_set_dai_clkdiv,
1340 .set_pll = wm8990_set_dai_pll,
1341 .set_sysclk = wm8990_set_dai_sysclk,
1342};
1343
1350struct snd_soc_dai wm8990_dai = { 1344struct snd_soc_dai wm8990_dai = {
1351/* ADC/DAC on primary */ 1345/* ADC/DAC on primary */
1352 .name = "WM8990 ADC/DAC Primary", 1346 .name = "WM8990 ADC/DAC Primary",
@@ -1363,21 +1357,14 @@ struct snd_soc_dai wm8990_dai = {
1363 .channels_max = 2, 1357 .channels_max = 2,
1364 .rates = WM8990_RATES, 1358 .rates = WM8990_RATES,
1365 .formats = WM8990_FORMATS,}, 1359 .formats = WM8990_FORMATS,},
1366 .ops = { 1360 .ops = &wm8990_dai_ops,
1367 .hw_params = wm8990_hw_params,
1368 .digital_mute = wm8990_mute,
1369 .set_fmt = wm8990_set_dai_fmt,
1370 .set_clkdiv = wm8990_set_dai_clkdiv,
1371 .set_pll = wm8990_set_dai_pll,
1372 .set_sysclk = wm8990_set_dai_sysclk,
1373 },
1374}; 1361};
1375EXPORT_SYMBOL_GPL(wm8990_dai); 1362EXPORT_SYMBOL_GPL(wm8990_dai);
1376 1363
1377static int wm8990_suspend(struct platform_device *pdev, pm_message_t state) 1364static int wm8990_suspend(struct platform_device *pdev, pm_message_t state)
1378{ 1365{
1379 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1366 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1380 struct snd_soc_codec *codec = socdev->codec; 1367 struct snd_soc_codec *codec = socdev->card->codec;
1381 1368
1382 /* we only need to suspend if we are a valid card */ 1369 /* we only need to suspend if we are a valid card */
1383 if (!codec->card) 1370 if (!codec->card)
@@ -1390,7 +1377,7 @@ static int wm8990_suspend(struct platform_device *pdev, pm_message_t state)
1390static int wm8990_resume(struct platform_device *pdev) 1377static int wm8990_resume(struct platform_device *pdev)
1391{ 1378{
1392 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1379 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1393 struct snd_soc_codec *codec = socdev->codec; 1380 struct snd_soc_codec *codec = socdev->card->codec;
1394 int i; 1381 int i;
1395 u8 data[2]; 1382 u8 data[2];
1396 u16 *cache = codec->reg_cache; 1383 u16 *cache = codec->reg_cache;
@@ -1418,7 +1405,7 @@ static int wm8990_resume(struct platform_device *pdev)
1418 */ 1405 */
1419static int wm8990_init(struct snd_soc_device *socdev) 1406static int wm8990_init(struct snd_soc_device *socdev)
1420{ 1407{
1421 struct snd_soc_codec *codec = socdev->codec; 1408 struct snd_soc_codec *codec = socdev->card->codec;
1422 u16 reg; 1409 u16 reg;
1423 int ret = 0; 1410 int ret = 0;
1424 1411
@@ -1461,7 +1448,8 @@ static int wm8990_init(struct snd_soc_device *socdev)
1461 wm8990_write(codec, WM8990_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8)); 1448 wm8990_write(codec, WM8990_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8));
1462 wm8990_write(codec, WM8990_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8)); 1449 wm8990_write(codec, WM8990_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8));
1463 1450
1464 wm8990_add_controls(codec); 1451 snd_soc_add_controls(codec, wm8990_snd_controls,
1452 ARRAY_SIZE(wm8990_snd_controls));
1465 wm8990_add_widgets(codec); 1453 wm8990_add_widgets(codec);
1466 ret = snd_soc_init_card(socdev); 1454 ret = snd_soc_init_card(socdev);
1467 if (ret < 0) { 1455 if (ret < 0) {
@@ -1495,7 +1483,7 @@ static int wm8990_i2c_probe(struct i2c_client *i2c,
1495 const struct i2c_device_id *id) 1483 const struct i2c_device_id *id)
1496{ 1484{
1497 struct snd_soc_device *socdev = wm8990_socdev; 1485 struct snd_soc_device *socdev = wm8990_socdev;
1498 struct snd_soc_codec *codec = socdev->codec; 1486 struct snd_soc_codec *codec = socdev->card->codec;
1499 int ret; 1487 int ret;
1500 1488
1501 i2c_set_clientdata(i2c, codec); 1489 i2c_set_clientdata(i2c, codec);
@@ -1594,7 +1582,7 @@ static int wm8990_probe(struct platform_device *pdev)
1594 } 1582 }
1595 1583
1596 codec->private_data = wm8990; 1584 codec->private_data = wm8990;
1597 socdev->codec = codec; 1585 socdev->card->codec = codec;
1598 mutex_init(&codec->mutex); 1586 mutex_init(&codec->mutex);
1599 INIT_LIST_HEAD(&codec->dapm_widgets); 1587 INIT_LIST_HEAD(&codec->dapm_widgets);
1600 INIT_LIST_HEAD(&codec->dapm_paths); 1588 INIT_LIST_HEAD(&codec->dapm_paths);
@@ -1620,7 +1608,7 @@ static int wm8990_probe(struct platform_device *pdev)
1620static int wm8990_remove(struct platform_device *pdev) 1608static int wm8990_remove(struct platform_device *pdev)
1621{ 1609{
1622 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1610 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1623 struct snd_soc_codec *codec = socdev->codec; 1611 struct snd_soc_codec *codec = socdev->card->codec;
1624 1612
1625 if (codec->control_data) 1613 if (codec->control_data)
1626 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF); 1614 wm8990_set_bias_level(codec, SND_SOC_BIAS_OFF);
diff --git a/sound/soc/codecs/wm9705.c b/sound/soc/codecs/wm9705.c
new file mode 100644
index 000000000000..3265817c5c26
--- /dev/null
+++ b/sound/soc/codecs/wm9705.c
@@ -0,0 +1,415 @@
1/*
2 * wm9705.c -- ALSA Soc WM9705 codec support
3 *
4 * Copyright 2008 Ian Molton <spyro@f2s.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; Version 2 of the License only.
9 *
10 */
11
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/kernel.h>
15#include <linux/device.h>
16#include <sound/core.h>
17#include <sound/pcm.h>
18#include <sound/ac97_codec.h>
19#include <sound/initval.h>
20#include <sound/soc.h>
21#include <sound/soc-dapm.h>
22
23#include "wm9705.h"
24
25/*
26 * WM9705 register cache
27 */
28static const u16 wm9705_reg[] = {
29 0x6150, 0x8000, 0x8000, 0x8000, /* 0x0 */
30 0x0000, 0x8000, 0x8008, 0x8008, /* 0x8 */
31 0x8808, 0x8808, 0x8808, 0x8808, /* 0x10 */
32 0x8808, 0x0000, 0x8000, 0x0000, /* 0x18 */
33 0x0000, 0x0000, 0x0000, 0x000f, /* 0x20 */
34 0x0605, 0x0000, 0xbb80, 0x0000, /* 0x28 */
35 0x0000, 0xbb80, 0x0000, 0x0000, /* 0x30 */
36 0x0000, 0x2000, 0x0000, 0x0000, /* 0x38 */
37 0x0000, 0x0000, 0x0000, 0x0000, /* 0x40 */
38 0x0000, 0x0000, 0x0000, 0x0000, /* 0x48 */
39 0x0000, 0x0000, 0x0000, 0x0000, /* 0x50 */
40 0x0000, 0x0000, 0x0000, 0x0000, /* 0x58 */
41 0x0000, 0x0000, 0x0000, 0x0000, /* 0x60 */
42 0x0000, 0x0000, 0x0000, 0x0000, /* 0x68 */
43 0x0000, 0x0808, 0x0000, 0x0006, /* 0x70 */
44 0x0000, 0x0000, 0x574d, 0x4c05, /* 0x78 */
45};
46
47static const struct snd_kcontrol_new wm9705_snd_ac97_controls[] = {
48 SOC_DOUBLE("Master Playback Volume", AC97_MASTER, 8, 0, 31, 1),
49 SOC_SINGLE("Master Playback Switch", AC97_MASTER, 15, 1, 1),
50 SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
51 SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 1, 1),
52 SOC_DOUBLE("PCM Playback Volume", AC97_PCM, 8, 0, 31, 1),
53 SOC_SINGLE("PCM Playback Switch", AC97_PCM, 15, 1, 1),
54 SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1),
55 SOC_SINGLE("Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1),
56 SOC_SINGLE("PCBeep Playback Volume", AC97_PC_BEEP, 1, 15, 1),
57 SOC_SINGLE("Phone Playback Volume", AC97_PHONE, 0, 31, 1),
58 SOC_DOUBLE("Line Playback Volume", AC97_LINE, 8, 0, 31, 1),
59 SOC_DOUBLE("CD Playback Volume", AC97_CD, 8, 0, 31, 1),
60 SOC_SINGLE("Mic Playback Volume", AC97_MIC, 0, 31, 1),
61 SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 6, 1, 0),
62 SOC_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 0),
63 SOC_SINGLE("Capture Switch", AC97_REC_GAIN, 15, 1, 1),
64};
65
66static const char *wm9705_mic[] = {"Mic 1", "Mic 2"};
67static const char *wm9705_rec_sel[] = {"Mic", "CD", "NC", "NC",
68 "Line", "Stereo Mix", "Mono Mix", "Phone"};
69
70static const struct soc_enum wm9705_enum_mic =
71 SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 8, 2, wm9705_mic);
72static const struct soc_enum wm9705_enum_rec_l =
73 SOC_ENUM_SINGLE(AC97_REC_SEL, 8, 8, wm9705_rec_sel);
74static const struct soc_enum wm9705_enum_rec_r =
75 SOC_ENUM_SINGLE(AC97_REC_SEL, 0, 8, wm9705_rec_sel);
76
77/* Headphone Mixer */
78static const struct snd_kcontrol_new wm9705_hp_mixer_controls[] = {
79 SOC_DAPM_SINGLE("PCBeep Playback Switch", AC97_PC_BEEP, 15, 1, 1),
80 SOC_DAPM_SINGLE("CD Playback Switch", AC97_CD, 15, 1, 1),
81 SOC_DAPM_SINGLE("Mic Playback Switch", AC97_MIC, 15, 1, 1),
82 SOC_DAPM_SINGLE("Phone Playback Switch", AC97_PHONE, 15, 1, 1),
83 SOC_DAPM_SINGLE("Line Playback Switch", AC97_LINE, 15, 1, 1),
84};
85
86/* Mic source */
87static const struct snd_kcontrol_new wm9705_mic_src_controls =
88 SOC_DAPM_ENUM("Route", wm9705_enum_mic);
89
90/* Capture source */
91static const struct snd_kcontrol_new wm9705_capture_selectl_controls =
92 SOC_DAPM_ENUM("Route", wm9705_enum_rec_l);
93static const struct snd_kcontrol_new wm9705_capture_selectr_controls =
94 SOC_DAPM_ENUM("Route", wm9705_enum_rec_r);
95
96/* DAPM widgets */
97static const struct snd_soc_dapm_widget wm9705_dapm_widgets[] = {
98 SND_SOC_DAPM_MUX("Mic Source", SND_SOC_NOPM, 0, 0,
99 &wm9705_mic_src_controls),
100 SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0,
101 &wm9705_capture_selectl_controls),
102 SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0,
103 &wm9705_capture_selectr_controls),
104 SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback",
105 SND_SOC_NOPM, 0, 0),
106 SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback",
107 SND_SOC_NOPM, 0, 0),
108 SND_SOC_DAPM_MIXER_NAMED_CTL("HP Mixer", SND_SOC_NOPM, 0, 0,
109 &wm9705_hp_mixer_controls[0],
110 ARRAY_SIZE(wm9705_hp_mixer_controls)),
111 SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
112 SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", SND_SOC_NOPM, 0, 0),
113 SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", SND_SOC_NOPM, 0, 0),
114 SND_SOC_DAPM_PGA("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
115 SND_SOC_DAPM_PGA("Speaker PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
116 SND_SOC_DAPM_PGA("Line PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
117 SND_SOC_DAPM_PGA("Line out PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
118 SND_SOC_DAPM_PGA("Mono PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
119 SND_SOC_DAPM_PGA("Phone PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
120 SND_SOC_DAPM_PGA("Mic PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
121 SND_SOC_DAPM_PGA("PCBEEP PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
122 SND_SOC_DAPM_PGA("CD PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
123 SND_SOC_DAPM_PGA("ADC PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
124 SND_SOC_DAPM_OUTPUT("HPOUTL"),
125 SND_SOC_DAPM_OUTPUT("HPOUTR"),
126 SND_SOC_DAPM_OUTPUT("LOUT"),
127 SND_SOC_DAPM_OUTPUT("ROUT"),
128 SND_SOC_DAPM_OUTPUT("MONOOUT"),
129 SND_SOC_DAPM_INPUT("PHONE"),
130 SND_SOC_DAPM_INPUT("LINEINL"),
131 SND_SOC_DAPM_INPUT("LINEINR"),
132 SND_SOC_DAPM_INPUT("CDINL"),
133 SND_SOC_DAPM_INPUT("CDINR"),
134 SND_SOC_DAPM_INPUT("PCBEEP"),
135 SND_SOC_DAPM_INPUT("MIC1"),
136 SND_SOC_DAPM_INPUT("MIC2"),
137};
138
139/* Audio map
140 * WM9705 has no switches to disable the route from the inputs to the HP mixer
141 * so in order to prevent active inputs from forcing the audio outputs to be
142 * constantly enabled, we use the mutes on those inputs to simulate such
143 * controls.
144 */
145static const struct snd_soc_dapm_route audio_map[] = {
146 /* HP mixer */
147 {"HP Mixer", "PCBeep Playback Switch", "PCBEEP PGA"},
148 {"HP Mixer", "CD Playback Switch", "CD PGA"},
149 {"HP Mixer", "Mic Playback Switch", "Mic PGA"},
150 {"HP Mixer", "Phone Playback Switch", "Phone PGA"},
151 {"HP Mixer", "Line Playback Switch", "Line PGA"},
152 {"HP Mixer", NULL, "Left DAC"},
153 {"HP Mixer", NULL, "Right DAC"},
154
155 /* mono mixer */
156 {"Mono Mixer", NULL, "HP Mixer"},
157
158 /* outputs */
159 {"Headphone PGA", NULL, "HP Mixer"},
160 {"HPOUTL", NULL, "Headphone PGA"},
161 {"HPOUTR", NULL, "Headphone PGA"},
162 {"Line out PGA", NULL, "HP Mixer"},
163 {"LOUT", NULL, "Line out PGA"},
164 {"ROUT", NULL, "Line out PGA"},
165 {"Mono PGA", NULL, "Mono Mixer"},
166 {"MONOOUT", NULL, "Mono PGA"},
167
168 /* inputs */
169 {"CD PGA", NULL, "CDINL"},
170 {"CD PGA", NULL, "CDINR"},
171 {"Line PGA", NULL, "LINEINL"},
172 {"Line PGA", NULL, "LINEINR"},
173 {"Phone PGA", NULL, "PHONE"},
174 {"Mic Source", "Mic 1", "MIC1"},
175 {"Mic Source", "Mic 2", "MIC2"},
176 {"Mic PGA", NULL, "Mic Source"},
177 {"PCBEEP PGA", NULL, "PCBEEP"},
178
179 /* Left capture selector */
180 {"Left Capture Source", "Mic", "Mic Source"},
181 {"Left Capture Source", "CD", "CDINL"},
182 {"Left Capture Source", "Line", "LINEINL"},
183 {"Left Capture Source", "Stereo Mix", "HP Mixer"},
184 {"Left Capture Source", "Mono Mix", "HP Mixer"},
185 {"Left Capture Source", "Phone", "PHONE"},
186
187 /* Right capture source */
188 {"Right Capture Source", "Mic", "Mic Source"},
189 {"Right Capture Source", "CD", "CDINR"},
190 {"Right Capture Source", "Line", "LINEINR"},
191 {"Right Capture Source", "Stereo Mix", "HP Mixer"},
192 {"Right Capture Source", "Mono Mix", "HP Mixer"},
193 {"Right Capture Source", "Phone", "PHONE"},
194
195 {"ADC PGA", NULL, "Left Capture Source"},
196 {"ADC PGA", NULL, "Right Capture Source"},
197
198 /* ADC's */
199 {"Left ADC", NULL, "ADC PGA"},
200 {"Right ADC", NULL, "ADC PGA"},
201};
202
203static int wm9705_add_widgets(struct snd_soc_codec *codec)
204{
205 snd_soc_dapm_new_controls(codec, wm9705_dapm_widgets,
206 ARRAY_SIZE(wm9705_dapm_widgets));
207 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
208 snd_soc_dapm_new_widgets(codec);
209
210 return 0;
211}
212
213/* We use a register cache to enhance read performance. */
214static unsigned int ac97_read(struct snd_soc_codec *codec, unsigned int reg)
215{
216 u16 *cache = codec->reg_cache;
217
218 switch (reg) {
219 case AC97_RESET:
220 case AC97_VENDOR_ID1:
221 case AC97_VENDOR_ID2:
222 return soc_ac97_ops.read(codec->ac97, reg);
223 default:
224 reg = reg >> 1;
225
226 if (reg >= (ARRAY_SIZE(wm9705_reg)))
227 return -EIO;
228
229 return cache[reg];
230 }
231}
232
233static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
234 unsigned int val)
235{
236 u16 *cache = codec->reg_cache;
237
238 soc_ac97_ops.write(codec->ac97, reg, val);
239 reg = reg >> 1;
240 if (reg < (ARRAY_SIZE(wm9705_reg)))
241 cache[reg] = val;
242
243 return 0;
244}
245
246static int ac97_prepare(struct snd_pcm_substream *substream,
247 struct snd_soc_dai *dai)
248{
249 struct snd_pcm_runtime *runtime = substream->runtime;
250 struct snd_soc_pcm_runtime *rtd = substream->private_data;
251 struct snd_soc_device *socdev = rtd->socdev;
252 struct snd_soc_codec *codec = socdev->card->codec;
253 int reg;
254 u16 vra;
255
256 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
257 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
258
259 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
260 reg = AC97_PCM_FRONT_DAC_RATE;
261 else
262 reg = AC97_PCM_LR_ADC_RATE;
263
264 return ac97_write(codec, reg, runtime->rate);
265}
266
267#define WM9705_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | \
268 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
269 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
270 SNDRV_PCM_RATE_48000)
271
272static struct snd_soc_dai_ops wm9705_dai_ops = {
273 .prepare = ac97_prepare,
274};
275
276struct snd_soc_dai wm9705_dai[] = {
277 {
278 .name = "AC97 HiFi",
279 .ac97_control = 1,
280 .playback = {
281 .stream_name = "HiFi Playback",
282 .channels_min = 1,
283 .channels_max = 2,
284 .rates = WM9705_AC97_RATES,
285 .formats = SNDRV_PCM_FMTBIT_S16_LE,
286 },
287 .capture = {
288 .stream_name = "HiFi Capture",
289 .channels_min = 1,
290 .channels_max = 2,
291 .rates = WM9705_AC97_RATES,
292 .formats = SNDRV_PCM_FMTBIT_S16_LE,
293 },
294 .ops = &wm9705_dai_ops,
295 },
296 {
297 .name = "AC97 Aux",
298 .playback = {
299 .stream_name = "Aux Playback",
300 .channels_min = 1,
301 .channels_max = 1,
302 .rates = WM9705_AC97_RATES,
303 .formats = SNDRV_PCM_FMTBIT_S16_LE,
304 },
305 }
306};
307EXPORT_SYMBOL_GPL(wm9705_dai);
308
309static int wm9705_reset(struct snd_soc_codec *codec)
310{
311 if (soc_ac97_ops.reset) {
312 soc_ac97_ops.reset(codec->ac97);
313 if (ac97_read(codec, 0) == wm9705_reg[0])
314 return 0; /* Success */
315 }
316
317 return -EIO;
318}
319
320static int wm9705_soc_probe(struct platform_device *pdev)
321{
322 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
323 struct snd_soc_codec *codec;
324 int ret = 0;
325
326 printk(KERN_INFO "WM9705 SoC Audio Codec\n");
327
328 socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec),
329 GFP_KERNEL);
330 if (socdev->card->codec == NULL)
331 return -ENOMEM;
332 codec = socdev->card->codec;
333 mutex_init(&codec->mutex);
334
335 codec->reg_cache = kmemdup(wm9705_reg, sizeof(wm9705_reg), GFP_KERNEL);
336 if (codec->reg_cache == NULL) {
337 ret = -ENOMEM;
338 goto cache_err;
339 }
340 codec->reg_cache_size = sizeof(wm9705_reg);
341 codec->reg_cache_step = 2;
342
343 codec->name = "WM9705";
344 codec->owner = THIS_MODULE;
345 codec->dai = wm9705_dai;
346 codec->num_dai = ARRAY_SIZE(wm9705_dai);
347 codec->write = ac97_write;
348 codec->read = ac97_read;
349 INIT_LIST_HEAD(&codec->dapm_widgets);
350 INIT_LIST_HEAD(&codec->dapm_paths);
351
352 ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0);
353 if (ret < 0) {
354 printk(KERN_ERR "wm9705: failed to register AC97 codec\n");
355 goto codec_err;
356 }
357
358 /* register pcms */
359 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
360 if (ret < 0)
361 goto pcm_err;
362
363 ret = wm9705_reset(codec);
364 if (ret)
365 goto reset_err;
366
367 snd_soc_add_controls(codec, wm9705_snd_ac97_controls,
368 ARRAY_SIZE(wm9705_snd_ac97_controls));
369 wm9705_add_widgets(codec);
370
371 ret = snd_soc_init_card(socdev);
372 if (ret < 0) {
373 printk(KERN_ERR "wm9705: failed to register card\n");
374 goto pcm_err;
375 }
376
377 return 0;
378
379reset_err:
380 snd_soc_free_pcms(socdev);
381pcm_err:
382 snd_soc_free_ac97_codec(codec);
383codec_err:
384 kfree(codec->reg_cache);
385cache_err:
386 kfree(socdev->card->codec);
387 socdev->card->codec = NULL;
388 return ret;
389}
390
391static int wm9705_soc_remove(struct platform_device *pdev)
392{
393 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
394 struct snd_soc_codec *codec = socdev->card->codec;
395
396 if (codec == NULL)
397 return 0;
398
399 snd_soc_dapm_free(socdev);
400 snd_soc_free_pcms(socdev);
401 snd_soc_free_ac97_codec(codec);
402 kfree(codec->reg_cache);
403 kfree(codec);
404 return 0;
405}
406
407struct snd_soc_codec_device soc_codec_dev_wm9705 = {
408 .probe = wm9705_soc_probe,
409 .remove = wm9705_soc_remove,
410};
411EXPORT_SYMBOL_GPL(soc_codec_dev_wm9705);
412
413MODULE_DESCRIPTION("ASoC WM9705 driver");
414MODULE_AUTHOR("Ian Molton");
415MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/codecs/wm9705.h b/sound/soc/codecs/wm9705.h
new file mode 100644
index 000000000000..d380f110f9e2
--- /dev/null
+++ b/sound/soc/codecs/wm9705.h
@@ -0,0 +1,14 @@
1/*
2 * wm9705.h -- WM9705 Soc Audio driver
3 */
4
5#ifndef _WM9705_H
6#define _WM9705_H
7
8#define WM9705_DAI_AC97_HIFI 0
9#define WM9705_DAI_AC97_AUX 1
10
11extern struct snd_soc_dai wm9705_dai[2];
12extern struct snd_soc_codec_device soc_codec_dev_wm9705;
13
14#endif
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
index af83d629078a..765cf1e7369e 100644
--- a/sound/soc/codecs/wm9712.c
+++ b/sound/soc/codecs/wm9712.c
@@ -154,21 +154,6 @@ SOC_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
154SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0), 154SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 7, 1, 0),
155}; 155};
156 156
157/* add non dapm controls */
158static int wm9712_add_controls(struct snd_soc_codec *codec)
159{
160 int err, i;
161
162 for (i = 0; i < ARRAY_SIZE(wm9712_snd_ac97_controls); i++) {
163 err = snd_ctl_add(codec->card,
164 snd_soc_cnew(&wm9712_snd_ac97_controls[i],
165 codec, NULL));
166 if (err < 0)
167 return err;
168 }
169 return 0;
170}
171
172/* We have to create a fake left and right HP mixers because 157/* We have to create a fake left and right HP mixers because
173 * the codec only has a single control that is shared by both channels. 158 * the codec only has a single control that is shared by both channels.
174 * This makes it impossible to determine the audio path. 159 * This makes it impossible to determine the audio path.
@@ -467,7 +452,7 @@ static unsigned int ac97_read(struct snd_soc_codec *codec,
467 else { 452 else {
468 reg = reg >> 1; 453 reg = reg >> 1;
469 454
470 if (reg > (ARRAY_SIZE(wm9712_reg))) 455 if (reg >= (ARRAY_SIZE(wm9712_reg)))
471 return -EIO; 456 return -EIO;
472 457
473 return cache[reg]; 458 return cache[reg];
@@ -481,7 +466,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
481 466
482 soc_ac97_ops.write(codec->ac97, reg, val); 467 soc_ac97_ops.write(codec->ac97, reg, val);
483 reg = reg >> 1; 468 reg = reg >> 1;
484 if (reg <= (ARRAY_SIZE(wm9712_reg))) 469 if (reg < (ARRAY_SIZE(wm9712_reg)))
485 cache[reg] = val; 470 cache[reg] = val;
486 471
487 return 0; 472 return 0;
@@ -493,7 +478,7 @@ static int ac97_prepare(struct snd_pcm_substream *substream,
493 struct snd_pcm_runtime *runtime = substream->runtime; 478 struct snd_pcm_runtime *runtime = substream->runtime;
494 struct snd_soc_pcm_runtime *rtd = substream->private_data; 479 struct snd_soc_pcm_runtime *rtd = substream->private_data;
495 struct snd_soc_device *socdev = rtd->socdev; 480 struct snd_soc_device *socdev = rtd->socdev;
496 struct snd_soc_codec *codec = socdev->codec; 481 struct snd_soc_codec *codec = socdev->card->codec;
497 int reg; 482 int reg;
498 u16 vra; 483 u16 vra;
499 484
@@ -514,7 +499,7 @@ static int ac97_aux_prepare(struct snd_pcm_substream *substream,
514 struct snd_pcm_runtime *runtime = substream->runtime; 499 struct snd_pcm_runtime *runtime = substream->runtime;
515 struct snd_soc_pcm_runtime *rtd = substream->private_data; 500 struct snd_soc_pcm_runtime *rtd = substream->private_data;
516 struct snd_soc_device *socdev = rtd->socdev; 501 struct snd_soc_device *socdev = rtd->socdev;
517 struct snd_soc_codec *codec = socdev->codec; 502 struct snd_soc_codec *codec = socdev->card->codec;
518 u16 vra, xsle; 503 u16 vra, xsle;
519 504
520 vra = ac97_read(codec, AC97_EXTENDED_STATUS); 505 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
@@ -532,6 +517,14 @@ static int ac97_aux_prepare(struct snd_pcm_substream *substream,
532 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\ 517 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
533 SNDRV_PCM_RATE_48000) 518 SNDRV_PCM_RATE_48000)
534 519
520static struct snd_soc_dai_ops wm9712_dai_ops_hifi = {
521 .prepare = ac97_prepare,
522};
523
524static struct snd_soc_dai_ops wm9712_dai_ops_aux = {
525 .prepare = ac97_aux_prepare,
526};
527
535struct snd_soc_dai wm9712_dai[] = { 528struct snd_soc_dai wm9712_dai[] = {
536{ 529{
537 .name = "AC97 HiFi", 530 .name = "AC97 HiFi",
@@ -548,8 +541,7 @@ struct snd_soc_dai wm9712_dai[] = {
548 .channels_max = 2, 541 .channels_max = 2,
549 .rates = WM9712_AC97_RATES, 542 .rates = WM9712_AC97_RATES,
550 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 543 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
551 .ops = { 544 .ops = &wm9712_dai_ops_hifi,
552 .prepare = ac97_prepare,},
553}, 545},
554{ 546{
555 .name = "AC97 Aux", 547 .name = "AC97 Aux",
@@ -559,8 +551,7 @@ struct snd_soc_dai wm9712_dai[] = {
559 .channels_max = 1, 551 .channels_max = 1,
560 .rates = WM9712_AC97_RATES, 552 .rates = WM9712_AC97_RATES,
561 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 553 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
562 .ops = { 554 .ops = &wm9712_dai_ops_aux,
563 .prepare = ac97_aux_prepare,},
564} 555}
565}; 556};
566EXPORT_SYMBOL_GPL(wm9712_dai); 557EXPORT_SYMBOL_GPL(wm9712_dai);
@@ -607,7 +598,7 @@ static int wm9712_soc_suspend(struct platform_device *pdev,
607 pm_message_t state) 598 pm_message_t state)
608{ 599{
609 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 600 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
610 struct snd_soc_codec *codec = socdev->codec; 601 struct snd_soc_codec *codec = socdev->card->codec;
611 602
612 wm9712_set_bias_level(codec, SND_SOC_BIAS_OFF); 603 wm9712_set_bias_level(codec, SND_SOC_BIAS_OFF);
613 return 0; 604 return 0;
@@ -616,7 +607,7 @@ static int wm9712_soc_suspend(struct platform_device *pdev,
616static int wm9712_soc_resume(struct platform_device *pdev) 607static int wm9712_soc_resume(struct platform_device *pdev)
617{ 608{
618 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 609 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
619 struct snd_soc_codec *codec = socdev->codec; 610 struct snd_soc_codec *codec = socdev->card->codec;
620 int i, ret; 611 int i, ret;
621 u16 *cache = codec->reg_cache; 612 u16 *cache = codec->reg_cache;
622 613
@@ -652,10 +643,11 @@ static int wm9712_soc_probe(struct platform_device *pdev)
652 643
653 printk(KERN_INFO "WM9711/WM9712 SoC Audio Codec %s\n", WM9712_VERSION); 644 printk(KERN_INFO "WM9711/WM9712 SoC Audio Codec %s\n", WM9712_VERSION);
654 645
655 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 646 socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec),
656 if (socdev->codec == NULL) 647 GFP_KERNEL);
648 if (socdev->card->codec == NULL)
657 return -ENOMEM; 649 return -ENOMEM;
658 codec = socdev->codec; 650 codec = socdev->card->codec;
659 mutex_init(&codec->mutex); 651 mutex_init(&codec->mutex);
660 652
661 codec->reg_cache = kmemdup(wm9712_reg, sizeof(wm9712_reg), GFP_KERNEL); 653 codec->reg_cache = kmemdup(wm9712_reg, sizeof(wm9712_reg), GFP_KERNEL);
@@ -698,7 +690,8 @@ static int wm9712_soc_probe(struct platform_device *pdev)
698 ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000); 690 ac97_write(codec, AC97_VIDEO, ac97_read(codec, AC97_VIDEO) | 0x3000);
699 691
700 wm9712_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 692 wm9712_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
701 wm9712_add_controls(codec); 693 snd_soc_add_controls(codec, wm9712_snd_ac97_controls,
694 ARRAY_SIZE(wm9712_snd_ac97_controls));
702 wm9712_add_widgets(codec); 695 wm9712_add_widgets(codec);
703 ret = snd_soc_init_card(socdev); 696 ret = snd_soc_init_card(socdev);
704 if (ret < 0) { 697 if (ret < 0) {
@@ -718,15 +711,15 @@ codec_err:
718 kfree(codec->reg_cache); 711 kfree(codec->reg_cache);
719 712
720cache_err: 713cache_err:
721 kfree(socdev->codec); 714 kfree(socdev->card->codec);
722 socdev->codec = NULL; 715 socdev->card->codec = NULL;
723 return ret; 716 return ret;
724} 717}
725 718
726static int wm9712_soc_remove(struct platform_device *pdev) 719static int wm9712_soc_remove(struct platform_device *pdev)
727{ 720{
728 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 721 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
729 struct snd_soc_codec *codec = socdev->codec; 722 struct snd_soc_codec *codec = socdev->card->codec;
730 723
731 if (codec == NULL) 724 if (codec == NULL)
732 return 0; 725 return 0;
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
index f3ca8aaf0139..523bad077fa0 100644
--- a/sound/soc/codecs/wm9713.c
+++ b/sound/soc/codecs/wm9713.c
@@ -32,7 +32,6 @@
32 32
33struct wm9713_priv { 33struct wm9713_priv {
34 u32 pll_in; /* PLL input frequency */ 34 u32 pll_in; /* PLL input frequency */
35 u32 pll_out; /* PLL output frequency */
36}; 35};
37 36
38static unsigned int ac97_read(struct snd_soc_codec *codec, 37static unsigned int ac97_read(struct snd_soc_codec *codec,
@@ -190,21 +189,6 @@ SOC_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
190SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), 189SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
191}; 190};
192 191
193/* add non dapm controls */
194static int wm9713_add_controls(struct snd_soc_codec *codec)
195{
196 int err, i;
197
198 for (i = 0; i < ARRAY_SIZE(wm9713_snd_ac97_controls); i++) {
199 err = snd_ctl_add(codec->card,
200 snd_soc_cnew(&wm9713_snd_ac97_controls[i],
201 codec, NULL));
202 if (err < 0)
203 return err;
204 }
205 return 0;
206}
207
208/* We have to create a fake left and right HP mixers because 192/* We have to create a fake left and right HP mixers because
209 * the codec only has a single control that is shared by both channels. 193 * the codec only has a single control that is shared by both channels.
210 * This makes it impossible to determine the audio path using the current 194 * This makes it impossible to determine the audio path using the current
@@ -636,7 +620,7 @@ static unsigned int ac97_read(struct snd_soc_codec *codec,
636 else { 620 else {
637 reg = reg >> 1; 621 reg = reg >> 1;
638 622
639 if (reg > (ARRAY_SIZE(wm9713_reg))) 623 if (reg >= (ARRAY_SIZE(wm9713_reg)))
640 return -EIO; 624 return -EIO;
641 625
642 return cache[reg]; 626 return cache[reg];
@@ -650,7 +634,7 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
650 if (reg < 0x7c) 634 if (reg < 0x7c)
651 soc_ac97_ops.write(codec->ac97, reg, val); 635 soc_ac97_ops.write(codec->ac97, reg, val);
652 reg = reg >> 1; 636 reg = reg >> 1;
653 if (reg <= (ARRAY_SIZE(wm9713_reg))) 637 if (reg < (ARRAY_SIZE(wm9713_reg)))
654 cache[reg] = val; 638 cache[reg] = val;
655 639
656 return 0; 640 return 0;
@@ -738,13 +722,13 @@ static int wm9713_set_pll(struct snd_soc_codec *codec,
738 struct _pll_div pll_div; 722 struct _pll_div pll_div;
739 723
740 /* turn PLL off ? */ 724 /* turn PLL off ? */
741 if (freq_in == 0 || freq_out == 0) { 725 if (freq_in == 0) {
742 /* disable PLL power and select ext source */ 726 /* disable PLL power and select ext source */
743 reg = ac97_read(codec, AC97_HANDSET_RATE); 727 reg = ac97_read(codec, AC97_HANDSET_RATE);
744 ac97_write(codec, AC97_HANDSET_RATE, reg | 0x0080); 728 ac97_write(codec, AC97_HANDSET_RATE, reg | 0x0080);
745 reg = ac97_read(codec, AC97_EXTENDED_MID); 729 reg = ac97_read(codec, AC97_EXTENDED_MID);
746 ac97_write(codec, AC97_EXTENDED_MID, reg | 0x0200); 730 ac97_write(codec, AC97_EXTENDED_MID, reg | 0x0200);
747 wm9713->pll_out = 0; 731 wm9713->pll_in = 0;
748 return 0; 732 return 0;
749 } 733 }
750 734
@@ -788,7 +772,6 @@ static int wm9713_set_pll(struct snd_soc_codec *codec,
788 ac97_write(codec, AC97_EXTENDED_MID, reg & 0xfdff); 772 ac97_write(codec, AC97_EXTENDED_MID, reg & 0xfdff);
789 reg = ac97_read(codec, AC97_HANDSET_RATE); 773 reg = ac97_read(codec, AC97_HANDSET_RATE);
790 ac97_write(codec, AC97_HANDSET_RATE, reg & 0xff7f); 774 ac97_write(codec, AC97_HANDSET_RATE, reg & 0xff7f);
791 wm9713->pll_out = freq_out;
792 wm9713->pll_in = freq_in; 775 wm9713->pll_in = freq_in;
793 776
794 /* wait 10ms AC97 link frames for the link to stabilise */ 777 /* wait 10ms AC97 link frames for the link to stabilise */
@@ -957,13 +940,14 @@ static void wm9713_voiceshutdown(struct snd_pcm_substream *substream,
957 struct snd_soc_dai *dai) 940 struct snd_soc_dai *dai)
958{ 941{
959 struct snd_soc_codec *codec = dai->codec; 942 struct snd_soc_codec *codec = dai->codec;
960 u16 status; 943 u16 status, rate;
961 944
962 /* Gracefully shut down the voice interface. */ 945 /* Gracefully shut down the voice interface. */
963 status = ac97_read(codec, AC97_EXTENDED_STATUS) | 0x1000; 946 status = ac97_read(codec, AC97_EXTENDED_STATUS) | 0x1000;
964 ac97_write(codec, AC97_HANDSET_RATE, 0x0280); 947 rate = ac97_read(codec, AC97_HANDSET_RATE) & 0xF0FF;
948 ac97_write(codec, AC97_HANDSET_RATE, rate | 0x0200);
965 schedule_timeout_interruptible(msecs_to_jiffies(1)); 949 schedule_timeout_interruptible(msecs_to_jiffies(1));
966 ac97_write(codec, AC97_HANDSET_RATE, 0x0F80); 950 ac97_write(codec, AC97_HANDSET_RATE, rate | 0x0F00);
967 ac97_write(codec, AC97_EXTENDED_MID, status); 951 ac97_write(codec, AC97_EXTENDED_MID, status);
968} 952}
969 953
@@ -1021,6 +1005,27 @@ static int ac97_aux_prepare(struct snd_pcm_substream *substream,
1021 (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \ 1005 (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \
1022 SNDRV_PCM_FORMAT_S24_LE) 1006 SNDRV_PCM_FORMAT_S24_LE)
1023 1007
1008static struct snd_soc_dai_ops wm9713_dai_ops_hifi = {
1009 .prepare = ac97_hifi_prepare,
1010 .set_clkdiv = wm9713_set_dai_clkdiv,
1011 .set_pll = wm9713_set_dai_pll,
1012};
1013
1014static struct snd_soc_dai_ops wm9713_dai_ops_aux = {
1015 .prepare = ac97_aux_prepare,
1016 .set_clkdiv = wm9713_set_dai_clkdiv,
1017 .set_pll = wm9713_set_dai_pll,
1018};
1019
1020static struct snd_soc_dai_ops wm9713_dai_ops_voice = {
1021 .hw_params = wm9713_pcm_hw_params,
1022 .shutdown = wm9713_voiceshutdown,
1023 .set_clkdiv = wm9713_set_dai_clkdiv,
1024 .set_pll = wm9713_set_dai_pll,
1025 .set_fmt = wm9713_set_dai_fmt,
1026 .set_tristate = wm9713_set_dai_tristate,
1027};
1028
1024struct snd_soc_dai wm9713_dai[] = { 1029struct snd_soc_dai wm9713_dai[] = {
1025{ 1030{
1026 .name = "AC97 HiFi", 1031 .name = "AC97 HiFi",
@@ -1037,10 +1042,7 @@ struct snd_soc_dai wm9713_dai[] = {
1037 .channels_max = 2, 1042 .channels_max = 2,
1038 .rates = WM9713_RATES, 1043 .rates = WM9713_RATES,
1039 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 1044 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
1040 .ops = { 1045 .ops = &wm9713_dai_ops_hifi,
1041 .prepare = ac97_hifi_prepare,
1042 .set_clkdiv = wm9713_set_dai_clkdiv,
1043 .set_pll = wm9713_set_dai_pll,},
1044 }, 1046 },
1045 { 1047 {
1046 .name = "AC97 Aux", 1048 .name = "AC97 Aux",
@@ -1050,10 +1052,7 @@ struct snd_soc_dai wm9713_dai[] = {
1050 .channels_max = 1, 1052 .channels_max = 1,
1051 .rates = WM9713_RATES, 1053 .rates = WM9713_RATES,
1052 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 1054 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
1053 .ops = { 1055 .ops = &wm9713_dai_ops_aux,
1054 .prepare = ac97_aux_prepare,
1055 .set_clkdiv = wm9713_set_dai_clkdiv,
1056 .set_pll = wm9713_set_dai_pll,},
1057 }, 1056 },
1058 { 1057 {
1059 .name = "WM9713 Voice", 1058 .name = "WM9713 Voice",
@@ -1069,14 +1068,7 @@ struct snd_soc_dai wm9713_dai[] = {
1069 .channels_max = 2, 1068 .channels_max = 2,
1070 .rates = WM9713_PCM_RATES, 1069 .rates = WM9713_PCM_RATES,
1071 .formats = WM9713_PCM_FORMATS,}, 1070 .formats = WM9713_PCM_FORMATS,},
1072 .ops = { 1071 .ops = &wm9713_dai_ops_voice,
1073 .hw_params = wm9713_pcm_hw_params,
1074 .shutdown = wm9713_voiceshutdown,
1075 .set_clkdiv = wm9713_set_dai_clkdiv,
1076 .set_pll = wm9713_set_dai_pll,
1077 .set_fmt = wm9713_set_dai_fmt,
1078 .set_tristate = wm9713_set_dai_tristate,
1079 },
1080 }, 1072 },
1081}; 1073};
1082EXPORT_SYMBOL_GPL(wm9713_dai); 1074EXPORT_SYMBOL_GPL(wm9713_dai);
@@ -1132,7 +1124,7 @@ static int wm9713_soc_suspend(struct platform_device *pdev,
1132 pm_message_t state) 1124 pm_message_t state)
1133{ 1125{
1134 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1126 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1135 struct snd_soc_codec *codec = socdev->codec; 1127 struct snd_soc_codec *codec = socdev->card->codec;
1136 u16 reg; 1128 u16 reg;
1137 1129
1138 /* Disable everything except touchpanel - that will be handled 1130 /* Disable everything except touchpanel - that will be handled
@@ -1150,7 +1142,7 @@ static int wm9713_soc_suspend(struct platform_device *pdev,
1150static int wm9713_soc_resume(struct platform_device *pdev) 1142static int wm9713_soc_resume(struct platform_device *pdev)
1151{ 1143{
1152 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1144 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1153 struct snd_soc_codec *codec = socdev->codec; 1145 struct snd_soc_codec *codec = socdev->card->codec;
1154 struct wm9713_priv *wm9713 = codec->private_data; 1146 struct wm9713_priv *wm9713 = codec->private_data;
1155 int i, ret; 1147 int i, ret;
1156 u16 *cache = codec->reg_cache; 1148 u16 *cache = codec->reg_cache;
@@ -1164,8 +1156,8 @@ static int wm9713_soc_resume(struct platform_device *pdev)
1164 wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY); 1156 wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
1165 1157
1166 /* do we need to re-start the PLL ? */ 1158 /* do we need to re-start the PLL ? */
1167 if (wm9713->pll_out) 1159 if (wm9713->pll_in)
1168 wm9713_set_pll(codec, 0, wm9713->pll_in, wm9713->pll_out); 1160 wm9713_set_pll(codec, 0, wm9713->pll_in, 0);
1169 1161
1170 /* only synchronise the codec if warm reset failed */ 1162 /* only synchronise the codec if warm reset failed */
1171 if (ret == 0) { 1163 if (ret == 0) {
@@ -1191,10 +1183,11 @@ static int wm9713_soc_probe(struct platform_device *pdev)
1191 1183
1192 printk(KERN_INFO "WM9713/WM9714 SoC Audio Codec %s\n", WM9713_VERSION); 1184 printk(KERN_INFO "WM9713/WM9714 SoC Audio Codec %s\n", WM9713_VERSION);
1193 1185
1194 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 1186 socdev->card->codec = kzalloc(sizeof(struct snd_soc_codec),
1195 if (socdev->codec == NULL) 1187 GFP_KERNEL);
1188 if (socdev->card->codec == NULL)
1196 return -ENOMEM; 1189 return -ENOMEM;
1197 codec = socdev->codec; 1190 codec = socdev->card->codec;
1198 mutex_init(&codec->mutex); 1191 mutex_init(&codec->mutex);
1199 1192
1200 codec->reg_cache = kmemdup(wm9713_reg, sizeof(wm9713_reg), GFP_KERNEL); 1193 codec->reg_cache = kmemdup(wm9713_reg, sizeof(wm9713_reg), GFP_KERNEL);
@@ -1245,7 +1238,8 @@ static int wm9713_soc_probe(struct platform_device *pdev)
1245 reg = ac97_read(codec, AC97_CD) & 0x7fff; 1238 reg = ac97_read(codec, AC97_CD) & 0x7fff;
1246 ac97_write(codec, AC97_CD, reg); 1239 ac97_write(codec, AC97_CD, reg);
1247 1240
1248 wm9713_add_controls(codec); 1241 snd_soc_add_controls(codec, wm9713_snd_ac97_controls,
1242 ARRAY_SIZE(wm9713_snd_ac97_controls));
1249 wm9713_add_widgets(codec); 1243 wm9713_add_widgets(codec);
1250 ret = snd_soc_init_card(socdev); 1244 ret = snd_soc_init_card(socdev);
1251 if (ret < 0) 1245 if (ret < 0)
@@ -1265,15 +1259,15 @@ priv_err:
1265 kfree(codec->reg_cache); 1259 kfree(codec->reg_cache);
1266 1260
1267cache_err: 1261cache_err:
1268 kfree(socdev->codec); 1262 kfree(socdev->card->codec);
1269 socdev->codec = NULL; 1263 socdev->card->codec = NULL;
1270 return ret; 1264 return ret;
1271} 1265}
1272 1266
1273static int wm9713_soc_remove(struct platform_device *pdev) 1267static int wm9713_soc_remove(struct platform_device *pdev)
1274{ 1268{
1275 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 1269 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1276 struct snd_soc_codec *codec = socdev->codec; 1270 struct snd_soc_codec *codec = socdev->card->codec;
1277 1271
1278 if (codec == NULL) 1272 if (codec == NULL)
1279 return 0; 1273 return 0;
diff --git a/sound/soc/davinci/Kconfig b/sound/soc/davinci/Kconfig
index b502741692d6..bd7392c9657e 100644
--- a/sound/soc/davinci/Kconfig
+++ b/sound/soc/davinci/Kconfig
@@ -20,7 +20,7 @@ config SND_DAVINCI_SOC_EVM
20 20
21config SND_DAVINCI_SOC_SFFSDR 21config SND_DAVINCI_SOC_SFFSDR
22 tristate "SoC Audio support for SFFSDR" 22 tristate "SoC Audio support for SFFSDR"
23 depends on SND_DAVINCI_SOC && MACH_DAVINCI_SFFSDR 23 depends on SND_DAVINCI_SOC && MACH_SFFSDR
24 select SND_DAVINCI_SOC_I2S 24 select SND_DAVINCI_SOC_I2S
25 select SND_SOC_PCM3008 25 select SND_SOC_PCM3008
26 select SFFSDR_FPGA 26 select SFFSDR_FPGA
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
index 54851f318568..9b90b347007c 100644
--- a/sound/soc/davinci/davinci-evm.c
+++ b/sound/soc/davinci/davinci-evm.c
@@ -186,7 +186,8 @@ static int __init evm_init(void)
186 186
187 platform_set_drvdata(evm_snd_device, &evm_snd_devdata); 187 platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
188 evm_snd_devdata.dev = &evm_snd_device->dev; 188 evm_snd_devdata.dev = &evm_snd_device->dev;
189 evm_snd_device->dev.platform_data = &evm_snd_data; 189 platform_device_add_data(evm_snd_device, &evm_snd_data,
190 sizeof(evm_snd_data));
190 191
191 ret = platform_device_add_resources(evm_snd_device, evm_snd_resources, 192 ret = platform_device_add_resources(evm_snd_device, evm_snd_resources,
192 ARRAY_SIZE(evm_snd_resources)); 193 ARRAY_SIZE(evm_snd_resources));
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c
index 0fee779e3c76..ffdb9439d3d8 100644
--- a/sound/soc/davinci/davinci-i2s.c
+++ b/sound/soc/davinci/davinci-i2s.c
@@ -499,6 +499,13 @@ static void davinci_i2s_remove(struct platform_device *pdev,
499 499
500#define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000 500#define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000
501 501
502static struct snd_soc_dai_ops davinci_i2s_dai_ops = {
503 .startup = davinci_i2s_startup,
504 .trigger = davinci_i2s_trigger,
505 .hw_params = davinci_i2s_hw_params,
506 .set_fmt = davinci_i2s_set_dai_fmt,
507};
508
502struct snd_soc_dai davinci_i2s_dai = { 509struct snd_soc_dai davinci_i2s_dai = {
503 .name = "davinci-i2s", 510 .name = "davinci-i2s",
504 .id = 0, 511 .id = 0,
@@ -514,12 +521,7 @@ struct snd_soc_dai davinci_i2s_dai = {
514 .channels_max = 2, 521 .channels_max = 2,
515 .rates = DAVINCI_I2S_RATES, 522 .rates = DAVINCI_I2S_RATES,
516 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 523 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
517 .ops = { 524 .ops = &davinci_i2s_dai_ops,
518 .startup = davinci_i2s_startup,
519 .trigger = davinci_i2s_trigger,
520 .hw_params = davinci_i2s_hw_params,
521 .set_fmt = davinci_i2s_set_dai_fmt,
522 },
523}; 525};
524EXPORT_SYMBOL_GPL(davinci_i2s_dai); 526EXPORT_SYMBOL_GPL(davinci_i2s_dai);
525 527
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c
index 366049d8578c..7af3b5b3a53d 100644
--- a/sound/soc/davinci/davinci-pcm.c
+++ b/sound/soc/davinci/davinci-pcm.c
@@ -286,7 +286,7 @@ static int davinci_pcm_mmap(struct snd_pcm_substream *substream,
286 runtime->dma_bytes); 286 runtime->dma_bytes);
287} 287}
288 288
289struct snd_pcm_ops davinci_pcm_ops = { 289static struct snd_pcm_ops davinci_pcm_ops = {
290 .open = davinci_pcm_open, 290 .open = davinci_pcm_open,
291 .close = davinci_pcm_close, 291 .close = davinci_pcm_close,
292 .ioctl = snd_pcm_lib_ioctl, 292 .ioctl = snd_pcm_lib_ioctl,
diff --git a/sound/soc/davinci/davinci-sffsdr.c b/sound/soc/davinci/davinci-sffsdr.c
index 4935d1bcbd8d..40eccfe9e358 100644
--- a/sound/soc/davinci/davinci-sffsdr.c
+++ b/sound/soc/davinci/davinci-sffsdr.c
@@ -25,7 +25,9 @@
25 25
26#include <asm/dma.h> 26#include <asm/dma.h>
27#include <asm/mach-types.h> 27#include <asm/mach-types.h>
28#ifdef CONFIG_SFFSDR_FPGA
28#include <asm/plat-sffsdr/sffsdr-fpga.h> 29#include <asm/plat-sffsdr/sffsdr-fpga.h>
30#endif
29 31
30#include <mach/mcbsp.h> 32#include <mach/mcbsp.h>
31#include <mach/edma.h> 33#include <mach/edma.h>
@@ -34,31 +36,45 @@
34#include "davinci-pcm.h" 36#include "davinci-pcm.h"
35#include "davinci-i2s.h" 37#include "davinci-i2s.h"
36 38
39/*
40 * CLKX and CLKR are the inputs for the Sample Rate Generator.
41 * FSX and FSR are outputs, driven by the sample Rate Generator.
42 */
43#define AUDIO_FORMAT (SND_SOC_DAIFMT_DSP_B | \
44 SND_SOC_DAIFMT_CBM_CFS | \
45 SND_SOC_DAIFMT_IB_NF)
46
37static int sffsdr_hw_params(struct snd_pcm_substream *substream, 47static int sffsdr_hw_params(struct snd_pcm_substream *substream,
38 struct snd_pcm_hw_params *params, 48 struct snd_pcm_hw_params *params)
39 struct snd_soc_dai *dai)
40{ 49{
41 struct snd_soc_pcm_runtime *rtd = substream->private_data; 50 struct snd_soc_pcm_runtime *rtd = substream->private_data;
42 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; 51 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
43 int fs; 52 int fs;
44 int ret = 0; 53 int ret = 0;
45 54
46 /* Set cpu DAI configuration:
47 * CLKX and CLKR are the inputs for the Sample Rate Generator.
48 * FSX and FSR are outputs, driven by the sample Rate Generator. */
49 ret = snd_soc_dai_set_fmt(cpu_dai,
50 SND_SOC_DAIFMT_RIGHT_J |
51 SND_SOC_DAIFMT_CBM_CFS |
52 SND_SOC_DAIFMT_IB_NF);
53 if (ret < 0)
54 return ret;
55
56 /* Fsref can be 32000, 44100 or 48000. */ 55 /* Fsref can be 32000, 44100 or 48000. */
57 fs = params_rate(params); 56 fs = params_rate(params);
58 57
58#ifndef CONFIG_SFFSDR_FPGA
59 /* Without the FPGA module, the Fs is fixed at 44100 Hz */
60 if (fs != 44100) {
61 pr_debug("warning: only 44.1 kHz is supported without SFFSDR FPGA module\n");
62 return -EINVAL;
63 }
64#endif
65
66 /* set cpu DAI configuration */
67 ret = snd_soc_dai_set_fmt(cpu_dai, AUDIO_FORMAT);
68 if (ret < 0)
69 return ret;
70
59 pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs); 71 pr_debug("sffsdr_hw_params: rate = %d Hz\n", fs);
60 72
73#ifndef CONFIG_SFFSDR_FPGA
74 return 0;
75#else
61 return sffsdr_fpga_set_codec_fs(fs); 76 return sffsdr_fpga_set_codec_fs(fs);
77#endif
62} 78}
63 79
64static struct snd_soc_ops sffsdr_ops = { 80static struct snd_soc_ops sffsdr_ops = {
@@ -127,7 +143,8 @@ static int __init sffsdr_init(void)
127 143
128 platform_set_drvdata(sffsdr_snd_device, &sffsdr_snd_devdata); 144 platform_set_drvdata(sffsdr_snd_device, &sffsdr_snd_devdata);
129 sffsdr_snd_devdata.dev = &sffsdr_snd_device->dev; 145 sffsdr_snd_devdata.dev = &sffsdr_snd_device->dev;
130 sffsdr_snd_device->dev.platform_data = &sffsdr_snd_data; 146 platform_device_add_data(sffsdr_snd_device, &sffsdr_snd_data,
147 sizeof(sffsdr_snd_data));
131 148
132 ret = platform_device_add_resources(sffsdr_snd_device, 149 ret = platform_device_add_resources(sffsdr_snd_device,
133 sffsdr_snd_resources, 150 sffsdr_snd_resources,
diff --git a/sound/soc/fsl/Kconfig b/sound/soc/fsl/Kconfig
index 95c12b26fe37..9fc908283371 100644
--- a/sound/soc/fsl/Kconfig
+++ b/sound/soc/fsl/Kconfig
@@ -1,17 +1,18 @@
1config SND_SOC_OF_SIMPLE 1config SND_SOC_OF_SIMPLE
2 tristate 2 tristate
3 3
4# ASoC platform support for the Freescale MPC8610 SOC. This compiles drivers
5# for the SSI and the Elo DMA controller. You will still need to select
6# a platform driver and a codec driver.
4config SND_SOC_MPC8610 7config SND_SOC_MPC8610
5 bool "ALSA SoC support for the MPC8610 SOC" 8 tristate
6 depends on MPC8610_HPCD 9 depends on MPC8610
7 default y if MPC8610
8 help
9 Say Y if you want to add support for codecs attached to the SSI
10 device on an MPC8610.
11 10
12config SND_SOC_MPC8610_HPCD 11config SND_SOC_MPC8610_HPCD
13 bool "ALSA SoC support for the Freescale MPC8610 HPCD board" 12 tristate "ALSA SoC support for the Freescale MPC8610 HPCD board"
14 depends on SND_SOC_MPC8610 13 # I2C is necessary for the CS4270 driver
14 depends on MPC8610_HPCD && I2C
15 select SND_SOC_MPC8610
15 select SND_SOC_CS4270 16 select SND_SOC_CS4270
16 select SND_SOC_CS4270_VD33_ERRATA 17 select SND_SOC_CS4270_VD33_ERRATA
17 default y if MPC8610_HPCD 18 default y if MPC8610_HPCD
diff --git a/sound/soc/fsl/Makefile b/sound/soc/fsl/Makefile
index 035da4afec34..f85134c86387 100644
--- a/sound/soc/fsl/Makefile
+++ b/sound/soc/fsl/Makefile
@@ -2,10 +2,13 @@
2obj-$(CONFIG_SND_SOC_OF_SIMPLE) += soc-of-simple.o 2obj-$(CONFIG_SND_SOC_OF_SIMPLE) += soc-of-simple.o
3 3
4# MPC8610 HPCD Machine Support 4# MPC8610 HPCD Machine Support
5obj-$(CONFIG_SND_SOC_MPC8610_HPCD) += mpc8610_hpcd.o 5snd-soc-mpc8610-hpcd-objs := mpc8610_hpcd.o
6obj-$(CONFIG_SND_SOC_MPC8610_HPCD) += snd-soc-mpc8610-hpcd.o
6 7
7# MPC8610 Platform Support 8# MPC8610 Platform Support
8obj-$(CONFIG_SND_SOC_MPC8610) += fsl_ssi.o fsl_dma.o 9snd-soc-fsl-ssi-objs := fsl_ssi.o
10snd-soc-fsl-dma-objs := fsl_dma.o
11obj-$(CONFIG_SND_SOC_MPC8610) += snd-soc-fsl-ssi.o snd-soc-fsl-dma.o
9 12
10obj-$(CONFIG_SND_SOC_MPC5200_I2S) += mpc5200_psc_i2s.o 13obj-$(CONFIG_SND_SOC_MPC5200_I2S) += mpc5200_psc_i2s.o
11 14
diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
index 64993eda5679..b3eb8570cd7b 100644
--- a/sound/soc/fsl/fsl_dma.c
+++ b/sound/soc/fsl/fsl_dma.c
@@ -142,7 +142,8 @@ static const struct snd_pcm_hardware fsl_dma_hardware = {
142 .info = SNDRV_PCM_INFO_INTERLEAVED | 142 .info = SNDRV_PCM_INFO_INTERLEAVED |
143 SNDRV_PCM_INFO_MMAP | 143 SNDRV_PCM_INFO_MMAP |
144 SNDRV_PCM_INFO_MMAP_VALID | 144 SNDRV_PCM_INFO_MMAP_VALID |
145 SNDRV_PCM_INFO_JOINT_DUPLEX, 145 SNDRV_PCM_INFO_JOINT_DUPLEX |
146 SNDRV_PCM_INFO_PAUSE,
146 .formats = FSLDMA_PCM_FORMATS, 147 .formats = FSLDMA_PCM_FORMATS,
147 .rates = FSLDMA_PCM_RATES, 148 .rates = FSLDMA_PCM_RATES,
148 .rate_min = 5512, 149 .rate_min = 5512,
@@ -464,11 +465,7 @@ static int fsl_dma_open(struct snd_pcm_substream *substream)
464 sizeof(struct fsl_dma_link_descriptor); 465 sizeof(struct fsl_dma_link_descriptor);
465 466
466 for (i = 0; i < NUM_DMA_LINKS; i++) { 467 for (i = 0; i < NUM_DMA_LINKS; i++) {
467 struct fsl_dma_link_descriptor *link = &dma_private->link[i]; 468 dma_private->link[i].next = cpu_to_be64(temp_link);
468
469 link->source_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP);
470 link->dest_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP);
471 link->next = cpu_to_be64(temp_link);
472 469
473 temp_link += sizeof(struct fsl_dma_link_descriptor); 470 temp_link += sizeof(struct fsl_dma_link_descriptor);
474 } 471 }
@@ -525,79 +522,9 @@ static int fsl_dma_open(struct snd_pcm_substream *substream)
525 * This function obtains hardware parameters about the opened stream and 522 * This function obtains hardware parameters about the opened stream and
526 * programs the DMA controller accordingly. 523 * programs the DMA controller accordingly.
527 * 524 *
528 * Note that due to a quirk of the SSI's STX register, the target address 525 * One drawback of big-endian is that when copying integers of different
529 * for the DMA operations depends on the sample size. So we don't program 526 * sizes to a fixed-sized register, the address to which the integer must be
530 * the dest_addr (for playback -- source_addr for capture) fields in the 527 * copied is dependent on the size of the integer.
531 * link descriptors here. We do that in fsl_dma_prepare()
532 */
533static int fsl_dma_hw_params(struct snd_pcm_substream *substream,
534 struct snd_pcm_hw_params *hw_params)
535{
536 struct snd_pcm_runtime *runtime = substream->runtime;
537 struct fsl_dma_private *dma_private = runtime->private_data;
538
539 dma_addr_t temp_addr; /* Pointer to next period */
540
541 unsigned int i;
542
543 /* Get all the parameters we need */
544 size_t buffer_size = params_buffer_bytes(hw_params);
545 size_t period_size = params_period_bytes(hw_params);
546
547 /* Initialize our DMA tracking variables */
548 dma_private->period_size = period_size;
549 dma_private->num_periods = params_periods(hw_params);
550 dma_private->dma_buf_end = dma_private->dma_buf_phys + buffer_size;
551 dma_private->dma_buf_next = dma_private->dma_buf_phys +
552 (NUM_DMA_LINKS * period_size);
553 if (dma_private->dma_buf_next >= dma_private->dma_buf_end)
554 dma_private->dma_buf_next = dma_private->dma_buf_phys;
555
556 /*
557 * The actual address in STX0 (destination for playback, source for
558 * capture) is based on the sample size, but we don't know the sample
559 * size in this function, so we'll have to adjust that later. See
560 * comments in fsl_dma_prepare().
561 *
562 * The DMA controller does not have a cache, so the CPU does not
563 * need to tell it to flush its cache. However, the DMA
564 * controller does need to tell the CPU to flush its cache.
565 * That's what the SNOOP bit does.
566 *
567 * Also, even though the DMA controller supports 36-bit addressing, for
568 * simplicity we currently support only 32-bit addresses for the audio
569 * buffer itself.
570 */
571 temp_addr = substream->dma_buffer.addr;
572
573 for (i = 0; i < NUM_DMA_LINKS; i++) {
574 struct fsl_dma_link_descriptor *link = &dma_private->link[i];
575
576 link->count = cpu_to_be32(period_size);
577
578 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
579 link->source_addr = cpu_to_be32(temp_addr);
580 else
581 link->dest_addr = cpu_to_be32(temp_addr);
582
583 temp_addr += period_size;
584 }
585
586 return 0;
587}
588
589/**
590 * fsl_dma_prepare - prepare the DMA registers for playback.
591 *
592 * This function is called after the specifics of the audio data are known,
593 * i.e. snd_pcm_runtime is initialized.
594 *
595 * In this function, we finish programming the registers of the DMA
596 * controller that are dependent on the sample size.
597 *
598 * One of the drawbacks with big-endian is that when copying integers of
599 * different sizes to a fixed-sized register, the address to which the
600 * integer must be copied is dependent on the size of the integer.
601 * 528 *
602 * For example, if P is the address of a 32-bit register, and X is a 32-bit 529 * For example, if P is the address of a 32-bit register, and X is a 32-bit
603 * integer, then X should be copied to address P. However, if X is a 16-bit 530 * integer, then X should be copied to address P. However, if X is a 16-bit
@@ -613,22 +540,58 @@ static int fsl_dma_hw_params(struct snd_pcm_substream *substream,
613 * and 8 bytes at a time). So we do not support packed 24-bit samples. 540 * and 8 bytes at a time). So we do not support packed 24-bit samples.
614 * 24-bit data must be padded to 32 bits. 541 * 24-bit data must be padded to 32 bits.
615 */ 542 */
616static int fsl_dma_prepare(struct snd_pcm_substream *substream) 543static int fsl_dma_hw_params(struct snd_pcm_substream *substream,
544 struct snd_pcm_hw_params *hw_params)
617{ 545{
618 struct snd_pcm_runtime *runtime = substream->runtime; 546 struct snd_pcm_runtime *runtime = substream->runtime;
619 struct fsl_dma_private *dma_private = runtime->private_data; 547 struct fsl_dma_private *dma_private = runtime->private_data;
548
549 /* Number of bits per sample */
550 unsigned int sample_size =
551 snd_pcm_format_physical_width(params_format(hw_params));
552
553 /* Number of bytes per frame */
554 unsigned int frame_size = 2 * (sample_size / 8);
555
556 /* Bus address of SSI STX register */
557 dma_addr_t ssi_sxx_phys = dma_private->ssi_sxx_phys;
558
559 /* Size of the DMA buffer, in bytes */
560 size_t buffer_size = params_buffer_bytes(hw_params);
561
562 /* Number of bytes per period */
563 size_t period_size = params_period_bytes(hw_params);
564
565 /* Pointer to next period */
566 dma_addr_t temp_addr = substream->dma_buffer.addr;
567
568 /* Pointer to DMA controller */
620 struct ccsr_dma_channel __iomem *dma_channel = dma_private->dma_channel; 569 struct ccsr_dma_channel __iomem *dma_channel = dma_private->dma_channel;
621 u32 mr; 570
571 u32 mr; /* DMA Mode Register */
572
622 unsigned int i; 573 unsigned int i;
623 dma_addr_t ssi_sxx_phys; /* Bus address of SSI STX register */
624 unsigned int frame_size; /* Number of bytes per frame */
625 574
626 ssi_sxx_phys = dma_private->ssi_sxx_phys; 575 /* Initialize our DMA tracking variables */
576 dma_private->period_size = period_size;
577 dma_private->num_periods = params_periods(hw_params);
578 dma_private->dma_buf_end = dma_private->dma_buf_phys + buffer_size;
579 dma_private->dma_buf_next = dma_private->dma_buf_phys +
580 (NUM_DMA_LINKS * period_size);
581
582 if (dma_private->dma_buf_next >= dma_private->dma_buf_end)
583 /* This happens if the number of periods == NUM_DMA_LINKS */
584 dma_private->dma_buf_next = dma_private->dma_buf_phys;
627 585
628 mr = in_be32(&dma_channel->mr) & ~(CCSR_DMA_MR_BWC_MASK | 586 mr = in_be32(&dma_channel->mr) & ~(CCSR_DMA_MR_BWC_MASK |
629 CCSR_DMA_MR_SAHTS_MASK | CCSR_DMA_MR_DAHTS_MASK); 587 CCSR_DMA_MR_SAHTS_MASK | CCSR_DMA_MR_DAHTS_MASK);
630 588
631 switch (runtime->sample_bits) { 589 /* Due to a quirk of the SSI's STX register, the target address
590 * for the DMA operations depends on the sample size. So we calculate
591 * that offset here. While we're at it, also tell the DMA controller
592 * how much data to transfer per sample.
593 */
594 switch (sample_size) {
632 case 8: 595 case 8:
633 mr |= CCSR_DMA_MR_DAHTS_1 | CCSR_DMA_MR_SAHTS_1; 596 mr |= CCSR_DMA_MR_DAHTS_1 | CCSR_DMA_MR_SAHTS_1;
634 ssi_sxx_phys += 3; 597 ssi_sxx_phys += 3;
@@ -641,12 +604,12 @@ static int fsl_dma_prepare(struct snd_pcm_substream *substream)
641 mr |= CCSR_DMA_MR_DAHTS_4 | CCSR_DMA_MR_SAHTS_4; 604 mr |= CCSR_DMA_MR_DAHTS_4 | CCSR_DMA_MR_SAHTS_4;
642 break; 605 break;
643 default: 606 default:
607 /* We should never get here */
644 dev_err(substream->pcm->card->dev, 608 dev_err(substream->pcm->card->dev,
645 "unsupported sample size %u\n", runtime->sample_bits); 609 "unsupported sample size %u\n", sample_size);
646 return -EINVAL; 610 return -EINVAL;
647 } 611 }
648 612
649 frame_size = runtime->frame_bits / 8;
650 /* 613 /*
651 * BWC should always be a multiple of the frame size. BWC determines 614 * BWC should always be a multiple of the frame size. BWC determines
652 * how many bytes are sent/received before the DMA controller checks the 615 * how many bytes are sent/received before the DMA controller checks the
@@ -655,7 +618,6 @@ static int fsl_dma_prepare(struct snd_pcm_substream *substream)
655 * capture, the receive FIFO is triggered when it contains one frame, so 618 * capture, the receive FIFO is triggered when it contains one frame, so
656 * we want to receive one frame at a time. 619 * we want to receive one frame at a time.
657 */ 620 */
658
659 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 621 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
660 mr |= CCSR_DMA_MR_BWC(2 * frame_size); 622 mr |= CCSR_DMA_MR_BWC(2 * frame_size);
661 else 623 else
@@ -663,16 +625,48 @@ static int fsl_dma_prepare(struct snd_pcm_substream *substream)
663 625
664 out_be32(&dma_channel->mr, mr); 626 out_be32(&dma_channel->mr, mr);
665 627
666 /*
667 * Program the address of the DMA transfer to/from the SSI.
668 */
669 for (i = 0; i < NUM_DMA_LINKS; i++) { 628 for (i = 0; i < NUM_DMA_LINKS; i++) {
670 struct fsl_dma_link_descriptor *link = &dma_private->link[i]; 629 struct fsl_dma_link_descriptor *link = &dma_private->link[i];
671 630
672 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 631 link->count = cpu_to_be32(period_size);
632
633 /* Even though the DMA controller supports 36-bit addressing,
634 * for simplicity we allow only 32-bit addresses for the audio
635 * buffer itself. This was enforced in fsl_dma_new() with the
636 * DMA mask.
637 *
638 * The snoop bit tells the DMA controller whether it should tell
639 * the ECM to snoop during a read or write to an address. For
640 * audio, we use DMA to transfer data between memory and an I/O
641 * device (the SSI's STX0 or SRX0 register). Snooping is only
642 * needed if there is a cache, so we need to snoop memory
643 * addresses only. For playback, that means we snoop the source
644 * but not the destination. For capture, we snoop the
645 * destination but not the source.
646 *
647 * Note that failing to snoop properly is unlikely to cause
648 * cache incoherency if the period size is larger than the
649 * size of L1 cache. This is because filling in one period will
650 * flush out the data for the previous period. So if you
651 * increased period_bytes_min to a large enough size, you might
652 * get more performance by not snooping, and you'll still be
653 * okay.
654 */
655 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
656 link->source_addr = cpu_to_be32(temp_addr);
657 link->source_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP);
658
673 link->dest_addr = cpu_to_be32(ssi_sxx_phys); 659 link->dest_addr = cpu_to_be32(ssi_sxx_phys);
674 else 660 link->dest_attr = cpu_to_be32(CCSR_DMA_ATR_NOSNOOP);
661 } else {
675 link->source_addr = cpu_to_be32(ssi_sxx_phys); 662 link->source_addr = cpu_to_be32(ssi_sxx_phys);
663 link->source_attr = cpu_to_be32(CCSR_DMA_ATR_NOSNOOP);
664
665 link->dest_addr = cpu_to_be32(temp_addr);
666 link->dest_attr = cpu_to_be32(CCSR_DMA_ATR_SNOOP);
667 }
668
669 temp_addr += period_size;
676 } 670 }
677 671
678 return 0; 672 return 0;
@@ -808,7 +802,6 @@ static struct snd_pcm_ops fsl_dma_ops = {
808 .ioctl = snd_pcm_lib_ioctl, 802 .ioctl = snd_pcm_lib_ioctl,
809 .hw_params = fsl_dma_hw_params, 803 .hw_params = fsl_dma_hw_params,
810 .hw_free = fsl_dma_hw_free, 804 .hw_free = fsl_dma_hw_free,
811 .prepare = fsl_dma_prepare,
812 .pointer = fsl_dma_pointer, 805 .pointer = fsl_dma_pointer,
813}; 806};
814 807
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index c6d6eb71dc1d..169bca295b78 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -72,6 +72,7 @@
72 * @dev: struct device pointer 72 * @dev: struct device pointer
73 * @playback: the number of playback streams opened 73 * @playback: the number of playback streams opened
74 * @capture: the number of capture streams opened 74 * @capture: the number of capture streams opened
75 * @asynchronous: 0=synchronous mode, 1=asynchronous mode
75 * @cpu_dai: the CPU DAI for this device 76 * @cpu_dai: the CPU DAI for this device
76 * @dev_attr: the sysfs device attribute structure 77 * @dev_attr: the sysfs device attribute structure
77 * @stats: SSI statistics 78 * @stats: SSI statistics
@@ -86,6 +87,7 @@ struct fsl_ssi_private {
86 struct device *dev; 87 struct device *dev;
87 unsigned int playback; 88 unsigned int playback;
88 unsigned int capture; 89 unsigned int capture;
90 int asynchronous;
89 struct snd_soc_dai cpu_dai; 91 struct snd_soc_dai cpu_dai;
90 struct device_attribute dev_attr; 92 struct device_attribute dev_attr;
91 93
@@ -301,9 +303,10 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
301 * 303 *
302 * FIXME: Little-endian samples require a different shift dir 304 * FIXME: Little-endian samples require a different shift dir
303 */ 305 */
304 clrsetbits_be32(&ssi->scr, CCSR_SSI_SCR_I2S_MODE_MASK, 306 clrsetbits_be32(&ssi->scr,
305 CCSR_SSI_SCR_TFR_CLK_DIS | 307 CCSR_SSI_SCR_I2S_MODE_MASK | CCSR_SSI_SCR_SYN,
306 CCSR_SSI_SCR_I2S_MODE_SLAVE | CCSR_SSI_SCR_SYN); 308 CCSR_SSI_SCR_TFR_CLK_DIS | CCSR_SSI_SCR_I2S_MODE_SLAVE
309 | (ssi_private->asynchronous ? 0 : CCSR_SSI_SCR_SYN));
307 310
308 out_be32(&ssi->stcr, 311 out_be32(&ssi->stcr,
309 CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TFEN0 | 312 CCSR_SSI_STCR_TXBIT0 | CCSR_SSI_STCR_TFEN0 |
@@ -382,10 +385,15 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
382 SNDRV_PCM_HW_PARAM_RATE, 385 SNDRV_PCM_HW_PARAM_RATE,
383 first_runtime->rate, first_runtime->rate); 386 first_runtime->rate, first_runtime->rate);
384 387
385 snd_pcm_hw_constraint_minmax(substream->runtime, 388 /* If we're in synchronous mode, then we need to constrain
386 SNDRV_PCM_HW_PARAM_SAMPLE_BITS, 389 * the sample size as well. We don't support independent sample
387 first_runtime->sample_bits, 390 * rates in asynchronous mode.
388 first_runtime->sample_bits); 391 */
392 if (!ssi_private->asynchronous)
393 snd_pcm_hw_constraint_minmax(substream->runtime,
394 SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
395 first_runtime->sample_bits,
396 first_runtime->sample_bits);
389 397
390 ssi_private->second_stream = substream; 398 ssi_private->second_stream = substream;
391 } 399 }
@@ -400,7 +408,7 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
400} 408}
401 409
402/** 410/**
403 * fsl_ssi_prepare: prepare the SSI. 411 * fsl_ssi_hw_params - program the sample size
404 * 412 *
405 * Most of the SSI registers have been programmed in the startup function, 413 * Most of the SSI registers have been programmed in the startup function,
406 * but the word length must be programmed here. Unfortunately, programming 414 * but the word length must be programmed here. Unfortunately, programming
@@ -412,23 +420,27 @@ static int fsl_ssi_startup(struct snd_pcm_substream *substream,
412 * Note: The SxCCR.DC and SxCCR.PM bits are only used if the SSI is the 420 * Note: The SxCCR.DC and SxCCR.PM bits are only used if the SSI is the
413 * clock master. 421 * clock master.
414 */ 422 */
415static int fsl_ssi_prepare(struct snd_pcm_substream *substream, 423static int fsl_ssi_hw_params(struct snd_pcm_substream *substream,
416 struct snd_soc_dai *dai) 424 struct snd_pcm_hw_params *hw_params, struct snd_soc_dai *cpu_dai)
417{ 425{
418 struct snd_pcm_runtime *runtime = substream->runtime; 426 struct fsl_ssi_private *ssi_private = cpu_dai->private_data;
419 struct snd_soc_pcm_runtime *rtd = substream->private_data;
420 struct fsl_ssi_private *ssi_private = rtd->dai->cpu_dai->private_data;
421
422 struct ccsr_ssi __iomem *ssi = ssi_private->ssi;
423 427
424 if (substream == ssi_private->first_stream) { 428 if (substream == ssi_private->first_stream) {
425 u32 wl; 429 struct ccsr_ssi __iomem *ssi = ssi_private->ssi;
430 unsigned int sample_size =
431 snd_pcm_format_width(params_format(hw_params));
432 u32 wl = CCSR_SSI_SxCCR_WL(sample_size);
426 433
427 /* The SSI should always be disabled at this points (SSIEN=0) */ 434 /* The SSI should always be disabled at this points (SSIEN=0) */
428 wl = CCSR_SSI_SxCCR_WL(snd_pcm_format_width(runtime->format));
429 435
430 /* In synchronous mode, the SSI uses STCCR for capture */ 436 /* In synchronous mode, the SSI uses STCCR for capture */
431 clrsetbits_be32(&ssi->stccr, CCSR_SSI_SxCCR_WL_MASK, wl); 437 if ((substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ||
438 !ssi_private->asynchronous)
439 clrsetbits_be32(&ssi->stccr,
440 CCSR_SSI_SxCCR_WL_MASK, wl);
441 else
442 clrsetbits_be32(&ssi->srccr,
443 CCSR_SSI_SxCCR_WL_MASK, wl);
432 } 444 }
433 445
434 return 0; 446 return 0;
@@ -452,28 +464,33 @@ static int fsl_ssi_trigger(struct snd_pcm_substream *substream, int cmd,
452 464
453 switch (cmd) { 465 switch (cmd) {
454 case SNDRV_PCM_TRIGGER_START: 466 case SNDRV_PCM_TRIGGER_START:
455 case SNDRV_PCM_TRIGGER_RESUME: 467 clrbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN);
456 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 468 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
457 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 469 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
458 clrbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN);
459 setbits32(&ssi->scr, 470 setbits32(&ssi->scr,
460 CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_TE); 471 CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_TE);
461 } else { 472 } else {
462 clrbits32(&ssi->scr, CCSR_SSI_SCR_SSIEN); 473 long timeout = jiffies + 10;
474
463 setbits32(&ssi->scr, 475 setbits32(&ssi->scr,
464 CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_RE); 476 CCSR_SSI_SCR_SSIEN | CCSR_SSI_SCR_RE);
465 477
466 /* 478 /* Wait until the SSI has filled its FIFO. Without this
467 * I think we need this delay to allow time for the SSI 479 * delay, ALSA complains about overruns. When the FIFO
468 * to put data into its FIFO. Without it, ALSA starts 480 * is full, the DMA controller initiates its first
469 * to complain about overruns. 481 * transfer. Until then, however, the DMA's DAR
482 * register is zero, which translates to an
483 * out-of-bounds pointer. This makes ALSA think an
484 * overrun has occurred.
470 */ 485 */
471 mdelay(1); 486 while (!(in_be32(&ssi->sisr) & CCSR_SSI_SISR_RFF0) &&
487 (jiffies < timeout));
488 if (!(in_be32(&ssi->sisr) & CCSR_SSI_SISR_RFF0))
489 return -EIO;
472 } 490 }
473 break; 491 break;
474 492
475 case SNDRV_PCM_TRIGGER_STOP: 493 case SNDRV_PCM_TRIGGER_STOP:
476 case SNDRV_PCM_TRIGGER_SUSPEND:
477 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 494 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
478 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 495 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
479 clrbits32(&ssi->scr, CCSR_SSI_SCR_TE); 496 clrbits32(&ssi->scr, CCSR_SSI_SCR_TE);
@@ -563,6 +580,15 @@ static int fsl_ssi_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int format)
563/** 580/**
564 * fsl_ssi_dai_template: template CPU DAI for the SSI 581 * fsl_ssi_dai_template: template CPU DAI for the SSI
565 */ 582 */
583static struct snd_soc_dai_ops fsl_ssi_dai_ops = {
584 .startup = fsl_ssi_startup,
585 .hw_params = fsl_ssi_hw_params,
586 .shutdown = fsl_ssi_shutdown,
587 .trigger = fsl_ssi_trigger,
588 .set_sysclk = fsl_ssi_set_sysclk,
589 .set_fmt = fsl_ssi_set_fmt,
590};
591
566static struct snd_soc_dai fsl_ssi_dai_template = { 592static struct snd_soc_dai fsl_ssi_dai_template = {
567 .playback = { 593 .playback = {
568 /* The SSI does not support monaural audio. */ 594 /* The SSI does not support monaural audio. */
@@ -577,14 +603,7 @@ static struct snd_soc_dai fsl_ssi_dai_template = {
577 .rates = FSLSSI_I2S_RATES, 603 .rates = FSLSSI_I2S_RATES,
578 .formats = FSLSSI_I2S_FORMATS, 604 .formats = FSLSSI_I2S_FORMATS,
579 }, 605 },
580 .ops = { 606 .ops = &fsl_ssi_dai_ops,
581 .startup = fsl_ssi_startup,
582 .prepare = fsl_ssi_prepare,
583 .shutdown = fsl_ssi_shutdown,
584 .trigger = fsl_ssi_trigger,
585 .set_sysclk = fsl_ssi_set_sysclk,
586 .set_fmt = fsl_ssi_set_fmt,
587 },
588}; 607};
589 608
590/** 609/**
@@ -654,6 +673,7 @@ struct snd_soc_dai *fsl_ssi_create_dai(struct fsl_ssi_info *ssi_info)
654 ssi_private->ssi_phys = ssi_info->ssi_phys; 673 ssi_private->ssi_phys = ssi_info->ssi_phys;
655 ssi_private->irq = ssi_info->irq; 674 ssi_private->irq = ssi_info->irq;
656 ssi_private->dev = ssi_info->dev; 675 ssi_private->dev = ssi_info->dev;
676 ssi_private->asynchronous = ssi_info->asynchronous;
657 677
658 ssi_private->dev->driver_data = fsl_ssi_dai; 678 ssi_private->dev->driver_data = fsl_ssi_dai;
659 679
@@ -704,6 +724,14 @@ void fsl_ssi_destroy_dai(struct snd_soc_dai *fsl_ssi_dai)
704} 724}
705EXPORT_SYMBOL_GPL(fsl_ssi_destroy_dai); 725EXPORT_SYMBOL_GPL(fsl_ssi_destroy_dai);
706 726
727static int __init fsl_ssi_init(void)
728{
729 printk(KERN_INFO "Freescale Synchronous Serial Interface (SSI) ASoC Driver\n");
730
731 return 0;
732}
733module_init(fsl_ssi_init);
734
707MODULE_AUTHOR("Timur Tabi <timur@freescale.com>"); 735MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
708MODULE_DESCRIPTION("Freescale Synchronous Serial Interface (SSI) ASoC Driver"); 736MODULE_DESCRIPTION("Freescale Synchronous Serial Interface (SSI) ASoC Driver");
709MODULE_LICENSE("GPL"); 737MODULE_LICENSE("GPL");
diff --git a/sound/soc/fsl/fsl_ssi.h b/sound/soc/fsl/fsl_ssi.h
index 83b44d700e33..eade01feaab6 100644
--- a/sound/soc/fsl/fsl_ssi.h
+++ b/sound/soc/fsl/fsl_ssi.h
@@ -208,6 +208,7 @@ struct ccsr_ssi {
208 * ssi_phys: physical address of the SSI registers 208 * ssi_phys: physical address of the SSI registers
209 * irq: IRQ of this SSI 209 * irq: IRQ of this SSI
210 * dev: struct device, used to create the sysfs statistics file 210 * dev: struct device, used to create the sysfs statistics file
211 * asynchronous: 0=synchronous mode, 1=asynchronous mode
211*/ 212*/
212struct fsl_ssi_info { 213struct fsl_ssi_info {
213 unsigned int id; 214 unsigned int id;
@@ -215,6 +216,7 @@ struct fsl_ssi_info {
215 dma_addr_t ssi_phys; 216 dma_addr_t ssi_phys;
216 unsigned int irq; 217 unsigned int irq;
217 struct device *dev; 218 struct device *dev;
219 int asynchronous;
218}; 220};
219 221
220struct snd_soc_dai *fsl_ssi_create_dai(struct fsl_ssi_info *ssi_info); 222struct snd_soc_dai *fsl_ssi_create_dai(struct fsl_ssi_info *ssi_info);
diff --git a/sound/soc/fsl/mpc5200_psc_i2s.c b/sound/soc/fsl/mpc5200_psc_i2s.c
index 9eb1ce185bd0..3aa729df27b5 100644
--- a/sound/soc/fsl/mpc5200_psc_i2s.c
+++ b/sound/soc/fsl/mpc5200_psc_i2s.c
@@ -468,6 +468,16 @@ static int psc_i2s_set_fmt(struct snd_soc_dai *cpu_dai, unsigned int format)
468/** 468/**
469 * psc_i2s_dai_template: template CPU Digital Audio Interface 469 * psc_i2s_dai_template: template CPU Digital Audio Interface
470 */ 470 */
471static struct snd_soc_dai_ops psc_i2s_dai_ops = {
472 .startup = psc_i2s_startup,
473 .hw_params = psc_i2s_hw_params,
474 .hw_free = psc_i2s_hw_free,
475 .shutdown = psc_i2s_shutdown,
476 .trigger = psc_i2s_trigger,
477 .set_sysclk = psc_i2s_set_sysclk,
478 .set_fmt = psc_i2s_set_fmt,
479};
480
471static struct snd_soc_dai psc_i2s_dai_template = { 481static struct snd_soc_dai psc_i2s_dai_template = {
472 .playback = { 482 .playback = {
473 .channels_min = 2, 483 .channels_min = 2,
@@ -481,15 +491,7 @@ static struct snd_soc_dai psc_i2s_dai_template = {
481 .rates = PSC_I2S_RATES, 491 .rates = PSC_I2S_RATES,
482 .formats = PSC_I2S_FORMATS, 492 .formats = PSC_I2S_FORMATS,
483 }, 493 },
484 .ops = { 494 .ops = &psc_i2s_dai_ops,
485 .startup = psc_i2s_startup,
486 .hw_params = psc_i2s_hw_params,
487 .hw_free = psc_i2s_hw_free,
488 .shutdown = psc_i2s_shutdown,
489 .trigger = psc_i2s_trigger,
490 .set_sysclk = psc_i2s_set_sysclk,
491 .set_fmt = psc_i2s_set_fmt,
492 },
493}; 495};
494 496
495/* --------------------------------------------------------------------- 497/* ---------------------------------------------------------------------
diff --git a/sound/soc/fsl/mpc8610_hpcd.c b/sound/soc/fsl/mpc8610_hpcd.c
index acf39a646b2f..ef67d1cdffe7 100644
--- a/sound/soc/fsl/mpc8610_hpcd.c
+++ b/sound/soc/fsl/mpc8610_hpcd.c
@@ -353,6 +353,11 @@ static int mpc8610_hpcd_probe(struct of_device *ofdev,
353 } 353 }
354 ssi_info.irq = machine_data->ssi_irq; 354 ssi_info.irq = machine_data->ssi_irq;
355 355
356 /* Do we want to use asynchronous mode? */
357 ssi_info.asynchronous =
358 of_find_property(np, "fsl,ssi-asynchronous", NULL) ? 1 : 0;
359 if (ssi_info.asynchronous)
360 dev_info(&ofdev->dev, "using asynchronous mode\n");
356 361
357 /* Map the global utilities registers. */ 362 /* Map the global utilities registers. */
358 guts_np = of_find_compatible_node(NULL, NULL, "fsl,mpc8610-guts"); 363 guts_np = of_find_compatible_node(NULL, NULL, "fsl,mpc8610-guts");
diff --git a/sound/soc/omap/Kconfig b/sound/soc/omap/Kconfig
index 4f7f04014585..675732e724d5 100644
--- a/sound/soc/omap/Kconfig
+++ b/sound/soc/omap/Kconfig
@@ -8,7 +8,7 @@ config SND_OMAP_SOC_MCBSP
8 8
9config SND_OMAP_SOC_N810 9config SND_OMAP_SOC_N810
10 tristate "SoC Audio support for Nokia N810" 10 tristate "SoC Audio support for Nokia N810"
11 depends on SND_OMAP_SOC && MACH_NOKIA_N810 11 depends on SND_OMAP_SOC && MACH_NOKIA_N810 && I2C
12 select SND_OMAP_SOC_MCBSP 12 select SND_OMAP_SOC_MCBSP
13 select OMAP_MUX 13 select OMAP_MUX
14 select SND_SOC_TLV320AIC3X 14 select SND_SOC_TLV320AIC3X
@@ -17,7 +17,7 @@ config SND_OMAP_SOC_N810
17 17
18config SND_OMAP_SOC_OSK5912 18config SND_OMAP_SOC_OSK5912
19 tristate "SoC Audio support for omap osk5912" 19 tristate "SoC Audio support for omap osk5912"
20 depends on SND_OMAP_SOC && MACH_OMAP_OSK 20 depends on SND_OMAP_SOC && MACH_OMAP_OSK && I2C
21 select SND_OMAP_SOC_MCBSP 21 select SND_OMAP_SOC_MCBSP
22 select SND_SOC_TLV320AIC23 22 select SND_SOC_TLV320AIC23
23 help 23 help
@@ -55,3 +55,13 @@ config SND_OMAP_SOC_OMAP3_PANDORA
55 select SND_SOC_TWL4030 55 select SND_SOC_TWL4030
56 help 56 help
57 Say Y if you want to add support for SoC audio on the OMAP3 Pandora. 57 Say Y if you want to add support for SoC audio on the OMAP3 Pandora.
58
59config SND_OMAP_SOC_OMAP3_BEAGLE
60 tristate "SoC Audio support for OMAP3 Beagle"
61 depends on TWL4030_CORE && SND_OMAP_SOC && MACH_OMAP3_BEAGLE
62 select SND_OMAP_SOC_MCBSP
63 select SND_SOC_TWL4030
64 help
65 Say Y if you want to add support for SoC audio on the Beagleboard.
66
67
diff --git a/sound/soc/omap/Makefile b/sound/soc/omap/Makefile
index 76fedd96e365..0c9e4ac37660 100644
--- a/sound/soc/omap/Makefile
+++ b/sound/soc/omap/Makefile
@@ -12,6 +12,7 @@ snd-soc-overo-objs := overo.o
12snd-soc-omap2evm-objs := omap2evm.o 12snd-soc-omap2evm-objs := omap2evm.o
13snd-soc-sdp3430-objs := sdp3430.o 13snd-soc-sdp3430-objs := sdp3430.o
14snd-soc-omap3pandora-objs := omap3pandora.o 14snd-soc-omap3pandora-objs := omap3pandora.o
15snd-soc-omap3beagle-objs := omap3beagle.o
15 16
16obj-$(CONFIG_SND_OMAP_SOC_N810) += snd-soc-n810.o 17obj-$(CONFIG_SND_OMAP_SOC_N810) += snd-soc-n810.o
17obj-$(CONFIG_SND_OMAP_SOC_OSK5912) += snd-soc-osk5912.o 18obj-$(CONFIG_SND_OMAP_SOC_OSK5912) += snd-soc-osk5912.o
@@ -19,3 +20,4 @@ obj-$(CONFIG_SND_OMAP_SOC_OVERO) += snd-soc-overo.o
19obj-$(CONFIG_MACH_OMAP2EVM) += snd-soc-omap2evm.o 20obj-$(CONFIG_MACH_OMAP2EVM) += snd-soc-omap2evm.o
20obj-$(CONFIG_SND_OMAP_SOC_SDP3430) += snd-soc-sdp3430.o 21obj-$(CONFIG_SND_OMAP_SOC_SDP3430) += snd-soc-sdp3430.o
21obj-$(CONFIG_SND_OMAP_SOC_OMAP3_PANDORA) += snd-soc-omap3pandora.o 22obj-$(CONFIG_SND_OMAP_SOC_OMAP3_PANDORA) += snd-soc-omap3pandora.o
23obj-$(CONFIG_SND_OMAP_SOC_OMAP3_BEAGLE) += snd-soc-omap3beagle.o
diff --git a/sound/soc/omap/n810.c b/sound/soc/omap/n810.c
index 25593fee9121..a6d1178ce128 100644
--- a/sound/soc/omap/n810.c
+++ b/sound/soc/omap/n810.c
@@ -40,6 +40,13 @@
40#define N810_HEADSET_AMP_GPIO 10 40#define N810_HEADSET_AMP_GPIO 10
41#define N810_SPEAKER_AMP_GPIO 101 41#define N810_SPEAKER_AMP_GPIO 101
42 42
43enum {
44 N810_JACK_DISABLED,
45 N810_JACK_HP,
46 N810_JACK_HS,
47 N810_JACK_MIC,
48};
49
43static struct clk *sys_clkout2; 50static struct clk *sys_clkout2;
44static struct clk *sys_clkout2_src; 51static struct clk *sys_clkout2_src;
45static struct clk *func96m_clk; 52static struct clk *func96m_clk;
@@ -50,15 +57,32 @@ static int n810_dmic_func;
50 57
51static void n810_ext_control(struct snd_soc_codec *codec) 58static void n810_ext_control(struct snd_soc_codec *codec)
52{ 59{
60 int hp = 0, line1l = 0;
61
62 switch (n810_jack_func) {
63 case N810_JACK_HS:
64 line1l = 1;
65 case N810_JACK_HP:
66 hp = 1;
67 break;
68 case N810_JACK_MIC:
69 line1l = 1;
70 break;
71 }
72
53 if (n810_spk_func) 73 if (n810_spk_func)
54 snd_soc_dapm_enable_pin(codec, "Ext Spk"); 74 snd_soc_dapm_enable_pin(codec, "Ext Spk");
55 else 75 else
56 snd_soc_dapm_disable_pin(codec, "Ext Spk"); 76 snd_soc_dapm_disable_pin(codec, "Ext Spk");
57 77
58 if (n810_jack_func) 78 if (hp)
59 snd_soc_dapm_enable_pin(codec, "Headphone Jack"); 79 snd_soc_dapm_enable_pin(codec, "Headphone Jack");
60 else 80 else
61 snd_soc_dapm_disable_pin(codec, "Headphone Jack"); 81 snd_soc_dapm_disable_pin(codec, "Headphone Jack");
82 if (line1l)
83 snd_soc_dapm_enable_pin(codec, "LINE1L");
84 else
85 snd_soc_dapm_disable_pin(codec, "LINE1L");
62 86
63 if (n810_dmic_func) 87 if (n810_dmic_func)
64 snd_soc_dapm_enable_pin(codec, "DMic"); 88 snd_soc_dapm_enable_pin(codec, "DMic");
@@ -72,7 +96,7 @@ static int n810_startup(struct snd_pcm_substream *substream)
72{ 96{
73 struct snd_pcm_runtime *runtime = substream->runtime; 97 struct snd_pcm_runtime *runtime = substream->runtime;
74 struct snd_soc_pcm_runtime *rtd = substream->private_data; 98 struct snd_soc_pcm_runtime *rtd = substream->private_data;
75 struct snd_soc_codec *codec = rtd->socdev->codec; 99 struct snd_soc_codec *codec = rtd->socdev->card->codec;
76 100
77 snd_pcm_hw_constraint_minmax(runtime, 101 snd_pcm_hw_constraint_minmax(runtime,
78 SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2); 102 SNDRV_PCM_HW_PARAM_CHANNELS, 2, 2);
@@ -229,7 +253,7 @@ static const struct snd_soc_dapm_route audio_map[] = {
229}; 253};
230 254
231static const char *spk_function[] = {"Off", "On"}; 255static const char *spk_function[] = {"Off", "On"};
232static const char *jack_function[] = {"Off", "Headphone"}; 256static const char *jack_function[] = {"Off", "Headphone", "Headset", "Mic"};
233static const char *input_function[] = {"ADC", "Digital Mic"}; 257static const char *input_function[] = {"ADC", "Digital Mic"};
234static const struct soc_enum n810_enum[] = { 258static const struct soc_enum n810_enum[] = {
235 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(spk_function), spk_function), 259 SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(spk_function), spk_function),
@@ -248,20 +272,23 @@ static const struct snd_kcontrol_new aic33_n810_controls[] = {
248 272
249static int n810_aic33_init(struct snd_soc_codec *codec) 273static int n810_aic33_init(struct snd_soc_codec *codec)
250{ 274{
251 int i, err; 275 int err;
252 276
253 /* Not connected */ 277 /* Not connected */
254 snd_soc_dapm_nc_pin(codec, "MONO_LOUT"); 278 snd_soc_dapm_nc_pin(codec, "MONO_LOUT");
255 snd_soc_dapm_nc_pin(codec, "HPLCOM"); 279 snd_soc_dapm_nc_pin(codec, "HPLCOM");
256 snd_soc_dapm_nc_pin(codec, "HPRCOM"); 280 snd_soc_dapm_nc_pin(codec, "HPRCOM");
281 snd_soc_dapm_nc_pin(codec, "MIC3L");
282 snd_soc_dapm_nc_pin(codec, "MIC3R");
283 snd_soc_dapm_nc_pin(codec, "LINE1R");
284 snd_soc_dapm_nc_pin(codec, "LINE2L");
285 snd_soc_dapm_nc_pin(codec, "LINE2R");
257 286
258 /* Add N810 specific controls */ 287 /* Add N810 specific controls */
259 for (i = 0; i < ARRAY_SIZE(aic33_n810_controls); i++) { 288 err = snd_soc_add_controls(codec, aic33_n810_controls,
260 err = snd_ctl_add(codec->card, 289 ARRAY_SIZE(aic33_n810_controls));
261 snd_soc_cnew(&aic33_n810_controls[i], codec, NULL)); 290 if (err < 0)
262 if (err < 0) 291 return err;
263 return err;
264 }
265 292
266 /* Add N810 specific widgets */ 293 /* Add N810 specific widgets */
267 snd_soc_dapm_new_controls(codec, aic33_dapm_widgets, 294 snd_soc_dapm_new_controls(codec, aic33_dapm_widgets,
diff --git a/sound/soc/omap/omap-mcbsp.c b/sound/soc/omap/omap-mcbsp.c
index 05dd5abcddf4..d6882be33452 100644
--- a/sound/soc/omap/omap-mcbsp.c
+++ b/sound/soc/omap/omap-mcbsp.c
@@ -461,6 +461,16 @@ static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
461 return err; 461 return err;
462} 462}
463 463
464static struct snd_soc_dai_ops omap_mcbsp_dai_ops = {
465 .startup = omap_mcbsp_dai_startup,
466 .shutdown = omap_mcbsp_dai_shutdown,
467 .trigger = omap_mcbsp_dai_trigger,
468 .hw_params = omap_mcbsp_dai_hw_params,
469 .set_fmt = omap_mcbsp_dai_set_dai_fmt,
470 .set_clkdiv = omap_mcbsp_dai_set_clkdiv,
471 .set_sysclk = omap_mcbsp_dai_set_dai_sysclk,
472};
473
464#define OMAP_MCBSP_DAI_BUILDER(link_id) \ 474#define OMAP_MCBSP_DAI_BUILDER(link_id) \
465{ \ 475{ \
466 .name = "omap-mcbsp-dai-"#link_id, \ 476 .name = "omap-mcbsp-dai-"#link_id, \
@@ -477,15 +487,7 @@ static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
477 .rates = OMAP_MCBSP_RATES, \ 487 .rates = OMAP_MCBSP_RATES, \
478 .formats = SNDRV_PCM_FMTBIT_S16_LE, \ 488 .formats = SNDRV_PCM_FMTBIT_S16_LE, \
479 }, \ 489 }, \
480 .ops = { \ 490 .ops = &omap_mcbsp_dai_ops, \
481 .startup = omap_mcbsp_dai_startup, \
482 .shutdown = omap_mcbsp_dai_shutdown, \
483 .trigger = omap_mcbsp_dai_trigger, \
484 .hw_params = omap_mcbsp_dai_hw_params, \
485 .set_fmt = omap_mcbsp_dai_set_dai_fmt, \
486 .set_clkdiv = omap_mcbsp_dai_set_clkdiv, \
487 .set_sysclk = omap_mcbsp_dai_set_dai_sysclk, \
488 }, \
489 .private_data = &mcbsp_data[(link_id)].bus_id, \ 491 .private_data = &mcbsp_data[(link_id)].bus_id, \
490} 492}
491 493
diff --git a/sound/soc/omap/omap-pcm.c b/sound/soc/omap/omap-pcm.c
index dd3bb2933762..8e1431cb46bb 100644
--- a/sound/soc/omap/omap-pcm.c
+++ b/sound/soc/omap/omap-pcm.c
@@ -265,7 +265,7 @@ static int omap_pcm_mmap(struct snd_pcm_substream *substream,
265 runtime->dma_bytes); 265 runtime->dma_bytes);
266} 266}
267 267
268struct snd_pcm_ops omap_pcm_ops = { 268static struct snd_pcm_ops omap_pcm_ops = {
269 .open = omap_pcm_open, 269 .open = omap_pcm_open,
270 .close = omap_pcm_close, 270 .close = omap_pcm_close,
271 .ioctl = snd_pcm_lib_ioctl, 271 .ioctl = snd_pcm_lib_ioctl,
diff --git a/sound/soc/omap/omap3pandora.c b/sound/soc/omap/omap3pandora.c
index fcc2f5d9a878..fe282d4ef422 100644
--- a/sound/soc/omap/omap3pandora.c
+++ b/sound/soc/omap/omap3pandora.c
@@ -143,7 +143,7 @@ static const struct snd_soc_dapm_widget omap3pandora_out_dapm_widgets[] = {
143}; 143};
144 144
145static const struct snd_soc_dapm_widget omap3pandora_in_dapm_widgets[] = { 145static const struct snd_soc_dapm_widget omap3pandora_in_dapm_widgets[] = {
146 SND_SOC_DAPM_MIC("Mic (Internal)", NULL), 146 SND_SOC_DAPM_MIC("Mic (internal)", NULL),
147 SND_SOC_DAPM_MIC("Mic (external)", NULL), 147 SND_SOC_DAPM_MIC("Mic (external)", NULL),
148 SND_SOC_DAPM_LINE("Line In", NULL), 148 SND_SOC_DAPM_LINE("Line In", NULL),
149}; 149};
@@ -155,16 +155,33 @@ static const struct snd_soc_dapm_route omap3pandora_out_map[] = {
155}; 155};
156 156
157static const struct snd_soc_dapm_route omap3pandora_in_map[] = { 157static const struct snd_soc_dapm_route omap3pandora_in_map[] = {
158 {"INL", NULL, "Line In"}, 158 {"AUXL", NULL, "Line In"},
159 {"INR", NULL, "Line In"}, 159 {"AUXR", NULL, "Line In"},
160 {"INL", NULL, "Mic (Internal)"}, 160
161 {"INR", NULL, "Mic (external)"}, 161 {"MAINMIC", NULL, "Mic Bias 1"},
162 {"Mic Bias 1", NULL, "Mic (internal)"},
163
164 {"SUBMIC", NULL, "Mic Bias 2"},
165 {"Mic Bias 2", NULL, "Mic (external)"},
162}; 166};
163 167
164static int omap3pandora_out_init(struct snd_soc_codec *codec) 168static int omap3pandora_out_init(struct snd_soc_codec *codec)
165{ 169{
166 int ret; 170 int ret;
167 171
172 /* All TWL4030 output pins are floating */
173 snd_soc_dapm_nc_pin(codec, "OUTL");
174 snd_soc_dapm_nc_pin(codec, "OUTR");
175 snd_soc_dapm_nc_pin(codec, "EARPIECE");
176 snd_soc_dapm_nc_pin(codec, "PREDRIVEL");
177 snd_soc_dapm_nc_pin(codec, "PREDRIVER");
178 snd_soc_dapm_nc_pin(codec, "HSOL");
179 snd_soc_dapm_nc_pin(codec, "HSOR");
180 snd_soc_dapm_nc_pin(codec, "CARKITL");
181 snd_soc_dapm_nc_pin(codec, "CARKITR");
182 snd_soc_dapm_nc_pin(codec, "HFL");
183 snd_soc_dapm_nc_pin(codec, "HFR");
184
168 ret = snd_soc_dapm_new_controls(codec, omap3pandora_out_dapm_widgets, 185 ret = snd_soc_dapm_new_controls(codec, omap3pandora_out_dapm_widgets,
169 ARRAY_SIZE(omap3pandora_out_dapm_widgets)); 186 ARRAY_SIZE(omap3pandora_out_dapm_widgets));
170 if (ret < 0) 187 if (ret < 0)
@@ -180,18 +197,11 @@ static int omap3pandora_in_init(struct snd_soc_codec *codec)
180{ 197{
181 int ret; 198 int ret;
182 199
183 /* All TWL4030 output pins are floating */ 200 /* Not comnnected */
184 snd_soc_dapm_nc_pin(codec, "OUTL"), 201 snd_soc_dapm_nc_pin(codec, "HSMIC");
185 snd_soc_dapm_nc_pin(codec, "OUTR"), 202 snd_soc_dapm_nc_pin(codec, "CARKITMIC");
186 snd_soc_dapm_nc_pin(codec, "EARPIECE"), 203 snd_soc_dapm_nc_pin(codec, "DIGIMIC0");
187 snd_soc_dapm_nc_pin(codec, "PREDRIVEL"), 204 snd_soc_dapm_nc_pin(codec, "DIGIMIC1");
188 snd_soc_dapm_nc_pin(codec, "PREDRIVER"),
189 snd_soc_dapm_nc_pin(codec, "HSOL"),
190 snd_soc_dapm_nc_pin(codec, "HSOR"),
191 snd_soc_dapm_nc_pin(codec, "CARKITL"),
192 snd_soc_dapm_nc_pin(codec, "CARKITR"),
193 snd_soc_dapm_nc_pin(codec, "HFL"),
194 snd_soc_dapm_nc_pin(codec, "HFR"),
195 205
196 ret = snd_soc_dapm_new_controls(codec, omap3pandora_in_dapm_widgets, 206 ret = snd_soc_dapm_new_controls(codec, omap3pandora_in_dapm_widgets,
197 ARRAY_SIZE(omap3pandora_in_dapm_widgets)); 207 ARRAY_SIZE(omap3pandora_in_dapm_widgets));
@@ -251,10 +261,9 @@ static int __init omap3pandora_soc_init(void)
251{ 261{
252 int ret; 262 int ret;
253 263
254 if (!machine_is_omap3_pandora()) { 264 if (!machine_is_omap3_pandora())
255 pr_debug(PREFIX "Not OMAP3 Pandora\n");
256 return -ENODEV; 265 return -ENODEV;
257 } 266
258 pr_info("OMAP3 Pandora SoC init\n"); 267 pr_info("OMAP3 Pandora SoC init\n");
259 268
260 ret = gpio_request(OMAP3_PANDORA_DAC_POWER_GPIO, "dac_power"); 269 ret = gpio_request(OMAP3_PANDORA_DAC_POWER_GPIO, "dac_power");
diff --git a/sound/soc/omap/osk5912.c b/sound/soc/omap/osk5912.c
index cd41a948df7b..a952a4eb3361 100644
--- a/sound/soc/omap/osk5912.c
+++ b/sound/soc/omap/osk5912.c
@@ -186,13 +186,6 @@ static int __init osk_soc_init(void)
186 return -ENODEV; 186 return -ENODEV;
187 } 187 }
188 188
189 if (clk_get_usecount(tlv320aic23_mclk) > 0) {
190 /* MCLK is already in use */
191 printk(KERN_WARNING
192 "MCLK in use at %d Hz. We change it to %d Hz\n",
193 (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK);
194 }
195
196 /* 189 /*
197 * Configure 12 MHz output on MCLK. 190 * Configure 12 MHz output on MCLK.
198 */ 191 */
@@ -205,9 +198,8 @@ static int __init osk_soc_init(void)
205 } 198 }
206 } 199 }
207 200
208 printk(KERN_INFO "MCLK = %d [%d], usecount = %d\n", 201 printk(KERN_INFO "MCLK = %d [%d]\n",
209 (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK, 202 (uint) clk_get_rate(tlv320aic23_mclk), CODEC_CLOCK);
210 clk_get_usecount(tlv320aic23_mclk));
211 203
212 return 0; 204 return 0;
213err1: 205err1:
diff --git a/sound/soc/omap/sdp3430.c b/sound/soc/omap/sdp3430.c
index e226fa75669c..10f1c867f11d 100644
--- a/sound/soc/omap/sdp3430.c
+++ b/sound/soc/omap/sdp3430.c
@@ -28,6 +28,7 @@
28#include <sound/pcm.h> 28#include <sound/pcm.h>
29#include <sound/soc.h> 29#include <sound/soc.h>
30#include <sound/soc-dapm.h> 30#include <sound/soc-dapm.h>
31#include <sound/jack.h>
31 32
32#include <asm/mach-types.h> 33#include <asm/mach-types.h>
33#include <mach/hardware.h> 34#include <mach/hardware.h>
@@ -38,6 +39,8 @@
38#include "omap-pcm.h" 39#include "omap-pcm.h"
39#include "../codecs/twl4030.h" 40#include "../codecs/twl4030.h"
40 41
42static struct snd_soc_card snd_soc_sdp3430;
43
41static int sdp3430_hw_params(struct snd_pcm_substream *substream, 44static int sdp3430_hw_params(struct snd_pcm_substream *substream,
42 struct snd_pcm_hw_params *params) 45 struct snd_pcm_hw_params *params)
43{ 46{
@@ -81,12 +84,121 @@ static struct snd_soc_ops sdp3430_ops = {
81 .hw_params = sdp3430_hw_params, 84 .hw_params = sdp3430_hw_params,
82}; 85};
83 86
87/* Headset jack */
88static struct snd_soc_jack hs_jack;
89
90/* Headset jack detection DAPM pins */
91static struct snd_soc_jack_pin hs_jack_pins[] = {
92 {
93 .pin = "Headset Mic",
94 .mask = SND_JACK_MICROPHONE,
95 },
96 {
97 .pin = "Headset Stereophone",
98 .mask = SND_JACK_HEADPHONE,
99 },
100};
101
102/* Headset jack detection gpios */
103static struct snd_soc_jack_gpio hs_jack_gpios[] = {
104 {
105 .gpio = (OMAP_MAX_GPIO_LINES + 2),
106 .name = "hsdet-gpio",
107 .report = SND_JACK_HEADSET,
108 .debounce_time = 200,
109 },
110};
111
112/* SDP3430 machine DAPM */
113static const struct snd_soc_dapm_widget sdp3430_twl4030_dapm_widgets[] = {
114 SND_SOC_DAPM_MIC("Ext Mic", NULL),
115 SND_SOC_DAPM_SPK("Ext Spk", NULL),
116 SND_SOC_DAPM_MIC("Headset Mic", NULL),
117 SND_SOC_DAPM_HP("Headset Stereophone", NULL),
118};
119
120static const struct snd_soc_dapm_route audio_map[] = {
121 /* External Mics: MAINMIC, SUBMIC with bias*/
122 {"MAINMIC", NULL, "Mic Bias 1"},
123 {"SUBMIC", NULL, "Mic Bias 2"},
124 {"Mic Bias 1", NULL, "Ext Mic"},
125 {"Mic Bias 2", NULL, "Ext Mic"},
126
127 /* External Speakers: HFL, HFR */
128 {"Ext Spk", NULL, "HFL"},
129 {"Ext Spk", NULL, "HFR"},
130
131 /* Headset Mic: HSMIC with bias */
132 {"HSMIC", NULL, "Headset Mic Bias"},
133 {"Headset Mic Bias", NULL, "Headset Mic"},
134
135 /* Headset Stereophone (Headphone): HSOL, HSOR */
136 {"Headset Stereophone", NULL, "HSOL"},
137 {"Headset Stereophone", NULL, "HSOR"},
138};
139
140static int sdp3430_twl4030_init(struct snd_soc_codec *codec)
141{
142 int ret;
143
144 /* Add SDP3430 specific widgets */
145 ret = snd_soc_dapm_new_controls(codec, sdp3430_twl4030_dapm_widgets,
146 ARRAY_SIZE(sdp3430_twl4030_dapm_widgets));
147 if (ret)
148 return ret;
149
150 /* Set up SDP3430 specific audio path audio_map */
151 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
152
153 /* SDP3430 connected pins */
154 snd_soc_dapm_enable_pin(codec, "Ext Mic");
155 snd_soc_dapm_enable_pin(codec, "Ext Spk");
156 snd_soc_dapm_disable_pin(codec, "Headset Mic");
157 snd_soc_dapm_disable_pin(codec, "Headset Stereophone");
158
159 /* TWL4030 not connected pins */
160 snd_soc_dapm_nc_pin(codec, "AUXL");
161 snd_soc_dapm_nc_pin(codec, "AUXR");
162 snd_soc_dapm_nc_pin(codec, "CARKITMIC");
163 snd_soc_dapm_nc_pin(codec, "DIGIMIC0");
164 snd_soc_dapm_nc_pin(codec, "DIGIMIC1");
165
166 snd_soc_dapm_nc_pin(codec, "OUTL");
167 snd_soc_dapm_nc_pin(codec, "OUTR");
168 snd_soc_dapm_nc_pin(codec, "EARPIECE");
169 snd_soc_dapm_nc_pin(codec, "PREDRIVEL");
170 snd_soc_dapm_nc_pin(codec, "PREDRIVER");
171 snd_soc_dapm_nc_pin(codec, "CARKITL");
172 snd_soc_dapm_nc_pin(codec, "CARKITR");
173
174 ret = snd_soc_dapm_sync(codec);
175 if (ret)
176 return ret;
177
178 /* Headset jack detection */
179 ret = snd_soc_jack_new(&snd_soc_sdp3430, "Headset Jack",
180 SND_JACK_HEADSET, &hs_jack);
181 if (ret)
182 return ret;
183
184 ret = snd_soc_jack_add_pins(&hs_jack, ARRAY_SIZE(hs_jack_pins),
185 hs_jack_pins);
186 if (ret)
187 return ret;
188
189 ret = snd_soc_jack_add_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
190 hs_jack_gpios);
191
192 return ret;
193}
194
84/* Digital audio interface glue - connects codec <--> CPU */ 195/* Digital audio interface glue - connects codec <--> CPU */
85static struct snd_soc_dai_link sdp3430_dai = { 196static struct snd_soc_dai_link sdp3430_dai = {
86 .name = "TWL4030", 197 .name = "TWL4030",
87 .stream_name = "TWL4030", 198 .stream_name = "TWL4030",
88 .cpu_dai = &omap_mcbsp_dai[0], 199 .cpu_dai = &omap_mcbsp_dai[0],
89 .codec_dai = &twl4030_dai, 200 .codec_dai = &twl4030_dai,
201 .init = sdp3430_twl4030_init,
90 .ops = &sdp3430_ops, 202 .ops = &sdp3430_ops,
91}; 203};
92 204
@@ -142,6 +254,9 @@ module_init(sdp3430_soc_init);
142 254
143static void __exit sdp3430_soc_exit(void) 255static void __exit sdp3430_soc_exit(void)
144{ 256{
257 snd_soc_jack_free_gpios(&hs_jack, ARRAY_SIZE(hs_jack_gpios),
258 hs_jack_gpios);
259
145 platform_device_unregister(sdp3430_snd_device); 260 platform_device_unregister(sdp3430_snd_device);
146} 261}
147module_exit(sdp3430_soc_exit); 262module_exit(sdp3430_soc_exit);
diff --git a/sound/soc/pxa/Kconfig b/sound/soc/pxa/Kconfig
index f82e10699471..5998ab366e83 100644
--- a/sound/soc/pxa/Kconfig
+++ b/sound/soc/pxa/Kconfig
@@ -61,6 +61,24 @@ config SND_PXA2XX_SOC_TOSA
61 Say Y if you want to add support for SoC audio on Sharp 61 Say Y if you want to add support for SoC audio on Sharp
62 Zaurus SL-C6000x models (Tosa). 62 Zaurus SL-C6000x models (Tosa).
63 63
64config SND_PXA2XX_SOC_E740
65 tristate "SoC AC97 Audio support for e740"
66 depends on SND_PXA2XX_SOC && MACH_E740
67 select SND_SOC_WM9705
68 select SND_PXA2XX_SOC_AC97
69 help
70 Say Y if you want to add support for SoC audio on the
71 toshiba e740 PDA
72
73config SND_PXA2XX_SOC_E750
74 tristate "SoC AC97 Audio support for e750"
75 depends on SND_PXA2XX_SOC && MACH_E750
76 select SND_SOC_WM9705
77 select SND_PXA2XX_SOC_AC97
78 help
79 Say Y if you want to add support for SoC audio on the
80 toshiba e750 PDA
81
64config SND_PXA2XX_SOC_E800 82config SND_PXA2XX_SOC_E800
65 tristate "SoC AC97 Audio support for e800" 83 tristate "SoC AC97 Audio support for e800"
66 depends on SND_PXA2XX_SOC && MACH_E800 84 depends on SND_PXA2XX_SOC && MACH_E800
@@ -97,3 +115,12 @@ config SND_SOC_ZYLONITE
97 help 115 help
98 Say Y if you want to add support for SoC audio on the 116 Say Y if you want to add support for SoC audio on the
99 Marvell Zylonite reference platform. 117 Marvell Zylonite reference platform.
118
119config SND_PXA2XX_SOC_MIOA701
120 tristate "SoC Audio support for MIO A701"
121 depends on SND_PXA2XX_SOC && MACH_MIOA701
122 select SND_PXA2XX_SOC_AC97
123 select SND_SOC_WM9713
124 help
125 Say Y if you want to add support for SoC audio on the
126 MIO A701.
diff --git a/sound/soc/pxa/Makefile b/sound/soc/pxa/Makefile
index 08a9f2797729..8ed881c5e5cc 100644
--- a/sound/soc/pxa/Makefile
+++ b/sound/soc/pxa/Makefile
@@ -13,17 +13,23 @@ obj-$(CONFIG_SND_PXA_SOC_SSP) += snd-soc-pxa-ssp.o
13snd-soc-corgi-objs := corgi.o 13snd-soc-corgi-objs := corgi.o
14snd-soc-poodle-objs := poodle.o 14snd-soc-poodle-objs := poodle.o
15snd-soc-tosa-objs := tosa.o 15snd-soc-tosa-objs := tosa.o
16snd-soc-e740-objs := e740_wm9705.o
17snd-soc-e750-objs := e750_wm9705.o
16snd-soc-e800-objs := e800_wm9712.o 18snd-soc-e800-objs := e800_wm9712.o
17snd-soc-spitz-objs := spitz.o 19snd-soc-spitz-objs := spitz.o
18snd-soc-em-x270-objs := em-x270.o 20snd-soc-em-x270-objs := em-x270.o
19snd-soc-palm27x-objs := palm27x.o 21snd-soc-palm27x-objs := palm27x.o
20snd-soc-zylonite-objs := zylonite.o 22snd-soc-zylonite-objs := zylonite.o
23snd-soc-mioa701-objs := mioa701_wm9713.o
21 24
22obj-$(CONFIG_SND_PXA2XX_SOC_CORGI) += snd-soc-corgi.o 25obj-$(CONFIG_SND_PXA2XX_SOC_CORGI) += snd-soc-corgi.o
23obj-$(CONFIG_SND_PXA2XX_SOC_POODLE) += snd-soc-poodle.o 26obj-$(CONFIG_SND_PXA2XX_SOC_POODLE) += snd-soc-poodle.o
24obj-$(CONFIG_SND_PXA2XX_SOC_TOSA) += snd-soc-tosa.o 27obj-$(CONFIG_SND_PXA2XX_SOC_TOSA) += snd-soc-tosa.o
28obj-$(CONFIG_SND_PXA2XX_SOC_E740) += snd-soc-e740.o
29obj-$(CONFIG_SND_PXA2XX_SOC_E750) += snd-soc-e750.o
25obj-$(CONFIG_SND_PXA2XX_SOC_E800) += snd-soc-e800.o 30obj-$(CONFIG_SND_PXA2XX_SOC_E800) += snd-soc-e800.o
26obj-$(CONFIG_SND_PXA2XX_SOC_SPITZ) += snd-soc-spitz.o 31obj-$(CONFIG_SND_PXA2XX_SOC_SPITZ) += snd-soc-spitz.o
27obj-$(CONFIG_SND_PXA2XX_SOC_EM_X270) += snd-soc-em-x270.o 32obj-$(CONFIG_SND_PXA2XX_SOC_EM_X270) += snd-soc-em-x270.o
28obj-$(CONFIG_SND_PXA2XX_SOC_PALM27X) += snd-soc-palm27x.o 33obj-$(CONFIG_SND_PXA2XX_SOC_PALM27X) += snd-soc-palm27x.o
34obj-$(CONFIG_SND_PXA2XX_SOC_MIOA701) += snd-soc-mioa701.o
29obj-$(CONFIG_SND_SOC_ZYLONITE) += snd-soc-zylonite.o 35obj-$(CONFIG_SND_SOC_ZYLONITE) += snd-soc-zylonite.o
diff --git a/sound/soc/pxa/corgi.c b/sound/soc/pxa/corgi.c
index 1ba25a559524..02263e5d8f03 100644
--- a/sound/soc/pxa/corgi.c
+++ b/sound/soc/pxa/corgi.c
@@ -16,6 +16,7 @@
16#include <linux/module.h> 16#include <linux/module.h>
17#include <linux/moduleparam.h> 17#include <linux/moduleparam.h>
18#include <linux/timer.h> 18#include <linux/timer.h>
19#include <linux/i2c.h>
19#include <linux/interrupt.h> 20#include <linux/interrupt.h>
20#include <linux/platform_device.h> 21#include <linux/platform_device.h>
21#include <linux/gpio.h> 22#include <linux/gpio.h>
@@ -100,7 +101,7 @@ static void corgi_ext_control(struct snd_soc_codec *codec)
100static int corgi_startup(struct snd_pcm_substream *substream) 101static int corgi_startup(struct snd_pcm_substream *substream)
101{ 102{
102 struct snd_soc_pcm_runtime *rtd = substream->private_data; 103 struct snd_soc_pcm_runtime *rtd = substream->private_data;
103 struct snd_soc_codec *codec = rtd->socdev->codec; 104 struct snd_soc_codec *codec = rtd->socdev->card->codec;
104 105
105 /* check the jack status at stream startup */ 106 /* check the jack status at stream startup */
106 corgi_ext_control(codec); 107 corgi_ext_control(codec);
@@ -275,18 +276,16 @@ static const struct snd_kcontrol_new wm8731_corgi_controls[] = {
275 */ 276 */
276static int corgi_wm8731_init(struct snd_soc_codec *codec) 277static int corgi_wm8731_init(struct snd_soc_codec *codec)
277{ 278{
278 int i, err; 279 int err;
279 280
280 snd_soc_dapm_nc_pin(codec, "LLINEIN"); 281 snd_soc_dapm_nc_pin(codec, "LLINEIN");
281 snd_soc_dapm_nc_pin(codec, "RLINEIN"); 282 snd_soc_dapm_nc_pin(codec, "RLINEIN");
282 283
283 /* Add corgi specific controls */ 284 /* Add corgi specific controls */
284 for (i = 0; i < ARRAY_SIZE(wm8731_corgi_controls); i++) { 285 err = snd_soc_add_controls(codec, wm8731_corgi_controls,
285 err = snd_ctl_add(codec->card, 286 ARRAY_SIZE(wm8731_corgi_controls));
286 snd_soc_cnew(&wm8731_corgi_controls[i], codec, NULL)); 287 if (err < 0)
287 if (err < 0) 288 return err;
288 return err;
289 }
290 289
291 /* Add corgi specific widgets */ 290 /* Add corgi specific widgets */
292 snd_soc_dapm_new_controls(codec, wm8731_dapm_widgets, 291 snd_soc_dapm_new_controls(codec, wm8731_dapm_widgets,
@@ -317,19 +316,44 @@ static struct snd_soc_card snd_soc_corgi = {
317 .num_links = 1, 316 .num_links = 1,
318}; 317};
319 318
320/* corgi audio private data */
321static struct wm8731_setup_data corgi_wm8731_setup = {
322 .i2c_bus = 0,
323 .i2c_address = 0x1b,
324};
325
326/* corgi audio subsystem */ 319/* corgi audio subsystem */
327static struct snd_soc_device corgi_snd_devdata = { 320static struct snd_soc_device corgi_snd_devdata = {
328 .card = &snd_soc_corgi, 321 .card = &snd_soc_corgi,
329 .codec_dev = &soc_codec_dev_wm8731, 322 .codec_dev = &soc_codec_dev_wm8731,
330 .codec_data = &corgi_wm8731_setup,
331}; 323};
332 324
325/*
326 * FIXME: This is a temporary bodge to avoid cross-tree merge issues.
327 * New drivers should register the wm8731 I2C device in the machine
328 * setup code (under arch/arm for ARM systems).
329 */
330static int wm8731_i2c_register(void)
331{
332 struct i2c_board_info info;
333 struct i2c_adapter *adapter;
334 struct i2c_client *client;
335
336 memset(&info, 0, sizeof(struct i2c_board_info));
337 info.addr = 0x1b;
338 strlcpy(info.type, "wm8731", I2C_NAME_SIZE);
339
340 adapter = i2c_get_adapter(0);
341 if (!adapter) {
342 printk(KERN_ERR "can't get i2c adapter 0\n");
343 return -ENODEV;
344 }
345
346 client = i2c_new_device(adapter, &info);
347 i2c_put_adapter(adapter);
348 if (!client) {
349 printk(KERN_ERR "can't add i2c device at 0x%x\n",
350 (unsigned int)info.addr);
351 return -ENODEV;
352 }
353
354 return 0;
355}
356
333static struct platform_device *corgi_snd_device; 357static struct platform_device *corgi_snd_device;
334 358
335static int __init corgi_init(void) 359static int __init corgi_init(void)
@@ -340,6 +364,10 @@ static int __init corgi_init(void)
340 machine_is_husky())) 364 machine_is_husky()))
341 return -ENODEV; 365 return -ENODEV;
342 366
367 ret = wm8731_i2c_register();
368 if (ret != 0)
369 return ret;
370
343 corgi_snd_device = platform_device_alloc("soc-audio", -1); 371 corgi_snd_device = platform_device_alloc("soc-audio", -1);
344 if (!corgi_snd_device) 372 if (!corgi_snd_device)
345 return -ENOMEM; 373 return -ENOMEM;
diff --git a/sound/soc/pxa/e740_wm9705.c b/sound/soc/pxa/e740_wm9705.c
new file mode 100644
index 000000000000..7cd2f89d7b10
--- /dev/null
+++ b/sound/soc/pxa/e740_wm9705.c
@@ -0,0 +1,211 @@
1/*
2 * e740-wm9705.c -- SoC audio for e740
3 *
4 * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 ONLY.
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/gpio.h>
15
16#include <sound/core.h>
17#include <sound/pcm.h>
18#include <sound/soc.h>
19#include <sound/soc-dapm.h>
20
21#include <mach/audio.h>
22#include <mach/eseries-gpio.h>
23
24#include <asm/mach-types.h>
25
26#include "../codecs/wm9705.h"
27#include "pxa2xx-pcm.h"
28#include "pxa2xx-ac97.h"
29
30
31#define E740_AUDIO_OUT 1
32#define E740_AUDIO_IN 2
33
34static int e740_audio_power;
35
36static void e740_sync_audio_power(int status)
37{
38 gpio_set_value(GPIO_E740_WM9705_nAVDD2, !status);
39 gpio_set_value(GPIO_E740_AMP_ON, (status & E740_AUDIO_OUT) ? 1 : 0);
40 gpio_set_value(GPIO_E740_MIC_ON, (status & E740_AUDIO_IN) ? 1 : 0);
41}
42
43static int e740_mic_amp_event(struct snd_soc_dapm_widget *w,
44 struct snd_kcontrol *kcontrol, int event)
45{
46 if (event & SND_SOC_DAPM_PRE_PMU)
47 e740_audio_power |= E740_AUDIO_IN;
48 else if (event & SND_SOC_DAPM_POST_PMD)
49 e740_audio_power &= ~E740_AUDIO_IN;
50
51 e740_sync_audio_power(e740_audio_power);
52
53 return 0;
54}
55
56static int e740_output_amp_event(struct snd_soc_dapm_widget *w,
57 struct snd_kcontrol *kcontrol, int event)
58{
59 if (event & SND_SOC_DAPM_PRE_PMU)
60 e740_audio_power |= E740_AUDIO_OUT;
61 else if (event & SND_SOC_DAPM_POST_PMD)
62 e740_audio_power &= ~E740_AUDIO_OUT;
63
64 e740_sync_audio_power(e740_audio_power);
65
66 return 0;
67}
68
69static const struct snd_soc_dapm_widget e740_dapm_widgets[] = {
70 SND_SOC_DAPM_HP("Headphone Jack", NULL),
71 SND_SOC_DAPM_SPK("Speaker", NULL),
72 SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
73 SND_SOC_DAPM_PGA_E("Output Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
74 e740_output_amp_event, SND_SOC_DAPM_PRE_PMU |
75 SND_SOC_DAPM_POST_PMD),
76 SND_SOC_DAPM_PGA_E("Mic Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
77 e740_mic_amp_event, SND_SOC_DAPM_PRE_PMU |
78 SND_SOC_DAPM_POST_PMD),
79};
80
81static const struct snd_soc_dapm_route audio_map[] = {
82 {"Output Amp", NULL, "LOUT"},
83 {"Output Amp", NULL, "ROUT"},
84 {"Output Amp", NULL, "MONOOUT"},
85
86 {"Speaker", NULL, "Output Amp"},
87 {"Headphone Jack", NULL, "Output Amp"},
88
89 {"MIC1", NULL, "Mic Amp"},
90 {"Mic Amp", NULL, "Mic (Internal)"},
91};
92
93static int e740_ac97_init(struct snd_soc_codec *codec)
94{
95 snd_soc_dapm_nc_pin(codec, "HPOUTL");
96 snd_soc_dapm_nc_pin(codec, "HPOUTR");
97 snd_soc_dapm_nc_pin(codec, "PHONE");
98 snd_soc_dapm_nc_pin(codec, "LINEINL");
99 snd_soc_dapm_nc_pin(codec, "LINEINR");
100 snd_soc_dapm_nc_pin(codec, "CDINL");
101 snd_soc_dapm_nc_pin(codec, "CDINR");
102 snd_soc_dapm_nc_pin(codec, "PCBEEP");
103 snd_soc_dapm_nc_pin(codec, "MIC2");
104
105 snd_soc_dapm_new_controls(codec, e740_dapm_widgets,
106 ARRAY_SIZE(e740_dapm_widgets));
107
108 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
109
110 snd_soc_dapm_sync(codec);
111
112 return 0;
113}
114
115static struct snd_soc_dai_link e740_dai[] = {
116 {
117 .name = "AC97",
118 .stream_name = "AC97 HiFi",
119 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
120 .codec_dai = &wm9705_dai[WM9705_DAI_AC97_HIFI],
121 .init = e740_ac97_init,
122 },
123 {
124 .name = "AC97 Aux",
125 .stream_name = "AC97 Aux",
126 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
127 .codec_dai = &wm9705_dai[WM9705_DAI_AC97_AUX],
128 },
129};
130
131static struct snd_soc_card e740 = {
132 .name = "Toshiba e740",
133 .platform = &pxa2xx_soc_platform,
134 .dai_link = e740_dai,
135 .num_links = ARRAY_SIZE(e740_dai),
136};
137
138static struct snd_soc_device e740_snd_devdata = {
139 .card = &e740,
140 .codec_dev = &soc_codec_dev_wm9705,
141};
142
143static struct platform_device *e740_snd_device;
144
145static int __init e740_init(void)
146{
147 int ret;
148
149 if (!machine_is_e740())
150 return -ENODEV;
151
152 ret = gpio_request(GPIO_E740_MIC_ON, "Mic amp");
153 if (ret)
154 return ret;
155
156 ret = gpio_request(GPIO_E740_AMP_ON, "Output amp");
157 if (ret)
158 goto free_mic_amp_gpio;
159
160 ret = gpio_request(GPIO_E740_WM9705_nAVDD2, "Audio power");
161 if (ret)
162 goto free_op_amp_gpio;
163
164 /* Disable audio */
165 ret = gpio_direction_output(GPIO_E740_MIC_ON, 0);
166 if (ret)
167 goto free_apwr_gpio;
168 ret = gpio_direction_output(GPIO_E740_AMP_ON, 0);
169 if (ret)
170 goto free_apwr_gpio;
171 ret = gpio_direction_output(GPIO_E740_WM9705_nAVDD2, 1);
172 if (ret)
173 goto free_apwr_gpio;
174
175 e740_snd_device = platform_device_alloc("soc-audio", -1);
176 if (!e740_snd_device) {
177 ret = -ENOMEM;
178 goto free_apwr_gpio;
179 }
180
181 platform_set_drvdata(e740_snd_device, &e740_snd_devdata);
182 e740_snd_devdata.dev = &e740_snd_device->dev;
183 ret = platform_device_add(e740_snd_device);
184
185 if (!ret)
186 return 0;
187
188/* Fail gracefully */
189 platform_device_put(e740_snd_device);
190free_apwr_gpio:
191 gpio_free(GPIO_E740_WM9705_nAVDD2);
192free_op_amp_gpio:
193 gpio_free(GPIO_E740_AMP_ON);
194free_mic_amp_gpio:
195 gpio_free(GPIO_E740_MIC_ON);
196
197 return ret;
198}
199
200static void __exit e740_exit(void)
201{
202 platform_device_unregister(e740_snd_device);
203}
204
205module_init(e740_init);
206module_exit(e740_exit);
207
208/* Module information */
209MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
210MODULE_DESCRIPTION("ALSA SoC driver for e740");
211MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/pxa/e750_wm9705.c b/sound/soc/pxa/e750_wm9705.c
new file mode 100644
index 000000000000..8dceccc5e059
--- /dev/null
+++ b/sound/soc/pxa/e750_wm9705.c
@@ -0,0 +1,187 @@
1/*
2 * e750-wm9705.c -- SoC audio for e750
3 *
4 * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; version 2 ONLY.
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/gpio.h>
15
16#include <sound/core.h>
17#include <sound/pcm.h>
18#include <sound/soc.h>
19#include <sound/soc-dapm.h>
20
21#include <mach/audio.h>
22#include <mach/eseries-gpio.h>
23
24#include <asm/mach-types.h>
25
26#include "../codecs/wm9705.h"
27#include "pxa2xx-pcm.h"
28#include "pxa2xx-ac97.h"
29
30static int e750_spk_amp_event(struct snd_soc_dapm_widget *w,
31 struct snd_kcontrol *kcontrol, int event)
32{
33 if (event & SND_SOC_DAPM_PRE_PMU)
34 gpio_set_value(GPIO_E750_SPK_AMP_OFF, 0);
35 else if (event & SND_SOC_DAPM_POST_PMD)
36 gpio_set_value(GPIO_E750_SPK_AMP_OFF, 1);
37
38 return 0;
39}
40
41static int e750_hp_amp_event(struct snd_soc_dapm_widget *w,
42 struct snd_kcontrol *kcontrol, int event)
43{
44 if (event & SND_SOC_DAPM_PRE_PMU)
45 gpio_set_value(GPIO_E750_HP_AMP_OFF, 0);
46 else if (event & SND_SOC_DAPM_POST_PMD)
47 gpio_set_value(GPIO_E750_HP_AMP_OFF, 1);
48
49 return 0;
50}
51
52static const struct snd_soc_dapm_widget e750_dapm_widgets[] = {
53 SND_SOC_DAPM_HP("Headphone Jack", NULL),
54 SND_SOC_DAPM_SPK("Speaker", NULL),
55 SND_SOC_DAPM_MIC("Mic (Internal)", NULL),
56 SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
57 e750_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
58 SND_SOC_DAPM_POST_PMD),
59 SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
60 e750_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
61 SND_SOC_DAPM_POST_PMD),
62};
63
64static const struct snd_soc_dapm_route audio_map[] = {
65 {"Headphone Amp", NULL, "HPOUTL"},
66 {"Headphone Amp", NULL, "HPOUTR"},
67 {"Headphone Jack", NULL, "Headphone Amp"},
68
69 {"Speaker Amp", NULL, "MONOOUT"},
70 {"Speaker", NULL, "Speaker Amp"},
71
72 {"MIC1", NULL, "Mic (Internal)"},
73};
74
75static int e750_ac97_init(struct snd_soc_codec *codec)
76{
77 snd_soc_dapm_nc_pin(codec, "LOUT");
78 snd_soc_dapm_nc_pin(codec, "ROUT");
79 snd_soc_dapm_nc_pin(codec, "PHONE");
80 snd_soc_dapm_nc_pin(codec, "LINEINL");
81 snd_soc_dapm_nc_pin(codec, "LINEINR");
82 snd_soc_dapm_nc_pin(codec, "CDINL");
83 snd_soc_dapm_nc_pin(codec, "CDINR");
84 snd_soc_dapm_nc_pin(codec, "PCBEEP");
85 snd_soc_dapm_nc_pin(codec, "MIC2");
86
87 snd_soc_dapm_new_controls(codec, e750_dapm_widgets,
88 ARRAY_SIZE(e750_dapm_widgets));
89
90 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
91
92 snd_soc_dapm_sync(codec);
93
94 return 0;
95}
96
97static struct snd_soc_dai_link e750_dai[] = {
98 {
99 .name = "AC97",
100 .stream_name = "AC97 HiFi",
101 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
102 .codec_dai = &wm9705_dai[WM9705_DAI_AC97_HIFI],
103 .init = e750_ac97_init,
104 /* use ops to check startup state */
105 },
106 {
107 .name = "AC97 Aux",
108 .stream_name = "AC97 Aux",
109 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
110 .codec_dai = &wm9705_dai[WM9705_DAI_AC97_AUX],
111 },
112};
113
114static struct snd_soc_card e750 = {
115 .name = "Toshiba e750",
116 .platform = &pxa2xx_soc_platform,
117 .dai_link = e750_dai,
118 .num_links = ARRAY_SIZE(e750_dai),
119};
120
121static struct snd_soc_device e750_snd_devdata = {
122 .card = &e750,
123 .codec_dev = &soc_codec_dev_wm9705,
124};
125
126static struct platform_device *e750_snd_device;
127
128static int __init e750_init(void)
129{
130 int ret;
131
132 if (!machine_is_e750())
133 return -ENODEV;
134
135 ret = gpio_request(GPIO_E750_HP_AMP_OFF, "Headphone amp");
136 if (ret)
137 return ret;
138
139 ret = gpio_request(GPIO_E750_SPK_AMP_OFF, "Speaker amp");
140 if (ret)
141 goto free_hp_amp_gpio;
142
143 ret = gpio_direction_output(GPIO_E750_HP_AMP_OFF, 1);
144 if (ret)
145 goto free_spk_amp_gpio;
146
147 ret = gpio_direction_output(GPIO_E750_SPK_AMP_OFF, 1);
148 if (ret)
149 goto free_spk_amp_gpio;
150
151 e750_snd_device = platform_device_alloc("soc-audio", -1);
152 if (!e750_snd_device) {
153 ret = -ENOMEM;
154 goto free_spk_amp_gpio;
155 }
156
157 platform_set_drvdata(e750_snd_device, &e750_snd_devdata);
158 e750_snd_devdata.dev = &e750_snd_device->dev;
159 ret = platform_device_add(e750_snd_device);
160
161 if (!ret)
162 return 0;
163
164/* Fail gracefully */
165 platform_device_put(e750_snd_device);
166free_spk_amp_gpio:
167 gpio_free(GPIO_E750_SPK_AMP_OFF);
168free_hp_amp_gpio:
169 gpio_free(GPIO_E750_HP_AMP_OFF);
170
171 return ret;
172}
173
174static void __exit e750_exit(void)
175{
176 platform_device_unregister(e750_snd_device);
177 gpio_free(GPIO_E750_SPK_AMP_OFF);
178 gpio_free(GPIO_E750_HP_AMP_OFF);
179}
180
181module_init(e750_init);
182module_exit(e750_exit);
183
184/* Module information */
185MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
186MODULE_DESCRIPTION("ALSA SoC driver for e750");
187MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/pxa/e800_wm9712.c b/sound/soc/pxa/e800_wm9712.c
index 2e3386dfa0f0..bc019cdce429 100644
--- a/sound/soc/pxa/e800_wm9712.c
+++ b/sound/soc/pxa/e800_wm9712.c
@@ -1,8 +1,6 @@
1/* 1/*
2 * e800-wm9712.c -- SoC audio for e800 2 * e800-wm9712.c -- SoC audio for e800
3 * 3 *
4 * Based on tosa.c
5 *
6 * Copyright 2007 (c) Ian Molton <spyro@f2s.com> 4 * Copyright 2007 (c) Ian Molton <spyro@f2s.com>
7 * 5 *
8 * This program is free software; you can redistribute it and/or modify it 6 * This program is free software; you can redistribute it and/or modify it
@@ -13,7 +11,7 @@
13 11
14#include <linux/module.h> 12#include <linux/module.h>
15#include <linux/moduleparam.h> 13#include <linux/moduleparam.h>
16#include <linux/device.h> 14#include <linux/gpio.h>
17 15
18#include <sound/core.h> 16#include <sound/core.h>
19#include <sound/pcm.h> 17#include <sound/pcm.h>
@@ -21,23 +19,85 @@
21#include <sound/soc-dapm.h> 19#include <sound/soc-dapm.h>
22 20
23#include <asm/mach-types.h> 21#include <asm/mach-types.h>
24#include <mach/pxa-regs.h>
25#include <mach/hardware.h>
26#include <mach/audio.h> 22#include <mach/audio.h>
23#include <mach/eseries-gpio.h>
27 24
28#include "../codecs/wm9712.h" 25#include "../codecs/wm9712.h"
29#include "pxa2xx-pcm.h" 26#include "pxa2xx-pcm.h"
30#include "pxa2xx-ac97.h" 27#include "pxa2xx-ac97.h"
31 28
32static struct snd_soc_card e800; 29static int e800_spk_amp_event(struct snd_soc_dapm_widget *w,
30 struct snd_kcontrol *kcontrol, int event)
31{
32 if (event & SND_SOC_DAPM_PRE_PMU)
33 gpio_set_value(GPIO_E800_SPK_AMP_ON, 1);
34 else if (event & SND_SOC_DAPM_POST_PMD)
35 gpio_set_value(GPIO_E800_SPK_AMP_ON, 0);
33 36
34static struct snd_soc_dai_link e800_dai[] = { 37 return 0;
38}
39
40static int e800_hp_amp_event(struct snd_soc_dapm_widget *w,
41 struct snd_kcontrol *kcontrol, int event)
42{
43 if (event & SND_SOC_DAPM_PRE_PMU)
44 gpio_set_value(GPIO_E800_HP_AMP_OFF, 0);
45 else if (event & SND_SOC_DAPM_POST_PMD)
46 gpio_set_value(GPIO_E800_HP_AMP_OFF, 1);
47
48 return 0;
49}
50
51static const struct snd_soc_dapm_widget e800_dapm_widgets[] = {
52 SND_SOC_DAPM_HP("Headphone Jack", NULL),
53 SND_SOC_DAPM_MIC("Mic (Internal1)", NULL),
54 SND_SOC_DAPM_MIC("Mic (Internal2)", NULL),
55 SND_SOC_DAPM_SPK("Speaker", NULL),
56 SND_SOC_DAPM_PGA_E("Headphone Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
57 e800_hp_amp_event, SND_SOC_DAPM_PRE_PMU |
58 SND_SOC_DAPM_POST_PMD),
59 SND_SOC_DAPM_PGA_E("Speaker Amp", SND_SOC_NOPM, 0, 0, NULL, 0,
60 e800_spk_amp_event, SND_SOC_DAPM_PRE_PMU |
61 SND_SOC_DAPM_POST_PMD),
62};
63
64static const struct snd_soc_dapm_route audio_map[] = {
65 {"Headphone Jack", NULL, "HPOUTL"},
66 {"Headphone Jack", NULL, "HPOUTR"},
67 {"Headphone Jack", NULL, "Headphone Amp"},
68
69 {"Speaker Amp", NULL, "MONOOUT"},
70 {"Speaker", NULL, "Speaker Amp"},
71
72 {"MIC1", NULL, "Mic (Internal1)"},
73 {"MIC2", NULL, "Mic (Internal2)"},
74};
75
76static int e800_ac97_init(struct snd_soc_codec *codec)
35{ 77{
36 .name = "AC97 Aux", 78 snd_soc_dapm_new_controls(codec, e800_dapm_widgets,
37 .stream_name = "AC97 Aux", 79 ARRAY_SIZE(e800_dapm_widgets));
38 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX], 80
39 .codec_dai = &wm9712_dai[WM9712_DAI_AC97_AUX], 81 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
40}, 82 snd_soc_dapm_sync(codec);
83
84 return 0;
85}
86
87static struct snd_soc_dai_link e800_dai[] = {
88 {
89 .name = "AC97",
90 .stream_name = "AC97 HiFi",
91 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
92 .codec_dai = &wm9712_dai[WM9712_DAI_AC97_HIFI],
93 .init = e800_ac97_init,
94 },
95 {
96 .name = "AC97 Aux",
97 .stream_name = "AC97 Aux",
98 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
99 .codec_dai = &wm9712_dai[WM9712_DAI_AC97_AUX],
100 },
41}; 101};
42 102
43static struct snd_soc_card e800 = { 103static struct snd_soc_card e800 = {
@@ -61,6 +121,22 @@ static int __init e800_init(void)
61 if (!machine_is_e800()) 121 if (!machine_is_e800())
62 return -ENODEV; 122 return -ENODEV;
63 123
124 ret = gpio_request(GPIO_E800_HP_AMP_OFF, "Headphone amp");
125 if (ret)
126 return ret;
127
128 ret = gpio_request(GPIO_E800_SPK_AMP_ON, "Speaker amp");
129 if (ret)
130 goto free_hp_amp_gpio;
131
132 ret = gpio_direction_output(GPIO_E800_HP_AMP_OFF, 1);
133 if (ret)
134 goto free_spk_amp_gpio;
135
136 ret = gpio_direction_output(GPIO_E800_SPK_AMP_ON, 1);
137 if (ret)
138 goto free_spk_amp_gpio;
139
64 e800_snd_device = platform_device_alloc("soc-audio", -1); 140 e800_snd_device = platform_device_alloc("soc-audio", -1);
65 if (!e800_snd_device) 141 if (!e800_snd_device)
66 return -ENOMEM; 142 return -ENOMEM;
@@ -69,8 +145,15 @@ static int __init e800_init(void)
69 e800_snd_devdata.dev = &e800_snd_device->dev; 145 e800_snd_devdata.dev = &e800_snd_device->dev;
70 ret = platform_device_add(e800_snd_device); 146 ret = platform_device_add(e800_snd_device);
71 147
72 if (ret) 148 if (!ret)
73 platform_device_put(e800_snd_device); 149 return 0;
150
151/* Fail gracefully */
152 platform_device_put(e800_snd_device);
153free_spk_amp_gpio:
154 gpio_free(GPIO_E800_SPK_AMP_ON);
155free_hp_amp_gpio:
156 gpio_free(GPIO_E800_HP_AMP_OFF);
74 157
75 return ret; 158 return ret;
76} 159}
@@ -78,6 +161,8 @@ static int __init e800_init(void)
78static void __exit e800_exit(void) 161static void __exit e800_exit(void)
79{ 162{
80 platform_device_unregister(e800_snd_device); 163 platform_device_unregister(e800_snd_device);
164 gpio_free(GPIO_E800_SPK_AMP_ON);
165 gpio_free(GPIO_E800_HP_AMP_OFF);
81} 166}
82 167
83module_init(e800_init); 168module_init(e800_init);
@@ -86,4 +171,4 @@ module_exit(e800_exit);
86/* Module information */ 171/* Module information */
87MODULE_AUTHOR("Ian Molton <spyro@f2s.com>"); 172MODULE_AUTHOR("Ian Molton <spyro@f2s.com>");
88MODULE_DESCRIPTION("ALSA SoC driver for e800"); 173MODULE_DESCRIPTION("ALSA SoC driver for e800");
89MODULE_LICENSE("GPL"); 174MODULE_LICENSE("GPL v2");
diff --git a/sound/soc/pxa/mioa701_wm9713.c b/sound/soc/pxa/mioa701_wm9713.c
new file mode 100644
index 000000000000..19eda8bbfdaf
--- /dev/null
+++ b/sound/soc/pxa/mioa701_wm9713.c
@@ -0,0 +1,250 @@
1/*
2 * Handles the Mitac mioa701 SoC system
3 *
4 * Copyright (C) 2008 Robert Jarzmik
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation in version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * This is a little schema of the sound interconnections :
20 *
21 * Sagem X200 Wolfson WM9713
22 * +--------+ +-------------------+ Rear Speaker
23 * | | | | /-+
24 * | +--->----->---+MONOIN SPKL+--->----+-+ |
25 * | GSM | | | | | |
26 * | +--->----->---+PCBEEP SPKR+--->----+-+ |
27 * | CHIP | | | \-+
28 * | +---<-----<---+MONO |
29 * | | | | Front Speaker
30 * +--------+ | | /-+
31 * | HPL+--->----+-+ |
32 * | | | | |
33 * | OUT3+--->----+-+ |
34 * | | \-+
35 * | |
36 * | | Front Micro
37 * | | +
38 * | MIC1+-----<--+o+
39 * | | +
40 * +-------------------+ ---
41 */
42
43#include <linux/module.h>
44#include <linux/moduleparam.h>
45#include <linux/platform_device.h>
46
47#include <asm/mach-types.h>
48#include <mach/audio.h>
49
50#include <sound/core.h>
51#include <sound/pcm.h>
52#include <sound/soc.h>
53#include <sound/soc-dapm.h>
54#include <sound/initval.h>
55#include <sound/ac97_codec.h>
56
57#include "pxa2xx-pcm.h"
58#include "pxa2xx-ac97.h"
59#include "../codecs/wm9713.h"
60
61#define ARRAY_AND_SIZE(x) (x), ARRAY_SIZE(x)
62
63#define AC97_GPIO_PULL 0x58
64
65/* Use GPIO8 for rear speaker amplifier */
66static int rear_amp_power(struct snd_soc_codec *codec, int power)
67{
68 unsigned short reg;
69
70 if (power) {
71 reg = snd_soc_read(codec, AC97_GPIO_CFG);
72 snd_soc_write(codec, AC97_GPIO_CFG, reg | 0x0100);
73 reg = snd_soc_read(codec, AC97_GPIO_PULL);
74 snd_soc_write(codec, AC97_GPIO_PULL, reg | (1<<15));
75 } else {
76 reg = snd_soc_read(codec, AC97_GPIO_CFG);
77 snd_soc_write(codec, AC97_GPIO_CFG, reg & ~0x0100);
78 reg = snd_soc_read(codec, AC97_GPIO_PULL);
79 snd_soc_write(codec, AC97_GPIO_PULL, reg & ~(1<<15));
80 }
81
82 return 0;
83}
84
85static int rear_amp_event(struct snd_soc_dapm_widget *widget,
86 struct snd_kcontrol *kctl, int event)
87{
88 struct snd_soc_codec *codec = widget->codec;
89
90 return rear_amp_power(codec, SND_SOC_DAPM_EVENT_ON(event));
91}
92
93/* mioa701 machine dapm widgets */
94static const struct snd_soc_dapm_widget mioa701_dapm_widgets[] = {
95 SND_SOC_DAPM_SPK("Front Speaker", NULL),
96 SND_SOC_DAPM_SPK("Rear Speaker", rear_amp_event),
97 SND_SOC_DAPM_MIC("Headset", NULL),
98 SND_SOC_DAPM_LINE("GSM Line Out", NULL),
99 SND_SOC_DAPM_LINE("GSM Line In", NULL),
100 SND_SOC_DAPM_MIC("Headset Mic", NULL),
101 SND_SOC_DAPM_MIC("Front Mic", NULL),
102};
103
104static const struct snd_soc_dapm_route audio_map[] = {
105 /* Call Mic */
106 {"Mic Bias", NULL, "Front Mic"},
107 {"MIC1", NULL, "Mic Bias"},
108
109 /* Headset Mic */
110 {"LINEL", NULL, "Headset Mic"},
111 {"LINER", NULL, "Headset Mic"},
112
113 /* GSM Module */
114 {"MONOIN", NULL, "GSM Line Out"},
115 {"PCBEEP", NULL, "GSM Line Out"},
116 {"GSM Line In", NULL, "MONO"},
117
118 /* headphone connected to HPL, HPR */
119 {"Headset", NULL, "HPL"},
120 {"Headset", NULL, "HPR"},
121
122 /* front speaker connected to HPL, OUT3 */
123 {"Front Speaker", NULL, "HPL"},
124 {"Front Speaker", NULL, "OUT3"},
125
126 /* rear speaker connected to SPKL, SPKR */
127 {"Rear Speaker", NULL, "SPKL"},
128 {"Rear Speaker", NULL, "SPKR"},
129};
130
131static int mioa701_wm9713_init(struct snd_soc_codec *codec)
132{
133 unsigned short reg;
134
135 /* Add mioa701 specific widgets */
136 snd_soc_dapm_new_controls(codec, ARRAY_AND_SIZE(mioa701_dapm_widgets));
137
138 /* Set up mioa701 specific audio path audio_mapnects */
139 snd_soc_dapm_add_routes(codec, ARRAY_AND_SIZE(audio_map));
140
141 /* Prepare GPIO8 for rear speaker amplifier */
142 reg = codec->read(codec, AC97_GPIO_CFG);
143 codec->write(codec, AC97_GPIO_CFG, reg | 0x0100);
144
145 /* Prepare MIC input */
146 reg = codec->read(codec, AC97_3D_CONTROL);
147 codec->write(codec, AC97_3D_CONTROL, reg | 0xc000);
148
149 snd_soc_dapm_enable_pin(codec, "Front Speaker");
150 snd_soc_dapm_enable_pin(codec, "Rear Speaker");
151 snd_soc_dapm_enable_pin(codec, "Front Mic");
152 snd_soc_dapm_enable_pin(codec, "GSM Line In");
153 snd_soc_dapm_enable_pin(codec, "GSM Line Out");
154 snd_soc_dapm_sync(codec);
155
156 return 0;
157}
158
159static struct snd_soc_ops mioa701_ops;
160
161static struct snd_soc_dai_link mioa701_dai[] = {
162 {
163 .name = "AC97",
164 .stream_name = "AC97 HiFi",
165 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_HIFI],
166 .codec_dai = &wm9713_dai[WM9713_DAI_AC97_HIFI],
167 .init = mioa701_wm9713_init,
168 .ops = &mioa701_ops,
169 },
170 {
171 .name = "AC97 Aux",
172 .stream_name = "AC97 Aux",
173 .cpu_dai = &pxa_ac97_dai[PXA2XX_DAI_AC97_AUX],
174 .codec_dai = &wm9713_dai[WM9713_DAI_AC97_AUX],
175 .ops = &mioa701_ops,
176 },
177};
178
179static struct snd_soc_card mioa701 = {
180 .name = "MioA701",
181 .platform = &pxa2xx_soc_platform,
182 .dai_link = mioa701_dai,
183 .num_links = ARRAY_SIZE(mioa701_dai),
184};
185
186static struct snd_soc_device mioa701_snd_devdata = {
187 .card = &mioa701,
188 .codec_dev = &soc_codec_dev_wm9713,
189};
190
191static struct platform_device *mioa701_snd_device;
192
193static int mioa701_wm9713_probe(struct platform_device *pdev)
194{
195 int ret;
196
197 if (!machine_is_mioa701())
198 return -ENODEV;
199
200 dev_warn(&pdev->dev, "Be warned that incorrect mixers/muxes setup will"
201 "lead to overheating and possible destruction of your device."
202 "Do not use without a good knowledge of mio's board design!\n");
203
204 mioa701_snd_device = platform_device_alloc("soc-audio", -1);
205 if (!mioa701_snd_device)
206 return -ENOMEM;
207
208 platform_set_drvdata(mioa701_snd_device, &mioa701_snd_devdata);
209 mioa701_snd_devdata.dev = &mioa701_snd_device->dev;
210
211 ret = platform_device_add(mioa701_snd_device);
212 if (!ret)
213 return 0;
214
215 platform_device_put(mioa701_snd_device);
216 return ret;
217}
218
219static int __devexit mioa701_wm9713_remove(struct platform_device *pdev)
220{
221 platform_device_unregister(mioa701_snd_device);
222 return 0;
223}
224
225static struct platform_driver mioa701_wm9713_driver = {
226 .probe = mioa701_wm9713_probe,
227 .remove = __devexit_p(mioa701_wm9713_remove),
228 .driver = {
229 .name = "mioa701-wm9713",
230 .owner = THIS_MODULE,
231 },
232};
233
234static int __init mioa701_asoc_init(void)
235{
236 return platform_driver_register(&mioa701_wm9713_driver);
237}
238
239static void __exit mioa701_asoc_exit(void)
240{
241 platform_driver_unregister(&mioa701_wm9713_driver);
242}
243
244module_init(mioa701_asoc_init);
245module_exit(mioa701_asoc_exit);
246
247/* Module information */
248MODULE_AUTHOR("Robert Jarzmik (rjarzmik@free.fr)");
249MODULE_DESCRIPTION("ALSA SoC WM9713 MIO A701");
250MODULE_LICENSE("GPL");
diff --git a/sound/soc/pxa/palm27x.c b/sound/soc/pxa/palm27x.c
index 4a9cf3083af0..48a73f64500b 100644
--- a/sound/soc/pxa/palm27x.c
+++ b/sound/soc/pxa/palm27x.c
@@ -55,7 +55,7 @@ static void palm27x_ext_control(struct snd_soc_codec *codec)
55static int palm27x_startup(struct snd_pcm_substream *substream) 55static int palm27x_startup(struct snd_pcm_substream *substream)
56{ 56{
57 struct snd_soc_pcm_runtime *rtd = substream->private_data; 57 struct snd_soc_pcm_runtime *rtd = substream->private_data;
58 struct snd_soc_codec *codec = rtd->socdev->codec; 58 struct snd_soc_codec *codec = rtd->socdev->card->codec;
59 59
60 /* check the jack status at stream startup */ 60 /* check the jack status at stream startup */
61 palm27x_ext_control(codec); 61 palm27x_ext_control(codec);
@@ -146,19 +146,16 @@ static const struct snd_kcontrol_new palm27x_controls[] = {
146 146
147static int palm27x_ac97_init(struct snd_soc_codec *codec) 147static int palm27x_ac97_init(struct snd_soc_codec *codec)
148{ 148{
149 int i, err; 149 int err;
150 150
151 snd_soc_dapm_nc_pin(codec, "OUT3"); 151 snd_soc_dapm_nc_pin(codec, "OUT3");
152 snd_soc_dapm_nc_pin(codec, "MONOOUT"); 152 snd_soc_dapm_nc_pin(codec, "MONOOUT");
153 153
154 /* add palm27x specific controls */ 154 /* add palm27x specific controls */
155 for (i = 0; i < ARRAY_SIZE(palm27x_controls); i++) { 155 err = snd_soc_add_controls(codec, palm27x_controls,
156 err = snd_ctl_add(codec->card, 156 ARRAY_SIZE(palm27x_controls));
157 snd_soc_cnew(&palm27x_controls[i], 157 if (err < 0)
158 codec, NULL)); 158 return err;
159 if (err < 0)
160 return err;
161 }
162 159
163 /* add palm27x specific widgets */ 160 /* add palm27x specific widgets */
164 snd_soc_dapm_new_controls(codec, palm27x_dapm_widgets, 161 snd_soc_dapm_new_controls(codec, palm27x_dapm_widgets,
diff --git a/sound/soc/pxa/poodle.c b/sound/soc/pxa/poodle.c
index 6e9827189fff..ef7c6c8dc8f1 100644
--- a/sound/soc/pxa/poodle.c
+++ b/sound/soc/pxa/poodle.c
@@ -17,6 +17,7 @@
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/moduleparam.h> 18#include <linux/moduleparam.h>
19#include <linux/timer.h> 19#include <linux/timer.h>
20#include <linux/i2c.h>
20#include <linux/interrupt.h> 21#include <linux/interrupt.h>
21#include <linux/platform_device.h> 22#include <linux/platform_device.h>
22#include <sound/core.h> 23#include <sound/core.h>
@@ -77,7 +78,7 @@ static void poodle_ext_control(struct snd_soc_codec *codec)
77static int poodle_startup(struct snd_pcm_substream *substream) 78static int poodle_startup(struct snd_pcm_substream *substream)
78{ 79{
79 struct snd_soc_pcm_runtime *rtd = substream->private_data; 80 struct snd_soc_pcm_runtime *rtd = substream->private_data;
80 struct snd_soc_codec *codec = rtd->socdev->codec; 81 struct snd_soc_codec *codec = rtd->socdev->card->codec;
81 82
82 /* check the jack status at stream startup */ 83 /* check the jack status at stream startup */
83 poodle_ext_control(codec); 84 poodle_ext_control(codec);
@@ -240,19 +241,17 @@ static const struct snd_kcontrol_new wm8731_poodle_controls[] = {
240 */ 241 */
241static int poodle_wm8731_init(struct snd_soc_codec *codec) 242static int poodle_wm8731_init(struct snd_soc_codec *codec)
242{ 243{
243 int i, err; 244 int err;
244 245
245 snd_soc_dapm_nc_pin(codec, "LLINEIN"); 246 snd_soc_dapm_nc_pin(codec, "LLINEIN");
246 snd_soc_dapm_nc_pin(codec, "RLINEIN"); 247 snd_soc_dapm_nc_pin(codec, "RLINEIN");
247 snd_soc_dapm_enable_pin(codec, "MICIN"); 248 snd_soc_dapm_enable_pin(codec, "MICIN");
248 249
249 /* Add poodle specific controls */ 250 /* Add poodle specific controls */
250 for (i = 0; i < ARRAY_SIZE(wm8731_poodle_controls); i++) { 251 err = snd_soc_add_controls(codec, wm8731_poodle_controls,
251 err = snd_ctl_add(codec->card, 252 ARRAY_SIZE(wm8731_poodle_controls));
252 snd_soc_cnew(&wm8731_poodle_controls[i], codec, NULL)); 253 if (err < 0)
253 if (err < 0) 254 return err;
254 return err;
255 }
256 255
257 /* Add poodle specific widgets */ 256 /* Add poodle specific widgets */
258 snd_soc_dapm_new_controls(codec, wm8731_dapm_widgets, 257 snd_soc_dapm_new_controls(codec, wm8731_dapm_widgets,
@@ -283,17 +282,42 @@ static struct snd_soc_card snd_soc_poodle = {
283 .num_links = 1, 282 .num_links = 1,
284}; 283};
285 284
286/* poodle audio private data */ 285/*
287static struct wm8731_setup_data poodle_wm8731_setup = { 286 * FIXME: This is a temporary bodge to avoid cross-tree merge issues.
288 .i2c_bus = 0, 287 * New drivers should register the wm8731 I2C device in the machine
289 .i2c_address = 0x1b, 288 * setup code (under arch/arm for ARM systems).
290}; 289 */
290static int wm8731_i2c_register(void)
291{
292 struct i2c_board_info info;
293 struct i2c_adapter *adapter;
294 struct i2c_client *client;
295
296 memset(&info, 0, sizeof(struct i2c_board_info));
297 info.addr = 0x1b;
298 strlcpy(info.type, "wm8731", I2C_NAME_SIZE);
299
300 adapter = i2c_get_adapter(0);
301 if (!adapter) {
302 printk(KERN_ERR "can't get i2c adapter 0\n");
303 return -ENODEV;
304 }
305
306 client = i2c_new_device(adapter, &info);
307 i2c_put_adapter(adapter);
308 if (!client) {
309 printk(KERN_ERR "can't add i2c device at 0x%x\n",
310 (unsigned int)info.addr);
311 return -ENODEV;
312 }
313
314 return 0;
315}
291 316
292/* poodle audio subsystem */ 317/* poodle audio subsystem */
293static struct snd_soc_device poodle_snd_devdata = { 318static struct snd_soc_device poodle_snd_devdata = {
294 .card = &snd_soc_poodle, 319 .card = &snd_soc_poodle,
295 .codec_dev = &soc_codec_dev_wm8731, 320 .codec_dev = &soc_codec_dev_wm8731,
296 .codec_data = &poodle_wm8731_setup,
297}; 321};
298 322
299static struct platform_device *poodle_snd_device; 323static struct platform_device *poodle_snd_device;
@@ -305,6 +329,10 @@ static int __init poodle_init(void)
305 if (!machine_is_poodle()) 329 if (!machine_is_poodle())
306 return -ENODEV; 330 return -ENODEV;
307 331
332 ret = wm8731_i2c_register();
333 if (ret != 0)
334 return ret;
335
308 locomo_gpio_set_dir(&poodle_locomo_device.dev, 336 locomo_gpio_set_dir(&poodle_locomo_device.dev,
309 POODLE_LOCOMO_GPIO_AMP_ON, 0); 337 POODLE_LOCOMO_GPIO_AMP_ON, 0);
310 /* should we mute HP at startup - burning power ?*/ 338 /* should we mute HP at startup - burning power ?*/
diff --git a/sound/soc/pxa/pxa-ssp.c b/sound/soc/pxa/pxa-ssp.c
index 73cb6b4c2f2d..b0bf40973d5b 100644
--- a/sound/soc/pxa/pxa-ssp.c
+++ b/sound/soc/pxa/pxa-ssp.c
@@ -1,4 +1,3 @@
1#define DEBUG
2/* 1/*
3 * pxa-ssp.c -- ALSA Soc Audio Layer 2 * pxa-ssp.c -- ALSA Soc Audio Layer
4 * 3 *
@@ -21,6 +20,8 @@
21#include <linux/clk.h> 20#include <linux/clk.h>
22#include <linux/io.h> 21#include <linux/io.h>
23 22
23#include <asm/irq.h>
24
24#include <sound/core.h> 25#include <sound/core.h>
25#include <sound/pcm.h> 26#include <sound/pcm.h>
26#include <sound/initval.h> 27#include <sound/initval.h>
@@ -221,9 +222,9 @@ static int pxa_ssp_startup(struct snd_pcm_substream *substream,
221 int ret = 0; 222 int ret = 0;
222 223
223 if (!cpu_dai->active) { 224 if (!cpu_dai->active) {
224 ret = ssp_init(&priv->dev, cpu_dai->id + 1, SSP_NO_IRQ); 225 priv->dev.port = cpu_dai->id + 1;
225 if (ret < 0) 226 priv->dev.irq = NO_IRQ;
226 return ret; 227 clk_enable(priv->dev.ssp->clk);
227 ssp_disable(&priv->dev); 228 ssp_disable(&priv->dev);
228 } 229 }
229 return ret; 230 return ret;
@@ -238,7 +239,7 @@ static void pxa_ssp_shutdown(struct snd_pcm_substream *substream,
238 239
239 if (!cpu_dai->active) { 240 if (!cpu_dai->active) {
240 ssp_disable(&priv->dev); 241 ssp_disable(&priv->dev);
241 ssp_exit(&priv->dev); 242 clk_disable(priv->dev.ssp->clk);
242 } 243 }
243} 244}
244 245
@@ -298,7 +299,7 @@ static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
298 int val; 299 int val;
299 300
300 u32 sscr0 = ssp_read_reg(ssp, SSCR0) & 301 u32 sscr0 = ssp_read_reg(ssp, SSCR0) &
301 ~(SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ADC); 302 ~(SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
302 303
303 dev_dbg(&ssp->pdev->dev, 304 dev_dbg(&ssp->pdev->dev,
304 "pxa_ssp_set_dai_sysclk id: %d, clk_id %d, freq %d\n", 305 "pxa_ssp_set_dai_sysclk id: %d, clk_id %d, freq %d\n",
@@ -326,7 +327,7 @@ static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
326 case PXA_SSP_CLK_AUDIO: 327 case PXA_SSP_CLK_AUDIO:
327 priv->sysclk = 0; 328 priv->sysclk = 0;
328 ssp_set_scr(&priv->dev, 1); 329 ssp_set_scr(&priv->dev, 1);
329 sscr0 |= SSCR0_ADC; 330 sscr0 |= SSCR0_ACS;
330 break; 331 break;
331 default: 332 default:
332 return -ENODEV; 333 return -ENODEV;
@@ -520,9 +521,20 @@ static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
520 u32 sscr1; 521 u32 sscr1;
521 u32 sspsp; 522 u32 sspsp;
522 523
524 /* check if we need to change anything at all */
525 if (priv->dai_fmt == fmt)
526 return 0;
527
528 /* we can only change the settings if the port is not in use */
529 if (ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) {
530 dev_err(&ssp->pdev->dev,
531 "can't change hardware dai format: stream is in use");
532 return -EINVAL;
533 }
534
523 /* reset port settings */ 535 /* reset port settings */
524 sscr0 = ssp_read_reg(ssp, SSCR0) & 536 sscr0 = ssp_read_reg(ssp, SSCR0) &
525 (SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ADC); 537 (SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
526 sscr1 = SSCR1_RxTresh(8) | SSCR1_TxTresh(7); 538 sscr1 = SSCR1_RxTresh(8) | SSCR1_TxTresh(7);
527 sspsp = 0; 539 sspsp = 0;
528 540
@@ -545,18 +557,18 @@ static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
545 557
546 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 558 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
547 case SND_SOC_DAIFMT_I2S: 559 case SND_SOC_DAIFMT_I2S:
548 sscr0 |= SSCR0_MOD | SSCR0_PSP; 560 sscr0 |= SSCR0_PSP;
549 sscr1 |= SSCR1_RWOT | SSCR1_TRAIL; 561 sscr1 |= SSCR1_RWOT | SSCR1_TRAIL;
550 562
563 /* See hw_params() */
551 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 564 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
552 case SND_SOC_DAIFMT_NB_NF: 565 case SND_SOC_DAIFMT_NB_NF:
553 sspsp |= SSPSP_FSRT; 566 sspsp |= SSPSP_SFRMP;
554 break; 567 break;
555 case SND_SOC_DAIFMT_NB_IF: 568 case SND_SOC_DAIFMT_NB_IF:
556 sspsp |= SSPSP_SFRMP | SSPSP_FSRT;
557 break; 569 break;
558 case SND_SOC_DAIFMT_IB_IF: 570 case SND_SOC_DAIFMT_IB_IF:
559 sspsp |= SSPSP_SFRMP; 571 sspsp |= SSPSP_SCMODE(3);
560 break; 572 break;
561 default: 573 default:
562 return -EINVAL; 574 return -EINVAL;
@@ -642,34 +654,65 @@ static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
642 sscr0 |= SSCR0_FPCKE; 654 sscr0 |= SSCR0_FPCKE;
643#endif 655#endif
644 sscr0 |= SSCR0_DataSize(16); 656 sscr0 |= SSCR0_DataSize(16);
645 if (params_channels(params) > 1)
646 sscr0 |= SSCR0_EDSS;
647 break; 657 break;
648 case SNDRV_PCM_FORMAT_S24_LE: 658 case SNDRV_PCM_FORMAT_S24_LE:
649 sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(8)); 659 sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(8));
650 /* we must be in network mode (2 slots) for 24 bit stereo */
651 break; 660 break;
652 case SNDRV_PCM_FORMAT_S32_LE: 661 case SNDRV_PCM_FORMAT_S32_LE:
653 sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(16)); 662 sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(16));
654 /* we must be in network mode (2 slots) for 32 bit stereo */
655 break; 663 break;
656 } 664 }
657 ssp_write_reg(ssp, SSCR0, sscr0); 665 ssp_write_reg(ssp, SSCR0, sscr0);
658 666
659 switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 667 switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
660 case SND_SOC_DAIFMT_I2S: 668 case SND_SOC_DAIFMT_I2S:
661 /* Cleared when the DAI format is set */ 669 sspsp = ssp_read_reg(ssp, SSPSP);
662 sspsp = ssp_read_reg(ssp, SSPSP) | SSPSP_SFRMWDTH(width); 670
671 if (((sscr0 & SSCR0_SCR) == SSCR0_SerClkDiv(4)) &&
672 (width == 16)) {
673 /* This is a special case where the bitclk is 64fs
674 * and we're not dealing with 2*32 bits of audio
675 * samples.
676 *
677 * The SSP values used for that are all found out by
678 * trying and failing a lot; some of the registers
679 * needed for that mode are only available on PXA3xx.
680 */
681
682#ifdef CONFIG_PXA3xx
683 if (!cpu_is_pxa3xx())
684 return -EINVAL;
685
686 sspsp |= SSPSP_SFRMWDTH(width * 2);
687 sspsp |= SSPSP_SFRMDLY(width * 4);
688 sspsp |= SSPSP_EDMYSTOP(3);
689 sspsp |= SSPSP_DMYSTOP(3);
690 sspsp |= SSPSP_DMYSTRT(1);
691#else
692 return -EINVAL;
693#endif
694 } else {
695 /* The frame width is the width the LRCLK is
696 * asserted for; the delay is expressed in
697 * half cycle units. We need the extra cycle
698 * because the data starts clocking out one BCLK
699 * after LRCLK changes polarity.
700 */
701 sspsp |= SSPSP_SFRMWDTH(width + 1);
702 sspsp |= SSPSP_SFRMDLY((width + 1) * 2);
703 sspsp |= SSPSP_DMYSTRT(1);
704 }
705
663 ssp_write_reg(ssp, SSPSP, sspsp); 706 ssp_write_reg(ssp, SSPSP, sspsp);
664 break; 707 break;
665 default: 708 default:
666 break; 709 break;
667 } 710 }
668 711
669 /* We always use a network mode so we always require TDM slots 712 /* When we use a network mode, we always require TDM slots
670 * - complain loudly and fail if they've not been set up yet. 713 * - complain loudly and fail if they've not been set up yet.
671 */ 714 */
672 if (!(ssp_read_reg(ssp, SSTSA) & 0xf)) { 715 if ((sscr0 & SSCR0_MOD) && !(ssp_read_reg(ssp, SSTSA) & 0xf)) {
673 dev_err(&ssp->pdev->dev, "No TDM timeslot configured\n"); 716 dev_err(&ssp->pdev->dev, "No TDM timeslot configured\n");
674 return -EINVAL; 717 return -EINVAL;
675 } 718 }
@@ -751,7 +794,7 @@ static int pxa_ssp_probe(struct platform_device *pdev,
751 if (!priv) 794 if (!priv)
752 return -ENOMEM; 795 return -ENOMEM;
753 796
754 priv->dev.ssp = ssp_request(dai->id, "SoC audio"); 797 priv->dev.ssp = ssp_request(dai->id + 1, "SoC audio");
755 if (priv->dev.ssp == NULL) { 798 if (priv->dev.ssp == NULL) {
756 ret = -ENODEV; 799 ret = -ENODEV;
757 goto err_priv; 800 goto err_priv;
@@ -782,6 +825,19 @@ static void pxa_ssp_remove(struct platform_device *pdev,
782 SNDRV_PCM_FMTBIT_S24_LE | \ 825 SNDRV_PCM_FMTBIT_S24_LE | \
783 SNDRV_PCM_FMTBIT_S32_LE) 826 SNDRV_PCM_FMTBIT_S32_LE)
784 827
828static struct snd_soc_dai_ops pxa_ssp_dai_ops = {
829 .startup = pxa_ssp_startup,
830 .shutdown = pxa_ssp_shutdown,
831 .trigger = pxa_ssp_trigger,
832 .hw_params = pxa_ssp_hw_params,
833 .set_sysclk = pxa_ssp_set_dai_sysclk,
834 .set_clkdiv = pxa_ssp_set_dai_clkdiv,
835 .set_pll = pxa_ssp_set_dai_pll,
836 .set_fmt = pxa_ssp_set_dai_fmt,
837 .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
838 .set_tristate = pxa_ssp_set_dai_tristate,
839};
840
785struct snd_soc_dai pxa_ssp_dai[] = { 841struct snd_soc_dai pxa_ssp_dai[] = {
786 { 842 {
787 .name = "pxa2xx-ssp1", 843 .name = "pxa2xx-ssp1",
@@ -802,18 +858,7 @@ struct snd_soc_dai pxa_ssp_dai[] = {
802 .rates = PXA_SSP_RATES, 858 .rates = PXA_SSP_RATES,
803 .formats = PXA_SSP_FORMATS, 859 .formats = PXA_SSP_FORMATS,
804 }, 860 },
805 .ops = { 861 .ops = &pxa_ssp_dai_ops,
806 .startup = pxa_ssp_startup,
807 .shutdown = pxa_ssp_shutdown,
808 .trigger = pxa_ssp_trigger,
809 .hw_params = pxa_ssp_hw_params,
810 .set_sysclk = pxa_ssp_set_dai_sysclk,
811 .set_clkdiv = pxa_ssp_set_dai_clkdiv,
812 .set_pll = pxa_ssp_set_dai_pll,
813 .set_fmt = pxa_ssp_set_dai_fmt,
814 .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
815 .set_tristate = pxa_ssp_set_dai_tristate,
816 },
817 }, 862 },
818 { .name = "pxa2xx-ssp2", 863 { .name = "pxa2xx-ssp2",
819 .id = 1, 864 .id = 1,
@@ -833,18 +878,7 @@ struct snd_soc_dai pxa_ssp_dai[] = {
833 .rates = PXA_SSP_RATES, 878 .rates = PXA_SSP_RATES,
834 .formats = PXA_SSP_FORMATS, 879 .formats = PXA_SSP_FORMATS,
835 }, 880 },
836 .ops = { 881 .ops = &pxa_ssp_dai_ops,
837 .startup = pxa_ssp_startup,
838 .shutdown = pxa_ssp_shutdown,
839 .trigger = pxa_ssp_trigger,
840 .hw_params = pxa_ssp_hw_params,
841 .set_sysclk = pxa_ssp_set_dai_sysclk,
842 .set_clkdiv = pxa_ssp_set_dai_clkdiv,
843 .set_pll = pxa_ssp_set_dai_pll,
844 .set_fmt = pxa_ssp_set_dai_fmt,
845 .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
846 .set_tristate = pxa_ssp_set_dai_tristate,
847 },
848 }, 882 },
849 { 883 {
850 .name = "pxa2xx-ssp3", 884 .name = "pxa2xx-ssp3",
@@ -865,18 +899,7 @@ struct snd_soc_dai pxa_ssp_dai[] = {
865 .rates = PXA_SSP_RATES, 899 .rates = PXA_SSP_RATES,
866 .formats = PXA_SSP_FORMATS, 900 .formats = PXA_SSP_FORMATS,
867 }, 901 },
868 .ops = { 902 .ops = &pxa_ssp_dai_ops,
869 .startup = pxa_ssp_startup,
870 .shutdown = pxa_ssp_shutdown,
871 .trigger = pxa_ssp_trigger,
872 .hw_params = pxa_ssp_hw_params,
873 .set_sysclk = pxa_ssp_set_dai_sysclk,
874 .set_clkdiv = pxa_ssp_set_dai_clkdiv,
875 .set_pll = pxa_ssp_set_dai_pll,
876 .set_fmt = pxa_ssp_set_dai_fmt,
877 .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
878 .set_tristate = pxa_ssp_set_dai_tristate,
879 },
880 }, 903 },
881 { 904 {
882 .name = "pxa2xx-ssp4", 905 .name = "pxa2xx-ssp4",
@@ -897,18 +920,7 @@ struct snd_soc_dai pxa_ssp_dai[] = {
897 .rates = PXA_SSP_RATES, 920 .rates = PXA_SSP_RATES,
898 .formats = PXA_SSP_FORMATS, 921 .formats = PXA_SSP_FORMATS,
899 }, 922 },
900 .ops = { 923 .ops = &pxa_ssp_dai_ops,
901 .startup = pxa_ssp_startup,
902 .shutdown = pxa_ssp_shutdown,
903 .trigger = pxa_ssp_trigger,
904 .hw_params = pxa_ssp_hw_params,
905 .set_sysclk = pxa_ssp_set_dai_sysclk,
906 .set_clkdiv = pxa_ssp_set_dai_clkdiv,
907 .set_pll = pxa_ssp_set_dai_pll,
908 .set_fmt = pxa_ssp_set_dai_fmt,
909 .set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
910 .set_tristate = pxa_ssp_set_dai_tristate,
911 },
912 }, 924 },
913}; 925};
914EXPORT_SYMBOL_GPL(pxa_ssp_dai); 926EXPORT_SYMBOL_GPL(pxa_ssp_dai);
diff --git a/sound/soc/pxa/pxa2xx-ac97.c b/sound/soc/pxa/pxa2xx-ac97.c
index 812c2b4d3e07..01c21c6cdbbc 100644
--- a/sound/soc/pxa/pxa2xx-ac97.c
+++ b/sound/soc/pxa/pxa2xx-ac97.c
@@ -106,13 +106,13 @@ static int pxa2xx_ac97_resume(struct snd_soc_dai *dai)
106static int pxa2xx_ac97_probe(struct platform_device *pdev, 106static int pxa2xx_ac97_probe(struct platform_device *pdev,
107 struct snd_soc_dai *dai) 107 struct snd_soc_dai *dai)
108{ 108{
109 return pxa2xx_ac97_hw_probe(pdev); 109 return pxa2xx_ac97_hw_probe(to_platform_device(dai->dev));
110} 110}
111 111
112static void pxa2xx_ac97_remove(struct platform_device *pdev, 112static void pxa2xx_ac97_remove(struct platform_device *pdev,
113 struct snd_soc_dai *dai) 113 struct snd_soc_dai *dai)
114{ 114{
115 pxa2xx_ac97_hw_remove(pdev); 115 pxa2xx_ac97_hw_remove(to_platform_device(dai->dev));
116} 116}
117 117
118static int pxa2xx_ac97_hw_params(struct snd_pcm_substream *substream, 118static int pxa2xx_ac97_hw_params(struct snd_pcm_substream *substream,
@@ -164,6 +164,18 @@ static int pxa2xx_ac97_hw_mic_params(struct snd_pcm_substream *substream,
164 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \ 164 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
165 SNDRV_PCM_RATE_48000) 165 SNDRV_PCM_RATE_48000)
166 166
167static struct snd_soc_dai_ops pxa_ac97_hifi_dai_ops = {
168 .hw_params = pxa2xx_ac97_hw_params,
169};
170
171static struct snd_soc_dai_ops pxa_ac97_aux_dai_ops = {
172 .hw_params = pxa2xx_ac97_hw_aux_params,
173};
174
175static struct snd_soc_dai_ops pxa_ac97_mic_dai_ops = {
176 .hw_params = pxa2xx_ac97_hw_mic_params,
177};
178
167/* 179/*
168 * There is only 1 physical AC97 interface for pxa2xx, but it 180 * There is only 1 physical AC97 interface for pxa2xx, but it
169 * has extra fifo's that can be used for aux DACs and ADCs. 181 * has extra fifo's that can be used for aux DACs and ADCs.
@@ -189,8 +201,7 @@ struct snd_soc_dai pxa_ac97_dai[] = {
189 .channels_max = 2, 201 .channels_max = 2,
190 .rates = PXA2XX_AC97_RATES, 202 .rates = PXA2XX_AC97_RATES,
191 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 203 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
192 .ops = { 204 .ops = &pxa_ac97_hifi_dai_ops,
193 .hw_params = pxa2xx_ac97_hw_params,},
194}, 205},
195{ 206{
196 .name = "pxa2xx-ac97-aux", 207 .name = "pxa2xx-ac97-aux",
@@ -208,8 +219,7 @@ struct snd_soc_dai pxa_ac97_dai[] = {
208 .channels_max = 1, 219 .channels_max = 1,
209 .rates = PXA2XX_AC97_RATES, 220 .rates = PXA2XX_AC97_RATES,
210 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 221 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
211 .ops = { 222 .ops = &pxa_ac97_aux_dai_ops,
212 .hw_params = pxa2xx_ac97_hw_aux_params,},
213}, 223},
214{ 224{
215 .name = "pxa2xx-ac97-mic", 225 .name = "pxa2xx-ac97-mic",
@@ -221,23 +231,52 @@ struct snd_soc_dai pxa_ac97_dai[] = {
221 .channels_max = 1, 231 .channels_max = 1,
222 .rates = PXA2XX_AC97_RATES, 232 .rates = PXA2XX_AC97_RATES,
223 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 233 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
224 .ops = { 234 .ops = &pxa_ac97_mic_dai_ops,
225 .hw_params = pxa2xx_ac97_hw_mic_params,},
226}, 235},
227}; 236};
228 237
229EXPORT_SYMBOL_GPL(pxa_ac97_dai); 238EXPORT_SYMBOL_GPL(pxa_ac97_dai);
230EXPORT_SYMBOL_GPL(soc_ac97_ops); 239EXPORT_SYMBOL_GPL(soc_ac97_ops);
231 240
232static int __init pxa_ac97_init(void) 241static int __devinit pxa2xx_ac97_dev_probe(struct platform_device *pdev)
233{ 242{
243 int i;
244
245 for (i = 0; i < ARRAY_SIZE(pxa_ac97_dai); i++)
246 pxa_ac97_dai[i].dev = &pdev->dev;
247
248 /* Punt most of the init to the SoC probe; we may need the machine
249 * driver to do interesting things with the clocking to get us up
250 * and running.
251 */
234 return snd_soc_register_dais(pxa_ac97_dai, ARRAY_SIZE(pxa_ac97_dai)); 252 return snd_soc_register_dais(pxa_ac97_dai, ARRAY_SIZE(pxa_ac97_dai));
235} 253}
254
255static int __devexit pxa2xx_ac97_dev_remove(struct platform_device *pdev)
256{
257 snd_soc_unregister_dais(pxa_ac97_dai, ARRAY_SIZE(pxa_ac97_dai));
258
259 return 0;
260}
261
262static struct platform_driver pxa2xx_ac97_driver = {
263 .probe = pxa2xx_ac97_dev_probe,
264 .remove = __devexit_p(pxa2xx_ac97_dev_remove),
265 .driver = {
266 .name = "pxa2xx-ac97",
267 .owner = THIS_MODULE,
268 },
269};
270
271static int __init pxa_ac97_init(void)
272{
273 return platform_driver_register(&pxa2xx_ac97_driver);
274}
236module_init(pxa_ac97_init); 275module_init(pxa_ac97_init);
237 276
238static void __exit pxa_ac97_exit(void) 277static void __exit pxa_ac97_exit(void)
239{ 278{
240 snd_soc_unregister_dais(pxa_ac97_dai, ARRAY_SIZE(pxa_ac97_dai)); 279 platform_driver_unregister(&pxa2xx_ac97_driver);
241} 280}
242module_exit(pxa_ac97_exit); 281module_exit(pxa_ac97_exit);
243 282
diff --git a/sound/soc/pxa/pxa2xx-i2s.c b/sound/soc/pxa/pxa2xx-i2s.c
index 517991fb1099..e6c24408c5f9 100644
--- a/sound/soc/pxa/pxa2xx-i2s.c
+++ b/sound/soc/pxa/pxa2xx-i2s.c
@@ -25,20 +25,11 @@
25 25
26#include <mach/hardware.h> 26#include <mach/hardware.h>
27#include <mach/pxa-regs.h> 27#include <mach/pxa-regs.h>
28#include <mach/pxa2xx-gpio.h>
29#include <mach/audio.h> 28#include <mach/audio.h>
30 29
31#include "pxa2xx-pcm.h" 30#include "pxa2xx-pcm.h"
32#include "pxa2xx-i2s.h" 31#include "pxa2xx-i2s.h"
33 32
34struct pxa2xx_gpio {
35 u32 sys;
36 u32 rx;
37 u32 tx;
38 u32 clk;
39 u32 frm;
40};
41
42/* 33/*
43 * I2S Controller Register and Bit Definitions 34 * I2S Controller Register and Bit Definitions
44 */ 35 */
@@ -106,21 +97,6 @@ static struct pxa2xx_pcm_dma_params pxa2xx_i2s_pcm_stereo_in = {
106 DCMD_BURST32 | DCMD_WIDTH4, 97 DCMD_BURST32 | DCMD_WIDTH4,
107}; 98};
108 99
109static struct pxa2xx_gpio gpio_bus[] = {
110 { /* I2S SoC Slave */
111 .rx = GPIO29_SDATA_IN_I2S_MD,
112 .tx = GPIO30_SDATA_OUT_I2S_MD,
113 .clk = GPIO28_BITCLK_IN_I2S_MD,
114 .frm = GPIO31_SYNC_I2S_MD,
115 },
116 { /* I2S SoC Master */
117 .rx = GPIO29_SDATA_IN_I2S_MD,
118 .tx = GPIO30_SDATA_OUT_I2S_MD,
119 .clk = GPIO28_BITCLK_OUT_I2S_MD,
120 .frm = GPIO31_SYNC_I2S_MD,
121 },
122};
123
124static int pxa2xx_i2s_startup(struct snd_pcm_substream *substream, 100static int pxa2xx_i2s_startup(struct snd_pcm_substream *substream,
125 struct snd_soc_dai *dai) 101 struct snd_soc_dai *dai)
126{ 102{
@@ -181,9 +157,6 @@ static int pxa2xx_i2s_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
181 if (clk_id != PXA2XX_I2S_SYSCLK) 157 if (clk_id != PXA2XX_I2S_SYSCLK)
182 return -ENODEV; 158 return -ENODEV;
183 159
184 if (pxa_i2s.master && dir == SND_SOC_CLOCK_OUT)
185 pxa_gpio_mode(gpio_bus[pxa_i2s.master].sys);
186
187 return 0; 160 return 0;
188} 161}
189 162
@@ -194,10 +167,6 @@ static int pxa2xx_i2s_hw_params(struct snd_pcm_substream *substream,
194 struct snd_soc_pcm_runtime *rtd = substream->private_data; 167 struct snd_soc_pcm_runtime *rtd = substream->private_data;
195 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; 168 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
196 169
197 pxa_gpio_mode(gpio_bus[pxa_i2s.master].rx);
198 pxa_gpio_mode(gpio_bus[pxa_i2s.master].tx);
199 pxa_gpio_mode(gpio_bus[pxa_i2s.master].frm);
200 pxa_gpio_mode(gpio_bus[pxa_i2s.master].clk);
201 BUG_ON(IS_ERR(clk_i2s)); 170 BUG_ON(IS_ERR(clk_i2s));
202 clk_enable(clk_i2s); 171 clk_enable(clk_i2s);
203 pxa_i2s_wait(); 172 pxa_i2s_wait();
@@ -335,6 +304,15 @@ static int pxa2xx_i2s_resume(struct snd_soc_dai *dai)
335 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \ 304 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
336 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000) 305 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000)
337 306
307static struct snd_soc_dai_ops pxa_i2s_dai_ops = {
308 .startup = pxa2xx_i2s_startup,
309 .shutdown = pxa2xx_i2s_shutdown,
310 .trigger = pxa2xx_i2s_trigger,
311 .hw_params = pxa2xx_i2s_hw_params,
312 .set_fmt = pxa2xx_i2s_set_dai_fmt,
313 .set_sysclk = pxa2xx_i2s_set_dai_sysclk,
314};
315
338struct snd_soc_dai pxa_i2s_dai = { 316struct snd_soc_dai pxa_i2s_dai = {
339 .name = "pxa2xx-i2s", 317 .name = "pxa2xx-i2s",
340 .id = 0, 318 .id = 0,
@@ -350,14 +328,7 @@ struct snd_soc_dai pxa_i2s_dai = {
350 .channels_max = 2, 328 .channels_max = 2,
351 .rates = PXA2XX_I2S_RATES, 329 .rates = PXA2XX_I2S_RATES,
352 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 330 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
353 .ops = { 331 .ops = &pxa_i2s_dai_ops,
354 .startup = pxa2xx_i2s_startup,
355 .shutdown = pxa2xx_i2s_shutdown,
356 .trigger = pxa2xx_i2s_trigger,
357 .hw_params = pxa2xx_i2s_hw_params,
358 .set_fmt = pxa2xx_i2s_set_dai_fmt,
359 .set_sysclk = pxa2xx_i2s_set_dai_sysclk,
360 },
361}; 332};
362 333
363EXPORT_SYMBOL_GPL(pxa_i2s_dai); 334EXPORT_SYMBOL_GPL(pxa_i2s_dai);
@@ -398,11 +369,6 @@ static struct platform_driver pxa2xx_i2s_driver = {
398 369
399static int __init pxa2xx_i2s_init(void) 370static int __init pxa2xx_i2s_init(void)
400{ 371{
401 if (cpu_is_pxa27x())
402 gpio_bus[1].sys = GPIO113_I2S_SYSCLK_MD;
403 else
404 gpio_bus[1].sys = GPIO32_SYSCLK_I2S_MD;
405
406 clk_i2s = ERR_PTR(-ENOENT); 372 clk_i2s = ERR_PTR(-ENOENT);
407 return platform_driver_register(&pxa2xx_i2s_driver); 373 return platform_driver_register(&pxa2xx_i2s_driver);
408} 374}
diff --git a/sound/soc/pxa/spitz.c b/sound/soc/pxa/spitz.c
index a3b9e6bdf979..6ca9f53080c6 100644
--- a/sound/soc/pxa/spitz.c
+++ b/sound/soc/pxa/spitz.c
@@ -109,7 +109,7 @@ static void spitz_ext_control(struct snd_soc_codec *codec)
109static int spitz_startup(struct snd_pcm_substream *substream) 109static int spitz_startup(struct snd_pcm_substream *substream)
110{ 110{
111 struct snd_soc_pcm_runtime *rtd = substream->private_data; 111 struct snd_soc_pcm_runtime *rtd = substream->private_data;
112 struct snd_soc_codec *codec = rtd->socdev->codec; 112 struct snd_soc_codec *codec = rtd->socdev->card->codec;
113 113
114 /* check the jack status at stream startup */ 114 /* check the jack status at stream startup */
115 spitz_ext_control(codec); 115 spitz_ext_control(codec);
@@ -278,7 +278,7 @@ static const struct snd_kcontrol_new wm8750_spitz_controls[] = {
278 */ 278 */
279static int spitz_wm8750_init(struct snd_soc_codec *codec) 279static int spitz_wm8750_init(struct snd_soc_codec *codec)
280{ 280{
281 int i, err; 281 int err;
282 282
283 /* NC codec pins */ 283 /* NC codec pins */
284 snd_soc_dapm_nc_pin(codec, "RINPUT1"); 284 snd_soc_dapm_nc_pin(codec, "RINPUT1");
@@ -290,12 +290,10 @@ static int spitz_wm8750_init(struct snd_soc_codec *codec)
290 snd_soc_dapm_nc_pin(codec, "MONO1"); 290 snd_soc_dapm_nc_pin(codec, "MONO1");
291 291
292 /* Add spitz specific controls */ 292 /* Add spitz specific controls */
293 for (i = 0; i < ARRAY_SIZE(wm8750_spitz_controls); i++) { 293 err = snd_soc_add_controls(codec, wm8750_spitz_controls,
294 err = snd_ctl_add(codec->card, 294 ARRAY_SIZE(wm8750_spitz_controls));
295 snd_soc_cnew(&wm8750_spitz_controls[i], codec, NULL)); 295 if (err < 0)
296 if (err < 0) 296 return err;
297 return err;
298 }
299 297
300 /* Add spitz specific widgets */ 298 /* Add spitz specific widgets */
301 snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets, 299 snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets,
diff --git a/sound/soc/pxa/tosa.c b/sound/soc/pxa/tosa.c
index c77194f74c9b..fc781374b1bf 100644
--- a/sound/soc/pxa/tosa.c
+++ b/sound/soc/pxa/tosa.c
@@ -82,7 +82,7 @@ static void tosa_ext_control(struct snd_soc_codec *codec)
82static int tosa_startup(struct snd_pcm_substream *substream) 82static int tosa_startup(struct snd_pcm_substream *substream)
83{ 83{
84 struct snd_soc_pcm_runtime *rtd = substream->private_data; 84 struct snd_soc_pcm_runtime *rtd = substream->private_data;
85 struct snd_soc_codec *codec = rtd->socdev->codec; 85 struct snd_soc_codec *codec = rtd->socdev->card->codec;
86 86
87 /* check the jack status at stream startup */ 87 /* check the jack status at stream startup */
88 tosa_ext_control(codec); 88 tosa_ext_control(codec);
@@ -188,18 +188,16 @@ static const struct snd_kcontrol_new tosa_controls[] = {
188 188
189static int tosa_ac97_init(struct snd_soc_codec *codec) 189static int tosa_ac97_init(struct snd_soc_codec *codec)
190{ 190{
191 int i, err; 191 int err;
192 192
193 snd_soc_dapm_nc_pin(codec, "OUT3"); 193 snd_soc_dapm_nc_pin(codec, "OUT3");
194 snd_soc_dapm_nc_pin(codec, "MONOOUT"); 194 snd_soc_dapm_nc_pin(codec, "MONOOUT");
195 195
196 /* add tosa specific controls */ 196 /* add tosa specific controls */
197 for (i = 0; i < ARRAY_SIZE(tosa_controls); i++) { 197 err = snd_soc_add_controls(codec, tosa_controls,
198 err = snd_ctl_add(codec->card, 198 ARRAY_SIZE(tosa_controls));
199 snd_soc_cnew(&tosa_controls[i],codec, NULL)); 199 if (err < 0)
200 if (err < 0) 200 return err;
201 return err;
202 }
203 201
204 /* add tosa specific widgets */ 202 /* add tosa specific widgets */
205 snd_soc_dapm_new_controls(codec, tosa_dapm_widgets, 203 snd_soc_dapm_new_controls(codec, tosa_dapm_widgets,
diff --git a/sound/soc/pxa/zylonite.c b/sound/soc/pxa/zylonite.c
index f8e9ecd589d3..9a386b4c4ed1 100644
--- a/sound/soc/pxa/zylonite.c
+++ b/sound/soc/pxa/zylonite.c
@@ -14,6 +14,7 @@
14#include <linux/module.h> 14#include <linux/module.h>
15#include <linux/moduleparam.h> 15#include <linux/moduleparam.h>
16#include <linux/device.h> 16#include <linux/device.h>
17#include <linux/clk.h>
17#include <linux/i2c.h> 18#include <linux/i2c.h>
18#include <sound/core.h> 19#include <sound/core.h>
19#include <sound/pcm.h> 20#include <sound/pcm.h>
@@ -26,6 +27,17 @@
26#include "pxa2xx-ac97.h" 27#include "pxa2xx-ac97.h"
27#include "pxa-ssp.h" 28#include "pxa-ssp.h"
28 29
30/*
31 * There is a physical switch SW15 on the board which changes the MCLK
32 * for the WM9713 between the standard AC97 master clock and the
33 * output of the CLK_POUT signal from the PXA.
34 */
35static int clk_pout;
36module_param(clk_pout, int, 0);
37MODULE_PARM_DESC(clk_pout, "Use CLK_POUT as WM9713 MCLK (SW15 on board).");
38
39static struct clk *pout;
40
29static struct snd_soc_card zylonite; 41static struct snd_soc_card zylonite;
30 42
31static const struct snd_soc_dapm_widget zylonite_dapm_widgets[] = { 43static const struct snd_soc_dapm_widget zylonite_dapm_widgets[] = {
@@ -61,10 +73,8 @@ static const struct snd_soc_dapm_route audio_map[] = {
61 73
62static int zylonite_wm9713_init(struct snd_soc_codec *codec) 74static int zylonite_wm9713_init(struct snd_soc_codec *codec)
63{ 75{
64 /* Currently we only support use of the AC97 clock here. If 76 if (clk_pout)
65 * CLK_POUT is selected by SW15 then the clock API will need 77 snd_soc_dai_set_pll(&codec->dai[0], 0, clk_get_rate(pout), 0);
66 * to be used to request and enable it here.
67 */
68 78
69 snd_soc_dapm_new_controls(codec, zylonite_dapm_widgets, 79 snd_soc_dapm_new_controls(codec, zylonite_dapm_widgets,
70 ARRAY_SIZE(zylonite_dapm_widgets)); 80 ARRAY_SIZE(zylonite_dapm_widgets));
@@ -86,40 +96,35 @@ static int zylonite_voice_hw_params(struct snd_pcm_substream *substream,
86 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; 96 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
87 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai; 97 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
88 unsigned int pll_out = 0; 98 unsigned int pll_out = 0;
89 unsigned int acds = 0;
90 unsigned int wm9713_div = 0; 99 unsigned int wm9713_div = 0;
91 int ret = 0; 100 int ret = 0;
101 int rate = params_rate(params);
102 int width = snd_pcm_format_physical_width(params_format(params));
92 103
93 switch (params_rate(params)) { 104 /* Only support ratios that we can generate neatly from the AC97
105 * based master clock - in particular, this excludes 44.1kHz.
106 * In most applications the voice DAC will be used for telephony
107 * data so multiples of 8kHz will be the common case.
108 */
109 switch (rate) {
94 case 8000: 110 case 8000:
95 wm9713_div = 12; 111 wm9713_div = 12;
96 pll_out = 2048000;
97 break; 112 break;
98 case 16000: 113 case 16000:
99 wm9713_div = 6; 114 wm9713_div = 6;
100 pll_out = 4096000;
101 break; 115 break;
102 case 48000: 116 case 48000:
103 default:
104 wm9713_div = 2; 117 wm9713_div = 2;
105 pll_out = 12288000;
106 acds = 1;
107 break; 118 break;
119 default:
120 /* Don't support OSS emulation */
121 return -EINVAL;
108 } 122 }
109 123
110 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | 124 /* Add 1 to the width for the leading clock cycle */
111 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS); 125 pll_out = rate * (width + 1) * 8;
112 if (ret < 0)
113 return ret;
114
115 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
116 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
117 if (ret < 0)
118 return ret;
119 126
120 ret = snd_soc_dai_set_tdm_slot(cpu_dai, 127 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0, 1);
121 params_channels(params),
122 params_channels(params));
123 if (ret < 0) 128 if (ret < 0)
124 return ret; 129 return ret;
125 130
@@ -127,19 +132,22 @@ static int zylonite_voice_hw_params(struct snd_pcm_substream *substream,
127 if (ret < 0) 132 if (ret < 0)
128 return ret; 133 return ret;
129 134
130 ret = snd_soc_dai_set_clkdiv(cpu_dai, PXA_SSP_AUDIO_DIV_ACDS, acds); 135 if (clk_pout)
136 ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_PLL_DIV,
137 WM9713_PCMDIV(wm9713_div));
138 else
139 ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_DIV,
140 WM9713_PCMDIV(wm9713_div));
131 if (ret < 0) 141 if (ret < 0)
132 return ret; 142 return ret;
133 143
134 ret = snd_soc_dai_set_sysclk(cpu_dai, PXA_SSP_CLK_AUDIO, 0, 1); 144 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
145 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
135 if (ret < 0) 146 if (ret < 0)
136 return ret; 147 return ret;
137 148
138 /* Note that if the PLL is in use the WM9713_PCMCLK_PLL_DIV needs 149 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
139 * to be set instead. 150 SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBS_CFS);
140 */
141 ret = snd_soc_dai_set_clkdiv(codec_dai, WM9713_PCMCLK_DIV,
142 WM9713_PCMDIV(wm9713_div));
143 if (ret < 0) 151 if (ret < 0)
144 return ret; 152 return ret;
145 153
@@ -173,8 +181,72 @@ static struct snd_soc_dai_link zylonite_dai[] = {
173}, 181},
174}; 182};
175 183
184static int zylonite_probe(struct platform_device *pdev)
185{
186 int ret;
187
188 if (clk_pout) {
189 pout = clk_get(NULL, "CLK_POUT");
190 if (IS_ERR(pout)) {
191 dev_err(&pdev->dev, "Unable to obtain CLK_POUT: %ld\n",
192 PTR_ERR(pout));
193 return PTR_ERR(pout);
194 }
195
196 ret = clk_enable(pout);
197 if (ret != 0) {
198 dev_err(&pdev->dev, "Unable to enable CLK_POUT: %d\n",
199 ret);
200 clk_put(pout);
201 return ret;
202 }
203
204 dev_dbg(&pdev->dev, "MCLK enabled at %luHz\n",
205 clk_get_rate(pout));
206 }
207
208 return 0;
209}
210
211static int zylonite_remove(struct platform_device *pdev)
212{
213 if (clk_pout) {
214 clk_disable(pout);
215 clk_put(pout);
216 }
217
218 return 0;
219}
220
221static int zylonite_suspend_post(struct platform_device *pdev,
222 pm_message_t state)
223{
224 if (clk_pout)
225 clk_disable(pout);
226
227 return 0;
228}
229
230static int zylonite_resume_pre(struct platform_device *pdev)
231{
232 int ret = 0;
233
234 if (clk_pout) {
235 ret = clk_enable(pout);
236 if (ret != 0)
237 dev_err(&pdev->dev, "Unable to enable CLK_POUT: %d\n",
238 ret);
239 }
240
241 return ret;
242}
243
176static struct snd_soc_card zylonite = { 244static struct snd_soc_card zylonite = {
177 .name = "Zylonite", 245 .name = "Zylonite",
246 .probe = &zylonite_probe,
247 .remove = &zylonite_remove,
248 .suspend_post = &zylonite_suspend_post,
249 .resume_pre = &zylonite_resume_pre,
178 .platform = &pxa2xx_soc_platform, 250 .platform = &pxa2xx_soc_platform,
179 .dai_link = zylonite_dai, 251 .dai_link = zylonite_dai,
180 .num_links = ARRAY_SIZE(zylonite_dai), 252 .num_links = ARRAY_SIZE(zylonite_dai),
diff --git a/sound/soc/s3c24xx/Kconfig b/sound/soc/s3c24xx/Kconfig
index fcd03acf10f6..2f3a21eee051 100644
--- a/sound/soc/s3c24xx/Kconfig
+++ b/sound/soc/s3c24xx/Kconfig
@@ -1,19 +1,31 @@
1config SND_S3C24XX_SOC 1config SND_S3C24XX_SOC
2 tristate "SoC Audio for the Samsung S3C24XX chips" 2 tristate "SoC Audio for the Samsung S3CXXXX chips"
3 depends on ARCH_S3C2410 3 depends on ARCH_S3C2410 || ARCH_S3C64XX
4 help 4 help
5 Say Y or M if you want to add support for codecs attached to 5 Say Y or M if you want to add support for codecs attached to
6 the S3C24XX AC97, I2S or SSP interface. You will also need 6 the S3C24XX and S3C64XX AC97, I2S or SSP interface. You will
7 to select the audio interfaces to support below. 7 also need to select the audio interfaces to support below.
8 8
9config SND_S3C24XX_SOC_I2S 9config SND_S3C24XX_SOC_I2S
10 tristate 10 tristate
11 select S3C2410_DMA
12
13config SND_S3C_I2SV2_SOC
14 tristate
11 15
12config SND_S3C2412_SOC_I2S 16config SND_S3C2412_SOC_I2S
13 tristate 17 tristate
18 select SND_S3C_I2SV2_SOC
19 select S3C2410_DMA
20
21config SND_S3C64XX_SOC_I2S
22 tristate
23 select SND_S3C_I2SV2_SOC
24 select S3C64XX_DMA
14 25
15config SND_S3C2443_SOC_AC97 26config SND_S3C2443_SOC_AC97
16 tristate 27 tristate
28 select S3C2410_DMA
17 select AC97_BUS 29 select AC97_BUS
18 select SND_SOC_AC97_BUS 30 select SND_SOC_AC97_BUS
19 31
@@ -26,6 +38,14 @@ config SND_S3C24XX_SOC_NEO1973_WM8753
26 Say Y if you want to add support for SoC audio on smdk2440 38 Say Y if you want to add support for SoC audio on smdk2440
27 with the WM8753. 39 with the WM8753.
28 40
41config SND_S3C24XX_SOC_JIVE_WM8750
42 tristate "SoC I2S Audio support for Jive"
43 depends on SND_S3C24XX_SOC && MACH_JIVE
44 select SND_SOC_WM8750
45 select SND_S3C2412_SOC_I2S
46 help
47 Sat Y if you want to add support for SoC audio on the Jive.
48
29config SND_S3C24XX_SOC_SMDK2443_WM9710 49config SND_S3C24XX_SOC_SMDK2443_WM9710
30 tristate "SoC AC97 Audio support for SMDK2443 - WM9710" 50 tristate "SoC AC97 Audio support for SMDK2443 - WM9710"
31 depends on SND_S3C24XX_SOC && MACH_SMDK2443 51 depends on SND_S3C24XX_SOC && MACH_SMDK2443
@@ -48,4 +68,5 @@ config SND_S3C24XX_SOC_S3C24XX_UDA134X
48 tristate "SoC I2S Audio support UDA134X wired to a S3C24XX" 68 tristate "SoC I2S Audio support UDA134X wired to a S3C24XX"
49 depends on SND_S3C24XX_SOC 69 depends on SND_S3C24XX_SOC
50 select SND_S3C24XX_SOC_I2S 70 select SND_S3C24XX_SOC_I2S
71 select SND_SOC_L3
51 select SND_SOC_UDA134X 72 select SND_SOC_UDA134X
diff --git a/sound/soc/s3c24xx/Makefile b/sound/soc/s3c24xx/Makefile
index 96b3f3f617d4..07a93a2ebe5f 100644
--- a/sound/soc/s3c24xx/Makefile
+++ b/sound/soc/s3c24xx/Makefile
@@ -2,19 +2,25 @@
2snd-soc-s3c24xx-objs := s3c24xx-pcm.o 2snd-soc-s3c24xx-objs := s3c24xx-pcm.o
3snd-soc-s3c24xx-i2s-objs := s3c24xx-i2s.o 3snd-soc-s3c24xx-i2s-objs := s3c24xx-i2s.o
4snd-soc-s3c2412-i2s-objs := s3c2412-i2s.o 4snd-soc-s3c2412-i2s-objs := s3c2412-i2s.o
5snd-soc-s3c64xx-i2s-objs := s3c64xx-i2s.o
5snd-soc-s3c2443-ac97-objs := s3c2443-ac97.o 6snd-soc-s3c2443-ac97-objs := s3c2443-ac97.o
7snd-soc-s3c-i2s-v2-objs := s3c-i2s-v2.o
6 8
7obj-$(CONFIG_SND_S3C24XX_SOC) += snd-soc-s3c24xx.o 9obj-$(CONFIG_SND_S3C24XX_SOC) += snd-soc-s3c24xx.o
8obj-$(CONFIG_SND_S3C24XX_SOC_I2S) += snd-soc-s3c24xx-i2s.o 10obj-$(CONFIG_SND_S3C24XX_SOC_I2S) += snd-soc-s3c24xx-i2s.o
9obj-$(CONFIG_SND_S3C2443_SOC_AC97) += snd-soc-s3c2443-ac97.o 11obj-$(CONFIG_SND_S3C2443_SOC_AC97) += snd-soc-s3c2443-ac97.o
10obj-$(CONFIG_SND_S3C2412_SOC_I2S) += snd-soc-s3c2412-i2s.o 12obj-$(CONFIG_SND_S3C2412_SOC_I2S) += snd-soc-s3c2412-i2s.o
13obj-$(CONFIG_SND_S3C64XX_SOC_I2S) += snd-soc-s3c64xx-i2s.o
14obj-$(CONFIG_SND_S3C_I2SV2_SOC) += snd-soc-s3c-i2s-v2.o
11 15
12# S3C24XX Machine Support 16# S3C24XX Machine Support
17snd-soc-jive-wm8750-objs := jive_wm8750.o
13snd-soc-neo1973-wm8753-objs := neo1973_wm8753.o 18snd-soc-neo1973-wm8753-objs := neo1973_wm8753.o
14snd-soc-smdk2443-wm9710-objs := smdk2443_wm9710.o 19snd-soc-smdk2443-wm9710-objs := smdk2443_wm9710.o
15snd-soc-ln2440sbc-alc650-objs := ln2440sbc_alc650.o 20snd-soc-ln2440sbc-alc650-objs := ln2440sbc_alc650.o
16snd-soc-s3c24xx-uda134x-objs := s3c24xx_uda134x.o 21snd-soc-s3c24xx-uda134x-objs := s3c24xx_uda134x.o
17 22
23obj-$(CONFIG_SND_S3C24XX_SOC_JIVE_WM8750) += snd-soc-jive-wm8750.o
18obj-$(CONFIG_SND_S3C24XX_SOC_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o 24obj-$(CONFIG_SND_S3C24XX_SOC_NEO1973_WM8753) += snd-soc-neo1973-wm8753.o
19obj-$(CONFIG_SND_S3C24XX_SOC_SMDK2443_WM9710) += snd-soc-smdk2443-wm9710.o 25obj-$(CONFIG_SND_S3C24XX_SOC_SMDK2443_WM9710) += snd-soc-smdk2443-wm9710.o
20obj-$(CONFIG_SND_S3C24XX_SOC_LN2440SBC_ALC650) += snd-soc-ln2440sbc-alc650.o 26obj-$(CONFIG_SND_S3C24XX_SOC_LN2440SBC_ALC650) += snd-soc-ln2440sbc-alc650.o
diff --git a/sound/soc/s3c24xx/jive_wm8750.c b/sound/soc/s3c24xx/jive_wm8750.c
new file mode 100644
index 000000000000..32063790d95b
--- /dev/null
+++ b/sound/soc/s3c24xx/jive_wm8750.c
@@ -0,0 +1,201 @@
1/* sound/soc/s3c24xx/jive_wm8750.c
2 *
3 * Copyright 2007,2008 Simtec Electronics
4 *
5 * Based on sound/soc/pxa/spitz.c
6 * Copyright 2005 Wolfson Microelectronics PLC.
7 * Copyright 2005 Openedhand Ltd.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12*/
13
14#include <linux/module.h>
15#include <linux/moduleparam.h>
16#include <linux/timer.h>
17#include <linux/interrupt.h>
18#include <linux/platform_device.h>
19#include <linux/clk.h>
20
21#include <sound/core.h>
22#include <sound/pcm.h>
23#include <sound/soc.h>
24#include <sound/soc-dapm.h>
25
26#include <asm/mach-types.h>
27
28#include "s3c24xx-pcm.h"
29#include "s3c2412-i2s.h"
30
31#include "../codecs/wm8750.h"
32
33static const struct snd_soc_dapm_route audio_map[] = {
34 { "Headphone Jack", NULL, "LOUT1" },
35 { "Headphone Jack", NULL, "ROUT1" },
36 { "Internal Speaker", NULL, "LOUT2" },
37 { "Internal Speaker", NULL, "ROUT2" },
38 { "LINPUT1", NULL, "Line Input" },
39 { "RINPUT1", NULL, "Line Input" },
40};
41
42static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
43 SND_SOC_DAPM_HP("Headphone Jack", NULL),
44 SND_SOC_DAPM_SPK("Internal Speaker", NULL),
45 SND_SOC_DAPM_LINE("Line In", NULL),
46};
47
48static int jive_hw_params(struct snd_pcm_substream *substream,
49 struct snd_pcm_hw_params *params)
50{
51 struct snd_soc_pcm_runtime *rtd = substream->private_data;
52 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
53 struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
54 struct s3c_i2sv2_rate_calc div;
55 unsigned int clk = 0;
56 int ret = 0;
57
58 switch (params_rate(params)) {
59 case 8000:
60 case 16000:
61 case 48000:
62 case 96000:
63 clk = 12288000;
64 break;
65 case 11025:
66 case 22050:
67 case 44100:
68 clk = 11289600;
69 break;
70 }
71
72 s3c_i2sv2_calc_rate(&div, NULL, params_rate(params),
73 s3c2412_get_iisclk());
74
75 /* set codec DAI configuration */
76 ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
77 SND_SOC_DAIFMT_NB_NF |
78 SND_SOC_DAIFMT_CBS_CFS);
79 if (ret < 0)
80 return ret;
81
82 /* set cpu DAI configuration */
83 ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S |
84 SND_SOC_DAIFMT_NB_NF |
85 SND_SOC_DAIFMT_CBS_CFS);
86 if (ret < 0)
87 return ret;
88
89 /* set the codec system clock for DAC and ADC */
90 ret = snd_soc_dai_set_sysclk(codec_dai, WM8750_SYSCLK, clk,
91 SND_SOC_CLOCK_IN);
92 if (ret < 0)
93 return ret;
94
95 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_RCLK, div.fs_div);
96 if (ret < 0)
97 return ret;
98
99 ret = snd_soc_dai_set_clkdiv(cpu_dai, S3C2412_DIV_PRESCALER,
100 div.clk_div - 1);
101 if (ret < 0)
102 return ret;
103
104 return 0;
105}
106
107static struct snd_soc_ops jive_ops = {
108 .hw_params = jive_hw_params,
109};
110
111static int jive_wm8750_init(struct snd_soc_codec *codec)
112{
113 int err;
114
115 /* These endpoints are not being used. */
116 snd_soc_dapm_nc_pin(codec, "LINPUT2");
117 snd_soc_dapm_nc_pin(codec, "RINPUT2");
118 snd_soc_dapm_nc_pin(codec, "LINPUT3");
119 snd_soc_dapm_nc_pin(codec, "RINPUT3");
120 snd_soc_dapm_nc_pin(codec, "OUT3");
121 snd_soc_dapm_nc_pin(codec, "MONO");
122
123 /* Add jive specific widgets */
124 err = snd_soc_dapm_new_controls(codec, wm8750_dapm_widgets,
125 ARRAY_SIZE(wm8750_dapm_widgets));
126 if (err) {
127 printk(KERN_ERR "%s: failed to add widgets (%d)\n",
128 __func__, err);
129 return err;
130 }
131
132 snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
133 snd_soc_dapm_sync(codec);
134
135 return 0;
136}
137
138static struct snd_soc_dai_link jive_dai = {
139 .name = "wm8750",
140 .stream_name = "WM8750",
141 .cpu_dai = &s3c2412_i2s_dai,
142 .codec_dai = &wm8750_dai,
143 .init = jive_wm8750_init,
144 .ops = &jive_ops,
145};
146
147/* jive audio machine driver */
148static struct snd_soc_machine snd_soc_machine_jive = {
149 .name = "Jive",
150 .dai_link = &jive_dai,
151 .num_links = 1,
152};
153
154/* jive audio private data */
155static struct wm8750_setup_data jive_wm8750_setup = {
156};
157
158/* jive audio subsystem */
159static struct snd_soc_device jive_snd_devdata = {
160 .machine = &snd_soc_machine_jive,
161 .platform = &s3c24xx_soc_platform,
162 .codec_dev = &soc_codec_dev_wm8750_spi,
163 .codec_data = &jive_wm8750_setup,
164};
165
166static struct platform_device *jive_snd_device;
167
168static int __init jive_init(void)
169{
170 int ret;
171
172 if (!machine_is_jive())
173 return 0;
174
175 printk("JIVE WM8750 Audio support\n");
176
177 jive_snd_device = platform_device_alloc("soc-audio", -1);
178 if (!jive_snd_device)
179 return -ENOMEM;
180
181 platform_set_drvdata(jive_snd_device, &jive_snd_devdata);
182 jive_snd_devdata.dev = &jive_snd_device->dev;
183 ret = platform_device_add(jive_snd_device);
184
185 if (ret)
186 platform_device_put(jive_snd_device);
187
188 return ret;
189}
190
191static void __exit jive_exit(void)
192{
193 platform_device_unregister(jive_snd_device);
194}
195
196module_init(jive_init);
197module_exit(jive_exit);
198
199MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
200MODULE_DESCRIPTION("ALSA SoC Jive Audio support");
201MODULE_LICENSE("GPL");
diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c
index 45bb12e8ea44..289fadf60b10 100644
--- a/sound/soc/s3c24xx/neo1973_wm8753.c
+++ b/sound/soc/s3c24xx/neo1973_wm8753.c
@@ -29,25 +29,17 @@
29#include <mach/regs-clock.h> 29#include <mach/regs-clock.h>
30#include <mach/regs-gpio.h> 30#include <mach/regs-gpio.h>
31#include <mach/hardware.h> 31#include <mach/hardware.h>
32#include <mach/audio.h> 32#include <plat/audio.h>
33#include <linux/io.h> 33#include <linux/io.h>
34#include <mach/spi-gpio.h> 34#include <mach/spi-gpio.h>
35 35
36#include <asm/plat-s3c24xx/regs-iis.h> 36#include <plat/regs-iis.h>
37 37
38#include "../codecs/wm8753.h" 38#include "../codecs/wm8753.h"
39#include "lm4857.h" 39#include "lm4857.h"
40#include "s3c24xx-pcm.h" 40#include "s3c24xx-pcm.h"
41#include "s3c24xx-i2s.h" 41#include "s3c24xx-i2s.h"
42 42
43/* Debugging stuff */
44#define S3C24XX_SOC_NEO1973_WM8753_DEBUG 0
45#if S3C24XX_SOC_NEO1973_WM8753_DEBUG
46#define DBG(x...) printk(KERN_DEBUG "s3c24xx-soc-neo1973-wm8753: " x)
47#else
48#define DBG(x...)
49#endif
50
51/* define the scenarios */ 43/* define the scenarios */
52#define NEO_AUDIO_OFF 0 44#define NEO_AUDIO_OFF 0
53#define NEO_GSM_CALL_AUDIO_HANDSET 1 45#define NEO_GSM_CALL_AUDIO_HANDSET 1
@@ -72,7 +64,7 @@ static int neo1973_hifi_hw_params(struct snd_pcm_substream *substream,
72 int ret = 0; 64 int ret = 0;
73 unsigned long iis_clkrate; 65 unsigned long iis_clkrate;
74 66
75 DBG("Entered %s\n", __func__); 67 pr_debug("Entered %s\n", __func__);
76 68
77 iis_clkrate = s3c24xx_i2s_get_clockrate(); 69 iis_clkrate = s3c24xx_i2s_get_clockrate();
78 70
@@ -158,7 +150,7 @@ static int neo1973_hifi_hw_free(struct snd_pcm_substream *substream)
158 struct snd_soc_pcm_runtime *rtd = substream->private_data; 150 struct snd_soc_pcm_runtime *rtd = substream->private_data;
159 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; 151 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
160 152
161 DBG("Entered %s\n", __func__); 153 pr_debug("Entered %s\n", __func__);
162 154
163 /* disable the PLL */ 155 /* disable the PLL */
164 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0); 156 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL1, 0, 0);
@@ -181,7 +173,7 @@ static int neo1973_voice_hw_params(struct snd_pcm_substream *substream,
181 int ret = 0; 173 int ret = 0;
182 unsigned long iis_clkrate; 174 unsigned long iis_clkrate;
183 175
184 DBG("Entered %s\n", __func__); 176 pr_debug("Entered %s\n", __func__);
185 177
186 iis_clkrate = s3c24xx_i2s_get_clockrate(); 178 iis_clkrate = s3c24xx_i2s_get_clockrate();
187 179
@@ -224,7 +216,7 @@ static int neo1973_voice_hw_free(struct snd_pcm_substream *substream)
224 struct snd_soc_pcm_runtime *rtd = substream->private_data; 216 struct snd_soc_pcm_runtime *rtd = substream->private_data;
225 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai; 217 struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
226 218
227 DBG("Entered %s\n", __func__); 219 pr_debug("Entered %s\n", __func__);
228 220
229 /* disable the PLL */ 221 /* disable the PLL */
230 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0); 222 return snd_soc_dai_set_pll(codec_dai, WM8753_PLL2, 0, 0);
@@ -246,7 +238,7 @@ static int neo1973_get_scenario(struct snd_kcontrol *kcontrol,
246 238
247static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario) 239static int set_scenario_endpoints(struct snd_soc_codec *codec, int scenario)
248{ 240{
249 DBG("Entered %s\n", __func__); 241 pr_debug("Entered %s\n", __func__);
250 242
251 switch (neo1973_scenario) { 243 switch (neo1973_scenario) {
252 case NEO_AUDIO_OFF: 244 case NEO_AUDIO_OFF:
@@ -330,7 +322,7 @@ static int neo1973_set_scenario(struct snd_kcontrol *kcontrol,
330{ 322{
331 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol); 323 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
332 324
333 DBG("Entered %s\n", __func__); 325 pr_debug("Entered %s\n", __func__);
334 326
335 if (neo1973_scenario == ucontrol->value.integer.value[0]) 327 if (neo1973_scenario == ucontrol->value.integer.value[0])
336 return 0; 328 return 0;
@@ -344,7 +336,7 @@ static u8 lm4857_regs[4] = {0x00, 0x40, 0x80, 0xC0};
344 336
345static void lm4857_write_regs(void) 337static void lm4857_write_regs(void)
346{ 338{
347 DBG("Entered %s\n", __func__); 339 pr_debug("Entered %s\n", __func__);
348 340
349 if (i2c_master_send(i2c, lm4857_regs, 4) != 4) 341 if (i2c_master_send(i2c, lm4857_regs, 4) != 4)
350 printk(KERN_ERR "lm4857: i2c write failed\n"); 342 printk(KERN_ERR "lm4857: i2c write failed\n");
@@ -357,7 +349,7 @@ static int lm4857_get_reg(struct snd_kcontrol *kcontrol,
357 int shift = (kcontrol->private_value >> 8) & 0x0F; 349 int shift = (kcontrol->private_value >> 8) & 0x0F;
358 int mask = (kcontrol->private_value >> 16) & 0xFF; 350 int mask = (kcontrol->private_value >> 16) & 0xFF;
359 351
360 DBG("Entered %s\n", __func__); 352 pr_debug("Entered %s\n", __func__);
361 353
362 ucontrol->value.integer.value[0] = (lm4857_regs[reg] >> shift) & mask; 354 ucontrol->value.integer.value[0] = (lm4857_regs[reg] >> shift) & mask;
363 return 0; 355 return 0;
@@ -385,7 +377,7 @@ static int lm4857_get_mode(struct snd_kcontrol *kcontrol,
385{ 377{
386 u8 value = lm4857_regs[LM4857_CTRL] & 0x0F; 378 u8 value = lm4857_regs[LM4857_CTRL] & 0x0F;
387 379
388 DBG("Entered %s\n", __func__); 380 pr_debug("Entered %s\n", __func__);
389 381
390 if (value) 382 if (value)
391 value -= 5; 383 value -= 5;
@@ -399,7 +391,7 @@ static int lm4857_set_mode(struct snd_kcontrol *kcontrol,
399{ 391{
400 u8 value = ucontrol->value.integer.value[0]; 392 u8 value = ucontrol->value.integer.value[0];
401 393
402 DBG("Entered %s\n", __func__); 394 pr_debug("Entered %s\n", __func__);
403 395
404 if (value) 396 if (value)
405 value += 5; 397 value += 5;
@@ -506,9 +498,9 @@ static const struct snd_kcontrol_new wm8753_neo1973_controls[] = {
506 */ 498 */
507static int neo1973_wm8753_init(struct snd_soc_codec *codec) 499static int neo1973_wm8753_init(struct snd_soc_codec *codec)
508{ 500{
509 int i, err; 501 int err;
510 502
511 DBG("Entered %s\n", __func__); 503 pr_debug("Entered %s\n", __func__);
512 504
513 /* set up NC codec pins */ 505 /* set up NC codec pins */
514 snd_soc_dapm_nc_pin(codec, "LOUT2"); 506 snd_soc_dapm_nc_pin(codec, "LOUT2");
@@ -526,13 +518,10 @@ static int neo1973_wm8753_init(struct snd_soc_codec *codec)
526 set_scenario_endpoints(codec, NEO_AUDIO_OFF); 518 set_scenario_endpoints(codec, NEO_AUDIO_OFF);
527 519
528 /* add neo1973 specific controls */ 520 /* add neo1973 specific controls */
529 for (i = 0; i < ARRAY_SIZE(wm8753_neo1973_controls); i++) { 521 err = snd_soc_add_controls(codec, wm8753_neo1973_controls,
530 err = snd_ctl_add(codec->card, 522 ARRAY_SIZE(8753_neo1973_controls));
531 snd_soc_cnew(&wm8753_neo1973_controls[i], 523 if (err < 0)
532 codec, NULL)); 524 return err;
533 if (err < 0)
534 return err;
535 }
536 525
537 /* set up neo1973 specific audio routes */ 526 /* set up neo1973 specific audio routes */
538 err = snd_soc_dapm_add_routes(codec, dapm_routes, 527 err = snd_soc_dapm_add_routes(codec, dapm_routes,
@@ -585,21 +574,15 @@ static struct snd_soc_card neo1973 = {
585 .num_links = ARRAY_SIZE(neo1973_dai), 574 .num_links = ARRAY_SIZE(neo1973_dai),
586}; 575};
587 576
588static struct wm8753_setup_data neo1973_wm8753_setup = {
589 .i2c_bus = 0,
590 .i2c_address = 0x1a,
591};
592
593static struct snd_soc_device neo1973_snd_devdata = { 577static struct snd_soc_device neo1973_snd_devdata = {
594 .card = &neo1973, 578 .card = &neo1973,
595 .codec_dev = &soc_codec_dev_wm8753, 579 .codec_dev = &soc_codec_dev_wm8753,
596 .codec_data = &neo1973_wm8753_setup,
597}; 580};
598 581
599static int lm4857_i2c_probe(struct i2c_client *client, 582static int lm4857_i2c_probe(struct i2c_client *client,
600 const struct i2c_device_id *id) 583 const struct i2c_device_id *id)
601{ 584{
602 DBG("Entered %s\n", __func__); 585 pr_debug("Entered %s\n", __func__);
603 586
604 i2c = client; 587 i2c = client;
605 588
@@ -609,7 +592,7 @@ static int lm4857_i2c_probe(struct i2c_client *client,
609 592
610static int lm4857_i2c_remove(struct i2c_client *client) 593static int lm4857_i2c_remove(struct i2c_client *client)
611{ 594{
612 DBG("Entered %s\n", __func__); 595 pr_debug("Entered %s\n", __func__);
613 596
614 i2c = NULL; 597 i2c = NULL;
615 598
@@ -620,7 +603,7 @@ static u8 lm4857_state;
620 603
621static int lm4857_suspend(struct i2c_client *dev, pm_message_t state) 604static int lm4857_suspend(struct i2c_client *dev, pm_message_t state)
622{ 605{
623 DBG("Entered %s\n", __func__); 606 pr_debug("Entered %s\n", __func__);
624 607
625 dev_dbg(&dev->dev, "lm4857_suspend\n"); 608 dev_dbg(&dev->dev, "lm4857_suspend\n");
626 lm4857_state = lm4857_regs[LM4857_CTRL] & 0xf; 609 lm4857_state = lm4857_regs[LM4857_CTRL] & 0xf;
@@ -633,7 +616,7 @@ static int lm4857_suspend(struct i2c_client *dev, pm_message_t state)
633 616
634static int lm4857_resume(struct i2c_client *dev) 617static int lm4857_resume(struct i2c_client *dev)
635{ 618{
636 DBG("Entered %s\n", __func__); 619 pr_debug("Entered %s\n", __func__);
637 620
638 if (lm4857_state) { 621 if (lm4857_state) {
639 lm4857_regs[LM4857_CTRL] |= (lm4857_state & 0x0f); 622 lm4857_regs[LM4857_CTRL] |= (lm4857_state & 0x0f);
@@ -644,7 +627,7 @@ static int lm4857_resume(struct i2c_client *dev)
644 627
645static void lm4857_shutdown(struct i2c_client *dev) 628static void lm4857_shutdown(struct i2c_client *dev)
646{ 629{
647 DBG("Entered %s\n", __func__); 630 pr_debug("Entered %s\n", __func__);
648 631
649 dev_dbg(&dev->dev, "lm4857_shutdown\n"); 632 dev_dbg(&dev->dev, "lm4857_shutdown\n");
650 lm4857_regs[LM4857_CTRL] &= 0xf0; 633 lm4857_regs[LM4857_CTRL] &= 0xf0;
@@ -675,7 +658,7 @@ static int __init neo1973_init(void)
675{ 658{
676 int ret; 659 int ret;
677 660
678 DBG("Entered %s\n", __func__); 661 pr_debug("Entered %s\n", __func__);
679 662
680 if (!machine_is_neo1973_gta01()) { 663 if (!machine_is_neo1973_gta01()) {
681 printk(KERN_INFO 664 printk(KERN_INFO
@@ -706,7 +689,7 @@ static int __init neo1973_init(void)
706 689
707static void __exit neo1973_exit(void) 690static void __exit neo1973_exit(void)
708{ 691{
709 DBG("Entered %s\n", __func__); 692 pr_debug("Entered %s\n", __func__);
710 693
711 i2c_del_driver(&lm4857_i2c_driver); 694 i2c_del_driver(&lm4857_i2c_driver);
712 platform_device_unregister(neo1973_snd_device); 695 platform_device_unregister(neo1973_snd_device);
diff --git a/sound/soc/s3c24xx/s3c-i2s-v2.c b/sound/soc/s3c24xx/s3c-i2s-v2.c
new file mode 100644
index 000000000000..295a4c910262
--- /dev/null
+++ b/sound/soc/s3c24xx/s3c-i2s-v2.c
@@ -0,0 +1,638 @@
1/* sound/soc/s3c24xx/s3c-i2c-v2.c
2 *
3 * ALSA Soc Audio Layer - I2S core for newer Samsung SoCs.
4 *
5 * Copyright (c) 2006 Wolfson Microelectronics PLC.
6 * Graeme Gregory graeme.gregory@wolfsonmicro.com
7 * linux@wolfsonmicro.com
8 *
9 * Copyright (c) 2008, 2007, 2004-2005 Simtec Electronics
10 * http://armlinux.simtec.co.uk/
11 * Ben Dooks <ben@simtec.co.uk>
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 */
18
19#include <linux/init.h>
20#include <linux/module.h>
21#include <linux/device.h>
22#include <linux/delay.h>
23#include <linux/clk.h>
24#include <linux/kernel.h>
25#include <linux/io.h>
26
27#include <sound/core.h>
28#include <sound/pcm.h>
29#include <sound/pcm_params.h>
30#include <sound/initval.h>
31#include <sound/soc.h>
32
33#include <plat/regs-s3c2412-iis.h>
34
35#include <plat/audio.h>
36#include <mach/dma.h>
37
38#include "s3c-i2s-v2.h"
39
40#define S3C2412_I2S_DEBUG_CON 0
41
42static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
43{
44 return cpu_dai->private_data;
45}
46
47#define bit_set(v, b) (((v) & (b)) ? 1 : 0)
48
49#if S3C2412_I2S_DEBUG_CON
50static void dbg_showcon(const char *fn, u32 con)
51{
52 printk(KERN_DEBUG "%s: LRI=%d, TXFEMPT=%d, RXFEMPT=%d, TXFFULL=%d, RXFFULL=%d\n", fn,
53 bit_set(con, S3C2412_IISCON_LRINDEX),
54 bit_set(con, S3C2412_IISCON_TXFIFO_EMPTY),
55 bit_set(con, S3C2412_IISCON_RXFIFO_EMPTY),
56 bit_set(con, S3C2412_IISCON_TXFIFO_FULL),
57 bit_set(con, S3C2412_IISCON_RXFIFO_FULL));
58
59 printk(KERN_DEBUG "%s: PAUSE: TXDMA=%d, RXDMA=%d, TXCH=%d, RXCH=%d\n",
60 fn,
61 bit_set(con, S3C2412_IISCON_TXDMA_PAUSE),
62 bit_set(con, S3C2412_IISCON_RXDMA_PAUSE),
63 bit_set(con, S3C2412_IISCON_TXCH_PAUSE),
64 bit_set(con, S3C2412_IISCON_RXCH_PAUSE));
65 printk(KERN_DEBUG "%s: ACTIVE: TXDMA=%d, RXDMA=%d, IIS=%d\n", fn,
66 bit_set(con, S3C2412_IISCON_TXDMA_ACTIVE),
67 bit_set(con, S3C2412_IISCON_RXDMA_ACTIVE),
68 bit_set(con, S3C2412_IISCON_IIS_ACTIVE));
69}
70#else
71static inline void dbg_showcon(const char *fn, u32 con)
72{
73}
74#endif
75
76
77/* Turn on or off the transmission path. */
78void s3c2412_snd_txctrl(struct s3c_i2sv2_info *i2s, int on)
79{
80 void __iomem *regs = i2s->regs;
81 u32 fic, con, mod;
82
83 pr_debug("%s(%d)\n", __func__, on);
84
85 fic = readl(regs + S3C2412_IISFIC);
86 con = readl(regs + S3C2412_IISCON);
87 mod = readl(regs + S3C2412_IISMOD);
88
89 pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
90
91 if (on) {
92 con |= S3C2412_IISCON_TXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE;
93 con &= ~S3C2412_IISCON_TXDMA_PAUSE;
94 con &= ~S3C2412_IISCON_TXCH_PAUSE;
95
96 switch (mod & S3C2412_IISMOD_MODE_MASK) {
97 case S3C2412_IISMOD_MODE_TXONLY:
98 case S3C2412_IISMOD_MODE_TXRX:
99 /* do nothing, we are in the right mode */
100 break;
101
102 case S3C2412_IISMOD_MODE_RXONLY:
103 mod &= ~S3C2412_IISMOD_MODE_MASK;
104 mod |= S3C2412_IISMOD_MODE_TXRX;
105 break;
106
107 default:
108 dev_err(i2s->dev, "TXEN: Invalid MODE in IISMOD\n");
109 }
110
111 writel(con, regs + S3C2412_IISCON);
112 writel(mod, regs + S3C2412_IISMOD);
113 } else {
114 /* Note, we do not have any indication that the FIFO problems
115 * tha the S3C2410/2440 had apply here, so we should be able
116 * to disable the DMA and TX without resetting the FIFOS.
117 */
118
119 con |= S3C2412_IISCON_TXDMA_PAUSE;
120 con |= S3C2412_IISCON_TXCH_PAUSE;
121 con &= ~S3C2412_IISCON_TXDMA_ACTIVE;
122
123 switch (mod & S3C2412_IISMOD_MODE_MASK) {
124 case S3C2412_IISMOD_MODE_TXRX:
125 mod &= ~S3C2412_IISMOD_MODE_MASK;
126 mod |= S3C2412_IISMOD_MODE_RXONLY;
127 break;
128
129 case S3C2412_IISMOD_MODE_TXONLY:
130 mod &= ~S3C2412_IISMOD_MODE_MASK;
131 con &= ~S3C2412_IISCON_IIS_ACTIVE;
132 break;
133
134 default:
135 dev_err(i2s->dev, "TXDIS: Invalid MODE in IISMOD\n");
136 }
137
138 writel(mod, regs + S3C2412_IISMOD);
139 writel(con, regs + S3C2412_IISCON);
140 }
141
142 fic = readl(regs + S3C2412_IISFIC);
143 dbg_showcon(__func__, con);
144 pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
145}
146EXPORT_SYMBOL_GPL(s3c2412_snd_txctrl);
147
148void s3c2412_snd_rxctrl(struct s3c_i2sv2_info *i2s, int on)
149{
150 void __iomem *regs = i2s->regs;
151 u32 fic, con, mod;
152
153 pr_debug("%s(%d)\n", __func__, on);
154
155 fic = readl(regs + S3C2412_IISFIC);
156 con = readl(regs + S3C2412_IISCON);
157 mod = readl(regs + S3C2412_IISMOD);
158
159 pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
160
161 if (on) {
162 con |= S3C2412_IISCON_RXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE;
163 con &= ~S3C2412_IISCON_RXDMA_PAUSE;
164 con &= ~S3C2412_IISCON_RXCH_PAUSE;
165
166 switch (mod & S3C2412_IISMOD_MODE_MASK) {
167 case S3C2412_IISMOD_MODE_TXRX:
168 case S3C2412_IISMOD_MODE_RXONLY:
169 /* do nothing, we are in the right mode */
170 break;
171
172 case S3C2412_IISMOD_MODE_TXONLY:
173 mod &= ~S3C2412_IISMOD_MODE_MASK;
174 mod |= S3C2412_IISMOD_MODE_TXRX;
175 break;
176
177 default:
178 dev_err(i2s->dev, "RXEN: Invalid MODE in IISMOD\n");
179 }
180
181 writel(mod, regs + S3C2412_IISMOD);
182 writel(con, regs + S3C2412_IISCON);
183 } else {
184 /* See txctrl notes on FIFOs. */
185
186 con &= ~S3C2412_IISCON_RXDMA_ACTIVE;
187 con |= S3C2412_IISCON_RXDMA_PAUSE;
188 con |= S3C2412_IISCON_RXCH_PAUSE;
189
190 switch (mod & S3C2412_IISMOD_MODE_MASK) {
191 case S3C2412_IISMOD_MODE_RXONLY:
192 con &= ~S3C2412_IISCON_IIS_ACTIVE;
193 mod &= ~S3C2412_IISMOD_MODE_MASK;
194 break;
195
196 case S3C2412_IISMOD_MODE_TXRX:
197 mod &= ~S3C2412_IISMOD_MODE_MASK;
198 mod |= S3C2412_IISMOD_MODE_TXONLY;
199 break;
200
201 default:
202 dev_err(i2s->dev, "RXEN: Invalid MODE in IISMOD\n");
203 }
204
205 writel(con, regs + S3C2412_IISCON);
206 writel(mod, regs + S3C2412_IISMOD);
207 }
208
209 fic = readl(regs + S3C2412_IISFIC);
210 pr_debug("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
211}
212EXPORT_SYMBOL_GPL(s3c2412_snd_rxctrl);
213
214/*
215 * Wait for the LR signal to allow synchronisation to the L/R clock
216 * from the codec. May only be needed for slave mode.
217 */
218static int s3c2412_snd_lrsync(struct s3c_i2sv2_info *i2s)
219{
220 u32 iiscon;
221 unsigned long timeout = jiffies + msecs_to_jiffies(5);
222
223 pr_debug("Entered %s\n", __func__);
224
225 while (1) {
226 iiscon = readl(i2s->regs + S3C2412_IISCON);
227 if (iiscon & S3C2412_IISCON_LRINDEX)
228 break;
229
230 if (timeout < jiffies) {
231 printk(KERN_ERR "%s: timeout\n", __func__);
232 return -ETIMEDOUT;
233 }
234 }
235
236 return 0;
237}
238
239/*
240 * Set S3C2412 I2S DAI format
241 */
242static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
243 unsigned int fmt)
244{
245 struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
246 u32 iismod;
247
248 pr_debug("Entered %s\n", __func__);
249
250 iismod = readl(i2s->regs + S3C2412_IISMOD);
251 pr_debug("hw_params r: IISMOD: %x \n", iismod);
252
253#if defined(CONFIG_CPU_S3C2412) || defined(CONFIG_CPU_S3C2413)
254#define IISMOD_MASTER_MASK S3C2412_IISMOD_MASTER_MASK
255#define IISMOD_SLAVE S3C2412_IISMOD_SLAVE
256#define IISMOD_MASTER S3C2412_IISMOD_MASTER_INTERNAL
257#endif
258
259#if defined(CONFIG_PLAT_S3C64XX)
260/* From Rev1.1 datasheet, we have two master and two slave modes:
261 * IMS[11:10]:
262 * 00 = master mode, fed from PCLK
263 * 01 = master mode, fed from CLKAUDIO
264 * 10 = slave mode, using PCLK
265 * 11 = slave mode, using I2SCLK
266 */
267#define IISMOD_MASTER_MASK (1 << 11)
268#define IISMOD_SLAVE (1 << 11)
269#define IISMOD_MASTER (0x0)
270#endif
271
272 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
273 case SND_SOC_DAIFMT_CBM_CFM:
274 i2s->master = 0;
275 iismod &= ~IISMOD_MASTER_MASK;
276 iismod |= IISMOD_SLAVE;
277 break;
278 case SND_SOC_DAIFMT_CBS_CFS:
279 i2s->master = 1;
280 iismod &= ~IISMOD_MASTER_MASK;
281 iismod |= IISMOD_MASTER;
282 break;
283 default:
284 pr_debug("unknwon master/slave format\n");
285 return -EINVAL;
286 }
287
288 iismod &= ~S3C2412_IISMOD_SDF_MASK;
289
290 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
291 case SND_SOC_DAIFMT_RIGHT_J:
292 iismod |= S3C2412_IISMOD_SDF_MSB;
293 break;
294 case SND_SOC_DAIFMT_LEFT_J:
295 iismod |= S3C2412_IISMOD_SDF_LSB;
296 break;
297 case SND_SOC_DAIFMT_I2S:
298 iismod |= S3C2412_IISMOD_SDF_IIS;
299 break;
300 default:
301 pr_debug("Unknown data format\n");
302 return -EINVAL;
303 }
304
305 writel(iismod, i2s->regs + S3C2412_IISMOD);
306 pr_debug("hw_params w: IISMOD: %x \n", iismod);
307 return 0;
308}
309
310static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
311 struct snd_pcm_hw_params *params,
312 struct snd_soc_dai *socdai)
313{
314 struct snd_soc_pcm_runtime *rtd = substream->private_data;
315 struct snd_soc_dai_link *dai = rtd->dai;
316 struct s3c_i2sv2_info *i2s = to_info(dai->cpu_dai);
317 u32 iismod;
318
319 pr_debug("Entered %s\n", __func__);
320
321 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
322 dai->cpu_dai->dma_data = i2s->dma_playback;
323 else
324 dai->cpu_dai->dma_data = i2s->dma_capture;
325
326 /* Working copies of register */
327 iismod = readl(i2s->regs + S3C2412_IISMOD);
328 pr_debug("%s: r: IISMOD: %x\n", __func__, iismod);
329
330 switch (params_format(params)) {
331 case SNDRV_PCM_FORMAT_S8:
332 iismod |= S3C2412_IISMOD_8BIT;
333 break;
334 case SNDRV_PCM_FORMAT_S16_LE:
335 iismod &= ~S3C2412_IISMOD_8BIT;
336 break;
337 }
338
339 writel(iismod, i2s->regs + S3C2412_IISMOD);
340 pr_debug("%s: w: IISMOD: %x\n", __func__, iismod);
341 return 0;
342}
343
344static int s3c2412_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
345 struct snd_soc_dai *dai)
346{
347 struct snd_soc_pcm_runtime *rtd = substream->private_data;
348 struct s3c_i2sv2_info *i2s = to_info(rtd->dai->cpu_dai);
349 int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
350 unsigned long irqs;
351 int ret = 0;
352
353 pr_debug("Entered %s\n", __func__);
354
355 switch (cmd) {
356 case SNDRV_PCM_TRIGGER_START:
357 /* On start, ensure that the FIFOs are cleared and reset. */
358
359 writel(capture ? S3C2412_IISFIC_RXFLUSH : S3C2412_IISFIC_TXFLUSH,
360 i2s->regs + S3C2412_IISFIC);
361
362 /* clear again, just in case */
363 writel(0x0, i2s->regs + S3C2412_IISFIC);
364
365 case SNDRV_PCM_TRIGGER_RESUME:
366 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
367 if (!i2s->master) {
368 ret = s3c2412_snd_lrsync(i2s);
369 if (ret)
370 goto exit_err;
371 }
372
373 local_irq_save(irqs);
374
375 if (capture)
376 s3c2412_snd_rxctrl(i2s, 1);
377 else
378 s3c2412_snd_txctrl(i2s, 1);
379
380 local_irq_restore(irqs);
381 break;
382
383 case SNDRV_PCM_TRIGGER_STOP:
384 case SNDRV_PCM_TRIGGER_SUSPEND:
385 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
386 local_irq_save(irqs);
387
388 if (capture)
389 s3c2412_snd_rxctrl(i2s, 0);
390 else
391 s3c2412_snd_txctrl(i2s, 0);
392
393 local_irq_restore(irqs);
394 break;
395 default:
396 ret = -EINVAL;
397 break;
398 }
399
400exit_err:
401 return ret;
402}
403
404/*
405 * Set S3C2412 Clock dividers
406 */
407static int s3c2412_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
408 int div_id, int div)
409{
410 struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
411 u32 reg;
412
413 pr_debug("%s(%p, %d, %d)\n", __func__, cpu_dai, div_id, div);
414
415 switch (div_id) {
416 case S3C_I2SV2_DIV_BCLK:
417 reg = readl(i2s->regs + S3C2412_IISMOD);
418 reg &= ~S3C2412_IISMOD_BCLK_MASK;
419 writel(reg | div, i2s->regs + S3C2412_IISMOD);
420
421 pr_debug("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD));
422 break;
423
424 case S3C_I2SV2_DIV_RCLK:
425 if (div > 3) {
426 /* convert value to bit field */
427
428 switch (div) {
429 case 256:
430 div = S3C2412_IISMOD_RCLK_256FS;
431 break;
432
433 case 384:
434 div = S3C2412_IISMOD_RCLK_384FS;
435 break;
436
437 case 512:
438 div = S3C2412_IISMOD_RCLK_512FS;
439 break;
440
441 case 768:
442 div = S3C2412_IISMOD_RCLK_768FS;
443 break;
444
445 default:
446 return -EINVAL;
447 }
448 }
449
450 reg = readl(i2s->regs + S3C2412_IISMOD);
451 reg &= ~S3C2412_IISMOD_RCLK_MASK;
452 writel(reg | div, i2s->regs + S3C2412_IISMOD);
453 pr_debug("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD));
454 break;
455
456 case S3C_I2SV2_DIV_PRESCALER:
457 if (div >= 0) {
458 writel((div << 8) | S3C2412_IISPSR_PSREN,
459 i2s->regs + S3C2412_IISPSR);
460 } else {
461 writel(0x0, i2s->regs + S3C2412_IISPSR);
462 }
463 pr_debug("%s: PSR=%08x\n", __func__, readl(i2s->regs + S3C2412_IISPSR));
464 break;
465
466 default:
467 return -EINVAL;
468 }
469
470 return 0;
471}
472
473/* default table of all avaialable root fs divisors */
474static unsigned int iis_fs_tab[] = { 256, 512, 384, 768 };
475
476int s3c2412_iis_calc_rate(struct s3c_i2sv2_rate_calc *info,
477 unsigned int *fstab,
478 unsigned int rate, struct clk *clk)
479{
480 unsigned long clkrate = clk_get_rate(clk);
481 unsigned int div;
482 unsigned int fsclk;
483 unsigned int actual;
484 unsigned int fs;
485 unsigned int fsdiv;
486 signed int deviation = 0;
487 unsigned int best_fs = 0;
488 unsigned int best_div = 0;
489 unsigned int best_rate = 0;
490 unsigned int best_deviation = INT_MAX;
491
492 if (fstab == NULL)
493 fstab = iis_fs_tab;
494
495 for (fs = 0; fs < ARRAY_SIZE(iis_fs_tab); fs++) {
496 fsdiv = iis_fs_tab[fs];
497
498 fsclk = clkrate / fsdiv;
499 div = fsclk / rate;
500
501 if ((fsclk % rate) > (rate / 2))
502 div++;
503
504 if (div <= 1)
505 continue;
506
507 actual = clkrate / (fsdiv * div);
508 deviation = actual - rate;
509
510 printk(KERN_DEBUG "%dfs: div %d => result %d, deviation %d\n",
511 fsdiv, div, actual, deviation);
512
513 deviation = abs(deviation);
514
515 if (deviation < best_deviation) {
516 best_fs = fsdiv;
517 best_div = div;
518 best_rate = actual;
519 best_deviation = deviation;
520 }
521
522 if (deviation == 0)
523 break;
524 }
525
526 printk(KERN_DEBUG "best: fs=%d, div=%d, rate=%d\n",
527 best_fs, best_div, best_rate);
528
529 info->fs_div = best_fs;
530 info->clk_div = best_div;
531
532 return 0;
533}
534EXPORT_SYMBOL_GPL(s3c2412_iis_calc_rate);
535
536int s3c_i2sv2_probe(struct platform_device *pdev,
537 struct snd_soc_dai *dai,
538 struct s3c_i2sv2_info *i2s,
539 unsigned long base)
540{
541 struct device *dev = &pdev->dev;
542
543 i2s->dev = dev;
544
545 /* record our i2s structure for later use in the callbacks */
546 dai->private_data = i2s;
547
548 i2s->regs = ioremap(base, 0x100);
549 if (i2s->regs == NULL) {
550 dev_err(dev, "cannot ioremap registers\n");
551 return -ENXIO;
552 }
553
554 i2s->iis_pclk = clk_get(dev, "iis");
555 if (i2s->iis_pclk == NULL) {
556 dev_err(dev, "failed to get iis_clock\n");
557 iounmap(i2s->regs);
558 return -ENOENT;
559 }
560
561 clk_enable(i2s->iis_pclk);
562
563 s3c2412_snd_txctrl(i2s, 0);
564 s3c2412_snd_rxctrl(i2s, 0);
565
566 return 0;
567}
568
569EXPORT_SYMBOL_GPL(s3c_i2sv2_probe);
570
571#ifdef CONFIG_PM
572static int s3c2412_i2s_suspend(struct snd_soc_dai *dai)
573{
574 struct s3c_i2sv2_info *i2s = to_info(dai);
575 u32 iismod;
576
577 if (dai->active) {
578 i2s->suspend_iismod = readl(i2s->regs + S3C2412_IISMOD);
579 i2s->suspend_iiscon = readl(i2s->regs + S3C2412_IISCON);
580 i2s->suspend_iispsr = readl(i2s->regs + S3C2412_IISPSR);
581
582 /* some basic suspend checks */
583
584 iismod = readl(i2s->regs + S3C2412_IISMOD);
585
586 if (iismod & S3C2412_IISCON_RXDMA_ACTIVE)
587 pr_warning("%s: RXDMA active?\n", __func__);
588
589 if (iismod & S3C2412_IISCON_TXDMA_ACTIVE)
590 pr_warning("%s: TXDMA active?\n", __func__);
591
592 if (iismod & S3C2412_IISCON_IIS_ACTIVE)
593 pr_warning("%s: IIS active\n", __func__);
594 }
595
596 return 0;
597}
598
599static int s3c2412_i2s_resume(struct snd_soc_dai *dai)
600{
601 struct s3c_i2sv2_info *i2s = to_info(dai);
602
603 pr_info("dai_active %d, IISMOD %08x, IISCON %08x\n",
604 dai->active, i2s->suspend_iismod, i2s->suspend_iiscon);
605
606 if (dai->active) {
607 writel(i2s->suspend_iiscon, i2s->regs + S3C2412_IISCON);
608 writel(i2s->suspend_iismod, i2s->regs + S3C2412_IISMOD);
609 writel(i2s->suspend_iispsr, i2s->regs + S3C2412_IISPSR);
610
611 writel(S3C2412_IISFIC_RXFLUSH | S3C2412_IISFIC_TXFLUSH,
612 i2s->regs + S3C2412_IISFIC);
613
614 ndelay(250);
615 writel(0x0, i2s->regs + S3C2412_IISFIC);
616 }
617
618 return 0;
619}
620#else
621#define s3c2412_i2s_suspend NULL
622#define s3c2412_i2s_resume NULL
623#endif
624
625int s3c_i2sv2_register_dai(struct snd_soc_dai *dai)
626{
627 dai->ops.trigger = s3c2412_i2s_trigger;
628 dai->ops.hw_params = s3c2412_i2s_hw_params;
629 dai->ops.set_fmt = s3c2412_i2s_set_fmt;
630 dai->ops.set_clkdiv = s3c2412_i2s_set_clkdiv;
631
632 dai->suspend = s3c2412_i2s_suspend;
633 dai->resume = s3c2412_i2s_resume;
634
635 return snd_soc_register_dai(dai);
636}
637
638EXPORT_SYMBOL_GPL(s3c_i2sv2_register_dai);
diff --git a/sound/soc/s3c24xx/s3c-i2s-v2.h b/sound/soc/s3c24xx/s3c-i2s-v2.h
new file mode 100644
index 000000000000..f66854a77fb2
--- /dev/null
+++ b/sound/soc/s3c24xx/s3c-i2s-v2.h
@@ -0,0 +1,90 @@
1/* sound/soc/s3c24xx/s3c-i2s-v2.h
2 *
3 * ALSA Soc Audio Layer - S3C_I2SV2 I2S driver
4 *
5 * Copyright (c) 2007 Simtec Electronics
6 * http://armlinux.simtec.co.uk/
7 * Ben Dooks <ben@simtec.co.uk>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2 of the License, or (at your
12 * option) any later version.
13*/
14
15/* This code is the core support for the I2S block found in a number of
16 * Samsung SoC devices which is unofficially named I2S-V2. Currently the
17 * S3C2412 and the S3C64XX series use this block to provide 1 or 2 I2S
18 * channels via configurable GPIO.
19 */
20
21#ifndef __SND_SOC_S3C24XX_S3C_I2SV2_I2S_H
22#define __SND_SOC_S3C24XX_S3C_I2SV2_I2S_H __FILE__
23
24#define S3C_I2SV2_DIV_BCLK (1)
25#define S3C_I2SV2_DIV_RCLK (2)
26#define S3C_I2SV2_DIV_PRESCALER (3)
27
28/**
29 * struct s3c_i2sv2_info - S3C I2S-V2 information
30 * @dev: The parent device passed to use from the probe.
31 * @regs: The pointer to the device registe block.
32 * @master: True if the I2S core is the I2S bit clock master.
33 * @dma_playback: DMA information for playback channel.
34 * @dma_capture: DMA information for capture channel.
35 * @suspend_iismod: PM save for the IISMOD register.
36 * @suspend_iiscon: PM save for the IISCON register.
37 * @suspend_iispsr: PM save for the IISPSR register.
38 *
39 * This is the private codec state for the hardware associated with an
40 * I2S channel such as the register mappings and clock sources.
41 */
42struct s3c_i2sv2_info {
43 struct device *dev;
44 void __iomem *regs;
45
46 struct clk *iis_pclk;
47 struct clk *iis_cclk;
48 struct clk *iis_clk;
49
50 unsigned char master;
51
52 struct s3c24xx_pcm_dma_params *dma_playback;
53 struct s3c24xx_pcm_dma_params *dma_capture;
54
55 u32 suspend_iismod;
56 u32 suspend_iiscon;
57 u32 suspend_iispsr;
58};
59
60struct s3c_i2sv2_rate_calc {
61 unsigned int clk_div; /* for prescaler */
62 unsigned int fs_div; /* for root frame clock */
63};
64
65extern int s3c_i2sv2_iis_calc_rate(struct s3c_i2sv2_rate_calc *info,
66 unsigned int *fstab,
67 unsigned int rate, struct clk *clk);
68
69/**
70 * s3c_i2sv2_probe - probe for i2s device helper
71 * @pdev: The platform device supplied to the original probe.
72 * @dai: The ASoC DAI structure supplied to the original probe.
73 * @i2s: Our local i2s structure to fill in.
74 * @base: The base address for the registers.
75 */
76extern int s3c_i2sv2_probe(struct platform_device *pdev,
77 struct snd_soc_dai *dai,
78 struct s3c_i2sv2_info *i2s,
79 unsigned long base);
80
81/**
82 * s3c_i2sv2_register_dai - register dai with soc core
83 * @dai: The snd_soc_dai structure to register
84 *
85 * Fill in any missing fields and then register the given dai with the
86 * soc core.
87 */
88extern int s3c_i2sv2_register_dai(struct snd_soc_dai *dai);
89
90#endif /* __SND_SOC_S3C24XX_S3C_I2SV2_I2S_H */
diff --git a/sound/soc/s3c24xx/s3c2412-i2s.c b/sound/soc/s3c24xx/s3c2412-i2s.c
index f3fc0aba0aaf..1ca3cdaa8213 100644
--- a/sound/soc/s3c24xx/s3c2412-i2s.c
+++ b/sound/soc/s3c24xx/s3c2412-i2s.c
@@ -22,6 +22,7 @@
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include <linux/clk.h> 23#include <linux/clk.h>
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/io.h>
25 26
26#include <sound/core.h> 27#include <sound/core.h>
27#include <sound/pcm.h> 28#include <sound/pcm.h>
@@ -30,26 +31,16 @@
30#include <sound/soc.h> 31#include <sound/soc.h>
31#include <mach/hardware.h> 32#include <mach/hardware.h>
32 33
33#include <linux/io.h> 34#include <plat/regs-s3c2412-iis.h>
34#include <asm/dma.h>
35
36#include <asm/plat-s3c24xx/regs-s3c2412-iis.h>
37 35
38#include <mach/regs-gpio.h> 36#include <plat/regs-gpio.h>
39#include <mach/audio.h> 37#include <plat/audio.h>
40#include <mach/dma.h> 38#include <mach/dma.h>
41 39
42#include "s3c24xx-pcm.h" 40#include "s3c24xx-pcm.h"
43#include "s3c2412-i2s.h" 41#include "s3c2412-i2s.h"
44 42
45#define S3C2412_I2S_DEBUG 0 43#define S3C2412_I2S_DEBUG 0
46#define S3C2412_I2S_DEBUG_CON 0
47
48#if S3C2412_I2S_DEBUG
49#define DBG(x...) printk(KERN_INFO x)
50#else
51#define DBG(x...) do { } while (0)
52#endif
53 44
54static struct s3c2410_dma_client s3c2412_dma_client_out = { 45static struct s3c2410_dma_client s3c2412_dma_client_out = {
55 .name = "I2S PCM Stereo out" 46 .name = "I2S PCM Stereo out"
@@ -73,431 +64,7 @@ static struct s3c24xx_pcm_dma_params s3c2412_i2s_pcm_stereo_in = {
73 .dma_size = 4, 64 .dma_size = 4,
74}; 65};
75 66
76struct s3c2412_i2s_info { 67static struct s3c_i2sv2_info s3c2412_i2s;
77 struct device *dev;
78 void __iomem *regs;
79 struct clk *iis_clk;
80 struct clk *iis_pclk;
81 struct clk *iis_cclk;
82
83 u32 suspend_iismod;
84 u32 suspend_iiscon;
85 u32 suspend_iispsr;
86};
87
88static struct s3c2412_i2s_info s3c2412_i2s;
89
90#define bit_set(v, b) (((v) & (b)) ? 1 : 0)
91
92#if S3C2412_I2S_DEBUG_CON
93static void dbg_showcon(const char *fn, u32 con)
94{
95 printk(KERN_DEBUG "%s: LRI=%d, TXFEMPT=%d, RXFEMPT=%d, TXFFULL=%d, RXFFULL=%d\n", fn,
96 bit_set(con, S3C2412_IISCON_LRINDEX),
97 bit_set(con, S3C2412_IISCON_TXFIFO_EMPTY),
98 bit_set(con, S3C2412_IISCON_RXFIFO_EMPTY),
99 bit_set(con, S3C2412_IISCON_TXFIFO_FULL),
100 bit_set(con, S3C2412_IISCON_RXFIFO_FULL));
101
102 printk(KERN_DEBUG "%s: PAUSE: TXDMA=%d, RXDMA=%d, TXCH=%d, RXCH=%d\n",
103 fn,
104 bit_set(con, S3C2412_IISCON_TXDMA_PAUSE),
105 bit_set(con, S3C2412_IISCON_RXDMA_PAUSE),
106 bit_set(con, S3C2412_IISCON_TXCH_PAUSE),
107 bit_set(con, S3C2412_IISCON_RXCH_PAUSE));
108 printk(KERN_DEBUG "%s: ACTIVE: TXDMA=%d, RXDMA=%d, IIS=%d\n", fn,
109 bit_set(con, S3C2412_IISCON_TXDMA_ACTIVE),
110 bit_set(con, S3C2412_IISCON_RXDMA_ACTIVE),
111 bit_set(con, S3C2412_IISCON_IIS_ACTIVE));
112}
113#else
114static inline void dbg_showcon(const char *fn, u32 con)
115{
116}
117#endif
118
119/* Turn on or off the transmission path. */
120static void s3c2412_snd_txctrl(int on)
121{
122 struct s3c2412_i2s_info *i2s = &s3c2412_i2s;
123 void __iomem *regs = i2s->regs;
124 u32 fic, con, mod;
125
126 DBG("%s(%d)\n", __func__, on);
127
128 fic = readl(regs + S3C2412_IISFIC);
129 con = readl(regs + S3C2412_IISCON);
130 mod = readl(regs + S3C2412_IISMOD);
131
132 DBG("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
133
134 if (on) {
135 con |= S3C2412_IISCON_TXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE;
136 con &= ~S3C2412_IISCON_TXDMA_PAUSE;
137 con &= ~S3C2412_IISCON_TXCH_PAUSE;
138
139 switch (mod & S3C2412_IISMOD_MODE_MASK) {
140 case S3C2412_IISMOD_MODE_TXONLY:
141 case S3C2412_IISMOD_MODE_TXRX:
142 /* do nothing, we are in the right mode */
143 break;
144
145 case S3C2412_IISMOD_MODE_RXONLY:
146 mod &= ~S3C2412_IISMOD_MODE_MASK;
147 mod |= S3C2412_IISMOD_MODE_TXRX;
148 break;
149
150 default:
151 dev_err(i2s->dev, "TXEN: Invalid MODE in IISMOD\n");
152 }
153
154 writel(con, regs + S3C2412_IISCON);
155 writel(mod, regs + S3C2412_IISMOD);
156 } else {
157 /* Note, we do not have any indication that the FIFO problems
158 * tha the S3C2410/2440 had apply here, so we should be able
159 * to disable the DMA and TX without resetting the FIFOS.
160 */
161
162 con |= S3C2412_IISCON_TXDMA_PAUSE;
163 con |= S3C2412_IISCON_TXCH_PAUSE;
164 con &= ~S3C2412_IISCON_TXDMA_ACTIVE;
165
166 switch (mod & S3C2412_IISMOD_MODE_MASK) {
167 case S3C2412_IISMOD_MODE_TXRX:
168 mod &= ~S3C2412_IISMOD_MODE_MASK;
169 mod |= S3C2412_IISMOD_MODE_RXONLY;
170 break;
171
172 case S3C2412_IISMOD_MODE_TXONLY:
173 mod &= ~S3C2412_IISMOD_MODE_MASK;
174 con &= ~S3C2412_IISCON_IIS_ACTIVE;
175 break;
176
177 default:
178 dev_err(i2s->dev, "TXDIS: Invalid MODE in IISMOD\n");
179 }
180
181 writel(mod, regs + S3C2412_IISMOD);
182 writel(con, regs + S3C2412_IISCON);
183 }
184
185 fic = readl(regs + S3C2412_IISFIC);
186 dbg_showcon(__func__, con);
187 DBG("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
188}
189
190static void s3c2412_snd_rxctrl(int on)
191{
192 struct s3c2412_i2s_info *i2s = &s3c2412_i2s;
193 void __iomem *regs = i2s->regs;
194 u32 fic, con, mod;
195
196 DBG("%s(%d)\n", __func__, on);
197
198 fic = readl(regs + S3C2412_IISFIC);
199 con = readl(regs + S3C2412_IISCON);
200 mod = readl(regs + S3C2412_IISMOD);
201
202 DBG("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
203
204 if (on) {
205 con |= S3C2412_IISCON_RXDMA_ACTIVE | S3C2412_IISCON_IIS_ACTIVE;
206 con &= ~S3C2412_IISCON_RXDMA_PAUSE;
207 con &= ~S3C2412_IISCON_RXCH_PAUSE;
208
209 switch (mod & S3C2412_IISMOD_MODE_MASK) {
210 case S3C2412_IISMOD_MODE_TXRX:
211 case S3C2412_IISMOD_MODE_RXONLY:
212 /* do nothing, we are in the right mode */
213 break;
214
215 case S3C2412_IISMOD_MODE_TXONLY:
216 mod &= ~S3C2412_IISMOD_MODE_MASK;
217 mod |= S3C2412_IISMOD_MODE_TXRX;
218 break;
219
220 default:
221 dev_err(i2s->dev, "RXEN: Invalid MODE in IISMOD\n");
222 }
223
224 writel(mod, regs + S3C2412_IISMOD);
225 writel(con, regs + S3C2412_IISCON);
226 } else {
227 /* See txctrl notes on FIFOs. */
228
229 con &= ~S3C2412_IISCON_RXDMA_ACTIVE;
230 con |= S3C2412_IISCON_RXDMA_PAUSE;
231 con |= S3C2412_IISCON_RXCH_PAUSE;
232
233 switch (mod & S3C2412_IISMOD_MODE_MASK) {
234 case S3C2412_IISMOD_MODE_RXONLY:
235 con &= ~S3C2412_IISCON_IIS_ACTIVE;
236 mod &= ~S3C2412_IISMOD_MODE_MASK;
237 break;
238
239 case S3C2412_IISMOD_MODE_TXRX:
240 mod &= ~S3C2412_IISMOD_MODE_MASK;
241 mod |= S3C2412_IISMOD_MODE_TXONLY;
242 break;
243
244 default:
245 dev_err(i2s->dev, "RXEN: Invalid MODE in IISMOD\n");
246 }
247
248 writel(con, regs + S3C2412_IISCON);
249 writel(mod, regs + S3C2412_IISMOD);
250 }
251
252 fic = readl(regs + S3C2412_IISFIC);
253 DBG("%s: IIS: CON=%x MOD=%x FIC=%x\n", __func__, con, mod, fic);
254}
255
256
257/*
258 * Wait for the LR signal to allow synchronisation to the L/R clock
259 * from the codec. May only be needed for slave mode.
260 */
261static int s3c2412_snd_lrsync(void)
262{
263 u32 iiscon;
264 unsigned long timeout = jiffies + msecs_to_jiffies(5);
265
266 DBG("Entered %s\n", __func__);
267
268 while (1) {
269 iiscon = readl(s3c2412_i2s.regs + S3C2412_IISCON);
270 if (iiscon & S3C2412_IISCON_LRINDEX)
271 break;
272
273 if (timeout < jiffies) {
274 printk(KERN_ERR "%s: timeout\n", __func__);
275 return -ETIMEDOUT;
276 }
277 }
278
279 return 0;
280}
281
282/*
283 * Check whether CPU is the master or slave
284 */
285static inline int s3c2412_snd_is_clkmaster(void)
286{
287 u32 iismod = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
288
289 DBG("Entered %s\n", __func__);
290
291 iismod &= S3C2412_IISMOD_MASTER_MASK;
292 return !(iismod == S3C2412_IISMOD_SLAVE);
293}
294
295/*
296 * Set S3C2412 I2S DAI format
297 */
298static int s3c2412_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
299 unsigned int fmt)
300{
301 u32 iismod;
302
303
304 DBG("Entered %s\n", __func__);
305
306 iismod = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
307 DBG("hw_params r: IISMOD: %x \n", iismod);
308
309 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
310 case SND_SOC_DAIFMT_CBM_CFM:
311 iismod &= ~S3C2412_IISMOD_MASTER_MASK;
312 iismod |= S3C2412_IISMOD_SLAVE;
313 break;
314 case SND_SOC_DAIFMT_CBS_CFS:
315 iismod &= ~S3C2412_IISMOD_MASTER_MASK;
316 iismod |= S3C2412_IISMOD_MASTER_INTERNAL;
317 break;
318 default:
319 DBG("unknwon master/slave format\n");
320 return -EINVAL;
321 }
322
323 iismod &= ~S3C2412_IISMOD_SDF_MASK;
324
325 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
326 case SND_SOC_DAIFMT_RIGHT_J:
327 iismod |= S3C2412_IISMOD_SDF_MSB;
328 break;
329 case SND_SOC_DAIFMT_LEFT_J:
330 iismod |= S3C2412_IISMOD_SDF_LSB;
331 break;
332 case SND_SOC_DAIFMT_I2S:
333 iismod |= S3C2412_IISMOD_SDF_IIS;
334 break;
335 default:
336 DBG("Unknown data format\n");
337 return -EINVAL;
338 }
339
340 writel(iismod, s3c2412_i2s.regs + S3C2412_IISMOD);
341 DBG("hw_params w: IISMOD: %x \n", iismod);
342 return 0;
343}
344
345static int s3c2412_i2s_hw_params(struct snd_pcm_substream *substream,
346 struct snd_pcm_hw_params *params,
347 struct snd_soc_dai *dai)
348{
349 struct snd_soc_pcm_runtime *rtd = substream->private_data;
350 u32 iismod;
351
352 DBG("Entered %s\n", __func__);
353
354 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
355 rtd->dai->cpu_dai->dma_data = &s3c2412_i2s_pcm_stereo_out;
356 else
357 rtd->dai->cpu_dai->dma_data = &s3c2412_i2s_pcm_stereo_in;
358
359 /* Working copies of register */
360 iismod = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
361 DBG("%s: r: IISMOD: %x\n", __func__, iismod);
362
363 switch (params_format(params)) {
364 case SNDRV_PCM_FORMAT_S8:
365 iismod |= S3C2412_IISMOD_8BIT;
366 break;
367 case SNDRV_PCM_FORMAT_S16_LE:
368 iismod &= ~S3C2412_IISMOD_8BIT;
369 break;
370 }
371
372 writel(iismod, s3c2412_i2s.regs + S3C2412_IISMOD);
373 DBG("%s: w: IISMOD: %x\n", __func__, iismod);
374 return 0;
375}
376
377static int s3c2412_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
378 struct snd_soc_dai *dai)
379{
380 int capture = (substream->stream == SNDRV_PCM_STREAM_CAPTURE);
381 unsigned long irqs;
382 int ret = 0;
383
384 DBG("Entered %s\n", __func__);
385
386 switch (cmd) {
387 case SNDRV_PCM_TRIGGER_START:
388 /* On start, ensure that the FIFOs are cleared and reset. */
389
390 writel(capture ? S3C2412_IISFIC_RXFLUSH : S3C2412_IISFIC_TXFLUSH,
391 s3c2412_i2s.regs + S3C2412_IISFIC);
392
393 /* clear again, just in case */
394 writel(0x0, s3c2412_i2s.regs + S3C2412_IISFIC);
395
396 case SNDRV_PCM_TRIGGER_RESUME:
397 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
398 if (!s3c2412_snd_is_clkmaster()) {
399 ret = s3c2412_snd_lrsync();
400 if (ret)
401 goto exit_err;
402 }
403
404 local_irq_save(irqs);
405
406 if (capture)
407 s3c2412_snd_rxctrl(1);
408 else
409 s3c2412_snd_txctrl(1);
410
411 local_irq_restore(irqs);
412 break;
413
414 case SNDRV_PCM_TRIGGER_STOP:
415 case SNDRV_PCM_TRIGGER_SUSPEND:
416 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
417 local_irq_save(irqs);
418
419 if (capture)
420 s3c2412_snd_rxctrl(0);
421 else
422 s3c2412_snd_txctrl(0);
423
424 local_irq_restore(irqs);
425 break;
426 default:
427 ret = -EINVAL;
428 break;
429 }
430
431exit_err:
432 return ret;
433}
434
435/* default table of all avaialable root fs divisors */
436static unsigned int s3c2412_iis_fs[] = { 256, 512, 384, 768, 0 };
437
438int s3c2412_iis_calc_rate(struct s3c2412_rate_calc *info,
439 unsigned int *fstab,
440 unsigned int rate, struct clk *clk)
441{
442 unsigned long clkrate = clk_get_rate(clk);
443 unsigned int div;
444 unsigned int fsclk;
445 unsigned int actual;
446 unsigned int fs;
447 unsigned int fsdiv;
448 signed int deviation = 0;
449 unsigned int best_fs = 0;
450 unsigned int best_div = 0;
451 unsigned int best_rate = 0;
452 unsigned int best_deviation = INT_MAX;
453
454
455 if (fstab == NULL)
456 fstab = s3c2412_iis_fs;
457
458 for (fs = 0;; fs++) {
459 fsdiv = s3c2412_iis_fs[fs];
460
461 if (fsdiv == 0)
462 break;
463
464 fsclk = clkrate / fsdiv;
465 div = fsclk / rate;
466
467 if ((fsclk % rate) > (rate / 2))
468 div++;
469
470 if (div <= 1)
471 continue;
472
473 actual = clkrate / (fsdiv * div);
474 deviation = actual - rate;
475
476 printk(KERN_DEBUG "%dfs: div %d => result %d, deviation %d\n",
477 fsdiv, div, actual, deviation);
478
479 deviation = abs(deviation);
480
481 if (deviation < best_deviation) {
482 best_fs = fsdiv;
483 best_div = div;
484 best_rate = actual;
485 best_deviation = deviation;
486 }
487
488 if (deviation == 0)
489 break;
490 }
491
492 printk(KERN_DEBUG "best: fs=%d, div=%d, rate=%d\n",
493 best_fs, best_div, best_rate);
494
495 info->fs_div = best_fs;
496 info->clk_div = best_div;
497
498 return 0;
499}
500EXPORT_SYMBOL_GPL(s3c2412_iis_calc_rate);
501 68
502/* 69/*
503 * Set S3C2412 Clock source 70 * Set S3C2412 Clock source
@@ -507,15 +74,17 @@ static int s3c2412_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
507{ 74{
508 u32 iismod = readl(s3c2412_i2s.regs + S3C2412_IISMOD); 75 u32 iismod = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
509 76
510 DBG("%s(%p, %d, %u, %d)\n", __func__, cpu_dai, clk_id, 77 pr_debug("%s(%p, %d, %u, %d)\n", __func__, cpu_dai, clk_id,
511 freq, dir); 78 freq, dir);
512 79
513 switch (clk_id) { 80 switch (clk_id) {
514 case S3C2412_CLKSRC_PCLK: 81 case S3C2412_CLKSRC_PCLK:
82 s3c2412_i2s.master = 1;
515 iismod &= ~S3C2412_IISMOD_MASTER_MASK; 83 iismod &= ~S3C2412_IISMOD_MASTER_MASK;
516 iismod |= S3C2412_IISMOD_MASTER_INTERNAL; 84 iismod |= S3C2412_IISMOD_MASTER_INTERNAL;
517 break; 85 break;
518 case S3C2412_CLKSRC_I2SCLK: 86 case S3C2412_CLKSRC_I2SCLK:
87 s3c2412_i2s.master = 0;
519 iismod &= ~S3C2412_IISMOD_MASTER_MASK; 88 iismod &= ~S3C2412_IISMOD_MASTER_MASK;
520 iismod |= S3C2412_IISMOD_MASTER_EXTERNAL; 89 iismod |= S3C2412_IISMOD_MASTER_EXTERNAL;
521 break; 90 break;
@@ -527,74 +96,6 @@ static int s3c2412_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
527 return 0; 96 return 0;
528} 97}
529 98
530/*
531 * Set S3C2412 Clock dividers
532 */
533static int s3c2412_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
534 int div_id, int div)
535{
536 struct s3c2412_i2s_info *i2s = &s3c2412_i2s;
537 u32 reg;
538
539 DBG("%s(%p, %d, %d)\n", __func__, cpu_dai, div_id, div);
540
541 switch (div_id) {
542 case S3C2412_DIV_BCLK:
543 reg = readl(i2s->regs + S3C2412_IISMOD);
544 reg &= ~S3C2412_IISMOD_BCLK_MASK;
545 writel(reg | div, i2s->regs + S3C2412_IISMOD);
546
547 DBG("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD));
548 break;
549
550 case S3C2412_DIV_RCLK:
551 if (div > 3) {
552 /* convert value to bit field */
553
554 switch (div) {
555 case 256:
556 div = S3C2412_IISMOD_RCLK_256FS;
557 break;
558
559 case 384:
560 div = S3C2412_IISMOD_RCLK_384FS;
561 break;
562
563 case 512:
564 div = S3C2412_IISMOD_RCLK_512FS;
565 break;
566
567 case 768:
568 div = S3C2412_IISMOD_RCLK_768FS;
569 break;
570
571 default:
572 return -EINVAL;
573 }
574 }
575
576 reg = readl(s3c2412_i2s.regs + S3C2412_IISMOD);
577 reg &= ~S3C2412_IISMOD_RCLK_MASK;
578 writel(reg | div, i2s->regs + S3C2412_IISMOD);
579 DBG("%s: MOD=%08x\n", __func__, readl(i2s->regs + S3C2412_IISMOD));
580 break;
581
582 case S3C2412_DIV_PRESCALER:
583 if (div >= 0) {
584 writel((div << 8) | S3C2412_IISPSR_PSREN,
585 i2s->regs + S3C2412_IISPSR);
586 } else {
587 writel(0x0, i2s->regs + S3C2412_IISPSR);
588 }
589 DBG("%s: PSR=%08x\n", __func__, readl(i2s->regs + S3C2412_IISPSR));
590 break;
591
592 default:
593 return -EINVAL;
594 }
595
596 return 0;
597}
598 99
599struct clk *s3c2412_get_iisclk(void) 100struct clk *s3c2412_get_iisclk(void)
600{ 101{
@@ -606,34 +107,30 @@ EXPORT_SYMBOL_GPL(s3c2412_get_iisclk);
606static int s3c2412_i2s_probe(struct platform_device *pdev, 107static int s3c2412_i2s_probe(struct platform_device *pdev,
607 struct snd_soc_dai *dai) 108 struct snd_soc_dai *dai)
608{ 109{
609 DBG("Entered %s\n", __func__); 110 int ret;
610 111
611 s3c2412_i2s.dev = &pdev->dev; 112 pr_debug("Entered %s\n", __func__);
612 113
613 s3c2412_i2s.regs = ioremap(S3C2410_PA_IIS, 0x100); 114 ret = s3c_i2sv2_probe(pdev, dai, &s3c2412_i2s, S3C2410_PA_IIS);
614 if (s3c2412_i2s.regs == NULL) 115 if (ret)
615 return -ENXIO; 116 return ret;
616 117
617 s3c2412_i2s.iis_pclk = clk_get(&pdev->dev, "iis"); 118 s3c2412_i2s.dma_capture = &s3c2412_i2s_pcm_stereo_in;
618 if (s3c2412_i2s.iis_pclk == NULL) { 119 s3c2412_i2s.dma_playback = &s3c2412_i2s_pcm_stereo_out;
619 DBG("failed to get iis_clock\n");
620 iounmap(s3c2412_i2s.regs);
621 return -ENODEV;
622 }
623 120
624 s3c2412_i2s.iis_cclk = clk_get(&pdev->dev, "i2sclk"); 121 s3c2412_i2s.iis_cclk = clk_get(&pdev->dev, "i2sclk");
625 if (s3c2412_i2s.iis_cclk == NULL) { 122 if (s3c2412_i2s.iis_cclk == NULL) {
626 DBG("failed to get i2sclk clock\n"); 123 pr_debug("failed to get i2sclk clock\n");
627 iounmap(s3c2412_i2s.regs); 124 iounmap(s3c2412_i2s.regs);
628 return -ENODEV; 125 return -ENODEV;
629 } 126 }
630 127
631 clk_set_parent(s3c2412_i2s.iis_cclk, clk_get(NULL, "mpll")); 128 /* Set MPLL as the source for IIS CLK */
632 129
633 clk_enable(s3c2412_i2s.iis_pclk); 130 clk_set_parent(s3c2412_i2s.iis_cclk, clk_get(NULL, "mpll"));
634 clk_enable(s3c2412_i2s.iis_cclk); 131 clk_enable(s3c2412_i2s.iis_cclk);
635 132
636 s3c2412_i2s.iis_clk = s3c2412_i2s.iis_pclk; 133 s3c2412_i2s.iis_cclk = s3c2412_i2s.iis_pclk;
637 134
638 /* Configure the I2S pins in correct mode */ 135 /* Configure the I2S pins in correct mode */
639 s3c2410_gpio_cfgpin(S3C2410_GPE0, S3C2410_GPE0_I2SLRCK); 136 s3c2410_gpio_cfgpin(S3C2410_GPE0, S3C2410_GPE0_I2SLRCK);
@@ -642,78 +139,22 @@ static int s3c2412_i2s_probe(struct platform_device *pdev,
642 s3c2410_gpio_cfgpin(S3C2410_GPE3, S3C2410_GPE3_I2SSDI); 139 s3c2410_gpio_cfgpin(S3C2410_GPE3, S3C2410_GPE3_I2SSDI);
643 s3c2410_gpio_cfgpin(S3C2410_GPE4, S3C2410_GPE4_I2SSDO); 140 s3c2410_gpio_cfgpin(S3C2410_GPE4, S3C2410_GPE4_I2SSDO);
644 141
645 s3c2412_snd_txctrl(0);
646 s3c2412_snd_rxctrl(0);
647
648 return 0; 142 return 0;
649} 143}
650 144
651#ifdef CONFIG_PM
652static int s3c2412_i2s_suspend(struct snd_soc_dai *dai)
653{
654 struct s3c2412_i2s_info *i2s = &s3c2412_i2s;
655 u32 iismod;
656
657 if (dai->active) {
658 i2s->suspend_iismod = readl(i2s->regs + S3C2412_IISMOD);
659 i2s->suspend_iiscon = readl(i2s->regs + S3C2412_IISCON);
660 i2s->suspend_iispsr = readl(i2s->regs + S3C2412_IISPSR);
661
662 /* some basic suspend checks */
663
664 iismod = readl(i2s->regs + S3C2412_IISMOD);
665
666 if (iismod & S3C2412_IISCON_RXDMA_ACTIVE)
667 pr_warning("%s: RXDMA active?\n", __func__);
668
669 if (iismod & S3C2412_IISCON_TXDMA_ACTIVE)
670 pr_warning("%s: TXDMA active?\n", __func__);
671
672 if (iismod & S3C2412_IISCON_IIS_ACTIVE)
673 pr_warning("%s: IIS active\n", __func__);
674 }
675
676 return 0;
677}
678
679static int s3c2412_i2s_resume(struct snd_soc_dai *dai)
680{
681 struct s3c2412_i2s_info *i2s = &s3c2412_i2s;
682
683 pr_info("dai_active %d, IISMOD %08x, IISCON %08x\n",
684 dai->active, i2s->suspend_iismod, i2s->suspend_iiscon);
685
686 if (dai->active) {
687 writel(i2s->suspend_iiscon, i2s->regs + S3C2412_IISCON);
688 writel(i2s->suspend_iismod, i2s->regs + S3C2412_IISMOD);
689 writel(i2s->suspend_iispsr, i2s->regs + S3C2412_IISPSR);
690
691 writel(S3C2412_IISFIC_RXFLUSH | S3C2412_IISFIC_TXFLUSH,
692 i2s->regs + S3C2412_IISFIC);
693
694 ndelay(250);
695 writel(0x0, i2s->regs + S3C2412_IISFIC);
696
697 }
698
699 return 0;
700}
701#else
702#define s3c2412_i2s_suspend NULL
703#define s3c2412_i2s_resume NULL
704#endif /* CONFIG_PM */
705
706#define S3C2412_I2S_RATES \ 145#define S3C2412_I2S_RATES \
707 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \ 146 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
708 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ 147 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
709 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) 148 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
710 149
150static struct snd_soc_dai_ops s3c2412_i2s_dai_ops = {
151 .set_sysclk = s3c2412_i2s_set_sysclk,
152};
153
711struct snd_soc_dai s3c2412_i2s_dai = { 154struct snd_soc_dai s3c2412_i2s_dai = {
712 .name = "s3c2412-i2s", 155 .name = "s3c2412-i2s",
713 .id = 0, 156 .id = 0,
714 .probe = s3c2412_i2s_probe, 157 .probe = s3c2412_i2s_probe,
715 .suspend = s3c2412_i2s_suspend,
716 .resume = s3c2412_i2s_resume,
717 .playback = { 158 .playback = {
718 .channels_min = 2, 159 .channels_min = 2,
719 .channels_max = 2, 160 .channels_max = 2,
@@ -726,19 +167,13 @@ struct snd_soc_dai s3c2412_i2s_dai = {
726 .rates = S3C2412_I2S_RATES, 167 .rates = S3C2412_I2S_RATES,
727 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE, 168 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,
728 }, 169 },
729 .ops = { 170 .ops = &s3c2412_i2s_dai_ops,
730 .trigger = s3c2412_i2s_trigger,
731 .hw_params = s3c2412_i2s_hw_params,
732 .set_fmt = s3c2412_i2s_set_fmt,
733 .set_clkdiv = s3c2412_i2s_set_clkdiv,
734 .set_sysclk = s3c2412_i2s_set_sysclk,
735 },
736}; 171};
737EXPORT_SYMBOL_GPL(s3c2412_i2s_dai); 172EXPORT_SYMBOL_GPL(s3c2412_i2s_dai);
738 173
739static int __init s3c2412_i2s_init(void) 174static int __init s3c2412_i2s_init(void)
740{ 175{
741 return snd_soc_register_dai(&s3c2412_i2s_dai); 176 return s3c_i2sv2_register_dai(&s3c2412_i2s_dai);
742} 177}
743module_init(s3c2412_i2s_init); 178module_init(s3c2412_i2s_init);
744 179
@@ -748,7 +183,6 @@ static void __exit s3c2412_i2s_exit(void)
748} 183}
749module_exit(s3c2412_i2s_exit); 184module_exit(s3c2412_i2s_exit);
750 185
751
752/* Module information */ 186/* Module information */
753MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); 187MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
754MODULE_DESCRIPTION("S3C2412 I2S SoC Interface"); 188MODULE_DESCRIPTION("S3C2412 I2S SoC Interface");
diff --git a/sound/soc/s3c24xx/s3c2412-i2s.h b/sound/soc/s3c24xx/s3c2412-i2s.h
index aac08a25e541..92848e54be16 100644
--- a/sound/soc/s3c24xx/s3c2412-i2s.h
+++ b/sound/soc/s3c24xx/s3c2412-i2s.h
@@ -15,9 +15,11 @@
15#ifndef __SND_SOC_S3C24XX_S3C2412_I2S_H 15#ifndef __SND_SOC_S3C24XX_S3C2412_I2S_H
16#define __SND_SOC_S3C24XX_S3C2412_I2S_H __FILE__ 16#define __SND_SOC_S3C24XX_S3C2412_I2S_H __FILE__
17 17
18#define S3C2412_DIV_BCLK (1) 18#include "s3c-i2s-v2.h"
19#define S3C2412_DIV_RCLK (2) 19
20#define S3C2412_DIV_PRESCALER (3) 20#define S3C2412_DIV_BCLK S3C_I2SV2_DIV_BCLK
21#define S3C2412_DIV_RCLK S3C_I2SV2_DIV_RCLK
22#define S3C2412_DIV_PRESCALER S3C_I2SV2_DIV_PRESCALER
21 23
22#define S3C2412_CLKSRC_PCLK (0) 24#define S3C2412_CLKSRC_PCLK (0)
23#define S3C2412_CLKSRC_I2SCLK (1) 25#define S3C2412_CLKSRC_I2SCLK (1)
@@ -26,13 +28,4 @@ extern struct clk *s3c2412_get_iisclk(void);
26 28
27extern struct snd_soc_dai s3c2412_i2s_dai; 29extern struct snd_soc_dai s3c2412_i2s_dai;
28 30
29struct s3c2412_rate_calc {
30 unsigned int clk_div; /* for prescaler */
31 unsigned int fs_div; /* for root frame clock */
32};
33
34extern int s3c2412_iis_calc_rate(struct s3c2412_rate_calc *info,
35 unsigned int *fstab,
36 unsigned int rate, struct clk *clk);
37
38#endif /* __SND_SOC_S3C24XX_S3C2412_I2S_H */ 31#endif /* __SND_SOC_S3C24XX_S3C2412_I2S_H */
diff --git a/sound/soc/s3c24xx/s3c2443-ac97.c b/sound/soc/s3c24xx/s3c2443-ac97.c
index 5822d2dd49ba..3698f707c44d 100644
--- a/sound/soc/s3c24xx/s3c2443-ac97.c
+++ b/sound/soc/s3c24xx/s3c2443-ac97.c
@@ -31,7 +31,7 @@
31#include <plat/regs-ac97.h> 31#include <plat/regs-ac97.h>
32#include <mach/regs-gpio.h> 32#include <mach/regs-gpio.h>
33#include <mach/regs-clock.h> 33#include <mach/regs-clock.h>
34#include <mach/audio.h> 34#include <plat/audio.h>
35#include <asm/dma.h> 35#include <asm/dma.h>
36#include <mach/dma.h> 36#include <mach/dma.h>
37 37
@@ -355,6 +355,16 @@ static int s3c2443_ac97_mic_trigger(struct snd_pcm_substream *substream,
355 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \ 355 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
356 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) 356 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000)
357 357
358static struct snd_soc_dai_ops s3c2443_ac97_dai_ops = {
359 .hw_params = s3c2443_ac97_hw_params,
360 .trigger = s3c2443_ac97_trigger,
361};
362
363static struct snd_soc_dai_ops s3c2443_ac97_mic_dai_ops = {
364 .hw_params = s3c2443_ac97_hw_mic_params,
365 .trigger = s3c2443_ac97_mic_trigger,
366};
367
358struct snd_soc_dai s3c2443_ac97_dai[] = { 368struct snd_soc_dai s3c2443_ac97_dai[] = {
359{ 369{
360 .name = "s3c2443-ac97", 370 .name = "s3c2443-ac97",
@@ -374,9 +384,7 @@ struct snd_soc_dai s3c2443_ac97_dai[] = {
374 .channels_max = 2, 384 .channels_max = 2,
375 .rates = s3c2443_AC97_RATES, 385 .rates = s3c2443_AC97_RATES,
376 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 386 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
377 .ops = { 387 .ops = &s3c2443_ac97_dai_ops,
378 .hw_params = s3c2443_ac97_hw_params,
379 .trigger = s3c2443_ac97_trigger},
380}, 388},
381{ 389{
382 .name = "pxa2xx-ac97-mic", 390 .name = "pxa2xx-ac97-mic",
@@ -388,9 +396,7 @@ struct snd_soc_dai s3c2443_ac97_dai[] = {
388 .channels_max = 1, 396 .channels_max = 1,
389 .rates = s3c2443_AC97_RATES, 397 .rates = s3c2443_AC97_RATES,
390 .formats = SNDRV_PCM_FMTBIT_S16_LE,}, 398 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
391 .ops = { 399 .ops = &s3c2443_ac97_mic_dai_ops,
392 .hw_params = s3c2443_ac97_hw_mic_params,
393 .trigger = s3c2443_ac97_mic_trigger,},
394}, 400},
395}; 401};
396EXPORT_SYMBOL_GPL(s3c2443_ac97_dai); 402EXPORT_SYMBOL_GPL(s3c2443_ac97_dai);
diff --git a/sound/soc/s3c24xx/s3c24xx-i2s.c b/sound/soc/s3c24xx/s3c24xx-i2s.c
index 6f4d439b57aa..cc066964dad6 100644
--- a/sound/soc/s3c24xx/s3c24xx-i2s.c
+++ b/sound/soc/s3c24xx/s3c24xx-i2s.c
@@ -4,7 +4,7 @@
4 * (c) 2006 Wolfson Microelectronics PLC. 4 * (c) 2006 Wolfson Microelectronics PLC.
5 * Graeme Gregory graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com 5 * Graeme Gregory graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
6 * 6 *
7 * (c) 2004-2005 Simtec Electronics 7 * Copyright 2004-2005 Simtec Electronics
8 * http://armlinux.simtec.co.uk/ 8 * http://armlinux.simtec.co.uk/
9 * Ben Dooks <ben@simtec.co.uk> 9 * Ben Dooks <ben@simtec.co.uk>
10 * 10 *
@@ -30,22 +30,15 @@
30#include <mach/hardware.h> 30#include <mach/hardware.h>
31#include <mach/regs-gpio.h> 31#include <mach/regs-gpio.h>
32#include <mach/regs-clock.h> 32#include <mach/regs-clock.h>
33#include <mach/audio.h> 33#include <plat/audio.h>
34#include <asm/dma.h> 34#include <asm/dma.h>
35#include <mach/dma.h> 35#include <mach/dma.h>
36 36
37#include <asm/plat-s3c24xx/regs-iis.h> 37#include <plat/regs-iis.h>
38 38
39#include "s3c24xx-pcm.h" 39#include "s3c24xx-pcm.h"
40#include "s3c24xx-i2s.h" 40#include "s3c24xx-i2s.h"
41 41
42#define S3C24XX_I2S_DEBUG 0
43#if S3C24XX_I2S_DEBUG
44#define DBG(x...) printk(KERN_DEBUG "s3c24xx-i2s: " x)
45#else
46#define DBG(x...)
47#endif
48
49static struct s3c2410_dma_client s3c24xx_dma_client_out = { 42static struct s3c2410_dma_client s3c24xx_dma_client_out = {
50 .name = "I2S PCM Stereo out" 43 .name = "I2S PCM Stereo out"
51}; 44};
@@ -84,13 +77,13 @@ static void s3c24xx_snd_txctrl(int on)
84 u32 iiscon; 77 u32 iiscon;
85 u32 iismod; 78 u32 iismod;
86 79
87 DBG("Entered %s\n", __func__); 80 pr_debug("Entered %s\n", __func__);
88 81
89 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); 82 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
90 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 83 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
91 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 84 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
92 85
93 DBG("r: IISCON: %lx IISMOD: %lx IISFCON: %lx\n", iiscon, iismod, iisfcon); 86 pr_debug("r: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon);
94 87
95 if (on) { 88 if (on) {
96 iisfcon |= S3C2410_IISFCON_TXDMA | S3C2410_IISFCON_TXENABLE; 89 iisfcon |= S3C2410_IISFCON_TXDMA | S3C2410_IISFCON_TXENABLE;
@@ -120,7 +113,7 @@ static void s3c24xx_snd_txctrl(int on)
120 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); 113 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
121 } 114 }
122 115
123 DBG("w: IISCON: %lx IISMOD: %lx IISFCON: %lx\n", iiscon, iismod, iisfcon); 116 pr_debug("w: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon);
124} 117}
125 118
126static void s3c24xx_snd_rxctrl(int on) 119static void s3c24xx_snd_rxctrl(int on)
@@ -129,13 +122,13 @@ static void s3c24xx_snd_rxctrl(int on)
129 u32 iiscon; 122 u32 iiscon;
130 u32 iismod; 123 u32 iismod;
131 124
132 DBG("Entered %s\n", __func__); 125 pr_debug("Entered %s\n", __func__);
133 126
134 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); 127 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
135 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 128 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
136 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 129 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
137 130
138 DBG("r: IISCON: %lx IISMOD: %lx IISFCON: %lx\n", iiscon, iismod, iisfcon); 131 pr_debug("r: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon);
139 132
140 if (on) { 133 if (on) {
141 iisfcon |= S3C2410_IISFCON_RXDMA | S3C2410_IISFCON_RXENABLE; 134 iisfcon |= S3C2410_IISFCON_RXDMA | S3C2410_IISFCON_RXENABLE;
@@ -165,7 +158,7 @@ static void s3c24xx_snd_rxctrl(int on)
165 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); 158 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
166 } 159 }
167 160
168 DBG("w: IISCON: %lx IISMOD: %lx IISFCON: %lx\n", iiscon, iismod, iisfcon); 161 pr_debug("w: IISCON: %x IISMOD: %x IISFCON: %x\n", iiscon, iismod, iisfcon);
169} 162}
170 163
171/* 164/*
@@ -177,7 +170,7 @@ static int s3c24xx_snd_lrsync(void)
177 u32 iiscon; 170 u32 iiscon;
178 int timeout = 50; /* 5ms */ 171 int timeout = 50; /* 5ms */
179 172
180 DBG("Entered %s\n", __func__); 173 pr_debug("Entered %s\n", __func__);
181 174
182 while (1) { 175 while (1) {
183 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 176 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
@@ -197,7 +190,7 @@ static int s3c24xx_snd_lrsync(void)
197 */ 190 */
198static inline int s3c24xx_snd_is_clkmaster(void) 191static inline int s3c24xx_snd_is_clkmaster(void)
199{ 192{
200 DBG("Entered %s\n", __func__); 193 pr_debug("Entered %s\n", __func__);
201 194
202 return (readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & S3C2410_IISMOD_SLAVE) ? 0:1; 195 return (readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & S3C2410_IISMOD_SLAVE) ? 0:1;
203} 196}
@@ -210,10 +203,10 @@ static int s3c24xx_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
210{ 203{
211 u32 iismod; 204 u32 iismod;
212 205
213 DBG("Entered %s\n", __func__); 206 pr_debug("Entered %s\n", __func__);
214 207
215 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 208 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
216 DBG("hw_params r: IISMOD: %lx \n", iismod); 209 pr_debug("hw_params r: IISMOD: %x \n", iismod);
217 210
218 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 211 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
219 case SND_SOC_DAIFMT_CBM_CFM: 212 case SND_SOC_DAIFMT_CBM_CFM:
@@ -238,7 +231,7 @@ static int s3c24xx_i2s_set_fmt(struct snd_soc_dai *cpu_dai,
238 } 231 }
239 232
240 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); 233 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
241 DBG("hw_params w: IISMOD: %lx \n", iismod); 234 pr_debug("hw_params w: IISMOD: %x \n", iismod);
242 return 0; 235 return 0;
243} 236}
244 237
@@ -249,7 +242,7 @@ static int s3c24xx_i2s_hw_params(struct snd_pcm_substream *substream,
249 struct snd_soc_pcm_runtime *rtd = substream->private_data; 242 struct snd_soc_pcm_runtime *rtd = substream->private_data;
250 u32 iismod; 243 u32 iismod;
251 244
252 DBG("Entered %s\n", __func__); 245 pr_debug("Entered %s\n", __func__);
253 246
254 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 247 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
255 rtd->dai->cpu_dai->dma_data = &s3c24xx_i2s_pcm_stereo_out; 248 rtd->dai->cpu_dai->dma_data = &s3c24xx_i2s_pcm_stereo_out;
@@ -258,7 +251,7 @@ static int s3c24xx_i2s_hw_params(struct snd_pcm_substream *substream,
258 251
259 /* Working copies of register */ 252 /* Working copies of register */
260 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 253 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
261 DBG("hw_params r: IISMOD: %lx\n", iismod); 254 pr_debug("hw_params r: IISMOD: %x\n", iismod);
262 255
263 switch (params_format(params)) { 256 switch (params_format(params)) {
264 case SNDRV_PCM_FORMAT_S8: 257 case SNDRV_PCM_FORMAT_S8:
@@ -276,7 +269,7 @@ static int s3c24xx_i2s_hw_params(struct snd_pcm_substream *substream,
276 } 269 }
277 270
278 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD); 271 writel(iismod, s3c24xx_i2s.regs + S3C2410_IISMOD);
279 DBG("hw_params w: IISMOD: %lx\n", iismod); 272 pr_debug("hw_params w: IISMOD: %x\n", iismod);
280 return 0; 273 return 0;
281} 274}
282 275
@@ -285,7 +278,7 @@ static int s3c24xx_i2s_trigger(struct snd_pcm_substream *substream, int cmd,
285{ 278{
286 int ret = 0; 279 int ret = 0;
287 280
288 DBG("Entered %s\n", __func__); 281 pr_debug("Entered %s\n", __func__);
289 282
290 switch (cmd) { 283 switch (cmd) {
291 case SNDRV_PCM_TRIGGER_START: 284 case SNDRV_PCM_TRIGGER_START:
@@ -327,7 +320,7 @@ static int s3c24xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
327{ 320{
328 u32 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 321 u32 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
329 322
330 DBG("Entered %s\n", __func__); 323 pr_debug("Entered %s\n", __func__);
331 324
332 iismod &= ~S3C2440_IISMOD_MPLL; 325 iismod &= ~S3C2440_IISMOD_MPLL;
333 326
@@ -353,7 +346,7 @@ static int s3c24xx_i2s_set_clkdiv(struct snd_soc_dai *cpu_dai,
353{ 346{
354 u32 reg; 347 u32 reg;
355 348
356 DBG("Entered %s\n", __func__); 349 pr_debug("Entered %s\n", __func__);
357 350
358 switch (div_id) { 351 switch (div_id) {
359 case S3C24XX_DIV_BCLK: 352 case S3C24XX_DIV_BCLK:
@@ -389,7 +382,7 @@ EXPORT_SYMBOL_GPL(s3c24xx_i2s_get_clockrate);
389static int s3c24xx_i2s_probe(struct platform_device *pdev, 382static int s3c24xx_i2s_probe(struct platform_device *pdev,
390 struct snd_soc_dai *dai) 383 struct snd_soc_dai *dai)
391{ 384{
392 DBG("Entered %s\n", __func__); 385 pr_debug("Entered %s\n", __func__);
393 386
394 s3c24xx_i2s.regs = ioremap(S3C2410_PA_IIS, 0x100); 387 s3c24xx_i2s.regs = ioremap(S3C2410_PA_IIS, 0x100);
395 if (s3c24xx_i2s.regs == NULL) 388 if (s3c24xx_i2s.regs == NULL)
@@ -397,7 +390,7 @@ static int s3c24xx_i2s_probe(struct platform_device *pdev,
397 390
398 s3c24xx_i2s.iis_clk = clk_get(&pdev->dev, "iis"); 391 s3c24xx_i2s.iis_clk = clk_get(&pdev->dev, "iis");
399 if (s3c24xx_i2s.iis_clk == NULL) { 392 if (s3c24xx_i2s.iis_clk == NULL) {
400 DBG("failed to get iis_clock\n"); 393 pr_err("failed to get iis_clock\n");
401 iounmap(s3c24xx_i2s.regs); 394 iounmap(s3c24xx_i2s.regs);
402 return -ENODEV; 395 return -ENODEV;
403 } 396 }
@@ -421,7 +414,7 @@ static int s3c24xx_i2s_probe(struct platform_device *pdev,
421#ifdef CONFIG_PM 414#ifdef CONFIG_PM
422static int s3c24xx_i2s_suspend(struct snd_soc_dai *cpu_dai) 415static int s3c24xx_i2s_suspend(struct snd_soc_dai *cpu_dai)
423{ 416{
424 DBG("Entered %s\n", __func__); 417 pr_debug("Entered %s\n", __func__);
425 418
426 s3c24xx_i2s.iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 419 s3c24xx_i2s.iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
427 s3c24xx_i2s.iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 420 s3c24xx_i2s.iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
@@ -435,7 +428,7 @@ static int s3c24xx_i2s_suspend(struct snd_soc_dai *cpu_dai)
435 428
436static int s3c24xx_i2s_resume(struct snd_soc_dai *cpu_dai) 429static int s3c24xx_i2s_resume(struct snd_soc_dai *cpu_dai)
437{ 430{
438 DBG("Entered %s\n", __func__); 431 pr_debug("Entered %s\n", __func__);
439 clk_enable(s3c24xx_i2s.iis_clk); 432 clk_enable(s3c24xx_i2s.iis_clk);
440 433
441 writel(s3c24xx_i2s.iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); 434 writel(s3c24xx_i2s.iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
@@ -456,6 +449,14 @@ static int s3c24xx_i2s_resume(struct snd_soc_dai *cpu_dai)
456 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ 449 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
457 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) 450 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
458 451
452static struct snd_soc_dai_ops s3c24xx_i2s_dai_ops = {
453 .trigger = s3c24xx_i2s_trigger,
454 .hw_params = s3c24xx_i2s_hw_params,
455 .set_fmt = s3c24xx_i2s_set_fmt,
456 .set_clkdiv = s3c24xx_i2s_set_clkdiv,
457 .set_sysclk = s3c24xx_i2s_set_sysclk,
458};
459
459struct snd_soc_dai s3c24xx_i2s_dai = { 460struct snd_soc_dai s3c24xx_i2s_dai = {
460 .name = "s3c24xx-i2s", 461 .name = "s3c24xx-i2s",
461 .id = 0, 462 .id = 0,
@@ -472,13 +473,7 @@ struct snd_soc_dai s3c24xx_i2s_dai = {
472 .channels_max = 2, 473 .channels_max = 2,
473 .rates = S3C24XX_I2S_RATES, 474 .rates = S3C24XX_I2S_RATES,
474 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,}, 475 .formats = SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE,},
475 .ops = { 476 .ops = &s3c24xx_i2s_dai_ops,
476 .trigger = s3c24xx_i2s_trigger,
477 .hw_params = s3c24xx_i2s_hw_params,
478 .set_fmt = s3c24xx_i2s_set_fmt,
479 .set_clkdiv = s3c24xx_i2s_set_clkdiv,
480 .set_sysclk = s3c24xx_i2s_set_sysclk,
481 },
482}; 477};
483EXPORT_SYMBOL_GPL(s3c24xx_i2s_dai); 478EXPORT_SYMBOL_GPL(s3c24xx_i2s_dai);
484 479
diff --git a/sound/soc/s3c24xx/s3c24xx-pcm.c b/sound/soc/s3c24xx/s3c24xx-pcm.c
index 7c64d31d067e..a9d68fa2b34a 100644
--- a/sound/soc/s3c24xx/s3c24xx-pcm.c
+++ b/sound/soc/s3c24xx/s3c24xx-pcm.c
@@ -4,7 +4,7 @@
4 * (c) 2006 Wolfson Microelectronics PLC. 4 * (c) 2006 Wolfson Microelectronics PLC.
5 * Graeme Gregory graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com 5 * Graeme Gregory graeme.gregory@wolfsonmicro.com or linux@wolfsonmicro.com
6 * 6 *
7 * (c) 2004-2005 Simtec Electronics 7 * Copyright 2004-2005 Simtec Electronics
8 * http://armlinux.simtec.co.uk/ 8 * http://armlinux.simtec.co.uk/
9 * Ben Dooks <ben@simtec.co.uk> 9 * Ben Dooks <ben@simtec.co.uk>
10 * 10 *
@@ -29,17 +29,10 @@
29#include <asm/dma.h> 29#include <asm/dma.h>
30#include <mach/hardware.h> 30#include <mach/hardware.h>
31#include <mach/dma.h> 31#include <mach/dma.h>
32#include <mach/audio.h> 32#include <plat/audio.h>
33 33
34#include "s3c24xx-pcm.h" 34#include "s3c24xx-pcm.h"
35 35
36#define S3C24XX_PCM_DEBUG 0
37#if S3C24XX_PCM_DEBUG
38#define DBG(x...) printk(KERN_DEBUG "s3c24xx-pcm: " x)
39#else
40#define DBG(x...)
41#endif
42
43static const struct snd_pcm_hardware s3c24xx_pcm_hardware = { 36static const struct snd_pcm_hardware s3c24xx_pcm_hardware = {
44 .info = SNDRV_PCM_INFO_INTERLEAVED | 37 .info = SNDRV_PCM_INFO_INTERLEAVED |
45 SNDRV_PCM_INFO_BLOCK_TRANSFER | 38 SNDRV_PCM_INFO_BLOCK_TRANSFER |
@@ -84,16 +77,16 @@ static void s3c24xx_pcm_enqueue(struct snd_pcm_substream *substream)
84 dma_addr_t pos = prtd->dma_pos; 77 dma_addr_t pos = prtd->dma_pos;
85 int ret; 78 int ret;
86 79
87 DBG("Entered %s\n", __func__); 80 pr_debug("Entered %s\n", __func__);
88 81
89 while (prtd->dma_loaded < prtd->dma_limit) { 82 while (prtd->dma_loaded < prtd->dma_limit) {
90 unsigned long len = prtd->dma_period; 83 unsigned long len = prtd->dma_period;
91 84
92 DBG("dma_loaded: %d\n", prtd->dma_loaded); 85 pr_debug("dma_loaded: %d\n", prtd->dma_loaded);
93 86
94 if ((pos + len) > prtd->dma_end) { 87 if ((pos + len) > prtd->dma_end) {
95 len = prtd->dma_end - pos; 88 len = prtd->dma_end - pos;
96 DBG(KERN_DEBUG "%s: corrected dma len %ld\n", 89 pr_debug(KERN_DEBUG "%s: corrected dma len %ld\n",
97 __func__, len); 90 __func__, len);
98 } 91 }
99 92
@@ -119,7 +112,7 @@ static void s3c24xx_audio_buffdone(struct s3c2410_dma_chan *channel,
119 struct snd_pcm_substream *substream = dev_id; 112 struct snd_pcm_substream *substream = dev_id;
120 struct s3c24xx_runtime_data *prtd; 113 struct s3c24xx_runtime_data *prtd;
121 114
122 DBG("Entered %s\n", __func__); 115 pr_debug("Entered %s\n", __func__);
123 116
124 if (result == S3C2410_RES_ABORT || result == S3C2410_RES_ERR) 117 if (result == S3C2410_RES_ABORT || result == S3C2410_RES_ERR)
125 return; 118 return;
@@ -148,7 +141,7 @@ static int s3c24xx_pcm_hw_params(struct snd_pcm_substream *substream,
148 unsigned long totbytes = params_buffer_bytes(params); 141 unsigned long totbytes = params_buffer_bytes(params);
149 int ret = 0; 142 int ret = 0;
150 143
151 DBG("Entered %s\n", __func__); 144 pr_debug("Entered %s\n", __func__);
152 145
153 /* return if this is a bufferless transfer e.g. 146 /* return if this is a bufferless transfer e.g.
154 * codec <--> BT codec or GSM modem -- lg FIXME */ 147 * codec <--> BT codec or GSM modem -- lg FIXME */
@@ -161,14 +154,14 @@ static int s3c24xx_pcm_hw_params(struct snd_pcm_substream *substream,
161 /* prepare DMA */ 154 /* prepare DMA */
162 prtd->params = dma; 155 prtd->params = dma;
163 156
164 DBG("params %p, client %p, channel %d\n", prtd->params, 157 pr_debug("params %p, client %p, channel %d\n", prtd->params,
165 prtd->params->client, prtd->params->channel); 158 prtd->params->client, prtd->params->channel);
166 159
167 ret = s3c2410_dma_request(prtd->params->channel, 160 ret = s3c2410_dma_request(prtd->params->channel,
168 prtd->params->client, NULL); 161 prtd->params->client, NULL);
169 162
170 if (ret < 0) { 163 if (ret < 0) {
171 DBG(KERN_ERR "failed to get dma channel\n"); 164 printk(KERN_ERR "failed to get dma channel\n");
172 return ret; 165 return ret;
173 } 166 }
174 } 167 }
@@ -196,7 +189,7 @@ static int s3c24xx_pcm_hw_free(struct snd_pcm_substream *substream)
196{ 189{
197 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 190 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
198 191
199 DBG("Entered %s\n", __func__); 192 pr_debug("Entered %s\n", __func__);
200 193
201 /* TODO - do we need to ensure DMA flushed */ 194 /* TODO - do we need to ensure DMA flushed */
202 snd_pcm_set_runtime_buffer(substream, NULL); 195 snd_pcm_set_runtime_buffer(substream, NULL);
@@ -214,7 +207,7 @@ static int s3c24xx_pcm_prepare(struct snd_pcm_substream *substream)
214 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 207 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
215 int ret = 0; 208 int ret = 0;
216 209
217 DBG("Entered %s\n", __func__); 210 pr_debug("Entered %s\n", __func__);
218 211
219 /* return if this is a bufferless transfer e.g. 212 /* return if this is a bufferless transfer e.g.
220 * codec <--> BT codec or GSM modem -- lg FIXME */ 213 * codec <--> BT codec or GSM modem -- lg FIXME */
@@ -259,7 +252,7 @@ static int s3c24xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
259 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 252 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
260 int ret = 0; 253 int ret = 0;
261 254
262 DBG("Entered %s\n", __func__); 255 pr_debug("Entered %s\n", __func__);
263 256
264 spin_lock(&prtd->lock); 257 spin_lock(&prtd->lock);
265 258
@@ -297,7 +290,7 @@ s3c24xx_pcm_pointer(struct snd_pcm_substream *substream)
297 unsigned long res; 290 unsigned long res;
298 dma_addr_t src, dst; 291 dma_addr_t src, dst;
299 292
300 DBG("Entered %s\n", __func__); 293 pr_debug("Entered %s\n", __func__);
301 294
302 spin_lock(&prtd->lock); 295 spin_lock(&prtd->lock);
303 s3c2410_dma_getposition(prtd->params->channel, &src, &dst); 296 s3c2410_dma_getposition(prtd->params->channel, &src, &dst);
@@ -309,7 +302,7 @@ s3c24xx_pcm_pointer(struct snd_pcm_substream *substream)
309 302
310 spin_unlock(&prtd->lock); 303 spin_unlock(&prtd->lock);
311 304
312 DBG("Pointer %x %x\n", src, dst); 305 pr_debug("Pointer %x %x\n", src, dst);
313 306
314 /* we seem to be getting the odd error from the pcm library due 307 /* we seem to be getting the odd error from the pcm library due
315 * to out-of-bounds pointers. this is maybe due to the dma engine 308 * to out-of-bounds pointers. this is maybe due to the dma engine
@@ -330,7 +323,7 @@ static int s3c24xx_pcm_open(struct snd_pcm_substream *substream)
330 struct snd_pcm_runtime *runtime = substream->runtime; 323 struct snd_pcm_runtime *runtime = substream->runtime;
331 struct s3c24xx_runtime_data *prtd; 324 struct s3c24xx_runtime_data *prtd;
332 325
333 DBG("Entered %s\n", __func__); 326 pr_debug("Entered %s\n", __func__);
334 327
335 snd_soc_set_runtime_hwparams(substream, &s3c24xx_pcm_hardware); 328 snd_soc_set_runtime_hwparams(substream, &s3c24xx_pcm_hardware);
336 329
@@ -349,10 +342,10 @@ static int s3c24xx_pcm_close(struct snd_pcm_substream *substream)
349 struct snd_pcm_runtime *runtime = substream->runtime; 342 struct snd_pcm_runtime *runtime = substream->runtime;
350 struct s3c24xx_runtime_data *prtd = runtime->private_data; 343 struct s3c24xx_runtime_data *prtd = runtime->private_data;
351 344
352 DBG("Entered %s\n", __func__); 345 pr_debug("Entered %s\n", __func__);
353 346
354 if (!prtd) 347 if (!prtd)
355 DBG("s3c24xx_pcm_close called with prtd == NULL\n"); 348 pr_debug("s3c24xx_pcm_close called with prtd == NULL\n");
356 349
357 kfree(prtd); 350 kfree(prtd);
358 351
@@ -364,7 +357,7 @@ static int s3c24xx_pcm_mmap(struct snd_pcm_substream *substream,
364{ 357{
365 struct snd_pcm_runtime *runtime = substream->runtime; 358 struct snd_pcm_runtime *runtime = substream->runtime;
366 359
367 DBG("Entered %s\n", __func__); 360 pr_debug("Entered %s\n", __func__);
368 361
369 return dma_mmap_writecombine(substream->pcm->card->dev, vma, 362 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
370 runtime->dma_area, 363 runtime->dma_area,
@@ -390,7 +383,7 @@ static int s3c24xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
390 struct snd_dma_buffer *buf = &substream->dma_buffer; 383 struct snd_dma_buffer *buf = &substream->dma_buffer;
391 size_t size = s3c24xx_pcm_hardware.buffer_bytes_max; 384 size_t size = s3c24xx_pcm_hardware.buffer_bytes_max;
392 385
393 DBG("Entered %s\n", __func__); 386 pr_debug("Entered %s\n", __func__);
394 387
395 buf->dev.type = SNDRV_DMA_TYPE_DEV; 388 buf->dev.type = SNDRV_DMA_TYPE_DEV;
396 buf->dev.dev = pcm->card->dev; 389 buf->dev.dev = pcm->card->dev;
@@ -409,7 +402,7 @@ static void s3c24xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
409 struct snd_dma_buffer *buf; 402 struct snd_dma_buffer *buf;
410 int stream; 403 int stream;
411 404
412 DBG("Entered %s\n", __func__); 405 pr_debug("Entered %s\n", __func__);
413 406
414 for (stream = 0; stream < 2; stream++) { 407 for (stream = 0; stream < 2; stream++) {
415 substream = pcm->streams[stream].substream; 408 substream = pcm->streams[stream].substream;
@@ -433,7 +426,7 @@ static int s3c24xx_pcm_new(struct snd_card *card,
433{ 426{
434 int ret = 0; 427 int ret = 0;
435 428
436 DBG("Entered %s\n", __func__); 429 pr_debug("Entered %s\n", __func__);
437 430
438 if (!card->dev->dma_mask) 431 if (!card->dev->dma_mask)
439 card->dev->dma_mask = &s3c24xx_pcm_dmamask; 432 card->dev->dma_mask = &s3c24xx_pcm_dmamask;
diff --git a/sound/soc/s3c24xx/s3c24xx_uda134x.c b/sound/soc/s3c24xx/s3c24xx_uda134x.c
index a0a4d1832a14..8e79a416db57 100644
--- a/sound/soc/s3c24xx/s3c24xx_uda134x.c
+++ b/sound/soc/s3c24xx/s3c24xx_uda134x.c
@@ -22,7 +22,7 @@
22#include <sound/s3c24xx_uda134x.h> 22#include <sound/s3c24xx_uda134x.h>
23#include <sound/uda134x.h> 23#include <sound/uda134x.h>
24 24
25#include <asm/plat-s3c24xx/regs-iis.h> 25#include <plat/regs-iis.h>
26 26
27#include "s3c24xx-pcm.h" 27#include "s3c24xx-pcm.h"
28#include "s3c24xx-i2s.h" 28#include "s3c24xx-i2s.h"
diff --git a/sound/soc/s3c24xx/s3c64xx-i2s.c b/sound/soc/s3c24xx/s3c64xx-i2s.c
new file mode 100644
index 000000000000..33c5de7e255f
--- /dev/null
+++ b/sound/soc/s3c24xx/s3c64xx-i2s.c
@@ -0,0 +1,222 @@
1/* sound/soc/s3c24xx/s3c64xx-i2s.c
2 *
3 * ALSA SoC Audio Layer - S3C64XX I2S driver
4 *
5 * Copyright 2008 Openmoko, Inc.
6 * Copyright 2008 Simtec Electronics
7 * Ben Dooks <ben@simtec.co.uk>
8 * http://armlinux.simtec.co.uk/
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/device.h>
18#include <linux/delay.h>
19#include <linux/clk.h>
20#include <linux/kernel.h>
21#include <linux/gpio.h>
22#include <linux/io.h>
23
24#include <sound/core.h>
25#include <sound/pcm.h>
26#include <sound/pcm_params.h>
27#include <sound/initval.h>
28#include <sound/soc.h>
29
30#include <plat/regs-s3c2412-iis.h>
31#include <plat/gpio-bank-d.h>
32#include <plat/gpio-bank-e.h>
33#include <plat/gpio-cfg.h>
34#include <plat/audio.h>
35
36#include <mach/map.h>
37#include <mach/dma.h>
38
39#include "s3c24xx-pcm.h"
40#include "s3c64xx-i2s.h"
41
42static struct s3c2410_dma_client s3c64xx_dma_client_out = {
43 .name = "I2S PCM Stereo out"
44};
45
46static struct s3c2410_dma_client s3c64xx_dma_client_in = {
47 .name = "I2S PCM Stereo in"
48};
49
50static struct s3c24xx_pcm_dma_params s3c64xx_i2s_pcm_stereo_out[2] = {
51 [0] = {
52 .channel = DMACH_I2S0_OUT,
53 .client = &s3c64xx_dma_client_out,
54 .dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISTXD,
55 .dma_size = 4,
56 },
57 [1] = {
58 .channel = DMACH_I2S1_OUT,
59 .client = &s3c64xx_dma_client_out,
60 .dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISTXD,
61 .dma_size = 4,
62 },
63};
64
65static struct s3c24xx_pcm_dma_params s3c64xx_i2s_pcm_stereo_in[2] = {
66 [0] = {
67 .channel = DMACH_I2S0_IN,
68 .client = &s3c64xx_dma_client_in,
69 .dma_addr = S3C64XX_PA_IIS0 + S3C2412_IISRXD,
70 .dma_size = 4,
71 },
72 [1] = {
73 .channel = DMACH_I2S1_IN,
74 .client = &s3c64xx_dma_client_in,
75 .dma_addr = S3C64XX_PA_IIS1 + S3C2412_IISRXD,
76 .dma_size = 4,
77 },
78};
79
80static struct s3c_i2sv2_info s3c64xx_i2s[2];
81
82static inline struct s3c_i2sv2_info *to_info(struct snd_soc_dai *cpu_dai)
83{
84 return cpu_dai->private_data;
85}
86
87static int s3c64xx_i2s_set_sysclk(struct snd_soc_dai *cpu_dai,
88 int clk_id, unsigned int freq, int dir)
89{
90 struct s3c_i2sv2_info *i2s = to_info(cpu_dai);
91 u32 iismod = readl(i2s->regs + S3C2412_IISMOD);
92
93 switch (clk_id) {
94 case S3C64XX_CLKSRC_PCLK:
95 iismod &= ~S3C64XX_IISMOD_IMS_SYSMUX;
96 break;
97
98 case S3C64XX_CLKSRC_MUX:
99 iismod |= S3C64XX_IISMOD_IMS_SYSMUX;
100 break;
101
102 default:
103 return -EINVAL;
104 }
105
106 writel(iismod, i2s->regs + S3C2412_IISMOD);
107
108 return 0;
109}
110
111
112unsigned long s3c64xx_i2s_get_clockrate(struct snd_soc_dai *dai)
113{
114 struct s3c_i2sv2_info *i2s = to_info(dai);
115
116 return clk_get_rate(i2s->iis_cclk);
117}
118EXPORT_SYMBOL_GPL(s3c64xx_i2s_get_clockrate);
119
120static int s3c64xx_i2s_probe(struct platform_device *pdev,
121 struct snd_soc_dai *dai)
122{
123 struct device *dev = &pdev->dev;
124 struct s3c_i2sv2_info *i2s;
125 int ret;
126
127 dev_dbg(dev, "%s: probing dai %d\n", __func__, pdev->id);
128
129 if (pdev->id < 0 || pdev->id > ARRAY_SIZE(s3c64xx_i2s)) {
130 dev_err(dev, "id %d out of range\n", pdev->id);
131 return -EINVAL;
132 }
133
134 i2s = &s3c64xx_i2s[pdev->id];
135
136 ret = s3c_i2sv2_probe(pdev, dai, i2s,
137 pdev->id ? S3C64XX_PA_IIS1 : S3C64XX_PA_IIS0);
138 if (ret)
139 return ret;
140
141 i2s->dma_capture = &s3c64xx_i2s_pcm_stereo_in[pdev->id];
142 i2s->dma_playback = &s3c64xx_i2s_pcm_stereo_out[pdev->id];
143
144 i2s->iis_cclk = clk_get(dev, "audio-bus");
145 if (IS_ERR(i2s->iis_cclk)) {
146 dev_err(dev, "failed to get audio-bus");
147 iounmap(i2s->regs);
148 return -ENODEV;
149 }
150
151 /* configure GPIO for i2s port */
152 switch (pdev->id) {
153 case 0:
154 s3c_gpio_cfgpin(S3C64XX_GPD(0), S3C64XX_GPD0_I2S0_CLK);
155 s3c_gpio_cfgpin(S3C64XX_GPD(1), S3C64XX_GPD1_I2S0_CDCLK);
156 s3c_gpio_cfgpin(S3C64XX_GPD(2), S3C64XX_GPD2_I2S0_LRCLK);
157 s3c_gpio_cfgpin(S3C64XX_GPD(3), S3C64XX_GPD3_I2S0_DI);
158 s3c_gpio_cfgpin(S3C64XX_GPD(4), S3C64XX_GPD4_I2S0_D0);
159 break;
160 case 1:
161 s3c_gpio_cfgpin(S3C64XX_GPE(0), S3C64XX_GPE0_I2S1_CLK);
162 s3c_gpio_cfgpin(S3C64XX_GPE(1), S3C64XX_GPE1_I2S1_CDCLK);
163 s3c_gpio_cfgpin(S3C64XX_GPE(2), S3C64XX_GPE2_I2S1_LRCLK);
164 s3c_gpio_cfgpin(S3C64XX_GPE(3), S3C64XX_GPE3_I2S1_DI);
165 s3c_gpio_cfgpin(S3C64XX_GPE(4), S3C64XX_GPE4_I2S1_D0);
166 }
167
168 return 0;
169}
170
171
172#define S3C64XX_I2S_RATES \
173 (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | SNDRV_PCM_RATE_16000 | \
174 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
175 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
176
177#define S3C64XX_I2S_FMTS \
178 (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE)
179
180static struct snd_soc_dai_ops s3c64xx_i2s_dai_ops = {
181 .set_sysclk = s3c64xx_i2s_set_sysclk,
182};
183
184struct snd_soc_dai s3c64xx_i2s_dai = {
185 .name = "s3c64xx-i2s",
186 .id = 0,
187 .probe = s3c64xx_i2s_probe,
188 .playback = {
189 .channels_min = 2,
190 .channels_max = 2,
191 .rates = S3C64XX_I2S_RATES,
192 .formats = S3C64XX_I2S_FMTS,
193 },
194 .capture = {
195 .channels_min = 2,
196 .channels_max = 2,
197 .rates = S3C64XX_I2S_RATES,
198 .formats = S3C64XX_I2S_FMTS,
199 },
200 .ops = &s3c64xx_i2s_dai_ops,
201};
202EXPORT_SYMBOL_GPL(s3c64xx_i2s_dai);
203
204static int __init s3c64xx_i2s_init(void)
205{
206 return s3c_i2sv2_register_dai(&s3c64xx_i2s_dai);
207}
208module_init(s3c64xx_i2s_init);
209
210static void __exit s3c64xx_i2s_exit(void)
211{
212 snd_soc_unregister_dai(&s3c64xx_i2s_dai);
213}
214module_exit(s3c64xx_i2s_exit);
215
216/* Module information */
217MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
218MODULE_DESCRIPTION("S3C64XX I2S SoC Interface");
219MODULE_LICENSE("GPL");
220
221
222
diff --git a/sound/soc/s3c24xx/s3c64xx-i2s.h b/sound/soc/s3c24xx/s3c64xx-i2s.h
new file mode 100644
index 000000000000..b7ffe3c38b66
--- /dev/null
+++ b/sound/soc/s3c24xx/s3c64xx-i2s.h
@@ -0,0 +1,31 @@
1/* sound/soc/s3c24xx/s3c64xx-i2s.h
2 *
3 * ALSA SoC Audio Layer - S3C64XX I2S driver
4 *
5 * Copyright 2008 Openmoko, Inc.
6 * Copyright 2008 Simtec Electronics
7 * Ben Dooks <ben@simtec.co.uk>
8 * http://armlinux.simtec.co.uk/
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 */
14
15#ifndef __SND_SOC_S3C24XX_S3C64XX_I2S_H
16#define __SND_SOC_S3C24XX_S3C64XX_I2S_H __FILE__
17
18#include "s3c-i2s-v2.h"
19
20#define S3C64XX_DIV_BCLK S3C_I2SV2_DIV_BCLK
21#define S3C64XX_DIV_RCLK S3C_I2SV2_DIV_RCLK
22#define S3C64XX_DIV_PRESCALER S3C_I2SV2_DIV_PRESCALER
23
24#define S3C64XX_CLKSRC_PCLK (0)
25#define S3C64XX_CLKSRC_MUX (1)
26
27extern struct snd_soc_dai s3c64xx_i2s_dai;
28
29extern unsigned long s3c64xx_i2s_get_clockrate(struct snd_soc_dai *cpu_dai);
30
31#endif /* __SND_SOC_S3C24XX_S3C64XX_I2S_H */
diff --git a/sound/soc/sh/hac.c b/sound/soc/sh/hac.c
index eab31838badf..41db75af3c69 100644
--- a/sound/soc/sh/hac.c
+++ b/sound/soc/sh/hac.c
@@ -267,6 +267,10 @@ static int hac_hw_params(struct snd_pcm_substream *substream,
267#define AC97_FMTS \ 267#define AC97_FMTS \
268 SNDRV_PCM_FMTBIT_S16_LE 268 SNDRV_PCM_FMTBIT_S16_LE
269 269
270static struct snd_soc_dai_ops hac_dai_ops = {
271 .hw_params = hac_hw_params,
272};
273
270struct snd_soc_dai sh4_hac_dai[] = { 274struct snd_soc_dai sh4_hac_dai[] = {
271{ 275{
272 .name = "HAC0", 276 .name = "HAC0",
@@ -284,9 +288,7 @@ struct snd_soc_dai sh4_hac_dai[] = {
284 .channels_min = 2, 288 .channels_min = 2,
285 .channels_max = 2, 289 .channels_max = 2,
286 }, 290 },
287 .ops = { 291 .ops = &hac_dai_ops,
288 .hw_params = hac_hw_params,
289 },
290}, 292},
291#ifdef CONFIG_CPU_SUBTYPE_SH7760 293#ifdef CONFIG_CPU_SUBTYPE_SH7760
292{ 294{
@@ -305,9 +307,7 @@ struct snd_soc_dai sh4_hac_dai[] = {
305 .channels_min = 2, 307 .channels_min = 2,
306 .channels_max = 2, 308 .channels_max = 2,
307 }, 309 },
308 .ops = { 310 .ops = &hac_dai_ops,
309 .hw_params = hac_hw_params,
310 },
311 311
312}, 312},
313#endif 313#endif
diff --git a/sound/soc/sh/ssi.c b/sound/soc/sh/ssi.c
index d1e5390fddeb..56fa0872abbb 100644
--- a/sound/soc/sh/ssi.c
+++ b/sound/soc/sh/ssi.c
@@ -336,6 +336,16 @@ static int ssi_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
336 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3LE | \ 336 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3LE | \
337 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_U32_LE) 337 SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_U32_LE)
338 338
339static struct snd_soc_dai_ops ssi_dai_ops = {
340 .startup = ssi_startup,
341 .shutdown = ssi_shutdown,
342 .trigger = ssi_trigger,
343 .hw_params = ssi_hw_params,
344 .set_sysclk = ssi_set_sysclk,
345 .set_clkdiv = ssi_set_clkdiv,
346 .set_fmt = ssi_set_fmt,
347};
348
339struct snd_soc_dai sh4_ssi_dai[] = { 349struct snd_soc_dai sh4_ssi_dai[] = {
340{ 350{
341 .name = "SSI0", 351 .name = "SSI0",
@@ -352,15 +362,7 @@ struct snd_soc_dai sh4_ssi_dai[] = {
352 .channels_min = 2, 362 .channels_min = 2,
353 .channels_max = 8, 363 .channels_max = 8,
354 }, 364 },
355 .ops = { 365 .ops = &ssi_dai_ops,
356 .startup = ssi_startup,
357 .shutdown = ssi_shutdown,
358 .trigger = ssi_trigger,
359 .hw_params = ssi_hw_params,
360 .set_sysclk = ssi_set_sysclk,
361 .set_clkdiv = ssi_set_clkdiv,
362 .set_fmt = ssi_set_fmt,
363 },
364}, 366},
365#ifdef CONFIG_CPU_SUBTYPE_SH7760 367#ifdef CONFIG_CPU_SUBTYPE_SH7760
366{ 368{
@@ -378,15 +380,7 @@ struct snd_soc_dai sh4_ssi_dai[] = {
378 .channels_min = 2, 380 .channels_min = 2,
379 .channels_max = 8, 381 .channels_max = 8,
380 }, 382 },
381 .ops = { 383 .ops = &ssi_dai_ops,
382 .startup = ssi_startup,
383 .shutdown = ssi_shutdown,
384 .trigger = ssi_trigger,
385 .hw_params = ssi_hw_params,
386 .set_sysclk = ssi_set_sysclk,
387 .set_clkdiv = ssi_set_clkdiv,
388 .set_fmt = ssi_set_fmt,
389 },
390}, 384},
391#endif 385#endif
392}; 386};
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index ec3f8bb4b51d..6e710f705a74 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -133,8 +133,8 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
133 mutex_lock(&pcm_mutex); 133 mutex_lock(&pcm_mutex);
134 134
135 /* startup the audio subsystem */ 135 /* startup the audio subsystem */
136 if (cpu_dai->ops.startup) { 136 if (cpu_dai->ops->startup) {
137 ret = cpu_dai->ops.startup(substream, cpu_dai); 137 ret = cpu_dai->ops->startup(substream, cpu_dai);
138 if (ret < 0) { 138 if (ret < 0) {
139 printk(KERN_ERR "asoc: can't open interface %s\n", 139 printk(KERN_ERR "asoc: can't open interface %s\n",
140 cpu_dai->name); 140 cpu_dai->name);
@@ -150,8 +150,8 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
150 } 150 }
151 } 151 }
152 152
153 if (codec_dai->ops.startup) { 153 if (codec_dai->ops->startup) {
154 ret = codec_dai->ops.startup(substream, codec_dai); 154 ret = codec_dai->ops->startup(substream, codec_dai);
155 if (ret < 0) { 155 if (ret < 0) {
156 printk(KERN_ERR "asoc: can't open codec %s\n", 156 printk(KERN_ERR "asoc: can't open codec %s\n",
157 codec_dai->name); 157 codec_dai->name);
@@ -234,7 +234,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
234 cpu_dai->capture.active = codec_dai->capture.active = 1; 234 cpu_dai->capture.active = codec_dai->capture.active = 1;
235 cpu_dai->active = codec_dai->active = 1; 235 cpu_dai->active = codec_dai->active = 1;
236 cpu_dai->runtime = runtime; 236 cpu_dai->runtime = runtime;
237 socdev->codec->active++; 237 card->codec->active++;
238 mutex_unlock(&pcm_mutex); 238 mutex_unlock(&pcm_mutex);
239 return 0; 239 return 0;
240 240
@@ -247,8 +247,8 @@ codec_dai_err:
247 platform->pcm_ops->close(substream); 247 platform->pcm_ops->close(substream);
248 248
249platform_err: 249platform_err:
250 if (cpu_dai->ops.shutdown) 250 if (cpu_dai->ops->shutdown)
251 cpu_dai->ops.shutdown(substream, cpu_dai); 251 cpu_dai->ops->shutdown(substream, cpu_dai);
252out: 252out:
253 mutex_unlock(&pcm_mutex); 253 mutex_unlock(&pcm_mutex);
254 return ret; 254 return ret;
@@ -264,7 +264,7 @@ static void close_delayed_work(struct work_struct *work)
264 struct snd_soc_card *card = container_of(work, struct snd_soc_card, 264 struct snd_soc_card *card = container_of(work, struct snd_soc_card,
265 delayed_work.work); 265 delayed_work.work);
266 struct snd_soc_device *socdev = card->socdev; 266 struct snd_soc_device *socdev = card->socdev;
267 struct snd_soc_codec *codec = socdev->codec; 267 struct snd_soc_codec *codec = card->codec;
268 struct snd_soc_dai *codec_dai; 268 struct snd_soc_dai *codec_dai;
269 int i; 269 int i;
270 270
@@ -319,7 +319,7 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
319 struct snd_soc_platform *platform = card->platform; 319 struct snd_soc_platform *platform = card->platform;
320 struct snd_soc_dai *cpu_dai = machine->cpu_dai; 320 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
321 struct snd_soc_dai *codec_dai = machine->codec_dai; 321 struct snd_soc_dai *codec_dai = machine->codec_dai;
322 struct snd_soc_codec *codec = socdev->codec; 322 struct snd_soc_codec *codec = card->codec;
323 323
324 mutex_lock(&pcm_mutex); 324 mutex_lock(&pcm_mutex);
325 325
@@ -340,11 +340,11 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
340 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 340 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
341 snd_soc_dai_digital_mute(codec_dai, 1); 341 snd_soc_dai_digital_mute(codec_dai, 1);
342 342
343 if (cpu_dai->ops.shutdown) 343 if (cpu_dai->ops->shutdown)
344 cpu_dai->ops.shutdown(substream, cpu_dai); 344 cpu_dai->ops->shutdown(substream, cpu_dai);
345 345
346 if (codec_dai->ops.shutdown) 346 if (codec_dai->ops->shutdown)
347 codec_dai->ops.shutdown(substream, codec_dai); 347 codec_dai->ops->shutdown(substream, codec_dai);
348 348
349 if (machine->ops && machine->ops->shutdown) 349 if (machine->ops && machine->ops->shutdown)
350 machine->ops->shutdown(substream); 350 machine->ops->shutdown(substream);
@@ -387,7 +387,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
387 struct snd_soc_platform *platform = card->platform; 387 struct snd_soc_platform *platform = card->platform;
388 struct snd_soc_dai *cpu_dai = machine->cpu_dai; 388 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
389 struct snd_soc_dai *codec_dai = machine->codec_dai; 389 struct snd_soc_dai *codec_dai = machine->codec_dai;
390 struct snd_soc_codec *codec = socdev->codec; 390 struct snd_soc_codec *codec = card->codec;
391 int ret = 0; 391 int ret = 0;
392 392
393 mutex_lock(&pcm_mutex); 393 mutex_lock(&pcm_mutex);
@@ -408,16 +408,16 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
408 } 408 }
409 } 409 }
410 410
411 if (codec_dai->ops.prepare) { 411 if (codec_dai->ops->prepare) {
412 ret = codec_dai->ops.prepare(substream, codec_dai); 412 ret = codec_dai->ops->prepare(substream, codec_dai);
413 if (ret < 0) { 413 if (ret < 0) {
414 printk(KERN_ERR "asoc: codec DAI prepare error\n"); 414 printk(KERN_ERR "asoc: codec DAI prepare error\n");
415 goto out; 415 goto out;
416 } 416 }
417 } 417 }
418 418
419 if (cpu_dai->ops.prepare) { 419 if (cpu_dai->ops->prepare) {
420 ret = cpu_dai->ops.prepare(substream, cpu_dai); 420 ret = cpu_dai->ops->prepare(substream, cpu_dai);
421 if (ret < 0) { 421 if (ret < 0) {
422 printk(KERN_ERR "asoc: cpu DAI prepare error\n"); 422 printk(KERN_ERR "asoc: cpu DAI prepare error\n");
423 goto out; 423 goto out;
@@ -494,8 +494,8 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
494 } 494 }
495 } 495 }
496 496
497 if (codec_dai->ops.hw_params) { 497 if (codec_dai->ops->hw_params) {
498 ret = codec_dai->ops.hw_params(substream, params, codec_dai); 498 ret = codec_dai->ops->hw_params(substream, params, codec_dai);
499 if (ret < 0) { 499 if (ret < 0) {
500 printk(KERN_ERR "asoc: can't set codec %s hw params\n", 500 printk(KERN_ERR "asoc: can't set codec %s hw params\n",
501 codec_dai->name); 501 codec_dai->name);
@@ -503,8 +503,8 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
503 } 503 }
504 } 504 }
505 505
506 if (cpu_dai->ops.hw_params) { 506 if (cpu_dai->ops->hw_params) {
507 ret = cpu_dai->ops.hw_params(substream, params, cpu_dai); 507 ret = cpu_dai->ops->hw_params(substream, params, cpu_dai);
508 if (ret < 0) { 508 if (ret < 0) {
509 printk(KERN_ERR "asoc: interface %s hw params failed\n", 509 printk(KERN_ERR "asoc: interface %s hw params failed\n",
510 cpu_dai->name); 510 cpu_dai->name);
@@ -526,12 +526,12 @@ out:
526 return ret; 526 return ret;
527 527
528platform_err: 528platform_err:
529 if (cpu_dai->ops.hw_free) 529 if (cpu_dai->ops->hw_free)
530 cpu_dai->ops.hw_free(substream, cpu_dai); 530 cpu_dai->ops->hw_free(substream, cpu_dai);
531 531
532interface_err: 532interface_err:
533 if (codec_dai->ops.hw_free) 533 if (codec_dai->ops->hw_free)
534 codec_dai->ops.hw_free(substream, codec_dai); 534 codec_dai->ops->hw_free(substream, codec_dai);
535 535
536codec_err: 536codec_err:
537 if (machine->ops && machine->ops->hw_free) 537 if (machine->ops && machine->ops->hw_free)
@@ -553,7 +553,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
553 struct snd_soc_platform *platform = card->platform; 553 struct snd_soc_platform *platform = card->platform;
554 struct snd_soc_dai *cpu_dai = machine->cpu_dai; 554 struct snd_soc_dai *cpu_dai = machine->cpu_dai;
555 struct snd_soc_dai *codec_dai = machine->codec_dai; 555 struct snd_soc_dai *codec_dai = machine->codec_dai;
556 struct snd_soc_codec *codec = socdev->codec; 556 struct snd_soc_codec *codec = card->codec;
557 557
558 mutex_lock(&pcm_mutex); 558 mutex_lock(&pcm_mutex);
559 559
@@ -570,11 +570,11 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
570 platform->pcm_ops->hw_free(substream); 570 platform->pcm_ops->hw_free(substream);
571 571
572 /* now free hw params for the DAI's */ 572 /* now free hw params for the DAI's */
573 if (codec_dai->ops.hw_free) 573 if (codec_dai->ops->hw_free)
574 codec_dai->ops.hw_free(substream, codec_dai); 574 codec_dai->ops->hw_free(substream, codec_dai);
575 575
576 if (cpu_dai->ops.hw_free) 576 if (cpu_dai->ops->hw_free)
577 cpu_dai->ops.hw_free(substream, cpu_dai); 577 cpu_dai->ops->hw_free(substream, cpu_dai);
578 578
579 mutex_unlock(&pcm_mutex); 579 mutex_unlock(&pcm_mutex);
580 return 0; 580 return 0;
@@ -591,8 +591,8 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
591 struct snd_soc_dai *codec_dai = machine->codec_dai; 591 struct snd_soc_dai *codec_dai = machine->codec_dai;
592 int ret; 592 int ret;
593 593
594 if (codec_dai->ops.trigger) { 594 if (codec_dai->ops->trigger) {
595 ret = codec_dai->ops.trigger(substream, cmd, codec_dai); 595 ret = codec_dai->ops->trigger(substream, cmd, codec_dai);
596 if (ret < 0) 596 if (ret < 0)
597 return ret; 597 return ret;
598 } 598 }
@@ -603,8 +603,8 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
603 return ret; 603 return ret;
604 } 604 }
605 605
606 if (cpu_dai->ops.trigger) { 606 if (cpu_dai->ops->trigger) {
607 ret = cpu_dai->ops.trigger(substream, cmd, cpu_dai); 607 ret = cpu_dai->ops->trigger(substream, cmd, cpu_dai);
608 if (ret < 0) 608 if (ret < 0)
609 return ret; 609 return ret;
610 } 610 }
@@ -629,7 +629,7 @@ static int soc_suspend(struct platform_device *pdev, pm_message_t state)
629 struct snd_soc_card *card = socdev->card; 629 struct snd_soc_card *card = socdev->card;
630 struct snd_soc_platform *platform = card->platform; 630 struct snd_soc_platform *platform = card->platform;
631 struct snd_soc_codec_device *codec_dev = socdev->codec_dev; 631 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
632 struct snd_soc_codec *codec = socdev->codec; 632 struct snd_soc_codec *codec = card->codec;
633 int i; 633 int i;
634 634
635 /* Due to the resume being scheduled into a workqueue we could 635 /* Due to the resume being scheduled into a workqueue we could
@@ -645,8 +645,8 @@ static int soc_suspend(struct platform_device *pdev, pm_message_t state)
645 /* mute any active DAC's */ 645 /* mute any active DAC's */
646 for (i = 0; i < card->num_links; i++) { 646 for (i = 0; i < card->num_links; i++) {
647 struct snd_soc_dai *dai = card->dai_link[i].codec_dai; 647 struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
648 if (dai->ops.digital_mute && dai->playback.active) 648 if (dai->ops->digital_mute && dai->playback.active)
649 dai->ops.digital_mute(dai, 1); 649 dai->ops->digital_mute(dai, 1);
650 } 650 }
651 651
652 /* suspend all pcms */ 652 /* suspend all pcms */
@@ -705,7 +705,7 @@ static void soc_resume_deferred(struct work_struct *work)
705 struct snd_soc_device *socdev = card->socdev; 705 struct snd_soc_device *socdev = card->socdev;
706 struct snd_soc_platform *platform = card->platform; 706 struct snd_soc_platform *platform = card->platform;
707 struct snd_soc_codec_device *codec_dev = socdev->codec_dev; 707 struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
708 struct snd_soc_codec *codec = socdev->codec; 708 struct snd_soc_codec *codec = card->codec;
709 struct platform_device *pdev = to_platform_device(socdev->dev); 709 struct platform_device *pdev = to_platform_device(socdev->dev);
710 int i; 710 int i;
711 711
@@ -741,8 +741,8 @@ static void soc_resume_deferred(struct work_struct *work)
741 /* unmute any active DACs */ 741 /* unmute any active DACs */
742 for (i = 0; i < card->num_links; i++) { 742 for (i = 0; i < card->num_links; i++) {
743 struct snd_soc_dai *dai = card->dai_link[i].codec_dai; 743 struct snd_soc_dai *dai = card->dai_link[i].codec_dai;
744 if (dai->ops.digital_mute && dai->playback.active) 744 if (dai->ops->digital_mute && dai->playback.active)
745 dai->ops.digital_mute(dai, 0); 745 dai->ops->digital_mute(dai, 0);
746 } 746 }
747 747
748 for (i = 0; i < card->num_links; i++) { 748 for (i = 0; i < card->num_links; i++) {
@@ -982,8 +982,8 @@ static struct platform_driver soc_driver = {
982static int soc_new_pcm(struct snd_soc_device *socdev, 982static int soc_new_pcm(struct snd_soc_device *socdev,
983 struct snd_soc_dai_link *dai_link, int num) 983 struct snd_soc_dai_link *dai_link, int num)
984{ 984{
985 struct snd_soc_codec *codec = socdev->codec;
986 struct snd_soc_card *card = socdev->card; 985 struct snd_soc_card *card = socdev->card;
986 struct snd_soc_codec *codec = card->codec;
987 struct snd_soc_platform *platform = card->platform; 987 struct snd_soc_platform *platform = card->platform;
988 struct snd_soc_dai *codec_dai = dai_link->codec_dai; 988 struct snd_soc_dai *codec_dai = dai_link->codec_dai;
989 struct snd_soc_dai *cpu_dai = dai_link->cpu_dai; 989 struct snd_soc_dai *cpu_dai = dai_link->cpu_dai;
@@ -998,7 +998,7 @@ static int soc_new_pcm(struct snd_soc_device *socdev,
998 998
999 rtd->dai = dai_link; 999 rtd->dai = dai_link;
1000 rtd->socdev = socdev; 1000 rtd->socdev = socdev;
1001 codec_dai->codec = socdev->codec; 1001 codec_dai->codec = card->codec;
1002 1002
1003 /* check client and interface hw capabilities */ 1003 /* check client and interface hw capabilities */
1004 sprintf(new_name, "%s %s-%d", dai_link->stream_name, codec_dai->name, 1004 sprintf(new_name, "%s %s-%d", dai_link->stream_name, codec_dai->name,
@@ -1048,9 +1048,8 @@ static int soc_new_pcm(struct snd_soc_device *socdev,
1048} 1048}
1049 1049
1050/* codec register dump */ 1050/* codec register dump */
1051static ssize_t soc_codec_reg_show(struct snd_soc_device *devdata, char *buf) 1051static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
1052{ 1052{
1053 struct snd_soc_codec *codec = devdata->codec;
1054 int i, step = 1, count = 0; 1053 int i, step = 1, count = 0;
1055 1054
1056 if (!codec->reg_cache_size) 1055 if (!codec->reg_cache_size)
@@ -1090,7 +1089,7 @@ static ssize_t codec_reg_show(struct device *dev,
1090 struct device_attribute *attr, char *buf) 1089 struct device_attribute *attr, char *buf)
1091{ 1090{
1092 struct snd_soc_device *devdata = dev_get_drvdata(dev); 1091 struct snd_soc_device *devdata = dev_get_drvdata(dev);
1093 return soc_codec_reg_show(devdata, buf); 1092 return soc_codec_reg_show(devdata->card->codec, buf);
1094} 1093}
1095 1094
1096static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL); 1095static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
@@ -1107,12 +1106,10 @@ static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
1107{ 1106{
1108 ssize_t ret; 1107 ssize_t ret;
1109 struct snd_soc_codec *codec = file->private_data; 1108 struct snd_soc_codec *codec = file->private_data;
1110 struct device *card_dev = codec->card->dev;
1111 struct snd_soc_device *devdata = card_dev->driver_data;
1112 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL); 1109 char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
1113 if (!buf) 1110 if (!buf)
1114 return -ENOMEM; 1111 return -ENOMEM;
1115 ret = soc_codec_reg_show(devdata, buf); 1112 ret = soc_codec_reg_show(codec, buf);
1116 if (ret >= 0) 1113 if (ret >= 0)
1117 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret); 1114 ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
1118 kfree(buf); 1115 kfree(buf);
@@ -1309,19 +1306,19 @@ EXPORT_SYMBOL_GPL(snd_soc_test_bits);
1309 */ 1306 */
1310int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid) 1307int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
1311{ 1308{
1312 struct snd_soc_codec *codec = socdev->codec;
1313 struct snd_soc_card *card = socdev->card; 1309 struct snd_soc_card *card = socdev->card;
1314 int ret = 0, i; 1310 struct snd_soc_codec *codec = card->codec;
1311 int ret, i;
1315 1312
1316 mutex_lock(&codec->mutex); 1313 mutex_lock(&codec->mutex);
1317 1314
1318 /* register a sound card */ 1315 /* register a sound card */
1319 codec->card = snd_card_new(idx, xid, codec->owner, 0); 1316 ret = snd_card_create(idx, xid, codec->owner, 0, &codec->card);
1320 if (!codec->card) { 1317 if (ret < 0) {
1321 printk(KERN_ERR "asoc: can't create sound card for codec %s\n", 1318 printk(KERN_ERR "asoc: can't create sound card for codec %s\n",
1322 codec->name); 1319 codec->name);
1323 mutex_unlock(&codec->mutex); 1320 mutex_unlock(&codec->mutex);
1324 return -ENODEV; 1321 return ret;
1325 } 1322 }
1326 1323
1327 codec->card->dev = socdev->dev; 1324 codec->card->dev = socdev->dev;
@@ -1355,8 +1352,8 @@ EXPORT_SYMBOL_GPL(snd_soc_new_pcms);
1355 */ 1352 */
1356int snd_soc_init_card(struct snd_soc_device *socdev) 1353int snd_soc_init_card(struct snd_soc_device *socdev)
1357{ 1354{
1358 struct snd_soc_codec *codec = socdev->codec;
1359 struct snd_soc_card *card = socdev->card; 1355 struct snd_soc_card *card = socdev->card;
1356 struct snd_soc_codec *codec = card->codec;
1360 int ret = 0, i, ac97 = 0, err = 0; 1357 int ret = 0, i, ac97 = 0, err = 0;
1361 1358
1362 for (i = 0; i < card->num_links; i++) { 1359 for (i = 0; i < card->num_links; i++) {
@@ -1407,7 +1404,7 @@ int snd_soc_init_card(struct snd_soc_device *socdev)
1407 if (err < 0) 1404 if (err < 0)
1408 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n"); 1405 printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
1409 1406
1410 soc_init_codec_debugfs(socdev->codec); 1407 soc_init_codec_debugfs(codec);
1411 mutex_unlock(&codec->mutex); 1408 mutex_unlock(&codec->mutex);
1412 1409
1413out: 1410out:
@@ -1424,18 +1421,19 @@ EXPORT_SYMBOL_GPL(snd_soc_init_card);
1424 */ 1421 */
1425void snd_soc_free_pcms(struct snd_soc_device *socdev) 1422void snd_soc_free_pcms(struct snd_soc_device *socdev)
1426{ 1423{
1427 struct snd_soc_codec *codec = socdev->codec; 1424 struct snd_soc_codec *codec = socdev->card->codec;
1428#ifdef CONFIG_SND_SOC_AC97_BUS 1425#ifdef CONFIG_SND_SOC_AC97_BUS
1429 struct snd_soc_dai *codec_dai; 1426 struct snd_soc_dai *codec_dai;
1430 int i; 1427 int i;
1431#endif 1428#endif
1432 1429
1433 mutex_lock(&codec->mutex); 1430 mutex_lock(&codec->mutex);
1434 soc_cleanup_codec_debugfs(socdev->codec); 1431 soc_cleanup_codec_debugfs(codec);
1435#ifdef CONFIG_SND_SOC_AC97_BUS 1432#ifdef CONFIG_SND_SOC_AC97_BUS
1436 for (i = 0; i < codec->num_dai; i++) { 1433 for (i = 0; i < codec->num_dai; i++) {
1437 codec_dai = &codec->dai[i]; 1434 codec_dai = &codec->dai[i];
1438 if (codec_dai->ac97_control && codec->ac97) { 1435 if (codec_dai->ac97_control && codec->ac97 &&
1436 strcmp(codec->name, "AC97") != 0) {
1439 soc_ac97_dev_unregister(codec); 1437 soc_ac97_dev_unregister(codec);
1440 goto free_card; 1438 goto free_card;
1441 } 1439 }
@@ -1498,6 +1496,37 @@ struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
1498EXPORT_SYMBOL_GPL(snd_soc_cnew); 1496EXPORT_SYMBOL_GPL(snd_soc_cnew);
1499 1497
1500/** 1498/**
1499 * snd_soc_add_controls - add an array of controls to a codec.
1500 * Convienience function to add a list of controls. Many codecs were
1501 * duplicating this code.
1502 *
1503 * @codec: codec to add controls to
1504 * @controls: array of controls to add
1505 * @num_controls: number of elements in the array
1506 *
1507 * Return 0 for success, else error.
1508 */
1509int snd_soc_add_controls(struct snd_soc_codec *codec,
1510 const struct snd_kcontrol_new *controls, int num_controls)
1511{
1512 struct snd_card *card = codec->card;
1513 int err, i;
1514
1515 for (i = 0; i < num_controls; i++) {
1516 const struct snd_kcontrol_new *control = &controls[i];
1517 err = snd_ctl_add(card, snd_soc_cnew(control, codec, NULL));
1518 if (err < 0) {
1519 dev_err(codec->dev, "%s: Failed to add %s\n",
1520 codec->name, control->name);
1521 return err;
1522 }
1523 }
1524
1525 return 0;
1526}
1527EXPORT_SYMBOL_GPL(snd_soc_add_controls);
1528
1529/**
1501 * snd_soc_info_enum_double - enumerated double mixer info callback 1530 * snd_soc_info_enum_double - enumerated double mixer info callback
1502 * @kcontrol: mixer control 1531 * @kcontrol: mixer control
1503 * @uinfo: control element information 1532 * @uinfo: control element information
@@ -2023,8 +2052,8 @@ EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
2023int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id, 2052int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
2024 unsigned int freq, int dir) 2053 unsigned int freq, int dir)
2025{ 2054{
2026 if (dai->ops.set_sysclk) 2055 if (dai->ops->set_sysclk)
2027 return dai->ops.set_sysclk(dai, clk_id, freq, dir); 2056 return dai->ops->set_sysclk(dai, clk_id, freq, dir);
2028 else 2057 else
2029 return -EINVAL; 2058 return -EINVAL;
2030} 2059}
@@ -2043,8 +2072,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
2043int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai, 2072int snd_soc_dai_set_clkdiv(struct snd_soc_dai *dai,
2044 int div_id, int div) 2073 int div_id, int div)
2045{ 2074{
2046 if (dai->ops.set_clkdiv) 2075 if (dai->ops->set_clkdiv)
2047 return dai->ops.set_clkdiv(dai, div_id, div); 2076 return dai->ops->set_clkdiv(dai, div_id, div);
2048 else 2077 else
2049 return -EINVAL; 2078 return -EINVAL;
2050} 2079}
@@ -2062,8 +2091,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_clkdiv);
2062int snd_soc_dai_set_pll(struct snd_soc_dai *dai, 2091int snd_soc_dai_set_pll(struct snd_soc_dai *dai,
2063 int pll_id, unsigned int freq_in, unsigned int freq_out) 2092 int pll_id, unsigned int freq_in, unsigned int freq_out)
2064{ 2093{
2065 if (dai->ops.set_pll) 2094 if (dai->ops->set_pll)
2066 return dai->ops.set_pll(dai, pll_id, freq_in, freq_out); 2095 return dai->ops->set_pll(dai, pll_id, freq_in, freq_out);
2067 else 2096 else
2068 return -EINVAL; 2097 return -EINVAL;
2069} 2098}
@@ -2078,8 +2107,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
2078 */ 2107 */
2079int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) 2108int snd_soc_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2080{ 2109{
2081 if (dai->ops.set_fmt) 2110 if (dai->ops->set_fmt)
2082 return dai->ops.set_fmt(dai, fmt); 2111 return dai->ops->set_fmt(dai, fmt);
2083 else 2112 else
2084 return -EINVAL; 2113 return -EINVAL;
2085} 2114}
@@ -2097,8 +2126,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_fmt);
2097int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai, 2126int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
2098 unsigned int mask, int slots) 2127 unsigned int mask, int slots)
2099{ 2128{
2100 if (dai->ops.set_sysclk) 2129 if (dai->ops->set_sysclk)
2101 return dai->ops.set_tdm_slot(dai, mask, slots); 2130 return dai->ops->set_tdm_slot(dai, mask, slots);
2102 else 2131 else
2103 return -EINVAL; 2132 return -EINVAL;
2104} 2133}
@@ -2113,8 +2142,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_tdm_slot);
2113 */ 2142 */
2114int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate) 2143int snd_soc_dai_set_tristate(struct snd_soc_dai *dai, int tristate)
2115{ 2144{
2116 if (dai->ops.set_sysclk) 2145 if (dai->ops->set_sysclk)
2117 return dai->ops.set_tristate(dai, tristate); 2146 return dai->ops->set_tristate(dai, tristate);
2118 else 2147 else
2119 return -EINVAL; 2148 return -EINVAL;
2120} 2149}
@@ -2129,8 +2158,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_tristate);
2129 */ 2158 */
2130int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute) 2159int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute)
2131{ 2160{
2132 if (dai->ops.digital_mute) 2161 if (dai->ops->digital_mute)
2133 return dai->ops.digital_mute(dai, mute); 2162 return dai->ops->digital_mute(dai, mute);
2134 else 2163 else
2135 return -EINVAL; 2164 return -EINVAL;
2136} 2165}
@@ -2183,6 +2212,9 @@ static int snd_soc_unregister_card(struct snd_soc_card *card)
2183 return 0; 2212 return 0;
2184} 2213}
2185 2214
2215static struct snd_soc_dai_ops null_dai_ops = {
2216};
2217
2186/** 2218/**
2187 * snd_soc_register_dai - Register a DAI with the ASoC core 2219 * snd_soc_register_dai - Register a DAI with the ASoC core
2188 * 2220 *
@@ -2197,6 +2229,9 @@ int snd_soc_register_dai(struct snd_soc_dai *dai)
2197 if (!dai->dev) 2229 if (!dai->dev)
2198 printk(KERN_WARNING "No device for DAI %s\n", dai->name); 2230 printk(KERN_WARNING "No device for DAI %s\n", dai->name);
2199 2231
2232 if (!dai->ops)
2233 dai->ops = &null_dai_ops;
2234
2200 INIT_LIST_HEAD(&dai->list); 2235 INIT_LIST_HEAD(&dai->list);
2201 2236
2202 mutex_lock(&client_mutex); 2237 mutex_lock(&client_mutex);
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index a2f1da8b4646..735903a74675 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -54,14 +54,15 @@
54static int dapm_up_seq[] = { 54static int dapm_up_seq[] = {
55 snd_soc_dapm_pre, snd_soc_dapm_micbias, snd_soc_dapm_mic, 55 snd_soc_dapm_pre, snd_soc_dapm_micbias, snd_soc_dapm_mic,
56 snd_soc_dapm_mux, snd_soc_dapm_value_mux, snd_soc_dapm_dac, 56 snd_soc_dapm_mux, snd_soc_dapm_value_mux, snd_soc_dapm_dac,
57 snd_soc_dapm_mixer, snd_soc_dapm_pga, snd_soc_dapm_adc, snd_soc_dapm_hp, 57 snd_soc_dapm_mixer, snd_soc_dapm_mixer_named_ctl, snd_soc_dapm_pga,
58 snd_soc_dapm_spk, snd_soc_dapm_post 58 snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk, snd_soc_dapm_post
59}; 59};
60
60static int dapm_down_seq[] = { 61static int dapm_down_seq[] = {
61 snd_soc_dapm_pre, snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk, 62 snd_soc_dapm_pre, snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk,
62 snd_soc_dapm_pga, snd_soc_dapm_mixer, snd_soc_dapm_dac, snd_soc_dapm_mic, 63 snd_soc_dapm_pga, snd_soc_dapm_mixer_named_ctl, snd_soc_dapm_mixer,
63 snd_soc_dapm_micbias, snd_soc_dapm_mux, snd_soc_dapm_value_mux, 64 snd_soc_dapm_dac, snd_soc_dapm_mic, snd_soc_dapm_micbias,
64 snd_soc_dapm_post 65 snd_soc_dapm_mux, snd_soc_dapm_value_mux, snd_soc_dapm_post
65}; 66};
66 67
67static int dapm_status = 1; 68static int dapm_status = 1;
@@ -101,7 +102,8 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
101{ 102{
102 switch (w->id) { 103 switch (w->id) {
103 case snd_soc_dapm_switch: 104 case snd_soc_dapm_switch:
104 case snd_soc_dapm_mixer: { 105 case snd_soc_dapm_mixer:
106 case snd_soc_dapm_mixer_named_ctl: {
105 int val; 107 int val;
106 struct soc_mixer_control *mc = (struct soc_mixer_control *) 108 struct soc_mixer_control *mc = (struct soc_mixer_control *)
107 w->kcontrols[i].private_value; 109 w->kcontrols[i].private_value;
@@ -323,15 +325,32 @@ static int dapm_new_mixer(struct snd_soc_codec *codec,
323 if (path->name != (char*)w->kcontrols[i].name) 325 if (path->name != (char*)w->kcontrols[i].name)
324 continue; 326 continue;
325 327
326 /* add dapm control with long name */ 328 /* add dapm control with long name.
327 name_len = 2 + strlen(w->name) 329 * for dapm_mixer this is the concatenation of the
328 + strlen(w->kcontrols[i].name); 330 * mixer and kcontrol name.
331 * for dapm_mixer_named_ctl this is simply the
332 * kcontrol name.
333 */
334 name_len = strlen(w->kcontrols[i].name) + 1;
335 if (w->id != snd_soc_dapm_mixer_named_ctl)
336 name_len += 1 + strlen(w->name);
337
329 path->long_name = kmalloc(name_len, GFP_KERNEL); 338 path->long_name = kmalloc(name_len, GFP_KERNEL);
339
330 if (path->long_name == NULL) 340 if (path->long_name == NULL)
331 return -ENOMEM; 341 return -ENOMEM;
332 342
333 snprintf(path->long_name, name_len, "%s %s", 343 switch (w->id) {
334 w->name, w->kcontrols[i].name); 344 default:
345 snprintf(path->long_name, name_len, "%s %s",
346 w->name, w->kcontrols[i].name);
347 break;
348 case snd_soc_dapm_mixer_named_ctl:
349 snprintf(path->long_name, name_len, "%s",
350 w->kcontrols[i].name);
351 break;
352 }
353
335 path->long_name[name_len - 1] = '\0'; 354 path->long_name[name_len - 1] = '\0';
336 355
337 path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w, 356 path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
@@ -503,6 +522,137 @@ int dapm_reg_event(struct snd_soc_dapm_widget *w,
503EXPORT_SYMBOL_GPL(dapm_reg_event); 522EXPORT_SYMBOL_GPL(dapm_reg_event);
504 523
505/* 524/*
525 * Scan a single DAPM widget for a complete audio path and update the
526 * power status appropriately.
527 */
528static int dapm_power_widget(struct snd_soc_codec *codec, int event,
529 struct snd_soc_dapm_widget *w)
530{
531 int in, out, power_change, power, ret;
532
533 /* vmid - no action */
534 if (w->id == snd_soc_dapm_vmid)
535 return 0;
536
537 /* active ADC */
538 if (w->id == snd_soc_dapm_adc && w->active) {
539 in = is_connected_input_ep(w);
540 dapm_clear_walk(w->codec);
541 w->power = (in != 0) ? 1 : 0;
542 dapm_update_bits(w);
543 return 0;
544 }
545
546 /* active DAC */
547 if (w->id == snd_soc_dapm_dac && w->active) {
548 out = is_connected_output_ep(w);
549 dapm_clear_walk(w->codec);
550 w->power = (out != 0) ? 1 : 0;
551 dapm_update_bits(w);
552 return 0;
553 }
554
555 /* pre and post event widgets */
556 if (w->id == snd_soc_dapm_pre) {
557 if (!w->event)
558 return 0;
559
560 if (event == SND_SOC_DAPM_STREAM_START) {
561 ret = w->event(w,
562 NULL, SND_SOC_DAPM_PRE_PMU);
563 if (ret < 0)
564 return ret;
565 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
566 ret = w->event(w,
567 NULL, SND_SOC_DAPM_PRE_PMD);
568 if (ret < 0)
569 return ret;
570 }
571 return 0;
572 }
573 if (w->id == snd_soc_dapm_post) {
574 if (!w->event)
575 return 0;
576
577 if (event == SND_SOC_DAPM_STREAM_START) {
578 ret = w->event(w,
579 NULL, SND_SOC_DAPM_POST_PMU);
580 if (ret < 0)
581 return ret;
582 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
583 ret = w->event(w,
584 NULL, SND_SOC_DAPM_POST_PMD);
585 if (ret < 0)
586 return ret;
587 }
588 return 0;
589 }
590
591 /* all other widgets */
592 in = is_connected_input_ep(w);
593 dapm_clear_walk(w->codec);
594 out = is_connected_output_ep(w);
595 dapm_clear_walk(w->codec);
596 power = (out != 0 && in != 0) ? 1 : 0;
597 power_change = (w->power == power) ? 0 : 1;
598 w->power = power;
599
600 if (!power_change)
601 return 0;
602
603 /* call any power change event handlers */
604 if (w->event)
605 pr_debug("power %s event for %s flags %x\n",
606 w->power ? "on" : "off",
607 w->name, w->event_flags);
608
609 /* power up pre event */
610 if (power && w->event &&
611 (w->event_flags & SND_SOC_DAPM_PRE_PMU)) {
612 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
613 if (ret < 0)
614 return ret;
615 }
616
617 /* power down pre event */
618 if (!power && w->event &&
619 (w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
620 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
621 if (ret < 0)
622 return ret;
623 }
624
625 /* Lower PGA volume to reduce pops */
626 if (w->id == snd_soc_dapm_pga && !power)
627 dapm_set_pga(w, power);
628
629 dapm_update_bits(w);
630
631 /* Raise PGA volume to reduce pops */
632 if (w->id == snd_soc_dapm_pga && power)
633 dapm_set_pga(w, power);
634
635 /* power up post event */
636 if (power && w->event &&
637 (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
638 ret = w->event(w,
639 NULL, SND_SOC_DAPM_POST_PMU);
640 if (ret < 0)
641 return ret;
642 }
643
644 /* power down post event */
645 if (!power && w->event &&
646 (w->event_flags & SND_SOC_DAPM_POST_PMD)) {
647 ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
648 if (ret < 0)
649 return ret;
650 }
651
652 return 0;
653}
654
655/*
506 * Scan each dapm widget for complete audio path. 656 * Scan each dapm widget for complete audio path.
507 * A complete path is a route that has valid endpoints i.e.:- 657 * A complete path is a route that has valid endpoints i.e.:-
508 * 658 *
@@ -514,7 +664,7 @@ EXPORT_SYMBOL_GPL(dapm_reg_event);
514static int dapm_power_widgets(struct snd_soc_codec *codec, int event) 664static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
515{ 665{
516 struct snd_soc_dapm_widget *w; 666 struct snd_soc_dapm_widget *w;
517 int in, out, i, c = 1, *seq = NULL, ret = 0, power_change, power; 667 int i, c = 1, *seq = NULL, ret = 0;
518 668
519 /* do we have a sequenced stream event */ 669 /* do we have a sequenced stream event */
520 if (event == SND_SOC_DAPM_STREAM_START) { 670 if (event == SND_SOC_DAPM_STREAM_START) {
@@ -525,135 +675,20 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
525 seq = dapm_down_seq; 675 seq = dapm_down_seq;
526 } 676 }
527 677
528 for(i = 0; i < c; i++) { 678 for (i = 0; i < c; i++) {
529 list_for_each_entry(w, &codec->dapm_widgets, list) { 679 list_for_each_entry(w, &codec->dapm_widgets, list) {
530 680
531 /* is widget in stream order */ 681 /* is widget in stream order */
532 if (seq && seq[i] && w->id != seq[i]) 682 if (seq && seq[i] && w->id != seq[i])
533 continue; 683 continue;
534 684
535 /* vmid - no action */ 685 ret = dapm_power_widget(codec, event, w);
536 if (w->id == snd_soc_dapm_vmid) 686 if (ret != 0)
537 continue; 687 return ret;
538
539 /* active ADC */
540 if (w->id == snd_soc_dapm_adc && w->active) {
541 in = is_connected_input_ep(w);
542 dapm_clear_walk(w->codec);
543 w->power = (in != 0) ? 1 : 0;
544 dapm_update_bits(w);
545 continue;
546 }
547
548 /* active DAC */
549 if (w->id == snd_soc_dapm_dac && w->active) {
550 out = is_connected_output_ep(w);
551 dapm_clear_walk(w->codec);
552 w->power = (out != 0) ? 1 : 0;
553 dapm_update_bits(w);
554 continue;
555 }
556
557 /* pre and post event widgets */
558 if (w->id == snd_soc_dapm_pre) {
559 if (!w->event)
560 continue;
561
562 if (event == SND_SOC_DAPM_STREAM_START) {
563 ret = w->event(w,
564 NULL, SND_SOC_DAPM_PRE_PMU);
565 if (ret < 0)
566 return ret;
567 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
568 ret = w->event(w,
569 NULL, SND_SOC_DAPM_PRE_PMD);
570 if (ret < 0)
571 return ret;
572 }
573 continue;
574 }
575 if (w->id == snd_soc_dapm_post) {
576 if (!w->event)
577 continue;
578
579 if (event == SND_SOC_DAPM_STREAM_START) {
580 ret = w->event(w,
581 NULL, SND_SOC_DAPM_POST_PMU);
582 if (ret < 0)
583 return ret;
584 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
585 ret = w->event(w,
586 NULL, SND_SOC_DAPM_POST_PMD);
587 if (ret < 0)
588 return ret;
589 }
590 continue;
591 }
592
593 /* all other widgets */
594 in = is_connected_input_ep(w);
595 dapm_clear_walk(w->codec);
596 out = is_connected_output_ep(w);
597 dapm_clear_walk(w->codec);
598 power = (out != 0 && in != 0) ? 1 : 0;
599 power_change = (w->power == power) ? 0: 1;
600 w->power = power;
601
602 if (!power_change)
603 continue;
604
605 /* call any power change event handlers */
606 if (w->event)
607 pr_debug("power %s event for %s flags %x\n",
608 w->power ? "on" : "off",
609 w->name, w->event_flags);
610
611 /* power up pre event */
612 if (power && w->event &&
613 (w->event_flags & SND_SOC_DAPM_PRE_PMU)) {
614 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
615 if (ret < 0)
616 return ret;
617 }
618
619 /* power down pre event */
620 if (!power && w->event &&
621 (w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
622 ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
623 if (ret < 0)
624 return ret;
625 }
626
627 /* Lower PGA volume to reduce pops */
628 if (w->id == snd_soc_dapm_pga && !power)
629 dapm_set_pga(w, power);
630
631 dapm_update_bits(w);
632
633 /* Raise PGA volume to reduce pops */
634 if (w->id == snd_soc_dapm_pga && power)
635 dapm_set_pga(w, power);
636
637 /* power up post event */
638 if (power && w->event &&
639 (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
640 ret = w->event(w,
641 NULL, SND_SOC_DAPM_POST_PMU);
642 if (ret < 0)
643 return ret;
644 }
645
646 /* power down post event */
647 if (!power && w->event &&
648 (w->event_flags & SND_SOC_DAPM_POST_PMD)) {
649 ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
650 if (ret < 0)
651 return ret;
652 }
653 } 688 }
654 } 689 }
655 690
656 return ret; 691 return 0;
657} 692}
658 693
659#ifdef DEBUG 694#ifdef DEBUG
@@ -687,6 +722,7 @@ static void dbg_dump_dapm(struct snd_soc_codec* codec, const char *action)
687 case snd_soc_dapm_adc: 722 case snd_soc_dapm_adc:
688 case snd_soc_dapm_pga: 723 case snd_soc_dapm_pga:
689 case snd_soc_dapm_mixer: 724 case snd_soc_dapm_mixer:
725 case snd_soc_dapm_mixer_named_ctl:
690 if (w->name) { 726 if (w->name) {
691 in = is_connected_input_ep(w); 727 in = is_connected_input_ep(w);
692 dapm_clear_walk(w->codec); 728 dapm_clear_walk(w->codec);
@@ -760,6 +796,7 @@ static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
760 int found = 0; 796 int found = 0;
761 797
762 if (widget->id != snd_soc_dapm_mixer && 798 if (widget->id != snd_soc_dapm_mixer &&
799 widget->id != snd_soc_dapm_mixer_named_ctl &&
763 widget->id != snd_soc_dapm_switch) 800 widget->id != snd_soc_dapm_switch)
764 return -ENODEV; 801 return -ENODEV;
765 802
@@ -795,7 +832,7 @@ static ssize_t dapm_widget_show(struct device *dev,
795 struct device_attribute *attr, char *buf) 832 struct device_attribute *attr, char *buf)
796{ 833{
797 struct snd_soc_device *devdata = dev_get_drvdata(dev); 834 struct snd_soc_device *devdata = dev_get_drvdata(dev);
798 struct snd_soc_codec *codec = devdata->codec; 835 struct snd_soc_codec *codec = devdata->card->codec;
799 struct snd_soc_dapm_widget *w; 836 struct snd_soc_dapm_widget *w;
800 int count = 0; 837 int count = 0;
801 char *state = "not set"; 838 char *state = "not set";
@@ -813,6 +850,7 @@ static ssize_t dapm_widget_show(struct device *dev,
813 case snd_soc_dapm_adc: 850 case snd_soc_dapm_adc:
814 case snd_soc_dapm_pga: 851 case snd_soc_dapm_pga:
815 case snd_soc_dapm_mixer: 852 case snd_soc_dapm_mixer:
853 case snd_soc_dapm_mixer_named_ctl:
816 if (w->name) 854 if (w->name)
817 count += sprintf(buf + count, "%s: %s\n", 855 count += sprintf(buf + count, "%s: %s\n",
818 w->name, w->power ? "On":"Off"); 856 w->name, w->power ? "On":"Off");
@@ -876,7 +914,7 @@ static void dapm_free_widgets(struct snd_soc_codec *codec)
876} 914}
877 915
878static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec, 916static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec,
879 char *pin, int status) 917 const char *pin, int status)
880{ 918{
881 struct snd_soc_dapm_widget *w; 919 struct snd_soc_dapm_widget *w;
882 920
@@ -991,6 +1029,7 @@ static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
991 break; 1029 break;
992 case snd_soc_dapm_switch: 1030 case snd_soc_dapm_switch:
993 case snd_soc_dapm_mixer: 1031 case snd_soc_dapm_mixer:
1032 case snd_soc_dapm_mixer_named_ctl:
994 ret = dapm_connect_mixer(codec, wsource, wsink, path, control); 1033 ret = dapm_connect_mixer(codec, wsource, wsink, path, control);
995 if (ret != 0) 1034 if (ret != 0)
996 goto err; 1035 goto err;
@@ -1068,6 +1107,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
1068 switch(w->id) { 1107 switch(w->id) {
1069 case snd_soc_dapm_switch: 1108 case snd_soc_dapm_switch:
1070 case snd_soc_dapm_mixer: 1109 case snd_soc_dapm_mixer:
1110 case snd_soc_dapm_mixer_named_ctl:
1071 dapm_new_mixer(codec, w); 1111 dapm_new_mixer(codec, w);
1072 break; 1112 break;
1073 case snd_soc_dapm_mux: 1113 case snd_soc_dapm_mux:
@@ -1396,6 +1436,76 @@ out:
1396EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double); 1436EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
1397 1437
1398/** 1438/**
1439 * snd_soc_dapm_info_pin_switch - Info for a pin switch
1440 *
1441 * @kcontrol: mixer control
1442 * @uinfo: control element information
1443 *
1444 * Callback to provide information about a pin switch control.
1445 */
1446int snd_soc_dapm_info_pin_switch(struct snd_kcontrol *kcontrol,
1447 struct snd_ctl_elem_info *uinfo)
1448{
1449 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1450 uinfo->count = 1;
1451 uinfo->value.integer.min = 0;
1452 uinfo->value.integer.max = 1;
1453
1454 return 0;
1455}
1456EXPORT_SYMBOL_GPL(snd_soc_dapm_info_pin_switch);
1457
1458/**
1459 * snd_soc_dapm_get_pin_switch - Get information for a pin switch
1460 *
1461 * @kcontrol: mixer control
1462 * @ucontrol: Value
1463 */
1464int snd_soc_dapm_get_pin_switch(struct snd_kcontrol *kcontrol,
1465 struct snd_ctl_elem_value *ucontrol)
1466{
1467 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1468 const char *pin = (const char *)kcontrol->private_value;
1469
1470 mutex_lock(&codec->mutex);
1471
1472 ucontrol->value.integer.value[0] =
1473 snd_soc_dapm_get_pin_status(codec, pin);
1474
1475 mutex_unlock(&codec->mutex);
1476
1477 return 0;
1478}
1479EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_switch);
1480
1481/**
1482 * snd_soc_dapm_put_pin_switch - Set information for a pin switch
1483 *
1484 * @kcontrol: mixer control
1485 * @ucontrol: Value
1486 */
1487int snd_soc_dapm_put_pin_switch(struct snd_kcontrol *kcontrol,
1488 struct snd_ctl_elem_value *ucontrol)
1489{
1490 struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
1491 const char *pin = (const char *)kcontrol->private_value;
1492
1493 mutex_lock(&codec->mutex);
1494
1495 if (ucontrol->value.integer.value[0])
1496 snd_soc_dapm_enable_pin(codec, pin);
1497 else
1498 snd_soc_dapm_disable_pin(codec, pin);
1499
1500 snd_soc_dapm_sync(codec);
1501
1502 mutex_unlock(&codec->mutex);
1503
1504 return 0;
1505}
1506EXPORT_SYMBOL_GPL(snd_soc_dapm_put_pin_switch);
1507
1508/**
1399 * snd_soc_dapm_new_control - create new dapm control 1509 * snd_soc_dapm_new_control - create new dapm control
1400 * @codec: audio codec 1510 * @codec: audio codec
1401 * @widget: widget template 1511 * @widget: widget template
@@ -1527,8 +1637,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
1527int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev, 1637int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
1528 enum snd_soc_bias_level level) 1638 enum snd_soc_bias_level level)
1529{ 1639{
1530 struct snd_soc_codec *codec = socdev->codec;
1531 struct snd_soc_card *card = socdev->card; 1640 struct snd_soc_card *card = socdev->card;
1641 struct snd_soc_codec *codec = socdev->card->codec;
1532 int ret = 0; 1642 int ret = 0;
1533 1643
1534 if (card->set_bias_level) 1644 if (card->set_bias_level)
@@ -1549,7 +1659,7 @@ int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
1549 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to 1659 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1550 * do any widget power switching. 1660 * do any widget power switching.
1551 */ 1661 */
1552int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, char *pin) 1662int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin)
1553{ 1663{
1554 return snd_soc_dapm_set_pin(codec, pin, 1); 1664 return snd_soc_dapm_set_pin(codec, pin, 1);
1555} 1665}
@@ -1564,7 +1674,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
1564 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to 1674 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1565 * do any widget power switching. 1675 * do any widget power switching.
1566 */ 1676 */
1567int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, char *pin) 1677int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin)
1568{ 1678{
1569 return snd_soc_dapm_set_pin(codec, pin, 0); 1679 return snd_soc_dapm_set_pin(codec, pin, 0);
1570} 1680}
@@ -1584,7 +1694,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
1584 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to 1694 * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
1585 * do any widget power switching. 1695 * do any widget power switching.
1586 */ 1696 */
1587int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, char *pin) 1697int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin)
1588{ 1698{
1589 return snd_soc_dapm_set_pin(codec, pin, 0); 1699 return snd_soc_dapm_set_pin(codec, pin, 0);
1590} 1700}
@@ -1599,7 +1709,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
1599 * 1709 *
1600 * Returns 1 for connected otherwise 0. 1710 * Returns 1 for connected otherwise 0.
1601 */ 1711 */
1602int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, char *pin) 1712int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin)
1603{ 1713{
1604 struct snd_soc_dapm_widget *w; 1714 struct snd_soc_dapm_widget *w;
1605 1715
@@ -1620,7 +1730,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
1620 */ 1730 */
1621void snd_soc_dapm_free(struct snd_soc_device *socdev) 1731void snd_soc_dapm_free(struct snd_soc_device *socdev)
1622{ 1732{
1623 struct snd_soc_codec *codec = socdev->codec; 1733 struct snd_soc_codec *codec = socdev->card->codec;
1624 1734
1625 snd_soc_dapm_sys_remove(socdev->dev); 1735 snd_soc_dapm_sys_remove(socdev->dev);
1626 dapm_free_widgets(codec); 1736 dapm_free_widgets(codec);
diff --git a/sound/soc/soc-jack.c b/sound/soc/soc-jack.c
new file mode 100644
index 000000000000..28346fb2e70c
--- /dev/null
+++ b/sound/soc/soc-jack.c
@@ -0,0 +1,267 @@
1/*
2 * soc-jack.c -- ALSA SoC jack handling
3 *
4 * Copyright 2008 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 */
13
14#include <sound/jack.h>
15#include <sound/soc.h>
16#include <sound/soc-dapm.h>
17#include <linux/gpio.h>
18#include <linux/interrupt.h>
19#include <linux/workqueue.h>
20#include <linux/delay.h>
21
22/**
23 * snd_soc_jack_new - Create a new jack
24 * @card: ASoC card
25 * @id: an identifying string for this jack
26 * @type: a bitmask of enum snd_jack_type values that can be detected by
27 * this jack
28 * @jack: structure to use for the jack
29 *
30 * Creates a new jack object.
31 *
32 * Returns zero if successful, or a negative error code on failure.
33 * On success jack will be initialised.
34 */
35int snd_soc_jack_new(struct snd_soc_card *card, const char *id, int type,
36 struct snd_soc_jack *jack)
37{
38 jack->card = card;
39 INIT_LIST_HEAD(&jack->pins);
40
41 return snd_jack_new(card->codec->card, id, type, &jack->jack);
42}
43EXPORT_SYMBOL_GPL(snd_soc_jack_new);
44
45/**
46 * snd_soc_jack_report - Report the current status for a jack
47 *
48 * @jack: the jack
49 * @status: a bitmask of enum snd_jack_type values that are currently detected.
50 * @mask: a bitmask of enum snd_jack_type values that being reported.
51 *
52 * If configured using snd_soc_jack_add_pins() then the associated
53 * DAPM pins will be enabled or disabled as appropriate and DAPM
54 * synchronised.
55 *
56 * Note: This function uses mutexes and should be called from a
57 * context which can sleep (such as a workqueue).
58 */
59void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask)
60{
61 struct snd_soc_codec *codec = jack->card->codec;
62 struct snd_soc_jack_pin *pin;
63 int enable;
64 int oldstatus;
65
66 if (!jack) {
67 WARN_ON_ONCE(!jack);
68 return;
69 }
70
71 mutex_lock(&codec->mutex);
72
73 oldstatus = jack->status;
74
75 jack->status &= ~mask;
76 jack->status |= status;
77
78 /* The DAPM sync is expensive enough to be worth skipping */
79 if (jack->status == oldstatus)
80 goto out;
81
82 list_for_each_entry(pin, &jack->pins, list) {
83 enable = pin->mask & status;
84
85 if (pin->invert)
86 enable = !enable;
87
88 if (enable)
89 snd_soc_dapm_enable_pin(codec, pin->pin);
90 else
91 snd_soc_dapm_disable_pin(codec, pin->pin);
92 }
93
94 snd_soc_dapm_sync(codec);
95
96 snd_jack_report(jack->jack, status);
97
98out:
99 mutex_unlock(&codec->mutex);
100}
101EXPORT_SYMBOL_GPL(snd_soc_jack_report);
102
103/**
104 * snd_soc_jack_add_pins - Associate DAPM pins with an ASoC jack
105 *
106 * @jack: ASoC jack
107 * @count: Number of pins
108 * @pins: Array of pins
109 *
110 * After this function has been called the DAPM pins specified in the
111 * pins array will have their status updated to reflect the current
112 * state of the jack whenever the jack status is updated.
113 */
114int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
115 struct snd_soc_jack_pin *pins)
116{
117 int i;
118
119 for (i = 0; i < count; i++) {
120 if (!pins[i].pin) {
121 printk(KERN_ERR "No name for pin %d\n", i);
122 return -EINVAL;
123 }
124 if (!pins[i].mask) {
125 printk(KERN_ERR "No mask for pin %d (%s)\n", i,
126 pins[i].pin);
127 return -EINVAL;
128 }
129
130 INIT_LIST_HEAD(&pins[i].list);
131 list_add(&(pins[i].list), &jack->pins);
132 }
133
134 /* Update to reflect the last reported status; canned jack
135 * implementations are likely to set their state before the
136 * card has an opportunity to associate pins.
137 */
138 snd_soc_jack_report(jack, 0, 0);
139
140 return 0;
141}
142EXPORT_SYMBOL_GPL(snd_soc_jack_add_pins);
143
144#ifdef CONFIG_GPIOLIB
145/* gpio detect */
146static void snd_soc_jack_gpio_detect(struct snd_soc_jack_gpio *gpio)
147{
148 struct snd_soc_jack *jack = gpio->jack;
149 int enable;
150 int report;
151
152 if (gpio->debounce_time > 0)
153 mdelay(gpio->debounce_time);
154
155 enable = gpio_get_value(gpio->gpio);
156 if (gpio->invert)
157 enable = !enable;
158
159 if (enable)
160 report = gpio->report;
161 else
162 report = 0;
163
164 snd_soc_jack_report(jack, report, gpio->report);
165}
166
167/* irq handler for gpio pin */
168static irqreturn_t gpio_handler(int irq, void *data)
169{
170 struct snd_soc_jack_gpio *gpio = data;
171
172 schedule_work(&gpio->work);
173
174 return IRQ_HANDLED;
175}
176
177/* gpio work */
178static void gpio_work(struct work_struct *work)
179{
180 struct snd_soc_jack_gpio *gpio;
181
182 gpio = container_of(work, struct snd_soc_jack_gpio, work);
183 snd_soc_jack_gpio_detect(gpio);
184}
185
186/**
187 * snd_soc_jack_add_gpios - Associate GPIO pins with an ASoC jack
188 *
189 * @jack: ASoC jack
190 * @count: number of pins
191 * @gpios: array of gpio pins
192 *
193 * This function will request gpio, set data direction and request irq
194 * for each gpio in the array.
195 */
196int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
197 struct snd_soc_jack_gpio *gpios)
198{
199 int i, ret;
200
201 for (i = 0; i < count; i++) {
202 if (!gpio_is_valid(gpios[i].gpio)) {
203 printk(KERN_ERR "Invalid gpio %d\n",
204 gpios[i].gpio);
205 ret = -EINVAL;
206 goto undo;
207 }
208 if (!gpios[i].name) {
209 printk(KERN_ERR "No name for gpio %d\n",
210 gpios[i].gpio);
211 ret = -EINVAL;
212 goto undo;
213 }
214
215 ret = gpio_request(gpios[i].gpio, gpios[i].name);
216 if (ret)
217 goto undo;
218
219 ret = gpio_direction_input(gpios[i].gpio);
220 if (ret)
221 goto err;
222
223 ret = request_irq(gpio_to_irq(gpios[i].gpio),
224 gpio_handler,
225 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
226 jack->card->dev->driver->name,
227 &gpios[i]);
228 if (ret)
229 goto err;
230
231 INIT_WORK(&gpios[i].work, gpio_work);
232 gpios[i].jack = jack;
233 }
234
235 return 0;
236
237err:
238 gpio_free(gpios[i].gpio);
239undo:
240 snd_soc_jack_free_gpios(jack, i, gpios);
241
242 return ret;
243}
244EXPORT_SYMBOL_GPL(snd_soc_jack_add_gpios);
245
246/**
247 * snd_soc_jack_free_gpios - Release GPIO pins' resources of an ASoC jack
248 *
249 * @jack: ASoC jack
250 * @count: number of pins
251 * @gpios: array of gpio pins
252 *
253 * Release gpio and irq resources for gpio pins associated with an ASoC jack.
254 */
255void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
256 struct snd_soc_jack_gpio *gpios)
257{
258 int i;
259
260 for (i = 0; i < count; i++) {
261 free_irq(gpio_to_irq(gpios[i].gpio), &gpios[i]);
262 gpio_free(gpios[i].gpio);
263 gpios[i].jack = NULL;
264 }
265}
266EXPORT_SYMBOL_GPL(snd_soc_jack_free_gpios);
267#endif /* CONFIG_GPIOLIB */
diff --git a/sound/sparc/amd7930.c b/sound/sparc/amd7930.c
index f87933e48812..574af56ba8a6 100644
--- a/sound/sparc/amd7930.c
+++ b/sound/sparc/amd7930.c
@@ -954,7 +954,8 @@ static int __devinit snd_amd7930_create(struct snd_card *card,
954 amd->regs = of_ioremap(&op->resource[0], 0, 954 amd->regs = of_ioremap(&op->resource[0], 0,
955 resource_size(&op->resource[0]), "amd7930"); 955 resource_size(&op->resource[0]), "amd7930");
956 if (!amd->regs) { 956 if (!amd->regs) {
957 snd_printk("amd7930-%d: Unable to map chip registers.\n", dev); 957 snd_printk(KERN_ERR
958 "amd7930-%d: Unable to map chip registers.\n", dev);
958 return -EIO; 959 return -EIO;
959 } 960 }
960 961
@@ -962,7 +963,7 @@ static int __devinit snd_amd7930_create(struct snd_card *card,
962 963
963 if (request_irq(irq, snd_amd7930_interrupt, 964 if (request_irq(irq, snd_amd7930_interrupt,
964 IRQF_DISABLED | IRQF_SHARED, "amd7930", amd)) { 965 IRQF_DISABLED | IRQF_SHARED, "amd7930", amd)) {
965 snd_printk("amd7930-%d: Unable to grab IRQ %d\n", 966 snd_printk(KERN_ERR "amd7930-%d: Unable to grab IRQ %d\n",
966 dev, irq); 967 dev, irq);
967 snd_amd7930_free(amd); 968 snd_amd7930_free(amd);
968 return -EBUSY; 969 return -EBUSY;
@@ -1018,9 +1019,10 @@ static int __devinit amd7930_sbus_probe(struct of_device *op, const struct of_de
1018 return -ENOENT; 1019 return -ENOENT;
1019 } 1020 }
1020 1021
1021 card = snd_card_new(index[dev_num], id[dev_num], THIS_MODULE, 0); 1022 err = snd_card_create(index[dev_num], id[dev_num], THIS_MODULE, 0,
1022 if (card == NULL) 1023 &card);
1023 return -ENOMEM; 1024 if (err < 0)
1025 return err;
1024 1026
1025 strcpy(card->driver, "AMD7930"); 1027 strcpy(card->driver, "AMD7930");
1026 strcpy(card->shortname, "Sun AMD7930"); 1028 strcpy(card->shortname, "Sun AMD7930");
diff --git a/sound/sparc/cs4231.c b/sound/sparc/cs4231.c
index 41c387587474..7d93fa705ccf 100644
--- a/sound/sparc/cs4231.c
+++ b/sound/sparc/cs4231.c
@@ -1563,6 +1563,7 @@ static int __init cs4231_attach_begin(struct snd_card **rcard)
1563{ 1563{
1564 struct snd_card *card; 1564 struct snd_card *card;
1565 struct snd_cs4231 *chip; 1565 struct snd_cs4231 *chip;
1566 int err;
1566 1567
1567 *rcard = NULL; 1568 *rcard = NULL;
1568 1569
@@ -1574,10 +1575,10 @@ static int __init cs4231_attach_begin(struct snd_card **rcard)
1574 return -ENOENT; 1575 return -ENOENT;
1575 } 1576 }
1576 1577
1577 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 1578 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
1578 sizeof(struct snd_cs4231)); 1579 sizeof(struct snd_cs4231), &card);
1579 if (card == NULL) 1580 if (err < 0)
1580 return -ENOMEM; 1581 return err;
1581 1582
1582 strcpy(card->driver, "CS4231"); 1583 strcpy(card->driver, "CS4231");
1583 strcpy(card->shortname, "Sun CS4231"); 1584 strcpy(card->shortname, "Sun CS4231");
diff --git a/sound/sparc/dbri.c b/sound/sparc/dbri.c
index 23ed6f04a718..af95ff1e126c 100644
--- a/sound/sparc/dbri.c
+++ b/sound/sparc/dbri.c
@@ -2612,10 +2612,10 @@ static int __devinit dbri_probe(struct of_device *op, const struct of_device_id
2612 return -ENODEV; 2612 return -ENODEV;
2613 } 2613 }
2614 2614
2615 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 2615 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
2616 sizeof(struct snd_dbri)); 2616 sizeof(struct snd_dbri), &card);
2617 if (card == NULL) 2617 if (err < 0)
2618 return -ENOMEM; 2618 return err;
2619 2619
2620 strcpy(card->driver, "DBRI"); 2620 strcpy(card->driver, "DBRI");
2621 strcpy(card->shortname, "Sun DBRI"); 2621 strcpy(card->shortname, "Sun DBRI");
diff --git a/sound/spi/at73c213.c b/sound/spi/at73c213.c
index 09802e8a6fb8..4c7b051f9d17 100644
--- a/sound/spi/at73c213.c
+++ b/sound/spi/at73c213.c
@@ -965,12 +965,11 @@ static int __devinit snd_at73c213_probe(struct spi_device *spi)
965 return PTR_ERR(board->dac_clk); 965 return PTR_ERR(board->dac_clk);
966 } 966 }
967 967
968 retval = -ENOMEM;
969
970 /* Allocate "card" using some unused identifiers. */ 968 /* Allocate "card" using some unused identifiers. */
971 snprintf(id, sizeof id, "at73c213_%d", board->ssc_id); 969 snprintf(id, sizeof id, "at73c213_%d", board->ssc_id);
972 card = snd_card_new(-1, id, THIS_MODULE, sizeof(struct snd_at73c213)); 970 retval = snd_card_create(-1, id, THIS_MODULE,
973 if (!card) 971 sizeof(struct snd_at73c213), &card);
972 if (retval < 0)
974 goto out; 973 goto out;
975 974
976 chip = card->private_data; 975 chip = card->private_data;
diff --git a/sound/synth/emux/emux_hwdep.c b/sound/synth/emux/emux_hwdep.c
index 0a5391436add..ff0b2a8fd25b 100644
--- a/sound/synth/emux/emux_hwdep.c
+++ b/sound/synth/emux/emux_hwdep.c
@@ -24,25 +24,6 @@
24#include <asm/uaccess.h> 24#include <asm/uaccess.h>
25#include "emux_voice.h" 25#include "emux_voice.h"
26 26
27/*
28 * open the hwdep device
29 */
30static int
31snd_emux_hwdep_open(struct snd_hwdep *hw, struct file *file)
32{
33 return 0;
34}
35
36
37/*
38 * close the device
39 */
40static int
41snd_emux_hwdep_release(struct snd_hwdep *hw, struct file *file)
42{
43 return 0;
44}
45
46 27
47#define TMP_CLIENT_ID 0x1001 28#define TMP_CLIENT_ID 0x1001
48 29
@@ -146,8 +127,6 @@ snd_emux_init_hwdep(struct snd_emux *emu)
146 emu->hwdep = hw; 127 emu->hwdep = hw;
147 strcpy(hw->name, SNDRV_EMUX_HWDEP_NAME); 128 strcpy(hw->name, SNDRV_EMUX_HWDEP_NAME);
148 hw->iface = SNDRV_HWDEP_IFACE_EMUX_WAVETABLE; 129 hw->iface = SNDRV_HWDEP_IFACE_EMUX_WAVETABLE;
149 hw->ops.open = snd_emux_hwdep_open;
150 hw->ops.release = snd_emux_hwdep_release;
151 hw->ops.ioctl = snd_emux_hwdep_ioctl; 130 hw->ops.ioctl = snd_emux_hwdep_ioctl;
152 hw->exclusive = 1; 131 hw->exclusive = 1;
153 hw->private_data = emu; 132 hw->private_data = emu;
diff --git a/sound/synth/emux/emux_oss.c b/sound/synth/emux/emux_oss.c
index 5c47b6c09264..87e42206c4ef 100644
--- a/sound/synth/emux/emux_oss.c
+++ b/sound/synth/emux/emux_oss.c
@@ -132,7 +132,7 @@ snd_emux_open_seq_oss(struct snd_seq_oss_arg *arg, void *closure)
132 p = snd_emux_create_port(emu, tmpname, 32, 132 p = snd_emux_create_port(emu, tmpname, 32,
133 1, &callback); 133 1, &callback);
134 if (p == NULL) { 134 if (p == NULL) {
135 snd_printk("can't create port\n"); 135 snd_printk(KERN_ERR "can't create port\n");
136 snd_emux_dec_count(emu); 136 snd_emux_dec_count(emu);
137 mutex_unlock(&emu->register_mutex); 137 mutex_unlock(&emu->register_mutex);
138 return -ENOMEM; 138 return -ENOMEM;
diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
index 335aa2ce2574..ca5f7effb4df 100644
--- a/sound/synth/emux/emux_seq.c
+++ b/sound/synth/emux/emux_seq.c
@@ -74,15 +74,15 @@ snd_emux_init_seq(struct snd_emux *emu, struct snd_card *card, int index)
74 emu->client = snd_seq_create_kernel_client(card, index, 74 emu->client = snd_seq_create_kernel_client(card, index,
75 "%s WaveTable", emu->name); 75 "%s WaveTable", emu->name);
76 if (emu->client < 0) { 76 if (emu->client < 0) {
77 snd_printk("can't create client\n"); 77 snd_printk(KERN_ERR "can't create client\n");
78 return -ENODEV; 78 return -ENODEV;
79 } 79 }
80 80
81 if (emu->num_ports < 0) { 81 if (emu->num_ports < 0) {
82 snd_printk("seqports must be greater than zero\n"); 82 snd_printk(KERN_WARNING "seqports must be greater than zero\n");
83 emu->num_ports = 1; 83 emu->num_ports = 1;
84 } else if (emu->num_ports >= SNDRV_EMUX_MAX_PORTS) { 84 } else if (emu->num_ports >= SNDRV_EMUX_MAX_PORTS) {
85 snd_printk("too many ports." 85 snd_printk(KERN_WARNING "too many ports."
86 "limited max. ports %d\n", SNDRV_EMUX_MAX_PORTS); 86 "limited max. ports %d\n", SNDRV_EMUX_MAX_PORTS);
87 emu->num_ports = SNDRV_EMUX_MAX_PORTS; 87 emu->num_ports = SNDRV_EMUX_MAX_PORTS;
88 } 88 }
@@ -100,7 +100,7 @@ snd_emux_init_seq(struct snd_emux *emu, struct snd_card *card, int index)
100 p = snd_emux_create_port(emu, tmpname, MIDI_CHANNELS, 100 p = snd_emux_create_port(emu, tmpname, MIDI_CHANNELS,
101 0, &pinfo); 101 0, &pinfo);
102 if (p == NULL) { 102 if (p == NULL) {
103 snd_printk("can't create port\n"); 103 snd_printk(KERN_ERR "can't create port\n");
104 return -ENOMEM; 104 return -ENOMEM;
105 } 105 }
106 106
@@ -147,12 +147,12 @@ snd_emux_create_port(struct snd_emux *emu, char *name,
147 147
148 /* Allocate structures for this channel */ 148 /* Allocate structures for this channel */
149 if ((p = kzalloc(sizeof(*p), GFP_KERNEL)) == NULL) { 149 if ((p = kzalloc(sizeof(*p), GFP_KERNEL)) == NULL) {
150 snd_printk("no memory\n"); 150 snd_printk(KERN_ERR "no memory\n");
151 return NULL; 151 return NULL;
152 } 152 }
153 p->chset.channels = kcalloc(max_channels, sizeof(struct snd_midi_channel), GFP_KERNEL); 153 p->chset.channels = kcalloc(max_channels, sizeof(struct snd_midi_channel), GFP_KERNEL);
154 if (p->chset.channels == NULL) { 154 if (p->chset.channels == NULL) {
155 snd_printk("no memory\n"); 155 snd_printk(KERN_ERR "no memory\n");
156 kfree(p); 156 kfree(p);
157 return NULL; 157 return NULL;
158 } 158 }
@@ -376,12 +376,12 @@ int snd_emux_init_virmidi(struct snd_emux *emu, struct snd_card *card)
376 goto __error; 376 goto __error;
377 } 377 }
378 emu->vmidi[i] = rmidi; 378 emu->vmidi[i] = rmidi;
379 //snd_printk("virmidi %d ok\n", i); 379 /* snd_printk(KERN_DEBUG "virmidi %d ok\n", i); */
380 } 380 }
381 return 0; 381 return 0;
382 382
383__error: 383__error:
384 //snd_printk("error init..\n"); 384 /* snd_printk(KERN_DEBUG "error init..\n"); */
385 snd_emux_delete_virmidi(emu); 385 snd_emux_delete_virmidi(emu);
386 return -ENOMEM; 386 return -ENOMEM;
387} 387}
diff --git a/sound/synth/emux/emux_synth.c b/sound/synth/emux/emux_synth.c
index 2cc6f6f79065..3e921b386fd5 100644
--- a/sound/synth/emux/emux_synth.c
+++ b/sound/synth/emux/emux_synth.c
@@ -956,7 +956,8 @@ void snd_emux_lock_voice(struct snd_emux *emu, int voice)
956 if (emu->voices[voice].state == SNDRV_EMUX_ST_OFF) 956 if (emu->voices[voice].state == SNDRV_EMUX_ST_OFF)
957 emu->voices[voice].state = SNDRV_EMUX_ST_LOCKED; 957 emu->voices[voice].state = SNDRV_EMUX_ST_LOCKED;
958 else 958 else
959 snd_printk("invalid voice for lock %d (state = %x)\n", 959 snd_printk(KERN_WARNING
960 "invalid voice for lock %d (state = %x)\n",
960 voice, emu->voices[voice].state); 961 voice, emu->voices[voice].state);
961 spin_unlock_irqrestore(&emu->voice_lock, flags); 962 spin_unlock_irqrestore(&emu->voice_lock, flags);
962} 963}
@@ -973,7 +974,8 @@ void snd_emux_unlock_voice(struct snd_emux *emu, int voice)
973 if (emu->voices[voice].state == SNDRV_EMUX_ST_LOCKED) 974 if (emu->voices[voice].state == SNDRV_EMUX_ST_LOCKED)
974 emu->voices[voice].state = SNDRV_EMUX_ST_OFF; 975 emu->voices[voice].state = SNDRV_EMUX_ST_OFF;
975 else 976 else
976 snd_printk("invalid voice for unlock %d (state = %x)\n", 977 snd_printk(KERN_WARNING
978 "invalid voice for unlock %d (state = %x)\n",
977 voice, emu->voices[voice].state); 979 voice, emu->voices[voice].state);
978 spin_unlock_irqrestore(&emu->voice_lock, flags); 980 spin_unlock_irqrestore(&emu->voice_lock, flags);
979} 981}
diff --git a/sound/synth/emux/soundfont.c b/sound/synth/emux/soundfont.c
index 36d53bd317ed..63c8f45c0c22 100644
--- a/sound/synth/emux/soundfont.c
+++ b/sound/synth/emux/soundfont.c
@@ -133,7 +133,7 @@ snd_soundfont_load(struct snd_sf_list *sflist, const void __user *data,
133 int rc; 133 int rc;
134 134
135 if (count < (long)sizeof(patch)) { 135 if (count < (long)sizeof(patch)) {
136 snd_printk("patch record too small %ld\n", count); 136 snd_printk(KERN_ERR "patch record too small %ld\n", count);
137 return -EINVAL; 137 return -EINVAL;
138 } 138 }
139 if (copy_from_user(&patch, data, sizeof(patch))) 139 if (copy_from_user(&patch, data, sizeof(patch)))
@@ -143,15 +143,16 @@ snd_soundfont_load(struct snd_sf_list *sflist, const void __user *data,
143 data += sizeof(patch); 143 data += sizeof(patch);
144 144
145 if (patch.key != SNDRV_OSS_SOUNDFONT_PATCH) { 145 if (patch.key != SNDRV_OSS_SOUNDFONT_PATCH) {
146 snd_printk("'The wrong kind of patch' %x\n", patch.key); 146 snd_printk(KERN_ERR "The wrong kind of patch %x\n", patch.key);
147 return -EINVAL; 147 return -EINVAL;
148 } 148 }
149 if (count < patch.len) { 149 if (count < patch.len) {
150 snd_printk("Patch too short %ld, need %d\n", count, patch.len); 150 snd_printk(KERN_ERR "Patch too short %ld, need %d\n",
151 count, patch.len);
151 return -EINVAL; 152 return -EINVAL;
152 } 153 }
153 if (patch.len < 0) { 154 if (patch.len < 0) {
154 snd_printk("poor length %d\n", patch.len); 155 snd_printk(KERN_ERR "poor length %d\n", patch.len);
155 return -EINVAL; 156 return -EINVAL;
156 } 157 }
157 158
@@ -195,7 +196,8 @@ snd_soundfont_load(struct snd_sf_list *sflist, const void __user *data,
195 case SNDRV_SFNT_REMOVE_INFO: 196 case SNDRV_SFNT_REMOVE_INFO:
196 /* patch must be opened */ 197 /* patch must be opened */
197 if (!sflist->currsf) { 198 if (!sflist->currsf) {
198 snd_printk("soundfont: remove_info: patch not opened\n"); 199 snd_printk(KERN_ERR "soundfont: remove_info: "
200 "patch not opened\n");
199 rc = -EINVAL; 201 rc = -EINVAL;
200 } else { 202 } else {
201 int bank, instr; 203 int bank, instr;
@@ -531,7 +533,7 @@ load_info(struct snd_sf_list *sflist, const void __user *data, long count)
531 return -EINVAL; 533 return -EINVAL;
532 534
533 if (count < (long)sizeof(hdr)) { 535 if (count < (long)sizeof(hdr)) {
534 printk("Soundfont error: invalid patch zone length\n"); 536 printk(KERN_ERR "Soundfont error: invalid patch zone length\n");
535 return -EINVAL; 537 return -EINVAL;
536 } 538 }
537 if (copy_from_user((char*)&hdr, data, sizeof(hdr))) 539 if (copy_from_user((char*)&hdr, data, sizeof(hdr)))
@@ -541,12 +543,14 @@ load_info(struct snd_sf_list *sflist, const void __user *data, long count)
541 count -= sizeof(hdr); 543 count -= sizeof(hdr);
542 544
543 if (hdr.nvoices <= 0 || hdr.nvoices >= 100) { 545 if (hdr.nvoices <= 0 || hdr.nvoices >= 100) {
544 printk("Soundfont error: Illegal voice number %d\n", hdr.nvoices); 546 printk(KERN_ERR "Soundfont error: Illegal voice number %d\n",
547 hdr.nvoices);
545 return -EINVAL; 548 return -EINVAL;
546 } 549 }
547 550
548 if (count < (long)sizeof(struct soundfont_voice_info) * hdr.nvoices) { 551 if (count < (long)sizeof(struct soundfont_voice_info) * hdr.nvoices) {
549 printk("Soundfont Error: patch length(%ld) is smaller than nvoices(%d)\n", 552 printk(KERN_ERR "Soundfont Error: "
553 "patch length(%ld) is smaller than nvoices(%d)\n",
550 count, hdr.nvoices); 554 count, hdr.nvoices);
551 return -EINVAL; 555 return -EINVAL;
552 } 556 }
@@ -952,7 +956,7 @@ load_guspatch(struct snd_sf_list *sflist, const char __user *data,
952 int rc; 956 int rc;
953 957
954 if (count < (long)sizeof(patch)) { 958 if (count < (long)sizeof(patch)) {
955 snd_printk("patch record too small %ld\n", count); 959 snd_printk(KERN_ERR "patch record too small %ld\n", count);
956 return -EINVAL; 960 return -EINVAL;
957 } 961 }
958 if (copy_from_user(&patch, data, sizeof(patch))) 962 if (copy_from_user(&patch, data, sizeof(patch)))
@@ -1034,7 +1038,8 @@ load_guspatch(struct snd_sf_list *sflist, const char __user *data,
1034 /* panning position; -128 - 127 => 0-127 */ 1038 /* panning position; -128 - 127 => 0-127 */
1035 zone->v.pan = (patch.panning + 128) / 2; 1039 zone->v.pan = (patch.panning + 128) / 2;
1036#if 0 1040#if 0
1037 snd_printk("gus: basefrq=%d (ofs=%d) root=%d,tune=%d, range:%d-%d\n", 1041 snd_printk(KERN_DEBUG
1042 "gus: basefrq=%d (ofs=%d) root=%d,tune=%d, range:%d-%d\n",
1038 (int)patch.base_freq, zone->v.rate_offset, 1043 (int)patch.base_freq, zone->v.rate_offset,
1039 zone->v.root, zone->v.tune, zone->v.low, zone->v.high); 1044 zone->v.root, zone->v.tune, zone->v.low, zone->v.high);
1040#endif 1045#endif
@@ -1068,7 +1073,8 @@ load_guspatch(struct snd_sf_list *sflist, const char __user *data,
1068 zone->v.parm.volrelease = 0x8000 | snd_sf_calc_parm_decay(release); 1073 zone->v.parm.volrelease = 0x8000 | snd_sf_calc_parm_decay(release);
1069 zone->v.attenuation = calc_gus_attenuation(patch.env_offset[0]); 1074 zone->v.attenuation = calc_gus_attenuation(patch.env_offset[0]);
1070#if 0 1075#if 0
1071 snd_printk("gus: atkhld=%x, dcysus=%x, volrel=%x, att=%d\n", 1076 snd_printk(KERN_DEBUG
1077 "gus: atkhld=%x, dcysus=%x, volrel=%x, att=%d\n",
1072 zone->v.parm.volatkhld, 1078 zone->v.parm.volatkhld,
1073 zone->v.parm.voldcysus, 1079 zone->v.parm.voldcysus,
1074 zone->v.parm.volrelease, 1080 zone->v.parm.volrelease,
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
index 4f0eac9bff1e..523aec188ccf 100644
--- a/sound/usb/Kconfig
+++ b/sound/usb/Kconfig
@@ -48,7 +48,10 @@ config SND_USB_CAIAQ
48 * Native Instruments Kore Controller 48 * Native Instruments Kore Controller
49 * Native Instruments Kore Controller 2 49 * Native Instruments Kore Controller 2
50 * Native Instruments Audio Kontrol 1 50 * Native Instruments Audio Kontrol 1
51 * Native Instruments Audio 4 DJ
51 * Native Instruments Audio 8 DJ 52 * Native Instruments Audio 8 DJ
53 * Native Instruments Guitar Rig Session I/O
54 * Native Instruments Guitar Rig mobile
52 55
53 To compile this driver as a module, choose M here: the module 56 To compile this driver as a module, choose M here: the module
54 will be called snd-usb-caiaq. 57 will be called snd-usb-caiaq.
diff --git a/sound/usb/caiaq/caiaq-audio.c b/sound/usb/caiaq/caiaq-audio.c
index b3a603325835..08d51e0c9fea 100644
--- a/sound/usb/caiaq/caiaq-audio.c
+++ b/sound/usb/caiaq/caiaq-audio.c
@@ -114,6 +114,7 @@ static int stream_start(struct snd_usb_caiaqdev *dev)
114 dev->output_panic = 0; 114 dev->output_panic = 0;
115 dev->first_packet = 1; 115 dev->first_packet = 1;
116 dev->streaming = 1; 116 dev->streaming = 1;
117 dev->warned = 0;
117 118
118 for (i = 0; i < N_URBS; i++) { 119 for (i = 0; i < N_URBS; i++) {
119 ret = usb_submit_urb(dev->data_urbs_in[i], GFP_ATOMIC); 120 ret = usb_submit_urb(dev->data_urbs_in[i], GFP_ATOMIC);
@@ -376,6 +377,9 @@ static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
376 377
377 for (stream = 0; stream < dev->n_streams; stream++, i++) { 378 for (stream = 0; stream < dev->n_streams; stream++, i++) {
378 sub = dev->sub_capture[stream]; 379 sub = dev->sub_capture[stream];
380 if (dev->input_panic)
381 usb_buf[i] = 0;
382
379 if (sub) { 383 if (sub) {
380 struct snd_pcm_runtime *rt = sub->runtime; 384 struct snd_pcm_runtime *rt = sub->runtime;
381 char *audio_buf = rt->dma_area; 385 char *audio_buf = rt->dma_area;
@@ -397,6 +401,9 @@ static void read_in_urb(struct snd_usb_caiaqdev *dev,
397 if (!dev->streaming) 401 if (!dev->streaming)
398 return; 402 return;
399 403
404 if (iso->actual_length < dev->bpp)
405 return;
406
400 switch (dev->spec.data_alignment) { 407 switch (dev->spec.data_alignment) {
401 case 0: 408 case 0:
402 read_in_urb_mode0(dev, urb, iso); 409 read_in_urb_mode0(dev, urb, iso);
@@ -406,10 +413,11 @@ static void read_in_urb(struct snd_usb_caiaqdev *dev,
406 break; 413 break;
407 } 414 }
408 415
409 if (dev->input_panic || dev->output_panic) { 416 if ((dev->input_panic || dev->output_panic) && !dev->warned) {
410 debug("streaming error detected %s %s\n", 417 debug("streaming error detected %s %s\n",
411 dev->input_panic ? "(input)" : "", 418 dev->input_panic ? "(input)" : "",
412 dev->output_panic ? "(output)" : ""); 419 dev->output_panic ? "(output)" : "");
420 dev->warned = 1;
413 } 421 }
414} 422}
415 423
@@ -638,9 +646,10 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
638 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1): 646 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AK1):
639 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3): 647 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_RIGKONTROL3):
640 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_SESSIONIO): 648 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_SESSIONIO):
641 dev->samplerates |= SNDRV_PCM_RATE_88200; 649 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_GUITARRIGMOBILE):
642 dev->samplerates |= SNDRV_PCM_RATE_192000; 650 dev->samplerates |= SNDRV_PCM_RATE_192000;
643 break; 651 /* fall thru */
652 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
644 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ): 653 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ):
645 dev->samplerates |= SNDRV_PCM_RATE_88200; 654 dev->samplerates |= SNDRV_PCM_RATE_88200;
646 break; 655 break;
diff --git a/sound/usb/caiaq/caiaq-control.c b/sound/usb/caiaq/caiaq-control.c
index ccd763dd7167..e92c2bbf4fe9 100644
--- a/sound/usb/caiaq/caiaq-control.c
+++ b/sound/usb/caiaq/caiaq-control.c
@@ -39,12 +39,12 @@ static int control_info(struct snd_kcontrol *kcontrol,
39 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card); 39 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
40 int pos = kcontrol->private_value; 40 int pos = kcontrol->private_value;
41 int is_intval = pos & CNT_INTVAL; 41 int is_intval = pos & CNT_INTVAL;
42 unsigned int id = dev->chip.usb_id;
42 43
43 uinfo->count = 1; 44 uinfo->count = 1;
44 pos &= ~CNT_INTVAL; 45 pos &= ~CNT_INTVAL;
45 46
46 if (dev->chip.usb_id == 47 if (id == USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ)
47 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO8DJ)
48 && (pos == 0)) { 48 && (pos == 0)) {
49 /* current input mode of A8DJ */ 49 /* current input mode of A8DJ */
50 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 50 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
@@ -53,6 +53,15 @@ static int control_info(struct snd_kcontrol *kcontrol,
53 return 0; 53 return 0;
54 } 54 }
55 55
56 if (id == USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ)
57 && (pos == 0)) {
58 /* current input mode of A4DJ */
59 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
60 uinfo->value.integer.min = 0;
61 uinfo->value.integer.max = 1;
62 return 0;
63 }
64
56 if (is_intval) { 65 if (is_intval) {
57 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 66 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
58 uinfo->value.integer.min = 0; 67 uinfo->value.integer.min = 0;
@@ -73,6 +82,14 @@ static int control_get(struct snd_kcontrol *kcontrol,
73 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card); 82 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
74 int pos = kcontrol->private_value; 83 int pos = kcontrol->private_value;
75 84
85 if (dev->chip.usb_id ==
86 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ)) {
87 /* A4DJ has only one control */
88 /* do not expose hardware input mode 0 */
89 ucontrol->value.integer.value[0] = dev->control_state[0] - 1;
90 return 0;
91 }
92
76 if (pos & CNT_INTVAL) 93 if (pos & CNT_INTVAL)
77 ucontrol->value.integer.value[0] 94 ucontrol->value.integer.value[0]
78 = dev->control_state[pos & ~CNT_INTVAL]; 95 = dev->control_state[pos & ~CNT_INTVAL];
@@ -90,10 +107,20 @@ static int control_put(struct snd_kcontrol *kcontrol,
90 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card); 107 struct snd_usb_caiaqdev *dev = caiaqdev(chip->card);
91 int pos = kcontrol->private_value; 108 int pos = kcontrol->private_value;
92 109
110 if (dev->chip.usb_id ==
111 USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ)) {
112 /* A4DJ has only one control */
113 /* do not expose hardware input mode 0 */
114 dev->control_state[0] = ucontrol->value.integer.value[0] + 1;
115 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
116 dev->control_state, sizeof(dev->control_state));
117 return 1;
118 }
119
93 if (pos & CNT_INTVAL) { 120 if (pos & CNT_INTVAL) {
94 dev->control_state[pos & ~CNT_INTVAL] 121 dev->control_state[pos & ~CNT_INTVAL]
95 = ucontrol->value.integer.value[0]; 122 = ucontrol->value.integer.value[0];
96 snd_usb_caiaq_send_command(dev, EP1_CMD_DIMM_LEDS, 123 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
97 dev->control_state, sizeof(dev->control_state)); 124 dev->control_state, sizeof(dev->control_state));
98 } else { 125 } else {
99 if (ucontrol->value.integer.value[0]) 126 if (ucontrol->value.integer.value[0])
@@ -243,10 +270,13 @@ static struct caiaq_controller a8dj_controller[] = {
243 { "GND lift for TC Vinyl mode", 24 + 0 }, 270 { "GND lift for TC Vinyl mode", 24 + 0 },
244 { "GND lift for TC CD/Line mode", 24 + 1 }, 271 { "GND lift for TC CD/Line mode", 24 + 1 },
245 { "GND lift for phono mode", 24 + 2 }, 272 { "GND lift for phono mode", 24 + 2 },
246 { "GND lift for TC Vinyl mode", 24 + 3 },
247 { "Software lock", 40 } 273 { "Software lock", 40 }
248}; 274};
249 275
276static struct caiaq_controller a4dj_controller[] = {
277 { "Current input mode", 0 | CNT_INTVAL }
278};
279
250static int __devinit add_controls(struct caiaq_controller *c, int num, 280static int __devinit add_controls(struct caiaq_controller *c, int num,
251 struct snd_usb_caiaqdev *dev) 281 struct snd_usb_caiaqdev *dev)
252{ 282{
@@ -295,6 +325,10 @@ int __devinit snd_usb_caiaq_control_init(struct snd_usb_caiaqdev *dev)
295 ret = add_controls(a8dj_controller, 325 ret = add_controls(a8dj_controller,
296 ARRAY_SIZE(a8dj_controller), dev); 326 ARRAY_SIZE(a8dj_controller), dev);
297 break; 327 break;
328 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
329 ret = add_controls(a4dj_controller,
330 ARRAY_SIZE(a4dj_controller), dev);
331 break;
298 } 332 }
299 333
300 return ret; 334 return ret;
diff --git a/sound/usb/caiaq/caiaq-device.c b/sound/usb/caiaq/caiaq-device.c
index 41c36b055f6b..cf573a982fdc 100644
--- a/sound/usb/caiaq/caiaq-device.c
+++ b/sound/usb/caiaq/caiaq-device.c
@@ -42,15 +42,17 @@
42#endif 42#endif
43 43
44MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); 44MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
45MODULE_DESCRIPTION("caiaq USB audio, version 1.3.10"); 45MODULE_DESCRIPTION("caiaq USB audio, version 1.3.13");
46MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
47MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2}," 47MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
48 "{Native Instruments, RigKontrol3}," 48 "{Native Instruments, RigKontrol3},"
49 "{Native Instruments, Kore Controller}," 49 "{Native Instruments, Kore Controller},"
50 "{Native Instruments, Kore Controller 2}," 50 "{Native Instruments, Kore Controller 2},"
51 "{Native Instruments, Audio Kontrol 1}," 51 "{Native Instruments, Audio Kontrol 1},"
52 "{Native Instruments, Audio 4 DJ},"
52 "{Native Instruments, Audio 8 DJ}," 53 "{Native Instruments, Audio 8 DJ},"
53 "{Native Instruments, Session I/O}}"); 54 "{Native Instruments, Session I/O},"
55 "{Native Instruments, GuitarRig mobile}");
54 56
55static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */ 57static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
56static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */ 58static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */
@@ -116,6 +118,16 @@ static struct usb_device_id snd_usb_id_table[] = {
116 .idVendor = USB_VID_NATIVEINSTRUMENTS, 118 .idVendor = USB_VID_NATIVEINSTRUMENTS,
117 .idProduct = USB_PID_SESSIONIO 119 .idProduct = USB_PID_SESSIONIO
118 }, 120 },
121 {
122 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
123 .idVendor = USB_VID_NATIVEINSTRUMENTS,
124 .idProduct = USB_PID_GUITARRIGMOBILE
125 },
126 {
127 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
128 .idVendor = USB_VID_NATIVEINSTRUMENTS,
129 .idProduct = USB_PID_AUDIO4DJ
130 },
119 { /* terminator */ } 131 { /* terminator */ }
120}; 132};
121 133
@@ -239,6 +251,8 @@ int snd_usb_caiaq_set_audio_params (struct snd_usb_caiaqdev *dev,
239 251
240 if (dev->audio_parm_answer != 1) 252 if (dev->audio_parm_answer != 1)
241 debug("unable to set the device's audio params\n"); 253 debug("unable to set the device's audio params\n");
254 else
255 dev->bpp = bpp;
242 256
243 return dev->audio_parm_answer == 1 ? 0 : -EINVAL; 257 return dev->audio_parm_answer == 1 ? 0 : -EINVAL;
244} 258}
@@ -300,6 +314,12 @@ static void __devinit setup_card(struct snd_usb_caiaqdev *dev)
300 } 314 }
301 315
302 break; 316 break;
317 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_AUDIO4DJ):
318 /* Audio 4 DJ - default input mode to phono */
319 dev->control_state[0] = 2;
320 snd_usb_caiaq_send_command(dev, EP1_CMD_WRITE_IO,
321 dev->control_state, 1);
322 break;
303 } 323 }
304 324
305 if (dev->spec.num_analog_audio_out + 325 if (dev->spec.num_analog_audio_out +
@@ -336,9 +356,10 @@ static void __devinit setup_card(struct snd_usb_caiaqdev *dev)
336 log("Unable to set up control system (ret=%d)\n", ret); 356 log("Unable to set up control system (ret=%d)\n", ret);
337} 357}
338 358
339static struct snd_card* create_card(struct usb_device* usb_dev) 359static int create_card(struct usb_device* usb_dev, struct snd_card **cardp)
340{ 360{
341 int devnum; 361 int devnum;
362 int err;
342 struct snd_card *card; 363 struct snd_card *card;
343 struct snd_usb_caiaqdev *dev; 364 struct snd_usb_caiaqdev *dev;
344 365
@@ -347,12 +368,12 @@ static struct snd_card* create_card(struct usb_device* usb_dev)
347 break; 368 break;
348 369
349 if (devnum >= SNDRV_CARDS) 370 if (devnum >= SNDRV_CARDS)
350 return NULL; 371 return -ENODEV;
351 372
352 card = snd_card_new(index[devnum], id[devnum], THIS_MODULE, 373 err = snd_card_create(index[devnum], id[devnum], THIS_MODULE,
353 sizeof(struct snd_usb_caiaqdev)); 374 sizeof(struct snd_usb_caiaqdev), &card);
354 if (!card) 375 if (err < 0)
355 return NULL; 376 return err;
356 377
357 dev = caiaqdev(card); 378 dev = caiaqdev(card);
358 dev->chip.dev = usb_dev; 379 dev->chip.dev = usb_dev;
@@ -362,7 +383,8 @@ static struct snd_card* create_card(struct usb_device* usb_dev)
362 spin_lock_init(&dev->spinlock); 383 spin_lock_init(&dev->spinlock);
363 snd_card_set_dev(card, &usb_dev->dev); 384 snd_card_set_dev(card, &usb_dev->dev);
364 385
365 return card; 386 *cardp = card;
387 return 0;
366} 388}
367 389
368static int __devinit init_card(struct snd_usb_caiaqdev *dev) 390static int __devinit init_card(struct snd_usb_caiaqdev *dev)
@@ -441,10 +463,10 @@ static int __devinit snd_probe(struct usb_interface *intf,
441 struct snd_card *card; 463 struct snd_card *card;
442 struct usb_device *device = interface_to_usbdev(intf); 464 struct usb_device *device = interface_to_usbdev(intf);
443 465
444 card = create_card(device); 466 ret = create_card(device, &card);
445 467
446 if (!card) 468 if (ret < 0)
447 return -ENOMEM; 469 return ret;
448 470
449 usb_set_intfdata(intf, card); 471 usb_set_intfdata(intf, card);
450 ret = init_card(caiaqdev(card)); 472 ret = init_card(caiaqdev(card));
diff --git a/sound/usb/caiaq/caiaq-device.h b/sound/usb/caiaq/caiaq-device.h
index ab56e738c5fc..4cce1ad7493d 100644
--- a/sound/usb/caiaq/caiaq-device.h
+++ b/sound/usb/caiaq/caiaq-device.h
@@ -10,8 +10,10 @@
10#define USB_PID_KORECONTROLLER 0x4711 10#define USB_PID_KORECONTROLLER 0x4711
11#define USB_PID_KORECONTROLLER2 0x4712 11#define USB_PID_KORECONTROLLER2 0x4712
12#define USB_PID_AK1 0x0815 12#define USB_PID_AK1 0x0815
13#define USB_PID_AUDIO4DJ 0x0839
13#define USB_PID_AUDIO8DJ 0x1978 14#define USB_PID_AUDIO8DJ 0x1978
14#define USB_PID_SESSIONIO 0x1915 15#define USB_PID_SESSIONIO 0x1915
16#define USB_PID_GUITARRIGMOBILE 0x0d8d
15 17
16#define EP1_BUFSIZE 64 18#define EP1_BUFSIZE 64
17#define CAIAQ_USB_STR_LEN 0xff 19#define CAIAQ_USB_STR_LEN 0xff
@@ -87,9 +89,9 @@ struct snd_usb_caiaqdev {
87 int audio_out_buf_pos[MAX_STREAMS]; 89 int audio_out_buf_pos[MAX_STREAMS];
88 int period_in_count[MAX_STREAMS]; 90 int period_in_count[MAX_STREAMS];
89 int period_out_count[MAX_STREAMS]; 91 int period_out_count[MAX_STREAMS];
90 int input_panic, output_panic; 92 int input_panic, output_panic, warned;
91 char *audio_in_buf, *audio_out_buf; 93 char *audio_in_buf, *audio_out_buf;
92 unsigned int samplerates; 94 unsigned int samplerates, bpp;
93 95
94 struct snd_pcm_substream *sub_playback[MAX_STREAMS]; 96 struct snd_pcm_substream *sub_playback[MAX_STREAMS];
95 struct snd_pcm_substream *sub_capture[MAX_STREAMS]; 97 struct snd_pcm_substream *sub_capture[MAX_STREAMS];
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
index 19e37451c216..c2db0f959681 100644
--- a/sound/usb/usbaudio.c
+++ b/sound/usb/usbaudio.c
@@ -107,7 +107,7 @@ MODULE_PARM_DESC(ignore_ctl_error,
107#define MAX_PACKS_HS (MAX_PACKS * 8) /* in high speed mode */ 107#define MAX_PACKS_HS (MAX_PACKS * 8) /* in high speed mode */
108#define MAX_URBS 8 108#define MAX_URBS 8
109#define SYNC_URBS 4 /* always four urbs for sync */ 109#define SYNC_URBS 4 /* always four urbs for sync */
110#define MIN_PACKS_URB 1 /* minimum 1 packet per urb */ 110#define MAX_QUEUE 24 /* try not to exceed this queue length, in ms */
111 111
112struct audioformat { 112struct audioformat {
113 struct list_head list; 113 struct list_head list;
@@ -525,7 +525,7 @@ static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs)
525/* 525/*
526 * Prepare urb for streaming before playback starts or when paused. 526 * Prepare urb for streaming before playback starts or when paused.
527 * 527 *
528 * We don't have any data, so we send a frame of silence. 528 * We don't have any data, so we send silence.
529 */ 529 */
530static int prepare_nodata_playback_urb(struct snd_usb_substream *subs, 530static int prepare_nodata_playback_urb(struct snd_usb_substream *subs,
531 struct snd_pcm_runtime *runtime, 531 struct snd_pcm_runtime *runtime,
@@ -537,13 +537,13 @@ static int prepare_nodata_playback_urb(struct snd_usb_substream *subs,
537 537
538 offs = 0; 538 offs = 0;
539 urb->dev = ctx->subs->dev; 539 urb->dev = ctx->subs->dev;
540 urb->number_of_packets = subs->packs_per_ms; 540 for (i = 0; i < ctx->packets; ++i) {
541 for (i = 0; i < subs->packs_per_ms; ++i) {
542 counts = snd_usb_audio_next_packet_size(subs); 541 counts = snd_usb_audio_next_packet_size(subs);
543 urb->iso_frame_desc[i].offset = offs * stride; 542 urb->iso_frame_desc[i].offset = offs * stride;
544 urb->iso_frame_desc[i].length = counts * stride; 543 urb->iso_frame_desc[i].length = counts * stride;
545 offs += counts; 544 offs += counts;
546 } 545 }
546 urb->number_of_packets = ctx->packets;
547 urb->transfer_buffer_length = offs * stride; 547 urb->transfer_buffer_length = offs * stride;
548 memset(urb->transfer_buffer, 548 memset(urb->transfer_buffer,
549 subs->cur_audiofmt->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0, 549 subs->cur_audiofmt->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0,
@@ -1034,9 +1034,9 @@ static void release_substream_urbs(struct snd_usb_substream *subs, int force)
1034static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int period_bytes, 1034static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int period_bytes,
1035 unsigned int rate, unsigned int frame_bits) 1035 unsigned int rate, unsigned int frame_bits)
1036{ 1036{
1037 unsigned int maxsize, n, i; 1037 unsigned int maxsize, i;
1038 int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK; 1038 int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
1039 unsigned int npacks[MAX_URBS], urb_packs, total_packs, packs_per_ms; 1039 unsigned int urb_packs, total_packs, packs_per_ms;
1040 1040
1041 /* calculate the frequency in 16.16 format */ 1041 /* calculate the frequency in 16.16 format */
1042 if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL) 1042 if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL)
@@ -1070,8 +1070,7 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1070 subs->packs_per_ms = packs_per_ms; 1070 subs->packs_per_ms = packs_per_ms;
1071 1071
1072 if (is_playback) { 1072 if (is_playback) {
1073 urb_packs = nrpacks; 1073 urb_packs = max(nrpacks, 1);
1074 urb_packs = max(urb_packs, (unsigned int)MIN_PACKS_URB);
1075 urb_packs = min(urb_packs, (unsigned int)MAX_PACKS); 1074 urb_packs = min(urb_packs, (unsigned int)MAX_PACKS);
1076 } else 1075 } else
1077 urb_packs = 1; 1076 urb_packs = 1;
@@ -1079,7 +1078,7 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1079 1078
1080 /* decide how many packets to be used */ 1079 /* decide how many packets to be used */
1081 if (is_playback) { 1080 if (is_playback) {
1082 unsigned int minsize; 1081 unsigned int minsize, maxpacks;
1083 /* determine how small a packet can be */ 1082 /* determine how small a packet can be */
1084 minsize = (subs->freqn >> (16 - subs->datainterval)) 1083 minsize = (subs->freqn >> (16 - subs->datainterval))
1085 * (frame_bits >> 3); 1084 * (frame_bits >> 3);
@@ -1092,8 +1091,13 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1092 total_packs = (total_packs + packs_per_ms - 1) 1091 total_packs = (total_packs + packs_per_ms - 1)
1093 & ~(packs_per_ms - 1); 1092 & ~(packs_per_ms - 1);
1094 /* we need at least two URBs for queueing */ 1093 /* we need at least two URBs for queueing */
1095 if (total_packs < 2 * MIN_PACKS_URB * packs_per_ms) 1094 if (total_packs < 2 * packs_per_ms) {
1096 total_packs = 2 * MIN_PACKS_URB * packs_per_ms; 1095 total_packs = 2 * packs_per_ms;
1096 } else {
1097 /* and we don't want too long a queue either */
1098 maxpacks = max(MAX_QUEUE * packs_per_ms, urb_packs * 2);
1099 total_packs = min(total_packs, maxpacks);
1100 }
1097 } else { 1101 } else {
1098 total_packs = MAX_URBS * urb_packs; 1102 total_packs = MAX_URBS * urb_packs;
1099 } 1103 }
@@ -1102,31 +1106,11 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1102 /* too much... */ 1106 /* too much... */
1103 subs->nurbs = MAX_URBS; 1107 subs->nurbs = MAX_URBS;
1104 total_packs = MAX_URBS * urb_packs; 1108 total_packs = MAX_URBS * urb_packs;
1105 } 1109 } else if (subs->nurbs < 2) {
1106 n = total_packs;
1107 for (i = 0; i < subs->nurbs; i++) {
1108 npacks[i] = n > urb_packs ? urb_packs : n;
1109 n -= urb_packs;
1110 }
1111 if (subs->nurbs <= 1) {
1112 /* too little - we need at least two packets 1110 /* too little - we need at least two packets
1113 * to ensure contiguous playback/capture 1111 * to ensure contiguous playback/capture
1114 */ 1112 */
1115 subs->nurbs = 2; 1113 subs->nurbs = 2;
1116 npacks[0] = (total_packs + 1) / 2;
1117 npacks[1] = total_packs - npacks[0];
1118 } else if (npacks[subs->nurbs-1] < MIN_PACKS_URB * packs_per_ms) {
1119 /* the last packet is too small.. */
1120 if (subs->nurbs > 2) {
1121 /* merge to the first one */
1122 npacks[0] += npacks[subs->nurbs - 1];
1123 subs->nurbs--;
1124 } else {
1125 /* divide to two */
1126 subs->nurbs = 2;
1127 npacks[0] = (total_packs + 1) / 2;
1128 npacks[1] = total_packs - npacks[0];
1129 }
1130 } 1114 }
1131 1115
1132 /* allocate and initialize data urbs */ 1116 /* allocate and initialize data urbs */
@@ -1134,7 +1118,8 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1134 struct snd_urb_ctx *u = &subs->dataurb[i]; 1118 struct snd_urb_ctx *u = &subs->dataurb[i];
1135 u->index = i; 1119 u->index = i;
1136 u->subs = subs; 1120 u->subs = subs;
1137 u->packets = npacks[i]; 1121 u->packets = (i + 1) * total_packs / subs->nurbs
1122 - i * total_packs / subs->nurbs;
1138 u->buffer_size = maxsize * u->packets; 1123 u->buffer_size = maxsize * u->packets;
1139 if (subs->fmt_type == USB_FORMAT_TYPE_II) 1124 if (subs->fmt_type == USB_FORMAT_TYPE_II)
1140 u->packets++; /* for transfer delimiter */ 1125 u->packets++; /* for transfer delimiter */
@@ -1292,14 +1277,14 @@ static int init_usb_sample_rate(struct usb_device *dev, int iface,
1292 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR, 1277 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), SET_CUR,
1293 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, 1278 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
1294 SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) { 1279 SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) {
1295 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep 0x%x\n", 1280 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n",
1296 dev->devnum, iface, fmt->altsetting, rate, ep); 1281 dev->devnum, iface, fmt->altsetting, rate, ep);
1297 return err; 1282 return err;
1298 } 1283 }
1299 if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR, 1284 if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), GET_CUR,
1300 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_IN, 1285 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_IN,
1301 SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) { 1286 SAMPLING_FREQ_CONTROL << 8, ep, data, 3, 1000)) < 0) {
1302 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep 0x%x\n", 1287 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n",
1303 dev->devnum, iface, fmt->altsetting, ep); 1288 dev->devnum, iface, fmt->altsetting, ep);
1304 return 0; /* some devices don't support reading */ 1289 return 0; /* some devices don't support reading */
1305 } 1290 }
@@ -1431,9 +1416,11 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
1431 subs->cur_audiofmt = fmt; 1416 subs->cur_audiofmt = fmt;
1432 1417
1433#if 0 1418#if 0
1434 printk("setting done: format = %d, rate = %d..%d, channels = %d\n", 1419 printk(KERN_DEBUG
1420 "setting done: format = %d, rate = %d..%d, channels = %d\n",
1435 fmt->format, fmt->rate_min, fmt->rate_max, fmt->channels); 1421 fmt->format, fmt->rate_min, fmt->rate_max, fmt->channels);
1436 printk(" datapipe = 0x%0x, syncpipe = 0x%0x\n", 1422 printk(KERN_DEBUG
1423 " datapipe = 0x%0x, syncpipe = 0x%0x\n",
1437 subs->datapipe, subs->syncpipe); 1424 subs->datapipe, subs->syncpipe);
1438#endif 1425#endif
1439 1426
@@ -1468,7 +1455,7 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
1468 channels = params_channels(hw_params); 1455 channels = params_channels(hw_params);
1469 fmt = find_format(subs, format, rate, channels); 1456 fmt = find_format(subs, format, rate, channels);
1470 if (!fmt) { 1457 if (!fmt) {
1471 snd_printd(KERN_DEBUG "cannot set format: format = 0x%x, rate = %d, channels = %d\n", 1458 snd_printd(KERN_DEBUG "cannot set format: format = %#x, rate = %d, channels = %d\n",
1472 format, rate, channels); 1459 format, rate, channels);
1473 return -EINVAL; 1460 return -EINVAL;
1474 } 1461 }
@@ -1795,7 +1782,7 @@ static int check_hw_params_convention(struct snd_usb_substream *subs)
1795 if (rates[f->format] && rates[f->format] != f->rates) 1782 if (rates[f->format] && rates[f->format] != f->rates)
1796 goto __out; 1783 goto __out;
1797 } 1784 }
1798 channels[f->format] |= (1 << f->channels); 1785 channels[f->format] |= 1 << (f->channels - 1);
1799 rates[f->format] |= f->rates; 1786 rates[f->format] |= f->rates;
1800 /* needs knot? */ 1787 /* needs knot? */
1801 if (f->rates & SNDRV_PCM_RATE_KNOT) 1788 if (f->rates & SNDRV_PCM_RATE_KNOT)
@@ -1822,7 +1809,7 @@ static int check_hw_params_convention(struct snd_usb_substream *subs)
1822 continue; 1809 continue;
1823 for (i = 0; i < 32; i++) { 1810 for (i = 0; i < 32; i++) {
1824 if (f->rates & (1 << i)) 1811 if (f->rates & (1 << i))
1825 channels[i] |= (1 << f->channels); 1812 channels[i] |= 1 << (f->channels - 1);
1826 } 1813 }
1827 } 1814 }
1828 cmaster = 0; 1815 cmaster = 0;
@@ -1919,7 +1906,7 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre
1919 * in the current code assume the 1ms period. 1906 * in the current code assume the 1ms period.
1920 */ 1907 */
1921 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 1908 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME,
1922 1000 * MIN_PACKS_URB, 1909 1000,
1923 /*(nrpacks * MAX_URBS) * 1000*/ UINT_MAX); 1910 /*(nrpacks * MAX_URBS) * 1000*/ UINT_MAX);
1924 1911
1925 err = check_hw_params_convention(subs); 1912 err = check_hw_params_convention(subs);
@@ -2160,7 +2147,7 @@ static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct s
2160 fp = list_entry(p, struct audioformat, list); 2147 fp = list_entry(p, struct audioformat, list);
2161 snd_iprintf(buffer, " Interface %d\n", fp->iface); 2148 snd_iprintf(buffer, " Interface %d\n", fp->iface);
2162 snd_iprintf(buffer, " Altset %d\n", fp->altsetting); 2149 snd_iprintf(buffer, " Altset %d\n", fp->altsetting);
2163 snd_iprintf(buffer, " Format: 0x%x\n", fp->format); 2150 snd_iprintf(buffer, " Format: %#x\n", fp->format);
2164 snd_iprintf(buffer, " Channels: %d\n", fp->channels); 2151 snd_iprintf(buffer, " Channels: %d\n", fp->channels);
2165 snd_iprintf(buffer, " Endpoint: %d %s (%s)\n", 2152 snd_iprintf(buffer, " Endpoint: %d %s (%s)\n",
2166 fp->endpoint & USB_ENDPOINT_NUMBER_MASK, 2153 fp->endpoint & USB_ENDPOINT_NUMBER_MASK,
@@ -2180,7 +2167,7 @@ static void proc_dump_substream_formats(struct snd_usb_substream *subs, struct s
2180 snd_iprintf(buffer, "\n"); 2167 snd_iprintf(buffer, "\n");
2181 } 2168 }
2182 // snd_iprintf(buffer, " Max Packet Size = %d\n", fp->maxpacksize); 2169 // snd_iprintf(buffer, " Max Packet Size = %d\n", fp->maxpacksize);
2183 // snd_iprintf(buffer, " EP Attribute = 0x%x\n", fp->attributes); 2170 // snd_iprintf(buffer, " EP Attribute = %#x\n", fp->attributes);
2184 } 2171 }
2185} 2172}
2186 2173
@@ -2621,7 +2608,7 @@ static int parse_audio_format_ii(struct snd_usb_audio *chip, struct audioformat
2621 fp->format = SNDRV_PCM_FORMAT_MPEG; 2608 fp->format = SNDRV_PCM_FORMAT_MPEG;
2622 break; 2609 break;
2623 default: 2610 default:
2624 snd_printd(KERN_INFO "%d:%u:%d : unknown format tag 0x%x is detected. processed as MPEG.\n", 2611 snd_printd(KERN_INFO "%d:%u:%d : unknown format tag %#x is detected. processed as MPEG.\n",
2625 chip->dev->devnum, fp->iface, fp->altsetting, format); 2612 chip->dev->devnum, fp->iface, fp->altsetting, format);
2626 fp->format = SNDRV_PCM_FORMAT_MPEG; 2613 fp->format = SNDRV_PCM_FORMAT_MPEG;
2627 break; 2614 break;
@@ -2819,7 +2806,7 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2819 continue; 2806 continue;
2820 } 2807 }
2821 2808
2822 snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint 0x%x\n", dev->devnum, iface_no, altno, fp->endpoint); 2809 snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint %#x\n", dev->devnum, iface_no, altno, fp->endpoint);
2823 err = add_audio_endpoint(chip, stream, fp); 2810 err = add_audio_endpoint(chip, stream, fp);
2824 if (err < 0) { 2811 if (err < 0) {
2825 kfree(fp->rate_table); 2812 kfree(fp->rate_table);
@@ -3466,10 +3453,10 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
3466 return -ENXIO; 3453 return -ENXIO;
3467 } 3454 }
3468 3455
3469 card = snd_card_new(index[idx], id[idx], THIS_MODULE, 0); 3456 err = snd_card_create(index[idx], id[idx], THIS_MODULE, 0, &card);
3470 if (card == NULL) { 3457 if (err < 0) {
3471 snd_printk(KERN_ERR "cannot create card instance %d\n", idx); 3458 snd_printk(KERN_ERR "cannot create card instance %d\n", idx);
3472 return -ENOMEM; 3459 return err;
3473 } 3460 }
3474 3461
3475 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 3462 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
@@ -3766,7 +3753,7 @@ static int usb_audio_resume(struct usb_interface *intf)
3766 3753
3767static int __init snd_usb_audio_init(void) 3754static int __init snd_usb_audio_init(void)
3768{ 3755{
3769 if (nrpacks < MIN_PACKS_URB || nrpacks > MAX_PACKS) { 3756 if (nrpacks < 1 || nrpacks > MAX_PACKS) {
3770 printk(KERN_WARNING "invalid nrpacks value.\n"); 3757 printk(KERN_WARNING "invalid nrpacks value.\n");
3771 return -EINVAL; 3758 return -EINVAL;
3772 } 3759 }
diff --git a/sound/usb/usbmixer.c b/sound/usb/usbmixer.c
index 00397c8a765b..ecb58e7a6245 100644
--- a/sound/usb/usbmixer.c
+++ b/sound/usb/usbmixer.c
@@ -66,6 +66,7 @@ static const struct rc_config {
66 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */ 66 { USB_ID(0x041e, 0x3000), 0, 1, 2, 1, 18, 0x0013 }, /* Extigy */
67 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */ 67 { USB_ID(0x041e, 0x3020), 2, 1, 6, 6, 18, 0x0013 }, /* Audigy 2 NX */
68 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */ 68 { USB_ID(0x041e, 0x3040), 2, 2, 6, 6, 2, 0x6e91 }, /* Live! 24-bit */
69 { USB_ID(0x041e, 0x3048), 2, 2, 6, 6, 2, 0x6e91 }, /* Toshiba SB0500 */
69}; 70};
70 71
71struct usb_mixer_interface { 72struct usb_mixer_interface {
@@ -78,7 +79,6 @@ struct usb_mixer_interface {
78 79
79 /* Sound Blaster remote control stuff */ 80 /* Sound Blaster remote control stuff */
80 const struct rc_config *rc_cfg; 81 const struct rc_config *rc_cfg;
81 unsigned long rc_hwdep_open;
82 u32 rc_code; 82 u32 rc_code;
83 wait_queue_head_t rc_waitq; 83 wait_queue_head_t rc_waitq;
84 struct urb *rc_urb; 84 struct urb *rc_urb;
@@ -110,6 +110,8 @@ struct mixer_build {
110 const struct usbmix_selector_map *selector_map; 110 const struct usbmix_selector_map *selector_map;
111}; 111};
112 112
113#define MAX_CHANNELS 10 /* max logical channels */
114
113struct usb_mixer_elem_info { 115struct usb_mixer_elem_info {
114 struct usb_mixer_interface *mixer; 116 struct usb_mixer_interface *mixer;
115 struct usb_mixer_elem_info *next_id_elem; /* list of controls with same id */ 117 struct usb_mixer_elem_info *next_id_elem; /* list of controls with same id */
@@ -120,6 +122,8 @@ struct usb_mixer_elem_info {
120 int channels; 122 int channels;
121 int val_type; 123 int val_type;
122 int min, max, res; 124 int min, max, res;
125 int cached;
126 int cache_val[MAX_CHANNELS];
123 u8 initialized; 127 u8 initialized;
124}; 128};
125 129
@@ -181,8 +185,6 @@ enum {
181 USB_PROC_DCR_RELEASE = 6, 185 USB_PROC_DCR_RELEASE = 6,
182}; 186};
183 187
184#define MAX_CHANNELS 10 /* max logical channels */
185
186 188
187/* 189/*
188 * manual mapping of mixer names 190 * manual mapping of mixer names
@@ -219,7 +221,10 @@ static int check_ignored_ctl(struct mixer_build *state, int unitid, int control)
219 for (p = state->map; p->id; p++) { 221 for (p = state->map; p->id; p++) {
220 if (p->id == unitid && ! p->name && 222 if (p->id == unitid && ! p->name &&
221 (! control || ! p->control || control == p->control)) { 223 (! control || ! p->control || control == p->control)) {
222 // printk("ignored control %d:%d\n", unitid, control); 224 /*
225 printk(KERN_DEBUG "ignored control %d:%d\n",
226 unitid, control);
227 */
223 return 1; 228 return 1;
224 } 229 }
225 } 230 }
@@ -376,11 +381,35 @@ static int get_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int *
376} 381}
377 382
378/* channel = 0: master, 1 = first channel */ 383/* channel = 0: master, 1 = first channel */
379static inline int get_cur_mix_value(struct usb_mixer_elem_info *cval, int channel, int *value) 384static inline int get_cur_mix_raw(struct usb_mixer_elem_info *cval,
385 int channel, int *value)
380{ 386{
381 return get_ctl_value(cval, GET_CUR, (cval->control << 8) | channel, value); 387 return get_ctl_value(cval, GET_CUR, (cval->control << 8) | channel, value);
382} 388}
383 389
390static int get_cur_mix_value(struct usb_mixer_elem_info *cval,
391 int channel, int index, int *value)
392{
393 int err;
394
395 if (cval->cached & (1 << channel)) {
396 *value = cval->cache_val[index];
397 return 0;
398 }
399 err = get_cur_mix_raw(cval, channel, value);
400 if (err < 0) {
401 if (!cval->mixer->ignore_ctl_error)
402 snd_printd(KERN_ERR "cannot get current value for "
403 "control %d ch %d: err = %d\n",
404 cval->control, channel, err);
405 return err;
406 }
407 cval->cached |= 1 << channel;
408 cval->cache_val[index] = *value;
409 return 0;
410}
411
412
384/* 413/*
385 * set a mixer value 414 * set a mixer value
386 */ 415 */
@@ -412,9 +441,17 @@ static int set_cur_ctl_value(struct usb_mixer_elem_info *cval, int validx, int v
412 return set_ctl_value(cval, SET_CUR, validx, value); 441 return set_ctl_value(cval, SET_CUR, validx, value);
413} 442}
414 443
415static inline int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel, int value) 444static int set_cur_mix_value(struct usb_mixer_elem_info *cval, int channel,
445 int index, int value)
416{ 446{
417 return set_ctl_value(cval, SET_CUR, (cval->control << 8) | channel, value); 447 int err;
448 err = set_ctl_value(cval, SET_CUR, (cval->control << 8) | channel,
449 value);
450 if (err < 0)
451 return err;
452 cval->cached |= 1 << channel;
453 cval->cache_val[index] = value;
454 return 0;
418} 455}
419 456
420/* 457/*
@@ -718,7 +755,7 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
718 if (cval->min + cval->res < cval->max) { 755 if (cval->min + cval->res < cval->max) {
719 int last_valid_res = cval->res; 756 int last_valid_res = cval->res;
720 int saved, test, check; 757 int saved, test, check;
721 get_cur_mix_value(cval, minchn, &saved); 758 get_cur_mix_raw(cval, minchn, &saved);
722 for (;;) { 759 for (;;) {
723 test = saved; 760 test = saved;
724 if (test < cval->max) 761 if (test < cval->max)
@@ -726,8 +763,8 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
726 else 763 else
727 test -= cval->res; 764 test -= cval->res;
728 if (test < cval->min || test > cval->max || 765 if (test < cval->min || test > cval->max ||
729 set_cur_mix_value(cval, minchn, test) || 766 set_cur_mix_value(cval, minchn, 0, test) ||
730 get_cur_mix_value(cval, minchn, &check)) { 767 get_cur_mix_raw(cval, minchn, &check)) {
731 cval->res = last_valid_res; 768 cval->res = last_valid_res;
732 break; 769 break;
733 } 770 }
@@ -735,7 +772,7 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min)
735 break; 772 break;
736 cval->res *= 2; 773 cval->res *= 2;
737 } 774 }
738 set_cur_mix_value(cval, minchn, saved); 775 set_cur_mix_value(cval, minchn, 0, saved);
739 } 776 }
740 777
741 cval->initialized = 1; 778 cval->initialized = 1;
@@ -775,35 +812,25 @@ static int mixer_ctl_feature_get(struct snd_kcontrol *kcontrol, struct snd_ctl_e
775 struct usb_mixer_elem_info *cval = kcontrol->private_data; 812 struct usb_mixer_elem_info *cval = kcontrol->private_data;
776 int c, cnt, val, err; 813 int c, cnt, val, err;
777 814
815 ucontrol->value.integer.value[0] = cval->min;
778 if (cval->cmask) { 816 if (cval->cmask) {
779 cnt = 0; 817 cnt = 0;
780 for (c = 0; c < MAX_CHANNELS; c++) { 818 for (c = 0; c < MAX_CHANNELS; c++) {
781 if (cval->cmask & (1 << c)) { 819 if (!(cval->cmask & (1 << c)))
782 err = get_cur_mix_value(cval, c + 1, &val); 820 continue;
783 if (err < 0) { 821 err = get_cur_mix_value(cval, c + 1, cnt, &val);
784 if (cval->mixer->ignore_ctl_error) { 822 if (err < 0)
785 ucontrol->value.integer.value[0] = cval->min; 823 return cval->mixer->ignore_ctl_error ? 0 : err;
786 return 0; 824 val = get_relative_value(cval, val);
787 } 825 ucontrol->value.integer.value[cnt] = val;
788 snd_printd(KERN_ERR "cannot get current value for control %d ch %d: err = %d\n", cval->control, c + 1, err); 826 cnt++;
789 return err;
790 }
791 val = get_relative_value(cval, val);
792 ucontrol->value.integer.value[cnt] = val;
793 cnt++;
794 }
795 } 827 }
828 return 0;
796 } else { 829 } else {
797 /* master channel */ 830 /* master channel */
798 err = get_cur_mix_value(cval, 0, &val); 831 err = get_cur_mix_value(cval, 0, 0, &val);
799 if (err < 0) { 832 if (err < 0)
800 if (cval->mixer->ignore_ctl_error) { 833 return cval->mixer->ignore_ctl_error ? 0 : err;
801 ucontrol->value.integer.value[0] = cval->min;
802 return 0;
803 }
804 snd_printd(KERN_ERR "cannot get current value for control %d master ch: err = %d\n", cval->control, err);
805 return err;
806 }
807 val = get_relative_value(cval, val); 834 val = get_relative_value(cval, val);
808 ucontrol->value.integer.value[0] = val; 835 ucontrol->value.integer.value[0] = val;
809 } 836 }
@@ -820,34 +847,28 @@ static int mixer_ctl_feature_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
820 if (cval->cmask) { 847 if (cval->cmask) {
821 cnt = 0; 848 cnt = 0;
822 for (c = 0; c < MAX_CHANNELS; c++) { 849 for (c = 0; c < MAX_CHANNELS; c++) {
823 if (cval->cmask & (1 << c)) { 850 if (!(cval->cmask & (1 << c)))
824 err = get_cur_mix_value(cval, c + 1, &oval); 851 continue;
825 if (err < 0) { 852 err = get_cur_mix_value(cval, c + 1, cnt, &oval);
826 if (cval->mixer->ignore_ctl_error) 853 if (err < 0)
827 return 0; 854 return cval->mixer->ignore_ctl_error ? 0 : err;
828 return err; 855 val = ucontrol->value.integer.value[cnt];
829 } 856 val = get_abs_value(cval, val);
830 val = ucontrol->value.integer.value[cnt]; 857 if (oval != val) {
831 val = get_abs_value(cval, val); 858 set_cur_mix_value(cval, c + 1, cnt, val);
832 if (oval != val) { 859 changed = 1;
833 set_cur_mix_value(cval, c + 1, val);
834 changed = 1;
835 }
836 get_cur_mix_value(cval, c + 1, &val);
837 cnt++;
838 } 860 }
861 cnt++;
839 } 862 }
840 } else { 863 } else {
841 /* master channel */ 864 /* master channel */
842 err = get_cur_mix_value(cval, 0, &oval); 865 err = get_cur_mix_value(cval, 0, 0, &oval);
843 if (err < 0 && cval->mixer->ignore_ctl_error)
844 return 0;
845 if (err < 0) 866 if (err < 0)
846 return err; 867 return cval->mixer->ignore_ctl_error ? 0 : err;
847 val = ucontrol->value.integer.value[0]; 868 val = ucontrol->value.integer.value[0];
848 val = get_abs_value(cval, val); 869 val = get_abs_value(cval, val);
849 if (val != oval) { 870 if (val != oval) {
850 set_cur_mix_value(cval, 0, val); 871 set_cur_mix_value(cval, 0, 0, val);
851 changed = 1; 872 changed = 1;
852 } 873 }
853 } 874 }
@@ -1706,7 +1727,8 @@ static void snd_usb_mixer_memory_change(struct usb_mixer_interface *mixer,
1706 break; 1727 break;
1707 /* live24ext: 4 = line-in jack */ 1728 /* live24ext: 4 = line-in jack */
1708 case 3: /* hp-out jack (may actuate Mute) */ 1729 case 3: /* hp-out jack (may actuate Mute) */
1709 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040)) 1730 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
1731 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
1710 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id); 1732 snd_usb_mixer_notify_id(mixer, mixer->rc_cfg->mute_mixer_id);
1711 break; 1733 break;
1712 default: 1734 default:
@@ -1797,24 +1819,6 @@ static void snd_usb_soundblaster_remote_complete(struct urb *urb)
1797 wake_up(&mixer->rc_waitq); 1819 wake_up(&mixer->rc_waitq);
1798} 1820}
1799 1821
1800static int snd_usb_sbrc_hwdep_open(struct snd_hwdep *hw, struct file *file)
1801{
1802 struct usb_mixer_interface *mixer = hw->private_data;
1803
1804 if (test_and_set_bit(0, &mixer->rc_hwdep_open))
1805 return -EBUSY;
1806 return 0;
1807}
1808
1809static int snd_usb_sbrc_hwdep_release(struct snd_hwdep *hw, struct file *file)
1810{
1811 struct usb_mixer_interface *mixer = hw->private_data;
1812
1813 clear_bit(0, &mixer->rc_hwdep_open);
1814 smp_mb__after_clear_bit();
1815 return 0;
1816}
1817
1818static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf, 1822static long snd_usb_sbrc_hwdep_read(struct snd_hwdep *hw, char __user *buf,
1819 long count, loff_t *offset) 1823 long count, loff_t *offset)
1820{ 1824{
@@ -1867,9 +1871,8 @@ static int snd_usb_soundblaster_remote_init(struct usb_mixer_interface *mixer)
1867 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC; 1871 hwdep->iface = SNDRV_HWDEP_IFACE_SB_RC;
1868 hwdep->private_data = mixer; 1872 hwdep->private_data = mixer;
1869 hwdep->ops.read = snd_usb_sbrc_hwdep_read; 1873 hwdep->ops.read = snd_usb_sbrc_hwdep_read;
1870 hwdep->ops.open = snd_usb_sbrc_hwdep_open;
1871 hwdep->ops.release = snd_usb_sbrc_hwdep_release;
1872 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll; 1874 hwdep->ops.poll = snd_usb_sbrc_hwdep_poll;
1875 hwdep->exclusive = 1;
1873 1876
1874 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL); 1877 mixer->rc_urb = usb_alloc_urb(0, GFP_KERNEL);
1875 if (!mixer->rc_urb) 1878 if (!mixer->rc_urb)
@@ -1956,8 +1959,9 @@ static int snd_audigy2nx_controls_create(struct usb_mixer_interface *mixer)
1956 int i, err; 1959 int i, err;
1957 1960
1958 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) { 1961 for (i = 0; i < ARRAY_SIZE(snd_audigy2nx_controls); ++i) {
1959 if (i > 1 && /* Live24ext has 2 LEDs only */ 1962 if (i > 1 && /* Live24ext has 2 LEDs only */
1960 mixer->chip->usb_id == USB_ID(0x041e, 0x3040)) 1963 (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
1964 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)))
1961 break; 1965 break;
1962 err = snd_ctl_add(mixer->chip->card, 1966 err = snd_ctl_add(mixer->chip->card,
1963 snd_ctl_new1(&snd_audigy2nx_controls[i], mixer)); 1967 snd_ctl_new1(&snd_audigy2nx_controls[i], mixer));
@@ -1994,7 +1998,8 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
1994 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname); 1998 snd_iprintf(buffer, "%s jacks\n\n", mixer->chip->card->shortname);
1995 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020)) 1999 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020))
1996 jacks = jacks_audigy2nx; 2000 jacks = jacks_audigy2nx;
1997 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040)) 2001 else if (mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2002 mixer->chip->usb_id == USB_ID(0x041e, 0x3048))
1998 jacks = jacks_live24ext; 2003 jacks = jacks_live24ext;
1999 else 2004 else
2000 return; 2005 return;
@@ -2044,7 +2049,8 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2044 goto _error; 2049 goto _error;
2045 2050
2046 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) || 2051 if (mixer->chip->usb_id == USB_ID(0x041e, 0x3020) ||
2047 mixer->chip->usb_id == USB_ID(0x041e, 0x3040)) { 2052 mixer->chip->usb_id == USB_ID(0x041e, 0x3040) ||
2053 mixer->chip->usb_id == USB_ID(0x041e, 0x3048)) {
2048 struct snd_info_entry *entry; 2054 struct snd_info_entry *entry;
2049 2055
2050 if ((err = snd_audigy2nx_controls_create(mixer)) < 0) 2056 if ((err = snd_audigy2nx_controls_create(mixer)) < 0)
diff --git a/sound/usb/usbmixer_maps.c b/sound/usb/usbmixer_maps.c
index d755be0ad811..3e5d66cf1f5a 100644
--- a/sound/usb/usbmixer_maps.c
+++ b/sound/usb/usbmixer_maps.c
@@ -261,6 +261,22 @@ static struct usbmix_name_map aureon_51_2_map[] = {
261 {} /* terminator */ 261 {} /* terminator */
262}; 262};
263 263
264static struct usbmix_name_map scratch_live_map[] = {
265 /* 1: IT Line 1 (USB streaming) */
266 /* 2: OT Line 1 (Speaker) */
267 /* 3: IT Line 1 (Line connector) */
268 { 4, "Line 1 In" }, /* FU */
269 /* 5: OT Line 1 (USB streaming) */
270 /* 6: IT Line 2 (USB streaming) */
271 /* 7: OT Line 2 (Speaker) */
272 /* 8: IT Line 2 (Line connector) */
273 { 9, "Line 2 In" }, /* FU */
274 /* 10: OT Line 2 (USB streaming) */
275 /* 11: IT Mic (Line connector) */
276 /* 12: OT Mic (USB streaming) */
277 { 0 } /* terminator */
278};
279
264/* 280/*
265 * Control map entries 281 * Control map entries
266 */ 282 */
@@ -285,6 +301,11 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
285 .map = live24ext_map, 301 .map = live24ext_map,
286 }, 302 },
287 { 303 {
304 .id = USB_ID(0x041e, 0x3048),
305 .map = audigy2nx_map,
306 .selector_map = audigy2nx_selectors,
307 },
308 {
288 /* Hercules DJ Console (Windows Edition) */ 309 /* Hercules DJ Console (Windows Edition) */
289 .id = USB_ID(0x06f8, 0xb000), 310 .id = USB_ID(0x06f8, 0xb000),
290 .ignore_ctl_error = 1, 311 .ignore_ctl_error = 1,
@@ -311,6 +332,11 @@ static struct usbmix_ctl_map usbmix_ctl_maps[] = {
311 .id = USB_ID(0x0ccd, 0x0028), 332 .id = USB_ID(0x0ccd, 0x0028),
312 .map = aureon_51_2_map, 333 .map = aureon_51_2_map,
313 }, 334 },
335 {
336 .id = USB_ID(0x13e5, 0x0001),
337 .map = scratch_live_map,
338 .ignore_ctl_error = 1,
339 },
314 { 0 } /* terminator */ 340 { 0 } /* terminator */
315}; 341};
316 342
diff --git a/sound/usb/usbquirks.h b/sound/usb/usbquirks.h
index 5d8ef09b9dcc..647ef5029651 100644
--- a/sound/usb/usbquirks.h
+++ b/sound/usb/usbquirks.h
@@ -39,6 +39,16 @@
39 .idProduct = prod, \ 39 .idProduct = prod, \
40 .bInterfaceClass = USB_CLASS_VENDOR_SPEC 40 .bInterfaceClass = USB_CLASS_VENDOR_SPEC
41 41
42/* Creative/Toshiba Multimedia Center SB-0500 */
43{
44 USB_DEVICE(0x041e, 0x3048),
45 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
46 .vendor_name = "Toshiba",
47 .product_name = "SB-0500",
48 .ifnum = QUIRK_NO_INTERFACE
49 }
50},
51
42/* Creative/E-Mu devices */ 52/* Creative/E-Mu devices */
43{ 53{
44 USB_DEVICE(0x041e, 0x3010), 54 USB_DEVICE(0x041e, 0x3010),
diff --git a/sound/usb/usx2y/us122l.c b/sound/usb/usx2y/us122l.c
index 73e59f4403a4..98276aafefe6 100644
--- a/sound/usb/usx2y/us122l.c
+++ b/sound/usb/usx2y/us122l.c
@@ -478,19 +478,21 @@ static bool us122l_create_card(struct snd_card *card)
478 return true; 478 return true;
479} 479}
480 480
481static struct snd_card *usx2y_create_card(struct usb_device *device) 481static int usx2y_create_card(struct usb_device *device, struct snd_card **cardp)
482{ 482{
483 int dev; 483 int dev;
484 struct snd_card *card; 484 struct snd_card *card;
485 int err;
486
485 for (dev = 0; dev < SNDRV_CARDS; ++dev) 487 for (dev = 0; dev < SNDRV_CARDS; ++dev)
486 if (enable[dev] && !snd_us122l_card_used[dev]) 488 if (enable[dev] && !snd_us122l_card_used[dev])
487 break; 489 break;
488 if (dev >= SNDRV_CARDS) 490 if (dev >= SNDRV_CARDS)
489 return NULL; 491 return -ENODEV;
490 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 492 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
491 sizeof(struct us122l)); 493 sizeof(struct us122l), &card);
492 if (!card) 494 if (err < 0)
493 return NULL; 495 return err;
494 snd_us122l_card_used[US122L(card)->chip.index = dev] = 1; 496 snd_us122l_card_used[US122L(card)->chip.index = dev] = 1;
495 497
496 US122L(card)->chip.dev = device; 498 US122L(card)->chip.dev = device;
@@ -509,46 +511,57 @@ static struct snd_card *usx2y_create_card(struct usb_device *device)
509 US122L(card)->chip.dev->devnum 511 US122L(card)->chip.dev->devnum
510 ); 512 );
511 snd_card_set_dev(card, &device->dev); 513 snd_card_set_dev(card, &device->dev);
512 return card; 514 *cardp = card;
515 return 0;
513} 516}
514 517
515static void *us122l_usb_probe(struct usb_interface *intf, 518static int us122l_usb_probe(struct usb_interface *intf,
516 const struct usb_device_id *device_id) 519 const struct usb_device_id *device_id,
520 struct snd_card **cardp)
517{ 521{
518 struct usb_device *device = interface_to_usbdev(intf); 522 struct usb_device *device = interface_to_usbdev(intf);
519 struct snd_card *card = usx2y_create_card(device); 523 struct snd_card *card;
524 int err;
520 525
521 if (!card) 526 err = usx2y_create_card(device, &card);
522 return NULL; 527 if (err < 0)
528 return err;
523 529
524 if (!us122l_create_card(card) || 530 if (!us122l_create_card(card)) {
525 snd_card_register(card) < 0) {
526 snd_card_free(card); 531 snd_card_free(card);
527 return NULL; 532 return -EINVAL;
533 }
534
535 err = snd_card_register(card);
536 if (err < 0) {
537 snd_card_free(card);
538 return err;
528 } 539 }
529 540
530 usb_get_dev(device); 541 usb_get_dev(device);
531 return card; 542 *cardp = card;
543 return 0;
532} 544}
533 545
534static int snd_us122l_probe(struct usb_interface *intf, 546static int snd_us122l_probe(struct usb_interface *intf,
535 const struct usb_device_id *id) 547 const struct usb_device_id *id)
536{ 548{
537 struct snd_card *card; 549 struct snd_card *card;
550 int err;
551
538 snd_printdd(KERN_DEBUG"%p:%i\n", 552 snd_printdd(KERN_DEBUG"%p:%i\n",
539 intf, intf->cur_altsetting->desc.bInterfaceNumber); 553 intf, intf->cur_altsetting->desc.bInterfaceNumber);
540 if (intf->cur_altsetting->desc.bInterfaceNumber != 1) 554 if (intf->cur_altsetting->desc.bInterfaceNumber != 1)
541 return 0; 555 return 0;
542 556
543 card = us122l_usb_probe(usb_get_intf(intf), id); 557 err = us122l_usb_probe(usb_get_intf(intf), id, &card);
544 558 if (err < 0) {
545 if (card) { 559 usb_put_intf(intf);
546 usb_set_intfdata(intf, card); 560 return err;
547 return 0;
548 } 561 }
549 562
550 usb_put_intf(intf); 563 usb_set_intfdata(intf, card);
551 return -EIO; 564 return 0;
552} 565}
553 566
554static void snd_us122l_disconnect(struct usb_interface *intf) 567static void snd_us122l_disconnect(struct usb_interface *intf)
diff --git a/sound/usb/usx2y/usX2Yhwdep.c b/sound/usb/usx2y/usX2Yhwdep.c
index 1558a5c4094f..4af8740db717 100644
--- a/sound/usb/usx2y/usX2Yhwdep.c
+++ b/sound/usb/usx2y/usX2Yhwdep.c
@@ -30,9 +30,6 @@
30#include "usbusx2y.h" 30#include "usbusx2y.h"
31#include "usX2Yhwdep.h" 31#include "usX2Yhwdep.h"
32 32
33int usX2Y_hwdep_pcm_new(struct snd_card *card);
34
35
36static int snd_us428ctls_vm_fault(struct vm_area_struct *area, 33static int snd_us428ctls_vm_fault(struct vm_area_struct *area,
37 struct vm_fault *vmf) 34 struct vm_fault *vmf)
38{ 35{
@@ -106,16 +103,6 @@ static unsigned int snd_us428ctls_poll(struct snd_hwdep *hw, struct file *file,
106} 103}
107 104
108 105
109static int snd_usX2Y_hwdep_open(struct snd_hwdep *hw, struct file *file)
110{
111 return 0;
112}
113
114static int snd_usX2Y_hwdep_release(struct snd_hwdep *hw, struct file *file)
115{
116 return 0;
117}
118
119static int snd_usX2Y_hwdep_dsp_status(struct snd_hwdep *hw, 106static int snd_usX2Y_hwdep_dsp_status(struct snd_hwdep *hw,
120 struct snd_hwdep_dsp_status *info) 107 struct snd_hwdep_dsp_status *info)
121{ 108{
@@ -267,8 +254,6 @@ int usX2Y_hwdep_new(struct snd_card *card, struct usb_device* device)
267 254
268 hw->iface = SNDRV_HWDEP_IFACE_USX2Y; 255 hw->iface = SNDRV_HWDEP_IFACE_USX2Y;
269 hw->private_data = usX2Y(card); 256 hw->private_data = usX2Y(card);
270 hw->ops.open = snd_usX2Y_hwdep_open;
271 hw->ops.release = snd_usX2Y_hwdep_release;
272 hw->ops.dsp_status = snd_usX2Y_hwdep_dsp_status; 257 hw->ops.dsp_status = snd_usX2Y_hwdep_dsp_status;
273 hw->ops.dsp_load = snd_usX2Y_hwdep_dsp_load; 258 hw->ops.dsp_load = snd_usX2Y_hwdep_dsp_load;
274 hw->ops.mmap = snd_us428ctls_mmap; 259 hw->ops.mmap = snd_us428ctls_mmap;
diff --git a/sound/usb/usx2y/usb_stream.c b/sound/usb/usx2y/usb_stream.c
index 70b96355ca4c..24393dafcb6e 100644
--- a/sound/usb/usx2y/usb_stream.c
+++ b/sound/usb/usx2y/usb_stream.c
@@ -557,7 +557,7 @@ static void stream_start(struct usb_stream_kernel *sk,
557 s->idle_insize -= max_diff - max_diff_0; 557 s->idle_insize -= max_diff - max_diff_0;
558 s->idle_insize += urb_size - s->period_size; 558 s->idle_insize += urb_size - s->period_size;
559 if (s->idle_insize < 0) { 559 if (s->idle_insize < 0) {
560 snd_printk("%i %i %i\n", 560 snd_printk(KERN_WARNING "%i %i %i\n",
561 s->idle_insize, urb_size, s->period_size); 561 s->idle_insize, urb_size, s->period_size);
562 return; 562 return;
563 } else if (s->idle_insize == 0) { 563 } else if (s->idle_insize == 0) {
diff --git a/sound/usb/usx2y/usbusx2y.c b/sound/usb/usx2y/usbusx2y.c
index 11639bd72a51..5ce0da23ee96 100644
--- a/sound/usb/usx2y/usbusx2y.c
+++ b/sound/usb/usx2y/usbusx2y.c
@@ -227,9 +227,9 @@ static void i_usX2Y_In04Int(struct urb *urb)
227 227
228 if (usX2Y->US04) { 228 if (usX2Y->US04) {
229 if (0 == usX2Y->US04->submitted) 229 if (0 == usX2Y->US04->submitted)
230 do 230 do {
231 err = usb_submit_urb(usX2Y->US04->urb[usX2Y->US04->submitted++], GFP_ATOMIC); 231 err = usb_submit_urb(usX2Y->US04->urb[usX2Y->US04->submitted++], GFP_ATOMIC);
232 while (!err && usX2Y->US04->submitted < usX2Y->US04->len); 232 } while (!err && usX2Y->US04->submitted < usX2Y->US04->len);
233 } else 233 } else
234 if (us428ctls && us428ctls->p4outLast >= 0 && us428ctls->p4outLast < N_us428_p4out_BUFS) { 234 if (us428ctls && us428ctls->p4outLast >= 0 && us428ctls->p4outLast < N_us428_p4out_BUFS) {
235 if (us428ctls->p4outLast != us428ctls->p4outSent) { 235 if (us428ctls->p4outLast != us428ctls->p4outSent) {
@@ -333,18 +333,21 @@ static struct usb_device_id snd_usX2Y_usb_id_table[] = {
333 { /* terminator */ } 333 { /* terminator */ }
334}; 334};
335 335
336static struct snd_card *usX2Y_create_card(struct usb_device *device) 336static int usX2Y_create_card(struct usb_device *device, struct snd_card **cardp)
337{ 337{
338 int dev; 338 int dev;
339 struct snd_card * card; 339 struct snd_card * card;
340 int err;
341
340 for (dev = 0; dev < SNDRV_CARDS; ++dev) 342 for (dev = 0; dev < SNDRV_CARDS; ++dev)
341 if (enable[dev] && !snd_usX2Y_card_used[dev]) 343 if (enable[dev] && !snd_usX2Y_card_used[dev])
342 break; 344 break;
343 if (dev >= SNDRV_CARDS) 345 if (dev >= SNDRV_CARDS)
344 return NULL; 346 return -ENODEV;
345 card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct usX2Ydev)); 347 err = snd_card_create(index[dev], id[dev], THIS_MODULE,
346 if (!card) 348 sizeof(struct usX2Ydev), &card);
347 return NULL; 349 if (err < 0)
350 return err;
348 snd_usX2Y_card_used[usX2Y(card)->chip.index = dev] = 1; 351 snd_usX2Y_card_used[usX2Y(card)->chip.index = dev] = 1;
349 card->private_free = snd_usX2Y_card_private_free; 352 card->private_free = snd_usX2Y_card_private_free;
350 usX2Y(card)->chip.dev = device; 353 usX2Y(card)->chip.dev = device;
@@ -362,26 +365,36 @@ static struct snd_card *usX2Y_create_card(struct usb_device *device)
362 usX2Y(card)->chip.dev->bus->busnum, usX2Y(card)->chip.dev->devnum 365 usX2Y(card)->chip.dev->bus->busnum, usX2Y(card)->chip.dev->devnum
363 ); 366 );
364 snd_card_set_dev(card, &device->dev); 367 snd_card_set_dev(card, &device->dev);
365 return card; 368 *cardp = card;
369 return 0;
366} 370}
367 371
368 372
369static void *usX2Y_usb_probe(struct usb_device *device, struct usb_interface *intf, const struct usb_device_id *device_id) 373static int usX2Y_usb_probe(struct usb_device *device,
374 struct usb_interface *intf,
375 const struct usb_device_id *device_id,
376 struct snd_card **cardp)
370{ 377{
371 int err; 378 int err;
372 struct snd_card * card; 379 struct snd_card * card;
380
381 *cardp = NULL;
373 if (le16_to_cpu(device->descriptor.idVendor) != 0x1604 || 382 if (le16_to_cpu(device->descriptor.idVendor) != 0x1604 ||
374 (le16_to_cpu(device->descriptor.idProduct) != USB_ID_US122 && 383 (le16_to_cpu(device->descriptor.idProduct) != USB_ID_US122 &&
375 le16_to_cpu(device->descriptor.idProduct) != USB_ID_US224 && 384 le16_to_cpu(device->descriptor.idProduct) != USB_ID_US224 &&
376 le16_to_cpu(device->descriptor.idProduct) != USB_ID_US428) || 385 le16_to_cpu(device->descriptor.idProduct) != USB_ID_US428))
377 !(card = usX2Y_create_card(device))) 386 return -EINVAL;
378 return NULL; 387
388 err = usX2Y_create_card(device, &card);
389 if (err < 0)
390 return err;
379 if ((err = usX2Y_hwdep_new(card, device)) < 0 || 391 if ((err = usX2Y_hwdep_new(card, device)) < 0 ||
380 (err = snd_card_register(card)) < 0) { 392 (err = snd_card_register(card)) < 0) {
381 snd_card_free(card); 393 snd_card_free(card);
382 return NULL; 394 return err;
383 } 395 }
384 return card; 396 *cardp = card;
397 return 0;
385} 398}
386 399
387/* 400/*
@@ -389,13 +402,14 @@ static void *usX2Y_usb_probe(struct usb_device *device, struct usb_interface *in
389 */ 402 */
390static int snd_usX2Y_probe(struct usb_interface *intf, const struct usb_device_id *id) 403static int snd_usX2Y_probe(struct usb_interface *intf, const struct usb_device_id *id)
391{ 404{
392 void *chip; 405 struct snd_card *card;
393 chip = usX2Y_usb_probe(interface_to_usbdev(intf), intf, id); 406 int err;
394 if (chip) { 407
395 usb_set_intfdata(intf, chip); 408 err = usX2Y_usb_probe(interface_to_usbdev(intf), intf, id, &card);
396 return 0; 409 if (err < 0)
397 } else 410 return err;
398 return -EIO; 411 dev_set_drvdata(&intf->dev, card);
412 return 0;
399} 413}
400 414
401static void snd_usX2Y_disconnect(struct usb_interface *intf) 415static void snd_usX2Y_disconnect(struct usb_interface *intf)
diff --git a/sound/usb/usx2y/usx2yhwdeppcm.h b/sound/usb/usx2y/usx2yhwdeppcm.h
index c3382fdc386b..9c4fb84b2aa0 100644
--- a/sound/usb/usx2y/usx2yhwdeppcm.h
+++ b/sound/usb/usx2y/usx2yhwdeppcm.h
@@ -18,3 +18,5 @@ struct snd_usX2Y_hwdep_pcm_shm {
18 volatile unsigned captured_iso_frames; 18 volatile unsigned captured_iso_frames;
19 int capture_iso_start; 19 int capture_iso_start;
20}; 20};
21
22int usX2Y_hwdep_pcm_new(struct snd_card *card);